UNPKG

@map.ir/mapbox-gl-draw-geospatial-tools

Version:

Advanced tools for geospatial edit and analysis based on Mapbox Gl Draw

1 lines 721 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MapboxDrawPro={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})})),e}var r={exports:{}};!function(t,n){t.exports=function(){var t=function(t,e){var n={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},r={on:function(t,e,r){if(void 0===n[t])throw new Error("Invalid event type: "+t);n[t].push({selector:e,fn:r})},render:function(t){e.store.featureChanged(t)}},i=function(t,i){for(var o=n[t],s=o.length;s--;){var a=o[s];if(a.selector(i)){a.fn.call(r,i)||e.store.render(),e.ui.updateMapClasses();break}}};return t.start.call(r),{render:t.render,stop:function(){t.stop&&t.stop()},trash:function(){t.trash&&(t.trash(),e.store.render())},combineFeatures:function(){t.combineFeatures&&t.combineFeatures()},uncombineFeatures:function(){t.uncombineFeatures&&t.uncombineFeatures()},drag:function(t){i("drag",t)},click:function(t){i("click",t)},mousemove:function(t){i("mousemove",t)},mousedown:function(t){i("mousedown",t)},mouseup:function(t){i("mouseup",t)},mouseout:function(t){i("mouseout",t)},keydown:function(t){i("keydown",t)},keyup:function(t){i("keyup",t)},touchstart:function(t){i("touchstart",t)},touchmove:function(t){i("touchmove",t)},touchend:function(t){i("touchend",t)},tap:function(t){i("tap",t)}}},n=6378137;function r(t){var e=0;if(t&&t.length>0){e+=Math.abs(i(t[0]));for(var n=1;n<t.length;n++)e-=Math.abs(i(t[n]))}return e}function i(t){var e,r,i,s,a,u,l=0,c=t.length;if(c>2){for(u=0;u<c;u++)u===c-2?(i=c-2,s=c-1,a=0):u===c-1?(i=c-1,s=0,a=1):(i=u,s=u+1,a=u+2),e=t[i],r=t[s],l+=(o(t[a][0])-o(e[0]))*Math.sin(o(r[1]));l=l*n*n/2}return l}function o(t){return t*Math.PI/180}var s={geometry:function t(e){var n,i=0;switch(e.type){case"Polygon":return r(e.coordinates);case"MultiPolygon":for(n=0;n<e.coordinates.length;n++)i+=r(e.coordinates[n]);return i;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<e.geometries.length;n++)i+=t(e.geometries[n]);return i}},ring:i},a="mapboxgl-ctrl",u="mapbox-gl-draw_ctrl-draw-btn",l="mapbox-gl-draw_line",c="mapbox-gl-draw_polygon",h="mapbox-gl-draw_point",p="mapbox-gl-draw_trash",f="mapbox-gl-draw_combine",d="mapbox-gl-draw_uncombine",g="mapboxgl-ctrl-group",y="active",m="mapbox-gl-draw_boxselect",_="mapbox-gl-draw-hot",v="mapbox-gl-draw-cold",b="add",E="move",w="drag",x="pointer",I="none",S={POLYGON:"polygon",LINE:"line_string",POINT:"point"},C="Feature",P="Polygon",M="LineString",N="Point",L="FeatureCollection",O="Multi",T="MultiPoint",A="MultiLineString",R="MultiPolygon",F={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select",STATIC:"static"},D="draw.create",k="draw.delete",G="draw.update",j="draw.selectionchange",U="draw.modechange",q="draw.actionable",B="draw.render",V="draw.combine",z="draw.uncombine",Y="move",X="change_coordinates",$="feature",J="midpoint",H="vertex",W="true",K="false",Z=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"],Q={Point:0,LineString:1,Polygon:2};function tt(t,e){var n=Q[t.geometry.type]-Q[e.geometry.type];return 0===n&&t.geometry.type===P?t.area-e.area:n}function et(t){if(this._items={},this._nums={},this._length=t?t.length:0,t)for(var e=0,n=t.length;e<n;e++)this.add(t[e]),void 0!==t[e]&&("string"==typeof t[e]?this._items[t[e]]=e:this._nums[t[e]]=e)}et.prototype.add=function(t){return this.has(t)||(this._length++,"string"==typeof t?this._items[t]=this._length:this._nums[t]=this._length),this},et.prototype.delete=function(t){return!1===this.has(t)||(this._length--,delete this._items[t],delete this._nums[t]),this},et.prototype.has=function(t){return!("string"!=typeof t&&"number"!=typeof t||void 0===this._items[t]&&void 0===this._nums[t])},et.prototype.values=function(){var t=this,e=[];return Object.keys(this._items).forEach((function(n){e.push({k:n,v:t._items[n]})})),Object.keys(this._nums).forEach((function(n){e.push({k:JSON.parse(n),v:t._nums[n]})})),e.sort((function(t,e){return t.v-e.v})).map((function(t){return t.k}))},et.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};var nt=[$,J,H],rt={click:function(t,e,n){return it(t,e,n,n.options.clickBuffer)},touch:function(t,e,n){return it(t,e,n,n.options.touchBuffer)}};function it(t,e,n,r){if(null===n.map)return[];var i=t?function(t,e){return void 0===e&&(e=0),[[t.point.x-e,t.point.y-e],[t.point.x+e,t.point.y+e]]}(t,r):e,o={};n.options.styles&&(o.layers=n.options.styles.map((function(t){return t.id})));var a=n.map.queryRenderedFeatures(i,o).filter((function(t){return-1!==nt.indexOf(t.properties.meta)})),u=new et,l=[];return a.forEach((function(t){var e=t.properties.id;u.has(e)||(u.add(e),l.push(t))})),function(t){return t.map((function(t){return t.geometry.type===P&&(t.area=s.geometry({type:C,property:{},geometry:t.geometry})),t})).sort(tt).map((function(t){return delete t.area,t}))}(l)}function ot(t,e){var n=rt.click(t,null,e),r={mouse:I};return n[0]&&(r.mouse=n[0].properties.active===W?E:x,r.feature=n[0].properties.meta),-1!==e.events.currentModeName().indexOf("draw")&&(r.mouse=b),e.ui.queueMapClasses(r),e.ui.updateMapClasses(),n[0]}function st(t,e){var n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function at(t,e,n){void 0===n&&(n={});var r=null!=n.fineTolerance?n.fineTolerance:4,i=null!=n.grossTolerance?n.grossTolerance:12,o=null!=n.interval?n.interval:500;t.point=t.point||e.point,t.time=t.time||e.time;var s=st(t.point,e.point);return s<r||s<i&&e.time-t.time<o}function ut(t,e,n){void 0===n&&(n={});var r=null!=n.tolerance?n.tolerance:25,i=null!=n.interval?n.interval:250;return t.point=t.point||e.point,t.time=t.time||e.time,st(t.point,e.point)<r&&e.time-t.time<i}function lt(t,e){return t(e={exports:{}},e.exports),e.exports}var ct=lt((function(t){var e=t.exports=function(t,n){if(n||(n=16),void 0===t&&(t=128),t<=0)return"0";for(var r=Math.log(Math.pow(2,t))/Math.log(n),i=2;r===1/0;i*=2)r=Math.log(Math.pow(2,t/i))/Math.log(n)*i;var o=r-Math.floor(r),s="";for(i=0;i<Math.floor(r);i++)s=Math.floor(Math.random()*n).toString(n)+s;if(o){var a=Math.pow(n,o);s=Math.floor(Math.random()*a).toString(n)+s}var u=parseInt(s,n);return u!==1/0&&u>=Math.pow(2,t)?e(t,n):s};e.rack=function(t,n,r){var i=function(i){var s=0;do{if(s++>10){if(!r)throw new Error("too many ID collisions, use more bits");t+=r}var a=e(t,n)}while(Object.hasOwnProperty.call(o,a));return o[a]=i,a},o=i.hats={};return i.get=function(t){return i.hats[t]},i.set=function(t,e){return i.hats[t]=e,i},i.bits=t||128,i.base=n||16,i}})),ht=function(t,e){this.ctx=t,this.properties=e.properties||{},this.coordinates=e.geometry.coordinates,this.id=e.id||ct(),this.type=e.geometry.type};ht.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ht.prototype.incomingCoords=function(t){this.setCoordinates(t)},ht.prototype.setCoordinates=function(t){this.coordinates=t,this.changed()},ht.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ht.prototype.setProperty=function(t,e){this.properties[t]=e},ht.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:C,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ht.prototype.internal=function(t){var e={id:this.id,meta:$,"meta:type":this.type,active:K,mode:t};if(this.ctx.options.userProperties)for(var n in this.properties)e["user_"+n]=this.properties[n];return{type:C,properties:e,geometry:{coordinates:this.getCoordinates(),type:this.type}}};var pt=function(t,e){ht.call(this,t,e)};(pt.prototype=Object.create(ht.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},pt.prototype.updateCoordinate=function(t,e,n){this.coordinates=3===arguments.length?[e,n]:[t,e],this.changed()},pt.prototype.getCoordinate=function(){return this.getCoordinates()};var ft=function(t,e){ht.call(this,t,e)};(ft.prototype=Object.create(ht.prototype)).isValid=function(){return this.coordinates.length>1},ft.prototype.addCoordinate=function(t,e,n){this.changed();var r=parseInt(t,10);this.coordinates.splice(r,0,[e,n])},ft.prototype.getCoordinate=function(t){var e=parseInt(t,10);return JSON.parse(JSON.stringify(this.coordinates[e]))},ft.prototype.removeCoordinate=function(t){this.changed(),this.coordinates.splice(parseInt(t,10),1)},ft.prototype.updateCoordinate=function(t,e,n){var r=parseInt(t,10);this.coordinates[r]=[e,n],this.changed()};var dt=function(t,e){ht.call(this,t,e),this.coordinates=this.coordinates.map((function(t){return t.slice(0,-1)}))};(dt.prototype=Object.create(ht.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every((function(t){return t.length>2}))},dt.prototype.incomingCoords=function(t){this.coordinates=t.map((function(t){return t.slice(0,-1)})),this.changed()},dt.prototype.setCoordinates=function(t){this.coordinates=t,this.changed()},dt.prototype.addCoordinate=function(t,e,n){this.changed();var r=t.split(".").map((function(t){return parseInt(t,10)}));this.coordinates[r[0]].splice(r[1],0,[e,n])},dt.prototype.removeCoordinate=function(t){this.changed();var e=t.split(".").map((function(t){return parseInt(t,10)})),n=this.coordinates[e[0]];n&&(n.splice(e[1],1),n.length<3&&this.coordinates.splice(e[0],1))},dt.prototype.getCoordinate=function(t){var e=t.split(".").map((function(t){return parseInt(t,10)})),n=this.coordinates[e[0]];return JSON.parse(JSON.stringify(n[e[1]]))},dt.prototype.getCoordinates=function(){return this.coordinates.map((function(t){return t.concat([t[0]])}))},dt.prototype.updateCoordinate=function(t,e,n){this.changed();var r=t.split("."),i=parseInt(r[0],10),o=parseInt(r[1],10);void 0===this.coordinates[i]&&(this.coordinates[i]=[]),this.coordinates[i][o]=[e,n]};var gt={MultiPoint:pt,MultiLineString:ft,MultiPolygon:dt},yt=function(t,e,n,r,i){var o=n.split("."),s=parseInt(o[0],10),a=o[1]?o.slice(1).join("."):null;return t[s][e](a,r,i)},mt=function(t,e){if(ht.call(this,t,e),delete this.coordinates,this.model=gt[e.geometry.type],void 0===this.model)throw new TypeError(e.geometry.type+" is not a valid type");this.features=this._coordinatesToFeatures(e.geometry.coordinates)};function _t(t){this.map=t.map,this.drawConfig=JSON.parse(JSON.stringify(t.options||{})),this._ctx=t}(mt.prototype=Object.create(ht.prototype))._coordinatesToFeatures=function(t){var e=this,n=this.model.bind(this);return t.map((function(t){return new n(e.ctx,{id:ct(),type:C,properties:{},geometry:{coordinates:t,type:e.type.replace("Multi","")}})}))},mt.prototype.isValid=function(){return this.features.every((function(t){return t.isValid()}))},mt.prototype.setCoordinates=function(t){this.features=this._coordinatesToFeatures(t),this.changed()},mt.prototype.getCoordinate=function(t){return yt(this.features,"getCoordinate",t)},mt.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map((function(t){return t.type===P?t.getCoordinates():t.coordinates}))))},mt.prototype.updateCoordinate=function(t,e,n){yt(this.features,"updateCoordinate",t,e,n),this.changed()},mt.prototype.addCoordinate=function(t,e,n){yt(this.features,"addCoordinate",t,e,n),this.changed()},mt.prototype.removeCoordinate=function(t){yt(this.features,"removeCoordinate",t),this.changed()},mt.prototype.getFeatures=function(){return this.features},_t.prototype.setSelected=function(t){return this._ctx.store.setSelected(t)},_t.prototype.setSelectedCoordinates=function(t){var e=this;this._ctx.store.setSelectedCoordinates(t),t.reduce((function(t,n){return void 0===t[n.feature_id]&&(t[n.feature_id]=!0,e._ctx.store.get(n.feature_id).changed()),t}),{})},_t.prototype.getSelected=function(){return this._ctx.store.getSelected()},_t.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},_t.prototype.isSelected=function(t){return this._ctx.store.isSelected(t)},_t.prototype.getFeature=function(t){return this._ctx.store.get(t)},_t.prototype.select=function(t){return this._ctx.store.select(t)},_t.prototype.deselect=function(t){return this._ctx.store.deselect(t)},_t.prototype.deleteFeature=function(t,e){return void 0===e&&(e={}),this._ctx.store.delete(t,e)},_t.prototype.addFeature=function(t){return this._ctx.store.add(t)},_t.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},_t.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},_t.prototype.setActionableState=function(t){void 0===t&&(t={});var e={trash:t.trash||!1,combineFeatures:t.combineFeatures||!1,uncombineFeatures:t.uncombineFeatures||!1};return this._ctx.events.actionable(e)},_t.prototype.changeMode=function(t,e,n){return void 0===e&&(e={}),void 0===n&&(n={}),this._ctx.events.changeMode(t,e,n)},_t.prototype.updateUIClasses=function(t){return this._ctx.ui.queueMapClasses(t)},_t.prototype.activateUIButton=function(t){return this._ctx.ui.setActiveButton(t)},_t.prototype.featuresAt=function(t,e,n){if(void 0===n&&(n="click"),"click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return rt[n](t,e,this._ctx)},_t.prototype.newFeature=function(t){var e=t.geometry.type;return e===N?new pt(this._ctx,t):e===M?new ft(this._ctx,t):e===P?new dt(this._ctx,t):new mt(this._ctx,t)},_t.prototype.isInstanceOf=function(t,e){if(t===N)return e instanceof pt;if(t===M)return e instanceof ft;if(t===P)return e instanceof dt;if("MultiFeature"===t)return e instanceof mt;throw new Error("Unknown feature class: "+t)},_t.prototype.doRender=function(t){return this._ctx.store.featureChanged(t)},_t.prototype.onSetup=function(){},_t.prototype.onDrag=function(){},_t.prototype.onClick=function(){},_t.prototype.onMouseMove=function(){},_t.prototype.onMouseDown=function(){},_t.prototype.onMouseUp=function(){},_t.prototype.onMouseOut=function(){},_t.prototype.onKeyUp=function(){},_t.prototype.onKeyDown=function(){},_t.prototype.onTouchStart=function(){},_t.prototype.onTouchMove=function(){},_t.prototype.onTouchEnd=function(){},_t.prototype.onTap=function(){},_t.prototype.onStop=function(){},_t.prototype.onTrash=function(){},_t.prototype.onCombineFeature=function(){},_t.prototype.onUncombineFeature=function(){},_t.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};var vt={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},bt=Object.keys(vt);function Et(t){var e=Object.keys(t);return function(n,r){void 0===r&&(r={});var i={},o=e.reduce((function(e,n){return e[n]=t[n],e}),new _t(n));return{start:function(){var e=this;i=o.onSetup(r),bt.forEach((function(n){var r,s=vt[n],a=function(){return!1};t[s]&&(a=function(){return!0}),e.on(n,a,(r=s,function(t){return o[r](i,t)}))}))},stop:function(){o.onStop(i)},trash:function(){o.onTrash(i)},combineFeatures:function(){o.onCombineFeatures(i)},uncombineFeatures:function(){o.onUncombineFeatures(i)},render:function(t,e){o.toDisplayFeatures(i,t,e)}}}}function wt(t){return[].concat(t).filter((function(t){return void 0!==t}))}function xt(){var t=this;if(!t.ctx.map||void 0===t.ctx.map.getSource(_))return u();var e=t.ctx.events.currentModeName();t.ctx.ui.queueMapClasses({mode:e});var n=[],r=[];t.isDirty?r=t.getAllIds():(n=t.getChangedIds().filter((function(e){return void 0!==t.get(e)})),r=t.sources.hot.filter((function(e){return e.properties.id&&-1===n.indexOf(e.properties.id)&&void 0!==t.get(e.properties.id)})).map((function(t){return t.properties.id}))),t.sources.hot=[];var i=t.sources.cold.length;t.sources.cold=t.isDirty?[]:t.sources.cold.filter((function(t){var e=t.properties.id||t.properties.parent;return-1===n.indexOf(e)}));var o=i!==t.sources.cold.length||r.length>0;function s(n,r){var i=t.get(n).internal(e);t.ctx.events.currentModeRender(i,(function(e){t.sources[r].push(e)}))}if(n.forEach((function(t){return s(t,"hot")})),r.forEach((function(t){return s(t,"cold")})),o&&t.ctx.map.getSource(v).setData({type:L,features:t.sources.cold}),t.ctx.map.getSource(_).setData({type:L,features:t.sources.hot}),t._emitSelectionChange&&(t.ctx.map.fire(j,{features:t.getSelected().map((function(t){return t.toGeoJSON()})),points:t.getSelectedCoordinates().map((function(t){return{type:C,properties:{},geometry:{type:N,coordinates:t.coordinates}}}))}),t._emitSelectionChange=!1),t._deletedFeaturesToEmit.length){var a=t._deletedFeaturesToEmit.map((function(t){return t.toGeoJSON()}));t._deletedFeaturesToEmit=[],t.ctx.map.fire(k,{features:a})}function u(){t.isDirty=!1,t.clearChangedIds()}u(),t.ctx.map.fire(B,{})}function It(t){var e,n=this;this._features={},this._featureIds=new et,this._selectedFeatureIds=new et,this._selectedCoordinates=[],this._changedFeatureIds=new et,this._deletedFeaturesToEmit=[],this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=t,this.sources={hot:[],cold:[]},this.render=function(){e||(e=requestAnimationFrame((function(){e=null,xt.call(n)})))},this.isDirty=!1}function St(t,e){var n=t._selectedCoordinates.filter((function(e){return t._selectedFeatureIds.has(e.feature_id)}));t._selectedCoordinates.length===n.length||e.silent||(t._emitSelectionChange=!0),t._selectedCoordinates=n}It.prototype.createRenderBatch=function(){var t=this,e=this.render,n=0;return this.render=function(){n++},function(){t.render=e,n>0&&t.render()}},It.prototype.setDirty=function(){return this.isDirty=!0,this},It.prototype.featureChanged=function(t){return this._changedFeatureIds.add(t),this},It.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},It.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},It.prototype.getAllIds=function(){return this._featureIds.values()},It.prototype.add=function(t){return this.featureChanged(t.id),this._features[t.id]=t,this._featureIds.add(t.id),this},It.prototype.delete=function(t,e){var n=this;return void 0===e&&(e={}),wt(t).forEach((function(t){n._featureIds.has(t)&&(n._featureIds.delete(t),n._selectedFeatureIds.delete(t),e.silent||-1===n._deletedFeaturesToEmit.indexOf(n._features[t])&&n._deletedFeaturesToEmit.push(n._features[t]),delete n._features[t],n.isDirty=!0)})),St(this,e),this},It.prototype.get=function(t){return this._features[t]},It.prototype.getAll=function(){var t=this;return Object.keys(this._features).map((function(e){return t._features[e]}))},It.prototype.select=function(t,e){var n=this;return void 0===e&&(e={}),wt(t).forEach((function(t){n._selectedFeatureIds.has(t)||(n._selectedFeatureIds.add(t),n._changedFeatureIds.add(t),e.silent||(n._emitSelectionChange=!0))})),this},It.prototype.deselect=function(t,e){var n=this;return void 0===e&&(e={}),wt(t).forEach((function(t){n._selectedFeatureIds.has(t)&&(n._selectedFeatureIds.delete(t),n._changedFeatureIds.add(t),e.silent||(n._emitSelectionChange=!0))})),St(this,e),this},It.prototype.clearSelected=function(t){return void 0===t&&(t={}),this.deselect(this._selectedFeatureIds.values(),{silent:t.silent}),this},It.prototype.setSelected=function(t,e){var n=this;return void 0===e&&(e={}),t=wt(t),this.deselect(this._selectedFeatureIds.values().filter((function(e){return-1===t.indexOf(e)})),{silent:e.silent}),this.select(t.filter((function(t){return!n._selectedFeatureIds.has(t)})),{silent:e.silent}),this},It.prototype.setSelectedCoordinates=function(t){return this._selectedCoordinates=t,this._emitSelectionChange=!0,this},It.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},It.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},It.prototype.getSelected=function(){var t=this;return this._selectedFeatureIds.values().map((function(e){return t.get(e)}))},It.prototype.getSelectedCoordinates=function(){var t=this;return this._selectedCoordinates.map((function(e){return{coordinates:t.get(e.feature_id).getCoordinate(e.coord_path)}}))},It.prototype.isSelected=function(t){return this._selectedFeatureIds.has(t)},It.prototype.setFeatureProperty=function(t,e,n){this.get(t).setProperty(e,n),this.featureChanged(t)},It.prototype.storeMapConfig=function(){var t=this;Z.forEach((function(e){t.ctx.map[e]&&(t._mapInitialConfig[e]=t.ctx.map[e].isEnabled())}))},It.prototype.restoreMapConfig=function(){var t=this;Object.keys(this._mapInitialConfig).forEach((function(e){t._mapInitialConfig[e]?t.ctx.map[e].enable():t.ctx.map[e].disable()}))},It.prototype.getInitialConfigValue=function(t){return void 0===this._mapInitialConfig[t]||this._mapInitialConfig[t]};var Ct=function(){for(var t=arguments,e={},n=0;n<arguments.length;n++){var r=t[n];for(var i in r)Pt.call(r,i)&&(e[i]=r[i])}return e},Pt=Object.prototype.hasOwnProperty,Mt=["mode","feature","mouse"];function Nt(e){var n=null,r=null,i={onRemove:function(){return e.map.off("load",i.connect),clearInterval(r),i.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.map=null,e.container=null,e.store=null,n&&n.parentNode&&n.parentNode.removeChild(n),n=null,this},connect:function(){e.map.off("load",i.connect),clearInterval(r),i.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd:function(o){var s=o.fire;return o.fire=function(t,e){var n=arguments;return 1===s.length&&1!==arguments.length&&(n=[Ct({},{type:t},e)]),s.apply(o,n)},e.map=o,e.events=function(e){var n=Object.keys(e.options.modes).reduce((function(t,n){return t[n]=Et(e.options.modes[n]),t}),{}),r={},i={},o={},s=null,a=null;o.drag=function(t,n){n({point:t.point,time:(new Date).getTime()})?(e.ui.queueMapClasses({mouse:w}),a.drag(t)):t.originalEvent.stopPropagation()},o.mousedrag=function(t){o.drag(t,(function(t){return!at(r,t)}))},o.touchdrag=function(t){o.drag(t,(function(t){return!ut(i,t)}))},o.mousemove=function(t){if(1===(void 0!==t.originalEvent.buttons?t.originalEvent.buttons:t.originalEvent.which))return o.mousedrag(t);var n=ot(t,e);t.featureTarget=n,a.mousemove(t)},o.mousedown=function(t){r={time:(new Date).getTime(),point:t.point};var n=ot(t,e);t.featureTarget=n,a.mousedown(t)},o.mouseup=function(t){var n=ot(t,e);t.featureTarget=n,at(r,{point:t.point,time:(new Date).getTime()})?a.click(t):a.mouseup(t)},o.mouseout=function(t){a.mouseout(t)},o.touchstart=function(t){if(t.originalEvent.preventDefault(),e.options.touchEnabled){i={time:(new Date).getTime(),point:t.point};var n=rt.touch(t,null,e)[0];t.featureTarget=n,a.touchstart(t)}},o.touchmove=function(t){if(t.originalEvent.preventDefault(),e.options.touchEnabled)return a.touchmove(t),o.touchdrag(t)},o.touchend=function(t){if(t.originalEvent.preventDefault(),e.options.touchEnabled){var n=rt.touch(t,null,e)[0];t.featureTarget=n,ut(i,{time:(new Date).getTime(),point:t.point})?a.tap(t):a.touchend(t)}};var u=function(t){return!(8===t||46===t||t>=48&&t<=57)};function l(r,i,o){void 0===o&&(o={}),a.stop();var u=n[r];if(void 0===u)throw new Error(r+" is not valid");s=r;var l=u(e,i);a=t(l,e),o.silent||e.map.fire(U,{mode:r}),e.store.setDirty(),e.store.render()}o.keydown=function(t){"mapboxgl-canvas"===(t.srcElement||t.target).classList[0]&&(8!==t.keyCode&&46!==t.keyCode||!e.options.controls.trash?u(t.keyCode)?a.keydown(t):49===t.keyCode&&e.options.controls.point?l(F.DRAW_POINT):50===t.keyCode&&e.options.controls.line_string?l(F.DRAW_LINE_STRING):51===t.keyCode&&e.options.controls.polygon&&l(F.DRAW_POLYGON):(t.preventDefault(),a.trash()))},o.keyup=function(t){u(t.keyCode)&&a.keyup(t)},o.zoomend=function(){e.store.changeZoom()},o.data=function(t){if("style"===t.dataType){var n=e.setup,r=e.map,i=e.options,o=e.store;i.styles.some((function(t){return r.getLayer(t.id)}))||(n.addLayers(),o.setDirty(),o.render())}};var c={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start:function(){s=e.options.defaultMode,a=t(n[s](e),e)},changeMode:l,actionable:function(t){var n=!1;Object.keys(t).forEach((function(e){if(void 0===c[e])throw new Error("Invalid action type");c[e]!==t[e]&&(n=!0),c[e]=t[e]})),n&&e.map.fire(q,{actions:c})},currentModeName:function(){return s},currentModeRender:function(t,e){return a.render(t,e)},fire:function(t,e){o[t]&&o[t](e)},addEventListeners:function(){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:function(){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:function(t){a.trash(t)},combineFeatures:function(){a.combineFeatures()},uncombineFeatures:function(){a.uncombineFeatures()},getMode:function(){return s}}}(e),e.ui=function(t){var e={},n=null,r={mode:null,feature:null,mouse:null},i={mode:null,feature:null,mouse:null};function o(t){i=Ct(i,t)}function s(){var e,n;if(t.container){var o=[],s=[];Mt.forEach((function(t){i[t]!==r[t]&&(o.push(t+"-"+r[t]),null!==i[t]&&s.push(t+"-"+i[t]))})),o.length>0&&(e=t.container.classList).remove.apply(e,o),s.length>0&&(n=t.container.classList).add.apply(n,s),r=Ct(r,i)}}function m(t,e){void 0===e&&(e={});var r=document.createElement("button");return r.className=u+" "+e.className,r.setAttribute("title",e.title),e.container.appendChild(r),r.addEventListener("click",(function(r){if(r.preventDefault(),r.stopPropagation(),r.target===n)return _(),void e.onDeactivate();v(t),e.onActivate()}),!0),r}function _(){n&&(n.classList.remove(y),n=null)}function v(t){_();var r=e[t];r&&r&&"trash"!==t&&(r.classList.add(y),n=r)}return{setActiveButton:v,queueMapClasses:o,updateMapClasses:s,clearMapClasses:function(){o({mode:null,feature:null,mouse:null}),s()},addButtons:function(){var n=t.options.controls,r=document.createElement("div");return r.className=g+" "+a,n?(n[S.LINE]&&(e[S.LINE]=m(S.LINE,{container:r,className:l,title:"LineString tool "+(t.options.keybindings?"(l)":""),onActivate:function(){return t.events.changeMode(F.DRAW_LINE_STRING)},onDeactivate:function(){return t.events.trash()}})),n[S.POLYGON]&&(e[S.POLYGON]=m(S.POLYGON,{container:r,className:c,title:"Polygon tool "+(t.options.keybindings?"(p)":""),onActivate:function(){return t.events.changeMode(F.DRAW_POLYGON)},onDeactivate:function(){return t.events.trash()}})),n[S.POINT]&&(e[S.POINT]=m(S.POINT,{container:r,className:h,title:"Marker tool "+(t.options.keybindings?"(m)":""),onActivate:function(){return t.events.changeMode(F.DRAW_POINT)},onDeactivate:function(){return t.events.trash()}})),n.trash&&(e.trash=m("trash",{container:r,className:p,title:"Delete",onActivate:function(){t.events.trash()}})),n.combine_features&&(e.combine_features=m("combineFeatures",{container:r,className:f,title:"Combine",onActivate:function(){t.events.combineFeatures()}})),n.uncombine_features&&(e.uncombine_features=m("uncombineFeatures",{container:r,className:d,title:"Uncombine",onActivate:function(){t.events.uncombineFeatures()}})),r):r},removeButtons:function(){Object.keys(e).forEach((function(t){var n=e[t];n.parentNode&&n.parentNode.removeChild(n),delete e[t]}))}}}(e),e.container=o.getContainer(),e.store=new It(e),n=e.ui.addButtons(),e.options.boxSelect&&(o.boxZoom.disable(),o.dragPan.disable(),o.dragPan.enable()),o.loaded()?i.connect():(o.on("load",i.connect),r=setInterval((function(){o.loaded()&&i.connect()}),16)),e.events.start(),n},addLayers:function(){e.map.addSource(v,{data:{type:L,features:[]},type:"geojson"}),e.map.addSource(_,{data:{type:L,features:[]},type:"geojson"}),e.options.styles.forEach((function(t){e.map.addLayer(t)})),e.store.setDirty(!0),e.store.render()},removeLayers:function(){e.options.styles.forEach((function(t){e.map.getLayer(t.id)&&e.map.removeLayer(t.id)})),e.map.getSource(v)&&e.map.removeSource(v),e.map.getSource(_)&&e.map.removeSource(_)}};return e.setup=i,i}function Lt(t){return function(e){var n=e.featureTarget;return!!n&&!!n.properties&&n.properties.meta===t}}function Ot(t){return!!t.featureTarget&&!!t.featureTarget.properties&&t.featureTarget.properties.active===W&&t.featureTarget.properties.meta===$}function Tt(t){return!!t.featureTarget&&!!t.featureTarget.properties&&t.featureTarget.properties.active===K&&t.featureTarget.properties.meta===$}function At(t){return void 0===t.featureTarget}function Rt(t){var e=t.featureTarget;return!!e&&!!e.properties&&e.properties.meta===H}function Ft(t){return!!t.originalEvent&&!0===t.originalEvent.shiftKey}function Dt(t){return 27===t.keyCode}function kt(t){return 13===t.keyCode}var Gt=jt;function jt(t,e){this.x=t,this.y=e}function Ut(t,e){var n=e.getBoundingClientRect();return new Gt(t.clientX-n.left-(e.clientLeft||0),t.clientY-n.top-(e.clientTop||0))}function qt(t,e,n,r){return{type:C,properties:{meta:H,parent:t,coord_path:n,active:r?W:K},geometry:{type:N,coordinates:e}}}function Bt(t,e,n){void 0===e&&(e={}),void 0===n&&(n=null);var r,i=t.geometry,o=i.type,s=i.coordinates,a=t.properties&&t.properties.id,u=[];function l(t,n){var r="",i=null;t.forEach((function(t,o){var s=null!=n?n+"."+o:String(o),l=qt(a,t,s,c(s));if(e.midpoints&&i){var h=function(t,e,n){var r=e.geometry.coordinates,i=n.geometry.coordinates;if(r[1]>85||r[1]<-85||i[1]>85||i[1]<-85)return null;var o={lng:(r[0]+i[0])/2,lat:(r[1]+i[1])/2};return{type:C,properties:{meta:J,parent:t,lng:o.lng,lat:o.lat,coord_path:n.properties.coord_path},geometry:{type:N,coordinates:[o.lng,o.lat]}}}(a,i,l);h&&u.push(h)}i=l;var p=JSON.stringify(t);r!==p&&u.push(l),0===o&&(r=p)}))}function c(t){return!!e.selectedPaths&&-1!==e.selectedPaths.indexOf(t)}return o===N?u.push(qt(a,s,n,c(n))):o===P?s.forEach((function(t,e){l(t,null!==n?n+"."+e:String(e))})):o===M?l(s,n):0===o.indexOf(O)&&(r=o.replace(O,""),s.forEach((function(n,i){var o={type:C,properties:t.properties,geometry:{type:r,coordinates:n}};u=u.concat(Bt(o,e,i))}))),u}jt.prototype={clone:function(){return new jt(this.x,this.y)},add:function(t){return this.clone()._add(t)},sub:function(t){return this.clone()._sub(t)},multByPoint:function(t){return this.clone()._multByPoint(t)},divByPoint:function(t){return this.clone()._divByPoint(t)},mult:function(t){return this.clone()._mult(t)},div:function(t){return this.clone()._div(t)},rotate:function(t){return this.clone()._rotate(t)},rotateAround:function(t,e){return this.clone()._rotateAround(t,e)},matMult:function(t){return this.clone()._matMult(t)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(t){return this.x===t.x&&this.y===t.y},dist:function(t){return Math.sqrt(this.distSqr(t))},distSqr:function(t){var e=t.x-this.x,n=t.y-this.y;return e*e+n*n},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(t){return Math.atan2(this.y-t.y,this.x-t.x)},angleWith:function(t){return this.angleWithSep(t.x,t.y)},angleWithSep:function(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)},_matMult:function(t){var e=t[0]*this.x+t[1]*this.y,n=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=n,this},_add:function(t){return this.x+=t.x,this.y+=t.y,this},_sub:function(t){return this.x-=t.x,this.y-=t.y,this},_mult:function(t){return this.x*=t,this.y*=t,this},_div:function(t){return this.x/=t,this.y/=t,this},_multByPoint:function(t){return this.x*=t.x,this.y*=t.y,this},_divByPoint:function(t){return this.x/=t.x,this.y/=t.y,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var t=this.y;return this.y=this.x,this.x=-t,this},_rotate:function(t){var e=Math.cos(t),n=Math.sin(t),r=e*this.x-n*this.y,i=n*this.x+e*this.y;return this.x=r,this.y=i,this},_rotateAround:function(t,e){var n=Math.cos(t),r=Math.sin(t),i=e.x+n*(this.x-e.x)-r*(this.y-e.y),o=e.y+r*(this.x-e.x)+n*(this.y-e.y);return this.x=i,this.y=o,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},jt.convert=function(t){return t instanceof jt?t:Array.isArray(t)?new jt(t[0],t[1]):t};var Vt=function(t){setTimeout((function(){t.map&&t.map.doubleClickZoom&&t._ctx&&t._ctx.store&&t._ctx.store.getInitialConfigValue&&t._ctx.store.getInitialConfigValue("doubleClickZoom")&&t.map.doubleClickZoom.enable()}),0)},zt=function(t){setTimeout((function(){t.map&&t.map.doubleClickZoom&&t.map.doubleClickZoom.disable()}),0)},Yt=function(t){if(!t||!t.type)return null;var e=Xt[t.type];return e?"geometry"===e?{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:t}]}:"feature"===e?{type:"FeatureCollection",features:[t]}:"featurecollection"===e?t:void 0:null},Xt={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};function $t(t){switch(t&&t.type||null){case"FeatureCollection":return t.features=t.features.reduce((function(t,e){return t.concat($t(e))}),[]),t;case"Feature":return t.geometry?$t(t.geometry).map((function(e){var n={type:"Feature",properties:JSON.parse(JSON.stringify(t.properties)),geometry:e};return void 0!==t.id&&(n.id=t.id),n})):[t];case"MultiPoint":return t.coordinates.map((function(t){return{type:"Point",coordinates:t}}));case"MultiPolygon":return t.coordinates.map((function(t){return{type:"Polygon",coordinates:t}}));case"MultiLineString":return t.coordinates.map((function(t){return{type:"LineString",coordinates:t}}));case"GeometryCollection":return t.geometries.map($t).reduce((function(t,e){return t.concat(e)}),[]);case"Point":case"Polygon":case"LineString":return[t]}}var Jt=function(t){if(!t)return[];var e=$t(Yt(t)),n=[];return e.features.forEach((function(t){t.geometry&&(n=n.concat(function t(e){return Array.isArray(e)&&e.length&&"number"==typeof e[0]?[e]:e.reduce((function(e,n){return Array.isArray(n)&&Array.isArray(n[0])?e.concat(t(n)):(e.push(n),e)}),[])}(t.geometry.coordinates)))})),n},Ht=lt((function(t){var e=t.exports=function(t){return new n(t)};function n(t){this.value=t}function r(t,e,n){var r=[],s=[],c=!0;return function t(h){var p=n?i(h):h,f={},d=!0,g={node:p,node_:h,path:[].concat(r),parent:s[s.length-1],parents:s,key:r.slice(-1)[0],isRoot:0===r.length,level:r.length,circular:null,update:function(t,e){g.isRoot||(g.parent.node[g.key]=t),g.node=t,e&&(d=!1)},delete:function(t){delete g.parent.node[g.key],t&&(d=!1)},remove:function(t){a(g.parent.node)?g.parent.node.splice(g.key,1):delete g.parent.node[g.key],t&&(d=!1)},keys:null,before:function(t){f.before=t},after:function(t){f.after=t},pre:function(t){f.pre=t},post:function(t){f.post=t},stop:function(){c=!1},block:function(){d=!1}};if(!c)return g;function y(){if("object"==typeof g.node&&null!==g.node){g.keys&&g.node_===g.node||(g.keys=o(g.node)),g.isLeaf=0==g.keys.length;for(var t=0;t<s.length;t++)if(s[t].node_===h){g.circular=s[t];break}}else g.isLeaf=!0,g.keys=null;g.notLeaf=!g.isLeaf,g.notRoot=!g.isRoot}y();var m=e.call(g,g.node);return void 0!==m&&g.update&&g.update(m),f.before&&f.before.call(g,g.node),d?("object"!=typeof g.node||null===g.node||g.circular||(s.push(g),y(),u(g.keys,(function(e,i){r.push(e),f.pre&&f.pre.call(g,g.node[e],e);var o=t(g.node[e]);n&&l.call(g.node,e)&&(g.node[e]=o.node),o.isLast=i==g.keys.length-1,o.isFirst=0==i,f.post&&f.post.call(g,o),r.pop()})),s.pop()),f.after&&f.after.call(g,g.node),g):g}(t).node}function i(t){if("object"==typeof t&&null!==t){var e;if(a(t))e=[];else if("[object Date]"===s(t))e=new Date(t.getTime?t.getTime():t);else if(function(t){return"[object RegExp]"===s(t)}(t))e=new RegExp(t);else if(function(t){return"[object Error]"===s(t)}(t))e={message:t.message};else if(function(t){return"[object Boolean]"===s(t)}(t))e=new Boolean(t);else if(function(t){return"[object Number]"===s(t)}(t))e=new Number(t);else if(function(t){return"[object String]"===s(t)}(t))e=new String(t);else if(Object.create&&Object.getPrototypeOf)e=Object.create(Object.getPrototypeOf(t));else if(t.constructor===Object)e={};else{var n=t.constructor&&t.constructor.prototype||t.__proto__||{},r=function(){};r.prototype=n,e=new r}return u(o(t),(function(n){e[n]=t[n]})),e}return t}n.prototype.get=function(t){for(var e=this.value,n=0;n<t.length;n++){var r=t[n];if(!e||!l.call(e,r)){e=void 0;break}e=e[r]}return e},n.prototype.has=function(t){for(var e=this.value,n=0;n<t.length;n++){var r=t[n];if(!e||!l.call(e,r))return!1;e=e[r]}return!0},n.prototype.set=function(t,e){for(var n=this.value,r=0;r<t.length-1;r++){var i=t[r];l.call(n,i)||(n[i]={}),n=n[i]}return n[t[r]]=e,e},n.prototype.map=function(t){return r(this.value,t,!0)},n.prototype.forEach=function(t){return this.value=r(this.value,t,!1),this.value},n.prototype.reduce=function(t,e){var n=1===arguments.length,r=n?this.value:e;return this.forEach((function(e){this.isRoot&&n||(r=t.call(this,r,e))})),r},n.prototype.paths=function(){var t=[];return this.forEach((function(e){t.push(this.path)})),t},n.prototype.nodes=function(){var t=[];return this.forEach((function(e){t.push(this.node)})),t},n.prototype.clone=function(){var t=[],e=[];return function n(r){for(var s=0;s<t.length;s++)if(t[s]===r)return e[s];if("object"==typeof r&&null!==r){var a=i(r);return t.push(r),e.push(a),u(o(r),(function(t){a[t]=n(r[t])})),t.pop(),e.pop(),a}return r}(this.value)};var o=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e};function s(t){return Object.prototype.toString.call(t)}var a=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},u=function(t,e){if(t.forEach)return t.forEach(e);for(var n=0;n<t.length;n++)e(t[n],n,t)};u(o(n.prototype),(function(t){e[t]=function(e){var r=[].slice.call(arguments,1),i=new n(e);return i[t].apply(i,r)}}));var l=Object.hasOwnProperty||function(t,e){return e in t}})),Wt=Kt;function Kt(t){if(!(this instanceof Kt))return new Kt(t);this._bbox=t||[1/0,1/0,-1/0,-1/0],this._valid=!!t}Kt.prototype.include=function(t){return this._valid=!0,this._bbox[0]=Math.min(this._bbox[0],t[0]),this._bbox[1]=Math.min(this._bbox[1],t[1]),this._bbox[2]=Math.max(this._bbox[2],t[0]),this._bbox[3]=Math.max(this._bbox[3],t[1]),this},Kt.prototype.equals=function(t){var e;return e=t instanceof Kt?t.bbox():t,this._bbox[0]==e[0]&&this._bbox[1]==e[1]&&this._bbox[2]==e[2]&&this._bbox[3]==e[3]},Kt.prototype.center=function(t){return this._valid?[(this._bbox[0]+this._bbox[2])/2,(this._bbox[1]+this._bbox[3])/2]:null},Kt.prototype.union=function(t){var e;return this._valid=!0,e=t instanceof Kt?t.bbox():t,this._bbox[0]=Math.min(this._bbox[0],e[0]),this._bbox[1]=Math.min(this._bbox[1],e[1]),this._bbox[2]=Math.max(this._bbox[2],e[2]),this._bbox[3]=Math.max(this._bbox[3],e[3]),this},Kt.prototype.bbox=function(){return this._valid?this._bbox:null},Kt.prototype.contains=function(t){if(!t)return this._fastContains();if(!this._valid)return null;var e=t[0],n=t[1];return this._bbox[0]<=e&&this._bbox[1]<=n&&this._bbox[2]>=e&&this._bbox[3]>=n},Kt.prototype.intersect=function(t){return this._valid?(e=t instanceof Kt?t.bbox():t,!(this._bbox[0]>e[2]||this._bbox[2]<e[0]||this._bbox[3]<e[1]||this._bbox[1]>e[3])):null;var e},Kt.prototype._fastContains=function(){if(!this._valid)return new Function("return null;");var t="return "+this._bbox[0]+"<= ll[0] &&"+this._bbox[1]+"<= ll[1] &&"+this._bbox[2]+">= ll[0] &&"+this._bbox[3]+">= ll[1]";return new Function("ll",t)},Kt.prototype.polygon=function(){return this._valid?{type:"Polygon",coordinates:[[[this._bbox[0],this._bbox[1]],[this._bbox[2],this._bbox[1]],[this._bbox[2],this._bbox[3]],[this._bbox[0],this._bbox[3]],[this._bbox[0],this._bbox[1]]]]}:null};var Zt={features:["FeatureCollection"],coordinates:["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],geometry:["Feature"],geometries:["GeometryCollection"]},Qt=Object.keys(Zt),te=function(t){return ee(t).bbox()};function ee(t){for(var e=Wt(),n=Jt(t),r=0;r<n.length;r++)e.include(n[r]);return e}function ne(t,e){var n=-90,r=90,i=-90,o=90,s=270,a=-270;t.forEach((function(t){var e=te(t),u=e[1],l=e[3],c=e[0],h=e[2];u>n&&(n=u),l<r&&(r=l),l>i&&(i=l),u<o&&(o=u),c<s&&(s=c),h>a&&(a=h)}));var u=e;return n+u.lat>85&&(u.lat=85-n),i+u.lat>90&&(u.lat=90-i),r+u.lat<-85&&(u.lat=-85-r),o+u.lat<-90&&(u.lat=-90-o),s+u.lng<=-270&&(u.lng+=360*Math.ceil(Math.abs(u.lng)/360)),a+u.lng>=270&&(u.lng-=360*Math.ceil(Math.abs(u.lng)/360)),u}function re(t,e){var n=ne(t.map((function(t){return t.toGeoJSON()})),e);t.forEach((function(t){var e,r=t.getCoordinates(),i=function(t){var e={lng:t[0]+n.lng,lat:t[1]+n.lat};return[e.lng,e.lat]},o=function(t){return t.map((function(t){return i(t)}))};t.type===N?e=i(r):t.type===M||t.type===T?e=r.map(i):t.type===P||t.type===A?e=r.map(o):t.type===R&&(e=r.map((function(t){return t.map((function(t){return o(t)}))}))),t.incomingCoords(e)}))}te.polygon=function(t){return ee(t).polygon()},te.bboxify=function(t){return Ht(t).map((function(t){t&&Qt.some((function(e){return!!t[e]&&-1!==Zt[e].indexOf(t.type)}))&&(t.bbox=ee(t).bbox(),this.update(t))}))};var ie={onSetup:function(t){var e=this,n={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initiallySelectedFeatureIds:t.featureIds||[]};return this.setSelected(n.initiallySelectedFeatureIds.filter((function(t){return void 0!==e.getFeature(t)}))),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),n},fireUpdate:function(){this.map.fire(G,{action:Y,features:this.getSelected().map((function(t){return t.toGeoJSON()}))})},fireActionable:function(){var t=this,e=this.getSelected(),n=e.filter((function(e){return t.isInstanceOf("MultiFeature",e)})),r=!1;if(e.length>1){r=!0;var i=e[0].type.replace("Multi","");e.forEach((function(t){t.type.replace("Multi","")!==i&&(r=!1)}))}var o=n.length>0,s=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:o,trash:s})},getUniqueIds:function(t){return t.length?t.map((function(t){return t.properties.id})).filter((function(t){return void 0!==t})).reduce((function(t,e){return t.add(e),t}),new et).values():[]},stopExtendedInteractions:function(t){t.boxSelectElement&&(t.boxSelectElement.parentNode&&t.boxSelectElement.parentNode.removeChild(t.boxSelectElement),t.boxSelectElement=null),this.map.dragPan.enable(),t.boxSelecting=!1,t.canBoxSelect=!1,t.dragMoving=!1,t.canDragMove=!1},onStop:function(){Vt(this)},onMouseMove:function(t){return this.stopExtendedInteractions(t),!0},onMouseOut:function(t){return!t.dragMoving||this.fireUpdate()}};ie.onTap=ie.onClick=function(t,e){return At(e)?this.clickAnywhere(t,e):Lt(H)(e)?this.clickOnVertex(t,e):function(t){return!!t.featureTarget&&!!t.featureTarget.properties&&t.featureTarget.properties.meta===$}(e)?this.clickOnFeature(t,e):void 0},ie.clickAnywhere=function(t){var e=this,n=this.getSelectedIds();n.length&&(this.clearSelectedFeatures(),n.forEach((function(t){return e.doRender(t)}))),Vt(this),this.stopExtendedInteractions(t)},ie.clickOnVertex=function(t,e){this.changeMode(F.DIRECT_SELECT,{featureId:e.featureTarget.properties.parent,coordPath:e.featureTarget.properties.coord_path,startPos:e.lngLat}),this.updateUIClasses({mouse:E})},ie.startOnActiveFeature=function(t,e){this.stopExtendedInteractions(t),this.map.dragPan.disable(),this.doRender(e.featureTarget.properties.id),t.canDragMove=!0,t.dragMoveLocation=e.lngLat},ie.clickOnFeature=function(t,e){var n=this;zt(this),this.stopExtendedInteractions(t);var r=Ft(e),i=this.getSelectedIds(),o=e.featureTarget.properties.id,s=this.isSelected(o);if(!r&&s&&this.getFeature(o).type!==N)return this.changeMode(F.DIRECT_SELECT,{featureId:o});s&&r?(this.deselect(o),this.updateUIClasses({mouse:x}),1===i.length&&Vt(this)):!s&&r?(this.select(o),this.updateUIClasses({mouse:E})):s||r||(i.forEach((function(t){return n.doRender(t)})),this.setSelected(o),this.updateUIClasses({mouse:E})),this.doRender(o)},ie.onMouseDown=function(t,e){return Ot(e)?this.startOnActiveFeature(t,e):this.drawConfig.boxSelect&&function(t){return!!t.originalEvent&&!!t.originalEvent.shiftKey&&0===t.originalEvent.button}(e)?this.startBoxSelect(t,e):void 0},ie.startBoxSelect=function(t,e){this.stopExtendedInteractions(t),this.map.dragPan.disable(),t.boxSelectStartLocation=Ut(e.originalEvent,this.map.getContainer()),t.canBoxSelect=!0},ie.onTouchStart=function(t,e){if(Ot(e))return this.startOnActiveFeature(t,e)},ie.onDrag=function(t,e){return t.canDragMove?this.dragMove(t,e):this.drawConfig.boxSelect&&t.canBoxSelect?this.whileBoxSelect(t,e):void 0},ie.whileBoxSelect=function(t,e){t.boxSelecting=!0,this.updateUIClasses({mouse:b}),t.boxSelectElement||(t.boxSelectElement=document.createElement("div"),t.boxSelectElement.classList.add(m),this.map.getContainer().appendChild(t.boxSelectElement));var n=Ut(e.originalEvent,this.map.getContainer()),r=Math.min(t.boxSelectStartLocation.x,n.x),i=Math.max(t.boxSelectStartLocation.x,n.x),o=Math.min(t.boxSelectStartLocation.y,n.y),s=Math.max(t.boxSelectStartLocation.y,n.y),a="translate("+r+"px, "+o+"px)";t.boxSelectElement.style.transform=a,t.boxSelectElement.style.WebkitTransform=a,t.boxSelectElement.style.width=i-r+"px",t.boxSelectElement.style.height=s-o+"px"},ie.dragMove=function(t,e){t.dragMoving=!0,e.originalEvent.stopPropagation();var n={lng:e.lngLat.lng-t.dragMoveLocation.lng,lat:e.lngLat.lat-t.dragMoveLocation.lat};re(this.getSelected(),n),t.dragMoveLocation=e.lngLat},ie.onMouseUp=function(t,e){var n=this;if(t.dragMoving)this.fireUpdate();else if(t.boxSelecting){var r=[t.boxSelectStartLocation,Ut(e.originalEvent,this.map.getContainer())],i=this.featuresAt(null,r,"click"),o=this.getUniqueIds(i).filter((function(t){return!n.isSelected(t)}));o.length&&(this.select(o),o.forEach((function(t){return n.doRender(t)})),this.updateUIClasses({mouse:E}))}this.stopExtendedInteractions(t)},ie.toDisplayFeatures=function(t,e,n){e.properties.active=this.isSelected(e.properties.id)?W:K,n(e),this.fireActionable(),e.properties.active===W&&e.geometry.type!==N&&Bt(e).forEach(n)},ie.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},ie.onCombineFeatures=function(){var t=this.getSelected();if(!(0===t.length||t.length<2)){for(var e=[],n=[],r=t[0].type.replace("Multi",""),i=0;i<t.length;i++){var o=t[i];if(o.type.replace("Multi","")!==r)return;o.type.includes("Multi")?o.getCoordinates().forEach((function(t){e.push(t)})):e.push(o.getCoordinates()),n.push(o.toGeoJSON())}if(n.length>1){var s=this.newFeature({type:C,properties:n[0].properties,geometry:{type:"Multi"+r,coordinates:e}});this.addFeature(s),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([s.id]),this.map.fire(V,{createdFeatures:[s.toGeoJSON()],deletedFeatures:n})}this.fireActionable()}},ie.onUncombineFeatures=function(){var t=this,e=this.getSelected();if(0!==e.length){for(var n=[],r=[],i=function(i){var o=e[i];t.isInstanceOf("MultiFeature",o)&&(o.getFeatures().forEach((function(e){t.addFeature(e),e.properties=o.properties,n.push(e.toGeoJSON()),t.select([e.id])})),t.deleteFeature(o.id,{silent:!0}),r.push(o.toGeoJSON()))},o=0;o<e.length;o++)i(o);n.length>1&&this.map.fire(z,{createdFeatures:n,deletedFeatures:r}),this.fireActionable()}};var oe=Lt(H),se=Lt(J),ae={fireUpdate:function(){this.map.fire(G,{action:X,features:this.getSelected().map((function(t){return t.toGeoJSON()}))})},fireActionable:function(t){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:t.selectedCoordPaths.length>0})},startDragging:function(t,e){this.map.dragPan.disable(),t.canDragMove=!0,t.dragMoveLocation=e.lngLat},stopDragging:function(t){this.map.dragPan.enable(),t.dragMoving=!1,t.canDragMove=!1,t.dragMoveLocation=null},onVertex:function(t,e){this.startDragging(t,e);var n=e.featureTarget.properties,r=t.selectedCoordPaths.indexOf(n.coord_path);Ft(e)||-1!==r?Ft(e)&&-1===r&&t.selectedCoordPaths.push(n.coord_path):t.selectedCoordPaths=[n.coord_path];var i=this.pathsToCoordinates(t.featureId,t.selectedCoordPaths);this.setSelectedCoordinates(i)},onMidpoint:function(t,e){this.startDragging(t,e);var n=e.featureTarget.properties;t.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),t.selectedCoordPaths=[n.coord_path]},pathsToCoordinates:function(t,e){return e.map((function(e){return{feature_id:t,coord_path:e}}))},onFeature:function(t,e){0===t.selectedCoordPaths.length?this.startDragging(t,e):this.stopDragging(t)},dragFeature:function(t,e,n){re(this.getSelected(),n),t.dragMoveLocation=e.lngLat},dragVertex:function(t,e,n){for(var r=t.selectedCoordPaths.map((function(e){return t.feature.getCoordinate(e)})),i=ne(r.map((function(t){return{type:C,properties:{},geometry:{type:N,coordinates:t}}})),n),o=0;o<r.length;o++){var s=r[o];t.feature.updateCoordinate(t.selectedCoordPaths[o],s[0]+i.lng,s[1]+i.lat)}},clickNoTarget:function(){this.changeMode(F.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(F.SIMPLE_SELECT)},clickActiveFeature:function(t){t.selectedC