@defra/interactive-map 0.0.37-alpha → 0.0.38-alpha
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/assets/templates/draw-tools.njk +4 -3
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api.md +32 -0
- package/docs/examples/draw-tools.mdx +0 -4
- package/docs/plugins/draw.md +482 -0
- package/docs/plugins.md +2 -6
- package/govuk-prototype-kit.config.json +3 -2
- package/package.json +2 -4
- package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
- package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/css/index.css +1 -97
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -0
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -0
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -0
- package/plugins/draw/dist/esm/index.js +1 -0
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -0
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +2 -0
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js.LICENSE.txt +1 -0
- package/plugins/draw/dist/umd/im-draw-plugin.js +2 -0
- package/plugins/draw/dist/umd/im-draw-plugin.js.LICENSE.txt +1 -0
- package/plugins/draw/dist/umd/index.js +2 -0
- package/plugins/draw/dist/umd/index.js.LICENSE.txt +1 -0
- package/plugins/draw/src/DrawInit.jsx +89 -0
- package/plugins/draw/src/DrawInit.test.jsx +184 -0
- package/plugins/draw/src/adapterEvents.js +127 -0
- package/plugins/draw/src/adapterEvents.test.js +20 -0
- package/plugins/draw/src/adapters/adapterContract.test.js +48 -0
- package/plugins/draw/src/adapters/loadDrawAdapter.js +14 -0
- package/plugins/draw/src/adapters/loadDrawAdapter.test.js +53 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +367 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +799 -0
- package/plugins/draw/src/adapters/maplibre/defaults.js +1 -0
- package/plugins/draw/src/adapters/maplibre/drawEvents.js +35 -0
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +126 -0
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +268 -0
- package/plugins/draw/src/adapters/maplibre/mapboxSnap.js +39 -0
- package/plugins/draw/src/adapters/maplibre/mapboxSnap.test.js +91 -0
- package/plugins/draw/src/adapters/maplibre/modes/createDrawMode.js +58 -0
- package/plugins/draw/src/adapters/maplibre/modes/createDrawMode.test.js +53 -0
- package/plugins/draw/src/adapters/maplibre/modes/disabledMode.js +23 -0
- package/plugins/draw/src/adapters/maplibre/modes/disabledMode.test.js +21 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawLineMode.js +15 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawLineMode.test.js +37 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/__helpers__/harness.js +115 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +193 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +241 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/keyboardHandlers.js +78 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/keyboardHandlers.test.js +75 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.js +78 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/lifecycle.test.js +48 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.js +103 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/pointerHandlers.test.js +127 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/renderHelpers.js +59 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/renderHelpers.test.js +34 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +193 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +195 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawPolygonMode.js +16 -0
- package/plugins/draw/src/adapters/maplibre/modes/drawPolygonMode.test.js +27 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/__helpers__/harness.js +107 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/geometryHelpers.js +139 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/geometryHelpers.test.js +46 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/helpers.js +2 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/helpers.test.js +17 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.js +151 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/keyboardHandlers.test.js +123 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +161 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +98 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.js +133 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/touchHandlers.test.js +105 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +166 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +133 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.js +210 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexOperations.test.js +167 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexQueries.js +121 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/vertexQueries.test.js +73 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +249 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.test.js +153 -0
- package/plugins/draw/src/adapters/maplibre/snap/constants.js +2 -0
- package/plugins/draw/src/adapters/maplibre/snap/mapHandlers.js +39 -0
- package/plugins/draw/src/adapters/maplibre/snap/mapHandlers.test.js +106 -0
- package/plugins/draw/src/adapters/maplibre/snap/prototypePatches.js +148 -0
- package/plugins/draw/src/adapters/maplibre/snap/prototypePatches.test.js +238 -0
- package/plugins/draw/src/adapters/maplibre/snap/snapInstance.js +115 -0
- package/plugins/draw/src/adapters/maplibre/snap/snapInstance.test.js +151 -0
- package/plugins/draw/src/adapters/maplibre/snap/sourceData.js +34 -0
- package/plugins/draw/src/adapters/maplibre/snap/sourceData.test.js +62 -0
- package/plugins/draw/src/adapters/maplibre/styles.js +207 -0
- package/plugins/draw/src/adapters/maplibre/styles.test.js +155 -0
- package/plugins/draw/src/adapters/maplibre/utils/snapHelpers.js +202 -0
- package/plugins/draw/src/adapters/maplibre/utils/snapHelpers.test.js +253 -0
- package/plugins/draw/src/adapters/maplibre/utils/touchClickWorkaround.js +57 -0
- package/plugins/draw/src/adapters/maplibre/utils/touchClickWorkaround.test.js +106 -0
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +117 -0
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +159 -0
- package/plugins/draw/src/adapters/openlayers/__helpers__/harness.js +90 -0
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +178 -0
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +153 -0
- package/plugins/draw/src/adapters/openlayers/core/featureStore.js +69 -0
- package/plugins/draw/src/adapters/openlayers/core/featureStore.test.js +58 -0
- package/plugins/draw/src/adapters/openlayers/core/internalEvents.js +8 -0
- package/plugins/draw/src/adapters/openlayers/core/styles.js +155 -0
- package/plugins/draw/src/adapters/openlayers/core/styles.test.js +143 -0
- package/plugins/draw/src/adapters/openlayers/defaults.js +1 -0
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +272 -0
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +431 -0
- package/plugins/draw/src/adapters/openlayers/draw/drawInput.js +139 -0
- package/plugins/draw/src/adapters/openlayers/draw/drawInput.test.js +140 -0
- package/plugins/draw/src/adapters/openlayers/draw/vertexPlacement.js +144 -0
- package/plugins/draw/src/adapters/openlayers/draw/vertexPlacement.test.js +196 -0
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +385 -0
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +303 -0
- package/plugins/draw/src/adapters/openlayers/edit/activeVertexLayer.js +55 -0
- package/plugins/draw/src/adapters/openlayers/edit/activeVertexLayer.test.js +53 -0
- package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.js +157 -0
- package/plugins/draw/src/adapters/openlayers/edit/keyboardHandler.test.js +195 -0
- package/plugins/draw/src/adapters/openlayers/edit/midpointLayer.js +57 -0
- package/plugins/draw/src/adapters/openlayers/edit/midpointLayer.test.js +42 -0
- package/plugins/draw/src/adapters/openlayers/edit/modifyInteraction.js +83 -0
- package/plugins/draw/src/adapters/openlayers/edit/modifyInteraction.test.js +80 -0
- package/plugins/draw/src/adapters/openlayers/edit/nudge.js +118 -0
- package/plugins/draw/src/adapters/openlayers/edit/nudge.test.js +165 -0
- package/plugins/draw/src/adapters/openlayers/edit/pointerHandlers.js +79 -0
- package/plugins/draw/src/adapters/openlayers/edit/pointerHandlers.test.js +78 -0
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +116 -0
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +109 -0
- package/plugins/draw/src/adapters/openlayers/edit/touchHandler.js +184 -0
- package/plugins/draw/src/adapters/openlayers/edit/touchHandler.test.js +133 -0
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +94 -0
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +64 -0
- package/plugins/draw/src/adapters/openlayers/edit/vertexHitTest.js +74 -0
- package/plugins/draw/src/adapters/openlayers/edit/vertexHitTest.test.js +28 -0
- package/plugins/draw/src/adapters/openlayers/edit/vertexLayer.js +49 -0
- package/plugins/draw/src/adapters/openlayers/edit/vertexLayer.test.js +42 -0
- package/plugins/draw/src/adapters/openlayers/edit/vertexOps.js +100 -0
- package/plugins/draw/src/adapters/openlayers/edit/vertexOps.test.js +80 -0
- package/plugins/draw/src/adapters/openlayers/olDraw.js +40 -0
- package/plugins/draw/src/adapters/openlayers/olDraw.test.js +70 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapEngine.js +220 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapEngine.test.js +232 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapGeometry.js +198 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapGeometry.test.js +136 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapIndicator.js +81 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapIndicator.test.js +72 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapInteraction.js +57 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapInteraction.test.js +68 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapManager.js +99 -0
- package/plugins/draw/src/adapters/openlayers/snap/snapManager.test.js +101 -0
- package/plugins/draw/src/adapters/openlayers/utils/geometryHelpers.js +103 -0
- package/plugins/draw/src/adapters/openlayers/utils/geometryHelpers.test.js +76 -0
- package/plugins/draw/src/adapters/openlayers/utils/olCoords.js +35 -0
- package/plugins/draw/src/adapters/openlayers/utils/olCoords.test.js +22 -0
- package/plugins/draw/src/adapters/openlayers/utils/sketchHelpers.js +22 -0
- package/plugins/draw/src/adapters/openlayers/utils/sketchHelpers.test.js +18 -0
- package/plugins/draw/src/adapters/openlayers/utils/touchTarget.js +8 -0
- package/plugins/draw/src/api/addFeature.js +22 -0
- package/plugins/draw/src/api/addFeature.test.js +41 -0
- package/plugins/draw/src/api/deleteFeature.js +11 -0
- package/plugins/draw/src/api/deleteFeature.test.js +24 -0
- package/plugins/draw/src/api/editFeature.js +54 -0
- package/plugins/draw/src/api/editFeature.test.js +134 -0
- package/plugins/draw/src/api/merge.js +30 -0
- package/plugins/draw/src/api/merge.test.js +57 -0
- package/plugins/draw/src/api/newLine.js +41 -0
- package/plugins/draw/src/api/newLine.test.js +93 -0
- package/plugins/draw/src/api/newPolygon.js +41 -0
- package/plugins/draw/src/api/newPolygon.test.js +93 -0
- package/plugins/draw/src/api/split.js +117 -0
- package/plugins/draw/src/api/split.test.js +204 -0
- package/plugins/draw/src/defaults.js +52 -0
- package/plugins/draw/src/defaults.test.js +18 -0
- package/plugins/draw/src/draw.scss +43 -0
- package/plugins/draw/src/events.js +237 -0
- package/plugins/draw/src/events.test.js +369 -0
- package/plugins/draw/src/index.js +10 -0
- package/plugins/draw/src/index.test.js +24 -0
- package/plugins/draw/src/manifest.js +170 -0
- package/plugins/draw/src/manifest.test.js +147 -0
- package/plugins/draw/src/reducer.js +69 -0
- package/plugins/draw/src/reducer.test.js +85 -0
- package/plugins/draw/src/utils/debounce.js +16 -0
- package/plugins/draw/src/utils/debounce.test.js +40 -0
- package/plugins/draw/src/utils/eventBus.js +36 -0
- package/plugins/draw/src/utils/eventBus.test.js +47 -0
- package/plugins/draw/src/utils/flattenStyleProperties.js +25 -0
- package/plugins/draw/src/utils/flattenStyleProperties.test.js +33 -0
- package/plugins/draw/src/utils/getValueForStyle.js +33 -0
- package/plugins/draw/src/utils/getValueForStyle.test.js +32 -0
- package/plugins/draw/src/utils/resolveColors.js +39 -0
- package/plugins/draw/src/utils/resolveColors.test.js +34 -0
- package/plugins/draw/src/utils/spatial.js +243 -0
- package/plugins/draw/src/utils/spatial.test.js +243 -0
- package/plugins/draw/src/utils/touchTarget.js +95 -0
- package/plugins/draw/src/utils/touchTarget.test.js +107 -0
- package/plugins/draw/src/utils/undoStack.js +31 -0
- package/plugins/draw/src/utils/undoStack.test.js +49 -0
- package/plugins/draw/src/validation/liveDrawChecks.js +120 -0
- package/plugins/draw/src/validation/liveDrawChecks.test.js +159 -0
- package/plugins/draw/src/validation/liveStroke.js +85 -0
- package/plugins/draw/src/validation/liveStroke.test.js +150 -0
- package/plugins/draw/src/validation/rules.areaError.test.js +12 -0
- package/plugins/draw/src/validation/rules.js +186 -0
- package/plugins/draw/src/validation/rules.test.js +120 -0
- package/plugins/draw/src/validation/validateGeometry.js +119 -0
- package/plugins/draw/src/validation/validateGeometry.test.js +200 -0
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/src/hooks/useInteractionHandlers.js +1 -1
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +1 -1
- package/plugins/interact/src/utils/buildStylesMap.js +1 -0
- package/plugins/search/dist/css/index.css +1 -317
- package/rollup.esm.mjs +35 -28
- package/sonar-project.properties +2 -2
- package/src/App/components/Attributions/Attributions.module.scss +1 -0
- package/src/App/components/Hints/Hints.module.scss +5 -4
- package/src/App/components/KeyboardHelp/KeyboardHelp.jsx +1 -1
- package/src/App/components/KeyboardHelp/KeyboardHelp.test.jsx +11 -0
- package/src/App/components/MoveControl/MoveControl.jsx +73 -9
- package/src/App/components/MoveControl/MoveControl.module.scss +12 -2
- package/src/App/components/MoveControl/MoveControl.test.jsx +136 -0
- package/src/App/hooks/useHintsAPI.js +67 -0
- package/src/App/hooks/useHintsAPI.test.js +145 -0
- package/src/App/renderer/PluginInits.jsx +4 -0
- package/src/App/renderer/PluginInits.test.jsx +7 -1
- package/src/InteractiveMap/InteractiveMap.js +20 -0
- package/src/InteractiveMap/InteractiveMap.test.js +7 -0
- package/src/config/events.js +4 -0
- package/src/scss/settings/_dimensions.scss +3 -0
- package/src/services/announcer.js +38 -3
- package/src/services/announcer.test.js +133 -1
- package/src/services/hints.js +3 -0
- package/src/services/hints.test.js +19 -0
- package/src/types.js +12 -0
- package/src/utils/detectInterfaceType.js +5 -1
- package/src/utils/isMac.js +15 -0
- package/src/utils/isMac.test.js +37 -0
- package/webpack.umd.mjs +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,S as o,C as i,M as a,K as s,s as c,a as l,b as u,d,e as p,r as h,l as f,p as g,f as y,g as m,m as v,h as x,j as _,k as b,n as E,o as S,q as w,t as I,v as O,u as P,L as M,H as C,A as T}from"./im-draw-plugin.js";const L={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},A={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},k={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},V={POLYGON:"polygon",LINE:"line_string",POINT:"point"},F={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},N={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},D={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},j={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},R={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},U={ACTIVE:"true",INACTIVE:"false"},B=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var G=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:85,LAT_RENDERED_MIN:-85,LNG_MAX:270,LNG_MIN:-270,activeStates:U,classes:L,cursors:k,events:D,geojsonTypes:F,interactions:B,meta:R,modes:N,sources:A,types:V,updateActions:j});function H(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function Y(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function X(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===U.ACTIVE&&e.featureTarget.properties.meta===R.FEATURE))}function J(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===U.INACTIVE&&e.featureTarget.properties.meta===R.FEATURE))}function $(e){return void 0===e.featureTarget}function K(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===R.FEATURE)}function q(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===R.VERTEX)}function z(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function Z(e){return"Escape"===e.key||27===e.keyCode}function W(e){return"Enter"===e.key||13===e.keyCode}function Q(e){return"Backspace"===e.key||8===e.keyCode}function ee(e){return"Delete"===e.key||46===e.keyCode}function te(e){return"1"===e.key||49===e.keyCode}function re(e){return"2"===e.key||50===e.keyCode}function ne(e){return"3"===e.key||51===e.keyCode}function oe(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var ie=Object.freeze({__proto__:null,isActiveFeature:X,isBackspaceKey:Q,isDeleteKey:ee,isDigit1Key:te,isDigit2Key:re,isDigit3Key:ne,isDigitKey:oe,isEnterKey:W,isEscapeKey:Z,isFeature:K,isInactiveFeature:J,isOfMetaType:H,isShiftDown:z,isShiftMousedown:Y,isTrue:function(){return!0},isVertex:q,noTarget:$});function ae(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function se(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){var r=!1;try{r=this instanceof e}catch{}return r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}),r}var ce,le,ue={},de={};function pe(){return ce||(ce=1,de.RADIUS=6378137,de.FLATTENING=1/298.257223563,de.POLAR_RADIUS=6356752.3142),de}var he=function(){if(le)return ue;le=1;var e=pe();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(r(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(r(e[n]))}return t}function r(t){var r,o,i,a,s,c,l=0,u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(i=u-2,a=u-1,s=0):c===u-1?(i=u-1,a=0,s=1):(i=c,a=c+1,s=c+2),r=t[i],o=t[a],l+=(n(t[s][0])-n(r[0]))*Math.sin(n(o[1]));l=l*e.RADIUS*e.RADIUS/2}return l}function n(e){return e*Math.PI/180}return ue.geometry=function e(r){var n,o=0;switch(r.type){case"Polygon":return t(r.coordinates);case"MultiPolygon":for(n=0;n<r.coordinates.length;n++)o+=t(r.coordinates[n]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<r.geometries.length;n++)o+=e(r.geometries[n]);return o}},ue.ring=r,ue}(),fe=ae(he);const ge={Point:0,LineString:1,MultiLineString:1,Polygon:2};function ye(e,t){const r=ge[e.geometry.type]-ge[t.geometry.type];return 0===r&&e.geometry.type===F.POLYGON?e.area-t.area:r}function me(e){return e.map(e=>(e.geometry.type===F.POLYGON&&(e.area=fe.geometry({type:F.FEATURE,property:{},geometry:e.geometry})),e)).sort(ye).map(e=>(delete e.area,e))}function ve(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function xe(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}xe.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},xe.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},xe.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},xe.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((e,t)=>e.v-t.v).map(e=>e.k)},xe.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const _e=[R.FEATURE,R.MIDPOINT,R.VERTEX];var be={click:function(e,t,r){return Ee(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return Ee(e,t,r,r.options.touchBuffer)}};function Ee(e,t,r,n){if(null===r.map)return[];const o=e?ve(e,n):t,i={};r.options.styles&&(i.layers=r.options.styles.map(e=>e.id).filter(e=>null!=r.map.getLayer(e)));const a=r.map.queryRenderedFeatures(o,i).filter(e=>-1!==_e.indexOf(e.properties.meta)),s=new xe,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),me(c)}function Se(e,t){const r=be.click(e,null,t),n={mouse:k.NONE};return r[0]&&(n.mouse=r[0].properties.active===U.ACTIVE?k.MOVE:k.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=k.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function we(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function Ie(e,t,r={}){const n=null!=r.fineTolerance?r.fineTolerance:4,o=null!=r.grossTolerance?r.grossTolerance:12,i=null!=r.interval?r.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;const a=we(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function Oe(e,t,r={}){const n=null!=r.tolerance?r.tolerance:25,o=null!=r.interval?r.interval:250;e.point=e.point||t.point,e.time=e.time||t.time;return we(e.point,t.point)<n&&t.time-e.time<o}const Pe=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===r[e])throw new Error(`Invalid event type: ${e}`);r[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},o=function(e,o){const i=r[e];let a=i.length;for(;a--;){const e=i[a];if(e.selector(o)){e.fn.call(n,o)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(e){o("drag",e)},click(e){o("click",e)},mousemove(e){o("mousemove",e)},mousedown(e){o("mousedown",e)},mouseup(e){o("mouseup",e)},mouseout(e){o("mouseout",e)},keydown(e){o("keydown",e)},keyup(e){o("keyup",e)},touchstart(e){o("touchstart",e)},touchmove(e){o("touchmove",e)},touchend(e){o("touchend",e)},tap(e){o("tap",e)}}};const Me=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Ce(){return Me()}const Te=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Ce(),this.type=t.geometry.type};Te.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Te.prototype.incomingCoords=function(e){this.setCoordinates(e)},Te.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Te.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Te.prototype.setProperty=function(e,t){this.properties[e]=t},Te.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:F.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Te.prototype.internal=function(e){const t={id:this.id,meta:R.FEATURE,"meta:type":this.type,active:U.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:F.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Le=function(e,t){Te.call(this,e,t)};(Le.prototype=Object.create(Te.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Le.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},Le.prototype.getCoordinate=function(){return this.getCoordinates()};const Ae=function(e,t){Te.call(this,e,t)};(Ae.prototype=Object.create(Te.prototype)).isValid=function(){return this.coordinates.length>1},Ae.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},Ae.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Ae.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Ae.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const ke=function(e,t){Te.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(ke.prototype=Object.create(Te.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},ke.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},ke.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ke.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(e=>parseInt(e,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},ke.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},ke.prototype.getCoordinate=function(e){const t=e.split(".").map(e=>parseInt(e,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},ke.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},ke.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),o=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[o]&&(this.coordinates[o]=[]),this.coordinates[o][i]=[t,r]};const Ve={MultiPoint:Le,MultiLineString:Ae,MultiPolygon:ke},Fe=(e,t,r,n,o)=>{const i=r.split("."),a=parseInt(i[0],10),s=i[1]?i.slice(1).join("."):null;return e[a][t](s,n,o)},Ne=function(e,t){if(Te.call(this,e,t),delete this.coordinates,this.model=Ve[t.geometry.type],void 0===this.model)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};function De(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ne.prototype=Object.create(Te.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Ce(),type:F.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ne.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ne.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ne.prototype.getCoordinate=function(e){return Fe(this.features,"getCoordinate",e)},Ne.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===F.POLYGON?e.getCoordinates():e.coordinates)))},Ne.prototype.updateCoordinate=function(e,t,r){Fe(this.features,"updateCoordinate",e,t,r),this.changed()},Ne.prototype.addCoordinate=function(e,t,r){Fe(this.features,"addCoordinate",e,t,r),this.changed()},Ne.prototype.removeCoordinate=function(e){Fe(this.features,"removeCoordinate",e),this.changed()},Ne.prototype.getFeatures=function(){return this.features},De.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},De.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((e,t)=>(void 0===e[t.feature_id]&&(e[t.feature_id]=!0,this._ctx.store.get(t.feature_id).changed()),e),{})},De.prototype.getSelected=function(){return this._ctx.store.getSelected()},De.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},De.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},De.prototype.getFeature=function(e){return this._ctx.store.get(e)},De.prototype.select=function(e){return this._ctx.store.select(e)},De.prototype.deselect=function(e){return this._ctx.store.deselect(e)},De.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},De.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},De.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},De.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},De.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},De.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},De.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},De.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},De.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},De.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return be[r](e,t,this._ctx)},De.prototype.newFeature=function(e){const t=e.geometry.type;return t===F.POINT?new Le(this._ctx,e):t===F.LINE_STRING?new Ae(this._ctx,e):t===F.POLYGON?new ke(this._ctx,e):new Ne(this._ctx,e)},De.prototype.isInstanceOf=function(e,t){if(e===F.POINT)return t instanceof Le;if(e===F.LINE_STRING)return t instanceof Ae;if(e===F.POLYGON)return t instanceof ke;if("MultiFeature"===e)return t instanceof Ne;throw new Error(`Unknown feature class: ${e}`)},De.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},De.prototype.onSetup=function(){},De.prototype.onDrag=function(){},De.prototype.onClick=function(){},De.prototype.onMouseMove=function(){},De.prototype.onMouseDown=function(){},De.prototype.onMouseUp=function(){},De.prototype.onMouseOut=function(){},De.prototype.onKeyUp=function(){},De.prototype.onKeyDown=function(){},De.prototype.onTouchStart=function(){},De.prototype.onTouchMove=function(){},De.prototype.onTouchEnd=function(){},De.prototype.onTap=function(){},De.prototype.onStop=function(){},De.prototype.onTrash=function(){},De.prototype.onCombineFeature=function(){},De.prototype.onUncombineFeature=function(){},De.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const je={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Re=Object.keys(je);function Ue(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new De(r));return{start(){o=i.onSetup(n),Re.forEach(t=>{const r=je[t];let n=()=>!1;var a;e[r]&&(n=()=>!0),this.on(t,n,(a=r,e=>i[a](o,e)))})},stop(){i.onStop(o)},trash(){i.onTrash(o)},combineFeatures(){i.onCombineFeatures(o)},uncombineFeatures(){i.onUncombineFeatures(o)},render(e,t){i.toDisplayFeatures(o,e,t)}}}}function Be(e){return[].concat(e).filter(e=>void 0!==e)}function Ge(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(A.HOT)))return s();const t=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:t});let r=[],n=[];e.isDirty?n=e.getAllIds():(r=e.getChangedIds().filter(t=>void 0!==e.get(t)),n=e.sources.hot.filter(t=>t.properties.id&&-1===r.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id)).map(e=>e.properties.id)),e.sources.hot=[];const o=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(e=>{const t=e.properties.id||e.properties.parent;return-1===r.indexOf(t)});const i=o!==e.sources.cold.length||n.length>0;function a(r,n){const o=e.get(r).internal(t);e.ctx.events.currentModeRender(o,r=>{r.properties.mode=t,e.sources[n].push(r)})}function s(){e.isDirty=!1,e.clearChangedIds()}r.forEach(e=>a(e,"hot")),n.forEach(e=>a(e,"cold")),i&&e.ctx.map.getSource(A.COLD).setData({type:F.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(A.HOT).setData({type:F.FEATURE_COLLECTION,features:e.sources.hot}),s()}function He(e){let t;this._features={},this._featureIds=new xe,this._selectedFeatureIds=new xe,this._selectedCoordinates=[],this._changedFeatureIds=new xe,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ge.call(this),this._emitSelectionChange&&(this.ctx.events.fire(D.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(D.RENDER,{})}))},this.isDirty=!1}function Ye(e,t={}){const r=e._selectedCoordinates.filter(t=>e._selectedFeatureIds.has(t.feature_id));e._selectedCoordinates.length===r.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=r}He.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},He.prototype.setDirty=function(){return this.isDirty=!0,this},He.prototype.featureCreated=function(e,t={}){this._changedFeatureIds.add(e);if(!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(D.CREATE,{features:[t.toGeoJSON()]})}return this},He.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(D.UPDATE,{action:t.action?t.action:j.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},He.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},He.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},He.prototype.getAllIds=function(){return this._featureIds.values()},He.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},He.prototype.delete=function(e,t={}){const r=[];return Be(e).forEach(e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===r.indexOf(this._features[e])&&r.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)}),r.length&&this.ctx.events.fire(D.DELETE,{features:r}),Ye(this,t),this},He.prototype.get=function(e){return this._features[e]},He.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},He.prototype.select=function(e,t={}){return Be(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},He.prototype.deselect=function(e,t={}){return Be(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),Ye(this,t),this},He.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},He.prototype.setSelected=function(e,t={}){return e=Be(e),this.deselect(this._selectedFeatureIds.values().filter(t=>-1===e.indexOf(t)),{silent:t.silent}),this.select(e.filter(e=>!this._selectedFeatureIds.has(e)),{silent:t.silent}),this},He.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},He.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},He.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},He.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},He.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},He.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},He.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:j.CHANGE_PROPERTIES})},He.prototype.storeMapConfig=function(){B.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},He.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},He.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Xe=["mode","feature","mouse"];function Je(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(o){if(e.map=o,e.events=function(e){const t=Object.keys(e.options.modes).reduce((t,r)=>(t[r]=Ue(e.options.modes[r]),t),{});let r={},n={};const o={};let i=null,a=null;o.drag=function(t,r){r({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:k.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Ie(r,e))},o.touchdrag=function(e){o.drag(e,e=>!Oe(n,e))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);const r=Se(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Se(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Se(t,e);t.featureTarget=n,Ie(r,{point:t.point,time:(new Date).getTime()})?a.click(t):a.mouseup(t)},o.mouseout=function(e){a.mouseout(e)},o.touchstart=function(t){if(!e.options.touchEnabled)return;n={time:(new Date).getTime(),point:t.point};const r=be.touch(t,null,e)[0];t.featureTarget=r,a.touchstart(t)},o.touchmove=function(t){if(e.options.touchEnabled)return a.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),!e.options.touchEnabled)return;const r=be.touch(t,null,e)[0];t.featureTarget=r,Oe(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=Q(e),r=ee(e),n=oe(e);return!(t||r||n)};function c(r,n,o={}){a.stop();const s=t[r];if(void 0===s)throw new Error(`${r} is not valid`);i=r;const c=s(e,n);a=Pe(c,e),o.silent||e.map.fire(D.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(L.CANVAS)&&((Q(t)||ee(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):te(t)&&e.options.controls.point?c(N.DRAW_POINT):re(t)&&e.options.controls.line_string?c(N.DRAW_LINE_STRING):ne(t)&&e.options.controls.polygon&&c(N.DRAW_POLYGON))},o.keyup=function(e){s(e)&&a.keyup(e)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){const{setup:t,map:r,options:n,store:o}=e;n.styles.some(e=>r.getLayer(e.id))||(t.addLayers(),o.setDirty(),o.render())}};const l={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){i=e.options.defaultMode,a=Pe(t[i](e),e)},changeMode:c,actionable:function(t){let r=!1;Object.keys(t).forEach(e=>{if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(r=!0),l[e]=t[e]}),r&&e.map.fire(D.ACTIONABLE,{actions:l})},currentModeName:()=>i,currentModeRender:(e,t)=>a.render(e,t),fire(t,r){e.map&&e.map.fire(t,r)},addEventListeners(){e.map.on("mousemove",o.mousemove),e.map.on("mousedown",o.mousedown),e.map.on("mouseup",o.mouseup),e.map.on("data",o.data),e.map.on("touchmove",o.touchmove),e.map.on("touchstart",o.touchstart),e.map.on("touchend",o.touchend),e.container.addEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",o.keydown),e.container.addEventListener("keyup",o.keyup))},removeEventListeners(){e.map.off("mousemove",o.mousemove),e.map.off("mousedown",o.mousedown),e.map.off("mouseup",o.mouseup),e.map.off("data",o.data),e.map.off("touchmove",o.touchmove),e.map.off("touchstart",o.touchstart),e.map.off("touchend",o.touchend),e.container.removeEventListener("mouseout",o.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",o.keydown),e.container.removeEventListener("keyup",o.keyup))},trash(e){a.trash(e)},combineFeatures(){a.combineFeatures()},uncombineFeatures(){a.uncombineFeatures()},getMode:()=>i}}(e),e.ui=function(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},o={mode:null,feature:null,mouse:null};function i(e){o=Object.assign(o,e)}function a(){if(!e.container)return;const t=[],r=[];Xe.forEach(e=>{o[e]!==n[e]&&(t.push(`${e}-${n[e]}`),null!==o[e]&&r.push(`${e}-${o[e]}`))}),t.length>0&&e.container.classList.remove(...t),r.length>0&&e.container.classList.add(...r),n=Object.assign(n,o)}function s(e,t={}){const n=document.createElement("button");return n.className=`${L.CONTROL_BUTTON} ${t.className}`,n.setAttribute("title",t.title),t.container.appendChild(n),n.addEventListener("click",n=>{if(n.preventDefault(),n.stopPropagation(),n.target===r)return c(),void t.onDeactivate();l(e),t.onActivate()},!0),n}function c(){r&&(r.classList.remove(L.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(L.ACTIVE_BUTTON),r=n)}return{setActiveButton:l,queueMapClasses:i,updateMapClasses:a,clearMapClasses:function(){i({mode:null,feature:null,mouse:null}),a()},addButtons:function(){const r=e.options.controls,n=document.createElement("div");return n.className=`${L.CONTROL_GROUP} ${L.CONTROL_BASE}`,r?(r[V.POINT]&&(t[V.POINT]=s(V.POINT,{container:n,className:L.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(N.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[V.LINE]&&(t[V.LINE]=s(V.LINE,{container:n,className:L.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(N.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[V.POLYGON]&&(t[V.POLYGON]=s(V.POLYGON,{container:n,className:L.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(N.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:L.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:L.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:L.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}})),n):n},removeButtons:function(){Object.keys(t).forEach(e=>{const r=t[e];r.parentNode&&r.parentNode.removeChild(r),delete t[e]})}}}(e),e.container=o.getContainer(),e.store=new He(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=o.boxZoom.isEnabled(),o.boxZoom.disable();const t=o.dragPan.isEnabled();o.dragPan.disable(),o.dragPan.enable(),t||o.dragPan.disable()}return o.loaded()?n.connect():(o.on("load",n.connect),r=setInterval(()=>{o.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(A.COLD,{data:{type:F.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(A.HOT,{data:{type:F.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(t=>{e.map.addLayer(t)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(t=>{e.map.getLayer(t.id)&&e.map.removeLayer(t.id)}),e.map.getSource(A.COLD)&&e.map.removeSource(A.COLD),e.map.getSource(A.HOT)&&e.map.removeSource(A.HOT)}};return e.setup=n,n}const $e="#3bb2d0",Ke="#fbb03b",qe="#fff";var ze=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Ke,$e],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],Ke,$e],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":qe}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],Ke,$e]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":qe}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":Ke}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Ke}}];function Ze(e,t){this.x=e,this.y=t}function We(e,t){const r=t.getBoundingClientRect();return new Ze(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function Qe(e,t,r,n){return{type:F.FEATURE,properties:{meta:R.VERTEX,parent:e,coord_path:r,active:n?U.ACTIVE:U.INACTIVE},geometry:{type:F.POINT,coordinates:t}}}function et(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return tt(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"features":return;default:t[r]=e[r]}}),t.features=e.features.map(e=>tt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return nt(e);default:throw new Error("unknown GeoJSON type")}}function tt(e){const t={type:"Feature"};return Object.keys(e).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:t[r]=e[r]}}),t.properties=rt(e.properties),null==e.geometry?t.geometry=null:t.geometry=nt(e.geometry),t}function rt(e){const t={};return e?(Object.keys(e).forEach(r=>{const n=e[r];"object"==typeof n?null===n?t[r]=null:Array.isArray(n)?t[r]=n.map(e=>e):t[r]=rt(n):t[r]=n}),t):t}function nt(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>nt(e)),t):(t.coordinates=ot(e.coordinates),t)}function ot(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>ot(e))}function it(e,t={}){return at(e,"mercator",t)}function at(e,n,o={}){var i=(o=o||{}).mutate;if(!e)throw new Error("geojson is required");return Array.isArray(e)&&t(e[0])?e="mercator"===n?st(e):ct(e):(!0!==i&&(e=et(e)),r(e,function(e){var t="mercator"===n?st(e):ct(e);e[0]=t[0],e[1]=t[1]})),e}function st(e){var t,r=Math.PI/180,n=6378137,o=20037508.342789244,i=[n*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*r,n*Math.log(Math.tan(.25*Math.PI+.5*e[1]*r))];return i[0]>o&&(i[0]=o),i[0]<-o&&(i[0]=-o),i[1]>o&&(i[1]=o),i[1]<-o&&(i[1]=-o),i}function ct(e){var t=180/Math.PI,r=6378137;return[e[0]*t/r,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/r)))*t]}function lt(e,t,r){const n=t.geometry.coordinates,o=r.geometry.coordinates;if(n[1]>85||n[1]<-85||o[1]>85||o[1]<-85)return null;const i=it(n),a=it(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return at(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:F.FEATURE,properties:{meta:R.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:F.POINT,coordinates:u}}}function ut(e,t={},r=null){const{type:n,coordinates:o}=e.geometry,i=e.properties&&e.properties.id;let a=[];function s(e,r){let n="",o=null;e.forEach((e,s)=>{const l=null!=r?`${r}.${s}`:String(s),u=Qe(i,e,l,c(l));if(t.midpoints&&o){const e=lt(i,o,u);e&&a.push(e)}o=u;const d=JSON.stringify(e);n!==d&&a.push(u),0===s&&(n=d)})}function c(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===F.POINT?a.push(Qe(i,o,r,c(r))):n===F.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===F.LINE_STRING?s(o,r):0===n.indexOf(F.MULTI_PREFIX)&&function(){const r=n.replace(F.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:F.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(ut(i,t,o))})}(),a}Ze.prototype={clone(){return new Ze(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,o=r*this.x+t*this.y;return this.x=n,this.y=o,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),o=t.x+r*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=o,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Ze},Ze.convert=function(e){if(e instanceof Ze)return e;if(Array.isArray(e))return new Ze(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Ze(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var dt={enable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}};const{LAT_MIN:pt,LAT_MAX:ht,LAT_RENDERED_MIN:ft,LAT_RENDERED_MAX:gt,LNG_MIN:yt,LNG_MAX:mt}=G;function vt(e,t){let r=pt,n=ht,o=pt,i=ht,a=mt,s=yt;e.forEach(e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(e=>e[0]),o=r.map(e=>e[1]),i=e=>Math.min.apply(null,e),a=e=>Math.max.apply(null,e);return[i(n),i(o),a(n),a(o)]}(e),c=t[1],l=t[3],u=t[0],d=t[2];c>r&&(r=c),l<n&&(n=l),l>o&&(o=l),c<i&&(i=c),u<a&&(a=u),d>s&&(s=d)});const c=t;return r+c.lat>gt&&(c.lat=gt-r),o+c.lat>ht&&(c.lat=ht-o),n+c.lat<ft&&(c.lat=ft-n),i+c.lat<pt&&(c.lat=pt-i),a+c.lng<=yt&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=mt&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function xt(e,t){const r=vt(e.map(e=>e.toGeoJSON()),t);e.forEach(e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+r.lng,lat:e[1]+r.lat};return[t.lng,t.lat]},o=e=>e.map(e=>n(e)),i=e=>e.map(e=>o(e));let a;e.type===F.POINT?a=n(t):e.type===F.LINE_STRING||e.type===F.MULTI_POINT?a=t.map(n):e.type===F.POLYGON||e.type===F.MULTI_LINE_STRING?a=t.map(o):e.type===F.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const _t={onSetup:function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(e=>void 0!==this.getFeature(e))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},fireUpdate:function(){this.fire(D.UPDATE,{action:j.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(){const e=this.getSelected(),t=e.filter(e=>this.isInstanceOf("MultiFeature",e));let r=!1;if(e.length>1){r=!0;const t=e[0].type.replace("Multi","");e.forEach(e=>{e.type.replace("Multi","")!==t&&(r=!1)})}const n=t.length>0,o=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:o})},getUniqueIds:function(e){if(!e.length)return[];return e.map(e=>e.properties.id).filter(e=>void 0!==e).reduce((e,t)=>(e.add(t),e),new xe).values()},stopExtendedInteractions:function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},onStop:function(){dt.enable(this)},onMouseMove:function(e,t){return K(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};_t.onTap=_t.onClick=function(e,t){return $(t)?this.clickAnywhere(e,t):H(R.VERTEX)(t)?this.clickOnVertex(e,t):K(t)?this.clickOnFeature(e,t):void 0},_t.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),dt.enable(this),this.stopExtendedInteractions(e)},_t.clickOnVertex=function(e,t){this.changeMode(N.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:k.MOVE})},_t.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},_t.clickOnFeature=function(e,t){dt.disable(this),this.stopExtendedInteractions(e);const r=z(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==F.POINT)return this.changeMode(N.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:k.POINTER}),1===n.length&&dt.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:k.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:k.MOVE})),this.doRender(o)},_t.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),X(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&Y(t)?this.startBoxSelect(e,t):void 0},_t.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=We(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},_t.onTouchStart=function(e,t){if(X(t))return this.startOnActiveFeature(e,t)},_t.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},_t.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:k.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(L.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=We(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),o=Math.max(e.boxSelectStartLocation.x,r.x),i=Math.min(e.boxSelectStartLocation.y,r.y),a=Math.max(e.boxSelectStartLocation.y,r.y),s=`translate(${n}px, ${i}px)`;e.boxSelectElement.style.transform=s,e.boxSelectElement.style.WebkitTransform=s,e.boxSelectElement.style.width=o-n+"px",e.boxSelectElement.style.height=a-i+"px"},_t.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},_t.onTouchEnd=_t.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,We(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),o=this.getUniqueIds(n).filter(e=>!this.isSelected(e));o.length&&(this.select(o),o.forEach(e=>this.doRender(e)),this.updateUIClasses({mouse:k.MOVE}))}this.stopExtendedInteractions(e)},_t.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?U.ACTIVE:U.INACTIVE,r(t),this.fireActionable(),t.properties.active===U.ACTIVE&&t.geometry.type!==F.POINT&&ut(t).forEach(r)},_t.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},_t.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let o=0;o<e.length;o++){const i=e[o];if(i.type.replace("Multi","")!==n)return;i.type.includes("Multi")?i.getCoordinates().forEach(e=>{t.push(e)}):t.push(i.getCoordinates()),r.push(i.toGeoJSON())}if(r.length>1){const e=this.newFeature({type:F.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(D.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},_t.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],r=[];for(let n=0;n<e.length;n++){const o=e[n];this.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach(e=>{this.addFeature(e),e.properties=o.properties,t.push(e.toGeoJSON()),this.select([e.id])}),this.deleteFeature(o.id,{silent:!0}),r.push(o.toGeoJSON()))}t.length>1&&this.fire(D.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const bt=H(R.VERTEX),Et=H(R.MIDPOINT),St={fireUpdate:function(){this.fire(D.UPDATE,{action:j.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},startDragging:function(e,t){null==e.initialDragPanState&&(e.initialDragPanState=this.map.dragPan.isEnabled()),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){e.canDragMove&&!0===e.initialDragPanState&&this.map.dragPan.enable(),e.initialDragPanState=null,e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);z(t)||-1!==n?z(t)&&-1===n&&e.selectedCoordPaths.push(r.coord_path):e.selectedCoordPaths=[r.coord_path];const o=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(o)},onMidpoint:function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},pathsToCoordinates:function(e,t){return t.map(t=>({feature_id:e,coord_path:t}))},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,r){xt(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=vt(n.map(e=>({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:e}})),r);for(let t=0;t<n.length;t++){const r=n[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],r[0]+o.lng,r[1]+o.lat)}},clickNoTarget:function(){this.changeMode(N.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(N.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===F.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),dt.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){dt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=U.ACTIVE,r(t),ut(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=U.INACTIVE,r(t)),this.fireActionable(e)},onTrash:function(e){e.selectedCoordPaths.sort((e,t)=>t.localeCompare(e,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),!1===e.feature.isValid()&&(this.deleteFeature([e.featureId]),this.changeMode(N.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=X(t),n=bt(t),o=Et(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:k.MOVE}):this.updateUIClasses({mouse:k.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};St.onTouchStart=St.onMouseDown=function(e,t){return bt(t)?this.onVertex(e,t):X(t)?this.onFeature(e,t):Et(t)?this.onMidpoint(e,t):void 0},St.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},St.onClick=function(e,t){return $(t)?this.clickNoTarget(e,t):X(t)?this.clickActiveFeature(e,t):J(t)?this.clickInactive(e,t):void this.stopDragging(e)},St.onTap=function(e,t){return $(t)?this.clickNoTarget(e,t):X(t)?this.clickActiveFeature(e,t):J(t)?this.clickInactive(e,t):void 0},St.onTouchEnd=St.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const wt={};function It(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}wt.onSetup=function(){const e=this.newFeature({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:k.ADD}),this.activateUIButton(V.POINT),this.setActionableState({trash:!0}),{point:e}},wt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},wt.onTap=wt.onClick=function(e,t){this.updateUIClasses({mouse:k.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(D.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.point.id]})},wt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},wt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?U.ACTIVE:U.INACTIVE,!n)return r(t)},wt.onTrash=wt.stopDrawingAndRemove,wt.onKeyUp=function(e,t){if(Z(t)||W(t))return this.stopDrawingAndRemove(e,t)};const Ot={onSetup:function(){const e=this.newFeature({type:F.FEATURE,properties:{},geometry:{type:F.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),dt.disable(this),this.updateUIClasses({mouse:k.ADD}),this.activateUIButton(V.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:k.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),q(t)&&this.updateUIClasses({mouse:k.POINTER})}};Ot.onTap=Ot.onClick=function(e,t){return q(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Ot.onKeyUp=function(e,t){Z(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)):W(t)&&this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Ot.onStop=function(e){this.updateUIClasses({mouse:k.NONE}),dt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(D.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Ot.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?U.ACTIVE:U.INACTIVE,!n)return r(t);if(0===t.geometry.coordinates.length)return;const o=t.geometry.coordinates[0].length;if(!(o<3)){if(t.properties.meta=R.FEATURE,r(Qe(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(Qe(e.polygon.id,t.geometry.coordinates[0][n],`0.${n}`,!1))}if(o<=4){const e=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:F.FEATURE,properties:t.properties,geometry:{coordinates:e,type:F.LINE_STRING}}),3===o)return}return r(t)}},Ot.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)};const Pt={onSetup:function(e){const t=(e=e||{}).featureId;let r,n,o="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");const a=r.coordinates.length-1;if(r.coordinates[a][0]===i[0]&&r.coordinates[a][1]===i[1])n=a+1,r.addCoordinate(n,...r.coordinates[a]);else{if(r.coordinates[0][0]!==i[0]||r.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");o="backwards",n=0,r.addCoordinate(n,...r.coordinates[0])}}else r=this.newFeature({type:F.FEATURE,properties:{},geometry:{type:F.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),dt.disable(this),this.updateUIClasses({mouse:k.ADD}),this.activateUIButton(V.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&It(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&It(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:k.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),q(t)&&this.updateUIClasses({mouse:k.POINTER})}};Pt.onTap=Pt.onClick=function(e,t){if(q(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Pt.onKeyUp=function(e,t){W(t)?this.changeMode(N.SIMPLE_SELECT,{featureIds:[e.line.id]}):Z(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT))},Pt.onStop=function(e){dt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(D.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT,{},{silent:!0})))},Pt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(N.SIMPLE_SELECT)},Pt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?U.ACTIVE:U.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=R.FEATURE,r(Qe(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],""+("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),r(t))};var Mt={simple_select:_t,direct_select:St,draw_point:wt,draw_polygon:Ot,draw_line_string:Pt};const Ct={defaultMode:N.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:ze,modes:Mt,controls:{},userProperties:!1,suppressAPIEvents:!0},Tt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Lt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function At(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?A.HOT:A.COLD}))}var kt,Vt;var Ft,Nt,Dt=ae(Vt?kt:(Vt=1,kt=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,o,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(o=n;0!==o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,i[o]))return!1;for(o=n;0!==o--;){var a=i[o];if(!e(t[a],r[a]))return!1}return!0}return t!=t&&r!=r}));var jt=function(){if(Nt)return Ft;Nt=1,Ft=function(t){if(!t||!t.type)return null;var r=e[t.type];if(!r)return null;if("geometry"===r)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]};if("feature"===r)return{type:"FeatureCollection",features:[t]};if("featurecollection"===r)return t};var e={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};return Ft}(),Rt=ae(jt);function Ut(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const Bt={Polygon:ke,LineString:Ae,Point:Le,MultiPolygon:Ne,MultiLineString:Ne,MultiPoint:Ne};var Gt=Object.freeze({__proto__:null,CommonSelectors:ie,ModeHandler:Pe,StringSet:xe,constrainFeatureMovement:vt,createMidPoint:lt,createSupplementaryPoints:ut,createVertex:Qe,doubleClickZoom:dt,euclideanDistance:we,featuresAt:be,getFeatureAtAndSetCursors:Se,isClick:Ie,isEventAtCoordinates:It,isTap:Oe,mapEventToBoundingBox:ve,moveFeatures:xt,sortFeatures:me,stringSetsAreEqual:Ut,theme:ze,toDenseArray:Be});const Ht=function(e,t){const r={options:e=function(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=Object.assign({},Lt,e.controls):t.controls=Object.assign({},Tt,e.controls),t=Object.assign({},Ct,t),t.styles=At(t.styles,"cold").concat(At(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=N;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return be.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:F.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:F.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:F.FEATURE,properties:{},geometry:{type:F.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==F.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const n=e.store.createRenderBatch();let o=e.store.getAllIds().slice();const i=t.add(r),a=new xe(i);return o=o.filter(e=>!a.has(e)),o.length&&t.delete(o),n(),i},t.add=function(t){const n=JSON.parse(JSON.stringify(Rt(t))).features.map(t=>{if(t.id=t.id||Ce(),null===t.geometry)throw new Error("Invalid geometry: null");if(void 0===e.store.get(t.id)||e.store.get(t.id).type!==t.geometry.type){const n=Bt[t.geometry.type];if(void 0===n)throw new Error(`Invalid geometry type: ${t.geometry.type}.`);const o=new n(e,t);e.store.add(o,{silent:r})}else{const n=e.store.get(t.id),o=n.properties;n.properties=t.properties,Dt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Dt(n.getCoordinates(),t.geometry.coordinates)||n.incomingCoords(t.geometry.coordinates)}return t.id});return e.store.render(),n},t.get=function(t){const r=e.store.get(t);if(r)return r.toGeoJSON()},t.getAll=function(){return{type:F.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==N.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===N.DIRECT_SELECT?e.events.changeMode(N.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===N.SIMPLE_SELECT&&t.getMode()===N.SIMPLE_SELECT?(Ut(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===N.DIRECT_SELECT&&t.getMode()===N.DIRECT_SELECT&&o.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,o,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,o,i){return e.store.setFeatureProperty(n,o,i,{silent:r}),t},t}(r,t),r.api=t;const n=Je(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=V,t.options=e,t};function Yt(e){Ht(e,this)}Yt.modes=Mt,Yt.constants=G,Yt.lib=Gt;var Xt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}};function Jt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function $t(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Jt(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Jt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Kt(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function qt(e){var t;return!!(null!=e&&e.status&&null!=e&&e.snapStatus&&(null===(t=e.snapCoords)||void 0===t?void 0:t.length)>=2)}function zt(e){return qt(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function Zt(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n}),!0}function Wt(e,t){var r,n,o;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(r=e.snappedFeatures)&&void 0!==r&&r.length&&(e.snappedFeatures.length=0),null!==(n=e.closeFeatures)&&void 0!==n&&n.length&&(e.closeFeatures.length=0),null!==(o=e.lines)&&void 0!==o&&o.length&&(e.lines.length=0));null!=t&&t.getLayer("snap-helper-circle")&&t.setLayoutProperty("snap-helper-circle","visibility","none")}function Qt(e){var t,r,n;e&&(e.snapStatus=!1,e.snapCoords=null,null!==(t=e.snappedFeatures)&&void 0!==t&&t.length&&(e.snappedFeatures.length=0),null!==(r=e.closeFeatures)&&void 0!==r&&r.length&&(e.closeFeatures.length=0),null!==(n=e.lines)&&void 0!==n&&n.length&&(e.lines.length=0))}function er(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var tr=e=>{if(null==e||!e.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flat(2);default:return[]}},rr=e=>{if(null==e||!e.coordinates)return[];var t=[],r=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!0}),r+=e.length});break;case"MultiLineString":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!1}),r+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,n)=>{e.forEach((e,o)=>{t.push({start:r,length:e.length,path:[n,o],closed:!0}),r+=e.length})})}return t},nr=(e,t)=>{for(var r of e)if(t>=r.start&&t<r.start+r.length)return{segment:r,localIdx:t-r.start};return null},or=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},ir=(e,t)=>{var r=t.split(".").map(Number),n=rr(e);for(var o of n){if(o.path.every((e,t)=>e===r[t])&&r.length===o.path.length+1){var i=r[r.length-1];return o.start+i}}return r[r.length-1]},ar=(e,t)=>({x:e.x*t,y:e.y*t}),sr=e=>e instanceof window.SVGElement||e.ownerSVGElement,cr={move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},lr={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},ur={fireGeometryChange(e){var t=this.getFeature(e.featureId);t&&this.map.fire("draw.update",{features:[t.toGeoJSON()],action:"change_coordinates"})},emitGeometryValidation(e,t,r){e&&setTimeout(()=>{var n=this.getFeature(r);n&&this.map.fire("draw.geometrychange",{feature:n.toGeoJSON(),phase:e,vertexIndex:t})},0)},pushUndo(e){var t=this.map._undoStack;t&&(t.push(e),this.emitGeometryValidation(cr[e.type],e.vertexIndex,e.featureId))},handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_vertex"===r.type?this.undoMoveVertex(e,r):"insert_vertex"===r.type?this.undoInsertVertex(e,r):"delete_vertex"===r.type&&this.undoDeleteVertex(e,r),this.emitGeometryValidation(lr[r.type],r.vertexIndex,r.featureId)}},undoMoveVertex(e,t){var{vertexIndex:r,previousPosition:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=rr(i),c=nr(s,r);if(c){or(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertecies[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,ar(this.map.project(l),e.scale))}}},undoInsertVertex(e,t){var{vertexIndex:r,featureId:n}=t,o=this.getFeature(n);if(o){var i=o.toGeoJSON(),a=rr(o),s=nr(a,r);if(s)or(i,s.segment.path).splice(s.localIdx,1),this._applyUndoAndSync(e,i,n),this.clearSelectedCoordinates(),this.hideTouchVertexIndicator(e),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}},undoDeleteVertex(e,t){var{vertexIndex:r,position:n,featureId:o}=t,i=this.getFeature(o);if(i){var a=i.toGeoJSON(),s=rr(i),c=nr(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)or(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,ar(this.map.project(e.vertecies[r]),e.scale)),this.changeMode(e,{selectedVertexIndex:r,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,r)})}},_applyUndoAndSync(e,t,r){this._ctx.api.add(t),e.vertecies=this.getVerticies(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}},dr=o.touchTargetSize/2;var pr=e=>{var t,r,n=e.querySelector("[data-im-draw-touch-target]");return n||(e.insertAdjacentHTML("beforeend",(t=o.touchTargetSize,r=dr,"\n <svg width='".concat(t,"' height='").concat(t,"' viewBox='0 0 48 48' fill-rule='evenodd'\n style='display:none;position:absolute;top:0;left:0;margin:").concat(r,"px 0 0 -").concat(r,"px;cursor:grab'\n class='im-draw-touch-target' data-im-draw-touch-target>\n <circle cx='24' cy='24' r='24' fill='var(--draw-halo, #000)'/>\n <path d=\"M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z\" fill='var(--draw-bg, #fff)'/>\n </svg>\n "))),n=e.querySelector("[data-im-draw-touch-target]")),n},hr=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},fr=(e,t)=>{t&&e&&(e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px"),e.style.display="block")},gr=e=>{e&&(e.style.display="none")},yr=e=>{if(!e)return!1;var t=e.parentNode;return t instanceof globalThis.SVGElement||null!=(null==t?void 0:t.ownerSVGElement)},mr=function(e){var t,r,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=null!==(t=null==e?void 0:e.mapColorScheme)&&void 0!==t?t:"light",c=null!==(r=null==e?void 0:e.id)&&void 0!==r?r:null,l=e=>{var t;return function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return"object"!=typeof e||null===e?e:r&&void 0!==e[r]?e[r]:void 0!==e[t]?e[t]:void 0!==e.light?e.light:Object.values(e)[0]}(null!==(t=a[e])&&void 0!==t?t:i[e],s,c)};return{editStroke:l("editStroke"),editFill:l("editFill"),editVertex:l("editVertex"),editMidpoint:l("editMidpoint"),editActive:l("editActive"),editHalo:l("editHalo"),invalidStroke:l("invalidStroke"),splitValid:l("splitValid"),splitInvalid:l("splitInvalid"),shapeStroke:l("shapeStroke"),strokeWidth:null!==(n=a.strokeWidth)&&void 0!==n?n:o.strokeWidth,shapeFill:l("shapeFill"),snapVertex:l("snapVertex"),snapEdge:l("snapEdge"),mapStyleId:c}};function vr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function xr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?vr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):vr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var _r=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=mr(t,r);hr(e,{editActive:n,editHalo:o,editVertex:i})}},br={addTouchVertexTarget(e){e.touchVertexTarget=pr(e.container),_r(e.touchVertexTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchVertexTarget(e,t){t&&"touch"===e.interfaceType&&e.selectedVertexIndex>=0?Object.assign(e.touchVertexTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchVertexTarget.style.display="none"},hideTouchVertexIndicator(e){e.touchVertexTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0,"touch"!==t.pointerType||"pointermove"!==t.type||sr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){Qt(Kt(this.map)),null!=e&&e.featureId&&(this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&void 0!==e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=void 0,e._touchMoved=!1)},onTap(e,t){var r,n,o=Kt(this.map);o&&Wt(o,this.map);var i=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,a=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if("vertex"===i){var s=this.getFeature(e.featureId),c=ir(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(xr(xr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){Qt(Kt(this.map));var r=this.getVerticies(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&sr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=t.touches[0].clientX,i=t.touches[0].clientY,a=window.getComputedStyle(e.touchVertexTarget);e.deltaTarget={x:o-Number.parseFloat(a.left),y:i-Number.parseFloat(a.top)};var s=this.map.project(n);e.deltaVertex={x:o/e.scale-s.x,y:i/e.scale-s.y}}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&sr(t.target.parentNode)){e._touchMoved=!0;var r=t.touches[0].clientX,n=t.touches[0].clientY,o={x:r/e.scale-e.deltaVertex.x,y:n/e.scale-e.deltaVertex.y},i=this.map.unproject(o);if(er(e)){var a=Kt(this.map);Zt(a,this.map,o),i=zt(a)||i}this.moveVertex(e,i),this.updateTouchVertexTarget(e,{x:r-e.deltaTarget.x,y:n-e.deltaTarget.y})}}};function Er(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}var Sr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},wr={updateMidpoint(e){setTimeout(()=>{this.map.getSource("mapbox-gl-draw-hot").setData({type:"Feature",properties:{meta:"midpoint",active:"true",id:"active-midpoint"},geometry:{type:"Point",coordinates:e}})},0)},updateVertex(t,r){var[n,o]=this.getVertexOrMidpoint(t,r);n<0||!o||this.changeMode(t,function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Er(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Er(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({selectedVertexIndex:n,selectedVertexType:o},"vertex"===o&&{coordPath:this.getCoordPath(t,n)}))},getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?s.nudgeAmount:s.stepAmount,[o,i]=t?Sr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+o,y:r.y+i})},getNewCoord(e,t){return this.getOffset(tr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},getOffsetByDelta(e,t,r,n){var o=this.map.project(e),i=n?s.stepAmount:s.nudgeAmount;return this.map.unproject({x:o.x+t*i,y:o.y+r*i})},resolveSnapTarget(e,t,r,o,i){var a=Kt(this.map);if(er(e)&&e._isSnapped&&a){var s=function(e){var t,r;return null!==(t=null==e||null===(r=e.options)||void 0===r?void 0:r.radius)&&void 0!==t?t:n.snapRadius}(a)+1,c=this.map.project(o);return e._isSnapped=!1,Wt(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return er(e)&&a&&(Zt(a,this.map,this.map.project(l)),qt(a))?(e._isSnapped=!0,zt(a)):(e._isSnapped=!1,l)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=tr(i))||void 0===o?void 0:o[e.selectedVertexIndex]);if(a){var s=[...a],c=e.selectedVertexIndex,l=this.resolveSnapTarget(e,t,r,a,()=>this.getOffsetByDelta(a,t,r,n));this.moveVertex(e,l),this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:c,previousPosition:s})}}},insertVertex(e,t){var r=e.selectedVertexIndex-e.vertecies.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=rr(o),s=r+1,c=null,l=0,u=0;for(var d of a){var p=d.closed?d.length:d.length-1;if(r<u+p){c=d,l=r-u+1,s=d.start+l;break}u+=p}c&&(or(i,c.path).splice(l,0,[n.lng,n.lat]),this._ctx.api.add(i),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:s}),this.changeMode(e,{selectedVertexIndex:s,selectedVertexType:"vertex",coordPath:this.getCoordPath(e,s)}))},moveVertex(e,t){if((arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).checkSnap&&!1!==e.enableSnap){var r,n=this.map._snapInstance;null!=n&&n.snapStatus&&(null===(r=n.snapCoords)||void 0===r?void 0:r.length)>=2&&(t={lng:n.snapCoords[0],lat:n.snapCoords[1]})}var o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=rr(o),s=nr(a,e.selectedVertexIndex);s&&(or(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertecies=this.getVerticies(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=rr(t),n=nr(r,e.selectedVertexIndex);if(n){var{segment:o}=n,i=o.closed?a.Polygon:a.LineString;if(!(o.length<=i)){var s=[...e.vertecies[e.selectedVertexIndex]],c=e.selectedVertexIndex,l=[...n.segment.path,n.localIdx].join(".");t.removeCoordinate(l),this.fireUpdate(),this.clearSelectedCoordinates(),t.changed(),this._ctx.store.render(),this.pushUndo({type:"delete_vertex",featureId:e.featureId,vertexIndex:c,position:s}),this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null})}}}}},Ir={findVertexIndex(e,t,r){var n=[];return e.forEach((e,r)=>{e[0]===t[0]&&e[1]===t[1]&&n.push(r)}),0===n.length?-1:1===n.length?n[0]:r>=0?n.reduce((e,t)=>Math.abs(t-r)<Math.abs(e-r)?t:e,n[0]):n[0]},getCoordPath(e,t){var r=this.getFeature(e.featureId);if(!r)return"0";var n=rr(r),o=nr(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVerticies(e){return tr(this.getFeature(e))},getMidpoints(e){var t=this.getFeature(e),r=tr(t),n=rr(t);if(null==r||!r.length||!n.length)return[];var o=[];for(var i of n)for(var a=i.closed?i.length:i.length-1,s=0;s<a;s++){var c=i.start+s,l=i.start+(s+1)%i.length,[u,d]=r[c],[p,h]=r[l];o.push([(u+p)/2,(d+h)/2])}return o},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertecies)&&void 0!==r&&r.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertecies)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertecies.map(o),...e.midpoints.map(o)].filter(Boolean);if(!i.length)return[-1,null];var a=i[e.selectedVertexIndex]||Object.values(this.map.project(this.map.getCenter())),s=c(a,i,t);return[s,s<e.vertecies.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=rr(r),o=t.split(".").map(Number),i=0;for(var a of n){if(a.path.every((e,t)=>e===o[t])&&o.length===a.path.length+1){var s=o[o.length-1],c=s>0?s-1:a.length-2;return e.vertecies.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertecies.length}},Or=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Pr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Mr=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Cr=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(Mr.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},Tr={onKeydown(e,t){Cr(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Or.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?(e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey)(t)&&this.handleUndoShortcut(e,t):this.changeMode(e,{isPanEnabled:!0,selectedVertexIndex:-1,selectedVertexType:null}):this.handleSpace(e,t))},handleSpace(e,t){t.preventDefault(),e.selectedVertexIndex<0&&this.startKeyboardSelection(e)},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),t.altKey?this.updateVertex(e,t.key):this.moveVertexByKey(e,t)},startKeyboardSelection(e){var t,r,n=Kt(this.map);n&&Wt(n,this.map),null!==(t=e.vertecies)&&void 0!==t&&t.length||(e.vertecies=this.getVerticies(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertecies)&&void 0!==r&&r.length&&(e.isPanEnabled=!1,this.updateVertex(e))},moveVertexByKey(e,t){var r;if("midpoint"!==e.selectedVertexType){var n=this.getFeature(e.featureId),o=n&&(null===(r=tr(n))||void 0===r?void 0:r[e.selectedVertexIndex]);o&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...o],e._keyboardMoveStartIndex=e.selectedVertexIndex),this.moveVertex(e,this._keyboardMoveTarget(e,t,o)))}else this.insertVertex(e,t)},_keyboardMoveTarget(e,t,r){var[n,o]=Pr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},handleUndoShortcut(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.handleUndo(e))},onKeyup(e,t){Cr(e)||(e.interfaceType="keyboard",Or.has(t.key)&&e.selectedVertexIndex>=0&&(t.stopPropagation(),e._keyboardMoveStartPosition&&null!=e._keyboardMoveStartIndex&&(this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._keyboardMoveStartIndex,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null,e._keyboardMoveStartIndex=null)),"Delete"===t.key&&this.deleteVertex(e))}},Lr="draw.vertexselection",Ar={onMouseDown(e,t){var r,n;Qt(Kt(this.map));var o=null===(r=t.featureTarget)||void 0===r?void 0:r.properties.meta,i=null===(n=t.featureTarget)||void 0===n?void 0:n.properties.coord_path;if(["vertex","midpoint"].includes(o)&&(e.dragMoveLocation=t.lngLat,e.dragMoving=!1,St.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=ir(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertecies)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=ir(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(Lr,{index:e.selectedVertexIndex,numVertecies:e.vertecies.length})}},onClick(e,t){if(e._isInsertingVertex&&null!=e._insertedVertexIndex){var r=e._insertedVertexIndex;return this.syncVertices(e),this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:r}),e.selectedVertexIndex=r,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,void this.map.fire(Lr,{index:r,numVertecies:e.vertecies.length})}St.onClick.call(this,e,t)},onMouseUp(e,t){Qt(Kt(this.map));var r=e._isInsertingVertex&&null!=e._insertedVertexIndex,n=this._didVertexMove(e);(e.dragMoving||n||r)&&(this.syncVertices(e),r?this._recordInsertionUndo(e):n&&this._recordMoveUndo(e)),e._moveStartPosition=null,e._moveStartIndex=null,St.onMouseUp.call(this,e,t)},_didVertexMove(e){var t;if(!e._moveStartPosition||null==e._moveStartIndex)return!1;var r=this.getFeature(e.featureId),n=r&&(null===(t=tr(r))||void 0===t?void 0:t[e._moveStartIndex]);return!!n&&(n[0]!==e._moveStartPosition[0]||n[1]!==e._moveStartPosition[1])},_recordInsertionUndo(e){var t=e._insertedVertexIndex;this.pushUndo({type:"insert_vertex",featureId:e.featureId,vertexIndex:t}),e.selectedVertexIndex=t,e.selectedVertexType="vertex",e._isInsertingVertex=!1,e._insertedVertexIndex=null,this.map.fire(Lr,{index:t,numVertecies:e.vertecies.length})},_recordMoveUndo(e){this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition})},onDrag(e,t){var r;if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var n=Kt(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),er(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),Zt(n,this.map,t.point);var o=zt(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else St.onDrag.call(this,e,t)}}};function kr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Vr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?kr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):kr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Fr="draw.nudgevertex",Nr=Vr(Vr(Vr(Vr(Vr(Vr(Vr(Vr({},Yt.modes.direct_select),ur),br),wr),Ir),Tr),Ar),{},{onSetup(e){var t,r,n,o=Yt.modes.direct_select.onSetup.call(this,e);(Object.assign(o,{container:e.container,interfaceType:e.interfaceType,deleteVertexButtonId:e.deleteVertexButtonId,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,featureId:o.featureId,selectedVertexIndex:null!==(t=e.selectedVertexIndex)&&void 0!==t?t:-1,selectedVertexType:e.selectedVertexType,coordPath:e.coordPath,scale:null!==(r=e.scale)&&void 0!==r?r:1}),this.map._lastEditFeatureId!==o.featureId)&&(null===(n=this.map._undoStack)||void 0===n||n.clear(),this.map._lastEditFeatureId=o.featureId);var i=this.getFeature(o.featureId);o.featureType=null==i?void 0:i.type,o.vertecies=this.getVerticies(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o);var a=Kt(this.map);if(a&&Wt(a,this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var s=o.vertecies[o.selectedVertexIndex];s&&setTimeout(()=>{this.updateTouchVertexTarget(o,ar(this.map.project(s),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=t=>r=>t.call(this,e,r),r=this.handlers={keydown:t(this.onKeydown),keyup:t(this.onKeyup),pointerdown:t(this.onPointerevent),pointermove:t(this.onPointerevent),pointerup:t(this.onPointerevent),click:t(this.onButtonClick),touchstart:t(this.onTouchstart),touchmove:t(this.onTouchmove),touchend:t(this.onTouchend),selectionchange:t(this.onSelectionChange),scalechange:t(this.onScaleChange),update:t(this.onUpdate),move:t(this.onMove),interfacetypechange:t(this.onInterfaceTypeChange),nudgevertex:t(this.onNudgeVertex)};window.addEventListener("keydown",r.keydown,{capture:!0}),window.addEventListener("keyup",r.keyup,{capture:!0}),window.addEventListener("click",r.click),e.container.addEventListener("pointerdown",r.pointerdown),e.container.addEventListener("pointermove",r.pointermove),e.container.addEventListener("pointerup",r.pointerup),e.container.addEventListener("touchstart",r.touchstart,{passive:!1}),e.container.addEventListener("touchmove",r.touchmove,{passive:!1}),e.container.addEventListener("touchend",r.touchend,{passive:!1}),this.map.on("draw.selectionchange",r.selectionchange),this.map.on("draw.scalechange",r.scalechange),this.map.on("draw.update",r.update),this.map.on("move",r.move),this.map.on("draw.interfacetypechange",r.interfacetypechange),this.map.on(Fr,r.nudgevertex)},applyVertexSelection(e,t){if("midpoint"===t.selectedVertexType)return e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render(),void this.updateMidpoint(e.midpoints[t.selectedVertexIndex-e.vertecies.length]);-1===t.selectedVertexIndex&&(e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed(),this._ctx.store.render())},onSelectionChange(e,t){var r,n;this.syncVertices(e);var o=null===(r=t.points[t.points.length-1])||void 0===r?void 0:r.geometry.coordinates;if("keyboard"!==e.interfaceType&&o&&!e.coordPath){var i,a=null===(i=t.features[0])||void 0===i?void 0:i.geometry,s=tr(a);e.selectedVertexIndex=this.findVertexIndex(s,o,e.selectedVertexIndex)}null!==(n=e.selectedVertexType)&&void 0!==n||(e.selectedVertexType=e.selectedVertexIndex>=0?"vertex":null),this.map.fire("draw.vertexselection",{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertecies:e.vertecies.length});var c=o||(e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?ar(this.map.project(c),e.scale):null)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType;var r=e.selectedVertexIndex>=0?e.vertecies[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?ar(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertecies.map(e=>JSON.stringify(e))).size!==e.vertecies.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertecies[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,ar(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertecies[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,ar(this.map.project(r),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.deleteVertexButtonId))&&"vertex"===e.selectedVertexType&&this.deleteVertex(e),t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},clickNoTarget(e){this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,isPanEnabled:!0})},changeMode(e,t){e.featureId&&this._ctx.api.changeMode("edit_vertex",Vr(Vr({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;e.container.removeEventListener("pointerdown",t.pointerdown),e.container.removeEventListener("pointermove",t.pointermove),e.container.removeEventListener("pointerup",t.pointerup),e.container.removeEventListener("touchstart",t.touchstart),e.container.removeEventListener("touchmove",t.touchmove),e.container.removeEventListener("touchend",t.touchend),this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.scalechange",t.scalechange),this.map.off("draw.update",t.update),this.map.off("move",t.move),this.map.off("draw.interfacetypechange",t.interfacetypechange),this.map.off(Fr,t.nudgevertex),this.map.dragPan.enable(),window.removeEventListener("click",t.click),window.removeEventListener("keydown",t.keydown,{capture:!0}),window.removeEventListener("keyup",t.keyup,{capture:!0}),this.hideTouchVertexIndicator(e)}});function Dr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function jr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Dr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Dr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Rr=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?jr(jr({},e),{},{featureId:null}):e,a=jr(jr({},t.onSetup.call(this,i)),e);a[r].properties=e.properties;var{container:s,vertexMarkerId:c,getInterfaceType:l}=a,u=l?l():a.interfaceType;a.interfaceType=u;var d=s.querySelector("#".concat(c));a.vertexMarker=d,["touch","keyboard"].includes(u)?this._showCrossHair(a):this._hideCrossHair(a);var p=(e,t)=>this[e]=t.bind(this,a),h={keydownHandler:this.onKeydown,keyupHandler:this.onKeyup,blurHandler:this.onBlur,createHandler:this.onCreate,moveHandler:this.onMove,pointerdownHandler:this.onPointerdown,pointermoveHandler:this.onPointermove,pointerupHandler:this.onPointerup,vertexButtonClickHandler:this.onVertexButtonClick,undoHandler:this.onUndo,interfaceTypeChangeHandler:this.onInterfaceTypeChange};return Object.entries(h).forEach(e=>{var[t,r]=e;return p(t,r)}),this._listeners=[[window,"keydown",this.keydownHandler],[window,"keyup",this.keyupHandler],[window,"click",this.vertexButtonClickHandler],[s,"blur",this.blurHandler],[s,"pointermove",this.pointermoveHandler],[s,"pointerup",this.pointerupHandler],[o,"pointerdown",this.pointerdownHandler],[o,"draw.create",this.createHandler],[o,"move",this.moveHandler],[o,"draw.undo",this.undoHandler],[o,"draw.interfacetypechange",this.interfaceTypeChangeHandler]],this._listeners.forEach(e=>{var[t,r,n]=e;return t.addEventListener?t.addEventListener(r,n):t.on(r,n)}),a},onStop(e){t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n]=e;return t.removeEventListener?t.removeEventListener(r,n):t.off(r,n)}),this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function Ur(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Br(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ur(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ur(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Gr=(e,t,r,n,o)=>{setTimeout(()=>{var i=t(n);i&&e.fire("draw.geometrychange",((e,t,r)=>{var n=t(e).slice(0,-1);return{feature:{type:"Feature",geometry:"Polygon"===e.toGeoJSON().geometry.type?{type:"Polygon",coordinates:[n]}:{type:"LineString",coordinates:n},properties:{}},phase:r,vertexIndex:Math.max(0,n.length-1)}})(i,r,o))},0)},Hr=e=>{var{geometryType:t,getFeature:r,getCoords:n}=e;return{_isIgnorableClick(e){return e.originalEvent.button>0||this.map._undoInProgress||e.originalEvent.target!==this.map.getCanvas()},_canPlaceVertex(e,o){var i=r(e);if(!i||!o)return!0;var a=l({placed:n(i).slice(0,-1),point:o,geometryType:t,onGeometryChange:this.map._drawGeometryValidator});return a.valid||this.map.fire("draw.placementblocked",a.blocked),a.valid},dispatchVertexChange(e){this.map.fire("draw.vertexchange",{numVertecies:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Gr(this.map,r,n,e,t)},onTap(){},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this.doClick(e)},onCreate(e,t){((e,t,r)=>{e.delete(t.id),t.id=r,e.add(t,{userProperties:!0})})(this._ctx.api,t.features[0],e.featureId)}}},Yr=e=>{var{ParentMode:t,getFeature:r,getCoords:n,validateClick:o,finishOnInvalidClick:i}=e;return{onClick(e,a){var s;if(!this._isIgnorableClick(a)&&(!1!==this.map._drawGeometryValid||"vertex"!==(null===(s=a.featureTarget)||void 0===s||null===(s=s.properties)||void 0===s?void 0:s.meta))){var c=Kt(this.map);if(er(e)&&qt(c))a=function(e,t){var r=zt(t);return r?$t($t({},e),{},{lngLat:r}):e}(a,c);else if(!((e,t)=>{var a=n(r(e));return a.length>0&&(a[a.length-1]=[t.lngLat.lng,t.lngLat.lat]),i||o(r(e))})(e,a))return;if(this._canPlaceVertex(e,[a.lngLat.lng,a.lngLat.lat])){var l=n(r(e)).length;t.onClick.call(this,e,a),n(r(e)).length>l&&(this.pushDrawUndo(e),this.dispatchVertexChange(n(r(e))),this.emitDrawValidation(e))}}},doClick(e){if(!this.map._undoInProgress){var a=r(e),s=n(a);if(this.dispatchVertexChange(s),o(a)){var c=Kt(this.map),l=er(e)&&function(e,t){var r=zt(t);if(!r)return null;var n=e.project([r.lng,r.lat]);return{lngLat:r,point:n,originalEvent:new MouseEvent("click",{clientX:n.x,clientY:n.y,bubbles:!0,cancelable:!0})}}(this.map,c),u=l?l.lngLat:this.map.getCenter();if(this._canPlaceVertex(e,[u.lng,u.lat])){l?(t.onClick.call(this,e,l),this._ctx.store.render()):this._simulateMouse("click",t.onClick,e);var d=n(r(e));this.pushDrawUndo(e),this.dispatchVertexChange(d),this.emitDrawValidation(e)}}else i&&!1!==this.map._drawGeometryValid&&(s.pop(),this.map.fire("draw.create",{features:[a.toGeoJSON()]}),this.changeMode("simple_select",{featureIds:[a.id]}))}}}};function Xr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Jr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var $r=e=>{var{geometryType:t,getFeature:r}=e;return{pushDrawUndo(e){var n=this.map._undoStack;n&&!this.map._undoInProgress&&n.push({type:"draw_vertex",geometryType:t,featureId:r(e).id})},onUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"draw_vertex"===(null==r?void 0:r.type)&&(this.map._undoInProgress=!0,setTimeout(()=>{this.map._undoInProgress=!1},100),this.undoVertex(e),this.emitDrawValidation(e,"commit-delete"))}},_handleUndoKeydown(e,t){var r,n=null===(r=document.activeElement)||void 0===r?void 0:r.tagName;"INPUT"!==n&&"TEXTAREA"!==n&&(t.preventDefault(),t.stopPropagation(),this.onUndo(e))}}},Kr=e=>{var{ParentMode:t,geometryType:r,getCoords:n,getFeature:o}=e;return{undoVertex(e){var t=o(e),r=n(t);return!(r.length<2)&&(2===r.length?this._reinitializeFeature(e,t):(this._removeLastVertex(e,t,r),!0))},_removeLastVertex(e,t,o){var i="Polygon"===r?t.coordinates[0]:o;i.splice(-2,1),i[i.length-1]=[...i[i.length-2]],e.currentVertexPosition=Math.max(1,e.currentVertexPosition-1),this._ctx.store.render(),this._updateRubberBand(e,n(t))},_updateRubberBand(e,n){if(["touch","keyboard"].includes(e.interfaceType))this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render();else{var o=n["Polygon"===r?n.length-2:n.length-1],i={lng:o[0],lat:o[1]},a=this.map.project(i);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.y})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}this.dispatchVertexChange(n)}}},qr=e=>{var{ParentMode:t,featureProp:r,geometryType:n}=e;return{_reinitializeFeature(e,o){var i=o.id;if(this._ctx.store.delete([i]),"LineString"===n)return this._restartLineStringDraw(e,i);var a=this.map.getCenter(),s=[[a.lng,a.lat],[a.lng,a.lat]],c=this.newFeature({type:"Feature",properties:e.properties||{},geometry:{type:n,coordinates:[s]}});return c.id=i,this._ctx.store.add(c),e[r]=c,e.currentVertexPosition=0,this._ctx.store.render(),this._simulateMouse("mousemove",t.onMouseMove,e),this._ctx.store.render(),this.dispatchVertexChange(s),!0},_restartLineStringDraw(e,t){var r=this.map._undoStack;return r&&r.clear(),this._ctx.api.changeMode("draw_line",{featureId:t,container:e.container,interfaceType:e.interfaceType,crossHair:e.crossHair,vertexMarkerId:e.vertexMarkerId,addVertexButtonId:e.addVertexButtonId,getSnapEnabled:e.getSnapEnabled,properties:e.properties}),!0}}},zr=e=>{var{ParentMode:t,getFeature:r,INTERFACE_KEYS:n}=e;return{onKeydown(e,t){"z"!==t.key||!t.metaKey&&!t.ctrlKey||t.shiftKey?document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t))):t.preventDefault()):this._handleUndoKeydown(e,t)},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&n.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e,t),"Enter"===t.key&&e.isActive&&this.doClick(e)):"keyboard"!==e.interfaceType&&this.map.fire("draw.cancel")},onKeyUp(e,n){var o=document.activeElement;if(!o||o===e.container||!e.container.contains(o))if("Escape"!==n.key)o!==e.container&&t.onKeyUp.call(this,e,n);else if("keyboard"===e.interfaceType){var i=this.map._undoStack;i&&i.clear(),this._reinitializeFeature(e,r(e))}}}};function Zr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Wr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Zr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Zr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Qr=e=>{var{ParentMode:t,getFeature:r,getCoords:n}=e;return{onTouchStart(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onTouchEnd(e,t){this._setInterface(e,"touch"),this.onMove(e,t)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onMouseMove(e,r){if(er(e)){var n=Kt(this.map);Zt(n,this.map,r.point);var o=zt(n);o&&(r=Wr(Wr({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e){if(["touch","keyboard"].includes(e.interfaceType)){er(e)&&function(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);e.snapToClosestPoint({point:n,lngLat:r})}(Kt(this.map),this.map);var r=Kt(this.map),n=er(e)&&zt(r);if(n){var o=this.map.project([n.lng,n.lat]);t.onMouseMove.call(this,e,{lngLat:n,point:o,originalEvent:new MouseEvent("mousemove",{clientX:o.x,clientY:o.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.polygon||e.line)}else this._simulateMouse("mousemove",t.onMouseMove,e)}},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onPointerup(e){this.dispatchVertexChange(n(r(e)))}}},en=e=>{var{ParentMode:t,geometryType:r,getFeature:n,getPlacedCoords:o}=e;return{_simulateMouse(e,t,r){var{map:n}=this,o=n.getCenter(),i=n.project(o);t.call(this,r,{lngLat:o,point:i,originalEvent:new MouseEvent(e,{clientX:i.x,clientY:i.y,bubbles:!0,cancelable:!0})}),this._ctx.store.render(),this.map.fire("draw.geometrychange",r.polygon||r.line)},_showCrossHair(e){e.crossHair?e.crossHair.show():e.vertexMarker.style.display="block"},_hideCrossHair(e){e.crossHair?e.crossHair.hide():e.vertexMarker.style.display="none"},_setInterface(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];e.interfaceType=t,r&&this._showCrossHair(e)},toDisplayFeatures(e,i,a){t.toDisplayFeatures.call(this,e,i,a);var s=n(e);i.geometry.type===r&&i.properties.id===s.id&&o(i).forEach(e=>a({type:"Feature",properties:{meta:"draw-vertex",parent:s.id,active:"false"},geometry:{type:"Point",coordinates:e}}))}}};function tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function rn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?tn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):tn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var nn=(e,t)=>{var{featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s=!1,finishOnInvalidClick:c=!1}=t,l={ParentMode:e,featureProp:r,geometryType:n,getCoords:o,validateClick:i,getPlacedCoords:a,excludeFeatureIdFromSetup:s,finishOnInvalidClick:c,getFeature:e=>e[r],INTERFACE_KEYS:new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"])};return rn(rn(rn(rn(rn(rn(rn({},e),Rr(l)),(e=>Br(Br({},Hr(e)),Yr(e)))(l)),(e=>Jr(Jr(Jr({},$r(e)),Kr(e)),qr(e)))(l)),zr(l)),Qr(l)),en(l))},on=nn(Yt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>u(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),an=nn(Yt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>d(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)}),sn=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],cn=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],paint:{"fill-color":sn(e,"fill",t.shapeFill)}}),ln=(e,t)=>({id:"stroke-inactive",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","false"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":sn(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),un=e=>({id:"stroke-preview-line",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":e,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),dn=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),pn=(e,t,r)=>({id:"vertex-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),hn=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),fn=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),gn=(e,t,r)=>({id:"midpoint-halo",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":r,"circle-stroke-width":3,"circle-color":e,"circle-stroke-color":t}}),yn=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),mn=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),vn=function(e){var t,r,n,i,a,s=mr(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:c,midpointRadius:l,vertexHaloRadius:u,midpointHaloRadius:d}=o;return[cn(e,s),(a=s.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":a}}),(i=s.editStroke,{id:"stroke-active",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":i,"line-width":2,"line-opacity":1}}),(n=s.invalidStroke,{id:"stroke-active-invalid",type:"line",filter:["all",["any",["==","$type","Polygon"],["==","$type","LineString"]],["==","active","true"],["!has","user_splitter"]],layout:{"line-cap":"round","line-join":"round",visibility:"none"},paint:{"line-color":n,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),ln(e,s),(r=s.splitInvalid,{id:"stroke-invalid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","invalid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":r,"line-width":2,"line-dasharray":[.2,2],"line-opacity":1}}),(t=s.splitValid,{id:"stroke-valid-splitter",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"],["==","user_splitter","valid"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":t,"line-width":2,"line-opacity":1}}),un(s.editStroke),fn(s.editMidpoint,l),gn(s.editHalo,s.editActive,d),yn(s.editMidpoint,l),dn(s.editVertex,c),pn(s.editHalo,s.editActive,u),hn(s.editVertex,c),mn(s.editStroke),{id:"touch-vertex-indicator",type:"circle",filter:["all",["==","$type","Point"],["==","meta","touch-vertex-indicator"]],paint:{"circle-radius":30,"circle-color":"#3bb2d0","circle-stroke-width":3,"circle-stroke-color":"#ffffff","circle-opacity":.9}}]};function xn(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function _n(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function bn(e,t,r){void 0===r&&(r={});var n=xn(e),o=xn(t),i=p(o[1]-n[1]),a=p(o[0]-n[0]),s=p(n[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function En(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Sn(e,t,r,n={}){const o=En(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return void 0!==o[2]?g([d,h,o[2]],n.properties):g([d,h],n.properties)}function wn(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return v(e,t);return x(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function In(e,t,r={}){if(!0===r.final)return function(e,t){let r=In(t,e);return r=(r+180)%360,r}(e,t);const n=En(e),o=En(t),i=p(n[0]),a=p(o[0]),s=p(n[1]),c=p(o[1]),l=Math.sin(a-i)*Math.cos(c),u=Math.cos(s)*Math.sin(c)-Math.sin(s)*Math.cos(c)*Math.cos(a-i);return y(Math.atan2(l,u))}var On=In;function Pn(e,t,r,n){void 0===n&&(n={});var o=xn(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return g([d,h],n.properties)}function Mn(e){if(!e)throw new Error("geojson is required");var t=[];return _(e,function(e){!function(e,t){var r=[],n=e.geometry;if(null!==n){switch(n.type){case"Polygon":r=_n(n);break;case"LineString":r=[_n(n)]}r.forEach(function(r){var n=function(e,t){var r=[];return e.reduce(function(e,n){var o,i,a,s,c,l,u=x([e,n],t);return u.bbox=(i=n,a=(o=e)[0],s=o[1],c=i[0],l=i[1],[a<c?a:c,s<l?s:l,a>c?a:c,s>l?s:l]),r.push(u),n}),r}(r,e.properties);n.forEach(function(e){e.id=t.length,t.push(e)})})}}(e,t)}),b(t)}var Cn={exports:{}};function Tn(e,t,r,n,o){Ln(e,t,r||0,n||e.length-1,o||kn)}function Ln(e,t,r,n,o){for(;n>r;){if(n-r>600){var i=n-r+1,a=t-r+1,s=Math.log(i),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(i-c)/i)*(a-i/2<0?-1:1);Ln(e,t,Math.max(r,Math.floor(t-a*c/i+l)),Math.min(n,Math.floor(t+(i-a)*c/i+l)),o)}var u=e[t],d=r,p=n;for(An(e,r,t),o(e[n],u)>0&&An(e,r,n);d<p;){for(An(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?An(e,r,p):An(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function An(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function kn(e,t){return e<t?-1:e>t?1:0}function Vn(e,t,r){if(!r)return t.indexOf(e);for(let n=0;n<t.length;n++)if(r(e,t[n]))return n;return-1}function Fn(e,t){Nn(e,0,e.children.length,t,e)}function Nn(e,t,r,n,o){o||(o=Jn(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let i=t;i<r;i++){const t=e.children[i];Dn(o,e.leaf?n(t):t)}return o}function Dn(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function jn(e,t){return e.minX-t.minX}function Rn(e,t){return e.minY-t.minY}function Un(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Bn(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Gn(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Hn(e,t){const r=Math.max(e.minX,t.minX),n=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),i=Math.min(e.maxY,t.maxY);return Math.max(0,o-r)*Math.max(0,i-n)}function Yn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Xn(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Jn(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function $n(e,t,r,n,o){const i=[t,r];for(;i.length;){if((r=i.pop())-(t=i.pop())<=n)continue;const a=t+Math.ceil((r-t)/n/2)*n;Tn(e,a,t,r,o),i.push(t,a,a,r)}}var Kn,qn=Object.freeze({__proto__:null,default:class{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(e){let t=this.data;const r=[];if(!Xn(e,t))return r;const n=this.toBBox,o=[];for(;t;){for(let i=0;i<t.children.length;i++){const a=t.children[i],s=t.leaf?n(a):a;Xn(e,s)&&(t.leaf?r.push(a):Yn(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!Xn(e,t))return!1;const r=[];for(;t;){for(let n=0;n<t.children.length;n++){const o=t.children[n],i=t.leaf?this.toBBox(o):o;if(Xn(e,i)){if(t.leaf||Yn(e,i))return!0;r.push(o)}}t=r.pop()}return!1}load(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return this}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){const e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t;return this}insert(e){return e&&this._insert(e,this.data.height-1),this}clear(){return this.data=Jn([]),this}remove(e,t){if(!e)return this;let r=this.data;const n=this.toBBox(e),o=[],i=[];let a,s,c;for(;r||o.length;){if(r||(r=o.pop(),s=o[o.length-1],a=i.pop(),c=!0),r.leaf){const n=Vn(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!Yn(r,n)?s?(a++,r=s.children[a],c=!1):r=null:(o.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}toJSON(){return this.data}fromJSON(e){return this.data=e,this}_all(e,t){const r=[];for(;e;)e.leaf?t.push(...e.children):r.push(...e.children),e=r.pop();return t}_build(e,t,r,n){const o=r-t+1;let i,a=this._maxEntries;if(o<=a)return i=Jn(e.slice(t,r+1)),Fn(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=Jn([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));$n(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);$n(e,o,t,s,this.compareMinY);for(let r=o;r<=t;r+=s){const o=Math.min(r+s-1,t);i.children.push(this._build(e,r,o,n-1))}}return Fn(i,this.toBBox),i}_chooseSubtree(e,t,r,n){for(;n.push(t),!t.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let i=0;i<t.children.length;i++){const a=t.children[i],s=Un(a),c=Gn(e,a)-s;c<o?(o=c,n=s<n?s:n,r=a):c===o&&s<n&&(n=s,r=a)}t=r||t.children[0]}return t}_insert(e,t,r){const n=r?e:this.toBBox(e),o=[],i=this._chooseSubtree(n,this.data,t,o);for(i.children.push(e),Dn(i,n);t>=0&&o[t].children.length>this._maxEntries;)this._split(o,t),t--;this._adjustParentBBoxes(n,o,t)}_split(e,t){const r=e[t],n=r.children.length,o=this._minEntries;this._chooseSplitAxis(r,o,n);const i=this._chooseSplitIndex(r,o,n),a=Jn(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Fn(r,this.toBBox),Fn(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=Jn([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Fn(this.data,this.toBBox)}_chooseSplitIndex(e,t,r){let n,o=1/0,i=1/0;for(let a=t;a<=r-t;a++){const t=Nn(e,0,a,this.toBBox),s=Nn(e,a,r,this.toBBox),c=Hn(t,s),l=Un(t)+Un(s);c<o?(o=c,n=a,i=l<i?l:i):c===o&&l<i&&(i=l,n=a)}return n||r-t}_chooseSplitAxis(e,t,r){const n=e.leaf?this.compareMinX:jn,o=e.leaf?this.compareMinY:Rn;this._allDistMargin(e,t,r,n)<this._allDistMargin(e,t,r,o)&&e.children.sort(n)}_allDistMargin(e,t,r,n){e.children.sort(n);const o=this.toBBox,i=Nn(e,0,t,o),a=Nn(e,r-t,r,o);let s=Bn(i)+Bn(a);for(let n=t;n<r-t;n++){const t=e.children[n];Dn(i,e.leaf?o(t):t),s+=Bn(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Dn(a,e.leaf?o(t):t),s+=Bn(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Dn(t[n],e)}_condense(e){for(let t,r=e.length-1;r>=0;r--)0===e[r].children.length?r>0?(t=e[r-1].children,t.splice(t.indexOf(e[r]),1)):this.clear():Fn(e[r],this.toBBox)}}}),zn=se(qn),Zn={};function Wn(){if(Kn)return Zn;Kn=1,Object.defineProperty(Zn,"__esModule",{value:!0});var e=6371008.8,t={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*e,kilometers:6371.0088,kilometres:6371.0088,meters:e,metres:e,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:e/1852,radians:1,yards:6967335.223679999},r={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,nauticalmiles:2.9155334959812285e-7,millimeters:1e6,millimetres:1e6,yards:1.195990046};function n(e,t,r={}){const n={type:"Feature"};return(0===r.id||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function o(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!f(e[0])||!f(e[1]))throw new Error("coordinates must contain numbers");return n({type:"Point",coordinates:e},t,r)}function i(e,t,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return n({type:"Polygon",coordinates:e},t,r)}function a(e,t,r={}){if(e.length<2)throw new Error("coordinates must be an array of two or more positions");return n({type:"LineString",coordinates:e},t,r)}function s(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function c(e,t,r={}){return n({type:"MultiLineString",coordinates:e},t,r)}function l(e,t,r={}){return n({type:"MultiPoint",coordinates:e},t,r)}function u(e,t,r={}){return n({type:"MultiPolygon",coordinates:e},t,r)}function d(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e*n}function p(e,r="kilometers"){const n=t[r];if(!n)throw new Error(r+" units is invalid");return e/n}function h(e){return 180*(e%(2*Math.PI))/Math.PI}function f(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}return Zn.areaFactors=r,Zn.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},Zn.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},Zn.convertArea=function(e,t="meters",n="kilometers"){if(!(e>=0))throw new Error("area must be a positive number");const o=r[t];if(!o)throw new Error("invalid original units");const i=r[n];if(!i)throw new Error("invalid final units");return e/o*i},Zn.convertLength=function(e,t="kilometers",r="kilometers"){if(!(e>=0))throw new Error("length must be a positive number");return d(p(e,t),r)},Zn.degreesToRadians=function(e){return e%360*Math.PI/180},Zn.earthRadius=e,Zn.factors=t,Zn.feature=n,Zn.featureCollection=s,Zn.geometry=function(e,t,r={}){switch(e){case"Point":return o(t).geometry;case"LineString":return a(t).geometry;case"Polygon":return i(t).geometry;case"MultiPoint":return l(t).geometry;case"MultiLineString":return c(t).geometry;case"MultiPolygon":return u(t).geometry;default:throw new Error(e+" is invalid")}},Zn.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},Zn.isNumber=f,Zn.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},Zn.lengthToDegrees=function(e,t){return h(p(e,t))},Zn.lengthToRadians=p,Zn.lineString=a,Zn.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},Zn.multiLineString=c,Zn.multiPoint=l,Zn.multiPolygon=u,Zn.point=o,Zn.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},Zn.polygon=i,Zn.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},Zn.radiansToDegrees=h,Zn.radiansToLength=d,Zn.round=function(e,t=0){if(t&&!(t>=0))throw new Error("precision must be a positive number");const r=Math.pow(10,t||0);return Math.round(e*r)/r},Zn.validateBBox=function(e){if(!e)throw new Error("bbox is required");if(!Array.isArray(e))throw new Error("bbox must be an Array");if(4!==e.length&&6!==e.length)throw new Error("bbox must be an Array of 4 or 6 numbers");e.forEach(e=>{if(!f(e))throw new Error("bbox must only contain numbers")})},Zn.validateId=function(e){if(!e)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof e))throw new Error("id must be a number or a string")},Zn}var Qn,eo={};function to(){if(Qn)return eo;Qn=1,Object.defineProperty(eo,"__esModule",{value:!0});var e=Wn();function t(e,r,n){if(null!==e)for(var o,i,a,s,c,l,u,d,p=0,h=0,f=e.type,g="FeatureCollection"===f,y="Feature"===f,m=g?e.features.length:1,v=0;v<m;v++){c=(d=!!(u=g?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var x=0;x<c;x++){var _=0,b=0;if(null!==(s=d?u.geometries[x]:u)){l=s.coordinates;var E=s.type;switch(p=!n||"Polygon"!==E&&"MultiPolygon"!==E?0:1,E){case null:break;case"Point":if(!1===r(l,h,v,_,b))return!1;h++,_++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,_,b))return!1;h++,"MultiPoint"===E&&_++}"LineString"===E&&_++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-p;i++){if(!1===r(l[o][i],h,v,_,b))return!1;h++}"MultiLineString"===E&&_++,"Polygon"===E&&b++}"Polygon"===E&&_++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(b=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-p;a++){if(!1===r(l[o][i][a],h,v,_,b))return!1;h++}b++}_++}break;case"GeometryCollection":for(o=0;o<s.geometries.length;o++)if(!1===t(s.geometries[o],r,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function r(e,t){var r;switch(e.type){case"FeatureCollection":for(r=0;r<e.features.length&&!1!==t(e.features[r].properties,r);r++);break;case"Feature":t(e.properties,0)}}function n(e,t){if("Feature"===e.type)t(e,0);else if("FeatureCollection"===e.type)for(var r=0;r<e.features.length&&!1!==t(e.features[r],r);r++);}function o(e,t){var r,n,o,i,a,s,c,l,u,d,p=0,h="FeatureCollection"===e.type,f="Feature"===e.type,g=h?e.features.length:1;for(r=0;r<g;r++){for(s=h?e.features[r].geometry:f?e.geometry:e,l=h?e.features[r].properties:f?e.properties:{},u=h?e.features[r].bbox:f?e.bbox:void 0,d=h?e.features[r].id:f?e.id:void 0,a=(c=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,o=0;o<a;o++)if(null!==(i=c?s.geometries[o]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===t(i,p,l,u,d))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===t(i.geometries[n],p,l,u,d))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===t(null,p,l,u,d))return!1;p++}}function i(t,r){o(t,function(t,n,o,i,a){var s,c=null===t?null:t.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return!1!==r(e.feature.call(void 0,t,o,{bbox:i,id:a}),n,0)&&void 0}switch(c){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u={type:s,coordinates:t.coordinates[l]};if(!1===r(e.feature.call(void 0,u,o),n,l))return!1}})}function a(r,n){i(r,function(r,o,i){var a=0;if(r.geometry){var s=r.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var c,l=0,u=0,d=0;return!1!==t(r,function(t,s,p,h,f){if(void 0===c||o>l||h>u||f>d)return c=t,l=o,u=h,d=f,void(a=0);var g=e.lineString.call(void 0,[c,t],r.properties);if(!1===n(g,o,i,f,a))return!1;a++,c=t})&&void 0}}})}function s(t,r){if(!t)throw new Error("geojson is required");i(t,function(t,n,o){if(null!==t.geometry){var i=t.geometry.type,a=t.geometry.coordinates;switch(i){case"LineString":if(!1===r(t,n,o,0,0))return!1;break;case"Polygon":for(var s=0;s<a.length;s++)if(!1===r(e.lineString.call(void 0,a[s],t.properties),n,o,s))return!1}}})}return eo.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},eo.coordEach=t,eo.coordReduce=function(e,r,n,o){var i=n;return t(e,function(e,t,o,a,s){i=0===t&&void 0===n?e:r(i,e,t,o,a,s)},o),i},eo.featureEach=n,eo.featureReduce=function(e,t,r){var o=r;return n(e,function(e,n){o=0===n&&void 0===r?e:t(o,e,n)}),o},eo.findPoint=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.coordIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return e.point.call(void 0,l,c,r);case"MultiPoint":return i<0&&(i=l.length+i),e.point.call(void 0,l[i],c,r);case"LineString":return s<0&&(s=l.length+s),e.point.call(void 0,l[s],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s),e.point.call(void 0,l[a][s],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s),e.point.call(void 0,l[i][s],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s),e.point.call(void 0,l[i][a][s],c,r)}throw new Error("geojson is invalid")},eo.findSegment=function(t,r){if(r=r||{},!e.isObject.call(void 0,r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,s=r.segmentIndex||0,c=r.properties;switch(t.type){case"FeatureCollection":o<0&&(o=t.features.length+o),c=c||t.features[o].properties,n=t.features[o].geometry;break;case"Feature":c=c||t.properties,n=t.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=t;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return s<0&&(s=l.length+s-1),e.lineString.call(void 0,[l[s],l[s+1]],c,r);case"Polygon":return a<0&&(a=l.length+a),s<0&&(s=l[a].length+s-1),e.lineString.call(void 0,[l[a][s],l[a][s+1]],c,r);case"MultiLineString":return i<0&&(i=l.length+i),s<0&&(s=l[i].length+s-1),e.lineString.call(void 0,[l[i][s],l[i][s+1]],c,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),s<0&&(s=l[i][a].length-s-1),e.lineString.call(void 0,[l[i][a][s],l[i][a][s+1]],c,r)}throw new Error("geojson is invalid")},eo.flattenEach=i,eo.flattenReduce=function(e,t,r){var n=r;return i(e,function(e,o,i){n=0===o&&0===i&&void 0===r?e:t(n,e,o,i)}),n},eo.geomEach=o,eo.geomReduce=function(e,t,r){var n=r;return o(e,function(e,o,i,a,s){n=0===o&&void 0===r?e:t(n,e,o,i,a,s)}),n},eo.lineEach=s,eo.lineReduce=function(e,t,r){var n=r;return s(e,function(e,o,i,a){n=0===o&&void 0===r?e:t(n,e,o,i,a)}),n},eo.propEach=r,eo.propReduce=function(e,t,n){var o=n;return r(e,function(e,r){o=0===r&&void 0===n?e:t(o,e,r)}),o},eo.segmentEach=a,eo.segmentReduce=function(e,t,r){var n=r,o=!1;return a(e,function(e,i,a,s,c){n=!1===o&&void 0===r?e:t(n,e,i,a,s,c),o=!0}),n},eo}var ro,no,oo={};function io(){if(ro)return oo;ro=1,Object.defineProperty(oo,"__esModule",{value:!0});var e=to();function t(t,r={}){if(null!=t.bbox&&!0!==r.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return e.coordEach.call(void 0,t,e=>{n[0]>e[0]&&(n[0]=e[0]),n[1]>e[1]&&(n[1]=e[1]),n[2]<e[0]&&(n[2]=e[0]),n[3]<e[1]&&(n[3]=e[1])}),n}var r=t;return oo.bbox=t,oo.default=r,oo}var ao=function(){if(no)return Cn.exports;no=1;var e=zn,t=Wn(),r=to(),n=io().default,o=r.featureEach;r.coordEach,t.polygon;var i=t.featureCollection;function a(t){var r=new e(t);return r.insert=function(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.insert.call(this,t)},r.load=function(t){var r=[];return Array.isArray(t)?t.forEach(function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}):o(t,function(e){if("Feature"!==e.type)throw new Error("invalid features");e.bbox=e.bbox?e.bbox:n(e),r.push(e)}),e.prototype.load.call(this,r)},r.remove=function(t,r){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:n(t),e.prototype.remove.call(this,t,r)},r.clear=function(){return e.prototype.clear.call(this)},r.search=function(t){var r=e.prototype.search.call(this,this.toBBox(t));return i(r)},r.collides=function(t){return e.prototype.collides.call(this,this.toBBox(t))},r.all=function(){var t=e.prototype.all.call(this);return i(t)},r.toJSON=function(){return e.prototype.toJSON.call(this)},r.fromJSON=function(t){return e.prototype.fromJSON.call(this,t)},r.toBBox=function(e){var t;if(e.bbox)t=e.bbox;else if(Array.isArray(e)&&4===e.length)t=e;else if(Array.isArray(e)&&6===e.length)t=[e[0],e[1],e[3],e[4]];else if("Feature"===e.type)t=n(e);else{if("FeatureCollection"!==e.type)throw new Error("invalid geojson");t=n(e)}return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}},r}return Cn.exports=a,Cn.exports.default=a,Cn.exports}(),so=ae(ao);function co(e,t){var r={},n=[];if("LineString"===e.type&&(e=E(e)),"LineString"===t.type&&(t=E(t)),"Feature"===e.type&&"Feature"===t.type&&null!==e.geometry&&null!==t.geometry&&"LineString"===e.geometry.type&&"LineString"===t.geometry.type&&2===e.geometry.coordinates.length&&2===t.geometry.coordinates.length){var o=lo(e,t);return o&&n.push(o),b(n)}var i=so();return i.load(Mn(t)),S(Mn(e),function(e){S(i.search(e),function(t){var o=lo(e,t);if(o){var i=_n(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),b(n)}function lo(e,t){var r=_n(e),n=_n(t);if(2!==r.length)throw new Error("<intersects> line1 must only contain 2 coordinates");if(2!==n.length)throw new Error("<intersects> line2 must only contain 2 coordinates");var o=r[0][0],i=r[0][1],a=r[1][0],s=r[1][1],c=n[0][0],l=n[0][1],u=n[1][0],d=n[1][1],p=(d-l)*(a-o)-(u-c)*(s-i),h=(u-c)*(i-l)-(d-l)*(o-c),f=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var y=h/p,m=f/p;return y>=0&&y<=1&&m>=0&&m<=1?g([o+y*(a-o),i+y*(s-i)]):null}function uo(e,t,r){void 0===r&&(r={});var n=g([1/0,1/0],{dist:1/0}),o=0;return _(e,function(e){for(var i=_n(e),a=0;a<i.length-1;a++){var s=g(i[a]);s.properties.dist=bn(t,s,r);var c=g(i[a+1]);c.properties.dist=bn(t,c,r);var l=bn(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=On(s,c),p=Pn(t,u,d+90,r),h=Pn(t,u,d-90,r),f=co(x([p.geometry.coordinates,h.geometry.coordinates]),x([s.geometry.coordinates,c.geometry.coordinates])),y=null;f.features.length>0&&((y=f.features[0]).properties.dist=bn(t,y,r),y.properties.location=o+bn(s,y,r)),s.properties.dist<n.properties.dist&&((n=s).properties.index=a,n.properties.location=o),c.properties.dist<n.properties.dist&&((n=c).properties.index=a+1,n.properties.location=o+l),y&&y.properties.dist<n.properties.dist&&((n=y).properties.index=a),o+=l}}),n}function po(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ho(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=po(e),i=p(o[0]),a=p(o[1]),s=p(r),c=f(t,n.units),l=Math.asin(Math.sin(a)*Math.cos(c)+Math.cos(a)*Math.sin(c)*Math.cos(s)),u=i+Math.atan2(Math.sin(s)*Math.sin(c)*Math.cos(a),Math.cos(c)-Math.sin(a)*Math.sin(l)),d=y(u),h=y(l);return g([d,h],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=po(e),o=po(t),i=p(o[1]-n[1]),a=p(o[0]-n[0]),s=p(n[1]),c=p(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return h(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,On(e,t));return r}var fo=function(){return fo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},fo.apply(this,arguments)},go=function(){function e(e){var t;this.status=null!==(t=e.status)&&void 0!==t&&t,this.map=e.map,this.drawing=e.drawing,this.options=e.options,this.onSnapped=function(t){void 0!==e.onSnapped&&e.onSnapped(t)},this.features={},this.snapStatus=!1,this.snapCoords=[],this.radiusInMeters=0,this.addRadiusCircleLayer(),this.addEvents()}return e.prototype.changeSnappedPoints=function(){for(var e=this.drawing.getAll(),t=[],r=0;r<e.features.length;r++){var n=e.features[r],o=n.id;if(this.features[o]){var i=this.features[o].snapPoints;if(void 0!==this.features.unknow){var a=this.features.unknow.snapPoints;i=fo(fo({},i),a)}var s=this.doSnap(n,i);t.push(s)}else if(void 0!==this.features.unknow){a=this.features.unknow.snapPoints,s=this.doSnap(n,a);t.push(s)}else t.push(n)}var c={type:"FeatureCollection",features:t};this.drawing.set(c),this.onSnapped&&this.onSnapped(c)},e.prototype.isPointSnapped=function(e,t){return bn(g(e),g(t),{units:"meters"})<this.radiusInMeters},e.prototype.doSnap=function(e,t){switch(e.geometry.type){case"Point":var r=e.geometry.coordinates;for(var n in t)this.isPointSnapped(r,t[n])&&(e.geometry.coordinates=t[n]);break;case"Polygon":for(var o=e.geometry.coordinates,i=[],a=0;a<o.length;a++){for(var s=o[a],c=[],l=0;l<s.length;l++){var u=s[l],d=!1;for(var n in t)if(this.isPointSnapped(u,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(u)}i.push(c)}e.geometry.coordinates=i;break;case"LineString":var p=e.geometry.coordinates;for(c=[],l=0;l<p.length;l++){var h=p[l];d=!1;for(var n in t)if(this.isPointSnapped(h,t[n])){d=!0,c.push(t[n]);break}0==d&&c.push(h)}e.geometry.coordinates=c}return e},e.prototype.getMe=function(){return this},e.prototype.setStatus=function(e){this.status=e},e.prototype.setMapData=function(e){var t=this.map.getSource("snap-helper-circle");t&&t.setData(e)},e.prototype.snapToClosestPoint=function(e){if(this.status){var t=e.point,r=this.map.unproject(t),n=[t.x+this.options.radius,t.y],o=this.map.unproject(n),i=bn(g([r.lng,r.lat]),g([o.lng,o.lat]),{units:"meters"});this.radiusInMeters=i;var a=!1,s=this.getCloseFeatures(e,i);s?(this.snapStatus=!0,this.snapCoords=s.coords,a=function(e,t,r={}){const n=r.steps||64,o=r.properties?r.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},i=[];for(let o=0;o<n;o++)i.push(Sn(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),m([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=b(0==a?[]:[a]);this.setMapData(c)}},e.prototype.addEvents=function(){var e=this;this.map.on("mousemove",function(t){e.snapToClosestPoint(t)}),this.map.on("draw.delete",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.update",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.create",function(t){setTimeout(function(){e.changeSnappedPoints()},100)}),this.map.on("draw.selectionchange",function(t){t.features.length>0?e.status=!0:(e.status=!1,e.setMapData(b([])))}),this.map.on("draw.modechange",function(t){e.status=!0,"simple_select"==t.mode&&(e.status=!1)}),this.map.on("draw.render",function(t){var r=e.map.getSource("mapbox-gl-draw-hot");if(r){var n=r._data;if(e.snapStatus){var o=[e.snapCoords[0],e.snapCoords[1]];n.features.length>0&&(n.features[0].geometry.coordinates=o)}}}),this.map.on("mouseup",function(){e.drawingSnapCheck()}),this.map.on("click",function(){e.drawingSnapCheck()})},e.prototype.drawingSnapCheck=function(){if(this.snapStatus){var e=this.map.getSource("mapbox-gl-draw-hot"),t=[this.snapCoords[0],this.snapCoords[1]],r=t[0].toFixed(6),n=t[1].toFixed(6),o={};if(o["".concat(r,"_").concat(n)]=t,e){var i=e._data;if(i.features.length>0){var a=i.features.find(function(e){return"feature"==e.properties.meta});if(a){var s=a.properties.id;this.features[s]?this.features[s].snapPoints["".concat(r,"_").concat(n)]=t:this.features[s]={id:s,snapPoints:o}}}else this.features.unknow?this.features.unknow.snapPoints["".concat(r,"_").concat(n)]=t:this.features.unknow={id:s,snapPoints:o}}}},e.prototype.searchInVertex=function(e,t,r){var n=w(e),o=[];if(n.map(function(e){var n=bn(g(e),g([t.lng,t.lat]),{units:"meters"});n<r&&o.push({coords:e,dist:n,color:"#8bc34a"})}),o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getLines=function(e,t,r){var n=[];switch(e.geometry.type){case"LineString":n.push(e);break;case"MultiLineString":e.geometry.coodinates.map(function(e){n.push(x(e))});break;case"Polygon":var o=wn(e.geometry);n.push(o);break;case"MultiPolygon":wn(e.geometry).coodinates.map(function(e){n.push(x(e))})}return n},e.prototype.searchInMidPoint=function(e,t,r){var n=this.getLines(e,t,r),o=[];n.map(function(e){o=o.concat(Mn(e).features)});var i=[];if(o.map(function(e){var n=ho(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=bn(n,g([t.lng,t.lat]),{units:"meters"});o<r&&i.push({coords:n.geometry.coordinates,dist:o,color:"#03a9f4"})}),i.length>0)return i.sort(function(e,t){return e.dist-t.dist}),i[0]},e.prototype.searchInEdge=function(e,t,r){for(var n=this.getLines(e,t,r),o=[],i=0;i<n.length;i++){var a=uo(n[i],g([t.lng,t.lat]),{units:"meters"});void 0!==a.properties.dist&&a.properties.dist<r&&o.push({coords:a.geometry.coordinates,dist:a.properties.dist,color:"#ff9800"})}if(o.length>0)return o.sort(function(e,t){return e.dist-t.dist}),o[0]},e.prototype.getCloseFeatures=function(e,t){var r=this.map.queryRenderedFeatures(e.point,{layers:this.options.layers});if(r.length>0){for(var n,o=!1,i=0;i<r.length;i++){var a=r[i],s=this.options.rules,c=e.lngLat;if(o=!1,-1!==s.indexOf("vertex")&&null==n&&(n=this.searchInVertex(a,c,t))){o=!0;break}if(-1!==s.indexOf("midpoint")&&null==n&&(n=this.searchInMidPoint(a,c,t))){o=!0;break}if(-1!==s.indexOf("edge")&&null==n&&(n=this.searchInEdge(a,c,t))){o=!0;break}}return!!o&&n}return!1},e.prototype.addRadiusCircleLayer=function(){this.map.addSource("snap-helper-circle",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:"snap-helper-circle",type:"fill",source:"snap-helper-circle",paint:{"fill-color":["get","color"],"fill-opacity":.6}})},e}(),yo="snap-helper-circle",mo="mapbox-gl-draw-hot";function vo(e){if(!go.prototype.__snapPatched){go.prototype.__snapPatched=!0;var t=go.prototype,r={setMapData:t.setMapData,drawingSnapCheck:t.drawingSnapCheck,getLines:t.getLines,getCloseFeatures:t.getCloseFeatures,searchInVertex:t.searchInVertex,searchInMidPoint:t.searchInMidPoint,searchInEdge:t.searchInEdge,snapToClosestPoint:t.snapToClosestPoint};t.changeSnappedPoints=()=>{},function(e,t){e.setMapData=function(e){var r,n;if(this.status){var o=t.setMapData.call(this,e);return(null==e||null===(r=e.features)||void 0===r?void 0:r.length)>0&&null!==(n=this.map)&&void 0!==n&&n.getLayer(yo)&&this.map.setLayoutProperty(yo,"visibility","visible"),o}},e.drawingSnapCheck=function(){if(this.status)return t.drawingSnapCheck.call(this)}}(t,r),function(e,t){e.getLines=function(e,r,n){var o=e.geometry;if(null==o||!o.coordinates)return[];var i=o.coordinates;if(!Array.isArray(i)||0===i.length)return[];try{return"MultiPolygon"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>m(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>x(e)):t.getLines.call(this,e,r,n)}catch(e){return[]}},e.getCloseFeatures=function(e,r){if(!this.status)return[];var o=this._activeLayers||this._defaultLayers||[];this.options.layers=o.filter(e=>this.map.getLayer(e));var i=this.options.radius||n.snapRadius,a=e.point;e.point=[[a.x-i,a.y-i],[a.x+i,a.y+i]];var s=t.getCloseFeatures.call(this,e,r);return e.point=a,s}}(t,r),function(e,t,r){e.searchInVertex=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInVertex.apply(this,n);return i&&(i.color=r.vertex),i},e.searchInMidPoint=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInMidPoint.apply(this,n);return i&&(i.color=r.midpoint),i},e.searchInEdge=function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=t.searchInEdge.apply(this,n);return i&&(i.color=r.edge),i}}(t,r,e),function(e,t){e.snapToClosestPoint=function(e){var r;if(this.status&&(null===(r=this.map)||void 0===r||!r._isZooming))try{var n,o,i=t.snapToClosestPoint.call(this,e);return(null===(n=this.closeFeatures)||void 0===n?void 0:n.length)>100&&(this.closeFeatures.length=0),(null===(o=this.lines)||void 0===o?void 0:o.length)>100&&(this.lines.length=0),i}catch(e){return this.snapStatus=!1,void(this.snapCoords=null)}}}(t,r)}}function xo(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function _o(e){var t;if(!(!e||e._data&&Array.isArray(null===(t=e._data)||void 0===t?void 0:t.features))){var r={type:"FeatureCollection",features:[]};Object.defineProperty(e,"_data",{get:()=>r,set:e=>{r=e&&"object"==typeof e&&Array.isArray(e.features)?e:{type:"FeatureCollection",features:[]}},configurable:!0})}}var bo=new Set(["draw_polygon","draw_line","edit_vertex"]);function Eo(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(yo)&&e.removeLayer(yo),e.getSource(yo)&&e.removeSource(yo)}(e),_o(r);var o=new go({map:e,drawing:t,options:{layers:n.layers,radius:n.radius,rules:n.rules},status:n.status,onSnapped:n.onSnapped});return function(e,t,r){var n=t;Object.defineProperty(e,"status",{get:()=>n&&bo.has(r.getMode()),set(){},configurable:!0}),e.setSnapStatus=e=>{n=e}}(o,n.status,t),function(e,t){e._defaultLayers=t,e._activeLayers=null,e.setSnapLayers=t=>{null==t?e._activeLayers=null:Array.isArray(t)&&(e._activeLayers=t)}}(o,n.layers),void 0!==e._pendingSnapLayers&&(o.setSnapLayers(e._pendingSnapLayers),delete e._pendingSnapLayers),e._snapInstance=o,o}function So(e,t,r){e.on("style.load",()=>{xo(()=>e._removed?null:e.getSource(mo),n=>{_o(n),function(e){var t;e.getSource(yo)||e.addSource(yo,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(yo)||e.addLayer({id:yo,type:"fill",source:yo,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Eo(e,t,n,r)})})}function wo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Io(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:a=[],radius:s=n.snapRadius,rules:c=["vertex","midpoint","edge"],status:l=!1,onSnapped:u=()=>{},colors:d={}}=o,p={layers:a,radius:s,rules:c,status:l,onSnapped:u};return vo(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?wo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):wo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:i.snapVertex,midpoint:i.snapMidpoint,edge:i.snapEdge},d)),So(t,r,p),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(yo)){e.setLayoutProperty(yo,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(yo,"visibility","visible")}})}(t),xo(()=>t._removed?null:t.getSource(mo),e=>Eo(t,r,e,p)),t._snapInstance}var Oo=e=>{var t=[];return{push(r){t.push(r),e(t.length)},pop(){var r=t.pop();return e(t.length),r},clear(){t.length=0,e(t.length)},get length(){return t.length}}};function Po(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Mo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Po(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Po(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Co=e=>{var t,{mapStyle:r,mapProvider:o,events:i,eventBus:a,snapLayers:s,pluginConfig:c={}}=e,{map:l}=o;Yt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Yt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Yt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var u=Mo(Mo({},Yt.modes),{},{disabled:Xt,edit_vertex:Nr,draw_polygon:on,draw_line:an}),d=o._mapboxDrawInstance;d?Object.assign(d.modes,u):(d=new Yt({modes:u,styles:vn(r,c),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),l.addControl(d),o._mapboxDrawInstance=d);var p=((e,t)=>{var r=e.getCanvas(),n=null,o=e=>{1===e.touches.length&&(n={x:e.touches[0].clientX,y:e.touches[0].clientY,time:Date.now()})},i=e=>{if("disabled"===t.getMode()&&n){var o=e.changedTouches[0],i=o.clientX-n.x,a=o.clientY-n.y;Date.now()-n.time<300&&Math.abs(i)<10&&Math.abs(a)<10&&r.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,clientX:o.clientX,clientY:o.clientY})),n=null}else n=null};return r.addEventListener("touchstart",o,{passive:!0}),r.addEventListener("touchend",i,{passive:!0}),{remove(){r.removeEventListener("touchstart",o),r.removeEventListener("touchend",i)}}})(l,d);o.draw=d,l._drawCurrentMapStyle=r,l._drawPluginConfig=c,o.snapEnabled=!1;var h=o.undoStack;h||(h=Oo(e=>l.fire("draw.undochange",{length:e})),o.undoStack=h),l._undoStack=h;var f=mr(r,c);Io(l,d,{layers:s,radius:null!==(t=c.snapRadius)&&void 0!==t?t:n.snapRadius,rules:["vertex","edge"],colors:{vertex:f.snapVertex,edge:f.snapEdge}});var g=e=>{l._drawCurrentMapStyle=e,l.once("idle",()=>{var t;!function(e,t){vn(t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).forEach(t=>{Object.entries(t.paint).forEach(r=>{var[n,o]=r;e.getLayer("".concat(t.id,".cold"))&&e.setPaintProperty("".concat(t.id,".cold"),n,o),e.getLayer("".concat(t.id,".hot"))&&e.setPaintProperty("".concat(t.id,".hot"),n,o)})})}(l,e,c);var r=null===(t=l._drawEditContainer)||void 0===t?void 0:t.querySelector("[data-im-draw-touch-target]");_r(r,e,c)})};a.on(i.MAP_SET_STYLE,g);var y=e=>{l.fire("draw.scalechange",{scale:I[e]})};return a.on(i.MAP_SET_SIZE,y),{draw:d,remove(){p.remove(),a.off(i.MAP_SET_STYLE,g),a.off(i.MAP_SET_SIZE,y),d.changeMode("disabled"),o.draw=null}}},To="draw.create",Lo="draw.update",Ao="draw.modechange",ko="draw.editfinish",Vo="draw.cancel",Fo="draw.vertexselection",No="draw.vertexchange",Do="draw.undochange",jo="draw.undo",Ro="draw.geometrychange",Uo="draw.interfacetypechange",Bo="draw.placementblocked",Go="draw.nudgevertex",Ho="styledata";function Yo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Xo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Yo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Yo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Jo=e=>"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,16),$o=e=>"function"==typeof cancelAnimationFrame?cancelAnimationFrame(e):clearTimeout(e),Ko=e=>{var{onChange:t,validate:r=O}=e,n=!1,o=null,i=null,a=()=>{null!=o&&($o(o),o=null),i=null},s=(e,r)=>{e!==n&&(n=e,t(e,null!=r?r:null))},c=()=>{if(o=null,i){var{feature:e,context:t,onGeometryChange:n}=i,{valid:a,reason:c}=r(e,t,{onGeometryChange:n});s(!a,c)}};return{update(e){var{feature:t,context:n={},numVertices:l,onGeometryChange:u}=e,d=Xo(Xo({},n),{},{numVertices:l}),p=r(t,d);return p.valid?"function"!=typeof u?(a(),void s(!1,null)):(i={feature:t,context:d,onGeometryChange:u},void(null==o&&(o=Jo(c)))):(a(),void s(!0,p.reason))},set(e,t){a(),s(e,null!=t?t:null)},refresh(){t(n,null)},destroy(){a()}}};function qo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function zo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Zo=e=>{var{onStrokeChange:t,onPlaceChange:r}=e,n=e=>{var t=!1;return(r,n)=>{r!==t&&(t=r,e(r,null!=n?n:null))}},o=n(t),i=n(r),s=!1,c=null,l=null,u=null,d=()=>{null!=l&&($o(l),l=null),u=null},p=(e,t,r,n,o)=>{var i,a=(null!==(i=t.numVertices)&&void 0!==i?i:0)<n?{valid:!0}:P(e,zo(zo({},t),{},{phase:"preview"}),{rules:r});o(!a.valid||s,a.valid?c:a.reason)},h=()=>{var e,t;if(u){var{feature:r,context:n}=u,s=null!==(e=a[null==r||null===(t=r.geometry)||void 0===t?void 0:t.type])&&void 0!==e?e:0;p(r,n,M,s,o),p(r,n,C,0,i)}},f=()=>{if(l=null,u){var{feature:e,context:t,onGeometryChange:r}=u,n=P(e,zo(zo({},t),{},{phase:"preview"}),{rules:[],onGeometryChange:r});s=!n.valid,c=n.reason,h()}};return{update(e){var{feature:t,context:r={},numVertices:n,onGeometryChange:o}=e;u={feature:t,context:zo(zo({},r),{},{numVertices:n}),onGeometryChange:o},h(),"function"==typeof o&&null==l&&(l=Jo(f))},reset(){d(),s=!1,c=null,o(!1,null),i(!1,null)},destroy(){d()}}};function Wo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Qo(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Wo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Wo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ei=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),ti=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),ri=(e,t)=>{var r,n,o,i,a,s,c;return"draw_polygon"===e?{feature:ei(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1}:"draw_line"===e?{feature:ti(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1}:"edit_vertex"===e?Array.isArray(null===(i=t[0])||void 0===i?void 0:i[0])?{feature:ei(t),numVertices:null!==(a=null===(s=t[0])||void 0===s?void 0:s.length)&&void 0!==a?a:0}:{feature:ti(t),numVertices:null!==(c=null==t?void 0:t.length)&&void 0!==c?c:0}:null};var ni=Object.freeze({__proto__:null,MaplibreDrawAdapter:class{constructor(e,t){var r,n;this._mapProvider=e,this._map=e.map,this._bus=(n=new Map,{on(e,t){n.has(e)||n.set(e,new Set),n.get(e).add(t)},off(e,t){var r;null===(r=n.get(e))||void 0===r||r.delete(t)},emit(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];var i=n.get(e);i&&Array.from(i).forEach(e=>e(...r))}}),this._editingFeatureId=null;var{draw:o,remove:i}=Co({mapStyle:t.mapStyle,mapProvider:e,events:t.events,eventBus:t.eventBus,snapLayers:t.snapLayers,pluginConfig:null!==(r=t.pluginConfig)&&void 0!==r?r:{}});this._draw=o,this._cleanupDraw=i,this._liveStroke=Ko({onChange:(e,t)=>{this._applyStrokeInvalid(e),"edit_vertex"===this._draw.getMode()&&this._bus.emit(T.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=Zo({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(T.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>this._bus.emit(T.CREATE,e.features[0]),editfinish:e=>this._bus.emit(T.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(T.CANCEL),vertexselection:e=>this._bus.emit(T.VERTEX_SELECTION,Qo(Qo({},e),{},{numVertices:e.numVertecies})),vertexchange:e=>this._bus.emit(T.VERTEX_CHANGE,Qo(Qo({},e),{},{numVertices:e.numVertecies})),undochange:e=>this._bus.emit(T.UNDO_CHANGE,e.length),update:e=>this._bus.emit(T.UPDATE,e.features[0]),geometrychange:e=>{null!=e&&e.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(T.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(T.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(T.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(To,this._mapHandlers.create),this._map.on(ko,this._mapHandlers.editfinish),this._map.on(Vo,this._mapHandlers.cancel),this._map.on(Fo,this._mapHandlers.vertexselection),this._map.on(No,this._mapHandlers.vertexchange),this._map.on(Do,this._mapHandlers.undochange),this._map.on(Lo,this._mapHandlers.update),this._map.on(Ro,this._mapHandlers.geometrychange),this._map.on(Bo,this._mapHandlers.placementblocked),this._map.on(Uo,this._mapHandlers.interfacetypechange),this._map.on(Ao,this._mapHandlers.modechange),this._map.on(Ho,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"===e&&(this._editingFeatureId=null!==(t=r.featureId)&&void 0!==t?t:null);"draw_polygon"!==e&&"draw_line"!==e||(this._liveStroke.set(!1),this._liveDrawChecks.reset()),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=ri(t,e.coordinates);r&&("draw_polygon"===t||"draw_line"===t?this._liveDrawChecks.update({feature:r.feature,numVertices:r.numVertices,context:{mode:t},onGeometryChange:this._geometryValidator}):this._liveStroke.update(Qo(Qo({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(Uo,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if("edit_vertex"===t&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(ko,{features:[this._draw.get(this._editingFeatureId)]});"draw_polygon"!==t&&"draw_line"!==t||(this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"}))}cancel(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();"draw_polygon"!==t&&"draw_line"!==t||this._draw.trash(),this._draw.changeMode("disabled"),this._handleModeChange({mode:"disabled"})}undo(){this._map.fire(jo)}nudgeSelectedVertex(e,t,r){this._map.fire(Go,{dx:e,dy:t,isLargeStep:r})}setGeometryValid(e){this._map._drawGeometryValid=e}set _geometryValidator(e){this._map._drawGeometryValidator=e}get _geometryValidator(){return this._map._drawGeometryValidator}setInvalid(e){this._liveStroke.set(e)}_applyStrokeInvalid(e){this._setLayerVisibility("stroke-active",!e),this._setLayerVisibility("stroke-active-invalid",e),this._setLayerVisibility("fill-active",!e)}_setLayerVisibility(e,t){["hot","cold"].forEach(r=>{var n="".concat(e,".").concat(r);this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility",t?"visible":"none")})}deleteVertex(){}get(e){return this._draw.get(e)}add(e){return this._draw.add(e)}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=Kt(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(Qt(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=Kt(this._map);null!=t&&t.setSnapLayers?t.setSnapLayers(e):e&&(this._map._pendingSnapLayers=e)}isSnapEnabled(){return!0===this._mapProvider.snapEnabled}setFeatureProperty(e,t,r){this._draw.setFeatureProperty(e,t,r)}setDrawingPreviewProperty(e,t){var r,n=this._currentDrawEvent;null!=n&&n.properties&&(n.properties[e]=t),null==n||null===(r=n.ctx)||void 0===r||null===(r=r.store)||void 0===r||r.render()}on(e,t){this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}_handleModeChange(e){new Set(["draw_polygon","draw_line","edit_vertex"]).has(e.mode)||Wt(Kt(this._map),this._map)}_handleStyleData(){var e;this._liveStroke.refresh();var t=this._map.getStyle().layers||[];!t.length||null!==(e=t[t.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||t.filter(e=>{var t;return null===(t=e.source)||void 0===t?void 0:t.startsWith("mapbox-gl-draw")}).forEach(e=>this._map.moveLayer(e.id))}remove(){this._map.off(To,this._mapHandlers.create),this._map.off(ko,this._mapHandlers.editfinish),this._map.off(Vo,this._mapHandlers.cancel),this._map.off(Fo,this._mapHandlers.vertexselection),this._map.off(No,this._mapHandlers.vertexchange),this._map.off(Do,this._mapHandlers.undochange),this._map.off(Lo,this._mapHandlers.update),this._map.off(Ro,this._mapHandlers.geometrychange),this._map.off(Bo,this._mapHandlers.placementblocked),this._map.off(Uo,this._mapHandlers.interfacetypechange),this._map.off(Ao,this._mapHandlers.modechange),this._map.off(Ho,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}},displayedShape:ri});export{ni as M,Zo as a,pr as b,Ko as c,hr as d,Oo as e,gr as h,yr as i,mr as r,fr as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"ol/layer/Vector.js";import n from"ol/source/Vector.js";import a from"ol/format/GeoJSON.js";import{c as o,a as i,b as l,d,h as s,s as c,i as u,e as v,r as p}from"./im-draw-ml-adapter.js";import g from"ol/style/Style.js";import y from"ol/style/Fill.js";import m from"ol/style/Stroke.js";import h from"ol/style/Circle.js";import x from"ol/geom/MultiPoint.js";import{S as f,T as S,A as I,M as w,a as T,w as V,K as P,s as C,t as b}from"./im-draw-plugin.js";import{transform as _}from"ol/proj.js";import E from"ol/layer/VectorTile.js";import L from"ol/Feature.js";import k from"ol/geom/Point.js";import{Style as O}from"ol/style.js";import D from"ol/interaction/Interaction.js";import F from"ol/interaction/Draw.js";import{noModifierKeys as j}from"ol/events/condition.js";import M from"ol/interaction/Modify.js";import A from"ol/Collection.js";import"preact/compat";import"@babel/runtime/helpers/objectWithoutProperties";var G="EPSG:27700",R=new a({dataProjection:G,featureProjection:G}),H=()=>{var e=new n;return{source:e,getOL(t){var r;return null!==(r=e.getFeatureById(String(t)))&&void 0!==r?r:null},add(t){var r=this.getOL(t.id);r&&e.removeFeature(r);var n=R.readFeature(t);return e.addFeature(n),n},get(e){var t=this.getOL(e);return t?R.writeFeatureObject(t):null},remove(t){var r=Array.isArray(t)?t:[t];for(var n of r){var a=this.getOL(n);a&&e.removeFeature(a)}},clear(){e.clear()},toGeoJSON:e=>R.writeFeatureObject(e),fromGeoJSON:e=>R.readFeature(e)}},N={Polygon:2,LineString:1},U=e=>{var t,r=e.getType();return("Polygon"===r?null!==(t=e.getCoordinates()[0])&&void 0!==t?t:[]:e.getCoordinates()).slice(0,-N[r])},B=e=>{var t;return null!==(t=U(e).at(-1))&&void 0!==t?t:null},q={outer:f.vertexHaloRadius+3,mid:f.vertexHaloRadius,inner:f.vertexRadius},Y={outer:f.midpointHaloRadius+3,mid:f.midpointHaloRadius,inner:f.midpointRadius},z=(e,t,r,n,a)=>{e.beginPath(),e.arc(t,r,n,0,2*Math.PI),e.fillStyle=a,e.fill()},K=(e,t,r)=>{var{outer:n,mid:a,inner:o}=e;return(e,i)=>{var l=i.context,d=i.pixelRatio,[s,c]=e;l.save(),z(l,s,c,n*d,t.editActive),z(l,s,c,a*d,t.editHalo),z(l,s,c,o*d,t[r]),l.restore()}},X=e=>e.charAt(0).toUpperCase()+e.slice(1),W=e=>{var{vertexImage:t,vertexStyle:r,selectedVertexStyle:n}=(e=>{var t=new h({radius:f.vertexRadius,fill:new y({color:e.editVertex})});return{vertexImage:t,vertexStyle:new g({image:t}),selectedVertexStyle:new g({renderer:K(q,e,"editVertex")})}})(e),{midpointStyle:a,selectedMidpointStyle:o}=(e=>({midpointStyle:new g({image:new h({radius:f.midpointRadius,fill:new y({color:e.editMidpoint})})}),selectedMidpointStyle:new g({renderer:K(Y,e,"editMidpoint")})}))(e),i=new g({stroke:new m({color:e.editStroke,width:2}),fill:new y({color:e.editFill})}),l=new g({stroke:new m({color:e.invalidStroke,width:2,lineDash:[2,4]})}),d=(e=>({valid:new g({stroke:new m({color:e.editStroke,width:2}),fill:new y({color:e.editFill})}),invalid:new g({stroke:new m({color:e.invalidStroke,width:2,lineDash:[2,4]})}),splitValid:new g({stroke:new m({color:e.splitValid,width:2})}),splitInvalid:new g({stroke:new m({color:e.splitInvalid,width:2,lineDash:[2,4]})})}))(e),s=new x([]),c=new g({image:t,geometry:e=>{var t=U(e.getGeometry());return t.length?(s.setCoordinates(t),s):null}});return{vertexStyle:r,selectedVertexStyle:n,midpointStyle:a,selectedMidpointStyle:o,editFeatureStyle:i,editFeatureStyleInvalid:l,createSketchStyle:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return r=>{var n=r.getGeometry().getType();if("Point"===n)return[];var a=r.get("splitter"),o=t?d.invalid:d.valid;return"valid"===a&&(o=d.splitValid),"invalid"===a&&(o=d.splitInvalid),n===e?[o,c]:[o]}},createFeatureStyle:()=>t=>{var r=t.getProperties(),n=e.mapStyleId,a=n&&r["stroke".concat(X(n))]||r.stroke||e.shapeStroke,o=n&&r["fill".concat(X(n))]||r.fill||e.shapeFill,i=r.strokeWidth||e.strokeWidth;return[new g({stroke:new m({color:a,width:i}),fill:new y({color:o})})]}}},J=(e,t)=>{var r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n},Z=(e,t,r)=>{var n=r[0]-t[0],a=r[1]-t[1],o=n*n+a*a;if(0===o)return[t[0],t[1]];var i=Math.max(0,Math.min(1,((e[0]-t[0])*n+(e[1]-t[1])*a)/o));return[t[0]+i*n,t[1]+i*a]},Q=(e,t)=>$(e,t)?t:e,$=(e,t)=>e?!!t&&("edge"===e.type&&"vertex"===t.type||("vertex"!==e.type||"edge"!==t.type)&&t.distSq<e.distSq):!!t,ee=(e,t,r,n)=>{for(var a=null,o=n&&e.length>1?e.length-1:e.length,i=n?o:o-1,l=0;l<o;l++){var d=e[l],s=J(t,d);s<=r&&(a=Q(a,{type:"vertex",coord:[d[0],d[1]],distSq:s}))}for(var c=0;c<i;c++){var u=e[c],v=e[(c+1)%o],p=Z(t,u,v),g=J(t,p);g<=r&&(a=Q(a,{type:"edge",coord:p,distSq:g}))}return a},te=(e,t,r,n,a,o)=>{for(var i=null,l=0;l<n;l++){var d=t+2*l,s=t+(l+1)%r*2,c=[e[d],e[d+1]],u=[e[s],e[s+1]],v=Z(a,c,u),p=J(a,v);p<=o&&(i=Q(i,{type:"edge",coord:v,distSq:p,seg:[c,u]}))}return i},re=(e,t,r)=>[e>0||r?e>0?e-1:t-1:null,e<t-1||r?e<t-1?e+1:0:null],ne=(e,t,r,n,a,o)=>{for(var i=n===r,l=r=>null===r?null:[e[t+2*r],e[t+2*r+1]],d=null,s=0;s<r;s++){var c=l(s),u=J(a,c);if(u<=o){var[v,p]=re(s,r,i),g=[l(v),l(p)];d=Q(d,{type:"vertex",coord:c,distSq:u,adjacent:g})}}return d},ae=(e,t,r,n,a,o)=>{var i=(r-t)/2,l=o?i:i-1;return{vertex:ne(e,t,i,l,n,a),edge:te(e,t,i,l,n,a)}},oe={point:(e,t,r)=>{var n=e.getCoordinates(),a=J(t,n);return a<=r?{type:"vertex",coord:[n[0],n[1]],distSq:a}:null},lineString:(e,t,r)=>ee(e.getCoordinates(),t,r,!1),linearRing:(e,t,r)=>ee(e.getCoordinates(),t,r,!0),polygon:(e,t,r)=>{var n=null;for(var a of e.getCoordinates())n=Q(n,ee(a,t,r,!0));return n},multiLineString:(e,t,r)=>{var n=null;for(var a of e.getCoordinates())n=Q(n,ee(a,t,r,!1));return n},multiPolygon:(e,t,r)=>{var n=null;for(var a of e.getCoordinates())for(var o of a)n=Q(n,ee(o,t,r,!0));return n}},ie=(e,t,r)=>{var n=e.getGeometry();if(!n)return null;var a=n.getType(),o=oe[a[0].toLowerCase()+a.slice(1)];return o?o(n,t,r):null};function le(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function de(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?le(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):le(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var se=(e,t,r)=>{if(!t||!r)return!1;var[n,a,o,i]=e.extent,l=(t,r,n)=>Math.min(Math.abs(t-r),Math.abs(t-n))<=e.band,d=Math.abs(t[0]-r[0])<=e.eps&&l(t[0],n,o),s=Math.abs(t[1]-r[1])<=e.eps&&l(t[1],a,i);return d||s},ce=(e,t)=>{var r,n=((e,t)=>{if(!e)return null;var{tileGrid:r,viewProj:n,sourceProj:a,zoom:o}=e,i=e=>e?_(e,n,a):null,l=i(t),d=r.getTileCoordForCoordAndZ(l,o),s=r.getTileCoordExtent(d),c=s[2]-s[0];return{toSource:i,anchor:l,extent:s,band:.0625*c,eps:c/4096*2}})(e,t.coord);if(!n)return!1;if("edge"===t.type){var[a,o]=t.seg;return se(n,n.toSource(a),n.toSource(o))}var[i,l]=null!==(r=t.adjacent)&&void 0!==r?r:[];return se(n,n.anchor,n.toSource(i))||se(n,n.anchor,n.toSource(l))},ue=()=>!0===globalThis.DEBUG_SNAP_VISIBILITY,ve=(e,t)=>{ue()&&console.log("[snap-candidate-found]",{type:e.type,layerId:null==t?void 0:t.id,layerType:null==t?void 0:t.type,coord:[e.coord[0].toFixed(2),e.coord[1].toFixed(2)],distSq:e.distSq.toFixed(2)})},pe=e=>{var{candidate:t,cursorCoord:r,mapboxLayer:n,boundaryState:a,map:o,vtLayers:i,resolution:l}=e;return ce(a,t)?(ue()&&console.log("[snap-filtered] tile clip artefact",t.type),!0):!("edge"!==t.type||"fill"!==(null==n?void 0:n.type)||!((e,t,r,n,a,o)=>{var i=e[0]-t[0],l=e[1]-t[1],d=i*i+l*l;if(d<1)return!1;var s=Math.sqrt(d),c=4*o,u=[e[0]+i/s*c,e[1]+l/s*c],v=n.getPixelFromCoordinate(u);return!!v&&!!n.forEachFeatureAtPixel(v,e=>{var t;return(null===(t=e.get("mapbox-layer"))||void 0===t?void 0:t.id)===r},{hitTolerance:2,layerFilter:e=>a.includes(e)})})(t.coord,r,n.id,o,i,l))&&(ue()&&console.log("[snap-filtered] invisible fill boundary"),!0)},ge=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=new Set,a=[],o=e=>{for(var t of(n=new Set,a=[],null!=e?e:[]))"string"==typeof t?n.add(t):t instanceof r&&a.push(t)};o(t);return{query:(t,r)=>{ue()&&console.log("[snap-query]",{coord:[t[0].toFixed(2),t[1].toFixed(2)],radiusPx:r,vtLayerCount:n.size,olLayerCount:a.length});var o=e.getView().getResolution();if(!o)return null;var i=r*o,l=i*i,d=[t[0]-i,t[1]-i,t[0]+i,t[1]+i],s=null;for(var c of a){var u=c.getSource();if(u)for(var v of u.getFeaturesInExtent(d))s=Q(s,ie(v,t,l))}if(n.size>0){var p=(e=>{var t=[];return e.getLayers().forEach(e=>{e instanceof E&&t.push(e)}),t})(e),g=p.length>0?e.getPixelFromCoordinate(t):null;if(g){var y=new Map;e.forEachFeatureAtPixel(g,(r,a)=>{var i=r.get("mapbox-layer");if(n.has(null==i?void 0:i.id)){var d=((e,t,r)=>{var n=e.getType(),a=e.getFlatCoordinates(),o=null,i=null;if("Point"===n){var l=J(t,a);l<=r&&(o={type:"vertex",coord:[a[0],a[1]],distSq:l})}else if("LineString"===n)({vertex:o,edge:i}=ae(a,0,a.length,t,r,!1));else if("Polygon"===n||"MultiLineString"===n){var d=e.getEnds(),s=0,c="Polygon"===n;for(var u of d){var v=ae(a,s,u,t,r,c);o=Q(o,v.vertex),i=Q(i,v.edge),s=u}}return[o,i].filter(Boolean)})(r,t,l);if(d.length){y.has(a)||y.set(a,((e,t)=>{var r,n=e.getSource(),a=null==n?void 0:n.getTileGrid();if(!a)return null;var o=t.getView().getProjection(),i=null!==(r=n.getProjection())&&void 0!==r?r:o,l=a.getZForResolution(t.getView().getResolution(),0);return{tileGrid:a,viewProj:o,sourceProj:i,zoom:l}})(a,e));var c=y.get(a);s=((e,t,r)=>{var n=e;for(var a of t)ve(a,r.mapboxLayer),pe(de({candidate:a},r))||(n=Q(n,a));return n})(s,d,{cursorCoord:t,mapboxLayer:i,boundaryState:c,map:e,vtLayers:p,resolution:o})}}},{hitTolerance:r,layerFilter:e=>p.includes(e)})}}return s?{type:s.type,coord:s.coord}:null},setLayers:o}},ye=e=>(t,r)=>{var n=r.context,[a,o]=t;n.beginPath(),n.arc(a,o,10*r.pixelRatio,0,2*Math.PI),n.fillStyle=e,n.fill()},me=e=>({vertex:new O({renderer:ye(e.snapVertex)}),edge:new O({renderer:ye(e.snapEdge)})}),he=new Set(["pointermove","pointerdrag","pointerdown","pointerup","singleclick","click"]),xe=(e,t,r,n)=>{var a=new D({handleEvent:o=>(a.getActive()&&((e,t,r,n,a)=>{var{type:o}=e;if("pointerout"!==o&&"pointerleave"!==o){if(he.has(o)){var i=t.query(e.coordinate,n);i&&(e.coordinate=i.coord.slice()),"pointermove"===o&&a()?i?r.show(i.coord,i.type):r.hide():"pointerdrag"===o&&r.hide()}}else r.hide()})(o,e,t,r,n),!0)});return a},fe=(e,t,a,o)=>{if(null==t||!t.length)return null;var i=ge(e,t),l=((e,t)=>{var a=me(t),o=new n,i=new r({source:o,style:e=>{var t;return null!==(t=a[e.get("snapType")])&&void 0!==t?t:null},zIndex:200,updateWhileAnimating:!0,updateWhileInteracting:!0});e.addLayer(i);var l=new L,d=!1;return{show(e,t){l.setGeometry(new k(e)),l.set("snapType",t,!0),d?o.changed():(o.addFeature(l),d=!0)},hide(){d&&(o.clear(),d=!1)},updateColors(e){a=me(e),d&&o.changed()},remove(){o.clear(),e.removeLayer(i)}}})(e,a),d=!1,s=xe(i,l,o,()=>d);e.addInteraction(s),s.setActive(!1);var c=!1;return{snapRadius:o,apply(e){if(!c)return e;var t=i.query(e,o);return t?(l.show(t.coord,t.type),t.coord):(l.hide(),e)},hideIndicator(){l.hide()},setIndicatorActive(e){d=e,e||l.hide()},setActive(e){c=e,s.setActive(e),e||l.hide()},setSnapLayers(e){i.setLayers(null==e?t:e)},reattach(){e.removeInteraction(s),e.addInteraction(s)},updateColors(e){l.updateColors(e)},destroy(){e.removeInteraction(s),l.remove()}}},Se=(e,t)=>{var r=e.getPixelFromCoordinate(t);return r?{x:r[0],y:r[1]}:null},Ie=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2),we=(e,t,r,n)=>{var a=e.getPixelFromCoordinate(t);return a?e.getCoordinateFromPixel([a[0]+r,a[1]+n]):t},Te=4,Ve=e=>{var{drawInteraction:t,canFinish:r,geom:n,sketchCoords:a,coord:o,lastPlacedCoord:i}=e;if(i&&i[0]===o[0]&&i[1]===o[1])return null!=r&&r()&&t.finishDrawing(),{handled:!0,lastPlacedCoord:null};var l=t.getMap();if(((e,t,r,n)=>{if("Polygon"!==n||r.length<Te)return!1;var a=Se(e,t),o=Se(e,r[0]);return!(!a||!o)&&Ie(a,o)<12})(l,o,a,n.getType()))return t.finishDrawing(),{handled:!0,lastPlacedCoord:i};var d=B(n);if(d){var s=l.getPixelFromCoordinate(d),c=l.getPixelFromCoordinate(o);if(s&&c){var u=s[0]-c[0],v=s[1]-c[1];if(u*u+v*v<4)return{handled:!0,lastPlacedCoord:o}}}return{handled:!1,lastPlacedCoord:i}},Pe=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Ce=e=>{var t,{drawInteraction:r,options:n}=e,{container:a,addVertexButtonId:o,mapProvider:i,snap:l,onUndo:d,canFinish:s,canPlace:c}=n,u=null!==(t=n.interfaceType)&&void 0!==t?t:"mouse",v=()=>u,p=(e=>{var{drawInteraction:t,mapProvider:r,snap:n,canFinish:a,canPlace:o,getInterfaceType:i}=e,l=null,d=null,s=function(){l=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,d=null};t.on("drawstart",e=>s(e.feature)),t.on("drawend",()=>s()),t.on("drawabort",()=>s());var c=()=>{var e=r.getCenter();return"mouse"!==i()&&n?n.apply(e):e};return{placeVertex:()=>{var e=c();if(null==n||n.hideIndicator(),l){var r=l.getGeometry(),i=r.getCoordinates(),s="Polygon"===r.getType()?i[0]||[]:i,u=Ve({drawInteraction:t,canFinish:a,geom:r,sketchCoords:s,coord:e,lastPlacedCoord:d});if(d=u.lastPlacedCoord,u.handled)return}o&&!o(e)||(t.appendCoordinates([e]),d=e)},updateRubberbanding:()=>{if(l){var e=l.getGeometry();e.getCoordinates().length&&((e,t)=>{if("LineString"===e.getType()){var r=[...e.getCoordinates()];r[r.length-1]=t,e.setCoordinates(r)}else if("Polygon"===e.getType()){var n=e.getCoordinates().map((e,r)=>{if(0!==r)return e;var n=[...e];return n[n.length-1]=t,n});e.setCoordinates(n)}})(e,c())}else"mouse"!==i()&&n&&n.apply(r.getCenter())},clearLastCoord(){d=null}}})({drawInteraction:r,mapProvider:i,snap:l,canFinish:s,canPlace:c,getInterfaceType:v}),g=r.getMap(),y=null==g?void 0:g.getView(),m=(e=>{var{container:t,addVertexButtonId:r,olView:n,onUndo:a,getInterfaceType:o,setInterfaceType:i,clearLastCoord:l,updateRubberbanding:d,placeVertex:s}=e,c=()=>{"mouse"!==o()&&d()};null==n||n.on("change:center",c);var u=e=>{t.contains(document.activeElement)&&(Pe.has(e.key)?i("keyboard"):("Enter"===e.key&&(e.preventDefault(),i("keyboard"),s()),"z"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),null==a||a())))},v=e=>{r&&e.target.closest("#".concat(r))&&s()},p=e=>{"touch"!==e.pointerType&&(i("mouse"),l())},g=()=>{i("touch")},y=()=>{"mouse"!==o()&&d()};return globalThis.addEventListener("keydown",u),globalThis.addEventListener("click",v),t.addEventListener("pointerdown",p),t.addEventListener("touchstart",g,{passive:!0}),t.addEventListener("pointermove",y),{destroy(){null==n||n.un("change:center",c),globalThis.removeEventListener("keydown",u),globalThis.removeEventListener("click",v),t.removeEventListener("pointerdown",p),t.removeEventListener("touchstart",g),t.removeEventListener("pointermove",y)}}})({container:a,addVertexButtonId:o,olView:y,onUndo:d,getInterfaceType:v,setInterfaceType:e=>{u=e},clearLastCoord:p.clearLastCoord,updateRubberbanding:p.updateRubberbanding,placeVertex:p.placeVertex}),h=()=>{"mouse"!==u&&null!=y&&y.getAnimating()&&p.updateRubberbanding()};return null==g||g.on("postrender",h),{getInterfaceType:v,setInterfaceType(e){u=e,"mouse"!==e&&p.updateRubberbanding()},destroy(){m.destroy(),null==g||g.un("postrender",h)}}},be="styleschanged",_e=(e,t)=>!!t&&U(t.getGeometry()).length>=w[e],Ee=(e,t,r,n)=>a=>{if(!j(a))return!1;var o=r();if(!n(a.coordinate))return!1;if(!o||_e(t,o))return!0;var i=B(o.getGeometry());if(!i)return!0;var l=e.getPixelFromCoordinate(i);if(!l)return!0;var d=a.pixel[0]-l[0],s=a.pixel[1]-l[1];return d*d+s*s>4},Le={Polygon:2,LineString:1},ke=(e,t)=>{var{manager:r,featureId:n,properties:a,onStart:o,onSketchChange:i}=t;e.on("drawstart",e=>{o(e.feature),e.feature.getGeometry().on("change",i)}),e.on("drawend",e=>((e,t,r,n)=>{t.setId(String(r)),t.setProperties(n),e.store.source.addFeature(t),e.emit(I.CREATE,e.store.toGeoJSON(t))})(r,e.feature,n,a)),e.on("drawabort",()=>{r.emit(I.CANCEL)})},Oe=e=>{var{map:t,manager:r,options:n}=e,{geometryType:a,featureId:l,properties:d={}}=n,s=null,c=!1,u=r.styles.createSketchStyle(a),{updateVertexCount:v,resetCount:p,emitUndoValidation:g}=((e,t)=>{var r=0,n=(r,n)=>{setTimeout(()=>{var a,o,i,l,d,s,c=t();c&&e.emit(I.GEOMETRY_CHANGE,{feature:(a=e.store,o=c,i=a.toGeoJSON(o),l=i.geometry.type,d=Le[l],s=("Polygon"===l?i.geometry.coordinates[0]:i.geometry.coordinates).slice(0,-d),{type:"Feature",geometry:"Polygon"===l?{type:"Polygon",coordinates:[s]}:{type:"LineString",coordinates:s},properties:i.properties}),phase:r,vertexIndex:n})},0)};return{resetCount:()=>{r=0},updateVertexCount:()=>{var a=t();if(a){var o=U(a.getGeometry()).length;e.emit(I.VERTEX_CHANGE,{numVertices:o}),o>r&&n("commit-add",o-1),r=o}},emitUndoValidation:()=>{var e=t();e&&n("commit-delete",U(e.getGeometry()).length)}}})(r,()=>s),y=(e=>{var{manager:t,geometryType:r,getSketch:n}=e;return e=>{var a=n(),o=T({placed:a?U(a.getGeometry()):[],point:e,geometryType:r,onGeometryChange:t._geometryValidator});return o.valid||t.emit(I.PLACEMENT_BLOCKED,o.blocked),o.valid}})({manager:r,geometryType:a,getSketch:()=>s}),m=new F({type:a,style:e=>u(e),stopClick:!0,snapTolerance:S.snapRadius,condition:Ee(t,a,()=>s,y),finishCondition:()=>!1!==r._geometryValid});t.addInteraction(m);var h=o({onChange:e=>{c=e,u=r.styles.createSketchStyle(a,c),m.overlay_.changed()}}),x=i({onStrokeChange:(e,t)=>h.set(e,t),onPlaceChange:(e,t)=>r.emit(I.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),f=V[a],w=()=>{if(s){var{feature:e,numVertices:t}=((e,t)=>{var r,n=t.getGeometry(),a=n.getCoordinates(),o="Polygon"===e?null!==(r=a[0])&&void 0!==r?r:[]:a;return{feature:{type:"Feature",geometry:"Polygon"===e?{type:"Polygon",coordinates:[o]}:{type:"LineString",coordinates:o}},numVertices:U(n).length}})(a,s);x.update({feature:e,context:{mode:f},numVertices:t,onGeometryChange:r._geometryValidator})}},P=()=>{u=r.styles.createSketchStyle(a,c),m.overlay_.changed()};r.on(be,P),m.overlay_.updateWhileAnimating_=!0,ke(m,{manager:r,featureId:l,properties:d,onStart:e=>{s=e,p()},onSketchChange:()=>{v(),w()}});var C=(e=>{var{drawInteraction:t,options:r,geometryType:n,getSketch:a,updateVertexCount:o,emitUndoValidation:i,canPlaceVertex:l}=e;return Ce({drawInteraction:t,options:{container:r.container,interfaceType:r.interfaceType,addVertexButtonId:r.addVertexButtonId,mapProvider:r.mapProvider,snap:r.snap,onUndo:()=>{t.removeLastPoint(),o(),i()},canFinish:()=>_e(n,a()),canPlace:l}})})({drawInteraction:m,options:n,geometryType:a,getSketch:()=>s,updateVertexCount:v,emitUndoValidation:g,canPlaceVertex:y});return(e=>{var{map:t,manager:r,drawInteraction:n,input:a,geometryType:o,getSketch:i,updateVertexCount:l,emitUndoValidation:d,onStylesChanged:s,clearSketch:c,setInvalid:u,liveStroke:v,liveDrawChecks:p}=e;return{done(){_e(o,i())&&n.finishDrawing()},cancel(){n.abortDrawing()},undo(){n.removeLastPoint(),l(),d()},setInvalid:u,setInterfaceType(e){a.setInterfaceType(e)},setDrawingPreviewProperty(e,t){var r=i();r&&(r.set(e,t),n.overlay_.changed())},destroy(){v.destroy(),p.destroy(),r.off(be,s),r.emit(I.INTERFACE_TYPE_CHANGE,{interfaceType:a.getInterfaceType()}),a.destroy(),t.removeInteraction(n),c()}}})({map:t,manager:r,drawInteraction:m,input:C,geometryType:a,getSketch:()=>s,updateVertexCount:v,emitUndoValidation:g,onStylesChanged:P,clearSketch:()=>{s=null},setInvalid:e=>h.set(e),liveStroke:h,liveDrawChecks:x})},De=e=>{if(null==e||!e.coordinates)return[];switch(e.type){case"LineString":return e.coordinates;case"Polygon":return e.coordinates.flatMap(e=>e.slice(0,-1));case"MultiLineString":return e.coordinates.flat(1);case"MultiPolygon":return e.coordinates.flatMap(e=>e.flatMap(e=>e.slice(0,-1)));default:return[]}},Fe=e=>{if(null==e||!e.coordinates)return[];var t=[],r=0;switch(e.type){case"LineString":t.push({start:0,length:e.coordinates.length,path:[],closed:!1});break;case"Polygon":e.coordinates.forEach((e,n)=>{var a=e.length-1;t.push({start:r,length:a,path:[n],closed:!0}),r+=a});break;case"MultiLineString":e.coordinates.forEach((e,n)=>{t.push({start:r,length:e.length,path:[n],closed:!1}),r+=e.length});break;case"MultiPolygon":e.coordinates.forEach((e,n)=>{e.forEach((e,a)=>{var o=e.length-1;t.push({start:r,length:o,path:[n,a],closed:!0}),r+=o})})}return t},je=(e,t)=>{for(var r of e)if(t>=r.start&&t<r.start+r.length)return{segment:r,localIdx:t-r.start};return null},Me=(e,t)=>{var r=e.coordinates;for(var n of t)r=r[n];return r},Ae=e=>{var t=De(e),r=Fe(e);if(!t.length||!r.length)return[];var n=[];for(var a of r)for(var o=a.closed?a.length:a.length-1,i=0;i<o;i++){var l=a.start+i,d=a.start+(i+1)%a.length,[s,c]=t[l],[u,v]=t[d];n.push([(s+u)/2,(c+v)/2])}return n},Ge=(e,t)=>{var a=new n,o=new r({source:a,zIndex:103});e.addLayer(o);return{update(e){if(a.clear(),!(e.selectedVertexIndex<0)){var{coord:r,style:n}=(e=>{var{selectedVertexIndex:r,selectedVertexType:n,vertices:a,midpoints:o}=e,i=t();return"vertex"===n?{coord:a[r],style:i.selectedVertexStyle}:"midpoint"===n?{coord:o[r-a.length],style:i.selectedMidpointStyle}:{coord:null,style:null}})(e);if(r){var o=new L({geometry:new k(r)});o.setStyle(n),a.addFeature(o)}}},remove(){a.clear(),e.removeLayer(o)}}},Re=e=>{var{map:t,manager:r,store:n,olFeature:a,interfaceType:o,layers:i}=e,{vertexLayer:l,midpointLayer:d,activeLayer:s}=i,c={olFeature:a,selectedVertexIndex:-1,selectedVertexType:null,vertices:[],midpoints:[],interfaceType:null!=o?o:"mouse"},u={onDeselect:null,onUpdate:null},v=()=>{var e=a.getGeometry();return{type:e.getType(),coordinates:e.getCoordinates()}},p=()=>((e,t)=>{var r,{vertexLayer:n,midpointLayer:a,activeLayer:o,manager:i,hooks:l}=t;n.setSelected("vertex"===e.selectedVertexType?e.selectedVertexIndex:-1),a.setSelected("midpoint"===e.selectedVertexType?e.selectedVertexIndex-e.vertices.length:-1),e.selectedVertexIndex<0&&(null===(r=l.onDeselect)||void 0===r||r.call(l)),o.update(e),i.emit(I.VERTEX_SELECTION,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length})})(c,{vertexLayer:l,midpointLayer:d,activeLayer:s,manager:r,hooks:u}),g=()=>{var e=v();c.vertices=De(e),c.midpoints=Ae(e),d.update(e),l.update(e),s.update(c)},y=((e,t,r)=>(n,a)=>{n&&setTimeout(()=>{e.emit(I.GEOMETRY_CHANGE,{feature:t.toGeoJSON(r),phase:n,vertexIndex:a})},0)})(r,n,a),m=()=>g();return a.getGeometry().on("change",m),{state:c,getState:()=>c,setState:e=>{var r,n;Object.assign(c,e),void 0!==e.selectedVertexIndex&&p(),void 0!==e.vertices&&(n=v(),d.update(n),l.update(n),c.midpoints=d.getCoords(),s.update(c),null===(r=u.onUpdate)||void 0===r||r.call(u),t.render())},syncGeom:()=>{g(),r.emit(I.VERTEX_CHANGE,{numVertices:c.vertices.length}),r.emit(I.UPDATE,n.toGeoJSON(a))},emitGeometryValidation:y,updateLayersFromGeom:g,setHooks:e=>{var{onDeselect:t,onUpdate:r}=e;return Object.assign(u,{onDeselect:t,onUpdate:r})},destroy(){a.getGeometry().un("change",m)}}},He=function(e,t,r,n){var a,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:12;return null!==(a=function(e,t,r){var n=-1,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:12;return t.forEach((t,o)=>{var i=Se(e,t);if(i){var l=Ie(i,r);l<a&&(a=l,n=o)}}),n>=0?{index:n,type:"vertex"}:null}(e,t,n,o))&&void 0!==a?a:function(e,t,r,n){var a=-1,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:12;return t.forEach((t,n)=>{var i=Se(e,t);if(i){var l=Ie(i,r);l<o&&(o=l,a=n)}}),a>=0?{index:n+a,type:"midpoint"}:null}(e,r,n,t.length,o)},Ne=e=>{var{map:t,olFeature:r,getState:n,onModifyEnd:a}=e,o=(e=>{var{map:t,getState:r}=e;return e=>{var{interfaceType:n,vertices:a,midpoints:o}=r();if("touch"===n)return!1;var i=t.getEventPixel(e.originalEvent);return null!==He(t,a,o,{x:i[0],y:i[1]})}})({map:t,getState:n}),i=new M({features:new A([r]),style:()=>[],pixelTolerance:12,condition:o});t.addInteraction(i);var l=null;return i.on("modifystart",()=>{"touch"!==n().interfaceType&&(l=n().vertices.map(e=>[...e]))}),i.on("modifyend",()=>{if("touch"!==n().interfaceType){var e=l;l=null,a(e)}}),{destroy(){t.removeInteraction(i)}}},Ue=(e,t,r,n)=>{var a=r-n,o=t[a];if(!o)return null;var i=e.getGeometry(),l={type:i.getType(),coordinates:i.getCoordinates()},d=Fe(l),s=0;for(var c of d){var u=c.closed?c.length:c.length-1;if(a<s+u){var v=a-s+1,p=c.start+v;return Me(l,c.path).splice(v,0,[...o]),i.setCoordinates(l.coordinates),{insertedIndex:p}}s+=u}return null},Be=(e,t,r)=>{var n=e.getGeometry(),a={type:n.getType(),coordinates:n.getCoordinates()},o=Fe(a),i=je(o,t);if(i){var l=Me(a,i.segment.path);l[i.localIdx]=[...r],i.segment.closed&&0===i.localIdx&&(l[l.length-1]=[...r]),n.setCoordinates(a.coordinates)}};function qe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ye(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qe(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qe(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ze=(e,t)=>{var{getState:r,onVertexMoved:n,snap:a,drag:o}=t;if(null==o.dragStartIndex)return((e,t)=>{var{map:r,getState:n,onTap:a,drag:o}=t;if(o.tapStart&&!o.tapStart.onTarget&&0!==e.changedTouches.length){var i=e.changedTouches[0],l=Date.now()-o.tapStart.time;if(Math.hypot(i.clientX-o.tapStart.x,i.clientY-o.tapStart.y)<10&&l<400){var d=r.getEventPixel({clientX:i.clientX,clientY:i.clientY}),s=n();null==a||a(He(r,s.vertices,s.midpoints,{x:d[0],y:d[1]},24)),e.preventDefault()}}})(e,t),void(o.tapStart=null);o.tapStart=null;var{vertices:i}=r();i[o.dragStartIndex]&&o.dragStartCoord&&n({vertexIndex:o.dragStartIndex,previousCoord:o.dragStartCoord}),null==a||a.hideIndicator(),o.dragStartCoord=null,o.dragStartIndex=null,o.vertexTouchDelta=null,o.targetTouchDelta=null,e.preventDefault()},Ke=e=>{var{container:t}=e,r={dragStartCoord:null,dragStartIndex:null,vertexTouchDelta:null,targetTouchDelta:null,tapStart:null},n=Ye(Ye({},e),{},{drag:r}),a=e=>((e,t)=>{var{map:r,targetEl:n,cssToOl:a,getState:o,drag:i}=t,l=e.touches[0],d=u(e.target);if(i.tapStart={x:l.clientX,y:l.clientY,time:Date.now(),onTarget:d},d){var{selectedVertexIndex:s,vertices:c}=o(),v=c[s];if(v){var p=r.getEventPixel({clientX:l.clientX,clientY:l.clientY}),g=Se(r,v),y=getComputedStyle(n),m=a({x:Number.parseFloat(y.left),y:Number.parseFloat(y.top)});i.dragStartCoord=[...v],i.dragStartIndex=s,i.vertexTouchDelta={x:p[0]-g.x,y:p[1]-g.y},i.targetTouchDelta={x:p[0]-m.x,y:p[1]-m.y},e.preventDefault()}}})(e,n),o=e=>((e,t)=>{var{map:r,targetEl:n,olToCSS:a,getState:o,setState:i,snap:l,drag:d}=t;if(u(e.target)&&null!=d.dragStartIndex){e.preventDefault();var s=r.getEventPixel({clientX:e.touches[0].clientX,clientY:e.touches[0].clientY}),v=((e,t)=>e.getCoordinateFromPixel([t.x,t.y]))(r,{x:s[0]-d.vertexTouchDelta.x,y:s[1]-d.vertexTouchDelta.y}),p=l?l.apply(v):v;null==l||l.hideIndicator();var{olFeature:g,vertices:y}=o();g&&(Be(g,d.dragStartIndex,p),i({vertices:y.map((e,t)=>t===d.dragStartIndex?p:e)}),c(n,a({x:s[0]-d.targetTouchDelta.x,y:s[1]-d.targetTouchDelta.y})))}})(e,n),i=e=>ze(e,n);return t.addEventListener("touchstart",a,{passive:!1}),t.addEventListener("touchmove",o,{passive:!1}),t.addEventListener("touchend",i,{passive:!1}),{isDragging:()=>null!=r.dragStartIndex,destroy(){t.removeEventListener("touchstart",a),t.removeEventListener("touchmove",o),t.removeEventListener("touchend",i)}}},Xe=e=>{var{map:t,snap:r,getState:n,setState:a,onInserted:o,onVertexMoved:i}=e,l={start:null,index:null},d=(e,o)=>{var{selectedVertexIndex:i,vertices:l,olFeature:d}=n();if(!d||i<0||!l[i])return null;var s=l[i],c=we(t,s,e,o),u=r?r.apply(c):c;null==r||r.hideIndicator();var v=((e,t,r,n,a,o,i)=>{if(!e)return a;var l=[n[0]-r[0],n[1]-r[1]],d=[a[0]-r[0],a[1]-r[1]],s=l[0]**2+l[1]**2;if(s>0&&(d[0]*l[0]+d[1]*l[1])/s<.5){var c=e.snapRadius+1;return we(t,r,0===o?0:Math.sign(o)*c,0===i?0:Math.sign(i)*c)}return a})(r,t,s,c,u,e,o);return Be(d,i,v),a({vertices:l.map((e,t)=>t===i?v:e)}),{previousCoord:s,vertexIndex:i}};return{nudge:e=>{var{selectedVertexIndex:i,selectedVertexType:s,vertices:c,midpoints:u,olFeature:v}=n();if(v){var p=e.shiftKey?P.nudgeAmount:P.stepAmount,g={ArrowUp:[0,-p],ArrowDown:[0,p],ArrowLeft:[-p,0],ArrowRight:[p,0]},[y,m]=g[e.key];"midpoint"!==s?i<0||!c[i]||(l.start||(l.start=[...c[i]],l.index=i),d(y,m)):((e,i,d,s,c,u)=>{var v=Ue(e,i,d,s.length);if(v){o({insertedIndex:v.insertedIndex});var p=n().vertices,g=p[v.insertedIndex];if(g){l.start=[...g],l.index=v.insertedIndex;var y=we(t,g,c,u),m=r?r.apply(y):y;Be(e,v.insertedIndex,m),a({selectedVertexIndex:v.insertedIndex,selectedVertexType:"vertex",vertices:p.map((e,t)=>t===v.insertedIndex?m:e)})}}})(v,u,i,c,y,m)}},keyMove:l,nudgeByDelta:(e,t,r)=>{var n=r?P.stepAmount:P.nudgeAmount,a=d(e*n,t*n);a&&i({vertexIndex:a.vertexIndex,previousCoord:a.previousCoord})}}},We=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Je=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Ze=e=>{var{map:t,getState:r,setState:n,nudge:a,keyMove:o,onUndo:i,onKeyboardActive:l,isFocused:d}=e,s=e=>{e.altKey?(e.preventDefault(),e.stopPropagation(),((e,t,r,n)=>{var{selectedVertexIndex:a,vertices:o,midpoints:i}=r();if(o.length){var l,d=[...o,...i].map(e=>Se(t,e)).filter(Boolean).map(e=>[e.x,e.y]),s=a>=0?d[a]:(l=Se(t,t.getView().getCenter()))?[l.x,l.y]:null;if(s){var c=C(s,d,e);n({selectedVertexIndex:c,selectedVertexType:c<o.length?"vertex":"midpoint"})}}})(e.key,t,r,n)):r().selectedVertexIndex>=0&&(e.preventDefault(),e.stopPropagation(),a(e))},c=e=>{if(null==l||l()," "===e.key)e.preventDefault(),r().selectedVertexIndex<0&&((e,t,r)=>{var{vertices:n,midpoints:a}=t();if(n.length){var o=Se(e,e.getView().getCenter());if(o){var i=[...n.map(t=>Se(e,t)),...a.map(t=>Se(e,t))].filter(Boolean).map(e=>[e.x,e.y]),l=C([o.x,o.y],i,void 0);r({selectedVertexIndex:l,selectedVertexType:l<n.length?"vertex":"midpoint"})}}})(t,r,n);else if(We.has(e.key))s(e);else if("z"===e.key&&(e.metaKey||e.ctrlKey)){var a,o=null===(a=document.activeElement)||void 0===a?void 0:a.tagName;Je.has(o)||(e.preventDefault(),e.stopPropagation(),i())}};return e=>{d()||("Escape"===e.key&&r().selectedVertexIndex>=0?(e.preventDefault(),o.start=null,o.index=null,n({selectedVertexIndex:-1,selectedVertexType:null})):c(e))}},Qe=e=>{var t,{map:r,snap:n,getState:a,setState:o,onVertexMoved:i,onInserted:l,onDeleted:d,onUndo:s,onKeyboardActive:c}=e,{nudge:u,keyMove:v,nudgeByDelta:p}=Xe({map:r,snap:n,getState:a,setState:o,onInserted:l,onVertexMoved:i}),g=null!==(t=r.getViewport().closest('[role="application"]'))&&void 0!==t?t:r.getViewport(),y=()=>(e=>{var t=document.activeElement;return!(!t||t===document.body)&&!e.contains(t)&&(Je.has(t.tagName)||t.isContentEditable||t.hasAttribute("tabindex"))})(g),m=Ze({map:r,getState:a,setState:o,nudge:u,keyMove:v,onUndo:s,onKeyboardActive:c,isFocused:y}),h=(e=>{var{snap:t,keyMove:r,onVertexMoved:n,onDeleted:a,isFocused:o}=e;return e=>{o()||(We.has(e.key)&&r.start&&null!=r.index&&(null==t||t.hideIndicator(),n({vertexIndex:r.index,previousCoord:r.start}),r.start=null,r.index=null),"Delete"===e.key&&a())}})({snap:n,keyMove:v,onVertexMoved:i,onDeleted:d,isFocused:y});return globalThis.addEventListener("keydown",m,{capture:!0}),globalThis.addEventListener("keyup",h,{capture:!0}),{nudgeByDelta:p,destroy(){globalThis.removeEventListener("keydown",m,{capture:!0}),globalThis.removeEventListener("keyup",h,{capture:!0})}}},$e=(e,t)=>{switch(t.type){case"move_vertex":return((e,t)=>{var{vertexIndex:r,previousCoord:n}=t,a=e.getGeometry(),o={type:a.getType(),coordinates:a.getCoordinates()},i=Fe(o),l=je(i,r);if(!l)return-1;var d=Me(o,l.segment.path);return d[l.localIdx]=[...n],l.segment.closed&&0===l.localIdx&&(d[d.length-1]=[...n]),a.setCoordinates(o.coordinates),r})(e,t);case"insert_vertex":return((e,t)=>{var{vertexIndex:r}=t,n=e.getGeometry(),a={type:n.getType(),coordinates:n.getCoordinates()},o=Fe(a),i=je(o,r);if(i){var l=Me(a,i.segment.path);l.splice(i.localIdx,1),i.segment.closed&&(l[l.length-1]=[...l[0]]),n.setCoordinates(a.coordinates)}return-1})(e,t);case"delete_vertex":return((e,t)=>{var{vertexIndex:r,deletedCoord:n}=t,a=e.getGeometry(),o={type:a.getType(),coordinates:a.getCoordinates()},i=Fe(o),l=je(i,r);if(!l)for(var d of i)if(r===d.start+d.length){l={segment:d,localIdx:d.length};break}if(!l)return-1;var s=Me(o,l.segment.path);return s.splice(l.localIdx,0,[...n]),l.segment.closed&&(s[s.length-1]=[...s[0]]),a.setCoordinates(o.coordinates),r})(e,t);default:return-1}},et="touch",tt="vertex",rt="commit-move",nt="commit-insert",at="commit-delete",ot={move_vertex:rt,insert_vertex:nt,delete_vertex:at},it={move_vertex:rt,insert_vertex:at,delete_vertex:nt},lt=e=>{var{olFeature:t,undoStack:r,selection:n,getTouchHandler:a}=e,{state:o,setState:i,syncGeom:l,emitGeometryValidation:d}=n;return{doDeleteVertex:()=>{if(!(o.selectedVertexType!==tt||o.selectedVertexIndex<0)){var e=((e,t)=>{var r=e.getGeometry(),n={type:r.getType(),coordinates:r.getCoordinates()},a=De(n),o=Fe(n),i=je(o,t);if(!i)return null;var{segment:l}=i,d=l.closed?w.Polygon:w.LineString;if(l.length<=d)return null;var s=[...a[t]],c=Me(n,l.path);return c.splice(i.localIdx,1),l.closed&&(c[c.length-1]=[...c[0]]),r.setCoordinates(n.coordinates),{deletedIndex:t,deletedCoord:s}})(t,o.selectedVertexIndex);e&&(r.push({type:"delete_vertex",vertexIndex:e.deletedIndex,deletedCoord:e.deletedCoord}),l(),d(at,e.deletedIndex),i({selectedVertexIndex:-1,selectedVertexType:null}))}},doUndo:()=>{var e=r.pop();if(e){var n=o.selectedVertexIndex,s=$e(t,e);l(),d(it[e.type],s);var c=n>=0?s:-1;i({selectedVertexIndex:c,selectedVertexType:c>=0?tt:null}),n>=0&&c>=0&&o.interfaceType===et&&a().updateTargetPosition()}}}},dt=e=>{var{map:t,container:r,manager:n,snap:a,olFeature:o,undoStack:i,selection:u}=e,{state:v,getState:p,setState:g,syncGeom:y,emitGeometryValidation:m}=u,h=e=>g({selectedVertexIndex:e,selectedVertexType:tt}),x=(e=>{var{map:t,container:r,getState:n,setState:a,onVertexMoved:o,onTap:i,colors:u,snap:v}=e,p=l(r);d(p,u);var g={scale:1,ox:0,oy:0},y=e=>({x:e.x*g.scale+g.ox,y:e.y*g.scale+g.oy}),m=()=>{var e=t.getViewport(),n=e.getBoundingClientRect(),a=r.getBoundingClientRect(),o=e.offsetWidth>0?n.width/e.offsetWidth:1,i=r.offsetWidth>0?a.width/r.offsetWidth:1;Object.assign(g,{scale:o/i,ox:(n.left-a.left)/i,oy:(n.top-a.top)/i})},h=Ke({container:r,map:t,targetEl:p,olToCSS:y,cssToOl:e=>({x:(e.x-g.ox)/g.scale,y:(e.y-g.oy)/g.scale}),getState:n,setState:a,onVertexMoved:o,onTap:i,snap:v}),x=()=>{var{selectedVertexIndex:e,vertices:r,interfaceType:a}=n();if(e<0||!r[e]||"touch"!==a)s(p);else{var o=Se(t,r[e]);o?c(p,y(o)):s(p)}},f=()=>{var{selectedVertexIndex:e,interfaceType:t}=n();e>=0&&!h.isDragging()&&"touch"===t&&x()};t.on("postrender",f);var S=()=>{m(),t.once("postrender",x)};return t.on("change:size",S),m(),{updateTargetPosition:x,updateColors(e){d(p,e)},hide(){s(p)},destroy(){t.un("change:size",S),t.un("postrender",f),h.destroy(),s(p)}}})({map:t,container:r,getState:p,setState:g,colors:n.colors,snap:a,onVertexMoved(e){var{vertexIndex:t,previousCoord:r}=e;i.push({type:"move_vertex",vertexIndex:t,previousCoord:r}),y(),m(rt,t),h(t),x.updateTargetPosition()},onTap(e){if(e){if(e.type===tt)return h(e.index),void x.updateTargetPosition();var t=Ue(o,v.midpoints,e.index,v.vertices.length);t&&(i.push({type:"insert_vertex",vertexIndex:t.insertedIndex}),y(),m(nt,t.insertedIndex),h(t.insertedIndex),x.updateTargetPosition())}else g({selectedVertexIndex:-1,selectedVertexType:null})}});return u.setHooks({onDeselect:()=>x.hide(),onUpdate(){v.interfaceType===et&&x.updateTargetPosition()}}),x},st=e=>{var{map:t,manager:a,options:i}=e,{featureId:l,container:d,interfaceType:s,deleteVertexButtonId:c,snap:u}=i,{store:v,undoStack:p}=a,g=v.getOL(l);if(!g)return null;var y=g.getStyle(),m=((e,t)=>{var a=t,o=-1,i=new n,l=new r({source:i,style:e=>e.get("midpointIndex")===o?null:[a],zIndex:101});return e.addLayer(l),{update(e){i.clear();var t=Ae(e).map((e,t)=>{var r=new L({geometry:new k(e)});return r.set("midpointIndex",t),r});i.addFeatures(t)},setSelected(e){o=e,i.changed()},updateStyle(e){a=e,i.changed()},getCoords:()=>i.getFeatures().sort((e,t)=>e.get("midpointIndex")-t.get("midpointIndex")).map(e=>e.getGeometry().getCoordinates()),remove(){i.clear(),e.removeLayer(l)}}})(t,a.styles.midpointStyle),h=((e,t)=>{var a=t,o=-1,i=new n,l=new r({source:i,style:e=>e.get("vertexIndex")===o?null:[a],zIndex:102});return e.addLayer(l),{update(e){i.clear(),De(e).forEach((e,t)=>{var r=new L({geometry:new k(e)});r.set("vertexIndex",t),i.addFeature(r)})},setSelected(e){o=e,i.changed()},updateStyle(e){a=e,i.changed()},remove(){i.clear(),e.removeLayer(l)}}})(t,a.styles.vertexStyle),x=Ge(t,()=>a.styles),f=Re({map:t,manager:a,store:v,olFeature:g,interfaceType:s,layers:{vertexLayer:h,midpointLayer:m,activeLayer:x}}),{state:S,getState:w,setState:T,syncGeom:V,emitGeometryValidation:P}=f,C=Ne({map:t,olFeature:g,getState:w,onModifyEnd(e){V();var t=e&&((e,t)=>{if(t.length>e.length){var r=t.findIndex((t,r)=>{var n;return t[0]!==(null===(n=e[r])||void 0===n?void 0:n[0])});return{type:"insert_vertex",vertexIndex:Math.max(0,r)}}if(t.length===e.length){var n=t.findIndex((t,r)=>t[0]!==e[r][0]||t[1]!==e[r][1]);if(n>=0)return{type:"move_vertex",vertexIndex:n,previousCoord:e[n]}}return null})(e,S.vertices);t&&(p.push(t),P(ot[t.type],t.vertexIndex),T({selectedVertexIndex:t.vertexIndex,selectedVertexType:tt}))}});V();var b={vertexLayer:h,midpointLayer:m,activeLayer:x},_=(e=>{var{map:t,manager:r,olFeature:n}=e,a=!1;n.setStyle(()=>a?r.styles.editFeatureStyleInvalid:r.styles.editFeatureStyle);var i=o({onChange:(e,n)=>{a=e,t.render(),r.emit(I.VALIDITY_CHANGE,{valid:!e,reason:n})}}),l=()=>{var e,t,a=n.getGeometry(),o=a.getType(),l=a.getCoordinates(),d="Polygon"===o?Math.max(0,(null!==(e=null===(t=l[0])||void 0===t?void 0:t.length)&&void 0!==e?e:1)-1):l.length;i.update({feature:{type:"Feature",geometry:{type:o,coordinates:l}},context:{mode:"edit_vertex"},numVertices:d,onGeometryChange:r._geometryValidator})};return n.getGeometry().on("change",l),{liveStroke:i,destroy(){n.getGeometry().un("change",l),i.destroy()}}})({map:t,manager:a,olFeature:g}),E=dt({map:t,container:d,manager:a,snap:u,olFeature:g,undoStack:p,selection:f}),O=lt({olFeature:g,undoStack:p,selection:f,getTouchHandler:()=>E}),D=(e=>{var{map:t,container:r,snap:n,undoStack:a,selection:o,touchHandler:i,actions:l}=e,{state:d,getState:s,setState:c,syncGeom:u,emitGeometryValidation:v}=o;return Qe({map:t,getState:s,setState:c,snap:n,onVertexMoved(e){var{vertexIndex:t,previousCoord:r}=e;a.push({type:"move_vertex",vertexIndex:t,previousCoord:r}),u(),v(rt,t),c({selectedVertexIndex:t,selectedVertexType:tt})},onInserted(e){var{insertedIndex:t}=e;a.push({type:"insert_vertex",vertexIndex:t}),u(),v(nt,t)},onDeleted:l.doDeleteVertex,onUndo:l.doUndo,onKeyboardActive(){"keyboard"!==d.interfaceType&&(d.interfaceType="keyboard",i.hide(),r.focus({preventScroll:!0}))}})})({map:t,container:d,snap:u,undoStack:p,selection:f,touchHandler:E,actions:O}),F=(e=>{var{map:t,container:r,getState:n,setState:a,touchHandler:o,deleteVertexButtonId:i,onDeleteVertex:l}=e,d=e=>{var{vertices:r,midpoints:a}=n(),o=t.getEventPixel(e);return He(t,r,a,{x:o[0],y:o[1]})},s=e=>{var t=n();if("touch"===e.pointerType)return t.interfaceType="touch",void o.updateTargetPosition();t.interfaceType="mouse";var r=d(e);"vertex"===(null==r?void 0:r.type)&&a({selectedVertexIndex:r.index,selectedVertexType:"vertex"})},c=e=>{if("touch"!==n().interfaceType){var t=d(e);"vertex"===(null==t?void 0:t.type)?a({selectedVertexIndex:t.index,selectedVertexType:"vertex"}):"midpoint"===(null==t?void 0:t.type)||a({selectedVertexIndex:-1,selectedVertexType:null})}},u=e=>{var t=n();"mouse"===e.pointerType&&"mouse"!==t.interfaceType&&(t.interfaceType="mouse",o.hide())},v=e=>{i&&e.target.closest("#".concat(i))&&l()};return r.addEventListener("pointerdown",s),r.addEventListener("pointerenter",u),r.addEventListener("pointermove",u),r.addEventListener("click",c),globalThis.addEventListener("click",v),{destroy(){r.removeEventListener("pointerdown",s),r.removeEventListener("pointerenter",u),r.removeEventListener("pointermove",u),r.removeEventListener("click",c),globalThis.removeEventListener("click",v)}}})({map:t,container:d,getState:w,setState:T,touchHandler:E,deleteVertexButtonId:c,onDeleteVertex:O.doDeleteVertex}),j=(e=>{var{map:t,manager:r,layers:n,selection:a,touchHandler:o,live:i}=e,{state:l}=a,d=e=>{i.liveStroke.refresh(),n.vertexLayer.updateStyle(e.vertexStyle),n.midpointLayer.updateStyle(e.midpointStyle),n.activeLayer.update(l),o.updateColors(r.colors)};r.on(be,d);var s=()=>{l.interfaceType!==et||l.selectedVertexIndex<0||t.once("postrender",()=>o.updateTargetPosition())};return t.on("change:size",s),{destroy(){r.off(be,d),t.un("change:size",s)}}})({map:t,manager:a,layers:b,selection:f,touchHandler:E,live:_});return(e=>{var{manager:t,store:r,olFeature:n,originalFeatureStyle:a,selection:o,actions:i,parts:l}=e,{state:d}=o,{touchHandler:s}=l;return{setInterfaceType(e){e!==d.interfaceType&&(d.interfaceType=e,e===et?s.updateTargetPosition():s.hide())},done(){t.emit(I.EDIT_FINISH,r.toGeoJSON(n))},setInvalid(e){l.live.liveStroke.set(e)},cancel(){},undo:i.doUndo,deleteVertex:i.doDeleteVertex,nudgeSelectedVertex:l.keyboardHandler.nudgeByDelta,destroy(){l.live.destroy(),n.setStyle(a),o.destroy(),l.mapSync.destroy(),l.pointerHandlers.destroy(),l.modify.destroy(),l.layers.activeLayer.remove(),l.layers.midpointLayer.remove(),l.layers.vertexLayer.remove(),s.destroy(),l.keyboardHandler.destroy()}}})({manager:a,store:v,olFeature:g,originalFeatureStyle:y,selection:f,actions:O,parts:{touchHandler:E,keyboardHandler:D,pointerHandlers:F,modify:C,mapSync:j,layers:b,live:_}})};function ct(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ut(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ct(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ct(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}class vt{constructor(e){var t,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this._map=e,this._pluginConfig=a,this._mode="disabled",this._modeInstance=null,this._listeners=new Map,this.store=H(),this.undoStack=v(e=>this.emit(I.UNDO_CHANGE,e)),this.colors=p(null,a),this.styles=W(this.colors),this.snap=fe(e,null!==(t=a.snapLayers)&&void 0!==t?t:null,this.colors,null!==(n=a.snapRadius)&&void 0!==n?n:S.snapRadius),this._layer=new r({source:this.store.source,style:this.styles.createFeatureStyle(),zIndex:100}),this._layer.set("layerId","draw"),e.addLayer(this._layer)}setMapStyle(e){var t;this.colors=p(e,this._pluginConfig),this.styles=W(this.colors),this._layer.setStyle(this.styles.createFeatureStyle()),this.store.source.changed(),null===(t=this.snap)||void 0===t||t.updateColors(this.colors),this.emit(be,this.styles)}on(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}off(e,t){var r;null===(r=this._listeners.get(e))||void 0===r||r.delete(t)}emit(e,t){var r=this._listeners.get(e);r&&Array.from(r).forEach(e=>e(t))}changeMode(e){var r=arguments,n=this;return t(function*(){var t,a,o,i=r.length>1&&void 0!==r[1]?r[1]:{};null===(t=n._modeInstance)||void 0===t||t.destroy(),n._modeInstance=null,n._mode=e;var l="draw_polygon"===e||"draw_line"===e||"edit_vertex"===e;null===(a=n.snap)||void 0===a||a.setIndicatorActive(l);var d=ut(ut({},i),{},{snap:n.snap});"draw_polygon"===e||"draw_line"===e?n._modeInstance=Oe({map:n._map,manager:n,options:d}):"edit_vertex"===e&&(n._modeInstance=st({map:n._map,manager:n,options:d})),null===(o=n.snap)||void 0===o||o.reattach()})()}getMode(){return this._mode}done(){var e;null===(e=this._modeInstance)||void 0===e||e.done()}cancel(){var e;null===(e=this._modeInstance)||void 0===e||e.cancel(),this.changeMode("disabled")}undo(){var e;null===(e=this._modeInstance)||void 0===e||e.undo()}deleteVertex(){var e;null===(e=this._modeInstance)||void 0===e||e.deleteVertex()}nudgeSelectedVertex(e,t,r){var n,a;null===(n=this._modeInstance)||void 0===n||null===(a=n.nudgeSelectedVertex)||void 0===a||a.call(n,e,t,r)}setInvalid(e){var t,r;null===(t=this._modeInstance)||void 0===t||null===(r=t.setInvalid)||void 0===r||r.call(t,e)}setDrawingPreviewProperty(e,t){var r,n;null===(r=this._modeInstance)||void 0===r||null===(n=r.setDrawingPreviewProperty)||void 0===n||n.call(r,e,t)}setInterfaceType(e){var t,r;null===(t=this._modeInstance)||void 0===t||null===(r=t.setInterfaceType)||void 0===r||r.call(t,e),this.emit(I.INTERFACE_TYPE_CHANGE,{interfaceType:e})}get(e){return this.store.get(e)}add(e){return this.store.add(e)}delete(e){return this.store.remove(e)}deleteAll(){return this.store.clear()}remove(){var e,t;null===(e=this._modeInstance)||void 0===e||e.destroy(),this._modeInstance=null,null===(t=this.snap)||void 0===t||t.destroy(),this.snap=null,this.store.clear(),this._map.removeLayer(this._layer),this._listeners.clear()}}function pt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function gt(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?pt(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):pt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}class yt{constructor(t,r){var n;e(this,"_snapEnabled",!1);var{manager:a,remove:o}=(e=>{var{mapProvider:t,events:r,eventBus:n,pluginConfig:a={},mapStyle:o=null}=e,{map:i}=t,l=new vt(i,a);o&&l.setMapStyle(o),t.draw=l;var d=e=>{var r;t.drawScale=null!==(r=b[e])&&void 0!==r?r:1};n.on(r.MAP_SET_SIZE,d);var s=e=>{l.setMapStyle(e)};return n.on(r.MAP_SET_STYLE,s),{manager:l,remove(){n.off(r.MAP_SET_SIZE,d),n.off(r.MAP_SET_STYLE,s),l.remove(),t.draw=null}}})({mapProvider:t,events:r.events,eventBus:r.eventBus,pluginConfig:null!==(n=r.pluginConfig)&&void 0!==n?n:{snapLayers:r.snapLayers},mapStyle:r.mapStyle});this._cleanupOLDraw=o,this._manager=a,this._mapProvider=t}changeMode(e){var t=gt(gt({},arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{},{mapProvider:this._mapProvider});return"draw_polygon"===e&&(t.geometryType="Polygon"),"draw_line"===e&&(t.geometryType="LineString"),this._manager.changeMode(e,t)}getMode(){return this._manager.getMode()}setInterfaceType(e){this._manager.setInterfaceType(e)}done(){this._manager.undoStack.clear(),this._manager.done()}cancel(){this._manager.undoStack.clear(),this._manager.cancel()}undo(){this._manager.undo()}deleteVertex(){this._manager.deleteVertex()}nudgeSelectedVertex(e,t,r){this._manager.nudgeSelectedVertex(e,t,r)}setGeometryValid(e){this._manager._geometryValid=e}set _geometryValidator(e){this._manager._geometryValidator=e}get _geometryValidator(){return this._manager._geometryValidator}setInvalid(e){this._manager.setInvalid(e)}get(e){return this._manager.get(e)}add(e){return this._manager.add(e)}delete(e){return this._manager.delete(e)}deleteAll(){return this._manager.deleteAll()}setSnapEnabled(e){var t;this._snapEnabled=e,null===(t=this._manager.snap)||void 0===t||t.setActive(e)}setSnapLayers(e){var t,r=null==e?void 0:e.map(e=>"stroke-inactive.cold"===e?this._manager._layer:e);null===(t=this._manager.snap)||void 0===t||t.setSnapLayers(r)}isSnapEnabled(){return this._snapEnabled}setFeatureProperty(){}setDrawingPreviewProperty(e,t){this._manager.setDrawingPreviewProperty(e,t)}on(e,t){this._manager.on(e,t)}off(e,t){this._manager.off(e,t)}remove(){this._cleanupOLDraw()}}export{yt as OLDrawAdapter};
|