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