@defra/interactive-map 0.0.52-alpha → 0.0.54-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/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/context.md +30 -12
- package/docs/api/marker-config.md +16 -8
- package/docs/api/symbol-config.md +24 -9
- package/docs/api/symbol-registry.md +49 -14
- package/docs/api.md +11 -3
- package/docs/plugins/datasets.md +6 -10
- package/docs/plugins/draw.md +2 -1
- package/docs/plugins/map-key.md +47 -4
- package/package.json +1 -1
- package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/beta/map-styles/dist/umd/index.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/esm/mapboxStyleLayerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/src/adapters/esri/esriLayerAdapter.js +6 -6
- package/plugins/datasets/src/adapters/esri/registry/esriDataset.test.js +1 -1
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.js +10 -10
- package/plugins/datasets/src/adapters/maplibre/layerBuilders.test.js +22 -6
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +9 -3
- package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +18 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -3
- package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +20 -27
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +16 -70
- package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +30 -115
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +11 -13
- package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +11 -3
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +48 -19
- package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +101 -13
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +27 -28
- package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +51 -32
- package/plugins/datasets/src/fetch/createDynamicSource.js +2 -2
- package/plugins/datasets/src/initialise/DatasetsInit.jsx +2 -2
- package/plugins/datasets/src/initialise/defaults.js +16 -27
- package/plugins/datasets/src/initialise/defaults.test.js +25 -57
- package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -4
- package/plugins/datasets/src/reducers/__data__/demoDatasets.js +1 -3
- package/plugins/datasets/src/reducers/mappedDatasetsReducer.test.js +1 -1
- package/plugins/datasets/src/registry/dataset.js +23 -17
- package/plugins/datasets/src/registry/dataset.test.js +114 -11
- package/plugins/datasets/src/registry/mapboxStyleDataset.js +1 -1
- package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +7 -5
- package/plugins/draw/src/DrawInit.test.jsx +18 -2
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +11 -5
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -11
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.js +12 -9
- package/plugins/draw/src/adapters/maplibre/mapboxDraw.test.js +18 -0
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.js +81 -56
- package/plugins/draw/src/adapters/maplibre/pointSymbolImages.test.js +149 -80
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +7 -6
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +22 -25
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +26 -8
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +58 -16
- package/plugins/draw/src/adapters/openlayers/core/styles.js +33 -20
- package/plugins/draw/src/adapters/openlayers/core/styles.test.js +47 -21
- package/plugins/draw/src/adapters/openlayers/olDraw.js +16 -12
- package/plugins/draw/src/adapters/openlayers/olDraw.test.js +27 -32
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.js +44 -49
- package/plugins/draw/src/adapters/openlayers/point/pointSymbolImages.test.js +100 -119
- package/plugins/draw/src/defaults.js +2 -6
- package/plugins/draw/src/utils/stripInternalProperties.test.js +2 -1
- package/plugins/draw/src/utils/symbolKeys.js +3 -4
- 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/dist/umd/index.js +1 -1
- package/plugins/map-key/dist/css/index.css +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -2
- package/plugins/map-key/dist/umd/index.js +1 -1
- package/plugins/map-key/src/components/Key/Key.jsx +8 -4
- package/plugins/map-key/src/components/Key/Key.module.scss +144 -53
- package/plugins/map-key/src/components/Key/KeyGroupItem.jsx +36 -3
- package/plugins/map-key/src/components/Key/KeyGroupItem.test.jsx +44 -2
- package/plugins/map-key/src/components/Key/KeyItem.jsx +2 -2
- package/plugins/map-key/src/components/Key/KeySvg.jsx +19 -18
- package/plugins/map-key/src/components/Key/KeySvg.test.jsx +25 -18
- package/plugins/map-key/src/components/Key/KeySvgPattern.jsx +1 -2
- package/plugins/map-key/src/components/Key/KeySvgPattern.test.jsx +3 -1
- package/plugins/map-key/src/components/Key/KeySvgRamp.jsx +35 -6
- package/plugins/map-key/src/components/Key/KeySvgRamp.test.jsx +56 -16
- package/plugins/map-key/src/components/Key/KeySvgSymbol.jsx +26 -12
- package/plugins/map-key/src/components/Key/KeySvgSymbol.test.jsx +24 -74
- package/plugins/map-key/src/components/Key/MapKey.jsx +3 -1
- package/plugins/map-key/src/components/Key/svgProperties.js +8 -2
- package/plugins/map-key/src/components/Key/useRampOrientation.js +61 -0
- package/plugins/map-key/src/components/Key/useRampOrientation.test.jsx +155 -0
- package/plugins/map-key/src/index.js +34 -0
- package/plugins/map-key/src/reducers/mergeKeyGroupItems.test.js +15 -0
- package/plugins/map-key/src/registry/index.js +0 -2
- package/plugins/map-key/src/registry/index.test.js +1 -9
- package/plugins/map-key/src/utils/groupStyles.js +5 -2
- package/plugins/menu/src/registry/index.js +0 -2
- package/plugins/menu/src/registry/index.test.js +1 -9
- package/plugins/search/dist/esm/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/im-search-plugin.js +1 -1
- package/plugins/search/dist/umd/index.js +1 -1
- package/plugins/search/src/Search.jsx +0 -1
- package/plugins/search/src/components/Form/Form.jsx +3 -3
- package/plugins/search/src/components/Suggestions/Suggestions.jsx +2 -0
- package/plugins/search/src/components/Suggestions/Suggestions.test.jsx +6 -0
- package/plugins/search/src/defaults.js +3 -0
- package/plugins/search/src/events/formHandlers.js +3 -9
- package/plugins/search/src/events/formHandlers.test.js +6 -9
- package/plugins/search/src/events/inputHandlers.js +8 -2
- package/plugins/search/src/events/inputHandlers.test.js +20 -0
- package/plugins/search/src/events/suggestionHandlers.js +3 -5
- package/plugins/search/src/events/suggestionHandlers.test.js +5 -8
- package/plugins/search/src/utils/showResult.js +9 -0
- package/plugins/search/src/utils/showResult.test.js +16 -0
- package/providers/beta/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/beta/openlayers/dist/umd/index.js +1 -1
- package/providers/beta/openlayers/src/openlayersProvider.js +102 -2
- package/providers/beta/openlayers/src/openlayersProvider.test.js +95 -0
- package/providers/beta/openlayers/src/utils/highlightFeatures.js +20 -25
- package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +73 -38
- package/providers/beta/openlayers/src/utils/patternImages.js +61 -0
- package/providers/beta/openlayers/src/utils/patternImages.test.js +74 -0
- package/providers/beta/openlayers/src/utils/symbolImages.js +103 -95
- package/providers/beta/openlayers/src/utils/symbolImages.test.js +136 -85
- package/providers/mapProvider.js +53 -1
- package/providers/mapProvider.test.js +6 -0
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +50 -17
- package/providers/maplibre/src/maplibreProvider.test.js +74 -20
- package/providers/maplibre/src/utils/highlightFeatures.js +19 -14
- package/providers/maplibre/src/utils/highlightFeatures.test.js +20 -14
- package/providers/maplibre/src/utils/patternImages.js +46 -29
- package/providers/maplibre/src/utils/patternImages.test.js +52 -4
- package/providers/maplibre/src/utils/symbolImages.js +80 -39
- package/providers/maplibre/src/utils/symbolImages.test.js +157 -54
- package/src/App/components/Hints/Hints.module.scss +1 -1
- package/src/App/components/Markers/Markers.jsx +16 -25
- package/src/App/components/Markers/Markers.test.jsx +34 -48
- package/src/App/components/Markers/SymbolLabelMarker.jsx +1 -1
- package/src/App/components/Markers/SymbolMarker.jsx +1 -1
- package/src/App/components/Viewport/Viewport.jsx +6 -4
- package/src/App/components/Viewport/Viewport.test.jsx +18 -1
- package/src/App/hooks/useMapAnnouncements.js +7 -2
- package/src/App/hooks/useMapAnnouncements.test.js +13 -2
- package/src/App/hooks/useModalPanelBehaviour.js +3 -1
- package/src/App/initialiseApp.js +1 -1
- package/src/App/store/ServiceProvider.jsx +12 -3
- package/src/App/store/ServiceProvider.test.jsx +39 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -3
- package/src/config/appConfig.js +1 -5
- package/src/config/mapSizeScales.js +8 -0
- package/src/config/symbolConfig.js +101 -25
- package/src/services/mapFocus.js +64 -0
- package/src/services/mapFocus.test.js +76 -0
- package/src/services/patternRegistry.js +97 -76
- package/src/services/patternRegistry.test.js +19 -1
- package/src/services/symbolComposer.js +184 -0
- package/src/services/symbolComposer.test.js +132 -0
- package/src/services/symbolRegistry.js +326 -155
- package/src/services/symbolRegistry.test.js +334 -32
- package/src/types.js +11 -5
- package/src/utils/detectInterfaceType.js +16 -5
- package/src/utils/detectInterfaceType.test.js +32 -0
- package/src/utils/hashString.js +23 -0
- package/src/utils/hashString.test.js +29 -0
- package/src/utils/imageDataCache.js +43 -0
- package/src/utils/imageDataCache.test.js +38 -0
- package/src/utils/pathBounds.js +330 -0
- package/src/utils/pathBounds.test.js +145 -0
- package/src/utils/patternUtils.js +0 -8
- package/src/utils/patternUtils.test.js +0 -25
- package/src/utils/recentImageSets.js +35 -0
- package/src/utils/recentImageSets.test.js +46 -0
- package/src/utils/symbolUtils.js +26 -29
- package/src/utils/symbolUtils.test.js +27 -41
- package/plugins/map-key/dist/umd/im-map-key-plugin.js.LICENSE.txt +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,K as o,M as i,v as a,a as s,b as c,d as l,S as u,e as d,r as p,l as h,p as f,f as g,g as y,m,h as v,j as _,k as x,n as b,o as P,q as E,C as O,s as S,t as w,u as I,w as M,A as T}from"./im-draw-plugin.js";import{c as C,r as L,a as k,s as A,b as j,d as F,e as V,f as N}from"./liveDrawChecks.js";import D from"@babel/runtime/helpers/asyncToGenerator";import"@babel/runtime/helpers/objectWithoutProperties";import"preact/compat";import"preact/jsx-runtime";const R={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"},U={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},B={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},G={POLYGON:"polygon",LINE:"line_string",POINT:"point"},H={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"},Y={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},X={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"},K={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},J={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},$={ACTIVE:"true",INACTIVE:"false"},q=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var Z=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:$,classes:R,cursors:B,events:X,geojsonTypes:H,interactions:q,meta:J,modes:Y,sources:U,types:G,updateActions:K});function z(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function W(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===$.ACTIVE&&e.featureTarget.properties.meta===J.FEATURE))}function ee(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===$.INACTIVE&&e.featureTarget.properties.meta===J.FEATURE))}function te(e){return void 0===e.featureTarget}function re(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===J.FEATURE)}function ne(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===J.VERTEX)}function oe(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function ie(e){return"Escape"===e.key||27===e.keyCode}function ae(e){return"Enter"===e.key||13===e.keyCode}function se(e){return"Backspace"===e.key||8===e.keyCode}function ce(e){return"Delete"===e.key||46===e.keyCode}function le(e){return"1"===e.key||49===e.keyCode}function ue(e){return"2"===e.key||50===e.keyCode}function de(e){return"3"===e.key||51===e.keyCode}function pe(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var he=Object.freeze({__proto__:null,isActiveFeature:Q,isBackspaceKey:se,isDeleteKey:ce,isDigit1Key:le,isDigit2Key:ue,isDigit3Key:de,isDigitKey:pe,isEnterKey:ae,isEscapeKey:ie,isFeature:re,isInactiveFeature:ee,isOfMetaType:z,isShiftDown:oe,isShiftMousedown:W,isTrue:function(){return!0},isVertex:ne,noTarget:te});function fe(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ge(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 ye,me,ve={},_e={};function xe(){return ye||(ye=1,_e.RADIUS=6378137,_e.FLATTENING=1/298.257223563,_e.POLAR_RADIUS=6356752.3142),_e}var be=function(){if(me)return ve;me=1;var e=xe();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 ve.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}},ve.ring=r,ve}(),Pe=fe(be);const Ee={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Oe(e,t){const r=Ee[e.geometry.type]-Ee[t.geometry.type];return 0===r&&e.geometry.type===H.POLYGON?e.area-t.area:r}function Se(e){return e.map(e=>(e.geometry.type===H.POLYGON&&(e.area=Pe.geometry({type:H.FEATURE,property:{},geometry:e.geometry})),e)).sort(Oe).map(e=>(delete e.area,e))}function we(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Ie(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)}Ie.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Ie.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Ie.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Ie.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)},Ie.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const Me=[J.FEATURE,J.MIDPOINT,J.VERTEX];var Te={click:function(e,t,r){return Ce(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return Ce(e,t,r,r.options.touchBuffer)}};function Ce(e,t,r,n){if(null===r.map)return[];const o=e?we(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!==Me.indexOf(e.properties.meta)),s=new Ie,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),Se(c)}function Le(e,t){const r=Te.click(e,null,t),n={mouse:B.NONE};return r[0]&&(n.mouse=r[0].properties.active===$.ACTIVE?B.MOVE:B.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=B.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function ke(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function Ae(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=ke(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function je(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 ke(e.point,t.point)<n&&t.time-e.time<o}const Fe=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 Ve=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Ne(){return Ve()}const De=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Ne(),this.type=t.geometry.type};De.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},De.prototype.incomingCoords=function(e){this.setCoordinates(e)},De.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},De.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},De.prototype.setProperty=function(e,t){this.properties[e]=t},De.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:H.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},De.prototype.internal=function(e){const t={id:this.id,meta:J.FEATURE,"meta:type":this.type,active:$.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:H.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Re=function(e,t){De.call(this,e,t)};(Re.prototype=Object.create(De.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},Re.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},Re.prototype.getCoordinate=function(){return this.getCoordinates()};const Ue=function(e,t){De.call(this,e,t)};(Ue.prototype=Object.create(De.prototype)).isValid=function(){return this.coordinates.length>1},Ue.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},Ue.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Ue.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Ue.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Be=function(e,t){De.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Be.prototype=Object.create(De.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Be.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Be.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Be.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])},Be.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))},Be.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]]))},Be.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Be.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 Ge={MultiPoint:Re,MultiLineString:Ue,MultiPolygon:Be},He=(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)},Ye=function(e,t){if(De.call(this,e,t),delete this.coordinates,this.model=Ge[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 Xe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(Ye.prototype=Object.create(De.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Ne(),type:H.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},Ye.prototype.isValid=function(){return this.features.every(e=>e.isValid())},Ye.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},Ye.prototype.getCoordinate=function(e){return He(this.features,"getCoordinate",e)},Ye.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===H.POLYGON?e.getCoordinates():e.coordinates)))},Ye.prototype.updateCoordinate=function(e,t,r){He(this.features,"updateCoordinate",e,t,r),this.changed()},Ye.prototype.addCoordinate=function(e,t,r){He(this.features,"addCoordinate",e,t,r),this.changed()},Ye.prototype.removeCoordinate=function(e){He(this.features,"removeCoordinate",e),this.changed()},Ye.prototype.getFeatures=function(){return this.features},Xe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Xe.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),{})},Xe.prototype.getSelected=function(){return this._ctx.store.getSelected()},Xe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Xe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Xe.prototype.getFeature=function(e){return this._ctx.store.get(e)},Xe.prototype.select=function(e){return this._ctx.store.select(e)},Xe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Xe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Xe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Xe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Xe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Xe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Xe.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Xe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Xe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Xe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Xe.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return Te[r](e,t,this._ctx)},Xe.prototype.newFeature=function(e){const t=e.geometry.type;return t===H.POINT?new Re(this._ctx,e):t===H.LINE_STRING?new Ue(this._ctx,e):t===H.POLYGON?new Be(this._ctx,e):new Ye(this._ctx,e)},Xe.prototype.isInstanceOf=function(e,t){if(e===H.POINT)return t instanceof Re;if(e===H.LINE_STRING)return t instanceof Ue;if(e===H.POLYGON)return t instanceof Be;if("MultiFeature"===e)return t instanceof Ye;throw new Error(`Unknown feature class: ${e}`)},Xe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Xe.prototype.onSetup=function(){},Xe.prototype.onDrag=function(){},Xe.prototype.onClick=function(){},Xe.prototype.onMouseMove=function(){},Xe.prototype.onMouseDown=function(){},Xe.prototype.onMouseUp=function(){},Xe.prototype.onMouseOut=function(){},Xe.prototype.onKeyUp=function(){},Xe.prototype.onKeyDown=function(){},Xe.prototype.onTouchStart=function(){},Xe.prototype.onTouchMove=function(){},Xe.prototype.onTouchEnd=function(){},Xe.prototype.onTap=function(){},Xe.prototype.onStop=function(){},Xe.prototype.onTrash=function(){},Xe.prototype.onCombineFeature=function(){},Xe.prototype.onUncombineFeature=function(){},Xe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Ke={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Je=Object.keys(Ke);function $e(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Xe(r));return{start(){o=i.onSetup(n),Je.forEach(t=>{const r=Ke[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 qe(e){return[].concat(e).filter(e=>void 0!==e)}function Ze(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(U.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(U.COLD).setData({type:H.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(U.HOT).setData({type:H.FEATURE_COLLECTION,features:e.sources.hot}),s()}function ze(e){let t;this._features={},this._featureIds=new Ie,this._selectedFeatureIds=new Ie,this._selectedCoordinates=[],this._changedFeatureIds=new Ie,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,Ze.call(this),this._emitSelectionChange&&(this.ctx.events.fire(X.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(X.RENDER,{})}))},this.isDirty=!1}function We(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}ze.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},ze.prototype.setDirty=function(){return this.isDirty=!0,this},ze.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(X.CREATE,{features:[t.toGeoJSON()]})}return this},ze.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(X.UPDATE,{action:t.action?t.action:K.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},ze.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},ze.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},ze.prototype.getAllIds=function(){return this._featureIds.values()},ze.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},ze.prototype.delete=function(e,t={}){const r=[];return qe(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(X.DELETE,{features:r}),We(this,t),this},ze.prototype.get=function(e){return this._features[e]},ze.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},ze.prototype.select=function(e,t={}){return qe(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},ze.prototype.deselect=function(e,t={}){return qe(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),We(this,t),this},ze.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},ze.prototype.setSelected=function(e,t={}){return e=qe(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},ze.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},ze.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},ze.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},ze.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},ze.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},ze.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},ze.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:K.CHANGE_PROPERTIES})},ze.prototype.storeMapConfig=function(){q.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},ze.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},ze.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Qe=["mode","feature","mouse"];function et(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]=$e(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:B.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!Ae(r,e))},o.touchdrag=function(e){o.drag(e,e=>!je(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=Le(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Le(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Le(t,e);t.featureTarget=n,Ae(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=Te.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=Te.touch(t,null,e)[0];t.featureTarget=r,je(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=se(e),r=ce(e),n=pe(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=Fe(c,e),o.silent||e.map.fire(X.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(R.CANVAS)&&((se(t)||ce(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):le(t)&&e.options.controls.point?c(Y.DRAW_POINT):ue(t)&&e.options.controls.line_string?c(Y.DRAW_LINE_STRING):de(t)&&e.options.controls.polygon&&c(Y.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=Fe(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(X.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=[];Qe.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=`${R.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(R.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(R.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=`${R.CONTROL_GROUP} ${R.CONTROL_BASE}`,r?(r[G.POINT]&&(t[G.POINT]=s(G.POINT,{container:n,className:R.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(Y.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[G.LINE]&&(t[G.LINE]=s(G.LINE,{container:n,className:R.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(Y.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[G.POLYGON]&&(t[G.POLYGON]=s(G.POLYGON,{container:n,className:R.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(Y.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:R.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:R.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:R.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 ze(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(U.COLD,{data:{type:H.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(U.HOT,{data:{type:H.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(U.COLD)&&e.map.removeSource(U.COLD),e.map.getSource(U.HOT)&&e.map.removeSource(U.HOT)}};return e.setup=n,n}const tt="#3bb2d0",rt="#fbb03b",nt="#fff";var ot=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],rt,tt],"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"],rt,tt],"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":nt}},{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"],rt,tt]}},{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":nt}},{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":rt}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":rt}}];function it(e,t){this.x=e,this.y=t}function at(e,t){const r=t.getBoundingClientRect();return new it(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function st(e,t,r,n){return{type:H.FEATURE,properties:{meta:J.VERTEX,parent:e,coord_path:r,active:n?$.ACTIVE:$.INACTIVE},geometry:{type:H.POINT,coordinates:t}}}function ct(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return lt(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=>lt(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return dt(e);default:throw new Error("unknown GeoJSON type")}}function lt(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=ut(e.properties),null==e.geometry?t.geometry=null:t.geometry=dt(e.geometry),t}function ut(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]=ut(n):t[r]=n}),t):t}function dt(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>dt(e)),t):(t.coordinates=pt(e.coordinates),t)}function pt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>pt(e))}function ht(e,t={}){return ft(e,"mercator",t)}function ft(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?gt(e):yt(e):(!0!==i&&(e=ct(e)),r(e,function(e){var t="mercator"===n?gt(e):yt(e);e[0]=t[0],e[1]=t[1]})),e}function gt(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 yt(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 mt(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=ht(n),a=ht(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ft(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:H.FEATURE,properties:{meta:J.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:H.POINT,coordinates:u}}}function vt(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=st(i,e,l,c(l));if(t.midpoints&&o){const e=mt(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===H.POINT?a.push(st(i,o,r,c(r))):n===H.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===H.LINE_STRING?s(o,r):0===n.indexOf(H.MULTI_PREFIX)&&function(){const r=n.replace(H.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:H.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(vt(i,t,o))})}(),a}it.prototype={clone(){return new it(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:it},it.convert=function(e){if(e instanceof it)return e;if(Array.isArray(e))return new it(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new it(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var _t={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:xt,LAT_MAX:bt,LAT_RENDERED_MIN:Pt,LAT_RENDERED_MAX:Et,LNG_MIN:Ot,LNG_MAX:St}=Z;function wt(e,t){let r=xt,n=bt,o=xt,i=bt,a=St,s=Ot;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>Et&&(c.lat=Et-r),o+c.lat>bt&&(c.lat=bt-o),n+c.lat<Pt&&(c.lat=Pt-n),i+c.lat<xt&&(c.lat=xt-i),a+c.lng<=Ot&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=St&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function It(e,t){const r=wt(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===H.POINT?a=n(t):e.type===H.LINE_STRING||e.type===H.MULTI_POINT?a=t.map(n):e.type===H.POLYGON||e.type===H.MULTI_LINE_STRING?a=t.map(o):e.type===H.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const Mt={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(X.UPDATE,{action:K.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 Ie).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(){_t.enable(this)},onMouseMove:function(e,t){return re(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Mt.onTap=Mt.onClick=function(e,t){return te(t)?this.clickAnywhere(e,t):z(J.VERTEX)(t)?this.clickOnVertex(e,t):re(t)?this.clickOnFeature(e,t):void 0},Mt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),_t.enable(this),this.stopExtendedInteractions(e)},Mt.clickOnVertex=function(e,t){this.changeMode(Y.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:B.MOVE})},Mt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Mt.clickOnFeature=function(e,t){_t.disable(this),this.stopExtendedInteractions(e);const r=oe(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==H.POINT)return this.changeMode(Y.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:B.POINTER}),1===n.length&&_t.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:B.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:B.MOVE})),this.doRender(o)},Mt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),Q(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&W(t)?this.startBoxSelect(e,t):void 0},Mt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=at(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Mt.onTouchStart=function(e,t){if(Q(t))return this.startOnActiveFeature(e,t)},Mt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Mt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:B.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(R.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=at(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"},Mt.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};It(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Mt.onTouchEnd=Mt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,at(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:B.MOVE}))}this.stopExtendedInteractions(e)},Mt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?$.ACTIVE:$.INACTIVE,r(t),this.fireActionable(),t.properties.active===$.ACTIVE&&t.geometry.type!==H.POINT&&vt(t).forEach(r)},Mt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Mt.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:H.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(X.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},Mt.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(X.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const Tt=z(J.VERTEX),Ct=z(J.MIDPOINT),Lt={fireUpdate:function(){this.fire(X.UPDATE,{action:K.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);oe(t)||-1!==n?oe(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){It(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=wt(n.map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.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(Y.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(Y.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===H.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),_t.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){_t.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=$.ACTIVE,r(t),vt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=$.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(Y.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=Q(t),n=Tt(t),o=Ct(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:B.MOVE}):this.updateUIClasses({mouse:B.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Lt.onTouchStart=Lt.onMouseDown=function(e,t){return Tt(t)?this.onVertex(e,t):Q(t)?this.onFeature(e,t):Ct(t)?this.onMidpoint(e,t):void 0},Lt.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},Lt.onClick=function(e,t){return te(t)?this.clickNoTarget(e,t):Q(t)?this.clickActiveFeature(e,t):ee(t)?this.clickInactive(e,t):void this.stopDragging(e)},Lt.onTap=function(e,t){return te(t)?this.clickNoTarget(e,t):Q(t)?this.clickActiveFeature(e,t):ee(t)?this.clickInactive(e,t):void 0},Lt.onTouchEnd=Lt.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const kt={};function At(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}kt.onSetup=function(){const e=this.newFeature({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:B.ADD}),this.activateUIButton(G.POINT),this.setActionableState({trash:!0}),{point:e}},kt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)},kt.onTap=kt.onClick=function(e,t){this.updateUIClasses({mouse:B.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(X.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.point.id]})},kt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},kt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?$.ACTIVE:$.INACTIVE,!n)return r(t)},kt.onTrash=kt.stopDrawingAndRemove,kt.onKeyUp=function(e,t){if(ie(t)||ae(t))return this.stopDrawingAndRemove(e,t)};const jt={onSetup:function(){const e=this.newFeature({type:H.FEATURE,properties:{},geometry:{type:H.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),_t.disable(this),this.updateUIClasses({mouse:B.ADD}),this.activateUIButton(G.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&At(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:B.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(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),ne(t)&&this.updateUIClasses({mouse:B.POINTER})}};jt.onTap=jt.onClick=function(e,t){return ne(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},jt.onKeyUp=function(e,t){ie(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)):ae(t)&&this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},jt.onStop=function(e){this.updateUIClasses({mouse:B.NONE}),_t.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(X.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT,{},{silent:!0})))},jt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?$.ACTIVE:$.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=J.FEATURE,r(st(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(st(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:H.FEATURE,properties:t.properties,geometry:{coordinates:e,type:H.LINE_STRING}}),3===o)return}return r(t)}},jt.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)};const Ft={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:H.FEATURE,properties:{},geometry:{type:H.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),_t.disable(this),this.updateUIClasses({mouse:B.ADD}),this.activateUIButton(G.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&At(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&At(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:B.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(Y.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),ne(t)&&this.updateUIClasses({mouse:B.POINTER})}};Ft.onTap=Ft.onClick=function(e,t){if(ne(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Ft.onKeyUp=function(e,t){ae(t)?this.changeMode(Y.SIMPLE_SELECT,{featureIds:[e.line.id]}):ie(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT))},Ft.onStop=function(e){_t.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(X.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT,{},{silent:!0})))},Ft.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Y.SIMPLE_SELECT)},Ft.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?$.ACTIVE:$.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=J.FEATURE,r(st(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 Vt={simple_select:Mt,direct_select:Lt,draw_point:kt,draw_polygon:jt,draw_line_string:Ft};const Nt={defaultMode:Y.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:ot,modes:Vt,controls:{},userProperties:!1,suppressAPIEvents:!0},Dt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Rt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Ut(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?U.HOT:U.COLD}))}var Bt,Gt;var Ht,Yt,Xt=fe(Gt?Bt:(Gt=1,Bt=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 Kt=function(){if(Yt)return Ht;Yt=1,Ht=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 Ht}(),Jt=fe(Kt);function $t(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const qt={Polygon:Be,LineString:Ue,Point:Re,MultiPolygon:Ye,MultiLineString:Ye,MultiPoint:Ye};var Zt=Object.freeze({__proto__:null,CommonSelectors:he,ModeHandler:Fe,StringSet:Ie,constrainFeatureMovement:wt,createMidPoint:mt,createSupplementaryPoints:vt,createVertex:st,doubleClickZoom:_t,euclideanDistance:ke,featuresAt:Te,getFeatureAtAndSetCursors:Le,isClick:Ae,isEventAtCoordinates:At,isTap:je,mapEventToBoundingBox:we,moveFeatures:It,sortFeatures:Se,stringSetsAreEqual:$t,theme:ot,toDenseArray:qe});const zt=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({},Rt,e.controls):t.controls=Object.assign({},Dt,e.controls),t=Object.assign({},Nt,t),t.styles=Ut(t.styles,"cold").concat(Ut(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=Y;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Te.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:H.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:H.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:H.FEATURE,properties:{},geometry:{type:H.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==H.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 Ie(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(Jt(t))).features.map(t=>{if(t.id=t.id||Ne(),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=qt[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,Xt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Xt(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:H.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==Y.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(Y.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===Y.DIRECT_SELECT?e.events.changeMode(Y.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===Y.SIMPLE_SELECT&&t.getMode()===Y.SIMPLE_SELECT?($t(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===Y.DIRECT_SELECT&&t.getMode()===Y.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=et(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=G,t.options=e,t};function Wt(e){zt(e,this)}Wt.modes=Vt,Wt.constants=Z,Wt.lib=Zt;var Qt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},er="draw.create",tr="draw.update",rr="draw.modechange",nr="draw.editfinish",or="draw.cancel",ir="draw.vertexselection",ar="draw.vertexchange",sr="draw.undochange",cr="draw.undo",lr="draw.geometrychange",ur="draw.interfacetypechange",dr="draw.placementblocked",pr="draw.nudgevertex",hr="draw.selectvertex",fr="draw.insertvertexatmidpoint",gr="styledata",yr=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[]}},mr=e=>{var t=yr(e),r=vr(e);if(!t.length||!r.length)return[];var n=[];for(var o of r)for(var i=o.closed?o.length:o.length-1,a=0;a<i;a++){var s=o.start+a,c=o.start+(a+1)%o.length,[l,u]=t[s],[d,p]=t[c];n.push([(l+d)/2,(u+p)/2])}return n},vr=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},_r=(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},xr=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},br=(e,t)=>{var r=t.split(".").map(Number),n=vr(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]},Pr=(e,t)=>({x:e.x*t,y:e.y*t}),Er=e=>e instanceof window.SVGElement||e.ownerSVGElement;function Or(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 Sr(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Or(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Or(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function wr(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function Ir(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 Mr(e){return Ir(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function Tr(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function Cr(e,t){e&&(e._autoSnapSuspended=t)}function Lr(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function kr(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 Ar(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 jr(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var Fr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r=>n=>r.call(e,t,n),o={keydown:n(e.onKeydown),keyup:n(e.onKeyup),pointerdown:n(e.onPointerevent),pointermove:n(e.onPointerevent),pointerup:n(e.onPointerevent),click:n(e.onButtonClick),touchstart:n(e.onTouchstart),touchmove:n(e.onTouchmove),touchend:n(e.onTouchend),scalechange:n(e.onScaleChange),move:n(e.onMove),interfacetypechange:n(e.onInterfaceTypeChange)};for(var[i,a]of Object.entries(r))o[i]=n(a);return o},Vr=(e,t,r)=>{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}),t.on("draw.scalechange",r.scalechange),t.on("move",r.move),t.on(ur,r.interfacetypechange),t.on(pr,r.nudge)},Nr=(e,t,r)=>{e.container.removeEventListener("pointerdown",r.pointerdown),e.container.removeEventListener("pointermove",r.pointermove),e.container.removeEventListener("pointerup",r.pointerup),e.container.removeEventListener("touchstart",r.touchstart),e.container.removeEventListener("touchmove",r.touchmove),e.container.removeEventListener("touchend",r.touchend),t.off("draw.scalechange",r.scalechange),t.off("move",r.move),t.off(ur,r.interfacetypechange),t.off(pr,r.nudge),t.dragPan.enable(),window.removeEventListener("click",r.click),window.removeEventListener("keydown",r.keydown,{capture:!0}),window.removeEventListener("keyup",r.keyup,{capture:!0})},Dr=e=>{var t=wr(e);t&&kr(t,e)},Rr={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(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}};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={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},Hr=Br(Br({},Rr),{},{UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Gr,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(Gr[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=vr(i),c=_r(s,r);if(c){xr(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,Pr(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=vr(o),s=_r(a,r);if(s)xr(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=vr(i),c=_r(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)xr(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,Pr(this.map.project(e.vertices[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.vertices=this.getVertices(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}}),Yr=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Xr=(e,t,r,n,o)=>{var i=window.getComputedStyle(t),a={x:r.x-Number.parseFloat(i.left),y:r.y-Number.parseFloat(i.top)},s=e.project(n);return{deltaTarget:a,deltaVertex:{x:r.x/o-s.x,y:r.y/o-s.y}}},Kr=(e,t,r)=>{var n={x:r.x/t.scale-t.deltaVertex.x,y:r.y/t.scale-t.deltaVertex.y},o=e.unproject(n);if(jr(t)){var i=wr(e);Tr(i,e,n),o=Mr(i)||o}return o};function Jr(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 $r(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Jr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Jr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var qr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=L(t,r);k(e,{editActive:n,editHalo:o,editVertex:i})}},Zr={addTouchVertexTarget(e){e.touchVertexTarget=C(e.container),qr(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||Er(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(Ar(wr(this.map)),null!=e&&e.featureId){this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&null!=e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=null,e._touchMoved=!1;var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,Pr(this.map.project(t),e.scale))}},onTap(e,t){var r,n,o=wr(this.map);o&&kr(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=br(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex($r($r({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){Ar(wr(this.map));var r=this.getVertices(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&Er(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=Yr(t);Object.assign(e,Xr(this.map,e.touchVertexTarget,o,n,e.scale))}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&Er(t.target.parentNode)){e._touchMoved=!0;var r=Yr(t);this.moveVertex(e,Kr(this.map,e,r)),this.updateTouchVertexTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}},zr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),Wr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Qr=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),en=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(Qr.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},tn=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,rn={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))}},nn={getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?o.nudgeAmount:o.stepAmount,[i,a]=t?Wr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+i,y:r.y+a})},getOffsetByDelta(e,t,r,n){var i=this.map.project(e),a=n?o.stepAmount:o.nudgeAmount;return this.map.unproject({x:i.x+t*a,y:i.y+r*a})},resolveSnapTarget(e,t,r,o,i){var a=wr(this.map);if(jr(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,kr(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return jr(e)&&a&&(Tr(a,this.map,this.map.project(l)),Ir(a))?(e._isSnapped=!0,Mr(a)):(e._isSnapped=!1,l)}};function on(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 an(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?on(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):on(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var sn=an(an({},nn),{},{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(e,t){var[r,n]=this.getVertexOrMidpoint(e,t);r<0||!n||this.changeMode(e,an({selectedVertexIndex:r,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,r)}))},getNewCoord(e,t){return this.getOffset(yr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=yr(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.vertices.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=vr(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&&(xr(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=vr(o),s=_r(a,e.selectedVertexIndex);s&&(xr(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertices=this.getVertices(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=vr(t),n=_r(r,e.selectedVertexIndex);if(n){var{segment:o}=n,a=o.closed?i.Polygon:i.LineString;if(!(o.length<=a)){var s=[...e.vertices[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})}}}}}),cn={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=vr(r),o=_r(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVertices(e){return yr(this.getFeature(e))},getMidpoints(e){return mr(this.getFeature(e))},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertices)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertices.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=A(a,i,t);return[s,s<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=vr(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.vertices.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertices.length}};function ln(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 un(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ln(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ln(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var dn=un(un({},rn),{},{onKeydown(e,t){en(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?zr.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?tn(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=wr(this.map);n&&kr(n,this.map),null!==(t=e.vertices)&&void 0!==t&&t.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertices)&&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=yr(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]=Wr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){en(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&j(t),zr.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))}}),pn={onMouseDown(e,t){var r,n;Ar(wr(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,Lt.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=br(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertices)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=br(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(ir,{index:e.selectedVertexIndex,numVertices:e.vertices.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(ir,{index:r,numVertices:e.vertices.length})}Lt.onClick.call(this,e,t)},onMouseUp(e,t){Ar(wr(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,Lt.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=yr(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(ir,{index:t,numVertices:e.vertices.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=wr(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),jr(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),Tr(n,this.map,t.point);var o=Mr(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Lt.onDrag.call(this,e,t)}}};function hn(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 fn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?hn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):hn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var gn=fn(fn(fn(fn(fn(fn(fn(fn({},Wt.modes.direct_select),Hr),Zr),sn),cn),dn),pn),{},{onSetup(e){var t,r,n,o=Wt.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);if(o.featureType=null==i?void 0:i.type,o.vertices=this.getVertices(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o),Dr(this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var a=o.vertices[o.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(o,Pr(this.map.project(a),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=this.handlers=Fr(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint});Vr(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(hr,t.selectvertex),this.map.on(fr,t.insertvertexatmidpoint)},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.vertices.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=yr(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(ir,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length});var c=o||(e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?Pr(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.vertices[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?Pr(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertices.map(e=>JSON.stringify(e))).size!==e.vertices.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,Pr(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertices[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,Pr(this.map.project(r),e.scale))},onSelectVertex(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId));var n=t.index<e.vertices.length?"vertex":"midpoint";this.changeMode(e,fn({selectedVertexIndex:t.index,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,t.index)}))},onInsertVertexAtMidpoint(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),this.insertVertex(fn(fn({},e),{},{selectedVertexIndex:t.index,selectedVertexType:"midpoint"}))},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",fn(fn({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),this.map.off(hr,t.selectvertex),this.map.off(fr,t.insertvertexatmidpoint),Nr(e,this.map,t),this.hideTouchVertexIndicator(e)}});function yn(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 mn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?yn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):yn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var vn={move_point:"commit-move"},_n=mn(mn({},Rr),{},{UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:vn,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_point"===r.type&&this.undoMovePoint(e,r),this.emitGeometryValidation(vn[r.type],r.vertexIndex,r.featureId)}},undoMovePoint(e,t){var{previousPosition:r,featureId:n}=t,o=this.getFeature(n);o&&(o.updateCoordinate("",r[0],r[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,Pr(this.map.project(r),e.scale)))}}),xn={addTouchPointTarget(e){e.touchPointTarget=C(e.container),qr(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchPointTarget.style.display="none"},hideTouchPointIndicator(e){e.touchPointTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){Ar(wr(this.map)),e._touchMoved&&e._moveStartPosition&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._touchMoved=!1,e.feature&&this.updateTouchPointTarget(e,Pr(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){Ar(wr(this.map));var r=this.getPointCoord(e);if(r&&Er(t.target.parentNode)){e._moveStartPosition=[...r],e._touchMoved=!1;var n=Yr(t);Object.assign(e,Xr(this.map,e.touchPointTarget,n,r,e.scale))}},onTouchmove(e,t){if(Er(t.target.parentNode)){e._touchMoved=!0;var r=Yr(t);this.movePoint(e,Kr(this.map,e,r)),this.updateTouchPointTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}};function bn(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 Pn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?bn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):bn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var En=Pn(Pn({},nn),{},{getPointCoord(e){var t;return null===(t=this.getFeature(e.featureId))||void 0===t?void 0:t.coordinates},getNewCoord(e,t){return this.getOffset(this.getPointCoord(e),t)},movePoint(e,t){e.feature.updateCoordinate("",t.lng,t.lat),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.feature)},nudgePointByDelta(e,t,r,n){var o=this.getPointCoord(e);if(o){var i=[...o],a=this.resolveSnapTarget(e,t,r,o,()=>this.getOffsetByDelta(o,t,r,n));this.movePoint(e,a),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}}});function On(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 Sn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?On(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):On(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var wn=Sn(Sn({},rn),{},{onKeydown(e,t){en(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?zr.has(t.key)?this.handleArrowKey(e,t):tn(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){var r=this.getPointCoord(e);r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r]),this.movePoint(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,r){var[n,o]=Wr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){en(e)||(e.interfaceType="keyboard",j(t),zr.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}}),In="edit_point",Mn={onFeature(e,t){e.dragMoving||(e._moveStartPosition=[...e.feature.coordinates],e._grabOffset=[e.feature.coordinates[0]-t.lngLat.lng,e.feature.coordinates[1]-t.lngLat.lat],Cr(wr(this.map),!0)),Lt.onFeature.call(this,e,t)},onClick(e,t){if(!Q(t)&&((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=a(r,{mode:In,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:In,vertexIndex:0}),n})(this.map,[t.lngLat.lng,t.lngLat.lat])){var r=[...e.feature.coordinates],n=wr(this.map),o=t.lngLat;jr(e)&&n&&(Tr(n,this.map,t.point),o=Mr(n)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:r})}},onMouseUp(e,t){var r=wr(this.map);Ar(r),Cr(r,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Lt.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;var t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var r=wr(this.map);if(r&&(r.snapStatus=!1,r.snapCoords=null),jr(e)&&null!=r&&r.status){if(e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};Tr(r,this.map,this.map.project([n.lng,n.lat]));var o=Mr(r)||n;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Lt.onDrag.call(this,e,t)}},onTrash(){}};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 Cn(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 Ln=Cn(Cn(Cn(Cn(Cn(Cn(Cn({},Wt.modes.direct_select),_n),xn),En),wn),Mn),{},{onSetup(e){var t,r,n=e.featureId,o=this.getFeature(n);if(!o)throw new Error("You must provide a featureId to enter edit_point mode");var i,a={featureId:n,feature:o,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};(this.setSelectedCoordinates([]),this.setSelected(n),_t.disable(this),this.setActionableState({trash:!1}),Object.assign(a,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:null!==(t=e.scale)&&void 0!==t?t:1}),this.map._lastEditFeatureId!==a.featureId)&&(null===(i=this.map._undoStack)||void 0===i||i.clear(),this.map._lastEditFeatureId=a.featureId);return this.setupEventListeners(a),this.map._drawEditContainer=e.container,this.addTouchPointTarget(a),null===(r=a.container)||void 0===r||r.focus({preventScroll:!0}),Dr(this.map),"touch"===a.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(a,Pr(this.map.project(a.feature.coordinates),a.scale))},0),this.map.fire(ir,{index:0,numVertices:1}),a},setupEventListeners(e){var t=this.handlers=Fr(this,e,{nudge:this.onNudgePoint});Vr(e,this.map,t)},toDisplayFeatures(e,t,r){t.properties.active=e.featureId===t.properties.id?"true":"false",r(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,Pr(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,Pr(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,Pr(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Nr(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}});function kn(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 An(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?kn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):kn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var jn=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?An(An({},e),{},{featureId:null}):e,a=An(An({},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),a.crossHair&&(a.crossHair.activate=()=>{var e;return null===(e=this._placeAtCrossHair)||void 0===e?void 0:e.call(this,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,"keyup",j,{capture:!0}],[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,o]=e;return t.addEventListener?t.addEventListener(r,n,o):t.on(r,n)}),a},onStop(e){var r;t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n,o]=e;return t.removeEventListener?t.removeEventListener(r,n,o):t.off(r,n)}),null!==(r=e.crossHair)&&void 0!==r&&r.activate&&(e.crossHair.activate=null),["touch","keyboard"].includes(e.interfaceType)||this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function Fn(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 Vn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Fn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Fn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Nn=(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)},Dn=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=s({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",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Nn(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)}}},Rn=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=wr(this.map);if(jr(e)&&Ir(c))a=function(e,t){var r=Mr(t);return r?Sr(Sr({},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=wr(this.map),l=jr(e)&&function(e,t){var r=Mr(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]}))}},_placeAtCrossHair(e){this.doClick(e)}}};function Un(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 Bn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Un(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Un(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Gn=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))}}},Hn=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)}}},Yn=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}}},Xn=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 Kn(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 Jn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Kn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Kn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var $n=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(jr(e)){var n=wr(this.map);Tr(n,this.map,r.point);var o=Mr(n);o&&(r=Jn(Jn({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e,r){var n="move"===(null==r?void 0:r.type)&&!r.originalEvent;if(["touch","keyboard"].includes(e.interfaceType)||n){jr(e)&&Lr(wr(this.map),this.map);var o=wr(this.map),i=jr(e)&&Mr(o);if(i){var a=this.map.project([i.lng,i.lat]);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.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)))}}},qn=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 Zn(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 zn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Zn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Zn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Wn=(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 zn(zn(zn(zn(zn(zn(zn({},e),jn(l)),(e=>Vn(Vn({},Dn(e)),Rn(e)))(l)),(e=>Bn(Bn(Bn({},Gn(e)),Hn(e)),Yn(e)))(l)),Xn(l)),$n(l)),qn(l))},Qn=Wn(Wt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>c(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),eo=Wn(Wt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>l(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)});function to(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 ro(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?to(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):to(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var no="draw_point",oo=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),io=Wt.modes.draw_point,ao=jn({ParentMode:io,featureProp:"point",excludeFeatureIdFromSetup:!1}),so={onKeyUp(){},_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)},onCreate(e,t){var r,n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),null===(r=e.resolvePointSymbol)||void 0===r||r.call(e,e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e,t){var r="move"===(null==t?void 0:t.type)&&!t.originalEvent;(["touch","keyboard"].includes(e.interfaceType)||r)&&jr(e)&&Lr(wr(this.map),this.map)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onTouchStart(e){this._setInterface(e,"touch"),this.onMove(e)},onTouchEnd(e){this._setInterface(e,"touch"),this.onMove(e)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onMouseMove(e,t){jr(e)&&Tr(wr(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),oo.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&oo.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e),"Enter"===t.key&&e.isActive&&this._placeAtCrossHair(e)):this.map.fire("draw.cancel")},onClick(e,t){if(!(t.originalEvent.button>0||t.originalEvent.target!==this.map.getCanvas())){var r=wr(this.map),n=jr(e)&&Ir(r)?Mr(r):null;this._commit(e,n||t.lngLat)}},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){var t=wr(this.map);jr(e)&&Lr(t,this.map);var r=jr(e)&&Ir(t)?Mr(t):null;this._commit(e,r||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=a(r,{mode:no,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:no,vertexIndex:0}),n})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},co=ro(ro(ro({},io),ao),so),lo=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],uo=["get","user_sortKey"],po=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":uo},paint:{"fill-color":lo(e,"fill",t.shapeFill)}}),ho=(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","line-sort-key":uo},paint:{"line-color":lo(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),fo=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}}),go=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),yo=(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}}),mo=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),vo=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),_o=(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}}),xo=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),bo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),Po=function(e){var t,r,n,o,i,a=L(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:s,midpointRadius:c,vertexHaloRadius:l,midpointHaloRadius:d}=u;return[po(e,a),(i=a.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":i}}),(o=a.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":o,"line-width":2,"line-opacity":1}}),(n=a.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}}),ho(e,a),{id:"point-symbol",type:"symbol",filter:["all",["==","$type","Point"],["==","meta","feature"]],layout:{"icon-image":["case",["==",["get","active"],"true"],["coalesce",["get","user_symbolSelectedImageId"],["get","user_symbolImageId"]],["get","user_symbolImageId"]],"icon-anchor":["get","user_symbolIconAnchor"],"icon-offset":["literal",[0,0]],"icon-allow-overlap":!0,"icon-ignore-placement":!0,"symbol-sort-key":uo},paint:{}},(r=a.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=a.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}}),fo(a.editStroke),vo(a.editMidpoint,c),_o(a.editHalo,a.editActive,d),xo(a.editMidpoint,c),go(a.editVertex,s),yo(a.editHalo,a.editActive,l),mo(a.editVertex,s),bo(a.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 Eo(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 Oo(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 So(e,t,r){void 0===r&&(r={});var n=Eo(e),o=Eo(t),i=d(o[1]-n[1]),a=d(o[0]-n[0]),s=d(n[1]),c=d(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return p(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function wo(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 Io(e,t,r,n={}){const o=wo(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(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)),p=g(u),y=g(l);return void 0!==o[2]?f([p,y,o[2]],n.properties):f([p,y],n.properties)}function Mo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return m(e,t);return v(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function To(e,t,r={}){if(!0===r.final)return function(e,t){let r=To(t,e);return r=(r+180)%360,r}(e,t);const n=wo(e),o=wo(t),i=d(n[0]),a=d(o[0]),s=d(n[1]),c=d(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 g(Math.atan2(l,u))}var Co=To;function Lo(e,t,r,n){void 0===n&&(n={});var o=Eo(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(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)),p=g(u),y=g(l);return f([p,y],n.properties)}function ko(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=Oo(n);break;case"LineString":r=[Oo(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=v([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)}),x(t)}var Ao={exports:{}};function jo(e,t,r,n,o){Fo(e,t,r||0,n||e.length-1,o||No)}function Fo(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);Fo(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(Vo(e,r,t),o(e[n],u)>0&&Vo(e,r,n);d<p;){for(Vo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?Vo(e,r,p):Vo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function Vo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function No(e,t){return e<t?-1:e>t?1:0}function Do(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 Ro(e,t){Uo(e,0,e.children.length,t,e)}function Uo(e,t,r,n,o){o||(o=Zo(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];Bo(o,e.leaf?n(t):t)}return o}function Bo(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 Go(e,t){return e.minX-t.minX}function Ho(e,t){return e.minY-t.minY}function Yo(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Xo(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Ko(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 Jo(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 $o(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function qo(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Zo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function zo(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;jo(e,a,t,r,o),i.push(t,a,a,r)}}var Wo,Qo=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(!qo(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;qo(e,s)&&(t.leaf?r.push(a):$o(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!qo(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(qo(e,i)){if(t.leaf||$o(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=Zo([]),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=Do(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!$o(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=Zo(e.slice(t,r+1)),Ro(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=Zo([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));zo(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);zo(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 Ro(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=Yo(a),c=Ko(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),Bo(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=Zo(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Ro(r,this.toBBox),Ro(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=Zo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Ro(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=Uo(e,0,a,this.toBBox),s=Uo(e,a,r,this.toBBox),c=Jo(t,s),l=Yo(t)+Yo(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:Go,o=e.leaf?this.compareMinY:Ho;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=Uo(e,0,t,o),a=Uo(e,r-t,r,o);let s=Xo(i)+Xo(a);for(let n=t;n<r-t;n++){const t=e.children[n];Bo(i,e.leaf?o(t):t),s+=Xo(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Bo(a,e.leaf?o(t):t),s+=Xo(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Bo(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():Ro(e[r],this.toBBox)}}}),ei=ge(Qo),ti={};function ri(){if(Wo)return ti;Wo=1,Object.defineProperty(ti,"__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 ti.areaFactors=r,ti.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},ti.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},ti.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},ti.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)},ti.degreesToRadians=function(e){return e%360*Math.PI/180},ti.earthRadius=e,ti.factors=t,ti.feature=n,ti.featureCollection=s,ti.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")}},ti.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},ti.isNumber=f,ti.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},ti.lengthToDegrees=function(e,t){return h(p(e,t))},ti.lengthToRadians=p,ti.lineString=a,ti.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},ti.multiLineString=c,ti.multiPoint=l,ti.multiPolygon=u,ti.point=o,ti.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},ti.polygon=i,ti.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},ti.radiansToDegrees=h,ti.radiansToLength=d,ti.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},ti.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")})},ti.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")},ti}var ni,oi={};function ii(){if(ni)return oi;ni=1,Object.defineProperty(oi,"__esModule",{value:!0});var e=ri();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 _=0;_<c;_++){var x=0,b=0;if(null!==(s=d?u.geometries[_]:u)){l=s.coordinates;var P=s.type;switch(p=!n||"Polygon"!==P&&"MultiPolygon"!==P?0:1,P){case null:break;case"Point":if(!1===r(l,h,v,x,b))return!1;h++,x++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,x,b))return!1;h++,"MultiPoint"===P&&x++}"LineString"===P&&x++;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,x,b))return!1;h++}"MultiLineString"===P&&x++,"Polygon"===P&&b++}"Polygon"===P&&x++;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,x,b))return!1;h++}b++}x++}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 oi.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},oi.coordEach=t,oi.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},oi.featureEach=n,oi.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},oi.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")},oi.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")},oi.flattenEach=i,oi.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},oi.geomEach=o,oi.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},oi.lineEach=s,oi.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},oi.propEach=r,oi.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},oi.segmentEach=a,oi.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},oi}var ai,si,ci={};function li(){if(ai)return ci;ai=1,Object.defineProperty(ci,"__esModule",{value:!0});var e=ii();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 ci.bbox=t,ci.default=r,ci}var ui=function(){if(si)return Ao.exports;si=1;var e=ei,t=ri(),r=ii(),n=li().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 Ao.exports=a,Ao.exports.default=a,Ao.exports}(),di=fe(ui);function pi(e,t){var r={},n=[];if("LineString"===e.type&&(e=b(e)),"LineString"===t.type&&(t=b(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=hi(e,t);return o&&n.push(o),x(n)}var i=di();return i.load(ko(t)),P(ko(e),function(e){P(i.search(e),function(t){var o=hi(e,t);if(o){var i=Oo(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),x(n)}function hi(e,t){var r=Oo(e),n=Oo(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),g=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var y=h/p,m=g/p;return y>=0&&y<=1&&m>=0&&m<=1?f([o+y*(a-o),i+y*(s-i)]):null}function fi(e,t,r){void 0===r&&(r={});var n=f([1/0,1/0],{dist:1/0}),o=0;return _(e,function(e){for(var i=Oo(e),a=0;a<i.length-1;a++){var s=f(i[a]);s.properties.dist=So(t,s,r);var c=f(i[a+1]);c.properties.dist=So(t,c,r);var l=So(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=Co(s,c),p=Lo(t,u,d+90,r),h=Lo(t,u,d-90,r),g=pi(v([p.geometry.coordinates,h.geometry.coordinates]),v([s.geometry.coordinates,c.geometry.coordinates])),y=null;g.features.length>0&&((y=g.features[0]).properties.dist=So(t,y,r),y.properties.location=o+So(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 gi(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 yi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=gi(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(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)),p=g(u),y=g(l);return f([p,y],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=gi(e),o=gi(t),i=d(o[1]-n[1]),a=d(o[0]-n[0]),s=d(n[1]),c=d(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return p(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,Co(e,t));return r}var mi=function(){return mi=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},mi.apply(this,arguments)},vi=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=mi(mi({},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 So(f(e),f(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=So(f([r.lng,r.lat]),f([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(Io(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),y([i],o)}(s.coords,i,{steps:64,units:"meters",properties:{color:s.color}})):(this.snapStatus=!1,this.snapCoords=[]);var c=x(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(x([])))}),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=E(e),o=[];if(n.map(function(e){var n=So(f(e),f([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(v(e))});break;case"Polygon":var o=Mo(e.geometry);n.push(o);break;case"MultiPolygon":Mo(e.geometry).coodinates.map(function(e){n.push(v(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(ko(e).features)});var i=[];if(o.map(function(e){var n=yi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=So(n,f([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=fi(n[i],f([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}(),_i="snap-helper-circle",xi="mapbox-gl-draw-hot";function bi(e){if(!vi.prototype.__snapPatched){vi.prototype.__snapPatched=!0;var t=vi.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(_i)&&this.map.setLayoutProperty(_i,"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=>y(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>v(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)&&(!this._autoSnapSuspended||e._explicit))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 Pi(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function Ei(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 Oi=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Si(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(_i)&&e.removeLayer(_i),e.getSource(_i)&&e.removeSource(_i)}(e),Ei(r);var o=new vi({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&&Oi.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 wi(e,t,r){e.on("style.load",()=>{Pi(()=>e._removed?null:e.getSource(xi),n=>{Ei(n),function(e){var t;e.getSource(_i)||e.addSource(_i,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(_i)||e.addLayer({id:_i,type:"fill",source:_i,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Si(e,t,n,r)})})}function Ii(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 Mi(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:i=[],radius:a=n.snapRadius,rules:s=["vertex","midpoint","edge"],status:c=!1,onSnapped:l=()=>{},colors:u={}}=o,d={layers:i,radius:a,rules:s,status:c,onSnapped:l};return bi(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ii(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ii(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:O.snapVertex,midpoint:O.snapMidpoint,edge:O.snapEdge},u)),wi(t,r,d),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(_i)){e.setLayoutProperty(_i,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(_i,"visibility","visible")}})}(t),Pi(()=>t._removed?null:t.getSource(xi),e=>Si(t,r,e,d)),t._snapInstance}var Ti=.25,Ci=.75,Li=e=>{var[t,r]=e,n=(e=>e<=Ti?"left":e>=Ci?"right":"")(t),o=(e=>e<=Ti?"top":e>=Ci?"bottom":"")(r);return o+(n&&o?"-":"")+n||"center"},ki=e=>e<=Ti?0:e>=Ci?1:.5,Ai=e=>Math.round(100*e)/100;function ji(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 Fi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ji(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ji(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Vi=e=>!!(null!=e&&e.symbol||null!=e&&e.symbolSvgContent),Ni=(e,t,r)=>{var n;if(null!==(n=e._symbolIconOffsetMap)&&void 0!==n||(e._symbolIconOffsetMap={}),!e._symbolIconOffsetMap[t]){e._symbolIconOffsetMap[t]=r;var o=(e=>{var t=["match",["get","user_symbolImageId"]];for(var[r,n]of Object.entries(e))t.push(r,["literal",n]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);["hot","cold"].forEach(t=>{var r="".concat("point-symbol",".").concat(t);e.getLayer(r)&&e.setLayoutProperty(r,"icon-offset",o)})}},Di=function(){var e=D(function*(e){var t,r,n,o,{draw:i,mapProvider:a,map:s,featureId:c,properties:l,pixelRatioOverride:u}=e;if(!Vi(l))return null;var d=s._drawCurrentMapStyle,p=null!=u?u:(e=>{var t;return(null===(t=e.getPixelRatio)||void 0===t?void 0:t.call(e))||1})(s);yield a.addSymbolsToMap([l],d,S);var h=i.get(c);if(!h)return null;var f=S.getSymbolImageId(l,d,!1,p);if(!f)return null;var g=null!==(t=null===(r=s._activeSymbolImageMap)||void 0===r?void 0:r[f])&&void 0!==t?t:null,y=null!==(n=null===(o=s._selectedSymbolImageMap)||void 0===o?void 0:o[f])&&void 0!==n?n:null,m=S.getSymbolDef(l),v=w(l,m),_=Li(v),x=((e,t)=>{var[r,n]=e,[,,o,i]=t.split(" ").map(Number);return[Ai((ki(r)-r)*o),Ai((ki(n)-n)*i)]})(v,I(l,m));return Ni(s,f,x),Fi(Fi({},h),{},{properties:Fi(Fi({},l),{},{symbolImageId:f,symbolIconAnchor:_,symbolActiveImageId:g,symbolSelectedImageId:y})})});return function(t){return e.apply(this,arguments)}}(),Ri=function(){var e=D(function*(e){try{var t=yield Di(e);if(!t)return;e.draw.add(t)}catch(t){console.error("[draw] failed to resolve point symbol",e.featureId,t)}});return function(t){return e.apply(this,arguments)}}(),Ui=function(){var e=D(function*(e){var{draw:t,mapProvider:r,map:n,pixelRatioOverride:o}=e,i=t.getAll().features.filter(e=>"Point"===e.geometry.type&&Vi(e.properties)),a=yield Promise.allSettled(i.map(e=>Di({draw:t,mapProvider:r,map:n,featureId:e.id,properties:e.properties,pixelRatioOverride:o})));a.filter(e=>"rejected"===e.status).forEach(e=>{console.error("[draw] failed to resolve point symbol",e.reason)});var s=a.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);s.length&&t.add({type:"FeatureCollection",features:s})});return function(t){return e.apply(this,arguments)}}();function Bi(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 Gi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Bi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Bi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Hi="mapbox-gl-draw-cold",Yi="mapbox-gl-draw-hot",Xi=e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:i}=e,a=t._drawCurrentMapStyle;t.once("idle",()=>{var e,s=((e,t)=>{if(e.getSource(Hi))return!1;var r={type:"FeatureCollection",features:[]};return e.addSource(Hi,{data:r,type:"geojson"}),e.addSource(Yi,{data:r,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(t,r);!function(e,t){Po(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)})})}(t,a,o);var c=null===(e=t._drawEditContainer)||void 0===e?void 0:e.querySelector("[data-im-draw-touch-target]");qr(c,a,o),Ui({draw:r,mapProvider:n,map:t}).then(()=>{s&&r.set(r.getAll()),t.triggerRepaint(),i()})})},Ki=e=>{var t,{mapStyle:r,mapProvider:o,events:i,eventBus:a,snapLayers:s,pluginConfig:c={}}=e,{map:l}=o;Wt.constants.classes.CONTROL_BASE="maplibregl-ctrl",Wt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",Wt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var u=Gi(Gi({},Wt.modes),{},{disabled:Qt,edit_vertex:gn,edit_point:Ln,draw_polygon:Qn,draw_line:eo,draw_point:co}),d=o._mapboxDrawInstance;d?Object.assign(d.modes,u):(d=new Wt({modes:u,styles:Po(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=F(e=>l.fire("draw.undochange",{length:e})),o.undoStack=h),l._undoStack=h;var f=L(r,c);Mi(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=()=>a.emit(i.MAP_DATA_CHANGE),{handleSetMapStyle:y,handleStyleChanged:m}=(e=>{var{map:t,draw:r,mapProvider:n,pluginConfig:o,eventBus:i,events:a,notifyPointSymbolsRefreshed:s}=e,c=e=>{t._drawCurrentMapStyle=e};i.on(a.MAP_SET_STYLE,c);var l=!1,u=()=>{l||(l=!0,Xi({map:t,draw:r,mapProvider:n,pluginConfig:o,onDone:()=>{l=!1,s()}}))};return i.on(a.MAP_STYLE_CHANGE,u),{handleSetMapStyle:c,handleStyleChanged:u}})({map:l,draw:d,mapProvider:o,pluginConfig:c,eventBus:a,events:i,notifyPointSymbolsRefreshed:g}),v=e=>{l.fire("draw.scalechange",{scale:M[e]})};a.on(i.MAP_SET_SIZE,v);var _=e=>{Ui({draw:d,mapProvider:o,map:l,pixelRatioOverride:e}).then(()=>{l.triggerRepaint(),g()})};return a.on(i.MAP_SET_PIXEL_RATIO,_),{draw:d,remove(){p.remove(),a.off(i.MAP_SET_STYLE,y),a.off(i.MAP_STYLE_CHANGE,m),a.off(i.MAP_SET_SIZE,v),a.off(i.MAP_SET_PIXEL_RATIO,_),d.changeMode("disabled"),o.draw=null}}};function Ji(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 $i(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ji(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ji(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var qi=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),Zi=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),zi=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),Wi=(e,t)=>{var r,n,o;if("draw_polygon"===e)return{feature:qi(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1};if("draw_line"===e)return{feature:Zi(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1};if("edit_vertex"===e){var i,a=t[0];return Array.isArray(null==a?void 0:a[0])?{feature:qi(t),numVertices:a.length}:{feature:Zi(t),numVertices:null!==(i=null==t?void 0:t.length)&&void 0!==i?i:0}}return"edit_point"===e?{feature:zi(t),numVertices:1}:null};class Qi{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,this._sortKeyCounter=0;var{draw:o,remove:i}=Ki({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=V({onChange:(e,t)=>{this._applyStrokeInvalid(e);var r=this._draw.getMode();"edit_vertex"!==r&&"edit_point"!==r||this._bus.emit(T.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=N({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=>{var t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(T.CREATE,this._draw.get(t.id))},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,e),vertexchange:e=>this._bus.emit(T.VERTEX_CHANGE,e),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(er,this._mapHandlers.create),this._map.on(nr,this._mapHandlers.editfinish),this._map.on(or,this._mapHandlers.cancel),this._map.on(ir,this._mapHandlers.vertexselection),this._map.on(ar,this._mapHandlers.vertexchange),this._map.on(sr,this._mapHandlers.undochange),this._map.on(tr,this._mapHandlers.update),this._map.on(lr,this._mapHandlers.geometrychange),this._map.on(dr,this._mapHandlers.placementblocked),this._map.on(ur,this._mapHandlers.interfacetypechange),this._map.on(rr,this._mapHandlers.modechange),this._map.on(gr,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"!==e&&"edit_point"!==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()),"draw_point"===e&&(r=$i($i({},r),{},{resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)})),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){return Ri({draw:this._draw,mapProvider:this._mapProvider,map:this._map,featureId:e,properties:t})}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=Wi(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($i($i({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(ur,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if(("edit_vertex"===t||"edit_point"===t)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(nr,{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(cr)}nudgeSelectedVertex(e,t,r){this._map.fire(pr,{dx:e,dy:t,isLargeStep:r})}getVertexItems(){var e={vertices:[],midpoints:[]};if("edit_vertex"!==this._draw.getMode()||!this._editingFeatureId)return e;var t=this._draw.get(this._editingFeatureId);if(!t)return e;var r=(e=>"Polygon"===e.type?$i($i({},e),{},{coordinates:e.coordinates.map(e=>e.slice(0,-1))}):"MultiPolygon"===e.type?$i($i({},e),{},{coordinates:e.coordinates.map(e=>e.map(e=>e.slice(0,-1)))}):e)(t.geometry);return{vertices:yr(r),midpoints:mr(r)}}selectVertex(e){this._map.fire(hr,{index:e})}insertVertexAtMidpoint(e){this._map.fire(fr,{index:e})}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)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){var t,r,n=null==(null===(t=e.properties)||void 0===t?void 0:t.sortKey)?$i($i({},e.properties),{},{sortKey:this._nextSortKey()}):e.properties,o=$i($i({},e),{},{properties:n}),i=this._draw.add(o);return"Point"===(null===(r=o.geometry)||void 0===r?void 0:r.type)&&Vi(n)&&this._resolvePointSymbol(i[0],n),i}setStyle(e,t){var r=this._draw.get(e);r&&this.add($i($i({},r),{},{properties:$i($i({},r.properties),t)}))}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=wr(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(Ar(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=wr(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","draw_point","edit_vertex","edit_point"]).has(e.mode)||kr(wr(this._map),this._map)}_handleStyleData(){var e,t=this._map.getStyle();if(t){this._liveStroke.refresh();var r=t.layers||[];!r.length||null!==(e=r[r.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||r.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(er,this._mapHandlers.create),this._map.off(nr,this._mapHandlers.editfinish),this._map.off(or,this._mapHandlers.cancel),this._map.off(ir,this._mapHandlers.vertexselection),this._map.off(ar,this._mapHandlers.vertexchange),this._map.off(sr,this._mapHandlers.undochange),this._map.off(tr,this._mapHandlers.update),this._map.off(lr,this._mapHandlers.geometrychange),this._map.off(dr,this._mapHandlers.placementblocked),this._map.off(ur,this._mapHandlers.interfacetypechange),this._map.off(rr,this._mapHandlers.modechange),this._map.off(gr,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{Qi as MaplibreDrawAdapter,Wi as displayedShape};
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import{i as t,c as r,T as n,K as o,M as i,v as a,a as s,b as c,d as l,S as u,e as d,r as p,l as h,p as f,f as g,g as y,m,h as v,j as _,k as b,n as x,o as P,q as E,C as O,s as S,t as I,u as w,A as M}from"./im-draw-plugin.js";import{c as T,r as C,a as L,s as k,b as A,d as j,e as F,f as V}from"./liveDrawChecks.js";import N from"@babel/runtime/helpers/asyncToGenerator";import"preact/compat";import"@babel/runtime/helpers/objectWithoutProperties";import"preact/jsx-runtime";const D={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"},R={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},U={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},B={POLYGON:"polygon",LINE:"line_string",POINT:"point"},G={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"},H={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},Y={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"},X={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},K={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},J={ACTIVE:"true",INACTIVE:"false"},$=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"];var q=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:J,classes:D,cursors:U,events:Y,geojsonTypes:G,interactions:$,meta:K,modes:H,sources:R,types:B,updateActions:X});function Z(e){return function(t){const r=t.featureTarget;return!!r&&(!!r.properties&&r.properties.meta===e)}}function z(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)}function W(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.ACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function Q(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===J.INACTIVE&&e.featureTarget.properties.meta===K.FEATURE))}function ee(e){return void 0===e.featureTarget}function te(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===K.FEATURE)}function re(e){const t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===K.VERTEX)}function ne(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function oe(e){return"Escape"===e.key||27===e.keyCode}function ie(e){return"Enter"===e.key||13===e.keyCode}function ae(e){return"Backspace"===e.key||8===e.keyCode}function se(e){return"Delete"===e.key||46===e.keyCode}function ce(e){return"1"===e.key||49===e.keyCode}function le(e){return"2"===e.key||50===e.keyCode}function ue(e){return"3"===e.key||51===e.keyCode}function de(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var pe=Object.freeze({__proto__:null,isActiveFeature:W,isBackspaceKey:ae,isDeleteKey:se,isDigit1Key:ce,isDigit2Key:le,isDigit3Key:ue,isDigitKey:de,isEnterKey:ie,isEscapeKey:oe,isFeature:te,isInactiveFeature:Q,isOfMetaType:Z,isShiftDown:ne,isShiftMousedown:z,isTrue:function(){return!0},isVertex:re,noTarget:ee});function he(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function fe(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 ge,ye,me={},ve={};function _e(){return ge||(ge=1,ve.RADIUS=6378137,ve.FLATTENING=1/298.257223563,ve.POLAR_RADIUS=6356752.3142),ve}var be=function(){if(ye)return me;ye=1;var e=_e();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 me.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}},me.ring=r,me}(),xe=he(be);const Pe={Point:0,LineString:1,MultiLineString:1,Polygon:2};function Ee(e,t){const r=Pe[e.geometry.type]-Pe[t.geometry.type];return 0===r&&e.geometry.type===G.POLYGON?e.area-t.area:r}function Oe(e){return e.map(e=>(e.geometry.type===G.POLYGON&&(e.area=xe.geometry({type:G.FEATURE,property:{},geometry:e.geometry})),e)).sort(Ee).map(e=>(delete e.area,e))}function Se(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function Ie(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)}Ie.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},Ie.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},Ie.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},Ie.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)},Ie.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const we=[K.FEATURE,K.MIDPOINT,K.VERTEX];var Me={click:function(e,t,r){return Te(e,t,r,r.options.clickBuffer)},touch:function(e,t,r){return Te(e,t,r,r.options.touchBuffer)}};function Te(e,t,r,n){if(null===r.map)return[];const o=e?Se(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!==we.indexOf(e.properties.meta)),s=new Ie,c=[];return a.forEach(e=>{const t=e.properties.id;s.has(t)||(s.add(t),c.push(e))}),Oe(c)}function Ce(e,t){const r=Me.click(e,null,t),n={mouse:U.NONE};return r[0]&&(n.mouse=r[0].properties.active===J.ACTIVE?U.MOVE:U.POINTER,n.feature=r[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(n.mouse=U.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function Le(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function ke(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=Le(e.point,t.point);return a<n||a<o&&t.time-e.time<i}function Ae(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 Le(e.point,t.point)<n&&t.time-e.time<o}const je=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 Fe=((e,t=21)=>(r=t)=>{let n="",o=0|r;for(;o--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function Ve(){return Fe()}const Ne=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||Ve(),this.type=t.geometry.type};Ne.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},Ne.prototype.incomingCoords=function(e){this.setCoordinates(e)},Ne.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ne.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},Ne.prototype.setProperty=function(e,t){this.properties[e]=t},Ne.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:G.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},Ne.prototype.internal=function(e){const t={id:this.id,meta:K.FEATURE,"meta:type":this.type,active:J.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:G.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const De=function(e,t){Ne.call(this,e,t)};(De.prototype=Object.create(Ne.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},De.prototype.updateCoordinate=function(e,t,r){this.coordinates=3===arguments.length?[t,r]:[e,t],this.changed()},De.prototype.getCoordinate=function(){return this.getCoordinates()};const Re=function(e,t){Ne.call(this,e,t)};(Re.prototype=Object.create(Ne.prototype)).isValid=function(){return this.coordinates.length>1},Re.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},Re.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},Re.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},Re.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Ue=function(e,t){Ne.call(this,e,t),this.coordinates=this.coordinates.map(e=>e.slice(0,-1))};(Ue.prototype=Object.create(Ne.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(e=>e.length>2)},Ue.prototype.incomingCoords=function(e){this.coordinates=e.map(e=>e.slice(0,-1)),this.changed()},Ue.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Ue.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])},Ue.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))},Ue.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]]))},Ue.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Ue.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 Be={MultiPoint:De,MultiLineString:Re,MultiPolygon:Ue},Ge=(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)},He=function(e,t){if(Ne.call(this,e,t),delete this.coordinates,this.model=Be[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 Ye(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(He.prototype=Object.create(Ne.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(e=>new t(this.ctx,{id:Ve(),type:G.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}}))},He.prototype.isValid=function(){return this.features.every(e=>e.isValid())},He.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},He.prototype.getCoordinate=function(e){return Ge(this.features,"getCoordinate",e)},He.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===G.POLYGON?e.getCoordinates():e.coordinates)))},He.prototype.updateCoordinate=function(e,t,r){Ge(this.features,"updateCoordinate",e,t,r),this.changed()},He.prototype.addCoordinate=function(e,t,r){Ge(this.features,"addCoordinate",e,t,r),this.changed()},He.prototype.removeCoordinate=function(e){Ge(this.features,"removeCoordinate",e),this.changed()},He.prototype.getFeatures=function(){return this.features},Ye.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},Ye.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),{})},Ye.prototype.getSelected=function(){return this._ctx.store.getSelected()},Ye.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},Ye.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},Ye.prototype.getFeature=function(e){return this._ctx.store.get(e)},Ye.prototype.select=function(e){return this._ctx.store.select(e)},Ye.prototype.deselect=function(e){return this._ctx.store.deselect(e)},Ye.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},Ye.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},Ye.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},Ye.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},Ye.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},Ye.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},Ye.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},Ye.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},Ye.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},Ye.prototype.featuresAt=function(e,t,r="click"){if("click"!==r&&"touch"!==r)throw new Error("invalid buffer type");return Me[r](e,t,this._ctx)},Ye.prototype.newFeature=function(e){const t=e.geometry.type;return t===G.POINT?new De(this._ctx,e):t===G.LINE_STRING?new Re(this._ctx,e):t===G.POLYGON?new Ue(this._ctx,e):new He(this._ctx,e)},Ye.prototype.isInstanceOf=function(e,t){if(e===G.POINT)return t instanceof De;if(e===G.LINE_STRING)return t instanceof Re;if(e===G.POLYGON)return t instanceof Ue;if("MultiFeature"===e)return t instanceof He;throw new Error(`Unknown feature class: ${e}`)},Ye.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},Ye.prototype.onSetup=function(){},Ye.prototype.onDrag=function(){},Ye.prototype.onClick=function(){},Ye.prototype.onMouseMove=function(){},Ye.prototype.onMouseDown=function(){},Ye.prototype.onMouseUp=function(){},Ye.prototype.onMouseOut=function(){},Ye.prototype.onKeyUp=function(){},Ye.prototype.onKeyDown=function(){},Ye.prototype.onTouchStart=function(){},Ye.prototype.onTouchMove=function(){},Ye.prototype.onTouchEnd=function(){},Ye.prototype.onTap=function(){},Ye.prototype.onStop=function(){},Ye.prototype.onTrash=function(){},Ye.prototype.onCombineFeature=function(){},Ye.prototype.onUncombineFeature=function(){},Ye.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const Xe={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},Ke=Object.keys(Xe);function Je(e){const t=Object.keys(e);return function(r,n={}){let o={};const i=t.reduce((t,r)=>(t[r]=e[r],t),new Ye(r));return{start(){o=i.onSetup(n),Ke.forEach(t=>{const r=Xe[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 $e(e){return[].concat(e).filter(e=>void 0!==e)}function qe(){const e=this;if(!(e.ctx.map&&void 0!==e.ctx.map.getSource(R.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(R.COLD).setData({type:G.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(R.HOT).setData({type:G.FEATURE_COLLECTION,features:e.sources.hot}),s()}function Ze(e){let t;this._features={},this._featureIds=new Ie,this._selectedFeatureIds=new Ie,this._selectedCoordinates=[],this._changedFeatureIds=new Ie,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,qe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(Y.SELECTION_CHANGE,{features:this.getSelected().map(e=>e.toGeoJSON()),points:this.getSelectedCoordinates().map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:e.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(Y.RENDER,{})}))},this.isDirty=!1}function ze(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}Ze.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Ze.prototype.setDirty=function(){return this.isDirty=!0,this},Ze.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(Y.CREATE,{features:[t.toGeoJSON()]})}return this},Ze.prototype.featureChanged=function(e,t={}){this._changedFeatureIds.add(e);return!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(Y.UPDATE,{action:t.action?t.action:X.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Ze.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Ze.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Ze.prototype.getAllIds=function(){return this._featureIds.values()},Ze.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Ze.prototype.delete=function(e,t={}){const r=[];return $e(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(Y.DELETE,{features:r}),ze(this,t),this},Ze.prototype.get=function(e){return this._features[e]},Ze.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Ze.prototype.select=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),this},Ze.prototype.deselect=function(e,t={}){return $e(e).forEach(e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))}),ze(this,t),this},Ze.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Ze.prototype.setSelected=function(e,t={}){return e=$e(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},Ze.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Ze.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Ze.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Ze.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Ze.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)}))},Ze.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Ze.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:X.CHANGE_PROPERTIES})},Ze.prototype.storeMapConfig=function(){$.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Ze.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Ze.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const We=["mode","feature","mouse"];function Qe(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]=Je(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:U.DRAG}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(e){o.drag(e,e=>!ke(r,e))},o.touchdrag=function(e){o.drag(e,e=>!Ae(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=Ce(t,e);t.featureTarget=r,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};const n=Ce(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){const n=Ce(t,e);t.featureTarget=n,ke(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=Me.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=Me.touch(t,null,e)[0];t.featureTarget=r,Ae(n,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)};const s=e=>{const t=ae(e),r=se(e),n=de(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=je(c,e),o.silent||e.map.fire(Y.MODE_CHANGE,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){(t.srcElement||t.target).classList.contains(D.CANVAS)&&((ae(t)||se(t))&&e.options.controls.trash?(t.preventDefault(),a.trash()):s(t)?a.keydown(t):ce(t)&&e.options.controls.point?c(H.DRAW_POINT):le(t)&&e.options.controls.line_string?c(H.DRAW_LINE_STRING):ue(t)&&e.options.controls.polygon&&c(H.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=je(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(Y.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=[];We.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=`${D.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(D.ACTIVE_BUTTON),r=null)}function l(e){c();const n=t[e];n&&n&&"trash"!==e&&(n.classList.add(D.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=`${D.CONTROL_GROUP} ${D.CONTROL_BASE}`,r?(r[B.POINT]&&(t[B.POINT]=s(B.POINT,{container:n,className:D.CONTROL_BUTTON_POINT,title:"Marker tool "+(e.options.keybindings?"(1)":""),onActivate:()=>e.events.changeMode(H.DRAW_POINT),onDeactivate:()=>e.events.trash()})),r[B.LINE]&&(t[B.LINE]=s(B.LINE,{container:n,className:D.CONTROL_BUTTON_LINE,title:"LineString tool "+(e.options.keybindings?"(2)":""),onActivate:()=>e.events.changeMode(H.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),r[B.POLYGON]&&(t[B.POLYGON]=s(B.POLYGON,{container:n,className:D.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(e.options.keybindings?"(3)":""),onActivate:()=>e.events.changeMode(H.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),r.trash&&(t.trash=s("trash",{container:n,className:D.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),r.combine_features&&(t.combine_features=s("combineFeatures",{container:n,className:D.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),r.uncombine_features&&(t.uncombine_features=s("uncombineFeatures",{container:n,className:D.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 Ze(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(R.COLD,{data:{type:G.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(R.HOT,{data:{type:G.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(R.COLD)&&e.map.removeSource(R.COLD),e.map.getSource(R.HOT)&&e.map.removeSource(R.HOT)}};return e.setup=n,n}const et="#3bb2d0",tt="#fbb03b",rt="#fff";var nt=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],tt,et],"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"],tt,et],"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":rt}},{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"],tt,et]}},{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":rt}},{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":tt}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":tt}}];function ot(e,t){this.x=e,this.y=t}function it(e,t){const r=t.getBoundingClientRect();return new ot(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function at(e,t,r,n){return{type:G.FEATURE,properties:{meta:K.VERTEX,parent:e,coord_path:r,active:n?J.ACTIVE:J.INACTIVE},geometry:{type:G.POINT,coordinates:t}}}function st(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return ct(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=>ct(e)),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return ut(e);default:throw new Error("unknown GeoJSON type")}}function ct(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=lt(e.properties),null==e.geometry?t.geometry=null:t.geometry=ut(e.geometry),t}function lt(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]=lt(n):t[r]=n}),t):t}function ut(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map(e=>ut(e)),t):(t.coordinates=dt(e.coordinates),t)}function dt(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map(e=>dt(e))}function pt(e,t={}){return ht(e,"mercator",t)}function ht(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?ft(e):gt(e):(!0!==i&&(e=st(e)),r(e,function(e){var t="mercator"===n?ft(e):gt(e);e[0]=t[0],e[1]=t[1]})),e}function ft(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 gt(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 yt(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=pt(n),a=pt(o),s=e=>Number(e.toFixed(8)),c=(e,t)=>(e+t)/2,l=function(e,t={}){return ht(e,"wgs84",t)}([c(i[0],a[0]),c(i[1],a[1])]),u=[s(l[0]),s(l[1])];return{type:G.FEATURE,properties:{meta:K.MIDPOINT,parent:e,lng:u[0],lat:u[1],coord_path:r.properties.coord_path},geometry:{type:G.POINT,coordinates:u}}}function mt(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=at(i,e,l,c(l));if(t.midpoints&&o){const e=yt(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===G.POINT?a.push(at(i,o,r,c(r))):n===G.POLYGON?o.forEach((e,t)=>{s(e,null!==r?`${r}.${t}`:String(t))}):n===G.LINE_STRING?s(o,r):0===n.indexOf(G.MULTI_PREFIX)&&function(){const r=n.replace(G.MULTI_PREFIX,"");o.forEach((n,o)=>{const i={type:G.FEATURE,properties:e.properties,geometry:{type:r,coordinates:n}};a=a.concat(mt(i,t,o))})}(),a}ot.prototype={clone(){return new ot(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:ot},ot.convert=function(e){if(e instanceof ot)return e;if(Array.isArray(e))return new ot(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new ot(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var vt={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:_t,LAT_MAX:bt,LAT_RENDERED_MIN:xt,LAT_RENDERED_MAX:Pt,LNG_MIN:Et,LNG_MAX:Ot}=q;function St(e,t){let r=_t,n=bt,o=_t,i=bt,a=Ot,s=Et;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>Pt&&(c.lat=Pt-r),o+c.lat>bt&&(c.lat=bt-o),n+c.lat<xt&&(c.lat=xt-n),i+c.lat<_t&&(c.lat=_t-i),a+c.lng<=Et&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),s+c.lng>=Ot&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function It(e,t){const r=St(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===G.POINT?a=n(t):e.type===G.LINE_STRING||e.type===G.MULTI_POINT?a=t.map(n):e.type===G.POLYGON||e.type===G.MULTI_LINE_STRING?a=t.map(o):e.type===G.MULTI_POLYGON&&(a=t.map(i)),e.incomingCoords(a)})}const wt={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(Y.UPDATE,{action:X.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 Ie).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(){vt.enable(this)},onMouseMove:function(e,t){return te(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};wt.onTap=wt.onClick=function(e,t){return ee(t)?this.clickAnywhere(e,t):Z(K.VERTEX)(t)?this.clickOnVertex(e,t):te(t)?this.clickOnFeature(e,t):void 0},wt.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(e=>this.doRender(e))),vt.enable(this),this.stopExtendedInteractions(e)},wt.clickOnVertex=function(e,t){this.changeMode(H.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:U.MOVE})},wt.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},wt.clickOnFeature=function(e,t){vt.disable(this),this.stopExtendedInteractions(e);const r=ne(t),n=this.getSelectedIds(),o=t.featureTarget.properties.id,i=this.isSelected(o);if(!r&&i&&this.getFeature(o).type!==G.POINT)return this.changeMode(H.DIRECT_SELECT,{featureId:o});i&&r?(this.deselect(o),this.updateUIClasses({mouse:U.POINTER}),1===n.length&&vt.enable(this)):!i&&r?(this.select(o),this.updateUIClasses({mouse:U.MOVE})):i||r||(n.forEach(e=>this.doRender(e)),this.setSelected(o),this.updateUIClasses({mouse:U.MOVE})),this.doRender(o)},wt.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),W(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&z(t)?this.startBoxSelect(e,t):void 0},wt.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=it(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},wt.onTouchStart=function(e,t){if(W(t))return this.startOnActiveFeature(e,t)},wt.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},wt.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:U.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(D.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=it(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"},wt.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};It(this.getSelected(),r),e.dragMoveLocation=t.lngLat},wt.onTouchEnd=wt.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,it(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:U.MOVE}))}this.stopExtendedInteractions(e)},wt.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?J.ACTIVE:J.INACTIVE,r(t),this.fireActionable(),t.properties.active===J.ACTIVE&&t.geometry.type!==G.POINT&&mt(t).forEach(r)},wt.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},wt.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:G.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(Y.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},wt.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(Y.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const Mt=Z(K.VERTEX),Tt=Z(K.MIDPOINT),Ct={fireUpdate:function(){this.fire(Y.UPDATE,{action:X.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);ne(t)||-1!==n?ne(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){It(this.getSelected(),r),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,r){const n=e.selectedCoordPaths.map(t=>e.feature.getCoordinate(t)),o=St(n.map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.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(H.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(H.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===G.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),vt.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){vt.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,r){e.featureId===t.properties.id?(t.properties.active=J.ACTIVE,r(t),mt(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=J.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(H.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const r=W(t),n=Mt(t),o=Tt(t),i=0===e.selectedCoordPaths.length;r&&i||n&&!i?this.updateUIClasses({mouse:U.MOVE}):this.updateUIClasses({mouse:U.NONE});return(n||r||o)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Ct.onTouchStart=Ct.onMouseDown=function(e,t){return Mt(t)?this.onVertex(e,t):W(t)?this.onFeature(e,t):Tt(t)?this.onMidpoint(e,t):void 0},Ct.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},Ct.onClick=function(e,t){return ee(t)?this.clickNoTarget(e,t):W(t)?this.clickActiveFeature(e,t):Q(t)?this.clickInactive(e,t):void this.stopDragging(e)},Ct.onTap=function(e,t){return ee(t)?this.clickNoTarget(e,t):W(t)?this.clickActiveFeature(e,t):Q(t)?this.clickInactive(e,t):void 0},Ct.onTouchEnd=Ct.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const Lt={};function kt(e,t){return!!e.lngLat&&(e.lngLat.lng===t[0]&&e.lngLat.lat===t[1])}Lt.onSetup=function(){const e=this.newFeature({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:U.ADD}),this.activateUIButton(B.POINT),this.setActionableState({trash:!0}),{point:e}},Lt.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)},Lt.onTap=Lt.onClick=function(e,t){this.updateUIClasses({mouse:U.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(Y.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.point.id]})},Lt.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},Lt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?J.ACTIVE:J.INACTIVE,!n)return r(t)},Lt.onTrash=Lt.stopDrawingAndRemove,Lt.onKeyUp=function(e,t){if(oe(t)||ie(t))return this.stopDrawingAndRemove(e,t)};const At={onSetup:function(){const e=this.newFeature({type:G.FEATURE,properties:{},geometry:{type:G.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),vt.disable(this),this.updateUIClasses({mouse:U.ADD}),this.activateUIButton(B.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&kt(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:U.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(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:U.POINTER})}};At.onTap=At.onClick=function(e,t){return re(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},At.onKeyUp=function(e,t){oe(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)):ie(t)&&this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},At.onStop=function(e){this.updateUIClasses({mouse:U.NONE}),vt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(Y.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT,{},{silent:!0})))},At.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?J.ACTIVE:J.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=K.FEATURE,r(at(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),o>3){const n=t.geometry.coordinates[0].length-3;r(at(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:G.FEATURE,properties:t.properties,geometry:{coordinates:e,type:G.LINE_STRING}}),3===o)return}return r(t)}},At.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)};const jt={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:G.FEATURE,properties:{},geometry:{type:G.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),vt.disable(this),this.updateUIClasses({mouse:U.ADD}),this.activateUIButton(B.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:o}},clickAnywhere:function(e,t){if(e.currentVertexPosition>0&&kt(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&kt(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:U.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(H.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),re(t)&&this.updateUIClasses({mouse:U.POINTER})}};jt.onTap=jt.onClick=function(e,t){if(re(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},jt.onKeyUp=function(e,t){ie(t)?this.changeMode(H.SIMPLE_SELECT,{featureIds:[e.line.id]}):oe(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT))},jt.onStop=function(e){vt.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(Y.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT,{},{silent:!0})))},jt.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(H.SIMPLE_SELECT)},jt.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?J.ACTIVE:J.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=K.FEATURE,r(at(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 Ft={simple_select:wt,direct_select:Ct,draw_point:Lt,draw_polygon:At,draw_line_string:jt};const Vt={defaultMode:H.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:nt,modes:Ft,controls:{},userProperties:!1,suppressAPIEvents:!0},Nt={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},Dt={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function Rt(e,t){return e.map(e=>e.source?e:Object.assign({},e,{id:`${e.id}.${t}`,source:"hot"===t?R.HOT:R.COLD}))}var Ut,Bt;var Gt,Ht,Yt=he(Bt?Ut:(Bt=1,Ut=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 Xt=function(){if(Ht)return Gt;Ht=1,Gt=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 Gt}(),Kt=he(Xt);function Jt(e,t){return e.length===t.length&&JSON.stringify(e.map(e=>e).sort())===JSON.stringify(t.map(e=>e).sort())}const $t={Polygon:Ue,LineString:Re,Point:De,MultiPolygon:He,MultiLineString:He,MultiPoint:He};var qt=Object.freeze({__proto__:null,CommonSelectors:pe,ModeHandler:je,StringSet:Ie,constrainFeatureMovement:St,createMidPoint:yt,createSupplementaryPoints:mt,createVertex:at,doubleClickZoom:vt,euclideanDistance:Le,featuresAt:Me,getFeatureAtAndSetCursors:Ce,isClick:ke,isEventAtCoordinates:kt,isTap:Ae,mapEventToBoundingBox:Se,moveFeatures:It,sortFeatures:Oe,stringSetsAreEqual:Jt,theme:nt,toDenseArray:$e});const Zt=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({},Dt,e.controls):t.controls=Object.assign({},Nt,e.controls),t=Object.assign({},Vt,t),t.styles=Rt(t.styles,"cold").concat(Rt(t.styles,"hot")),t}(e)};t=function(e,t){t.modes=H;const r=void 0===e.options.suppressAPIEvents||!!e.options.suppressAPIEvents;return t.getFeatureIdsAt=function(t){return Me.click({point:t},null,e).map(e=>e.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:G.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(t=>e.store.get(t)).map(e=>e.toGeoJSON())}},t.getSelectedPoints=function(){return{type:G.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(e=>({type:G.FEATURE,properties:{},geometry:{type:G.POINT,coordinates:e.coordinates}}))}},t.set=function(r){if(void 0===r.type||r.type!==G.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 Ie(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(Kt(t))).features.map(t=>{if(t.id=t.id||Ve(),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=$t[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,Yt(o,t.properties)||e.store.featureChanged(n.id,{silent:r}),Yt(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:G.FEATURE_COLLECTION,features:e.store.getAll().map(e=>e.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()!==H.DIRECT_SELECT||e.store.getSelectedIds().length?e.store.render():e.events.changeMode(H.SIMPLE_SELECT,void 0,{silent:r}),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===H.DIRECT_SELECT?e.events.changeMode(H.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,o={}){return n===H.SIMPLE_SELECT&&t.getMode()===H.SIMPLE_SELECT?(Jt(o.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(o.featureIds,{silent:r}),e.store.render()),t):(n===H.DIRECT_SELECT&&t.getMode()===H.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=Qe(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=B,t.options=e,t};function zt(e){Zt(e,this)}zt.modes=Ft,zt.constants=q,zt.lib=qt;var Wt={onSetup:()=>({}),onClick:()=>!1,onKeyUp:()=>!1,onDrag:()=>!1,toDisplayFeatures(e,t,r){t.properties.active="false",r(t)}},Qt="draw.create",er="draw.update",tr="draw.modechange",rr="draw.editfinish",nr="draw.cancel",or="draw.vertexselection",ir="draw.vertexchange",ar="draw.undochange",sr="draw.undo",cr="draw.geometrychange",lr="draw.interfacetypechange",ur="draw.placementblocked",dr="draw.nudgevertex",pr="draw.selectvertex",hr="draw.insertvertexatmidpoint",fr="styledata",gr=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[]}},yr=e=>{var t=gr(e),r=mr(e);if(!t.length||!r.length)return[];var n=[];for(var o of r)for(var i=o.closed?o.length:o.length-1,a=0;a<i;a++){var s=o.start+a,c=o.start+(a+1)%o.length,[l,u]=t[s],[d,p]=t[c];n.push([(l+d)/2,(u+p)/2])}return n},mr=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},vr=(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},_r=(e,t)=>{var r=e.geometry.coordinates;for(var n of t)r=r[n];return r},br=(e,t)=>{var r=t.split(".").map(Number),n=mr(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]},xr=(e,t)=>({x:e.x*t,y:e.y*t}),Pr=e=>e instanceof window.SVGElement||e.ownerSVGElement;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}function Or(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}function Sr(e){var t;return null!==(t=null==e?void 0:e._snapInstance)&&void 0!==t?t:null}function Ir(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 wr(e){return Ir(e)?{lng:e.snapCoords[0],lat:e.snapCoords[1]}:null}function Mr(e,t,r){if(!e||!t||!e.status)return!1;var n=t.unproject(r);return e.snapToClosestPoint({point:r,lngLat:n,_explicit:!0}),!0}function Tr(e,t){e&&(e._autoSnapSuspended=t)}function Cr(e,t){if(!e||!t||!e.status)return!1;var r=t.getCenter(),n=t.project(r);return e.snapToClosestPoint({point:n,lngLat:r,_explicit:!0}),!0}function Lr(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 kr(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 Ar(e){return"function"==typeof(null==e?void 0:e.getSnapEnabled)&&!0===e.getSnapEnabled()}var jr=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r=>n=>r.call(e,t,n),o={keydown:n(e.onKeydown),keyup:n(e.onKeyup),pointerdown:n(e.onPointerevent),pointermove:n(e.onPointerevent),pointerup:n(e.onPointerevent),click:n(e.onButtonClick),touchstart:n(e.onTouchstart),touchmove:n(e.onTouchmove),touchend:n(e.onTouchend),scalechange:n(e.onScaleChange),move:n(e.onMove),interfacetypechange:n(e.onInterfaceTypeChange)};for(var[i,a]of Object.entries(r))o[i]=n(a);return o},Fr=(e,t,r)=>{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}),t.on("draw.scalechange",r.scalechange),t.on("move",r.move),t.on(lr,r.interfacetypechange),t.on(dr,r.nudge)},Vr=(e,t,r)=>{e.container.removeEventListener("pointerdown",r.pointerdown),e.container.removeEventListener("pointermove",r.pointermove),e.container.removeEventListener("pointerup",r.pointerup),e.container.removeEventListener("touchstart",r.touchstart),e.container.removeEventListener("touchmove",r.touchmove),e.container.removeEventListener("touchend",r.touchend),t.off("draw.scalechange",r.scalechange),t.off("move",r.move),t.off(lr,r.interfacetypechange),t.off(dr,r.nudge),t.dragPan.enable(),window.removeEventListener("click",r.click),window.removeEventListener("keydown",r.keydown,{capture:!0}),window.removeEventListener("keyup",r.keyup,{capture:!0})},Nr=e=>{var t=Sr(e);t&&Lr(t,e)},Dr={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(this.UNDO_OP_PHASE[e.type],e.vertexIndex,e.featureId))}};function Rr(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 Ur(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Rr(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rr(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Br={move_vertex:"commit-move",insert_vertex:"commit-delete",delete_vertex:"commit-insert"},Gr=Ur(Ur({},Dr),{},{UNDO_OP_PHASE:{move_vertex:"commit-move",insert_vertex:"commit-insert",delete_vertex:"commit-delete"},UNDO_INVERSE_PHASE:Br,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(Br[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=mr(i),c=vr(s,r);if(c){_r(a,c.segment.path)[c.localIdx]=n,this._applyUndoAndSync(e,a,o);var l=e.vertices[e.selectedVertexIndex];l&&this.updateTouchVertexTarget(e,xr(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=mr(o),s=vr(a,r);if(s)_r(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=mr(i),c=vr(s,r);if(!c)for(var l of s)if(r===l.start+l.length){c={segment:l,localIdx:l.length};break}if(c)_r(a,c.segment.path).splice(c.localIdx,0,n),this._applyUndoAndSync(e,a,o),this.updateTouchVertexTarget(e,xr(this.map.project(e.vertices[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.vertices=this.getVertices(r),e.midpoints=this.getMidpoints(r),this._ctx.store.render(),this.fireGeometryChange(e)}}),Hr=e=>({x:e.touches[0].clientX,y:e.touches[0].clientY}),Yr=(e,t,r,n,o)=>{var i=window.getComputedStyle(t),a={x:r.x-Number.parseFloat(i.left),y:r.y-Number.parseFloat(i.top)},s=e.project(n);return{deltaTarget:a,deltaVertex:{x:r.x/o-s.x,y:r.y/o-s.y}}},Xr=(e,t,r)=>{var n={x:r.x/t.scale-t.deltaVertex.x,y:r.y/t.scale-t.deltaVertex.y},o=e.unproject(n);if(Ar(t)){var i=Sr(e);Mr(i,e,n),o=wr(i)||o}return o};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 Jr(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 $r=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(e){var{editActive:n,editHalo:o,editVertex:i}=C(t,r);L(e,{editActive:n,editHalo:o,editVertex:i})}},qr={addTouchVertexTarget(e){e.touchVertexTarget=T(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||Pr(t.target.parentNode)||e._ignorePointermoveDeselect||this.changeMode(e,{selectedVertexIndex:-1,selectedVertexType:null,coordPath:null})},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){if(kr(Sr(this.map)),null!=e&&e.featureId){this.syncVertices(e),e._touchMoved&&e._moveStartPosition&&null!=e._moveStartIndex&&this.pushUndo({type:"move_vertex",featureId:e.featureId,vertexIndex:e._moveStartIndex,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._moveStartIndex=null,e._touchMoved=!1;var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xr(this.map.project(t),e.scale))}},onTap(e,t){var r,n,o=Sr(this.map);o&&Lr(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=br(s,a);this.changeMode(e,{selectedVertexIndex:c,selectedVertexType:"vertex",coordPath:a})}else"midpoint"===i?this.insertVertex(Jr(Jr({},e),{},{selectedVertexIndex:this.getVertexIndexFromMidpoint(e,a),selectedVertexType:"midpoint"})):this.clickNoTarget(e)},onTouchstart(e,t){kr(Sr(this.map));var r=this.getVertices(e.featureId),n=null==r?void 0:r[e.selectedVertexIndex];if(n&&Pr(t.target.parentNode)){e._moveStartPosition=[...n],e._moveStartIndex=e.selectedVertexIndex,e._touchMoved=!1;var o=Hr(t);Object.assign(e,Yr(this.map,e.touchVertexTarget,o,n,e.scale))}},onTouchmove(e,t){if(!(e.selectedVertexIndex<0)&&Pr(t.target.parentNode)){e._touchMoved=!0;var r=Hr(t);this.moveVertex(e,Xr(this.map,e,r)),this.updateTouchVertexTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}},Zr=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),zr={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Wr=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),Qr=e=>{var t,r=document.activeElement;return!(!r||r===document.body)&&((null===(t=e.container)||void 0===t||!t.contains(r))&&(Wr.has(r.tagName)||r.isContentEditable||r.hasAttribute("tabindex")))},en=e=>"z"===e.key&&(e.metaKey||e.ctrlKey)&&!e.shiftKey,tn={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))}},rn={getOffset(e,t){var r=this.map.project(e),n=null!=t&&t.shiftKey?o.nudgeAmount:o.stepAmount,[i,a]=t?zr[t.key].map(e=>e*n):[0,0];return this.map.unproject({x:r.x+i,y:r.y+a})},getOffsetByDelta(e,t,r,n){var i=this.map.project(e),a=n?o.stepAmount:o.nudgeAmount;return this.map.unproject({x:i.x+t*a,y:i.y+r*a})},resolveSnapTarget(e,t,r,o,i){var a=Sr(this.map);if(Ar(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,Lr(a,this.map),this.map.unproject({x:c.x+t*s,y:c.y+r*s})}var l=i();return Ar(e)&&a&&(Mr(a,this.map,this.map.project(l)),Ir(a))?(e._isSnapped=!0,wr(a)):(e._isSnapped=!1,l)}};function nn(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 on(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?nn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):nn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var an=on(on({},rn),{},{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(e,t){var[r,n]=this.getVertexOrMidpoint(e,t);r<0||!n||this.changeMode(e,on({selectedVertexIndex:r,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,r)}))},getNewCoord(e,t){return this.getOffset(gr(this.getFeature(e.featureId))[e.selectedVertexIndex],t)},nudgeVertexByDelta(e,t,r,n){var o;if(!("vertex"!==e.selectedVertexType||e.selectedVertexIndex<0)){var i=this.getFeature(e.featureId),a=i&&(null===(o=gr(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.vertices.length,n=this.getOffset(e.midpoints[r],t),o=this.getFeature(e.featureId),i=o.toGeoJSON(),a=mr(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&&(_r(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=mr(o),s=vr(a,e.selectedVertexIndex);s&&(_r(i,s.segment.path)[s.localIdx]=[t.lng,t.lat],this._ctx.api.add(i),e.vertices=this.getVertices(e.featureId),this.map.fire("draw.geometrychange",e.feature))},deleteVertex(e){var t=this.getFeature(e.featureId);if(t){var r=mr(t),n=vr(r,e.selectedVertexIndex);if(n){var{segment:o}=n,a=o.closed?i.Polygon:i.LineString;if(!(o.length<=a)){var s=[...e.vertices[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})}}}}}),sn={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=mr(r),o=vr(n,t);if(!o)return"0";var{segment:i,localIdx:a}=o;return[...i.path,a].join(".")},syncVertices(e){e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)},getVertices(e){return gr(this.getFeature(e))},getMidpoints(e){return yr(this.getFeature(e))},getVertexOrMidpoint(e,t){var r,n;if(null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null===(n=e.vertices)||void 0===n||!n.length)return[-1,null];var o=e=>e?Object.values(this.map.project(e)):null,i=[...e.vertices.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=k(a,i,t);return[s,s<e.vertices.length?"vertex":"midpoint"]},getVertexIndexFromMidpoint(e,t){var r=this.getFeature(e.featureId),n=mr(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.vertices.length+i+c}i+=a.closed?a.length:a.length-1}return e.vertices.length}};function cn(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 ln(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?cn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):cn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var un=ln(ln({},tn),{},{onKeydown(e,t){Qr(e)||(e.interfaceType="keyboard",this.hideTouchVertexIndicator(e)," "!==t.key?Zr.has(t.key)&&e.selectedVertexIndex>=0?this.handleArrowKey(e,t):"Escape"!==t.key?en(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=Sr(this.map);n&&Lr(n,this.map),null!==(t=e.vertices)&&void 0!==t&&t.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),null!==(r=e.vertices)&&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=gr(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]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Qr(e)||(e.interfaceType="keyboard",e.selectedVertexIndex>=0&&A(t),Zr.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))}}),dn={onMouseDown(e,t){var r,n;kr(Sr(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,Ct.onMouseDown.call(this,e,t),"vertex"===o&&i)){var a,s=this.getFeature(e.featureId),c=br(s,i);e.selectedVertexIndex=c,e.selectedVertexType="vertex",e.coordPath=i;var l=null===(a=e.vertices)||void 0===a?void 0:a[c];l&&(e._moveStartPosition=[...l],e._moveStartIndex=c)}if("midpoint"===o){var u=this.getFeature(e.featureId),d=br(u,i);e._insertedVertexIndex=d,e._isInsertingVertex=!0,e.selectedVertexIndex=this.getVertexIndexFromMidpoint(e,i),e.selectedVertexType="vertex",e.coordPath=null,this.map.fire(or,{index:e.selectedVertexIndex,numVertices:e.vertices.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(or,{index:r,numVertices:e.vertices.length})}Ct.onClick.call(this,e,t)},onMouseUp(e,t){kr(Sr(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,Ct.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=gr(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(or,{index:t,numVertices:e.vertices.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=Sr(this.map);if(n&&(n.snapStatus=!1,n.snapCoords=null),Ar(e)&&null!=n&&n.status){if(null!==(r=e.selectedCoordPaths)&&void 0!==r&&r.length&&e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation(),Mr(n,this.map,t.point);var o=wr(n)||t.lngLat;e.feature.updateCoordinate(e.selectedCoordPaths[0],o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Ct.onDrag.call(this,e,t)}}};function pn(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 hn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?pn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):pn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var fn=hn(hn(hn(hn(hn(hn(hn(hn({},zt.modes.direct_select),Gr),qr),an),sn),un),dn),{},{onSetup(e){var t,r,n,o=zt.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);if(o.featureType=null==i?void 0:i.type,o.vertices=this.getVertices(o.featureId),o.midpoints=this.getMidpoints(o.featureId),this.setupEventListeners(o),this.applyVertexSelection(o,e),this.map._drawEditContainer=e.container,this.addTouchVertexTarget(o),Nr(this.map),"touch"===o.interfaceType&&o.selectedVertexIndex>=0&&"vertex"===o.selectedVertexType){var a=o.vertices[o.selectedVertexIndex];a&&setTimeout(()=>{this.updateTouchVertexTarget(o,xr(this.map.project(a),o.scale))},0)}return o._ignorePointermoveDeselect=!0,setTimeout(()=>{o._ignorePointermoveDeselect=!1},100),o},setupEventListeners(e){var t=this.handlers=jr(this,e,{nudge:this.onNudgeVertex,selectionchange:this.onSelectionChange,update:this.onUpdate,selectvertex:this.onSelectVertex,insertvertexatmidpoint:this.onInsertVertexAtMidpoint});Fr(e,this.map,t),this.map.on("draw.selectionchange",t.selectionchange),this.map.on("draw.update",t.update),this.map.on(pr,t.selectvertex),this.map.on(hr,t.insertvertexatmidpoint)},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.vertices.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=gr(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(or,{index:"vertex"===e.selectedVertexType?e.selectedVertexIndex:-1,numVertices:e.vertices.length});var c=o||(e.selectedVertexIndex>=0?e.vertices[e.selectedVertexIndex]:null);this.updateTouchVertexTarget(e,c?xr(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.vertices[e.selectedVertexIndex]:null;this.updateTouchVertexTarget(e,r?xr(this.map.project(r),e.scale):null)},onUpdate(e){var t;new Set(e.vertices.map(e=>JSON.stringify(e))).size!==e.vertices.length&&(e.selectedVertexIndex=-1,null!==(t=e.selectedVertexType)&&void 0!==t||(e.selectedVertexType=null))},onMove(e){var t=e.vertices[e.selectedVertexIndex];t&&this.updateTouchVertexTarget(e,xr(this.map.project(t),e.scale))},onNudgeVertex(e,t){this.nudgeVertexByDelta(e,t.dx,t.dy,t.isLargeStep);var r=e.vertices[e.selectedVertexIndex];r&&this.updateTouchVertexTarget(e,xr(this.map.project(r),e.scale))},onSelectVertex(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId));var n=t.index<e.vertices.length?"vertex":"midpoint";this.changeMode(e,hn({selectedVertexIndex:t.index,selectedVertexType:n},"vertex"===n&&{coordPath:this.getCoordPath(e,t.index)}))},onInsertVertexAtMidpoint(e,t){var r;null!==(r=e.vertices)&&void 0!==r&&r.length||(e.vertices=this.getVertices(e.featureId),e.midpoints=this.getMidpoints(e.featureId)),this.insertVertex(hn(hn({},e),{},{selectedVertexIndex:t.index,selectedVertexType:"midpoint"}))},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",hn(hn({},e),t))},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null;var t=this.handlers;this.map.off("draw.selectionchange",t.selectionchange),this.map.off("draw.update",t.update),this.map.off(pr,t.selectvertex),this.map.off(hr,t.insertvertexatmidpoint),Vr(e,this.map,t),this.hideTouchVertexIndicator(e)}});function gn(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 yn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?gn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var mn={move_point:"commit-move"},vn=yn(yn({},Dr),{},{UNDO_OP_PHASE:{move_point:"commit-move"},UNDO_INVERSE_PHASE:mn,handleUndo(e){var t=this.map._undoStack;if(t&&0!==t.length){var r=t.pop();"move_point"===r.type&&this.undoMovePoint(e,r),this.emitGeometryValidation(mn[r.type],r.vertexIndex,r.featureId)}},undoMovePoint(e,t){var{previousPosition:r,featureId:n}=t,o=this.getFeature(n);o&&(o.updateCoordinate("",r[0],r[1]),this._ctx.store.render(),this.fireGeometryChange(e),this.updateTouchPointTarget(e,xr(this.map.project(r),e.scale)))}}),_n={addTouchPointTarget(e){e.touchPointTarget=T(e.container),$r(e.touchPointTarget,this.map._drawCurrentMapStyle,this.map._drawPluginConfig)},updateTouchPointTarget(e,t){t&&"touch"===e.interfaceType?Object.assign(e.touchPointTarget.style,{display:"block",top:"".concat(t.y,"px"),left:"".concat(t.x,"px")}):e.touchPointTarget.style.display="none"},hideTouchPointIndicator(e){e.touchPointTarget.style.display="none"},onPointerevent(e,t){e.interfaceType="touch"===t.pointerType?"touch":"mouse",e.isPanEnabled=!0},onTouchStart(){},onTouchMove(){},onTouchEnd(){},onTouchend(e){kr(Sr(this.map)),e._touchMoved&&e._moveStartPosition&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,e._touchMoved=!1,e.feature&&this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onTap(){},onTouchstart(e,t){kr(Sr(this.map));var r=this.getPointCoord(e);if(r&&Pr(t.target.parentNode)){e._moveStartPosition=[...r],e._touchMoved=!1;var n=Hr(t);Object.assign(e,Yr(this.map,e.touchPointTarget,n,r,e.scale))}},onTouchmove(e,t){if(Pr(t.target.parentNode)){e._touchMoved=!0;var r=Hr(t);this.movePoint(e,Xr(this.map,e,r)),this.updateTouchPointTarget(e,{x:r.x-e.deltaTarget.x,y:r.y-e.deltaTarget.y})}}};function bn(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 xn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?bn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):bn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Pn=xn(xn({},rn),{},{getPointCoord(e){var t;return null===(t=this.getFeature(e.featureId))||void 0===t?void 0:t.coordinates},getNewCoord(e,t){return this.getOffset(this.getPointCoord(e),t)},movePoint(e,t){e.feature.updateCoordinate("",t.lng,t.lat),this._ctx.store.render(),this.map.fire("draw.geometrychange",e.feature)},nudgePointByDelta(e,t,r,n){var o=this.getPointCoord(e);if(o){var i=[...o],a=this.resolveSnapTarget(e,t,r,o,()=>this.getOffsetByDelta(o,t,r,n));this.movePoint(e,a),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:i})}}});function En(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 On(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?En(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):En(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Sn=On(On({},tn),{},{onKeydown(e,t){Qr(e)||(e.interfaceType="keyboard",this.hideTouchPointIndicator(e)," "!==t.key?Zr.has(t.key)?this.handleArrowKey(e,t):en(t)&&this.handleUndoShortcut(e,t):t.preventDefault())},handleArrowKey(e,t){t.preventDefault(),t.stopPropagation(),this.movePointByKey(e,t)},movePointByKey(e,t){var r=this.getPointCoord(e);r&&(e._keyboardMoveStartPosition||(e._keyboardMoveStartPosition=[...r]),this.movePoint(e,this._keyboardMoveTarget(e,t,r)))},_keyboardMoveTarget(e,t,r){var[n,o]=zr[t.key];return this.resolveSnapTarget(e,n,o,r,()=>this.getNewCoord(e,t))},onKeyup(e,t){Qr(e)||(e.interfaceType="keyboard",A(t),Zr.has(t.key)&&(t.stopPropagation(),e._keyboardMoveStartPosition&&(this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._keyboardMoveStartPosition}),e._keyboardMoveStartPosition=null)))}}),In="edit_point",wn={onFeature(e,t){e.dragMoving||(e._moveStartPosition=[...e.feature.coordinates],e._grabOffset=[e.feature.coordinates[0]-t.lngLat.lng,e.feature.coordinates[1]-t.lngLat.lat],Tr(Sr(this.map),!0)),Ct.onFeature.call(this,e,t)},onClick(e,t){if(!W(t)&&((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=a(r,{mode:In,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:In,vertexIndex:0}),n})(this.map,[t.lngLat.lng,t.lngLat.lat])){var r=[...e.feature.coordinates],n=Sr(this.map),o=t.lngLat;Ar(e)&&n&&(Mr(n,this.map,t.point),o=wr(n)||t.lngLat),this.movePoint(e,o),this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:r})}},onMouseUp(e,t){var r=Sr(this.map);kr(r),Tr(r,!1),this._didPointMove(e)&&this.pushUndo({type:"move_point",featureId:e.featureId,vertexIndex:0,previousPosition:e._moveStartPosition}),e._moveStartPosition=null,Ct.onMouseUp.call(this,e,t)},_didPointMove(e){if(!e._moveStartPosition)return!1;var t=e.feature.coordinates;return t[0]!==e._moveStartPosition[0]||t[1]!==e._moveStartPosition[1]},onDrag(e,t){if("touch"!==e.interfaceType){this.map.fire("draw.geometrychange",e.feature);var r=Sr(this.map);if(r&&(r.snapStatus=!1,r.snapCoords=null),Ar(e)&&null!=r&&r.status){if(e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng+e._grabOffset[0],lat:t.lngLat.lat+e._grabOffset[1]};Mr(r,this.map,this.map.project([n.lng,n.lat]));var o=wr(r)||n;e.feature.updateCoordinate("",o.lng,o.lat),e.dragMoveLocation=t.lngLat}}else Ct.onDrag.call(this,e,t)}},onTrash(){}};function Mn(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 Tn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Mn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Mn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Cn=Tn(Tn(Tn(Tn(Tn(Tn(Tn({},zt.modes.direct_select),vn),_n),Pn),Sn),wn),{},{onSetup(e){var t,r,n=e.featureId,o=this.getFeature(n);if(!o)throw new Error("You must provide a featureId to enter edit_point mode");var i,a={featureId:n,feature:o,dragMoveLocation:null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:[]};(this.setSelectedCoordinates([]),this.setSelected(n),vt.disable(this),this.setActionableState({trash:!1}),Object.assign(a,{container:e.container,interfaceType:e.interfaceType,undoButtonId:e.undoButtonId,isPanEnabled:e.isPanEnabled,getSnapEnabled:e.getSnapEnabled,scale:null!==(t=e.scale)&&void 0!==t?t:1}),this.map._lastEditFeatureId!==a.featureId)&&(null===(i=this.map._undoStack)||void 0===i||i.clear(),this.map._lastEditFeatureId=a.featureId);return this.setupEventListeners(a),this.map._drawEditContainer=e.container,this.addTouchPointTarget(a),null===(r=a.container)||void 0===r||r.focus({preventScroll:!0}),Nr(this.map),"touch"===a.interfaceType&&setTimeout(()=>{this.updateTouchPointTarget(a,xr(this.map.project(a.feature.coordinates),a.scale))},0),this.map.fire(or,{index:0,numVertices:1}),a},setupEventListeners(e){var t=this.handlers=jr(this,e,{nudge:this.onNudgePoint});Fr(e,this.map,t)},toDisplayFeatures(e,t,r){t.properties.active=e.featureId===t.properties.id?"true":"false",r(t)},onScaleChange(e,t){e.scale=t.scale},onInterfaceTypeChange(e,t){e.interfaceType=t.interfaceType,this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onMove(e){this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onNudgePoint(e,t){this.nudgePointByDelta(e,t.dx,t.dy,t.isLargeStep),this.updateTouchPointTarget(e,xr(this.map.project(e.feature.coordinates),e.scale))},onButtonClick(e,t){t.target.closest("#".concat(e.undoButtonId))&&this.handleUndo(e)},onStop(e){this.map._drawEditContainer=null,this.map._editingFeatureId=null,Vr(e,this.map,this.handlers),this.hideTouchPointIndicator(e)}});function Ln(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 kn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ln(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ln(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var An=e=>{var{ParentMode:t,featureProp:r,excludeFeatureIdFromSetup:n}=e;return{onSetup(e){var{map:o}=this,i=n?kn(kn({},e),{},{featureId:null}):e,a=kn(kn({},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),a.crossHair&&(a.crossHair.activate=()=>{var e;return null===(e=this._placeAtCrossHair)||void 0===e?void 0:e.call(this,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,"keyup",A,{capture:!0}],[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,o]=e;return t.addEventListener?t.addEventListener(r,n,o):t.on(r,n)}),a},onStop(e){var r;t.onStop.call(this,e),this._listeners.forEach(e=>{var[t,r,n,o]=e;return t.removeEventListener?t.removeEventListener(r,n,o):t.off(r,n)}),null!==(r=e.crossHair)&&void 0!==r&&r.activate&&(e.crossHair.activate=null),["touch","keyboard"].includes(e.interfaceType)||this._hideCrossHair(e),this.map.fire("draw.interfacetypechange",{interfaceType:e.interfaceType})}}};function jn(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 Fn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?jn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):jn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Vn=(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)},Nn=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=s({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",{numVertices:Math.max(0,e.length-1)})},emitDrawValidation(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"commit-add";Vn(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)}}},Dn=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=Sr(this.map);if(Ar(e)&&Ir(c))a=function(e,t){var r=wr(t);return r?Or(Or({},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=Sr(this.map),l=Ar(e)&&function(e,t){var r=wr(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]}))}},_placeAtCrossHair(e){this.doClick(e)}}};function Rn(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 Un(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Rn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Bn=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))}}},Gn=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)}}},Hn=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}}},Yn=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 Xn(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 Kn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Xn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Jn=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(Ar(e)){var n=Sr(this.map);Mr(n,this.map,r.point);var o=wr(n);o&&(r=Kn(Kn({},r),{},{lngLat:o}))}t.onMouseMove.call(this,e,r),this.map.fire("draw.geometrychange",e.polygon||e.line)},onMove(e,r){var n="move"===(null==r?void 0:r.type)&&!r.originalEvent;if(["touch","keyboard"].includes(e.interfaceType)||n){Ar(e)&&Cr(Sr(this.map),this.map);var o=Sr(this.map),i=Ar(e)&&wr(o);if(i){var a=this.map.project([i.lng,i.lat]);t.onMouseMove.call(this,e,{lngLat:i,point:a,originalEvent:new MouseEvent("mousemove",{clientX:a.x,clientY:a.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)))}}},$n=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 qn(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 Zn(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?qn(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qn(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var zn=(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 Zn(Zn(Zn(Zn(Zn(Zn(Zn({},e),An(l)),(e=>Fn(Fn({},Nn(e)),Dn(e)))(l)),(e=>Un(Un(Un({},Bn(e)),Gn(e)),Hn(e)))(l)),Yn(l)),Jn(l)),$n(l))},Wn=zn(zt.modes.draw_polygon,{featureProp:"polygon",geometryType:"Polygon",getCoords:e=>e.coordinates[0],validateClick:e=>c(e.coordinates),getPlacedCoords:e=>e.geometry.coordinates[0].slice(0,-2)}),Qn=zn(zt.modes.draw_line_string,{featureProp:"line",geometryType:"LineString",getCoords:e=>e.coordinates,validateClick:e=>l(e.coordinates),excludeFeatureIdFromSetup:!0,finishOnInvalidClick:!0,getPlacedCoords:e=>e.geometry.coordinates.slice(0,-1)});function eo(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 to(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?eo(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):eo(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ro="draw_point",no=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Enter"]),oo=zt.modes.draw_point,io=An({ParentMode:oo,featureProp:"point",excludeFeatureIdFromSetup:!1}),ao={onKeyUp(){},_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)},onCreate(e,t){var r,n=t.features[0];this._ctx.api.delete(n.id),n.id=e.featureId,this._ctx.api.add(n,{userProperties:!0}),null===(r=e.resolvePointSymbol)||void 0===r||r.call(e,e.featureId,n.properties)},onUndo(){},onPointerup(){},onMove(e,t){var r="move"===(null==t?void 0:t.type)&&!t.originalEvent;(["touch","keyboard"].includes(e.interfaceType)||r)&&Ar(e)&&Cr(Sr(this.map),this.map)},onBlur(e,t){t.target!==e.container&&this._hideCrossHair(e)},onPointerdown(e,t){"touch"!==t.pointerType&&this._setInterface(e,"mouse",!1)},onPointermove(e,t){"touch"!==t.pointerType&&this._hideCrossHair(e)},onTouchStart(e){this._setInterface(e,"touch"),this.onMove(e)},onTouchEnd(e){this._setInterface(e,"touch"),this.onMove(e)},onInterfaceTypeChange(e,t){this._setInterface(e,t.interfaceType,["touch","keyboard"].includes(t.interfaceType)),this.onMove(e)},onMouseMove(e,t){Ar(e)&&Mr(Sr(this.map),this.map,t.point)},onVertexButtonClick(e,t){e.addVertexButtonId&&!this.map._undoInProgress&&t.target.closest("#".concat(e.addVertexButtonId))&&this._placeAtCrossHair(e)},onKeydown(e,t){document.activeElement===e.container&&("Escape"!==t.key?("Enter"===t.key&&(e.isActive=!0),no.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e))):t.preventDefault())},onKeyup(e,t){"Escape"!==t.key?document.activeElement===e.container&&no.has(t.key)&&(this._setInterface(e,"keyboard"),this.onMove(e),"Enter"===t.key&&e.isActive&&this._placeAtCrossHair(e)):this.map.fire("draw.cancel")},onClick(e,t){if(!(t.originalEvent.button>0||t.originalEvent.target!==this.map.getCanvas())){var r=Sr(this.map),n=Ar(e)&&Ir(r)?wr(r):null;this._commit(e,n||t.lngLat)}},onTap(e,t){this.onClick(e,t)},_placeAtCrossHair(e){var t=Sr(this.map);Ar(e)&&Cr(t,this.map);var r=Ar(e)&&Ir(t)?wr(t):null;this._commit(e,r||this.map.getCenter()),this._ctx.store.render()},_commit(e,t){((e,t)=>{var r={type:"Feature",geometry:{type:"Point",coordinates:t},properties:{}},{valid:n,reason:o}=a(r,{mode:ro,vertexIndex:0},{onGeometryChange:e._drawGeometryValidator});return n||e.fire("draw.placementblocked",{feature:r,reason:null!=o?o:null,phase:"place",mode:ro,vertexIndex:0}),n})(this.map,[t.lng,t.lat])&&(e.point.updateCoordinate("",t.lng,t.lat),this.map.fire("draw.create",{features:[e.point.toGeoJSON()]}))}},so=to(to(to({},oo),io),ao),co=(e,t,r)=>["coalesce",["get","user_".concat(t).concat(e.id.charAt(0).toUpperCase()+e.id.slice(1))],["get","user_".concat(t)],r],lo=["get","user_sortKey"],uo=(e,t)=>({id:"fill-inactive",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","false"]],layout:{"fill-sort-key":lo},paint:{"fill-color":co(e,"fill",t.shapeFill)}}),po=(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","line-sort-key":lo},paint:{"line-color":co(e,"stroke",t.shapeStroke),"line-width":t.strokeWidth}}),ho=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}}),fo=(e,t)=>({id:"vertex",type:"circle",filter:["all",["==","$type","Point"],["in","meta","vertex","draw-vertex"]],paint:{"circle-radius":t,"circle-color":e}}),go=(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}}),yo=(e,t)=>({id:"vertex-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),mo=(e,t)=>({id:"midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":t,"circle-color":e}}),vo=(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}}),_o=(e,t)=>({id:"midpoint-active",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":t,"circle-color":e}}),bo=e=>({id:"circle",type:"line",filter:["==","id","circle"],paint:{"line-color":e,"line-width":2,"line-opacity":.8}}),xo=function(e){var t,r,n,o,i,a=C(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}),{vertexRadius:s,midpointRadius:c,vertexHaloRadius:l,midpointHaloRadius:d}=u;return[uo(e,a),(i=a.editFill,{id:"fill-active",type:"fill",filter:["all",["==","$type","Polygon"],["==","active","true"]],paint:{"fill-color":i}}),(o=a.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":o,"line-width":2,"line-opacity":1}}),(n=a.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}}),po(e,a),{id:"point-symbol",type:"symbol",filter:["all",["==","$type","Point"],["==","meta","feature"]],layout:{"icon-image":["case",["==",["get","active"],"true"],["coalesce",["get","user_symbolSelectedImageId"],["get","user_symbolImageId"]],["get","user_symbolImageId"]],"icon-anchor":["get","user_symbolIconAnchor"],"icon-offset":["literal",[0,0]],"icon-allow-overlap":!0,"icon-ignore-placement":!0,"symbol-sort-key":lo},paint:{}},(r=a.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=a.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}}),ho(a.editStroke),mo(a.editMidpoint,c),vo(a.editHalo,a.editActive,d),_o(a.editMidpoint,c),fo(a.editVertex,s),go(a.editHalo,a.editActive,l),yo(a.editVertex,s),bo(a.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 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 Eo(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 Oo(e,t,r){void 0===r&&(r={});var n=Po(e),o=Po(t),i=d(o[1]-n[1]),a=d(o[0]-n[0]),s=d(n[1]),c=d(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return p(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}function So(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 Io(e,t,r,n={}){const o=So(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(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)),p=g(u),y=g(l);return void 0!==o[2]?f([p,y,o[2]],n.properties):f([p,y],n.properties)}function wo(e,t){var r;return void 0===t&&(t={}),function(e,t){if(e.length>1)return m(e,t);return v(e[0],t)}(("Feature"===(r=e).type?r.geometry:r).coordinates,t.properties?t.properties:"Feature"===e.type?e.properties:{})}function Mo(e,t,r={}){if(!0===r.final)return function(e,t){let r=Mo(t,e);return r=(r+180)%360,r}(e,t);const n=So(e),o=So(t),i=d(n[0]),a=d(o[0]),s=d(n[1]),c=d(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 g(Math.atan2(l,u))}var To=Mo;function Co(e,t,r,n){void 0===n&&(n={});var o=Po(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(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)),p=g(u),y=g(l);return f([p,y],n.properties)}function Lo(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=Eo(n);break;case"LineString":r=[Eo(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=v([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 ko={exports:{}};function Ao(e,t,r,n,o){jo(e,t,r||0,n||e.length-1,o||Vo)}function jo(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);jo(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(Fo(e,r,t),o(e[n],u)>0&&Fo(e,r,n);d<p;){for(Fo(e,d,p),d++,p--;o(e[d],u)<0;)d++;for(;o(e[p],u)>0;)p--}0===o(e[r],u)?Fo(e,r,p):Fo(e,++p,n),p<=t&&(r=p+1),t<=p&&(n=p-1)}}function Fo(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Vo(e,t){return e<t?-1:e>t?1:0}function No(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 Do(e,t){Ro(e,0,e.children.length,t,e)}function Ro(e,t,r,n,o){o||(o=qo(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];Uo(o,e.leaf?n(t):t)}return o}function Uo(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 Bo(e,t){return e.minX-t.minX}function Go(e,t){return e.minY-t.minY}function Ho(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Yo(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Xo(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 Ko(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 Jo(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function $o(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function qo(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Zo(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;Ao(e,a,t,r,o),i.push(t,a,a,r)}}var zo,Wo=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(!$o(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;$o(e,s)&&(t.leaf?r.push(a):Jo(e,s)?this._all(a,r):o.push(a))}t=o.pop()}return r}collides(e){let t=this.data;if(!$o(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($o(e,i)){if(t.leaf||Jo(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=qo([]),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=No(e,r.children,t);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}c||r.leaf||!Jo(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=qo(e.slice(t,r+1)),Do(i,this.toBBox),i;n||(n=Math.ceil(Math.log(o)/Math.log(a)),a=Math.ceil(o/Math.pow(a,n-1))),i=qo([]),i.leaf=!1,i.height=n;const s=Math.ceil(o/a),c=s*Math.ceil(Math.sqrt(a));Zo(e,t,r,c,this.compareMinX);for(let o=t;o<=r;o+=c){const t=Math.min(o+c-1,r);Zo(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 Do(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=Ho(a),c=Xo(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),Uo(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=qo(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,Do(r,this.toBBox),Do(a,this.toBBox),t?e[t-1].children.push(a):this._splitRoot(r,a)}_splitRoot(e,t){this.data=qo([e,t]),this.data.height=e.height+1,this.data.leaf=!1,Do(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=Ro(e,0,a,this.toBBox),s=Ro(e,a,r,this.toBBox),c=Ko(t,s),l=Ho(t)+Ho(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:Bo,o=e.leaf?this.compareMinY:Go;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=Ro(e,0,t,o),a=Ro(e,r-t,r,o);let s=Yo(i)+Yo(a);for(let n=t;n<r-t;n++){const t=e.children[n];Uo(i,e.leaf?o(t):t),s+=Yo(i)}for(let n=r-t-1;n>=t;n--){const t=e.children[n];Uo(a,e.leaf?o(t):t),s+=Yo(a)}return s}_adjustParentBBoxes(e,t,r){for(let n=r;n>=0;n--)Uo(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():Do(e[r],this.toBBox)}}}),Qo=fe(Wo),ei={};function ti(){if(zo)return ei;zo=1,Object.defineProperty(ei,"__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 ei.areaFactors=r,ei.azimuthToBearing=function(e){return(e%=360)>180?e-360:e<-180?e+360:e},ei.bearingToAzimuth=function(e){let t=e%360;return t<0&&(t+=360),t},ei.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},ei.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)},ei.degreesToRadians=function(e){return e%360*Math.PI/180},ei.earthRadius=e,ei.factors=t,ei.feature=n,ei.featureCollection=s,ei.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")}},ei.geometryCollection=function(e,t,r={}){return n({type:"GeometryCollection",geometries:e},t,r)},ei.isNumber=f,ei.isObject=function(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)},ei.lengthToDegrees=function(e,t){return h(p(e,t))},ei.lengthToRadians=p,ei.lineString=a,ei.lineStrings=function(e,t,r={}){return s(e.map(e=>a(e,t)),r)},ei.multiLineString=c,ei.multiPoint=l,ei.multiPolygon=u,ei.point=o,ei.points=function(e,t,r={}){return s(e.map(e=>o(e,t)),r)},ei.polygon=i,ei.polygons=function(e,t,r={}){return s(e.map(e=>i(e,t)),r)},ei.radiansToDegrees=h,ei.radiansToLength=d,ei.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},ei.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")})},ei.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")},ei}var ri,ni={};function oi(){if(ri)return ni;ri=1,Object.defineProperty(ni,"__esModule",{value:!0});var e=ti();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 _=0;_<c;_++){var b=0,x=0;if(null!==(s=d?u.geometries[_]:u)){l=s.coordinates;var P=s.type;switch(p=!n||"Polygon"!==P&&"MultiPolygon"!==P?0:1,P){case null:break;case"Point":if(!1===r(l,h,v,b,x))return!1;h++,b++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],h,v,b,x))return!1;h++,"MultiPoint"===P&&b++}"LineString"===P&&b++;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,x))return!1;h++}"MultiLineString"===P&&b++,"Polygon"===P&&x++}"Polygon"===P&&b++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(x=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,x))return!1;h++}x++}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 ni.coordAll=function(e){var r=[];return t(e,function(e){r.push(e)}),r},ni.coordEach=t,ni.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},ni.featureEach=n,ni.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},ni.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")},ni.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")},ni.flattenEach=i,ni.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},ni.geomEach=o,ni.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},ni.lineEach=s,ni.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},ni.propEach=r,ni.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},ni.segmentEach=a,ni.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},ni}var ii,ai,si={};function ci(){if(ii)return si;ii=1,Object.defineProperty(si,"__esModule",{value:!0});var e=oi();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 si.bbox=t,si.default=r,si}var li=function(){if(ai)return ko.exports;ai=1;var e=Qo,t=ti(),r=oi(),n=ci().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 ko.exports=a,ko.exports.default=a,ko.exports}(),ui=he(li);function di(e,t){var r={},n=[];if("LineString"===e.type&&(e=x(e)),"LineString"===t.type&&(t=x(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=pi(e,t);return o&&n.push(o),b(n)}var i=ui();return i.load(Lo(t)),P(Lo(e),function(e){P(i.search(e),function(t){var o=pi(e,t);if(o){var i=Eo(o).join(",");r[i]||(r[i]=!0,n.push(o))}})}),b(n)}function pi(e,t){var r=Eo(e),n=Eo(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),g=(a-o)*(i-l)-(s-i)*(o-c);if(0===p)return null;var y=h/p,m=g/p;return y>=0&&y<=1&&m>=0&&m<=1?f([o+y*(a-o),i+y*(s-i)]):null}function hi(e,t,r){void 0===r&&(r={});var n=f([1/0,1/0],{dist:1/0}),o=0;return _(e,function(e){for(var i=Eo(e),a=0;a<i.length-1;a++){var s=f(i[a]);s.properties.dist=Oo(t,s,r);var c=f(i[a+1]);c.properties.dist=Oo(t,c,r);var l=Oo(s,c,r),u=Math.max(s.properties.dist,c.properties.dist),d=To(s,c),p=Co(t,u,d+90,r),h=Co(t,u,d-90,r),g=di(v([p.geometry.coordinates,h.geometry.coordinates]),v([s.geometry.coordinates,c.geometry.coordinates])),y=null;g.features.length>0&&((y=g.features[0]).properties.dist=Oo(t,y,r),y.properties.location=o+Oo(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 fi(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 gi(e,t){var r=function(e,t,r,n){void 0===n&&(n={});var o=fi(e),i=d(o[0]),a=d(o[1]),s=d(r),c=h(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)),p=g(u),y=g(l);return f([p,y],n.properties)}(e,function(e,t,r){void 0===r&&(r={});var n=fi(e),o=fi(t),i=d(o[1]-n[1]),a=d(o[0]-n[0]),s=d(n[1]),c=d(o[1]),l=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(c);return p(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),r.units)}(e,t)/2,To(e,t));return r}var yi=function(){return yi=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},yi.apply(this,arguments)},mi=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=yi(yi({},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 Oo(f(e),f(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=Oo(f([r.lng,r.lat]),f([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(Io(e,t,-360*o/n,r).geometry.coordinates);return i.push(i[0]),y([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=E(e),o=[];if(n.map(function(e){var n=Oo(f(e),f([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(v(e))});break;case"Polygon":var o=wo(e.geometry);n.push(o);break;case"MultiPolygon":wo(e.geometry).coodinates.map(function(e){n.push(v(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(Lo(e).features)});var i=[];if(o.map(function(e){var n=gi(e.geometry.coordinates[0],e.geometry.coordinates[1]),o=Oo(n,f([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=hi(n[i],f([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}(),vi="snap-helper-circle",_i="mapbox-gl-draw-hot";function bi(e){if(!mi.prototype.__snapPatched){mi.prototype.__snapPatched=!0;var t=mi.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(vi)&&this.map.setLayoutProperty(vi,"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=>y(e)):"MultiLineString"===o.type?i.filter(e=>Array.isArray(e)&&e.length>0).map(e=>v(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)&&(!this._autoSnapSuspended||e._explicit))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 xi(e,t){!function r(){var n=e();null!==n&&(n?t(n):requestAnimationFrame(r))}()}function Pi(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 Ei=new Set(["draw_polygon","draw_line","draw_point","edit_vertex","edit_point"]);function Oi(e,t,r,n){if(e._snapInstance||e._snapCreating)return e._snapInstance;e._snapCreating=!0,function(e){e.getLayer(vi)&&e.removeLayer(vi),e.getSource(vi)&&e.removeSource(vi)}(e),Pi(r);var o=new mi({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&&Ei.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 Si(e,t,r){e.on("style.load",()=>{xi(()=>e._removed?null:e.getSource(_i),n=>{Pi(n),function(e){var t;e.getSource(vi)||e.addSource(vi,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(vi)||e.addLayer({id:vi,type:"fill",source:vi,paint:{"fill-color":["get","color"]},layout:{visibility:null!==(t=e._snapInstance)&&void 0!==t&&t.status?"visible":"none"}})}(e),e._snapInstance||Oi(e,t,n,r)})})}function Ii(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 wi(t,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t._snapInitialized)return t._snapInstance;t._snapInitialized=!0;var{layers:i=[],radius:a=n.snapRadius,rules:s=["vertex","midpoint","edge"],status:c=!1,onSnapped:l=()=>{},colors:u={}}=o,d={layers:i,radius:a,rules:s,status:c,onSnapped:l};return bi(function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Ii(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ii(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({vertex:O.snapVertex,midpoint:O.snapMidpoint,edge:O.snapEdge},u)),Si(t,r,d),function(e){e.on("zoomstart",()=>{e._isZooming=!0}),e.on("zoomend",()=>{if(e._isZooming=!1,e.getLayer(vi)){e.setLayoutProperty(vi,"visibility","none");var t=e._snapInstance;null!=t&&t.status&&e.setLayoutProperty(vi,"visibility","visible")}})}(t),xi(()=>t._removed?null:t.getSource(_i),e=>Oi(t,r,e,d)),t._snapInstance}function Mi(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 Ti(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Mi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Mi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Ci="point-symbol",Li=new Set(["".concat(Ci,".hot"),"".concat(Ci,".cold")]),ki=(e,t)=>{var r,n=(e=>{var t=["match",["get","user_symbolImageId"]];for(var[r,n]of Object.entries(e))t.push(r,["literal",n]);return t.push(["literal",[0,0]]),t})(e._symbolIconOffsetMap);null===(r=t.options)||void 0===r||null===(r=r.styles)||void 0===r||r.forEach(e=>{Li.has(e.id)&&(e.layout=Ti(Ti({},e.layout),{},{"icon-offset":n}))}),Li.forEach(t=>{e.getLayer(t)&&e.setLayoutProperty(t,"icon-offset",n)})},Ai=function(){var e=N(function*(e){var{draw:t,mapProvider:r,map:n,symbolRegistry:o,featureId:i,properties:a,pixelRatioOverride:s}=e;if(!S(a))return null;var c=n._drawCurrentMapStyle,l=null!=s?s:(e=>{var t;return(null===(t=e.getPixelRatio)||void 0===t?void 0:t.call(e))||1})(n);yield r.addSymbolsToMap([a],c,o,l);var u=t.get(i);if(!u)return null;var d=o.getSymbolImageId(a,c,"normal",l);if(!d)return null;var p=r.getActiveSymbolImageId(d),h=r.getSelectedSymbolImageId(d),f=r.getSymbolIconLayout(o.getSymbolDef(a));return((e,t,r,n)=>{var o;null!==(o=e._symbolIconOffsetMap)&&void 0!==o||(e._symbolIconOffsetMap={}),e._symbolIconOffsetMap[r]||(e._symbolIconOffsetMap[r]=n,ki(e,t))})(n,t,d,f["icon-offset"]),Ti(Ti({},u),{},{properties:Ti(Ti({},a),{},{symbolImageId:d,symbolIconAnchor:f["icon-anchor"],symbolActiveImageId:p,symbolSelectedImageId:h})})});return function(t){return e.apply(this,arguments)}}(),ji=function(){var e=N(function*(e){var t=yield Ai(e);t&&e.draw.add(t)});return function(t){return e.apply(this,arguments)}}(),Fi=function(){var e=N(function*(e){var t,{draw:r,mapProvider:n,map:o,symbolRegistry:i,pixelRatioOverride:a}=e;o._pointSymbolRefreshId=(null!==(t=o._pointSymbolRefreshId)&&void 0!==t?t:0)+1;var s=o._pointSymbolRefreshId,c=r.getAll().features.filter(e=>"Point"===e.geometry.type&&S(e.properties)),l=yield Promise.allSettled(c.map(e=>Ai({draw:r,mapProvider:n,map:o,symbolRegistry:i,featureId:e.id,properties:e.properties,pixelRatioOverride:a})));if(l.filter(e=>"rejected"===e.status).forEach(e=>{I.error("[draw] failed to resolve point symbol",e.reason)}),o._pointSymbolRefreshId===s){var u=l.filter(e=>"fulfilled"===e.status&&e.value).map(e=>e.value);u.length&&r.add({type:"FeatureCollection",features:u}),((e,t)=>{var r=e._symbolIconOffsetMap;if(r){var n=new Set(t.getAll().features.map(e=>{var t;return null===(t=e.properties)||void 0===t?void 0:t.symbolImageId})),o=Object.keys(r).filter(e=>!n.has(e));o.length&&(o.forEach(e=>delete r[e]),ki(e,t))}})(o,r)}});return function(t){return e.apply(this,arguments)}}();function Vi(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 Ni(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Vi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Vi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Di="mapbox-gl-draw-cold",Ri="mapbox-gl-draw-hot",Ui=e=>{var{map:t,draw:r,mapProvider:n,symbolRegistry:o,pluginConfig:i,onDone:a}=e,s=t._drawCurrentMapStyle;t.once("idle",()=>{var e,c=((e,t)=>{if(e.getSource(Di))return!1;var r={type:"FeatureCollection",features:[]};return e.addSource(Di,{data:r,type:"geojson"}),e.addSource(Ri,{data:r,type:"geojson"}),t.options.styles.forEach(t=>e.addLayer(t)),!0})(t,r);!function(e,t){xo(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)})})}(t,s,i);var l=null===(e=t._drawEditContainer)||void 0===e?void 0:e.querySelector("[data-im-draw-touch-target]");$r(l,s,i),Fi({draw:r,mapProvider:n,map:t,symbolRegistry:o}).then(()=>{c&&r.set(r.getAll()),t.triggerRepaint(),a()}).catch(e=>I.error("[draw] failed to refresh point symbols after a style change",e))})},Bi=e=>{var t,{mapStyle:r,mapProvider:o,symbolRegistry:i,events:a,eventBus:s,snapLayers:c,pluginConfig:l={}}=e,{map:u}=o;zt.constants.classes.CONTROL_BASE="maplibregl-ctrl",zt.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-",zt.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var d=Ni(Ni({},zt.modes),{},{disabled:Wt,edit_vertex:fn,edit_point:Cn,draw_polygon:Wn,draw_line:Qn,draw_point:so}),p=o._mapboxDrawInstance;p?Object.assign(p.modes,d):(p=new zt({modes:d,styles:xo(r,l),displayControlsDefault:!1,userProperties:!0,defaultMode:"disabled"}),u.addControl(p),o._mapboxDrawInstance=p);var h=((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)}}})(u,p);o.draw=p,u._drawCurrentMapStyle=r,u._drawPluginConfig=l,o.snapEnabled=!1;var f=o.undoStack;f||(f=j(e=>u.fire("draw.undochange",{length:e})),o.undoStack=f),u._undoStack=f;var g=C(r,l);wi(u,p,{layers:c,radius:null!==(t=l.snapRadius)&&void 0!==t?t:n.snapRadius,rules:["vertex","edge"],colors:{vertex:g.snapVertex,edge:g.snapEdge}});var y=()=>s.emit(a.MAP_DATA_CHANGE),{handleSetMapStyle:m,handleStyleChanged:v}=(e=>{var{map:t,draw:r,mapProvider:n,symbolRegistry:o,pluginConfig:i,eventBus:a,events:s,notifyPointSymbolsRefreshed:c}=e,l=e=>{t._drawCurrentMapStyle=e};a.on(s.MAP_SET_STYLE,l);var u=!1,d=()=>{u||(u=!0,Ui({map:t,draw:r,mapProvider:n,symbolRegistry:o,pluginConfig:i,onDone:()=>{u=!1,c()}}))};return a.on(s.MAP_STYLE_CHANGE,d),{handleSetMapStyle:l,handleStyleChanged:d}})({map:u,draw:p,mapProvider:o,symbolRegistry:i,pluginConfig:l,eventBus:s,events:a,notifyPointSymbolsRefreshed:y}),_=e=>{u.fire("draw.scalechange",{scale:w[e]})};s.on(a.MAP_SET_SIZE,_);var b=e=>{Fi({draw:p,mapProvider:o,map:u,symbolRegistry:i,pixelRatioOverride:e}).then(()=>{u.triggerRepaint(),y()}).catch(e=>I.error("[draw] failed to refresh point symbols",e))};return s.on(a.MAP_SET_PIXEL_RATIO,b),{draw:p,remove(){h.remove(),s.off(a.MAP_SET_STYLE,m),s.off(a.MAP_STYLE_CHANGE,v),s.off(a.MAP_SET_SIZE,_),s.off(a.MAP_SET_PIXEL_RATIO,b),p.changeMode("disabled"),o.draw=null}}};function Gi(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 Hi(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Gi(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Gi(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var Yi=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e}}),Xi=e=>({type:"Feature",geometry:{type:"LineString",coordinates:e}}),Ki=e=>({type:"Feature",geometry:{type:"Point",coordinates:e}}),Ji=(e,t)=>{var r,n,o;if("draw_polygon"===e)return{feature:Yi(t),numVertices:(null!==(r=null===(n=t[0])||void 0===n?void 0:n.length)&&void 0!==r?r:1)-1};if("draw_line"===e)return{feature:Xi(t),numVertices:(null!==(o=null==t?void 0:t.length)&&void 0!==o?o:1)-1};if("edit_vertex"===e){var i,a=t[0];return Array.isArray(null==a?void 0:a[0])?{feature:Yi(t),numVertices:a.length}:{feature:Xi(t),numVertices:null!==(i=null==t?void 0:t.length)&&void 0!==i?i:0}}return"edit_point"===e?{feature:Ki(t),numVertices:1}:null};class $i{constructor(e,t){var r,n;this._mapProvider=e,this._map=e.map,this._symbolRegistry=t.symbolRegistry,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,this._sortKeyCounter=0;var{draw:o,remove:i}=Bi({mapStyle:t.mapStyle,mapProvider:e,symbolRegistry:t.symbolRegistry,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=F({onChange:(e,t)=>{this._applyStrokeInvalid(e);var r=this._draw.getMode();"edit_vertex"!==r&&"edit_point"!==r||this._bus.emit(M.VALIDITY_CHANGE,{valid:!e,reason:t})}}),this._liveDrawChecks=V({onStrokeChange:(e,t)=>this._liveStroke.set(e,t),onPlaceChange:(e,t)=>this._bus.emit(M.CAN_PLACE_CHANGE,{canPlace:!e,reason:t})}),this._mapHandlers={create:e=>{var t=e.features[0];setTimeout(()=>{this._draw.setFeatureProperty(t.id,"sortKey",this._nextSortKey()),this._bus.emit(M.CREATE,this._draw.get(t.id))},0)},editfinish:e=>this._bus.emit(M.EDIT_FINISH,e.features[0]),cancel:()=>this._bus.emit(M.CANCEL),vertexselection:e=>this._bus.emit(M.VERTEX_SELECTION,e),vertexchange:e=>this._bus.emit(M.VERTEX_CHANGE,e),undochange:e=>this._bus.emit(M.UNDO_CHANGE,e.length),update:e=>this._bus.emit(M.UPDATE,e.features[0]),geometrychange:e=>{null!=e&&e.phase||(this._updateLiveStroke(e),this._currentDrawEvent=e),this._bus.emit(M.GEOMETRY_CHANGE,e)},placementblocked:e=>this._bus.emit(M.PLACEMENT_BLOCKED,e),interfacetypechange:e=>this._bus.emit(M.INTERFACE_TYPE_CHANGE,{interfaceType:e.interfaceType}),modechange:e=>this._handleModeChange(e),styledata:()=>this._handleStyleData()},this._map.on(Qt,this._mapHandlers.create),this._map.on(rr,this._mapHandlers.editfinish),this._map.on(nr,this._mapHandlers.cancel),this._map.on(or,this._mapHandlers.vertexselection),this._map.on(ir,this._mapHandlers.vertexchange),this._map.on(ar,this._mapHandlers.undochange),this._map.on(er,this._mapHandlers.update),this._map.on(cr,this._mapHandlers.geometrychange),this._map.on(ur,this._mapHandlers.placementblocked),this._map.on(lr,this._mapHandlers.interfacetypechange),this._map.on(tr,this._mapHandlers.modechange),this._map.on(fr,this._mapHandlers.styledata)}changeMode(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"edit_vertex"!==e&&"edit_point"!==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()),"draw_point"===e&&(r=Hi(Hi({},r),{},{resolvePointSymbol:(e,t)=>this._resolvePointSymbol(e,t)})),this._draw.changeMode(e,r),this._handleModeChange({mode:e})}_resolvePointSymbol(e,t){ji({draw:this._draw,mapProvider:this._mapProvider,map:this._map,symbolRegistry:this._symbolRegistry,featureId:e,properties:t}).catch(t=>I.error("[draw] failed to resolve point symbol",e,t))}_updateLiveStroke(e){if(null!=e&&e.coordinates){var t=this._draw.getMode(),r=Ji(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(Hi(Hi({},r),{},{context:{mode:t},onGeometryChange:this._geometryValidator})))}}getMode(){return this._draw.getMode()}setInterfaceType(e){this._map.fire(lr,{interfaceType:e})}done(){var e;null===(e=this._mapProvider.undoStack)||void 0===e||e.clear();var t=this._draw.getMode();if(("edit_vertex"===t||"edit_point"===t)&&this._editingFeatureId)return this._handleModeChange({mode:"disabled"}),void this._map.fire(rr,{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(sr)}nudgeSelectedVertex(e,t,r){this._map.fire(dr,{dx:e,dy:t,isLargeStep:r})}getVertexItems(){var e={vertices:[],midpoints:[]};if("edit_vertex"!==this._draw.getMode()||!this._editingFeatureId)return e;var t=this._draw.get(this._editingFeatureId);if(!t)return e;var r=(e=>"Polygon"===e.type?Hi(Hi({},e),{},{coordinates:e.coordinates.map(e=>e.slice(0,-1))}):"MultiPolygon"===e.type?Hi(Hi({},e),{},{coordinates:e.coordinates.map(e=>e.map(e=>e.slice(0,-1)))}):e)(t.geometry);return{vertices:gr(r),midpoints:yr(r)}}selectVertex(e){this._map.fire(pr,{index:e})}insertVertexAtMidpoint(e){this._map.fire(hr,{index:e})}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)}_nextSortKey(){return this._sortKeyCounter+=1,this._sortKeyCounter}add(e){var t,r,n=null==(null===(t=e.properties)||void 0===t?void 0:t.sortKey)?Hi(Hi({},e.properties),{},{sortKey:this._nextSortKey()}):e.properties,o=Hi(Hi({},e),{},{properties:n}),i=this._draw.add(o);return"Point"===(null===(r=o.geometry)||void 0===r?void 0:r.type)&&S(n)&&this._resolvePointSymbol(i[0],n),i}setStyle(e,t){var r=this._draw.get(e);r&&this.add(Hi(Hi({},r),{},{properties:Hi(Hi({},r.properties),t)}))}delete(e){this._draw.delete(e)}deleteAll(){this._draw.deleteAll()}setSnapEnabled(e){this._mapProvider.snapEnabled=e;var t=Sr(this._map);null!=t&&t.setSnapStatus&&t.setSnapStatus(e),!e&&t&&(kr(t),this._map.getLayer("snap-helper-circle")&&this._map.setLayoutProperty("snap-helper-circle","visibility","none"))}setSnapLayers(e){var t=Sr(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","draw_point","edit_vertex","edit_point"]).has(e.mode)||Lr(Sr(this._map),this._map)}_handleStyleData(){var e,t=this._map.getStyle();if(t){this._liveStroke.refresh();var r=t.layers||[];!r.length||null!==(e=r[r.length-1].source)&&void 0!==e&&e.startsWith("mapbox-gl-draw")||r.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(Qt,this._mapHandlers.create),this._map.off(rr,this._mapHandlers.editfinish),this._map.off(nr,this._mapHandlers.cancel),this._map.off(or,this._mapHandlers.vertexselection),this._map.off(ir,this._mapHandlers.vertexchange),this._map.off(ar,this._mapHandlers.undochange),this._map.off(er,this._mapHandlers.update),this._map.off(cr,this._mapHandlers.geometrychange),this._map.off(ur,this._mapHandlers.placementblocked),this._map.off(lr,this._mapHandlers.interfacetypechange),this._map.off(tr,this._mapHandlers.modechange),this._map.off(fr,this._mapHandlers.styledata),this._liveStroke.destroy(),this._liveDrawChecks.destroy(),this._cleanupDraw()}}export{$i as MaplibreDrawAdapter,Ji as displayedShape};
|