More svelte work

This commit is contained in:
Pieter Vander Vennet 2023-01-31 14:45:32 +01:00
parent 890980d534
commit 112162e6c8
6 changed files with 75 additions and 31 deletions

View file

@ -209,11 +209,15 @@ export class GeoOperations {
* GeoOperations.inside([1.42822265625, 48.61838518688487], multiPolygon) // => false * GeoOperations.inside([1.42822265625, 48.61838518688487], multiPolygon) // => false
* GeoOperations.inside([4.02099609375, 47.81315451752768], multiPolygon) // => false * GeoOperations.inside([4.02099609375, 47.81315451752768], multiPolygon) // => false
*/ */
public static inside(pointCoordinate: [number, number] | Feature<Point>, feature): boolean { public static inside(
pointCoordinate: [number, number] | Feature<Point>,
feature: Feature
): boolean {
// ray-casting algorithm based on // ray-casting algorithm based on
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
if (feature.geometry.type === "Point") { if (feature.geometry.type === "Point") {
// The feature that should 'contain' pointCoordinate is a point itself, so it cannot contain anything
return false return false
} }
@ -227,6 +231,7 @@ export class GeoOperations {
if (feature.geometry.type === "MultiPolygon") { if (feature.geometry.type === "MultiPolygon") {
const coordinatess = feature.geometry.coordinates const coordinatess = feature.geometry.coordinates
for (const coordinates of coordinatess) { for (const coordinates of coordinatess) {
// @ts-ignore
const inThisPolygon = GeoOperations.pointInPolygonCoordinates(x, y, coordinates) const inThisPolygon = GeoOperations.pointInPolygonCoordinates(x, y, coordinates)
if (inThisPolygon) { if (inThisPolygon) {
return true return true
@ -236,6 +241,7 @@ export class GeoOperations {
} }
if (feature.geometry.type === "Polygon") { if (feature.geometry.type === "Polygon") {
// @ts-ignore
return GeoOperations.pointInPolygonCoordinates(x, y, feature.geometry.coordinates) return GeoOperations.pointInPolygonCoordinates(x, y, feature.geometry.coordinates)
} }

View file

@ -114,7 +114,7 @@ export abstract class Store<T> implements Readable<T> {
abstract map<J>(f: (t: T) => J): Store<J> abstract map<J>(f: (t: T) => J): Store<J>
abstract map<J>(f: (t: T) => J, extraStoresToWatch: Store<any>[]): Store<J> abstract map<J>(f: (t: T) => J, extraStoresToWatch: Store<any>[]): Store<J>
public mapD<J>(f: (t: T) => J, extraStoresToWatch: Store<any>[]): Store<J> { public mapD<J>(f: (t: T) => J, extraStoresToWatch?: Store<any>[]): Store<J> {
return this.map((t) => { return this.map((t) => {
if (t === undefined) { if (t === undefined) {
return undefined return undefined

View file

@ -108,7 +108,10 @@ class SingleLayerSelectionButton extends Toggle {
// Is the previous layer still valid? If so, we don't bother to switch // Is the previous layer still valid? If so, we don't bother to switch
if ( if (
previousLayer.data.feature === null || previousLayer.data.feature === null ||
GeoOperations.inside(locationControl.data, previousLayer.data.feature) GeoOperations.inside(
[locationControl.data.lon, locationControl.data.lat],
previousLayer.data.feature
)
) { ) {
return return
} }

View file

@ -1,11 +1,14 @@
<!-- A contact link indicates how a mapper can contact their local community -->
<script lang="ts"> <script lang="ts">
import {Store} from "../../Logic/UIEventSource"; import {Store} from "../../Logic/UIEventSource";
// A contact link indicates how a mapper can contact their local community
<!-- The _properties_ of a community feature --> // The _properties_ of a community feature
export let country: Store<{ resources; nameEn: string }> export let country: Store<{ resources; nameEn: string }>
let resources = country.mapD(country => Object.values(country?.resources ?? {})) let resources : Store<{ id: string, resolved: Record<string, string> }[]> = country.map(country => {
if(country === undefined){
return []
}
return Array.from(Object.values(country?.resources ?? {}))
})
</script> </script>
<div> <div>

72
package-lock.json generated
View file

@ -9,6 +9,7 @@
"version": "0.25.1", "version": "0.25.1",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"dependencies": { "dependencies": {
"@rollup/plugin-typescript": "^11.0.0",
"@turf/boolean-intersects": "^6.5.0", "@turf/boolean-intersects": "^6.5.0",
"@turf/buffer": "^6.5.0", "@turf/buffer": "^6.5.0",
"@turf/collect": "^6.5.0", "@turf/collect": "^6.5.0",
@ -79,9 +80,10 @@
"sharp": "^0.30.5", "sharp": "^0.30.5",
"svelte": "^3.55.1", "svelte": "^3.55.1",
"svelte-check": "^3.0.2", "svelte-check": "^3.0.2",
"svelte-preprocess": "^5.0.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"ts2json-schema": "^1.4.0", "ts2json-schema": "^1.4.0",
"tslib": "^2.4.1", "tslib": "^2.5.0",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-no-circular-imports": "^0.7.0", "tslint-no-circular-imports": "^0.7.0",
"typescript": "^4.7.4", "typescript": "^4.7.4",
@ -1784,11 +1786,35 @@
} }
} }
}, },
"node_modules/@rollup/plugin-typescript": {
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.0.0.tgz",
"integrity": "sha512-goPyCWBiimk1iJgSTgsehFD5OOFHiAknrRJjqFCudcW8JtWiBlK284Xnn4flqMqg6YAjVG/EE+3aVzrL5qNSzQ==",
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"resolve": "^1.22.1"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^2.14.0||^3.0.0",
"tslib": "*",
"typescript": ">=3.7.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
},
"tslib": {
"optional": true
}
}
},
"node_modules/@rollup/pluginutils": { "node_modules/@rollup/pluginutils": {
"version": "5.0.2", "version": "5.0.2",
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz",
"integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==",
"dev": true,
"dependencies": { "dependencies": {
"@types/estree": "^1.0.0", "@types/estree": "^1.0.0",
"estree-walker": "^2.0.2", "estree-walker": "^2.0.2",
@ -3429,8 +3455,7 @@
"node_modules/@types/estree": { "node_modules/@types/estree": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz",
"integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==", "integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ=="
"dev": true
}, },
"node_modules/@types/geojson": { "node_modules/@types/geojson": {
"version": "7946.0.10", "version": "7946.0.10",
@ -5158,8 +5183,7 @@
"node_modules/estree-walker": { "node_modules/estree-walker": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="
"dev": true
}, },
"node_modules/esutils": { "node_modules/esutils": {
"version": "2.0.3", "version": "2.0.3",
@ -8023,7 +8047,7 @@
"version": "3.10.0", "version": "3.10.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.10.0.tgz", "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.10.0.tgz",
"integrity": "sha512-JmRYz44NjC1MjVF2VKxc0M1a97vn+cDxeqWmnwyAF4FvpjK8YFdHpaqvQB+3IxCvX05vJxKZkoMDU8TShhmJVA==", "integrity": "sha512-JmRYz44NjC1MjVF2VKxc0M1a97vn+cDxeqWmnwyAF4FvpjK8YFdHpaqvQB+3IxCvX05vJxKZkoMDU8TShhmJVA==",
"dev": true, "devOptional": true,
"bin": { "bin": {
"rollup": "dist/bin/rollup" "rollup": "dist/bin/rollup"
}, },
@ -9358,10 +9382,10 @@
} }
}, },
"node_modules/tslib": { "node_modules/tslib": {
"version": "2.4.1", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==", "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
"dev": true "devOptional": true
}, },
"node_modules/tslint": { "node_modules/tslint": {
"version": "6.1.3", "version": "6.1.3",
@ -11903,11 +11927,19 @@
"@rollup/pluginutils": "^5.0.1" "@rollup/pluginutils": "^5.0.1"
} }
}, },
"@rollup/plugin-typescript": {
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.0.0.tgz",
"integrity": "sha512-goPyCWBiimk1iJgSTgsehFD5OOFHiAknrRJjqFCudcW8JtWiBlK284Xnn4flqMqg6YAjVG/EE+3aVzrL5qNSzQ==",
"requires": {
"@rollup/pluginutils": "^5.0.1",
"resolve": "^1.22.1"
}
},
"@rollup/pluginutils": { "@rollup/pluginutils": {
"version": "5.0.2", "version": "5.0.2",
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz",
"integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==",
"dev": true,
"requires": { "requires": {
"@types/estree": "^1.0.0", "@types/estree": "^1.0.0",
"estree-walker": "^2.0.2", "estree-walker": "^2.0.2",
@ -13209,8 +13241,7 @@
"@types/estree": { "@types/estree": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz",
"integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==", "integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ=="
"dev": true
}, },
"@types/geojson": { "@types/geojson": {
"version": "7946.0.10", "version": "7946.0.10",
@ -14549,8 +14580,7 @@
"estree-walker": { "estree-walker": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="
"dev": true
}, },
"esutils": { "esutils": {
"version": "2.0.3", "version": "2.0.3",
@ -16722,7 +16752,7 @@
"version": "3.10.0", "version": "3.10.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.10.0.tgz", "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.10.0.tgz",
"integrity": "sha512-JmRYz44NjC1MjVF2VKxc0M1a97vn+cDxeqWmnwyAF4FvpjK8YFdHpaqvQB+3IxCvX05vJxKZkoMDU8TShhmJVA==", "integrity": "sha512-JmRYz44NjC1MjVF2VKxc0M1a97vn+cDxeqWmnwyAF4FvpjK8YFdHpaqvQB+3IxCvX05vJxKZkoMDU8TShhmJVA==",
"dev": true, "devOptional": true,
"requires": { "requires": {
"fsevents": "~2.3.2" "fsevents": "~2.3.2"
} }
@ -17660,10 +17690,10 @@
} }
}, },
"tslib": { "tslib": {
"version": "2.4.1", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==", "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==",
"dev": true "devOptional": true
}, },
"tslint": { "tslint": {
"version": "6.1.3", "version": "6.1.3",

View file

@ -5,7 +5,7 @@
"description": "A small website to edit OSM easily", "description": "A small website to edit OSM easily",
"bugs": "https://github.com/pietervdvn/MapComplete/issues", "bugs": "https://github.com/pietervdvn/MapComplete/issues",
"homepage": "https://mapcomplete.osm.be", "homepage": "https://mapcomplete.osm.be",
"main": "index.js", "main": "index.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"start": "npm run generate:layeroverview && npm run strt", "start": "npm run generate:layeroverview && npm run strt",
@ -64,6 +64,7 @@
"not op_mini all" "not op_mini all"
], ],
"dependencies": { "dependencies": {
"@rollup/plugin-typescript": "^11.0.0",
"@turf/boolean-intersects": "^6.5.0", "@turf/boolean-intersects": "^6.5.0",
"@turf/buffer": "^6.5.0", "@turf/buffer": "^6.5.0",
"@turf/collect": "^6.5.0", "@turf/collect": "^6.5.0",
@ -134,9 +135,10 @@
"sharp": "^0.30.5", "sharp": "^0.30.5",
"svelte": "^3.55.1", "svelte": "^3.55.1",
"svelte-check": "^3.0.2", "svelte-check": "^3.0.2",
"svelte-preprocess": "^5.0.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"ts2json-schema": "^1.4.0", "ts2json-schema": "^1.4.0",
"tslib": "^2.4.1", "tslib": "^2.5.0",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-no-circular-imports": "^0.7.0", "tslint-no-circular-imports": "^0.7.0",
"typescript": "^4.7.4", "typescript": "^4.7.4",