draw-libre 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/index.d.ts +46 -16
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
## Features
|
|
7
7
|
|
|
8
8
|
- Draw linestrings (including closed ones) and polygons
|
|
9
|
-
- Compatible with maplibre-gl.js and mapbox-gl.js (currently supports Mercator projection only)
|
|
9
|
+
- Compatible with maplibre-gl.js(v3, v4, v5) and mapbox-gl.js (currently supports Mercator projection only)
|
|
10
10
|
- Customizable UI and controls
|
|
11
11
|
- Event-driven architecture for easy integration
|
|
12
12
|
|
|
@@ -113,15 +113,15 @@ map.on(mdl:add, (event: PointAddEvent) => {
|
|
|
113
113
|
|
|
114
114
|
Available events:
|
|
115
115
|
|
|
116
|
-
- `mdl:doubleclick` (PointDoubleClickEvent)
|
|
117
|
-
- `mdl:pointenter` (PointEnterEvent)
|
|
118
|
-
- `mdl:pointleave` (PointLeaveEvent)
|
|
119
|
-
- `mdl:moveend` (PointMoveEvent)
|
|
120
|
-
- `mdl:add` (PointAddEvent)
|
|
121
|
-
- `mdl:undo` (UndoEvent)
|
|
122
|
-
- `mdl:removeall` (RemoveAllEvent)
|
|
123
|
-
- `mdl:save` (SaveEvent)
|
|
124
|
-
- `mdl:modechanged` (ModeChangeEvent)
|
|
116
|
+
- `mdl:doubleclick` (PointDoubleClickEvent) -- Fired when a point is double-clicked
|
|
117
|
+
- `mdl:pointenter` (PointEnterEvent) -- Fired when the cursor enters a point
|
|
118
|
+
- `mdl:pointleave` (PointLeaveEvent) -- Fired when the cursor leaves a point
|
|
119
|
+
- `mdl:moveend` (PointMoveEvent) -- Fired when a point is moved
|
|
120
|
+
- `mdl:add` (PointAddEvent) -- Fired when a point is added
|
|
121
|
+
- `mdl:undo` (UndoEvent) -- Fired when the undo button is clicked
|
|
122
|
+
- `mdl:removeall` (RemoveAllEvent) -- Fired when all points are removed by clicking the delete button
|
|
123
|
+
- `mdl:save` (SaveEvent) -- Fired when the save button is clicked
|
|
124
|
+
- `mdl:modechanged` (ModeChangeEvent) -- Fired when the drawing mode is changed
|
|
125
125
|
|
|
126
126
|
### Methods
|
|
127
127
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import mapboxgl from 'mapbox-gl';
|
|
2
|
+
import { CircleLayerSpecification, LineLayerSpecification, FillLayerSpecification } from 'maplibre-gl';
|
|
3
3
|
|
|
4
|
-
type Map = Map
|
|
5
|
-
type IControl = IControl
|
|
4
|
+
type Map = maplibregl.Map & mapboxgl.Map;
|
|
5
|
+
type IControl = maplibregl.IControl & mapboxgl.IControl;
|
|
6
6
|
|
|
7
7
|
type Func<T> = (event: T) => any;
|
|
8
8
|
type ChangeEvent<T> = {
|
|
@@ -133,48 +133,78 @@ type RequiredDrawOptions = DeepRequired<Omit<DrawOptions, "layersPaint">> & {
|
|
|
133
133
|
layersPaint: LayersPaint;
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
-
interface BaseEvent {
|
|
137
|
-
id: Uuid;
|
|
138
|
-
total: number;
|
|
139
|
-
timestamp: number;
|
|
140
|
-
target: Map;
|
|
141
|
-
}
|
|
142
136
|
interface ModeEvent {
|
|
143
137
|
geometry: Mode;
|
|
144
138
|
closedGeometry: boolean;
|
|
145
139
|
}
|
|
146
|
-
interface UndoEvent
|
|
140
|
+
interface UndoEvent {
|
|
147
141
|
coordinates: LatLng;
|
|
148
142
|
originalEvent: MouseEvent;
|
|
143
|
+
id: Uuid;
|
|
144
|
+
total: number;
|
|
145
|
+
timestamp: number;
|
|
146
|
+
target: Map;
|
|
147
|
+
type: "mdl:undo";
|
|
149
148
|
}
|
|
150
149
|
interface RemoveAllEvent {
|
|
151
150
|
originalEvent: MouseEvent;
|
|
151
|
+
type: "mdl:removeall";
|
|
152
|
+
target: Map;
|
|
152
153
|
}
|
|
153
154
|
interface SaveEvent {
|
|
154
155
|
originalEvent: MouseEvent;
|
|
155
156
|
timestamp: number;
|
|
156
157
|
steps: Step[];
|
|
157
158
|
mode: ModeEvent;
|
|
159
|
+
target: Map;
|
|
160
|
+
type: "mdl:save";
|
|
158
161
|
}
|
|
159
|
-
interface PointDoubleClickEvent
|
|
162
|
+
interface PointDoubleClickEvent {
|
|
163
|
+
id: Uuid;
|
|
164
|
+
total: number;
|
|
165
|
+
timestamp: number;
|
|
166
|
+
target: Map;
|
|
160
167
|
coordinates: LatLng;
|
|
168
|
+
type: "mdl:doubleclick";
|
|
161
169
|
}
|
|
162
|
-
interface PointAddEvent
|
|
170
|
+
interface PointAddEvent {
|
|
171
|
+
id: Uuid;
|
|
172
|
+
total: number;
|
|
173
|
+
timestamp: number;
|
|
174
|
+
target: Map;
|
|
163
175
|
coordinates: LatLng;
|
|
164
176
|
mode: ModeEvent;
|
|
177
|
+
type: "mdl:add";
|
|
165
178
|
}
|
|
166
|
-
interface PointMoveEvent
|
|
179
|
+
interface PointMoveEvent {
|
|
167
180
|
start_coordinates: LatLng;
|
|
168
181
|
end_coordinates: LatLng;
|
|
182
|
+
id: Uuid;
|
|
183
|
+
total: number;
|
|
184
|
+
timestamp: number;
|
|
185
|
+
target: Map;
|
|
186
|
+
type: "mdl:moveend";
|
|
169
187
|
}
|
|
170
|
-
interface PointEnterEvent
|
|
188
|
+
interface PointEnterEvent {
|
|
171
189
|
coordinates: LatLng;
|
|
190
|
+
id: Uuid;
|
|
191
|
+
total: number;
|
|
192
|
+
timestamp: number;
|
|
193
|
+
target: Map;
|
|
194
|
+
type: "mdl:pointenter";
|
|
172
195
|
}
|
|
173
|
-
interface PointLeaveEvent
|
|
196
|
+
interface PointLeaveEvent {
|
|
174
197
|
coordinates: LatLng;
|
|
198
|
+
id: Uuid;
|
|
199
|
+
total: number;
|
|
200
|
+
timestamp: number;
|
|
201
|
+
target: Map;
|
|
202
|
+
type: "mdl:pointleave";
|
|
175
203
|
}
|
|
176
204
|
interface ModeChangeEvent {
|
|
177
205
|
mode: Mode | "break";
|
|
206
|
+
target: Map;
|
|
207
|
+
type: "mdl:modechanged";
|
|
178
208
|
}
|
|
179
209
|
|
|
180
210
|
declare class DrawLibre implements IControl {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var l=class n{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=n.testProp(["transform","WebkitTransform"]);static testProp(e){if(!n.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in n.docStyle)return e[t];return e[0]}static create(e,t,i){let o=window.document.createElement(e);return t!==void 0&&(o.className=t),i&&i.appendChild(o),o}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){n.transformProp&&e.style&&(e.style[n.transformProp]=t);}static manageEventListener(e,t,i,o,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,o,s):t[a](i,o,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var F=class{#e;#i;#t;_undoButton;_deleteButton;_saveButton;_container;_updatePositionCallback;constructor(e){this.#e=e,this._container=void 0,this.#i=!0,this.#t=void 0,this.#r(),this.#o();}#o(){this.#e.mode?.addObserver(this.#n);}#n=e=>{let{store:t}=this.#e,{type:i,data:o}=e;i==="MODE_CHANGED"&&!o&&this.hidePanel(),i==="MODE_CHANGED"&&o&&t.tail?.val&&this.setPanelLocation({lat:t.tail?.val?.lat,lng:t.tail?.val?.lng});};#s(){this.#t&&(this.#t.className="dashboard-container",this.#t.style.position="absolute",this.#t.style.zIndex="1000000",this.#t.style.pointerEvents="auto",this.#t.style.display=this.#i?"none":"block");}#r=()=>{let{store:e}=this.#e;this.createPanel(),this.#t=document.createElement("div"),this.#s(),this._container&&this.#t.appendChild(this._container),document.body.appendChild(this.#t),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{if(!this.#t)return;this.#i&&this.showPanel();let t=this.#e.map.project(e);this.#a(t),this.#l(e);};#a=e=>{if(this.#i||!this.#t)return;let i=this.#e.map.getContainer().getBoundingClientRect(),o=i.left+e.x,s=i.top+e.y,a=36;this.#t.style.left=`${o-a}px`,this.#t.style.top=`${s-a}px`;};#l(e){this.#c(),this._updatePositionCallback=()=>{this.#i||!this.#t||this.#a(this.#e.map.project(e));},this.#e.map.on("move",this._updatePositionCallback),this.#e.map.on("zoom",this._updatePositionCallback);}#c(){this._updatePositionCallback&&(this.#e.map.off("move",this._updatePositionCallback),this.#e.map.off("zoom",this._updatePositionCallback),this._updatePositionCallback=void 0);}showPanel=()=>{this.#i&&this.#t&&(this.#i=!1,this.#t.style.display="block",this.#t.style.transition="opacity 0.2s",this.#t.style.opacity="1");};hidePanel=()=>{!this.#i&&this.#t&&(this.#i=!0,this.#t.style.display="none");};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._updatePositionCallback&&(this.#e.map.off("move",this._updatePositionCallback),this.#e.map.off("zoom",this._updatePositionCallback),this._updatePositionCallback=void 0),this.#t&&(document.body.removeChild(this.#t),this.#t=void 0),this._container&&(l.remove(this._container),this._container=void 0);};createButton=(e,t,i,o)=>{let s=l.create("button",`panel-button panel-button-${i}`,o);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:o,save:s}=e.panel.buttons,a=e.panel.size,c=l.create("div","dashboard");i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,c)),o.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,c)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,c)),this._container=c;}};var N={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},G={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},ae={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},p={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},w={large:6.5,default:5.5},H={large:"#FF6464",default:"#666666"},k={"circle-radius":w.default,"circle-color":"#FEFFFE","circle-stroke-color":H.default,"circle-stroke-width":3},O={"circle-radius":w.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},A={"fill-color":"grey","fill-opacity":.4},_={"line-width":3,"line-color":"grey","line-opacity":.7},T={"circle-radius":w.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},D={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},U=n=>[{id:r.SinglePointLayer,source:p.SinglePointSource,type:"circle",paint:n.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:p.PolygonSource,type:"fill",paint:n.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:p.LineDynamicSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:p.LineSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:p.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:p.LineSourceBreak,type:"line",paint:n.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:p.PointsSource,type:"circle",paint:n.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:p.PointsSource,type:"circle",paint:n.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var f=class{static#e=0;static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",w.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",H.large);};static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",w.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",H.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#i(e):this.#t(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let o=U(t).find(s=>s.id===r.LineLayerTransparent);o&&e.addLayer(o);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var m=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(o=>t.includes(o.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:o}=t;return e.project([o,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},g=class{static#e(e){let t=[],i=e.head,o=new Set;for(;i!==null;){if(o.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}o.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],o=new Set;for(;t!==null&&!o.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}o.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},d=class n{static getGeometryIndex=(e,t)=>{let i=e.head,o=0;for(;i!==null;){if(i.val?.id===t)return o;o++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),c=this.distance(i,t);return Math.abs(a+c-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,o=e.tail;do{if(i?.val?.id===t){i!==e.head&&(o.next=i.next,e.head=i,e.tail=o),e.tail.next=null;return}o=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:o,map:s}=e;n.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),f.togglePointCircleRadius(s,"default"),o.renderPolygon(N));}},P=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function n(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(o){let s="";for(let a=0;a<o;a++)s+=n();return s}function t(o){let s=o===0,a=o===4;return s?8:a?12:4}let i=[];for(let o=0;o<5;o++)i.push(e(t(o)));return i.join("-")},M=(n,e)=>{let t,i=!0;function o(){i&&t&&(n(...t),t=null,i=!1,setTimeout(()=>{i=!0,o();},e));}return function(...s){t=s,o();}};var x=class{#e;#i;#t;#o;constructor(e){this.#e=e,this.#n(),this.render();}#n(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(p).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;U(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,o=i.getLayer(e),s=i.getLayer(t);o&&s&&i.moveLayer(e,t);};#l=()=>{let{map:e}=this.#e;Object.values(p).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#c=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#c(),this.#l();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(p.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,o=i.getSource(t);o&&o.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(p.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,o=g.getPoints(i),s=g.getAllLines(i);if(this.#i=o,this.#t=s,this.renderPoints(o),this.renderLines(s,p.LineSource),t.modes.polygon.visible&&e.isPolygon()){let c=g.getPolygon(i);this.#o=c,this.renderPolygon(c);}};#p=(e,t)=>{if(this.#o.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let o=this.#o.features[0].geometry.coordinates[0]?.length-1;this.#o.features[0].geometry.coordinates[0][o]=[t.lng,t.lat];}this.renderPolygon(this.#o);};#d=(e,t)=>{let{mode:i}=this.#e;this.#t.features[0].geometry.coordinates[e]=[t.lng,t.lat];let o=e===0;if(this.#t&&i.getClosedGeometry()&&o){let a=this.#t.features[0].geometry.coordinates?.length-1;this.#t.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#t,p.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:o}=this.#e;this.#i.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#i),this.#d(e,t),o.modes.polygon.visible&&i.isPolygon()&&this.#p(e,t);};resetGeometries=()=>{this.renderPoints(ae),this.renderLines(G,p.LineSource),this.renderPolygon(N);}};var he=8,me=8,b=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#i=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#t=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:o,height:s}=this.#i();return {x:i-me-o,y:t-s-2}};#o=e=>{let{bottom:t,left:i,right:o}=e.target.getBoundingClientRect(),{width:s}=this.#i();return {x:(o-i)/2+i-s/2,y:t+he}};getPosition=(e,t)=>t==="left"?this.#t(e):this.#o(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var v={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var q=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",n,t,i);},z=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",n,t,i);},le=(n,e)=>{let t=e.locale.line,i=e.locale.polygon,o=e.locale.break;return {line:t,polygon:i,break:o}[n]};var y={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",MODECHANGED:"mdl:modechanged"};var u={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{initial:null,line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:O,firstPoint:k,points:T,line:_,polygon:A,breakLine:D},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var h=class{static addPoint(e,t,i){t.fire(y.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(y.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(y.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(y.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(y.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(y.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static modeChanged(e,t){e.fire(y.MODECHANGED,{mode:t});}static removeAllPoints(e,t){e.fire(y.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:o,mode:s}=e;o.fire(y.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onLineBreak(e){e.fire(y.BREAK);}};var Y=class{#e;constructor(e){this.#e=e,this.#i();}#i=()=>{this.#e.mode.addObserver(this.#l);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#l);};#t=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#o=e=>{this.#t(),e.classList.add("control-button-active");};#n=e=>{let{data:t}=e,{_line:i,_polygon:o,_break:s}=this.#e.control,{mode:a}=this.#e;if(h.modeChanged(this.#e.map,t),!(!i||!o||!s)){switch(t){case"line":this.#o(i);break;case"polygon":this.#o(o);break;}t?a.getClosedGeometry()&&this.#r(s):this.#s(s);}};#s=e=>{e.setAttribute("disabled","true"),e.setAttribute("aria-disabled","true");};#r=e=>{e.removeAttribute("disabled"),e.removeAttribute("aria-disabled");};#a=e=>{let{data:t}=e,{_break:i,_line:o,_polygon:s}=this.#e.control,{mode:a}=this.#e;t?(i&&this.#r(i),a.getMode()==="polygon"&&o&&this.#s(o),a.getMode()==="line"&&s&&this.#s(s)):(i&&this.#s(i),a.getMode()==="polygon"&&o&&this.#r(o),a.getMode()==="line"&&s&&this.#r(s));};#l=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#n(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#a(e),t==="BREAK_CHANGED"&&i){let{_break:o}=this.#e.control;this.#o(o),h.modeChanged(this.#e.map,"break");}}};var j=class{#e;#i;#t;constructor(e){this.#e=e,this.#t=new Y(e),this.#i=new b,this.#o();}#o(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&q(e._line,{...t,click:this.onLineClick}),e._polygon&&q(e._polygon,{...t,click:this.onPolygonClick}),e._break&&q(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&z(e._line,{...t,click:this.onLineClick}),e._polygon&&z(e._polygon,{...t,click:this.onPolygonClick}),e._break&&z(e._break,{...t,click:this.onBreakClick});}}remove(){this.#t.removeConsumers(),this.#n(),this.#i.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let o=le(i,t),s="left";this.#i.create({label:o,placement:s}).setPosition(this.#i.getPosition(e,s));}};onButtonLeave=()=>{this.#i.remove();};#s=()=>{let{control:e}=this.#e;e._line?.classList.remove("control-button-active"),e._polygon?.classList.remove("control-button-active"),e._break?.classList.remove("control-button-active");};#r=()=>{let{map:e,mode:t}=this.#e;t.getMode()||e.fire("mode:initialize");};onLineClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="line"&&!t.getBreak()?(t.setMode(null),e.fire("mode:remove"),i.resetGeometries()):(o._line?.classList.add("control-button-active"),t.setMode("line"),i.render());};onPolygonClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="polygon"&&!t.getBreak()?(t.setMode(null),e.fire("mode:remove"),e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries()):(o._polygon?.classList.add("control-button-active"),t.setMode("polygon"),i.render());};onBreakClick=()=>{let{map:e,mode:t,control:i}=this.#e;t.getBreak()&&(t.setMode(null),e.fire("mode:remove")),this.#s(),i._break?.classList.add("control-button-active"),t.setBreak(!0),e.getCanvasContainer().style.cursor=v.POINTER;}};var C=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var I={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var V=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},B=class extends C{head;tail;size;constructor(e){super();let t=E.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new V(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new V(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},E=class n{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(I.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:o,closeGeometry:s,generateId:a}=e.initial;return n.fromArray(o,s,a)}return null}static#e=e=>e.map(t=>({...t,id:P()}));static buildStepSequence(e){let t=new B;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let o=i?this.#e(e):e,s=this.buildStepSequence(o);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],o=e;for(;o!==null&&!t.has(o);)t.add(o),i.push(o.val),o=o.next;return i}};var K=class{#e;#i;constructor(e){this.#e=e,this.#i=new b;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#n),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#o),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#n),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#o),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#t=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#t(t);this.#i.create({label:i,placement:"bottom"}).setPosition(this.#i.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#i.remove();};#o=e=>{let{tiles:t,mode:i,panel:o,store:s,map:a}=this.#e;s.reset(),o.hidePanel(),i.reset(),f.togglePointCircleRadius(a,"default"),this.#i.remove(),t.resetGeometries(),h.removeAllPoints(a,e);};#n=e=>{let{store:t,panel:i,map:o,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id);let c={...a,total:t.size};h.undoPoint(c,o,e),d.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#i.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;h.onSaveClick(this.#e,E.toArray(t.head),e),this.#i.remove(),i.panel.buttons.save.clearOnSave&&this.#o(e);}};var L=class{static updatePointsData(e){let i=e.target.getSource(p.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,store:o,map:s}=t;d.canCloseGeometry(o)&&f.togglePointCircleRadius(s,"large"),i?.setPanelLocation(e.lngLat);}static addPointToMap=(e,t)=>{let{store:i,tiles:o,map:s,mode:a}=t,c={...e.lngLat,id:P()};i.push(c),h.addPoint({...c,total:i.size},s,a),this.triggerPostPointAddition(e,t),requestAnimationFrame(o.render);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var se=(n,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let o=n.target,s=m.getPixelCoordinates(o,t.val),a=m.getPixelCoordinates(o,t.next.val),c=m.getPixelCoordinates(o,n.lngLat);if(d.checkIfPointIsOnLine(s,a,c))return t}i.add(t),t=t.next;}return null},ce=(n,e)=>{let t=se(n,e);if(t){let i={...n.lngLat,id:P()};return e.insert(i,t),i}return null},pe=(n,e)=>{let{store:t,tiles:i,panel:o}=e;t.tail?.val&&(o?.setPanelLocation(t.tail.val),L.setSinglePointHidden(n),i.render());},de=n=>m.isFeatureTriggered(n,[r.PointsLayer,r.FirstPointLayer]);var ue=15,Z=class{props;#e;#i;constructor(e){this.props=e,this.#e=null,this.#i=M(this.#o,ue);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#t),e.on("mouseenter",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#i),e.on("mouseleave",r.LineLayerTransparent,this.#n);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#t),e.off("mouseenter",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#i),e.off("mouseleave",r.LineLayerTransparent,this.#n);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#t=()=>{let{store:e,mode:t,panel:i,map:o,tiles:s}=this.props,a=this.#e?.next?.val?.id;d.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#n(),o.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),h.onLineBreak(o);};#o=e=>{let{map:t,store:i}=this.props,o=se(e,i);o?.val?.id!==this.#e?.val?.id&&(this.#e=o);let s=t.getSource(p.LineSourceBreak),a=[o?.val?.lng,o?.val?.lat],c=[o?.next?.val?.lng,o?.next?.val?.lat],S=g.getLine(a,c);S&&(s.setData(S),this.showBreakLine());};#n=()=>{setTimeout(()=>{this.hideBreakLine();},ue+10);}};var ye=10,$=class{#e;#i;#t;#o;#n;#s;constructor(e){this.#e=e,this.#i=e.options.dynamicLine,this.#t=null,this.#o=null,this.#r(),this.#s=M(this.#d,ye);}#r(){this.#e.store.addObserver(this.#l),this.#e.mode.addObserver(this.#c),this.#e.mouseEvents.addObserver(this.#a);}removeLine=()=>{this.hideDynamicLine();};removeConsumers=()=>{this.#e.store.removeObserver(this.#l),this.#e.mode.removeObserver(this.#c),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#i=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#i=!0),!!this.#i&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#t=i.tail?.val,this.#o=i.tail?.val,this.showDynamicLine();}};#l=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!d.isClosedGeometry(t)&&(this.#t=e.data.tail?.val,this.showDynamicLine());break;}};#c=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#t=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(y.REMOVEALL,this.hideDynamicLine),e.on(y.UNDO,this.#m),e.on(y.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(y.REMOVEALL,this.hideDynamicLine),e.off(y.UNDO,this.#m),e.off(y.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#t=null,this.#o=null,this.#n=null,e.off("mousemove",this.#s),t.renderLines(G,p.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#t?.lng,this.#t?.lat],i=[this.#o?.lng,this.#o?.lat];this.#n=g.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#o&&this.#p({lng:this.#o?.lng,lat:this.#o?.lat}),e.on("mousemove",this.#s);};#p=e=>{if(!this.#n)return;let{tiles:t}=this.#e;this.#n.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#n,p.LineDynamicSource);};#d=e=>{this.#p(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=m.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#o={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let o=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#o={lng:o.lng,lat:o.lat},this.#t=t.tail?.val,this.showDynamicLine();}};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#o={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#t=t.tail?.val,this.showDynamicLine());}};var fe=22,J=class{props;#e;#i;constructor(e){this.props=e,this.#e=!1,this.#i=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#n),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#n),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#t=e=>{let{store:t,map:i,mode:o}=this.props;if(de(e))return;let s=ce(e,t);s&&(h.addPoint({...s,total:t.size},i,o),pe(e,this.props));};#o=e=>{L.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&L.updatePointsData(e);};#n=M(e=>{if(m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#i=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#i&&(this.#o(this.#i),this.#e=!1);})));},fe);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,L.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,L.setSinglePointHidden(e));}};var W=class{props;#e;#i;#t;#o;constructor(e){this.props=e,this.#e=new Z(e),this.#i=new J(e),this.#t=null,this.#o="default";}init(){this.#n(),this.#s(),this.#r();}#n=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#t=new $(this.props));};#s(){!this.props.mode.getBreak()&&(this.#i.initEvents(),this.props.options.dynamicLine&&this.#t?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#p),this.props.mouseEvents.addObserver(this.#c);}remove(){this.#a(),this.#l();}#a(){this.props.mode.removeObserver(this.#p),this.props.mouseEvents.removeObserver(this.#c),this.props.options.dynamicLine&&this.#t?.removeConsumers();}#l(){this.#e.removeBreakEvents(),this.#i.removeEvents(),this.props.options.dynamicLine&&(this.#t?.removeEvents(),this.#t?.removeLine());}#c=e=>{let{type:t,data:i}=e,{mode:o}=this.props;if(!(!i||!o.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#p=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#o==="break"&&(this.#e.removeBreakEvents(),this.#i.initEvents(),this.#o="default"),t==="BREAK_CHANGED"&&i&&this.#o==="default"&&(this.#i.removeEvents(),this.#e.initBreakEvents(),this.#o="break");}};var X=class{#e;#i;#t;constructor(e){this.#i=e,this.#e=!1,this.#t=new b,e.mode.addObserver(this.#o);}initEvents(){let{map:e}=this.#i;e.on("click",r.FirstPointLayer,this.#n),e.on("mouseenter",r.FirstPointLayer,this.#c),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#i;e.off("click",r.FirstPointLayer,this.#n),e.off("mouseenter",r.FirstPointLayer,this.#c),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#o=e=>{let{map:t,store:i}=this.#i,{type:o,data:s}=e;o==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#n):t.off("click",r.FirstPointLayer,this.#n),d.canCloseGeometry(i)&&f.togglePointCircleRadius(t,"large"));};#n=()=>{let{store:e,map:t,mode:i,tiles:o}=this.#i;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),d.canCloseGeometry(e)){d.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:P(),total:e.size});h.addPoint(s,t,i),f.togglePointCircleRadius(t,"default"),o.render();}};#s=()=>{this.#e=!0,this.#t.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#i;this.#e||(e.firstPointMouseLeave=!0,this.#t.remove());};#l=()=>{let{mode:e,options:t}=this.#i;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#c=e=>{let{mode:t,mouseEvents:i,store:o}=this.#i;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,d.canCloseGeometry(o))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#t.create({label:this.#l(),placement:"bottom"});let S=this.#t._label?this.#t._label.clientWidth/2:0;this.#t.setPosition({x:s-S,y:a+14});}}}};var Q=class{#e;#i;#t;#o;#n;#s;#r;#a;constructor(e){this.#e=e,this.#i=void 0,this.#t=null,this.#o=null,this.#n=null,this.#s=new X(e),this.#r=!1,this.#a=null;}#l=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#d),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#E),e.on("mousedown",r.FirstPointLayer,this.#h),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#h),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#p),e.on("click",r.PointsLayer,this.#d),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#E),e.on("mousedown",r.PointsLayer,this.#h),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#h),this.#l();};#c=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#d),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#E),e.off("mousedown",r.FirstPointLayer,this.#h),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#h),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#p),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#d),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#E),e.off("mousedown",r.PointsLayer,this.#h),e.off("mouseup",r.PointsLayer,this.#u),this.#c();};#p=e=>{e.preventDefault();};#d=e=>{let{store:t,tiles:i,panel:o,map:s,mouseEvents:a}=this.#e;f.isDoubleClick()&&this.#o&&(t.removeStepById(this.#o.id),o.onPointRemove(t.tail?.val),h.pointDoubleClick({...this.#o,total:t.size},this.#e.map),d.switchToLineModeIfCan(this.#e));let c=m.queryPointId(s,e.point);E.isLastPoint(t,c)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:o}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),o.getCanvasContainer().style.cursor="grab",L.addPointToMap(e,this.#e),L.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#g=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#n,e.lngLat);};#y=M(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#o||!this.#a||(L.updateSelectedStepLatLng(this.#a,this.#o),this.#v(this.#a),this.#g(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:o}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;L.setSinglePointHidden(e);let s=m.queryPointId(i,e.point);E.isLastPoint(o,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=o.findStepById(s);a&&(this.#t=a,h.enterPoint(Object.assign({},a,{total:o.size}),i));};#E=e=>{let{mouseEvents:t,store:i,map:o}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=m.queryPointId(o,e.point);E.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),h.leavePoint(Object.assign({},this.#t,{total:i.size}),o);};#P=()=>{let{store:e,panel:t}=this.#e;this.#o&&E.isLastPoint(e,this.#o.id)&&t.hidePanel();};#M=e=>{let{store:t,map:i}=this.#e,o=m.queryPointId(i,e.point),s=t.findStepById(o);s&&(this.#o=s);};#h=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:o}=this.#e;f.removeTransparentLine(i),this.#M(e),this.#P();let s=m.queryPointId(i,e.point);this.#n=d.getGeometryIndex(o,s),t&&(t.pointMouseDown=!0),this.#i=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:o,options:s}=this.#e;e.pointMouseUp=!0,this.#o&&(E.isLastPoint(t,this.#o.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),h.movePoint({id:this.#o.id,total:t.size,end:{lat:this.#o.lat,lng:this.#o.lng},start:this.#i},o)),e&&(e.pointMouseDown=!1),f.addTransparentLine(o,s),o.off("mousemove",this.#y),o.off("touchmove",this.#y);}};var ee=class extends x{#e;#i;#t;#o;#n;constructor(e){super({...e}),this.#e=e,this.#i=new K(e),this.#t=new j(e),this.#o=new Q(e),this.#n=new W(e),e.map.on("mode:initialize",this.#s),e.map.on("mode:remove",this.#r);}#s=()=>{this.#n.init(),this.#i?.initEvents(),this.#o?.initEvents();};#r=()=>{this.#i?.removeEvents(),this.#o?.removeEvents(),this.#n?.remove();};removeMapEventsAndConsumers=()=>{this.#i?.removeEvents(),this.#o?.removeEvents(),this.#t?.remove(),this.#n?.remove(),this.#e.map.off("mode:initialize",this.#s);}};var te=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,o)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),o&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#i=e=>{let{mode:t,options:i}=e,o=this.#e.modes.line.visible,s=i.locale.line;o&&(this._line=this.createControlButton("line",s,t.getMode()==="line"));};#t=e=>{let{mode:t,options:i}=e,o=this.#e.modes.polygon.visible,s=i.locale.polygon;o&&(this._polygon=this.createControlButton("polygon",s,t.getMode()==="polygon"));};#o=e=>{let{mode:t,options:i}=e,o=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(o){let c=!this.#e?.initial?.closeGeometry,S=t.getBreak();this._break=this.createControlButton("break",s,S,c);}};createControl=e=>{this.#i(e),this.#t(e),this.#o(e);};getContainer=()=>this._container};function ve(n){return n.initial?.geometry?n.initial?.geometry:n.modes.initial?n.modes.initial:null}var ie=class extends C{#e;#i;#t;constructor(e){super(),this.#e=ve(e),this.#i=!1,this.#t=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#i;setBreak=e=>{this.#i=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#t;setClosedGeometry=e=>{this.#t=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#t});};isPolygon=()=>this.#e==="polygon"&&this.#t;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var oe=class{#e;#i;constructor(e){this.#e=e,this.#i=this.#e.map.getCanvasContainer(),this.#i.style.cursor=e.mode.getMode()?v.CROSSHAIR:v.AUTO,this.#t();}set=e=>{this.#i.style.cursor=e;};get=()=>this.#i.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;if(!e.pointMouseDown){if(!t.getMode()){this.set(v.AUTO);return}t.getClosedGeometry()?this.set(v.AUTO):this.set(v.CROSSHAIR);}};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(v.MOVE),d.canCloseGeometry(t)&&this.set(v.POINTER);};#t(){let{mouseEvents:e}=this.#e;e.addObserver(this.#o);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#o);}#o=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:o,data:s}=e;if(s)switch(o){case"pointMouseDown":this.set(v.GRABBING);break;case"pointMouseUp":this.set(v.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(v.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(v.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(v.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var ne=class extends C{#e;#i;#t;#o;#n;#s;#r;#a;#l;#c;#p;#d;constructor(){super(),this.#e=!1,this.#i=!1,this.#t=!1,this.#o=!1,this.#n=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#l=!1,this.#c=!1,this.#p=!1,this.#d=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#i}set firstPointMouseLeave(e){this.#i=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#t}set lastPointMouseClick(e){this.#t=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#o}set lastPointMouseUp(e){this.#o=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#n}set lastPointMouseEnter(e){this.#n=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#l}set pointMouseEnter(e){this.#l=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#c}set pointMouseLeave(e){this.#c=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#p}set lineMouseEnter(e){this.#p=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#d}set lineMouseLeave(e){this.#d=e,this.notify({type:"lineMouseLeave",data:e});}};var R=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,o=!this.allStepsHaveIds(e);if(i&&o)throw new Error(I.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(I.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let o=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,c=i[i.length-1]?.lat;if((o!==s||a!==c)&&t)throw new Error(I.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:o}=e;this.checkIfMissingIds(o,i),this.checkIfEnoughPointsToClose(o,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:Le(e),modes:Ee(e),layersPaint:ge(e),initial:e.initial||u.initial,locale:Pe(e),dynamicLine:e.dynamicLine??u.dynamicLine}:u}};function Le(n){return {size:n.panel?.size||u.panel.size,buttons:{undo:{visible:n.panel?.buttons?.undo?.visible??u.panel.buttons.undo.visible},delete:{visible:n.panel?.buttons?.delete?.visible??u.panel.buttons.delete.visible},save:{visible:n.panel?.buttons?.save?.visible??u.panel.buttons.save.visible,clearOnSave:n.panel?.buttons?.save?.clearOnSave??u.panel.buttons.save.clearOnSave}}}}function Ee(n){return {initial:n.modes?.initial||u.modes.initial,line:{visible:n?.modes?.line?.visible!==void 0?n.modes.line.visible:n?.initial?.geometry==="line"||u.modes.line.visible,closeGeometry:n?.modes?.line?.closeGeometry??n?.initial?.closeGeometry??u.modes.line.closeGeometry},polygon:{visible:n?.modes?.polygon?.visible!==void 0?n.modes.polygon.visible:n?.initial?.geometry==="polygon"||u.modes.polygon.visible},breakGeometry:{visible:n?.modes?.breakGeometry?.visible??u.modes.breakGeometry.visible}}}function ge(n){return {onLinePoint:{"circle-radius":n.layersPaint?.onLinePoint?.["circle-radius"]||O["circle-radius"],"circle-color":n.layersPaint?.onLinePoint?.["circle-color"]||O["circle-color"],"circle-stroke-color":n.layersPaint?.onLinePoint?.["circle-stroke-color"]||O["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.onLinePoint?.["circle-stroke-width"]||O["circle-stroke-width"],...n.layersPaint?.onLinePoint},firstPoint:{"circle-radius":n.layersPaint?.firstPoint?.["circle-radius"]||k["circle-radius"],"circle-color":n.layersPaint?.firstPoint?.["circle-color"]||k["circle-color"],"circle-stroke-color":n.layersPaint?.firstPoint?.["circle-stroke-color"]||k["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.firstPoint?.["circle-stroke-width"]||k["circle-stroke-width"],...n.layersPaint?.firstPoint},points:{"circle-radius":n.layersPaint?.points?.["circle-radius"]||T["circle-radius"],"circle-color":n.layersPaint?.points?.["circle-color"]||T["circle-color"],"circle-stroke-color":n.layersPaint?.points?.["circle-stroke-color"]||T["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.points?.["circle-stroke-width"]||T["circle-stroke-width"],...n.layersPaint?.points},line:{"line-width":n.layersPaint?.line?.["line-width"]||_["line-width"],"line-color":n.layersPaint?.line?.["line-color"]||_["line-color"],"line-opacity":n.layersPaint?.line?.["line-opacity"]||_["line-opacity"],...n.layersPaint?.line},polygon:{"fill-color":n.layersPaint?.polygon?.["fill-color"]||A["fill-color"],"fill-opacity":n.layersPaint?.polygon?.["fill-opacity"]||A["fill-opacity"],...n.layersPaint?.polygon},breakLine:{"line-width":n.layersPaint?.breakLine?.["line-width"]||D["line-width"],"line-color":n.layersPaint?.breakLine?.["line-color"]||D["line-color"],"line-dasharray":n.layersPaint?.breakLine?.["line-dasharray"]||D["line-dasharray"],...n.layersPaint?.breakLine}}}function Pe(n){return {save:n.locale?.save??u.locale.save,delete:n.locale?.delete??u.locale.delete,undo:n.locale?.undo??u.locale.undo,line:n.locale?.line??u.locale.line,polygon:n.locale?.polygon??u.locale.polygon,break:n.locale?.break??u.locale.break,closeLine:n.locale?.closeLine??u.locale.closeLine,createPolygon:n.locale?.createPolygon??u.locale.createPolygon}}var re=class n{#e;#i;#t;#o;#n;#s;#r;#a;#l;static#c=null;static#p=!1;constructor(e){if(this.#o=R.init(e),this.#o.initial&&R.checkInitialStepsOption(this.#o.initial),n.#p)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");n.#p=!0,this.#i=void 0,this.#t=void 0,this.#n=void 0,this.#s=void 0,this.#r=void 0,this.#l=void 0,this.#a=void 0;}static getInstance(e){return n.#c||(n.#c=new n(e)),n.#c}onAdd(e){this.#i=new B(this.#o),this.#t=new ie(this.#o),this.#r=new F({map:e,mode:this.#t,options:this.#o,store:this.#i}),this.#s=new x({map:e,store:this.#i,options:this.#o,mode:this.#t});let t=new te({options:this.#o,mode:this.#t});return this.#l=new ne,this.#a=new oe({map:e,mode:this.#t,mouseEvents:this.#l,store:this.#i}),this.#n=new ee({map:e,store:this.#i,options:this.#o,panel:this.#r,control:t,mode:this.#t,tiles:this.#s,mouseEvents:this.#l}),this.#t.getMode()&&e.fire("mode:initialize"),this.#t.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#n?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#i?.reset(),this.#t?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||P()};this.#i?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#i?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#i)return E.toArray(this.#i.head);if(e==="linkedlist")return this.#i;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#o=e(this.#o);};removeAllSteps=()=>{this.#i?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
1
|
+
var l=class n{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=n.testProp(["transform","WebkitTransform"]);static testProp(e){if(!n.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in n.docStyle)return e[t];return e[0]}static create(e,t,i){let o=window.document.createElement(e);return t!==void 0&&(o.className=t),i&&i.appendChild(o),o}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){n.transformProp&&e.style&&(e.style[n.transformProp]=t);}static manageEventListener(e,t,i,o,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,o,s):t[a](i,o,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var F=class{#e;#i;#t;_undoButton;_deleteButton;_saveButton;_container;_updatePositionCallback;constructor(e){this.#e=e,this._container=void 0,this.#i=!0,this.#t=void 0,this.#r(),this.#o();}#o(){this.#e.mode?.addObserver(this.#n);}#n=e=>{let{store:t}=this.#e,{type:i,data:o}=e;i==="MODE_CHANGED"&&!o&&this.hidePanel(),i==="MODE_CHANGED"&&o&&t.tail?.val&&this.setPanelLocation({lat:t.tail?.val?.lat,lng:t.tail?.val?.lng});};#s(){this.#t&&(this.#t.className="dashboard-container",this.#t.style.position="absolute",this.#t.style.zIndex="1000000",this.#t.style.pointerEvents="auto",this.#t.style.display=this.#i?"none":"block");}#r=()=>{let{store:e}=this.#e;this.createPanel(),this.#t=document.createElement("div"),this.#s(),this._container&&this.#t.appendChild(this._container),document.body.appendChild(this.#t),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{if(!this.#t)return;this.#i&&this.showPanel();let t=this.#e.map.project(e);this.#a(t),this.#l(e);};#a=e=>{if(this.#i||!this.#t)return;let i=this.#e.map.getContainer().getBoundingClientRect(),o=i.left+e.x,s=i.top+e.y,a=36;this.#t.style.left=`${o-a}px`,this.#t.style.top=`${s-a}px`;};#l(e){this.#c(),this._updatePositionCallback=()=>{this.#i||!this.#t||this.#a(this.#e.map.project(e));},this.#e.map.on("move",this._updatePositionCallback),this.#e.map.on("zoom",this._updatePositionCallback);}#c(){this._updatePositionCallback&&(this.#e.map.off("move",this._updatePositionCallback),this.#e.map.off("zoom",this._updatePositionCallback),this._updatePositionCallback=void 0);}showPanel=()=>{this.#i&&this.#t&&(this.#i=!1,this.#t.style.display="block",this.#t.style.transition="opacity 0.2s",this.#t.style.opacity="1");};hidePanel=()=>{!this.#i&&this.#t&&(this.#i=!0,this.#t.style.display="none");};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._updatePositionCallback&&(this.#e.map.off("move",this._updatePositionCallback),this.#e.map.off("zoom",this._updatePositionCallback),this._updatePositionCallback=void 0),this.#t&&(document.body.removeChild(this.#t),this.#t=void 0),this._container&&(l.remove(this._container),this._container=void 0);};createButton=(e,t,i,o)=>{let s=l.create("button",`panel-button panel-button-${i}`,o);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:o,save:s}=e.panel.buttons,a=e.panel.size,c=l.create("div","dashboard");i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,c)),o.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,c)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,c)),this._container=c;}};var N={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},G={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},ae={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},p={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},w={large:6.5,default:5.5},H={large:"#FF6464",default:"#666666"},k={"circle-radius":w.default,"circle-color":"#FEFFFE","circle-stroke-color":H.default,"circle-stroke-width":3},O={"circle-radius":w.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},A={"fill-color":"grey","fill-opacity":.4},_={"line-width":3,"line-color":"grey","line-opacity":.7},T={"circle-radius":w.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},D={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},U=n=>[{id:r.SinglePointLayer,source:p.SinglePointSource,type:"circle",paint:n.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:p.PolygonSource,type:"fill",paint:n.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:p.LineDynamicSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:p.LineSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:p.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:p.LineSourceBreak,type:"line",paint:n.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:p.PointsSource,type:"circle",paint:n.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:p.PointsSource,type:"circle",paint:n.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var f=class{static#e=0;static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",w.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",H.large);};static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",w.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",H.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#i(e):this.#t(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let o=U(t).find(s=>s.id===r.LineLayerTransparent);o&&e.addLayer(o);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var m=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(o=>t.includes(o.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:o}=t;return e.project([o,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},g=class{static#e(e){let t=[],i=e.head,o=new Set;for(;i!==null;){if(o.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}o.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],o=new Set;for(;t!==null&&!o.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}o.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},d=class n{static getGeometryIndex=(e,t)=>{let i=e.head,o=0;for(;i!==null;){if(i.val?.id===t)return o;o++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),c=this.distance(i,t);return Math.abs(a+c-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,o=e.tail;do{if(i?.val?.id===t){i!==e.head&&(o.next=i.next,e.head=i,e.tail=o),e.tail.next=null;return}o=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:o,map:s}=e;n.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),f.togglePointCircleRadius(s,"default"),o.renderPolygon(N));}},P=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function n(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(o){let s="";for(let a=0;a<o;a++)s+=n();return s}function t(o){let s=o===0,a=o===4;return s?8:a?12:4}let i=[];for(let o=0;o<5;o++)i.push(e(t(o)));return i.join("-")},M=(n,e)=>{let t,i=!0;function o(){i&&t&&(n(...t),t=null,i=!1,setTimeout(()=>{i=!0,o();},e));}return function(...s){t=s,o();}};var x=class{#e;#i;#t;#o;constructor(e){this.#e=e,this.#n(),this.render();}#n(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(p).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;U(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,o=i.getLayer(e),s=i.getLayer(t);o&&s&&i.moveLayer(e,t);};#l=()=>{let{map:e}=this.#e;Object.values(p).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#c=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#c(),this.#l();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(p.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,o=i.getSource(t);o&&o.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(p.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,o=g.getPoints(i),s=g.getAllLines(i);if(this.#i=o,this.#t=s,this.renderPoints(o),this.renderLines(s,p.LineSource),t.modes.polygon.visible&&e.isPolygon()){let c=g.getPolygon(i);this.#o=c,this.renderPolygon(c);}};#p=(e,t)=>{if(this.#o.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let o=this.#o.features[0].geometry.coordinates[0]?.length-1;this.#o.features[0].geometry.coordinates[0][o]=[t.lng,t.lat];}this.renderPolygon(this.#o);};#d=(e,t)=>{let{mode:i}=this.#e;this.#t.features[0].geometry.coordinates[e]=[t.lng,t.lat];let o=e===0;if(this.#t&&i.getClosedGeometry()&&o){let a=this.#t.features[0].geometry.coordinates?.length-1;this.#t.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#t,p.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:o}=this.#e;this.#i.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#i),this.#d(e,t),o.modes.polygon.visible&&i.isPolygon()&&this.#p(e,t);};resetGeometries=()=>{this.renderPoints(ae),this.renderLines(G,p.LineSource),this.renderPolygon(N);}};var he=8,me=8,b=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#i=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#t=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:o,height:s}=this.#i();return {x:i-me-o,y:t-s-2}};#o=e=>{let{bottom:t,left:i,right:o}=e.target.getBoundingClientRect(),{width:s}=this.#i();return {x:(o-i)/2+i-s/2,y:t+he}};getPosition=(e,t)=>t==="left"?this.#t(e):this.#o(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var v={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var q=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",n,t,i);},z=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",n,t,i);},le=(n,e)=>{let t=e.locale.line,i=e.locale.polygon,o=e.locale.break;return {line:t,polygon:i,break:o}[n]};var y={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",MODECHANGED:"mdl:modechanged"};var u={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{initial:null,line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:O,firstPoint:k,points:T,line:_,polygon:A,breakLine:D},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var h=class{static addPoint(e,t,i){t.fire(y.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(y.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(y.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(y.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(y.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(y.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static modeChanged(e,t){e.fire(y.MODECHANGED,{mode:t});}static removeAllPoints(e,t){e.fire(y.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:o,mode:s}=e;o.fire(y.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onLineBreak(e){e.fire(y.BREAK);}};var Y=class{#e;constructor(e){this.#e=e,this.#i();}#i=()=>{this.#e.mode.addObserver(this.#l);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#l);};#t=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#o=e=>{this.#t(),e.classList.add("control-button-active");};#n=e=>{let{data:t}=e,{_line:i,_polygon:o,_break:s}=this.#e.control,{mode:a}=this.#e;if(h.modeChanged(this.#e.map,t),!(!i||!o||!s)){switch(t){case"line":this.#o(i);break;case"polygon":this.#o(o);break;}t?a.getClosedGeometry()&&this.#r(s):this.#s(s);}};#s=e=>{e.setAttribute("disabled","true"),e.setAttribute("aria-disabled","true");};#r=e=>{e.removeAttribute("disabled"),e.removeAttribute("aria-disabled");};#a=e=>{let{data:t}=e,{_break:i,_line:o,_polygon:s}=this.#e.control,{mode:a}=this.#e;t?(i&&this.#r(i),a.getMode()==="polygon"&&o&&this.#s(o),a.getMode()==="line"&&s&&this.#s(s)):(i&&this.#s(i),a.getMode()==="polygon"&&o&&this.#r(o),a.getMode()==="line"&&s&&this.#r(s));};#l=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#n(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#a(e),t==="BREAK_CHANGED"&&i){let{_break:o}=this.#e.control;this.#o(o),h.modeChanged(this.#e.map,"break");}}};var j=class{#e;#i;#t;constructor(e){this.#e=e,this.#t=new Y(e),this.#i=new b,this.#o();}#o(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&q(e._line,{...t,click:this.onLineClick}),e._polygon&&q(e._polygon,{...t,click:this.onPolygonClick}),e._break&&q(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&z(e._line,{...t,click:this.onLineClick}),e._polygon&&z(e._polygon,{...t,click:this.onPolygonClick}),e._break&&z(e._break,{...t,click:this.onBreakClick});}}remove(){this.#t.removeConsumers(),this.#n(),this.#i.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let o=le(i,t),s="left";this.#i.create({label:o,placement:s}).setPosition(this.#i.getPosition(e,s));}};onButtonLeave=()=>{this.#i.remove();};#s=()=>{let{control:e}=this.#e;e._line?.classList.remove("control-button-active"),e._polygon?.classList.remove("control-button-active"),e._break?.classList.remove("control-button-active");};#r=()=>{let{map:e,mode:t}=this.#e;t.getMode()||e.fire("mode:initialize");};onLineClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="line"&&!t.getBreak()?(t.setMode(null),e.fire("mode:remove"),i.resetGeometries()):(o._line?.classList.add("control-button-active"),t.setMode("line"),i.render());};onPolygonClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="polygon"&&!t.getBreak()?(t.setMode(null),e.fire("mode:remove"),e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries()):(o._polygon?.classList.add("control-button-active"),t.setMode("polygon"),i.render());};onBreakClick=()=>{let{map:e,mode:t,control:i}=this.#e;t.getBreak()&&(t.setMode(null),e.fire("mode:remove")),this.#s(),i._break?.classList.add("control-button-active"),t.setBreak(!0),e.getCanvasContainer().style.cursor=v.POINTER;}};var C=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var I={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var V=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},B=class extends C{head;tail;size;constructor(e){super();let t=E.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new V(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new V(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},E=class n{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(I.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:o,closeGeometry:s,generateId:a}=e.initial;return n.fromArray(o,s,a)}return null}static#e=e=>e.map(t=>({...t,id:P()}));static buildStepSequence(e){let t=new B;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let o=i?this.#e(e):e,s=this.buildStepSequence(o);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],o=e;for(;o!==null&&!t.has(o);)t.add(o),i.push(o.val),o=o.next;return i}};var K=class{#e;#i;constructor(e){this.#e=e,this.#i=new b;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#n),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#o),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#n),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#o),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#t=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#t(t);this.#i.create({label:i,placement:"bottom"}).setPosition(this.#i.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#i.remove();};#o=e=>{let{tiles:t,mode:i,panel:o,store:s,map:a}=this.#e;s.reset(),o.hidePanel(),i.reset(),f.togglePointCircleRadius(a,"default"),this.#i.remove(),t.resetGeometries(),h.removeAllPoints(a,e);};#n=e=>{let{store:t,panel:i,map:o,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id),console.log("removeStepById",a);let c={...a,total:t.size};h.undoPoint(c,o,e),d.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#i.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;h.onSaveClick(this.#e,E.toArray(t.head),e),this.#i.remove(),i.panel.buttons.save.clearOnSave&&this.#o(e);}};var L=class{static updatePointsData(e){let i=e.target.getSource(p.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,store:o,map:s}=t;d.canCloseGeometry(o)&&f.togglePointCircleRadius(s,"large"),i?.setPanelLocation(e.lngLat);}static addPointToMap=(e,t)=>{let{store:i,tiles:o,map:s,mode:a}=t,c={...e.lngLat,id:P()};i.push(c),h.addPoint({...c,total:i.size},s,a),this.triggerPostPointAddition(e,t),requestAnimationFrame(o.render);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var se=(n,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let o=n.target,s=m.getPixelCoordinates(o,t.val),a=m.getPixelCoordinates(o,t.next.val),c=m.getPixelCoordinates(o,n.lngLat);if(d.checkIfPointIsOnLine(s,a,c))return t}i.add(t),t=t.next;}return null},ce=(n,e)=>{let t=se(n,e);if(t){let i={...n.lngLat,id:P()};return e.insert(i,t),i}return null},pe=(n,e)=>{let{store:t,tiles:i,panel:o}=e;t.tail?.val&&(o?.setPanelLocation(t.tail.val),L.setSinglePointHidden(n),i.render());},de=n=>m.isFeatureTriggered(n,[r.PointsLayer,r.FirstPointLayer]);var ue=15,Z=class{props;#e;#i;constructor(e){this.props=e,this.#e=null,this.#i=M(this.#o,ue);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#t),e.on("mouseenter",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#i),e.on("mouseleave",r.LineLayerTransparent,this.#n);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#t),e.off("mouseenter",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#i),e.off("mouseleave",r.LineLayerTransparent,this.#n);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#t=()=>{let{store:e,mode:t,panel:i,map:o,tiles:s}=this.props,a=this.#e?.next?.val?.id;d.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#n(),o.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),h.onLineBreak(o);};#o=e=>{let{map:t,store:i}=this.props,o=se(e,i);o?.val?.id!==this.#e?.val?.id&&(this.#e=o);let s=t.getSource(p.LineSourceBreak),a=[o?.val?.lng,o?.val?.lat],c=[o?.next?.val?.lng,o?.next?.val?.lat],S=g.getLine(a,c);S&&(s.setData(S),this.showBreakLine());};#n=()=>{setTimeout(()=>{this.hideBreakLine();},ue+10);}};var ye=10,$=class{#e;#i;#t;#o;#n;#s;constructor(e){this.#e=e,this.#i=e.options.dynamicLine,this.#t=null,this.#o=null,this.#r(),this.#s=M(this.#d,ye);}#r(){this.#e.store.addObserver(this.#l),this.#e.mode.addObserver(this.#c),this.#e.mouseEvents.addObserver(this.#a);}removeLine=()=>{this.hideDynamicLine();};removeConsumers=()=>{this.#e.store.removeObserver(this.#l),this.#e.mode.removeObserver(this.#c),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#i=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#i=!0),!!this.#i&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#t=i.tail?.val,this.#o=i.tail?.val,this.showDynamicLine();}};#l=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!d.isClosedGeometry(t)&&(this.#t=e.data.tail?.val,this.showDynamicLine());break;}};#c=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#t=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(y.REMOVEALL,this.hideDynamicLine),e.on(y.UNDO,this.#m),e.on(y.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(y.REMOVEALL,this.hideDynamicLine),e.off(y.UNDO,this.#m),e.off(y.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#t=null,this.#o=null,this.#n=null,e.off("mousemove",this.#s),t.renderLines(G,p.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#t?.lng,this.#t?.lat],i=[this.#o?.lng,this.#o?.lat];this.#n=g.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#o&&this.#p({lng:this.#o?.lng,lat:this.#o?.lat}),e.on("mousemove",this.#s);};#p=e=>{if(!this.#n)return;let{tiles:t}=this.#e;this.#n.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#n,p.LineDynamicSource);};#d=e=>{this.#p(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=m.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#o={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let o=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#o={lng:o.lng,lat:o.lat},this.#t=t.tail?.val,this.showDynamicLine();}t.size===0&&this.hideDynamicLine();};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#o={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#t=t.tail?.val,this.showDynamicLine()),t.size===0&&this.hideDynamicLine();}};var fe=22,J=class{props;#e;#i;constructor(e){this.props=e,this.#e=!1,this.#i=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#n),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#n),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#t=e=>{let{store:t,map:i,mode:o}=this.props;if(de(e))return;let s=ce(e,t);s&&(h.addPoint({...s,total:t.size},i,o),pe(e,this.props));};#o=e=>{L.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&L.updatePointsData(e);};#n=M(e=>{if(m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#i=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#i&&(this.#o(this.#i),this.#e=!1);})));},fe);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,L.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,L.setSinglePointHidden(e));}};var W=class{props;#e;#i;#t;#o;constructor(e){this.props=e,this.#e=new Z(e),this.#i=new J(e),this.#t=null,this.#o="default";}init(){this.#n(),this.#s(),this.#r();}#n=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#t=new $(this.props));};#s(){!this.props.mode.getBreak()&&(this.#i.initEvents(),this.props.options.dynamicLine&&this.#t?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#p),this.props.mouseEvents.addObserver(this.#c);}remove(){this.#a(),this.#l();}#a(){this.props.mode.removeObserver(this.#p),this.props.mouseEvents.removeObserver(this.#c),this.props.options.dynamicLine&&this.#t?.removeConsumers();}#l(){this.#e.removeBreakEvents(),this.#i.removeEvents(),this.props.options.dynamicLine&&(this.#t?.removeEvents(),this.#t?.removeLine());}#c=e=>{let{type:t,data:i}=e,{mode:o}=this.props;if(!(!i||!o.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#p=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#o==="break"&&(this.#e.removeBreakEvents(),this.#i.initEvents(),this.#o="default"),t==="BREAK_CHANGED"&&i&&this.#o==="default"&&(this.#i.removeEvents(),this.#e.initBreakEvents(),this.#o="break");}};var X=class{#e;#i;#t;constructor(e){this.#i=e,this.#e=!1,this.#t=new b,e.mode.addObserver(this.#o);}initEvents(){let{map:e}=this.#i;e.on("click",r.FirstPointLayer,this.#n),e.on("mouseenter",r.FirstPointLayer,this.#c),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#i;e.off("click",r.FirstPointLayer,this.#n),e.off("mouseenter",r.FirstPointLayer,this.#c),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#o=e=>{let{map:t,store:i}=this.#i,{type:o,data:s}=e;o==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#n):t.off("click",r.FirstPointLayer,this.#n),d.canCloseGeometry(i)&&f.togglePointCircleRadius(t,"large"));};#n=()=>{let{store:e,map:t,mode:i,tiles:o}=this.#i;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),d.canCloseGeometry(e)){d.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:P(),total:e.size});h.addPoint(s,t,i),f.togglePointCircleRadius(t,"default"),o.render();}};#s=()=>{this.#e=!0,this.#t.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#i;this.#e||(e.firstPointMouseLeave=!0,this.#t.remove());};#l=()=>{let{mode:e,options:t}=this.#i;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#c=e=>{let{mode:t,mouseEvents:i,store:o}=this.#i;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,d.canCloseGeometry(o))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#t.create({label:this.#l(),placement:"bottom"});let S=this.#t._label?this.#t._label.clientWidth/2:0;this.#t.setPosition({x:s-S,y:a+14});}}}};var Q=class{#e;#i;#t;#o;#n;#s;#r;#a;constructor(e){this.#e=e,this.#i=void 0,this.#t=null,this.#o=null,this.#n=null,this.#s=new X(e),this.#r=!1,this.#a=null;}#l=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#d),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#E),e.on("mousedown",r.FirstPointLayer,this.#h),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#h),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#p),e.on("click",r.PointsLayer,this.#d),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#E),e.on("mousedown",r.PointsLayer,this.#h),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#h),this.#l();};#c=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#d),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#E),e.off("mousedown",r.FirstPointLayer,this.#h),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#h),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#p),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#d),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#E),e.off("mousedown",r.PointsLayer,this.#h),e.off("mouseup",r.PointsLayer,this.#u),this.#c();};#p=e=>{e.preventDefault();};#d=e=>{let{store:t,tiles:i,panel:o,map:s,mouseEvents:a}=this.#e;f.isDoubleClick()&&this.#o&&(t.removeStepById(this.#o.id),o.onPointRemove(t.tail?.val),h.pointDoubleClick({...this.#o,total:t.size},this.#e.map),d.switchToLineModeIfCan(this.#e));let c=m.queryPointId(s,e.point);E.isLastPoint(t,c)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:o}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),o.getCanvasContainer().style.cursor="grab",L.addPointToMap(e,this.#e),L.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#g=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#n,e.lngLat);};#y=M(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#o||!this.#a||(L.updateSelectedStepLatLng(this.#a,this.#o),this.#v(this.#a),this.#g(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:o}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;L.setSinglePointHidden(e);let s=m.queryPointId(i,e.point);E.isLastPoint(o,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=o.findStepById(s);a&&(this.#t=a,h.enterPoint(Object.assign({},a,{total:o.size}),i));};#E=e=>{let{mouseEvents:t,store:i,map:o}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=m.queryPointId(o,e.point);E.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),h.leavePoint(Object.assign({},this.#t,{total:i.size}),o);};#P=()=>{let{store:e,panel:t}=this.#e;this.#o&&E.isLastPoint(e,this.#o.id)&&t.hidePanel();};#M=e=>{let{store:t,map:i}=this.#e,o=m.queryPointId(i,e.point),s=t.findStepById(o);s&&(this.#o=s);};#h=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:o}=this.#e;f.removeTransparentLine(i),this.#M(e),this.#P();let s=m.queryPointId(i,e.point);this.#n=d.getGeometryIndex(o,s),t&&(t.pointMouseDown=!0),this.#i=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:o,options:s}=this.#e;e.pointMouseUp=!0,this.#o&&(E.isLastPoint(t,this.#o.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),h.movePoint({id:this.#o.id,total:t.size,end:{lat:this.#o.lat,lng:this.#o.lng},start:this.#i},o)),e&&(e.pointMouseDown=!1),f.addTransparentLine(o,s),o.off("mousemove",this.#y),o.off("touchmove",this.#y);}};var ee=class extends x{#e;#i;#t;#o;#n;constructor(e){super({...e}),this.#e=e,this.#i=new K(e),this.#t=new j(e),this.#o=new Q(e),this.#n=new W(e),e.map.on("mode:initialize",this.#s),e.map.on("mode:remove",this.#r);}#s=()=>{this.#n.init(),this.#i?.initEvents(),this.#o?.initEvents();};#r=()=>{this.#i?.removeEvents(),this.#o?.removeEvents(),this.#n?.remove();};removeMapEventsAndConsumers=()=>{this.#i?.removeEvents(),this.#o?.removeEvents(),this.#t?.remove(),this.#n?.remove(),this.#e.map.off("mode:initialize",this.#s);}};var te=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,o)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),o&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#i=e=>{let{mode:t,options:i}=e,o=this.#e.modes.line.visible,s=i.locale.line;o&&(this._line=this.createControlButton("line",s,t.getMode()==="line"));};#t=e=>{let{mode:t,options:i}=e,o=this.#e.modes.polygon.visible,s=i.locale.polygon;o&&(this._polygon=this.createControlButton("polygon",s,t.getMode()==="polygon"));};#o=e=>{let{mode:t,options:i}=e,o=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(o){let c=!this.#e?.initial?.closeGeometry,S=t.getBreak();this._break=this.createControlButton("break",s,S,c);}};createControl=e=>{this.#i(e),this.#t(e),this.#o(e);};getContainer=()=>this._container};function ve(n){return n.initial?.geometry?n.initial?.geometry:n.modes.initial?n.modes.initial:null}var ie=class extends C{#e;#i;#t;constructor(e){super(),this.#e=ve(e),this.#i=!1,this.#t=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#i;setBreak=e=>{this.#i=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#t;setClosedGeometry=e=>{this.#t=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#t});};isPolygon=()=>this.#e==="polygon"&&this.#t;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var oe=class{#e;#i;constructor(e){this.#e=e,this.#i=this.#e.map.getCanvasContainer(),this.#i.style.cursor=e.mode.getMode()?v.CROSSHAIR:v.AUTO,this.#t();}set=e=>{this.#i.style.cursor=e;};get=()=>this.#i.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;if(!e.pointMouseDown){if(!t.getMode()){this.set(v.AUTO);return}t.getClosedGeometry()?this.set(v.AUTO):this.set(v.CROSSHAIR);}};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(v.MOVE),d.canCloseGeometry(t)&&this.set(v.POINTER);};#t(){let{mouseEvents:e}=this.#e;e.addObserver(this.#o);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#o);}#o=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:o,data:s}=e;if(s)switch(o){case"pointMouseDown":this.set(v.GRABBING);break;case"pointMouseUp":this.set(v.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(v.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(v.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(v.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var ne=class extends C{#e;#i;#t;#o;#n;#s;#r;#a;#l;#c;#p;#d;constructor(){super(),this.#e=!1,this.#i=!1,this.#t=!1,this.#o=!1,this.#n=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#l=!1,this.#c=!1,this.#p=!1,this.#d=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#i}set firstPointMouseLeave(e){this.#i=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#t}set lastPointMouseClick(e){this.#t=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#o}set lastPointMouseUp(e){this.#o=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#n}set lastPointMouseEnter(e){this.#n=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#l}set pointMouseEnter(e){this.#l=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#c}set pointMouseLeave(e){this.#c=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#p}set lineMouseEnter(e){this.#p=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#d}set lineMouseLeave(e){this.#d=e,this.notify({type:"lineMouseLeave",data:e});}};var R=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,o=!this.allStepsHaveIds(e);if(i&&o)throw new Error(I.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(I.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let o=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,c=i[i.length-1]?.lat;if((o!==s||a!==c)&&t)throw new Error(I.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:o}=e;this.checkIfMissingIds(o,i),this.checkIfEnoughPointsToClose(o,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:Le(e),modes:Ee(e),layersPaint:ge(e),initial:e.initial||u.initial,locale:Pe(e),dynamicLine:e.dynamicLine??u.dynamicLine}:u}};function Le(n){return {size:n.panel?.size||u.panel.size,buttons:{undo:{visible:n.panel?.buttons?.undo?.visible??u.panel.buttons.undo.visible},delete:{visible:n.panel?.buttons?.delete?.visible??u.panel.buttons.delete.visible},save:{visible:n.panel?.buttons?.save?.visible??u.panel.buttons.save.visible,clearOnSave:n.panel?.buttons?.save?.clearOnSave??u.panel.buttons.save.clearOnSave}}}}function Ee(n){return {initial:n.modes?.initial||u.modes.initial,line:{visible:n?.modes?.line?.visible!==void 0?n.modes.line.visible:n?.initial?.geometry==="line"||u.modes.line.visible,closeGeometry:n?.modes?.line?.closeGeometry??n?.initial?.closeGeometry??u.modes.line.closeGeometry},polygon:{visible:n?.modes?.polygon?.visible!==void 0?n.modes.polygon.visible:n?.initial?.geometry==="polygon"||u.modes.polygon.visible},breakGeometry:{visible:n?.modes?.breakGeometry?.visible??u.modes.breakGeometry.visible}}}function ge(n){return {onLinePoint:{"circle-radius":n.layersPaint?.onLinePoint?.["circle-radius"]||O["circle-radius"],"circle-color":n.layersPaint?.onLinePoint?.["circle-color"]||O["circle-color"],"circle-stroke-color":n.layersPaint?.onLinePoint?.["circle-stroke-color"]||O["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.onLinePoint?.["circle-stroke-width"]||O["circle-stroke-width"],...n.layersPaint?.onLinePoint},firstPoint:{"circle-radius":n.layersPaint?.firstPoint?.["circle-radius"]||k["circle-radius"],"circle-color":n.layersPaint?.firstPoint?.["circle-color"]||k["circle-color"],"circle-stroke-color":n.layersPaint?.firstPoint?.["circle-stroke-color"]||k["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.firstPoint?.["circle-stroke-width"]||k["circle-stroke-width"],...n.layersPaint?.firstPoint},points:{"circle-radius":n.layersPaint?.points?.["circle-radius"]||T["circle-radius"],"circle-color":n.layersPaint?.points?.["circle-color"]||T["circle-color"],"circle-stroke-color":n.layersPaint?.points?.["circle-stroke-color"]||T["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.points?.["circle-stroke-width"]||T["circle-stroke-width"],...n.layersPaint?.points},line:{"line-width":n.layersPaint?.line?.["line-width"]||_["line-width"],"line-color":n.layersPaint?.line?.["line-color"]||_["line-color"],"line-opacity":n.layersPaint?.line?.["line-opacity"]||_["line-opacity"],...n.layersPaint?.line},polygon:{"fill-color":n.layersPaint?.polygon?.["fill-color"]||A["fill-color"],"fill-opacity":n.layersPaint?.polygon?.["fill-opacity"]||A["fill-opacity"],...n.layersPaint?.polygon},breakLine:{"line-width":n.layersPaint?.breakLine?.["line-width"]||D["line-width"],"line-color":n.layersPaint?.breakLine?.["line-color"]||D["line-color"],"line-dasharray":n.layersPaint?.breakLine?.["line-dasharray"]||D["line-dasharray"],...n.layersPaint?.breakLine}}}function Pe(n){return {save:n.locale?.save??u.locale.save,delete:n.locale?.delete??u.locale.delete,undo:n.locale?.undo??u.locale.undo,line:n.locale?.line??u.locale.line,polygon:n.locale?.polygon??u.locale.polygon,break:n.locale?.break??u.locale.break,closeLine:n.locale?.closeLine??u.locale.closeLine,createPolygon:n.locale?.createPolygon??u.locale.createPolygon}}var re=class n{#e;#i;#t;#o;#n;#s;#r;#a;#l;static#c=null;static#p=!1;constructor(e){if(this.#o=R.init(e),this.#o.initial&&R.checkInitialStepsOption(this.#o.initial),n.#p)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");n.#p=!0,this.#i=void 0,this.#t=void 0,this.#n=void 0,this.#s=void 0,this.#r=void 0,this.#l=void 0,this.#a=void 0;}static getInstance(e){return n.#c||(n.#c=new n(e)),n.#c}onAdd(e){this.#i=new B(this.#o),this.#t=new ie(this.#o),this.#r=new F({map:e,mode:this.#t,options:this.#o,store:this.#i}),this.#s=new x({map:e,store:this.#i,options:this.#o,mode:this.#t});let t=new te({options:this.#o,mode:this.#t});return this.#l=new ne,this.#a=new oe({map:e,mode:this.#t,mouseEvents:this.#l,store:this.#i}),this.#n=new ee({map:e,store:this.#i,options:this.#o,panel:this.#r,control:t,mode:this.#t,tiles:this.#s,mouseEvents:this.#l}),this.#t.getMode()&&e.fire("mode:initialize"),this.#t.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#n?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#i?.reset(),this.#t?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||P()};this.#i?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#i?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#i)return E.toArray(this.#i.head);if(e==="linkedlist")return this.#i;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#o=e(this.#o);};removeAllSteps=()=>{this.#i?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
2
2
|
|
|
3
3
|
export { re as default };
|
|
4
4
|
//# sourceMappingURL=index.js.map
|