terra-draw 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +27 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +5 -0
- package/CODE_OF_CONDUCT.md +36 -0
- package/CONTRIBUTING.md +17 -0
- package/DEVELOPMENT.md +77 -0
- package/LICENSE +8 -0
- package/README.md +19 -0
- package/ROADMAP.md +63 -0
- package/common/addModeChangeHandler.ts +26 -0
- package/data/sample.ts +10126 -0
- package/dist/adapters/google-maps.adapter.d.ts +38 -0
- package/dist/adapters/leaflet.adapter.d.ts +35 -0
- package/dist/adapters/mapbox-gl.adapter.d.ts +36 -0
- package/dist/bundle.js +6 -0
- package/dist/bundle.js.LICENSE.txt +4 -0
- package/dist/common.d.ts +99 -0
- package/dist/geometry/boolean/point-in-polygon.d.ts +2 -0
- package/dist/geometry/boolean/self-intersects.d.ts +2 -0
- package/dist/geometry/centroid.d.ts +2 -0
- package/dist/geometry/coordinates-identical.d.ts +2 -0
- package/dist/geometry/create-circle.d.ts +6 -0
- package/dist/geometry/get-coordinates-as-points.d.ts +6 -0
- package/dist/geometry/get-midpoints.d.ts +7 -0
- package/dist/geometry/get-pixel-distance-to-line.d.ts +10 -0
- package/dist/geometry/get-pixel-distance.d.ts +7 -0
- package/dist/geometry/haversine-distance.d.ts +1 -0
- package/dist/geometry/helpers.d.ts +4 -0
- package/dist/geometry/limit-decimal-precision.d.ts +1 -0
- package/dist/geometry/measure/haversine-distance.d.ts +2 -0
- package/dist/geometry/measure/pixel-distance-to-line.d.ts +10 -0
- package/dist/geometry/measure/pixel-distance.d.ts +7 -0
- package/dist/geometry/measure/rhumb-bearing.d.ts +2 -0
- package/dist/geometry/measure/rhumb-destination.d.ts +2 -0
- package/dist/geometry/measure/rhumb-distance.d.ts +2 -0
- package/dist/geometry/midpoint-coordinate.d.ts +2 -0
- package/dist/geometry/point-in-polygon.d.ts +1 -0
- package/dist/geometry/self-intersects.d.ts +2 -0
- package/dist/geometry/shape/create-circle.d.ts +7 -0
- package/dist/geometry/transform/rotate.d.ts +2 -0
- package/dist/geometry/transform/scale.d.ts +2 -0
- package/dist/modes/base.behavior.d.ts +19 -0
- package/dist/modes/base.mode.d.ts +30 -0
- package/dist/modes/circle/circle.mode.d.ts +27 -0
- package/dist/modes/circle.mode.d.ts +18 -0
- package/dist/modes/click-bounding-box.behavior.d.ts +7 -0
- package/dist/modes/freehand/freehand.mode.d.ts +29 -0
- package/dist/modes/freehand.mode.d.ts +20 -0
- package/dist/modes/line-string.mode.d.ts +21 -0
- package/dist/modes/linestring/linestring.mode.d.ts +34 -0
- package/dist/modes/pixel-distance.behavior.d.ts +7 -0
- package/dist/modes/point/point.mode.d.ts +18 -0
- package/dist/modes/point.mode.d.ts +14 -0
- package/dist/modes/polygon/behaviors/start-end-point.behavior.d.ts +11 -0
- package/dist/modes/polygon/polygon.mode.d.ts +37 -0
- package/dist/modes/polygon.mode.d.ts +21 -0
- package/dist/modes/select/behaviors/drag-coordinate.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/drag-feature.behavior.d.ts +17 -0
- package/dist/modes/select/behaviors/features-at-mouse-event.behavior.d.ts +15 -0
- package/dist/modes/select/behaviors/midpoint.behavior.d.ts +18 -0
- package/dist/modes/select/behaviors/rotate-feature.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/scale-feature.behavior.d.ts +13 -0
- package/dist/modes/select/behaviors/selection-point.behavior.d.ts +18 -0
- package/dist/modes/select/select.mode.d.ts +62 -0
- package/dist/modes/select.mode.d.ts +21 -0
- package/dist/modes/snapping.behavior.d.ts +13 -0
- package/dist/modes/static/static.mode.d.ts +13 -0
- package/dist/modes/static.mode.d.ts +10 -0
- package/dist/store/spatial-index/quickselect.d.ts +2 -0
- package/dist/store/spatial-index/rbush.d.ts +35 -0
- package/dist/store/spatial-index/spatial-index.d.ts +18 -0
- package/dist/store/store.d.ts +48 -0
- package/dist/terra-draw.cjs +2 -0
- package/dist/terra-draw.cjs.map +1 -0
- package/dist/terra-draw.d.ts +47 -0
- package/dist/terra-draw.modern.js +2 -0
- package/dist/terra-draw.modern.js.map +1 -0
- package/dist/terra-draw.module.js +2 -0
- package/dist/terra-draw.module.js.map +1 -0
- package/dist/terra-draw.umd.js +2 -0
- package/dist/terra-draw.umd.js.map +1 -0
- package/dist/util/geoms.d.ts +3 -0
- package/dist/util/id.d.ts +1 -0
- package/dist/util/styling.d.ts +2 -0
- package/jest.config.ts +27 -0
- package/package.json +86 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terra-draw.cjs","sources":["../src/geometry/limit-decimal-precision.ts","../src/adapters/google-maps.adapter.ts","../src/adapters/leaflet.adapter.ts","../src/adapters/mapbox-gl.adapter.ts","../src/geometry/create-circle.ts","../src/util/styling.ts","../src/modes/circle.mode.ts","../src/geometry/haversine-distance.ts","../src/modes/freehand.mode.ts","../src/geometry/self-intersects.ts","../src/geometry/get-pixel-distance.ts","../src/modes/line-string.mode.ts","../src/modes/point.mode.ts","../src/modes/polygon.mode.ts","../src/geometry/point-in-polygon.ts","../src/geometry/get-pixel-distance-to-line.ts","../src/modes/select.mode.ts","../src/modes/static.mode.ts","../src/store/store.ts","../src/util/id.ts","../src/terra-draw.ts"],"sourcesContent":["export function limitPrecision(num: number, decimalLimit = 9) {\n const decimals = Math.pow(10, decimalLimit);\n return Math.round(num * decimals) / decimals;\n}\n","import {\n TerraDrawCallbacks,\n TerraDrawAdapter,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { Feature, GeoJsonObject } from \"geojson\";\n\nimport { limitPrecision } from \"../geometry/limit-decimal-precision\";\n\nexport class TerraDrawGoogleMapsAdapter implements TerraDrawAdapter {\n constructor(config: {\n lib: typeof google.maps;\n map: google.maps.Map;\n coordinatePrecision?: number;\n }) {\n this._lib = config.lib;\n this._map = config.map;\n this._coordinatePrecision =\n typeof config.coordinatePrecision === \"number\"\n ? config.coordinatePrecision\n : 9;\n\n this.project = (lng: number, lat: number) => {\n const bounds = this._map.getBounds();\n const northWest = new this._lib.LatLng(\n bounds.getNorthEast().lat(),\n bounds.getSouthWest().lng()\n );\n const projection = this._map.getProjection();\n const projectedNorthWest = projection.fromLatLngToPoint(northWest);\n const projected = projection.fromLatLngToPoint({ lng, lat });\n\n const scale = Math.pow(2, this._map.getZoom());\n return {\n x: Math.floor((projected.x - projectedNorthWest.x) * scale),\n y: Math.floor((projected.y - projectedNorthWest.y) * scale),\n };\n };\n }\n\n private _coordinatePrecision: number;\n private _lib: typeof google.maps;\n private _map: google.maps.Map;\n private _onMouseMoveListener: google.maps.MapsEventListener;\n private _onMouseMoveCallback: (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => void;\n private _onClickListener: google.maps.MapsEventListener;\n private _onClickCallback: (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => void;\n private _onKeyUpListener: any;\n private _layers: boolean;\n\n public project: TerraDrawModeRegisterConfig[\"project\"];\n\n // https://stackoverflow.com/a/27905268/1363484\n private circlePath(cx: number, cy: number, r: number) {\n return (\n \"M \" +\n cx +\n \" \" +\n cy +\n \" m -\" +\n r +\n \", 0 a \" +\n r +\n \",\" +\n r +\n \" 0 1,0 \" +\n r * 2 +\n \",0 a \" +\n r +\n \",\" +\n r +\n \" 0 1,0 -\" +\n r * 2 +\n \",0\"\n );\n }\n\n register(callbacks: TerraDrawCallbacks) {\n this._onClickCallback = (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n callbacks.onClick({\n lng: limitPrecision(event.latLng.lng(), this._coordinatePrecision),\n lat: limitPrecision(event.latLng.lat(), this._coordinatePrecision),\n containerX: event.domEvent.clientX - this._map.getDiv().offsetLeft,\n containerY: event.domEvent.clientY - this._map.getDiv().offsetTop,\n });\n };\n this._onClickListener = this._map.addListener(\n \"click\",\n this._onClickCallback\n );\n\n this._onMouseMoveCallback = (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n callbacks.onMouseMove({\n lng: limitPrecision(event.latLng.lng(), this._coordinatePrecision),\n lat: limitPrecision(event.latLng.lat(), this._coordinatePrecision),\n containerX: event.domEvent.clientX,\n containerY: event.domEvent.clientY,\n });\n };\n this._onMouseMoveListener = this._map.addListener(\n \"mousemove\",\n this._onMouseMoveCallback\n );\n\n this._onKeyUpListener = (event: KeyboardEvent) => {\n callbacks.onKeyPress({ key: event.key });\n };\n\n this._map.getDiv().addEventListener(\"keyup\", this._onKeyUpListener);\n }\n\n unregister() {\n if (this._onClickListener) {\n this._onClickCallback = undefined;\n this._onClickListener.remove();\n this._onClickListener = undefined;\n }\n if (this._onMouseMoveListener) {\n this._onMouseMoveCallback = undefined;\n this._onMouseMoveListener.remove();\n this._onMouseMoveListener = undefined;\n }\n\n if (this._onKeyUpListener) {\n this._map.getDiv().removeEventListener(\"keyup\", this._onKeyUpListener);\n this._onKeyUpListener = undefined;\n }\n }\n\n render(\n features: Feature[],\n styling: { [mode: string]: TerraDrawAdapterStyling }\n ) {\n if (this._layers) {\n this._map.data.forEach((layer) => {\n this._map.data.remove(layer);\n });\n } else {\n // Clicking on data geometries triggers\n // swallows the map onclick event,\n // so we need to forward it to the click callback handler\n this._map.data.addListener(\n \"click\",\n (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n this._onClickCallback(event);\n }\n );\n\n this._map.data.addListener(\n \"mousemove\",\n (\n event: google.maps.MapMouseEvent & {\n domEvent: MouseEvent;\n }\n ) => {\n this._onMouseMoveCallback(event);\n }\n );\n }\n\n console.log(features);\n\n // features.forEach((feature) => {\n // if (feature.geometry.type === \"Polygon\") {\n // console.log(feature.geometry.coordinates);\n\n // if (feature.geometry.coordinates[0].length === 2) {\n // feature.geometry.coordinates[0] = [\n // feature.geometry.coordinates[0][0],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][0],\n // ];\n // } else if (feature.geometry.coordinates[0].length === 3) {\n // feature.geometry.coordinates[0] = [\n // feature.geometry.coordinates[0][0],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][2],\n // feature.geometry.coordinates[0][0],\n // ];\n // } else if (feature.geometry.coordinates[0].length > 3) {\n // feature.geometry.coordinates[0] = [\n // feature.geometry.coordinates[0][0],\n // feature.geometry.coordinates[0][1],\n // feature.geometry.coordinates[0][2],\n // feature.geometry.coordinates[0][0],\n // ]\n // }\n // }\n // });\n\n const featureCollection = {\n type: \"FeatureCollection\",\n features,\n } as GeoJsonObject;\n\n this._map.data.addGeoJson(featureCollection);\n\n this._map.data.setStyle((feature) => {\n const mode = feature.getProperty(\"mode\");\n const type = feature.getGeometry().getType();\n const selected = feature.getProperty(\"selected\");\n\n switch (type) {\n case \"Point\":\n return {\n icon: {\n path: this.circlePath(\n styling[mode].pointWidth,\n styling[mode].pointWidth,\n styling[mode].pointWidth\n ),\n fillColor: selected\n ? styling[mode].selectedColor\n : styling[mode].pointColor,\n fillOpacity: 1,\n strokeWeight: 0,\n rotation: 0,\n scale: 1,\n },\n };\n\n case \"LineString\":\n return {\n strokeColor: selected\n ? styling[mode].selectedColor\n : styling[mode].lineStringColor,\n strokeWeight: styling[mode].lineStringWidth,\n };\n case \"Polygon\":\n console.log(\"STYLING\", styling, mode, styling[mode]);\n return {\n strokeColor: styling[mode].polygonOutlineColor,\n strokeWeight: styling[mode].polygonOutlineWidth,\n fillOpacity: styling[mode].polygonFillOpacity,\n fillColor: selected\n ? styling[mode].selectedColor\n : styling[mode].polygonFillColor,\n };\n }\n\n return;\n });\n\n this._layers = true;\n }\n}\n","import {\n TerraDrawCallbacks,\n TerraDrawAdapter,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { Feature, GeoJsonObject } from \"geojson\";\nimport L from \"leaflet\";\nimport { limitPrecision } from \"../geometry/limit-decimal-precision\";\n\nexport class TerraDrawLeafletAdapter implements TerraDrawAdapter {\n constructor(config: {\n lib: typeof L;\n map: L.Map;\n coordinatePrecision?: number;\n }) {\n this._lib = config.lib;\n this._map = config.map;\n this._coordinatePrecision =\n typeof config.coordinatePrecision === \"number\"\n ? config.coordinatePrecision\n : 9;\n\n this.project = (lng: number, lat: number) => {\n const { x, y } = this._map.latLngToContainerPoint({ lng, lat });\n return { x, y };\n };\n }\n\n private _lib: typeof L;\n private _coordinatePrecision: number;\n private _map: L.Map;\n private _onMouseMoveListener: (ev: any) => void;\n private _onClickListener: (ev: any) => void;\n private _onKeyPressListener: (ev: any) => void;\n private _layer: L.Layer;\n\n public project: TerraDrawModeRegisterConfig[\"project\"];\n\n register(callbacks: TerraDrawCallbacks) {\n this._onClickListener = (event: L.LeafletMouseEvent) => {\n event.originalEvent.preventDefault();\n\n callbacks.onClick({\n lng: limitPrecision(event.latlng.lng, this._coordinatePrecision),\n lat: limitPrecision(event.latlng.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n\n this._map.on(\"click\", this._onClickListener);\n\n this._onMouseMoveListener = (event: L.LeafletMouseEvent) => {\n event.originalEvent.preventDefault();\n\n callbacks.onMouseMove({\n lng: limitPrecision(event.latlng.lng, this._coordinatePrecision),\n lat: limitPrecision(event.latlng.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n\n this._map.on(\"mousemove\", this._onMouseMoveListener);\n\n this._onKeyPressListener = (event: L.LeafletKeyboardEvent) => {\n event.originalEvent.preventDefault();\n\n callbacks.onKeyPress({ key: event.originalEvent.key });\n };\n\n this._map.on(\"keyup\", this._onKeyPressListener);\n }\n\n unregister() {\n if (this._onClickListener) {\n this._map.off(\"click\", this._onClickListener);\n this._onClickListener = undefined;\n }\n if (this._onMouseMoveListener) {\n this._map.off(\"click\", this._onClickListener);\n this._onClickListener = undefined;\n }\n }\n\n render(\n features: Feature[],\n styling: { [mode: string]: TerraDrawAdapterStyling }\n ) {\n if (this._layer) {\n this._map.removeLayer(this._layer);\n }\n\n const featureCollection = {\n type: \"FeatureCollection\",\n features,\n } as GeoJsonObject;\n\n // Style points - convert markers to circle markers\n const pointToLayer = (feature: Feature, latlng: L.LatLngExpression) => {\n const mode = feature.properties.mode;\n const modeStyle = styling[mode];\n\n return this._lib.circleMarker(latlng, {\n radius: modeStyle.pointWidth,\n fillColor: feature.properties.selected\n ? modeStyle.selectedColor\n : modeStyle.pointColor,\n color: modeStyle.pointOutlineColor,\n weight: 1,\n opacity: 1,\n fillOpacity: 0.8,\n });\n };\n\n // Style LineStrings and Polygons\n const style = (feature: Feature) => {\n const mode = feature.properties.mode;\n const modeStyle = styling[mode];\n\n if (feature.geometry.type === \"LineString\") {\n return {\n color: feature.properties.selected\n ? modeStyle.selectedColor\n : modeStyle.lineStringColor,\n\n weight: modeStyle.lineStringWidth,\n };\n } else if (feature.geometry.type === \"Polygon\") {\n return {\n fillOpacity: modeStyle.polygonFillOpacity,\n color: feature.properties.selected\n ? modeStyle.selectedColor\n : modeStyle.polygonFillColor,\n };\n }\n };\n\n const layer = this._lib.geoJSON(featureCollection, {\n pointToLayer,\n style,\n });\n\n layer.addTo(this._map);\n\n this._layer = layer;\n }\n}\n","import {\n TerraDrawCallbacks,\n TerraDrawAdapter,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { Feature, LineString, Point, Polygon } from \"geojson\";\nimport { limitPrecision } from \"../geometry/limit-decimal-precision\";\nimport { CircleLayer, FillLayer, LineLayer } from \"mapbox-gl\";\nimport { GeoJSONStoreFeatures, GeoJSONStoreGeometries } from \"../store/store\";\n\nexport class TerraDrawMapboxGLAdapter implements TerraDrawAdapter {\n constructor(config: { map: mapboxgl.Map; coordinatePrecision: number }) {\n this._map = config.map;\n this._coordinatePrecision =\n typeof config.coordinatePrecision === \"number\"\n ? config.coordinatePrecision\n : 9;\n\n this.project = (lng: number, lat: number) => {\n const { x, y } = this._map.project({ lng, lat });\n return { x, y };\n };\n }\n\n private _coordinatePrecision: number;\n private _map: mapboxgl.Map;\n private _onMouseMoveListener: (\n event: mapboxgl.MapMouseEvent & mapboxgl.EventData\n ) => void;\n private _onClickListener: (\n event: mapboxgl.MapMouseEvent & mapboxgl.EventData\n ) => void;\n private _onKeyPressListener: (event: KeyboardEvent) => any;\n private _rendered: boolean = false;\n\n public project: TerraDrawModeRegisterConfig[\"project\"];\n\n private _addGeoJSONSource(id: string, features: Feature[]) {\n this._map.addSource(id, {\n type: \"geojson\",\n data: {\n type: \"FeatureCollection\",\n features: features,\n },\n });\n }\n\n private _addFillLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id,\n source: id,\n type: \"fill\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"Polygon\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"fill-color\": [\"get\", \"selectedStyle\"],\n \"fill-opacity\": styling.polygonFillOpacity,\n },\n } as FillLayer);\n }\n\n private _addFillOutlineLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id: id + \"outline\",\n source: id,\n type: \"line\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"Polygon\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"line-width\": styling.polygonOutlineWidth,\n \"line-color\": [\"get\", \"selectedStyle\"],\n },\n } as LineLayer);\n }\n\n private _addLineLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id,\n source: id,\n type: \"line\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"LineString\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"line-width\": styling.lineStringWidth,\n \"line-color\": [\"get\", \"selectedStyle\"],\n },\n } as LineLayer);\n }\n\n private _addPointLayer(\n id: string,\n mode: string,\n styling: TerraDrawAdapterStyling\n ) {\n return this._map.addLayer({\n id,\n source: id,\n type: \"circle\",\n filter: [\n \"all\",\n [\"match\", [\"geometry-type\"], \"Point\", true, false],\n [\"match\", [\"get\", \"mode\"], mode, true, false],\n ],\n paint: {\n \"circle-radius\": styling.pointWidth,\n \"circle-color\": [\"get\", \"selectedStyle\"],\n },\n } as CircleLayer);\n }\n\n private _addLayer(\n id: string,\n mode: string,\n featureType: \"Point\" | \"LineString\" | \"Polygon\",\n styling: TerraDrawAdapterStyling\n ) {\n if (featureType === \"Point\") {\n this._addPointLayer(id, mode, styling);\n }\n if (featureType === \"LineString\") {\n this._addLineLayer(id, mode, styling);\n }\n if (featureType === \"Polygon\") {\n this._addFillLayer(id, mode, styling);\n this._addFillOutlineLayer(id, mode, styling);\n }\n }\n\n private _addGeoJSONLayer<T extends GeoJSONStoreGeometries>(\n mode: string,\n featureType: Feature<T>[\"geometry\"][\"type\"],\n features: Feature<T>[],\n styling: TerraDrawAdapterStyling\n ) {\n const id = `${mode}-${featureType.toLowerCase()}`;\n\n this._addGeoJSONSource(id, features);\n\n this._addLayer(id, mode, featureType, styling);\n }\n\n private _setGeoJSONLayerData<T extends GeoJSONStoreGeometries>(\n mode: string,\n featureType: Feature<T>[\"geometry\"][\"type\"],\n features: Feature<T>[]\n ) {\n const id = `${mode}-${featureType.toLowerCase()}`;\n (this._map.getSource(id) as any).setData({\n type: \"FeatureCollection\",\n features: features,\n });\n }\n register(callbacks: TerraDrawCallbacks) {\n this._onClickListener = (event) => {\n event.preventDefault();\n\n callbacks.onClick({\n lng: limitPrecision(event.lngLat.lng, this._coordinatePrecision),\n lat: limitPrecision(event.lngLat.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n this._map.on(\"click\", this._onClickListener);\n\n this._onMouseMoveListener = (event) => {\n event.preventDefault();\n\n callbacks.onMouseMove({\n lng: limitPrecision(event.lngLat.lng, this._coordinatePrecision),\n lat: limitPrecision(event.lngLat.lat, this._coordinatePrecision),\n containerX:\n event.originalEvent.clientX - this._map.getContainer().offsetLeft,\n containerY:\n event.originalEvent.clientY - this._map.getContainer().offsetTop,\n });\n };\n this._map.on(\"mousemove\", this._onMouseMoveListener);\n\n // map has no keypress event, so we add one to the canvas itself\n this._onKeyPressListener = (event: KeyboardEvent) => {\n event.preventDefault();\n\n callbacks.onKeyPress({ key: event.key });\n };\n this._map.getCanvas().addEventListener(\"keyup\", this._onKeyPressListener);\n }\n\n unregister() {\n if (this._onClickListener) {\n this._map.off(\"click\", this._onClickListener);\n this._onClickListener = undefined;\n }\n if (this._onMouseMoveListener) {\n this._map.off(\"mousemove\", this._onMouseMoveListener);\n this._onMouseMoveListener = undefined;\n }\n\n if (this._onKeyPressListener) {\n this._map\n .getCanvas()\n .removeEventListener(\"keypress\", this._onKeyPressListener);\n }\n }\n\n render(\n features: GeoJSONStoreFeatures[],\n styling: { [mode: string]: TerraDrawAdapterStyling }\n ) {\n const getFeatureOfType = <T extends GeoJSONStoreGeometries>(\n type: T[\"type\"],\n features: GeoJSONStoreFeatures[]\n ) => {\n return features.filter((f) => f.geometry.type === type) as Feature<T>[];\n };\n\n const createUpdateGeoJSONLayers = (method: \"create\" | \"update\") => {\n Object.keys(styling).forEach((mode) => {\n const styles = styling[mode];\n\n const modeFeatures = features.filter((f) => f.properties.mode === mode);\n\n const points = getFeatureOfType<Point>(\"Point\", modeFeatures);\n\n points.forEach((feature) => {\n if (feature.properties.selected) {\n feature.properties.selectedStyle = styles.selectedColor;\n } else {\n feature.properties.selectedStyle = styles.pointColor;\n }\n });\n\n const lines = getFeatureOfType<LineString>(\"LineString\", modeFeatures);\n\n lines.forEach((feature) => {\n if (feature.properties.selected) {\n feature.properties.selectedStyle = styles.selectedColor;\n } else {\n feature.properties.selectedStyle = styles.lineStringColor;\n }\n });\n\n const polygons = getFeatureOfType<Polygon>(\"Polygon\", modeFeatures);\n\n polygons.forEach((feature) => {\n if (feature.properties.selected) {\n feature.properties.selectedStyle = styles.selectedColor;\n } else {\n feature.properties.selectedStyle = styles.polygonFillColor;\n }\n });\n\n if (method === \"create\") {\n this._addGeoJSONLayer<Point>(mode, \"Point\", points, styles);\n this._addGeoJSONLayer<LineString>(mode, \"LineString\", lines, styles);\n this._addGeoJSONLayer<Polygon>(mode, \"Polygon\", polygons, styles);\n } else if (method === \"update\") {\n this._setGeoJSONLayerData<Point>(mode, \"Point\", points);\n this._setGeoJSONLayerData<LineString>(mode, \"LineString\", lines);\n this._setGeoJSONLayerData<Polygon>(mode, \"Polygon\", polygons);\n }\n });\n };\n\n if (!this._rendered) {\n createUpdateGeoJSONLayers(\"create\");\n this._rendered = true;\n } else {\n createUpdateGeoJSONLayers(\"update\");\n }\n }\n}\n","import { Feature, Polygon } from \"geojson\";\n\n// Based on Turf.js Circl module\n// https://github.com/Turfjs/turf/blob/master/packages/turf-circle/index.ts\n\nfunction degreesToRadians(degrees: number): number {\n const radians = degrees % 360;\n return (radians * Math.PI) / 180;\n}\n\nfunction lengthToRadians(distance: number): number {\n const earthRadius = 6371008.8;\n const factor = earthRadius / 1000;\n return distance / factor;\n}\n\nfunction radiansToDegrees(radians: number): number {\n const degrees = radians % (2 * Math.PI);\n return (degrees * 180) / Math.PI;\n}\n\nfunction destination(\n origin: [lng: number, lat: number],\n distance: number,\n bearing: number\n): [number, number] {\n const longitude1 = degreesToRadians(origin[0]);\n const latitude1 = degreesToRadians(origin[1]);\n const bearingRad = degreesToRadians(bearing);\n const radians = lengthToRadians(distance);\n\n // Main\n const latitude2 = Math.asin(\n Math.sin(latitude1) * Math.cos(radians) +\n Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)\n );\n const longitude2 =\n longitude1 +\n Math.atan2(\n Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),\n Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)\n );\n const lng = radiansToDegrees(longitude2);\n const lat = radiansToDegrees(latitude2);\n\n return [lng, lat];\n}\n\nexport function circle(options: {\n center: [number, number];\n radiusKilometers: number;\n steps?: number;\n}): Feature<Polygon> {\n const { center, radiusKilometers } = options;\n const steps = options.steps ? options.steps : 64;\n\n const coordinates: [number, number][] = [];\n for (let i = 0; i < steps; i++) {\n coordinates.push(destination(center, radiusKilometers, (i * -360) / steps));\n }\n coordinates.push(coordinates[0]);\n\n return {\n type: \"Feature\",\n geometry: { type: \"Polygon\", coordinates: [coordinates] },\n properties: {},\n };\n}\n","import { TerraDrawAdapterStyling } from \"../common\";\n\nexport const getDefaultStyling = (): TerraDrawAdapterStyling => {\n return {\n polygonFillColor: \"#3f97e0\",\n polygonOutlineColor: \"#3f97e0\",\n polygonOutlineWidth: 4,\n polygonFillOpacity: 0.3,\n pointColor: \"#3f97e0\",\n pointOutlineColor: \"#3f97e0\",\n pointWidth: 6,\n lineStringColor: \"#3f97e0\",\n lineStringWidth: 4,\n selectedColor: \"#26a9c8\",\n };\n};\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { circle } from \"../geometry/create-circle\";\nimport { haversineDistanceKilometers } from \"../geometry/haversine-distance\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawCircleMode implements TerraDrawMode {\n mode = \"circle\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n private center: [number, number];\n private clickCount: number = 0;\n private currentCircleId: string;\n\n constructor(options?: { styling?: Partial<TerraDrawAdapterStyling> }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.clickCount === 0) {\n this.center = [event.lng, event.lat];\n const startingCircle = circle({\n center: this.center,\n radiusKilometers: 0.00001,\n });\n\n this.currentCircleId = this.store.create(startingCircle.geometry, {\n mode: this.mode,\n });\n\n this.clickCount++;\n } else {\n // Finish drawing\n this.center = undefined;\n this.currentCircleId = undefined;\n this.clickCount = 0;\n }\n }\n onMouseMove(event: TerraDrawMouseEvent) {\n if (this.clickCount === 1) {\n const distanceKm = haversineDistanceKilometers(this.center, [\n event.lng,\n event.lat,\n ]);\n\n const updatedCircle = circle({\n center: this.center,\n radiusKilometers: distanceKm,\n });\n\n this.store.updateGeometry(this.currentCircleId, updatedCircle.geometry);\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n cleanUp() {\n try {\n this.store.delete(this.currentCircleId);\n } catch (error) {}\n this.center = undefined;\n this.currentCircleId = undefined;\n this.clickCount = 0;\n }\n}\n","export function haversineDistanceKilometers(\n pointOne: [lng: number, lat: number],\n pointTwo: [lng: number, lat: number]\n) {\n const toRadians = (latOrLng: number) => (latOrLng * Math.PI) / 180;\n\n const phiOne = toRadians(pointOne[1]);\n const lambdaOne = toRadians(pointOne[0]);\n const phiTwo = toRadians(pointTwo[1]);\n const lambdaTwo = toRadians(pointTwo[0]);\n const deltaPhi = phiTwo - phiOne;\n const deltalambda = lambdaTwo - lambdaOne;\n\n const a =\n Math.sin(deltaPhi / 2) * Math.sin(deltaPhi / 2) +\n Math.cos(phiOne) *\n Math.cos(phiTwo) *\n Math.sin(deltalambda / 2) *\n Math.sin(deltalambda / 2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\n const radius = 6371e3;\n const distance = radius * c;\n\n return distance / 1000;\n}\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { Polygon } from \"geojson\";\n\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawFreehandMode implements TerraDrawMode {\n mode = \"freehand\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n\n private startingClick = false;\n private currentId: string;\n\n private skip: number = 0;\n private everyNthMouseEvent: number;\n\n constructor(options?: {\n styling?: Partial<TerraDrawAdapterStyling>;\n everyNthMouseEvent?: number;\n }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n this.everyNthMouseEvent = (options && options.everyNthMouseEvent) || 10;\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onMouseMove(event: TerraDrawMouseEvent) {\n if (!this.currentId || this.startingClick === false) {\n return;\n }\n\n if (this.skip > this.everyNthMouseEvent) {\n this.skip = 0;\n const currentLineGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n currentLineGeometry.coordinates[0].pop();\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [\n [\n ...currentLineGeometry.coordinates[0],\n [event.lng, event.lat],\n currentLineGeometry.coordinates[0][0],\n ],\n ],\n });\n }\n\n this.skip++;\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.startingClick === false) {\n this.currentId = this.store.create(\n {\n type: \"Polygon\",\n coordinates: [\n [\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n ],\n ],\n },\n { mode: this.mode }\n );\n\n this.startingClick = true;\n return;\n }\n\n this.startingClick = false;\n this.currentId = undefined;\n }\n\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n\n cleanUp() {\n try {\n this.store.delete(this.currentId);\n } catch (error) {}\n this.currentId = undefined;\n this.startingClick = false;\n }\n}\n","import { Feature, LineString, Polygon } from \"geojson\";\n// import * as rbush from \"rbush\";\n\ntype SelfIntersectsOptions = {\n epsilon: number;\n // reportVertexOnVertex: boolean;\n // reportVertexOnEdge: boolean;\n};\n\nexport function selfIntersects(\n feature: Feature<Polygon> | Feature<LineString>\n): boolean {\n let options: SelfIntersectsOptions = {\n epsilon: 0,\n // reportVertexOnVertex: false,\n // reportVertexOnEdge: false,\n };\n\n let coord: number[][][];\n\n if (feature.geometry.type === \"Polygon\") {\n coord = feature.geometry.coordinates;\n } else if (feature.geometry.type === \"LineString\") {\n coord = [feature.geometry.coordinates];\n }\n\n var output: number[][] = [];\n var seen: { [key: string]: boolean } = {};\n\n for (let ring0 = 0; ring0 < coord.length; ring0++) {\n for (let edge0 = 0; edge0 < coord[ring0].length - 1; edge0++) {\n for (let ring1 = 0; ring1 < coord.length; ring1++) {\n for (let edge1 = 0; edge1 < coord[ring1].length - 1; edge1++) {\n // TODO: speedup possible if only interested in unique: start last two loops at ring0 and edge0+1\n ifInteresctionAddToOutput(ring0, edge0, ring1, edge1);\n }\n }\n }\n }\n\n return output.length > 0;\n\n // true if frac is (almost) 1.0 or 0.0\n // function isBoundaryCase(frac: number) {\n // const e2 = options.epsilon * options.epsilon;\n // return e2 >= (frac - 1) * (frac - 1) || e2 >= frac * frac;\n // }\n\n function isOutside(frac: number) {\n return frac < 0 - options.epsilon || frac > 1 + options.epsilon;\n }\n // Function to check if two edges intersect and add the intersection to the output\n function ifInteresctionAddToOutput(\n ring0: number,\n edge0: number,\n ring1: number,\n edge1: number\n ) {\n const start0 = coord[ring0][edge0] as [number, number];\n const end0 = coord[ring0][edge0 + 1] as [number, number];\n const start1 = coord[ring1][edge1] as [number, number];\n const end1 = coord[ring1][edge1 + 1] as [number, number];\n\n const intersection = intersect(start0, end0, start1, end1);\n\n if (intersection === null) {\n return; // discard parallels and coincidence\n }\n\n let frac0;\n let frac1;\n\n if (end0[0] !== start0[0]) {\n frac0 = (intersection[0] - start0[0]) / (end0[0] - start0[0]);\n } else {\n frac0 = (intersection[1] - start0[1]) / (end0[1] - start0[1]);\n }\n if (end1[0] !== start1[0]) {\n frac1 = (intersection[0] - start1[0]) / (end1[0] - start1[0]);\n } else {\n frac1 = (intersection[1] - start1[1]) / (end1[1] - start1[1]);\n }\n\n // There are roughly three cases we need to deal with.\n // 1. If at least one of the fracs lies outside [0,1], there is no intersection.\n if (isOutside(frac0) || isOutside(frac1)) {\n return; // require segment intersection\n }\n\n // 2. If both are either exactly 0 or exactly 1, this is not an intersection but just\n // two edge segments sharing a common vertex.\n // if (isBoundaryCase(frac0) && isBoundaryCase(frac1)) {\n // if (!options.reportVertexOnVertex) {\n // return;\n // }\n // }\n\n // // 3. If only one of the fractions is exactly 0 or 1, this is\n // // a vertex-on-edge situation.\n // if (isBoundaryCase(frac0) || isBoundaryCase(frac1)) {\n // if (!options.reportVertexOnEdge) {\n // return;\n // }\n // }\n\n var key = intersection.toString();\n var unique = !seen[key];\n if (unique) {\n seen[key] = true;\n }\n\n output.push(intersection);\n }\n}\n\nfunction equalArrays(array1: [number, number], array2: [number, number]) {\n return array1[0] === array2[0] && array1[1] === array2[1];\n}\n\n// Function to compute where two lines (not segments) intersect. From https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection\nfunction intersect(\n start0: [number, number],\n end0: [number, number],\n start1: [number, number],\n end1: [number, number]\n) {\n if (\n equalArrays(start0, start1) ||\n equalArrays(start0, end1) ||\n equalArrays(end0, start1) ||\n equalArrays(end1, start1)\n ) {\n return null;\n }\n\n let x0 = start0[0],\n y0 = start0[1],\n x1 = end0[0],\n y1 = end0[1],\n x2 = start1[0],\n y2 = start1[1],\n x3 = end1[0],\n y3 = end1[1];\n\n const denom = (x0 - x1) * (y2 - y3) - (y0 - y1) * (x2 - x3);\n if (denom === 0) {\n return null;\n }\n\n const x4 =\n ((x0 * y1 - y0 * x1) * (x2 - x3) - (x0 - x1) * (x2 * y3 - y2 * x3)) / denom;\n\n const y4 =\n ((x0 * y1 - y0 * x1) * (y2 - y3) - (y0 - y1) * (x2 * y3 - y2 * x3)) / denom;\n\n return [x4, y4];\n}\n","export const getPixelDistance = (\n pointOne: { x: number; y: number },\n pointTwo: { x: number; y: number }\n) => {\n const { x: x1, y: y1 } = pointOne;\n const { x: x2, y: y2 } = pointTwo;\n const y = x2 - x1;\n const x = y2 - y1;\n return Math.sqrt(x * x + y * y);\n};\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { LineString } from \"geojson\";\nimport { selfIntersects } from \"../geometry/self-intersects\";\nimport { getPixelDistance } from \"../geometry/get-pixel-distance\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawLineStringMode implements TerraDrawMode {\n public mode = \"linestring\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n private pointerDistance: number;\n\n private currentCoordinate = 0;\n private currentId: string;\n private allowSelfIntersections;\n\n constructor(options?: {\n allowSelfIntersections?: boolean;\n styling?: Partial<TerraDrawAdapterStyling>;\n pointerDistance?: number;\n }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n\n this.pointerDistance = (options && options.pointerDistance) || 40;\n\n this.allowSelfIntersections =\n options && options.allowSelfIntersections !== undefined\n ? options.allowSelfIntersections\n : true;\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onMouseMove(event: TerraDrawMouseEvent) {\n if (!this.currentId || this.currentCoordinate === 0) {\n return;\n }\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n // Remove the 'live' point that changes on mouse move\n currentLineGeometry.coordinates.pop();\n\n // Update the 'live' point\n this.store.updateGeometry(this.currentId, {\n type: \"LineString\",\n coordinates: [...currentLineGeometry.coordinates, [event.lng, event.lat]],\n });\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.currentCoordinate === 0) {\n this.currentId = this.store.create(\n {\n type: \"LineString\",\n coordinates: [\n [event.lng, event.lat],\n [event.lng, event.lat], // This is the 'live' point that changes on mouse move\n ],\n },\n { mode: this.mode }\n );\n this.currentCoordinate++;\n } else if (this.currentCoordinate === 1) {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n this.store.updateGeometry(this.currentId, {\n type: \"LineString\",\n coordinates: [\n currentLineGeometry.coordinates[0],\n [event.lng, event.lat],\n [event.lng, event.lat],\n ],\n });\n\n this.currentCoordinate++;\n } else {\n const currentLineGeometry = this.store.getGeometryCopy<LineString>(\n this.currentId\n );\n\n const [previousLng, previousLat] = currentLineGeometry.coordinates[\n currentLineGeometry.coordinates.length - 2\n ];\n const { x, y } = this.project(previousLng, previousLat);\n const distance = getPixelDistance(\n { x, y },\n { x: event.containerX, y: event.containerY }\n );\n\n const isClosingClick = distance < this.pointerDistance;\n\n if (isClosingClick) {\n // Finish off the drawing\n currentLineGeometry.coordinates.pop();\n this.store.updateGeometry(this.currentId, {\n type: \"LineString\",\n coordinates: [...currentLineGeometry.coordinates],\n });\n\n this.currentCoordinate = 0;\n this.currentId = undefined;\n } else {\n // If not close to the final point, keep adding points\n const newLineString = {\n type: \"LineString\",\n coordinates: [\n ...currentLineGeometry.coordinates,\n [event.lng, event.lat],\n ],\n } as LineString;\n\n if (!this.allowSelfIntersections) {\n const hasSelfIntersections = selfIntersects({\n type: \"Feature\",\n geometry: newLineString,\n properties: {},\n });\n\n if (hasSelfIntersections) {\n return;\n }\n }\n\n this.store.updateGeometry(this.currentId, newLineString);\n this.currentCoordinate++;\n }\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n cleanUp() {\n try {\n this.store.delete(this.currentId);\n } catch (error) {}\n\n this.currentId = undefined;\n this.currentCoordinate = 0;\n }\n}\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawPointMode implements TerraDrawMode {\n mode = \"point\";\n\n private store: GeoJSONStore;\n\n constructor(options?: { styling?: Partial<TerraDrawAdapterStyling> }) {\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (!this.store) {\n throw new Error(\"Mode must be registered first\");\n }\n\n this.store.create(\n {\n type: \"Point\",\n coordinates: [event.lng, event.lat],\n },\n { mode: this.mode }\n );\n }\n onMouseMove() {}\n onKeyPress() {}\n cleanUp() {}\n}\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawAdapterStyling,\n TerraDrawKeyboardEvent,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { Polygon } from \"geojson\";\nimport { getPixelDistance } from \"../geometry/get-pixel-distance\";\nimport { selfIntersects } from \"../geometry/self-intersects\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawPolygonMode implements TerraDrawMode {\n mode = \"polygon\";\n\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n\n private currentCoordinate = 0;\n private currentId: string;\n private allowSelfIntersections: boolean;\n private pointerDistance: number;\n\n constructor(options?: {\n allowSelfIntersections?: boolean;\n styling?: Partial<TerraDrawAdapterStyling>;\n pointerDistance?: number;\n }) {\n this.pointerDistance = (options && options.pointerDistance) || 40;\n\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n\n this.allowSelfIntersections =\n options && options.allowSelfIntersections !== undefined\n ? options.allowSelfIntersections\n : true;\n }\n\n styling: TerraDrawAdapterStyling;\n\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n }\n\n onMouseMove(event: TerraDrawMouseEvent) {\n if (!this.currentId || this.currentCoordinate === 0) {\n return;\n }\n\n const currentLineCoordinates = this.store.getGeometryCopy<Polygon>(\n this.currentId\n ).coordinates[0];\n\n let updatedCoordinates;\n\n if (this.currentCoordinate === 1) {\n updatedCoordinates = [\n currentLineCoordinates[0],\n [event.lng, event.lat],\n currentLineCoordinates[0],\n currentLineCoordinates[0],\n ];\n } else if (this.currentCoordinate === 2) {\n updatedCoordinates = [\n currentLineCoordinates[0],\n currentLineCoordinates[1],\n [event.lng, event.lat],\n currentLineCoordinates[0],\n ];\n } else {\n updatedCoordinates = [\n ...currentLineCoordinates.slice(0, -2),\n [event.lng, event.lat],\n currentLineCoordinates[0],\n ];\n }\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [updatedCoordinates],\n });\n }\n\n onClick(event: TerraDrawMouseEvent) {\n if (this.currentCoordinate === 0) {\n this.currentId = this.store.create(\n {\n type: \"Polygon\",\n coordinates: [\n [\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n [event.lng, event.lat],\n ],\n ],\n },\n { mode: this.mode }\n );\n\n this.currentCoordinate++;\n } else if (this.currentCoordinate === 1) {\n const currentPolygonGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [\n [\n currentPolygonGeometry.coordinates[0][0],\n [event.lng, event.lat],\n [event.lng, event.lat],\n currentPolygonGeometry.coordinates[0][0],\n ],\n ],\n });\n\n this.currentCoordinate++;\n } else if (this.currentCoordinate === 2) {\n const currentPolygonGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n this.store.updateGeometry(this.currentId, {\n type: \"Polygon\",\n coordinates: [\n [\n currentPolygonGeometry.coordinates[0][0],\n currentPolygonGeometry.coordinates[0][1],\n [event.lng, event.lat],\n [event.lng, event.lat],\n currentPolygonGeometry.coordinates[0][0],\n ],\n ],\n });\n this.currentCoordinate++;\n } else {\n const currentPolygonGeometry = this.store.getGeometryCopy<Polygon>(\n this.currentId\n );\n\n const [firstLng, firstLat] = currentPolygonGeometry.coordinates[0][0];\n const { x, y } = this.project(firstLng, firstLat);\n const distance = getPixelDistance(\n { x, y },\n { x: event.containerX, y: event.containerY }\n );\n\n console.log(distance, this.pointerDistance);\n\n const isClosingClick = distance < this.pointerDistance;\n\n if (isClosingClick) {\n this.currentCoordinate = 0;\n this.currentId = undefined;\n } else {\n const newPolygon = {\n type: \"Polygon\",\n coordinates: [\n [\n ...currentPolygonGeometry.coordinates[0].slice(0, -1),\n [event.lng, event.lat],\n currentPolygonGeometry.coordinates[0][0],\n ],\n ],\n } as Polygon;\n\n if (this.currentCoordinate > 2 && !this.allowSelfIntersections) {\n const hasSelfIntersections = selfIntersects({\n type: \"Feature\",\n geometry: newPolygon,\n properties: {},\n });\n\n if (hasSelfIntersections) {\n this.store.updateGeometry(this.currentId, currentPolygonGeometry);\n return;\n }\n }\n\n console.log(newPolygon);\n\n // If not close to the final point, keep adding points\n this.store.updateGeometry(this.currentId, newPolygon);\n this.currentCoordinate++;\n }\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n\n cleanUp() {\n try {\n this.store.delete(this.currentId);\n } catch (error) {}\n this.currentId = undefined;\n this.currentCoordinate = 0;\n }\n}\n","// Based on which-polygon\n// https://github.com/mapbox/which-polygon/blob/2eb5b8a427d018ebd964c05acd3b9166c4558b2c/index.js#L81\nexport function pointInPolygon(\n point: [number, number],\n rings: [number, number][][]\n) {\n let inside = false;\n for (let i = 0, len = rings.length; i < len; i++) {\n const ring = rings[i];\n for (let j = 0, len2 = ring.length, k = len2 - 1; j < len2; k = j++) {\n if (rayIntersect(point, ring[j], ring[k])) {\n inside = !inside;\n }\n }\n }\n return inside;\n}\n\nfunction rayIntersect(\n p: [number, number],\n p1: [number, number],\n p2: [number, number]\n) {\n return (\n p1[1] > p[1] !== p2[1] > p[1] &&\n p[0] < ((p2[0] - p1[0]) * (p[1] - p1[1])) / (p2[1] - p1[1]) + p1[0]\n );\n}\n","export const getPixelDistanceToLine = (\n point: { x: number; y: number },\n linePointOne: { x: number; y: number },\n linePointTwo: { x: number; y: number }\n) => {\n const square = (x: number) => {\n return x * x;\n };\n const dist2 = (v: { x: number; y: number }, w: { x: number; y: number }) => {\n return square(v.x - w.x) + square(v.y - w.y);\n };\n const distToSegmentSquared = (\n p: { x: number; y: number },\n v: { x: number; y: number },\n w: { x: number; y: number }\n ) => {\n const l2 = dist2(v, w);\n\n if (l2 === 0) {\n return dist2(p, v);\n }\n\n let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;\n t = Math.max(0, Math.min(1, t));\n\n return dist2(p, { x: v.x + t * (w.x - v.x), y: v.y + t * (w.y - v.y) });\n };\n\n return Math.sqrt(distToSegmentSquared(point, linePointOne, linePointTwo));\n};\n","import {\n TerraDrawMouseEvent,\n TerraDrawMode,\n TerraDrawModeRegisterConfig,\n TerraDrawKeyboardEvent,\n TerraDrawAdapterStyling,\n} from \"../common\";\nimport { GeoJSONStore } from \"../store/store\";\nimport { pointInPolygon } from \"../geometry/point-in-polygon\";\nimport { getPixelDistance } from \"../geometry/get-pixel-distance\";\nimport { getPixelDistanceToLine } from \"../geometry/get-pixel-distance-to-line\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawSelectMode implements TerraDrawMode {\n mode = \"select\";\n private store: GeoJSONStore;\n private project: TerraDrawModeRegisterConfig[\"project\"];\n private selected: string[] = [];\n private pointerDistance: number;\n\n constructor(options?: {\n styling?: Partial<TerraDrawAdapterStyling>;\n pointerDistance?: number;\n }) {\n this.pointerDistance = (options && options.pointerDistance) || 40;\n\n this.styling =\n options && options.styling\n ? { ...getDefaultStyling(), ...options.styling }\n : getDefaultStyling();\n }\n\n styling: TerraDrawAdapterStyling;\n\n onClick(event: TerraDrawMouseEvent) {\n const features = this.store.copyAll();\n\n let clickedFeatureId: string;\n let clickedFeatureDistance = Infinity;\n\n for (let i = 0; i < features.length; i++) {\n const feature = features[i];\n const geometry = feature.geometry;\n\n if (geometry.type === \"Point\") {\n const { x, y } = this.project(\n geometry.coordinates[0],\n geometry.coordinates[1]\n );\n const distance = getPixelDistance(\n { x, y },\n { x: event.containerX, y: event.containerY }\n );\n if (\n distance < this.pointerDistance &&\n distance < clickedFeatureDistance\n ) {\n clickedFeatureDistance = distance;\n clickedFeatureId = feature.id as string;\n }\n } else if (geometry.type === \"LineString\") {\n for (let i = 0; i < geometry.coordinates.length - 1; i++) {\n const coord = geometry.coordinates[i];\n const nextCoord = geometry.coordinates[i + 1];\n const distanceToLine = getPixelDistanceToLine(\n { x: event.containerX, y: event.containerY },\n this.project(coord[0], coord[1]),\n this.project(nextCoord[0], nextCoord[1])\n );\n\n if (\n distanceToLine < this.pointerDistance &&\n distanceToLine < clickedFeatureDistance\n ) {\n clickedFeatureDistance = distanceToLine;\n clickedFeatureId = feature.id as string;\n }\n }\n } else if (geometry.type === \"Polygon\") {\n const clickInsidePolygon = pointInPolygon(\n [event.lng, event.lat],\n geometry.coordinates as [number, number][][]\n );\n\n if (clickInsidePolygon) {\n clickedFeatureDistance = 0;\n clickedFeatureId = feature.id as string;\n }\n }\n }\n\n if (clickedFeatureId) {\n // TODO: Handle multi select?\n this.selected = [clickedFeatureId];\n this.onSelect(clickedFeatureId);\n } else if (this.selected.length) {\n this.selected = [];\n this.onDeselect();\n }\n }\n onKeyPress(event: TerraDrawKeyboardEvent) {\n if (event.key === \"Delete\") {\n if (!this.selected.length) {\n return;\n }\n // Delete all selected features\n // from the store and clear selected\n this.selected.forEach((id) => {\n this.store.delete(id);\n });\n this.selected = [];\n\n // We are technically deselecting\n // because the selected feature\n // no longer exists\n this.onDeselect();\n } else if (event.key === \"Escape\") {\n this.cleanUp();\n }\n }\n cleanUp() {\n if (this.selected.length) {\n this.onDeselect();\n }\n\n this.selected = [];\n }\n onMouseMove() {}\n register(config: TerraDrawModeRegisterConfig) {\n this.store = config.store;\n this.store.registerOnChange(config.onChange);\n this.project = config.project;\n this.onSelect = config.onSelect;\n this.onDeselect = config.onDeselect;\n }\n onDeselect() {}\n onSelect(selectedId: string) {}\n}\n","import { TerraDrawAdapterStyling, TerraDrawMode } from \"../common\";\nimport { getDefaultStyling } from \"../util/styling\";\n\nexport class TerraDrawStaticMode implements TerraDrawMode {\n mode = \"static\";\n styling: TerraDrawAdapterStyling = getDefaultStyling();\n register() {}\n onKeyPress() {}\n onClick() {}\n onMouseMove() {}\n cleanUp() {}\n}\n","import { Feature, Point, Polygon, LineString } from \"geojson\";\nimport { uuid4 } from \"../util/id\";\n\ntype JSON = string | number | boolean | null | JSONArray | JSONObject;\n\ninterface JSONObject {\n [member: string]: JSON;\n}\ninterface JSONArray extends Array<JSON> {}\n\nexport type GeoJSONStoreGeometries = Polygon | LineString | Point;\n\nexport type GeoJSONStoreFeatures = Feature<GeoJSONStoreGeometries>;\n\nexport type StoreChangeEvents = \"delete\" | \"create\" | \"update\";\n\nexport type StoreChangeHandler = (\n id: string,\n change: StoreChangeEvents\n) => void;\n\nexport class GeoJSONStore {\n constructor(config?: { data: GeoJSONStoreFeatures[] }) {\n this.store = {};\n\n if (config && config.data) {\n config.data.forEach((feature) => {\n this.featureValidation(feature);\n this.store[feature.id] = feature;\n });\n }\n }\n\n private featureValidation(feature: any) {\n if (!feature || !feature.id) {\n throw new Error(\"Feature has no id\");\n } else if (typeof feature.id !== \"string\" || feature.id.length !== 36) {\n throw new Error(`Feature must have uuid4 ID ${feature.id}`);\n } else if (!feature.geometry) {\n throw new Error(\"Feature has no geometry\");\n } else if (!feature.properties) {\n throw new Error(\"Feature has no properties\");\n } else if (\n ![\"Polygon\", \"LineString\", \"Point\"].includes(feature.geometry.type)\n ) {\n throw new Error(\"Feature is not Point, LineString or Polygon\");\n } else if (!Array.isArray(feature.geometry.coordinates)) {\n throw new Error(\"Feature coordinates is not an array\");\n }\n }\n\n private store: {\n [key: string]: GeoJSONStoreFeatures;\n };\n\n private _onChange: StoreChangeHandler;\n\n private getId(): string {\n return uuid4();\n }\n\n registerOnChange(onChange: StoreChangeHandler) {\n this._onChange = (id, change) => {\n onChange(id, change);\n };\n }\n\n updateGeometry(id: string, geometry: GeoJSONStoreGeometries): string {\n const feature = this.store[id];\n\n if (!feature) {\n throw new Error(\"No feature with this id, can not update geometry\");\n }\n\n feature.geometry = JSON.parse(JSON.stringify(geometry));\n\n if (this._onChange) {\n this._onChange(id, \"update\");\n }\n\n return id;\n }\n\n getGeometryCopy<T>(id: string): T {\n const feature = this.store[id];\n if (!feature) {\n throw new Error(\"No feature with this id, can not get geometry copy\");\n }\n return JSON.parse(JSON.stringify(feature.geometry));\n }\n\n create(geometry: GeoJSONStoreGeometries, properties: JSON = {}): string {\n const id = this.getId();\n const feature = {\n id,\n type: \"Feature\",\n geometry,\n properties,\n } as GeoJSONStoreFeatures;\n\n this.store[id] = feature;\n\n if (this._onChange) {\n this._onChange(id, \"create\");\n }\n\n return id;\n }\n\n delete(id: string): void {\n if (this.store[id]) {\n delete this.store[id];\n if (this._onChange) {\n this._onChange(id, \"delete\");\n }\n } else {\n throw new Error(\"No feature with this id, can not delete\");\n }\n }\n\n copyAll(): GeoJSONStoreFeatures[] {\n return JSON.parse(\n JSON.stringify(Object.keys(this.store).map((id) => this.store[id]))\n );\n }\n}\n","export const uuid4 = function (): string {\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {\n var r = (Math.random() * 16) | 0,\n v = c == \"x\" ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n","import { FeatureCollection, LineString, Point, Polygon } from \"geojson\";\nimport { flattenDiagnosticMessageText } from \"typescript\";\nimport { TerraDrawGoogleMapsAdapter } from \"./adapters/google-maps.adapter\";\nimport { TerraDrawLeafletAdapter } from \"./adapters/leaflet.adapter\";\nimport { TerraDrawMapboxGLAdapter } from \"./adapters/mapbox-gl.adapter\";\nimport {\n TerraDrawMode,\n TerraDrawAdapter,\n TerraDrawAdapterStyling,\n} from \"./common\";\nimport { TerraDrawCircleMode } from \"./modes/circle.mode\";\nimport { TerraDrawFreehandMode } from \"./modes/freehand.mode\";\nimport { TerraDrawLineStringMode } from \"./modes/line-string.mode\";\nimport { TerraDrawPointMode } from \"./modes/point.mode\";\nimport { TerraDrawPolygonMode } from \"./modes/polygon.mode\";\nimport { TerraDrawSelectMode } from \"./modes/select.mode\";\nimport { TerraDrawStaticMode } from \"./modes/static.mode\";\nimport {\n GeoJSONStore,\n GeoJSONStoreFeatures,\n GeoJSONStoreGeometries,\n StoreChangeHandler,\n} from \"./store/store\";\n\ntype ChangeListener = (id: string, type: string) => void;\ntype SelectListener = (id: string) => void;\ntype DeselectListener = () => void;\n\ninterface TerraDrawEventListeners {\n change: ChangeListener;\n select: SelectListener;\n deselect: DeselectListener;\n}\n\ntype TerraDrawEvents = keyof TerraDrawEventListeners;\n\nclass TerraDraw {\n private _modes: { [mode: string]: TerraDrawMode };\n private _mode: TerraDrawMode;\n private _adapter: TerraDrawAdapter;\n private _enabled = false;\n private _store: GeoJSONStore;\n private _eventListeners: {\n change: ChangeListener[];\n select: SelectListener[];\n deselect: DeselectListener[];\n };\n constructor(options: {\n adapter: TerraDrawAdapter;\n modes: { [mode: string]: TerraDrawMode };\n data?: GeoJSONStoreFeatures[];\n }) {\n this._adapter = options.adapter;\n this._mode = new TerraDrawStaticMode();\n this._modes = { ...options.modes, static: this._mode };\n this._eventListeners = { change: [], select: [], deselect: [] };\n\n if (options.data) {\n this._store = new GeoJSONStore({ data: options.data });\n\n // Remove all non mode features\n const initialRender = this._store.copyAll().filter((feature) => {\n if (!Object.keys(this._modes).includes(feature.properties.mode)) {\n this._store.delete(feature.id as string);\n return false;\n }\n return true;\n });\n\n this._adapter.render(initialRender, this.getModeStyles());\n } else {\n this._store = new GeoJSONStore();\n }\n\n // Register stores and callbacks\n Object.keys(this._modes).forEach((modeId) => {\n const onChange: StoreChangeHandler = (id, event) => {\n this._eventListeners.change.forEach((listener) => {\n listener(id, event);\n });\n this._adapter.render(this._store.copyAll(), this.getModeStyles());\n };\n\n const onSelect = (selectedId: string) => {\n this._eventListeners.select.forEach((listener) => {\n listener(selectedId);\n });\n\n const features = this._store.copyAll();\n features.forEach((feature) => {\n if (feature.id === selectedId) {\n feature.properties.selected = true;\n }\n });\n this._adapter.render(features, this.getModeStyles());\n };\n\n const onDeselect = () => {\n this._eventListeners.deselect.forEach((listener) => {\n listener();\n });\n\n const features = this._store.copyAll();\n this._adapter.render(features, this.getModeStyles());\n };\n\n this._modes[modeId].register({\n store: this._store,\n project: this._adapter.project,\n onChange: onChange,\n onSelect: onSelect,\n onDeselect: onDeselect,\n });\n });\n }\n\n private getModeStyles() {\n const modeStyles: { [key: string]: TerraDrawAdapterStyling } = {};\n Object.keys(this._modes).forEach((mode) => {\n modeStyles[mode] = this._modes[mode].styling;\n });\n return modeStyles;\n }\n\n getSnapshot() {\n return this._store.copyAll();\n }\n\n get enabled() {\n return this._enabled;\n }\n\n changeMode(mode: string) {\n if (this._modes[mode]) {\n // Before we swap modes we want to\n // clean up any state that has been left behind,\n // for example current drawing geometries\n // and mode state\n this._mode.cleanUp();\n\n // Swap the mode to the new mode\n this._mode = this._modes[mode];\n } else {\n // If the mode doesn't exist, we throw an error\n throw new Error(\"No mode with this name present\");\n }\n }\n\n start() {\n this._enabled = true;\n this._adapter.register({\n onClick: (event) => {\n this._mode.onClick(event);\n },\n onMouseMove: (event) => {\n this._mode.onMouseMove(event);\n },\n onKeyPress: (event) => {\n this._mode.onKeyPress(event);\n },\n });\n }\n\n stop() {\n this._enabled = false;\n this._adapter.unregister();\n }\n\n on<T extends TerraDrawEvents>(\n event: T,\n callback: TerraDrawEventListeners[T]\n ) {\n const listeners = this._eventListeners[\n event\n ] as TerraDrawEventListeners[T][];\n if (!listeners.includes(callback)) {\n listeners.push(callback);\n }\n }\n\n off<T extends TerraDrawEvents>(\n event: TerraDrawEvents,\n callback: TerraDrawEventListeners[T]\n ) {\n const listeners = this._eventListeners[\n event\n ] as TerraDrawEventListeners[T][];\n if (listeners.includes(callback)) {\n listeners.splice(listeners.indexOf(callback), 1);\n }\n }\n}\n\nexport {\n TerraDraw,\n TerraDrawSelectMode,\n TerraDrawPointMode,\n TerraDrawLineStringMode,\n TerraDrawPolygonMode,\n TerraDrawCircleMode,\n TerraDrawFreehandMode,\n TerraDrawGoogleMapsAdapter,\n TerraDrawMapboxGLAdapter,\n TerraDrawLeafletAdapter,\n};\n"],"names":["limitPrecision","num","decimalLimit","decimals","Math","pow","round","TerraDrawGoogleMapsAdapter","config","_this","this","_coordinatePrecision","_lib","_map","_onMouseMoveListener","_onMouseMoveCallback","_onClickListener","_onClickCallback","_onKeyUpListener","_layers","project","lib","map","coordinatePrecision","lng","lat","bounds","getBounds","northWest","LatLng","getNorthEast","getSouthWest","getProjection","projectedNorthWest","projection","fromLatLngToPoint","scale","getZoom","x","floor","projected","y","_proto","prototype","circlePath","cx","cy","r","register","callbacks","_this2","event","onClick","latLng","containerX","domEvent","clientX","getDiv","offsetLeft","containerY","clientY","offsetTop","addListener","onMouseMove","onKeyPress","key","addEventListener","unregister","undefined","remove","removeEventListener","render","features","styling","_this3","data","forEach","layer","console","log","addGeoJson","type","setStyle","feature","mode","getProperty","getGeometry","getType","selected","icon","path","pointWidth","fillColor","selectedColor","pointColor","fillOpacity","strokeWeight","rotation","strokeColor","lineStringColor","lineStringWidth","polygonOutlineColor","polygonOutlineWidth","polygonFillOpacity","polygonFillColor","TerraDrawLeafletAdapter","_onKeyPressListener","_layer","_this$_map$latLngToCo","latLngToContainerPoint","originalEvent","preventDefault","latlng","getContainer","on","off","removeLayer","geoJSON","pointToLayer","modeStyle","properties","circleMarker","radius","color","pointOutlineColor","weight","opacity","style","geometry","addTo","TerraDrawMapboxGLAdapter","_rendered","_this$_map$project","_addGeoJSONSource","id","addSource","_addFillLayer","addLayer","source","filter","paint","_addFillOutlineLayer","_addLineLayer","_addPointLayer","_addLayer","featureType","_addGeoJSONLayer","toLowerCase","_setGeoJSONLayerData","getSource","setData","lngLat","getCanvas","getFeatureOfType","f","createUpdateGeoJSONLayers","method","Object","keys","styles","modeFeatures","points","selectedStyle","lines","polygons","degrees","PI","radiansToDegrees","radians","circle","options","origin","distance","bearing","longitude1","latitude1","bearingRad","latitude2","center","radiusKilometers","steps","coordinates","i","push","degreesToRadians","earthRadius","lengthToRadians","asin","sin","cos","atan2","TerraDrawCircleMode","store","clickCount","currentCircleId","getDefaultStyling","registerOnChange","onChange","startingCircle","create","distanceKm","pointTwo","phiOne","toRadians","latOrLng","pointOne","lambdaOne","deltaPhi","phiTwo","a","deltalambda","sqrt","updatedCircle","updateGeometry","cleanUp","error","TerraDrawFreehandMode","startingClick","currentId","skip","everyNthMouseEvent","currentLineGeometry","getGeometryCopy","pop","concat","selfIntersects","coord","ring0","length","edge0","ring1","edge1","ifInteresctionAddToOutput","output","isOutside","frac","frac1","start1","end1","start0","end0","equalArrays","x0","y0","x1","y1","x2","y2","x3","y3","denom","intersect","intersection","toString","array1","array2","getPixelDistance","TerraDrawLineStringMode","pointerDistance","currentCoordinate","allowSelfIntersections","_currentLineGeometry$","_this$project","previousLat","newLineString","TerraDrawPointMode","_extends","Error","TerraDrawPolygonMode","updatedCoordinates","currentLineCoordinates","slice","currentPolygonGeometry","_currentPolygonGeometry","_currentPolygonGeomet","newPolygon","pointInPolygon","point","rings","p","p1","p2","inside","len","j","len2","ring","k","linePointOne","linePointTwo","square","dist2","v","w","l2","t","max","min","distToSegmentSquared","TerraDrawSelectMode","clickedFeatureId","copyAll","Infinity","clickedFeatureDistance","nextCoord","distanceToLine","getPixelDistanceToLine","onSelect","onDeselect","selectedId","TerraDrawStaticMode","GeoJSONStore","_onChange","featureValidation","includes","Array","isArray","getId","replace","c","random","change","JSON","parse","stringify","TerraDraw","_modes","_mode","_adapter","_enabled","_store","_eventListeners","adapter","modes","static","select","deselect","initialRender","getModeStyles","modeId","listener","modeStyles","getSnapshot","changeMode","start","stop","callback","listeners","splice","indexOf"],"mappings":"oOAAgBA,SAAAA,EAAeC,EAAaC,YAAAA,IAAAA,EAAe,GACzD,IAAcC,EAAGC,KAAKC,IAAI,GAAIH,GAC9B,OAAWE,KAACE,MAAML,EAAME,GAAYA,ECQzBI,IAAbA,eAAA,WACE,SAAYC,EAAAA,GAIX,IAAAC,EAAAC,KAAAA,KA0BOC,0BACAC,EAAAA,KAAAA,UACAC,EAAAA,KAAAA,UACAC,EAAAA,KAAAA,iCACAC,0BA9BP,EAAAL,KAmCOM,sBAnCP,EAAAN,KAoCOO,sBApCP,EAAAP,KAyCOQ,sBACAC,EAAAA,KAAAA,oBAEDC,aA5CN,EACCV,KAAKE,KAAOJ,EAAOa,IACnBX,KAAKG,KAAOL,EAAOc,IACnBZ,KAAKC,qBACmC,iBAA/BH,EAAOe,oBACVf,EAAOe,oBACP,EAENb,KAAKU,QAAU,SAACI,EAAaC,GAC3B,IAAMC,EAASjB,EAAKI,KAAKc,YACnBC,EAAY,IAAInB,EAAKG,KAAKiB,OAC9BH,EAAOI,eAAeL,MACtBC,EAAOK,eAAeP,SAELf,EAAKI,KAAKmB,gBACvBC,EAAqBC,EAAWC,kBAAkBP,KACtCM,EAAWC,kBAAkB,CAAEX,IAAAA,EAAKC,IAAAA,IAE3CW,EAAGhC,K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P,MAAMxQ,YAAYZ,IAEzBa,WAAY,SAACb,GACXuB,EAAK6P,MAAMvQ,WAAWb,SAK5BsS,KAAA,WACE/U,KAAK+T,UAAW,EAChB/T,KAAK8T,SAASrQ,cAGhB+C,EAAAA,GAAA,SACE/D,EACAuS,GAEA,IAAMC,EAAYjV,KAAKiU,gBACrBxR,GAEGwS,EAAUjC,SAASgC,IACtBC,EAAUpK,KAAKmK,MAInBvO,IAAA,SACEhE,EACAuS,GAEA,IAAMC,EAAYjV,KAAKiU,gBACrBxR,GAEEwS,EAAUjC,SAASgC,IACrBC,EAAUC,OAAOD,EAAUE,QAAQH,GAAW,+BA5DlD,WACE,OAAYjB,KAAAA,uPAlFd"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TerraDrawGoogleMapsAdapter } from "./adapters/google-maps.adapter";
|
|
2
|
+
import { TerraDrawLeafletAdapter } from "./adapters/leaflet.adapter";
|
|
3
|
+
import { TerraDrawMapboxGLAdapter } from "./adapters/mapbox-gl.adapter";
|
|
4
|
+
import { TerraDrawMode, TerraDrawAdapter, TerraDrawAdapterStyling } from "./common";
|
|
5
|
+
import { TerraDrawCircleMode } from "./modes/circle/circle.mode";
|
|
6
|
+
import { TerraDrawFreehandMode } from "./modes/freehand/freehand.mode";
|
|
7
|
+
import { TerraDrawLineStringMode } from "./modes/linestring/linestring.mode";
|
|
8
|
+
import { TerraDrawPointMode } from "./modes/point/point.mode";
|
|
9
|
+
import { TerraDrawPolygonMode } from "./modes/polygon/polygon.mode";
|
|
10
|
+
import { TerraDrawSelectMode } from "./modes/select/select.mode";
|
|
11
|
+
import { GeoJSONStoreFeatures } from "./store/store";
|
|
12
|
+
declare type ChangeListener = (ids: string[], type: string) => void;
|
|
13
|
+
declare type SelectListener = (id: string) => void;
|
|
14
|
+
declare type DeselectListener = () => void;
|
|
15
|
+
interface TerraDrawEventListeners {
|
|
16
|
+
change: ChangeListener;
|
|
17
|
+
select: SelectListener;
|
|
18
|
+
deselect: DeselectListener;
|
|
19
|
+
}
|
|
20
|
+
declare type TerraDrawEvents = keyof TerraDrawEventListeners;
|
|
21
|
+
declare class TerraDraw {
|
|
22
|
+
private _modes;
|
|
23
|
+
private _mode;
|
|
24
|
+
private _adapter;
|
|
25
|
+
private _enabled;
|
|
26
|
+
private _store;
|
|
27
|
+
private _eventListeners;
|
|
28
|
+
constructor(options: {
|
|
29
|
+
adapter: TerraDrawAdapter;
|
|
30
|
+
modes: {
|
|
31
|
+
[mode: string]: TerraDrawMode;
|
|
32
|
+
};
|
|
33
|
+
data?: GeoJSONStoreFeatures[];
|
|
34
|
+
});
|
|
35
|
+
private getModeStyles;
|
|
36
|
+
setModeStyling(mode: string, styling: TerraDrawAdapterStyling): void;
|
|
37
|
+
getSnapshot(): GeoJSONStoreFeatures[];
|
|
38
|
+
get enabled(): boolean;
|
|
39
|
+
set enabled(_: boolean);
|
|
40
|
+
getCurrentMode(): string;
|
|
41
|
+
changeMode(mode: string): void;
|
|
42
|
+
start(): void;
|
|
43
|
+
stop(): void;
|
|
44
|
+
on<T extends TerraDrawEvents>(event: T, callback: TerraDrawEventListeners[T]): void;
|
|
45
|
+
off<T extends TerraDrawEvents>(event: TerraDrawEvents, callback: TerraDrawEventListeners[T]): void;
|
|
46
|
+
}
|
|
47
|
+
export { TerraDraw, TerraDrawSelectMode, TerraDrawPointMode, TerraDrawLineStringMode, TerraDrawPolygonMode, TerraDrawCircleMode, TerraDrawFreehandMode, TerraDrawGoogleMapsAdapter, TerraDrawMapboxGLAdapter, TerraDrawLeafletAdapter, };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},t.apply(this,arguments)}function e(t,e=9){const i=Math.pow(10,e);return Math.round(t*i)/i}class i{constructor(t){this._heldKeys=new Set,this._cursor=void 0,this._cursorStyleSheet=void 0,this._coordinatePrecision=void 0,this._lib=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onMouseMoveCallback=void 0,this._onClickListener=void 0,this._onRightClickListener=void 0,this._onClickCallback=void 0,this._onKeyUpListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._layers=!1,this.getMapContainer=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.getMapContainer=()=>this._map.getDiv(),this.project=(t,e)=>{const i=this._map.getBounds();if(void 0===i)throw new Error("cannot get bounds");const o=new this._lib.LatLng(i.getNorthEast().lat(),i.getSouthWest().lng()),n=this._map.getProjection();if(void 0===n)throw new Error("cannot get projection");const s=n.fromLatLngToPoint(o);if(null===s)throw new Error("cannot get projectedNorthWest");const r=n.fromLatLngToPoint({lng:t,lat:e});if(null===r)throw new Error("cannot get projected lng lat");const a=this._map.getZoom();if(void 0===a)throw new Error("cannot get zoom");const h=Math.pow(2,a);return{x:Math.floor((r.x-s.x)*h),y:Math.floor((r.y-s.y)*h)}},this.unproject=(t,e)=>{const i=this._map.getProjection();if(void 0===i)throw new Error("cannot get projection");const o=this._map.getBounds();if(void 0===o)throw new Error("cannot get bounds");const n=i.fromLatLngToPoint(o.getNorthEast());if(null===n)throw new Error("cannot get topRight");const s=i.fromLatLngToPoint(o.getSouthWest());if(null===s)throw new Error("cannot get bottomLeft");const r=this._map.getZoom();if(void 0===r)throw new Error("zoom get bounds");const a=Math.pow(2,r),h=new google.maps.Point(t/a+s.x,e/a+n.y),c=i.fromPointToLatLng(h);if(null===c)throw new Error("zoom get bounds");return{lng:c.lng(),lat:c.lat()}},this.setCursor=t=>{if(t!==this._cursor){if(this._cursorStyleSheet&&(this._cursorStyleSheet.remove(),this._cursorStyleSheet=void 0),"unset"!==t){const e=this.getMapContainer(),i=document.createElement("style");i.type="text/css",i.innerHTML=`#${e.id} [aria-label="Map"] { cursor: ${t} !important; }`,document.getElementsByTagName("head")[0].appendChild(i),this._cursorStyleSheet=i}this._cursor=t}}}circlePath(t,e,i){return"M "+t+" "+e+" m -"+i+", 0 a "+i+","+i+" 0 1,0 "+2*i+",0 a "+i+","+i+" 0 1,0 -"+2*i+",0"}register(t){this._onClickCallback=i=>{i.latLng&&t.onClick({lng:e(i.latLng.lng(),this._coordinatePrecision),lat:e(i.latLng.lat(),this._coordinatePrecision),containerX:i.domEvent.clientX-this.getMapContainer().offsetLeft,containerY:i.domEvent.clientY-this.getMapContainer().offsetTop,button:0===i.domEvent.button?"left":"right",heldKeys:[...this._heldKeys]})},this._onClickListener=this._map.addListener("click",this._onClickCallback),this._onRightClickListener=this._map.addListener("rightclick",this._onClickCallback),this._onMouseMoveCallback=i=>{i.latLng&&t.onMouseMove({lng:e(i.latLng.lng(),this._coordinatePrecision),lat:e(i.latLng.lat(),this._coordinatePrecision),containerX:i.domEvent.clientX-this.getMapContainer().offsetLeft,containerY:i.domEvent.clientY-this.getMapContainer().offsetTop,button:0===i.domEvent.button?"left":"right",heldKeys:[...this._heldKeys]})},this._onMouseMoveListener=this._map.addListener("mousemove",this._onMouseMoveCallback),this._onKeyUpListener=e=>{t.onKeyUp({key:e.key})},this.getMapContainer().addEventListener("keyup",this._onKeyUpListener);let i="not-dragging";this._onDragStartListener=t=>{i="pre-dragging"};const o=this.getMapContainer();o.addEventListener("mousedown",this._onDragStartListener),this._onDragListener=n=>{const s={x:n.clientX-o.offsetLeft,y:n.clientY-o.offsetTop},{lng:r,lat:a}=this.unproject(s.x,s.y),h={lng:e(r,this._coordinatePrecision),lat:e(a,this._coordinatePrecision),containerX:n.clientX-o.offsetLeft,containerY:n.clientY-o.offsetTop,button:0===n.button?"left":"right",heldKeys:[...this._heldKeys]};"pre-dragging"===i?(i="dragging",t.onDragStart(h,t=>{this._map.setOptions({draggable:!1})})):"dragging"===i&&t.onDrag(h)},o.addEventListener("mousemove",this._onDragListener),this._onDragEndListener=n=>{if("dragging"===i){const i={x:n.clientX-o.offsetLeft,y:n.clientY-o.offsetTop},{lng:s,lat:r}=this.unproject(i.x,i.y);t.onDragEnd({lng:e(s,this._coordinatePrecision),lat:e(r,this._coordinatePrecision),containerX:n.clientX-o.offsetLeft,containerY:n.clientY-o.offsetTop,button:0===n.button?"left":"right",heldKeys:[...this._heldKeys]},t=>{this._map.setOptions({draggable:t})})}i="not-dragging"},o.addEventListener("mouseup",this._onDragEndListener)}unregister(){this._onClickListener&&(this._onClickCallback=void 0,this._onClickListener.remove(),this._onClickListener=void 0),this._onRightClickListener&&(this._onClickCallback=void 0,this._onRightClickListener.remove(),this._onRightClickListener=void 0),this._onMouseMoveListener&&(this._onMouseMoveCallback=void 0,this._onMouseMoveListener.remove(),this._onMouseMoveListener=void 0),this._onKeyUpListener&&(this.getMapContainer().removeEventListener("keyup",this._onKeyUpListener),this._onKeyUpListener=void 0)}render(t,e){this._layers?(t.deletedIds.forEach(t=>{const e=this._map.data.getFeatureById(t);e&&this._map.data.remove(e)}),t.updated.forEach(t=>{if(!t||!t.id)throw new Error("Feature is not valid");const e=this._map.data.getFeatureById(t.id);if(!e)throw new Error("Feature could not be found by Google Maps API");switch(e.forEachProperty((t,i)=>{e.setProperty(i,void 0)}),Object.keys(t.properties).forEach(i=>{e.setProperty(i,t.properties[i])}),t.geometry.type){case"Point":{const i=t.geometry.coordinates;e.setGeometry(new google.maps.Data.Point(new google.maps.LatLng(i[1],i[0])))}break;case"LineString":{const i=t.geometry.coordinates,o=[];for(let t=0;t<i.length;t++){const e=i[t],n=new google.maps.LatLng(e[1],e[0]);o.push(n)}e.setGeometry(new google.maps.Data.LineString(o))}break;case"Polygon":{const i=t.geometry.coordinates,o=[];for(let t=0;t<i.length;t++){const e=[];for(let o=0;o<i[t].length;o++){const n=new google.maps.LatLng(i[t][o][1],i[t][o][0]);e.push(n)}o.push(e)}e.setGeometry(new google.maps.Data.Polygon(o))}}}),t.created.forEach(t=>{this._map.data.addGeoJson(t)})):(this._map.data.addListener("click",t=>{this._onClickCallback&&this._onClickCallback(t)}),this._map.data.addListener("mousemove",t=>{this._onMouseMoveCallback&&this._onMouseMoveCallback(t)}));const i={type:"FeatureCollection",features:[...t.created]};this._map.data.addGeoJson(i),this._map.data.setStyle(t=>{const i=t.getProperty("mode"),o=t.getGeometry();if(!o)throw new Error("Google Maps geometry not found");const n=o.getType(),s=t.getProperty("selected"),r=Boolean(t.getProperty("selectionPoint")),a=Boolean(t.getProperty("midPoint"));switch(n){case"Point":const t=s||r,o=a;return{clickable:!1,icon:{path:this.circlePath(0,0,t?e[i].selectionPointWidth:o?e[i].midPointWidth:e[i].pointWidth),fillColor:t?e[i].selectedColor:o?e[i].midPointColor:e[i].pointColor,fillOpacity:1,strokeColor:t?e[i].selectedPointOutlineColor:o?e[i].midPointOutlineColor:void 0,strokeWeight:t||o?2:0,rotation:0,scale:1}};case"LineString":return{strokeColor:s?e[i].selectedColor:e[i].lineStringColor,strokeWeight:e[i].lineStringWidth};case"Polygon":return{strokeColor:s?e[i].selectedColor:e[i].polygonOutlineColor,strokeWeight:e[i].polygonOutlineWidth,fillOpacity:e[i].polygonFillOpacity,fillColor:s?e[i].selectedColor:e[i].polygonFillColor}}throw Error("Unknown feature type")}),this._layers=!0}}class o{constructor(t){this._heldKeys=new Set,this._lib=void 0,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onKeyUpListener=void 0,this._onKeyDownListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._layer=void 0,this._midPointPaneZIndexStyleSheet=void 0,this._midPointPane="midPointPane",this._selectionPaneZIndexStyleSheet=void 0,this._selectedPane="selectedPane",this.project=void 0,this.unproject=void 0,this.setCursor=void 0,this.getMapContainer=void 0,this._lib=t.lib,this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.getMapContainer=()=>this._map.getContainer(),this.project=(t,e)=>{const{x:i,y:o}=this._map.latLngToContainerPoint({lng:t,lat:e});return{x:i,y:o}},this.unproject=(t,e)=>{const{lng:i,lat:o}=this._map.containerPointToLatLng({x:t,y:e});return{lng:i,lat:o}},this.setCursor=t=>{"unset"===t?this.getMapContainer().style.removeProperty("cursor"):this.getMapContainer().style.cursor=t}}createPaneStyleSheet(t,e){const i=document.createElement("style");return i.type="text/css",i.innerHTML=`.leaflet-${t} {z-index: ${e};}`,document.getElementsByTagName("head")[0].appendChild(i),this._map.createPane(t),i}register(t){this._selectionPaneZIndexStyleSheet||(this._selectionPaneZIndexStyleSheet=this.createPaneStyleSheet(this._selectedPane,10)),this._midPointPaneZIndexStyleSheet||(this._midPointPaneZIndexStyleSheet=this.createPaneStyleSheet(this._midPointPane,20));const i=this.getMapContainer();let o="not-dragging";this._onClickListener=i=>{"not-dragging"!==o&&"pre-dragging"!==o||t.onClick({lng:e(i.latlng.lng,this._coordinatePrecision),lat:e(i.latlng.lat,this._coordinatePrecision),containerX:i.originalEvent.clientX-this.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-this.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[...this._heldKeys]})},this._map.on("mouseup",this._onClickListener),this._map.on("contextmenu",this._onClickListener),this._onMouseMoveListener=i=>{i.originalEvent.preventDefault(),t.onMouseMove({lng:e(i.latlng.lng,this._coordinatePrecision),lat:e(i.latlng.lat,this._coordinatePrecision),containerX:i.originalEvent.clientX-this.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-this.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[...this._heldKeys]})},this._map.on("mousemove",this._onMouseMoveListener),this._onDragStartListener=t=>{o="pre-dragging"},i.addEventListener("pointerdown",this._onDragStartListener),this._onDragListener=n=>{const s={x:n.clientX-i.offsetLeft,y:n.clientY-i.offsetTop},{lng:r,lat:a}=this._map.containerPointToLatLng(s),h={lng:e(r,this._coordinatePrecision),lat:e(a,this._coordinatePrecision),containerX:n.clientX-i.offsetLeft,containerY:n.clientY-i.offsetTop,button:0===n.button?"left":"right",heldKeys:[...this._heldKeys]};"pre-dragging"===o?(o="dragging",t.onDragStart(h,t=>{t?this._map.dragging.enable():this._map.dragging.disable()})):"dragging"===o&&t.onDrag(h)},i.addEventListener("pointermove",this._onDragListener),this._onDragEndListener=n=>{if(n.preventDefault(),"dragging"===o){const s={x:n.clientX-i.offsetLeft,y:n.clientY-i.offsetTop},{lng:r,lat:a}=this._map.containerPointToLatLng(s);return t.onDragEnd({lng:e(r,this._coordinatePrecision),lat:e(a,this._coordinatePrecision),containerX:n.clientX-i.offsetLeft,containerY:n.clientY-i.offsetTop,button:0===n.button?"left":"right",heldKeys:[...this._heldKeys]},t=>{t?this._map.dragging.enable():this._map.dragging.disable()}),o="after-dragging",void this._map.dragging.enable()}o="not-dragging",this._map.dragging.enable()},i.addEventListener("pointerup",this._onDragEndListener),this._onKeyUpListener=e=>{e.preventDefault(),this._heldKeys.delete(e.key),t.onKeyUp({key:e.key})},i.addEventListener("keyup",this._onKeyUpListener),this._onKeyDownListener=e=>{e.preventDefault(),this._heldKeys.add(e.key),t.onKeyDown({key:e.key})},i.addEventListener("keydown",this._onKeyDownListener)}unregister(){this._onClickListener&&(this._map.off("contextmenu",this._onClickListener),this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("click",this._onClickListener),this._onClickListener=void 0);const t=this._map.getPane(this._selectedPane);t&&t.remove()}render(t,e){const i=[...t.created,...t.updated,...t.unchanged];this._layer&&this._map.removeLayer(this._layer);const o=this._lib.geoJSON({type:"FeatureCollection",features:i},{pointToLayer:(t,i)=>{if(!t.properties)throw new Error("Feature has no properties");const o=e[t.properties.mode],n=t.properties.selected||t.properties.selectionPoint,s=t.properties.midPoint;return this._lib.circleMarker(i,{radius:n?o.selectionPointWidth:s?o.midPointWidth:o.pointWidth,fillColor:n?o.selectedColor:s?o.midPointColor:o.pointColor,stroke:n||s,color:n?o.selectedPointOutlineColor:s?o.midPointOutlineColor:o.pointOutlineColor,weight:n||s?2:0,fillOpacity:.8,pane:n?this._selectedPane:s?this._midPointPane:void 0,interactive:!1})},style:t=>{if(!t||!t.properties)return{};const i=e[t.properties.mode];return"LineString"===t.geometry.type?{interactive:!1,color:t.properties.selected?i.selectedColor:i.lineStringColor,weight:i.lineStringWidth}:"Polygon"===t.geometry.type?{interactive:!1,fillOpacity:i.polygonFillOpacity,fillColor:t.properties.selected?i.selectedColor:i.polygonFillColor,weight:i.polygonOutlineWidth,stroke:!0,color:t.properties.selected?i.selectedColor:i.polygonOutlineColor}:{}}});this._map.addLayer(o),this._layer=o}}class n{constructor(t){this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.getMapContainer=void 0,this._heldKeys=new Set,this._coordinatePrecision=void 0,this._map=void 0,this._onMouseMoveListener=void 0,this._onClickListener=void 0,this._onDragStartListener=void 0,this._onDragListener=void 0,this._onDragEndListener=void 0,this._onKeyDownListener=void 0,this._onKeyUpListener=void 0,this._rendered={},this._map=t.map,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9,this.project=(t,e)=>{const{x:i,y:o}=this._map.project({lng:t,lat:e});return{x:i,y:o}},this.unproject=(t,e)=>{const{lng:i,lat:o}=this._map.unproject({x:t,y:e});return{lng:i,lat:o}},this.setCursor=t=>{this._map.getCanvas().style.cursor=t},this.getMapContainer=()=>this._map.getContainer()}_addGeoJSONSource(t,e){this._map.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:e}})}_addFillLayer(t,e,i){return this._map.addLayer({id:t,source:t,type:"fill",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":i.polygonFillOpacity}})}_addFillOutlineLayer(t,e,i,o){const n=this._map.addLayer({id:t+"outline",source:t,type:"line",filter:["all",["match",["geometry-type"],"Polygon",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":i.polygonOutlineWidth,"line-color":["get","polygonOutlineColor"]}});return o&&this._map.moveLayer(t,o),n}_addLineLayer(t,e,i,o){const n=this._map.addLayer({id:t,source:t,type:"line",filter:["all",["match",["geometry-type"],"LineString",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"line-width":i.lineStringWidth,"line-color":["get","lineStringColor"]}});return o&&this._map.moveLayer(t,o),n}_addPointLayer(t,e,i,o){const n=this._map.addLayer({id:t,source:t,type:"circle",filter:["all",["match",["geometry-type"],"Point",!0,!1],["match",["get","mode"],e,!0,!1]],paint:{"circle-stroke-color":["get","selectedPointOutlineColor"],"circle-stroke-width":2,"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}});return o&&this._map.moveLayer(t,o),n}_addLayer(t,e,i,o,n){"Point"===i&&this._addPointLayer(t,e,o,n),"LineString"===i&&this._addLineLayer(t,e,o,n),"Polygon"===i&&(this._addFillLayer(t,e,o),this._addFillOutlineLayer(t,e,o,n))}_addGeoJSONLayer(t,e,i,o){const n=`td-${t}-${e.toLowerCase()}`;return this._addGeoJSONSource(n,i),this._addLayer(n,t,e,o),n}_setGeoJSONLayerData(t,e,i){const o=`td-${t}-${e.toLowerCase()}`;return this._map.getSource(o).setData({type:"FeatureCollection",features:i}),o}register(t){this._onClickListener=i=>{t.onClick({lng:e(i.lngLat.lng,this._coordinatePrecision),lat:e(i.lngLat.lat,this._coordinatePrecision),containerX:i.originalEvent.clientX-this.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-this.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[...this._heldKeys]})},this._map.on("click",this._onClickListener),this._map.on("contextmenu",this._onClickListener),this._onMouseMoveListener=i=>{t.onMouseMove({lng:e(i.lngLat.lng,this._coordinatePrecision),lat:e(i.lngLat.lat,this._coordinatePrecision),containerX:i.originalEvent.clientX-this.getMapContainer().offsetLeft,containerY:i.originalEvent.clientY-this.getMapContainer().offsetTop,button:0===i.originalEvent.button?"left":"right",heldKeys:[...this._heldKeys]})},this._map.on("mousemove",this._onMouseMoveListener);let i="not-dragging";this._onDragStartListener=t=>{i="pre-dragging"};const o=this.getMapContainer();o.addEventListener("mousedown",this._onDragStartListener),this._onDragListener=n=>{const{lng:s,lat:r}=this._map.unproject({x:n.clientX-o.offsetLeft,y:n.clientY-o.offsetTop}),a={lng:e(s,this._coordinatePrecision),lat:e(r,this._coordinatePrecision),containerX:n.clientX-o.offsetLeft,containerY:n.clientY-o.offsetTop,button:0===n.button?"left":"right",heldKeys:[...this._heldKeys]};"pre-dragging"===i?(i="dragging",t.onDragStart(a,t=>{t?this._map.dragPan.enable():this._map.dragPan.disable()})):"dragging"===i&&t.onDrag(a)},o.addEventListener("mousemove",this._onDragListener),this._onDragEndListener=n=>{if("dragging"===i){const i={x:n.clientX-o.offsetLeft,y:n.clientY-o.offsetTop},{lng:s,lat:r}=this._map.unproject(i);t.onDragEnd({lng:e(s,this._coordinatePrecision),lat:e(r,this._coordinatePrecision),containerX:n.clientX-o.offsetLeft,containerY:n.clientY-o.offsetTop,button:0===n.button?"left":"right",heldKeys:[...this._heldKeys]},t=>{t?this._map.dragPan.enable():this._map.dragPan.disable()})}i="not-dragging"},o.addEventListener("mouseup",this._onDragEndListener),this._onKeyUpListener=e=>{e.preventDefault(),this._heldKeys.delete(e.key),t.onKeyUp({key:e.key})},o.addEventListener("keyup",this._onKeyUpListener),this._onKeyDownListener=e=>{e.preventDefault(),this._heldKeys.add(e.key),t.onKeyDown({key:e.key})},o.addEventListener("keydown",this._onKeyDownListener)}unregister(){this._onClickListener&&(this._map.off("contextmenue",this._onClickListener),this._map.off("click",this._onClickListener),this._onClickListener=void 0),this._onMouseMoveListener&&(this._map.off("mousemove",this._onMouseMoveListener),this._onMouseMoveListener=void 0),this._onKeyUpListener&&this._map.getCanvas().removeEventListener("keypress",this._onKeyUpListener),this._onDragStartListener&&this._map.getCanvas().removeEventListener("mousedown",this._onDragStartListener),this._onDragListener&&this._map.getCanvas().removeEventListener("mousemove",this._onDragListener),this._onDragEndListener&&this._map.getCanvas().removeEventListener("mouseup",this._onDragEndListener)}render(t,e){const i=[...t.created,...t.updated,...t.unchanged],o={};for(let t=0;t<i.length;t++){const n=i[t];Object.keys(e).forEach(t=>{const i=e[t];n.properties.mode===t&&(o[t]||(o[t]={points:[],linestrings:[],polygons:[]}),"Point"===n.geometry.type?(n.properties.selected||n.properties.selectionPoint?(n.properties.pointColor=i.selectedColor,n.properties.selectedPointOutlineColor=i.selectedPointOutlineColor,n.properties.pointWidth=i.selectionPointWidth):n.properties.midPoint?(n.properties.pointColor=i.midPointColor,n.properties.selectedPointOutlineColor=i.midPointOutlineColor,n.properties.pointWidth=i.midPointWidth):(n.properties.pointColor=i.pointColor,n.properties.selectedPointOutlineColor=i.pointColor,n.properties.pointWidth=i.pointWidth),o[t].points.push(n)):"LineString"===n.geometry.type?(n.properties.lineStringColor=n.properties.selected?i.selectedColor:i.lineStringColor,o[t].linestrings.push(n)):"Polygon"===n.geometry.type&&(n.properties.selected?(n.properties.polygonFillColor=i.selectedColor,n.properties.polygonOutlineColor=i.selectedColor):(n.properties.polygonFillColor=i.polygonFillColor,n.properties.polygonOutlineColor=i.polygonOutlineColor),o[t].polygons.push(n)))})}Object.keys(e).forEach(t=>{const i=e[t];if(!o[t]||!i)return;const{points:n,linestrings:s,polygons:r}=o[t];if(this._rendered[t]){const e=this._setGeoJSONLayerData(t,"Point",n);this._setGeoJSONLayerData(t,"LineString",s),this._setGeoJSONLayerData(t,"Polygon",r),this._map.moveLayer(e)}else this._addGeoJSONLayer(t,"Point",n,i),this._addGeoJSONLayer(t,"LineString",s,i),this._addGeoJSONLayer(t,"Polygon",r,i),this._rendered[t]=!0})}}function s(t,e){const i=t=>t*Math.PI/180,o=i(t[1]),n=i(t[0]),s=i(e[1]),r=s-o,a=i(e[0])-n,h=Math.sin(r/2)*Math.sin(r/2)+Math.cos(o)*Math.cos(s)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(h),Math.sqrt(1-h))*6371e3/1e3}function r(t){return t%360*Math.PI/180}function a(t){return t%(2*Math.PI)*180/Math.PI}function h(t,e,i){const o=r(t[0]),n=r(t[1]),s=r(i),h=function(t){return t/6371.0088}(e),c=Math.asin(Math.sin(n)*Math.cos(h)+Math.cos(n)*Math.sin(h)*Math.cos(s));return[a(o+Math.atan2(Math.sin(s)*Math.sin(h)*Math.cos(n),Math.cos(h)-Math.sin(n)*Math.sin(c))),a(c)]}function c(t){const{center:e,radiusKilometers:i}=t,o=t.steps?t.steps:64,n=[];for(let t=0;t<o;t++)n.push(h(e,i,-360*t/o));return n.push(n[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[n]},properties:{}}}class d{get state(){return this._state}set state(t){throw new Error("Please use the modes lifecycle methods")}get styling(){return this._styling}set styling(t){if("object"!=typeof t)throw new Error("Styling must be an object");this.onStyleChange([],"styling"),this._styling=t}registerBehaviors(t){}constructor(e){this._state=void 0,this._styling=void 0,this.behaviors=[],this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.onStyleChange=void 0,this.store=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this._state="unregistered",this._styling=e&&e.styling?t({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8",selectedPointOutlineColor:"#ffffff",selectionPointWidth:6,midPointColor:"#3f97e0",midPointOutlineColor:"#ffffff",midPointWidth:4,closingPointColor:"#3f97e0",closingPointOutlineColor:"#ffffff",closingPointWidth:4},e.styling):{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOutlineColor:"#3f97e0",pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,selectedColor:"#26a9c8",selectedPointOutlineColor:"#ffffff",selectionPointWidth:6,midPointColor:"#3f97e0",midPointOutlineColor:"#ffffff",midPointWidth:4,closingPointColor:"#3f97e0",closingPointOutlineColor:"#ffffff",closingPointWidth:4},this.pointerDistance=e&&e.pointerDistance||40,this.coordinatePrecision=e&&e.coordinatePrecision||9}setStarted(){if("stopped"!==this._state&&"registered"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="started"}setStopped(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped"}register(t){if("unregistered"!==this._state)throw new Error("Can not register unless mode is unregistered");this._state="registered",this.store=t.store,this.store.registerOnChange(t.onChange),this.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:this.coordinatePrecision})}onDeselect(t){}onSelect(t){}}class l extends d{constructor(t){super(t),this.mode="circle",this.center=void 0,this.clickCount=0,this.currentCircleId=void 0,this.keyEvents=void 0,this.keyEvents=t&&t.keyEvents?t.keyEvents:{cancel:"Escape"}}start(){this.setStarted(),this.setCursor("crosshair")}stop(){this.setStopped(),this.setCursor("unset"),this.cleanUp()}onClick(t){if(0===this.clickCount){this.center=[t.lng,t.lat];const e=c({center:this.center,radiusKilometers:1e-5}),[i]=this.store.create([{geometry:e.geometry,properties:{mode:this.mode}}]);this.currentCircleId=i,this.clickCount++}else this.center=void 0,this.currentCircleId=void 0,this.clickCount=0}onMouseMove(t){if(1===this.clickCount&&this.center&&this.currentCircleId){const e=s(this.center,[t.lng,t.lat]),i=c({center:this.center,radiusKilometers:e});this.store.updateGeometry([{id:this.currentCircleId,geometry:i.geometry}])}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentCircleId&&this.store.delete([this.currentCircleId])}catch(t){}this.center=void 0,this.currentCircleId=void 0,this.clickCount=0}}class p extends d{constructor(t){super(t),this.mode="freehand",this.startingClick=!1,this.currentId=void 0,this.skip=0,this.everyNthMouseEvent=void 0,this.keyEvents=void 0,this.everyNthMouseEvent=t&&t.everyNthMouseEvent||10,this.keyEvents=t&&t.keyEvents?t.keyEvents:{cancel:"Escape"}}start(){this.setStarted(),this.setCursor("crosshair")}stop(){this.setStopped(),this.setCursor("unset"),this.cleanUp()}onMouseMove(t){if(this.currentId&&!1!==this.startingClick){if(this.skip>this.everyNthMouseEvent){this.skip=0;const e=this.store.getGeometryCopy(this.currentId);e.coordinates[0].pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[...e.coordinates[0],[t.lng,t.lat],e.coordinates[0][0]]]}}])}this.skip++}}onClick(t){if(!1===this.startingClick){const[e]=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);return this.currentId=e,void(this.startingClick=!0)}this.startingClick=!1,this.currentId=void 0}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.startingClick=!1}}function g(t){let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}const i=[];for(let t=0;t<e.length;t++)for(let i=0;i<e[t].length-1;i++)for(let o=0;o<e.length;o++)for(let s=0;s<e[o].length-1;s++)n(t,i,o,s);return i.length>0;function o(t){return t<0||t>1}function n(t,n,s,r){const a=e[t][n],h=e[t][n+1],c=e[s][r],d=e[s][r+1],l=function(t,e,i,o){if(u(t,i)||u(t,o)||u(e,i)||u(o,i))return null;const n=t[0],s=t[1],r=e[0],a=e[1],h=i[0],c=i[1],d=o[0],l=o[1],p=(n-r)*(c-l)-(s-a)*(h-d);return 0===p?null:[((n*a-s*r)*(h-d)-(n-r)*(h*l-c*d))/p,((n*a-s*r)*(c-l)-(s-a)*(h*l-c*d))/p]}(a,h,c,d);if(null===l)return;let p,g;p=h[0]!==a[0]?(l[0]-a[0])/(h[0]-a[0]):(l[1]-a[1])/(h[1]-a[1]),g=d[0]!==c[0]?(l[0]-c[0])/(d[0]-c[0]):(l[1]-c[1])/(d[1]-c[1]),o(p)||o(g)||(l.toString(),i.push(l))}}function u(t,e){return t[0]===e[0]&&t[1]===e[1]}const y=(t,e)=>{const{x:i,y:o}=t,{x:n,y:s}=e,r=n-i,a=s-o;return Math.sqrt(a*a+r*r)};class m{constructor({store:t,mode:e,project:i,unproject:o,pointerDistance:n,coordinatePrecision:s}){this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.store=t,this.mode=e,this.project=i,this.unproject=o,this.pointerDistance=n,this.coordinatePrecision=s}}class f extends m{constructor(t){super(t)}create(t){const{containerX:e,containerY:i}=t,o=this.pointerDistance/2;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[this.unproject(e-o,i-o),this.unproject(e+o,i-o),this.unproject(e+o,i+o),this.unproject(e-o,i+o),this.unproject(e-o,i-o)].map(t=>[t.lng,t.lat])]}}}}class _ extends m{constructor(t){super(t)}measure(t,e){const{x:i,y:o}=this.project(e[0],e[1]);return y({x:i,y:o},{x:t.containerX,y:t.containerY})}}class v extends m{constructor(t,e,i){super(t),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinate=(t,e)=>this.getSnappable(t,t=>Boolean(t.properties&&t.properties.mode===this.mode&&t.id!==e)),this.config=t,this.pixelDistance=e,this.clickBoundingBox=i}getSnappable(t,e){const i=this.clickBoundingBox.create(t),o=this.store.search(i,e),n={coord:void 0,minDist:Infinity};return o.forEach(e=>{let i;if("Polygon"===e.geometry.type)i=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;i=e.geometry.coordinates}i.forEach(e=>{const i=this.pixelDistance.measure(t,e);i<n.minDist&&i<this.pointerDistance&&(n.coord=e)})}),n.coord}}class P extends d{constructor(t){super(t),this.mode="linestring",this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.snapping=void 0,this.snappingEnabled=!(!t||void 0===t.snapping)&&t.snapping,this.allowSelfIntersections=!t||void 0===t.allowSelfIntersections||t.allowSelfIntersections,this.keyEvents=t&&t.keyEvents?t.keyEvents:{cancel:"Escape"}}registerBehaviors(t){this.snapping=new v(t,new _(t),new f(t))}start(){this.setStarted(),this.setCursor("crosshair")}stop(){this.setStopped(),this.setCursor("unset"),this.cleanUp()}onMouseMove(t){if(!this.currentId||0===this.currentCoordinate)return;const e=this.store.getGeometryCopy(this.currentId);e.coordinates.pop();const i=this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId);this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[...e.coordinates,i||[t.lng,t.lat]]}}])}onClick(t){const e=this.currentId&&this.snappingEnabled&&this.snapping.getSnappableCoordinate(t,this.currentId)||[t.lng,t.lat];if(0===this.currentCoordinate){const[t]=this.store.create([{geometry:{type:"LineString",coordinates:[e,e]},properties:{mode:this.mode}}]);this.currentId=t,this.currentCoordinate++}else if(1===this.currentCoordinate&&this.currentId){const t=this.store.getGeometryCopy(this.currentId);this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[t.coordinates[0],e,e]}}]),this.currentCoordinate++}else if(this.currentId){const i=this.store.getGeometryCopy(this.currentId),[o,n]=i.coordinates[i.coordinates.length-2],{x:s,y:r}=this.project(o,n);if(y({x:s,y:r},{x:t.containerX,y:t.containerY})<this.pointerDistance)i.coordinates.pop(),this.store.updateGeometry([{id:this.currentId,geometry:{type:"LineString",coordinates:[...i.coordinates]}}]),this.currentCoordinate=0,this.currentId=void 0;else{const t={type:"LineString",coordinates:[...i.coordinates,e]};if(!this.allowSelfIntersections&&g({type:"Feature",geometry:t,properties:{}}))return;this.store.updateGeometry([{id:this.currentId,geometry:t}]),this.currentCoordinate++}}}onKeyDown(){}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp()}onDragStart(){}onDrag(){}onDragEnd(){}cleanUp(){try{this.currentId&&this.store.delete([this.currentId])}catch(t){}this.currentId=void 0,this.currentCoordinate=0}}class C extends d{constructor(t){super(t),this.mode="point"}start(){this.setStarted(),this.setCursor("crosshair")}stop(){this.setStopped(),this.setCursor("unset"),this.cleanUp()}onClick(t){if(!this.store)throw new Error("Mode must be registered first");this.store.create([{geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{mode:this.mode}}])}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){}onDragStart(){}onDrag(){}onDragEnd(){}}function M(t,e){return t[0]===e[0]&&t[1]===e[1]}class L extends m{constructor(t){super(t),this._startEndPoints=[]}get ids(){return this._startEndPoints.concat()}set ids(t){}create(t,e){if(this.ids.length)throw new Error("Opening and closing points already creating");this._startEndPoints=this.store.create([{geometry:{type:"Point",coordinates:t[0]},properties:{mode:e}}])}delete(){this.ids.length&&(this.store.delete(this.ids),this._startEndPoints=[])}update(t){this.store.updateGeometry([{id:this.ids[0],geometry:{type:"Point",coordinates:t[0]}}])}}class x extends d{constructor(t){super(t),this.mode="polygon",this.currentCoordinate=0,this.currentId=void 0,this.allowSelfIntersections=void 0,this.keyEvents=void 0,this.snappingEnabled=void 0,this.isClosed=!1,this.snapping=void 0,this.pixelDistance=void 0,this.startEndPoint=void 0,this.snappingEnabled=!(!t||void 0===t.snapping)&&t.snapping,this.allowSelfIntersections=!t||void 0===t.allowSelfIntersections||t.allowSelfIntersections,this.keyEvents=t&&t.keyEvents?t.keyEvents:{cancel:"Escape"}}registerBehaviors(t){this.pixelDistance=new _(t),this.snapping=new v(t,this.pixelDistance,new f(t)),this.startEndPoint=new L(t)}start(){this.setStarted(),this.setCursor("crosshair")}stop(){this.setStopped(),this.setCursor("unset"),this.cleanUp()}onMouseMove(t){if(this.setCursor("crosshair"),!this.currentId||0===this.currentCoordinate)return;const e=this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0,i=this.store.getGeometryCopy(this.currentId).coordinates[0];let o;if(e&&(t.lng=e[0],t.lat=e[1]),1===this.currentCoordinate){const e=1/Math.pow(10,this.coordinatePrecision-1),n=Math.max(1e-6,e);o=[i[0],[t.lng,t.lat],[t.lng,t.lat+n],i[0]]}else if(2===this.currentCoordinate)o=[i[0],i[1],[t.lng,t.lat],i[0]];else{const e=this.pixelDistance.measure(t,i[0]),n=this.pixelDistance.measure(t,i[i.length-2]);e<this.pointerDistance||n<this.pointerDistance?(this.setCursor("pointer"),this.isClosed?o=[...i]:(o=[...i.slice(0,-2),i[0],i[0]],this.isClosed=!0)):(this.isClosed&&(this.isClosed=!1),o=[...i.slice(0,-2),[t.lng,t.lat],i[0]])}this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[o]}}]),this.startEndPoint.ids.length&&this.startEndPoint.update(o)}onClick(t){const e=this.currentId&&this.snappingEnabled?this.snapping.getSnappableCoordinate(t,this.currentId):void 0;if(0===this.currentCoordinate){e&&(t.lng=e[0],t.lat=e[1]);const[i]=this.store.create([{geometry:{type:"Polygon",coordinates:[[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]]]},properties:{mode:this.mode}}]);this.currentId=i,this.currentCoordinate++}else if(1===this.currentCoordinate&&this.currentId){e&&(t.lng=e[0],t.lat=e[1]);const i=this.store.getGeometryCopy(this.currentId);if(M([t.lng,t.lat],i.coordinates[0][0]))return;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[i.coordinates[0][0],[t.lng,t.lat],[t.lng,t.lat],i.coordinates[0][0]]]}}]),this.currentCoordinate++}else if(2===this.currentCoordinate&&this.currentId){e&&(t.lng=e[0],t.lat=e[1]);const i=this.store.getGeometryCopy(this.currentId);if(2===this.currentCoordinate&&(console.log("creating"),this.startEndPoint.create(i.coordinates[0],"polygon")),M([t.lng,t.lat],i.coordinates[0][1]))return;this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[i.coordinates[0][0],i.coordinates[0][1],[t.lng,t.lat],[t.lng,t.lat],i.coordinates[0][0]]]}}]),this.currentCoordinate++}else if(this.currentId){const i=this.store.getGeometryCopy(this.currentId);if(this.pixelDistance.measure(t,i.coordinates[0][0])<this.pointerDistance)this.store.updateGeometry([{id:this.currentId,geometry:{type:"Polygon",coordinates:[[...i.coordinates[0].slice(0,-2),i.coordinates[0][0]]]}}]),this.currentCoordinate=0,this.currentId=void 0,this.startEndPoint.delete();else{if(e&&(t.lng=e[0],t.lat=e[1]),M([t.lng,t.lat],i.coordinates[0][this.currentCoordinate-1]))return;const o=function(t=[[[0,0],[0,1],[1,1],[1,0],[0,0]]]){return{type:"Feature",geometry:{type:"Polygon",coordinates:t},properties:{}}}([[...i.coordinates[0].slice(0,-1),[t.lng,t.lat],i.coordinates[0][0]]]);if(this.currentCoordinate>2&&!this.allowSelfIntersections&&g(o))return;this.store.updateGeometry([{id:this.currentId,geometry:o.geometry}]),this.currentCoordinate++}}}onKeyUp(t){t.key===this.keyEvents.cancel&&this.cleanUp()}onKeyDown(){}onDragStart(){this.setCursor("unset")}onDrag(){}onDragEnd(){this.setCursor("crosshair")}cleanUp(){try{this.currentId&&this.store.delete([this.currentId]),this.startEndPoint.ids.length&&this.startEndPoint.delete()}catch(t){}this.currentId=void 0,this.currentCoordinate=0}}function E(t,i,o){const n=s(t,i),c=function(t,e){const i=r(t[0]),o=r(e[0]),n=r(t[1]),s=r(e[1]),h=Math.sin(o-i)*Math.cos(s),c=Math.cos(n)*Math.sin(s)-Math.sin(n)*Math.cos(s)*Math.cos(o-i);return a(Math.atan2(h,c))}(t,i),d=h(t,n/2,c);return[e(d[0],o),e(d[1],o)]}function k(t,e){const i=[];for(let o=0;o<t.length-1;o++){const n=E(t[o],t[o+1],e);i.push(n)}return i}class S extends m{constructor(t,e){super(t),this.config=void 0,this.selectionPointBehavior=void 0,this._midPoints=[],this.config=t,this.selectionPointBehavior=e}get ids(){return this._midPoints.concat()}set ids(t){}insert(t,e){const i=this.store.getGeometryCopy(t),{midPointFeatureId:o,midPointSegment:n}=this.store.getPropertiesCopy(t),s=this.store.getGeometryCopy(o),r="Polygon"===s.type?s.coordinates[0]:s.coordinates;r.splice(n+1,0,i.coordinates),s.coordinates="Polygon"===s.type?[r]:r,this.store.updateGeometry([{id:o,geometry:s}]),this.store.delete([...this._midPoints,...this.selectionPointBehavior.ids]),this.create(r,o,e),this.selectionPointBehavior.create(r,s.type,o)}create(t,e,i){if(!this.store.has(e))throw new Error("Store does not have feature with this id");this._midPoints=this.store.create(function(t,e,i){return k(t,i).map((t,i)=>({geometry:{type:"Point",coordinates:t},properties:e(i)}))}(t,t=>({mode:this.mode,midPoint:!0,midPointSegment:t,midPointFeatureId:e}),i))}delete(){this._midPoints.length&&(this.store.delete(this._midPoints),this._midPoints=[])}getUpdated(t){if(0!==this._midPoints.length)return k(t,this.coordinatePrecision).map((t,e)=>({id:this._midPoints[e],geometry:{type:"Point",coordinates:t}}))}}class w extends m{constructor(t){super(t),this._selectionPoints=[]}get ids(){return this._selectionPoints.concat()}set ids(t){}create(t,e,i){this._selectionPoints=this.store.create(function(t,e,i){const o=[],n="Polygon"===e?t.length-1:t.length;for(let e=0;e<n;e++)o.push({geometry:{type:"Point",coordinates:t[e]},properties:i(e)});return o}(t,e,t=>({mode:this.mode,selectionPoint:!0,selectionPointFeatureId:i,index:t})))}delete(){this.ids.length&&(this.store.delete(this.ids),this._selectionPoints=[])}getUpdated(t){if(0!==this._selectionPoints.length)return this._selectionPoints.map((e,i)=>({id:e,geometry:{type:"Point",coordinates:t[i]}}))}getOneUpdated(t,e){if(void 0!==this._selectionPoints[t])return{id:this._selectionPoints[t],geometry:{type:"Point",coordinates:e}}}}function D(t,e){let i=!1;for(let r=0,a=e.length;r<a;r++){const a=e[r];for(let e=0,r=a.length,h=r-1;e<r;h=e++)(n=a[e])[1]>(o=t)[1]!=(s=a[h])[1]>o[1]&&o[0]<(s[0]-n[0])*(o[1]-n[1])/(s[1]-n[1])+n[0]&&(i=!i)}var o,n,s;return i}const I=(t,e,i)=>{const o=t=>t*t,n=(t,e)=>o(t.x-e.x)+o(t.y-e.y);return Math.sqrt(((t,e,i)=>{const o=n(e,i);if(0===o)return n(t,e);let s=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/o;return s=Math.max(0,Math.min(1,s)),n(t,{x:e.x+s*(i.x-e.x),y:e.y+s*(i.y-e.y)})})(t,e,i))};class b extends m{constructor(t,e,i){super(t),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=t,this.createClickBoundingBox=e,this.pixelDistance=i}find(t,e){let i,o,n=Infinity,s=Infinity;const r=this.createClickBoundingBox.create(t),a=this.store.search(r);for(let r=0;r<a.length;r++){const h=a[r],c=h.geometry;if("Point"===c.type){const r=!e&&h.properties.midPoint;if(h.properties.selectionPoint||r)continue;const a=this.pixelDistance.measure(t,c.coordinates);h.properties.midPoint&&a<this.pointerDistance&&a<s?(s=a,o=h):!h.properties.midPoint&&a<this.pointerDistance&&a<n&&(n=a,i=h)}else if("LineString"===c.type)for(let e=0;e<c.coordinates.length-1;e++){const o=c.coordinates[e],s=c.coordinates[e+1],r=I({x:t.containerX,y:t.containerY},this.project(o[0],o[1]),this.project(s[0],s[1]));r<this.pointerDistance&&r<n&&(n=r,i=h)}else"Polygon"===c.type&&D([t.lng,t.lat],c.coordinates)&&(n=0,i=h)}return{clickedFeature:i,clickedMidPoint:o}}}class B extends m{constructor(t,e,i,o){super(t),this.config=void 0,this.featuresAtMouseEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.dragPosition=void 0,this.config=t,this.featuresAtMouseEvent=e,this.selectionPoints=i,this.midPoints=o}get position(){return this.dragPosition?this.dragPosition.concat():void 0}set position(t){if(void 0!==t){if(!Array.isArray(t)||2!==t.length||"number"!=typeof t[0]||"number"!=typeof t[1])throw new Error("Position must be [number, number] array");this.dragPosition=t.concat()}else this.dragPosition=void 0}drag(t,e){const{clickedFeature:i}=this.featuresAtMouseEvent.find(t,!0);if(!i||i.id!==e)return;const o=this.store.getGeometryCopy(e),n=[t.lng,t.lat];if("Polygon"===o.type||"LineString"===o.type){let t,i;if("Polygon"===o.type?(t=o.coordinates[0],i=t.length-1):"LineString"===o.type&&(t=o.coordinates,i=t.length),void 0===i||!t||!this.dragPosition)return!1;for(let e=0;e<i;e++){const i=t[e],o=[this.dragPosition[0]-n[0],this.dragPosition[1]-n[1]];t[e]=[i[0]-o[0],i[1]-o[1]]}"Polygon"===o.type&&(t[t.length-1]=[t[0][0],t[0][1]]);const s=this.selectionPoints.getUpdated(t)||[],r=this.midPoints.getUpdated(t)||[];this.store.updateGeometry([{id:e,geometry:o},...s,...r])}else"Point"===o.type&&this.store.updateGeometry([{id:e,geometry:{type:"Point",coordinates:n}}])}}class O extends m{constructor(t,e,i,o){super(t),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.config=t,this.pixelDistance=e,this.selectionPoints=i,this.midPoints=o}drag(t,e){const i=this.store.getGeometryCopy(e);let o;if("LineString"===i.type)o=i.coordinates;else{if("Polygon"!==i.type)return!1;o=i.coordinates[0]}const n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};for(let e=0;e<o.length;e++){const s=this.pixelDistance.measure(t,o[e]);if(s<this.pointerDistance&&s<n.dist){const t="Polygon"===i.type&&(e===o.length-1||0===e);n.dist=s,n.index=t?0:e,n.isFirstOrLastPolygonCoord=t}}if(-1===n.index)return!1;const s=[t.lng,t.lat];if(n.isFirstOrLastPolygonCoord){const t=o.length-1;o[0]=s,o[t]=s}else o[n.index]=s;const r=this.selectionPoints.getOneUpdated(n.index,s),a=r?[r]:[],h=this.midPoints.getUpdated(o)||[];return this.store.updateGeometry([{id:e,geometry:i},...a,...h]),!0}}function K(t){let e=0,i=0,o=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(t=>{e+=t[0],i+=t[1],o++},!0),[e/o,i/o]}function X(t,e){const i=t,o=e,n=r(i[1]),s=r(o[1]);let h=r(o[0]-i[0]);h>Math.PI&&(h-=2*Math.PI),h<-Math.PI&&(h+=2*Math.PI);const c=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),d=(a(Math.atan2(h,c))+360)%360;return d>180?-(360-d):d}function Y(t,e,i){const o=e/6371008.8,n=t[0]*Math.PI/180,s=r(t[1]),a=r(i),h=o*Math.cos(a);let c=s+h;Math.abs(c)>Math.PI/2&&(c=c>0?Math.PI-c:-Math.PI-c);const d=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),l=Math.abs(d)>1e-11?h/d:Math.cos(s),p=[(180*(n+o*Math.sin(a)/l)/Math.PI+540)%360-180,180*c/Math.PI];return p[0]+=p[0]-t[0]>180?-360:t[0]-p[0]>180?360:0,p}function j(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;const i=e[1]*Math.PI/180,o=t[1]*Math.PI/180,n=o-i;let s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);const r=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(r)>1e-11?n/r:Math.cos(i);return 6371008.8*Math.sqrt(n*n+a*a*s*s)}class F extends m{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastBearing=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastBearing=void 0}rotate(t,i){const o=this.store.getGeometryCopy(i);if("Polygon"!==o.type&&"LineString"!==o.type)return;const n=[t.lng,t.lat],s=X(K({type:"Feature",geometry:o,properties:{}}),n);if(!this.lastBearing)return void(this.lastBearing=s+180);let r;if(function(t,e){if(0===e)return t;const i=K(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const o=X(i,t)+e,n=j(i,t),s=Y(i,n,o);t[0]=s[0],t[1]=s[1]})}({type:"Feature",geometry:o,properties:{}},-(this.lastBearing-(s+180))),"Polygon"===o.type)r=o.coordinates[0];else{if("LineString"!==o.type)return;r=o.coordinates}r.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const a=this.midPoints.getUpdated(r)||[],h=this.selectionPoints.getUpdated(r)||[];this.store.updateGeometry([{id:i,geometry:o},...h,...a]),this.lastBearing=s+180}}class G extends m{constructor(t,e,i){super(t),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.lastDistance=void 0,this.config=t,this.selectionPoints=e,this.midPoints=i}reset(){this.lastDistance=void 0}scale(t,i){const o=this.store.getGeometryCopy(i);if("Polygon"!==o.type&&"LineString"!==o.type)return;const n=[t.lng,t.lat],r=s(K({type:"Feature",geometry:o,properties:{}}),n);if(!this.lastDistance)return void(this.lastDistance=r);let a;if(function(t,e){if(1===e)return t;const i=K(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(t=>{const o=j(i,t),n=X(i,t),s=Y(i,o*e,n);t[0]=s[0],t[1]=s[1]})}({type:"Feature",geometry:o,properties:{}},1-(this.lastDistance-r)/r),"Polygon"===o.type)a=o.coordinates[0];else{if("LineString"!==o.type)return;a=o.coordinates}a.forEach(t=>{t[0]=e(t[0],this.coordinatePrecision),t[1]=e(t[1],this.coordinatePrecision)});const h=this.midPoints.getUpdated(a)||[],c=this.selectionPoints.getUpdated(a)||[];this.store.updateGeometry([{id:i,geometry:o},...c,...h]),this.lastDistance=r}}class U extends d{constructor(t){super(t),this.mode="select",this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags=void 0,this.keyEvents=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.flags=t&&t.flags?t.flags:{},this.keyEvents=t&&t.keyEvents?t.keyEvents:{deselect:"Escape",delete:"Delete",rotate:"r",scale:"s"},this.dragEventThrottle=t&&void 0!==t.dragEventThrottle&&t.dragEventThrottle||5}registerBehaviors(t){this.pixelDistance=new _(t),this.clickBoundingBox=new f(t),this.featuresAtMouseEvent=new b(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new w(t),this.midPoints=new S(t,this.selectionPoints),this.rotateFeature=new F(t,this.selectionPoints,this.midPoints),this.scaleFeature=new G(t,this.selectionPoints,this.midPoints),this.dragFeature=new B(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints),this.dragCoordinate=new O(t,this.pixelDistance,this.selectionPoints,this.midPoints)}deselect(){this.store.updateProperty(this.selected.map(t=>({id:t,property:"selected",value:!1}))),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete()}deleteSelected(){this.store.delete(this.selected),this.selected=[]}onRightClick(t){if(!this.selectionPoints.ids.length)return;let e,i=Infinity;if(this.selectionPoints.ids.forEach(o=>{const n=this.store.getGeometryCopy(o),s=this.pixelDistance.measure(t,n.coordinates);s<this.pointerDistance&&s<i&&(i=s,e=this.store.getPropertiesCopy(o))}),!e)return;const o=e.selectionPointFeatureId,n=e.index,s=this.store.getPropertiesCopy(o),r=this.flags[s.mode];if(!(r&&r.feature&&r.feature.coordinates&&r.feature.coordinates.deletable))return;const a=this.store.getGeometryCopy(o);let h;if("Polygon"===a.type){if(h=a.coordinates[0],h.length<=4)return}else if("LineString"===a.type&&(h=a.coordinates,h.length<=3))return;h&&("Polygon"===a.type&&0===n||n===h.length-1?(h.shift(),h.pop(),h.push([h[0][0],h[0][1]])):h.splice(n,1),this.store.delete([...this.midPoints.ids,...this.selectionPoints.ids]),this.store.updateGeometry([{id:o,geometry:a}]),this.selectionPoints.create(h,a.type,o),r&&r.feature&&r.feature.coordinates&&r.feature.coordinates.midpoints&&this.midPoints.create(h,o,this.coordinatePrecision))}onLeftClick(t){const{clickedFeature:e,clickedMidPoint:i}=this.featuresAtMouseEvent.find(t,this.selected.length>0);if(this.selected.length&&i)this.midPoints.insert(i.id,this.coordinatePrecision);else if(e){const{mode:t}=this.store.getPropertiesCopy(e.id),i=this.selected[0];if(i){if(i===e.id)return;this.deselect()}const o=this.flags[t];if(!o||!o.feature)return;this.selected=[e.id],this.store.updateProperty([{id:e.id,property:"selected",value:!0}]),this.onSelect(e.id);const{type:n,coordinates:s}=this.store.getGeometryCopy(e.id);let r;"LineString"===n?r=s:"Polygon"===n&&(r=s[0]),r&&o&&o.feature.coordinates&&(this.selectionPoints.create(r,n,e.id),o.feature.coordinates.midpoints&&this.midPoints.create(r,e.id,this.coordinatePrecision))}else if(this.selected.length)return void this.deselect()}start(){this.setStarted()}stop(){this.setStopped(),this.cleanUp()}onClick(t){"right"!==t.button?"left"===t.button&&this.onLeftClick(t):this.onRightClick(t)}onKeyDown(){}onKeyUp(t){if(t.key===this.keyEvents.delete){if(!this.selected.length)return;this.onDeselect(this.selected[0]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else t.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect()}onDragStart(t,e){if(!this.selected.length)return;const i=this.store.getPropertiesCopy(this.selected[0]),o=this.flags[i.mode];o&&o.feature&&(o.feature.draggable||o.feature.coordinates&&o.feature.coordinates.draggable)&&(this.dragEventCount=0,this.setCursor("grabbing"),this.dragFeature.position=[t.lng,t.lat],e(!1))}onDrag(t){const e=this.selected[0];if(!e||!this.dragFeature.position)return;const i=this.store.getPropertiesCopy(e),o=this.flags[i.mode];if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0)if(o&&o.feature&&o.feature.rotateable&&t.heldKeys.includes("r"))this.rotateFeature.rotate(t,e);else if(o&&o.feature&&o.feature.scaleable&&t.heldKeys.includes("s"))this.scaleFeature.scale(t,e);else{if(o&&o.feature&&o.feature.coordinates&&o.feature.coordinates.draggable&&this.dragCoordinate.drag(t,e))return;o&&o.feature&&o.feature.draggable&&(this.dragFeature.drag(t,e),this.dragFeature.position=[t.lng,t.lat])}}onDragEnd(t,e){this.setCursor("grab"),this.dragFeature.position=void 0,this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0)}onMouseMove(t){if(!this.selected.length||this.dragFeature.position)return;let e=!1;this.midPoints.ids.forEach(i=>{if(e)return;const o=this.store.getGeometryCopy(i);this.pixelDistance.measure(t,o.coordinates)<this.pointerDistance&&(e=!0)}),this.selectionPoints.ids.forEach(i=>{const o=this.store.getGeometryCopy(i);this.pixelDistance.measure(t,o.coordinates)<this.pointerDistance&&(e=!1)}),this.setCursor(e?"crosshair":"unset")}}class T extends d{constructor(...t){super(...t),this.mode="static"}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}}const W=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})};function N(t,e,i,o,n){for(;o>i;){if(o-i>600){const s=o-i+1,r=e-i+1,a=Math.log(s),h=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*h*(s-h)/s)*(r-s/2<0?-1:1);N(t,e,Math.max(i,Math.floor(e-r*h/s+c)),Math.min(o,Math.floor(e+(s-r)*h/s+c)),n)}const s=t[e];let r=i,a=o;for(A(t,i,e),n(t[o],s)>0&&A(t,i,o);r<a;){for(A(t,r,a),r++,a--;n(t[r],s)<0;)r++;for(;n(t[a],s)>0;)a--}0===n(t[i],s)?A(t,i,a):(a++,A(t,a,o)),a<=e&&(i=a+1),e<=a&&(o=a-1)}}function A(t,e,i){const o=t[e];t[e]=t[i],t[i]=o}function J(t,e){$(t,0,t.children.length,e,t)}function $(t,e,i,o,n){n||(n=et([])),n.minX=Infinity,n.minY=Infinity,n.maxX=-Infinity,n.maxY=-Infinity;for(let s=e;s<i;s++){const e=t.children[s];R(n,t.leaf?o(e):e)}return n}function R(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function Z(t,e){return t.minX-e.minX}function q(t,e){return t.minY-e.minY}function z(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function H(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Q(t,e){const i=Math.max(t.minX,e.minX),o=Math.max(t.minY,e.minY),n=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,n-i)*Math.max(0,s-o)}function V(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function tt(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function et(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function it(t,e,i,o,n){const s=[e,i];for(;s.length;){if((i=s.pop())-(e=s.pop())<=o)continue;const r=e+Math.ceil((i-e)/o/2)*o;N(t,r,e,i,n),s.push(e,r,r,i)}}class ot{constructor(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(t){let e=this.data;const i=[];if(!tt(t,e))return i;const o=this.toBBox,n=[];for(;e;){for(let s=0;s<e.children.length;s++){const r=e.children[s],a=e.leaf?o(r):r;tt(t,a)&&(e.leaf?i.push(r):V(t,a)?this._all(r,i):n.push(r))}e=n.pop()}return i}collides(t){let e=this.data;if(tt(t,e)){const i=[];for(;e;){for(let o=0;o<e.children.length;o++){const n=e.children[o],s=e.leaf?this.toBBox(n):n;if(tt(t,s)){if(e.leaf||V(t,s))return!0;i.push(n)}}e=i.pop()}}return!1}load(t){if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e}insert(t){this._insert(t,this.data.height-1)}clear(){this.data=et([])}remove(t){let e=this.data;const i=this.toBBox(t),o=[],n=[];let s,r,a=!1;for(;e||o.length;){if(e||(e=o.pop(),r=o[o.length-1],s=n.pop(),a=!0),e.leaf){const i=e.children.indexOf(t);-1!==i&&(e.children.splice(i,1),o.push(e),this._condense(o))}a||e.leaf||!V(e,i)?r?(s++,e=r.children[s],a=!1):e=null:(o.push(e),n.push(s),s=0,r=e,e=e.children[0])}}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,o){const n=i-e+1;let s,r=this._maxEntries;if(n<=r)return s=et(t.slice(e,i+1)),J(s,this.toBBox),s;o||(o=Math.ceil(Math.log(n)/Math.log(r)),r=Math.ceil(n/Math.pow(r,o-1))),s=et([]),s.leaf=!1,s.height=o;const a=Math.ceil(n/r),h=a*Math.ceil(Math.sqrt(r));it(t,e,i,h,this.compareMinX);for(let n=e;n<=i;n+=h){const e=Math.min(n+h-1,i);it(t,n,e,a,this.compareMinY);for(let i=n;i<=e;i+=a){const n=Math.min(i+a-1,e);s.children.push(this._build(t,i,n,o-1))}}return J(s,this.toBBox),s}_chooseSubtree(t,e,i,o){for(;o.push(e),!e.leaf&&o.length-1!==i;){let i,o=Infinity,r=Infinity;for(let a=0;a<e.children.length;a++){const h=e.children[a],c=z(h),d=(n=t,s=h,(Math.max(s.maxX,n.maxX)-Math.min(s.minX,n.minX))*(Math.max(s.maxY,n.maxY)-Math.min(s.minY,n.minY))-c);d<r?(r=d,o=c<o?c:o,i=h):d===r&&c<o&&(o=c,i=h)}e=i||e.children[0]}var n,s;return e}_insert(t,e,i){const o=i?t:this.toBBox(t),n=[],s=this._chooseSubtree(o,this.data,e,n);for(s.children.push(t),R(s,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)}_split(t,e){const i=t[e],o=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,o);const s=this._chooseSplitIndex(i,n,o),r=et(i.children.splice(s,i.children.length-s));r.height=i.height,r.leaf=i.leaf,J(i,this.toBBox),J(r,this.toBBox),e?t[e-1].children.push(r):this._splitRoot(i,r)}_splitRoot(t,e){this.data=et([t,e]),this.data.height=t.height+1,this.data.leaf=!1,J(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let o,n=Infinity,s=Infinity;for(let r=e;r<=i-e;r++){const e=$(t,0,r,this.toBBox),a=$(t,r,i,this.toBBox),h=Q(e,a),c=z(e)+z(a);h<n?(n=h,o=r,s=c<s?c:s):h===n&&c<s&&(s=c,o=r)}return o||i-e}_chooseSplitAxis(t,e,i){const o=t.leaf?this.compareMinX:Z,n=t.leaf?this.compareMinY:q;this._allDistMargin(t,e,i,o)<this._allDistMargin(t,e,i,n)&&t.children.sort(o)}_allDistMargin(t,e,i,o){t.children.sort(o);const n=this.toBBox,s=$(t,0,e,n),r=$(t,i-e,i,n);let a=H(s)+H(r);for(let o=e;o<i-e;o++){const e=t.children[o];R(s,t.leaf?n(e):e),a+=H(s)}for(let o=i-e-1;o>=e;o--){const e=t.children[o];R(r,t.leaf?n(e):e),a+=H(r)}return a}_adjustParentBBoxes(t,e,i){for(let o=i;o>=0;o--)R(e[o],t)}_condense(t){for(let e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children,e.splice(e.indexOf(t[i]),1)):this.clear():J(t[i],this.toBBox)}}class nt{constructor(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new ot(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(t,e){this.idToNode.set(String(t.id),e),this.nodeToId.set(e,String(t.id))}toBBox(t){const e=[],i=[];let o;if("Polygon"===t.geometry.type)o=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)o=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");o=[t.geometry.coordinates]}for(let t=0;t<o.length;t++)i.push(o[t][1]),e.push(o[t][0]);const n=Math.min(...i),s=Math.max(...i);return{minX:Math.min(...e),minY:n,maxX:Math.max(...e),maxY:s}}insert(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}load(t){const e=[],i=new Set;t.forEach(t=>{const o=this.toBBox(t);if(this.setMaps(t,o),i.has(String(t.id)))throw new Error(`Duplicate feature ID found ${t.id}`);i.add(String(t.id)),e.push(o)}),this.tree.load(e)}update(t){this.remove(t.id);const e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)}remove(t){const e=this.idToNode.get(t);if(!e)throw new Error(`${t} not inserted into the spatial index`);this.tree.remove(e)}clear(){this.tree.clear()}search(t){return this.tree.search(this.toBBox(t)).map(t=>this.nodeToId.get(t))}collides(t){return this.tree.collides(this.toBBox(t))}}class st{constructor(t){this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new nt,this.tracked=!t||!1!==t.tracked,t&&t.data&&this.load(t.data,t.validateFeature)}getId(){return W()}clone(t){return JSON.parse(JSON.stringify(t))}has(t){return Boolean(this.store[t])}load(t,e){if(0===t.length)return;const i=this.clone(t);i.forEach(t=>{t.id||(t.id=W()),this.tracked&&(t.properties.createdAt||(t.properties.createdAt=+new Date),t.properties.updatedAt||(t.properties.updatedAt=+new Date))});const o=[];i.forEach(t=>{e&&e(t),this.store[t.id]=t,o.push(t.id)}),this.spatialIndex.load(i),this._onChange(o,"create")}search(t,e){const i=this.spatialIndex.search(t).map(t=>this.store[t]);return this.clone(e?i.filter(e):i)}registerOnChange(t){this._onChange=(e,i)=>{t(e,i)}}getGeometryCopy(t){const e=this.store[t];if(!e)throw new Error(`No feature with this id (${t}), can not get geometry copy`);return this.clone(e.geometry)}getPropertiesCopy(t){const e=this.store[t];if(!e)throw new Error(`No feature with this id (${t}), can not get properties copy`);return this.clone(e.properties)}updateProperty(t){const e=[];t.forEach(({id:t,property:i,value:o})=>{const n=this.store[t];if(!n)throw new Error(`No feature with this (${t}), can not update geometry`);e.push(t),n.properties[i]=o,this.tracked&&(n.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,"update")}updateGeometry(t){const e=[];t.forEach(({id:t,geometry:i})=>{e.push(t);const o=this.store[t];if(!o)throw new Error(`No feature with this (${t}), can not update geometry`);o.geometry=this.clone(i),this.spatialIndex.update(o),this.tracked&&(o.properties.updatedAt=+new Date)}),this._onChange&&this._onChange(e,"update")}create(e){const i=[];return e.forEach(({geometry:e,properties:o})=>{let n,s=t({},o);this.tracked&&(n=+new Date,o?(s.createdAt="number"==typeof o.createdAt?o.createdAt:n,s.updatedAt="number"==typeof o.updatedAt?o.updatedAt:n):s={createdAt:n,updatedAt:n});const r=this.getId(),a={id:r,type:"Feature",geometry:e,properties:s};this.store[r]=a,this.spatialIndex.insert(a),i.push(r)}),this._onChange&&this._onChange([...i],"create"),i}delete(t){t.forEach(t=>{if(!this.store[t])throw new Error("No feature with this id, can not delete");delete this.store[t],this.spatialIndex.remove(t)}),this._onChange&&this._onChange([...t],"delete")}copyAll(){return this.clone(Object.keys(this.store).map(t=>this.store[t]))}}class rt{constructor(e){this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._adapter=e.adapter,this._mode=new T,this._modes=t({},e.modes,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[]},this._store=e.data?new st({data:e.data}):new st;const i=t=>{const e=[],i=this._store.copyAll().filter(i=>!t.includes(i.id)||(e.push(i),!1));return{changed:e,unchanged:i}},o=(t,e)=>{this._eventListeners.change.forEach(i=>{i(t,e)});const{changed:o,unchanged:n}=i(t);"create"===e?this._adapter.render({created:o,deletedIds:[],unchanged:n,updated:[]},this.getModeStyles()):"update"===e?this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:o},this.getModeStyles()):"delete"===e?this._adapter.render({created:[],deletedIds:t,unchanged:n,updated:[]},this.getModeStyles()):"styling"===e&&this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:[]},this.getModeStyles())},n=t=>{this._eventListeners.select.forEach(e=>{e(t)});const{changed:e,unchanged:o}=i([t]);this._adapter.render({created:[],deletedIds:[],unchanged:o,updated:e},this.getModeStyles())},s=t=>{this._eventListeners.deselect.forEach(t=>{t()});const{changed:e,unchanged:o}=i([t]);e&&this._adapter.render({created:[],deletedIds:[],unchanged:o,updated:e},this.getModeStyles())};if(Object.keys(this._modes).forEach(t=>{this._modes[t].register({mode:t,store:this._store,setCursor:this._adapter.setCursor,project:this._adapter.project,unproject:this._adapter.unproject,onChange:o,onSelect:n,onDeselect:s})}),e.data){const t=this._store.copyAll().filter(t=>!(t.properties&&!Object.keys(this._modes).includes(t.properties.mode)&&(this._store.delete([t.id]),1)));this._adapter.render({created:t,deletedIds:[],unchanged:[],updated:[]},this.getModeStyles())}}getModeStyles(){const t={};return Object.keys(this._modes).forEach(e=>{t[e]=this._modes[e].styling}),t}setModeStyling(t,e){this._modes[t].styling=e}getSnapshot(){return this._store.copyAll()}get enabled(){return this._enabled}set enabled(t){throw new Error("Enabled is read only")}getCurrentMode(){return this._mode.mode}changeMode(t){if(!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()}start(){this._enabled=!0,this._adapter.register({onClick:t=>{this._mode.onClick(t)},onMouseMove:t=>{this._mode.onMouseMove(t)},onKeyDown:t=>{this._mode.onKeyDown(t)},onKeyUp:t=>{this._mode.onKeyUp(t)},onDragStart:(t,e)=>{this._mode.onDragStart(t,e)},onDrag:t=>{this._mode.onDrag(t)},onDragEnd:(t,e)=>{this._mode.onDragEnd(t,e)}})}stop(){this._enabled=!1,this._adapter.unregister()}on(t,e){const i=this._eventListeners[t];i.includes(e)||i.push(e)}off(t,e){const i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)}}export{rt as TerraDraw,l as TerraDrawCircleMode,p as TerraDrawFreehandMode,i as TerraDrawGoogleMapsAdapter,o as TerraDrawLeafletAdapter,P as TerraDrawLineStringMode,n as TerraDrawMapboxGLAdapter,C as TerraDrawPointMode,x as TerraDrawPolygonMode,U as TerraDrawSelectMode};
|
|
2
|
+
//# sourceMappingURL=terra-draw.modern.js.map
|