UNPKG

@mapbox/mapbox-gl-draw

Version:

A drawing component for Mapbox GL JS

1 lines 62.3 kB
var e,t;e=this,t=function(){const e={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"},t={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},o={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},n={POLYGON:"polygon",LINE:"line_string",POINT:"point"},r={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"},i={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},s={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"},a={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},c={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},u={ACTIVE:"true",INACTIVE:"false"},l=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"],d=-85,p=85;var h=Object.freeze({__proto__:null,LAT_MAX:90,LAT_MIN:-90,LAT_RENDERED_MAX:p,LAT_RENDERED_MIN:d,LNG_MAX:270,LNG_MIN:-270,activeStates:u,classes:e,cursors:o,events:s,geojsonTypes:r,interactions:l,meta:c,modes:i,sources:t,types:n,updateActions:a});function f(e){return function(t){const o=t.featureTarget;return!!o&&!!o.properties&&o.properties.meta===e}}function g(e){return!!e.originalEvent&&!!e.originalEvent.shiftKey&&0===e.originalEvent.button}function y(e){return!!e.featureTarget&&!!e.featureTarget.properties&&e.featureTarget.properties.active===u.ACTIVE&&e.featureTarget.properties.meta===c.FEATURE}function m(e){return!!e.featureTarget&&!!e.featureTarget.properties&&e.featureTarget.properties.active===u.INACTIVE&&e.featureTarget.properties.meta===c.FEATURE}function E(e){return void 0===e.featureTarget}function C(e){return!!e.featureTarget&&!!e.featureTarget.properties&&e.featureTarget.properties.meta===c.FEATURE}function T(e){const t=e.featureTarget;return!!t&&!!t.properties&&t.properties.meta===c.VERTEX}function _(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey}function v(e){return"Escape"===e.key||27===e.keyCode}function I(e){return"Enter"===e.key||13===e.keyCode}function S(e){return"Backspace"===e.key||8===e.keyCode}function O(e){return"Delete"===e.key||46===e.keyCode}function M(e){return"1"===e.key||49===e.keyCode}function L(e){return"2"===e.key||50===e.keyCode}function N(e){return"3"===e.key||51===e.keyCode}function b(e){const t=e.key||String.fromCharCode(e.keyCode);return t>="0"&&t<="9"}var P=Object.freeze({__proto__:null,isActiveFeature:y,isBackspaceKey:S,isDeleteKey:O,isDigit1Key:M,isDigit2Key:L,isDigit3Key:N,isDigitKey:b,isEnterKey:I,isEscapeKey:v,isFeature:C,isInactiveFeature:m,isOfMetaType:f,isShiftDown:_,isShiftMousedown:g,isTrue:function(){return!0},isVertex:T,noTarget:E});function x(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var A,F,w={},R={};function D(){return A||(A=1,R.RADIUS=6378137,R.FLATTENING=1/298.257223563,R.POLAR_RADIUS=6356752.3142),R}var U=function(){if(F)return w;F=1;var e=D();function t(e){var t=0;if(e&&e.length>0){t+=Math.abs(o(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(o(e[n]))}return t}function o(t){var o,r,i,s,a,c,u=0,l=t.length;if(l>2){for(c=0;c<l;c++)c===l-2?(i=l-2,s=l-1,a=0):c===l-1?(i=l-1,s=0,a=1):(i=c,s=c+1,a=c+2),o=t[i],r=t[s],u+=(n(t[a][0])-n(o[0]))*Math.sin(n(r[1]));u=u*e.RADIUS*e.RADIUS/2}return u}function n(e){return e*Math.PI/180}return w.geometry=function e(o){var n,r=0;switch(o.type){case"Polygon":return t(o.coordinates);case"MultiPolygon":for(n=0;n<o.coordinates.length;n++)r+=t(o.coordinates[n]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<o.geometries.length;n++)r+=e(o.geometries[n]);return r}},w.ring=o,w}(),k=x(U);const V={Point:0,LineString:1,MultiLineString:1,Polygon:2};function G(e,t){const o=V[e.geometry.type]-V[t.geometry.type];return 0===o&&e.geometry.type===r.POLYGON?e.area-t.area:o}function B(e){return e.map((e=>(e.geometry.type===r.POLYGON&&(e.area=k.geometry({type:r.FEATURE,property:{},geometry:e.geometry})),e))).sort(G).map((e=>(delete e.area,e)))}function j(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function J(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(let t=0,o=e.length;t<o;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}J.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},J.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},J.prototype.has=function(e){return!("string"!=typeof e&&"number"!=typeof e||void 0===this._items[e]&&void 0===this._nums[e])},J.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))},J.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const $=[c.FEATURE,c.MIDPOINT,c.VERTEX];var Y={click:function(e,t,o){return H(e,t,o,o.options.clickBuffer)},touch:function(e,t,o){return H(e,t,o,o.options.touchBuffer)}};function H(e,t,o,n){if(null===o.map)return[];const r=e?j(e,n):t,i={};o.options.styles&&(i.layers=o.options.styles.map((e=>e.id)).filter((e=>null!=o.map.getLayer(e))));const s=o.map.queryRenderedFeatures(r,i).filter((e=>-1!==$.indexOf(e.properties.meta))),a=new J,c=[];return s.forEach((e=>{const t=e.properties.id;a.has(t)||(a.add(t),c.push(e))})),B(c)}function X(e,t){const n=Y.click(e,null,t),r={mouse:o.NONE};return n[0]&&(r.mouse=n[0].properties.active===u.ACTIVE?o.MOVE:o.POINTER,r.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(r.mouse=o.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function q(e,t){const o=e.x-t.x,n=e.y-t.y;return Math.sqrt(o*o+n*n)}const K=4,Z=12,W=500;function z(e,t,o={}){const n=null!=o.fineTolerance?o.fineTolerance:K,r=null!=o.grossTolerance?o.grossTolerance:Z,i=null!=o.interval?o.interval:W;e.point=e.point||t.point,e.time=e.time||t.time;const s=q(e.point,t.point);return s<n||s<r&&t.time-e.time<i}const Q=25,ee=250;function te(e,t,o={}){const n=null!=o.tolerance?o.tolerance:Q,r=null!=o.interval?o.interval:ee;return e.point=e.point||t.point,e.time=e.time||t.time,q(e.point,t.point)<n&&t.time-e.time<r}const oe=function(e,t){const o={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(e,t,n){if(void 0===o[e])throw new Error(`Invalid event type: ${e}`);o[e].push({selector:t,fn:n})},render(e){t.store.featureChanged(e)}},r=function(e,r){const i=o[e];let s=i.length;for(;s--;){const e=i[s];if(e.selector(r)){e.fn.call(n,r)||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){r("drag",e)},click(e){r("click",e)},mousemove(e){r("mousemove",e)},mousedown(e){r("mousedown",e)},mouseup(e){r("mouseup",e)},mouseout(e){r("mouseout",e)},keydown(e){r("keydown",e)},keyup(e){r("keyup",e)},touchstart(e){r("touchstart",e)},touchmove(e){r("touchmove",e)},touchend(e){r("touchend",e)},tap(e){r("tap",e)}}},ne=((e,t=21)=>(o=t)=>{let n="",r=0|o;for(;r--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function re(){return ne()}const ie=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||re(),this.type=t.geometry.type};ie.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ie.prototype.incomingCoords=function(e){this.setCoordinates(e)},ie.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ie.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ie.prototype.setProperty=function(e,t){this.properties[e]=t},ie.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:r.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ie.prototype.internal=function(e){const t={id:this.id,meta:c.FEATURE,"meta:type":this.type,active:u.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const e in this.properties)t[`user_${e}`]=this.properties[e];return{type:r.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const se=function(e,t){ie.call(this,e,t)};(se.prototype=Object.create(ie.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},se.prototype.updateCoordinate=function(e,t,o){this.coordinates=3===arguments.length?[t,o]:[e,t],this.changed()},se.prototype.getCoordinate=function(){return this.getCoordinates()};const ae=function(e,t){ie.call(this,e,t)};(ae.prototype=Object.create(ie.prototype)).isValid=function(){return this.coordinates.length>1},ae.prototype.addCoordinate=function(e,t,o){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,o])},ae.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},ae.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},ae.prototype.updateCoordinate=function(e,t,o){const n=parseInt(e,10);this.coordinates[n]=[t,o],this.changed()};const ce=function(e,t){ie.call(this,e,t),this.coordinates=this.coordinates.map((e=>e.slice(0,-1)))};(ce.prototype=Object.create(ie.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every((e=>e.length>2))},ce.prototype.incomingCoords=function(e){this.coordinates=e.map((e=>e.slice(0,-1))),this.changed()},ce.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ce.prototype.addCoordinate=function(e,t,o){this.changed();const n=e.split(".").map((e=>parseInt(e,10)));this.coordinates[n[0]].splice(n[1],0,[t,o])},ce.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map((e=>parseInt(e,10))),o=this.coordinates[t[0]];o&&(o.splice(t[1],1),o.length<3&&this.coordinates.splice(t[0],1))},ce.prototype.getCoordinate=function(e){const t=e.split(".").map((e=>parseInt(e,10))),o=this.coordinates[t[0]];return JSON.parse(JSON.stringify(o[t[1]]))},ce.prototype.getCoordinates=function(){return this.coordinates.map((e=>e.concat([e[0]])))},ce.prototype.updateCoordinate=function(e,t,o){this.changed();const n=e.split("."),r=parseInt(n[0],10),i=parseInt(n[1],10);void 0===this.coordinates[r]&&(this.coordinates[r]=[]),this.coordinates[r][i]=[t,o]};const ue={MultiPoint:se,MultiLineString:ae,MultiPolygon:ce},le=(e,t,o,n,r)=>{const i=o.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,n,r)},de=function(e,t){if(ie.call(this,e,t),delete this.coordinates,this.model=ue[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 pe(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}(de.prototype=Object.create(ie.prototype))._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map((e=>new t(this.ctx,{id:re(),type:r.FEATURE,properties:{},geometry:{coordinates:e,type:this.type.replace("Multi","")}})))},de.prototype.isValid=function(){return this.features.every((e=>e.isValid()))},de.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},de.prototype.getCoordinate=function(e){return le(this.features,"getCoordinate",e)},de.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map((e=>e.type===r.POLYGON?e.getCoordinates():e.coordinates))))},de.prototype.updateCoordinate=function(e,t,o){le(this.features,"updateCoordinate",e,t,o),this.changed()},de.prototype.addCoordinate=function(e,t,o){le(this.features,"addCoordinate",e,t,o),this.changed()},de.prototype.removeCoordinate=function(e){le(this.features,"removeCoordinate",e),this.changed()},de.prototype.getFeatures=function(){return this.features},pe.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},pe.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)),{})},pe.prototype.getSelected=function(){return this._ctx.store.getSelected()},pe.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},pe.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},pe.prototype.getFeature=function(e){return this._ctx.store.get(e)},pe.prototype.select=function(e){return this._ctx.store.select(e)},pe.prototype.deselect=function(e){return this._ctx.store.deselect(e)},pe.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},pe.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},pe.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},pe.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},pe.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},pe.prototype.changeMode=function(e,t={},o={}){return this._ctx.events.changeMode(e,t,o)},pe.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},pe.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},pe.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},pe.prototype.featuresAt=function(e,t,o="click"){if("click"!==o&&"touch"!==o)throw new Error("invalid buffer type");return Y[o](e,t,this._ctx)},pe.prototype.newFeature=function(e){const t=e.geometry.type;return t===r.POINT?new se(this._ctx,e):t===r.LINE_STRING?new ae(this._ctx,e):t===r.POLYGON?new ce(this._ctx,e):new de(this._ctx,e)},pe.prototype.isInstanceOf=function(e,t){if(e===r.POINT)return t instanceof se;if(e===r.LINE_STRING)return t instanceof ae;if(e===r.POLYGON)return t instanceof ce;if("MultiFeature"===e)return t instanceof de;throw new Error(`Unknown feature class: ${e}`)},pe.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},pe.prototype.onSetup=function(){},pe.prototype.onDrag=function(){},pe.prototype.onClick=function(){},pe.prototype.onMouseMove=function(){},pe.prototype.onMouseDown=function(){},pe.prototype.onMouseUp=function(){},pe.prototype.onMouseOut=function(){},pe.prototype.onKeyUp=function(){},pe.prototype.onKeyDown=function(){},pe.prototype.onTouchStart=function(){},pe.prototype.onTouchMove=function(){},pe.prototype.onTouchEnd=function(){},pe.prototype.onTap=function(){},pe.prototype.onStop=function(){},pe.prototype.onTrash=function(){},pe.prototype.onCombineFeature=function(){},pe.prototype.onUncombineFeature=function(){},pe.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const he={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},fe=Object.keys(he);function ge(e){const t=Object.keys(e);return function(o,n={}){let r={};const i=t.reduce(((t,o)=>(t[o]=e[o],t)),new pe(o));return{start(){r=i.onSetup(n),fe.forEach((t=>{const o=he[t];let n=()=>!1;var s;e[o]&&(n=()=>!0),this.on(t,n,(s=o,e=>i[s](r,e)))}))},stop(){i.onStop(r)},trash(){i.onTrash(r)},combineFeatures(){i.onCombineFeatures(r)},uncombineFeatures(){i.onUncombineFeatures(r)},render(e,t){i.toDisplayFeatures(r,e,t)}}}}function ye(e){return[].concat(e).filter((e=>void 0!==e))}function me(){const e=this;if(!e.ctx.map||void 0===e.ctx.map.getSource(t.HOT))return u();const o=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:o});let n=[],i=[];e.isDirty?i=e.getAllIds():(n=e.getChangedIds().filter((t=>void 0!==e.get(t))),i=e.sources.hot.filter((t=>t.properties.id&&-1===n.indexOf(t.properties.id)&&void 0!==e.get(t.properties.id))).map((e=>e.properties.id))),e.sources.hot=[];const s=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter((e=>{const t=e.properties.id||e.properties.parent;return-1===n.indexOf(t)}));const a=s!==e.sources.cold.length||i.length>0;function c(t,n){const r=e.get(t).internal(o);e.ctx.events.currentModeRender(r,(t=>{t.properties.mode=o,e.sources[n].push(t)}))}function u(){e.isDirty=!1,e.clearChangedIds()}n.forEach((e=>c(e,"hot"))),i.forEach((e=>c(e,"cold"))),a&&e.ctx.map.getSource(t.COLD).setData({type:r.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(t.HOT).setData({type:r.FEATURE_COLLECTION,features:e.sources.hot}),u()}function Ee(e){let t;this._features={},this._featureIds=new J,this._selectedFeatureIds=new J,this._selectedCoordinates=[],this._changedFeatureIds=new J,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=()=>{t||(t=requestAnimationFrame((()=>{t=null,me.call(this),this._emitSelectionChange&&(this.ctx.events.fire(s.SELECTION_CHANGE,{features:this.getSelected().map((e=>e.toGeoJSON())),points:this.getSelectedCoordinates().map((e=>({type:r.FEATURE,properties:{},geometry:{type:r.POINT,coordinates:e.coordinates}})))}),this._emitSelectionChange=!1),this.ctx.events.fire(s.RENDER,{})})))},this.isDirty=!1}function Ce(e,t={}){const o=e._selectedCoordinates.filter((t=>e._selectedFeatureIds.has(t.feature_id)));e._selectedCoordinates.length===o.length||t.silent||(e._emitSelectionChange=!0),e._selectedCoordinates=o}Ee.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Ee.prototype.setDirty=function(){return this.isDirty=!0,this},Ee.prototype.featureCreated=function(e,t={}){if(this._changedFeatureIds.add(e),!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)){const t=this.get(e);this.ctx.events.fire(s.CREATE,{features:[t.toGeoJSON()]})}return this},Ee.prototype.featureChanged=function(e,t={}){return this._changedFeatureIds.add(e),!0!==(null!=t.silent?t.silent:this.ctx.options.suppressAPIEvents)&&this.ctx.events.fire(s.UPDATE,{action:t.action?t.action:a.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Ee.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Ee.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Ee.prototype.getAllIds=function(){return this._featureIds.values()},Ee.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Ee.prototype.delete=function(e,t={}){const o=[];return ye(e).forEach((e=>{this._featureIds.has(e)&&(this._featureIds.delete(e),this._selectedFeatureIds.delete(e),t.silent||-1===o.indexOf(this._features[e])&&o.push(this._features[e].toGeoJSON()),delete this._features[e],this.isDirty=!0)})),o.length&&this.ctx.events.fire(s.DELETE,{features:o}),Ce(this,t),this},Ee.prototype.get=function(e){return this._features[e]},Ee.prototype.getAll=function(){return Object.keys(this._features).map((e=>this._features[e]))},Ee.prototype.select=function(e,t={}){return ye(e).forEach((e=>{this._selectedFeatureIds.has(e)||(this._selectedFeatureIds.add(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))})),this},Ee.prototype.deselect=function(e,t={}){return ye(e).forEach((e=>{this._selectedFeatureIds.has(e)&&(this._selectedFeatureIds.delete(e),this._changedFeatureIds.add(e),t.silent||(this._emitSelectionChange=!0))})),Ce(this,t),this},Ee.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Ee.prototype.setSelected=function(e,t={}){return e=ye(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},Ee.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Ee.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Ee.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Ee.prototype.getSelected=function(){return this.getSelectedIds().map((e=>this.get(e)))},Ee.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map((e=>({coordinates:this.get(e.feature_id).getCoordinate(e.coord_path)})))},Ee.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Ee.prototype.setFeatureProperty=function(e,t,o,n={}){this.get(e).setProperty(t,o),this.featureChanged(e,{silent:n.silent,action:a.CHANGE_PROPERTIES})},Ee.prototype.storeMapConfig=function(){l.forEach((e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())}))},Ee.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach((e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()}))},Ee.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]};const Te=["mode","feature","mouse"];function _e(a){let c=null,u=null;const l={onRemove(){return a.map.off("load",l.connect),clearInterval(u),l.removeLayers(),a.store.restoreMapConfig(),a.ui.removeButtons(),a.events.removeEventListeners(),a.ui.clearMapClasses(),a.boxZoomInitial&&a.map.boxZoom.enable(),a.map=null,a.container=null,a.store=null,c&&c.parentNode&&c.parentNode.removeChild(c),c=null,this},connect(){a.map.off("load",l.connect),clearInterval(u),l.addLayers(),a.store.storeMapConfig(),a.events.addEventListeners()},onAdd(t){if(a.map=t,a.events=function(t){const n=Object.keys(t.options.modes).reduce(((e,o)=>(e[o]=ge(t.options.modes[o]),e)),{});let r={},a={};const c={};let u=null,l=null;c.drag=function(e,n){n({point:e.point,time:(new Date).getTime()})?(t.ui.queueMapClasses({mouse:o.DRAG}),l.drag(e)):e.originalEvent.stopPropagation()},c.mousedrag=function(e){c.drag(e,(e=>!z(r,e)))},c.touchdrag=function(e){c.drag(e,(e=>!te(a,e)))},c.mousemove=function(e){if(1===(void 0!==e.originalEvent.buttons?e.originalEvent.buttons:e.originalEvent.which))return c.mousedrag(e);const o=X(e,t);e.featureTarget=o,l.mousemove(e)},c.mousedown=function(e){r={time:(new Date).getTime(),point:e.point};const o=X(e,t);e.featureTarget=o,l.mousedown(e)},c.mouseup=function(e){const o=X(e,t);e.featureTarget=o,z(r,{point:e.point,time:(new Date).getTime()})?l.click(e):l.mouseup(e)},c.mouseout=function(e){l.mouseout(e)},c.touchstart=function(e){if(!t.options.touchEnabled)return;a={time:(new Date).getTime(),point:e.point};const o=Y.touch(e,null,t)[0];e.featureTarget=o,l.touchstart(e)},c.touchmove=function(e){if(t.options.touchEnabled)return l.touchmove(e),c.touchdrag(e)},c.touchend=function(e){if(e.originalEvent.preventDefault(),!t.options.touchEnabled)return;const o=Y.touch(e,null,t)[0];e.featureTarget=o,te(a,{time:(new Date).getTime(),point:e.point})?l.tap(e):l.touchend(e)};const d=e=>{const t=S(e),o=O(e),n=b(e);return!(t||o||n)};function p(e,o,r={}){l.stop();const i=n[e];if(void 0===i)throw new Error(`${e} is not valid`);u=e;const a=i(t,o);l=oe(a,t),r.silent||t.map.fire(s.MODE_CHANGE,{mode:e}),t.store.setDirty(),t.store.render()}c.keydown=function(o){(o.srcElement||o.target).classList.contains(e.CANVAS)&&((S(o)||O(o))&&t.options.controls.trash?(o.preventDefault(),l.trash()):d(o)?l.keydown(o):M(o)&&t.options.controls.point?p(i.DRAW_POINT):L(o)&&t.options.controls.line_string?p(i.DRAW_LINE_STRING):N(o)&&t.options.controls.polygon&&p(i.DRAW_POLYGON))},c.keyup=function(e){d(e)&&l.keyup(e)},c.zoomend=function(){t.store.changeZoom()},c.data=function(e){if("style"===e.dataType){const{setup:e,map:o,options:n,store:r}=t;n.styles.some((e=>o.getLayer(e.id)))||(e.addLayers(),r.setDirty(),r.render())}};const h={trash:!1,combineFeatures:!1,uncombineFeatures:!1};return{start(){u=t.options.defaultMode,l=oe(n[u](t),t)},changeMode:p,actionable:function(e){let o=!1;Object.keys(e).forEach((t=>{if(void 0===h[t])throw new Error("Invalid action type");h[t]!==e[t]&&(o=!0),h[t]=e[t]})),o&&t.map.fire(s.ACTIONABLE,{actions:h})},currentModeName:()=>u,currentModeRender:(e,t)=>l.render(e,t),fire(e,o){t.map&&t.map.fire(e,o)},addEventListeners(){t.map.on("mousemove",c.mousemove),t.map.on("mousedown",c.mousedown),t.map.on("mouseup",c.mouseup),t.map.on("data",c.data),t.map.on("touchmove",c.touchmove),t.map.on("touchstart",c.touchstart),t.map.on("touchend",c.touchend),t.container.addEventListener("mouseout",c.mouseout),t.options.keybindings&&(t.container.addEventListener("keydown",c.keydown),t.container.addEventListener("keyup",c.keyup))},removeEventListeners(){t.map.off("mousemove",c.mousemove),t.map.off("mousedown",c.mousedown),t.map.off("mouseup",c.mouseup),t.map.off("data",c.data),t.map.off("touchmove",c.touchmove),t.map.off("touchstart",c.touchstart),t.map.off("touchend",c.touchend),t.container.removeEventListener("mouseout",c.mouseout),t.options.keybindings&&(t.container.removeEventListener("keydown",c.keydown),t.container.removeEventListener("keyup",c.keyup))},trash(e){l.trash(e)},combineFeatures(){l.combineFeatures()},uncombineFeatures(){l.uncombineFeatures()},getMode:()=>u}}(a),a.ui=function(t){const o={};let r=null,s={mode:null,feature:null,mouse:null},a={mode:null,feature:null,mouse:null};function c(e){a=Object.assign(a,e)}function u(){if(!t.container)return;const e=[],o=[];Te.forEach((t=>{a[t]!==s[t]&&(e.push(`${t}-${s[t]}`),null!==a[t]&&o.push(`${t}-${a[t]}`))})),e.length>0&&t.container.classList.remove(...e),o.length>0&&t.container.classList.add(...o),s=Object.assign(s,a)}function l(t,o={}){const n=document.createElement("button");return n.className=`${e.CONTROL_BUTTON} ${o.className}`,n.setAttribute("title",o.title),o.container.appendChild(n),n.addEventListener("click",(e=>{if(e.preventDefault(),e.stopPropagation(),e.target===r)return d(),void o.onDeactivate();p(t),o.onActivate()}),!0),n}function d(){r&&(r.classList.remove(e.ACTIVE_BUTTON),r=null)}function p(t){d();const n=o[t];n&&n&&"trash"!==t&&(n.classList.add(e.ACTIVE_BUTTON),r=n)}return{setActiveButton:p,queueMapClasses:c,updateMapClasses:u,clearMapClasses:function(){c({mode:null,feature:null,mouse:null}),u()},addButtons:function(){const r=t.options.controls,s=document.createElement("div");return s.className=`${e.CONTROL_GROUP} ${e.CONTROL_BASE}`,r?(r[n.POINT]&&(o[n.POINT]=l(n.POINT,{container:s,className:e.CONTROL_BUTTON_POINT,title:"Marker tool "+(t.options.keybindings?"(1)":""),onActivate:()=>t.events.changeMode(i.DRAW_POINT),onDeactivate:()=>t.events.trash()})),r[n.LINE]&&(o[n.LINE]=l(n.LINE,{container:s,className:e.CONTROL_BUTTON_LINE,title:"LineString tool "+(t.options.keybindings?"(2)":""),onActivate:()=>t.events.changeMode(i.DRAW_LINE_STRING),onDeactivate:()=>t.events.trash()})),r[n.POLYGON]&&(o[n.POLYGON]=l(n.POLYGON,{container:s,className:e.CONTROL_BUTTON_POLYGON,title:"Polygon tool "+(t.options.keybindings?"(3)":""),onActivate:()=>t.events.changeMode(i.DRAW_POLYGON),onDeactivate:()=>t.events.trash()})),r.trash&&(o.trash=l("trash",{container:s,className:e.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{t.events.trash()}})),r.combine_features&&(o.combine_features=l("combineFeatures",{container:s,className:e.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{t.events.combineFeatures()}})),r.uncombine_features&&(o.uncombine_features=l("uncombineFeatures",{container:s,className:e.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{t.events.uncombineFeatures()}})),s):s},removeButtons:function(){Object.keys(o).forEach((e=>{const t=o[e];t.parentNode&&t.parentNode.removeChild(t),delete o[e]}))}}}(a),a.container=t.getContainer(),a.store=new Ee(a),c=a.ui.addButtons(),a.options.boxSelect){a.boxZoomInitial=t.boxZoom.isEnabled(),t.boxZoom.disable();const e=t.dragPan.isEnabled();t.dragPan.disable(),t.dragPan.enable(),e||t.dragPan.disable()}return t.loaded()?l.connect():(t.on("load",l.connect),u=setInterval((()=>{t.loaded()&&l.connect()}),16)),a.events.start(),c},addLayers(){a.map.addSource(t.COLD,{data:{type:r.FEATURE_COLLECTION,features:[]},type:"geojson"}),a.map.addSource(t.HOT,{data:{type:r.FEATURE_COLLECTION,features:[]},type:"geojson"}),a.options.styles.forEach((e=>{a.map.addLayer(e)})),a.store.setDirty(!0),a.store.render()},removeLayers(){a.options.styles.forEach((e=>{a.map.getLayer(e.id)&&a.map.removeLayer(e.id)})),a.map.getSource(t.COLD)&&a.map.removeSource(t.COLD),a.map.getSource(t.HOT)&&a.map.removeSource(t.HOT)}};return a.setup=l,l}const ve="#3bb2d0",Ie="#fbb03b",Se="#fff";var Oe=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],Ie,ve],"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"],Ie,ve],"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":Se}},{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"],Ie,ve]}},{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":Se}},{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":Ie}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":Ie}}];function Me(e,t){this.x=e,this.y=t}function Le(e,t){const o=t.getBoundingClientRect();return new Me(e.clientX-o.left-(t.clientLeft||0),e.clientY-o.top-(t.clientTop||0))}function Ne(e,t,o,n){return{type:r.FEATURE,properties:{meta:c.VERTEX,parent:e,coord_path:o,active:n?u.ACTIVE:u.INACTIVE},geometry:{type:r.POINT,coordinates:t}}}function be(e,t,o){if(null!==e)for(var n,r,i,s,a,c,u,l,d=0,p=0,h=e.type,f="FeatureCollection"===h,g="Feature"===h,y=f?e.features.length:1,m=0;m<y;m++){a=(l=!!(u=f?e.features[m].geometry:g?e.geometry:e)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var E=0;E<a;E++){var C=0,T=0;if(null!==(s=l?u.geometries[E]:u)){c=s.coordinates;var _=s.type;switch(d=0,_){case null:break;case"Point":if(!1===t(c,p,m,C,T))return!1;p++,C++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(!1===t(c[n],p,m,C,T))return!1;p++,"MultiPoint"===_&&C++}"LineString"===_&&C++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(r=0;r<c[n].length-d;r++){if(!1===t(c[n][r],p,m,C,T))return!1;p++}"MultiLineString"===_&&C++,"Polygon"===_&&T++}"Polygon"===_&&C++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(T=0,r=0;r<c[n].length;r++){for(i=0;i<c[n][r].length-d;i++){if(!1===t(c[n][r][i],p,m,C,T))return!1;p++}T++}C++}break;case"GeometryCollection":for(n=0;n<s.geometries.length;n++)if(!1===be(s.geometries[n],t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Pe(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return xe(e);case"FeatureCollection":return function(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach((o=>{switch(o){case"type":case"features":return;default:t[o]=e[o]}})),t.features=e.features.map((e=>xe(e))),t}(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Fe(e);default:throw new Error("unknown GeoJSON type")}}function xe(e){const t={type:"Feature"};return Object.keys(e).forEach((o=>{switch(o){case"type":case"properties":case"geometry":return;default:t[o]=e[o]}})),t.properties=Ae(e.properties),null==e.geometry?t.geometry=null:t.geometry=Fe(e.geometry),t}function Ae(e){const t={};return e?(Object.keys(e).forEach((o=>{const n=e[o];"object"==typeof n?null===n?t[o]=null:Array.isArray(n)?t[o]=n.map((e=>e)):t[o]=Ae(n):t[o]=n})),t):t}function Fe(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),"GeometryCollection"===e.type?(t.geometries=e.geometries.map((e=>Fe(e))),t):(t.coordinates=we(e.coordinates),t)}function we(e){const t=e;return"object"!=typeof t[0]?t.slice():t.map((e=>we(e)))}function Re(e,t={}){return De(e,"mercator",t)}function De(e,t,o={}){var n,r=(o=o||{}).mutate;if(!e)throw new Error("geojson is required");return!Array.isArray(e)||(n=e[0],isNaN(n)||null===n||Array.isArray(n))?(!0!==r&&(e=Pe(e)),be(e,(function(e){var o="mercator"===t?Ue(e):ke(e);e[0]=o[0],e[1]=o[1]}))):e="mercator"===t?Ue(e):ke(e),e}function Ue(e){var t,o=Math.PI/180,n=6378137,r=20037508.342789244,i=[n*(Math.abs(e[0])<=180?e[0]:e[0]-360*((t=e[0])<0?-1:t>0?1:0))*o,n*Math.log(Math.tan(.25*Math.PI+.5*e[1]*o))];return i[0]>r&&(i[0]=r),i[0]<-r&&(i[0]=-r),i[1]>r&&(i[1]=r),i[1]<-r&&(i[1]=-r),i}function ke(e){var t=180/Math.PI,o=6378137;return[e[0]*t/o,(.5*Math.PI-2*Math.atan(Math.exp(-e[1]/o)))*t]}function Ve(e,t,o){const n=t.geometry.coordinates,i=o.geometry.coordinates;if(n[1]>p||n[1]<d||i[1]>p||i[1]<d)return null;const s=Re(n),a=Re(i),u=e=>Number(e.toFixed(8)),l=(e,t)=>(e+t)/2,h=function(e,t={}){return De(e,"wgs84",t)}([l(s[0],a[0]),l(s[1],a[1])]),f=[u(h[0]),u(h[1])];return{type:r.FEATURE,properties:{meta:c.MIDPOINT,parent:e,lng:f[0],lat:f[1],coord_path:o.properties.coord_path},geometry:{type:r.POINT,coordinates:f}}}function Ge(e,t={},o=null){const{type:n,coordinates:i}=e.geometry,s=e.properties&&e.properties.id;let a=[];function c(e,o){let n="",r=null;e.forEach(((e,i)=>{const c=null!=o?`${o}.${i}`:String(i),l=Ne(s,e,c,u(c));if(t.midpoints&&r){const e=Ve(s,r,l);e&&a.push(e)}r=l;const d=JSON.stringify(e);n!==d&&a.push(l),0===i&&(n=d)}))}function u(e){return!!t.selectedPaths&&-1!==t.selectedPaths.indexOf(e)}return n===r.POINT?a.push(Ne(s,i,o,u(o))):n===r.POLYGON?i.forEach(((e,t)=>{c(e,null!==o?`${o}.${t}`:String(t))})):n===r.LINE_STRING?c(i,o):0===n.indexOf(r.MULTI_PREFIX)&&function(){const o=n.replace(r.MULTI_PREFIX,"");i.forEach(((n,i)=>{const s={type:r.FEATURE,properties:e.properties,geometry:{type:o,coordinates:n}};a=a.concat(Ge(s,t,i))}))}(),a}Me.prototype={clone(){return new Me(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,o=e.y-this.y;return t*t+o*o},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,o=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=o,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),o=Math.sin(e),n=t*this.x-o*this.y,r=o*this.x+t*this.y;return this.x=n,this.y=r,this},_rotateAround(e,t){const o=Math.cos(e),n=Math.sin(e),r=t.x+o*(this.x-t.x)-n*(this.y-t.y),i=t.y+n*(this.x-t.x)+o*(this.y-t.y);return this.x=r,this.y=i,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Me},Me.convert=function(e){if(e instanceof Me)return e;if(Array.isArray(e))return new Me(+e[0],+e[1]);if(void 0!==e.x&&void 0!==e.y)return new Me(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};var Be={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:je,LAT_MAX:Je,LAT_RENDERED_MIN:$e,LAT_RENDERED_MAX:Ye,LNG_MIN:He,LNG_MAX:Xe}=h;function qe(e,t){let o=je,n=Je,r=je,i=Je,s=Xe,a=He;e.forEach((e=>{const t=function(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],o=[e.geometry.coordinates].flat(t),n=o.map((e=>e[0])),r=o.map((e=>e[1])),i=e=>Math.min.apply(null,e),s=e=>Math.max.apply(null,e);return[i(n),i(r),s(n),s(r)]}(e),c=t[1],u=t[3],l=t[0],d=t[2];c>o&&(o=c),u<n&&(n=u),u>r&&(r=u),c<i&&(i=c),l<s&&(s=l),d>a&&(a=d)}));const c=t;return o+c.lat>Ye&&(c.lat=Ye-o),r+c.lat>Je&&(c.lat=Je-r),n+c.lat<$e&&(c.lat=$e-n),i+c.lat<je&&(c.lat=je-i),s+c.lng<=He&&(c.lng+=360*Math.ceil(Math.abs(c.lng)/360)),a+c.lng>=Xe&&(c.lng-=360*Math.ceil(Math.abs(c.lng)/360)),c}function Ke(e,t){const o=qe(e.map((e=>e.toGeoJSON())),t);e.forEach((e=>{const t=e.getCoordinates(),n=e=>{const t={lng:e[0]+o.lng,lat:e[1]+o.lat};return[t.lng,t.lat]},i=e=>e.map((e=>n(e))),s=e=>e.map((e=>i(e)));let a;e.type===r.POINT?a=n(t):e.type===r.LINE_STRING||e.type===r.MULTI_POINT?a=t.map(n):e.type===r.POLYGON||e.type===r.MULTI_LINE_STRING?a=t.map(i):e.type===r.MULTI_POLYGON&&(a=t.map(s)),e.incomingCoords(a)}))}const Ze={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(s.UPDATE,{action:a.MOVE,features:this.getSelected().map((e=>e.toGeoJSON()))})},fireActionable:function(){const e=this.getSelected(),t=e.filter((e=>this.isInstanceOf("MultiFeature",e)));let o=!1;if(e.length>1){o=!0;const t=e[0].type.replace("Multi","");e.forEach((e=>{e.type.replace("Multi","")!==t&&(o=!1)}))}const n=t.length>0,r=e.length>0;this.setActionableState({combineFeatures:o,uncombineFeatures:n,trash:r})},getUniqueIds:function(e){return e.length?e.map((e=>e.properties.id)).filter((e=>void 0!==e)).reduce(((e,t)=>(e.add(t),e)),new J).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(){Be.enable(this)},onMouseMove:function(e,t){return C(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},onMouseOut:function(e){return!e.dragMoving||this.fireUpdate()}};Ze.onTap=Ze.onClick=function(e,t){return E(t)?this.clickAnywhere(e,t):f(c.VERTEX)(t)?this.clickOnVertex(e,t):C(t)?this.clickOnFeature(e,t):void 0},Ze.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach((e=>this.doRender(e)))),Be.enable(this),this.stopExtendedInteractions(e)},Ze.clickOnVertex=function(e,t){this.changeMode(i.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:o.MOVE})},Ze.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Ze.clickOnFeature=function(e,t){Be.disable(this),this.stopExtendedInteractions(e);const n=_(t),s=this.getSelectedIds(),a=t.featureTarget.properties.id,c=this.isSelected(a);if(!n&&c&&this.getFeature(a).type!==r.POINT)return this.changeMode(i.DIRECT_SELECT,{featureId:a});c&&n?(this.deselect(a),this.updateUIClasses({mouse:o.POINTER}),1===s.length&&Be.enable(this)):!c&&n?(this.select(a),this.updateUIClasses({mouse:o.MOVE})):c||n||(s.forEach((e=>this.doRender(e))),this.setSelected(a),this.updateUIClasses({mouse:o.MOVE})),this.doRender(a)},Ze.onMouseDown=function(e,t){return e.initialDragPanState=this.map.dragPan.isEnabled(),y(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&g(t)?this.startBoxSelect(e,t):void 0},Ze.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=Le(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Ze.onTouchStart=function(e,t){if(y(t))return this.startOnActiveFeature(e,t)},Ze.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},Ze.whileBoxSelect=function(t,n){t.boxSelecting=!0,this.updateUIClasses({mouse:o.ADD}),t.boxSelectElement||(t.boxSelectElement=document.createElement("div"),t.boxSelectElement.classList.add(e.BOX_SELECT),this.map.getContainer().appendChild(t.boxSelectElement));const r=Le(n.originalEvent,this.map.getContainer()),i=Math.min(t.boxSelectStartLocation.x,r.x),s=Math.max(t.boxSelectStartLocation.x,r.x),a=Math.min(t.boxSelectStartLocation.y,r.y),c=Math.max(t.boxSelectStartLocation.y,r.y),u=`translate(${i}px, ${a}px)`;t.boxSelectElement.style.transform=u,t.boxSelectElement.style.WebkitTransform=u,t.boxSelectElement.style.width=s-i+"px",t.boxSelectElement.style.height=c-a+"px"},Ze.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const o={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};Ke(this.getSelected(),o),e.dragMoveLocation=t.lngLat},Ze.onTouchEnd=Ze.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,Le(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,n,"click"),i=this.getUniqueIds(r).filter((e=>!this.isSelected(e)));i.length&&(this.select(i),i.forEach((e=>this.doRender(e))),this.updateUIClasses({mouse:o.MOVE}))}this.stopExtendedInteractions(e)},Ze.toDisplayFeatures=function(e,t,o){t.properties.active=this.isSelected(t.properties.id)?u.ACTIVE:u.INACTIVE,o(t),this.fireActionable(),t.properties.active===u.ACTIVE&&t.geometry.type!==r.POINT&&Ge(t).forEach(o)},Ze.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Ze.onCombineFeatures=function(){const e=this.getSelected();if(0===e.length||e.length<2)return;const t=[],o=[],n=e[0].type.replace("Multi","");for(let r=0;r<e.length;r++){const i=e[r];if(i.type.replace("Multi","")!==n)return;i.type.includes("Multi")?i.getCoordinates().forEach((e=>{t.push(e)})):t.push(i.getCoordinates()),o.push(i.toGeoJSON())}if(o.length>1){const e=this.newFeature({type:r.FEATURE,properties:o[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(e),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([e.id]),this.fire(s.COMBINE_FEATURES,{createdFeatures:[e.toGeoJSON()],deletedFeatures:o})}this.fireActionable()},Ze.onUncombineFeatures=function(){const e=this.getSelected();if(0===e.length)return;const t=[],o=[];for(let n=0;n<e.length;n++){const r=e[n];this.isInstanceOf("MultiFeature",r)&&(r.getFeatures().forEach((e=>{this.addFeature(e),e.properties=r.properties,t.push(e.toGeoJSON()),this.select([e.id])})),this.deleteFeature(r.id,{silent:!0}),o.push(r.toGeoJSON()))}t.length>1&&this.fire(s.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:o}),this.fireActionable()};const We=f(c.VERTEX),ze=f(c.MIDPOINT),Qe={fireUpdate:function(){this.fire(s.UPDATE,{action:a.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 o=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(o.coord_path);_(t)||-1!==n?_(t)&&-1===n&&e.selectedCoordPaths.push(o.coord_path):e.selectedCoordPaths=[o.coord_path];const r=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(r)},onMidpoint:function(e,t){this.startDragging(e,t);const o=t.featureTarget.properties;e.feature.addCoordinate(o.coord_path,o.lng,o.lat),this.fireUpdate(),e.selectedCoordPaths=[o.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,o){Ke(this.getSelected(),o),e.dragMoveLocation=t.lngLat},dragVertex:function(e,t,o){const n=e.selectedCoordPaths.map((t=>e.feature.getCoordinate(t))),i=qe(n.map((e=>({type:r.FEATURE,properties:{},geometry:{type:r.POINT,coordinates:e}}))),o);for(let t=0;t<n.length;t++){const o=n[t];e.feature.updateCoordinate(e.selectedCoordPaths[t],o[0]+i.lng,o[1]+i.lat)}},clickNoTarget:function(){this.changeMode(i.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(i.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){const t=e.featureId,o=this.getFeature(t);if(!o)throw new Error("You must provide a featureId to enter direct_select mode");if(o.type===r.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:o,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),Be.disable(this),this.setActionableState({trash:!0}),n},onStop:function(){Be.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,o){e.featureId===t.properties.id?(t.properties.active=u.ACTIVE,o(t),Ge(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(o)):(t.properties.active=u.INACTIVE,o(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(i.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){const n=y(t),r=We(t),i=ze(t),s=0===e.selectedCoordPaths.length;return n&&s||r&&!s?this.updateUIClasses({mouse:o.MOVE}):this.updateUIClasses({mouse:o.NONE}),(r||n||i)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},onMouseOut:function(e){return e.dragMoving&&this.fireUpdate(),!0}};Qe.onTouchStart=Qe.onMouseDown=function(e,t){return We(t)?this.onVertex(e,t):y(t)?this.onFeature(e,t):ze(t)?this.onMidpoint(e,t):void 0},Qe.onDrag=function(e,t){if(!0!==e.canDragMove)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const o={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,o):this.dragFeature(e,t,o),e.dragMoveLocation=t.lngLat},Qe.onClick=function(e,t){return E(t)?this.clickNoTarget(e,t):y(t)?this.clickActiveFeature(e,t):m(t)?this.clickInactive(e,t):void this.stopDragging(e)},Qe.onTap=function(e,t){return E(t)?this.clickNoTarget(e,t):y(t)?this.clickActiveFeature(e,t):m(t)?this.clickInactive(e,t):void 0},Qe.onTouchEnd=Qe.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const et={};function tt(e,t){return!!e.lngLat&&e.lngLat.lng===t[0]&&e.lngLat.lat===t[1]}et.onSetup=function(){const e=this.newFeature({type:r.FEATURE,properties:{},geometry:{type:r.POINT,coordinates:[]}});return this.a