maplibre-gl-components 0.20.4 → 0.20.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ControlGrid-uSfBqe_5.cjs → ControlGrid-BWs3QP5M.cjs} +8 -8
- package/dist/{ControlGrid-DZuo4G2B.js → ControlGrid-V59Ovz6J.js} +14 -14
- package/dist/{DuckDBConverter-B6C0hZof.js → DuckDBConverter-BiaCHtYV.js} +1 -1
- package/dist/{DuckDBConverter-BFaMPglx.cjs → DuckDBConverter-D-Von6Le.cjs} +1 -1
- package/dist/{ShapefileConverter-B27S0Yww.js → ShapefileConverter-CWtJ9IOJ.js} +1 -1
- package/dist/{ShapefileConverter-BIT7sJmm.cjs → ShapefileConverter-wLF296OF.cjs} +1 -1
- package/dist/{geotiff-DG1Dpz4s.cjs → geotiff-CNfLW-N0.cjs} +2 -2
- package/dist/{geotiff-CgNQDPkf.js → geotiff-D9_iwF_H.js} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +3 -3
- package/dist/{lerc-Uc8LAlgh.js → lerc-DZUVO3mM.js} +1 -1
- package/dist/{lerc-BGzVl9ck.cjs → lerc-aWBIByFf.cjs} +1 -1
- package/dist/{maplibre-geoman.es-D7gaavHL.cjs → maplibre-geoman.es-DcHAy9ox.cjs} +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.mjs +1 -1
- package/package.json +1 -1
|
@@ -75,7 +75,7 @@ var Wae=Object.create;var A9=Object.defineProperty;var Xae=Object.getOwnProperty
|
|
|
75
75
|
<p class="maplibre-gl-vector-dataset-loading-text">Loading...</p>
|
|
76
76
|
<p class="maplibre-gl-vector-dataset-loading-progress"></p>
|
|
77
77
|
</div>
|
|
78
|
-
`,this._loadingOverlay.style.display="none",this._loadingText=this._loadingOverlay.querySelector(".maplibre-gl-vector-dataset-loading-text"),this._loadingProgress=this._loadingOverlay.querySelector(".maplibre-gl-vector-dataset-loading-progress"),e.appendChild(this._loadingOverlay),this._boundDragOver=i=>this._handleDragOver(i),this._boundDragLeave=i=>this._handleDragLeave(i),this._boundDrop=i=>this._handleDrop(i),e.addEventListener("dragover",this._boundDragOver),e.addEventListener("dragleave",this._boundDragLeave),e.addEventListener("drop",this._boundDrop)}_removeDragAndDrop(){if(!this._map)return;const e=this._map.getContainer();this._boundDragOver&&e.removeEventListener("dragover",this._boundDragOver),this._boundDragLeave&&e.removeEventListener("dragleave",this._boundDragLeave),this._boundDrop&&e.removeEventListener("drop",this._boundDrop),this._dropZone&&this._dropZone.parentNode&&this._dropZone.parentNode.removeChild(this._dropZone),this._loadingOverlay&&this._loadingOverlay.parentNode&&this._loadingOverlay.parentNode.removeChild(this._loadingOverlay)}_handleDragOver(e){e.preventDefault(),e.stopPropagation(),this._state.isDragging||(this._state.isDragging=!0,this._dropZone&&(this._dropZone.style.display="flex"),this._emit("dragenter"))}_handleDragLeave(e){e.preventDefault(),e.stopPropagation();const t=this._map?.getContainer();t&&!t.contains(e.relatedTarget)&&(this._state.isDragging=!1,this._dropZone&&(this._dropZone.style.display="none"),this._emit("dragleave"))}_handleDrop(e){e.preventDefault(),e.stopPropagation(),this._state.isDragging=!1,this._dropZone&&(this._dropZone.style.display="none");const t=e.dataTransfer?.files;t&&t.length>0&&this._processFiles(Array.from(t))}_handleFileSelect(e){const t=e.target,i=t.files;i&&i.length>0&&this._processFiles(Array.from(i)),t.value=""}async _processFiles(e){this._state.isLoading=!0,this._state.error=null,this._updateButtonState();for(const t of e){if(!ej(t.name,this._options.enableAdvancedFormats)){this._state.error=`Invalid file type: ${t.name}. Accepted: ${this._options.acceptedExtensions.join(", ")}`,this._emit("error",void 0,this._state.error,t.name);continue}if(t.size>this._options.maxFileSize){const n=(this._options.maxFileSize/1048576).toFixed(1);this._state.error=`File too large: ${t.name}. Maximum size: ${n}MB`,this._emit("error",void 0,this._state.error,t.name);continue}const i=YY(t.name);try{if(JY(i)){if(!this._options.enableAdvancedFormats){this._state.error=`${tj(i)} files require enableAdvancedFormats: true`,this._emit("error",void 0,this._state.error,t.name);continue}this._showLoading(`Loading ${t.name}...`),await this._processAdvancedFormat(t,i),this._hideLoading()}else{this._showLoading(`Loading ${t.name}...`);const n=await t.text(),r=JSON.parse(n);await this._processGeoJSON(r,t.name,"geojson"),this._hideLoading()}}catch(n){this._hideLoading(),this._state.error=`Failed to process ${t.name}: ${n instanceof Error?n.message:"Unknown error"}`,this._emit("error",void 0,this._state.error,t.name)}}this._state.isLoading=!1,this._updateButtonState()}async _processAdvancedFormat(e,t){const i=r=>{const s=r.message||`Processing ${e.name}...`,a=r.percent!==void 0?`${r.percent}%`:"";this._updateLoading(s,a),this._options.onConversionProgress?.(r)};this._updateLoading(`Reading ${e.name}...`);const n=await KY(e);if(t==="shapefile"){if(!this._shapefileConverter){this._updateLoading("Loading Shapefile converter...");const{getShapefileConverter:s}=await Promise.resolve().then(()=>require("./ShapefileConverter-BIT7sJmm.cjs")).then(a=>a.ShapefileConverter_exports);this._shapefileConverter=s()}const r=await this._shapefileConverter.convert(n,e.name,i);r.geojson&&(this._updateLoading("Adding to map..."),await this._processGeoJSON(r.geojson,e.name,t))}else if(jY(t)){if(!this._duckdbConverter){this._updateLoading("Loading DuckDB converter...");const{getDuckDBConverter:s}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(a=>a.DuckDBConverter_exports);if(this._duckdbConverter=s(),this._options.duckdbBundleUrl){const{DuckDBConverter:a}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(l=>l.DuckDBConverter_exports);this._duckdbConverter=new a(this._options.duckdbBundleUrl)}}const r=await this._duckdbConverter.convert(n,e.name,i);r.geojson&&(this._updateLoading("Adding to map..."),await this._processGeoJSON(r.geojson,e.name,t))}}async _processGeoJSON(e,t,i="geojson"){if(!this._map)return null;if(!e.type)return this._state.error=`Invalid GeoJSON: missing type property in ${t}`,this._emit("error",void 0,this._state.error,t),null;let n;e.type==="FeatureCollection"?n=e:e.type==="Feature"?n={type:"FeatureCollection",features:[e]}:n={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]};const r=Qu("vds"),s=`${r}-source`,a=new Set;for(const l of n.features)l.geometry&&a.add(l.geometry.type);try{this._map.addSource(s,{type:"geojson",data:n,generateId:!0});const l=[],h=this._options.defaultStyle;if(a.has("Polygon")||a.has("MultiPolygon")){const p=`${r}-fill`;this._map.addLayer({id:p,type:"fill",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-color":h.fillColor,"fill-opacity":h.fillOpacity}}),l.push(p);const g=`${r}-outline`;this._map.addLayer({id:g,type:"line",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"line-color":h.strokeColor,"line-width":h.strokeWidth,"line-opacity":h.strokeOpacity}}),l.push(g)}if(a.has("LineString")||a.has("MultiLineString")){const p=`${r}-line`;this._map.addLayer({id:p,type:"line",source:s,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"MultiLineString"]],paint:{"line-color":h.strokeColor,"line-width":h.strokeWidth,"line-opacity":h.strokeOpacity}}),l.push(p)}if(a.has("Point")||a.has("MultiPoint")){const p=`${r}-point`;this._map.addLayer({id:p,type:"circle",source:s,filter:["any",["==",["geometry-type"],"Point"],["==",["geometry-type"],"MultiPoint"]],paint:{"circle-radius":h.circleRadius,"circle-color":h.circleColor,"circle-stroke-color":h.circleStrokeColor,"circle-stroke-width":h.circleStrokeWidth}}),l.push(p)}const d={id:r,filename:t,sourceId:s,layerIds:l,featureCount:n.features.length,geometryTypes:Array.from(a),loadedAt:new Date,originalFormat:i};return this._state.loadedDatasets.push(d),this._options.fitBounds&&n.features.length>0&&this._fitToData(n),this._emit("load",d),this._emit("update"),d}catch(l){return this._state.error=`Failed to add ${t} to map: ${l instanceof Error?l.message:"Unknown error"}`,this._emit("error",void 0,this._state.error,t),null}}_fitToData(e){if(!this._map)return;let t=1/0,i=1/0,n=-1/0,r=-1/0;const s=l=>{t=Math.min(t,l[0]),n=Math.max(n,l[0]),i=Math.min(i,l[1]),r=Math.max(r,l[1])},a=l=>{for(const h of l)typeof h[0]=="number"?s(h):a(h)};for(const l of e.features){if(!l.geometry)continue;const h=l.geometry;h.type==="Point"?s(h.coordinates):(h.type==="MultiPoint"||h.type==="LineString"||h.type==="MultiLineString"||h.type==="Polygon"||h.type==="MultiPolygon")&&a(h.coordinates)}t!==1/0&&this._map.fitBounds([[t,i],[n,r]],{padding:this._options.fitBoundsPadding})}_removeAllDatasets(){for(const e of this._state.loadedDatasets)if(this._map){for(const t of e.layerIds)this._map.getLayer(t)&&this._map.removeLayer(t);this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)}this._state.loadedDatasets=[]}_checkZoomVisibility(){if(!this._map)return;const e=this._map.getZoom(),{minzoom:t,maxzoom:i}=this._options,n=e>=t&&e<=i;n!==this._zoomVisible&&(this._zoomVisible=n,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const e=this._state.visible&&this._zoomVisible;this._container.style.display=e?"flex":"none"}_updateButtonState(){this._button&&(this._state.isLoading?(this._button.classList.add("maplibre-gl-vector-dataset-button--loading"),this._button.disabled=!0):(this._button.classList.remove("maplibre-gl-vector-dataset-button--loading"),this._button.disabled=!1))}_showLoading(e,t){this._loadingOverlay&&(this._loadingOverlay.style.display="flex",this._loadingText&&(this._loadingText.textContent=e),this._loadingProgress&&(this._loadingProgress.textContent=t||""))}_updateLoading(e,t){this._loadingText&&(this._loadingText.textContent=e),this._loadingProgress&&(this._loadingProgress.textContent=t||"")}_hideLoading(){this._loadingOverlay&&(this._loadingOverlay.style.display="none")}},t6={fillColor:"#ffff00",fillOpacity:.3,strokeColor:"#ffff00",strokeWidth:3,circleRadius:10,circleStrokeWidth:3},Eoe={position:"top-right",className:"",visible:!0,enabled:!1,maxFeatures:10,includeLayers:[],excludeLayers:[],highlightStyle:t6,excludeProperties:[],showGeometryType:!0,showLayerName:!0,maxWidth:320,maxHeight:300,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#333",minzoom:0,maxzoom:24},Soe='<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',rj=class{_container;_button;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_popup;_highlightSourceId="";_highlightLayerIds=[];_boundClickHandler;constructor(e){this._options={...Eoe,...e,highlightStyle:{...t6,...e?.highlightStyle}},this._state={visible:this._options.visible,enabled:this._options.enabled,inspectedFeatures:[],selectedIndex:0,error:null},this._highlightSourceId=`inspect-highlight-${Qu()}`}onAdd(e){return this._map=e,this._container=this._createContainer(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._state.enabled&&this._setupMapListeners(),this._container}onRemove(){this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=void 0),this._removeMapListeners(),this._removeHighlight(),this._hidePopup(),this._map=void 0,this._container?.parentNode?.removeChild(this._container),this._container=void 0,this._button=void 0,this._eventHandlers.clear()}enable(){this._state.enabled||(this._state.enabled=!0,this._updateButtonState(),this._setupMapListeners(),this._updateCursor(!0),this._emit("enable"))}disable(){this._state.enabled&&(this._state.enabled=!1,this._updateButtonState(),this._removeMapListeners(),this._updateCursor(!1),this.clear(),this._emit("disable"))}toggle(){this._state.enabled?this.disable():this.enable()}isEnabled(){return this._state.enabled}show(){this._state.visible||(this._state.visible=!0,this._updateDisplayState(),this._emit("show"))}hide(){this._state.visible&&(this._state.visible=!0,this._updateDisplayState(),this._emit("hide"))}clear(){this._state.inspectedFeatures=[],this._state.selectedIndex=0,this._removeHighlight(),this._hidePopup(),this._emit("clear")}getState(){return{...this._state}}getInspectedFeatures(){return[...this._state.inspectedFeatures]}getSelectedFeature(){return this._state.inspectedFeatures[this._state.selectedIndex]||null}selectFeature(e){if(e>=0&&e<this._state.inspectedFeatures.length){this._state.selectedIndex=e;const t=this._state.inspectedFeatures[e];this._addHighlight(t),this._updatePopupContent(),this._emit("featureselect",t)}}nextFeature(){if(this._state.inspectedFeatures.length>1){const e=(this._state.selectedIndex+1)%this._state.inspectedFeatures.length;this.selectFeature(e)}}previousFeature(){if(this._state.inspectedFeatures.length>1){const e=this._state.selectedIndex===0?this._state.inspectedFeatures.length-1:this._state.selectedIndex-1;this.selectFeature(e)}}update(e){Object.assign(this._options,e),e.highlightStyle&&(this._options.highlightStyle={...t6,...e.highlightStyle}),e.visible!==void 0&&(this._state.visible=e.visible,this._updateDisplayState()),e.enabled!==void 0&&(e.enabled?this.enable():this.disable()),this._emit("update")}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}_emit(e,t){const i=this._eventHandlers.get(e);i&&i.forEach(n=>n({type:e,state:this.getState(),feature:t,features:this._state.inspectedFeatures}))}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibregl-ctrl-group maplibre-gl-inspect ${this._options.className}`.trim(),this._options.backgroundColor&&(e.style.backgroundColor=this._options.backgroundColor),this._options.borderRadius&&(e.style.borderRadius=`${this._options.borderRadius}px`),this._options.opacity!==void 0&&this._options.opacity!==1&&(e.style.opacity=String(this._options.opacity)),this._button=document.createElement("button"),this._button.type="button",this._button.className="maplibre-gl-inspect-button",this._button.title="Inspect features",this._button.innerHTML=Soe,this._button.addEventListener("click",()=>this.toggle()),e.appendChild(this._button),e.style.display=this._state.visible?"block":"none",e}_updateButtonState(){this._button&&(this._state.enabled?(this._button.classList.add("maplibre-gl-inspect-button--active"),this._button.title="Disable inspect mode"):(this._button.classList.remove("maplibre-gl-inspect-button--active"),this._button.title="Inspect features"))}_updateCursor(e){if(this._map){const t=this._map.getCanvas();e?t.style.cursor="crosshair":t.style.cursor=""}}_setupMapListeners(){!this._map||this._boundClickHandler||(this._boundClickHandler=e=>this._handleMapClick(e),this._map.on("click",this._boundClickHandler))}_removeMapListeners(){this._map&&this._boundClickHandler&&(this._map.off("click",this._boundClickHandler),this._boundClickHandler=void 0)}_handleMapClick(e){if(!this._map)return;const t=e.point,i=[e.lngLat.lng,e.lngLat.lat],n=this._queryFeatures(t);if(n.length===0){this.clear();return}const r=n.slice(0,this._options.maxFeatures).map(a=>{const l=a.id,h={type:"Feature",geometry:a.geometry,properties:a.properties||{}};return l!==void 0&&(h.id=l),{id:Qu("inspect"),feature:h,layerId:a.layer?.id||"unknown",sourceId:a.source||"unknown",sourceLayer:a.sourceLayer,featureId:l===void 0?void 0:l,lngLat:i}});this._state.inspectedFeatures=r,this._state.selectedIndex=0;const s=r[0];this._addHighlight(s),this._showPopup(s,i),this._emit("featureselect",s)}_queryFeatures(e){if(!this._map)return[];const t={};this._options.includeLayers.length>0&&(t.layers=this._options.includeLayers);let i=this._map.queryRenderedFeatures(e,t);return this._options.excludeLayers.length>0&&(i=i.filter(n=>n.layer&&!this._options.excludeLayers.includes(n.layer.id))),i=i.filter(n=>n.layer&&!n.layer.id.startsWith("inspect-highlight-")),i}_addHighlight(e){if(!this._map)return;const t=this._map;this._removeHighlight();const i=e.feature,n=i.geometry.type,r=this._options.highlightStyle,s=this._getHighlightTarget(e),a=l=>{if(n==="Point"||n==="MultiPoint"){const h=`${this._highlightSourceId}-circle`;t.addLayer({id:h,type:"circle",...l,paint:{"circle-radius":r.circleRadius,"circle-color":r.fillColor,"circle-opacity":r.fillOpacity,"circle-stroke-color":r.strokeColor,"circle-stroke-width":r.circleStrokeWidth}}),this._highlightLayerIds.push(h)}else if(n==="LineString"||n==="MultiLineString"){const h=`${this._highlightSourceId}-line`;t.addLayer({id:h,type:"line",...l,paint:{"line-color":r.strokeColor,"line-width":r.strokeWidth,"line-opacity":1}}),this._highlightLayerIds.push(h)}else if(n==="Polygon"||n==="MultiPolygon"){const h=`${this._highlightSourceId}-fill`;t.addLayer({id:h,type:"fill",...l,paint:{"fill-color":r.fillColor,"fill-opacity":r.fillOpacity}}),this._highlightLayerIds.push(h);const d=`${this._highlightSourceId}-outline`;t.addLayer({id:d,type:"line",...l,paint:{"line-color":r.strokeColor,"line-width":r.strokeWidth}}),this._highlightLayerIds.push(d)}};if(s){const l={source:s.sourceId};s.sourceLayer&&(l["source-layer"]=s.sourceLayer),l.filter=s.filter;try{a(l);return}catch{this._removeHighlight()}}t.addSource(this._highlightSourceId,{type:"geojson",data:i}),a({source:this._highlightSourceId})}_getHighlightTarget(e){if(!this._map)return null;const{sourceId:t,sourceLayer:i,featureId:n}=e;if(!t||t==="unknown"||n==null)return null;const r=this._map.getSource(t);return!r||r.type==="vector"&&!i?null:{sourceId:t,sourceLayer:i,filter:["==","$id",n]}}_removeHighlight(){if(this._map){for(const e of this._highlightLayerIds)this._map.getLayer(e)&&this._map.removeLayer(e);this._highlightLayerIds=[],this._map.getSource(this._highlightSourceId)&&this._map.removeSource(this._highlightSourceId)}}_showPopup(e,t){if(!this._map)return;this._hidePopup();const i=this._renderPopupContent();this._popup=new ks.Popup({closeButton:!0,closeOnClick:!1,maxWidth:`${this._options.maxWidth}px`,className:"maplibre-gl-inspect-popup"}).setLngLat(t).setHTML(i).addTo(this._map),requestAnimationFrame(()=>{this._attachPopupListeners()})}_hidePopup(){this._popup&&(this._popup.remove(),this._popup=void 0)}_updatePopupContent(){if(this._popup){const e=this._renderPopupContent();this._popup.setHTML(e),this._attachPopupListeners()}}_attachPopupListeners(){if(!this._popup)return;const e=this._popup.getElement();if(!e)return;const t=e.querySelector(".maplibre-gl-inspect-nav-prev"),i=e.querySelector(".maplibre-gl-inspect-nav-next");t&&(t.onclick=n=>{n.stopPropagation(),n.preventDefault(),this.previousFeature()}),i&&(i.onclick=n=>{n.stopPropagation(),n.preventDefault(),this.nextFeature()})}_renderPopupContent(){const e=this._state.inspectedFeatures,t=this._state.selectedIndex,i=e[t];if(!i)return'<div class="maplibre-gl-inspect-empty">No feature selected</div>';const n=i.feature.geometry.type,r=i.layerId,s=i.feature.properties||{};let a='<div class="maplibre-gl-inspect-header">';if(this._options.showGeometryType&&(a+=`<span class="maplibre-gl-inspect-geometry">${this._formatGeometryType(n)}</span>`),this._options.showLayerName&&(a+=`<span class="maplibre-gl-inspect-layer" title="${r}">${r}</span>`),e.length>1){const h=e.length<=1?"disabled":"",d=e.length<=1?"disabled":"";a+=`
|
|
78
|
+
`,this._loadingOverlay.style.display="none",this._loadingText=this._loadingOverlay.querySelector(".maplibre-gl-vector-dataset-loading-text"),this._loadingProgress=this._loadingOverlay.querySelector(".maplibre-gl-vector-dataset-loading-progress"),e.appendChild(this._loadingOverlay),this._boundDragOver=i=>this._handleDragOver(i),this._boundDragLeave=i=>this._handleDragLeave(i),this._boundDrop=i=>this._handleDrop(i),e.addEventListener("dragover",this._boundDragOver),e.addEventListener("dragleave",this._boundDragLeave),e.addEventListener("drop",this._boundDrop)}_removeDragAndDrop(){if(!this._map)return;const e=this._map.getContainer();this._boundDragOver&&e.removeEventListener("dragover",this._boundDragOver),this._boundDragLeave&&e.removeEventListener("dragleave",this._boundDragLeave),this._boundDrop&&e.removeEventListener("drop",this._boundDrop),this._dropZone&&this._dropZone.parentNode&&this._dropZone.parentNode.removeChild(this._dropZone),this._loadingOverlay&&this._loadingOverlay.parentNode&&this._loadingOverlay.parentNode.removeChild(this._loadingOverlay)}_handleDragOver(e){e.preventDefault(),e.stopPropagation(),this._state.isDragging||(this._state.isDragging=!0,this._dropZone&&(this._dropZone.style.display="flex"),this._emit("dragenter"))}_handleDragLeave(e){e.preventDefault(),e.stopPropagation();const t=this._map?.getContainer();t&&!t.contains(e.relatedTarget)&&(this._state.isDragging=!1,this._dropZone&&(this._dropZone.style.display="none"),this._emit("dragleave"))}_handleDrop(e){e.preventDefault(),e.stopPropagation(),this._state.isDragging=!1,this._dropZone&&(this._dropZone.style.display="none");const t=e.dataTransfer?.files;t&&t.length>0&&this._processFiles(Array.from(t))}_handleFileSelect(e){const t=e.target,i=t.files;i&&i.length>0&&this._processFiles(Array.from(i)),t.value=""}async _processFiles(e){this._state.isLoading=!0,this._state.error=null,this._updateButtonState();for(const t of e){if(!ej(t.name,this._options.enableAdvancedFormats)){this._state.error=`Invalid file type: ${t.name}. Accepted: ${this._options.acceptedExtensions.join(", ")}`,this._emit("error",void 0,this._state.error,t.name);continue}if(t.size>this._options.maxFileSize){const n=(this._options.maxFileSize/1048576).toFixed(1);this._state.error=`File too large: ${t.name}. Maximum size: ${n}MB`,this._emit("error",void 0,this._state.error,t.name);continue}const i=YY(t.name);try{if(JY(i)){if(!this._options.enableAdvancedFormats){this._state.error=`${tj(i)} files require enableAdvancedFormats: true`,this._emit("error",void 0,this._state.error,t.name);continue}this._showLoading(`Loading ${t.name}...`),await this._processAdvancedFormat(t,i),this._hideLoading()}else{this._showLoading(`Loading ${t.name}...`);const n=await t.text(),r=JSON.parse(n);await this._processGeoJSON(r,t.name,"geojson"),this._hideLoading()}}catch(n){this._hideLoading(),this._state.error=`Failed to process ${t.name}: ${n instanceof Error?n.message:"Unknown error"}`,this._emit("error",void 0,this._state.error,t.name)}}this._state.isLoading=!1,this._updateButtonState()}async _processAdvancedFormat(e,t){const i=r=>{const s=r.message||`Processing ${e.name}...`,a=r.percent!==void 0?`${r.percent}%`:"";this._updateLoading(s,a),this._options.onConversionProgress?.(r)};this._updateLoading(`Reading ${e.name}...`);const n=await KY(e);if(t==="shapefile"){if(!this._shapefileConverter){this._updateLoading("Loading Shapefile converter...");const{getShapefileConverter:s}=await Promise.resolve().then(()=>require("./ShapefileConverter-wLF296OF.cjs")).then(a=>a.ShapefileConverter_exports);this._shapefileConverter=s()}const r=await this._shapefileConverter.convert(n,e.name,i);r.geojson&&(this._updateLoading("Adding to map..."),await this._processGeoJSON(r.geojson,e.name,t))}else if(jY(t)){if(!this._duckdbConverter){this._updateLoading("Loading DuckDB converter...");const{getDuckDBConverter:s}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(a=>a.DuckDBConverter_exports);if(this._duckdbConverter=s(),this._options.duckdbBundleUrl){const{DuckDBConverter:a}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(l=>l.DuckDBConverter_exports);this._duckdbConverter=new a(this._options.duckdbBundleUrl)}}const r=await this._duckdbConverter.convert(n,e.name,i);r.geojson&&(this._updateLoading("Adding to map..."),await this._processGeoJSON(r.geojson,e.name,t))}}async _processGeoJSON(e,t,i="geojson"){if(!this._map)return null;if(!e.type)return this._state.error=`Invalid GeoJSON: missing type property in ${t}`,this._emit("error",void 0,this._state.error,t),null;let n;e.type==="FeatureCollection"?n=e:e.type==="Feature"?n={type:"FeatureCollection",features:[e]}:n={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]};const r=Qu("vds"),s=`${r}-source`,a=new Set;for(const l of n.features)l.geometry&&a.add(l.geometry.type);try{this._map.addSource(s,{type:"geojson",data:n,generateId:!0});const l=[],h=this._options.defaultStyle;if(a.has("Polygon")||a.has("MultiPolygon")){const p=`${r}-fill`;this._map.addLayer({id:p,type:"fill",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-color":h.fillColor,"fill-opacity":h.fillOpacity}}),l.push(p);const g=`${r}-outline`;this._map.addLayer({id:g,type:"line",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"line-color":h.strokeColor,"line-width":h.strokeWidth,"line-opacity":h.strokeOpacity}}),l.push(g)}if(a.has("LineString")||a.has("MultiLineString")){const p=`${r}-line`;this._map.addLayer({id:p,type:"line",source:s,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"MultiLineString"]],paint:{"line-color":h.strokeColor,"line-width":h.strokeWidth,"line-opacity":h.strokeOpacity}}),l.push(p)}if(a.has("Point")||a.has("MultiPoint")){const p=`${r}-point`;this._map.addLayer({id:p,type:"circle",source:s,filter:["any",["==",["geometry-type"],"Point"],["==",["geometry-type"],"MultiPoint"]],paint:{"circle-radius":h.circleRadius,"circle-color":h.circleColor,"circle-stroke-color":h.circleStrokeColor,"circle-stroke-width":h.circleStrokeWidth}}),l.push(p)}const d={id:r,filename:t,sourceId:s,layerIds:l,featureCount:n.features.length,geometryTypes:Array.from(a),loadedAt:new Date,originalFormat:i};return this._state.loadedDatasets.push(d),this._options.fitBounds&&n.features.length>0&&this._fitToData(n),this._emit("load",d),this._emit("update"),d}catch(l){return this._state.error=`Failed to add ${t} to map: ${l instanceof Error?l.message:"Unknown error"}`,this._emit("error",void 0,this._state.error,t),null}}_fitToData(e){if(!this._map)return;let t=1/0,i=1/0,n=-1/0,r=-1/0;const s=l=>{t=Math.min(t,l[0]),n=Math.max(n,l[0]),i=Math.min(i,l[1]),r=Math.max(r,l[1])},a=l=>{for(const h of l)typeof h[0]=="number"?s(h):a(h)};for(const l of e.features){if(!l.geometry)continue;const h=l.geometry;h.type==="Point"?s(h.coordinates):(h.type==="MultiPoint"||h.type==="LineString"||h.type==="MultiLineString"||h.type==="Polygon"||h.type==="MultiPolygon")&&a(h.coordinates)}t!==1/0&&this._map.fitBounds([[t,i],[n,r]],{padding:this._options.fitBoundsPadding})}_removeAllDatasets(){for(const e of this._state.loadedDatasets)if(this._map){for(const t of e.layerIds)this._map.getLayer(t)&&this._map.removeLayer(t);this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)}this._state.loadedDatasets=[]}_checkZoomVisibility(){if(!this._map)return;const e=this._map.getZoom(),{minzoom:t,maxzoom:i}=this._options,n=e>=t&&e<=i;n!==this._zoomVisible&&(this._zoomVisible=n,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const e=this._state.visible&&this._zoomVisible;this._container.style.display=e?"flex":"none"}_updateButtonState(){this._button&&(this._state.isLoading?(this._button.classList.add("maplibre-gl-vector-dataset-button--loading"),this._button.disabled=!0):(this._button.classList.remove("maplibre-gl-vector-dataset-button--loading"),this._button.disabled=!1))}_showLoading(e,t){this._loadingOverlay&&(this._loadingOverlay.style.display="flex",this._loadingText&&(this._loadingText.textContent=e),this._loadingProgress&&(this._loadingProgress.textContent=t||""))}_updateLoading(e,t){this._loadingText&&(this._loadingText.textContent=e),this._loadingProgress&&(this._loadingProgress.textContent=t||"")}_hideLoading(){this._loadingOverlay&&(this._loadingOverlay.style.display="none")}},t6={fillColor:"#ffff00",fillOpacity:.3,strokeColor:"#ffff00",strokeWidth:3,circleRadius:10,circleStrokeWidth:3},Eoe={position:"top-right",className:"",visible:!0,enabled:!1,maxFeatures:10,includeLayers:[],excludeLayers:[],highlightStyle:t6,excludeProperties:[],showGeometryType:!0,showLayerName:!0,maxWidth:320,maxHeight:300,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#333",minzoom:0,maxzoom:24},Soe='<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',rj=class{_container;_button;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_popup;_highlightSourceId="";_highlightLayerIds=[];_boundClickHandler;constructor(e){this._options={...Eoe,...e,highlightStyle:{...t6,...e?.highlightStyle}},this._state={visible:this._options.visible,enabled:this._options.enabled,inspectedFeatures:[],selectedIndex:0,error:null},this._highlightSourceId=`inspect-highlight-${Qu()}`}onAdd(e){return this._map=e,this._container=this._createContainer(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._state.enabled&&this._setupMapListeners(),this._container}onRemove(){this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=void 0),this._removeMapListeners(),this._removeHighlight(),this._hidePopup(),this._map=void 0,this._container?.parentNode?.removeChild(this._container),this._container=void 0,this._button=void 0,this._eventHandlers.clear()}enable(){this._state.enabled||(this._state.enabled=!0,this._updateButtonState(),this._setupMapListeners(),this._updateCursor(!0),this._emit("enable"))}disable(){this._state.enabled&&(this._state.enabled=!1,this._updateButtonState(),this._removeMapListeners(),this._updateCursor(!1),this.clear(),this._emit("disable"))}toggle(){this._state.enabled?this.disable():this.enable()}isEnabled(){return this._state.enabled}show(){this._state.visible||(this._state.visible=!0,this._updateDisplayState(),this._emit("show"))}hide(){this._state.visible&&(this._state.visible=!0,this._updateDisplayState(),this._emit("hide"))}clear(){this._state.inspectedFeatures=[],this._state.selectedIndex=0,this._removeHighlight(),this._hidePopup(),this._emit("clear")}getState(){return{...this._state}}getInspectedFeatures(){return[...this._state.inspectedFeatures]}getSelectedFeature(){return this._state.inspectedFeatures[this._state.selectedIndex]||null}selectFeature(e){if(e>=0&&e<this._state.inspectedFeatures.length){this._state.selectedIndex=e;const t=this._state.inspectedFeatures[e];this._addHighlight(t),this._updatePopupContent(),this._emit("featureselect",t)}}nextFeature(){if(this._state.inspectedFeatures.length>1){const e=(this._state.selectedIndex+1)%this._state.inspectedFeatures.length;this.selectFeature(e)}}previousFeature(){if(this._state.inspectedFeatures.length>1){const e=this._state.selectedIndex===0?this._state.inspectedFeatures.length-1:this._state.selectedIndex-1;this.selectFeature(e)}}update(e){Object.assign(this._options,e),e.highlightStyle&&(this._options.highlightStyle={...t6,...e.highlightStyle}),e.visible!==void 0&&(this._state.visible=e.visible,this._updateDisplayState()),e.enabled!==void 0&&(e.enabled?this.enable():this.disable()),this._emit("update")}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}_emit(e,t){const i=this._eventHandlers.get(e);i&&i.forEach(n=>n({type:e,state:this.getState(),feature:t,features:this._state.inspectedFeatures}))}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibregl-ctrl-group maplibre-gl-inspect ${this._options.className}`.trim(),this._options.backgroundColor&&(e.style.backgroundColor=this._options.backgroundColor),this._options.borderRadius&&(e.style.borderRadius=`${this._options.borderRadius}px`),this._options.opacity!==void 0&&this._options.opacity!==1&&(e.style.opacity=String(this._options.opacity)),this._button=document.createElement("button"),this._button.type="button",this._button.className="maplibre-gl-inspect-button",this._button.title="Inspect features",this._button.innerHTML=Soe,this._button.addEventListener("click",()=>this.toggle()),e.appendChild(this._button),e.style.display=this._state.visible?"block":"none",e}_updateButtonState(){this._button&&(this._state.enabled?(this._button.classList.add("maplibre-gl-inspect-button--active"),this._button.title="Disable inspect mode"):(this._button.classList.remove("maplibre-gl-inspect-button--active"),this._button.title="Inspect features"))}_updateCursor(e){if(this._map){const t=this._map.getCanvas();e?t.style.cursor="crosshair":t.style.cursor=""}}_setupMapListeners(){!this._map||this._boundClickHandler||(this._boundClickHandler=e=>this._handleMapClick(e),this._map.on("click",this._boundClickHandler))}_removeMapListeners(){this._map&&this._boundClickHandler&&(this._map.off("click",this._boundClickHandler),this._boundClickHandler=void 0)}_handleMapClick(e){if(!this._map)return;const t=e.point,i=[e.lngLat.lng,e.lngLat.lat],n=this._queryFeatures(t);if(n.length===0){this.clear();return}const r=n.slice(0,this._options.maxFeatures).map(a=>{const l=a.id,h={type:"Feature",geometry:a.geometry,properties:a.properties||{}};return l!==void 0&&(h.id=l),{id:Qu("inspect"),feature:h,layerId:a.layer?.id||"unknown",sourceId:a.source||"unknown",sourceLayer:a.sourceLayer,featureId:l===void 0?void 0:l,lngLat:i}});this._state.inspectedFeatures=r,this._state.selectedIndex=0;const s=r[0];this._addHighlight(s),this._showPopup(s,i),this._emit("featureselect",s)}_queryFeatures(e){if(!this._map)return[];const t={};this._options.includeLayers.length>0&&(t.layers=this._options.includeLayers);let i=this._map.queryRenderedFeatures(e,t);return this._options.excludeLayers.length>0&&(i=i.filter(n=>n.layer&&!this._options.excludeLayers.includes(n.layer.id))),i=i.filter(n=>n.layer&&!n.layer.id.startsWith("inspect-highlight-")),i}_addHighlight(e){if(!this._map)return;const t=this._map;this._removeHighlight();const i=e.feature,n=i.geometry.type,r=this._options.highlightStyle,s=this._getHighlightTarget(e),a=l=>{if(n==="Point"||n==="MultiPoint"){const h=`${this._highlightSourceId}-circle`;t.addLayer({id:h,type:"circle",...l,paint:{"circle-radius":r.circleRadius,"circle-color":r.fillColor,"circle-opacity":r.fillOpacity,"circle-stroke-color":r.strokeColor,"circle-stroke-width":r.circleStrokeWidth}}),this._highlightLayerIds.push(h)}else if(n==="LineString"||n==="MultiLineString"){const h=`${this._highlightSourceId}-line`;t.addLayer({id:h,type:"line",...l,paint:{"line-color":r.strokeColor,"line-width":r.strokeWidth,"line-opacity":1}}),this._highlightLayerIds.push(h)}else if(n==="Polygon"||n==="MultiPolygon"){const h=`${this._highlightSourceId}-fill`;t.addLayer({id:h,type:"fill",...l,paint:{"fill-color":r.fillColor,"fill-opacity":r.fillOpacity}}),this._highlightLayerIds.push(h);const d=`${this._highlightSourceId}-outline`;t.addLayer({id:d,type:"line",...l,paint:{"line-color":r.strokeColor,"line-width":r.strokeWidth}}),this._highlightLayerIds.push(d)}};if(s){const l={source:s.sourceId};s.sourceLayer&&(l["source-layer"]=s.sourceLayer),l.filter=s.filter;try{a(l);return}catch{this._removeHighlight()}}t.addSource(this._highlightSourceId,{type:"geojson",data:i}),a({source:this._highlightSourceId})}_getHighlightTarget(e){if(!this._map)return null;const{sourceId:t,sourceLayer:i,featureId:n}=e;if(!t||t==="unknown"||n==null)return null;const r=this._map.getSource(t);return!r||r.type==="vector"&&!i?null:{sourceId:t,sourceLayer:i,filter:["==","$id",n]}}_removeHighlight(){if(this._map){for(const e of this._highlightLayerIds)this._map.getLayer(e)&&this._map.removeLayer(e);this._highlightLayerIds=[],this._map.getSource(this._highlightSourceId)&&this._map.removeSource(this._highlightSourceId)}}_showPopup(e,t){if(!this._map)return;this._hidePopup();const i=this._renderPopupContent();this._popup=new ks.Popup({closeButton:!0,closeOnClick:!1,maxWidth:`${this._options.maxWidth}px`,className:"maplibre-gl-inspect-popup"}).setLngLat(t).setHTML(i).addTo(this._map),requestAnimationFrame(()=>{this._attachPopupListeners()})}_hidePopup(){this._popup&&(this._popup.remove(),this._popup=void 0)}_updatePopupContent(){if(this._popup){const e=this._renderPopupContent();this._popup.setHTML(e),this._attachPopupListeners()}}_attachPopupListeners(){if(!this._popup)return;const e=this._popup.getElement();if(!e)return;const t=e.querySelector(".maplibre-gl-inspect-nav-prev"),i=e.querySelector(".maplibre-gl-inspect-nav-next");t&&(t.onclick=n=>{n.stopPropagation(),n.preventDefault(),this.previousFeature()}),i&&(i.onclick=n=>{n.stopPropagation(),n.preventDefault(),this.nextFeature()})}_renderPopupContent(){const e=this._state.inspectedFeatures,t=this._state.selectedIndex,i=e[t];if(!i)return'<div class="maplibre-gl-inspect-empty">No feature selected</div>';const n=i.feature.geometry.type,r=i.layerId,s=i.feature.properties||{};let a='<div class="maplibre-gl-inspect-header">';if(this._options.showGeometryType&&(a+=`<span class="maplibre-gl-inspect-geometry">${this._formatGeometryType(n)}</span>`),this._options.showLayerName&&(a+=`<span class="maplibre-gl-inspect-layer" title="${r}">${r}</span>`),e.length>1){const h=e.length<=1?"disabled":"",d=e.length<=1?"disabled":"";a+=`
|
|
79
79
|
<span class="maplibre-gl-inspect-nav">
|
|
80
80
|
<button class="maplibre-gl-inspect-nav-prev" ${h} title="Previous feature"><</button>
|
|
81
81
|
<span class="maplibre-gl-inspect-nav-count">${t+1}/${e.length}</span>
|
|
@@ -103,7 +103,7 @@ var Wae=Object.create;var A9=Object.defineProperty;var Xae=Object.getOwnProperty
|
|
|
103
103
|
color.b = clamp((color.b - rescaleFloat.minVal) / range, 0.0, 1.0);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
`},uniformTypes:{minVal:"f32",maxVal:"f32",isSingleBand:"f32"},getUniforms:e=>({minVal:e.minVal,maxVal:e.maxVal,isSingleBand:e.isSingleBand})};function aj(e,t){return e&&(Array.isArray(e)?e.map(i=>aj(i,t)):typeof e.clone=="function"?e.clone({opacity:t}):e)}function Roe(e,t){return Array.isArray(e)?t(e):e&&Array.isArray(e.renderPipeline)?{...e,renderPipeline:t(e.renderPipeline)}:e}function Boe(e){let t=e.replace("#","");return t.length===3&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function Loe(e){const i=new Uint8ClampedArray(1024),n=e.map(r=>({pos:r.position,rgb:Boe(r.color)}));for(let r=0;r<256;r++){const s=r/255;let a=n[0],l=n[n.length-1];for(let p=0;p<n.length-1;p++)if(s>=n[p].pos&&s<=n[p+1].pos){a=n[p],l=n[p+1];break}const h=l.pos-a.pos,d=h>0?(s-a.pos)/h:0;i[r*4]=a.rgb[0]+(l.rgb[0]-a.rgb[0])*d,i[r*4+1]=a.rgb[1]+(l.rgb[1]-a.rgb[1])*d,i[r*4+2]=a.rgb[2]+(l.rgb[2]-a.rgb[2])*d,i[r*4+3]=255}return new ImageData(i,256,1)}function koe(e){return e?.[0]===1}function gm(e){return typeof e=="number"}function Poe(e,t){return Number.isNaN(t)?Number.isNaN(e):e===t}function w9(e,t,i){const n=Math.floor(e.length/t),r=new Uint8Array(n);r.fill(255);let s=!1;const a=gm(i);for(let l=0;l<n;l++){const h=l*t;let d=!1,p=a;for(let g=0;g<t;g++){const v=e[h+g];Number.isFinite(v)||(d=!0),a&&p&&!Poe(v,i)&&(p=!1)}(d||p)&&(r[l]=0,s=!0)}return s?r:null}function C9(e,t,i){if(!t||!("set"in e))return;const n=e;for(let r=0;r<t.length;r++){if(t[r]!==0)continue;const s=r*i;for(let a=0;a<i;a++)n[s+a]=0}}function Noe(e,t){if(!e)return t;if(!t)return e;const i=new Uint8Array(e.length);for(let n=0;n<e.length;n++)i[n]=e[n]===0||t[n]===0?0:255;return i}function E9(e,t){const i=Loe(jl(t));return e.createTexture({data:i.data,dimension:"2d-array",format:"rgba8unorm",width:i.width,height:i.height,depth:1,mipLevels:1,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge"}})}var Foe=["none","bone","bwr","cividis","cool","coolwarm","gray","hot","inferno","jet","magma","ocean","plasma","rainbow","RdBu","RdYlBu","RdYlGn","seismic","spectral","terrain","turbo","viridis"],Doe={position:"top-right",className:"",visible:!0,collapsed:!0,beforeId:"",defaultUrl:"",loadDefaultUrl:!1,defaultBands:"1",defaultColormap:"none",defaultRescaleMin:0,defaultRescaleMax:255,defaultNodata:void 0,defaultLayerName:"",defaultOpacity:1,defaultPickable:!0,panelWidth:300,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#333",minzoom:0,maxzoom:24},Ooe='<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',i6=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_deckOverlay;_cogLayers=new Map;_cogLayerPropsMap=new Map;_layerCounter=0;_activePopup;_mapClickHandler;constructor(e){this._options={...Doe,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,url:this._options.defaultUrl,bands:this._options.defaultBands,colormap:this._options.defaultColormap,rescaleMin:this._options.defaultRescaleMin,rescaleMax:this._options.defaultRescaleMax,nodata:this._options.defaultNodata,layerName:this._options.defaultLayerName,layerOpacity:this._options.defaultOpacity,pickable:this._options.defaultPickable,hasLayer:!1,layerCount:0,layers:[],loading:!1,error:null,status:null}}onAdd(e){if(this._map=e,this._container=this._createContainer(),this._render(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._setupClickHandler(),this._options.loadDefaultUrl&&this._options.defaultUrl){const t=()=>{this._addLayer()};this._map.isStyleLoaded()?setTimeout(t,100):this._map.once("idle",t)}return this._container}onRemove(){if(this._removeLayer(),this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=void 0),this._map&&this._mapClickHandler&&(this._map.off("click",this._mapClickHandler),this._mapClickHandler=void 0),this._activePopup&&(this._activePopup.remove(),this._activePopup=void 0),this._deckOverlay&&this._map){try{this._map.removeControl(this._deckOverlay)}catch{}this._deckOverlay=void 0}this._map=void 0,this._container?.parentNode?.removeChild(this._container),this._container=void 0,this._button=void 0,this._panel=void 0,this._eventHandlers.clear()}show(){this._state.visible||(this._state.visible=!0,this._updateDisplayState(),this._emit("show"))}hide(){this._state.visible&&(this._state.visible=!1,this._updateDisplayState(),this._emit("hide"))}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._render(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._render(),this._emit("collapse"))}toggle(){this._state.collapsed?this.expand():this.collapse()}getState(){return{...this._state}}update(e){this._options={...this._options,...e},e.visible!==void 0&&(this._state.visible=e.visible),e.collapsed!==void 0&&(this._state.collapsed=e.collapsed),this._render(),this._emit("update")}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}async addLayer(e){e&&(this._state.url=e),await this._addLayer()}removeLayer(e){this._removeLayer(e),this._render()}getLayerIds(){return Array.from(this._cogLayers.keys())}getLayerOpacity(e){const t=this._cogLayers.get(e);return!t||!t.props?null:t.props.opacity??1}setLayerOpacity(e,t){const i=this._cogLayers.get(e);if(!i||typeof i.clone!="function")return;const n=Math.max(0,Math.min(1,t)),r=i.clone({opacity:n});this._cogLayers.set(e,r),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}getLayerVisibility(e){const t=this.getLayerOpacity(e);return t!==null&&t>0}setLayerVisibility(e,t,i=1){t?this.setLayerOpacity(e,i):this.setLayerOpacity(e,0)}getLayerUrl(e){const t=this._cogLayerPropsMap.get(e);return t?t._sourceUrl??(typeof t.geotiff=="string"?t.geotiff:null):null}_emit(e,t){const i=this._eventHandlers.get(e);if(i){const n={type:e,state:this.getState(),...t};i.forEach(r=>r(n))}}_checkZoomVisibility(){if(!this._map)return;const e=this._map.getZoom(),{minzoom:t,maxzoom:i}=this._options,n=e>=t&&e<=i;n!==this._zoomVisible&&(this._zoomVisible=n,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const e=this._state.visible&&this._zoomVisible;this._container.style.display=e?"block":"none"}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-cog-layer${this._options.className?` ${this._options.className}`:""}`,this._state.visible&&this._zoomVisible||(e.style.display="none"),Object.assign(e.style,{backgroundColor:this._options.backgroundColor,borderRadius:`${this._options.borderRadius}px`,boxShadow:"0 0 0 2px rgba(0, 0, 0, 0.1)"}),this._options.opacity!==1&&(e.style.opacity=String(this._options.opacity)),e}_render(){if(!this._container)return;const e=this._container.querySelector(".maplibre-gl-cog-layer-panel"),t=e?e.scrollTop:0;if(this._container.innerHTML="",this._state.collapsed?this._renderCollapsed():this._renderExpanded(),this._updateDisplayState(),t>0){const i=this._container.querySelector(".maplibre-gl-cog-layer-panel");i&&(i.scrollTop=t)}}_renderCollapsed(){this._container&&(this._button=document.createElement("button"),this._button.type="button",this._button.className=`maplibre-gl-cog-layer-button${this._state.hasLayer?" maplibre-gl-cog-layer-button--active":""}`,this._button.title="COG Layer",this._button.setAttribute("aria-label","COG Layer"),this._button.innerHTML=Ooe,this._button.addEventListener("click",()=>this.expand()),this._container.appendChild(this._button),this._panel=void 0)}_renderExpanded(){if(!this._container)return;const e=document.createElement("div");e.className="maplibre-gl-cog-layer-panel",e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),this._panel=e;const t=document.createElement("div");t.className="maplibre-gl-cog-layer-header";const i=document.createElement("span");i.className="maplibre-gl-cog-layer-title",i.textContent="COG Layer",t.appendChild(i);const n=document.createElement("button");n.className="maplibre-gl-cog-layer-close",n.innerHTML="×",n.title="Close",n.addEventListener("click",()=>this.collapse()),t.appendChild(n),e.appendChild(t);const r=this._createFormGroup("COG URL","url"),s=document.createElement("input");s.type="text",s.className="maplibre-gl-cog-layer-input",s.style.color="#000",s.placeholder="https://example.com/cog.tif",s.value=this._state.url,s.addEventListener("input",()=>{this._state.url=s.value}),r.appendChild(s),e.appendChild(r);const a=this._createFormGroup("Bands (comma-separated)","bands"),l=document.createElement("input");l.type="text",l.className="maplibre-gl-cog-layer-input",l.style.color="#000",l.placeholder="1 or 1,2,3",l.value=this._state.bands,l.addEventListener("input",()=>{this._state.bands=l.value}),a.appendChild(l),e.appendChild(a);const h=this._createFormGroup("Colormap","colormap"),d=document.createElement("select");d.className="maplibre-gl-cog-layer-select",d.style.color="#000";for(const ee of Foe){const ae=document.createElement("option");ae.value=ee,ae.textContent=ee,ee===this._state.colormap&&(ae.selected=!0),d.appendChild(ae)}d.addEventListener("change",()=>{this._state.colormap=d.value,this._updateColormapPreview()}),h.appendChild(d);const p=document.createElement("div");p.className="maplibre-gl-cog-layer-colormap-preview",p.id="cog-colormap-preview",this._updateColormapPreviewElement(p),h.appendChild(p),e.appendChild(h);const g=document.createElement("div");g.className="maplibre-gl-cog-layer-row";const v=this._createFormGroup("Rescale Min","rescale-min"),y=document.createElement("input");y.type="number",y.className="maplibre-gl-cog-layer-input",y.style.color="#000",y.value=String(this._state.rescaleMin),y.addEventListener("input",()=>{this._state.rescaleMin=Number(y.value)||0}),v.appendChild(y),g.appendChild(v);const E=this._createFormGroup("Rescale Max","rescale-max"),S=document.createElement("input");S.type="number",S.className="maplibre-gl-cog-layer-input",S.style.color="#000",S.value=String(this._state.rescaleMax),S.addEventListener("input",()=>{this._state.rescaleMax=Number(S.value)||0}),E.appendChild(S),g.appendChild(E),e.appendChild(g);const R=this._createFormGroup("Nodata","nodata"),I=document.createElement("input");I.type="number",I.className="maplibre-gl-cog-layer-input",I.style.color="#000",I.placeholder="e.g. 0 or -9999",I.value=this._state.nodata!==void 0?String(this._state.nodata):"",I.addEventListener("input",()=>{this._state.nodata=I.value!==""?Number(I.value):void 0}),R.appendChild(I),e.appendChild(R);const k=this._createFormGroup("Opacity","opacity"),D=document.createElement("div");D.className="maplibre-gl-cog-layer-slider-row";const F=document.createElement("input");F.type="range",F.className="maplibre-gl-cog-layer-slider",F.min="0",F.max="100",F.value=String(Math.round(this._state.layerOpacity*100));const Z=document.createElement("span");Z.className="maplibre-gl-cog-layer-slider-value",Z.textContent=`${Math.round(this._state.layerOpacity*100)}%`,F.addEventListener("input",()=>{const ee=Number(F.value);this._state.layerOpacity=ee/100,Z.textContent=`${ee}%`,this._updateOpacity()}),D.appendChild(F),D.appendChild(Z),k.appendChild(D),e.appendChild(k);const Y=document.createElement("div");Y.className="maplibre-gl-cog-layer-form-group maplibre-gl-cog-layer-checkbox-group";const Q=document.createElement("label");Q.className="maplibre-gl-cog-layer-checkbox-label";const V=document.createElement("input");V.type="checkbox",V.className="maplibre-gl-cog-layer-checkbox",V.checked=this._state.pickable,V.addEventListener("change",()=>{this._state.pickable=V.checked,this._updatePickable()}),Q.appendChild(V);const U=document.createElement("span");U.textContent="Pickable (click to show pixel value)",Q.appendChild(U),Y.appendChild(Q),e.appendChild(Y);const H=this._createFormGroup("Layer Name","layer-name"),W=document.createElement("input");W.type="text",W.className="maplibre-gl-cog-layer-input",W.style.color="#000",W.placeholder="Optional custom layer name",W.value=this._state.layerName,W.addEventListener("input",()=>{this._state.layerName=W.value}),H.appendChild(W),e.appendChild(H);const ne=this._createFormGroup("Before Layer ID (optional)","before-id"),te=document.createElement("input");te.type="text",te.className="maplibre-gl-cog-layer-input",te.style.color="#000",te.placeholder="e.g. labels or water",te.value=this._options.beforeId||"",te.addEventListener("input",()=>{this._options.beforeId=te.value||""}),ne.appendChild(te),e.appendChild(ne);const oe=document.createElement("div");oe.className="maplibre-gl-cog-layer-buttons";const X=document.createElement("button");if(X.className="maplibre-gl-cog-layer-btn maplibre-gl-cog-layer-btn--primary",X.textContent="Add Layer",X.disabled=this._state.loading,X.addEventListener("click",()=>this._addLayer()),oe.appendChild(X),e.appendChild(oe),this._state.loading?this._appendStatus("Loading COG...","info"):this._state.error?this._appendStatus(this._state.error,"error"):this._state.status&&this._appendStatus(this._state.status,"success"),this._cogLayers.size>0){const ee=document.createElement("div");ee.className="maplibre-gl-cog-layer-list";const ae=document.createElement("div");ae.className="maplibre-gl-cog-layer-list-header",ae.textContent=`Layers (${this._cogLayers.size})`,ee.appendChild(ae);for(const[ce]of this._cogLayers){const de=this._cogLayerPropsMap.get(ce);if(!de)continue;const pe=document.createElement("div");pe.className="maplibre-gl-cog-layer-list-item";const Ie=document.createElement("span");Ie.className="maplibre-gl-cog-layer-list-label";const we=de._sourceUrl??(typeof de.geotiff=="string"?de.geotiff:""),Ee=de._layerName;let Se;if(Ee)Se=Ee;else try{Se=new URL(we).pathname.split("/").pop()||we}catch{Se=we}Ie.textContent=Se,Ie.title=we,pe.appendChild(Ie);const Ve=document.createElement("button");Ve.className="maplibre-gl-cog-layer-list-remove",Ve.innerHTML="×",Ve.title="Remove layer",Ve.addEventListener("click",()=>{this._removeLayer(ce),this._render()}),pe.appendChild(Ve),ee.appendChild(pe)}e.appendChild(ee)}this._container.appendChild(e),this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-cog-layer-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`cog-layer-${t}`,i.appendChild(n),i}_appendStatus(e,t){if(!this._panel)return;const i=document.createElement("div");i.className=`maplibre-gl-cog-layer-status maplibre-gl-cog-layer-status--${t}`,i.textContent=e,this._panel.appendChild(i)}_updateColormapPreview(){const e=document.getElementById("cog-colormap-preview");e&&this._updateColormapPreviewElement(e)}_updateColormapPreviewElement(e){if(this._state.colormap==="none")e.style.background="linear-gradient(to right, #888, #888)",e.style.display="none";else{const t=jl(this._state.colormap).map(i=>i.color).join(", ");e.style.background=`linear-gradient(to right, ${t})`,e.style.display="block"}}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:e}=await import("@deck.gl/mapbox");this._deckOverlay=new e({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const e=this._map;this._mapClickHandler=t=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:i}=t,n=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(n[0]);let s='<div class="maplibre-gl-cog-layer-popup">';s+='<table class="maplibre-gl-cog-layer-popup-table">',s+=`<tr><td><strong>Layers</strong></td><td>${n.length} COG layer(s)</td></tr>`,s+=`<tr><td><strong>Lng</strong></td><td>${i.lng.toFixed(6)}</td></tr>`,s+=`<tr><td><strong>Lat</strong></td><td>${i.lat.toFixed(6)}</td></tr>`,r&&(s+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(s+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),s+="</table>",s+="</div>",this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(i).setHTML(s).addTo(e);const a=this._activePopup.getElement();a&&(a.style.zIndex="1000")},e.on("click",this._mapClickHandler)}_updatePickable(){if(this._deckOverlay){for(const[,e]of this._cogLayerPropsMap)e.pickable=this._state.pickable;this._rebuildLayers()}}async _rebuildLayers(){if(this._deckOverlay)try{const{COGLayer:e}=await import("@developmentseed/deck.gl-geotiff");this._patchCOGLayerForFloat(e),this._patchCOGLayerForOpacity(e);const t=[];for(const[i,n]of this._cogLayerPropsMap){const r=new e(n);this._cogLayers.set(i,r),t.push(r)}this._deckOverlay.setProps({layers:t})}catch(e){console.error("Failed to rebuild layers:",e)}}async _registerCommonProjections(e){e.defs("EPSG:3978","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +type=crs"),e.defs("EPSG:3979","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=-0.991,1.9072,0.5129,-1.25033e-07,-4.6785e-08,-5.6529e-08,0 +units=m +no_defs +type=crs")}_buildGeoKeysParser(e){let t=null;return Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")).then(i=>{t=i.default||i,typeof t=="function"&&this._registerCommonProjections(t)}),async i=>{try{const n=e.toProj4(i);if(n&&n.proj4){let r=n.proj4;if(r=r.replace(/\+axis=\w+\s*/g,""),!t){const a=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs"));t=a.default||a,typeof t=="function"&&await this._registerCommonProjections(t)}let s={};if(typeof t=="function")try{t.defs("custom",r),s=t.defs("custom")||{}}catch{}return{def:r,parsed:s,coordinatesUnits:n.coordinatesUnits||"metre"}}}catch{}return null}}_patchCOGLayerForFloat(e){if(e.__floatPatched)return;e.__floatPatched=!0;const t=e.prototype._parseGeoTIFF;e.prototype._parseGeoTIFF=async function(){try{await t.call(this);const i=this.props._nodata;if(i!=null&&!isNaN(i)){const{FilterNoDataVal:n}=await import("@developmentseed/deck.gl-raster/gpu-modules"),r=this.state.defaultRenderTile;if(typeof r=="function"){const s=a=>Roe(r(a),l=>{const h=l.filter(d=>d.module!==n);return h.splice(1,0,{module:n,props:{value:i}}),h});this.setState({defaultRenderTile:s})}}}catch(i){if(!(i instanceof Error?i.message:String(i)).includes("non-unsigned integers not yet supported"))throw i;const{parseCOGTileMatrixSet:n,texture:r}=await import("@developmentseed/deck.gl-geotiff");if(typeof n!="function"||typeof r?.inferTextureFormat!="function")throw i;const{fromUrl:s}=await Promise.resolve().then(()=>require("./geotiff-DG1Dpz4s.cjs")),{CreateTexture:a,FilterNoDataVal:l,MaskTexture:h}=await import("@developmentseed/deck.gl-raster/gpu-modules"),d=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")),p=d.default||d,g=this.props.geotiff,v=typeof g=="string"?await s(g):g,y=this.props.geoKeysParser,E=await n(v,y),S=await v.getImage(),R=await v.getImageCount(),I=[];for(let ae=0;ae<R;ae++)I.push(await v.getImage(ae));const k=await y(S.getGeoKeys());if(!k)throw new Error("Could not determine source projection from GeoTIFF geo keys");const D=p(k.def,"EPSG:4326"),F=(ae,ce)=>D.forward([ae,ce],!1),Z=(ae,ce)=>D.inverse([ae,ce],!1);if(this.props.onGeoTIFFLoad){const ae=S.getBoundingBox(),ce=[D.forward([ae[0],ae[1]]),D.forward([ae[2],ae[1]]),D.forward([ae[2],ae[3]]),D.forward([ae[0],ae[3]])],de=ce.map(we=>we[0]),pe=ce.map(we=>we[1]),Ie={west:Math.min(...de),south:Math.min(...pe),east:Math.max(...de),north:Math.max(...pe)};this.props.onGeoTIFFLoad(v,{projection:k,geographicBounds:Ie})}const{BitsPerSample:Y,SampleFormat:Q,SamplesPerPixel:V,GDAL_NODATA:U}=S.getFileDirectory();let H=null;if(U){const ae=U[U.length-1]==="\0"?U.slice(0,-1):U;ae.length>0&&(H=parseFloat(ae))}const W=this,ne=async(ae,ce)=>{const{device:de}=ce,pe=await ae.readRasters({...ce,interleave:!0});let Ie=pe,we=V;const Ee=gm(W.props._nodata)?W.props._nodata:H,Se=w9(Ie,we,gm(Ee)?Ee:void 0);if(C9(Ie,Se,we),V===3){const Le=pe.width*pe.height,nt=new Float32Array(Le*4);for(let lt=0;lt<Le;lt++)nt[lt*4]=pe[lt*3],nt[lt*4+1]=pe[lt*3+1],nt[lt*4+2]=pe[lt*3+2],nt[lt*4+3]=1;Ie=nt,Ie.width=pe.width,Ie.height=pe.height,we=4}const Ve=r.inferTextureFormat(we,Y,Q),ze=de.createTexture({data:Ie,format:Ve,width:pe.width,height:pe.height,sampler:{magFilter:"nearest",minFilter:"nearest"}});let it;return Se&&(it=de.createTexture({data:Se,format:"r8unorm",width:pe.width,height:pe.height,sampler:{magFilter:"nearest",minFilter:"nearest"}})),{texture:ze,height:pe.height,mask:it,width:pe.width}};let te=null,oe=null;const{Colormap:X}=await import("@developmentseed/deck.gl-raster/gpu-modules"),ee=ae=>{const ce=[{module:a,props:{textureName:ae.texture}}];ae.mask&&ce.push({module:h,props:{maskTexture:ae.mask}});const de=W.props._nodata!==void 0&&W.props._nodata!==null&&!isNaN(W.props._nodata)?W.props._nodata:H;gm(de)&&!Number.isNaN(de)&&ce.push({module:l,props:{value:de}});const pe=W.props._rescaleMin??0,Ie=W.props._rescaleMax??255;ce.push({module:x9,props:{minVal:pe,maxVal:Ie,isSingleBand:V===1?1:0}});const we=W.props._colormap;return we&&we!=="none"&&(we!==te&&(oe=E9(W.context.device,we),te=we),ce.push({module:X,props:{colormapTexture:oe}})),{renderPipeline:ce}};this.setState({metadata:E,forwardReproject:F,inverseReproject:Z,images:I,defaultGetTileData:ne,defaultRenderTile:ee})}}}_patchCOGLayerForOpacity(e){if(e.__opacityPatched)return;e.__opacityPatched=!0;const t=e.prototype._renderSubLayers;e.prototype._renderSubLayers=function(...i){const n=t.apply(this,i),r=this.props.opacity;return r==null?n:aj(n,Math.max(0,Math.min(1,r)))}}async _createFloatCogLayerProps(e){const{GeoTIFF:t}=await import("@developmentseed/geotiff"),i=await t.fromUrl(e);if(koe(i.cachedTags.sampleFormat))return{geotiff:i};const{texture:n}=await import("@developmentseed/deck.gl-geotiff"),{CreateTexture:r,FilterNoDataVal:s,MaskTexture:a,Colormap:l}=await import("@developmentseed/deck.gl-raster/gpu-modules"),h=this._state.colormap,d=this._state.nodata,p=this._state.rescaleMax,g=this._state.rescaleMin,v=async(R,I)=>{const{device:k,pool:D,signal:F,x:Z,y:Y}=I,{array:Q}=await R.fetchTile(Z,Y,{boundless:!1,pool:D,signal:F});if(Q.layout==="band-separate")throw new Error("Band-separate images are not yet implemented.");const V=R.cachedTags;let U=Q.data,H=V.samplesPerPixel,W=V.bitsPerSample,ne=V.sampleFormat;const te=gm(d)?d:V.nodata;U instanceof Float64Array&&(U=new Float32Array(U),W=Array.from({length:H},()=>32));const oe=w9(U,H,gm(te)?te:void 0);if(C9(U,oe,H),H===3){const pe=Q.width*Q.height,Ie=new Float32Array(pe*4);for(let we=0;we<pe;we++)Ie[we*4]=U[we*3],Ie[we*4+1]=U[we*3+1],Ie[we*4+2]=U[we*3+2],Ie[we*4+3]=1;U=Ie,H=4,W=[32,32,32,32],ne=[3,3,3,3]}const X=n.inferTextureFormat(H,W,ne);let ee=U.byteLength;const ae=k.createTexture({data:U,format:X,width:Q.width,height:Q.height,sampler:{magFilter:"nearest",minFilter:"nearest"}});let ce;const de=Noe(Q.mask,oe);return de&&(ce=k.createTexture({data:de,format:"r8unorm",width:Q.width,height:Q.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),ee+=de.byteLength),{byteLength:ee,device:k,height:Q.height,mask:ce,nodata:te,samplesPerPixel:H,texture:ae,width:Q.width}};let y=null,E=null;return{geotiff:i,getTileData:v,renderTile:R=>{const I=[{module:r,props:{textureName:R.texture}}];R.mask&&I.push({module:a,props:{maskTexture:R.mask}});const k=R.nodata;return gm(k)&&!Number.isNaN(k)&&I.push({module:s,props:{value:k}}),I.push({module:x9,props:{minVal:g,maxVal:p,isSingleBand:R.samplesPerPixel===1?1:0}}),h&&h!=="none"&&(y!==h&&(E=E9(R.device,h),y=h),I.push({module:l,props:{colormapTexture:E}})),{renderPipeline:I}}}}async _addLayer(){if(!this._map||!this._state.url){this._state.error="Please enter a COG URL.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{await this._ensureOverlay();const{COGLayer:e}=await import("@developmentseed/deck.gl-geotiff");this._patchCOGLayerForFloat(e),this._patchCOGLayerForOpacity(e);const t=this._map,i=await this._createFloatCogLayerProps(this._state.url),n={geotiff:this._state.url,_sourceUrl:this._state.url,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:this._state.rescaleMin,_rescaleMax:this._state.rescaleMax,_colormap:this._state.colormap,_nodata:this._state.nodata,...i??{},...(()=>{if(this._options.beforeId){if(t.getLayer(this._options.beforeId))return{beforeId:this._options.beforeId};console.warn(`[CogLayerControl] beforeId "${this._options.beforeId}" not found in map layers, adding layer on top`)}return{}})(),onGeoTIFFLoad:(l,h)=>{try{if(h&&h.geographicBounds){const{west:d,south:p,east:g,north:v}=h.geographicBounds;t.fitBounds([[d,p],[g,v]],{padding:50,duration:1e3})}}catch{}}};try{const l=await Promise.resolve().then(()=>require("./main-dist-DOx_Axbx.cjs")),h=l.default||l;h&&typeof h.toProj4=="function"&&(n.geoKeysParser=this._buildGeoKeysParser(h))}catch{}const r=`cog-layer-${this._layerCounter++}`;n.id=r;const s=this._state.layerName?.trim();s&&(n._layerName=s),this._cogLayerPropsMap.set(r,n);const a=new e(n);this._cogLayers.set(r,a),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.layers=this._buildLayerInfoList(),this._state.loading=!1,this._state.status="COG layer added successfully.",this._state.layerName="",this._render(),this._emit("layeradd",{url:this._state.url,layerId:r})}catch(e){this._state.loading=!1,this._state.error=`Failed to load COG: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_removeLayer(e){e?(this._cogLayers.delete(e),this._cogLayerPropsMap.delete(e),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.layers=this._buildLayerInfoList(),this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e})):(this._deckOverlay&&this._deckOverlay.setProps({layers:[]}),this._cogLayers.clear(),this._cogLayerPropsMap.clear(),this._state.hasLayer=!1,this._state.layerCount=0,this._state.layers=[],this._state.status=null,this._state.error=null,this._emit("layerremove"))}_updateOpacity(){if(!this._deckOverlay||this._cogLayers.size===0)return;const e=this._state.layerOpacity;for(const[t,i]of this._cogLayers)typeof i.clone=="function"&&this._cogLayers.set(t,i.clone({opacity:e}));this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}_buildLayerInfoList(){const e=[];for(const[t,i]of this._cogLayerPropsMap)e.push({id:t,name:i._layerName||void 0,url:i._sourceUrl??(typeof i.geotiff=="string"?i.geotiff:""),bands:"1",colormap:i._colormap||"none",rescaleMin:i._rescaleMin??0,rescaleMax:i._rescaleMax??255,nodata:i._nodata,opacity:i.opacity??1});return e}},Uoe={position:"bottom-left",className:"",visible:!0,collapsed:!1,width:250,height:180,zoomOffset:-5,style:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",viewportRectColor:"#0078d7",viewportRectOpacity:.2,toggleable:!0,interactive:!1,minzoom:0,maxzoom:24},Goe='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><rect x="7" y="7" width="10" height="10" rx="1" stroke-dasharray="2 2"/></svg>',pE="maplibre-minimap-viewport",zoe="maplibre-minimap-viewport-fill",Voe="maplibre-minimap-viewport-line",oj=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_minimapMap;_handleMove;_handleZoom;_zoomVisible=!0;_isDragging=!1;_dragStartLngLat;_dragCleanup;constructor(e){this._options={...Uoe,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed}}getDefaultPosition(){return this._options.position}onAdd(e){return this._map=e,this._container=this._createContainer(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._state.collapsed||this._showPanel(),this._state.visible||(this._container.style.display="none"),this._container}onRemove(){this._dragCleanup&&(this._dragCleanup(),this._dragCleanup=void 0),this._isDragging=!1,this._dragStartLngLat=void 0,this._minimapMap&&(this._minimapMap.remove(),this._minimapMap=void 0),this._map&&this._handleMove&&this._map.off("move",this._handleMove),this._map&&this._handleZoom&&this._map.off("zoom",this._handleZoom),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=void 0,this._button=void 0,this._panel=void 0,this._map=void 0}on(e,t){return this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t),this}off(e,t){return this._eventHandlers.get(e)?.delete(t),this}_emit(e){const t=this._eventHandlers.get(e);if(t){const i={type:e,state:this.getState()};t.forEach(n=>n(i))}}_createContainer(){const e=document.createElement("div");return e.classList.add("maplibregl-ctrl","maplibre-gl-minimap-control"),this._options.className&&e.classList.add(this._options.className),this._options.toggleable&&(this._button=document.createElement("button"),this._button.type="button",this._button.className="minimap-button",this._button.title="Toggle minimap",this._button.innerHTML=Goe,this._button.addEventListener("click",()=>this.toggle()),e.appendChild(this._button)),e}_showPanel(){if(!this._container||!this._map||this._panel)return;this._panel=document.createElement("div"),this._panel.className="minimap-panel",this._panel.style.width=`${this._options.width}px`,this._panel.style.height=`${this._options.height}px`;const e=document.createElement("div");e.className="minimap-map",this._panel.appendChild(e),this._container.appendChild(this._panel);const t=this._map.getCenter(),i=this._map.getZoom(),n=Math.max(0,i+this._options.zoomOffset);if(this._minimapMap=new ks.default.Map({container:e,style:this._options.style,center:t,zoom:n,interactive:!1,attributionControl:!1}),this._minimapMap.on("load",()=>{this._addViewportRect(),this._updateViewportRect()}),this._handleMove=()=>{this._isDragging||(this._syncMinimap(),this._updateViewportRect())},this._map.on("move",this._handleMove),this._options.interactive&&this._minimapMap){const r=this._minimapMap._canvas;r.style.cursor="pointer";let s=null,a=!1,l=null;const h=g=>{if(!this._minimapMap||!this._map)return;g.preventDefault(),this._isDragging=!0,a=!1,s={x:g.clientX,y:g.clientY},r.style.cursor="grabbing";const v=r.getBoundingClientRect(),y=g.clientX-v.left,E=g.clientY-v.top;this._dragStartLngLat=this._minimapMap.unproject([y,E]),l=this._map.getCenter()},d=g=>{if(!this._isDragging||!this._minimapMap||!this._map||!this._dragStartLngLat||!l)return;if(s&&!a){const k=g.clientX-s.x,D=g.clientY-s.y;(Math.abs(k)>3||Math.abs(D)>3)&&(a=!0)}if(!a)return;const v=r.getBoundingClientRect(),y=g.clientX-v.left,E=g.clientY-v.top,S=this._minimapMap.unproject([y,E]),R=S.lng-this._dragStartLngLat.lng,I=S.lat-this._dragStartLngLat.lat;this._map.setCenter([l.lng+R,l.lat+I]),this._updateViewportRect()},p=g=>{if(this._isDragging&&!a&&this._minimapMap&&this._map){const v=r.getBoundingClientRect(),y=g.clientX-v.left,E=g.clientY-v.top,S=this._minimapMap.unproject([y,E]);this._map.flyTo({center:S})}this._isDragging=!1,a=!1,s=null,l=null,this._dragStartLngLat=void 0,r.style.cursor="pointer",this._syncMinimap(),this._updateViewportRect()};r.addEventListener("mousedown",h),document.addEventListener("mousemove",d),document.addEventListener("mouseup",p),this._dragCleanup=()=>{r.removeEventListener("mousedown",h),document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",p)}}}_hidePanel(){this._dragCleanup&&(this._dragCleanup(),this._dragCleanup=void 0),this._isDragging=!1,this._dragStartLngLat=void 0,this._minimapMap&&(this._minimapMap.remove(),this._minimapMap=void 0),this._map&&this._handleMove&&(this._map.off("move",this._handleMove),this._handleMove=void 0),this._panel&&(this._panel.remove(),this._panel=void 0)}_syncMinimap(){if(!this._minimapMap||!this._map)return;const e=this._map.getCenter(),t=Math.max(0,this._map.getZoom()+this._options.zoomOffset);this._minimapMap.jumpTo({center:e,zoom:t})}_addViewportRect(){this._minimapMap&&(this._minimapMap.addSource(pE,{type:"geojson",data:{type:"Feature",geometry:{type:"Polygon",coordinates:[[]]},properties:{}}}),this._minimapMap.addLayer({id:zoe,type:"fill",source:pE,paint:{"fill-color":this._options.viewportRectColor,"fill-opacity":this._options.viewportRectOpacity}}),this._minimapMap.addLayer({id:Voe,type:"line",source:pE,paint:{"line-color":this._options.viewportRectColor,"line-width":2}}))}_updateViewportRect(){if(!this._minimapMap||!this._map)return;const e=this._minimapMap.getSource(pE);if(!e||!("setData"in e))return;const t=this._map.getBounds(),i=t.getSouthWest(),n=t.getNorthEast(),r=t.getNorthWest(),s=t.getSouthEast(),a=[[i.lng,i.lat],[s.lng,s.lat],[n.lng,n.lat],[r.lng,r.lat],[i.lng,i.lat]];e.setData({type:"Feature",geometry:{type:"Polygon",coordinates:[a]},properties:{}})}_checkZoomVisibility(){if(!this._map||!this._container)return;const e=this._map.getZoom(),t=this._zoomVisible;this._zoomVisible=e>=this._options.minzoom&&e<=this._options.maxzoom,t!==this._zoomVisible&&(this._container.style.display=this._zoomVisible&&this._state.visible?"":"none")}show(){return this._state.visible=!0,this._container&&(this._container.style.display=this._zoomVisible?"":"none"),this._emit("show"),this}hide(){return this._state.visible=!1,this._container&&(this._container.style.display="none"),this._emit("hide"),this}expand(){return this._state.collapsed?(this._state.collapsed=!1,this._showPanel(),this._emit("expand"),this):this}collapse(){return this._state.collapsed?this:(this._state.collapsed=!0,this._hidePanel(),this._emit("collapse"),this)}toggle(){return this._state.collapsed?this.expand():this.collapse()}getState(){return{...this._state}}},$oe={position:"top-right",className:"",visible:!0,collapsed:!0,defaultMode:"distance",distanceUnit:"kilometers",areaUnit:"square-kilometers",lineColor:"#3b82f6",lineWidth:3,fillColor:"rgba(59, 130, 246, 0.2)",pointColor:"#ef4444",pointRadius:6,showSegments:!0,showTotal:!0,precision:2,panelWidth:240,maxHeight:500,backgroundColor:"",borderRadius:4,opacity:1,fontSize:12,fontColor:"",minzoom:0,maxzoom:24},S9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z"/><path d="m14.5 12.5 2-2"/><path d="m11.5 9.5 2-2"/><path d="m8.5 6.5 2-2"/><path d="m17.5 15.5 2-2"/></svg>',M9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v4l-4 0"/><path d="M4 7l16 14"/><path d="M16 21v-4l4 0"/></svg>',I9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>',T9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',Hoe='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',J0={meters:{label:"Meters",factor:1},kilometers:{label:"Kilometers",factor:.001},miles:{label:"Miles",factor:621371e-9},feet:{label:"Feet",factor:3.28084},yards:{label:"Yards",factor:1.09361},"nautical-miles":{label:"Nautical Miles",factor:539957e-9}},e_={"square-meters":{label:"Square Meters",factor:1},"square-kilometers":{label:"Square Kilometers",factor:1e-6},"square-miles":{label:"Square Miles",factor:3861e-10},hectares:{label:"Hectares",factor:1e-4},acres:{label:"Acres",factor:247105e-9},"square-feet":{label:"Square Feet",factor:10.7639}};function Qoe(e,t){const n=e.lat*Math.PI/180,r=t.lat*Math.PI/180,s=(t.lat-e.lat)*Math.PI/180,a=(t.lng-e.lng)*Math.PI/180,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 6371e3*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))}function Woe(e){if(e.length<3)return 0;const t=6371e3;let i=0;for(let n=0;n<e.length;n++){const r=(n+1)%e.length,s=e[n].lat*Math.PI/180,a=e[r].lat*Math.PI/180,l=e[n].lng*Math.PI/180,h=e[r].lng*Math.PI/180;i+=(h-l)*(2+Math.sin(s)+Math.sin(a))}return i=Math.abs(i*t*t/2),i}var lj=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_sourceId;_lineLayerId;_fillLayerId;_resultValueEl;_resultUnitEl;_segmentListEl;_instructionsEl;_measurementsListEl;_boundClickHandler;_boundMoveHandler;_boundDblClickHandler;_boundKeyHandler;_markers=[];constructor(e){this._options={...$oe,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,mode:this._options.defaultMode,distanceUnit:this._options.distanceUnit,areaUnit:this._options.areaUnit,isDrawing:!1,currentPoints:[],currentValue:0,currentSegments:[],measurements:[]};const t=Qu("measure");this._sourceId=`${t}-source`,this._lineLayerId=`${t}-line`,this._fillLayerId=`${t}-fill`}onAdd(e){return this._map=e,this._container=this._createContainer(),e.isStyleLoaded()?this._setupMapSources():e.once("styledata",()=>this._setupMapSources()),this._setupZoomHandler(),this._state.collapsed||this._showPanel(),this._container}onRemove(){this._stopDrawing(),this._cleanupMapSources(),this._clearMarkers(),this._handleZoom&&this._map&&this._map.off("zoom",this._handleZoom),this._container?.remove(),this._container=void 0,this._map=void 0}getDefaultPosition(){return this._options.position}on(e,t){return this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t),this}off(e,t){return this._eventHandlers.get(e)?.delete(t),this}_emit(e,t){const i=this._eventHandlers.get(e);if(i){const n={type:e,state:{...this._state},...t};i.forEach(r=>r(n))}}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-measure-control ${this._options.className}`,e.style.opacity=String(this._options.opacity),this._state.visible||(e.style.display="none"),this._button=document.createElement("button"),this._button.type="button",this._button.className="measure-button",this._button.title="Measure distances and areas",this._button.innerHTML=S9,this._button.addEventListener("click",()=>this._togglePanel()),e.appendChild(this._button),e}_createPanel(){const e=document.createElement("div");e.className=`measure-panel ${this._options.position.includes("left")?"right":"left"}`,e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),this._options.backgroundColor&&(e.style.background=this._options.backgroundColor),e.style.borderRadius=`${this._options.borderRadius}px`,e.style.fontSize=`${this._options.fontSize}px`,this._options.fontColor&&(e.style.color=this._options.fontColor);const t=document.createElement("div");t.className="measure-header",t.innerHTML=`
|
|
106
|
+
`},uniformTypes:{minVal:"f32",maxVal:"f32",isSingleBand:"f32"},getUniforms:e=>({minVal:e.minVal,maxVal:e.maxVal,isSingleBand:e.isSingleBand})};function aj(e,t){return e&&(Array.isArray(e)?e.map(i=>aj(i,t)):typeof e.clone=="function"?e.clone({opacity:t}):e)}function Roe(e,t){return Array.isArray(e)?t(e):e&&Array.isArray(e.renderPipeline)?{...e,renderPipeline:t(e.renderPipeline)}:e}function Boe(e){let t=e.replace("#","");return t.length===3&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function Loe(e){const i=new Uint8ClampedArray(1024),n=e.map(r=>({pos:r.position,rgb:Boe(r.color)}));for(let r=0;r<256;r++){const s=r/255;let a=n[0],l=n[n.length-1];for(let p=0;p<n.length-1;p++)if(s>=n[p].pos&&s<=n[p+1].pos){a=n[p],l=n[p+1];break}const h=l.pos-a.pos,d=h>0?(s-a.pos)/h:0;i[r*4]=a.rgb[0]+(l.rgb[0]-a.rgb[0])*d,i[r*4+1]=a.rgb[1]+(l.rgb[1]-a.rgb[1])*d,i[r*4+2]=a.rgb[2]+(l.rgb[2]-a.rgb[2])*d,i[r*4+3]=255}return new ImageData(i,256,1)}function koe(e){return e?.[0]===1}function gm(e){return typeof e=="number"}function Poe(e,t){return Number.isNaN(t)?Number.isNaN(e):e===t}function w9(e,t,i){const n=Math.floor(e.length/t),r=new Uint8Array(n);r.fill(255);let s=!1;const a=gm(i);for(let l=0;l<n;l++){const h=l*t;let d=!1,p=a;for(let g=0;g<t;g++){const v=e[h+g];Number.isFinite(v)||(d=!0),a&&p&&!Poe(v,i)&&(p=!1)}(d||p)&&(r[l]=0,s=!0)}return s?r:null}function C9(e,t,i){if(!t||!("set"in e))return;const n=e;for(let r=0;r<t.length;r++){if(t[r]!==0)continue;const s=r*i;for(let a=0;a<i;a++)n[s+a]=0}}function Noe(e,t){if(!e)return t;if(!t)return e;const i=new Uint8Array(e.length);for(let n=0;n<e.length;n++)i[n]=e[n]===0||t[n]===0?0:255;return i}function E9(e,t){const i=Loe(jl(t));return e.createTexture({data:i.data,dimension:"2d-array",format:"rgba8unorm",width:i.width,height:i.height,depth:1,mipLevels:1,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge"}})}var Foe=["none","bone","bwr","cividis","cool","coolwarm","gray","hot","inferno","jet","magma","ocean","plasma","rainbow","RdBu","RdYlBu","RdYlGn","seismic","spectral","terrain","turbo","viridis"],Doe={position:"top-right",className:"",visible:!0,collapsed:!0,beforeId:"",defaultUrl:"",loadDefaultUrl:!1,defaultBands:"1",defaultColormap:"none",defaultRescaleMin:0,defaultRescaleMax:255,defaultNodata:void 0,defaultLayerName:"",defaultOpacity:1,defaultPickable:!0,panelWidth:300,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#333",minzoom:0,maxzoom:24},Ooe='<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',i6=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_deckOverlay;_cogLayers=new Map;_cogLayerPropsMap=new Map;_layerCounter=0;_activePopup;_mapClickHandler;constructor(e){this._options={...Doe,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,url:this._options.defaultUrl,bands:this._options.defaultBands,colormap:this._options.defaultColormap,rescaleMin:this._options.defaultRescaleMin,rescaleMax:this._options.defaultRescaleMax,nodata:this._options.defaultNodata,layerName:this._options.defaultLayerName,layerOpacity:this._options.defaultOpacity,pickable:this._options.defaultPickable,hasLayer:!1,layerCount:0,layers:[],loading:!1,error:null,status:null}}onAdd(e){if(this._map=e,this._container=this._createContainer(),this._render(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._setupClickHandler(),this._options.loadDefaultUrl&&this._options.defaultUrl){const t=()=>{this._addLayer()};this._map.isStyleLoaded()?setTimeout(t,100):this._map.once("idle",t)}return this._container}onRemove(){if(this._removeLayer(),this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=void 0),this._map&&this._mapClickHandler&&(this._map.off("click",this._mapClickHandler),this._mapClickHandler=void 0),this._activePopup&&(this._activePopup.remove(),this._activePopup=void 0),this._deckOverlay&&this._map){try{this._map.removeControl(this._deckOverlay)}catch{}this._deckOverlay=void 0}this._map=void 0,this._container?.parentNode?.removeChild(this._container),this._container=void 0,this._button=void 0,this._panel=void 0,this._eventHandlers.clear()}show(){this._state.visible||(this._state.visible=!0,this._updateDisplayState(),this._emit("show"))}hide(){this._state.visible&&(this._state.visible=!1,this._updateDisplayState(),this._emit("hide"))}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._render(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._render(),this._emit("collapse"))}toggle(){this._state.collapsed?this.expand():this.collapse()}getState(){return{...this._state}}update(e){this._options={...this._options,...e},e.visible!==void 0&&(this._state.visible=e.visible),e.collapsed!==void 0&&(this._state.collapsed=e.collapsed),this._render(),this._emit("update")}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}async addLayer(e){e&&(this._state.url=e),await this._addLayer()}removeLayer(e){this._removeLayer(e),this._render()}getLayerIds(){return Array.from(this._cogLayers.keys())}getLayerOpacity(e){const t=this._cogLayers.get(e);return!t||!t.props?null:t.props.opacity??1}setLayerOpacity(e,t){const i=this._cogLayers.get(e);if(!i||typeof i.clone!="function")return;const n=Math.max(0,Math.min(1,t)),r=i.clone({opacity:n});this._cogLayers.set(e,r),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}getLayerVisibility(e){const t=this.getLayerOpacity(e);return t!==null&&t>0}setLayerVisibility(e,t,i=1){t?this.setLayerOpacity(e,i):this.setLayerOpacity(e,0)}getLayerUrl(e){const t=this._cogLayerPropsMap.get(e);return t?t._sourceUrl??(typeof t.geotiff=="string"?t.geotiff:null):null}_emit(e,t){const i=this._eventHandlers.get(e);if(i){const n={type:e,state:this.getState(),...t};i.forEach(r=>r(n))}}_checkZoomVisibility(){if(!this._map)return;const e=this._map.getZoom(),{minzoom:t,maxzoom:i}=this._options,n=e>=t&&e<=i;n!==this._zoomVisible&&(this._zoomVisible=n,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const e=this._state.visible&&this._zoomVisible;this._container.style.display=e?"block":"none"}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-cog-layer${this._options.className?` ${this._options.className}`:""}`,this._state.visible&&this._zoomVisible||(e.style.display="none"),Object.assign(e.style,{backgroundColor:this._options.backgroundColor,borderRadius:`${this._options.borderRadius}px`,boxShadow:"0 0 0 2px rgba(0, 0, 0, 0.1)"}),this._options.opacity!==1&&(e.style.opacity=String(this._options.opacity)),e}_render(){if(!this._container)return;const e=this._container.querySelector(".maplibre-gl-cog-layer-panel"),t=e?e.scrollTop:0;if(this._container.innerHTML="",this._state.collapsed?this._renderCollapsed():this._renderExpanded(),this._updateDisplayState(),t>0){const i=this._container.querySelector(".maplibre-gl-cog-layer-panel");i&&(i.scrollTop=t)}}_renderCollapsed(){this._container&&(this._button=document.createElement("button"),this._button.type="button",this._button.className=`maplibre-gl-cog-layer-button${this._state.hasLayer?" maplibre-gl-cog-layer-button--active":""}`,this._button.title="COG Layer",this._button.setAttribute("aria-label","COG Layer"),this._button.innerHTML=Ooe,this._button.addEventListener("click",()=>this.expand()),this._container.appendChild(this._button),this._panel=void 0)}_renderExpanded(){if(!this._container)return;const e=document.createElement("div");e.className="maplibre-gl-cog-layer-panel",e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),this._panel=e;const t=document.createElement("div");t.className="maplibre-gl-cog-layer-header";const i=document.createElement("span");i.className="maplibre-gl-cog-layer-title",i.textContent="COG Layer",t.appendChild(i);const n=document.createElement("button");n.className="maplibre-gl-cog-layer-close",n.innerHTML="×",n.title="Close",n.addEventListener("click",()=>this.collapse()),t.appendChild(n),e.appendChild(t);const r=this._createFormGroup("COG URL","url"),s=document.createElement("input");s.type="text",s.className="maplibre-gl-cog-layer-input",s.style.color="#000",s.placeholder="https://example.com/cog.tif",s.value=this._state.url,s.addEventListener("input",()=>{this._state.url=s.value}),r.appendChild(s),e.appendChild(r);const a=this._createFormGroup("Bands (comma-separated)","bands"),l=document.createElement("input");l.type="text",l.className="maplibre-gl-cog-layer-input",l.style.color="#000",l.placeholder="1 or 1,2,3",l.value=this._state.bands,l.addEventListener("input",()=>{this._state.bands=l.value}),a.appendChild(l),e.appendChild(a);const h=this._createFormGroup("Colormap","colormap"),d=document.createElement("select");d.className="maplibre-gl-cog-layer-select",d.style.color="#000";for(const ee of Foe){const ae=document.createElement("option");ae.value=ee,ae.textContent=ee,ee===this._state.colormap&&(ae.selected=!0),d.appendChild(ae)}d.addEventListener("change",()=>{this._state.colormap=d.value,this._updateColormapPreview()}),h.appendChild(d);const p=document.createElement("div");p.className="maplibre-gl-cog-layer-colormap-preview",p.id="cog-colormap-preview",this._updateColormapPreviewElement(p),h.appendChild(p),e.appendChild(h);const g=document.createElement("div");g.className="maplibre-gl-cog-layer-row";const v=this._createFormGroup("Rescale Min","rescale-min"),y=document.createElement("input");y.type="number",y.className="maplibre-gl-cog-layer-input",y.style.color="#000",y.value=String(this._state.rescaleMin),y.addEventListener("input",()=>{this._state.rescaleMin=Number(y.value)||0}),v.appendChild(y),g.appendChild(v);const E=this._createFormGroup("Rescale Max","rescale-max"),S=document.createElement("input");S.type="number",S.className="maplibre-gl-cog-layer-input",S.style.color="#000",S.value=String(this._state.rescaleMax),S.addEventListener("input",()=>{this._state.rescaleMax=Number(S.value)||0}),E.appendChild(S),g.appendChild(E),e.appendChild(g);const R=this._createFormGroup("Nodata","nodata"),I=document.createElement("input");I.type="number",I.className="maplibre-gl-cog-layer-input",I.style.color="#000",I.placeholder="e.g. 0 or -9999",I.value=this._state.nodata!==void 0?String(this._state.nodata):"",I.addEventListener("input",()=>{this._state.nodata=I.value!==""?Number(I.value):void 0}),R.appendChild(I),e.appendChild(R);const k=this._createFormGroup("Opacity","opacity"),D=document.createElement("div");D.className="maplibre-gl-cog-layer-slider-row";const F=document.createElement("input");F.type="range",F.className="maplibre-gl-cog-layer-slider",F.min="0",F.max="100",F.value=String(Math.round(this._state.layerOpacity*100));const Z=document.createElement("span");Z.className="maplibre-gl-cog-layer-slider-value",Z.textContent=`${Math.round(this._state.layerOpacity*100)}%`,F.addEventListener("input",()=>{const ee=Number(F.value);this._state.layerOpacity=ee/100,Z.textContent=`${ee}%`,this._updateOpacity()}),D.appendChild(F),D.appendChild(Z),k.appendChild(D),e.appendChild(k);const Y=document.createElement("div");Y.className="maplibre-gl-cog-layer-form-group maplibre-gl-cog-layer-checkbox-group";const Q=document.createElement("label");Q.className="maplibre-gl-cog-layer-checkbox-label";const V=document.createElement("input");V.type="checkbox",V.className="maplibre-gl-cog-layer-checkbox",V.checked=this._state.pickable,V.addEventListener("change",()=>{this._state.pickable=V.checked,this._updatePickable()}),Q.appendChild(V);const U=document.createElement("span");U.textContent="Pickable (click to show pixel value)",Q.appendChild(U),Y.appendChild(Q),e.appendChild(Y);const H=this._createFormGroup("Layer Name","layer-name"),W=document.createElement("input");W.type="text",W.className="maplibre-gl-cog-layer-input",W.style.color="#000",W.placeholder="Optional custom layer name",W.value=this._state.layerName,W.addEventListener("input",()=>{this._state.layerName=W.value}),H.appendChild(W),e.appendChild(H);const ne=this._createFormGroup("Before Layer ID (optional)","before-id"),te=document.createElement("input");te.type="text",te.className="maplibre-gl-cog-layer-input",te.style.color="#000",te.placeholder="e.g. labels or water",te.value=this._options.beforeId||"",te.addEventListener("input",()=>{this._options.beforeId=te.value||""}),ne.appendChild(te),e.appendChild(ne);const oe=document.createElement("div");oe.className="maplibre-gl-cog-layer-buttons";const X=document.createElement("button");if(X.className="maplibre-gl-cog-layer-btn maplibre-gl-cog-layer-btn--primary",X.textContent="Add Layer",X.disabled=this._state.loading,X.addEventListener("click",()=>this._addLayer()),oe.appendChild(X),e.appendChild(oe),this._state.loading?this._appendStatus("Loading COG...","info"):this._state.error?this._appendStatus(this._state.error,"error"):this._state.status&&this._appendStatus(this._state.status,"success"),this._cogLayers.size>0){const ee=document.createElement("div");ee.className="maplibre-gl-cog-layer-list";const ae=document.createElement("div");ae.className="maplibre-gl-cog-layer-list-header",ae.textContent=`Layers (${this._cogLayers.size})`,ee.appendChild(ae);for(const[ce]of this._cogLayers){const de=this._cogLayerPropsMap.get(ce);if(!de)continue;const pe=document.createElement("div");pe.className="maplibre-gl-cog-layer-list-item";const Ie=document.createElement("span");Ie.className="maplibre-gl-cog-layer-list-label";const we=de._sourceUrl??(typeof de.geotiff=="string"?de.geotiff:""),Ee=de._layerName;let Se;if(Ee)Se=Ee;else try{Se=new URL(we).pathname.split("/").pop()||we}catch{Se=we}Ie.textContent=Se,Ie.title=we,pe.appendChild(Ie);const Ve=document.createElement("button");Ve.className="maplibre-gl-cog-layer-list-remove",Ve.innerHTML="×",Ve.title="Remove layer",Ve.addEventListener("click",()=>{this._removeLayer(ce),this._render()}),pe.appendChild(Ve),ee.appendChild(pe)}e.appendChild(ee)}this._container.appendChild(e),this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-cog-layer-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`cog-layer-${t}`,i.appendChild(n),i}_appendStatus(e,t){if(!this._panel)return;const i=document.createElement("div");i.className=`maplibre-gl-cog-layer-status maplibre-gl-cog-layer-status--${t}`,i.textContent=e,this._panel.appendChild(i)}_updateColormapPreview(){const e=document.getElementById("cog-colormap-preview");e&&this._updateColormapPreviewElement(e)}_updateColormapPreviewElement(e){if(this._state.colormap==="none")e.style.background="linear-gradient(to right, #888, #888)",e.style.display="none";else{const t=jl(this._state.colormap).map(i=>i.color).join(", ");e.style.background=`linear-gradient(to right, ${t})`,e.style.display="block"}}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:e}=await import("@deck.gl/mapbox");this._deckOverlay=new e({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const e=this._map;this._mapClickHandler=t=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:i}=t,n=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(n[0]);let s='<div class="maplibre-gl-cog-layer-popup">';s+='<table class="maplibre-gl-cog-layer-popup-table">',s+=`<tr><td><strong>Layers</strong></td><td>${n.length} COG layer(s)</td></tr>`,s+=`<tr><td><strong>Lng</strong></td><td>${i.lng.toFixed(6)}</td></tr>`,s+=`<tr><td><strong>Lat</strong></td><td>${i.lat.toFixed(6)}</td></tr>`,r&&(s+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(s+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),s+="</table>",s+="</div>",this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(i).setHTML(s).addTo(e);const a=this._activePopup.getElement();a&&(a.style.zIndex="1000")},e.on("click",this._mapClickHandler)}_updatePickable(){if(this._deckOverlay){for(const[,e]of this._cogLayerPropsMap)e.pickable=this._state.pickable;this._rebuildLayers()}}async _rebuildLayers(){if(this._deckOverlay)try{const{COGLayer:e}=await import("@developmentseed/deck.gl-geotiff");this._patchCOGLayerForFloat(e),this._patchCOGLayerForOpacity(e);const t=[];for(const[i,n]of this._cogLayerPropsMap){const r=new e(n);this._cogLayers.set(i,r),t.push(r)}this._deckOverlay.setProps({layers:t})}catch(e){console.error("Failed to rebuild layers:",e)}}async _registerCommonProjections(e){e.defs("EPSG:3978","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +type=crs"),e.defs("EPSG:3979","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=-0.991,1.9072,0.5129,-1.25033e-07,-4.6785e-08,-5.6529e-08,0 +units=m +no_defs +type=crs")}_buildGeoKeysParser(e){let t=null;return Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")).then(i=>{t=i.default||i,typeof t=="function"&&this._registerCommonProjections(t)}),async i=>{try{const n=e.toProj4(i);if(n&&n.proj4){let r=n.proj4;if(r=r.replace(/\+axis=\w+\s*/g,""),!t){const a=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs"));t=a.default||a,typeof t=="function"&&await this._registerCommonProjections(t)}let s={};if(typeof t=="function")try{t.defs("custom",r),s=t.defs("custom")||{}}catch{}return{def:r,parsed:s,coordinatesUnits:n.coordinatesUnits||"metre"}}}catch{}return null}}_patchCOGLayerForFloat(e){if(e.__floatPatched)return;e.__floatPatched=!0;const t=e.prototype._parseGeoTIFF;e.prototype._parseGeoTIFF=async function(){try{await t.call(this);const i=this.props._nodata;if(i!=null&&!isNaN(i)){const{FilterNoDataVal:n}=await import("@developmentseed/deck.gl-raster/gpu-modules"),r=this.state.defaultRenderTile;if(typeof r=="function"){const s=a=>Roe(r(a),l=>{const h=l.filter(d=>d.module!==n);return h.splice(1,0,{module:n,props:{value:i}}),h});this.setState({defaultRenderTile:s})}}}catch(i){if(!(i instanceof Error?i.message:String(i)).includes("non-unsigned integers not yet supported"))throw i;const{parseCOGTileMatrixSet:n,texture:r}=await import("@developmentseed/deck.gl-geotiff");if(typeof n!="function"||typeof r?.inferTextureFormat!="function")throw i;const{fromUrl:s}=await Promise.resolve().then(()=>require("./geotiff-CNfLW-N0.cjs")),{CreateTexture:a,FilterNoDataVal:l,MaskTexture:h}=await import("@developmentseed/deck.gl-raster/gpu-modules"),d=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")),p=d.default||d,g=this.props.geotiff,v=typeof g=="string"?await s(g):g,y=this.props.geoKeysParser,E=await n(v,y),S=await v.getImage(),R=await v.getImageCount(),I=[];for(let ae=0;ae<R;ae++)I.push(await v.getImage(ae));const k=await y(S.getGeoKeys());if(!k)throw new Error("Could not determine source projection from GeoTIFF geo keys");const D=p(k.def,"EPSG:4326"),F=(ae,ce)=>D.forward([ae,ce],!1),Z=(ae,ce)=>D.inverse([ae,ce],!1);if(this.props.onGeoTIFFLoad){const ae=S.getBoundingBox(),ce=[D.forward([ae[0],ae[1]]),D.forward([ae[2],ae[1]]),D.forward([ae[2],ae[3]]),D.forward([ae[0],ae[3]])],de=ce.map(we=>we[0]),pe=ce.map(we=>we[1]),Ie={west:Math.min(...de),south:Math.min(...pe),east:Math.max(...de),north:Math.max(...pe)};this.props.onGeoTIFFLoad(v,{projection:k,geographicBounds:Ie})}const{BitsPerSample:Y,SampleFormat:Q,SamplesPerPixel:V,GDAL_NODATA:U}=S.getFileDirectory();let H=null;if(U){const ae=U[U.length-1]==="\0"?U.slice(0,-1):U;ae.length>0&&(H=parseFloat(ae))}const W=this,ne=async(ae,ce)=>{const{device:de}=ce,pe=await ae.readRasters({...ce,interleave:!0});let Ie=pe,we=V;const Ee=gm(W.props._nodata)?W.props._nodata:H,Se=w9(Ie,we,gm(Ee)?Ee:void 0);if(C9(Ie,Se,we),V===3){const Le=pe.width*pe.height,nt=new Float32Array(Le*4);for(let lt=0;lt<Le;lt++)nt[lt*4]=pe[lt*3],nt[lt*4+1]=pe[lt*3+1],nt[lt*4+2]=pe[lt*3+2],nt[lt*4+3]=1;Ie=nt,Ie.width=pe.width,Ie.height=pe.height,we=4}const Ve=r.inferTextureFormat(we,Y,Q),ze=de.createTexture({data:Ie,format:Ve,width:pe.width,height:pe.height,sampler:{magFilter:"nearest",minFilter:"nearest"}});let it;return Se&&(it=de.createTexture({data:Se,format:"r8unorm",width:pe.width,height:pe.height,sampler:{magFilter:"nearest",minFilter:"nearest"}})),{texture:ze,height:pe.height,mask:it,width:pe.width}};let te=null,oe=null;const{Colormap:X}=await import("@developmentseed/deck.gl-raster/gpu-modules"),ee=ae=>{const ce=[{module:a,props:{textureName:ae.texture}}];ae.mask&&ce.push({module:h,props:{maskTexture:ae.mask}});const de=W.props._nodata!==void 0&&W.props._nodata!==null&&!isNaN(W.props._nodata)?W.props._nodata:H;gm(de)&&!Number.isNaN(de)&&ce.push({module:l,props:{value:de}});const pe=W.props._rescaleMin??0,Ie=W.props._rescaleMax??255;ce.push({module:x9,props:{minVal:pe,maxVal:Ie,isSingleBand:V===1?1:0}});const we=W.props._colormap;return we&&we!=="none"&&(we!==te&&(oe=E9(W.context.device,we),te=we),ce.push({module:X,props:{colormapTexture:oe}})),{renderPipeline:ce}};this.setState({metadata:E,forwardReproject:F,inverseReproject:Z,images:I,defaultGetTileData:ne,defaultRenderTile:ee})}}}_patchCOGLayerForOpacity(e){if(e.__opacityPatched)return;e.__opacityPatched=!0;const t=e.prototype._renderSubLayers;e.prototype._renderSubLayers=function(...i){const n=t.apply(this,i),r=this.props.opacity;return r==null?n:aj(n,Math.max(0,Math.min(1,r)))}}async _createFloatCogLayerProps(e){const{GeoTIFF:t}=await import("@developmentseed/geotiff"),i=await t.fromUrl(e);if(koe(i.cachedTags.sampleFormat))return{geotiff:i};const{texture:n}=await import("@developmentseed/deck.gl-geotiff"),{CreateTexture:r,FilterNoDataVal:s,MaskTexture:a,Colormap:l}=await import("@developmentseed/deck.gl-raster/gpu-modules"),h=this._state.colormap,d=this._state.nodata,p=this._state.rescaleMax,g=this._state.rescaleMin,v=async(R,I)=>{const{device:k,pool:D,signal:F,x:Z,y:Y}=I,{array:Q}=await R.fetchTile(Z,Y,{boundless:!1,pool:D,signal:F});if(Q.layout==="band-separate")throw new Error("Band-separate images are not yet implemented.");const V=R.cachedTags;let U=Q.data,H=V.samplesPerPixel,W=V.bitsPerSample,ne=V.sampleFormat;const te=gm(d)?d:V.nodata;U instanceof Float64Array&&(U=new Float32Array(U),W=Array.from({length:H},()=>32));const oe=w9(U,H,gm(te)?te:void 0);if(C9(U,oe,H),H===3){const pe=Q.width*Q.height,Ie=new Float32Array(pe*4);for(let we=0;we<pe;we++)Ie[we*4]=U[we*3],Ie[we*4+1]=U[we*3+1],Ie[we*4+2]=U[we*3+2],Ie[we*4+3]=1;U=Ie,H=4,W=[32,32,32,32],ne=[3,3,3,3]}const X=n.inferTextureFormat(H,W,ne);let ee=U.byteLength;const ae=k.createTexture({data:U,format:X,width:Q.width,height:Q.height,sampler:{magFilter:"nearest",minFilter:"nearest"}});let ce;const de=Noe(Q.mask,oe);return de&&(ce=k.createTexture({data:de,format:"r8unorm",width:Q.width,height:Q.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),ee+=de.byteLength),{byteLength:ee,device:k,height:Q.height,mask:ce,nodata:te,samplesPerPixel:H,texture:ae,width:Q.width}};let y=null,E=null;return{geotiff:i,getTileData:v,renderTile:R=>{const I=[{module:r,props:{textureName:R.texture}}];R.mask&&I.push({module:a,props:{maskTexture:R.mask}});const k=R.nodata;return gm(k)&&!Number.isNaN(k)&&I.push({module:s,props:{value:k}}),I.push({module:x9,props:{minVal:g,maxVal:p,isSingleBand:R.samplesPerPixel===1?1:0}}),h&&h!=="none"&&(y!==h&&(E=E9(R.device,h),y=h),I.push({module:l,props:{colormapTexture:E}})),{renderPipeline:I}}}}async _addLayer(){if(!this._map||!this._state.url){this._state.error="Please enter a COG URL.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{await this._ensureOverlay();const{COGLayer:e}=await import("@developmentseed/deck.gl-geotiff");this._patchCOGLayerForFloat(e),this._patchCOGLayerForOpacity(e);const t=this._map,i=await this._createFloatCogLayerProps(this._state.url),n={geotiff:this._state.url,_sourceUrl:this._state.url,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:this._state.rescaleMin,_rescaleMax:this._state.rescaleMax,_colormap:this._state.colormap,_nodata:this._state.nodata,...i??{},...(()=>{if(this._options.beforeId){if(t.getLayer(this._options.beforeId))return{beforeId:this._options.beforeId};console.warn(`[CogLayerControl] beforeId "${this._options.beforeId}" not found in map layers, adding layer on top`)}return{}})(),onGeoTIFFLoad:(l,h)=>{try{if(h&&h.geographicBounds){const{west:d,south:p,east:g,north:v}=h.geographicBounds;t.fitBounds([[d,p],[g,v]],{padding:50,duration:1e3})}}catch{}}};try{const l=await Promise.resolve().then(()=>require("./main-dist-DOx_Axbx.cjs")),h=l.default||l;h&&typeof h.toProj4=="function"&&(n.geoKeysParser=this._buildGeoKeysParser(h))}catch{}const r=`cog-layer-${this._layerCounter++}`;n.id=r;const s=this._state.layerName?.trim();s&&(n._layerName=s),this._cogLayerPropsMap.set(r,n);const a=new e(n);this._cogLayers.set(r,a),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.layers=this._buildLayerInfoList(),this._state.loading=!1,this._state.status="COG layer added successfully.",this._state.layerName="",this._render(),this._emit("layeradd",{url:this._state.url,layerId:r})}catch(e){this._state.loading=!1,this._state.error=`Failed to load COG: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_removeLayer(e){e?(this._cogLayers.delete(e),this._cogLayerPropsMap.delete(e),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.layers=this._buildLayerInfoList(),this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e})):(this._deckOverlay&&this._deckOverlay.setProps({layers:[]}),this._cogLayers.clear(),this._cogLayerPropsMap.clear(),this._state.hasLayer=!1,this._state.layerCount=0,this._state.layers=[],this._state.status=null,this._state.error=null,this._emit("layerremove"))}_updateOpacity(){if(!this._deckOverlay||this._cogLayers.size===0)return;const e=this._state.layerOpacity;for(const[t,i]of this._cogLayers)typeof i.clone=="function"&&this._cogLayers.set(t,i.clone({opacity:e}));this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}_buildLayerInfoList(){const e=[];for(const[t,i]of this._cogLayerPropsMap)e.push({id:t,name:i._layerName||void 0,url:i._sourceUrl??(typeof i.geotiff=="string"?i.geotiff:""),bands:"1",colormap:i._colormap||"none",rescaleMin:i._rescaleMin??0,rescaleMax:i._rescaleMax??255,nodata:i._nodata,opacity:i.opacity??1});return e}},Uoe={position:"bottom-left",className:"",visible:!0,collapsed:!1,width:250,height:180,zoomOffset:-5,style:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",viewportRectColor:"#0078d7",viewportRectOpacity:.2,toggleable:!0,interactive:!1,minzoom:0,maxzoom:24},Goe='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><rect x="7" y="7" width="10" height="10" rx="1" stroke-dasharray="2 2"/></svg>',pE="maplibre-minimap-viewport",zoe="maplibre-minimap-viewport-fill",Voe="maplibre-minimap-viewport-line",oj=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_minimapMap;_handleMove;_handleZoom;_zoomVisible=!0;_isDragging=!1;_dragStartLngLat;_dragCleanup;constructor(e){this._options={...Uoe,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed}}getDefaultPosition(){return this._options.position}onAdd(e){return this._map=e,this._container=this._createContainer(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._state.collapsed||this._showPanel(),this._state.visible||(this._container.style.display="none"),this._container}onRemove(){this._dragCleanup&&(this._dragCleanup(),this._dragCleanup=void 0),this._isDragging=!1,this._dragStartLngLat=void 0,this._minimapMap&&(this._minimapMap.remove(),this._minimapMap=void 0),this._map&&this._handleMove&&this._map.off("move",this._handleMove),this._map&&this._handleZoom&&this._map.off("zoom",this._handleZoom),this._container?.parentNode&&this._container.parentNode.removeChild(this._container),this._container=void 0,this._button=void 0,this._panel=void 0,this._map=void 0}on(e,t){return this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t),this}off(e,t){return this._eventHandlers.get(e)?.delete(t),this}_emit(e){const t=this._eventHandlers.get(e);if(t){const i={type:e,state:this.getState()};t.forEach(n=>n(i))}}_createContainer(){const e=document.createElement("div");return e.classList.add("maplibregl-ctrl","maplibre-gl-minimap-control"),this._options.className&&e.classList.add(this._options.className),this._options.toggleable&&(this._button=document.createElement("button"),this._button.type="button",this._button.className="minimap-button",this._button.title="Toggle minimap",this._button.innerHTML=Goe,this._button.addEventListener("click",()=>this.toggle()),e.appendChild(this._button)),e}_showPanel(){if(!this._container||!this._map||this._panel)return;this._panel=document.createElement("div"),this._panel.className="minimap-panel",this._panel.style.width=`${this._options.width}px`,this._panel.style.height=`${this._options.height}px`;const e=document.createElement("div");e.className="minimap-map",this._panel.appendChild(e),this._container.appendChild(this._panel);const t=this._map.getCenter(),i=this._map.getZoom(),n=Math.max(0,i+this._options.zoomOffset);if(this._minimapMap=new ks.default.Map({container:e,style:this._options.style,center:t,zoom:n,interactive:!1,attributionControl:!1}),this._minimapMap.on("load",()=>{this._addViewportRect(),this._updateViewportRect()}),this._handleMove=()=>{this._isDragging||(this._syncMinimap(),this._updateViewportRect())},this._map.on("move",this._handleMove),this._options.interactive&&this._minimapMap){const r=this._minimapMap._canvas;r.style.cursor="pointer";let s=null,a=!1,l=null;const h=g=>{if(!this._minimapMap||!this._map)return;g.preventDefault(),this._isDragging=!0,a=!1,s={x:g.clientX,y:g.clientY},r.style.cursor="grabbing";const v=r.getBoundingClientRect(),y=g.clientX-v.left,E=g.clientY-v.top;this._dragStartLngLat=this._minimapMap.unproject([y,E]),l=this._map.getCenter()},d=g=>{if(!this._isDragging||!this._minimapMap||!this._map||!this._dragStartLngLat||!l)return;if(s&&!a){const k=g.clientX-s.x,D=g.clientY-s.y;(Math.abs(k)>3||Math.abs(D)>3)&&(a=!0)}if(!a)return;const v=r.getBoundingClientRect(),y=g.clientX-v.left,E=g.clientY-v.top,S=this._minimapMap.unproject([y,E]),R=S.lng-this._dragStartLngLat.lng,I=S.lat-this._dragStartLngLat.lat;this._map.setCenter([l.lng+R,l.lat+I]),this._updateViewportRect()},p=g=>{if(this._isDragging&&!a&&this._minimapMap&&this._map){const v=r.getBoundingClientRect(),y=g.clientX-v.left,E=g.clientY-v.top,S=this._minimapMap.unproject([y,E]);this._map.flyTo({center:S})}this._isDragging=!1,a=!1,s=null,l=null,this._dragStartLngLat=void 0,r.style.cursor="pointer",this._syncMinimap(),this._updateViewportRect()};r.addEventListener("mousedown",h),document.addEventListener("mousemove",d),document.addEventListener("mouseup",p),this._dragCleanup=()=>{r.removeEventListener("mousedown",h),document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",p)}}}_hidePanel(){this._dragCleanup&&(this._dragCleanup(),this._dragCleanup=void 0),this._isDragging=!1,this._dragStartLngLat=void 0,this._minimapMap&&(this._minimapMap.remove(),this._minimapMap=void 0),this._map&&this._handleMove&&(this._map.off("move",this._handleMove),this._handleMove=void 0),this._panel&&(this._panel.remove(),this._panel=void 0)}_syncMinimap(){if(!this._minimapMap||!this._map)return;const e=this._map.getCenter(),t=Math.max(0,this._map.getZoom()+this._options.zoomOffset);this._minimapMap.jumpTo({center:e,zoom:t})}_addViewportRect(){this._minimapMap&&(this._minimapMap.addSource(pE,{type:"geojson",data:{type:"Feature",geometry:{type:"Polygon",coordinates:[[]]},properties:{}}}),this._minimapMap.addLayer({id:zoe,type:"fill",source:pE,paint:{"fill-color":this._options.viewportRectColor,"fill-opacity":this._options.viewportRectOpacity}}),this._minimapMap.addLayer({id:Voe,type:"line",source:pE,paint:{"line-color":this._options.viewportRectColor,"line-width":2}}))}_updateViewportRect(){if(!this._minimapMap||!this._map)return;const e=this._minimapMap.getSource(pE);if(!e||!("setData"in e))return;const t=this._map.getBounds(),i=t.getSouthWest(),n=t.getNorthEast(),r=t.getNorthWest(),s=t.getSouthEast(),a=[[i.lng,i.lat],[s.lng,s.lat],[n.lng,n.lat],[r.lng,r.lat],[i.lng,i.lat]];e.setData({type:"Feature",geometry:{type:"Polygon",coordinates:[a]},properties:{}})}_checkZoomVisibility(){if(!this._map||!this._container)return;const e=this._map.getZoom(),t=this._zoomVisible;this._zoomVisible=e>=this._options.minzoom&&e<=this._options.maxzoom,t!==this._zoomVisible&&(this._container.style.display=this._zoomVisible&&this._state.visible?"":"none")}show(){return this._state.visible=!0,this._container&&(this._container.style.display=this._zoomVisible?"":"none"),this._emit("show"),this}hide(){return this._state.visible=!1,this._container&&(this._container.style.display="none"),this._emit("hide"),this}expand(){return this._state.collapsed?(this._state.collapsed=!1,this._showPanel(),this._emit("expand"),this):this}collapse(){return this._state.collapsed?this:(this._state.collapsed=!0,this._hidePanel(),this._emit("collapse"),this)}toggle(){return this._state.collapsed?this.expand():this.collapse()}getState(){return{...this._state}}},$oe={position:"top-right",className:"",visible:!0,collapsed:!0,defaultMode:"distance",distanceUnit:"kilometers",areaUnit:"square-kilometers",lineColor:"#3b82f6",lineWidth:3,fillColor:"rgba(59, 130, 246, 0.2)",pointColor:"#ef4444",pointRadius:6,showSegments:!0,showTotal:!0,precision:2,panelWidth:240,maxHeight:500,backgroundColor:"",borderRadius:4,opacity:1,fontSize:12,fontColor:"",minzoom:0,maxzoom:24},S9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z"/><path d="m14.5 12.5 2-2"/><path d="m11.5 9.5 2-2"/><path d="m8.5 6.5 2-2"/><path d="m17.5 15.5 2-2"/></svg>',M9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v4l-4 0"/><path d="M4 7l16 14"/><path d="M16 21v-4l4 0"/></svg>',I9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>',T9='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',Hoe='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',J0={meters:{label:"Meters",factor:1},kilometers:{label:"Kilometers",factor:.001},miles:{label:"Miles",factor:621371e-9},feet:{label:"Feet",factor:3.28084},yards:{label:"Yards",factor:1.09361},"nautical-miles":{label:"Nautical Miles",factor:539957e-9}},e_={"square-meters":{label:"Square Meters",factor:1},"square-kilometers":{label:"Square Kilometers",factor:1e-6},"square-miles":{label:"Square Miles",factor:3861e-10},hectares:{label:"Hectares",factor:1e-4},acres:{label:"Acres",factor:247105e-9},"square-feet":{label:"Square Feet",factor:10.7639}};function Qoe(e,t){const n=e.lat*Math.PI/180,r=t.lat*Math.PI/180,s=(t.lat-e.lat)*Math.PI/180,a=(t.lng-e.lng)*Math.PI/180,l=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 6371e3*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))}function Woe(e){if(e.length<3)return 0;const t=6371e3;let i=0;for(let n=0;n<e.length;n++){const r=(n+1)%e.length,s=e[n].lat*Math.PI/180,a=e[r].lat*Math.PI/180,l=e[n].lng*Math.PI/180,h=e[r].lng*Math.PI/180;i+=(h-l)*(2+Math.sin(s)+Math.sin(a))}return i=Math.abs(i*t*t/2),i}var lj=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_sourceId;_lineLayerId;_fillLayerId;_resultValueEl;_resultUnitEl;_segmentListEl;_instructionsEl;_measurementsListEl;_boundClickHandler;_boundMoveHandler;_boundDblClickHandler;_boundKeyHandler;_markers=[];constructor(e){this._options={...$oe,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,mode:this._options.defaultMode,distanceUnit:this._options.distanceUnit,areaUnit:this._options.areaUnit,isDrawing:!1,currentPoints:[],currentValue:0,currentSegments:[],measurements:[]};const t=Qu("measure");this._sourceId=`${t}-source`,this._lineLayerId=`${t}-line`,this._fillLayerId=`${t}-fill`}onAdd(e){return this._map=e,this._container=this._createContainer(),e.isStyleLoaded()?this._setupMapSources():e.once("styledata",()=>this._setupMapSources()),this._setupZoomHandler(),this._state.collapsed||this._showPanel(),this._container}onRemove(){this._stopDrawing(),this._cleanupMapSources(),this._clearMarkers(),this._handleZoom&&this._map&&this._map.off("zoom",this._handleZoom),this._container?.remove(),this._container=void 0,this._map=void 0}getDefaultPosition(){return this._options.position}on(e,t){return this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t),this}off(e,t){return this._eventHandlers.get(e)?.delete(t),this}_emit(e,t){const i=this._eventHandlers.get(e);if(i){const n={type:e,state:{...this._state},...t};i.forEach(r=>r(n))}}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-measure-control ${this._options.className}`,e.style.opacity=String(this._options.opacity),this._state.visible||(e.style.display="none"),this._button=document.createElement("button"),this._button.type="button",this._button.className="measure-button",this._button.title="Measure distances and areas",this._button.innerHTML=S9,this._button.addEventListener("click",()=>this._togglePanel()),e.appendChild(this._button),e}_createPanel(){const e=document.createElement("div");e.className=`measure-panel ${this._options.position.includes("left")?"right":"left"}`,e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),this._options.backgroundColor&&(e.style.background=this._options.backgroundColor),e.style.borderRadius=`${this._options.borderRadius}px`,e.style.fontSize=`${this._options.fontSize}px`,this._options.fontColor&&(e.style.color=this._options.fontColor);const t=document.createElement("div");t.className="measure-header",t.innerHTML=`
|
|
107
107
|
<span>Measure</span>
|
|
108
108
|
<button type="button" class="measure-close" title="Close">${T9}</button>
|
|
109
109
|
`,t.querySelector(".measure-close")?.addEventListener("click",()=>this._togglePanel()),e.appendChild(t);const i=document.createElement("div");i.className="measure-content";const n=document.createElement("div");n.className="measure-mode-toggle",n.innerHTML=`
|
|
@@ -128,7 +128,7 @@ var Wae=Object.create;var A9=Object.defineProperty;var Xae=Object.getOwnProperty
|
|
|
128
128
|
<div class="segment-label">Segments</div>
|
|
129
129
|
<div class="segment-list"></div>
|
|
130
130
|
</div>
|
|
131
|
-
`,this._resultValueEl=a.querySelector(".result-value"),this._resultUnitEl=a.querySelector(".result-unit"),this._segmentListEl=a.querySelector(".segment-list"),i.appendChild(a),this._instructionsEl=document.createElement("div"),this._instructionsEl.className="measure-instructions",this._instructionsEl.textContent="Click
|
|
131
|
+
`,this._resultValueEl=a.querySelector(".result-value"),this._resultUnitEl=a.querySelector(".result-unit"),this._segmentListEl=a.querySelector(".segment-list"),i.appendChild(a),this._instructionsEl=document.createElement("div"),this._instructionsEl.className="measure-instructions",this._instructionsEl.textContent="Click Start, then click the map to add points. Double-click to finish.",i.appendChild(this._instructionsEl),this._measurementsListEl=document.createElement("div"),this._measurementsListEl.className="measurements-list",this._measurementsListEl.style.display="none",i.appendChild(this._measurementsListEl);const l=document.createElement("div");return l.className="measure-actions",l.innerHTML=`
|
|
132
132
|
<button type="button" class="action-btn primary start-btn">
|
|
133
133
|
${S9}
|
|
134
134
|
<span>Start</span>
|
|
@@ -137,7 +137,7 @@ var Wae=Object.create;var A9=Object.defineProperty;var Xae=Object.getOwnProperty
|
|
|
137
137
|
${Hoe}
|
|
138
138
|
<span>Clear All</span>
|
|
139
139
|
</button>
|
|
140
|
-
`,l.querySelector(".start-btn")?.addEventListener("click",()=>{this._state.isDrawing?this._finishDrawing():this._startDrawing()}),l.querySelector(".clear-btn")?.addEventListener("click",()=>this._clearAll()),i.appendChild(l),e.appendChild(i),e}_updateUnitOptions(e){e.innerHTML="";const t=this._state.mode==="distance"?J0:e_,i=this._state.mode==="distance"?this._state.distanceUnit:this._state.areaUnit;Object.entries(t).forEach(([n,{label:r}])=>{const s=document.createElement("option");s.value=n,s.textContent=r,s.selected=n===i,e.appendChild(s)})}_getCurrentUnitLabel(){return this._state.mode==="distance"?J0[this._state.distanceUnit].label:e_[this._state.areaUnit].label}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._showPanel(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._hidePanel(),this._emit("collapse"))}_togglePanel(){this._state.collapsed?this.expand():this.collapse()}_showPanel(){!this._panel&&this._container&&(this._panel=this._createPanel(),this._container.appendChild(this._panel)),this._button?.classList.add("active")}_hidePanel(){this._stopDrawing(),this._panel?.remove(),this._panel=void 0,this._button?.classList.remove("active")}_setMode(e){if(e===this._state.mode)return;this._stopDrawing(),this._state.mode=e,this._panel?.querySelectorAll(".mode-btn").forEach(n=>{n.classList.toggle("active",n.dataset.mode===e)});const t=this._panel?.querySelector(".measure-unit select");t&&this._updateUnitOptions(t);const i=this._panel?.querySelector(".result-label");i&&(i.textContent=e==="distance"?"Total Distance":"Total Area"),this._emit("modechange")}_setupMapSources(){this._map&&(this._map.addSource(this._sourceId,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this._map.addLayer({id:this._fillLayerId,type:"fill",source:this._sourceId,filter:["==","$type","Polygon"],paint:{"fill-color":this._options.fillColor}}),this._map.addLayer({id:this._lineLayerId,type:"line",source:this._sourceId,paint:{"line-color":this._options.lineColor,"line-width":this._options.lineWidth}}))}_cleanupMapSources(){this._map&&(this._map.getLayer(this._lineLayerId)&&this._map.removeLayer(this._lineLayerId),this._map.getLayer(this._fillLayerId)&&this._map.removeLayer(this._fillLayerId),this._map.getSource(this._sourceId)&&this._map.removeSource(this._sourceId))}_startDrawing(){if(!this._map||this._state.isDrawing)return;this._state.isDrawing=!0,this._state.currentPoints=[],this._state.currentValue=0,this._state.currentSegments=[];const e=this._panel?.querySelector(".start-btn span");e&&(e.textContent="Finish");const t=this._panel?.querySelector(".measure-result");t&&(t.style.display="block"),this._instructionsEl&&(this._instructionsEl.textContent=this._state.mode==="distance"?"Click to add points. Double-click or press Enter to finish.":"Click to add vertices. Double-click or press Enter to close the polygon."),this._boundClickHandler=i=>this._handleClick(i),this._boundMoveHandler=i=>this._handleMouseMove(i),this._boundDblClickHandler=i=>{i.preventDefault(),this._finishDrawing()},this._boundKeyHandler=i=>{i.key==="Enter"?this._finishDrawing():i.key==="Escape"&&this._cancelDrawing()},this._map.on("click",this._boundClickHandler),this._map.on("mousemove",this._boundMoveHandler),this._map.on("dblclick",this._boundDblClickHandler),document.addEventListener("keydown",this._boundKeyHandler),this._map.getCanvas().style.cursor="crosshair",this._emit("drawstart")}_stopDrawing(){if(!this._map)return;this._boundClickHandler&&this._map.off("click",this._boundClickHandler),this._boundMoveHandler&&this._map.off("mousemove",this._boundMoveHandler),this._boundDblClickHandler&&this._map.off("dblclick",this._boundDblClickHandler),this._boundKeyHandler&&document.removeEventListener("keydown",this._boundKeyHandler),this._map.getCanvas().style.cursor="",this._state.isDrawing=!1;const e=this._panel?.querySelector(".start-btn span");e&&(e.textContent="Start")}_handleClick(e){const t={lng:e.lngLat.lng,lat:e.lngLat.lat};this._state.currentPoints.push(t),this._addMarker(t),this._updateMeasurement(),this._updateMapGeometry(),this._emit("drawupdate")}_handleMouseMove(e){if(this._state.currentPoints.length===0)return;const t=[...this._state.currentPoints,{lng:e.lngLat.lng,lat:e.lngLat.lat}];this._updateMapGeometry(t)}_finishDrawing(){if(this._state.currentPoints.length<2){this._cancelDrawing();return}if(this._state.mode==="area"&&this._state.currentPoints.length<3){this._cancelDrawing();return}const e={id:Qu("measurement"),mode:this._state.mode,points:[...this._state.currentPoints],segments:[...this._state.currentSegments]};this._state.mode==="distance"?e.distance=this._state.currentValue:e.area=this._state.currentValue,this._state.measurements.push(e),this._stopDrawing(),this._updateMapGeometry(),this._updateMeasurementsList();const t=this._panel?.querySelector(".clear-btn");t&&(t.disabled=!1),this._emit("drawend",{measurement:e}),this._emit("measurementadd",{measurement:e})}_cancelDrawing(){this._stopDrawing(),this._clearMarkers(),this._state.currentPoints=[],this._state.currentValue=0,this._state.currentSegments=[],this._updateMapGeometry();const e=this._panel?.querySelector(".measure-result");e&&(e.style.display="none"),this._instructionsEl&&(this._instructionsEl.textContent="Click
|
|
140
|
+
`,l.querySelector(".start-btn")?.addEventListener("click",()=>{this._state.isDrawing?this._finishDrawing():this._startDrawing()}),l.querySelector(".clear-btn")?.addEventListener("click",()=>this._clearAll()),i.appendChild(l),e.appendChild(i),e}_updateUnitOptions(e){e.innerHTML="";const t=this._state.mode==="distance"?J0:e_,i=this._state.mode==="distance"?this._state.distanceUnit:this._state.areaUnit;Object.entries(t).forEach(([n,{label:r}])=>{const s=document.createElement("option");s.value=n,s.textContent=r,s.selected=n===i,e.appendChild(s)})}_getCurrentUnitLabel(){return this._state.mode==="distance"?J0[this._state.distanceUnit].label:e_[this._state.areaUnit].label}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._showPanel(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._hidePanel(),this._emit("collapse"))}_togglePanel(){this._state.collapsed?this.expand():this.collapse()}_showPanel(){!this._panel&&this._container&&(this._panel=this._createPanel(),this._container.appendChild(this._panel)),this._button?.classList.add("active")}_hidePanel(){this._stopDrawing(),this._panel?.remove(),this._panel=void 0,this._button?.classList.remove("active")}_setMode(e){if(e===this._state.mode)return;this._stopDrawing(),this._state.mode=e,this._panel?.querySelectorAll(".mode-btn").forEach(n=>{n.classList.toggle("active",n.dataset.mode===e)});const t=this._panel?.querySelector(".measure-unit select");t&&this._updateUnitOptions(t);const i=this._panel?.querySelector(".result-label");i&&(i.textContent=e==="distance"?"Total Distance":"Total Area"),this._emit("modechange")}_setupMapSources(){this._map&&(this._map.addSource(this._sourceId,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this._map.addLayer({id:this._fillLayerId,type:"fill",source:this._sourceId,filter:["==","$type","Polygon"],paint:{"fill-color":this._options.fillColor}}),this._map.addLayer({id:this._lineLayerId,type:"line",source:this._sourceId,paint:{"line-color":this._options.lineColor,"line-width":this._options.lineWidth}}))}_cleanupMapSources(){this._map&&(this._map.getLayer(this._lineLayerId)&&this._map.removeLayer(this._lineLayerId),this._map.getLayer(this._fillLayerId)&&this._map.removeLayer(this._fillLayerId),this._map.getSource(this._sourceId)&&this._map.removeSource(this._sourceId))}_startDrawing(){if(!this._map||this._state.isDrawing)return;this._state.isDrawing=!0,this._state.currentPoints=[],this._state.currentValue=0,this._state.currentSegments=[];const e=this._panel?.querySelector(".start-btn span");e&&(e.textContent="Finish");const t=this._panel?.querySelector(".measure-result");t&&(t.style.display="block"),this._instructionsEl&&(this._instructionsEl.textContent=this._state.mode==="distance"?"Click to add points. Double-click or press Enter to finish.":"Click to add vertices. Double-click or press Enter to close the polygon."),this._boundClickHandler=i=>this._handleClick(i),this._boundMoveHandler=i=>this._handleMouseMove(i),this._boundDblClickHandler=i=>{i.preventDefault(),this._finishDrawing()},this._boundKeyHandler=i=>{i.key==="Enter"?this._finishDrawing():i.key==="Escape"&&this._cancelDrawing()},this._map.on("click",this._boundClickHandler),this._map.on("mousemove",this._boundMoveHandler),this._map.on("dblclick",this._boundDblClickHandler),document.addEventListener("keydown",this._boundKeyHandler),this._map.getCanvas().style.cursor="crosshair",this._emit("drawstart")}_stopDrawing(){if(!this._map)return;this._boundClickHandler&&this._map.off("click",this._boundClickHandler),this._boundMoveHandler&&this._map.off("mousemove",this._boundMoveHandler),this._boundDblClickHandler&&this._map.off("dblclick",this._boundDblClickHandler),this._boundKeyHandler&&document.removeEventListener("keydown",this._boundKeyHandler),this._map.getCanvas().style.cursor="",this._state.isDrawing=!1;const e=this._panel?.querySelector(".start-btn span");e&&(e.textContent="Start")}_handleClick(e){const t={lng:e.lngLat.lng,lat:e.lngLat.lat};this._state.currentPoints.push(t),this._addMarker(t),this._updateMeasurement(),this._updateMapGeometry(),this._emit("drawupdate")}_handleMouseMove(e){if(this._state.currentPoints.length===0)return;const t=[...this._state.currentPoints,{lng:e.lngLat.lng,lat:e.lngLat.lat}];this._updateMapGeometry(t)}_finishDrawing(){if(this._state.currentPoints.length<2){this._cancelDrawing();return}if(this._state.mode==="area"&&this._state.currentPoints.length<3){this._cancelDrawing();return}const e={id:Qu("measurement"),mode:this._state.mode,points:[...this._state.currentPoints],segments:[...this._state.currentSegments]};this._state.mode==="distance"?e.distance=this._state.currentValue:e.area=this._state.currentValue,this._state.measurements.push(e),this._stopDrawing(),this._updateMapGeometry(),this._updateMeasurementsList();const t=this._panel?.querySelector(".clear-btn");t&&(t.disabled=!1),this._emit("drawend",{measurement:e}),this._emit("measurementadd",{measurement:e})}_cancelDrawing(){this._stopDrawing(),this._clearMarkers(),this._state.currentPoints=[],this._state.currentValue=0,this._state.currentSegments=[],this._updateMapGeometry();const e=this._panel?.querySelector(".measure-result");e&&(e.style.display="none"),this._instructionsEl&&(this._instructionsEl.textContent="Click Start, then click the map to add points. Double-click to finish.")}_updateMeasurement(){const e=this._state.currentPoints;if(this._state.mode==="distance"){let t=0;const i=[];for(let n=1;n<e.length;n++){const r=Qoe(e[n-1],e[n]);i.push(r),t+=r}this._state.currentValue=t,this._state.currentSegments=i}else this._state.currentValue=Woe(e);this._updateResult()}_updateResult(){if(!this._resultValueEl||!this._resultUnitEl)return;let e,t;if(this._state.mode==="distance"){const i=J0[this._state.distanceUnit].factor;e=this._state.currentValue*i,t=J0[this._state.distanceUnit].label}else{const i=e_[this._state.areaUnit].factor;e=this._state.currentValue*i,t=e_[this._state.areaUnit].label}if(this._resultValueEl.textContent=e.toFixed(this._options.precision),this._resultUnitEl.textContent=t,this._segmentListEl&&this._state.mode==="distance"&&this._options.showSegments){const i=this._segmentListEl.parentElement;if(this._state.currentSegments.length>0){i.style.display="block";const n=J0[this._state.distanceUnit].factor;this._segmentListEl.innerHTML=this._state.currentSegments.map((r,s)=>`<span class="segment-item">${s+1}: ${(r*n).toFixed(2)}</span>`).join("")}else i.style.display="none"}}_updateMapGeometry(e){if(!this._map)return;const t=this._map.getSource(this._sourceId);if(!t)return;const i=[];for(const r of this._state.measurements)if(r.mode==="distance")i.push({type:"Feature",properties:{id:r.id,mode:r.mode},geometry:{type:"LineString",coordinates:r.points.map(s=>[s.lng,s.lat])}});else{const s=r.points.map(a=>[a.lng,a.lat]);s.push(s[0]),i.push({type:"Feature",properties:{id:r.id,mode:r.mode},geometry:{type:"Polygon",coordinates:[s]}})}const n=e||this._state.currentPoints;if(n.length>=2)if(this._state.mode==="distance")i.push({type:"Feature",properties:{current:!0},geometry:{type:"LineString",coordinates:n.map(r=>[r.lng,r.lat])}});else if(n.length>=3){const r=n.map(s=>[s.lng,s.lat]);r.push(r[0]),i.push({type:"Feature",properties:{current:!0},geometry:{type:"Polygon",coordinates:[r]}})}else i.push({type:"Feature",properties:{current:!0},geometry:{type:"LineString",coordinates:n.map(r=>[r.lng,r.lat])}});t.setData({type:"FeatureCollection",features:i})}_addMarker(e){if(!this._map)return;const t=window.maplibregl;import("maplibre-gl").then(i=>{const n=i.Marker||t?.Marker;if(!n||!this._map)return;const r=document.createElement("div");r.className="maplibre-gl-measure-vertex",r.style.width=`${this._options.pointRadius*2}px`,r.style.height=`${this._options.pointRadius*2}px`,r.style.borderRadius="50%",r.style.backgroundColor=this._options.pointColor,r.style.border="2px solid white",r.style.boxShadow="0 1px 4px rgba(0,0,0,0.3)",r.style.cursor="pointer";const s=new n({element:r}).setLngLat([e.lng,e.lat]).addTo(this._map);this._markers.push(s)})}_clearMarkers(){this._markers.forEach(e=>e.remove()),this._markers=[]}_updateMeasurementsList(){if(this._measurementsListEl){if(this._state.measurements.length===0){this._measurementsListEl.style.display="none";return}this._measurementsListEl.style.display="block",this._measurementsListEl.innerHTML=this._state.measurements.map(e=>{let t,i;if(e.mode==="distance"){const n=J0[this._state.distanceUnit].factor;t=`${((e.distance||0)*n).toFixed(2)} ${J0[this._state.distanceUnit].label}`,i=M9}else{const n=e_[this._state.areaUnit].factor;t=`${((e.area||0)*n).toFixed(2)} ${e_[this._state.areaUnit].label}`,i=I9}return`
|
|
141
141
|
<div class="measurement-item" data-id="${e.id}">
|
|
142
142
|
<div class="measurement-info">
|
|
143
143
|
<span class="measurement-icon">${i}</span>
|
|
@@ -225,7 +225,7 @@ var Wae=Object.create;var A9=Object.defineProperty;var Xae=Object.getOwnProperty
|
|
|
225
225
|
</div>
|
|
226
226
|
<div><strong>Date:</strong> ${this._state.stacItem.properties?.datetime||"N/A"}</div>
|
|
227
227
|
<div><strong>Assets:</strong> ${this._state.assets.length} available</div>
|
|
228
|
-
`,e.appendChild(l)}if(this._cogLayers.size>0){const l=document.createElement("div");l.className="maplibre-gl-stac-layer-list";const h=document.createElement("div");h.className="maplibre-gl-stac-layer-list-header",h.textContent=`Layers (${this._cogLayers.size})`,l.appendChild(h);for(const[d]of this._cogLayers){const p=document.createElement("div");p.className="maplibre-gl-stac-layer-list-item";const g=document.createElement("span");g.className="maplibre-gl-stac-layer-list-label",g.textContent=this._cogLayerPropsMap.get(d)?._layerName||d,g.title=d,p.appendChild(g);const v=document.createElement("button");v.className="maplibre-gl-stac-layer-list-remove",v.innerHTML="×",v.title="Remove layer",v.addEventListener("click",()=>{this._removeLayer(d),this._render()}),p.appendChild(v),l.appendChild(p)}e.appendChild(l)}this._container.appendChild(e),this._panel=e,this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-stac-layer-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`stac-layer-${t}`,i.appendChild(n),i}_appendStatus(e,t,i){const n=document.createElement("div");n.className=`maplibre-gl-stac-layer-status maplibre-gl-stac-layer-status--${i}`,n.textContent=t,e.appendChild(n)}_autoSetRescale(){if(!this._state.selectedAsset)return;const e=this._state.assets.find(i=>i.key===this._state.selectedAsset);if(!e)return;const t=e.dataType?.toLowerCase();t==="uint16"?(this._state.rescaleMin=0,this._state.rescaleMax=1e4):t==="int16"?(this._state.rescaleMin=-32768,this._state.rescaleMax=32767):t==="float32"||t==="float64"?(this._state.rescaleMin=0,this._state.rescaleMax=1):t==="uint8"&&(this._state.rescaleMin=0,this._state.rescaleMax=255)}_updateColormapPreview(){const e=this._colormapPreview;if(!e)return;if(this._state.colormap==="none"){e.style.display="none";return}const t=jl(this._state.colormap);if(t&&t.length>0){const i=t.map(n=>n.color).join(", ");e.style.background=`linear-gradient(to right, ${i})`,e.style.display="block"}else e.style.display="none"}async _fetchStacItem(){if(!this._state.stacUrl){this._state.error="Please enter a STAC item URL.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._state.stacItem=null,this._state.assets=[],this._state.selectedAsset=null,this._render();try{const e=await fetch(this._state.stacUrl);if(!e.ok)throw new Error(`Failed to fetch: ${e.status} ${e.statusText}`);const t=await e.text(),i=JSON.parse(t);if(i.type!=="Feature"||!i.assets)throw new Error("Invalid STAC item: missing 'type: Feature' or 'assets'");this._state.stacItem=i;const n=[],r=t.match(/"assets"\s*:\s*\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}/);if(r){const l=r[1].matchAll(/"([^"]+)"\s*:\s*\{/g);for(const h of l)n.push(h[1])}const s=n.length>0?n:Object.keys(i.assets),a=[];for(const l of s){const h=i.assets[l];if(!h)continue;const d=h;if(d.type?.includes("geotiff")||d.type?.includes("image/tiff")||d.href?.endsWith(".tif")||d.href?.endsWith(".tiff")){const p=d["raster:bands"]?.[0],g=d["eo:bands"]?.[0];a.push({key:l,href:d.href,type:d.type||"image/tiff",title:d.title||l,dataType:p?.data_type||d.data_type,nodata:p?.nodata??d.nodata,scale:p?.scale,offset:p?.offset,centerWavelength:g?.center_wavelength,commonName:g?.common_name})}}a.sort((l,h)=>l.centerWavelength!==void 0&&h.centerWavelength!==void 0?l.centerWavelength-h.centerWavelength:l.centerWavelength!==void 0?-1:h.centerWavelength!==void 0?1:0),this._state.assets=a,this._state.loading=!1,this._state.status=`Found ${a.length} COG asset(s)`,this._emit("stacload",{url:this._state.stacUrl})}catch(e){this._state.loading=!1,this._state.error=`Failed to load STAC: ${e instanceof Error?e.message:String(e)}`,this._emit("error",{error:this._state.error})}this._render()}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:e}=await import("@deck.gl/mapbox");this._deckOverlay=new e({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const e=this._map;this._mapClickHandler=t=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:i}=t,n=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(n[0]);let s='<div class="maplibre-gl-stac-layer-popup">';s+='<table class="maplibre-gl-stac-layer-popup-table">',s+=`<tr><td><strong>Layers</strong></td><td>${n.length} STAC layer(s)</td></tr>`,s+=`<tr><td><strong>Lng</strong></td><td>${i.lng.toFixed(6)}</td></tr>`,s+=`<tr><td><strong>Lat</strong></td><td>${i.lat.toFixed(6)}</td></tr>`,r&&(s+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(s+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),s+="</table></div>",this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(i).setHTML(s).addTo(e);const a=this._activePopup.getElement();a&&(a.style.zIndex="1000")},e.on("click",this._mapClickHandler)}async _addLayer(){if(!this._map){this._state.error="Map not available.",this._render();return}if(this._state.rgbMode){const[t,i,n]=this._state.rgbAssets;if(!t||!i||!n){this._state.error="Please select assets for all RGB bands.",this._render();return}const r=this._state.assets.find(l=>l.key===t),s=this._state.assets.find(l=>l.key===i),a=this._state.assets.find(l=>l.key===n);if(!r||!s||!a){this._state.error="One or more selected assets not found.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{await this._ensureOverlay();const{COGLayer:l}=await import("@developmentseed/deck.gl-geotiff"),{fromUrl:h}=await Promise.resolve().then(()=>require("./geotiff-DG1Dpz4s.cjs"));this._patchCOGLayer(l);const d=`stac-${this._state.stacItem?.id||"layer"}-rgb-${this._layerCounter++}`,[p,g,v]=await Promise.all([h(r.href),h(s.href),h(a.href)]),y=await p.getImageCount(),E=await g.getImageCount(),S=await v.getImageCount(),R=[],I=[],k=[];for(let H=0;H<y;H++)R.push(await p.getImage(H));for(let H=0;H<E;H++)I.push(await g.getImage(H));for(let H=0;H<S;H++)k.push(await v.getImage(H));const D=this._state.rescaleMin,F=this._state.rescaleMax,Z=F-D,Y={id:d,geotiff:p,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:D,_rescaleMax:F,_isRgb:!0,_preRescaled:!0,getTileData:async(H,W)=>{const{window:ne,pool:te,device:oe}=W,X=H.getWidth(),ee=H.getHeight();let ae=I[0],ce=k[0];for(const nt of I)if(nt.getWidth()===X&&nt.getHeight()===ee){ae=nt;break}for(const nt of k)if(nt.getWidth()===X&&nt.getHeight()===ee){ce=nt;break}const de={window:ne,pool:te,interleave:!1},[pe,Ie,we]=await Promise.all([H.readRasters(de),ae.readRasters(de),ce.readRasters(de)]),Ee=pe.width,Se=pe.height,Ve=pe[0],ze=Ie[0],it=we[0],Le=new Uint8ClampedArray(Ee*Se*4);for(let nt=0;nt<Ee*Se;nt++){const lt=Ve[nt],Ae=ze[nt],vt=it[nt];if(lt===0&&Ae===0&&vt===0)Le[nt*4]=0,Le[nt*4+1]=0,Le[nt*4+2]=0,Le[nt*4+3]=0;else{const Ne=Math.max(0,Math.min(255,(lt-D)/Z*255)),$t=Math.max(0,Math.min(255,(Ae-D)/Z*255)),It=Math.max(0,Math.min(255,(vt-D)/Z*255));Le[nt*4]=Ne,Le[nt*4+1]=$t,Le[nt*4+2]=It,Le[nt*4+3]=255}}return{texture:oe.createTexture({data:Le,format:"rgba8unorm",width:Ee,height:Se,sampler:{magFilter:"nearest",minFilter:"nearest"}}),width:Ee,height:Se,_preRescaled:!0}}},Q=await this._buildGeoKeysParser();Q&&(Y.geoKeysParser=Q);const V=this._state.layerName?.trim();V&&(Y._layerName=V),this._cogLayerPropsMap.set(d,Y);const U=new l(Y);if(this._cogLayers.set(d,U),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[H,W,ne,te]=this._state.stacItem.bbox;this._map.fitBounds([[H,W],[ne,te]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.loading=!1,this._state.status=`Added RGB layer: ${t}, ${i}, ${n}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:d,assetKey:`${t},${i},${n}`,url:r.href,layerName:V||void 0})}catch(l){this._state.loading=!1,this._state.error=`Failed to add RGB layer: ${l instanceof Error?l.message:String(l)}`,this._render(),this._emit("error",{error:this._state.error})}return}if(!this._state.selectedAsset){this._state.error="Please select an asset.",this._render();return}const e=this._state.assets.find(t=>t.key===this._state.selectedAsset);if(!e){this._state.error="Selected asset not found.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{await this._ensureOverlay();const{COGLayer:t}=await import("@developmentseed/deck.gl-geotiff");this._patchCOGLayer(t);const i=`stac-${this._state.stacItem?.id||"layer"}-${e.key}-${this._layerCounter++}`,n={id:i,geotiff:e.href,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:this._state.rescaleMin,_rescaleMax:this._state.rescaleMax,_colormap:this._state.colormap},r=this._state.layerName?.trim();r&&(n._layerName=r);const s=await this._buildGeoKeysParser();s&&(n.geoKeysParser=s),this._cogLayerPropsMap.set(i,n);const a=new t(n);if(this._cogLayers.set(i,a),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[l,h,d,p]=this._state.stacItem.bbox;this._map.fitBounds([[l,h],[d,p]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.loading=!1,this._state.status=`Added layer: ${e.title||e.key}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:i,assetKey:e.key,url:e.href,layerName:r||void 0})}catch(t){this._state.loading=!1,this._state.error=`Failed to add layer: ${t instanceof Error?t.message:String(t)}`,this._render(),this._emit("error",{error:this._state.error})}}_updateOpacity(){if(!this._deckOverlay)return;for(const[,t]of this._cogLayerPropsMap)t.opacity=this._state.layerOpacity;const e=Array.from(this._cogLayers.entries()).map(([t])=>{const i=this._cogLayerPropsMap.get(t);return this._cogLayers.get(t).clone(i)});this._deckOverlay.setProps({layers:e})}_updateRescaleAndColormap(){if(!this._deckOverlay||this._cogLayers.size===0)return;for(const[,t]of this._cogLayerPropsMap)t._isRgb||(t._rescaleMin=this._state.rescaleMin,t._rescaleMax=this._state.rescaleMax,t._colormap=this._state.colormap);const e=Array.from(this._cogLayers.entries()).map(([t])=>{const i=this._cogLayerPropsMap.get(t);return this._cogLayers.get(t).clone(i)});this._deckOverlay.setProps({layers:e})}_removeLayer(e){this._map&&(this._cogLayers.delete(e),this._cogLayerPropsMap.delete(e),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e}))}_removeAllLayers(){for(const[e]of this._cogLayers)this._removeLayer(e)}_patchCOGLayer(e){if(e.__stacPatched)return;e.__stacPatched=!0;const t=e.prototype._renderSubLayers;e.prototype._renderSubLayers=function(...n){const r=t.apply(this,n),s=this.props.opacity;return s==null?r:fj(r,Math.max(0,Math.min(1,s)))};const i=e.prototype._parseGeoTIFF;e.prototype._parseGeoTIFF=async function(){const{parseCOGTileMatrixSet:n,texture:r}=await import("@developmentseed/deck.gl-geotiff");if(typeof n!="function"||typeof r?.inferTextureFormat!="function")return i.call(this);const{fromUrl:s}=await Promise.resolve().then(()=>require("./geotiff-DG1Dpz4s.cjs")),{CreateTexture:a,FilterNoDataVal:l,Colormap:h}=await import("@developmentseed/deck.gl-raster/gpu-modules"),d=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")),p=d.default||d,g=this.props.geotiff,v=typeof g=="string"?await s(g):g,y=this.props.geoKeysParser;let E;try{E=await n(v,y)}catch{E=await n(v,void 0)}const S=await v.getImage(),R=await v.getImageCount(),I=[];for(let ce=0;ce<R;ce++)I.push(await v.getImage(ce));const k=y?await y(S.getGeoKeys()):null;let D=null,F=null;if(k&&typeof p=="function"){const ce=p(k.def,"EPSG:4326");if(D=(de,pe)=>ce.forward([de,pe],!1),F=(de,pe)=>ce.inverse([de,pe],!1),this.props.onGeoTIFFLoad){const de=S.getBoundingBox(),pe=[ce.forward([de[0],de[1]]),ce.forward([de[2],de[1]]),ce.forward([de[2],de[3]]),ce.forward([de[0],de[3]])],Ie=pe.map(Se=>Se[0]),we=pe.map(Se=>Se[1]),Ee={west:Math.min(...Ie),south:Math.min(...we),east:Math.max(...Ie),north:Math.max(...we)};this.props.onGeoTIFFLoad(v,{projection:k,geographicBounds:Ee})}}const{BitsPerSample:Z,SampleFormat:Y,SamplesPerPixel:Q,GDAL_NODATA:V}=S.getFileDirectory();let U=null;if(V){const ce=V[V.length-1]==="\0"?V.slice(0,-1):V;ce.length>0&&(U=parseFloat(ce))}const H=this,W=H.props._rescaleMin??0,ne=H.props._rescaleMax??1e4,te=async(ce,de)=>{const{device:pe}=de,Ie=await ce.readRasters({...de,interleave:!0}),we=typeof Z=="object"&&Z?.[0]!==void 0?Z[0]:Z,Ee=Ie.width*Ie.height;if(Q===1&&we===16){const Ve=new Uint8ClampedArray(Ee*4),ze=ne-W,it=H.props._colormap;let Le=null;it&&it!=="none"&&(Le=jl(it));for(let nt=0;nt<Ee;nt++){const lt=Ie[nt];if(lt===0||lt===U)Ve[nt*4]=0,Ve[nt*4+1]=0,Ve[nt*4+2]=0,Ve[nt*4+3]=0;else{const Ae=Math.max(0,Math.min(1,(lt-W)/ze));if(Le){const vt=mle(Le,Ae);Ve[nt*4]=vt[0],Ve[nt*4+1]=vt[1],Ve[nt*4+2]=vt[2],Ve[nt*4+3]=255}else{const vt=Math.round(Ae*255);Ve[nt*4]=vt,Ve[nt*4+1]=vt,Ve[nt*4+2]=vt,Ve[nt*4+3]=255}}}return{texture:pe.createTexture({data:Ve,format:"rgba8unorm",width:Ie.width,height:Ie.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:Ie.height,width:Ie.width,_preRescaled:!0,_colormapApplied:!!Le}}if(Q===3){const Ve=new Uint8ClampedArray(Ee*4);for(let ze=0;ze<Ee;ze++){const it=Ie[ze*3],Le=Ie[ze*3+1],nt=Ie[ze*3+2];it===0&&Le===0&&nt===0?(Ve[ze*4]=0,Ve[ze*4+1]=0,Ve[ze*4+2]=0,Ve[ze*4+3]=0):(Ve[ze*4]=it,Ve[ze*4+1]=Le,Ve[ze*4+2]=nt,Ve[ze*4+3]=255)}return{texture:pe.createTexture({data:Ve,format:"rgba8unorm",width:Ie.width,height:Ie.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:Ie.height,width:Ie.width,_preRescaled:!0}}const Se=r.inferTextureFormat(Q,Z,Y);return{texture:pe.createTexture({data:Ie,format:Se,width:Ie.width,height:Ie.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:Ie.height,width:Ie.width}},oe=this;let X=null,ee=null;const ae=ce=>{const de=[{module:a,props:{textureName:ce.texture}}];if(!ce._preRescaled){U!==null&&de.push({module:l,props:{value:U}});const Ie=oe.props._rescaleMin??0,we=oe.props._rescaleMax??255;de.push({module:fle,props:{minVal:Ie,maxVal:we,isSingleBand:Q===1?1:0}})}const pe=oe.props._colormap;if(pe&&pe!=="none"&&!ce._colormapApplied){if(pe!==X){const Ie=ple(jl(pe));ee=oe.context.device.createTexture({data:Ie.data,format:"rgba8unorm",width:Ie.width,height:Ie.height,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}}),X=pe}de.push({module:h,props:{colormapTexture:ee}})}return{renderPipeline:de}};oe.setState({metadata:E,forwardReproject:D,inverseReproject:F,images:I,defaultGetTileData:te,defaultRenderTile:ae})}}async _registerCommonProjections(e){e.defs("EPSG:3978","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +type=crs"),e.defs("EPSG:3979","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=-0.991,1.9072,0.5129,-1.25033e-07,-4.6785e-08,-5.6529e-08,0 +units=m +no_defs +type=crs")}async _buildGeoKeysParser(){try{const e=await Promise.resolve().then(()=>require("./main-dist-DOx_Axbx.cjs")),t=e.default||e;if(!t||typeof t.toProj4!="function")return console.warn("geotiff-geokeys-to-proj4 not available or invalid"),null;const i=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")),n=i.default||i;return typeof n=="function"&&await this._registerCommonProjections(n),async r=>{try{const s=t.toProj4(r);if(s&&s.proj4){let a=s.proj4;a=a.replace(/\+axis=\w+\s*/g,"");let l={};if(typeof n=="function")try{n.defs("custom",a),l=n.defs("custom")||{}}catch(h){console.error("STAC proj4 parsing error:",h)}return{def:a,parsed:l,coordinatesUnits:s.coordinatesUnits||"metre"}}}catch(s){console.error("STAC geoKeysParser error:",s)}return null}}catch(e){return console.error("STAC _buildGeoKeysParser error:",e),null}}},vle=[{name:"Element84 Earth Search",url:"https://earth-search.aws.element84.com/v1"},{name:"Microsoft Planetary Computer",url:"https://planetarycomputer.microsoft.com/api/stac/v1"}],yle=["viridis","plasma","inferno","magma","cividis","coolwarm","bwr","seismic","RdBu","RdYlBu","RdYlGn","spectral","jet","rainbow","turbo","terrain","ocean","hot","cool","gray","bone"],ble={position:"top-right",className:"",visible:!0,collapsed:!0,panelWidth:360,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#1a1a1a",catalogs:vle,maxItems:20,defaultRescaleMin:0,defaultRescaleMax:1e4,defaultColormap:"viridis",defaultRgbMode:!0,showFootprints:!0,minzoom:0,maxzoom:24},xle=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
228
|
+
`,e.appendChild(l)}if(this._cogLayers.size>0){const l=document.createElement("div");l.className="maplibre-gl-stac-layer-list";const h=document.createElement("div");h.className="maplibre-gl-stac-layer-list-header",h.textContent=`Layers (${this._cogLayers.size})`,l.appendChild(h);for(const[d]of this._cogLayers){const p=document.createElement("div");p.className="maplibre-gl-stac-layer-list-item";const g=document.createElement("span");g.className="maplibre-gl-stac-layer-list-label",g.textContent=this._cogLayerPropsMap.get(d)?._layerName||d,g.title=d,p.appendChild(g);const v=document.createElement("button");v.className="maplibre-gl-stac-layer-list-remove",v.innerHTML="×",v.title="Remove layer",v.addEventListener("click",()=>{this._removeLayer(d),this._render()}),p.appendChild(v),l.appendChild(p)}e.appendChild(l)}this._container.appendChild(e),this._panel=e,this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-stac-layer-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`stac-layer-${t}`,i.appendChild(n),i}_appendStatus(e,t,i){const n=document.createElement("div");n.className=`maplibre-gl-stac-layer-status maplibre-gl-stac-layer-status--${i}`,n.textContent=t,e.appendChild(n)}_autoSetRescale(){if(!this._state.selectedAsset)return;const e=this._state.assets.find(i=>i.key===this._state.selectedAsset);if(!e)return;const t=e.dataType?.toLowerCase();t==="uint16"?(this._state.rescaleMin=0,this._state.rescaleMax=1e4):t==="int16"?(this._state.rescaleMin=-32768,this._state.rescaleMax=32767):t==="float32"||t==="float64"?(this._state.rescaleMin=0,this._state.rescaleMax=1):t==="uint8"&&(this._state.rescaleMin=0,this._state.rescaleMax=255)}_updateColormapPreview(){const e=this._colormapPreview;if(!e)return;if(this._state.colormap==="none"){e.style.display="none";return}const t=jl(this._state.colormap);if(t&&t.length>0){const i=t.map(n=>n.color).join(", ");e.style.background=`linear-gradient(to right, ${i})`,e.style.display="block"}else e.style.display="none"}async _fetchStacItem(){if(!this._state.stacUrl){this._state.error="Please enter a STAC item URL.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._state.stacItem=null,this._state.assets=[],this._state.selectedAsset=null,this._render();try{const e=await fetch(this._state.stacUrl);if(!e.ok)throw new Error(`Failed to fetch: ${e.status} ${e.statusText}`);const t=await e.text(),i=JSON.parse(t);if(i.type!=="Feature"||!i.assets)throw new Error("Invalid STAC item: missing 'type: Feature' or 'assets'");this._state.stacItem=i;const n=[],r=t.match(/"assets"\s*:\s*\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}/);if(r){const l=r[1].matchAll(/"([^"]+)"\s*:\s*\{/g);for(const h of l)n.push(h[1])}const s=n.length>0?n:Object.keys(i.assets),a=[];for(const l of s){const h=i.assets[l];if(!h)continue;const d=h;if(d.type?.includes("geotiff")||d.type?.includes("image/tiff")||d.href?.endsWith(".tif")||d.href?.endsWith(".tiff")){const p=d["raster:bands"]?.[0],g=d["eo:bands"]?.[0];a.push({key:l,href:d.href,type:d.type||"image/tiff",title:d.title||l,dataType:p?.data_type||d.data_type,nodata:p?.nodata??d.nodata,scale:p?.scale,offset:p?.offset,centerWavelength:g?.center_wavelength,commonName:g?.common_name})}}a.sort((l,h)=>l.centerWavelength!==void 0&&h.centerWavelength!==void 0?l.centerWavelength-h.centerWavelength:l.centerWavelength!==void 0?-1:h.centerWavelength!==void 0?1:0),this._state.assets=a,this._state.loading=!1,this._state.status=`Found ${a.length} COG asset(s)`,this._emit("stacload",{url:this._state.stacUrl})}catch(e){this._state.loading=!1,this._state.error=`Failed to load STAC: ${e instanceof Error?e.message:String(e)}`,this._emit("error",{error:this._state.error})}this._render()}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:e}=await import("@deck.gl/mapbox");this._deckOverlay=new e({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const e=this._map;this._mapClickHandler=t=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:i}=t,n=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(n[0]);let s='<div class="maplibre-gl-stac-layer-popup">';s+='<table class="maplibre-gl-stac-layer-popup-table">',s+=`<tr><td><strong>Layers</strong></td><td>${n.length} STAC layer(s)</td></tr>`,s+=`<tr><td><strong>Lng</strong></td><td>${i.lng.toFixed(6)}</td></tr>`,s+=`<tr><td><strong>Lat</strong></td><td>${i.lat.toFixed(6)}</td></tr>`,r&&(s+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(s+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),s+="</table></div>",this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(i).setHTML(s).addTo(e);const a=this._activePopup.getElement();a&&(a.style.zIndex="1000")},e.on("click",this._mapClickHandler)}async _addLayer(){if(!this._map){this._state.error="Map not available.",this._render();return}if(this._state.rgbMode){const[t,i,n]=this._state.rgbAssets;if(!t||!i||!n){this._state.error="Please select assets for all RGB bands.",this._render();return}const r=this._state.assets.find(l=>l.key===t),s=this._state.assets.find(l=>l.key===i),a=this._state.assets.find(l=>l.key===n);if(!r||!s||!a){this._state.error="One or more selected assets not found.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{await this._ensureOverlay();const{COGLayer:l}=await import("@developmentseed/deck.gl-geotiff"),{fromUrl:h}=await Promise.resolve().then(()=>require("./geotiff-CNfLW-N0.cjs"));this._patchCOGLayer(l);const d=`stac-${this._state.stacItem?.id||"layer"}-rgb-${this._layerCounter++}`,[p,g,v]=await Promise.all([h(r.href),h(s.href),h(a.href)]),y=await p.getImageCount(),E=await g.getImageCount(),S=await v.getImageCount(),R=[],I=[],k=[];for(let H=0;H<y;H++)R.push(await p.getImage(H));for(let H=0;H<E;H++)I.push(await g.getImage(H));for(let H=0;H<S;H++)k.push(await v.getImage(H));const D=this._state.rescaleMin,F=this._state.rescaleMax,Z=F-D,Y={id:d,geotiff:p,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:D,_rescaleMax:F,_isRgb:!0,_preRescaled:!0,getTileData:async(H,W)=>{const{window:ne,pool:te,device:oe}=W,X=H.getWidth(),ee=H.getHeight();let ae=I[0],ce=k[0];for(const nt of I)if(nt.getWidth()===X&&nt.getHeight()===ee){ae=nt;break}for(const nt of k)if(nt.getWidth()===X&&nt.getHeight()===ee){ce=nt;break}const de={window:ne,pool:te,interleave:!1},[pe,Ie,we]=await Promise.all([H.readRasters(de),ae.readRasters(de),ce.readRasters(de)]),Ee=pe.width,Se=pe.height,Ve=pe[0],ze=Ie[0],it=we[0],Le=new Uint8ClampedArray(Ee*Se*4);for(let nt=0;nt<Ee*Se;nt++){const lt=Ve[nt],Ae=ze[nt],vt=it[nt];if(lt===0&&Ae===0&&vt===0)Le[nt*4]=0,Le[nt*4+1]=0,Le[nt*4+2]=0,Le[nt*4+3]=0;else{const Ne=Math.max(0,Math.min(255,(lt-D)/Z*255)),$t=Math.max(0,Math.min(255,(Ae-D)/Z*255)),It=Math.max(0,Math.min(255,(vt-D)/Z*255));Le[nt*4]=Ne,Le[nt*4+1]=$t,Le[nt*4+2]=It,Le[nt*4+3]=255}}return{texture:oe.createTexture({data:Le,format:"rgba8unorm",width:Ee,height:Se,sampler:{magFilter:"nearest",minFilter:"nearest"}}),width:Ee,height:Se,_preRescaled:!0}}},Q=await this._buildGeoKeysParser();Q&&(Y.geoKeysParser=Q);const V=this._state.layerName?.trim();V&&(Y._layerName=V),this._cogLayerPropsMap.set(d,Y);const U=new l(Y);if(this._cogLayers.set(d,U),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[H,W,ne,te]=this._state.stacItem.bbox;this._map.fitBounds([[H,W],[ne,te]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.loading=!1,this._state.status=`Added RGB layer: ${t}, ${i}, ${n}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:d,assetKey:`${t},${i},${n}`,url:r.href,layerName:V||void 0})}catch(l){this._state.loading=!1,this._state.error=`Failed to add RGB layer: ${l instanceof Error?l.message:String(l)}`,this._render(),this._emit("error",{error:this._state.error})}return}if(!this._state.selectedAsset){this._state.error="Please select an asset.",this._render();return}const e=this._state.assets.find(t=>t.key===this._state.selectedAsset);if(!e){this._state.error="Selected asset not found.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{await this._ensureOverlay();const{COGLayer:t}=await import("@developmentseed/deck.gl-geotiff");this._patchCOGLayer(t);const i=`stac-${this._state.stacItem?.id||"layer"}-${e.key}-${this._layerCounter++}`,n={id:i,geotiff:e.href,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:this._state.rescaleMin,_rescaleMax:this._state.rescaleMax,_colormap:this._state.colormap},r=this._state.layerName?.trim();r&&(n._layerName=r);const s=await this._buildGeoKeysParser();s&&(n.geoKeysParser=s),this._cogLayerPropsMap.set(i,n);const a=new t(n);if(this._cogLayers.set(i,a),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[l,h,d,p]=this._state.stacItem.bbox;this._map.fitBounds([[l,h],[d,p]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.loading=!1,this._state.status=`Added layer: ${e.title||e.key}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:i,assetKey:e.key,url:e.href,layerName:r||void 0})}catch(t){this._state.loading=!1,this._state.error=`Failed to add layer: ${t instanceof Error?t.message:String(t)}`,this._render(),this._emit("error",{error:this._state.error})}}_updateOpacity(){if(!this._deckOverlay)return;for(const[,t]of this._cogLayerPropsMap)t.opacity=this._state.layerOpacity;const e=Array.from(this._cogLayers.entries()).map(([t])=>{const i=this._cogLayerPropsMap.get(t);return this._cogLayers.get(t).clone(i)});this._deckOverlay.setProps({layers:e})}_updateRescaleAndColormap(){if(!this._deckOverlay||this._cogLayers.size===0)return;for(const[,t]of this._cogLayerPropsMap)t._isRgb||(t._rescaleMin=this._state.rescaleMin,t._rescaleMax=this._state.rescaleMax,t._colormap=this._state.colormap);const e=Array.from(this._cogLayers.entries()).map(([t])=>{const i=this._cogLayerPropsMap.get(t);return this._cogLayers.get(t).clone(i)});this._deckOverlay.setProps({layers:e})}_removeLayer(e){this._map&&(this._cogLayers.delete(e),this._cogLayerPropsMap.delete(e),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.hasLayer=this._cogLayers.size>0,this._state.layerCount=this._cogLayers.size,this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e}))}_removeAllLayers(){for(const[e]of this._cogLayers)this._removeLayer(e)}_patchCOGLayer(e){if(e.__stacPatched)return;e.__stacPatched=!0;const t=e.prototype._renderSubLayers;e.prototype._renderSubLayers=function(...n){const r=t.apply(this,n),s=this.props.opacity;return s==null?r:fj(r,Math.max(0,Math.min(1,s)))};const i=e.prototype._parseGeoTIFF;e.prototype._parseGeoTIFF=async function(){const{parseCOGTileMatrixSet:n,texture:r}=await import("@developmentseed/deck.gl-geotiff");if(typeof n!="function"||typeof r?.inferTextureFormat!="function")return i.call(this);const{fromUrl:s}=await Promise.resolve().then(()=>require("./geotiff-CNfLW-N0.cjs")),{CreateTexture:a,FilterNoDataVal:l,Colormap:h}=await import("@developmentseed/deck.gl-raster/gpu-modules"),d=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")),p=d.default||d,g=this.props.geotiff,v=typeof g=="string"?await s(g):g,y=this.props.geoKeysParser;let E;try{E=await n(v,y)}catch{E=await n(v,void 0)}const S=await v.getImage(),R=await v.getImageCount(),I=[];for(let ce=0;ce<R;ce++)I.push(await v.getImage(ce));const k=y?await y(S.getGeoKeys()):null;let D=null,F=null;if(k&&typeof p=="function"){const ce=p(k.def,"EPSG:4326");if(D=(de,pe)=>ce.forward([de,pe],!1),F=(de,pe)=>ce.inverse([de,pe],!1),this.props.onGeoTIFFLoad){const de=S.getBoundingBox(),pe=[ce.forward([de[0],de[1]]),ce.forward([de[2],de[1]]),ce.forward([de[2],de[3]]),ce.forward([de[0],de[3]])],Ie=pe.map(Se=>Se[0]),we=pe.map(Se=>Se[1]),Ee={west:Math.min(...Ie),south:Math.min(...we),east:Math.max(...Ie),north:Math.max(...we)};this.props.onGeoTIFFLoad(v,{projection:k,geographicBounds:Ee})}}const{BitsPerSample:Z,SampleFormat:Y,SamplesPerPixel:Q,GDAL_NODATA:V}=S.getFileDirectory();let U=null;if(V){const ce=V[V.length-1]==="\0"?V.slice(0,-1):V;ce.length>0&&(U=parseFloat(ce))}const H=this,W=H.props._rescaleMin??0,ne=H.props._rescaleMax??1e4,te=async(ce,de)=>{const{device:pe}=de,Ie=await ce.readRasters({...de,interleave:!0}),we=typeof Z=="object"&&Z?.[0]!==void 0?Z[0]:Z,Ee=Ie.width*Ie.height;if(Q===1&&we===16){const Ve=new Uint8ClampedArray(Ee*4),ze=ne-W,it=H.props._colormap;let Le=null;it&&it!=="none"&&(Le=jl(it));for(let nt=0;nt<Ee;nt++){const lt=Ie[nt];if(lt===0||lt===U)Ve[nt*4]=0,Ve[nt*4+1]=0,Ve[nt*4+2]=0,Ve[nt*4+3]=0;else{const Ae=Math.max(0,Math.min(1,(lt-W)/ze));if(Le){const vt=mle(Le,Ae);Ve[nt*4]=vt[0],Ve[nt*4+1]=vt[1],Ve[nt*4+2]=vt[2],Ve[nt*4+3]=255}else{const vt=Math.round(Ae*255);Ve[nt*4]=vt,Ve[nt*4+1]=vt,Ve[nt*4+2]=vt,Ve[nt*4+3]=255}}}return{texture:pe.createTexture({data:Ve,format:"rgba8unorm",width:Ie.width,height:Ie.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:Ie.height,width:Ie.width,_preRescaled:!0,_colormapApplied:!!Le}}if(Q===3){const Ve=new Uint8ClampedArray(Ee*4);for(let ze=0;ze<Ee;ze++){const it=Ie[ze*3],Le=Ie[ze*3+1],nt=Ie[ze*3+2];it===0&&Le===0&&nt===0?(Ve[ze*4]=0,Ve[ze*4+1]=0,Ve[ze*4+2]=0,Ve[ze*4+3]=0):(Ve[ze*4]=it,Ve[ze*4+1]=Le,Ve[ze*4+2]=nt,Ve[ze*4+3]=255)}return{texture:pe.createTexture({data:Ve,format:"rgba8unorm",width:Ie.width,height:Ie.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:Ie.height,width:Ie.width,_preRescaled:!0}}const Se=r.inferTextureFormat(Q,Z,Y);return{texture:pe.createTexture({data:Ie,format:Se,width:Ie.width,height:Ie.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:Ie.height,width:Ie.width}},oe=this;let X=null,ee=null;const ae=ce=>{const de=[{module:a,props:{textureName:ce.texture}}];if(!ce._preRescaled){U!==null&&de.push({module:l,props:{value:U}});const Ie=oe.props._rescaleMin??0,we=oe.props._rescaleMax??255;de.push({module:fle,props:{minVal:Ie,maxVal:we,isSingleBand:Q===1?1:0}})}const pe=oe.props._colormap;if(pe&&pe!=="none"&&!ce._colormapApplied){if(pe!==X){const Ie=ple(jl(pe));ee=oe.context.device.createTexture({data:Ie.data,format:"rgba8unorm",width:Ie.width,height:Ie.height,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}}),X=pe}de.push({module:h,props:{colormapTexture:ee}})}return{renderPipeline:de}};oe.setState({metadata:E,forwardReproject:D,inverseReproject:F,images:I,defaultGetTileData:te,defaultRenderTile:ae})}}async _registerCommonProjections(e){e.defs("EPSG:3978","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +type=crs"),e.defs("EPSG:3979","+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=-0.991,1.9072,0.5129,-1.25033e-07,-4.6785e-08,-5.6529e-08,0 +units=m +no_defs +type=crs")}async _buildGeoKeysParser(){try{const e=await Promise.resolve().then(()=>require("./main-dist-DOx_Axbx.cjs")),t=e.default||e;if(!t||typeof t.toProj4!="function")return console.warn("geotiff-geokeys-to-proj4 not available or invalid"),null;const i=await Promise.resolve().then(()=>require("./lib-B4jvG7hB.cjs")),n=i.default||i;return typeof n=="function"&&await this._registerCommonProjections(n),async r=>{try{const s=t.toProj4(r);if(s&&s.proj4){let a=s.proj4;a=a.replace(/\+axis=\w+\s*/g,"");let l={};if(typeof n=="function")try{n.defs("custom",a),l=n.defs("custom")||{}}catch(h){console.error("STAC proj4 parsing error:",h)}return{def:a,parsed:l,coordinatesUnits:s.coordinatesUnits||"metre"}}}catch(s){console.error("STAC geoKeysParser error:",s)}return null}}catch(e){return console.error("STAC _buildGeoKeysParser error:",e),null}}},vle=[{name:"Element84 Earth Search",url:"https://earth-search.aws.element84.com/v1"},{name:"Microsoft Planetary Computer",url:"https://planetarycomputer.microsoft.com/api/stac/v1"}],yle=["viridis","plasma","inferno","magma","cividis","coolwarm","bwr","seismic","RdBu","RdYlBu","RdYlGn","spectral","jet","rainbow","turbo","terrain","ocean","hot","cool","gray","bone"],ble={position:"top-right",className:"",visible:!0,collapsed:!0,panelWidth:360,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#1a1a1a",catalogs:vle,maxItems:20,defaultRescaleMin:0,defaultRescaleMax:1e4,defaultColormap:"viridis",defaultRgbMode:!0,showFootprints:!0,minzoom:0,maxzoom:24},xle=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
229
229
|
<circle cx="11" cy="11" r="8"/>
|
|
230
230
|
<path d="m21 21-4.3-4.3"/>
|
|
231
231
|
<path d="M11 8v6"/>
|
|
@@ -238,7 +238,7 @@ var Wae=Object.create;var A9=Object.defineProperty;var Xae=Object.getOwnProperty
|
|
|
238
238
|
{
|
|
239
239
|
"type": "FeatureCollection",
|
|
240
240
|
"features": [...]
|
|
241
|
-
}`,X.value=this._state.geojsonText,X.rows=6,X.addEventListener("input",()=>{this._state.geojsonText=X.value}),oe.appendChild(X);const ee=document.createElement("div");ee.className="maplibre-gl-add-vector-format-hint",ee.textContent="Paste a valid GeoJSON FeatureCollection, Feature, or Geometry",oe.appendChild(ee),e.appendChild(oe)}const h=this._createFormGroup("Fill Color","fill-color"),d=document.createElement("div");d.className="maplibre-gl-add-vector-color-row";const p=document.createElement("input");p.type="color",p.id="add-vector-fill-color",p.className="maplibre-gl-add-vector-color-input",p.value=this._state.fillColor,p.addEventListener("input",()=>{this._state.fillColor=p.value}),d.appendChild(p);const g=document.createElement("input");g.type="text",g.className="maplibre-gl-add-vector-input",g.style.color="#000",g.style.flex="1",g.value=this._state.fillColor,g.addEventListener("input",()=>{this._state.fillColor=g.value,p.value=g.value}),d.appendChild(g),h.appendChild(d),e.appendChild(h);const v=this._createFormGroup("Stroke Color","stroke-color"),y=document.createElement("div");y.className="maplibre-gl-add-vector-color-row";const E=document.createElement("input");E.type="color",E.id="add-vector-stroke-color",E.className="maplibre-gl-add-vector-color-input",E.value=this._state.strokeColor,E.addEventListener("input",()=>{this._state.strokeColor=E.value}),y.appendChild(E);const S=document.createElement("input");S.type="text",S.className="maplibre-gl-add-vector-input",S.style.color="#000",S.style.flex="1",S.value=this._state.strokeColor,S.addEventListener("input",()=>{this._state.strokeColor=S.value,E.value=S.value}),y.appendChild(S),v.appendChild(y),e.appendChild(v);const R=this._createFormGroup("Opacity","opacity"),I=document.createElement("div");I.className="maplibre-gl-add-vector-slider-row";const k=document.createElement("input");k.type="range",k.id="add-vector-opacity",k.className="maplibre-gl-add-vector-slider",k.min="0",k.max="100",k.value=String(Math.round(this._state.layerOpacity*100));const D=document.createElement("span");D.className="maplibre-gl-add-vector-slider-value",D.textContent=`${Math.round(this._state.layerOpacity*100)}%`,k.addEventListener("input",()=>{const oe=Number(k.value);this._state.layerOpacity=oe/100,D.textContent=`${oe}%`;for(const[,X]of this._vectorLayers){for(const ee of X.layerIds)this._setLayerOpacityDirect(ee,this._state.layerOpacity);X.opacity=this._state.layerOpacity}}),I.appendChild(k),I.appendChild(D),R.appendChild(I),e.appendChild(R);const F=document.createElement("div");F.className="maplibre-gl-add-vector-form-group maplibre-gl-add-vector-checkbox-group";const Z=document.createElement("label");Z.className="maplibre-gl-add-vector-checkbox-label";const Y=document.createElement("input");Y.type="checkbox",Y.id="add-vector-pickable",Y.className="maplibre-gl-add-vector-checkbox",Y.checked=this._state.pickable,Y.style.marginRight="6px",Y.addEventListener("change",()=>{this._state.pickable=Y.checked}),Z.appendChild(Y);const Q=document.createElement("span");Q.textContent="Pickable (click to show feature info)",Z.appendChild(Q),F.appendChild(Z),e.appendChild(F);const V=this._createFormGroup("Layer Name","layer-name"),U=document.createElement("input");U.type="text",U.id="add-vector-layer-name",U.className="maplibre-gl-add-vector-input",U.style.color="#000",U.placeholder="Optional custom layer name",U.value=this._state.layerName,U.addEventListener("input",()=>{this._state.layerName=U.value}),V.appendChild(U),e.appendChild(V);const H=this._createFormGroup("Before Layer ID","before-id"),W=document.createElement("input");W.type="text",W.id="add-vector-before-id",W.className="maplibre-gl-add-vector-input",W.style.color="#000",W.placeholder="Optional layer ID to insert before",W.value=this._state.beforeId,W.addEventListener("input",()=>{this._state.beforeId=W.value}),H.appendChild(W),e.appendChild(H);const ne=document.createElement("div");ne.className="maplibre-gl-add-vector-buttons";const te=document.createElement("button");if(te.className="maplibre-gl-add-vector-btn maplibre-gl-add-vector-btn--primary",te.textContent="Add Layer",te.disabled=this._state.loading,te.addEventListener("click",()=>this._addLayer()),ne.appendChild(te),e.appendChild(ne),this._state.loading?this._appendStatus("Loading vector data...","info"):this._state.error?this._appendStatus(this._state.error,"error"):this._state.status&&this._appendStatus(this._state.status,"success"),this._vectorLayers.size>0){const oe=document.createElement("div");oe.className="maplibre-gl-add-vector-list";const X=document.createElement("div");X.className="maplibre-gl-add-vector-list-header",X.textContent=`Layers (${this._vectorLayers.size})`,oe.appendChild(X);for(const[ee,ae]of this._vectorLayers){const ce=document.createElement("div");ce.className="maplibre-gl-add-vector-list-item";const de=document.createElement("span");de.className="maplibre-gl-add-vector-list-label";let pe;try{pe=new URL(ae.url).pathname.split("/").pop()||ae.url}catch{pe=ae.url}de.textContent=pe,de.title=ae.url;const Ie=document.createElement("span");if(Ie.className=`maplibre-gl-add-vector-badge ${Ele(ae.format)}`,Ie.textContent=ae.format==="auto"?"geojson":ae.format,de.appendChild(Ie),ae.viewportLoading){const Ee=document.createElement("span");Ee.className="maplibre-gl-add-vector-badge maplibre-gl-add-vector-badge--viewport",Ee.textContent="viewport",Ee.title=`Min zoom: ${ae.viewportMinZoom??this._state.viewportMinZoom}`,de.appendChild(Ee)}ce.appendChild(de);const we=document.createElement("button");we.className="maplibre-gl-add-vector-list-remove",we.innerHTML="×",we.title="Remove layer",we.addEventListener("click",()=>{this._removeLayer(ee),this._render()}),ce.appendChild(we),oe.appendChild(ce)}e.appendChild(oe)}this._container.appendChild(e),this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-add-vector-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`add-vector-${t}`,i.appendChild(n),i}_appendStatus(e,t){if(!this._panel)return;const i=document.createElement("div");i.className=`maplibre-gl-add-vector-status maplibre-gl-add-vector-status--${t}`,i.textContent=e,this._panel.appendChild(i)}async _addLayer(){if(!this._map){this._state.error="Map not initialized.",this._render();return}if(this._state.inputMode==="url"&&!this._state.url){this._state.error="Please enter a vector URL.",this._render();return}if(this._state.inputMode==="text"&&!this._state.geojsonText.trim()){this._state.error="Please paste GeoJSON content.",this._render();return}const e=this._map;this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{let t,i="geojson",n="";if(this._state.inputMode==="text")try{const E=JSON.parse(this._state.geojsonText);t=this._normalizeGeoJSON(E),n="inline-geojson"}catch(E){throw new Error(`Invalid GeoJSON: ${E instanceof Error?E.message:"Failed to parse JSON"}`)}else if(n=this._state.url,i=this._state.format,i==="auto"&&(i=WF(this._state.url)),i==="geojson"){let E;try{E=await fetch(this._state.url)}catch{throw new Error("CORS error: The server doesn't allow cross-origin requests. Try using a CORS-enabled URL.")}if(!E.ok)throw new Error(`Failed to fetch: ${E.status} ${E.statusText}`);const S=await E.json();t=this._normalizeGeoJSON(S)}else if(i==="geoparquet")this._state.viewportLoading?t={type:"FeatureCollection",features:[]}:t=await this._loadGeoParquet(this._state.url);else if(i==="flatgeobuf")t=await this._loadFlatGeobuf(this._state.url);else throw new Error(`Unsupported format: ${i}`);let r=this._state.layerName?.trim();if(!r&&this._state.inputMode==="url")try{r=(new URL(this._state.url).pathname.split("/").pop()||"").replace(/\.[^.]+$/,"")}catch{}r||(r=Qu("addvec"));const s=`${r}-source`,a=new Set;for(const E of t.features)E.geometry&&a.add(E.geometry.type);e.addSource(s,{type:"geojson",data:t,generateId:!0});const l=[],h=this._state.beforeId?.trim(),d=this._options.beforeId,p=h||d,g=p&&e.getLayer(p)?p:void 0,v=i==="geoparquet"&&this._state.viewportLoading;if(v||a.has("Polygon")||a.has("MultiPolygon")){const E=`${r}-fill`;e.addLayer({id:E,type:"fill",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-color":this._state.fillColor,"fill-opacity":this._state.layerOpacity}},g),l.push(E);const S=`${r}-outline`;e.addLayer({id:S,type:"line",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"line-color":this._state.strokeColor,"line-width":2,"line-opacity":this._state.layerOpacity}},g),l.push(S)}if(v||a.has("LineString")||a.has("MultiLineString")){const E=`${r}-line`;e.addLayer({id:E,type:"line",source:s,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"MultiLineString"]],paint:{"line-color":this._state.strokeColor,"line-width":2,"line-opacity":this._state.layerOpacity}},g),l.push(E)}if(v||a.has("Point")||a.has("MultiPoint")){const E=`${r}-point`;e.addLayer({id:E,type:"circle",source:s,filter:["any",["==",["geometry-type"],"Point"],["==",["geometry-type"],"MultiPoint"]],paint:{"circle-radius":6,"circle-color":this._state.circleColor,"circle-stroke-color":this._state.strokeColor,"circle-stroke-width":2,"circle-opacity":this._state.layerOpacity}},g),l.push(E)}if(this._state.pickable)for(const E of l)e.on("mouseenter",E,()=>{e.getCanvas().style.cursor="pointer"}),e.on("mouseleave",E,()=>{e.getCanvas().style.cursor=""}),e.on("click",E,S=>{if(!S.features||S.features.length===0)return;const R=S.features[0].properties||{},I=Object.entries(R);if(I.length===0)return;let k='<div class="maplibre-gl-add-vector-popup">';k+='<table class="maplibre-gl-add-vector-popup-table">';for(const[D,F]of I)k+=`<tr><td><strong>${D}</strong></td><td>${F}</td></tr>`;k+="</table></div>",this._activePopup&&this._activePopup.remove(),this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"300px"}).setLngLat(S.lngLat).setHTML(k).addTo(e)});const y={id:r,url:n,format:i,sourceId:s,layerIds:l,featureCount:t.features.length,geometryTypes:Array.from(a),opacity:this._state.layerOpacity,fillColor:this._state.fillColor,strokeColor:this._state.strokeColor,pickable:this._state.pickable,viewportLoading:i==="geoparquet"&&this._state.viewportLoading,viewportMinZoom:i==="geoparquet"&&this._state.viewportLoading?this._state.viewportMinZoom:void 0};if(this._vectorLayers.set(r,y),this._state.hasLayer=this._vectorLayers.size>0,this._state.layerCount=this._vectorLayers.size,this._state.layers=Array.from(this._vectorLayers.values()),this._state.loading=!1,i==="geoparquet"&&this._state.viewportLoading)try{await this._setupViewportLoading(r,n,s);const E=this._vectorLayers.get(r)?.featureCount??0;this._state.status=`Viewport loading enabled (${E} features in view, minzoom: ${this._state.viewportMinZoom}).`,this._state.layers=Array.from(this._vectorLayers.values())}catch(E){console.warn("Viewport loading setup failed, falling back to full download:",E),y.viewportLoading=!1,y.viewportMinZoom=void 0;const S=await this._loadGeoParquet(n),R=this._map.getSource(s);R&&R.type==="geojson"&&R.setData(S),y.featureCount=S.features.length,this._state.layers=Array.from(this._vectorLayers.values()),this._state.status=`Added ${S.features.length} features (${i}, viewport loading failed).`}else{const E=this._state.inputMode==="text"?"inline GeoJSON":i;this._state.status=`Added ${t.features.length} features (${E}).`}this._options.fitBounds&&t.features.length>0&&!y.viewportLoading&&this._fitToData(t),this._render(),this._emit("layeradd",{url:n,layerId:r})}catch(t){this._state.loading=!1,this._state.error=`Failed to load: ${t instanceof Error?t.message:String(t)}`,this._render(),this._emit("error",{error:this._state.error})}}_normalizeGeoJSON(e){return e.type==="FeatureCollection"?e:e.type==="Feature"?{type:"FeatureCollection",features:[e]}:{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]}}async _fetchWithCorsProxy(e){try{const i=await fetch(e,{mode:"cors"});if(i.ok)return i}catch{}if(this._options.corsProxy){const i=this._options.corsProxy+encodeURIComponent(e);try{const n=await fetch(i,{mode:"cors"});if(n.ok)return n}catch{}}const t="https://corsproxy.io/?";try{const i=await fetch(t+encodeURIComponent(e),{mode:"cors"});if(i.ok)return i}catch{}throw new Error("CORS error: Unable to fetch the file. The server doesn't allow cross-origin requests.")}async _loadGeoParquet(e){const{getDuckDBConverter:t}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(a=>a.DuckDBConverter_exports),i=t(),n=await this._fetchWithCorsProxy(e);let r;try{r=await n.arrayBuffer()}catch(a){throw new Error(`Failed to read GeoParquet response: ${a instanceof Error?a.message:String(a)}`)}let s;try{s=await i.convert(r,"data.parquet")}catch(a){throw new Error(`Failed to convert GeoParquet: ${a instanceof Error?a.message:String(a)}`)}if(s.geojson)return s.geojson;throw new Error("Failed to convert GeoParquet: No GeoJSON output")}async _loadFlatGeobuf(e){const t=await Promise.resolve().then(()=>require("./geojson-CxMdRvJX.cjs")),i=await fetch(e);if(!i.ok)throw new Error(`Failed to fetch: ${i.status} ${i.statusText}`);if(!i.body)throw new Error("Response body is null - streaming not supported");const n=[];for await(const r of t.deserialize(i.body))n.push(r);return{type:"FeatureCollection",features:n}}_fitToData(e){if(!this._map)return;let t=1/0,i=1/0,n=-1/0,r=-1/0;const s=l=>{t=Math.min(t,l[0]),n=Math.max(n,l[0]),i=Math.min(i,l[1]),r=Math.max(r,l[1])},a=l=>{for(const h of l)typeof h[0]=="number"?s(h):a(h)};for(const l of e.features){if(!l.geometry)continue;const h=l.geometry;h.type==="Point"?s(h.coordinates):(h.type==="MultiPoint"||h.type==="LineString"||h.type==="MultiLineString"||h.type==="Polygon"||h.type==="MultiPolygon")&&a(h.coordinates)}t!==1/0&&this._map.fitBounds([[t,i],[n,r]],{padding:this._options.fitBoundsPadding})}async _setupViewportLoading(e,t,i){if(!this._map)return;const{getDuckDBConverter:n}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(a=>a.DuckDBConverter_exports),r=n(),s=`${e}.parquet`;try{await r.registerRemoteParquet(t,s);const a=await r.getParquetSchema(s);if(!a.geometryColumn)throw new Error("No geometry column found in parquet file");const l=this._vectorLayers.get(e);l&&(l.viewportLoading=!0,l.duckdbFileName=s,l.geometryColumn=a.geometryColumn??void 0,l.geometryColumnType=a.geometryColumnType??void 0,l.propertyColumns=a.propertyColumns),this._viewportLoadingLayers.add(e);const h=FY(()=>{this._updateViewportData(e)},this._options.geoparquetDebounceMs),d=this._viewportHandler;this._viewportHandler=()=>{d&&d(),h()},d&&this._map.off("moveend",d),this._map.on("moveend",this._viewportHandler),await this._updateViewportData(e)}catch(a){throw console.error("Failed to setup viewport loading:",a),await r.unregisterFile(s),a}}async _updateViewportData(e){if(!this._map)return;const t=this._vectorLayers.get(e);if(!t||!t.viewportLoading||!t.duckdbFileName||!t.geometryColumn)return;const i=t.viewportMinZoom??this._state.viewportMinZoom??8;if(this._map.getZoom()<i){for(const n of t.layerIds)this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility","none");return}for(const n of t.layerIds)this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility","visible");this._viewportLoadingState.set(e,!0);try{const{getDuckDBConverter:n}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(d=>d.DuckDBConverter_exports),r=n(),s=this._map.getBounds(),a=[s.getWest(),s.getSouth(),s.getEast(),s.getNorth()],l=await r.queryByBounds(t.duckdbFileName,a,t.geometryColumn,t.propertyColumns||[],t.geometryColumnType),h=this._map.getSource(t.sourceId);h&&h.type==="geojson"&&h.setData(l),t.featureCount=l.features.length,this._state.layers=Array.from(this._vectorLayers.values())}catch(n){console.error("Failed to update viewport data:",n)}finally{this._viewportLoadingState.set(e,!1)}}async _cleanupViewportLoading(){if(this._map&&this._viewportHandler&&(this._map.off("moveend",this._viewportHandler),this._viewportHandler=void 0),this._viewportLoadingLayers.size>0)try{const{getDuckDBConverter:e}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(i=>i.DuckDBConverter_exports),t=e();for(const i of this._viewportLoadingLayers){const n=this._vectorLayers.get(i);n?.duckdbFileName&&await t.unregisterFile(n.duckdbFileName)}}catch{}this._viewportLoadingLayers.clear(),this._viewportLoadingState.clear()}async _cleanupLayerViewportLoading(e){const t=this._vectorLayers.get(e);if(!(!t?.viewportLoading||!t.duckdbFileName)){try{const{getDuckDBConverter:i}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(n=>n.DuckDBConverter_exports);await i().unregisterFile(t.duckdbFileName)}catch{}this._viewportLoadingLayers.delete(e),this._viewportLoadingState.delete(e),this._viewportLoadingLayers.size===0&&this._viewportHandler&&(this._map&&this._map.off("moveend",this._viewportHandler),this._viewportHandler=void 0)}}_removeLayer(e){if(this._map)if(e){const t=this._vectorLayers.get(e);if(t){t.viewportLoading&&this._cleanupLayerViewportLoading(e);for(const i of t.layerIds)try{this._map.getLayer(i)&&this._map.removeLayer(i)}catch{}try{this._map.getSource(t.sourceId)&&this._map.removeSource(t.sourceId)}catch{}}this._vectorLayers.delete(e),this._state.hasLayer=this._vectorLayers.size>0,this._state.layerCount=this._vectorLayers.size,this._state.layers=Array.from(this._vectorLayers.values()),this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e})}else this._removeAllLayers()}_removeAllLayers(){if(this._map){for(const[,e]of this._vectorLayers){for(const t of e.layerIds)try{this._map.getLayer(t)&&this._map.removeLayer(t)}catch{}try{this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)}catch{}}this._vectorLayers.clear(),this._state.hasLayer=!1,this._state.layerCount=0,this._state.layers=[],this._state.status=null,this._state.error=null,this._emit("layerremove")}}},Sle=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
241
|
+
}`,X.value=this._state.geojsonText,X.rows=6,X.addEventListener("input",()=>{this._state.geojsonText=X.value}),oe.appendChild(X);const ee=document.createElement("div");ee.className="maplibre-gl-add-vector-format-hint",ee.textContent="Paste a valid GeoJSON FeatureCollection, Feature, or Geometry",oe.appendChild(ee),e.appendChild(oe)}const h=this._createFormGroup("Fill Color","fill-color"),d=document.createElement("div");d.className="maplibre-gl-add-vector-color-row";const p=document.createElement("input");p.type="color",p.id="add-vector-fill-color",p.className="maplibre-gl-add-vector-color-input",p.value=this._state.fillColor,p.addEventListener("input",()=>{this._state.fillColor=p.value}),d.appendChild(p);const g=document.createElement("input");g.type="text",g.className="maplibre-gl-add-vector-input",g.style.color="#000",g.style.flex="1",g.value=this._state.fillColor,g.addEventListener("input",()=>{this._state.fillColor=g.value,p.value=g.value}),d.appendChild(g),h.appendChild(d),e.appendChild(h);const v=this._createFormGroup("Stroke Color","stroke-color"),y=document.createElement("div");y.className="maplibre-gl-add-vector-color-row";const E=document.createElement("input");E.type="color",E.id="add-vector-stroke-color",E.className="maplibre-gl-add-vector-color-input",E.value=this._state.strokeColor,E.addEventListener("input",()=>{this._state.strokeColor=E.value}),y.appendChild(E);const S=document.createElement("input");S.type="text",S.className="maplibre-gl-add-vector-input",S.style.color="#000",S.style.flex="1",S.value=this._state.strokeColor,S.addEventListener("input",()=>{this._state.strokeColor=S.value,E.value=S.value}),y.appendChild(S),v.appendChild(y),e.appendChild(v);const R=this._createFormGroup("Opacity","opacity"),I=document.createElement("div");I.className="maplibre-gl-add-vector-slider-row";const k=document.createElement("input");k.type="range",k.id="add-vector-opacity",k.className="maplibre-gl-add-vector-slider",k.min="0",k.max="100",k.value=String(Math.round(this._state.layerOpacity*100));const D=document.createElement("span");D.className="maplibre-gl-add-vector-slider-value",D.textContent=`${Math.round(this._state.layerOpacity*100)}%`,k.addEventListener("input",()=>{const oe=Number(k.value);this._state.layerOpacity=oe/100,D.textContent=`${oe}%`;for(const[,X]of this._vectorLayers){for(const ee of X.layerIds)this._setLayerOpacityDirect(ee,this._state.layerOpacity);X.opacity=this._state.layerOpacity}}),I.appendChild(k),I.appendChild(D),R.appendChild(I),e.appendChild(R);const F=document.createElement("div");F.className="maplibre-gl-add-vector-form-group maplibre-gl-add-vector-checkbox-group";const Z=document.createElement("label");Z.className="maplibre-gl-add-vector-checkbox-label";const Y=document.createElement("input");Y.type="checkbox",Y.id="add-vector-pickable",Y.className="maplibre-gl-add-vector-checkbox",Y.checked=this._state.pickable,Y.style.marginRight="6px",Y.addEventListener("change",()=>{this._state.pickable=Y.checked}),Z.appendChild(Y);const Q=document.createElement("span");Q.textContent="Pickable (click to show feature info)",Z.appendChild(Q),F.appendChild(Z),e.appendChild(F);const V=this._createFormGroup("Layer Name","layer-name"),U=document.createElement("input");U.type="text",U.id="add-vector-layer-name",U.className="maplibre-gl-add-vector-input",U.style.color="#000",U.placeholder="Optional custom layer name",U.value=this._state.layerName,U.addEventListener("input",()=>{this._state.layerName=U.value}),V.appendChild(U),e.appendChild(V);const H=this._createFormGroup("Before Layer ID","before-id"),W=document.createElement("input");W.type="text",W.id="add-vector-before-id",W.className="maplibre-gl-add-vector-input",W.style.color="#000",W.placeholder="Optional layer ID to insert before",W.value=this._state.beforeId,W.addEventListener("input",()=>{this._state.beforeId=W.value}),H.appendChild(W),e.appendChild(H);const ne=document.createElement("div");ne.className="maplibre-gl-add-vector-buttons";const te=document.createElement("button");if(te.className="maplibre-gl-add-vector-btn maplibre-gl-add-vector-btn--primary",te.textContent="Add Layer",te.disabled=this._state.loading,te.addEventListener("click",()=>this._addLayer()),ne.appendChild(te),e.appendChild(ne),this._state.loading?this._appendStatus("Loading vector data...","info"):this._state.error?this._appendStatus(this._state.error,"error"):this._state.status&&this._appendStatus(this._state.status,"success"),this._vectorLayers.size>0){const oe=document.createElement("div");oe.className="maplibre-gl-add-vector-list";const X=document.createElement("div");X.className="maplibre-gl-add-vector-list-header",X.textContent=`Layers (${this._vectorLayers.size})`,oe.appendChild(X);for(const[ee,ae]of this._vectorLayers){const ce=document.createElement("div");ce.className="maplibre-gl-add-vector-list-item";const de=document.createElement("span");de.className="maplibre-gl-add-vector-list-label";let pe;try{pe=new URL(ae.url).pathname.split("/").pop()||ae.url}catch{pe=ae.url}de.textContent=pe,de.title=ae.url;const Ie=document.createElement("span");if(Ie.className=`maplibre-gl-add-vector-badge ${Ele(ae.format)}`,Ie.textContent=ae.format==="auto"?"geojson":ae.format,de.appendChild(Ie),ae.viewportLoading){const Ee=document.createElement("span");Ee.className="maplibre-gl-add-vector-badge maplibre-gl-add-vector-badge--viewport",Ee.textContent="viewport",Ee.title=`Min zoom: ${ae.viewportMinZoom??this._state.viewportMinZoom}`,de.appendChild(Ee)}ce.appendChild(de);const we=document.createElement("button");we.className="maplibre-gl-add-vector-list-remove",we.innerHTML="×",we.title="Remove layer",we.addEventListener("click",()=>{this._removeLayer(ee),this._render()}),ce.appendChild(we),oe.appendChild(ce)}e.appendChild(oe)}this._container.appendChild(e),this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-add-vector-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`add-vector-${t}`,i.appendChild(n),i}_appendStatus(e,t){if(!this._panel)return;const i=document.createElement("div");i.className=`maplibre-gl-add-vector-status maplibre-gl-add-vector-status--${t}`,i.textContent=e,this._panel.appendChild(i)}async _addLayer(){if(!this._map){this._state.error="Map not initialized.",this._render();return}if(this._state.inputMode==="url"&&!this._state.url){this._state.error="Please enter a vector URL.",this._render();return}if(this._state.inputMode==="text"&&!this._state.geojsonText.trim()){this._state.error="Please paste GeoJSON content.",this._render();return}const e=this._map;this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{let t,i="geojson",n="";if(this._state.inputMode==="text")try{const E=JSON.parse(this._state.geojsonText);t=this._normalizeGeoJSON(E),n="inline-geojson"}catch(E){throw new Error(`Invalid GeoJSON: ${E instanceof Error?E.message:"Failed to parse JSON"}`)}else if(n=this._state.url,i=this._state.format,i==="auto"&&(i=WF(this._state.url)),i==="geojson"){let E;try{E=await fetch(this._state.url)}catch{throw new Error("CORS error: The server doesn't allow cross-origin requests. Try using a CORS-enabled URL.")}if(!E.ok)throw new Error(`Failed to fetch: ${E.status} ${E.statusText}`);const S=await E.json();t=this._normalizeGeoJSON(S)}else if(i==="geoparquet")this._state.viewportLoading?t={type:"FeatureCollection",features:[]}:t=await this._loadGeoParquet(this._state.url);else if(i==="flatgeobuf")t=await this._loadFlatGeobuf(this._state.url);else throw new Error(`Unsupported format: ${i}`);let r=this._state.layerName?.trim();if(!r&&this._state.inputMode==="url")try{r=(new URL(this._state.url).pathname.split("/").pop()||"").replace(/\.[^.]+$/,"")}catch{}r||(r=Qu("addvec"));const s=`${r}-source`,a=new Set;for(const E of t.features)E.geometry&&a.add(E.geometry.type);e.addSource(s,{type:"geojson",data:t,generateId:!0});const l=[],h=this._state.beforeId?.trim(),d=this._options.beforeId,p=h||d,g=p&&e.getLayer(p)?p:void 0,v=i==="geoparquet"&&this._state.viewportLoading;if(v||a.has("Polygon")||a.has("MultiPolygon")){const E=`${r}-fill`;e.addLayer({id:E,type:"fill",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-color":this._state.fillColor,"fill-opacity":this._state.layerOpacity}},g),l.push(E);const S=`${r}-outline`;e.addLayer({id:S,type:"line",source:s,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"line-color":this._state.strokeColor,"line-width":2,"line-opacity":this._state.layerOpacity}},g),l.push(S)}if(v||a.has("LineString")||a.has("MultiLineString")){const E=`${r}-line`;e.addLayer({id:E,type:"line",source:s,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"MultiLineString"]],paint:{"line-color":this._state.strokeColor,"line-width":2,"line-opacity":this._state.layerOpacity}},g),l.push(E)}if(v||a.has("Point")||a.has("MultiPoint")){const E=`${r}-point`;e.addLayer({id:E,type:"circle",source:s,filter:["any",["==",["geometry-type"],"Point"],["==",["geometry-type"],"MultiPoint"]],paint:{"circle-radius":6,"circle-color":this._state.circleColor,"circle-stroke-color":this._state.strokeColor,"circle-stroke-width":2,"circle-opacity":this._state.layerOpacity}},g),l.push(E)}if(this._state.pickable)for(const E of l)e.on("mouseenter",E,()=>{e.getCanvas().style.cursor="pointer"}),e.on("mouseleave",E,()=>{e.getCanvas().style.cursor=""}),e.on("click",E,S=>{if(!S.features||S.features.length===0)return;const R=S.features[0].properties||{},I=Object.entries(R);if(I.length===0)return;let k='<div class="maplibre-gl-add-vector-popup">';k+='<table class="maplibre-gl-add-vector-popup-table">';for(const[D,F]of I)k+=`<tr><td><strong>${D}</strong></td><td>${F}</td></tr>`;k+="</table></div>",this._activePopup&&this._activePopup.remove(),this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"300px"}).setLngLat(S.lngLat).setHTML(k).addTo(e)});const y={id:r,url:n,format:i,sourceId:s,layerIds:l,featureCount:t.features.length,geometryTypes:Array.from(a),opacity:this._state.layerOpacity,fillColor:this._state.fillColor,strokeColor:this._state.strokeColor,pickable:this._state.pickable,viewportLoading:i==="geoparquet"&&this._state.viewportLoading,viewportMinZoom:i==="geoparquet"&&this._state.viewportLoading?this._state.viewportMinZoom:void 0};if(this._vectorLayers.set(r,y),this._state.hasLayer=this._vectorLayers.size>0,this._state.layerCount=this._vectorLayers.size,this._state.layers=Array.from(this._vectorLayers.values()),this._state.loading=!1,i==="geoparquet"&&this._state.viewportLoading)try{await this._setupViewportLoading(r,n,s);const E=this._vectorLayers.get(r)?.featureCount??0;this._state.status=`Viewport loading enabled (${E} features in view, minzoom: ${this._state.viewportMinZoom}).`,this._state.layers=Array.from(this._vectorLayers.values())}catch(E){console.warn("Viewport loading setup failed, falling back to full download:",E),y.viewportLoading=!1,y.viewportMinZoom=void 0;const S=await this._loadGeoParquet(n),R=this._map.getSource(s);R&&R.type==="geojson"&&R.setData(S),y.featureCount=S.features.length,this._state.layers=Array.from(this._vectorLayers.values()),this._state.status=`Added ${S.features.length} features (${i}, viewport loading failed).`}else{const E=this._state.inputMode==="text"?"inline GeoJSON":i;this._state.status=`Added ${t.features.length} features (${E}).`}this._options.fitBounds&&t.features.length>0&&!y.viewportLoading&&this._fitToData(t),this._render(),this._emit("layeradd",{url:n,layerId:r})}catch(t){this._state.loading=!1,this._state.error=`Failed to load: ${t instanceof Error?t.message:String(t)}`,this._render(),this._emit("error",{error:this._state.error})}}_normalizeGeoJSON(e){return e.type==="FeatureCollection"?e:e.type==="Feature"?{type:"FeatureCollection",features:[e]}:{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]}}async _fetchWithCorsProxy(e){try{const i=await fetch(e,{mode:"cors"});if(i.ok)return i}catch{}if(this._options.corsProxy){const i=this._options.corsProxy+encodeURIComponent(e);try{const n=await fetch(i,{mode:"cors"});if(n.ok)return n}catch{}}const t="https://corsproxy.io/?";try{const i=await fetch(t+encodeURIComponent(e),{mode:"cors"});if(i.ok)return i}catch{}throw new Error("CORS error: Unable to fetch the file. The server doesn't allow cross-origin requests.")}async _loadGeoParquet(e){const{getDuckDBConverter:t}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(a=>a.DuckDBConverter_exports),i=t(),n=await this._fetchWithCorsProxy(e);let r;try{r=await n.arrayBuffer()}catch(a){throw new Error(`Failed to read GeoParquet response: ${a instanceof Error?a.message:String(a)}`)}let s;try{s=await i.convert(r,"data.parquet")}catch(a){throw new Error(`Failed to convert GeoParquet: ${a instanceof Error?a.message:String(a)}`)}if(s.geojson)return s.geojson;throw new Error("Failed to convert GeoParquet: No GeoJSON output")}async _loadFlatGeobuf(e){const t=await Promise.resolve().then(()=>require("./geojson-CxMdRvJX.cjs")),i=await fetch(e);if(!i.ok)throw new Error(`Failed to fetch: ${i.status} ${i.statusText}`);if(!i.body)throw new Error("Response body is null - streaming not supported");const n=[];for await(const r of t.deserialize(i.body))n.push(r);return{type:"FeatureCollection",features:n}}_fitToData(e){if(!this._map)return;let t=1/0,i=1/0,n=-1/0,r=-1/0;const s=l=>{t=Math.min(t,l[0]),n=Math.max(n,l[0]),i=Math.min(i,l[1]),r=Math.max(r,l[1])},a=l=>{for(const h of l)typeof h[0]=="number"?s(h):a(h)};for(const l of e.features){if(!l.geometry)continue;const h=l.geometry;h.type==="Point"?s(h.coordinates):(h.type==="MultiPoint"||h.type==="LineString"||h.type==="MultiLineString"||h.type==="Polygon"||h.type==="MultiPolygon")&&a(h.coordinates)}t!==1/0&&this._map.fitBounds([[t,i],[n,r]],{padding:this._options.fitBoundsPadding})}async _setupViewportLoading(e,t,i){if(!this._map)return;const{getDuckDBConverter:n}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(a=>a.DuckDBConverter_exports),r=n(),s=`${e}.parquet`;try{await r.registerRemoteParquet(t,s);const a=await r.getParquetSchema(s);if(!a.geometryColumn)throw new Error("No geometry column found in parquet file");const l=this._vectorLayers.get(e);l&&(l.viewportLoading=!0,l.duckdbFileName=s,l.geometryColumn=a.geometryColumn??void 0,l.geometryColumnType=a.geometryColumnType??void 0,l.propertyColumns=a.propertyColumns),this._viewportLoadingLayers.add(e);const h=FY(()=>{this._updateViewportData(e)},this._options.geoparquetDebounceMs),d=this._viewportHandler;this._viewportHandler=()=>{d&&d(),h()},d&&this._map.off("moveend",d),this._map.on("moveend",this._viewportHandler),await this._updateViewportData(e)}catch(a){throw console.error("Failed to setup viewport loading:",a),await r.unregisterFile(s),a}}async _updateViewportData(e){if(!this._map)return;const t=this._vectorLayers.get(e);if(!t||!t.viewportLoading||!t.duckdbFileName||!t.geometryColumn)return;const i=t.viewportMinZoom??this._state.viewportMinZoom??8;if(this._map.getZoom()<i){for(const n of t.layerIds)this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility","none");return}for(const n of t.layerIds)this._map.getLayer(n)&&this._map.setLayoutProperty(n,"visibility","visible");this._viewportLoadingState.set(e,!0);try{const{getDuckDBConverter:n}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(d=>d.DuckDBConverter_exports),r=n(),s=this._map.getBounds(),a=[s.getWest(),s.getSouth(),s.getEast(),s.getNorth()],l=await r.queryByBounds(t.duckdbFileName,a,t.geometryColumn,t.propertyColumns||[],t.geometryColumnType),h=this._map.getSource(t.sourceId);h&&h.type==="geojson"&&h.setData(l),t.featureCount=l.features.length,this._state.layers=Array.from(this._vectorLayers.values())}catch(n){console.error("Failed to update viewport data:",n)}finally{this._viewportLoadingState.set(e,!1)}}async _cleanupViewportLoading(){if(this._map&&this._viewportHandler&&(this._map.off("moveend",this._viewportHandler),this._viewportHandler=void 0),this._viewportLoadingLayers.size>0)try{const{getDuckDBConverter:e}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(i=>i.DuckDBConverter_exports),t=e();for(const i of this._viewportLoadingLayers){const n=this._vectorLayers.get(i);n?.duckdbFileName&&await t.unregisterFile(n.duckdbFileName)}}catch{}this._viewportLoadingLayers.clear(),this._viewportLoadingState.clear()}async _cleanupLayerViewportLoading(e){const t=this._vectorLayers.get(e);if(!(!t?.viewportLoading||!t.duckdbFileName)){try{const{getDuckDBConverter:i}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(n=>n.DuckDBConverter_exports);await i().unregisterFile(t.duckdbFileName)}catch{}this._viewportLoadingLayers.delete(e),this._viewportLoadingState.delete(e),this._viewportLoadingLayers.size===0&&this._viewportHandler&&(this._map&&this._map.off("moveend",this._viewportHandler),this._viewportHandler=void 0)}}_removeLayer(e){if(this._map)if(e){const t=this._vectorLayers.get(e);if(t){t.viewportLoading&&this._cleanupLayerViewportLoading(e);for(const i of t.layerIds)try{this._map.getLayer(i)&&this._map.removeLayer(i)}catch{}try{this._map.getSource(t.sourceId)&&this._map.removeSource(t.sourceId)}catch{}}this._vectorLayers.delete(e),this._state.hasLayer=this._vectorLayers.size>0,this._state.layerCount=this._vectorLayers.size,this._state.layers=Array.from(this._vectorLayers.values()),this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e})}else this._removeAllLayers()}_removeAllLayers(){if(this._map){for(const[,e]of this._vectorLayers){for(const t of e.layerIds)try{this._map.getLayer(t)&&this._map.removeLayer(t)}catch{}try{this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)}catch{}}this._vectorLayers.clear(),this._state.hasLayer=!1,this._state.layerCount=0,this._state.layers=[],this._state.status=null,this._state.error=null,this._emit("layerremove")}}},Sle=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
242
242
|
<path d="M3 3h7v7H3z" fill="#4292c6" fill-opacity="0.7" stroke="#2171b5"/>
|
|
243
243
|
<path d="M10 3h7v7h-7z" fill="#9ecae1" fill-opacity="0.7" stroke="#6baed6"/>
|
|
244
244
|
<path d="M17 3h4v7h-4z" fill="#08519c" fill-opacity="0.7" stroke="#08306b"/>
|
|
@@ -248,7 +248,7 @@ var Wae=Object.create;var A9=Object.defineProperty;var Xae=Object.getOwnProperty
|
|
|
248
248
|
<path d="M3 17h7v4H3z" fill="#2171b5" fill-opacity="0.7" stroke="#08519c"/>
|
|
249
249
|
<path d="M10 17h7v4h-7z" fill="#08306b" fill-opacity="0.7" stroke="#08306b"/>
|
|
250
250
|
<path d="M17 17h4v4h-4z" fill="#4292c6" fill-opacity="0.7" stroke="#2171b5"/>
|
|
251
|
-
</svg>`,Mle=[{value:"quantile",label:"Quantile"},{value:"equal_interval",label:"Equal Interval"},{value:"natural_breaks",label:"Natural Breaks (Jenks)"},{value:"std_mean",label:"Standard Deviation"},{value:"head_tail",label:"Head/Tail Breaks"}],Ile={position:"top-right",className:"",visible:!0,collapsed:!0,beforeId:"",defaultUrl:"",defaultLayerName:"",loadDefaultUrl:!1,defaultFormat:"auto",defaultColumn:"",defaultColormap:"viridis",defaultScheme:"quantile",defaultK:5,defaultOpacity:.8,defaultOutlineColor:"#ffffff",defaultExtrude:!1,defaultScaleFactor:1,defaultPickable:!0,fitBounds:!0,fitBoundsPadding:50,panelWidth:320,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#333",minzoom:0,maxzoom:24};function Tle(e){const t=e.toLowerCase();return t.endsWith(".geojson")||t.endsWith(".json")?"geojson":t.endsWith(".parquet")||t.endsWith(".geoparquet")?"geoparquet":t.endsWith(".fgb")?"flatgeobuf":"geojson"}function Rle(e,t,i){const n=[...e].filter(d=>!isNaN(d)).sort((d,p)=>d-p),r=n.length;if(r===0)return{breaks:[0,1],bins:e.map(()=>0)};const s=n[0],a=n[r-1];let l;switch(t){case"equal_interval":{l=[s];const d=(a-s)/i;for(let p=1;p<i;p++)l.push(s+d*p);l.push(a);break}case"quantile":l=[s];for(let d=1;d<i;d++){const p=Math.floor(d*r/i);l.push(n[Math.min(p,r-1)])}l.push(a),l=[...new Set(l)].sort((d,p)=>d-p);break;case"natural_breaks":l=Ble(n,i);break;case"std_mean":{const d=n.reduce((y,E)=>y+E,0)/r,p=n.reduce((y,E)=>y+(E-d)**2,0)/r,g=Math.sqrt(p);l=[s];const v=[-2,-1,0,1,2].map(y=>d+y*g);for(const y of v)y>s&&y<a&&l.push(y);l.push(a),l=[...new Set(l)].sort((y,E)=>y-E);break}case"head_tail":{l=[s];let d=n;for(;l.length<i&&d.length>1;){const p=d.reduce((g,v)=>g+v,0)/d.length;if(p<=l[l.length-1])break;l.push(p),d=d.filter(g=>g>p)}l.push(a),l=[...new Set(l)].sort((p,g)=>p-g);break}default:{l=[s];const d=(a-s)/i;for(let p=1;p<i;p++)l.push(s+d*p);l.push(a)}}const h=e.map(d=>{if(isNaN(d))return 0;for(let p=0;p<l.length-1;p++)if(d<=l[p+1])return Math.min(p,l.length-2);return l.length-2});return{breaks:l,bins:h}}function Ble(e,t){const i=e.length;if(i<=t)return[...new Set(e)].sort((h,d)=>h-d);const n=Array.from({length:i+1},()=>new Array(t+1).fill(1/0)),r=Array.from({length:i+1},()=>new Array(t+1).fill(0));for(let h=1;h<=t;h++)n[1][h]=0,r[1][h]=1;for(let h=2;h<=i;h++){let d=0,p=0;for(let g=1;g<=h;g++){const v=e[h-1];p+=v,d+=v*v;const y=d-p*p/g,E=h-g+1;if(E!==1)for(let S=2;S<=t;S++)n[h][S]>=y+n[E-1][S-1]&&(r[h][S]=E,n[h][S]=y+n[E-1][S-1])}n[h][1]=d-p*p/h,r[h][1]=1}const s=new Array(t+1);s[t]=i;let a=t;for(;a>=2;)s[a-1]=r[s[a]][a]-1,a--;s[0]=0;const l=[e[0]];for(let h=1;h<t;h++)s[h]<i&&l.push(e[s[h]]);return l.push(e[i-1]),[...new Set(l)].sort((h,d)=>h-d)}function Lle(e,t){const i=jl(e),n=[];for(let r=0;r<t;r++){const s=t===1?.5:r/(t-1);n.push(OY(i,s))}return n}var gj=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_choroplethLayers=new Map;_legendControls=new Map;_activePopup;_cachedGeojson;_cachedColumns=[];constructor(e){this._options={...Ile,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,url:this._options.defaultUrl,layerName:this._options.defaultLayerName,beforeId:this._options.beforeId,format:this._options.defaultFormat,column:this._options.defaultColumn,colormap:this._options.defaultColormap,scheme:this._options.defaultScheme,k:this._options.defaultK,opacity:this._options.defaultOpacity,showOutline:!0,outlineColor:this._options.defaultOutlineColor,extrude:this._options.defaultExtrude,scaleFactor:this._options.defaultScaleFactor,pickable:this._options.defaultPickable,hasLayer:!1,layerCount:0,layers:[],loading:!1,error:null,status:null,availableColumns:[]}}onAdd(e){if(this._map=e,this._container=this._createContainer(),this._render(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._options.loadDefaultUrl&&this._options.defaultUrl){const t=()=>this._loadData();this._map.isStyleLoaded()?setTimeout(t,100):this._map.once("idle",t)}return this._container}onRemove(){this._removeAllLayers(),this._removeAllLegendControls(),this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=void 0),this._map=void 0,this._container?.parentNode?.removeChild(this._container),this._container=void 0,this._button=void 0,this._panel=void 0,this._eventHandlers.clear()}show(){this._state.visible||(this._state.visible=!0,this._updateDisplayState(),this._emit("show"))}hide(){this._state.visible&&(this._state.visible=!1,this._updateDisplayState(),this._emit("hide"))}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._render(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._render(),this._emit("collapse"))}toggle(){this._state.collapsed?this.expand():this.collapse()}getState(){return{...this._state}}update(e){this._options={...this._options,...e},e.visible!==void 0&&(this._state.visible=e.visible),e.collapsed!==void 0&&(this._state.collapsed=e.collapsed),this._render(),this._emit("update")}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}async addLayer(e,t,i){e&&(this._state.url=e),t&&(this._state.column=t),i?.colormap&&(this._state.colormap=i.colormap),i?.scheme&&(this._state.scheme=i.scheme),i?.k&&(this._state.k=i.k),await this._loadData(),this._cachedGeojson&&this._state.column&&await this._addChoroplethLayer()}removeLayer(e){this._removeLayer(e),this._render()}getLayerIds(){const e=[];for(const t of this._choroplethLayers.values())e.push(...t.layerIds);return e}_emit(e,t){const i=this._eventHandlers.get(e);if(i){const n={type:e,state:this.getState(),...t};i.forEach(r=>r(n))}}_checkZoomVisibility(){if(!this._map)return;const e=this._map.getZoom(),{minzoom:t,maxzoom:i}=this._options,n=e>=t&&e<=i;n!==this._zoomVisible&&(this._zoomVisible=n,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const e=this._state.visible&&this._zoomVisible;this._container.style.display=e?"block":"none"}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-choropleth${this._options.className?` ${this._options.className}`:""}`,this._state.visible&&this._zoomVisible||(e.style.display="none"),Object.assign(e.style,{backgroundColor:this._options.backgroundColor,borderRadius:`${this._options.borderRadius}px`,boxShadow:"0 0 0 2px rgba(0, 0, 0, 0.1)"}),this._options.opacity!==1&&(e.style.opacity=String(this._options.opacity)),e}_render(){if(!this._container)return;const e=this._container.querySelector(".maplibre-gl-choropleth-panel"),t=e?e.scrollTop:0;if(this._container.innerHTML="",this._state.collapsed?this._renderCollapsed():this._renderExpanded(),this._updateDisplayState(),t>0){const i=this._container.querySelector(".maplibre-gl-choropleth-panel");i&&(i.scrollTop=t)}}_renderCollapsed(){this._container&&(this._button=document.createElement("button"),this._button.type="button",this._button.className=`maplibre-gl-choropleth-button${this._state.hasLayer?" maplibre-gl-choropleth-button--active":""}`,this._button.title="Choropleth Map",this._button.setAttribute("aria-label","Choropleth Map"),this._button.innerHTML=Sle,this._button.addEventListener("click",()=>this.expand()),this._container.appendChild(this._button),this._panel=void 0)}_renderExpanded(){if(!this._container)return;const e=document.createElement("div");e.className="maplibre-gl-choropleth-panel",e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),this._panel=e;const t=document.createElement("div");t.className="maplibre-gl-choropleth-header";const i=document.createElement("span");i.className="maplibre-gl-choropleth-title",i.textContent="Choropleth Map",t.appendChild(i);const n=document.createElement("button");n.className="maplibre-gl-choropleth-close",n.innerHTML="×",n.title="Close",n.addEventListener("click",()=>this.collapse()),t.appendChild(n),e.appendChild(t);const r=document.createElement("div");r.className="maplibre-gl-choropleth-section-title",r.textContent="Data Source",r.style.marginTop="0",r.style.borderTop="none",r.style.paddingTop="0",e.appendChild(r);const s=this._createFormGroup("Vector URL","url"),a=document.createElement("input");a.type="text",a.id="choropleth-url",a.className="maplibre-gl-choropleth-input",a.style.color="#000",a.placeholder="https://data.source.coop/giswqs/opengeos/h3_res4_geo.parquet",a.value=this._state.url,a.addEventListener("input",()=>{this._state.url=a.value}),s.appendChild(a);const l=document.createElement("div");l.className="maplibre-gl-choropleth-format-hint",l.textContent="Supports GeoJSON, GeoParquet, and FlatGeobuf",s.appendChild(l),e.appendChild(s);const h=this._createFormGroup("Format","format"),d=document.createElement("select");d.id="choropleth-format",d.className="maplibre-gl-choropleth-select",d.style.color="#000";for(const v of[{value:"auto",label:"Auto-detect"},{value:"geojson",label:"GeoJSON"},{value:"geoparquet",label:"GeoParquet"},{value:"flatgeobuf",label:"FlatGeobuf"}]){const y=document.createElement("option");y.value=v.value,y.textContent=v.label,y.selected=v.value===this._state.format,d.appendChild(y)}d.addEventListener("change",()=>{this._state.format=d.value}),h.appendChild(d),e.appendChild(h);const p=document.createElement("div");p.className="maplibre-gl-choropleth-buttons";const g=document.createElement("button");if(g.className="maplibre-gl-choropleth-btn maplibre-gl-choropleth-btn--primary",g.textContent=this._cachedGeojson?"Reload Data":"Load Data",g.disabled=this._state.loading,g.addEventListener("click",()=>this._loadData()),p.appendChild(g),e.appendChild(p),this._cachedColumns.length>0){const v=document.createElement("div");v.className="maplibre-gl-choropleth-section-title",v.textContent="Classification",e.appendChild(v);const y=this._createFormGroup("Column","column"),E=document.createElement("select");E.id="choropleth-column",E.className="maplibre-gl-choropleth-select",E.style.color="#000";const S=document.createElement("option");S.value="",S.textContent="-- Select column --",S.disabled=!0,S.selected=!this._state.column,E.appendChild(S);for(const be of this._cachedColumns){const rt=document.createElement("option");rt.value=be,rt.textContent=be,rt.selected=be===this._state.column,E.appendChild(rt)}E.addEventListener("change",()=>{this._state.column=E.value}),y.appendChild(E),e.appendChild(y);const R=document.createElement("div");R.className="maplibre-gl-choropleth-row";const I=this._createFormGroup("Scheme","scheme"),k=document.createElement("select");k.id="choropleth-scheme",k.className="maplibre-gl-choropleth-select",k.style.color="#000";for(const be of Mle){const rt=document.createElement("option");rt.value=be.value,rt.textContent=be.label,rt.selected=be.value===this._state.scheme,k.appendChild(rt)}k.addEventListener("change",()=>{this._state.scheme=k.value}),I.appendChild(k),R.appendChild(I);const D=this._createFormGroup("Classes","k"),F=document.createElement("input");F.type="number",F.id="choropleth-k",F.className="maplibre-gl-choropleth-input",F.style.color="#000",F.min="2",F.max="20",F.value=String(this._state.k),F.addEventListener("change",()=>{this._state.k=Math.max(2,Math.min(20,Number(F.value)||5)),F.value=String(this._state.k)}),D.appendChild(F),R.appendChild(D),e.appendChild(R);const Z=document.createElement("div");Z.className="maplibre-gl-choropleth-section-title",Z.textContent="Styling",e.appendChild(Z);const Y=this._createFormGroup("Colormap","colormap"),Q=document.createElement("select");Q.id="choropleth-colormap",Q.className="maplibre-gl-choropleth-select",Q.style.color="#000";for(const be of IT()){const rt=document.createElement("option");rt.value=be,rt.textContent=be,rt.selected=be===this._state.colormap,Q.appendChild(rt)}Q.addEventListener("change",()=>{this._state.colormap=Q.value,this._updateColormapPreview(V,this._state.colormap)}),Y.appendChild(Q);const V=document.createElement("div");V.className="maplibre-gl-choropleth-colormap-preview",this._updateColormapPreview(V,this._state.colormap),Y.appendChild(V),e.appendChild(Y);const U=this._createFormGroup("Opacity","opacity"),H=document.createElement("div");H.className="maplibre-gl-choropleth-slider-row";const W=document.createElement("input");W.type="range",W.id="choropleth-opacity",W.className="maplibre-gl-choropleth-slider",W.min="0",W.max="100",W.value=String(Math.round(this._state.opacity*100));const ne=document.createElement("span");ne.className="maplibre-gl-choropleth-slider-value",ne.textContent=`${Math.round(this._state.opacity*100)}%`,W.addEventListener("input",()=>{const be=Number(W.value);this._state.opacity=be/100,ne.textContent=`${be}%`}),H.appendChild(W),H.appendChild(ne),U.appendChild(H),e.appendChild(U);const te=document.createElement("div");te.className="maplibre-gl-choropleth-form-group maplibre-gl-choropleth-checkbox-group";const oe=document.createElement("label");oe.className="maplibre-gl-choropleth-checkbox-label";const X=document.createElement("input");X.type="checkbox",X.id="choropleth-show-outline",X.className="maplibre-gl-choropleth-checkbox",X.checked=this._state.showOutline,X.addEventListener("change",()=>{this._state.showOutline=X.checked,ae.style.display=X.checked?"block":"none"}),oe.appendChild(X);const ee=document.createElement("span");ee.textContent="Show Outline",oe.appendChild(ee),te.appendChild(oe),e.appendChild(te);const ae=this._createFormGroup("Outline Color","outline-color");ae.style.display=this._state.showOutline?"block":"none";const ce=document.createElement("div");ce.className="maplibre-gl-choropleth-color-row";const de=document.createElement("input");de.type="color",de.id="choropleth-outline-color",de.className="maplibre-gl-choropleth-color-input",de.value=this._state.outlineColor,de.addEventListener("input",()=>{this._state.outlineColor=de.value,pe.value=de.value}),ce.appendChild(de);const pe=document.createElement("input");pe.type="text",pe.className="maplibre-gl-choropleth-input",pe.style.color="#000",pe.style.flex="1",pe.value=this._state.outlineColor,pe.addEventListener("input",()=>{this._state.outlineColor=pe.value,de.value=pe.value}),ce.appendChild(pe),ae.appendChild(ce),e.appendChild(ae);const Ie=document.createElement("div");Ie.className="maplibre-gl-choropleth-form-group maplibre-gl-choropleth-checkbox-group";const we=document.createElement("label");we.className="maplibre-gl-choropleth-checkbox-label";const Ee=document.createElement("input");Ee.type="checkbox",Ee.id="choropleth-extrude",Ee.className="maplibre-gl-choropleth-checkbox",Ee.checked=this._state.extrude,Ee.addEventListener("change",()=>{this._state.extrude=Ee.checked,Ve.style.display=Ee.checked?"block":"none"}),we.appendChild(Ee);const Se=document.createElement("span");Se.textContent="3D Extrusion (fill-extrusion)",we.appendChild(Se),Ie.appendChild(we),e.appendChild(Ie);const Ve=this._createFormGroup("Scale Factor","scale-factor");Ve.style.display=this._state.extrude?"block":"none";const ze=document.createElement("input");ze.type="number",ze.id="choropleth-scale-factor",ze.className="maplibre-gl-choropleth-input",ze.style.color="#000",ze.step="0.1",ze.min="0.001",ze.value=String(this._state.scaleFactor),ze.addEventListener("change",()=>{this._state.scaleFactor=Math.max(.001,Number(ze.value)||1)});const it=document.createElement("div");it.className="maplibre-gl-choropleth-format-hint",it.textContent="Divide column values by this factor for extrusion height",Ve.appendChild(ze),Ve.appendChild(it),e.appendChild(Ve);const Le=document.createElement("div");Le.className="maplibre-gl-choropleth-form-group maplibre-gl-choropleth-checkbox-group";const nt=document.createElement("label");nt.className="maplibre-gl-choropleth-checkbox-label";const lt=document.createElement("input");lt.type="checkbox",lt.id="choropleth-pickable",lt.className="maplibre-gl-choropleth-checkbox",lt.checked=this._state.pickable,lt.addEventListener("change",()=>{this._state.pickable=lt.checked}),nt.appendChild(lt);const Ae=document.createElement("span");Ae.textContent="Pickable (click to show feature info)",nt.appendChild(Ae),Le.appendChild(nt),e.appendChild(Le);const vt=this._createFormGroup("Layer Name","layer-name"),Ne=document.createElement("input");Ne.type="text",Ne.id="choropleth-layer-name",Ne.className="maplibre-gl-choropleth-input",Ne.style.color="#000",Ne.placeholder="Optional custom layer name",Ne.value=this._state.layerName,Ne.addEventListener("input",()=>{this._state.layerName=Ne.value}),vt.appendChild(Ne),e.appendChild(vt);const $t=this._createFormGroup("Before Layer ID","before-id"),It=document.createElement("input");It.type="text",It.id="choropleth-before-id",It.className="maplibre-gl-choropleth-input",It.style.color="#000",It.placeholder="Optional layer ID to insert before",It.value=this._state.beforeId,It.addEventListener("input",()=>{this._state.beforeId=It.value}),$t.appendChild(It),e.appendChild($t);const di=document.createElement("div");di.className="maplibre-gl-choropleth-buttons";const Ge=document.createElement("button");Ge.className="maplibre-gl-choropleth-btn maplibre-gl-choropleth-btn--primary",Ge.textContent="Add Choropleth",Ge.disabled=this._state.loading||!this._state.column,Ge.addEventListener("click",()=>this._addChoroplethLayer()),di.appendChild(Ge),e.appendChild(di)}if(this._state.loading?this._appendStatus("Loading data...","info"):this._state.error?this._appendStatus(this._state.error,"error"):this._state.status&&this._appendStatus(this._state.status,"success"),this._choroplethLayers.size>0){const v=document.createElement("div");v.className="maplibre-gl-choropleth-layer-list";const y=document.createElement("div");y.className="maplibre-gl-choropleth-layer-header",y.textContent=`Choropleth Layers (${this._choroplethLayers.size})`,v.appendChild(y);for(const[E,S]of this._choroplethLayers){const R=document.createElement("div");R.className="maplibre-gl-choropleth-layer-item";const I=document.createElement("span");I.className="maplibre-gl-choropleth-layer-label",I.textContent=`${S.id} (${S.column}, ${S.scheme})`,I.title=`${S.url} - ${S.column}`,R.appendChild(I);const k=document.createElement("button");if(k.className="maplibre-gl-choropleth-layer-remove",k.innerHTML="×",k.title="Remove layer",k.addEventListener("click",()=>{this._removeLayer(E),this._render()}),R.appendChild(k),v.appendChild(R),S.legendColors&&S.legendLabels){const D=document.createElement("div");D.className="maplibre-gl-choropleth-legend";const F=document.createElement("div");F.style.display="flex",F.style.justifyContent="space-between",F.style.alignItems="center",F.style.marginBottom="4px";const Z=document.createElement("div");Z.className="maplibre-gl-choropleth-legend-title",Z.style.marginBottom="0",Z.textContent=S.column,F.appendChild(Z);const Y=this._legendControls.has(E),Q=document.createElement("button");Q.className=`maplibre-gl-choropleth-btn${Y?" maplibre-gl-choropleth-btn--danger":" maplibre-gl-choropleth-btn--primary"}`,Q.style.flex="0 0 auto",Q.style.padding="3px 8px",Q.style.fontSize="10px",Q.textContent=Y?"Remove Legend":"Add to Map",Q.addEventListener("click",()=>{this._legendControls.has(E)?this._removeLegendControl(E):this._addLegendControl(E,S),this._render()}),F.appendChild(Q),D.appendChild(F);for(let V=0;V<S.legendColors.length;V++){const U=document.createElement("div");U.className="maplibre-gl-choropleth-legend-item";const H=document.createElement("div");H.className="maplibre-gl-choropleth-legend-swatch",H.style.backgroundColor=S.legendColors[V],U.appendChild(H);const W=document.createElement("span");W.textContent=S.legendLabels[V]||"",U.appendChild(W),D.appendChild(U)}v.appendChild(D)}}e.appendChild(v)}this._container.appendChild(e),this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-choropleth-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`choropleth-${t}`,i.appendChild(n),i}_appendStatus(e,t){if(!this._panel)return;const i=document.createElement("div");i.className=`maplibre-gl-choropleth-status maplibre-gl-choropleth-status--${t}`,i.textContent=e,this._panel.appendChild(i)}_updateColormapPreview(e,t){if(!MT(t))return;const i=jl(t).map(n=>`${n.color} ${n.position*100}%`).join(", ");e.style.background=`linear-gradient(to right, ${i})`}async _loadData(){if(!this._map||!this._state.url){this._state.error="Please enter a vector URL.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{let e=this._state.format;e==="auto"&&(e=Tle(this._state.url));let t;if(e==="geojson"){let n;try{n=await fetch(this._state.url)}catch{throw new Error("CORS error: The server doesn't allow cross-origin requests.")}if(!n.ok)throw new Error(`Failed to fetch: ${n.status} ${n.statusText}`);const r=await n.json();t=this._normalizeGeoJSON(r)}else if(e==="geoparquet")t=await this._loadGeoParquet(this._state.url);else if(e==="flatgeobuf")t=await this._loadFlatGeobuf(this._state.url);else throw new Error(`Unsupported format: ${e}`);this._cachedGeojson=t;const i=this._detectNumericColumns(t);this._cachedColumns=i,this._state.availableColumns=i,!this._state.column&&i.length>0&&(this._state.column=i[0]),this._state.loading=!1,this._state.status=`Loaded ${t.features.length} features, ${i.length} numeric columns.`,this._render()}catch(e){this._state.loading=!1,this._state.error=`Failed to load: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_detectNumericColumns(e){const t=new Map,i=Math.min(e.features.length,100);for(let r=0;r<i;r++){const s=e.features[r]?.properties;if(s)for(const[a,l]of Object.entries(s)){t.has(a)||t.set(a,{numericCount:0,totalCount:0});const h=t.get(a);h.totalCount++,typeof l=="number"&&!isNaN(l)&&h.numericCount++}}const n=[];for(const[r,s]of t)s.totalCount>0&&s.numericCount/s.totalCount>.8&&n.push(r);return n.sort()}async _addChoroplethLayer(){if(!this._map||!this._cachedGeojson||!this._state.column){this._state.error="Load data and select a column first.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{const e=this._cachedGeojson,t=this._state.column,i=this._state.k,n=this._state.scheme,r=this._state.colormap,s=this._state.opacity,a=this._state.showOutline,l=a?this._state.outlineColor:"transparent",h=this._state.extrude,d=this._state.scaleFactor,{breaks:p,bins:g}=Rle(e.features.map(te=>{const oe=te.properties?.[t];return typeof oe=="number"?oe:NaN}),n,i),v=p.length-1,y=Lle(r,v),E={type:"FeatureCollection",features:e.features.map((te,oe)=>({...te,properties:{...te.properties,_choropleth_color:y[g[oe]]||y[0],_choropleth_bin:g[oe]}}))};let S=this._state.layerName?.trim();if(!S)try{S=(new URL(this._state.url).pathname.split("/").pop()||"").replace(/\.[^.]+$/,"")}catch{}S||(S=Qu("choropleth")),S=`${S}-${t}`;const R=`${S}-source`,I=new Set;for(const te of E.features)te.geometry&&I.add(te.geometry.type);this._map.addSource(R,{type:"geojson",data:E,generateId:!0});const k=[],D=this._state.beforeId?.trim(),F=this._options.beforeId,Z=D||F,Y=Z&&this._map.getLayer(Z)?Z:void 0,Q=I.has("Polygon")||I.has("MultiPolygon"),V=I.has("LineString")||I.has("MultiLineString"),U=I.has("Point")||I.has("MultiPoint");if(Q)if(h){const te=["interpolate",["linear"],["get",t]],oe=["interpolate",["linear"],["get",t]];for(let ee=0;ee<p.length;ee++){const ae=Math.min(ee,y.length-1);te.push(p[ee],y[ae]),oe.push(p[ee],p[ee]/d)}const X=`${S}-extrusion`;this._map.addLayer({id:X,type:"fill-extrusion",source:R,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-extrusion-color":te,"fill-extrusion-height":oe,"fill-extrusion-base":10,"fill-extrusion-opacity":s}},Y),k.push(X)}else{const te=`${S}-fill`;if(this._map.addLayer({id:te,type:"fill",source:R,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-color":["get","_choropleth_color"],"fill-opacity":s,"fill-outline-color":l}},Y),k.push(te),a){const oe=`${S}-outline`;this._map.addLayer({id:oe,type:"line",source:R,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"line-color":l,"line-width":.5,"line-opacity":s}},Y),k.push(oe)}}if(V){const te=`${S}-line`;this._map.addLayer({id:te,type:"line",source:R,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"MultiLineString"]],paint:{"line-color":["get","_choropleth_color"],"line-width":2,"line-opacity":s}},Y),k.push(te)}if(U){const te=`${S}-point`;this._map.addLayer({id:te,type:"circle",source:R,filter:["any",["==",["geometry-type"],"Point"],["==",["geometry-type"],"MultiPoint"]],paint:{"circle-color":["get","_choropleth_color"],"circle-radius":6,"circle-stroke-color":l,"circle-stroke-width":a?1:0,"circle-opacity":s}},Y),k.push(te)}if(this._state.pickable&&this._map){const te=this._map;for(const oe of k)te.on("mouseenter",oe,()=>{te.getCanvas().style.cursor="pointer"}),te.on("mouseleave",oe,()=>{te.getCanvas().style.cursor=""}),te.on("click",oe,X=>{if(!X.features||X.features.length===0)return;const ee=X.features[0].properties||{},ae=Object.entries(ee).filter(([de])=>!de.startsWith("_choropleth_"));if(ae.length===0)return;let ce='<div class="maplibre-gl-choropleth-popup">';ce+='<table class="maplibre-gl-choropleth-popup-table">';for(const[de,pe]of ae){const Ie=typeof pe=="number"?Number.isInteger(pe)?pe.toString():pe.toFixed(4):String(pe);ce+=`<tr><td><strong>${de}</strong></td><td>${Ie}</td></tr>`}ce+="</table></div>",this._activePopup&&this._activePopup.remove(),this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"300px"}).setLngLat(X.lngLat).setHTML(ce).addTo(te)})}const H=y,W=[];for(let te=0;te<p.length-1;te++){const oe=this._formatBreak(p[te]),X=this._formatBreak(p[te+1]);W.push(`${oe} – ${X}`)}const ne={id:S,url:this._state.url,sourceId:R,layerIds:k,featureCount:E.features.length,geometryTypes:Array.from(I),column:t,scheme:n,k:v,colormap:r,breaks:p,legendColors:H,legendLabels:W,opacity:s,extrude:h,scaleFactor:d};this._choroplethLayers.set(S,ne),this._state.hasLayer=this._choroplethLayers.size>0,this._state.layerCount=this._choroplethLayers.size,this._state.layers=Array.from(this._choroplethLayers.values()),this._state.loading=!1,this._state.status=`Added choropleth: ${t} (${v} classes, ${n}).`,this._options.fitBounds&&E.features.length>0&&this._fitToData(E),this._render(),this._emit("layeradd",{url:this._state.url,layerId:S})}catch(e){this._state.loading=!1,this._state.error=`Failed: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_formatBreak(e){return Math.abs(e)>=1e3?Math.round(e).toLocaleString():Math.abs(e)>=1?e.toFixed(2):Math.abs(e)>=.01?e.toFixed(4):e.toExponential(2)}_normalizeGeoJSON(e){return e.type==="FeatureCollection"?e:e.type==="Feature"?{type:"FeatureCollection",features:[e]}:{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]}}async _fetchWithCorsProxy(e){try{const i=await fetch(e,{mode:"cors"});if(i.ok)return i}catch{}const t="https://corsproxy.io/?";try{const i=await fetch(t+encodeURIComponent(e),{mode:"cors"});if(i.ok)return i}catch{}throw new Error("CORS error: Unable to fetch the file. The server doesn't allow cross-origin requests.")}async _loadGeoParquet(e){const{getDuckDBConverter:t}=await Promise.resolve().then(()=>require("./DuckDBConverter-BFaMPglx.cjs")).then(a=>a.DuckDBConverter_exports),i=t(),n=await this._fetchWithCorsProxy(e);let r;try{r=await n.arrayBuffer()}catch(a){throw new Error(`Failed to read GeoParquet response: ${a instanceof Error?a.message:String(a)}`)}let s;try{s=await i.convert(r,"data.parquet")}catch(a){throw new Error(`Failed to convert GeoParquet: ${a instanceof Error?a.message:String(a)}`)}if(s.geojson)return s.geojson;throw new Error("Failed to convert GeoParquet: No GeoJSON output")}async _loadFlatGeobuf(e){const t=await Promise.resolve().then(()=>require("./geojson-CxMdRvJX.cjs")),i=await fetch(e);if(!i.ok)throw new Error(`Failed to fetch: ${i.status} ${i.statusText}`);if(!i.body)throw new Error("Response body is null - streaming not supported");const n=[];for await(const r of t.deserialize(i.body))n.push(r);return{type:"FeatureCollection",features:n}}_fitToData(e){if(!this._map)return;let t=1/0,i=1/0,n=-1/0,r=-1/0;const s=l=>{t=Math.min(t,l[0]),n=Math.max(n,l[0]),i=Math.min(i,l[1]),r=Math.max(r,l[1])},a=l=>{for(const h of l)typeof h[0]=="number"?s(h):a(h)};for(const l of e.features){if(!l.geometry)continue;const h=l.geometry;h.type==="Point"?s(h.coordinates):(h.type==="MultiPoint"||h.type==="LineString"||h.type==="MultiLineString"||h.type==="Polygon"||h.type==="MultiPolygon")&&a(h.coordinates)}t!==1/0&&this._map.fitBounds([[t,i],[n,r]],{padding:this._options.fitBoundsPadding})}_removeLayer(e){if(this._map)if(e){const t=this._choroplethLayers.get(e);if(t){for(const i of t.layerIds)try{this._map.getLayer(i)&&this._map.removeLayer(i)}catch{}try{this._map.getSource(t.sourceId)&&this._map.removeSource(t.sourceId)}catch{}}this._choroplethLayers.delete(e),this._removeLegendControl(e),this._state.hasLayer=this._choroplethLayers.size>0,this._state.layerCount=this._choroplethLayers.size,this._state.layers=Array.from(this._choroplethLayers.values()),this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e})}else this._removeAllLayers()}_addLegendControl(e,t){if(!this._map||this._legendControls.has(e))return;const i=t.legendColors.map((r,s)=>({label:t.legendLabels[s]||"",color:r,shape:"square"})),n=new PG({title:t.column,items:i,position:"bottom-left",collapsible:!0,collapsed:!1,visible:!0});this._map.addControl(n,"bottom-left"),this._legendControls.set(e,n)}_removeLegendControl(e){if(!this._map)return;const t=this._legendControls.get(e);t&&(this._map.removeControl(t),this._legendControls.delete(e))}_removeAllLegendControls(){if(this._map){for(const[,e]of this._legendControls)try{this._map.removeControl(e)}catch{}this._legendControls.clear()}}_removeAllLayers(){if(this._map){for(const[,e]of this._choroplethLayers){for(const t of e.layerIds)try{this._map.getLayer(t)&&this._map.removeLayer(t)}catch{}try{this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)}catch{}}this._choroplethLayers.clear(),this._removeAllLegendControls(),this._state.hasLayer=!1,this._state.layerCount=0,this._state.layers=[],this._state.status=null,this._state.error=null,this._emit("layerremove")}}},kle={position:"top-right",className:"",visible:!0,collapsed:!0,panelWidth:280,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:12,fontColor:"#333",minzoom:0,maxzoom:24},Ple='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="none"><defs><linearGradient id="cbg" x1="0" y1="1" x2="0" y2="0"><stop offset="0%" stop-color="#440154"/><stop offset="25%" stop-color="#31688e"/><stop offset="50%" stop-color="#21918c"/><stop offset="75%" stop-color="#90d743"/><stop offset="100%" stop-color="#fde725"/></linearGradient></defs><rect x="8" y="2" width="8" height="20" rx="2" fill="url(#cbg)" stroke="currentColor" stroke-width="1.5"/></svg>',Nle='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',_j=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_colorbar;_colorbars=[];_colorbarEntries=[];_colorbarSelect;_colormapSelect;_vminInput;_vmaxInput;_labelInput;_unitsInput;_orientationSelect;_positionSelect;_addBtn;_updateBtn;_removeBtn;_previewEl;_customColorsTextarea;_modeNamedRadio;_modeCustomRadio;_namedSection;_customSection;constructor(e){this._options={...kle,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,mode:"named",colormap:"viridis",customColors:"#440154, #31688e, #21918c, #90d743, #fde725",vmin:0,vmax:100,label:"",units:"",orientation:"vertical",colorbarPosition:"bottom-right",hasColorbar:!1,selectedColorbarIndex:-1,colorbars:[]}}onAdd(e){return this._map=e,this._container=this._createContainer(),this._setupZoomHandler(),this._state.collapsed||this._showPanel(),this._container}onRemove(){this._handleZoom&&this._map&&this._map.off("zoom",this._handleZoom),this._removeAllColorbars(),this._container?.remove(),this._container=void 0,this._map=void 0}getDefaultPosition(){return this._options.position}on(e,t){return this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t),this}off(e,t){return this._eventHandlers.get(e)?.delete(t),this}_emit(e){const t=this._eventHandlers.get(e);if(t){const i={type:e,state:{...this._state}};t.forEach(n=>n(i))}}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._showPanel(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._hidePanel(),this._emit("collapse"))}show(){return this._state.visible=!0,this._container&&this._zoomVisible&&(this._container.style.display=""),this._emit("show"),this}hide(){return this._state.visible=!1,this._container&&(this._container.style.display="none"),this._emit("hide"),this}getState(){return{...this._state,colorbars:this._colorbarEntries.map(e=>({...e}))}}setState(e){this._map&&this._colorbars.forEach(r=>{this._map.removeControl(r)});const t=(e.colorbars??[]).map(r=>({...r}));this._colorbars=[],this._colorbarEntries=t,this._map&&t.forEach(r=>{const s=this._createColorbar(r);this._map.addControl(s,r.colorbarPosition),this._colorbars.push(s)});const i=typeof e.selectedColorbarIndex=="number"&&e.selectedColorbarIndex>=0&&e.selectedColorbarIndex<t.length?e.selectedColorbarIndex:t.length>0?t.length-1:-1,n=i>=0?t[i]:{mode:e.mode??this._state.mode,colormap:e.colormap??this._state.colormap,customColors:e.customColors??this._state.customColors,vmin:e.vmin??this._state.vmin,vmax:e.vmax??this._state.vmax,label:e.label??this._state.label,units:e.units??this._state.units,orientation:e.orientation??this._state.orientation,colorbarPosition:e.colorbarPosition??this._state.colorbarPosition};return this._state={...this._state,...n,visible:e.visible??this._state.visible,collapsed:e.collapsed??this._state.collapsed,hasColorbar:t.length>0,selectedColorbarIndex:i,colorbars:t.map(r=>({...r}))},this._colorbar=i>=0?this._colorbars[i]:void 0,this._applyEntryToForm(n),this._state.collapsed?this._hidePanel():this._showPanel(),this._container&&(this._container.style.display=this._state.visible&&this._zoomVisible?"":"none"),this._updateButtonStates(),this._emit("colorbarupdate"),this}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-colorbar-gui-control ${this._options.className}`,this._state.visible||(e.style.display="none"),this._button=document.createElement("button"),this._button.type="button",this._button.className="colorbar-gui-button",this._button.title="Colorbar",this._button.innerHTML=Ple,this._button.addEventListener("click",()=>this._togglePanel()),e.appendChild(this._button),e}_createPanel(){const e=document.createElement("div");e.className=`colorbar-gui-panel ${this._options.position.includes("left")?"right":"left"}`,e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),e.style.background=this._options.backgroundColor,e.style.borderRadius=`${this._options.borderRadius}px`,e.style.fontSize=`${this._options.fontSize}px`,e.style.color=this._options.fontColor;const t=document.createElement("div");t.className="colorbar-gui-header",t.innerHTML=`
|
|
251
|
+
</svg>`,Mle=[{value:"quantile",label:"Quantile"},{value:"equal_interval",label:"Equal Interval"},{value:"natural_breaks",label:"Natural Breaks (Jenks)"},{value:"std_mean",label:"Standard Deviation"},{value:"head_tail",label:"Head/Tail Breaks"}],Ile={position:"top-right",className:"",visible:!0,collapsed:!0,beforeId:"",defaultUrl:"",defaultLayerName:"",loadDefaultUrl:!1,defaultFormat:"auto",defaultColumn:"",defaultColormap:"viridis",defaultScheme:"quantile",defaultK:5,defaultOpacity:.8,defaultOutlineColor:"#ffffff",defaultExtrude:!1,defaultScaleFactor:1,defaultPickable:!0,fitBounds:!0,fitBoundsPadding:50,panelWidth:320,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:13,fontColor:"#333",minzoom:0,maxzoom:24};function Tle(e){const t=e.toLowerCase();return t.endsWith(".geojson")||t.endsWith(".json")?"geojson":t.endsWith(".parquet")||t.endsWith(".geoparquet")?"geoparquet":t.endsWith(".fgb")?"flatgeobuf":"geojson"}function Rle(e,t,i){const n=[...e].filter(d=>!isNaN(d)).sort((d,p)=>d-p),r=n.length;if(r===0)return{breaks:[0,1],bins:e.map(()=>0)};const s=n[0],a=n[r-1];let l;switch(t){case"equal_interval":{l=[s];const d=(a-s)/i;for(let p=1;p<i;p++)l.push(s+d*p);l.push(a);break}case"quantile":l=[s];for(let d=1;d<i;d++){const p=Math.floor(d*r/i);l.push(n[Math.min(p,r-1)])}l.push(a),l=[...new Set(l)].sort((d,p)=>d-p);break;case"natural_breaks":l=Ble(n,i);break;case"std_mean":{const d=n.reduce((y,E)=>y+E,0)/r,p=n.reduce((y,E)=>y+(E-d)**2,0)/r,g=Math.sqrt(p);l=[s];const v=[-2,-1,0,1,2].map(y=>d+y*g);for(const y of v)y>s&&y<a&&l.push(y);l.push(a),l=[...new Set(l)].sort((y,E)=>y-E);break}case"head_tail":{l=[s];let d=n;for(;l.length<i&&d.length>1;){const p=d.reduce((g,v)=>g+v,0)/d.length;if(p<=l[l.length-1])break;l.push(p),d=d.filter(g=>g>p)}l.push(a),l=[...new Set(l)].sort((p,g)=>p-g);break}default:{l=[s];const d=(a-s)/i;for(let p=1;p<i;p++)l.push(s+d*p);l.push(a)}}const h=e.map(d=>{if(isNaN(d))return 0;for(let p=0;p<l.length-1;p++)if(d<=l[p+1])return Math.min(p,l.length-2);return l.length-2});return{breaks:l,bins:h}}function Ble(e,t){const i=e.length;if(i<=t)return[...new Set(e)].sort((h,d)=>h-d);const n=Array.from({length:i+1},()=>new Array(t+1).fill(1/0)),r=Array.from({length:i+1},()=>new Array(t+1).fill(0));for(let h=1;h<=t;h++)n[1][h]=0,r[1][h]=1;for(let h=2;h<=i;h++){let d=0,p=0;for(let g=1;g<=h;g++){const v=e[h-1];p+=v,d+=v*v;const y=d-p*p/g,E=h-g+1;if(E!==1)for(let S=2;S<=t;S++)n[h][S]>=y+n[E-1][S-1]&&(r[h][S]=E,n[h][S]=y+n[E-1][S-1])}n[h][1]=d-p*p/h,r[h][1]=1}const s=new Array(t+1);s[t]=i;let a=t;for(;a>=2;)s[a-1]=r[s[a]][a]-1,a--;s[0]=0;const l=[e[0]];for(let h=1;h<t;h++)s[h]<i&&l.push(e[s[h]]);return l.push(e[i-1]),[...new Set(l)].sort((h,d)=>h-d)}function Lle(e,t){const i=jl(e),n=[];for(let r=0;r<t;r++){const s=t===1?.5:r/(t-1);n.push(OY(i,s))}return n}var gj=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_choroplethLayers=new Map;_legendControls=new Map;_activePopup;_cachedGeojson;_cachedColumns=[];constructor(e){this._options={...Ile,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,url:this._options.defaultUrl,layerName:this._options.defaultLayerName,beforeId:this._options.beforeId,format:this._options.defaultFormat,column:this._options.defaultColumn,colormap:this._options.defaultColormap,scheme:this._options.defaultScheme,k:this._options.defaultK,opacity:this._options.defaultOpacity,showOutline:!0,outlineColor:this._options.defaultOutlineColor,extrude:this._options.defaultExtrude,scaleFactor:this._options.defaultScaleFactor,pickable:this._options.defaultPickable,hasLayer:!1,layerCount:0,layers:[],loading:!1,error:null,status:null,availableColumns:[]}}onAdd(e){if(this._map=e,this._container=this._createContainer(),this._render(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._options.loadDefaultUrl&&this._options.defaultUrl){const t=()=>this._loadData();this._map.isStyleLoaded()?setTimeout(t,100):this._map.once("idle",t)}return this._container}onRemove(){this._removeAllLayers(),this._removeAllLegendControls(),this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=void 0),this._map=void 0,this._container?.parentNode?.removeChild(this._container),this._container=void 0,this._button=void 0,this._panel=void 0,this._eventHandlers.clear()}show(){this._state.visible||(this._state.visible=!0,this._updateDisplayState(),this._emit("show"))}hide(){this._state.visible&&(this._state.visible=!1,this._updateDisplayState(),this._emit("hide"))}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._render(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._render(),this._emit("collapse"))}toggle(){this._state.collapsed?this.expand():this.collapse()}getState(){return{...this._state}}update(e){this._options={...this._options,...e},e.visible!==void 0&&(this._state.visible=e.visible),e.collapsed!==void 0&&(this._state.collapsed=e.collapsed),this._render(),this._emit("update")}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}async addLayer(e,t,i){e&&(this._state.url=e),t&&(this._state.column=t),i?.colormap&&(this._state.colormap=i.colormap),i?.scheme&&(this._state.scheme=i.scheme),i?.k&&(this._state.k=i.k),await this._loadData(),this._cachedGeojson&&this._state.column&&await this._addChoroplethLayer()}removeLayer(e){this._removeLayer(e),this._render()}getLayerIds(){const e=[];for(const t of this._choroplethLayers.values())e.push(...t.layerIds);return e}_emit(e,t){const i=this._eventHandlers.get(e);if(i){const n={type:e,state:this.getState(),...t};i.forEach(r=>r(n))}}_checkZoomVisibility(){if(!this._map)return;const e=this._map.getZoom(),{minzoom:t,maxzoom:i}=this._options,n=e>=t&&e<=i;n!==this._zoomVisible&&(this._zoomVisible=n,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const e=this._state.visible&&this._zoomVisible;this._container.style.display=e?"block":"none"}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-choropleth${this._options.className?` ${this._options.className}`:""}`,this._state.visible&&this._zoomVisible||(e.style.display="none"),Object.assign(e.style,{backgroundColor:this._options.backgroundColor,borderRadius:`${this._options.borderRadius}px`,boxShadow:"0 0 0 2px rgba(0, 0, 0, 0.1)"}),this._options.opacity!==1&&(e.style.opacity=String(this._options.opacity)),e}_render(){if(!this._container)return;const e=this._container.querySelector(".maplibre-gl-choropleth-panel"),t=e?e.scrollTop:0;if(this._container.innerHTML="",this._state.collapsed?this._renderCollapsed():this._renderExpanded(),this._updateDisplayState(),t>0){const i=this._container.querySelector(".maplibre-gl-choropleth-panel");i&&(i.scrollTop=t)}}_renderCollapsed(){this._container&&(this._button=document.createElement("button"),this._button.type="button",this._button.className=`maplibre-gl-choropleth-button${this._state.hasLayer?" maplibre-gl-choropleth-button--active":""}`,this._button.title="Choropleth Map",this._button.setAttribute("aria-label","Choropleth Map"),this._button.innerHTML=Sle,this._button.addEventListener("click",()=>this.expand()),this._container.appendChild(this._button),this._panel=void 0)}_renderExpanded(){if(!this._container)return;const e=document.createElement("div");e.className="maplibre-gl-choropleth-panel",e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),this._panel=e;const t=document.createElement("div");t.className="maplibre-gl-choropleth-header";const i=document.createElement("span");i.className="maplibre-gl-choropleth-title",i.textContent="Choropleth Map",t.appendChild(i);const n=document.createElement("button");n.className="maplibre-gl-choropleth-close",n.innerHTML="×",n.title="Close",n.addEventListener("click",()=>this.collapse()),t.appendChild(n),e.appendChild(t);const r=document.createElement("div");r.className="maplibre-gl-choropleth-section-title",r.textContent="Data Source",r.style.marginTop="0",r.style.borderTop="none",r.style.paddingTop="0",e.appendChild(r);const s=this._createFormGroup("Vector URL","url"),a=document.createElement("input");a.type="text",a.id="choropleth-url",a.className="maplibre-gl-choropleth-input",a.style.color="#000",a.placeholder="https://data.source.coop/giswqs/opengeos/h3_res4_geo.parquet",a.value=this._state.url,a.addEventListener("input",()=>{this._state.url=a.value}),s.appendChild(a);const l=document.createElement("div");l.className="maplibre-gl-choropleth-format-hint",l.textContent="Supports GeoJSON, GeoParquet, and FlatGeobuf",s.appendChild(l),e.appendChild(s);const h=this._createFormGroup("Format","format"),d=document.createElement("select");d.id="choropleth-format",d.className="maplibre-gl-choropleth-select",d.style.color="#000";for(const v of[{value:"auto",label:"Auto-detect"},{value:"geojson",label:"GeoJSON"},{value:"geoparquet",label:"GeoParquet"},{value:"flatgeobuf",label:"FlatGeobuf"}]){const y=document.createElement("option");y.value=v.value,y.textContent=v.label,y.selected=v.value===this._state.format,d.appendChild(y)}d.addEventListener("change",()=>{this._state.format=d.value}),h.appendChild(d),e.appendChild(h);const p=document.createElement("div");p.className="maplibre-gl-choropleth-buttons";const g=document.createElement("button");if(g.className="maplibre-gl-choropleth-btn maplibre-gl-choropleth-btn--primary",g.textContent=this._cachedGeojson?"Reload Data":"Load Data",g.disabled=this._state.loading,g.addEventListener("click",()=>this._loadData()),p.appendChild(g),e.appendChild(p),this._cachedColumns.length>0){const v=document.createElement("div");v.className="maplibre-gl-choropleth-section-title",v.textContent="Classification",e.appendChild(v);const y=this._createFormGroup("Column","column"),E=document.createElement("select");E.id="choropleth-column",E.className="maplibre-gl-choropleth-select",E.style.color="#000";const S=document.createElement("option");S.value="",S.textContent="-- Select column --",S.disabled=!0,S.selected=!this._state.column,E.appendChild(S);for(const be of this._cachedColumns){const rt=document.createElement("option");rt.value=be,rt.textContent=be,rt.selected=be===this._state.column,E.appendChild(rt)}E.addEventListener("change",()=>{this._state.column=E.value}),y.appendChild(E),e.appendChild(y);const R=document.createElement("div");R.className="maplibre-gl-choropleth-row";const I=this._createFormGroup("Scheme","scheme"),k=document.createElement("select");k.id="choropleth-scheme",k.className="maplibre-gl-choropleth-select",k.style.color="#000";for(const be of Mle){const rt=document.createElement("option");rt.value=be.value,rt.textContent=be.label,rt.selected=be.value===this._state.scheme,k.appendChild(rt)}k.addEventListener("change",()=>{this._state.scheme=k.value}),I.appendChild(k),R.appendChild(I);const D=this._createFormGroup("Classes","k"),F=document.createElement("input");F.type="number",F.id="choropleth-k",F.className="maplibre-gl-choropleth-input",F.style.color="#000",F.min="2",F.max="20",F.value=String(this._state.k),F.addEventListener("change",()=>{this._state.k=Math.max(2,Math.min(20,Number(F.value)||5)),F.value=String(this._state.k)}),D.appendChild(F),R.appendChild(D),e.appendChild(R);const Z=document.createElement("div");Z.className="maplibre-gl-choropleth-section-title",Z.textContent="Styling",e.appendChild(Z);const Y=this._createFormGroup("Colormap","colormap"),Q=document.createElement("select");Q.id="choropleth-colormap",Q.className="maplibre-gl-choropleth-select",Q.style.color="#000";for(const be of IT()){const rt=document.createElement("option");rt.value=be,rt.textContent=be,rt.selected=be===this._state.colormap,Q.appendChild(rt)}Q.addEventListener("change",()=>{this._state.colormap=Q.value,this._updateColormapPreview(V,this._state.colormap)}),Y.appendChild(Q);const V=document.createElement("div");V.className="maplibre-gl-choropleth-colormap-preview",this._updateColormapPreview(V,this._state.colormap),Y.appendChild(V),e.appendChild(Y);const U=this._createFormGroup("Opacity","opacity"),H=document.createElement("div");H.className="maplibre-gl-choropleth-slider-row";const W=document.createElement("input");W.type="range",W.id="choropleth-opacity",W.className="maplibre-gl-choropleth-slider",W.min="0",W.max="100",W.value=String(Math.round(this._state.opacity*100));const ne=document.createElement("span");ne.className="maplibre-gl-choropleth-slider-value",ne.textContent=`${Math.round(this._state.opacity*100)}%`,W.addEventListener("input",()=>{const be=Number(W.value);this._state.opacity=be/100,ne.textContent=`${be}%`}),H.appendChild(W),H.appendChild(ne),U.appendChild(H),e.appendChild(U);const te=document.createElement("div");te.className="maplibre-gl-choropleth-form-group maplibre-gl-choropleth-checkbox-group";const oe=document.createElement("label");oe.className="maplibre-gl-choropleth-checkbox-label";const X=document.createElement("input");X.type="checkbox",X.id="choropleth-show-outline",X.className="maplibre-gl-choropleth-checkbox",X.checked=this._state.showOutline,X.addEventListener("change",()=>{this._state.showOutline=X.checked,ae.style.display=X.checked?"block":"none"}),oe.appendChild(X);const ee=document.createElement("span");ee.textContent="Show Outline",oe.appendChild(ee),te.appendChild(oe),e.appendChild(te);const ae=this._createFormGroup("Outline Color","outline-color");ae.style.display=this._state.showOutline?"block":"none";const ce=document.createElement("div");ce.className="maplibre-gl-choropleth-color-row";const de=document.createElement("input");de.type="color",de.id="choropleth-outline-color",de.className="maplibre-gl-choropleth-color-input",de.value=this._state.outlineColor,de.addEventListener("input",()=>{this._state.outlineColor=de.value,pe.value=de.value}),ce.appendChild(de);const pe=document.createElement("input");pe.type="text",pe.className="maplibre-gl-choropleth-input",pe.style.color="#000",pe.style.flex="1",pe.value=this._state.outlineColor,pe.addEventListener("input",()=>{this._state.outlineColor=pe.value,de.value=pe.value}),ce.appendChild(pe),ae.appendChild(ce),e.appendChild(ae);const Ie=document.createElement("div");Ie.className="maplibre-gl-choropleth-form-group maplibre-gl-choropleth-checkbox-group";const we=document.createElement("label");we.className="maplibre-gl-choropleth-checkbox-label";const Ee=document.createElement("input");Ee.type="checkbox",Ee.id="choropleth-extrude",Ee.className="maplibre-gl-choropleth-checkbox",Ee.checked=this._state.extrude,Ee.addEventListener("change",()=>{this._state.extrude=Ee.checked,Ve.style.display=Ee.checked?"block":"none"}),we.appendChild(Ee);const Se=document.createElement("span");Se.textContent="3D Extrusion (fill-extrusion)",we.appendChild(Se),Ie.appendChild(we),e.appendChild(Ie);const Ve=this._createFormGroup("Scale Factor","scale-factor");Ve.style.display=this._state.extrude?"block":"none";const ze=document.createElement("input");ze.type="number",ze.id="choropleth-scale-factor",ze.className="maplibre-gl-choropleth-input",ze.style.color="#000",ze.step="0.1",ze.min="0.001",ze.value=String(this._state.scaleFactor),ze.addEventListener("change",()=>{this._state.scaleFactor=Math.max(.001,Number(ze.value)||1)});const it=document.createElement("div");it.className="maplibre-gl-choropleth-format-hint",it.textContent="Divide column values by this factor for extrusion height",Ve.appendChild(ze),Ve.appendChild(it),e.appendChild(Ve);const Le=document.createElement("div");Le.className="maplibre-gl-choropleth-form-group maplibre-gl-choropleth-checkbox-group";const nt=document.createElement("label");nt.className="maplibre-gl-choropleth-checkbox-label";const lt=document.createElement("input");lt.type="checkbox",lt.id="choropleth-pickable",lt.className="maplibre-gl-choropleth-checkbox",lt.checked=this._state.pickable,lt.addEventListener("change",()=>{this._state.pickable=lt.checked}),nt.appendChild(lt);const Ae=document.createElement("span");Ae.textContent="Pickable (click to show feature info)",nt.appendChild(Ae),Le.appendChild(nt),e.appendChild(Le);const vt=this._createFormGroup("Layer Name","layer-name"),Ne=document.createElement("input");Ne.type="text",Ne.id="choropleth-layer-name",Ne.className="maplibre-gl-choropleth-input",Ne.style.color="#000",Ne.placeholder="Optional custom layer name",Ne.value=this._state.layerName,Ne.addEventListener("input",()=>{this._state.layerName=Ne.value}),vt.appendChild(Ne),e.appendChild(vt);const $t=this._createFormGroup("Before Layer ID","before-id"),It=document.createElement("input");It.type="text",It.id="choropleth-before-id",It.className="maplibre-gl-choropleth-input",It.style.color="#000",It.placeholder="Optional layer ID to insert before",It.value=this._state.beforeId,It.addEventListener("input",()=>{this._state.beforeId=It.value}),$t.appendChild(It),e.appendChild($t);const di=document.createElement("div");di.className="maplibre-gl-choropleth-buttons";const Ge=document.createElement("button");Ge.className="maplibre-gl-choropleth-btn maplibre-gl-choropleth-btn--primary",Ge.textContent="Add Choropleth",Ge.disabled=this._state.loading||!this._state.column,Ge.addEventListener("click",()=>this._addChoroplethLayer()),di.appendChild(Ge),e.appendChild(di)}if(this._state.loading?this._appendStatus("Loading data...","info"):this._state.error?this._appendStatus(this._state.error,"error"):this._state.status&&this._appendStatus(this._state.status,"success"),this._choroplethLayers.size>0){const v=document.createElement("div");v.className="maplibre-gl-choropleth-layer-list";const y=document.createElement("div");y.className="maplibre-gl-choropleth-layer-header",y.textContent=`Choropleth Layers (${this._choroplethLayers.size})`,v.appendChild(y);for(const[E,S]of this._choroplethLayers){const R=document.createElement("div");R.className="maplibre-gl-choropleth-layer-item";const I=document.createElement("span");I.className="maplibre-gl-choropleth-layer-label",I.textContent=`${S.id} (${S.column}, ${S.scheme})`,I.title=`${S.url} - ${S.column}`,R.appendChild(I);const k=document.createElement("button");if(k.className="maplibre-gl-choropleth-layer-remove",k.innerHTML="×",k.title="Remove layer",k.addEventListener("click",()=>{this._removeLayer(E),this._render()}),R.appendChild(k),v.appendChild(R),S.legendColors&&S.legendLabels){const D=document.createElement("div");D.className="maplibre-gl-choropleth-legend";const F=document.createElement("div");F.style.display="flex",F.style.justifyContent="space-between",F.style.alignItems="center",F.style.marginBottom="4px";const Z=document.createElement("div");Z.className="maplibre-gl-choropleth-legend-title",Z.style.marginBottom="0",Z.textContent=S.column,F.appendChild(Z);const Y=this._legendControls.has(E),Q=document.createElement("button");Q.className=`maplibre-gl-choropleth-btn${Y?" maplibre-gl-choropleth-btn--danger":" maplibre-gl-choropleth-btn--primary"}`,Q.style.flex="0 0 auto",Q.style.padding="3px 8px",Q.style.fontSize="10px",Q.textContent=Y?"Remove Legend":"Add to Map",Q.addEventListener("click",()=>{this._legendControls.has(E)?this._removeLegendControl(E):this._addLegendControl(E,S),this._render()}),F.appendChild(Q),D.appendChild(F);for(let V=0;V<S.legendColors.length;V++){const U=document.createElement("div");U.className="maplibre-gl-choropleth-legend-item";const H=document.createElement("div");H.className="maplibre-gl-choropleth-legend-swatch",H.style.backgroundColor=S.legendColors[V],U.appendChild(H);const W=document.createElement("span");W.textContent=S.legendLabels[V]||"",U.appendChild(W),D.appendChild(U)}v.appendChild(D)}}e.appendChild(v)}this._container.appendChild(e),this._button=void 0}_createFormGroup(e,t){const i=document.createElement("div");i.className="maplibre-gl-choropleth-form-group";const n=document.createElement("label");return n.textContent=e,n.htmlFor=`choropleth-${t}`,i.appendChild(n),i}_appendStatus(e,t){if(!this._panel)return;const i=document.createElement("div");i.className=`maplibre-gl-choropleth-status maplibre-gl-choropleth-status--${t}`,i.textContent=e,this._panel.appendChild(i)}_updateColormapPreview(e,t){if(!MT(t))return;const i=jl(t).map(n=>`${n.color} ${n.position*100}%`).join(", ");e.style.background=`linear-gradient(to right, ${i})`}async _loadData(){if(!this._map||!this._state.url){this._state.error="Please enter a vector URL.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{let e=this._state.format;e==="auto"&&(e=Tle(this._state.url));let t;if(e==="geojson"){let n;try{n=await fetch(this._state.url)}catch{throw new Error("CORS error: The server doesn't allow cross-origin requests.")}if(!n.ok)throw new Error(`Failed to fetch: ${n.status} ${n.statusText}`);const r=await n.json();t=this._normalizeGeoJSON(r)}else if(e==="geoparquet")t=await this._loadGeoParquet(this._state.url);else if(e==="flatgeobuf")t=await this._loadFlatGeobuf(this._state.url);else throw new Error(`Unsupported format: ${e}`);this._cachedGeojson=t;const i=this._detectNumericColumns(t);this._cachedColumns=i,this._state.availableColumns=i,!this._state.column&&i.length>0&&(this._state.column=i[0]),this._state.loading=!1,this._state.status=`Loaded ${t.features.length} features, ${i.length} numeric columns.`,this._render()}catch(e){this._state.loading=!1,this._state.error=`Failed to load: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_detectNumericColumns(e){const t=new Map,i=Math.min(e.features.length,100);for(let r=0;r<i;r++){const s=e.features[r]?.properties;if(s)for(const[a,l]of Object.entries(s)){t.has(a)||t.set(a,{numericCount:0,totalCount:0});const h=t.get(a);h.totalCount++,typeof l=="number"&&!isNaN(l)&&h.numericCount++}}const n=[];for(const[r,s]of t)s.totalCount>0&&s.numericCount/s.totalCount>.8&&n.push(r);return n.sort()}async _addChoroplethLayer(){if(!this._map||!this._cachedGeojson||!this._state.column){this._state.error="Load data and select a column first.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{const e=this._cachedGeojson,t=this._state.column,i=this._state.k,n=this._state.scheme,r=this._state.colormap,s=this._state.opacity,a=this._state.showOutline,l=a?this._state.outlineColor:"transparent",h=this._state.extrude,d=this._state.scaleFactor,{breaks:p,bins:g}=Rle(e.features.map(te=>{const oe=te.properties?.[t];return typeof oe=="number"?oe:NaN}),n,i),v=p.length-1,y=Lle(r,v),E={type:"FeatureCollection",features:e.features.map((te,oe)=>({...te,properties:{...te.properties,_choropleth_color:y[g[oe]]||y[0],_choropleth_bin:g[oe]}}))};let S=this._state.layerName?.trim();if(!S)try{S=(new URL(this._state.url).pathname.split("/").pop()||"").replace(/\.[^.]+$/,"")}catch{}S||(S=Qu("choropleth")),S=`${S}-${t}`;const R=`${S}-source`,I=new Set;for(const te of E.features)te.geometry&&I.add(te.geometry.type);this._map.addSource(R,{type:"geojson",data:E,generateId:!0});const k=[],D=this._state.beforeId?.trim(),F=this._options.beforeId,Z=D||F,Y=Z&&this._map.getLayer(Z)?Z:void 0,Q=I.has("Polygon")||I.has("MultiPolygon"),V=I.has("LineString")||I.has("MultiLineString"),U=I.has("Point")||I.has("MultiPoint");if(Q)if(h){const te=["interpolate",["linear"],["get",t]],oe=["interpolate",["linear"],["get",t]];for(let ee=0;ee<p.length;ee++){const ae=Math.min(ee,y.length-1);te.push(p[ee],y[ae]),oe.push(p[ee],p[ee]/d)}const X=`${S}-extrusion`;this._map.addLayer({id:X,type:"fill-extrusion",source:R,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-extrusion-color":te,"fill-extrusion-height":oe,"fill-extrusion-base":10,"fill-extrusion-opacity":s}},Y),k.push(X)}else{const te=`${S}-fill`;if(this._map.addLayer({id:te,type:"fill",source:R,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"fill-color":["get","_choropleth_color"],"fill-opacity":s,"fill-outline-color":l}},Y),k.push(te),a){const oe=`${S}-outline`;this._map.addLayer({id:oe,type:"line",source:R,filter:["any",["==",["geometry-type"],"Polygon"],["==",["geometry-type"],"MultiPolygon"]],paint:{"line-color":l,"line-width":.5,"line-opacity":s}},Y),k.push(oe)}}if(V){const te=`${S}-line`;this._map.addLayer({id:te,type:"line",source:R,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"MultiLineString"]],paint:{"line-color":["get","_choropleth_color"],"line-width":2,"line-opacity":s}},Y),k.push(te)}if(U){const te=`${S}-point`;this._map.addLayer({id:te,type:"circle",source:R,filter:["any",["==",["geometry-type"],"Point"],["==",["geometry-type"],"MultiPoint"]],paint:{"circle-color":["get","_choropleth_color"],"circle-radius":6,"circle-stroke-color":l,"circle-stroke-width":a?1:0,"circle-opacity":s}},Y),k.push(te)}if(this._state.pickable&&this._map){const te=this._map;for(const oe of k)te.on("mouseenter",oe,()=>{te.getCanvas().style.cursor="pointer"}),te.on("mouseleave",oe,()=>{te.getCanvas().style.cursor=""}),te.on("click",oe,X=>{if(!X.features||X.features.length===0)return;const ee=X.features[0].properties||{},ae=Object.entries(ee).filter(([de])=>!de.startsWith("_choropleth_"));if(ae.length===0)return;let ce='<div class="maplibre-gl-choropleth-popup">';ce+='<table class="maplibre-gl-choropleth-popup-table">';for(const[de,pe]of ae){const Ie=typeof pe=="number"?Number.isInteger(pe)?pe.toString():pe.toFixed(4):String(pe);ce+=`<tr><td><strong>${de}</strong></td><td>${Ie}</td></tr>`}ce+="</table></div>",this._activePopup&&this._activePopup.remove(),this._activePopup=new ks.default.Popup({closeButton:!0,maxWidth:"300px"}).setLngLat(X.lngLat).setHTML(ce).addTo(te)})}const H=y,W=[];for(let te=0;te<p.length-1;te++){const oe=this._formatBreak(p[te]),X=this._formatBreak(p[te+1]);W.push(`${oe} – ${X}`)}const ne={id:S,url:this._state.url,sourceId:R,layerIds:k,featureCount:E.features.length,geometryTypes:Array.from(I),column:t,scheme:n,k:v,colormap:r,breaks:p,legendColors:H,legendLabels:W,opacity:s,extrude:h,scaleFactor:d};this._choroplethLayers.set(S,ne),this._state.hasLayer=this._choroplethLayers.size>0,this._state.layerCount=this._choroplethLayers.size,this._state.layers=Array.from(this._choroplethLayers.values()),this._state.loading=!1,this._state.status=`Added choropleth: ${t} (${v} classes, ${n}).`,this._options.fitBounds&&E.features.length>0&&this._fitToData(E),this._render(),this._emit("layeradd",{url:this._state.url,layerId:S})}catch(e){this._state.loading=!1,this._state.error=`Failed: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_formatBreak(e){return Math.abs(e)>=1e3?Math.round(e).toLocaleString():Math.abs(e)>=1?e.toFixed(2):Math.abs(e)>=.01?e.toFixed(4):e.toExponential(2)}_normalizeGeoJSON(e){return e.type==="FeatureCollection"?e:e.type==="Feature"?{type:"FeatureCollection",features:[e]}:{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]}}async _fetchWithCorsProxy(e){try{const i=await fetch(e,{mode:"cors"});if(i.ok)return i}catch{}const t="https://corsproxy.io/?";try{const i=await fetch(t+encodeURIComponent(e),{mode:"cors"});if(i.ok)return i}catch{}throw new Error("CORS error: Unable to fetch the file. The server doesn't allow cross-origin requests.")}async _loadGeoParquet(e){const{getDuckDBConverter:t}=await Promise.resolve().then(()=>require("./DuckDBConverter-D-Von6Le.cjs")).then(a=>a.DuckDBConverter_exports),i=t(),n=await this._fetchWithCorsProxy(e);let r;try{r=await n.arrayBuffer()}catch(a){throw new Error(`Failed to read GeoParquet response: ${a instanceof Error?a.message:String(a)}`)}let s;try{s=await i.convert(r,"data.parquet")}catch(a){throw new Error(`Failed to convert GeoParquet: ${a instanceof Error?a.message:String(a)}`)}if(s.geojson)return s.geojson;throw new Error("Failed to convert GeoParquet: No GeoJSON output")}async _loadFlatGeobuf(e){const t=await Promise.resolve().then(()=>require("./geojson-CxMdRvJX.cjs")),i=await fetch(e);if(!i.ok)throw new Error(`Failed to fetch: ${i.status} ${i.statusText}`);if(!i.body)throw new Error("Response body is null - streaming not supported");const n=[];for await(const r of t.deserialize(i.body))n.push(r);return{type:"FeatureCollection",features:n}}_fitToData(e){if(!this._map)return;let t=1/0,i=1/0,n=-1/0,r=-1/0;const s=l=>{t=Math.min(t,l[0]),n=Math.max(n,l[0]),i=Math.min(i,l[1]),r=Math.max(r,l[1])},a=l=>{for(const h of l)typeof h[0]=="number"?s(h):a(h)};for(const l of e.features){if(!l.geometry)continue;const h=l.geometry;h.type==="Point"?s(h.coordinates):(h.type==="MultiPoint"||h.type==="LineString"||h.type==="MultiLineString"||h.type==="Polygon"||h.type==="MultiPolygon")&&a(h.coordinates)}t!==1/0&&this._map.fitBounds([[t,i],[n,r]],{padding:this._options.fitBoundsPadding})}_removeLayer(e){if(this._map)if(e){const t=this._choroplethLayers.get(e);if(t){for(const i of t.layerIds)try{this._map.getLayer(i)&&this._map.removeLayer(i)}catch{}try{this._map.getSource(t.sourceId)&&this._map.removeSource(t.sourceId)}catch{}}this._choroplethLayers.delete(e),this._removeLegendControl(e),this._state.hasLayer=this._choroplethLayers.size>0,this._state.layerCount=this._choroplethLayers.size,this._state.layers=Array.from(this._choroplethLayers.values()),this._state.status=null,this._state.error=null,this._emit("layerremove",{layerId:e})}else this._removeAllLayers()}_addLegendControl(e,t){if(!this._map||this._legendControls.has(e))return;const i=t.legendColors.map((r,s)=>({label:t.legendLabels[s]||"",color:r,shape:"square"})),n=new PG({title:t.column,items:i,position:"bottom-left",collapsible:!0,collapsed:!1,visible:!0});this._map.addControl(n,"bottom-left"),this._legendControls.set(e,n)}_removeLegendControl(e){if(!this._map)return;const t=this._legendControls.get(e);t&&(this._map.removeControl(t),this._legendControls.delete(e))}_removeAllLegendControls(){if(this._map){for(const[,e]of this._legendControls)try{this._map.removeControl(e)}catch{}this._legendControls.clear()}}_removeAllLayers(){if(this._map){for(const[,e]of this._choroplethLayers){for(const t of e.layerIds)try{this._map.getLayer(t)&&this._map.removeLayer(t)}catch{}try{this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)}catch{}}this._choroplethLayers.clear(),this._removeAllLegendControls(),this._state.hasLayer=!1,this._state.layerCount=0,this._state.layers=[],this._state.status=null,this._state.error=null,this._emit("layerremove")}}},kle={position:"top-right",className:"",visible:!0,collapsed:!0,panelWidth:280,maxHeight:500,backgroundColor:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:12,fontColor:"#333",minzoom:0,maxzoom:24},Ple='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="none"><defs><linearGradient id="cbg" x1="0" y1="1" x2="0" y2="0"><stop offset="0%" stop-color="#440154"/><stop offset="25%" stop-color="#31688e"/><stop offset="50%" stop-color="#21918c"/><stop offset="75%" stop-color="#90d743"/><stop offset="100%" stop-color="#fde725"/></linearGradient></defs><rect x="8" y="2" width="8" height="20" rx="2" fill="url(#cbg)" stroke="currentColor" stroke-width="1.5"/></svg>',Nle='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',_j=class{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_colorbar;_colorbars=[];_colorbarEntries=[];_colorbarSelect;_colormapSelect;_vminInput;_vmaxInput;_labelInput;_unitsInput;_orientationSelect;_positionSelect;_addBtn;_updateBtn;_removeBtn;_previewEl;_customColorsTextarea;_modeNamedRadio;_modeCustomRadio;_namedSection;_customSection;constructor(e){this._options={...kle,...e},this._state={visible:this._options.visible,collapsed:this._options.collapsed,mode:"named",colormap:"viridis",customColors:"#440154, #31688e, #21918c, #90d743, #fde725",vmin:0,vmax:100,label:"",units:"",orientation:"vertical",colorbarPosition:"bottom-right",hasColorbar:!1,selectedColorbarIndex:-1,colorbars:[]}}onAdd(e){return this._map=e,this._container=this._createContainer(),this._setupZoomHandler(),this._state.collapsed||this._showPanel(),this._container}onRemove(){this._handleZoom&&this._map&&this._map.off("zoom",this._handleZoom),this._removeAllColorbars(),this._container?.remove(),this._container=void 0,this._map=void 0}getDefaultPosition(){return this._options.position}on(e,t){return this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t),this}off(e,t){return this._eventHandlers.get(e)?.delete(t),this}_emit(e){const t=this._eventHandlers.get(e);if(t){const i={type:e,state:{...this._state}};t.forEach(n=>n(i))}}expand(){this._state.collapsed&&(this._state.collapsed=!1,this._showPanel(),this._emit("expand"))}collapse(){this._state.collapsed||(this._state.collapsed=!0,this._hidePanel(),this._emit("collapse"))}show(){return this._state.visible=!0,this._container&&this._zoomVisible&&(this._container.style.display=""),this._emit("show"),this}hide(){return this._state.visible=!1,this._container&&(this._container.style.display="none"),this._emit("hide"),this}getState(){return{...this._state,colorbars:this._colorbarEntries.map(e=>({...e}))}}setState(e){this._map&&this._colorbars.forEach(r=>{this._map.removeControl(r)});const t=(e.colorbars??[]).map(r=>({...r}));this._colorbars=[],this._colorbarEntries=t,this._map&&t.forEach(r=>{const s=this._createColorbar(r);this._map.addControl(s,r.colorbarPosition),this._colorbars.push(s)});const i=typeof e.selectedColorbarIndex=="number"&&e.selectedColorbarIndex>=0&&e.selectedColorbarIndex<t.length?e.selectedColorbarIndex:t.length>0?t.length-1:-1,n=i>=0?t[i]:{mode:e.mode??this._state.mode,colormap:e.colormap??this._state.colormap,customColors:e.customColors??this._state.customColors,vmin:e.vmin??this._state.vmin,vmax:e.vmax??this._state.vmax,label:e.label??this._state.label,units:e.units??this._state.units,orientation:e.orientation??this._state.orientation,colorbarPosition:e.colorbarPosition??this._state.colorbarPosition};return this._state={...this._state,...n,visible:e.visible??this._state.visible,collapsed:e.collapsed??this._state.collapsed,hasColorbar:t.length>0,selectedColorbarIndex:i,colorbars:t.map(r=>({...r}))},this._colorbar=i>=0?this._colorbars[i]:void 0,this._applyEntryToForm(n),this._state.collapsed?this._hidePanel():this._showPanel(),this._container&&(this._container.style.display=this._state.visible&&this._zoomVisible?"":"none"),this._updateButtonStates(),this._emit("colorbarupdate"),this}_createContainer(){const e=document.createElement("div");return e.className=`maplibregl-ctrl maplibre-gl-colorbar-gui-control ${this._options.className}`,this._state.visible||(e.style.display="none"),this._button=document.createElement("button"),this._button.type="button",this._button.className="colorbar-gui-button",this._button.title="Colorbar",this._button.innerHTML=Ple,this._button.addEventListener("click",()=>this._togglePanel()),e.appendChild(this._button),e}_createPanel(){const e=document.createElement("div");e.className=`colorbar-gui-panel ${this._options.position.includes("left")?"right":"left"}`,e.style.width=`${this._options.panelWidth}px`,this._options.maxHeight>0&&(e.style.maxHeight=`${this._options.maxHeight}px`,e.style.overflowY="auto"),e.style.background=this._options.backgroundColor,e.style.borderRadius=`${this._options.borderRadius}px`,e.style.fontSize=`${this._options.fontSize}px`,e.style.color=this._options.fontColor;const t=document.createElement("div");t.className="colorbar-gui-header",t.innerHTML=`
|
|
252
252
|
<span>Colorbar</span>
|
|
253
253
|
<button type="button" class="colorbar-gui-close" title="Close">${Nle}</button>
|
|
254
254
|
`,t.querySelector(".colorbar-gui-close")?.addEventListener("click",()=>this._togglePanel()),e.appendChild(t);const i=document.createElement("div");i.className="colorbar-gui-content";const n=this._createField("Colorbar");this._colorbarSelect=document.createElement("select"),this._colorbarSelect.className="colorbar-gui-select",this._colorbarSelect.addEventListener("change",()=>{this._selectColorbar(parseInt(this._colorbarSelect.value,10))}),n.appendChild(this._colorbarSelect),i.appendChild(n),this._renderColorbarSelect();const r=this._createField("Color Source"),s=document.createElement("div");s.className="colorbar-gui-mode-row";const a=document.createElement("label");a.className="colorbar-gui-radio-label",this._modeNamedRadio=document.createElement("input"),this._modeNamedRadio.type="radio",this._modeNamedRadio.name="colorbar-mode",this._modeNamedRadio.checked=this._state.mode==="named",this._modeNamedRadio.addEventListener("change",()=>{this._modeNamedRadio.checked&&this._setMode("named")}),a.appendChild(this._modeNamedRadio),a.appendChild(document.createTextNode(" Named Colormap")),s.appendChild(a);const l=document.createElement("label");l.className="colorbar-gui-radio-label",this._modeCustomRadio=document.createElement("input"),this._modeCustomRadio.type="radio",this._modeCustomRadio.name="colorbar-mode",this._modeCustomRadio.checked=this._state.mode==="custom",this._modeCustomRadio.addEventListener("change",()=>{this._modeCustomRadio.checked&&this._setMode("custom")}),l.appendChild(this._modeCustomRadio),l.appendChild(document.createTextNode(" Custom Colors")),s.appendChild(l),r.appendChild(s),i.appendChild(r),this._namedSection=document.createElement("div");const h=this._createField("Colormap");this._colormapSelect=document.createElement("select"),this._colormapSelect.className="colorbar-gui-select",IT().forEach(D=>{const F=document.createElement("option");F.value=D,F.textContent=D,F.selected=D===this._state.colormap,this._colormapSelect.appendChild(F)}),this._colormapSelect.addEventListener("change",()=>{this._state.colormap=this._colormapSelect.value,this._updatePreview()}),h.appendChild(this._colormapSelect),this._namedSection.appendChild(h),i.appendChild(this._namedSection),this._customSection=document.createElement("div");const d=this._createField("Colors (comma-separated)");this._customColorsTextarea=document.createElement("textarea"),this._customColorsTextarea.className="colorbar-gui-textarea",this._customColorsTextarea.rows=3,this._customColorsTextarea.value=this._state.customColors,this._customColorsTextarea.placeholder=`e.g., red, #00ff00, blue, yellow
|
|
@@ -267,7 +267,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
267
267
|
`}[B]}}])})(),at=(function(){function B(){r(this,B)}return l(B,null,[{key:"log10",value:function(b){var w=Math.log(b);return pe.isInfinite(w)||pe.isNaN(w)?w:w/B.LOG_10}},{key:"min",value:function(b,w,L,G){var K=b;return w<K&&(K=w),L<K&&(K=L),G<K&&(K=G),K}},{key:"clamp",value:function(){if(typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var b=arguments[0],w=arguments[1],L=arguments[2];return b<w?w:b>L?L:b}if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var G=arguments[0],K=arguments[1],le=arguments[2];return G<K?K:G>le?le:G}}},{key:"wrap",value:function(b,w){return b<0?w- -b%w:b%w}},{key:"max",value:function(){if(arguments.length===3){var b=arguments[1],w=arguments[2],L=arguments[0];return b>L&&(L=b),w>L&&(L=w),L}if(arguments.length===4){var G=arguments[1],K=arguments[2],le=arguments[3],fe=arguments[0];return G>fe&&(fe=G),K>fe&&(fe=K),le>fe&&(fe=le),fe}}},{key:"average",value:function(b,w){return(b+w)/2}}])})();at.LOG_10=Math.log(10);var ei=(function(){function B(){r(this,B)}return l(B,null,[{key:"segmentToSegment",value:function(b,w,L,G){if(b.equals(w))return B.pointToSegment(b,L,G);if(L.equals(G))return B.pointToSegment(G,b,w);var K=!1;if(nt.intersects(b,w,L,G)){var le=(w.x-b.x)*(G.y-L.y)-(w.y-b.y)*(G.x-L.x);if(le===0)K=!0;else{var fe=(b.y-L.y)*(G.x-L.x)-(b.x-L.x)*(G.y-L.y),_e=((b.y-L.y)*(w.x-b.x)-(b.x-L.x)*(w.y-b.y))/le,Oe=fe/le;(Oe<0||Oe>1||_e<0||_e>1)&&(K=!0)}}else K=!0;return K?at.min(B.pointToSegment(b,L,G),B.pointToSegment(w,L,G),B.pointToSegment(L,b,w),B.pointToSegment(G,b,w)):0}},{key:"pointToSegment",value:function(b,w,L){if(w.x===L.x&&w.y===L.y)return b.distance(w);var G=(L.x-w.x)*(L.x-w.x)+(L.y-w.y)*(L.y-w.y),K=((b.x-w.x)*(L.x-w.x)+(b.y-w.y)*(L.y-w.y))/G;if(K<=0)return b.distance(w);if(K>=1)return b.distance(L);var le=((w.y-b.y)*(L.x-w.x)-(w.x-b.x)*(L.y-w.y))/G;return Math.abs(le)*Math.sqrt(G)}},{key:"pointToLinePerpendicular",value:function(b,w,L){var G=(L.x-w.x)*(L.x-w.x)+(L.y-w.y)*(L.y-w.y),K=((w.y-b.y)*(L.x-w.x)-(w.x-b.x)*(L.y-w.y))/G;return Math.abs(K)*Math.sqrt(G)}},{key:"pointToSegmentString",value:function(b,w){if(w.length===0)throw new Z("Line array must contain at least one vertex");for(var L=b.distance(w[0]),G=0;G<w.length-1;G++){var K=B.pointToSegment(b,w[G],w[G+1]);K<L&&(L=K)}return L}}])})(),oi=(function(){return l((function B(){r(this,B)}),[{key:"create",value:function(){if(arguments.length===1)arguments[0]instanceof Array||Pe(arguments[0],ct);else if(arguments.length!==2){if(arguments.length===3){var B=arguments[0],b=arguments[1];return this.create(B,b)}}}}])})(),Li=(function(){return l((function B(){r(this,B)}),[{key:"filter",value:function(B){}}])})(),si=(function(){return l((function B(){r(this,B)}),null,[{key:"ofLine",value:function(B){var b=B.size();if(b<=1)return 0;var w=0,L=new Le;B.getCoordinate(0,L);for(var G=L.x,K=L.y,le=1;le<b;le++){B.getCoordinate(le,L);var fe=L.x,_e=L.y,Oe=fe-G,ut=_e-K;w+=Math.sqrt(Oe*Oe+ut*ut),G=fe,K=_e}return w}}])})(),Ot=l((function B(){r(this,B)})),pi=(function(){function B(){r(this,B)}return l(B,null,[{key:"copyCoord",value:function(b,w,L,G){for(var K=Math.min(b.getDimension(),L.getDimension()),le=0;le<K;le++)L.setOrdinate(G,le,b.getOrdinate(w,le))}},{key:"isRing",value:function(b){var w=b.size();return w===0||!(w<=3)&&b.getOrdinate(0,ct.X)===b.getOrdinate(w-1,ct.X)&&b.getOrdinate(0,ct.Y)===b.getOrdinate(w-1,ct.Y)}},{key:"scroll",value:function(){if(arguments.length===2){if(Pe(arguments[0],ct)&&Number.isInteger(arguments[1])){var b=arguments[0],w=arguments[1];B.scroll(b,w,B.isRing(b))}else if(Pe(arguments[0],ct)&&arguments[1]instanceof Le){var L=arguments[0],G=arguments[1],K=B.indexOf(G,L);if(K<=0)return null;B.scroll(L,K)}}else if(arguments.length===3){var le=arguments[0],fe=arguments[1],_e=arguments[2];if(fe<=0)return null;for(var Oe=le.copy(),ut=_e?le.size()-1:le.size(),_t=0;_t<ut;_t++)for(var St=0;St<le.getDimension();St++)le.setOrdinate(_t,St,Oe.getOrdinate((fe+_t)%ut,St));if(_e)for(var Mi=0;Mi<le.getDimension();Mi++)le.setOrdinate(ut,Mi,le.getOrdinate(0,Mi))}}},{key:"isEqual",value:function(b,w){var L=b.size();if(L!==w.size())return!1;for(var G=Math.min(b.getDimension(),w.getDimension()),K=0;K<L;K++)for(var le=0;le<G;le++){var fe=b.getOrdinate(K,le),_e=w.getOrdinate(K,le);if(b.getOrdinate(K,le)!==w.getOrdinate(K,le)&&(!pe.isNaN(fe)||!pe.isNaN(_e)))return!1}return!0}},{key:"minCoordinateIndex",value:function(){if(arguments.length===1){var b=arguments[0];return B.minCoordinateIndex(b,0,b.size()-1)}if(arguments.length===3){for(var w=arguments[0],L=arguments[2],G=-1,K=null,le=arguments[1];le<=L;le++){var fe=w.getCoordinate(le);(K===null||K.compareTo(fe)>0)&&(K=fe,G=le)}return G}}},{key:"extend",value:function(b,w,L){var G=b.create(L,w.getDimension()),K=w.size();if(B.copy(w,0,G,0,K),K>0)for(var le=K;le<L;le++)B.copy(w,K-1,G,le,1);return G}},{key:"reverse",value:function(b){for(var w=b.size()-1,L=Math.trunc(w/2),G=0;G<=L;G++)B.swap(b,G,w-G)}},{key:"swap",value:function(b,w,L){if(w===L)return null;for(var G=0;G<b.getDimension();G++){var K=b.getOrdinate(w,G);b.setOrdinate(w,G,b.getOrdinate(L,G)),b.setOrdinate(L,G,K)}}},{key:"copy",value:function(b,w,L,G,K){for(var le=0;le<K;le++)B.copyCoord(b,w+le,L,G+le)}},{key:"ensureValidRing",value:function(b,w){var L=w.size();return L===0?w:L<=3?B.createClosedRing(b,w,4):w.getOrdinate(0,ct.X)===w.getOrdinate(L-1,ct.X)&&w.getOrdinate(0,ct.Y)===w.getOrdinate(L-1,ct.Y)?w:B.createClosedRing(b,w,L+1)}},{key:"indexOf",value:function(b,w){for(var L=0;L<w.size();L++)if(b.x===w.getOrdinate(L,ct.X)&&b.y===w.getOrdinate(L,ct.Y))return L;return-1}},{key:"createClosedRing",value:function(b,w,L){var G=b.create(L,w.getDimension()),K=w.size();B.copy(w,0,G,0,K);for(var le=K;le<L;le++)B.copy(w,0,G,le,1);return G}},{key:"minCoordinate",value:function(b){for(var w=null,L=0;L<b.size();L++){var G=b.getCoordinate(L);(w===null||w.compareTo(G)>0)&&(w=G)}return w}}])})(),Rt=(function(){function B(){r(this,B)}return l(B,null,[{key:"toDimensionSymbol",value:function(b){switch(b){case B.FALSE:return B.SYM_FALSE;case B.TRUE:return B.SYM_TRUE;case B.DONTCARE:return B.SYM_DONTCARE;case B.P:return B.SYM_P;case B.L:return B.SYM_L;case B.A:return B.SYM_A}throw new Z("Unknown dimension value: "+b)}},{key:"toDimensionValue",value:function(b){switch(ht.toUpperCase(b)){case B.SYM_FALSE:return B.FALSE;case B.SYM_TRUE:return B.TRUE;case B.SYM_DONTCARE:return B.DONTCARE;case B.SYM_P:return B.P;case B.SYM_L:return B.L;case B.SYM_A:return B.A}throw new Z("Unknown dimension symbol: "+b)}}])})();Rt.P=0,Rt.L=1,Rt.A=2,Rt.FALSE=-1,Rt.TRUE=-2,Rt.DONTCARE=-3,Rt.SYM_FALSE="F",Rt.SYM_TRUE="T",Rt.SYM_DONTCARE="*",Rt.SYM_P="0",Rt.SYM_L="1",Rt.SYM_A="2";var Ln=(function(){return l((function B(){r(this,B)}),[{key:"filter",value:function(B){}}])})(),sn=(function(){return l((function B(){r(this,B)}),[{key:"filter",value:function(B,b){}},{key:"isDone",value:function(){}},{key:"isGeometryChanged",value:function(){}}])})(),_r=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"computeEnvelopeInternal",value:function(){return this.isEmpty()?new nt:this._points.expandEnvelope(new nt)}},{key:"isRing",value:function(){return this.isClosed()&&this.isSimple()}},{key:"getCoordinates",value:function(){return this._points.toCoordinateArray()}},{key:"copyInternal",value:function(){return new b(this._points.copy(),this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof lt){var w=arguments[0],L=arguments[1];if(!this.isEquivalentClass(w))return!1;var G=w;if(this._points.size()!==G._points.size())return!1;for(var K=0;K<this._points.size();K++)if(!this.equal(this._points.getCoordinate(K),G._points.getCoordinate(K),L))return!1;return!0}return E(b,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var w=0;w<Math.trunc(this._points.size()/2);w++){var L=this._points.size()-1-w;if(!this._points.getCoordinate(w).equals(this._points.getCoordinate(L))){if(this._points.getCoordinate(w).compareTo(this._points.getCoordinate(L))>0){var G=this._points.copy();pi.reverse(G),this._points=G}return null}}}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._points.getCoordinate(0)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?Rt.FALSE:0}},{key:"isClosed",value:function(){return!this.isEmpty()&&this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints()-1))}},{key:"reverseInternal",value:function(){var w=this._points.copy();return pi.reverse(w),this.getFactory().createLineString(w)}},{key:"getEndPoint",value:function(){return this.isEmpty()?null:this.getPointN(this.getNumPoints()-1)}},{key:"getTypeCode",value:function(){return lt.TYPECODE_LINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getLength",value:function(){return si.ofLine(this._points)}},{key:"getNumPoints",value:function(){return this._points.size()}},{key:"compareToSameClass",value:function(){if(arguments.length===1){for(var w=arguments[0],L=0,G=0;L<this._points.size()&&G<w._points.size();){var K=this._points.getCoordinate(L).compareTo(w._points.getCoordinate(G));if(K!==0)return K;L++,G++}return L<this._points.size()?1:G<w._points.size()?-1:0}if(arguments.length===2){var le=arguments[0];return arguments[1].compare(this._points,le._points)}}},{key:"apply",value:function(){if(Pe(arguments[0],Li))for(var w=arguments[0],L=0;L<this._points.size();L++)w.filter(this._points.getCoordinate(L));else if(Pe(arguments[0],sn)){var G=arguments[0];if(this._points.size()===0)return null;for(var K=0;K<this._points.size()&&(G.filter(this._points,K),!G.isDone());K++);G.isGeometryChanged()&&this.geometryChanged()}else Pe(arguments[0],Ln)?arguments[0].filter(this):Pe(arguments[0],Y)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){throw new $t}},{key:"isEquivalentClass",value:function(w){return w instanceof b}},{key:"getCoordinateN",value:function(w){return this._points.getCoordinate(w)}},{key:"getGeometryType",value:function(){return lt.TYPENAME_LINESTRING}},{key:"getCoordinateSequence",value:function(){return this._points}},{key:"isEmpty",value:function(){return this._points.size()===0}},{key:"init",value:function(w){if(w===null&&(w=this.getFactory().getCoordinateSequenceFactory().create([])),w.size()===1)throw new Z("Invalid number of points in LineString (found "+w.size()+" - must be 0 or >= 2)");this._points=w}},{key:"isCoordinate",value:function(w){for(var L=0;L<this._points.size();L++)if(this._points.getCoordinate(L).equals(w))return!0;return!1}},{key:"getStartPoint",value:function(){return this.isEmpty()?null:this.getPointN(0)}},{key:"getPointN",value:function(w){return this.getFactory().createPoint(this._points.getCoordinate(w))}},{key:"interfaces_",get:function(){return[Ot]}}],[{key:"constructor_",value:function(){if(this._points=null,arguments.length!==0){if(arguments.length===2){var w=arguments[0],L=arguments[1];lt.constructor_.call(this,L),this.init(w)}}}}])})(lt),Ar=l((function B(){r(this,B)})),sr=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"computeEnvelopeInternal",value:function(){if(this.isEmpty())return new nt;var w=new nt;return w.expandToInclude(this._coordinates.getX(0),this._coordinates.getY(0)),w}},{key:"getCoordinates",value:function(){return this.isEmpty()?[]:[this.getCoordinate()]}},{key:"copyInternal",value:function(){return new b(this._coordinates.copy(),this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof lt){var w=arguments[0],L=arguments[1];return!!this.isEquivalentClass(w)&&(!(!this.isEmpty()||!w.isEmpty())||this.isEmpty()===w.isEmpty()&&this.equal(w.getCoordinate(),this.getCoordinate(),L))}return E(b,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){}},{key:"getCoordinate",value:function(){return this._coordinates.size()!==0?this._coordinates.getCoordinate(0):null}},{key:"getBoundaryDimension",value:function(){return Rt.FALSE}},{key:"reverseInternal",value:function(){return this.getFactory().createPoint(this._coordinates.copy())}},{key:"getTypeCode",value:function(){return lt.TYPECODE_POINT}},{key:"getDimension",value:function(){return 0}},{key:"getNumPoints",value:function(){return this.isEmpty()?0:1}},{key:"getX",value:function(){if(this.getCoordinate()===null)throw new IllegalStateException("getX called on empty Point");return this.getCoordinate().x}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var w=arguments[0];return this.getCoordinate().compareTo(w.getCoordinate())}if(arguments.length===2){var L=arguments[0];return arguments[1].compare(this._coordinates,L._coordinates)}}},{key:"apply",value:function(){if(Pe(arguments[0],Li)){var w=arguments[0];if(this.isEmpty())return null;w.filter(this.getCoordinate())}else if(Pe(arguments[0],sn)){var L=arguments[0];if(this.isEmpty())return null;L.filter(this._coordinates,0),L.isGeometryChanged()&&this.geometryChanged()}else Pe(arguments[0],Ln)?arguments[0].filter(this):Pe(arguments[0],Y)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return lt.TYPENAME_POINT}},{key:"getCoordinateSequence",value:function(){return this._coordinates}},{key:"getY",value:function(){if(this.getCoordinate()===null)throw new IllegalStateException("getY called on empty Point");return this.getCoordinate().y}},{key:"isEmpty",value:function(){return this._coordinates.size()===0}},{key:"init",value:function(w){w===null&&(w=this.getFactory().getCoordinateSequenceFactory().create([])),Se.isTrue(w.size()<=1),this._coordinates=w}},{key:"isSimple",value:function(){return!0}},{key:"interfaces_",get:function(){return[Ar]}}],[{key:"constructor_",value:function(){this._coordinates=null;var w=arguments[0],L=arguments[1];lt.constructor_.call(this,L),this.init(w)}}])})(lt),kr=(function(){function B(){r(this,B)}return l(B,null,[{key:"ofRing",value:function(){if(arguments[0]instanceof Array){var b=arguments[0];return Math.abs(B.ofRingSigned(b))}if(Pe(arguments[0],ct)){var w=arguments[0];return Math.abs(B.ofRingSigned(w))}}},{key:"ofRingSigned",value:function(){if(arguments[0]instanceof Array){var b=arguments[0];if(b.length<3)return 0;for(var w=0,L=b[0].x,G=1;G<b.length-1;G++){var K=b[G].x-L,le=b[G+1].y;w+=K*(b[G-1].y-le)}return w/2}if(Pe(arguments[0],ct)){var fe=arguments[0],_e=fe.size();if(_e<3)return 0;var Oe=new Le,ut=new Le,_t=new Le;fe.getCoordinate(0,ut),fe.getCoordinate(1,_t);var St=ut.x;_t.x-=St;for(var Mi=0,an=1;an<_e-1;an++)Oe.y=ut.y,ut.x=_t.x,ut.y=_t.y,fe.getCoordinate(an+1,_t),_t.x-=St,Mi+=ut.x*(Oe.y-_t.y);return Mi/2}}}])})(),Qe=(function(){return l((function B(){r(this,B)}),null,[{key:"sort",value:function(){var B=arguments,b=arguments[0];if(arguments.length===1)b.sort((function(St,Mi){return St.compareTo(Mi)}));else if(arguments.length===2)b.sort((function(St,Mi){return B[1].compare(St,Mi)}));else if(arguments.length===3){var w=b.slice(arguments[1],arguments[2]);w.sort();var L=b.slice(0,arguments[1]).concat(w,b.slice(arguments[2],b.length));b.splice(0,b.length);var G,K=h(L);try{for(K.s();!(G=K.n()).done;){var le=G.value;b.push(le)}}catch(St){K.e(St)}finally{K.f()}}else if(arguments.length===4){var fe=b.slice(arguments[1],arguments[2]);fe.sort((function(St,Mi){return B[3].compare(St,Mi)}));var _e=b.slice(0,arguments[1]).concat(fe,b.slice(arguments[2],b.length));b.splice(0,b.length);var Oe,ut=h(_e);try{for(ut.s();!(Oe=ut.n()).done;){var _t=Oe.value;b.push(_t)}}catch(St){ut.e(St)}finally{ut.f()}}}},{key:"asList",value:function(B){var b,w=new Pt,L=h(B);try{for(L.s();!(b=L.n()).done;){var G=b.value;w.add(G)}}catch(K){L.e(K)}finally{L.f()}return w}},{key:"copyOf",value:function(B,b){return B.slice(0,b)}}])})(),dt=l((function B(){r(this,B)})),yt=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"computeEnvelopeInternal",value:function(){return this._shell.getEnvelopeInternal()}},{key:"getCoordinates",value:function(){if(this.isEmpty())return[];for(var w=new Array(this.getNumPoints()).fill(null),L=-1,G=this._shell.getCoordinates(),K=0;K<G.length;K++)w[++L]=G[K];for(var le=0;le<this._holes.length;le++)for(var fe=this._holes[le].getCoordinates(),_e=0;_e<fe.length;_e++)w[++L]=fe[_e];return w}},{key:"getArea",value:function(){var w=0;w+=kr.ofRing(this._shell.getCoordinateSequence());for(var L=0;L<this._holes.length;L++)w-=kr.ofRing(this._holes[L].getCoordinateSequence());return w}},{key:"copyInternal",value:function(){for(var w=this._shell.copy(),L=new Array(this._holes.length).fill(null),G=0;G<this._holes.length;G++)L[G]=this._holes[G].copy();return new b(w,L,this._factory)}},{key:"isRectangle",value:function(){if(this.getNumInteriorRing()!==0||this._shell===null||this._shell.getNumPoints()!==5)return!1;for(var w=this._shell.getCoordinateSequence(),L=this.getEnvelopeInternal(),G=0;G<5;G++){var K=w.getX(G);if(K!==L.getMinX()&&K!==L.getMaxX())return!1;var le=w.getY(G);if(le!==L.getMinY()&&le!==L.getMaxY())return!1}for(var fe=w.getX(0),_e=w.getY(0),Oe=1;Oe<=4;Oe++){var ut=w.getX(Oe),_t=w.getY(Oe);if(ut!==fe==(_t!==_e))return!1;fe=ut,_e=_t}return!0}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof lt){var w=arguments[0],L=arguments[1];if(!this.isEquivalentClass(w))return!1;var G=w,K=this._shell,le=G._shell;if(!K.equalsExact(le,L)||this._holes.length!==G._holes.length)return!1;for(var fe=0;fe<this._holes.length;fe++)if(!this._holes[fe].equalsExact(G._holes[fe],L))return!1;return!0}return E(b,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){if(arguments.length===0){this._shell=this.normalized(this._shell,!0);for(var w=0;w<this._holes.length;w++)this._holes[w]=this.normalized(this._holes[w],!1);Qe.sort(this._holes)}else if(arguments.length===2){var L=arguments[0],G=arguments[1];if(L.isEmpty())return null;var K=L.getCoordinateSequence(),le=pi.minCoordinateIndex(K,0,K.size()-2);pi.scroll(K,le,!0),et.isCCW(K)===G&&pi.reverse(K)}}},{key:"getCoordinate",value:function(){return this._shell.getCoordinate()}},{key:"getNumInteriorRing",value:function(){return this._holes.length}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"reverseInternal",value:function(){for(var w=this.getExteriorRing().reverse(),L=new Array(this.getNumInteriorRing()).fill(null),G=0;G<L.length;G++)L[G]=this.getInteriorRingN(G).reverse();return this.getFactory().createPolygon(w,L)}},{key:"getTypeCode",value:function(){return lt.TYPECODE_POLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getLength",value:function(){var w=0;w+=this._shell.getLength();for(var L=0;L<this._holes.length;L++)w+=this._holes[L].getLength();return w}},{key:"getNumPoints",value:function(){for(var w=this._shell.getNumPoints(),L=0;L<this._holes.length;L++)w+=this._holes[L].getNumPoints();return w}},{key:"convexHull",value:function(){return this.getExteriorRing().convexHull()}},{key:"normalized",value:function(w,L){var G=w.copy();return this.normalize(G,L),G}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var w=arguments[0],L=this._shell,G=w._shell;return L.compareToSameClass(G)}if(arguments.length===2){var K=arguments[1],le=arguments[0],fe=this._shell,_e=le._shell,Oe=fe.compareToSameClass(_e,K);if(Oe!==0)return Oe;for(var ut=this.getNumInteriorRing(),_t=le.getNumInteriorRing(),St=0;St<ut&&St<_t;){var Mi=this.getInteriorRingN(St),an=le.getInteriorRingN(St),mn=Mi.compareToSameClass(an,K);if(mn!==0)return mn;St++}return St<ut?1:St<_t?-1:0}}},{key:"apply",value:function(){if(Pe(arguments[0],Li)){var w=arguments[0];this._shell.apply(w);for(var L=0;L<this._holes.length;L++)this._holes[L].apply(w)}else if(Pe(arguments[0],sn)){var G=arguments[0];if(this._shell.apply(G),!G.isDone())for(var K=0;K<this._holes.length&&(this._holes[K].apply(G),!G.isDone());K++);G.isGeometryChanged()&&this.geometryChanged()}else if(Pe(arguments[0],Ln))arguments[0].filter(this);else if(Pe(arguments[0],Y)){var le=arguments[0];le.filter(this),this._shell.apply(le);for(var fe=0;fe<this._holes.length;fe++)this._holes[fe].apply(le)}}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();var w=new Array(this._holes.length+1).fill(null);w[0]=this._shell;for(var L=0;L<this._holes.length;L++)w[L+1]=this._holes[L];return w.length<=1?this.getFactory().createLinearRing(w[0].getCoordinateSequence()):this.getFactory().createMultiLineString(w)}},{key:"getGeometryType",value:function(){return lt.TYPENAME_POLYGON}},{key:"getExteriorRing",value:function(){return this._shell}},{key:"isEmpty",value:function(){return this._shell.isEmpty()}},{key:"getInteriorRingN",value:function(w){return this._holes[w]}},{key:"interfaces_",get:function(){return[dt]}}],[{key:"constructor_",value:function(){this._shell=null,this._holes=null;var w=arguments[0],L=arguments[1],G=arguments[2];if(lt.constructor_.call(this,G),w===null&&(w=this.getFactory().createLinearRing()),L===null&&(L=[]),lt.hasNullElements(L))throw new Z("holes must not contain null elements");if(w.isEmpty()&<.hasNonEmptyElements(L))throw new Z("shell is empty but holes are not");this._shell=w,this._holes=L}}])})(lt),Bt=(function(B){function b(w){var L;return r(this,b),(L=n(this,b)).array=[],w instanceof vt&&L.addAll(w),L}return g(b,B),l(b,[{key:"contains",value:function(w){var L,G=h(this.array);try{for(G.s();!(L=G.n()).done;)if(L.value.compareTo(w)===0)return!0}catch(K){G.e(K)}finally{G.f()}return!1}},{key:"add",value:function(w){if(this.contains(w))return!1;for(var L=0,G=this.array.length;L<G;L++)if(this.array[L].compareTo(w)===1)return!!this.array.splice(L,0,w);return this.array.push(w),!0}},{key:"addAll",value:function(w){var L,G=h(w);try{for(G.s();!(L=G.n()).done;){var K=L.value;this.add(K)}}catch(le){G.e(le)}finally{G.f()}return!0}},{key:"remove",value:function(){throw new $t}},{key:"size",value:function(){return this.array.length}},{key:"isEmpty",value:function(){return this.array.length===0}},{key:"toArray",value:function(){return this.array.slice()}},{key:"iterator",value:function(){return new Ut(this.array)}}])})((function(B){function b(){return r(this,b),n(this,b,arguments)}return g(b,B),l(b)})(It)),Ut=(function(){return l((function B(b){r(this,B),this.array=b,this.position=0}),[{key:"next",value:function(){if(this.position===this.array.length)throw new Ne;return this.array[this.position++]}},{key:"hasNext",value:function(){return this.position<this.array.length}},{key:"remove",value:function(){throw new $t}}])})(),Zt=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"computeEnvelopeInternal",value:function(){for(var w=new nt,L=0;L<this._geometries.length;L++)w.expandToInclude(this._geometries[L].getEnvelopeInternal());return w}},{key:"getGeometryN",value:function(w){return this._geometries[w]}},{key:"getCoordinates",value:function(){for(var w=new Array(this.getNumPoints()).fill(null),L=-1,G=0;G<this._geometries.length;G++)for(var K=this._geometries[G].getCoordinates(),le=0;le<K.length;le++)w[++L]=K[le];return w}},{key:"getArea",value:function(){for(var w=0,L=0;L<this._geometries.length;L++)w+=this._geometries[L].getArea();return w}},{key:"copyInternal",value:function(){for(var w=new Array(this._geometries.length).fill(null),L=0;L<w.length;L++)w[L]=this._geometries[L].copy();return new b(w,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof lt){var w=arguments[0],L=arguments[1];if(!this.isEquivalentClass(w))return!1;var G=w;if(this._geometries.length!==G._geometries.length)return!1;for(var K=0;K<this._geometries.length;K++)if(!this._geometries[K].equalsExact(G._geometries[K],L))return!1;return!0}return E(b,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var w=0;w<this._geometries.length;w++)this._geometries[w].normalize();Qe.sort(this._geometries)}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._geometries[0].getCoordinate()}},{key:"getBoundaryDimension",value:function(){for(var w=Rt.FALSE,L=0;L<this._geometries.length;L++)w=Math.max(w,this._geometries[L].getBoundaryDimension());return w}},{key:"reverseInternal",value:function(){for(var w=this._geometries.length,L=new Pt(w),G=0;G<w;G++)L.add(this._geometries[G].reverse());return this.getFactory().buildGeometry(L)}},{key:"getTypeCode",value:function(){return lt.TYPECODE_GEOMETRYCOLLECTION}},{key:"getDimension",value:function(){for(var w=Rt.FALSE,L=0;L<this._geometries.length;L++)w=Math.max(w,this._geometries[L].getDimension());return w}},{key:"getLength",value:function(){for(var w=0,L=0;L<this._geometries.length;L++)w+=this._geometries[L].getLength();return w}},{key:"getNumPoints",value:function(){for(var w=0,L=0;L<this._geometries.length;L++)w+=this._geometries[L].getNumPoints();return w}},{key:"getNumGeometries",value:function(){return this._geometries.length}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var w=arguments[0],L=new Bt(Qe.asList(this._geometries)),G=new Bt(Qe.asList(w._geometries));return this.compare(L,G)}if(arguments.length===2){for(var K=arguments[1],le=arguments[0],fe=this.getNumGeometries(),_e=le.getNumGeometries(),Oe=0;Oe<fe&&Oe<_e;){var ut=this.getGeometryN(Oe),_t=le.getGeometryN(Oe),St=ut.compareToSameClass(_t,K);if(St!==0)return St;Oe++}return Oe<fe?1:Oe<_e?-1:0}}},{key:"apply",value:function(){if(Pe(arguments[0],Li))for(var w=arguments[0],L=0;L<this._geometries.length;L++)this._geometries[L].apply(w);else if(Pe(arguments[0],sn)){var G=arguments[0];if(this._geometries.length===0)return null;for(var K=0;K<this._geometries.length&&(this._geometries[K].apply(G),!G.isDone());K++);G.isGeometryChanged()&&this.geometryChanged()}else if(Pe(arguments[0],Ln)){var le=arguments[0];le.filter(this);for(var fe=0;fe<this._geometries.length;fe++)this._geometries[fe].apply(le)}else if(Pe(arguments[0],Y)){var _e=arguments[0];_e.filter(this);for(var Oe=0;Oe<this._geometries.length;Oe++)this._geometries[Oe].apply(_e)}}},{key:"getBoundary",value:function(){return lt.checkNotGeometryCollection(this),Se.shouldNeverReachHere(),null}},{key:"getGeometryType",value:function(){return lt.TYPENAME_GEOMETRYCOLLECTION}},{key:"isEmpty",value:function(){for(var w=0;w<this._geometries.length;w++)if(!this._geometries[w].isEmpty())return!1;return!0}}],[{key:"constructor_",value:function(){if(this._geometries=null,arguments.length!==0){if(arguments.length===2){var w=arguments[0],L=arguments[1];if(lt.constructor_.call(this,L),w===null&&(w=[]),lt.hasNullElements(w))throw new Z("geometries must not contain null elements");this._geometries=w}}}}])})(lt),ki=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"copyInternal",value:function(){for(var w=new Array(this._geometries.length).fill(null),L=0;L<w.length;L++)w[L]=this._geometries[L].copy();return new b(w,this._factory)}},{key:"isValid",value:function(){return!0}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof lt){var w=arguments[0],L=arguments[1];return!!this.isEquivalentClass(w)&&E(b,"equalsExact",this,1).call(this,w,L)}return E(b,"equalsExact",this,1).apply(this,arguments)}},{key:"getCoordinate",value:function(){if(arguments.length===1&&Number.isInteger(arguments[0])){var w=arguments[0];return this._geometries[w].getCoordinate()}return E(b,"getCoordinate",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return Rt.FALSE}},{key:"getTypeCode",value:function(){return lt.TYPECODE_MULTIPOINT}},{key:"getDimension",value:function(){return 0}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return lt.TYPENAME_MULTIPOINT}},{key:"interfaces_",get:function(){return[Ar]}}],[{key:"constructor_",value:function(){var w=arguments[0],L=arguments[1];Zt.constructor_.call(this,w,L)}}])})(Zt),nn=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"copyInternal",value:function(){return new b(this._points.copy(),this._factory)}},{key:"getBoundaryDimension",value:function(){return Rt.FALSE}},{key:"isClosed",value:function(){return!!this.isEmpty()||E(b,"isClosed",this,1).call(this)}},{key:"reverseInternal",value:function(){var w=this._points.copy();return pi.reverse(w),this.getFactory().createLinearRing(w)}},{key:"getTypeCode",value:function(){return lt.TYPECODE_LINEARRING}},{key:"validateConstruction",value:function(){if(!this.isEmpty()&&!E(b,"isClosed",this,1).call(this))throw new Z("Points of LinearRing do not form a closed linestring");if(this.getCoordinateSequence().size()>=1&&this.getCoordinateSequence().size()<b.MINIMUM_VALID_SIZE)throw new Z("Invalid number of points in LinearRing (found "+this.getCoordinateSequence().size()+" - must be 0 or >= 4)")}},{key:"getGeometryType",value:function(){return lt.TYPENAME_LINEARRING}}],[{key:"constructor_",value:function(){var w=arguments[0],L=arguments[1];_r.constructor_.call(this,w,L),this.validateConstruction()}}])})(_r);nn.MINIMUM_VALID_SIZE=4;var Ei=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"setOrdinate",value:function(w,L){switch(w){case b.X:this.x=L;break;case b.Y:this.y=L;break;default:throw new Z("Invalid ordinate index: "+w)}}},{key:"getZ",value:function(){return Le.NULL_ORDINATE}},{key:"getOrdinate",value:function(w){switch(w){case b.X:return this.x;case b.Y:return this.y}throw new Z("Invalid ordinate index: "+w)}},{key:"setZ",value:function(w){throw new Z("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new b(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+")"}},{key:"setCoordinate",value:function(w){this.x=w.x,this.y=w.y,this.z=w.getZ()}}],[{key:"constructor_",value:function(){if(arguments.length===0)Le.constructor_.call(this);else if(arguments.length===1){if(arguments[0]instanceof b){var w=arguments[0];Le.constructor_.call(this,w.x,w.y)}else if(arguments[0]instanceof Le){var L=arguments[0];Le.constructor_.call(this,L.x,L.y)}}else if(arguments.length===2){var G=arguments[0],K=arguments[1];Le.constructor_.call(this,G,K,Le.NULL_ORDINATE)}}}])})(Le);Ei.X=0,Ei.Y=1,Ei.Z=-1,Ei.M=-1;var yn=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(w,L){switch(w){case b.X:this.x=L;break;case b.Y:this.y=L;break;case b.M:this._m=L;break;default:throw new Z("Invalid ordinate index: "+w)}}},{key:"setM",value:function(w){this._m=w}},{key:"getZ",value:function(){return Le.NULL_ORDINATE}},{key:"getOrdinate",value:function(w){switch(w){case b.X:return this.x;case b.Y:return this.y;case b.M:return this._m}throw new Z("Invalid ordinate index: "+w)}},{key:"setZ",value:function(w){throw new Z("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new b(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(w){this.x=w.x,this.y=w.y,this.z=w.getZ(),this._m=w.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,arguments.length===0)Le.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof b){var w=arguments[0];Le.constructor_.call(this,w.x,w.y),this._m=w._m}else if(arguments[0]instanceof Le){var L=arguments[0];Le.constructor_.call(this,L.x,L.y),this._m=this.getM()}}else if(arguments.length===3){var G=arguments[0],K=arguments[1],le=arguments[2];Le.constructor_.call(this,G,K,Le.NULL_ORDINATE),this._m=le}}}])})(Le);yn.X=0,yn.Y=1,yn.Z=-1,yn.M=2;var _n=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(w,L){switch(w){case Le.X:this.x=L;break;case Le.Y:this.y=L;break;case Le.Z:this.z=L;break;case Le.M:this._m=L;break;default:throw new Z("Invalid ordinate index: "+w)}}},{key:"setM",value:function(w){this._m=w}},{key:"getOrdinate",value:function(w){switch(w){case Le.X:return this.x;case Le.Y:return this.y;case Le.Z:return this.getZ();case Le.M:return this.getM()}throw new Z("Invalid ordinate index: "+w)}},{key:"copy",value:function(){return new b(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(w){this.x=w.x,this.y=w.y,this.z=w.getZ(),this._m=w.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,arguments.length===0)Le.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof b){var w=arguments[0];Le.constructor_.call(this,w),this._m=w._m}else if(arguments[0]instanceof Le){var L=arguments[0];Le.constructor_.call(this,L),this._m=this.getM()}}else if(arguments.length===4){var G=arguments[0],K=arguments[1],le=arguments[2],fe=arguments[3];Le.constructor_.call(this,G,K,le),this._m=fe}}}])})(Le),An=(function(){function B(){r(this,B)}return l(B,null,[{key:"measures",value:function(b){return b instanceof Ei?0:b instanceof yn||b instanceof _n?1:0}},{key:"dimension",value:function(b){return b instanceof Ei?2:b instanceof yn?3:b instanceof _n?4:3}},{key:"create",value:function(){if(arguments.length===1){var b=arguments[0];return B.create(b,0)}if(arguments.length===2){var w=arguments[0],L=arguments[1];return w===2?new Ei:w===3&&L===0?new Le:w===3&&L===1?new yn:w===4&&L===1?new _n:new Le}}}])})(),kn=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"getCoordinate",value:function(w){return this.get(w)}},{key:"addAll",value:function(){if(arguments.length===2&&typeof arguments[1]=="boolean"&&Pe(arguments[0],vt)){for(var w=arguments[1],L=!1,G=arguments[0].iterator();G.hasNext();)this.add(G.next(),w),L=!0;return L}return E(b,"addAll",this,1).apply(this,arguments)}},{key:"clone",value:function(){for(var w=E(b,"clone",this,1).call(this),L=0;L<this.size();L++)w.add(L,this.get(L).clone());return w}},{key:"toCoordinateArray",value:function(){if(arguments.length===0)return this.toArray(b.coordArrayType);if(arguments.length===1){if(arguments[0])return this.toArray(b.coordArrayType);for(var w=this.size(),L=new Array(w).fill(null),G=0;G<w;G++)L[G]=this.get(w-G-1);return L}}},{key:"add",value:function(){if(arguments.length===1){var w=arguments[0];return E(b,"add",this,1).call(this,w)}if(arguments.length===2){if(arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){var L=arguments[0],G=arguments[1];return this.add(L,G,!0),!0}if(arguments[0]instanceof Le&&typeof arguments[1]=="boolean"){var K=arguments[0];if(!arguments[1]&&this.size()>=1&&this.get(this.size()-1).equals2D(K))return null;E(b,"add",this,1).call(this,K)}else if(arguments[0]instanceof Object&&typeof arguments[1]=="boolean"){var le=arguments[0],fe=arguments[1];return this.add(le,fe),!0}}else if(arguments.length===3){if(typeof arguments[2]=="boolean"&&arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){var _e=arguments[0],Oe=arguments[1];if(arguments[2])for(var ut=0;ut<_e.length;ut++)this.add(_e[ut],Oe);else for(var _t=_e.length-1;_t>=0;_t--)this.add(_e[_t],Oe);return!0}if(typeof arguments[2]=="boolean"&&Number.isInteger(arguments[0])&&arguments[1]instanceof Le){var St=arguments[0],Mi=arguments[1];if(!arguments[2]){var an=this.size();if(an>0&&(St>0&&this.get(St-1).equals2D(Mi)||St<an&&this.get(St).equals2D(Mi)))return null}E(b,"add",this,1).call(this,St,Mi)}}else if(arguments.length===4){var mn=arguments[0],tr=arguments[1],Qi=arguments[2],vr=arguments[3],Hs=1;Qi>vr&&(Hs=-1);for(var Os=Qi;Os!==vr;Os+=Hs)this.add(mn[Os],tr);return!0}}},{key:"closeRing",value:function(){if(this.size()>0){var w=this.get(0).copy();this.add(w,!1)}}}],[{key:"constructor_",value:function(){if(arguments.length!==0){if(arguments.length===1){var w=arguments[0];this.ensureCapacity(w.length),this.add(w,!0)}else if(arguments.length===2){var L=arguments[0],G=arguments[1];this.ensureCapacity(L.length),this.add(L,G)}}}}])})(Pt);kn.coordArrayType=new Array(0).fill(null);var $n=(function(){function B(){r(this,B)}return l(B,null,[{key:"isRing",value:function(b){return!(b.length<4)&&!!b[0].equals2D(b[b.length-1])}},{key:"ptNotInList",value:function(b,w){for(var L=0;L<b.length;L++){var G=b[L];if(B.indexOf(G,w)<0)return G}return null}},{key:"scroll",value:function(b,w){var L=B.indexOf(w,b);if(L<0)return null;var G=new Array(b.length).fill(null);Hi.arraycopy(b,L,G,0,b.length-L),Hi.arraycopy(b,0,G,b.length-L,L),Hi.arraycopy(G,0,b,0,b.length)}},{key:"equals",value:function(){if(arguments.length===2){var b=arguments[0],w=arguments[1];if(b===w)return!0;if(b===null||w===null||b.length!==w.length)return!1;for(var L=0;L<b.length;L++)if(!b[L].equals(w[L]))return!1;return!0}if(arguments.length===3){var G=arguments[0],K=arguments[1],le=arguments[2];if(G===K)return!0;if(G===null||K===null||G.length!==K.length)return!1;for(var fe=0;fe<G.length;fe++)if(le.compare(G[fe],K[fe])!==0)return!1;return!0}}},{key:"intersection",value:function(b,w){for(var L=new kn,G=0;G<b.length;G++)w.intersects(b[G])&&L.add(b[G],!0);return L.toCoordinateArray()}},{key:"measures",value:function(b){if(b===null||b.length===0)return 0;var w,L=0,G=h(b);try{for(G.s();!(w=G.n()).done;){var K=w.value;L=Math.max(L,An.measures(K))}}catch(le){G.e(le)}finally{G.f()}return L}},{key:"hasRepeatedPoints",value:function(b){for(var w=1;w<b.length;w++)if(b[w-1].equals(b[w]))return!0;return!1}},{key:"removeRepeatedPoints",value:function(b){return B.hasRepeatedPoints(b)?new kn(b,!1).toCoordinateArray():b}},{key:"reverse",value:function(b){for(var w=b.length-1,L=Math.trunc(w/2),G=0;G<=L;G++){var K=b[G];b[G]=b[w-G],b[w-G]=K}}},{key:"removeNull",value:function(b){for(var w=0,L=0;L<b.length;L++)b[L]!==null&&w++;var G=new Array(w).fill(null);if(w===0)return G;for(var K=0,le=0;le<b.length;le++)b[le]!==null&&(G[K++]=b[le]);return G}},{key:"copyDeep",value:function(){if(arguments.length===1){for(var b=arguments[0],w=new Array(b.length).fill(null),L=0;L<b.length;L++)w[L]=b[L].copy();return w}if(arguments.length===5)for(var G=arguments[0],K=arguments[1],le=arguments[2],fe=arguments[3],_e=arguments[4],Oe=0;Oe<_e;Oe++)le[fe+Oe]=G[K+Oe].copy()}},{key:"isEqualReversed",value:function(b,w){for(var L=0;L<b.length;L++){var G=b[L],K=w[b.length-L-1];if(G.compareTo(K)!==0)return!1}return!0}},{key:"envelope",value:function(b){for(var w=new nt,L=0;L<b.length;L++)w.expandToInclude(b[L]);return w}},{key:"toCoordinateArray",value:function(b){return b.toArray(B.coordArrayType)}},{key:"dimension",value:function(b){if(b===null||b.length===0)return 3;var w,L=0,G=h(b);try{for(G.s();!(w=G.n()).done;){var K=w.value;L=Math.max(L,An.dimension(K))}}catch(le){G.e(le)}finally{G.f()}return L}},{key:"atLeastNCoordinatesOrNothing",value:function(b,w){return w.length>=b?w:[]}},{key:"indexOf",value:function(b,w){for(var L=0;L<w.length;L++)if(b.equals(w[L]))return L;return-1}},{key:"increasingDirection",value:function(b){for(var w=0;w<Math.trunc(b.length/2);w++){var L=b.length-1-w,G=b[w].compareTo(b[L]);if(G!==0)return G}return 1}},{key:"compare",value:function(b,w){for(var L=0;L<b.length&&L<w.length;){var G=b[L].compareTo(w[L]);if(G!==0)return G;L++}return L<w.length?-1:L<b.length?1:0}},{key:"minCoordinate",value:function(b){for(var w=null,L=0;L<b.length;L++)(w===null||w.compareTo(b[L])>0)&&(w=b[L]);return w}},{key:"extract",value:function(b,w,L){w=at.clamp(w,0,b.length);var G=(L=at.clamp(L,-1,b.length))-w+1;L<0&&(G=0),w>=b.length&&(G=0),L<w&&(G=0);var K=new Array(G).fill(null);if(G===0)return K;for(var le=0,fe=w;fe<=L;fe++)K[le++]=b[fe];return K}}])})(),Te=(function(){return l((function B(){r(this,B)}),[{key:"compare",value:function(B,b){var w=B,L=b;return $n.compare(w,L)}},{key:"interfaces_",get:function(){return[Ie]}}])})(),ft=(function(){return l((function B(){r(this,B)}),[{key:"compare",value:function(B,b){var w=B,L=b;if(w.length<L.length)return-1;if(w.length>L.length)return 1;if(w.length===0)return 0;var G=$n.compare(w,L);return $n.isEqualReversed(w,L)?0:G}},{key:"OLDcompare",value:function(B,b){var w=B,L=b;if(w.length<L.length)return-1;if(w.length>L.length)return 1;if(w.length===0)return 0;for(var G=$n.increasingDirection(w),K=$n.increasingDirection(L),le=G>0?0:w.length-1,fe=K>0?0:w.length-1,_e=0;_e<w.length;_e++){var Oe=w[le].compareTo(L[fe]);if(Oe!==0)return Oe;le+=G,fe+=K}return 0}},{key:"interfaces_",get:function(){return[Ie]}}])})();$n.ForwardComparator=Te,$n.BidirectionalComparator=ft,$n.coordArrayType=new Array(0).fill(null);var At=(function(){return l((function B(b){r(this,B),this.str=b}),[{key:"append",value:function(B){this.str+=B}},{key:"setCharAt",value:function(B,b){this.str=this.str.substr(0,B)+b+this.str.substr(B+1)}},{key:"toString",value:function(){return this.str}}])})(),bt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getM",value:function(b){return this.hasM()?this._coordinates[b].getM():pe.NaN}},{key:"setOrdinate",value:function(b,w,L){switch(w){case ct.X:this._coordinates[b].x=L;break;case ct.Y:this._coordinates[b].y=L;break;default:this._coordinates[b].setOrdinate(w,L)}}},{key:"getZ",value:function(b){return this.hasZ()?this._coordinates[b].getZ():pe.NaN}},{key:"size",value:function(){return this._coordinates.length}},{key:"getOrdinate",value:function(b,w){switch(w){case ct.X:return this._coordinates[b].x;case ct.Y:return this._coordinates[b].y;default:return this._coordinates[b].getOrdinate(w)}}},{key:"getCoordinate",value:function(){if(arguments.length===1){var b=arguments[0];return this._coordinates[b]}if(arguments.length===2){var w=arguments[0];arguments[1].setCoordinate(this._coordinates[w])}}},{key:"getCoordinateCopy",value:function(b){var w=this.createCoordinate();return w.setCoordinate(this._coordinates[b]),w}},{key:"createCoordinate",value:function(){return An.create(this.getDimension(),this.getMeasures())}},{key:"getDimension",value:function(){return this._dimension}},{key:"getX",value:function(b){return this._coordinates[b].x}},{key:"getMeasures",value:function(){return this._measures}},{key:"expandEnvelope",value:function(b){for(var w=0;w<this._coordinates.length;w++)b.expandToInclude(this._coordinates[w]);return b}},{key:"copy",value:function(){for(var b=new Array(this.size()).fill(null),w=0;w<this._coordinates.length;w++){var L=this.createCoordinate();L.setCoordinate(this._coordinates[w]),b[w]=L}return new B(b,this._dimension,this._measures)}},{key:"toString",value:function(){if(this._coordinates.length>0){var b=new At(17*this._coordinates.length);b.append("("),b.append(this._coordinates[0]);for(var w=1;w<this._coordinates.length;w++)b.append(", "),b.append(this._coordinates[w]);return b.append(")"),b.toString()}return"()"}},{key:"getY",value:function(b){return this._coordinates[b].y}},{key:"toCoordinateArray",value:function(){return this._coordinates}},{key:"interfaces_",get:function(){return[ct,U]}}],[{key:"constructor_",value:function(){if(this._dimension=3,this._measures=0,this._coordinates=null,arguments.length===1){if(arguments[0]instanceof Array){var b=arguments[0];B.constructor_.call(this,b,$n.dimension(b),$n.measures(b))}else if(Number.isInteger(arguments[0])){var w=arguments[0];this._coordinates=new Array(w).fill(null);for(var L=0;L<w;L++)this._coordinates[L]=new Le}else if(Pe(arguments[0],ct)){var G=arguments[0];if(G===null)return this._coordinates=new Array(0).fill(null),null;this._dimension=G.getDimension(),this._measures=G.getMeasures(),this._coordinates=new Array(G.size()).fill(null);for(var K=0;K<this._coordinates.length;K++)this._coordinates[K]=G.getCoordinateCopy(K)}}else if(arguments.length===2){if(arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var le=arguments[0],fe=arguments[1];B.constructor_.call(this,le,fe,$n.measures(le))}else if(Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var _e=arguments[0],Oe=arguments[1];this._coordinates=new Array(_e).fill(null),this._dimension=Oe;for(var ut=0;ut<_e;ut++)this._coordinates[ut]=An.create(Oe)}}else if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var _t=arguments[0],St=arguments[1],Mi=arguments[2];this._dimension=St,this._measures=Mi,this._coordinates=_t===null?new Array(0).fill(null):_t}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var an=arguments[0],mn=arguments[1],tr=arguments[2];this._coordinates=new Array(an).fill(null),this._dimension=mn,this._measures=tr;for(var Qi=0;Qi<an;Qi++)this._coordinates[Qi]=this.createCoordinate()}}}}])})(),ot=(function(){function B(){r(this,B)}return l(B,[{key:"readResolve",value:function(){return B.instance()}},{key:"create",value:function(){if(arguments.length===1){if(arguments[0]instanceof Array)return new bt(arguments[0]);if(Pe(arguments[0],ct))return new bt(arguments[0])}else{if(arguments.length===2){var b=arguments[1];return b>3&&(b=3),b<2&&(b=2),new bt(arguments[0],b)}if(arguments.length===3){var w=arguments[2],L=arguments[1]-w;return w>1&&(w=1),L>3&&(L=3),L<2&&(L=2),new bt(arguments[0],L+w,w)}}}},{key:"interfaces_",get:function(){return[oi,U]}}],[{key:"instance",value:function(){return B.instanceObject}}])})();ot.instanceObject=new ot;var Wt=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"copyInternal",value:function(){for(var w=new Array(this._geometries.length).fill(null),L=0;L<w.length;L++)w[L]=this._geometries[L].copy();return new b(w,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof lt){var w=arguments[0],L=arguments[1];return!!this.isEquivalentClass(w)&&E(b,"equalsExact",this,1).call(this,w,L)}return E(b,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"getTypeCode",value:function(){return lt.TYPECODE_MULTIPOLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();for(var w=new Pt,L=0;L<this._geometries.length;L++)for(var G=this._geometries[L].getBoundary(),K=0;K<G.getNumGeometries();K++)w.add(G.getGeometryN(K));var le=new Array(w.size()).fill(null);return this.getFactory().createMultiLineString(w.toArray(le))}},{key:"getGeometryType",value:function(){return lt.TYPENAME_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[dt]}}],[{key:"constructor_",value:function(){var w=arguments[0],L=arguments[1];Zt.constructor_.call(this,w,L)}}])})(Zt),_i=(function(){return l((function B(){r(this,B)}),[{key:"get",value:function(){}},{key:"put",value:function(){}},{key:"size",value:function(){}},{key:"values",value:function(){}},{key:"entrySet",value:function(){}}])})(),ui=(function(B){function b(){var w;return r(this,b),(w=n(this,b)).map=new Map,w}return g(b,B),l(b,[{key:"get",value:function(w){return this.map.get(w)||null}},{key:"put",value:function(w,L){return this.map.set(w,L),L}},{key:"values",value:function(){for(var w=new Pt,L=this.map.values(),G=L.next();!G.done;)w.add(G.value),G=L.next();return w}},{key:"entrySet",value:function(){var w=new di;return this.map.entries().forEach((function(L){return w.add(L)})),w}},{key:"size",value:function(){return this.map.size()}}])})(_i),yi=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"equals",value:function(b){if(!(b instanceof B))return!1;var w=b;return this._modelType===w._modelType&&this._scale===w._scale}},{key:"compareTo",value:function(b){var w=b,L=this.getMaximumSignificantDigits(),G=w.getMaximumSignificantDigits();return je.compare(L,G)}},{key:"getScale",value:function(){return this._scale}},{key:"isFloating",value:function(){return this._modelType===B.FLOATING||this._modelType===B.FLOATING_SINGLE}},{key:"getType",value:function(){return this._modelType}},{key:"toString",value:function(){var b="UNKNOWN";return this._modelType===B.FLOATING?b="Floating":this._modelType===B.FLOATING_SINGLE?b="Floating-Single":this._modelType===B.FIXED&&(b="Fixed (Scale="+this.getScale()+")"),b}},{key:"makePrecise",value:function(){if(typeof arguments[0]=="number"){var b=arguments[0];return pe.isNaN(b)||this._modelType===B.FLOATING_SINGLE?b:this._modelType===B.FIXED?Math.round(b*this._scale)/this._scale:b}if(arguments[0]instanceof Le){var w=arguments[0];if(this._modelType===B.FLOATING)return null;w.x=this.makePrecise(w.x),w.y=this.makePrecise(w.y)}}},{key:"getMaximumSignificantDigits",value:function(){var b=16;return this._modelType===B.FLOATING?b=16:this._modelType===B.FLOATING_SINGLE?b=6:this._modelType===B.FIXED&&(b=1+Math.trunc(Math.ceil(Math.log(this.getScale())/Math.log(10)))),b}},{key:"setScale",value:function(b){this._scale=Math.abs(b)}},{key:"interfaces_",get:function(){return[U,Q]}}],[{key:"constructor_",value:function(){if(this._modelType=null,this._scale=null,arguments.length===0)this._modelType=B.FLOATING;else if(arguments.length===1){if(arguments[0]instanceof Ti){var b=arguments[0];this._modelType=b,b===B.FIXED&&this.setScale(1)}else if(typeof arguments[0]=="number"){var w=arguments[0];this._modelType=B.FIXED,this.setScale(w)}else if(arguments[0]instanceof B){var L=arguments[0];this._modelType=L._modelType,this._scale=L._scale}}}},{key:"mostPrecise",value:function(b,w){return b.compareTo(w)>=0?b:w}}])})(),Ti=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"readResolve",value:function(){return B.nameToTypeMap.get(this._name)}},{key:"toString",value:function(){return this._name}},{key:"interfaces_",get:function(){return[U]}}],[{key:"constructor_",value:function(){this._name=null;var b=arguments[0];this._name=b,B.nameToTypeMap.put(b,this)}}])})();Ti.nameToTypeMap=new ui,yi.Type=Ti,yi.FIXED=new Ti("FIXED"),yi.FLOATING=new Ti("FLOATING"),yi.FLOATING_SINGLE=new Ti("FLOATING SINGLE"),yi.maximumPreciseValue=9007199254740992;var tn=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"copyInternal",value:function(){for(var w=new Array(this._geometries.length).fill(null),L=0;L<w.length;L++)w[L]=this._geometries[L].copy();return new b(w,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof lt){var w=arguments[0],L=arguments[1];return!!this.isEquivalentClass(w)&&E(b,"equalsExact",this,1).call(this,w,L)}return E(b,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?Rt.FALSE:0}},{key:"isClosed",value:function(){if(this.isEmpty())return!1;for(var w=0;w<this._geometries.length;w++)if(!this._geometries[w].isClosed())return!1;return!0}},{key:"getTypeCode",value:function(){return lt.TYPECODE_MULTILINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getBoundary",value:function(){throw new $t}},{key:"getGeometryType",value:function(){return lt.TYPENAME_MULTILINESTRING}},{key:"interfaces_",get:function(){return[Ot]}}],[{key:"constructor_",value:function(){var w=arguments[0],L=arguments[1];Zt.constructor_.call(this,w,L)}}])})(Zt),qi=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"createEmpty",value:function(b){switch(b){case-1:return this.createGeometryCollection();case 0:return this.createPoint();case 1:return this.createLineString();case 2:return this.createPolygon();default:throw new Z("Invalid dimension: "+b)}}},{key:"toGeometry",value:function(b){return b.isNull()?this.createPoint():b.getMinX()===b.getMaxX()&&b.getMinY()===b.getMaxY()?this.createPoint(new Le(b.getMinX(),b.getMinY())):b.getMinX()===b.getMaxX()||b.getMinY()===b.getMaxY()?this.createLineString([new Le(b.getMinX(),b.getMinY()),new Le(b.getMaxX(),b.getMaxY())]):this.createPolygon(this.createLinearRing([new Le(b.getMinX(),b.getMinY()),new Le(b.getMinX(),b.getMaxY()),new Le(b.getMaxX(),b.getMaxY()),new Le(b.getMaxX(),b.getMinY()),new Le(b.getMinX(),b.getMinY())]),null)}},{key:"createLineString",value:function(){if(arguments.length===0)return this.createLineString(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){var b=arguments[0];return this.createLineString(b!==null?this.getCoordinateSequenceFactory().create(b):null)}if(Pe(arguments[0],ct))return new _r(arguments[0],this)}}},{key:"createMultiLineString",value:function(){return arguments.length===0?new tn(null,this):arguments.length===1?new tn(arguments[0],this):void 0}},{key:"buildGeometry",value:function(b){for(var w=null,L=!1,G=!1,K=b.iterator();K.hasNext();){var le=K.next(),fe=le.getTypeCode();w===null&&(w=fe),fe!==w&&(L=!0),le instanceof Zt&&(G=!0)}if(w===null)return this.createGeometryCollection();if(L||G)return this.createGeometryCollection(B.toGeometryArray(b));var _e=b.iterator().next();if(b.size()>1){if(_e instanceof yt)return this.createMultiPolygon(B.toPolygonArray(b));if(_e instanceof _r)return this.createMultiLineString(B.toLineStringArray(b));if(_e instanceof sr)return this.createMultiPoint(B.toPointArray(b));Se.shouldNeverReachHere("Unhandled geometry type: "+_e.getGeometryType())}return _e}},{key:"createMultiPointFromCoords",value:function(b){return this.createMultiPoint(b!==null?this.getCoordinateSequenceFactory().create(b):null)}},{key:"createPoint",value:function(){if(arguments.length===0)return this.createPoint(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Le){var b=arguments[0];return this.createPoint(b!==null?this.getCoordinateSequenceFactory().create([b]):null)}if(Pe(arguments[0],ct))return new sr(arguments[0],this)}}},{key:"getCoordinateSequenceFactory",value:function(){return this._coordinateSequenceFactory}},{key:"createPolygon",value:function(){if(arguments.length===0)return this.createPolygon(null,null);if(arguments.length===1){if(Pe(arguments[0],ct)){var b=arguments[0];return this.createPolygon(this.createLinearRing(b))}if(arguments[0]instanceof Array){var w=arguments[0];return this.createPolygon(this.createLinearRing(w))}if(arguments[0]instanceof nn){var L=arguments[0];return this.createPolygon(L,null)}}else if(arguments.length===2)return new yt(arguments[0],arguments[1],this)}},{key:"getSRID",value:function(){return this._SRID}},{key:"createGeometryCollection",value:function(){return arguments.length===0?new Zt(null,this):arguments.length===1?new Zt(arguments[0],this):void 0}},{key:"getPrecisionModel",value:function(){return this._precisionModel}},{key:"createLinearRing",value:function(){if(arguments.length===0)return this.createLinearRing(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){var b=arguments[0];return this.createLinearRing(b!==null?this.getCoordinateSequenceFactory().create(b):null)}if(Pe(arguments[0],ct))return new nn(arguments[0],this)}}},{key:"createMultiPolygon",value:function(){return arguments.length===0?new Wt(null,this):arguments.length===1?new Wt(arguments[0],this):void 0}},{key:"createMultiPoint",value:function(){if(arguments.length===0)return new ki(null,this);if(arguments.length===1){if(arguments[0]instanceof Array)return new ki(arguments[0],this);if(Pe(arguments[0],ct)){var b=arguments[0];if(b===null)return this.createMultiPoint(new Array(0).fill(null));for(var w=new Array(b.size()).fill(null),L=0;L<b.size();L++){var G=this.getCoordinateSequenceFactory().create(1,b.getDimension(),b.getMeasures());pi.copy(b,L,G,0,1),w[L]=this.createPoint(G)}return this.createMultiPoint(w)}}}},{key:"interfaces_",get:function(){return[U]}}],[{key:"constructor_",value:function(){if(this._precisionModel=null,this._coordinateSequenceFactory=null,this._SRID=null,arguments.length===0)B.constructor_.call(this,new yi,0);else if(arguments.length===1){if(Pe(arguments[0],oi)){var b=arguments[0];B.constructor_.call(this,new yi,0,b)}else if(arguments[0]instanceof yi){var w=arguments[0];B.constructor_.call(this,w,0,B.getDefaultCoordinateSequenceFactory())}}else if(arguments.length===2){var L=arguments[0],G=arguments[1];B.constructor_.call(this,L,G,B.getDefaultCoordinateSequenceFactory())}else if(arguments.length===3){var K=arguments[0],le=arguments[1],fe=arguments[2];this._precisionModel=K,this._coordinateSequenceFactory=fe,this._SRID=le}}},{key:"toMultiPolygonArray",value:function(b){var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"toGeometryArray",value:function(b){if(b===null)return null;var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"getDefaultCoordinateSequenceFactory",value:function(){return ot.instance()}},{key:"toMultiLineStringArray",value:function(b){var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"toLineStringArray",value:function(b){var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"toMultiPointArray",value:function(b){var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"toLinearRingArray",value:function(b){var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"toPointArray",value:function(b){var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"toPolygonArray",value:function(b){var w=new Array(b.size()).fill(null);return b.toArray(w)}},{key:"createPointFromInternalCoord",value:function(b,w){return w.getPrecisionModel().makePrecise(b),w.getFactory().createPoint(b)}}])})(),Mn="XY",Sn="XYZ",Wn="XYM",Zn="XYZM",Un={POINT:"Point",LINE_STRING:"LineString",LINEAR_RING:"LinearRing",POLYGON:"Polygon",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection",CIRCLE:"Circle"},Yi="EMPTY",er=1,bn=2,Pr=3,Dr=4,ur=5,Qo=6;for(var ar in Un)Un[ar].toUpperCase();var as=(function(){return l((function B(b){r(this,B),this.wkt=b,this.index_=-1}),[{key:"isAlpha_",value:function(B){return B>="a"&&B<="z"||B>="A"&&B<="Z"}},{key:"isNumeric_",value:function(B,b){return B>="0"&&B<="9"||B=="."&&!(b!==void 0&&b)}},{key:"isWhiteSpace_",value:function(B){return B==" "||B==" "||B=="\r"||B==`
|
|
268
268
|
`}},{key:"nextChar_",value:function(){return this.wkt.charAt(++this.index_)}},{key:"nextToken",value:function(){var B,b=this.nextChar_(),w=this.index_,L=b;if(b=="(")B=bn;else if(b==",")B=ur;else if(b==")")B=Pr;else if(this.isNumeric_(b)||b=="-")B=Dr,L=this.readNumber_();else if(this.isAlpha_(b))B=er,L=this.readText_();else{if(this.isWhiteSpace_(b))return this.nextToken();if(b!=="")throw new Error("Unexpected character: "+b);B=Qo}return{position:w,value:L,type:B}}},{key:"readNumber_",value:function(){var B,b=this.index_,w=!1,L=!1;do B=="."?w=!0:B!="e"&&B!="E"||(L=!0),B=this.nextChar_();while(this.isNumeric_(B,w)||!L&&(B=="e"||B=="E")||L&&(B=="-"||B=="+"));return parseFloat(this.wkt.substring(b,this.index_--))}},{key:"readText_",value:function(){var B,b=this.index_;do B=this.nextChar_();while(this.isAlpha_(B));return this.wkt.substring(b,this.index_--).toUpperCase()}}])})(),vs=(function(){return l((function B(b,w){r(this,B),this.lexer_=b,this.token_,this.layout_=Mn,this.factory=w}),[{key:"consume_",value:function(){this.token_=this.lexer_.nextToken()}},{key:"isTokenType",value:function(B){return this.token_.type==B}},{key:"match",value:function(B){var b=this.isTokenType(B);return b&&this.consume_(),b}},{key:"parse",value:function(){return this.consume_(),this.parseGeometry_()}},{key:"parseGeometryLayout_",value:function(){var B=Mn,b=this.token_;if(this.isTokenType(er)){var w=b.value;w==="Z"?B=Sn:w==="M"?B=Wn:w==="ZM"&&(B=Zn),B!==Mn&&this.consume_()}return B}},{key:"parseGeometryCollectionText_",value:function(){if(this.match(bn)){var B=[];do B.push(this.parseGeometry_());while(this.match(ur));if(this.match(Pr))return B}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePointText_",value:function(){if(this.match(bn)){var B=this.parsePoint_();if(this.match(Pr))return B}else if(this.isEmptyGeometry_())return null;throw new Error(this.formatErrorMessage_())}},{key:"parseLineStringText_",value:function(){if(this.match(bn)){var B=this.parsePointList_();if(this.match(Pr))return B}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePolygonText_",value:function(){if(this.match(bn)){var B=this.parseLineStringTextList_();if(this.match(Pr))return B}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPointText_",value:function(){var B;if(this.match(bn)){if(B=this.token_.type==bn?this.parsePointTextList_():this.parsePointList_(),this.match(Pr))return B}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiLineStringText_",value:function(){if(this.match(bn)){var B=this.parseLineStringTextList_();if(this.match(Pr))return B}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPolygonText_",value:function(){if(this.match(bn)){var B=this.parsePolygonTextList_();if(this.match(Pr))return B}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePoint_",value:function(){for(var B=[],b=this.layout_.length,w=0;w<b;++w){var L=this.token_;if(!this.match(Dr))break;B.push(L.value)}if(B.length==b)return B;throw new Error(this.formatErrorMessage_())}},{key:"parsePointList_",value:function(){for(var B=[this.parsePoint_()];this.match(ur);)B.push(this.parsePoint_());return B}},{key:"parsePointTextList_",value:function(){for(var B=[this.parsePointText_()];this.match(ur);)B.push(this.parsePointText_());return B}},{key:"parseLineStringTextList_",value:function(){for(var B=[this.parseLineStringText_()];this.match(ur);)B.push(this.parseLineStringText_());return B}},{key:"parsePolygonTextList_",value:function(){for(var B=[this.parsePolygonText_()];this.match(ur);)B.push(this.parsePolygonText_());return B}},{key:"isEmptyGeometry_",value:function(){var B=this.isTokenType(er)&&this.token_.value==Yi;return B&&this.consume_(),B}},{key:"formatErrorMessage_",value:function(){return"Unexpected `"+this.token_.value+"` at position "+this.token_.position+" in `"+this.lexer_.wkt+"`"}},{key:"parseGeometry_",value:function(){var B=this.factory,b=function(mn){return s(Le,S(mn))},w=function(mn){var tr=mn.map((function(Qi){return B.createLinearRing(Qi.map(b))}));return tr.length>1?B.createPolygon(tr[0],tr.slice(1)):B.createPolygon(tr[0])},L=this.token_;if(this.match(er)){var G=L.value;if(this.layout_=this.parseGeometryLayout_(),G=="GEOMETRYCOLLECTION"){var K=this.parseGeometryCollectionText_();return B.createGeometryCollection(K)}switch(G){case"POINT":var le=this.parsePointText_();return le?B.createPoint(s(Le,S(le))):B.createPoint();case"LINESTRING":var fe=this.parseLineStringText_().map(b);return B.createLineString(fe);case"LINEARRING":var _e=this.parseLineStringText_().map(b);return B.createLinearRing(_e);case"POLYGON":var Oe=this.parsePolygonText_();return Oe&&Oe.length!==0?w(Oe):B.createPolygon();case"MULTIPOINT":var ut=this.parseMultiPointText_();if(!ut||ut.length===0)return B.createMultiPoint();var _t=ut.map(b).map((function(mn){return B.createPoint(mn)}));return B.createMultiPoint(_t);case"MULTILINESTRING":var St=this.parseMultiLineStringText_().map((function(mn){return B.createLineString(mn.map(b))}));return B.createMultiLineString(St);case"MULTIPOLYGON":var Mi=this.parseMultiPolygonText_();if(!Mi||Mi.length===0)return B.createMultiPolygon();var an=Mi.map(w);return B.createMultiPolygon(an);default:throw new Error("Invalid geometry type: "+G)}}throw new Error(this.formatErrorMessage_())}}])})();function Xn(B){if(B.isEmpty())return"";var b=B.getCoordinate(),w=[b.x,b.y];return b.z===void 0||Number.isNaN(b.z)||w.push(b.z),b.m===void 0||Number.isNaN(b.m)||w.push(b.m),w.join(" ")}function Qr(B){for(var b=B.getCoordinates().map((function(K){var le=[K.x,K.y];return K.z===void 0||Number.isNaN(K.z)||le.push(K.z),K.m===void 0||Number.isNaN(K.m)||le.push(K.m),le})),w=[],L=0,G=b.length;L<G;++L)w.push(b[L].join(" "));return w.join(", ")}function Za(B){var b=[];b.push("("+Qr(B.getExteriorRing())+")");for(var w=0,L=B.getNumInteriorRing();w<L;++w)b.push("("+Qr(B.getInteriorRingN(w))+")");return b.join(", ")}var ia={Point:Xn,LineString:Qr,LinearRing:Qr,Polygon:Za,MultiPoint:function(B){for(var b=[],w=0,L=B.getNumGeometries();w<L;++w)b.push("("+Xn(B.getGeometryN(w))+")");return b.join(", ")},MultiLineString:function(B){for(var b=[],w=0,L=B.getNumGeometries();w<L;++w)b.push("("+Qr(B.getGeometryN(w))+")");return b.join(", ")},MultiPolygon:function(B){for(var b=[],w=0,L=B.getNumGeometries();w<L;++w)b.push("("+Za(B.getGeometryN(w))+")");return b.join(", ")},GeometryCollection:function(B){for(var b=[],w=0,L=B.getNumGeometries();w<L;++w)b.push(Ao(B.getGeometryN(w)));return b.join(", ")}};function Ao(B){var b=B.getGeometryType(),w=ia[b];b=b.toUpperCase();var L=(function(G){var K="";if(G.isEmpty())return K;var le=G.getCoordinate();return le.z===void 0||Number.isNaN(le.z)||(K+="Z"),le.m===void 0||Number.isNaN(le.m)||(K+="M"),K})(B);return L.length>0&&(b+=" "+L),B.isEmpty()?b+" "+Yi:b+" ("+w(B)+")"}var od=(function(){return l((function B(b){r(this,B),this.geometryFactory=b||new qi,this.precisionModel=this.geometryFactory.getPrecisionModel()}),[{key:"read",value:function(B){return new vs(new as(B),this.geometryFactory).parse()}},{key:"write",value:function(B){return Ao(B)}}])})(),ca=(function(){return l((function B(b){r(this,B),this.parser=new od(b)}),[{key:"write",value:function(B){return this.parser.write(B)}}],[{key:"toLineString",value:function(B,b){if(arguments.length!==2)throw new Error("Not implemented");return"LINESTRING ( "+B.x+" "+B.y+", "+b.x+" "+b.y+" )"}}])})(),Pn=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getIndexAlongSegment",value:function(b,w){return this.computeIntLineIndex(),this._intLineIndex[b][w]}},{key:"getTopologySummary",value:function(){var b=new At;return this.isEndPoint()&&b.append(" endpoint"),this._isProper&&b.append(" proper"),this.isCollinear()&&b.append(" collinear"),b.toString()}},{key:"computeIntersection",value:function(b,w,L,G){this._inputLines[0][0]=b,this._inputLines[0][1]=w,this._inputLines[1][0]=L,this._inputLines[1][1]=G,this._result=this.computeIntersect(b,w,L,G)}},{key:"getIntersectionNum",value:function(){return this._result}},{key:"computeIntLineIndex",value:function(){if(arguments.length===0)this._intLineIndex===null&&(this._intLineIndex=Array(2).fill().map((function(){return Array(2)})),this.computeIntLineIndex(0),this.computeIntLineIndex(1));else if(arguments.length===1){var b=arguments[0];this.getEdgeDistance(b,0)>this.getEdgeDistance(b,1)?(this._intLineIndex[b][0]=0,this._intLineIndex[b][1]=1):(this._intLineIndex[b][0]=1,this._intLineIndex[b][1]=0)}}},{key:"isProper",value:function(){return this.hasIntersection()&&this._isProper}},{key:"setPrecisionModel",value:function(b){this._precisionModel=b}},{key:"isInteriorIntersection",value:function(){if(arguments.length===0)return!!this.isInteriorIntersection(0)||!!this.isInteriorIntersection(1);if(arguments.length===1){for(var b=arguments[0],w=0;w<this._result;w++)if(!this._intPt[w].equals2D(this._inputLines[b][0])&&!this._intPt[w].equals2D(this._inputLines[b][1]))return!0;return!1}}},{key:"getIntersection",value:function(b){return this._intPt[b]}},{key:"isEndPoint",value:function(){return this.hasIntersection()&&!this._isProper}},{key:"hasIntersection",value:function(){return this._result!==B.NO_INTERSECTION}},{key:"getEdgeDistance",value:function(b,w){return B.computeEdgeDistance(this._intPt[w],this._inputLines[b][0],this._inputLines[b][1])}},{key:"isCollinear",value:function(){return this._result===B.COLLINEAR_INTERSECTION}},{key:"toString",value:function(){return ca.toLineString(this._inputLines[0][0],this._inputLines[0][1])+" - "+ca.toLineString(this._inputLines[1][0],this._inputLines[1][1])+this.getTopologySummary()}},{key:"getEndpoint",value:function(b,w){return this._inputLines[b][w]}},{key:"isIntersection",value:function(b){for(var w=0;w<this._result;w++)if(this._intPt[w].equals2D(b))return!0;return!1}},{key:"getIntersectionAlongSegment",value:function(b,w){return this.computeIntLineIndex(),this._intPt[this._intLineIndex[b][w]]}}],[{key:"constructor_",value:function(){this._result=null,this._inputLines=Array(2).fill().map((function(){return Array(2)})),this._intPt=new Array(2).fill(null),this._intLineIndex=null,this._isProper=null,this._pa=null,this._pb=null,this._precisionModel=null,this._intPt[0]=new Le,this._intPt[1]=new Le,this._pa=this._intPt[0],this._pb=this._intPt[1],this._result=0}},{key:"computeEdgeDistance",value:function(b,w,L){var G=Math.abs(L.x-w.x),K=Math.abs(L.y-w.y),le=-1;if(b.equals(w))le=0;else if(b.equals(L))le=G>K?G:K;else{var fe=Math.abs(b.x-w.x),_e=Math.abs(b.y-w.y);(le=G>K?fe:_e)!==0||b.equals(w)||(le=Math.max(fe,_e))}return Se.isTrue(!(le===0&&!b.equals(w)),"Bad distance calculation"),le}},{key:"nonRobustComputeEdgeDistance",value:function(b,w,L){var G=b.x-w.x,K=b.y-w.y,le=Math.sqrt(G*G+K*K);return Se.isTrue(!(le===0&&!b.equals(w)),"Invalid distance calculation"),le}}])})();Pn.DONT_INTERSECT=0,Pn.DO_INTERSECT=1,Pn.COLLINEAR=2,Pn.NO_INTERSECTION=0,Pn.POINT_INTERSECTION=1,Pn.COLLINEAR_INTERSECTION=2;var ys=(function(B){function b(){return r(this,b),n(this,b)}return g(b,B),l(b,[{key:"isInSegmentEnvelopes",value:function(w){var L=new nt(this._inputLines[0][0],this._inputLines[0][1]),G=new nt(this._inputLines[1][0],this._inputLines[1][1]);return L.contains(w)&&G.contains(w)}},{key:"computeIntersection",value:function(){if(arguments.length!==3)return E(b,"computeIntersection",this,1).apply(this,arguments);var w=arguments[0],L=arguments[1],G=arguments[2];if(this._isProper=!1,nt.intersects(L,G,w)&&et.index(L,G,w)===0&&et.index(G,L,w)===0)return this._isProper=!0,(w.equals(L)||w.equals(G))&&(this._isProper=!1),this._result=Pn.POINT_INTERSECTION,null;this._result=Pn.NO_INTERSECTION}},{key:"intersection",value:function(w,L,G,K){var le=this.intersectionSafe(w,L,G,K);return this.isInSegmentEnvelopes(le)||(le=new Le(b.nearestEndpoint(w,L,G,K))),this._precisionModel!==null&&this._precisionModel.makePrecise(le),le}},{key:"checkDD",value:function(w,L,G,K,le){var fe=st.intersection(w,L,G,K),_e=this.isInSegmentEnvelopes(fe);Hi.out.println("DD in env = "+_e+" --------------------- "+fe),le.distance(fe)>1e-4&&Hi.out.println("Distance = "+le.distance(fe))}},{key:"intersectionSafe",value:function(w,L,G,K){var le=hi.intersection(w,L,G,K);return le===null&&(le=b.nearestEndpoint(w,L,G,K)),le}},{key:"computeCollinearIntersection",value:function(w,L,G,K){var le=nt.intersects(w,L,G),fe=nt.intersects(w,L,K),_e=nt.intersects(G,K,w),Oe=nt.intersects(G,K,L);return le&&fe?(this._intPt[0]=G,this._intPt[1]=K,Pn.COLLINEAR_INTERSECTION):_e&&Oe?(this._intPt[0]=w,this._intPt[1]=L,Pn.COLLINEAR_INTERSECTION):le&&_e?(this._intPt[0]=G,this._intPt[1]=w,!G.equals(w)||fe||Oe?Pn.COLLINEAR_INTERSECTION:Pn.POINT_INTERSECTION):le&&Oe?(this._intPt[0]=G,this._intPt[1]=L,!G.equals(L)||fe||_e?Pn.COLLINEAR_INTERSECTION:Pn.POINT_INTERSECTION):fe&&_e?(this._intPt[0]=K,this._intPt[1]=w,!K.equals(w)||le||Oe?Pn.COLLINEAR_INTERSECTION:Pn.POINT_INTERSECTION):fe&&Oe?(this._intPt[0]=K,this._intPt[1]=L,!K.equals(L)||le||_e?Pn.COLLINEAR_INTERSECTION:Pn.POINT_INTERSECTION):Pn.NO_INTERSECTION}},{key:"computeIntersect",value:function(w,L,G,K){if(this._isProper=!1,!nt.intersects(w,L,G,K))return Pn.NO_INTERSECTION;var le=et.index(w,L,G),fe=et.index(w,L,K);if(le>0&&fe>0||le<0&&fe<0)return Pn.NO_INTERSECTION;var _e=et.index(G,K,w),Oe=et.index(G,K,L);return _e>0&&Oe>0||_e<0&&Oe<0?Pn.NO_INTERSECTION:le===0&&fe===0&&_e===0&&Oe===0?this.computeCollinearIntersection(w,L,G,K):(le===0||fe===0||_e===0||Oe===0?(this._isProper=!1,w.equals2D(G)||w.equals2D(K)?this._intPt[0]=w:L.equals2D(G)||L.equals2D(K)?this._intPt[0]=L:le===0?this._intPt[0]=new Le(G):fe===0?this._intPt[0]=new Le(K):_e===0?this._intPt[0]=new Le(w):Oe===0&&(this._intPt[0]=new Le(L))):(this._isProper=!0,this._intPt[0]=this.intersection(w,L,G,K)),Pn.POINT_INTERSECTION)}}],[{key:"nearestEndpoint",value:function(w,L,G,K){var le=w,fe=ei.pointToSegment(w,G,K),_e=ei.pointToSegment(L,G,K);return _e<fe&&(fe=_e,le=L),(_e=ei.pointToSegment(G,w,L))<fe&&(fe=_e,le=G),(_e=ei.pointToSegment(K,w,L))<fe&&(fe=_e,le=K),le}}])})(Pn),hu=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"countSegment",value:function(b,w){if(b.x<this._p.x&&w.x<this._p.x)return null;if(this._p.x===w.x&&this._p.y===w.y)return this._isPointOnSegment=!0,null;if(b.y===this._p.y&&w.y===this._p.y){var L=b.x,G=w.x;return L>G&&(L=w.x,G=b.x),this._p.x>=L&&this._p.x<=G&&(this._isPointOnSegment=!0),null}if(b.y>this._p.y&&w.y<=this._p.y||w.y>this._p.y&&b.y<=this._p.y){var K=et.index(b,w,this._p);if(K===et.COLLINEAR)return this._isPointOnSegment=!0,null;w.y<b.y&&(K=-K),K===et.LEFT&&this._crossingCount++}}},{key:"isPointInPolygon",value:function(){return this.getLocation()!==Ae.EXTERIOR}},{key:"getLocation",value:function(){return this._isPointOnSegment?Ae.BOUNDARY:this._crossingCount%2==1?Ae.INTERIOR:Ae.EXTERIOR}},{key:"isOnSegment",value:function(){return this._isPointOnSegment}}],[{key:"constructor_",value:function(){this._p=null,this._crossingCount=0,this._isPointOnSegment=!1;var b=arguments[0];this._p=b}},{key:"locatePointInRing",value:function(){if(arguments[0]instanceof Le&&Pe(arguments[1],ct)){for(var b=arguments[1],w=new B(arguments[0]),L=new Le,G=new Le,K=1;K<b.size();K++)if(b.getCoordinate(K,L),b.getCoordinate(K-1,G),w.countSegment(L,G),w.isOnSegment())return w.getLocation();return w.getLocation()}if(arguments[0]instanceof Le&&arguments[1]instanceof Array){for(var le=arguments[1],fe=new B(arguments[0]),_e=1;_e<le.length;_e++){var Oe=le[_e],ut=le[_e-1];if(fe.countSegment(Oe,ut),fe.isOnSegment())return fe.getLocation()}return fe.getLocation()}}}])})(),Ps=(function(){function B(){r(this,B)}return l(B,null,[{key:"isOnLine",value:function(){if(arguments[0]instanceof Le&&Pe(arguments[1],ct)){for(var b=arguments[0],w=arguments[1],L=new ys,G=new Le,K=new Le,le=w.size(),fe=1;fe<le;fe++)if(w.getCoordinate(fe-1,G),w.getCoordinate(fe,K),L.computeIntersection(b,G,K),L.hasIntersection())return!0;return!1}if(arguments[0]instanceof Le&&arguments[1]instanceof Array){for(var _e=arguments[0],Oe=arguments[1],ut=new ys,_t=1;_t<Oe.length;_t++){var St=Oe[_t-1],Mi=Oe[_t];if(ut.computeIntersection(_e,St,Mi),ut.hasIntersection())return!0}return!1}}},{key:"locateInRing",value:function(b,w){return hu.locatePointInRing(b,w)}},{key:"isInRing",value:function(b,w){return B.locateInRing(b,w)!==Ae.EXTERIOR}}])})(),os=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"setAllLocations",value:function(b){for(var w=0;w<this.location.length;w++)this.location[w]=b}},{key:"isNull",value:function(){for(var b=0;b<this.location.length;b++)if(this.location[b]!==Ae.NONE)return!1;return!0}},{key:"setAllLocationsIfNull",value:function(b){for(var w=0;w<this.location.length;w++)this.location[w]===Ae.NONE&&(this.location[w]=b)}},{key:"isLine",value:function(){return this.location.length===1}},{key:"merge",value:function(b){if(b.location.length>this.location.length){var w=new Array(3).fill(null);w[be.ON]=this.location[be.ON],w[be.LEFT]=Ae.NONE,w[be.RIGHT]=Ae.NONE,this.location=w}for(var L=0;L<this.location.length;L++)this.location[L]===Ae.NONE&&L<b.location.length&&(this.location[L]=b.location[L])}},{key:"getLocations",value:function(){return this.location}},{key:"flip",value:function(){if(this.location.length<=1)return null;var b=this.location[be.LEFT];this.location[be.LEFT]=this.location[be.RIGHT],this.location[be.RIGHT]=b}},{key:"toString",value:function(){var b=new ve;return this.location.length>1&&b.append(Ae.toLocationSymbol(this.location[be.LEFT])),b.append(Ae.toLocationSymbol(this.location[be.ON])),this.location.length>1&&b.append(Ae.toLocationSymbol(this.location[be.RIGHT])),b.toString()}},{key:"setLocations",value:function(b,w,L){this.location[be.ON]=b,this.location[be.LEFT]=w,this.location[be.RIGHT]=L}},{key:"get",value:function(b){return b<this.location.length?this.location[b]:Ae.NONE}},{key:"isArea",value:function(){return this.location.length>1}},{key:"isAnyNull",value:function(){for(var b=0;b<this.location.length;b++)if(this.location[b]===Ae.NONE)return!0;return!1}},{key:"setLocation",value:function(){if(arguments.length===1){var b=arguments[0];this.setLocation(be.ON,b)}else if(arguments.length===2){var w=arguments[0],L=arguments[1];this.location[w]=L}}},{key:"init",value:function(b){this.location=new Array(b).fill(null),this.setAllLocations(Ae.NONE)}},{key:"isEqualOnSide",value:function(b,w){return this.location[w]===b.location[w]}},{key:"allPositionsEqual",value:function(b){for(var w=0;w<this.location.length;w++)if(this.location[w]!==b)return!1;return!0}}],[{key:"constructor_",value:function(){if(this.location=null,arguments.length===1){if(arguments[0]instanceof Array){var b=arguments[0];this.init(b.length)}else if(Number.isInteger(arguments[0])){var w=arguments[0];this.init(1),this.location[be.ON]=w}else if(arguments[0]instanceof B){var L=arguments[0];if(this.init(L.location.length),L!==null)for(var G=0;G<this.location.length;G++)this.location[G]=L.location[G]}}else if(arguments.length===3){var K=arguments[0],le=arguments[1],fe=arguments[2];this.init(3),this.location[be.ON]=K,this.location[be.LEFT]=le,this.location[be.RIGHT]=fe}}}])})(),Jr=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getGeometryCount",value:function(){var b=0;return this.elt[0].isNull()||b++,this.elt[1].isNull()||b++,b}},{key:"setAllLocations",value:function(b,w){this.elt[b].setAllLocations(w)}},{key:"isNull",value:function(b){return this.elt[b].isNull()}},{key:"setAllLocationsIfNull",value:function(){if(arguments.length===1){var b=arguments[0];this.setAllLocationsIfNull(0,b),this.setAllLocationsIfNull(1,b)}else if(arguments.length===2){var w=arguments[0],L=arguments[1];this.elt[w].setAllLocationsIfNull(L)}}},{key:"isLine",value:function(b){return this.elt[b].isLine()}},{key:"merge",value:function(b){for(var w=0;w<2;w++)this.elt[w]===null&&b.elt[w]!==null?this.elt[w]=new os(b.elt[w]):this.elt[w].merge(b.elt[w])}},{key:"flip",value:function(){this.elt[0].flip(),this.elt[1].flip()}},{key:"getLocation",value:function(){if(arguments.length===1){var b=arguments[0];return this.elt[b].get(be.ON)}if(arguments.length===2){var w=arguments[0],L=arguments[1];return this.elt[w].get(L)}}},{key:"toString",value:function(){var b=new ve;return this.elt[0]!==null&&(b.append("A:"),b.append(this.elt[0].toString())),this.elt[1]!==null&&(b.append(" B:"),b.append(this.elt[1].toString())),b.toString()}},{key:"isArea",value:function(){if(arguments.length===0)return this.elt[0].isArea()||this.elt[1].isArea();if(arguments.length===1){var b=arguments[0];return this.elt[b].isArea()}}},{key:"isAnyNull",value:function(b){return this.elt[b].isAnyNull()}},{key:"setLocation",value:function(){if(arguments.length===2){var b=arguments[0],w=arguments[1];this.elt[b].setLocation(be.ON,w)}else if(arguments.length===3){var L=arguments[0],G=arguments[1],K=arguments[2];this.elt[L].setLocation(G,K)}}},{key:"isEqualOnSide",value:function(b,w){return this.elt[0].isEqualOnSide(b.elt[0],w)&&this.elt[1].isEqualOnSide(b.elt[1],w)}},{key:"allPositionsEqual",value:function(b,w){return this.elt[b].allPositionsEqual(w)}},{key:"toLine",value:function(b){this.elt[b].isArea()&&(this.elt[b]=new os(this.elt[b].location[0]))}}],[{key:"constructor_",value:function(){if(this.elt=new Array(2).fill(null),arguments.length===1){if(Number.isInteger(arguments[0])){var b=arguments[0];this.elt[0]=new os(b),this.elt[1]=new os(b)}else if(arguments[0]instanceof B){var w=arguments[0];this.elt[0]=new os(w.elt[0]),this.elt[1]=new os(w.elt[1])}}else if(arguments.length===2){var L=arguments[0],G=arguments[1];this.elt[0]=new os(Ae.NONE),this.elt[1]=new os(Ae.NONE),this.elt[L].setLocation(G)}else if(arguments.length===3){var K=arguments[0],le=arguments[1],fe=arguments[2];this.elt[0]=new os(K,le,fe),this.elt[1]=new os(K,le,fe)}else if(arguments.length===4){var _e=arguments[0],Oe=arguments[1],ut=arguments[2],_t=arguments[3];this.elt[0]=new os(Ae.NONE,Ae.NONE,Ae.NONE),this.elt[1]=new os(Ae.NONE,Ae.NONE,Ae.NONE),this.elt[_e].setLocations(Oe,ut,_t)}}},{key:"toLineLabel",value:function(b){for(var w=new B(Ae.NONE),L=0;L<2;L++)w.setLocation(L,b.getLocation(L));return w}}])})(),Ns=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"computeRing",value:function(){if(this._ring!==null)return null;for(var B=new Array(this._pts.size()).fill(null),b=0;b<this._pts.size();b++)B[b]=this._pts.get(b);this._ring=this._geometryFactory.createLinearRing(B),this._isHole=et.isCCW(this._ring.getCoordinates())}},{key:"isIsolated",value:function(){return this._label.getGeometryCount()===1}},{key:"computePoints",value:function(B){this._startDe=B;var b=B,w=!0;do{if(b===null)throw new ii("Found null DirectedEdge");if(b.getEdgeRing()===this)throw new ii("Directed Edge visited twice during ring-building at "+b.getCoordinate());this._edges.add(b);var L=b.getLabel();Se.isTrue(L.isArea()),this.mergeLabel(L),this.addPoints(b.getEdge(),b.isForward(),w),w=!1,this.setEdgeRing(b,this),b=this.getNext(b)}while(b!==this._startDe)}},{key:"getLinearRing",value:function(){return this._ring}},{key:"getCoordinate",value:function(B){return this._pts.get(B)}},{key:"computeMaxNodeDegree",value:function(){this._maxNodeDegree=0;var B=this._startDe;do{var b=B.getNode().getEdges().getOutgoingDegree(this);b>this._maxNodeDegree&&(this._maxNodeDegree=b),B=this.getNext(B)}while(B!==this._startDe);this._maxNodeDegree*=2}},{key:"addPoints",value:function(B,b,w){var L=B.getCoordinates();if(b){var G=1;w&&(G=0);for(var K=G;K<L.length;K++)this._pts.add(L[K])}else{var le=L.length-2;w&&(le=L.length-1);for(var fe=le;fe>=0;fe--)this._pts.add(L[fe])}}},{key:"isHole",value:function(){return this._isHole}},{key:"setInResult",value:function(){var B=this._startDe;do B.getEdge().setInResult(!0),B=B.getNext();while(B!==this._startDe)}},{key:"containsPoint",value:function(B){var b=this.getLinearRing();if(!b.getEnvelopeInternal().contains(B)||!Ps.isInRing(B,b.getCoordinates()))return!1;for(var w=this._holes.iterator();w.hasNext();)if(w.next().containsPoint(B))return!1;return!0}},{key:"addHole",value:function(B){this._holes.add(B)}},{key:"isShell",value:function(){return this._shell===null}},{key:"getLabel",value:function(){return this._label}},{key:"getEdges",value:function(){return this._edges}},{key:"getMaxNodeDegree",value:function(){return this._maxNodeDegree<0&&this.computeMaxNodeDegree(),this._maxNodeDegree}},{key:"getShell",value:function(){return this._shell}},{key:"mergeLabel",value:function(){if(arguments.length===1){var B=arguments[0];this.mergeLabel(B,0),this.mergeLabel(B,1)}else if(arguments.length===2){var b=arguments[1],w=arguments[0].getLocation(b,be.RIGHT);if(w===Ae.NONE)return null;if(this._label.getLocation(b)===Ae.NONE)return this._label.setLocation(b,w),null}}},{key:"setShell",value:function(B){this._shell=B,B!==null&&B.addHole(this)}},{key:"toPolygon",value:function(B){for(var b=new Array(this._holes.size()).fill(null),w=0;w<this._holes.size();w++)b[w]=this._holes.get(w).getLinearRing();return B.createPolygon(this.getLinearRing(),b)}}],[{key:"constructor_",value:function(){if(this._startDe=null,this._maxNodeDegree=-1,this._edges=new Pt,this._pts=new Pt,this._label=new Jr(Ae.NONE),this._ring=null,this._isHole=null,this._shell=null,this._holes=new Pt,this._geometryFactory=null,arguments.length!==0){if(arguments.length===2){var B=arguments[0],b=arguments[1];this._geometryFactory=b,this.computePoints(B),this.computeRing()}}}}])})(),Wo=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"setEdgeRing",value:function(w,L){w.setMinEdgeRing(L)}},{key:"getNext",value:function(w){return w.getNextMin()}}],[{key:"constructor_",value:function(){var w=arguments[0],L=arguments[1];Ns.constructor_.call(this,w,L)}}])})(Ns),Ec=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"buildMinimalRings",value:function(){var w=new Pt,L=this._startDe;do{if(L.getMinEdgeRing()===null){var G=new Wo(L,this._geometryFactory);w.add(G)}L=L.getNext()}while(L!==this._startDe);return w}},{key:"setEdgeRing",value:function(w,L){w.setEdgeRing(L)}},{key:"linkDirectedEdgesForMinimalEdgeRings",value:function(){var w=this._startDe;do w.getNode().getEdges().linkMinimalDirectedEdges(this),w=w.getNext();while(w!==this._startDe)}},{key:"getNext",value:function(w){return w.getNext()}}],[{key:"constructor_",value:function(){var w=arguments[0],L=arguments[1];Ns.constructor_.call(this,w,L)}}])})(Ns),ac=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"setVisited",value:function(B){this._isVisited=B}},{key:"setInResult",value:function(B){this._isInResult=B}},{key:"isCovered",value:function(){return this._isCovered}},{key:"isCoveredSet",value:function(){return this._isCoveredSet}},{key:"setLabel",value:function(B){this._label=B}},{key:"getLabel",value:function(){return this._label}},{key:"setCovered",value:function(B){this._isCovered=B,this._isCoveredSet=!0}},{key:"updateIM",value:function(B){Se.isTrue(this._label.getGeometryCount()>=2,"found partial label"),this.computeIM(B)}},{key:"isInResult",value:function(){return this._isInResult}},{key:"isVisited",value:function(){return this._isVisited}}],[{key:"constructor_",value:function(){if(this._label=null,this._isInResult=!1,this._isCovered=!1,this._isCoveredSet=!1,this._isVisited=!1,arguments.length!==0){if(arguments.length===1){var B=arguments[0];this._label=B}}}}])})(),qa=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"isIncidentEdgeInResult",value:function(){for(var w=this.getEdges().getEdges().iterator();w.hasNext();)if(w.next().getEdge().isInResult())return!0;return!1}},{key:"isIsolated",value:function(){return this._label.getGeometryCount()===1}},{key:"getCoordinate",value:function(){return this._coord}},{key:"print",value:function(w){w.println("node "+this._coord+" lbl: "+this._label)}},{key:"computeIM",value:function(w){}},{key:"computeMergedLocation",value:function(w,L){var G=Ae.NONE;if(G=this._label.getLocation(L),!w.isNull(L)){var K=w.getLocation(L);G!==Ae.BOUNDARY&&(G=K)}return G}},{key:"setLabel",value:function(){if(arguments.length!==2||!Number.isInteger(arguments[1])||!Number.isInteger(arguments[0]))return E(b,"setLabel",this,1).apply(this,arguments);var w=arguments[0],L=arguments[1];this._label===null?this._label=new Jr(w,L):this._label.setLocation(w,L)}},{key:"getEdges",value:function(){return this._edges}},{key:"mergeLabel",value:function(){if(arguments[0]instanceof b){var w=arguments[0];this.mergeLabel(w._label)}else if(arguments[0]instanceof Jr)for(var L=arguments[0],G=0;G<2;G++){var K=this.computeMergedLocation(L,G);this._label.getLocation(G)===Ae.NONE&&this._label.setLocation(G,K)}}},{key:"add",value:function(w){this._edges.insert(w),w.setNode(this)}},{key:"setLabelBoundary",value:function(w){if(this._label===null)return null;var L=Ae.NONE;this._label!==null&&(L=this._label.getLocation(w));var G=null;switch(L){case Ae.BOUNDARY:G=Ae.INTERIOR;break;case Ae.INTERIOR:default:G=Ae.BOUNDARY}this._label.setLocation(w,G)}}],[{key:"constructor_",value:function(){this._coord=null,this._edges=null;var w=arguments[0],L=arguments[1];this._coord=w,this._edges=L,this._label=new Jr(0,Ae.NONE)}}])})(ac),uu=(function(B){function b(){return r(this,b),n(this,b,arguments)}return g(b,B),l(b)})(_i);function oc(B){return B==null?0:B.color}function xn(B){return B==null?null:B.parent}function na(B,b){B!==null&&(B.color=b)}function Sc(B){return B==null?null:B.left}function Cl(B){return B==null?null:B.right}var Fs=(function(B){function b(){var w;return r(this,b),(w=n(this,b)).root_=null,w.size_=0,w}return g(b,B),l(b,[{key:"get",value:function(w){for(var L=this.root_;L!==null;){var G=w.compareTo(L.key);if(G<0)L=L.left;else{if(!(G>0))return L.value;L=L.right}}return null}},{key:"put",value:function(w,L){if(this.root_===null)return this.root_={key:w,value:L,left:null,right:null,parent:null,color:0,getValue:function(){return this.value},getKey:function(){return this.key}},this.size_=1,null;var G,K,le=this.root_;do if(G=le,(K=w.compareTo(le.key))<0)le=le.left;else{if(!(K>0)){var fe=le.value;return le.value=L,fe}le=le.right}while(le!==null);var _e={key:w,left:null,right:null,value:L,parent:G,color:0,getValue:function(){return this.value},getKey:function(){return this.key}};return K<0?G.left=_e:G.right=_e,this.fixAfterInsertion(_e),this.size_++,null}},{key:"fixAfterInsertion",value:function(w){var L;for(w.color=1;w!=null&&w!==this.root_&&w.parent.color===1;)xn(w)===Sc(xn(xn(w)))?oc(L=Cl(xn(xn(w))))===1?(na(xn(w),0),na(L,0),na(xn(xn(w)),1),w=xn(xn(w))):(w===Cl(xn(w))&&(w=xn(w),this.rotateLeft(w)),na(xn(w),0),na(xn(xn(w)),1),this.rotateRight(xn(xn(w)))):oc(L=Sc(xn(xn(w))))===1?(na(xn(w),0),na(L,0),na(xn(xn(w)),1),w=xn(xn(w))):(w===Sc(xn(w))&&(w=xn(w),this.rotateRight(w)),na(xn(w),0),na(xn(xn(w)),1),this.rotateLeft(xn(xn(w))));this.root_.color=0}},{key:"values",value:function(){var w=new Pt,L=this.getFirstEntry();if(L!==null)for(w.add(L.value);(L=b.successor(L))!==null;)w.add(L.value);return w}},{key:"entrySet",value:function(){var w=new di,L=this.getFirstEntry();if(L!==null)for(w.add(L);(L=b.successor(L))!==null;)w.add(L);return w}},{key:"rotateLeft",value:function(w){if(w!=null){var L=w.right;w.right=L.left,L.left!=null&&(L.left.parent=w),L.parent=w.parent,w.parent==null?this.root_=L:w.parent.left===w?w.parent.left=L:w.parent.right=L,L.left=w,w.parent=L}}},{key:"rotateRight",value:function(w){if(w!=null){var L=w.left;w.left=L.right,L.right!=null&&(L.right.parent=w),L.parent=w.parent,w.parent==null?this.root_=L:w.parent.right===w?w.parent.right=L:w.parent.left=L,L.right=w,w.parent=L}}},{key:"getFirstEntry",value:function(){var w=this.root_;if(w!=null)for(;w.left!=null;)w=w.left;return w}},{key:"size",value:function(){return this.size_}},{key:"containsKey",value:function(w){for(var L=this.root_;L!==null;){var G=w.compareTo(L.key);if(G<0)L=L.left;else{if(!(G>0))return!0;L=L.right}}return!1}}],[{key:"successor",value:function(w){var L;if(w===null)return null;if(w.right!==null){for(L=w.right;L.left!==null;)L=L.left;return L}L=w.parent;for(var G=w;L!==null&&G===L.right;)G=L,L=L.parent;return L}}])})(uu),vo=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"find",value:function(B){return this.nodeMap.get(B)}},{key:"addNode",value:function(){if(arguments[0]instanceof Le){var B=arguments[0],b=this.nodeMap.get(B);return b===null&&(b=this.nodeFact.createNode(B),this.nodeMap.put(B,b)),b}if(arguments[0]instanceof qa){var w=arguments[0],L=this.nodeMap.get(w.getCoordinate());return L===null?(this.nodeMap.put(w.getCoordinate(),w),w):(L.mergeLabel(w),L)}}},{key:"print",value:function(B){for(var b=this.iterator();b.hasNext();)b.next().print(B)}},{key:"iterator",value:function(){return this.nodeMap.values().iterator()}},{key:"values",value:function(){return this.nodeMap.values()}},{key:"getBoundaryNodes",value:function(B){for(var b=new Pt,w=this.iterator();w.hasNext();){var L=w.next();L.getLabel().getLocation(B)===Ae.BOUNDARY&&b.add(L)}return b}},{key:"add",value:function(B){var b=B.getCoordinate();this.addNode(b).add(B)}}],[{key:"constructor_",value:function(){this.nodeMap=new Fs,this.nodeFact=null;var B=arguments[0];this.nodeFact=B}}])})(),dr=(function(){function B(){r(this,B)}return l(B,null,[{key:"isNorthern",value:function(b){return b===B.NE||b===B.NW}},{key:"isOpposite",value:function(b,w){return b!==w&&(b-w+4)%4===2}},{key:"commonHalfPlane",value:function(b,w){if(b===w)return b;if((b-w+4)%4===2)return-1;var L=b<w?b:w;return L===0&&(b>w?b:w)===3?3:L}},{key:"isInHalfPlane",value:function(b,w){return w===B.SE?b===B.SE||b===B.SW:b===w||b===w+1}},{key:"quadrant",value:function(){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var b=arguments[0],w=arguments[1];if(b===0&&w===0)throw new Z("Cannot compute the quadrant for point ( "+b+", "+w+" )");return b>=0?w>=0?B.NE:B.SE:w>=0?B.NW:B.SW}if(arguments[0]instanceof Le&&arguments[1]instanceof Le){var L=arguments[0],G=arguments[1];if(G.x===L.x&&G.y===L.y)throw new Z("Cannot compute the quadrant for two identical points "+L);return G.x>=L.x?G.y>=L.y?B.NE:B.SE:G.y>=L.y?B.NW:B.SW}}}])})();dr.NE=0,dr.NW=1,dr.SW=2,dr.SE=3;var yo=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"compareDirection",value:function(b){return this._dx===b._dx&&this._dy===b._dy?0:this._quadrant>b._quadrant?1:this._quadrant<b._quadrant?-1:et.index(b._p0,b._p1,this._p1)}},{key:"getDy",value:function(){return this._dy}},{key:"getCoordinate",value:function(){return this._p0}},{key:"setNode",value:function(b){this._node=b}},{key:"print",value:function(b){var w=Math.atan2(this._dy,this._dx),L=this.getClass().getName(),G=L.lastIndexOf("."),K=L.substring(G+1);b.print(" "+K+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+w+" "+this._label)}},{key:"compareTo",value:function(b){var w=b;return this.compareDirection(w)}},{key:"getDirectedCoordinate",value:function(){return this._p1}},{key:"getDx",value:function(){return this._dx}},{key:"getLabel",value:function(){return this._label}},{key:"getEdge",value:function(){return this._edge}},{key:"getQuadrant",value:function(){return this._quadrant}},{key:"getNode",value:function(){return this._node}},{key:"toString",value:function(){var b=Math.atan2(this._dy,this._dx),w=this.getClass().getName(),L=w.lastIndexOf(".");return" "+w.substring(L+1)+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+b+" "+this._label}},{key:"computeLabel",value:function(b){}},{key:"init",value:function(b,w){this._p0=b,this._p1=w,this._dx=w.x-b.x,this._dy=w.y-b.y,this._quadrant=dr.quadrant(this._dx,this._dy),Se.isTrue(!(this._dx===0&&this._dy===0),"EdgeEnd with identical endpoints found")}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){if(this._edge=null,this._label=null,this._node=null,this._p0=null,this._p1=null,this._dx=null,this._dy=null,this._quadrant=null,arguments.length===1){var b=arguments[0];this._edge=b}else if(arguments.length===3){var w=arguments[0],L=arguments[1],G=arguments[2];B.constructor_.call(this,w,L,G,null)}else if(arguments.length===4){var K=arguments[0],le=arguments[1],fe=arguments[2],_e=arguments[3];B.constructor_.call(this,K),this.init(le,fe),this._label=_e}}}])})(),Mc=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"getNextMin",value:function(){return this._nextMin}},{key:"getDepth",value:function(w){return this._depth[w]}},{key:"setVisited",value:function(w){this._isVisited=w}},{key:"computeDirectedLabel",value:function(){this._label=new Jr(this._edge.getLabel()),this._isForward||this._label.flip()}},{key:"getNext",value:function(){return this._next}},{key:"setDepth",value:function(w,L){if(this._depth[w]!==-999&&this._depth[w]!==L)throw new ii("assigned depths do not match",this.getCoordinate());this._depth[w]=L}},{key:"isInteriorAreaEdge",value:function(){for(var w=!0,L=0;L<2;L++)this._label.isArea(L)&&this._label.getLocation(L,be.LEFT)===Ae.INTERIOR&&this._label.getLocation(L,be.RIGHT)===Ae.INTERIOR||(w=!1);return w}},{key:"setNextMin",value:function(w){this._nextMin=w}},{key:"print",value:function(w){E(b,"print",this,1).call(this,w),w.print(" "+this._depth[be.LEFT]+"/"+this._depth[be.RIGHT]),w.print(" ("+this.getDepthDelta()+")"),this._isInResult&&w.print(" inResult")}},{key:"setMinEdgeRing",value:function(w){this._minEdgeRing=w}},{key:"isLineEdge",value:function(){var w=this._label.isLine(0)||this._label.isLine(1),L=!this._label.isArea(0)||this._label.allPositionsEqual(0,Ae.EXTERIOR),G=!this._label.isArea(1)||this._label.allPositionsEqual(1,Ae.EXTERIOR);return w&&L&&G}},{key:"setEdgeRing",value:function(w){this._edgeRing=w}},{key:"getMinEdgeRing",value:function(){return this._minEdgeRing}},{key:"getDepthDelta",value:function(){var w=this._edge.getDepthDelta();return this._isForward||(w=-w),w}},{key:"setInResult",value:function(w){this._isInResult=w}},{key:"getSym",value:function(){return this._sym}},{key:"isForward",value:function(){return this._isForward}},{key:"getEdge",value:function(){return this._edge}},{key:"printEdge",value:function(w){this.print(w),w.print(" "),this._isForward?this._edge.print(w):this._edge.printReverse(w)}},{key:"setSym",value:function(w){this._sym=w}},{key:"setVisitedEdge",value:function(w){this.setVisited(w),this._sym.setVisited(w)}},{key:"setEdgeDepths",value:function(w,L){var G=this.getEdge().getDepthDelta();this._isForward||(G=-G);var K=1;w===be.LEFT&&(K=-1);var le=be.opposite(w),fe=L+G*K;this.setDepth(w,L),this.setDepth(le,fe)}},{key:"getEdgeRing",value:function(){return this._edgeRing}},{key:"isInResult",value:function(){return this._isInResult}},{key:"setNext",value:function(w){this._next=w}},{key:"isVisited",value:function(){return this._isVisited}}],[{key:"constructor_",value:function(){this._isForward=null,this._isInResult=!1,this._isVisited=!1,this._sym=null,this._next=null,this._nextMin=null,this._edgeRing=null,this._minEdgeRing=null,this._depth=[0,-999,-999];var w=arguments[0],L=arguments[1];if(yo.constructor_.call(this,w),this._isForward=L,L)this.init(w.getCoordinate(0),w.getCoordinate(1));else{var G=w.getNumPoints()-1;this.init(w.getCoordinate(G),w.getCoordinate(G-1))}this.computeDirectedLabel()}},{key:"depthFactor",value:function(w,L){return w===Ae.EXTERIOR&&L===Ae.INTERIOR?1:w===Ae.INTERIOR&&L===Ae.EXTERIOR?-1:0}}])})(yo),Ic=(function(){return l((function B(){r(this,B)}),[{key:"createNode",value:function(B){return new qa(B,null)}}])})(),du=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"printEdges",value:function(B){B.println("Edges:");for(var b=0;b<this._edges.size();b++){B.println("edge "+b+":");var w=this._edges.get(b);w.print(B),w.eiList.print(B)}}},{key:"find",value:function(B){return this._nodes.find(B)}},{key:"addNode",value:function(){if(arguments[0]instanceof qa){var B=arguments[0];return this._nodes.addNode(B)}if(arguments[0]instanceof Le){var b=arguments[0];return this._nodes.addNode(b)}}},{key:"getNodeIterator",value:function(){return this._nodes.iterator()}},{key:"linkResultDirectedEdges",value:function(){for(var B=this._nodes.iterator();B.hasNext();)B.next().getEdges().linkResultDirectedEdges()}},{key:"debugPrintln",value:function(B){Hi.out.println(B)}},{key:"isBoundaryNode",value:function(B,b){var w=this._nodes.find(b);if(w===null)return!1;var L=w.getLabel();return L!==null&&L.getLocation(B)===Ae.BOUNDARY}},{key:"linkAllDirectedEdges",value:function(){for(var B=this._nodes.iterator();B.hasNext();)B.next().getEdges().linkAllDirectedEdges()}},{key:"matchInSameDirection",value:function(B,b,w,L){return!!B.equals(w)&&et.index(B,b,L)===et.COLLINEAR&&dr.quadrant(B,b)===dr.quadrant(w,L)}},{key:"getEdgeEnds",value:function(){return this._edgeEndList}},{key:"debugPrint",value:function(B){Hi.out.print(B)}},{key:"getEdgeIterator",value:function(){return this._edges.iterator()}},{key:"findEdgeInSameDirection",value:function(B,b){for(var w=0;w<this._edges.size();w++){var L=this._edges.get(w),G=L.getCoordinates();if(this.matchInSameDirection(B,b,G[0],G[1])||this.matchInSameDirection(B,b,G[G.length-1],G[G.length-2]))return L}return null}},{key:"insertEdge",value:function(B){this._edges.add(B)}},{key:"findEdgeEnd",value:function(B){for(var b=this.getEdgeEnds().iterator();b.hasNext();){var w=b.next();if(w.getEdge()===B)return w}return null}},{key:"addEdges",value:function(B){for(var b=B.iterator();b.hasNext();){var w=b.next();this._edges.add(w);var L=new Mc(w,!0),G=new Mc(w,!1);L.setSym(G),G.setSym(L),this.add(L),this.add(G)}}},{key:"add",value:function(B){this._nodes.add(B),this._edgeEndList.add(B)}},{key:"getNodes",value:function(){return this._nodes.values()}},{key:"findEdge",value:function(B,b){for(var w=0;w<this._edges.size();w++){var L=this._edges.get(w),G=L.getCoordinates();if(B.equals(G[0])&&b.equals(G[1]))return L}return null}}],[{key:"constructor_",value:function(){if(this._edges=new Pt,this._nodes=null,this._edgeEndList=new Pt,arguments.length===0)this._nodes=new vo(new Ic);else if(arguments.length===1){var B=arguments[0];this._nodes=new vo(B)}}},{key:"linkResultDirectedEdges",value:function(B){for(var b=B.iterator();b.hasNext();)b.next().getEdges().linkResultDirectedEdges()}}])})(),ha=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"sortShellsAndHoles",value:function(b,w,L){for(var G=b.iterator();G.hasNext();){var K=G.next();K.isHole()?L.add(K):w.add(K)}}},{key:"computePolygons",value:function(b){for(var w=new Pt,L=b.iterator();L.hasNext();){var G=L.next().toPolygon(this._geometryFactory);w.add(G)}return w}},{key:"placeFreeHoles",value:function(b,w){for(var L=w.iterator();L.hasNext();){var G=L.next();if(G.getShell()===null){var K=B.findEdgeRingContaining(G,b);if(K===null)throw new ii("unable to assign hole to a shell",G.getCoordinate(0));G.setShell(K)}}}},{key:"buildMinimalEdgeRings",value:function(b,w,L){for(var G=new Pt,K=b.iterator();K.hasNext();){var le=K.next();if(le.getMaxNodeDegree()>2){le.linkDirectedEdgesForMinimalEdgeRings();var fe=le.buildMinimalRings(),_e=this.findShell(fe);_e!==null?(this.placePolygonHoles(_e,fe),w.add(_e)):L.addAll(fe)}else G.add(le)}return G}},{key:"buildMaximalEdgeRings",value:function(b){for(var w=new Pt,L=b.iterator();L.hasNext();){var G=L.next();if(G.isInResult()&&G.getLabel().isArea()&&G.getEdgeRing()===null){var K=new Ec(G,this._geometryFactory);w.add(K),K.setInResult()}}return w}},{key:"placePolygonHoles",value:function(b,w){for(var L=w.iterator();L.hasNext();){var G=L.next();G.isHole()&&G.setShell(b)}}},{key:"getPolygons",value:function(){return this.computePolygons(this._shellList)}},{key:"findShell",value:function(b){for(var w=0,L=null,G=b.iterator();G.hasNext();){var K=G.next();K.isHole()||(L=K,w++)}return Se.isTrue(w<=1,"found two shells in MinimalEdgeRing list"),L}},{key:"add",value:function(){if(arguments.length===1){var b=arguments[0];this.add(b.getEdgeEnds(),b.getNodes())}else if(arguments.length===2){var w=arguments[0],L=arguments[1];du.linkResultDirectedEdges(L);var G=this.buildMaximalEdgeRings(w),K=new Pt,le=this.buildMinimalEdgeRings(G,this._shellList,K);this.sortShellsAndHoles(le,this._shellList,K),this.placeFreeHoles(this._shellList,K)}}}],[{key:"constructor_",value:function(){this._geometryFactory=null,this._shellList=new Pt;var b=arguments[0];this._geometryFactory=b}},{key:"findEdgeRingContaining",value:function(b,w){for(var L=b.getLinearRing(),G=L.getEnvelopeInternal(),K=L.getCoordinateN(0),le=null,fe=null,_e=w.iterator();_e.hasNext();){var Oe=_e.next(),ut=Oe.getLinearRing(),_t=ut.getEnvelopeInternal();if(!_t.equals(G)&&_t.contains(G)){K=$n.ptNotInList(L.getCoordinates(),ut.getCoordinates());var St=!1;Ps.isInRing(K,ut.getCoordinates())&&(St=!0),St&&(le===null||fe.contains(_t))&&(fe=(le=Oe).getLinearRing().getEnvelopeInternal())}}return le}}])})(),ua=(function(){return l((function B(){r(this,B)}),[{key:"getBounds",value:function(){}}])})(),Ds=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getItem",value:function(){return this._item}},{key:"getBounds",value:function(){return this._bounds}},{key:"interfaces_",get:function(){return[ua,U]}}],[{key:"constructor_",value:function(){this._bounds=null,this._item=null;var B=arguments[0],b=arguments[1];this._bounds=B,this._item=b}}])})(),Tc=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"poll",value:function(){if(this.isEmpty())return null;var B=this._items.get(1);return this._items.set(1,this._items.get(this._size)),this._size-=1,this.reorder(1),B}},{key:"size",value:function(){return this._size}},{key:"reorder",value:function(B){for(var b=null,w=this._items.get(B);2*B<=this._size&&((b=2*B)!==this._size&&this._items.get(b+1).compareTo(this._items.get(b))<0&&b++,this._items.get(b).compareTo(w)<0);B=b)this._items.set(B,this._items.get(b));this._items.set(B,w)}},{key:"clear",value:function(){this._size=0,this._items.clear()}},{key:"peek",value:function(){return this.isEmpty()?null:this._items.get(1)}},{key:"isEmpty",value:function(){return this._size===0}},{key:"add",value:function(B){this._items.add(null),this._size+=1;var b=this._size;for(this._items.set(0,B);B.compareTo(this._items.get(Math.trunc(b/2)))<0;b/=2)this._items.set(b,this._items.get(Math.trunc(b/2)));this._items.set(b,B)}}],[{key:"constructor_",value:function(){this._size=null,this._items=null,this._size=0,this._items=new Pt,this._items.add(null)}}])})(),ld=(function(){return l((function B(){r(this,B)}),[{key:"insert",value:function(B,b){}},{key:"remove",value:function(B,b){}},{key:"query",value:function(){}}])})(),ra=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getLevel",value:function(){return this._level}},{key:"size",value:function(){return this._childBoundables.size()}},{key:"getChildBoundables",value:function(){return this._childBoundables}},{key:"addChildBoundable",value:function(B){Se.isTrue(this._bounds===null),this._childBoundables.add(B)}},{key:"isEmpty",value:function(){return this._childBoundables.isEmpty()}},{key:"getBounds",value:function(){return this._bounds===null&&(this._bounds=this.computeBounds()),this._bounds}},{key:"interfaces_",get:function(){return[ua,U]}}],[{key:"constructor_",value:function(){if(this._childBoundables=new Pt,this._bounds=null,this._level=null,arguments.length!==0){if(arguments.length===1){var B=arguments[0];this._level=B}}}}])})(),bo={reverseOrder:function(){return{compare:function(B,b){return b.compareTo(B)}}},min:function(B){return bo.sort(B),B.get(0)},sort:function(B,b){var w=B.toArray();b?Qe.sort(w,b):Qe.sort(w);for(var L=B.iterator(),G=0,K=w.length;G<K;G++)L.next(),L.set(w[G])},singletonList:function(B){var b=new Pt;return b.add(B),b}},cd=(function(){function B(){r(this,B)}return l(B,null,[{key:"maxDistance",value:function(b,w,L,G,K,le,fe,_e){var Oe=B.distance(b,w,K,le);return Oe=Math.max(Oe,B.distance(b,w,fe,_e)),Oe=Math.max(Oe,B.distance(L,G,K,le)),Oe=Math.max(Oe,B.distance(L,G,fe,_e))}},{key:"distance",value:function(b,w,L,G){var K=L-b,le=G-w;return Math.sqrt(K*K+le*le)}},{key:"maximumDistance",value:function(b,w){var L=Math.min(b.getMinX(),w.getMinX()),G=Math.min(b.getMinY(),w.getMinY()),K=Math.max(b.getMaxX(),w.getMaxX()),le=Math.max(b.getMaxY(),w.getMaxY());return B.distance(L,G,K,le)}},{key:"minMaxDistance",value:function(b,w){var L=b.getMinX(),G=b.getMinY(),K=b.getMaxX(),le=b.getMaxY(),fe=w.getMinX(),_e=w.getMinY(),Oe=w.getMaxX(),ut=w.getMaxY(),_t=B.maxDistance(L,G,L,le,fe,_e,fe,ut);return _t=Math.min(_t,B.maxDistance(L,G,L,le,fe,_e,Oe,_e)),_t=Math.min(_t,B.maxDistance(L,G,L,le,Oe,ut,fe,ut)),_t=Math.min(_t,B.maxDistance(L,G,L,le,Oe,ut,Oe,_e)),_t=Math.min(_t,B.maxDistance(L,G,K,G,fe,_e,fe,ut)),_t=Math.min(_t,B.maxDistance(L,G,K,G,fe,_e,Oe,_e)),_t=Math.min(_t,B.maxDistance(L,G,K,G,Oe,ut,fe,ut)),_t=Math.min(_t,B.maxDistance(L,G,K,G,Oe,ut,Oe,_e)),_t=Math.min(_t,B.maxDistance(K,le,L,le,fe,_e,fe,ut)),_t=Math.min(_t,B.maxDistance(K,le,L,le,fe,_e,Oe,_e)),_t=Math.min(_t,B.maxDistance(K,le,L,le,Oe,ut,fe,ut)),_t=Math.min(_t,B.maxDistance(K,le,L,le,Oe,ut,Oe,_e)),_t=Math.min(_t,B.maxDistance(K,le,K,G,fe,_e,fe,ut)),_t=Math.min(_t,B.maxDistance(K,le,K,G,fe,_e,Oe,_e)),_t=Math.min(_t,B.maxDistance(K,le,K,G,Oe,ut,fe,ut)),_t=Math.min(_t,B.maxDistance(K,le,K,G,Oe,ut,Oe,_e))}}])})(),da=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"maximumDistance",value:function(){return cd.maximumDistance(this._boundable1.getBounds(),this._boundable2.getBounds())}},{key:"expandToQueue",value:function(b,w){var L=B.isComposite(this._boundable1),G=B.isComposite(this._boundable2);if(L&&G)return B.area(this._boundable1)>B.area(this._boundable2)?(this.expand(this._boundable1,this._boundable2,!1,b,w),null):(this.expand(this._boundable2,this._boundable1,!0,b,w),null);if(L)return this.expand(this._boundable1,this._boundable2,!1,b,w),null;if(G)return this.expand(this._boundable2,this._boundable1,!0,b,w),null;throw new Z("neither boundable is composite")}},{key:"isLeaves",value:function(){return!(B.isComposite(this._boundable1)||B.isComposite(this._boundable2))}},{key:"compareTo",value:function(b){var w=b;return this._distance<w._distance?-1:this._distance>w._distance?1:0}},{key:"expand",value:function(b,w,L,G,K){for(var le=b.getChildBoundables().iterator();le.hasNext();){var fe=le.next(),_e=null;(_e=L?new B(w,fe,this._itemDistance):new B(fe,w,this._itemDistance)).getDistance()<K&&G.add(_e)}}},{key:"getBoundable",value:function(b){return b===0?this._boundable1:this._boundable2}},{key:"getDistance",value:function(){return this._distance}},{key:"distance",value:function(){return this.isLeaves()?this._itemDistance.distance(this._boundable1,this._boundable2):this._boundable1.getBounds().distance(this._boundable2.getBounds())}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){this._boundable1=null,this._boundable2=null,this._distance=null,this._itemDistance=null;var b=arguments[0],w=arguments[1],L=arguments[2];this._boundable1=b,this._boundable2=w,this._itemDistance=L,this._distance=this.distance()}},{key:"area",value:function(b){return b.getBounds().getArea()}},{key:"isComposite",value:function(b){return b instanceof ra}}])})(),yh=(function(){return l((function B(){r(this,B)}),[{key:"visitItem",value:function(B){}}])})(),El=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"queryInternal",value:function(){if(Pe(arguments[2],yh)&&arguments[0]instanceof Object&&arguments[1]instanceof ra)for(var b=arguments[0],w=arguments[2],L=arguments[1].getChildBoundables(),G=0;G<L.size();G++){var K=L.get(G);this.getIntersectsOp().intersects(K.getBounds(),b)&&(K instanceof ra?this.queryInternal(b,K,w):K instanceof Ds?w.visitItem(K.getItem()):Se.shouldNeverReachHere())}else if(Pe(arguments[2],ti)&&arguments[0]instanceof Object&&arguments[1]instanceof ra)for(var le=arguments[0],fe=arguments[2],_e=arguments[1].getChildBoundables(),Oe=0;Oe<_e.size();Oe++){var ut=_e.get(Oe);this.getIntersectsOp().intersects(ut.getBounds(),le)&&(ut instanceof ra?this.queryInternal(le,ut,fe):ut instanceof Ds?fe.add(ut.getItem()):Se.shouldNeverReachHere())}}},{key:"getNodeCapacity",value:function(){return this._nodeCapacity}},{key:"lastNode",value:function(b){return b.get(b.size()-1)}},{key:"size",value:function(){if(arguments.length===0)return this.isEmpty()?0:(this.build(),this.size(this._root));if(arguments.length===1){for(var b=0,w=arguments[0].getChildBoundables().iterator();w.hasNext();){var L=w.next();L instanceof ra?b+=this.size(L):L instanceof Ds&&(b+=1)}return b}}},{key:"removeItem",value:function(b,w){for(var L=null,G=b.getChildBoundables().iterator();G.hasNext();){var K=G.next();K instanceof Ds&&K.getItem()===w&&(L=K)}return L!==null&&(b.getChildBoundables().remove(L),!0)}},{key:"itemsTree",value:function(){if(arguments.length===0){this.build();var b=this.itemsTree(this._root);return b===null?new Pt:b}if(arguments.length===1){for(var w=arguments[0],L=new Pt,G=w.getChildBoundables().iterator();G.hasNext();){var K=G.next();if(K instanceof ra){var le=this.itemsTree(K);le!==null&&L.add(le)}else K instanceof Ds?L.add(K.getItem()):Se.shouldNeverReachHere()}return L.size()<=0?null:L}}},{key:"insert",value:function(b,w){Se.isTrue(!this._built,"Cannot insert items into an STR packed R-tree after it has been built."),this._itemBoundables.add(new Ds(b,w))}},{key:"boundablesAtLevel",value:function(){if(arguments.length===1){var b=arguments[0],w=new Pt;return this.boundablesAtLevel(b,this._root,w),w}if(arguments.length===3){var L=arguments[0],G=arguments[1],K=arguments[2];if(Se.isTrue(L>-2),G.getLevel()===L)return K.add(G),null;for(var le=G.getChildBoundables().iterator();le.hasNext();){var fe=le.next();fe instanceof ra?this.boundablesAtLevel(L,fe,K):(Se.isTrue(fe instanceof Ds),L===-1&&K.add(fe))}return null}}},{key:"query",value:function(){if(arguments.length===1){var b=arguments[0];this.build();var w=new Pt;return this.isEmpty()||this.getIntersectsOp().intersects(this._root.getBounds(),b)&&this.queryInternal(b,this._root,w),w}if(arguments.length===2){var L=arguments[0],G=arguments[1];if(this.build(),this.isEmpty())return null;this.getIntersectsOp().intersects(this._root.getBounds(),L)&&this.queryInternal(L,this._root,G)}}},{key:"build",value:function(){if(this._built)return null;this._root=this._itemBoundables.isEmpty()?this.createNode(0):this.createHigherLevels(this._itemBoundables,-1),this._itemBoundables=null,this._built=!0}},{key:"getRoot",value:function(){return this.build(),this._root}},{key:"remove",value:function(){if(arguments.length===2){var b=arguments[0],w=arguments[1];return this.build(),!!this.getIntersectsOp().intersects(this._root.getBounds(),b)&&this.remove(b,this._root,w)}if(arguments.length===3){var L=arguments[0],G=arguments[1],K=arguments[2],le=this.removeItem(G,K);if(le)return!0;for(var fe=null,_e=G.getChildBoundables().iterator();_e.hasNext();){var Oe=_e.next();if(this.getIntersectsOp().intersects(Oe.getBounds(),L)&&Oe instanceof ra&&(le=this.remove(L,Oe,K))){fe=Oe;break}}return fe!==null&&fe.getChildBoundables().isEmpty()&&G.getChildBoundables().remove(fe),le}}},{key:"createHigherLevels",value:function(b,w){Se.isTrue(!b.isEmpty());var L=this.createParentBoundables(b,w+1);return L.size()===1?L.get(0):this.createHigherLevels(L,w+1)}},{key:"depth",value:function(){if(arguments.length===0)return this.isEmpty()?0:(this.build(),this.depth(this._root));if(arguments.length===1){for(var b=0,w=arguments[0].getChildBoundables().iterator();w.hasNext();){var L=w.next();if(L instanceof ra){var G=this.depth(L);G>b&&(b=G)}}return b+1}}},{key:"createParentBoundables",value:function(b,w){Se.isTrue(!b.isEmpty());var L=new Pt;L.add(this.createNode(w));var G=new Pt(b);bo.sort(G,this.getComparator());for(var K=G.iterator();K.hasNext();){var le=K.next();this.lastNode(L).getChildBoundables().size()===this.getNodeCapacity()&&L.add(this.createNode(w)),this.lastNode(L).addChildBoundable(le)}return L}},{key:"isEmpty",value:function(){return this._built?this._root.isEmpty():this._itemBoundables.isEmpty()}},{key:"interfaces_",get:function(){return[U]}}],[{key:"constructor_",value:function(){if(this._root=null,this._built=!1,this._itemBoundables=new Pt,this._nodeCapacity=null,arguments.length===0)B.constructor_.call(this,B.DEFAULT_NODE_CAPACITY);else if(arguments.length===1){var b=arguments[0];Se.isTrue(b>1,"Node capacity must be greater than 1"),this._nodeCapacity=b}}},{key:"compareDoubles",value:function(b,w){return b>w?1:b<w?-1:0}}])})();El.IntersectsOp=function(){},El.DEFAULT_NODE_CAPACITY=10;var fu=(function(){return l((function B(){r(this,B)}),[{key:"distance",value:function(B,b){}}])})(),Ta=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"createParentBoundablesFromVerticalSlices",value:function(w,L){Se.isTrue(w.length>0);for(var G=new Pt,K=0;K<w.length;K++)G.addAll(this.createParentBoundablesFromVerticalSlice(w[K],L));return G}},{key:"nearestNeighbourK",value:function(){if(arguments.length===2){var w=arguments[0],L=arguments[1];return this.nearestNeighbourK(w,pe.POSITIVE_INFINITY,L)}if(arguments.length===3){var G=arguments[0],K=arguments[2],le=arguments[1],fe=new Tc;fe.add(G);for(var _e=new Tc;!fe.isEmpty()&&le>=0;){var Oe=fe.poll(),ut=Oe.getDistance();if(ut>=le)break;Oe.isLeaves()?_e.size()<K?_e.add(Oe):(_e.peek().getDistance()>ut&&(_e.poll(),_e.add(Oe)),le=_e.peek().getDistance()):Oe.expandToQueue(fe,le)}return b.getItems(_e)}}},{key:"createNode",value:function(w){return new pu(w)}},{key:"size",value:function(){return arguments.length===0?E(b,"size",this,1).call(this):E(b,"size",this,1).apply(this,arguments)}},{key:"insert",value:function(){if(!(arguments.length===2&&arguments[1]instanceof Object&&arguments[0]instanceof nt))return E(b,"insert",this,1).apply(this,arguments);var w=arguments[0],L=arguments[1];if(w.isNull())return null;E(b,"insert",this,1).call(this,w,L)}},{key:"getIntersectsOp",value:function(){return b.intersectsOp}},{key:"verticalSlices",value:function(w,L){for(var G=Math.trunc(Math.ceil(w.size()/L)),K=new Array(L).fill(null),le=w.iterator(),fe=0;fe<L;fe++){K[fe]=new Pt;for(var _e=0;le.hasNext()&&_e<G;){var Oe=le.next();K[fe].add(Oe),_e++}}return K}},{key:"query",value:function(){if(arguments.length===1){var w=arguments[0];return E(b,"query",this,1).call(this,w)}if(arguments.length===2){var L=arguments[0],G=arguments[1];E(b,"query",this,1).call(this,L,G)}}},{key:"getComparator",value:function(){return b.yComparator}},{key:"createParentBoundablesFromVerticalSlice",value:function(w,L){return E(b,"createParentBoundables",this,1).call(this,w,L)}},{key:"remove",value:function(){if(arguments.length===2&&arguments[1]instanceof Object&&arguments[0]instanceof nt){var w=arguments[0],L=arguments[1];return E(b,"remove",this,1).call(this,w,L)}return E(b,"remove",this,1).apply(this,arguments)}},{key:"depth",value:function(){return arguments.length===0?E(b,"depth",this,1).call(this):E(b,"depth",this,1).apply(this,arguments)}},{key:"createParentBoundables",value:function(w,L){Se.isTrue(!w.isEmpty());var G=Math.trunc(Math.ceil(w.size()/this.getNodeCapacity())),K=new Pt(w);bo.sort(K,b.xComparator);var le=this.verticalSlices(K,Math.trunc(Math.ceil(Math.sqrt(G))));return this.createParentBoundablesFromVerticalSlices(le,L)}},{key:"nearestNeighbour",value:function(){if(arguments.length===1){if(Pe(arguments[0],fu)){var w=arguments[0];if(this.isEmpty())return null;var L=new da(this.getRoot(),this.getRoot(),w);return this.nearestNeighbour(L)}if(arguments[0]instanceof da){var G=arguments[0],K=pe.POSITIVE_INFINITY,le=null,fe=new Tc;for(fe.add(G);!fe.isEmpty()&&K>0;){var _e=fe.poll(),Oe=_e.getDistance();if(Oe>=K)break;_e.isLeaves()?(K=Oe,le=_e):_e.expandToQueue(fe,K)}return le===null?null:[le.getBoundable(0).getItem(),le.getBoundable(1).getItem()]}}else{if(arguments.length===2){var ut=arguments[0],_t=arguments[1];if(this.isEmpty()||ut.isEmpty())return null;var St=new da(this.getRoot(),ut.getRoot(),_t);return this.nearestNeighbour(St)}if(arguments.length===3){var Mi=arguments[2],an=new Ds(arguments[0],arguments[1]),mn=new da(this.getRoot(),an,Mi);return this.nearestNeighbour(mn)[0]}if(arguments.length===4){var tr=arguments[2],Qi=arguments[3],vr=new Ds(arguments[0],arguments[1]),Hs=new da(this.getRoot(),vr,tr);return this.nearestNeighbourK(Hs,Qi)}}}},{key:"isWithinDistance",value:function(){if(arguments.length===2){var w=arguments[0],L=arguments[1],G=pe.POSITIVE_INFINITY,K=new Tc;for(K.add(w);!K.isEmpty();){var le=K.poll(),fe=le.getDistance();if(fe>L)return!1;if(le.maximumDistance()<=L)return!0;if(le.isLeaves()){if((G=fe)<=L)return!0}else le.expandToQueue(K,G)}return!1}if(arguments.length===3){var _e=arguments[0],Oe=arguments[1],ut=arguments[2],_t=new da(this.getRoot(),_e.getRoot(),Oe);return this.isWithinDistance(_t,ut)}}},{key:"interfaces_",get:function(){return[ld,U]}}],[{key:"constructor_",value:function(){if(arguments.length===0)b.constructor_.call(this,b.DEFAULT_NODE_CAPACITY);else if(arguments.length===1){var w=arguments[0];El.constructor_.call(this,w)}}},{key:"centreX",value:function(w){return b.avg(w.getMinX(),w.getMaxX())}},{key:"avg",value:function(w,L){return(w+L)/2}},{key:"getItems",value:function(w){for(var L=new Array(w.size()).fill(null),G=0;!w.isEmpty();)L[G]=w.poll().getBoundable(0).getItem(),G++;return L}},{key:"centreY",value:function(w){return b.avg(w.getMinY(),w.getMaxY())}}])})(El),pu=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"computeBounds",value:function(){for(var w=null,L=this.getChildBoundables().iterator();L.hasNext();){var G=L.next();w===null?w=new nt(G.getBounds()):w.expandToInclude(G.getBounds())}return w}}],[{key:"constructor_",value:function(){var w=arguments[0];ra.constructor_.call(this,w)}}])})(ra);Ta.STRtreeNode=pu,Ta.xComparator=new((function(){return l((function B(){r(this,B)}),[{key:"interfaces_",get:function(){return[Ie]}},{key:"compare",value:function(B,b){return El.compareDoubles(Ta.centreX(B.getBounds()),Ta.centreX(b.getBounds()))}}])})()),Ta.yComparator=new((function(){return l((function B(){r(this,B)}),[{key:"interfaces_",get:function(){return[Ie]}},{key:"compare",value:function(B,b){return El.compareDoubles(Ta.centreY(B.getBounds()),Ta.centreY(b.getBounds()))}}])})()),Ta.intersectsOp=new((function(){return l((function B(){r(this,B)}),[{key:"interfaces_",get:function(){return[IntersectsOp]}},{key:"intersects",value:function(B,b){return B.intersects(b)}}])})()),Ta.DEFAULT_NODE_CAPACITY=10;var xo=(function(){function B(){r(this,B)}return l(B,null,[{key:"relativeSign",value:function(b,w){return b<w?-1:b>w?1:0}},{key:"compare",value:function(b,w,L){if(w.equals2D(L))return 0;var G=B.relativeSign(w.x,L.x),K=B.relativeSign(w.y,L.y);switch(b){case 0:return B.compareValue(G,K);case 1:return B.compareValue(K,G);case 2:return B.compareValue(K,-G);case 3:return B.compareValue(-G,K);case 4:return B.compareValue(-G,-K);case 5:return B.compareValue(-K,-G);case 6:return B.compareValue(-K,G);case 7:return B.compareValue(G,-K)}return Se.shouldNeverReachHere("invalid octant value"),0}},{key:"compareValue",value:function(b,w){return b<0?-1:b>0?1:w<0?-1:w>0?1:0}}])})(),Tn=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(B){B.print(this.coord),B.print(" seg # = "+this.segmentIndex)}},{key:"compareTo",value:function(B){var b=B;return this.segmentIndex<b.segmentIndex?-1:this.segmentIndex>b.segmentIndex?1:this.coord.equals2D(b.coord)?0:this._isInterior?b._isInterior?xo.compare(this._segmentOctant,this.coord,b.coord):1:-1}},{key:"isEndPoint",value:function(B){return this.segmentIndex===0&&!this._isInterior||this.segmentIndex===B}},{key:"toString",value:function(){return this.segmentIndex+":"+this.coord.toString()}},{key:"isInterior",value:function(){return this._isInterior}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){this._segString=null,this.coord=null,this.segmentIndex=null,this._segmentOctant=null,this._isInterior=null;var B=arguments[0],b=arguments[1],w=arguments[2],L=arguments[3];this._segString=B,this.coord=new Le(b),this.segmentIndex=w,this._segmentOctant=L,this._isInterior=!b.equals2D(B.getCoordinate(w))}}])})(),Sl=(function(){return l((function B(){r(this,B)}),[{key:"hasNext",value:function(){}},{key:"next",value:function(){}},{key:"remove",value:function(){}}])})(),hd=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getSplitCoordinates",value:function(){var B=new kn;this.addEndpoints();for(var b=this.iterator(),w=b.next();b.hasNext();){var L=b.next();this.addEdgeCoordinates(w,L,B),w=L}return B.toCoordinateArray()}},{key:"addCollapsedNodes",value:function(){var B=new Pt;this.findCollapsesFromInsertedNodes(B),this.findCollapsesFromExistingVertices(B);for(var b=B.iterator();b.hasNext();){var w=b.next().intValue();this.add(this._edge.getCoordinate(w),w)}}},{key:"createSplitEdgePts",value:function(B,b){var w=b.segmentIndex-B.segmentIndex+2;if(w===2)return[new Le(B.coord),new Le(b.coord)];var L=this._edge.getCoordinate(b.segmentIndex),G=b.isInterior()||!b.coord.equals2D(L);G||w--;var K=new Array(w).fill(null),le=0;K[le++]=new Le(B.coord);for(var fe=B.segmentIndex+1;fe<=b.segmentIndex;fe++)K[le++]=this._edge.getCoordinate(fe);return G&&(K[le]=new Le(b.coord)),K}},{key:"print",value:function(B){B.println("Intersections:");for(var b=this.iterator();b.hasNext();)b.next().print(B)}},{key:"findCollapsesFromExistingVertices",value:function(B){for(var b=0;b<this._edge.size()-2;b++){var w=this._edge.getCoordinate(b);this._edge.getCoordinate(b+1);var L=this._edge.getCoordinate(b+2);w.equals2D(L)&&B.add(je.valueOf(b+1))}}},{key:"addEdgeCoordinates",value:function(B,b,w){var L=this.createSplitEdgePts(B,b);w.add(L,!1)}},{key:"iterator",value:function(){return this._nodeMap.values().iterator()}},{key:"addSplitEdges",value:function(B){this.addEndpoints(),this.addCollapsedNodes();for(var b=this.iterator(),w=b.next();b.hasNext();){var L=b.next(),G=this.createSplitEdge(w,L);B.add(G),w=L}}},{key:"findCollapseIndex",value:function(B,b,w){if(!B.coord.equals2D(b.coord))return!1;var L=b.segmentIndex-B.segmentIndex;return b.isInterior()||L--,L===1&&(w[0]=B.segmentIndex+1,!0)}},{key:"findCollapsesFromInsertedNodes",value:function(B){for(var b=new Array(1).fill(null),w=this.iterator(),L=w.next();w.hasNext();){var G=w.next();this.findCollapseIndex(L,G,b)&&B.add(je.valueOf(b[0])),L=G}}},{key:"getEdge",value:function(){return this._edge}},{key:"addEndpoints",value:function(){var B=this._edge.size()-1;this.add(this._edge.getCoordinate(0),0),this.add(this._edge.getCoordinate(B),B)}},{key:"createSplitEdge",value:function(B,b){return new fa(this.createSplitEdgePts(B,b),this._edge.getData())}},{key:"add",value:function(B,b){var w=new Tn(this._edge,B,b,this._edge.getSegmentOctant(b)),L=this._nodeMap.get(w);return L!==null?(Se.isTrue(L.coord.equals2D(B),"Found equal nodes with different coordinates"),L):(this._nodeMap.put(w,w),w)}},{key:"checkSplitEdgesCorrectness",value:function(B){var b=this._edge.getCoordinates(),w=B.get(0).getCoordinate(0);if(!w.equals2D(b[0]))throw new we("bad split edge start point at "+w);var L=B.get(B.size()-1).getCoordinates(),G=L[L.length-1];if(!G.equals2D(b[b.length-1]))throw new we("bad split edge end point at "+G)}}],[{key:"constructor_",value:function(){this._nodeMap=new Fs,this._edge=null;var B=arguments[0];this._edge=B}}])})(),wo=(function(){function B(){r(this,B)}return l(B,null,[{key:"octant",value:function(){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var b=arguments[0],w=arguments[1];if(b===0&&w===0)throw new Z("Cannot compute the octant for point ( "+b+", "+w+" )");var L=Math.abs(b),G=Math.abs(w);return b>=0?w>=0?L>=G?0:1:L>=G?7:6:w>=0?L>=G?3:2:L>=G?4:5}if(arguments[0]instanceof Le&&arguments[1]instanceof Le){var K=arguments[0],le=arguments[1],fe=le.x-K.x,_e=le.y-K.y;if(fe===0&&_e===0)throw new Z("Cannot compute the octant for two identical points "+K);return B.octant(fe,_e)}}}])})(),Ra=(function(){return l((function B(){r(this,B)}),[{key:"getCoordinates",value:function(){}},{key:"size",value:function(){}},{key:"getCoordinate",value:function(B){}},{key:"isClosed",value:function(){}},{key:"setData",value:function(B){}},{key:"getData",value:function(){}}])})(),Bn=(function(){return l((function B(){r(this,B)}),[{key:"addIntersection",value:function(B,b){}},{key:"interfaces_",get:function(){return[Ra]}}])})(),fa=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getCoordinates",value:function(){return this._pts}},{key:"size",value:function(){return this._pts.length}},{key:"getCoordinate",value:function(b){return this._pts[b]}},{key:"isClosed",value:function(){return this._pts[0].equals(this._pts[this._pts.length-1])}},{key:"getSegmentOctant",value:function(b){return b===this._pts.length-1?-1:this.safeOctant(this.getCoordinate(b),this.getCoordinate(b+1))}},{key:"setData",value:function(b){this._data=b}},{key:"safeOctant",value:function(b,w){return b.equals2D(w)?0:wo.octant(b,w)}},{key:"getData",value:function(){return this._data}},{key:"addIntersection",value:function(){if(arguments.length===2){var b=arguments[0],w=arguments[1];this.addIntersectionNode(b,w)}else if(arguments.length===4){var L=arguments[1],G=arguments[3],K=new Le(arguments[0].getIntersection(G));this.addIntersection(K,L)}}},{key:"toString",value:function(){return ca.toLineString(new bt(this._pts))}},{key:"getNodeList",value:function(){return this._nodeList}},{key:"addIntersectionNode",value:function(b,w){var L=w,G=L+1;if(G<this._pts.length){var K=this._pts[G];b.equals2D(K)&&(L=G)}return this._nodeList.add(b,L)}},{key:"addIntersections",value:function(b,w,L){for(var G=0;G<b.getIntersectionNum();G++)this.addIntersection(b,w,L,G)}},{key:"interfaces_",get:function(){return[Bn]}}],[{key:"constructor_",value:function(){this._nodeList=new hd(this),this._pts=null,this._data=null;var b=arguments[0],w=arguments[1];this._pts=b,this._data=w}},{key:"getNodedSubstrings",value:function(){if(arguments.length===1){var b=arguments[0],w=new Pt;return B.getNodedSubstrings(b,w),w}if(arguments.length===2)for(var L=arguments[1],G=arguments[0].iterator();G.hasNext();)G.next().getNodeList().addSplitEdges(L)}}])})(),bs=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"minX",value:function(){return Math.min(this.p0.x,this.p1.x)}},{key:"orientationIndex",value:function(){if(arguments[0]instanceof B){var b=arguments[0],w=et.index(this.p0,this.p1,b.p0),L=et.index(this.p0,this.p1,b.p1);return w>=0&&L>=0||w<=0&&L<=0?Math.max(w,L):0}if(arguments[0]instanceof Le){var G=arguments[0];return et.index(this.p0,this.p1,G)}}},{key:"toGeometry",value:function(b){return b.createLineString([this.p0,this.p1])}},{key:"isVertical",value:function(){return this.p0.x===this.p1.x}},{key:"equals",value:function(b){if(!(b instanceof B))return!1;var w=b;return this.p0.equals(w.p0)&&this.p1.equals(w.p1)}},{key:"intersection",value:function(b){var w=new ys;return w.computeIntersection(this.p0,this.p1,b.p0,b.p1),w.hasIntersection()?w.getIntersection(0):null}},{key:"project",value:function(){if(arguments[0]instanceof Le){var b=arguments[0];if(b.equals(this.p0)||b.equals(this.p1))return new Le(b);var w=this.projectionFactor(b),L=new Le;return L.x=this.p0.x+w*(this.p1.x-this.p0.x),L.y=this.p0.y+w*(this.p1.y-this.p0.y),L}if(arguments[0]instanceof B){var G=arguments[0],K=this.projectionFactor(G.p0),le=this.projectionFactor(G.p1);if(K>=1&&le>=1||K<=0&&le<=0)return null;var fe=this.project(G.p0);K<0&&(fe=this.p0),K>1&&(fe=this.p1);var _e=this.project(G.p1);return le<0&&(_e=this.p0),le>1&&(_e=this.p1),new B(fe,_e)}}},{key:"normalize",value:function(){this.p1.compareTo(this.p0)<0&&this.reverse()}},{key:"angle",value:function(){return Math.atan2(this.p1.y-this.p0.y,this.p1.x-this.p0.x)}},{key:"getCoordinate",value:function(b){return b===0?this.p0:this.p1}},{key:"distancePerpendicular",value:function(b){return ei.pointToLinePerpendicular(b,this.p0,this.p1)}},{key:"minY",value:function(){return Math.min(this.p0.y,this.p1.y)}},{key:"midPoint",value:function(){return B.midPoint(this.p0,this.p1)}},{key:"projectionFactor",value:function(b){if(b.equals(this.p0))return 0;if(b.equals(this.p1))return 1;var w=this.p1.x-this.p0.x,L=this.p1.y-this.p0.y,G=w*w+L*L;return G<=0?pe.NaN:((b.x-this.p0.x)*w+(b.y-this.p0.y)*L)/G}},{key:"closestPoints",value:function(b){var w=this.intersection(b);if(w!==null)return[w,w];var L=new Array(2).fill(null),G=pe.MAX_VALUE,K=null,le=this.closestPoint(b.p0);G=le.distance(b.p0),L[0]=le,L[1]=b.p0;var fe=this.closestPoint(b.p1);(K=fe.distance(b.p1))<G&&(G=K,L[0]=fe,L[1]=b.p1);var _e=b.closestPoint(this.p0);(K=_e.distance(this.p0))<G&&(G=K,L[0]=this.p0,L[1]=_e);var Oe=b.closestPoint(this.p1);return(K=Oe.distance(this.p1))<G&&(G=K,L[0]=this.p1,L[1]=Oe),L}},{key:"closestPoint",value:function(b){var w=this.projectionFactor(b);return w>0&&w<1?this.project(b):this.p0.distance(b)<this.p1.distance(b)?this.p0:this.p1}},{key:"maxX",value:function(){return Math.max(this.p0.x,this.p1.x)}},{key:"getLength",value:function(){return this.p0.distance(this.p1)}},{key:"compareTo",value:function(b){var w=b,L=this.p0.compareTo(w.p0);return L!==0?L:this.p1.compareTo(w.p1)}},{key:"reverse",value:function(){var b=this.p0;this.p0=this.p1,this.p1=b}},{key:"equalsTopo",value:function(b){return this.p0.equals(b.p0)&&this.p1.equals(b.p1)||this.p0.equals(b.p1)&&this.p1.equals(b.p0)}},{key:"lineIntersection",value:function(b){return hi.intersection(this.p0,this.p1,b.p0,b.p1)}},{key:"maxY",value:function(){return Math.max(this.p0.y,this.p1.y)}},{key:"pointAlongOffset",value:function(b,w){var L=this.p0.x+b*(this.p1.x-this.p0.x),G=this.p0.y+b*(this.p1.y-this.p0.y),K=this.p1.x-this.p0.x,le=this.p1.y-this.p0.y,fe=Math.sqrt(K*K+le*le),_e=0,Oe=0;if(w!==0){if(fe<=0)throw new IllegalStateException("Cannot compute offset from zero-length line segment");_e=w*K/fe,Oe=w*le/fe}return new Le(L-Oe,G+_e)}},{key:"setCoordinates",value:function(){if(arguments.length===1){var b=arguments[0];this.setCoordinates(b.p0,b.p1)}else if(arguments.length===2){var w=arguments[0],L=arguments[1];this.p0.x=w.x,this.p0.y=w.y,this.p1.x=L.x,this.p1.y=L.y}}},{key:"segmentFraction",value:function(b){var w=this.projectionFactor(b);return w<0?w=0:(w>1||pe.isNaN(w))&&(w=1),w}},{key:"toString",value:function(){return"LINESTRING( "+this.p0.x+" "+this.p0.y+", "+this.p1.x+" "+this.p1.y+")"}},{key:"isHorizontal",value:function(){return this.p0.y===this.p1.y}},{key:"reflect",value:function(b){var w=this.p1.getY()-this.p0.getY(),L=this.p0.getX()-this.p1.getX(),G=this.p0.getY()*(this.p1.getX()-this.p0.getX())-this.p0.getX()*(this.p1.getY()-this.p0.getY()),K=w*w+L*L,le=w*w-L*L,fe=b.getX(),_e=b.getY();return new Le((-le*fe-2*w*L*_e-2*w*G)/K,(le*_e-2*w*L*fe-2*L*G)/K)}},{key:"distance",value:function(){if(arguments[0]instanceof B){var b=arguments[0];return ei.segmentToSegment(this.p0,this.p1,b.p0,b.p1)}if(arguments[0]instanceof Le){var w=arguments[0];return ei.pointToSegment(w,this.p0,this.p1)}}},{key:"pointAlong",value:function(b){var w=new Le;return w.x=this.p0.x+b*(this.p1.x-this.p0.x),w.y=this.p0.y+b*(this.p1.y-this.p0.y),w}},{key:"hashCode",value:function(){var b=pe.doubleToLongBits(this.p0.x);b^=31*pe.doubleToLongBits(this.p0.y);var w=Math.trunc(b)^Math.trunc(b>>32),L=pe.doubleToLongBits(this.p1.x);return L^=31*pe.doubleToLongBits(this.p1.y),w^(Math.trunc(L)^Math.trunc(L>>32))}},{key:"interfaces_",get:function(){return[Q,U]}}],[{key:"constructor_",value:function(){if(this.p0=null,this.p1=null,arguments.length===0)B.constructor_.call(this,new Le,new Le);else if(arguments.length===1){var b=arguments[0];B.constructor_.call(this,b.p0,b.p1)}else if(arguments.length===2){var w=arguments[0],L=arguments[1];this.p0=w,this.p1=L}else if(arguments.length===4){var G=arguments[0],K=arguments[1],le=arguments[2],fe=arguments[3];B.constructor_.call(this,new Le(G,K),new Le(le,fe))}}},{key:"midPoint",value:function(b,w){return new Le((b.x+w.x)/2,(b.y+w.y)/2)}}])})(),pa=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"overlap",value:function(){if(arguments.length!==2){if(arguments.length===4){var B=arguments[1],b=arguments[2],w=arguments[3];arguments[0].getLineSegment(B,this._overlapSeg1),b.getLineSegment(w,this._overlapSeg2),this.overlap(this._overlapSeg1,this._overlapSeg2)}}}}],[{key:"constructor_",value:function(){this._overlapSeg1=new bs,this._overlapSeg2=new bs}}])})(),lc=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getLineSegment",value:function(B,b){b.p0=this._pts[B],b.p1=this._pts[B+1]}},{key:"computeSelect",value:function(B,b,w,L){var G=this._pts[b],K=this._pts[w];if(w-b==1)return L.select(this,b),null;if(!B.intersects(G,K))return null;var le=Math.trunc((b+w)/2);b<le&&this.computeSelect(B,b,le,L),le<w&&this.computeSelect(B,le,w,L)}},{key:"getCoordinates",value:function(){for(var B=new Array(this._end-this._start+1).fill(null),b=0,w=this._start;w<=this._end;w++)B[b++]=this._pts[w];return B}},{key:"computeOverlaps",value:function(){if(arguments.length===2){var B=arguments[0],b=arguments[1];this.computeOverlaps(this._start,this._end,B,B._start,B._end,b)}else if(arguments.length===6){var w=arguments[0],L=arguments[1],G=arguments[2],K=arguments[3],le=arguments[4],fe=arguments[5];if(L-w==1&&le-K==1)return fe.overlap(this,w,G,K),null;if(!this.overlaps(w,L,G,K,le))return null;var _e=Math.trunc((w+L)/2),Oe=Math.trunc((K+le)/2);w<_e&&(K<Oe&&this.computeOverlaps(w,_e,G,K,Oe,fe),Oe<le&&this.computeOverlaps(w,_e,G,Oe,le,fe)),_e<L&&(K<Oe&&this.computeOverlaps(_e,L,G,K,Oe,fe),Oe<le&&this.computeOverlaps(_e,L,G,Oe,le,fe))}}},{key:"setId",value:function(B){this._id=B}},{key:"select",value:function(B,b){this.computeSelect(B,this._start,this._end,b)}},{key:"getEnvelope",value:function(){if(this._env===null){var B=this._pts[this._start],b=this._pts[this._end];this._env=new nt(B,b)}return this._env}},{key:"overlaps",value:function(B,b,w,L,G){return nt.intersects(this._pts[B],this._pts[b],w._pts[L],w._pts[G])}},{key:"getEndIndex",value:function(){return this._end}},{key:"getStartIndex",value:function(){return this._start}},{key:"getContext",value:function(){return this._context}},{key:"getId",value:function(){return this._id}}],[{key:"constructor_",value:function(){this._pts=null,this._start=null,this._end=null,this._env=null,this._context=null,this._id=null;var B=arguments[0],b=arguments[1],w=arguments[2],L=arguments[3];this._pts=B,this._start=b,this._end=w,this._context=L}}])})(),Ml=(function(){function B(){r(this,B)}return l(B,null,[{key:"findChainEnd",value:function(b,w){for(var L=w;L<b.length-1&&b[L].equals2D(b[L+1]);)L++;if(L>=b.length-1)return b.length-1;for(var G=dr.quadrant(b[L],b[L+1]),K=w+1;K<b.length&&!(!b[K-1].equals2D(b[K])&&dr.quadrant(b[K-1],b[K])!==G);)K++;return K-1}},{key:"getChains",value:function(){if(arguments.length===1){var b=arguments[0];return B.getChains(b,null)}if(arguments.length===2){var w=arguments[0],L=arguments[1],G=new Pt,K=0;do{var le=B.findChainEnd(w,K),fe=new lc(w,K,le,L);G.add(fe),K=le}while(K<w.length-1);return G}}}])})(),Il=(function(){return l((function B(){r(this,B)}),[{key:"computeNodes",value:function(B){}},{key:"getNodedSubstrings",value:function(){}}])})(),Rc=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"setSegmentIntersector",value:function(B){this._segInt=B}},{key:"interfaces_",get:function(){return[Il]}}],[{key:"constructor_",value:function(){if(this._segInt=null,arguments.length!==0){if(arguments.length===1){var B=arguments[0];this.setSegmentIntersector(B)}}}}])})(),Tl=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"getMonotoneChains",value:function(){return this._monoChains}},{key:"getNodedSubstrings",value:function(){return fa.getNodedSubstrings(this._nodedSegStrings)}},{key:"getIndex",value:function(){return this._index}},{key:"add",value:function(w){for(var L=Ml.getChains(w.getCoordinates(),w).iterator();L.hasNext();){var G=L.next();G.setId(this._idCounter++),this._index.insert(G.getEnvelope(),G),this._monoChains.add(G)}}},{key:"computeNodes",value:function(w){this._nodedSegStrings=w;for(var L=w.iterator();L.hasNext();)this.add(L.next());this.intersectChains()}},{key:"intersectChains",value:function(){for(var w=new xe(this._segInt),L=this._monoChains.iterator();L.hasNext();)for(var G=L.next(),K=this._index.query(G.getEnvelope()).iterator();K.hasNext();){var le=K.next();if(le.getId()>G.getId()&&(G.computeOverlaps(le,w),this._nOverlaps++),this._segInt.isDone())return null}}}],[{key:"constructor_",value:function(){if(this._monoChains=new Pt,this._index=new Ta,this._idCounter=0,this._nodedSegStrings=null,this._nOverlaps=0,arguments.length!==0){if(arguments.length===1){var w=arguments[0];Rc.constructor_.call(this,w)}}}}])})(Rc),xe=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"overlap",value:function(){if(arguments.length!==4)return E(b,"overlap",this,1).apply(this,arguments);var w=arguments[1],L=arguments[2],G=arguments[3],K=arguments[0].getContext(),le=L.getContext();this._si.processIntersections(K,w,le,G)}}],[{key:"constructor_",value:function(){this._si=null;var w=arguments[0];this._si=w}}])})(pa);Tl.SegmentOverlapAction=xe;var ye=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"isDeletable",value:function(b,w,L,G){var K=this._inputLine[b],le=this._inputLine[w],fe=this._inputLine[L];return!!this.isConcave(K,le,fe)&&!!this.isShallow(K,le,fe,G)&&this.isShallowSampled(K,le,b,L,G)}},{key:"deleteShallowConcavities",value:function(){for(var b=1,w=this.findNextNonDeletedIndex(b),L=this.findNextNonDeletedIndex(w),G=!1;L<this._inputLine.length;){var K=!1;this.isDeletable(b,w,L,this._distanceTol)&&(this._isDeleted[w]=B.DELETE,K=!0,G=!0),b=K?L:w,w=this.findNextNonDeletedIndex(b),L=this.findNextNonDeletedIndex(w)}return G}},{key:"isShallowConcavity",value:function(b,w,L,G){return et.index(b,w,L)===this._angleOrientation&&ei.pointToSegment(w,b,L)<G}},{key:"isShallowSampled",value:function(b,w,L,G,K){var le=Math.trunc((G-L)/B.NUM_PTS_TO_CHECK);le<=0&&(le=1);for(var fe=L;fe<G;fe+=le)if(!this.isShallow(b,w,this._inputLine[fe],K))return!1;return!0}},{key:"isConcave",value:function(b,w,L){return et.index(b,w,L)===this._angleOrientation}},{key:"simplify",value:function(b){this._distanceTol=Math.abs(b),b<0&&(this._angleOrientation=et.CLOCKWISE),this._isDeleted=new Array(this._inputLine.length).fill(null);var w=!1;do w=this.deleteShallowConcavities();while(w);return this.collapseLine()}},{key:"findNextNonDeletedIndex",value:function(b){for(var w=b+1;w<this._inputLine.length&&this._isDeleted[w]===B.DELETE;)w++;return w}},{key:"isShallow",value:function(b,w,L,G){return ei.pointToSegment(w,b,L)<G}},{key:"collapseLine",value:function(){for(var b=new kn,w=0;w<this._inputLine.length;w++)this._isDeleted[w]!==B.DELETE&&b.add(this._inputLine[w]);return b.toCoordinateArray()}}],[{key:"constructor_",value:function(){this._inputLine=null,this._distanceTol=null,this._isDeleted=null,this._angleOrientation=et.COUNTERCLOCKWISE;var b=arguments[0];this._inputLine=b}},{key:"simplify",value:function(b,w){return new B(b).simplify(w)}}])})();ye.INIT=0,ye.DELETE=1,ye.KEEP=1,ye.NUM_PTS_TO_CHECK=10;var Ze=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getCoordinates",value:function(){return this._ptList.toArray(B.COORDINATE_ARRAY_TYPE)}},{key:"setPrecisionModel",value:function(b){this._precisionModel=b}},{key:"addPt",value:function(b){var w=new Le(b);if(this._precisionModel.makePrecise(w),this.isRedundant(w))return null;this._ptList.add(w)}},{key:"reverse",value:function(){}},{key:"addPts",value:function(b,w){if(w)for(var L=0;L<b.length;L++)this.addPt(b[L]);else for(var G=b.length-1;G>=0;G--)this.addPt(b[G])}},{key:"isRedundant",value:function(b){if(this._ptList.size()<1)return!1;var w=this._ptList.get(this._ptList.size()-1);return b.distance(w)<this._minimimVertexDistance}},{key:"toString",value:function(){return new qi().createLineString(this.getCoordinates()).toString()}},{key:"closeRing",value:function(){if(this._ptList.size()<1)return null;var b=new Le(this._ptList.get(0)),w=this._ptList.get(this._ptList.size()-1);if(b.equals(w))return null;this._ptList.add(b)}},{key:"setMinimumVertexDistance",value:function(b){this._minimimVertexDistance=b}}],[{key:"constructor_",value:function(){this._ptList=null,this._precisionModel=null,this._minimimVertexDistance=0,this._ptList=new Pt}}])})();Ze.COORDINATE_ARRAY_TYPE=new Array(0).fill(null);var j=(function(){function B(){r(this,B)}return l(B,null,[{key:"toDegrees",value:function(b){return 180*b/Math.PI}},{key:"normalize",value:function(b){for(;b>Math.PI;)b-=B.PI_TIMES_2;for(;b<=-Math.PI;)b+=B.PI_TIMES_2;return b}},{key:"angle",value:function(){if(arguments.length===1){var b=arguments[0];return Math.atan2(b.y,b.x)}if(arguments.length===2){var w=arguments[0],L=arguments[1],G=L.x-w.x,K=L.y-w.y;return Math.atan2(K,G)}}},{key:"isAcute",value:function(b,w,L){var G=b.x-w.x,K=b.y-w.y;return G*(L.x-w.x)+K*(L.y-w.y)>0}},{key:"isObtuse",value:function(b,w,L){var G=b.x-w.x,K=b.y-w.y;return G*(L.x-w.x)+K*(L.y-w.y)<0}},{key:"interiorAngle",value:function(b,w,L){var G=B.angle(w,b),K=B.angle(w,L);return Math.abs(K-G)}},{key:"normalizePositive",value:function(b){if(b<0){for(;b<0;)b+=B.PI_TIMES_2;b>=B.PI_TIMES_2&&(b=0)}else{for(;b>=B.PI_TIMES_2;)b-=B.PI_TIMES_2;b<0&&(b=0)}return b}},{key:"angleBetween",value:function(b,w,L){var G=B.angle(w,b),K=B.angle(w,L);return B.diff(G,K)}},{key:"diff",value:function(b,w){var L=null;return(L=b<w?w-b:b-w)>Math.PI&&(L=2*Math.PI-L),L}},{key:"toRadians",value:function(b){return b*Math.PI/180}},{key:"getTurn",value:function(b,w){var L=Math.sin(w-b);return L>0?B.COUNTERCLOCKWISE:L<0?B.CLOCKWISE:B.NONE}},{key:"angleBetweenOriented",value:function(b,w,L){var G=B.angle(w,b),K=B.angle(w,L)-G;return K<=-Math.PI?K+B.PI_TIMES_2:K>Math.PI?K-B.PI_TIMES_2:K}}])})();j.PI_TIMES_2=2*Math.PI,j.PI_OVER_2=Math.PI/2,j.PI_OVER_4=Math.PI/4,j.COUNTERCLOCKWISE=et.COUNTERCLOCKWISE,j.CLOCKWISE=et.CLOCKWISE,j.NONE=et.COLLINEAR;var pt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"addNextSegment",value:function(b,w){if(this._s0=this._s1,this._s1=this._s2,this._s2=b,this._seg0.setCoordinates(this._s0,this._s1),this.computeOffsetSegment(this._seg0,this._side,this._distance,this._offset0),this._seg1.setCoordinates(this._s1,this._s2),this.computeOffsetSegment(this._seg1,this._side,this._distance,this._offset1),this._s1.equals(this._s2))return null;var L=et.index(this._s0,this._s1,this._s2),G=L===et.CLOCKWISE&&this._side===be.LEFT||L===et.COUNTERCLOCKWISE&&this._side===be.RIGHT;L===0?this.addCollinear(w):G?this.addOutsideTurn(L,w):this.addInsideTurn(L,w)}},{key:"addLineEndCap",value:function(b,w){var L=new bs(b,w),G=new bs;this.computeOffsetSegment(L,be.LEFT,this._distance,G);var K=new bs;this.computeOffsetSegment(L,be.RIGHT,this._distance,K);var le=w.x-b.x,fe=w.y-b.y,_e=Math.atan2(fe,le);switch(this._bufParams.getEndCapStyle()){case D.CAP_ROUND:this._segList.addPt(G.p1),this.addDirectedFillet(w,_e+Math.PI/2,_e-Math.PI/2,et.CLOCKWISE,this._distance),this._segList.addPt(K.p1);break;case D.CAP_FLAT:this._segList.addPt(G.p1),this._segList.addPt(K.p1);break;case D.CAP_SQUARE:var Oe=new Le;Oe.x=Math.abs(this._distance)*Math.cos(_e),Oe.y=Math.abs(this._distance)*Math.sin(_e);var ut=new Le(G.p1.x+Oe.x,G.p1.y+Oe.y),_t=new Le(K.p1.x+Oe.x,K.p1.y+Oe.y);this._segList.addPt(ut),this._segList.addPt(_t)}}},{key:"getCoordinates",value:function(){return this._segList.getCoordinates()}},{key:"addMitreJoin",value:function(b,w,L,G){var K=hi.intersection(w.p0,w.p1,L.p0,L.p1);if(K!==null&&(G<=0?1:K.distance(b)/Math.abs(G))<=this._bufParams.getMitreLimit())return this._segList.addPt(K),null;this.addLimitedMitreJoin(w,L,G,this._bufParams.getMitreLimit())}},{key:"addOutsideTurn",value:function(b,w){if(this._offset0.p1.distance(this._offset1.p0)<this._distance*B.OFFSET_SEGMENT_SEPARATION_FACTOR)return this._segList.addPt(this._offset0.p1),null;this._bufParams.getJoinStyle()===D.JOIN_MITRE?this.addMitreJoin(this._s1,this._offset0,this._offset1,this._distance):this._bufParams.getJoinStyle()===D.JOIN_BEVEL?this.addBevelJoin(this._offset0,this._offset1):(w&&this._segList.addPt(this._offset0.p1),this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,b,this._distance),this._segList.addPt(this._offset1.p0))}},{key:"createSquare",value:function(b){this._segList.addPt(new Le(b.x+this._distance,b.y+this._distance)),this._segList.addPt(new Le(b.x+this._distance,b.y-this._distance)),this._segList.addPt(new Le(b.x-this._distance,b.y-this._distance)),this._segList.addPt(new Le(b.x-this._distance,b.y+this._distance)),this._segList.closeRing()}},{key:"addSegments",value:function(b,w){this._segList.addPts(b,w)}},{key:"addFirstSegment",value:function(){this._segList.addPt(this._offset1.p0)}},{key:"addCornerFillet",value:function(b,w,L,G,K){var le=w.x-b.x,fe=w.y-b.y,_e=Math.atan2(fe,le),Oe=L.x-b.x,ut=L.y-b.y,_t=Math.atan2(ut,Oe);G===et.CLOCKWISE?_e<=_t&&(_e+=2*Math.PI):_e>=_t&&(_e-=2*Math.PI),this._segList.addPt(w),this.addDirectedFillet(b,_e,_t,G,K),this._segList.addPt(L)}},{key:"addLastSegment",value:function(){this._segList.addPt(this._offset1.p1)}},{key:"initSideSegments",value:function(b,w,L){this._s1=b,this._s2=w,this._side=L,this._seg1.setCoordinates(b,w),this.computeOffsetSegment(this._seg1,L,this._distance,this._offset1)}},{key:"addLimitedMitreJoin",value:function(b,w,L,G){var K=this._seg0.p1,le=j.angle(K,this._seg0.p0),fe=j.angleBetweenOriented(this._seg0.p0,K,this._seg1.p1)/2,_e=j.normalize(le+fe),Oe=j.normalize(_e+Math.PI),ut=G*L,_t=L-ut*Math.abs(Math.sin(fe)),St=new bs(K,new Le(K.x+ut*Math.cos(Oe),K.y+ut*Math.sin(Oe))),Mi=St.pointAlongOffset(1,_t),an=St.pointAlongOffset(1,-_t);this._side===be.LEFT?(this._segList.addPt(Mi),this._segList.addPt(an)):(this._segList.addPt(an),this._segList.addPt(Mi))}},{key:"addDirectedFillet",value:function(b,w,L,G,K){var le=G===et.CLOCKWISE?-1:1,fe=Math.abs(w-L),_e=Math.trunc(fe/this._filletAngleQuantum+.5);if(_e<1)return null;for(var Oe=fe/_e,ut=new Le,_t=0;_t<_e;_t++){var St=w+le*_t*Oe;ut.x=b.x+K*Math.cos(St),ut.y=b.y+K*Math.sin(St),this._segList.addPt(ut)}}},{key:"computeOffsetSegment",value:function(b,w,L,G){var K=w===be.LEFT?1:-1,le=b.p1.x-b.p0.x,fe=b.p1.y-b.p0.y,_e=Math.sqrt(le*le+fe*fe),Oe=K*L*le/_e,ut=K*L*fe/_e;G.p0.x=b.p0.x-ut,G.p0.y=b.p0.y+Oe,G.p1.x=b.p1.x-ut,G.p1.y=b.p1.y+Oe}},{key:"addInsideTurn",value:function(b,w){if(this._li.computeIntersection(this._offset0.p0,this._offset0.p1,this._offset1.p0,this._offset1.p1),this._li.hasIntersection())this._segList.addPt(this._li.getIntersection(0));else if(this._hasNarrowConcaveAngle=!0,this._offset0.p1.distance(this._offset1.p0)<this._distance*B.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR)this._segList.addPt(this._offset0.p1);else{if(this._segList.addPt(this._offset0.p1),this._closingSegLengthFactor>0){var L=new Le((this._closingSegLengthFactor*this._offset0.p1.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset0.p1.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(L);var G=new Le((this._closingSegLengthFactor*this._offset1.p0.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset1.p0.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(G)}else this._segList.addPt(this._s1);this._segList.addPt(this._offset1.p0)}}},{key:"createCircle",value:function(b){var w=new Le(b.x+this._distance,b.y);this._segList.addPt(w),this.addDirectedFillet(b,0,2*Math.PI,-1,this._distance),this._segList.closeRing()}},{key:"addBevelJoin",value:function(b,w){this._segList.addPt(b.p1),this._segList.addPt(w.p0)}},{key:"init",value:function(b){this._distance=b,this._maxCurveSegmentError=b*(1-Math.cos(this._filletAngleQuantum/2)),this._segList=new Ze,this._segList.setPrecisionModel(this._precisionModel),this._segList.setMinimumVertexDistance(b*B.CURVE_VERTEX_SNAP_DISTANCE_FACTOR)}},{key:"addCollinear",value:function(b){this._li.computeIntersection(this._s0,this._s1,this._s1,this._s2),this._li.getIntersectionNum()>=2&&(this._bufParams.getJoinStyle()===D.JOIN_BEVEL||this._bufParams.getJoinStyle()===D.JOIN_MITRE?(b&&this._segList.addPt(this._offset0.p1),this._segList.addPt(this._offset1.p0)):this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,et.CLOCKWISE,this._distance))}},{key:"closeRing",value:function(){this._segList.closeRing()}},{key:"hasNarrowConcaveAngle",value:function(){return this._hasNarrowConcaveAngle}}],[{key:"constructor_",value:function(){this._maxCurveSegmentError=0,this._filletAngleQuantum=null,this._closingSegLengthFactor=1,this._segList=null,this._distance=0,this._precisionModel=null,this._bufParams=null,this._li=null,this._s0=null,this._s1=null,this._s2=null,this._seg0=new bs,this._seg1=new bs,this._offset0=new bs,this._offset1=new bs,this._side=0,this._hasNarrowConcaveAngle=!1;var b=arguments[0],w=arguments[1],L=arguments[2];this._precisionModel=b,this._bufParams=w,this._li=new ys,this._filletAngleQuantum=Math.PI/2/w.getQuadrantSegments(),w.getQuadrantSegments()>=8&&w.getJoinStyle()===D.JOIN_ROUND&&(this._closingSegLengthFactor=B.MAX_CLOSING_SEG_LEN_FACTOR),this.init(L)}}])})();pt.OFFSET_SEGMENT_SEPARATION_FACTOR=.001,pt.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR=.001,pt.CURVE_VERTEX_SNAP_DISTANCE_FACTOR=1e-6,pt.MAX_CLOSING_SEG_LEN_FACTOR=80;var f=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getOffsetCurve",value:function(b,w){if(this._distance=w,w===0)return null;var L=w<0,G=Math.abs(w),K=this.getSegGen(G);b.length<=1?this.computePointCurve(b[0],K):this.computeOffsetCurve(b,L,K);var le=K.getCoordinates();return L&&$n.reverse(le),le}},{key:"computeSingleSidedBufferCurve",value:function(b,w,L){var G=this.simplifyTolerance(this._distance);if(w){L.addSegments(b,!0);var K=ye.simplify(b,-G),le=K.length-1;L.initSideSegments(K[le],K[le-1],be.LEFT),L.addFirstSegment();for(var fe=le-2;fe>=0;fe--)L.addNextSegment(K[fe],!0)}else{L.addSegments(b,!1);var _e=ye.simplify(b,G),Oe=_e.length-1;L.initSideSegments(_e[0],_e[1],be.LEFT),L.addFirstSegment();for(var ut=2;ut<=Oe;ut++)L.addNextSegment(_e[ut],!0)}L.addLastSegment(),L.closeRing()}},{key:"computeRingBufferCurve",value:function(b,w,L){var G=this.simplifyTolerance(this._distance);w===be.RIGHT&&(G=-G);var K=ye.simplify(b,G),le=K.length-1;L.initSideSegments(K[le-1],K[0],w);for(var fe=1;fe<=le;fe++){var _e=fe!==1;L.addNextSegment(K[fe],_e)}L.closeRing()}},{key:"computeLineBufferCurve",value:function(b,w){var L=this.simplifyTolerance(this._distance),G=ye.simplify(b,L),K=G.length-1;w.initSideSegments(G[0],G[1],be.LEFT);for(var le=2;le<=K;le++)w.addNextSegment(G[le],!0);w.addLastSegment(),w.addLineEndCap(G[K-1],G[K]);var fe=ye.simplify(b,-L),_e=fe.length-1;w.initSideSegments(fe[_e],fe[_e-1],be.LEFT);for(var Oe=_e-2;Oe>=0;Oe--)w.addNextSegment(fe[Oe],!0);w.addLastSegment(),w.addLineEndCap(fe[1],fe[0]),w.closeRing()}},{key:"computePointCurve",value:function(b,w){switch(this._bufParams.getEndCapStyle()){case D.CAP_ROUND:w.createCircle(b);break;case D.CAP_SQUARE:w.createSquare(b)}}},{key:"getLineCurve",value:function(b,w){if(this._distance=w,this.isLineOffsetEmpty(w))return null;var L=Math.abs(w),G=this.getSegGen(L);if(b.length<=1)this.computePointCurve(b[0],G);else if(this._bufParams.isSingleSided()){var K=w<0;this.computeSingleSidedBufferCurve(b,K,G)}else this.computeLineBufferCurve(b,G);return G.getCoordinates()}},{key:"getBufferParameters",value:function(){return this._bufParams}},{key:"simplifyTolerance",value:function(b){return b*this._bufParams.getSimplifyFactor()}},{key:"getRingCurve",value:function(b,w,L){if(this._distance=L,b.length<=2)return this.getLineCurve(b,L);if(L===0)return B.copyCoordinates(b);var G=this.getSegGen(L);return this.computeRingBufferCurve(b,w,G),G.getCoordinates()}},{key:"computeOffsetCurve",value:function(b,w,L){var G=this.simplifyTolerance(this._distance);if(w){var K=ye.simplify(b,-G),le=K.length-1;L.initSideSegments(K[le],K[le-1],be.LEFT),L.addFirstSegment();for(var fe=le-2;fe>=0;fe--)L.addNextSegment(K[fe],!0)}else{var _e=ye.simplify(b,G),Oe=_e.length-1;L.initSideSegments(_e[0],_e[1],be.LEFT),L.addFirstSegment();for(var ut=2;ut<=Oe;ut++)L.addNextSegment(_e[ut],!0)}L.addLastSegment()}},{key:"isLineOffsetEmpty",value:function(b){return b===0||b<0&&!this._bufParams.isSingleSided()}},{key:"getSegGen",value:function(b){return new pt(this._precisionModel,this._bufParams,b)}}],[{key:"constructor_",value:function(){this._distance=0,this._precisionModel=null,this._bufParams=null;var b=arguments[0],w=arguments[1];this._precisionModel=b,this._bufParams=w}},{key:"copyCoordinates",value:function(b){for(var w=new Array(b.length).fill(null),L=0;L<w.length;L++)w[L]=new Le(b[L]);return w}}])})(),ie=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"findStabbedSegments",value:function(){if(arguments.length===1){for(var B=arguments[0],b=new Pt,w=this._subgraphs.iterator();w.hasNext();){var L=w.next(),G=L.getEnvelope();B.y<G.getMinY()||B.y>G.getMaxY()||this.findStabbedSegments(B,L.getDirectedEdges(),b)}return b}if(arguments.length===3){if(Pe(arguments[2],ti)&&arguments[0]instanceof Le&&arguments[1]instanceof Mc){for(var K=arguments[0],le=arguments[1],fe=arguments[2],_e=le.getEdge().getCoordinates(),Oe=0;Oe<_e.length-1;Oe++)if(this._seg.p0=_e[Oe],this._seg.p1=_e[Oe+1],this._seg.p0.y>this._seg.p1.y&&this._seg.reverse(),!(Math.max(this._seg.p0.x,this._seg.p1.x)<K.x||this._seg.isHorizontal()||K.y<this._seg.p0.y||K.y>this._seg.p1.y||et.index(this._seg.p0,this._seg.p1,K)===et.RIGHT)){var ut=le.getDepth(be.LEFT);this._seg.p0.equals(_e[Oe])||(ut=le.getDepth(be.RIGHT));var _t=new Me(this._seg,ut);fe.add(_t)}}else if(Pe(arguments[2],ti)&&arguments[0]instanceof Le&&Pe(arguments[1],ti))for(var St=arguments[0],Mi=arguments[2],an=arguments[1].iterator();an.hasNext();){var mn=an.next();mn.isForward()&&this.findStabbedSegments(St,mn,Mi)}}}},{key:"getDepth",value:function(B){var b=this.findStabbedSegments(B);return b.size()===0?0:bo.min(b)._leftDepth}}],[{key:"constructor_",value:function(){this._subgraphs=null,this._seg=new bs;var B=arguments[0];this._subgraphs=B}}])})(),Me=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"compareTo",value:function(B){var b=B;if(this._upwardSeg.minX()>=b._upwardSeg.maxX())return 1;if(this._upwardSeg.maxX()<=b._upwardSeg.minX())return-1;var w=this._upwardSeg.orientationIndex(b._upwardSeg);return w!==0||(w=-1*b._upwardSeg.orientationIndex(this._upwardSeg))!==0?w:this._upwardSeg.compareTo(b._upwardSeg)}},{key:"compareX",value:function(B,b){var w=B.p0.compareTo(b.p0);return w!==0?w:B.p1.compareTo(b.p1)}},{key:"toString",value:function(){return this._upwardSeg.toString()}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){this._upwardSeg=null,this._leftDepth=null;var B=arguments[0],b=arguments[1];this._upwardSeg=new bs(B),this._leftDepth=b}}])})();ie.DepthSegment=Me;var q=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,null,[{key:"constructor_",value:function(){F.constructor_.call(this,"Projective point not representable on the Cartesian plane.")}}])})(F),Be=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getY",value:function(){var b=this.y/this.w;if(pe.isNaN(b)||pe.isInfinite(b))throw new q;return b}},{key:"getX",value:function(){var b=this.x/this.w;if(pe.isNaN(b)||pe.isInfinite(b))throw new q;return b}},{key:"getCoordinate",value:function(){var b=new Le;return b.x=this.getX(),b.y=this.getY(),b}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.w=null,arguments.length===0)this.x=0,this.y=0,this.w=1;else if(arguments.length===1){var b=arguments[0];this.x=b.x,this.y=b.y,this.w=1}else if(arguments.length===2){if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var w=arguments[0],L=arguments[1];this.x=w,this.y=L,this.w=1}else if(arguments[0]instanceof B&&arguments[1]instanceof B){var G=arguments[0],K=arguments[1];this.x=G.y*K.w-K.y*G.w,this.y=K.x*G.w-G.x*K.w,this.w=G.x*K.y-K.x*G.y}else if(arguments[0]instanceof Le&&arguments[1]instanceof Le){var le=arguments[0],fe=arguments[1];this.x=le.y-fe.y,this.y=fe.x-le.x,this.w=le.x*fe.y-fe.x*le.y}}else if(arguments.length===3){var _e=arguments[0],Oe=arguments[1],ut=arguments[2];this.x=_e,this.y=Oe,this.w=ut}else if(arguments.length===4){var _t=arguments[0],St=arguments[1],Mi=arguments[2],an=arguments[3],mn=_t.y-St.y,tr=St.x-_t.x,Qi=_t.x*St.y-St.x*_t.y,vr=Mi.y-an.y,Hs=an.x-Mi.x,Os=Mi.x*an.y-an.x*Mi.y;this.x=tr*Os-Hs*Qi,this.y=vr*Qi-mn*Os,this.w=mn*Hs-vr*tr}}}])})(),m=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"area",value:function(){return B.area(this.p0,this.p1,this.p2)}},{key:"signedArea",value:function(){return B.signedArea(this.p0,this.p1,this.p2)}},{key:"interpolateZ",value:function(b){if(b===null)throw new Z("Supplied point is null.");return B.interpolateZ(b,this.p0,this.p1,this.p2)}},{key:"longestSideLength",value:function(){return B.longestSideLength(this.p0,this.p1,this.p2)}},{key:"isAcute",value:function(){return B.isAcute(this.p0,this.p1,this.p2)}},{key:"circumcentre",value:function(){return B.circumcentre(this.p0,this.p1,this.p2)}},{key:"area3D",value:function(){return B.area3D(this.p0,this.p1,this.p2)}},{key:"centroid",value:function(){return B.centroid(this.p0,this.p1,this.p2)}},{key:"inCentre",value:function(){return B.inCentre(this.p0,this.p1,this.p2)}}],[{key:"constructor_",value:function(){this.p0=null,this.p1=null,this.p2=null;var b=arguments[0],w=arguments[1],L=arguments[2];this.p0=b,this.p1=w,this.p2=L}},{key:"area",value:function(b,w,L){return Math.abs(((L.x-b.x)*(w.y-b.y)-(w.x-b.x)*(L.y-b.y))/2)}},{key:"signedArea",value:function(b,w,L){return((L.x-b.x)*(w.y-b.y)-(w.x-b.x)*(L.y-b.y))/2}},{key:"det",value:function(b,w,L,G){return b*G-w*L}},{key:"interpolateZ",value:function(b,w,L,G){var K=w.x,le=w.y,fe=L.x-K,_e=G.x-K,Oe=L.y-le,ut=G.y-le,_t=fe*ut-_e*Oe,St=b.x-K,Mi=b.y-le,an=(ut*St-_e*Mi)/_t,mn=(-Oe*St+fe*Mi)/_t;return w.getZ()+an*(L.getZ()-w.getZ())+mn*(G.getZ()-w.getZ())}},{key:"longestSideLength",value:function(b,w,L){var G=b.distance(w),K=w.distance(L),le=L.distance(b),fe=G;return K>fe&&(fe=K),le>fe&&(fe=le),fe}},{key:"circumcentreDD",value:function(b,w,L){var G=De.valueOf(b.x).subtract(L.x),K=De.valueOf(b.y).subtract(L.y),le=De.valueOf(w.x).subtract(L.x),fe=De.valueOf(w.y).subtract(L.y),_e=De.determinant(G,K,le,fe).multiply(2),Oe=G.sqr().add(K.sqr()),ut=le.sqr().add(fe.sqr()),_t=De.determinant(K,Oe,fe,ut),St=De.determinant(G,Oe,le,ut);return new Le(De.valueOf(L.x).subtract(_t.divide(_e)).doubleValue(),De.valueOf(L.y).add(St.divide(_e)).doubleValue())}},{key:"isAcute",value:function(b,w,L){return!!j.isAcute(b,w,L)&&!!j.isAcute(w,L,b)&&!!j.isAcute(L,b,w)}},{key:"circumcentre",value:function(b,w,L){var G=L.x,K=L.y,le=b.x-G,fe=b.y-K,_e=w.x-G,Oe=w.y-K,ut=2*B.det(le,fe,_e,Oe),_t=B.det(fe,le*le+fe*fe,Oe,_e*_e+Oe*Oe),St=B.det(le,le*le+fe*fe,_e,_e*_e+Oe*Oe);return new Le(G-_t/ut,K+St/ut)}},{key:"perpendicularBisector",value:function(b,w){var L=w.x-b.x,G=w.y-b.y;return new Be(new Be(b.x+L/2,b.y+G/2,1),new Be(b.x-G+L/2,b.y+L+G/2,1))}},{key:"angleBisector",value:function(b,w,L){var G=w.distance(b),K=G/(G+w.distance(L)),le=L.x-b.x,fe=L.y-b.y;return new Le(b.x+K*le,b.y+K*fe)}},{key:"area3D",value:function(b,w,L){var G=w.x-b.x,K=w.y-b.y,le=w.getZ()-b.getZ(),fe=L.x-b.x,_e=L.y-b.y,Oe=L.getZ()-b.getZ(),ut=K*Oe-le*_e,_t=le*fe-G*Oe,St=G*_e-K*fe,Mi=ut*ut+_t*_t+St*St;return Math.sqrt(Mi)/2}},{key:"centroid",value:function(b,w,L){return new Le((b.x+w.x+L.x)/3,(b.y+w.y+L.y)/3)}},{key:"inCentre",value:function(b,w,L){var G=w.distance(L),K=b.distance(L),le=b.distance(w),fe=G+K+le;return new Le((G*b.x+K*w.x+le*L.x)/fe,(G*b.y+K*w.y+le*L.y)/fe)}}])})(),ke=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"addRingSide",value:function(B,b,w,L,G){if(b===0&&B.length<nn.MINIMUM_VALID_SIZE)return null;var K=L,le=G;B.length>=nn.MINIMUM_VALID_SIZE&&et.isCCW(B)&&(K=G,le=L,w=be.opposite(w));var fe=this._curveBuilder.getRingCurve(B,w,b);this.addCurve(fe,K,le)}},{key:"addRingBothSides",value:function(B,b){this.addRingSide(B,b,be.LEFT,Ae.EXTERIOR,Ae.INTERIOR),this.addRingSide(B,b,be.RIGHT,Ae.INTERIOR,Ae.EXTERIOR)}},{key:"addPoint",value:function(B){if(this._distance<=0)return null;var b=B.getCoordinates(),w=this._curveBuilder.getLineCurve(b,this._distance);this.addCurve(w,Ae.EXTERIOR,Ae.INTERIOR)}},{key:"addPolygon",value:function(B){var b=this._distance,w=be.LEFT;this._distance<0&&(b=-this._distance,w=be.RIGHT);var L=B.getExteriorRing(),G=$n.removeRepeatedPoints(L.getCoordinates());if(this._distance<0&&this.isErodedCompletely(L,this._distance)||this._distance<=0&&G.length<3)return null;this.addRingSide(G,b,w,Ae.EXTERIOR,Ae.INTERIOR);for(var K=0;K<B.getNumInteriorRing();K++){var le=B.getInteriorRingN(K),fe=$n.removeRepeatedPoints(le.getCoordinates());this._distance>0&&this.isErodedCompletely(le,-this._distance)||this.addRingSide(fe,b,be.opposite(w),Ae.INTERIOR,Ae.EXTERIOR)}}},{key:"isTriangleErodedCompletely",value:function(B,b){var w=new m(B[0],B[1],B[2]),L=w.inCentre();return ei.pointToSegment(L,w.p0,w.p1)<Math.abs(b)}},{key:"addLineString",value:function(B){if(this._curveBuilder.isLineOffsetEmpty(this._distance))return null;var b=$n.removeRepeatedPoints(B.getCoordinates());if($n.isRing(b)&&!this._curveBuilder.getBufferParameters().isSingleSided())this.addRingBothSides(b,this._distance);else{var w=this._curveBuilder.getLineCurve(b,this._distance);this.addCurve(w,Ae.EXTERIOR,Ae.INTERIOR)}}},{key:"addCurve",value:function(B,b,w){if(B===null||B.length<2)return null;var L=new fa(B,new Jr(0,Ae.BOUNDARY,b,w));this._curveList.add(L)}},{key:"getCurves",value:function(){return this.add(this._inputGeom),this._curveList}},{key:"add",value:function(B){if(B.isEmpty())return null;if(B instanceof yt)this.addPolygon(B);else if(B instanceof _r)this.addLineString(B);else if(B instanceof sr)this.addPoint(B);else if(B instanceof ki)this.addCollection(B);else if(B instanceof tn)this.addCollection(B);else if(B instanceof Wt)this.addCollection(B);else{if(!(B instanceof Zt))throw new $t(B.getGeometryType());this.addCollection(B)}}},{key:"isErodedCompletely",value:function(B,b){var w=B.getCoordinates();if(w.length<4)return b<0;if(w.length===4)return this.isTriangleErodedCompletely(w,b);var L=B.getEnvelopeInternal(),G=Math.min(L.getHeight(),L.getWidth());return b<0&&2*Math.abs(b)>G}},{key:"addCollection",value:function(B){for(var b=0;b<B.getNumGeometries();b++){var w=B.getGeometryN(b);this.add(w)}}}],[{key:"constructor_",value:function(){this._inputGeom=null,this._distance=null,this._curveBuilder=null,this._curveList=new Pt;var B=arguments[0],b=arguments[1],w=arguments[2];this._inputGeom=B,this._distance=b,this._curveBuilder=w}}])})(),xt=(function(){return l((function B(){r(this,B)}),[{key:"locate",value:function(B){}}])})(),Et=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"next",value:function(){if(this._atStart)return this._atStart=!1,B.isAtomic(this._parent)&&this._index++,this._parent;if(this._subcollectionIterator!==null){if(this._subcollectionIterator.hasNext())return this._subcollectionIterator.next();this._subcollectionIterator=null}if(this._index>=this._max)throw new Ne;var b=this._parent.getGeometryN(this._index++);return b instanceof Zt?(this._subcollectionIterator=new B(b),this._subcollectionIterator.next()):b}},{key:"remove",value:function(){throw new $t(this.getClass().getName())}},{key:"hasNext",value:function(){if(this._atStart)return!0;if(this._subcollectionIterator!==null){if(this._subcollectionIterator.hasNext())return!0;this._subcollectionIterator=null}return!(this._index>=this._max)}},{key:"interfaces_",get:function(){return[Sl]}}],[{key:"constructor_",value:function(){this._parent=null,this._atStart=null,this._max=null,this._index=null,this._subcollectionIterator=null;var b=arguments[0];this._parent=b,this._atStart=!0,this._index=0,this._max=b.getNumGeometries()}},{key:"isAtomic",value:function(b){return!(b instanceof Zt)}}])})(),Je=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"locate",value:function(b){return B.locate(b,this._geom)}},{key:"interfaces_",get:function(){return[xt]}}],[{key:"constructor_",value:function(){this._geom=null;var b=arguments[0];this._geom=b}},{key:"locatePointInPolygon",value:function(b,w){if(w.isEmpty())return Ae.EXTERIOR;var L=w.getExteriorRing(),G=B.locatePointInRing(b,L);if(G!==Ae.INTERIOR)return G;for(var K=0;K<w.getNumInteriorRing();K++){var le=w.getInteriorRingN(K),fe=B.locatePointInRing(b,le);if(fe===Ae.BOUNDARY)return Ae.BOUNDARY;if(fe===Ae.INTERIOR)return Ae.EXTERIOR}return Ae.INTERIOR}},{key:"locatePointInRing",value:function(b,w){return w.getEnvelopeInternal().intersects(b)?Ps.locateInRing(b,w.getCoordinates()):Ae.EXTERIOR}},{key:"containsPointInPolygon",value:function(b,w){return Ae.EXTERIOR!==B.locatePointInPolygon(b,w)}},{key:"locateInGeometry",value:function(b,w){if(w instanceof yt)return B.locatePointInPolygon(b,w);if(w instanceof Zt)for(var L=new Et(w);L.hasNext();){var G=L.next();if(G!==w){var K=B.locateInGeometry(b,G);if(K!==Ae.EXTERIOR)return K}}return Ae.EXTERIOR}},{key:"isContained",value:function(b,w){return Ae.EXTERIOR!==B.locate(b,w)}},{key:"locate",value:function(b,w){return w.isEmpty()?Ae.EXTERIOR:w.getEnvelopeInternal().intersects(b)?B.locateInGeometry(b,w):Ae.EXTERIOR}}])})(),zt=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"linkResultDirectedEdges",value:function(){this.getResultAreaEdges();for(var w=null,L=null,G=this._SCANNING_FOR_INCOMING,K=0;K<this._resultAreaEdgeList.size();K++){var le=this._resultAreaEdgeList.get(K),fe=le.getSym();if(le.getLabel().isArea())switch(w===null&&le.isInResult()&&(w=le),G){case this._SCANNING_FOR_INCOMING:if(!fe.isInResult())continue;L=fe,G=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(!le.isInResult())continue;L.setNext(le),G=this._SCANNING_FOR_INCOMING}}if(G===this._LINKING_TO_OUTGOING){if(w===null)throw new ii("no outgoing dirEdge found",this.getCoordinate());Se.isTrue(w.isInResult(),"unable to link last incoming dirEdge"),L.setNext(w)}}},{key:"insert",value:function(w){var L=w;this.insertEdgeEnd(L,L)}},{key:"getRightmostEdge",value:function(){var w=this.getEdges(),L=w.size();if(L<1)return null;var G=w.get(0);if(L===1)return G;var K=w.get(L-1),le=G.getQuadrant(),fe=K.getQuadrant();return dr.isNorthern(le)&&dr.isNorthern(fe)?G:dr.isNorthern(le)||dr.isNorthern(fe)?G.getDy()!==0?G:K.getDy()!==0?K:(Se.shouldNeverReachHere("found two horizontal edges incident on node"),null):K}},{key:"print",value:function(w){Hi.out.println("DirectedEdgeStar: "+this.getCoordinate());for(var L=this.iterator();L.hasNext();){var G=L.next();w.print("out "),G.print(w),w.println(),w.print("in "),G.getSym().print(w),w.println()}}},{key:"getResultAreaEdges",value:function(){if(this._resultAreaEdgeList!==null)return this._resultAreaEdgeList;this._resultAreaEdgeList=new Pt;for(var w=this.iterator();w.hasNext();){var L=w.next();(L.isInResult()||L.getSym().isInResult())&&this._resultAreaEdgeList.add(L)}return this._resultAreaEdgeList}},{key:"updateLabelling",value:function(w){for(var L=this.iterator();L.hasNext();){var G=L.next().getLabel();G.setAllLocationsIfNull(0,w.getLocation(0)),G.setAllLocationsIfNull(1,w.getLocation(1))}}},{key:"linkAllDirectedEdges",value:function(){this.getEdges();for(var w=null,L=null,G=this._edgeList.size()-1;G>=0;G--){var K=this._edgeList.get(G),le=K.getSym();L===null&&(L=le),w!==null&&le.setNext(w),w=K}L.setNext(w)}},{key:"computeDepths",value:function(){if(arguments.length===1){var w=arguments[0],L=this.findIndex(w),G=w.getDepth(be.LEFT),K=w.getDepth(be.RIGHT),le=this.computeDepths(L+1,this._edgeList.size(),G);if(this.computeDepths(0,L,le)!==K)throw new ii("depth mismatch at "+w.getCoordinate())}else if(arguments.length===3){for(var fe=arguments[1],_e=arguments[2],Oe=arguments[0];Oe<fe;Oe++){var ut=this._edgeList.get(Oe);ut.setEdgeDepths(be.RIGHT,_e),_e=ut.getDepth(be.LEFT)}return _e}}},{key:"mergeSymLabels",value:function(){for(var w=this.iterator();w.hasNext();){var L=w.next();L.getLabel().merge(L.getSym().getLabel())}}},{key:"linkMinimalDirectedEdges",value:function(w){for(var L=null,G=null,K=this._SCANNING_FOR_INCOMING,le=this._resultAreaEdgeList.size()-1;le>=0;le--){var fe=this._resultAreaEdgeList.get(le),_e=fe.getSym();switch(L===null&&fe.getEdgeRing()===w&&(L=fe),K){case this._SCANNING_FOR_INCOMING:if(_e.getEdgeRing()!==w)continue;G=_e,K=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(fe.getEdgeRing()!==w)continue;G.setNextMin(fe),K=this._SCANNING_FOR_INCOMING}}K===this._LINKING_TO_OUTGOING&&(Se.isTrue(L!==null,"found null for first outgoing dirEdge"),Se.isTrue(L.getEdgeRing()===w,"unable to link last incoming dirEdge"),G.setNextMin(L))}},{key:"getOutgoingDegree",value:function(){if(arguments.length===0){for(var w=0,L=this.iterator();L.hasNext();)L.next().isInResult()&&w++;return w}if(arguments.length===1){for(var G=arguments[0],K=0,le=this.iterator();le.hasNext();)le.next().getEdgeRing()===G&&K++;return K}}},{key:"getLabel",value:function(){return this._label}},{key:"findCoveredLineEdges",value:function(){for(var w=Ae.NONE,L=this.iterator();L.hasNext();){var G=L.next(),K=G.getSym();if(!G.isLineEdge()){if(G.isInResult()){w=Ae.INTERIOR;break}if(K.isInResult()){w=Ae.EXTERIOR;break}}}if(w===Ae.NONE)return null;for(var le=w,fe=this.iterator();fe.hasNext();){var _e=fe.next(),Oe=_e.getSym();_e.isLineEdge()?_e.getEdge().setCovered(le===Ae.INTERIOR):(_e.isInResult()&&(le=Ae.EXTERIOR),Oe.isInResult()&&(le=Ae.INTERIOR))}}},{key:"computeLabelling",value:function(w){E(b,"computeLabelling",this,1).call(this,w),this._label=new Jr(Ae.NONE);for(var L=this.iterator();L.hasNext();)for(var G=L.next().getEdge().getLabel(),K=0;K<2;K++){var le=G.getLocation(K);le!==Ae.INTERIOR&&le!==Ae.BOUNDARY||this._label.setLocation(K,Ae.INTERIOR)}}}],[{key:"constructor_",value:function(){this._resultAreaEdgeList=null,this._label=null,this._SCANNING_FOR_INCOMING=1,this._LINKING_TO_OUTGOING=2}}])})((function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getNextCW",value:function(B){this.getEdges();var b=this._edgeList.indexOf(B),w=b-1;return b===0&&(w=this._edgeList.size()-1),this._edgeList.get(w)}},{key:"propagateSideLabels",value:function(B){for(var b=Ae.NONE,w=this.iterator();w.hasNext();){var L=w.next().getLabel();L.isArea(B)&&L.getLocation(B,be.LEFT)!==Ae.NONE&&(b=L.getLocation(B,be.LEFT))}if(b===Ae.NONE)return null;for(var G=b,K=this.iterator();K.hasNext();){var le=K.next(),fe=le.getLabel();if(fe.getLocation(B,be.ON)===Ae.NONE&&fe.setLocation(B,be.ON,G),fe.isArea(B)){var _e=fe.getLocation(B,be.LEFT),Oe=fe.getLocation(B,be.RIGHT);if(Oe!==Ae.NONE){if(Oe!==G)throw new ii("side location conflict",le.getCoordinate());_e===Ae.NONE&&Se.shouldNeverReachHere("found single null side (at "+le.getCoordinate()+")"),G=_e}else Se.isTrue(fe.getLocation(B,be.LEFT)===Ae.NONE,"found single null side"),fe.setLocation(B,be.RIGHT,G),fe.setLocation(B,be.LEFT,G)}}}},{key:"getCoordinate",value:function(){var B=this.iterator();return B.hasNext()?B.next().getCoordinate():null}},{key:"print",value:function(B){Hi.out.println("EdgeEndStar: "+this.getCoordinate());for(var b=this.iterator();b.hasNext();)b.next().print(B)}},{key:"isAreaLabelsConsistent",value:function(B){return this.computeEdgeEndLabels(B.getBoundaryNodeRule()),this.checkAreaLabelsConsistent(0)}},{key:"checkAreaLabelsConsistent",value:function(B){var b=this.getEdges();if(b.size()<=0)return!0;var w=b.size()-1,L=b.get(w).getLabel().getLocation(B,be.LEFT);Se.isTrue(L!==Ae.NONE,"Found unlabelled area edge");for(var G=L,K=this.iterator();K.hasNext();){var le=K.next().getLabel();Se.isTrue(le.isArea(B),"Found non-area edge");var fe=le.getLocation(B,be.LEFT),_e=le.getLocation(B,be.RIGHT);if(fe===_e||_e!==G)return!1;G=fe}return!0}},{key:"findIndex",value:function(B){this.iterator();for(var b=0;b<this._edgeList.size();b++)if(this._edgeList.get(b)===B)return b;return-1}},{key:"iterator",value:function(){return this.getEdges().iterator()}},{key:"getEdges",value:function(){return this._edgeList===null&&(this._edgeList=new Pt(this._edgeMap.values())),this._edgeList}},{key:"getLocation",value:function(B,b,w){return this._ptInAreaLocation[B]===Ae.NONE&&(this._ptInAreaLocation[B]=Je.locate(b,w[B].getGeometry())),this._ptInAreaLocation[B]}},{key:"toString",value:function(){var B=new ve;B.append("EdgeEndStar: "+this.getCoordinate()),B.append(`
|
|
269
269
|
`);for(var b=this.iterator();b.hasNext();){var w=b.next();B.append(w),B.append(`
|
|
270
|
-
`)}return B.toString()}},{key:"computeEdgeEndLabels",value:function(B){for(var b=this.iterator();b.hasNext();)b.next().computeLabel(B)}},{key:"computeLabelling",value:function(B){this.computeEdgeEndLabels(B[0].getBoundaryNodeRule()),this.propagateSideLabels(0),this.propagateSideLabels(1);for(var b=[!1,!1],w=this.iterator();w.hasNext();)for(var L=w.next().getLabel(),G=0;G<2;G++)L.isLine(G)&&L.getLocation(G)===Ae.BOUNDARY&&(b[G]=!0);for(var K=this.iterator();K.hasNext();)for(var le=K.next(),fe=le.getLabel(),_e=0;_e<2;_e++)if(fe.isAnyNull(_e)){var Oe=Ae.NONE;if(b[_e])Oe=Ae.EXTERIOR;else{var ut=le.getCoordinate();Oe=this.getLocation(_e,ut,B)}fe.setAllLocationsIfNull(_e,Oe)}}},{key:"getDegree",value:function(){return this._edgeMap.size()}},{key:"insertEdgeEnd",value:function(B,b){this._edgeMap.put(B,b),this._edgeList=null}}],[{key:"constructor_",value:function(){this._edgeMap=new Fs,this._edgeList=null,this._ptInAreaLocation=[Ae.NONE,Ae.NONE]}}])})()),bi=(function(B){function b(){return r(this,b),n(this,b)}return g(b,B),l(b,[{key:"createNode",value:function(w){return new qa(w,new zt)}}])})(Ic),wn=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"compareTo",value:function(b){var w=b;return B.compareOriented(this._pts,this._orientation,w._pts,w._orientation)}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){this._pts=null,this._orientation=null;var b=arguments[0];this._pts=b,this._orientation=B.orientation(b)}},{key:"orientation",value:function(b){return $n.increasingDirection(b)===1}},{key:"compareOriented",value:function(b,w,L,G){for(var K=w?1:-1,le=G?1:-1,fe=w?b.length:-1,_e=G?L.length:-1,Oe=w?0:b.length-1,ut=G?0:L.length-1;;){var _t=b[Oe].compareTo(L[ut]);if(_t!==0)return _t;var St=(Oe+=K)===fe,Mi=(ut+=le)===_e;if(St&&!Mi)return-1;if(!St&&Mi)return 1;if(St&&Mi)return 0}}}])})(),dn=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"print",value:function(B){B.print("MULTILINESTRING ( ");for(var b=0;b<this._edges.size();b++){var w=this._edges.get(b);b>0&&B.print(","),B.print("(");for(var L=w.getCoordinates(),G=0;G<L.length;G++)G>0&&B.print(","),B.print(L[G].x+" "+L[G].y);B.println(")")}B.print(") ")}},{key:"addAll",value:function(B){for(var b=B.iterator();b.hasNext();)this.add(b.next())}},{key:"findEdgeIndex",value:function(B){for(var b=0;b<this._edges.size();b++)if(this._edges.get(b).equals(B))return b;return-1}},{key:"iterator",value:function(){return this._edges.iterator()}},{key:"getEdges",value:function(){return this._edges}},{key:"get",value:function(B){return this._edges.get(B)}},{key:"findEqualEdge",value:function(B){var b=new wn(B.getCoordinates());return this._ocaMap.get(b)}},{key:"add",value:function(B){this._edges.add(B);var b=new wn(B.getCoordinates());this._ocaMap.put(b,B)}}],[{key:"constructor_",value:function(){this._edges=new Pt,this._ocaMap=new Fs}}])})(),en=(function(){return l((function B(){r(this,B)}),[{key:"processIntersections",value:function(B,b,w,L){}},{key:"isDone",value:function(){}}])})(),Cn=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"isTrivialIntersection",value:function(b,w,L,G){if(b===L&&this._li.getIntersectionNum()===1){if(B.isAdjacentSegments(w,G))return!0;if(b.isClosed()){var K=b.size()-1;if(w===0&&G===K||G===0&&w===K)return!0}}return!1}},{key:"getProperIntersectionPoint",value:function(){return this._properIntersectionPoint}},{key:"hasProperInteriorIntersection",value:function(){return this._hasProperInterior}},{key:"getLineIntersector",value:function(){return this._li}},{key:"hasProperIntersection",value:function(){return this._hasProper}},{key:"processIntersections",value:function(b,w,L,G){if(b===L&&w===G)return null;this.numTests++;var K=b.getCoordinates()[w],le=b.getCoordinates()[w+1],fe=L.getCoordinates()[G],_e=L.getCoordinates()[G+1];this._li.computeIntersection(K,le,fe,_e),this._li.hasIntersection()&&(this.numIntersections++,this._li.isInteriorIntersection()&&(this.numInteriorIntersections++,this._hasInterior=!0),this.isTrivialIntersection(b,w,L,G)||(this._hasIntersection=!0,b.addIntersections(this._li,w,0),L.addIntersections(this._li,G,1),this._li.isProper()&&(this.numProperIntersections++,this._hasProper=!0,this._hasProperInterior=!0)))}},{key:"hasIntersection",value:function(){return this._hasIntersection}},{key:"isDone",value:function(){return!1}},{key:"hasInteriorIntersection",value:function(){return this._hasInterior}},{key:"interfaces_",get:function(){return[en]}}],[{key:"constructor_",value:function(){this._hasIntersection=!1,this._hasProper=!1,this._hasProperInterior=!1,this._hasInterior=!1,this._properIntersectionPoint=null,this._li=null,this._isSelfIntersection=null,this.numIntersections=0,this.numInteriorIntersections=0,this.numProperIntersections=0,this.numTests=0;var b=arguments[0];this._li=b}},{key:"isAdjacentSegments",value:function(b,w){return Math.abs(b-w)===1}}])})(),pn=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getSegmentIndex",value:function(){return this.segmentIndex}},{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(B){B.print(this.coord),B.print(" seg # = "+this.segmentIndex),B.println(" dist = "+this.dist)}},{key:"compareTo",value:function(B){var b=B;return this.compare(b.segmentIndex,b.dist)}},{key:"isEndPoint",value:function(B){return this.segmentIndex===0&&this.dist===0||this.segmentIndex===B}},{key:"toString",value:function(){return this.coord+" seg # = "+this.segmentIndex+" dist = "+this.dist}},{key:"getDistance",value:function(){return this.dist}},{key:"compare",value:function(B,b){return this.segmentIndex<B?-1:this.segmentIndex>B?1:this.dist<b?-1:this.dist>b?1:0}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){this.coord=null,this.segmentIndex=null,this.dist=null;var B=arguments[0],b=arguments[1],w=arguments[2];this.coord=new Le(B),this.segmentIndex=b,this.dist=w}}])})(),ma=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"print",value:function(B){B.println("Intersections:");for(var b=this.iterator();b.hasNext();)b.next().print(B)}},{key:"iterator",value:function(){return this._nodeMap.values().iterator()}},{key:"addSplitEdges",value:function(B){this.addEndpoints();for(var b=this.iterator(),w=b.next();b.hasNext();){var L=b.next(),G=this.createSplitEdge(w,L);B.add(G),w=L}}},{key:"addEndpoints",value:function(){var B=this.edge.pts.length-1;this.add(this.edge.pts[0],0,0),this.add(this.edge.pts[B],B,0)}},{key:"createSplitEdge",value:function(B,b){var w=b.segmentIndex-B.segmentIndex+2,L=this.edge.pts[b.segmentIndex],G=b.dist>0||!b.coord.equals2D(L);G||w--;var K=new Array(w).fill(null),le=0;K[le++]=new Le(B.coord);for(var fe=B.segmentIndex+1;fe<=b.segmentIndex;fe++)K[le++]=this.edge.pts[fe];return G&&(K[le]=b.coord),new kt(K,new Jr(this.edge._label))}},{key:"add",value:function(B,b,w){var L=new pn(B,b,w),G=this._nodeMap.get(L);return G!==null?G:(this._nodeMap.put(L,L),L)}},{key:"isIntersection",value:function(B){for(var b=this.iterator();b.hasNext();)if(b.next().coord.equals(B))return!0;return!1}}],[{key:"constructor_",value:function(){this._nodeMap=new Fs,this.edge=null;var B=arguments[0];this.edge=B}}])})(),Kr=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"isIntersects",value:function(){return!this.isDisjoint()}},{key:"isCovers",value:function(){return(B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.INTERIOR][Ae.BOUNDARY])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]))&&this._matrix[Ae.EXTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]===Rt.FALSE}},{key:"isCoveredBy",value:function(){return(B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.INTERIOR][Ae.BOUNDARY])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]))&&this._matrix[Ae.INTERIOR][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]===Rt.FALSE}},{key:"set",value:function(){if(arguments.length===1)for(var b=arguments[0],w=0;w<b.length;w++){var L=Math.trunc(w/3),G=w%3;this._matrix[L][G]=Rt.toDimensionValue(b.charAt(w))}else if(arguments.length===3){var K=arguments[0],le=arguments[1],fe=arguments[2];this._matrix[K][le]=fe}}},{key:"isContains",value:function(){return B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&this._matrix[Ae.EXTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]===Rt.FALSE}},{key:"setAtLeast",value:function(){if(arguments.length===1)for(var b=arguments[0],w=0;w<b.length;w++){var L=Math.trunc(w/3),G=w%3;this.setAtLeast(L,G,Rt.toDimensionValue(b.charAt(w)))}else if(arguments.length===3){var K=arguments[0],le=arguments[1],fe=arguments[2];this._matrix[K][le]<fe&&(this._matrix[K][le]=fe)}}},{key:"setAtLeastIfValid",value:function(b,w,L){b>=0&&w>=0&&this.setAtLeast(b,w,L)}},{key:"isWithin",value:function(){return B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&this._matrix[Ae.INTERIOR][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]===Rt.FALSE}},{key:"isTouches",value:function(b,w){return b>w?this.isTouches(w,b):(b===Rt.A&&w===Rt.A||b===Rt.L&&w===Rt.L||b===Rt.L&&w===Rt.A||b===Rt.P&&w===Rt.A||b===Rt.P&&w===Rt.L)&&this._matrix[Ae.INTERIOR][Ae.INTERIOR]===Rt.FALSE&&(B.isTrue(this._matrix[Ae.INTERIOR][Ae.BOUNDARY])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]))}},{key:"isOverlaps",value:function(b,w){return b===Rt.P&&w===Rt.P||b===Rt.A&&w===Rt.A?B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.EXTERIOR])&&B.isTrue(this._matrix[Ae.EXTERIOR][Ae.INTERIOR]):b===Rt.L&&w===Rt.L&&this._matrix[Ae.INTERIOR][Ae.INTERIOR]===1&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.EXTERIOR])&&B.isTrue(this._matrix[Ae.EXTERIOR][Ae.INTERIOR])}},{key:"isEquals",value:function(b,w){return b===w&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&this._matrix[Ae.INTERIOR][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]===Rt.FALSE}},{key:"toString",value:function(){for(var b=new At("123456789"),w=0;w<3;w++)for(var L=0;L<3;L++)b.setCharAt(3*w+L,Rt.toDimensionSymbol(this._matrix[w][L]));return b.toString()}},{key:"setAll",value:function(b){for(var w=0;w<3;w++)for(var L=0;L<3;L++)this._matrix[w][L]=b}},{key:"get",value:function(b,w){return this._matrix[b][w]}},{key:"transpose",value:function(){var b=this._matrix[1][0];return this._matrix[1][0]=this._matrix[0][1],this._matrix[0][1]=b,b=this._matrix[2][0],this._matrix[2][0]=this._matrix[0][2],this._matrix[0][2]=b,b=this._matrix[2][1],this._matrix[2][1]=this._matrix[1][2],this._matrix[1][2]=b,this}},{key:"matches",value:function(b){if(b.length!==9)throw new Z("Should be length 9: "+b);for(var w=0;w<3;w++)for(var L=0;L<3;L++)if(!B.matches(this._matrix[w][L],b.charAt(3*w+L)))return!1;return!0}},{key:"add",value:function(b){for(var w=0;w<3;w++)for(var L=0;L<3;L++)this.setAtLeast(w,L,b.get(w,L))}},{key:"isDisjoint",value:function(){return this._matrix[Ae.INTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.INTERIOR][Ae.BOUNDARY]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]===Rt.FALSE}},{key:"isCrosses",value:function(b,w){return b===Rt.P&&w===Rt.L||b===Rt.P&&w===Rt.A||b===Rt.L&&w===Rt.A?B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.EXTERIOR]):b===Rt.L&&w===Rt.P||b===Rt.A&&w===Rt.P||b===Rt.A&&w===Rt.L?B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&B.isTrue(this._matrix[Ae.EXTERIOR][Ae.INTERIOR]):b===Rt.L&&w===Rt.L&&this._matrix[Ae.INTERIOR][Ae.INTERIOR]===0}},{key:"interfaces_",get:function(){return[V]}}],[{key:"constructor_",value:function(){if(this._matrix=null,arguments.length===0)this._matrix=Array(3).fill().map((function(){return Array(3)})),this.setAll(Rt.FALSE);else if(arguments.length===1){if(typeof arguments[0]=="string"){var b=arguments[0];B.constructor_.call(this),this.set(b)}else if(arguments[0]instanceof B){var w=arguments[0];B.constructor_.call(this),this._matrix[Ae.INTERIOR][Ae.INTERIOR]=w._matrix[Ae.INTERIOR][Ae.INTERIOR],this._matrix[Ae.INTERIOR][Ae.BOUNDARY]=w._matrix[Ae.INTERIOR][Ae.BOUNDARY],this._matrix[Ae.INTERIOR][Ae.EXTERIOR]=w._matrix[Ae.INTERIOR][Ae.EXTERIOR],this._matrix[Ae.BOUNDARY][Ae.INTERIOR]=w._matrix[Ae.BOUNDARY][Ae.INTERIOR],this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]=w._matrix[Ae.BOUNDARY][Ae.BOUNDARY],this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]=w._matrix[Ae.BOUNDARY][Ae.EXTERIOR],this._matrix[Ae.EXTERIOR][Ae.INTERIOR]=w._matrix[Ae.EXTERIOR][Ae.INTERIOR],this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]=w._matrix[Ae.EXTERIOR][Ae.BOUNDARY],this._matrix[Ae.EXTERIOR][Ae.EXTERIOR]=w._matrix[Ae.EXTERIOR][Ae.EXTERIOR]}}}},{key:"matches",value:function(){if(Number.isInteger(arguments[0])&&typeof arguments[1]=="string"){var b=arguments[0],w=arguments[1];return w===Rt.SYM_DONTCARE||w===Rt.SYM_TRUE&&(b>=0||b===Rt.TRUE)||w===Rt.SYM_FALSE&&b===Rt.FALSE||w===Rt.SYM_P&&b===Rt.P||w===Rt.SYM_L&&b===Rt.L||w===Rt.SYM_A&&b===Rt.A}if(typeof arguments[0]=="string"&&typeof arguments[1]=="string"){var L=arguments[1];return new B(arguments[0]).matches(L)}}},{key:"isTrue",value:function(b){return b>=0||b===Rt.TRUE}}])})(),me=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"size",value:function(){return this._size}},{key:"addAll",value:function(b){return b===null||b.length===0?null:(this.ensureCapacity(this._size+b.length),Hi.arraycopy(b,0,this._data,this._size,b.length),void(this._size+=b.length))}},{key:"ensureCapacity",value:function(b){if(b<=this._data.length)return null;var w=Math.max(b,2*this._data.length);this._data=Qe.copyOf(this._data,w)}},{key:"toArray",value:function(){var b=new Array(this._size).fill(null);return Hi.arraycopy(this._data,0,b,0,this._size),b}},{key:"add",value:function(b){this.ensureCapacity(this._size+1),this._data[this._size]=b,++this._size}}],[{key:"constructor_",value:function(){if(this._data=null,this._size=0,arguments.length===0)B.constructor_.call(this,10);else if(arguments.length===1){var b=arguments[0];this._data=new Array(b).fill(null)}}}])})(),ge=(function(){function B(){r(this,B)}return l(B,[{key:"getChainStartIndices",value:function(b){var w=0,L=new me(Math.trunc(b.length/2));L.add(w);do{var G=this.findChainEnd(b,w);L.add(G),w=G}while(w<b.length-1);return L.toArray()}},{key:"findChainEnd",value:function(b,w){for(var L=dr.quadrant(b[w],b[w+1]),G=w+1;G<b.length&&dr.quadrant(b[G-1],b[G])===L;)G++;return G-1}},{key:"OLDgetChainStartIndices",value:function(b){var w=0,L=new Pt;L.add(w);do{var G=this.findChainEnd(b,w);L.add(G),w=G}while(w<b.length-1);return B.toIntArray(L)}}],[{key:"toIntArray",value:function(b){for(var w=new Array(b.size()).fill(null),L=0;L<w.length;L++)w[L]=b.get(L).intValue();return w}}])})(),We=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getCoordinates",value:function(){return this.pts}},{key:"getMaxX",value:function(B){var b=this.pts[this.startIndex[B]].x,w=this.pts[this.startIndex[B+1]].x;return b>w?b:w}},{key:"getMinX",value:function(B){var b=this.pts[this.startIndex[B]].x,w=this.pts[this.startIndex[B+1]].x;return b<w?b:w}},{key:"computeIntersectsForChain",value:function(){if(arguments.length===4){var B=arguments[0],b=arguments[1],w=arguments[2],L=arguments[3];this.computeIntersectsForChain(this.startIndex[B],this.startIndex[B+1],b,b.startIndex[w],b.startIndex[w+1],L)}else if(arguments.length===6){var G=arguments[0],K=arguments[1],le=arguments[2],fe=arguments[3],_e=arguments[4],Oe=arguments[5];if(K-G==1&&_e-fe==1)return Oe.addIntersections(this.e,G,le.e,fe),null;if(!this.overlaps(G,K,le,fe,_e))return null;var ut=Math.trunc((G+K)/2),_t=Math.trunc((fe+_e)/2);G<ut&&(fe<_t&&this.computeIntersectsForChain(G,ut,le,fe,_t,Oe),_t<_e&&this.computeIntersectsForChain(G,ut,le,_t,_e,Oe)),ut<K&&(fe<_t&&this.computeIntersectsForChain(ut,K,le,fe,_t,Oe),_t<_e&&this.computeIntersectsForChain(ut,K,le,_t,_e,Oe))}}},{key:"overlaps",value:function(B,b,w,L,G){return nt.intersects(this.pts[B],this.pts[b],w.pts[L],w.pts[G])}},{key:"getStartIndexes",value:function(){return this.startIndex}},{key:"computeIntersects",value:function(B,b){for(var w=0;w<this.startIndex.length-1;w++)for(var L=0;L<B.startIndex.length-1;L++)this.computeIntersectsForChain(w,B,L,b)}}],[{key:"constructor_",value:function(){this.e=null,this.pts=null,this.startIndex=null;var B=arguments[0];this.e=B,this.pts=B.getCoordinates();var b=new ge;this.startIndex=b.getChainStartIndices(this.pts)}}])})(),gt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getDepth",value:function(b,w){return this._depth[b][w]}},{key:"setDepth",value:function(b,w,L){this._depth[b][w]=L}},{key:"isNull",value:function(){if(arguments.length===0){for(var b=0;b<2;b++)for(var w=0;w<3;w++)if(this._depth[b][w]!==B.NULL_VALUE)return!1;return!0}if(arguments.length===1){var L=arguments[0];return this._depth[L][1]===B.NULL_VALUE}if(arguments.length===2){var G=arguments[0],K=arguments[1];return this._depth[G][K]===B.NULL_VALUE}}},{key:"normalize",value:function(){for(var b=0;b<2;b++)if(!this.isNull(b)){var w=this._depth[b][1];this._depth[b][2]<w&&(w=this._depth[b][2]),w<0&&(w=0);for(var L=1;L<3;L++){var G=0;this._depth[b][L]>w&&(G=1),this._depth[b][L]=G}}}},{key:"getDelta",value:function(b){return this._depth[b][be.RIGHT]-this._depth[b][be.LEFT]}},{key:"getLocation",value:function(b,w){return this._depth[b][w]<=0?Ae.EXTERIOR:Ae.INTERIOR}},{key:"toString",value:function(){return"A: "+this._depth[0][1]+","+this._depth[0][2]+" B: "+this._depth[1][1]+","+this._depth[1][2]}},{key:"add",value:function(){if(arguments.length===1)for(var b=arguments[0],w=0;w<2;w++)for(var L=1;L<3;L++){var G=b.getLocation(w,L);G!==Ae.EXTERIOR&&G!==Ae.INTERIOR||(this.isNull(w,L)?this._depth[w][L]=B.depthAtLocation(G):this._depth[w][L]+=B.depthAtLocation(G))}else if(arguments.length===3){var K=arguments[0],le=arguments[1];arguments[2]===Ae.INTERIOR&&this._depth[K][le]++}}}],[{key:"constructor_",value:function(){this._depth=Array(2).fill().map((function(){return Array(3)}));for(var b=0;b<2;b++)for(var w=0;w<3;w++)this._depth[b][w]=B.NULL_VALUE}},{key:"depthAtLocation",value:function(b){return b===Ae.EXTERIOR?0:b===Ae.INTERIOR?1:B.NULL_VALUE}}])})();gt.NULL_VALUE=-1;var kt=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"getDepth",value:function(){return this._depth}},{key:"getCollapsedEdge",value:function(){var w=new Array(2).fill(null);return w[0]=this.pts[0],w[1]=this.pts[1],new b(w,Jr.toLineLabel(this._label))}},{key:"isIsolated",value:function(){return this._isIsolated}},{key:"getCoordinates",value:function(){return this.pts}},{key:"setIsolated",value:function(w){this._isIsolated=w}},{key:"setName",value:function(w){this._name=w}},{key:"equals",value:function(w){if(!(w instanceof b))return!1;var L=w;if(this.pts.length!==L.pts.length)return!1;for(var G=!0,K=!0,le=this.pts.length,fe=0;fe<this.pts.length;fe++)if(this.pts[fe].equals2D(L.pts[fe])||(G=!1),this.pts[fe].equals2D(L.pts[--le])||(K=!1),!G&&!K)return!1;return!0}},{key:"getCoordinate",value:function(){if(arguments.length===0)return this.pts.length>0?this.pts[0]:null;if(arguments.length===1){var w=arguments[0];return this.pts[w]}}},{key:"print",value:function(w){w.print("edge "+this._name+": "),w.print("LINESTRING (");for(var L=0;L<this.pts.length;L++)L>0&&w.print(","),w.print(this.pts[L].x+" "+this.pts[L].y);w.print(") "+this._label+" "+this._depthDelta)}},{key:"computeIM",value:function(w){b.updateIM(this._label,w)}},{key:"isCollapsed",value:function(){return!!this._label.isArea()&&this.pts.length===3&&!!this.pts[0].equals(this.pts[2])}},{key:"isClosed",value:function(){return this.pts[0].equals(this.pts[this.pts.length-1])}},{key:"getMaximumSegmentIndex",value:function(){return this.pts.length-1}},{key:"getDepthDelta",value:function(){return this._depthDelta}},{key:"getNumPoints",value:function(){return this.pts.length}},{key:"printReverse",value:function(w){w.print("edge "+this._name+": ");for(var L=this.pts.length-1;L>=0;L--)w.print(this.pts[L]+" ");w.println("")}},{key:"getMonotoneChainEdge",value:function(){return this._mce===null&&(this._mce=new We(this)),this._mce}},{key:"getEnvelope",value:function(){if(this._env===null){this._env=new nt;for(var w=0;w<this.pts.length;w++)this._env.expandToInclude(this.pts[w])}return this._env}},{key:"addIntersection",value:function(w,L,G,K){var le=new Le(w.getIntersection(K)),fe=L,_e=w.getEdgeDistance(G,K),Oe=fe+1;if(Oe<this.pts.length){var ut=this.pts[Oe];le.equals2D(ut)&&(fe=Oe,_e=0)}this.eiList.add(le,fe,_e)}},{key:"toString",value:function(){var w=new At;w.append("edge "+this._name+": "),w.append("LINESTRING (");for(var L=0;L<this.pts.length;L++)L>0&&w.append(","),w.append(this.pts[L].x+" "+this.pts[L].y);return w.append(") "+this._label+" "+this._depthDelta),w.toString()}},{key:"isPointwiseEqual",value:function(w){if(this.pts.length!==w.pts.length)return!1;for(var L=0;L<this.pts.length;L++)if(!this.pts[L].equals2D(w.pts[L]))return!1;return!0}},{key:"setDepthDelta",value:function(w){this._depthDelta=w}},{key:"getEdgeIntersectionList",value:function(){return this.eiList}},{key:"addIntersections",value:function(w,L,G){for(var K=0;K<w.getIntersectionNum();K++)this.addIntersection(w,L,G,K)}}],[{key:"constructor_",value:function(){if(this.pts=null,this._env=null,this.eiList=new ma(this),this._name=null,this._mce=null,this._isIsolated=!0,this._depth=new gt,this._depthDelta=0,arguments.length===1){var w=arguments[0];b.constructor_.call(this,w,null)}else if(arguments.length===2){var L=arguments[0],G=arguments[1];this.pts=L,this._label=G}}},{key:"updateIM",value:function(){if(!(arguments.length===2&&arguments[1]instanceof Kr&&arguments[0]instanceof Jr))return E(b,"updateIM",this).apply(this,arguments);var w=arguments[0],L=arguments[1];L.setAtLeastIfValid(w.getLocation(0,be.ON),w.getLocation(1,be.ON),1),w.isArea()&&(L.setAtLeastIfValid(w.getLocation(0,be.LEFT),w.getLocation(1,be.LEFT),2),L.setAtLeastIfValid(w.getLocation(0,be.RIGHT),w.getLocation(1,be.RIGHT),2))}}])})(ac),Ht=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"setWorkingPrecisionModel",value:function(b){this._workingPrecisionModel=b}},{key:"insertUniqueEdge",value:function(b){var w=this._edgeList.findEqualEdge(b);if(w!==null){var L=w.getLabel(),G=b.getLabel();w.isPointwiseEqual(b)||(G=new Jr(b.getLabel())).flip(),L.merge(G);var K=B.depthDelta(G),le=w.getDepthDelta()+K;w.setDepthDelta(le)}else this._edgeList.add(b),b.setDepthDelta(B.depthDelta(b.getLabel()))}},{key:"buildSubgraphs",value:function(b,w){for(var L=new Pt,G=b.iterator();G.hasNext();){var K=G.next(),le=K.getRightmostCoordinate(),fe=new ie(L).getDepth(le);K.computeDepth(fe),K.findResultEdges(),L.add(K),w.add(K.getDirectedEdges(),K.getNodes())}}},{key:"createSubgraphs",value:function(b){for(var w=new Pt,L=b.getNodes().iterator();L.hasNext();){var G=L.next();if(!G.isVisited()){var K=new ni;K.create(G),w.add(K)}}return bo.sort(w,bo.reverseOrder()),w}},{key:"createEmptyResultGeometry",value:function(){return this._geomFact.createPolygon()}},{key:"getNoder",value:function(b){if(this._workingNoder!==null)return this._workingNoder;var w=new Tl,L=new ys;return L.setPrecisionModel(b),w.setSegmentIntersector(new Cn(L)),w}},{key:"buffer",value:function(b,w){var L=this._workingPrecisionModel;L===null&&(L=b.getPrecisionModel()),this._geomFact=b.getFactory();var G=new ke(b,w,new f(L,this._bufParams)).getCurves();if(G.size()<=0)return this.createEmptyResultGeometry();this.computeNodedEdges(G,L),this._graph=new du(new bi),this._graph.addEdges(this._edgeList.getEdges());var K=this.createSubgraphs(this._graph),le=new ha(this._geomFact);this.buildSubgraphs(K,le);var fe=le.getPolygons();return fe.size()<=0?this.createEmptyResultGeometry():this._geomFact.buildGeometry(fe)}},{key:"computeNodedEdges",value:function(b,w){var L=this.getNoder(w);L.computeNodes(b);for(var G=L.getNodedSubstrings().iterator();G.hasNext();){var K=G.next(),le=K.getCoordinates();if(le.length!==2||!le[0].equals2D(le[1])){var fe=K.getData(),_e=new kt(K.getCoordinates(),new Jr(fe));this.insertUniqueEdge(_e)}}}},{key:"setNoder",value:function(b){this._workingNoder=b}}],[{key:"constructor_",value:function(){this._bufParams=null,this._workingPrecisionModel=null,this._workingNoder=null,this._geomFact=null,this._graph=null,this._edgeList=new dn;var b=arguments[0];this._bufParams=b}},{key:"depthDelta",value:function(b){var w=b.getLocation(0,be.LEFT),L=b.getLocation(0,be.RIGHT);return w===Ae.INTERIOR&&L===Ae.EXTERIOR?1:w===Ae.EXTERIOR&&L===Ae.INTERIOR?-1:0}},{key:"convertSegStrings",value:function(b){for(var w=new qi,L=new Pt;b.hasNext();){var G=b.next(),K=w.createLineString(G.getCoordinates());L.add(K)}return w.buildGeometry(L)}}])})(),Gt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"rescale",value:function(){if(Pe(arguments[0],vt))for(var b=arguments[0].iterator();b.hasNext();){var w=b.next();this.rescale(w.getCoordinates())}else if(arguments[0]instanceof Array){for(var L=arguments[0],G=0;G<L.length;G++)L[G].x=L[G].x/this._scaleFactor+this._offsetX,L[G].y=L[G].y/this._scaleFactor+this._offsetY;L.length===2&&L[0].equals2D(L[1])&&Hi.out.println(L)}}},{key:"scale",value:function(){if(Pe(arguments[0],vt)){for(var b=arguments[0],w=new Pt(b.size()),L=b.iterator();L.hasNext();){var G=L.next();w.add(new fa(this.scale(G.getCoordinates()),G.getData()))}return w}if(arguments[0]instanceof Array){for(var K=arguments[0],le=new Array(K.length).fill(null),fe=0;fe<K.length;fe++)le[fe]=new Le(Math.round((K[fe].x-this._offsetX)*this._scaleFactor),Math.round((K[fe].y-this._offsetY)*this._scaleFactor),K[fe].getZ());return $n.removeRepeatedPoints(le)}}},{key:"isIntegerPrecision",value:function(){return this._scaleFactor===1}},{key:"getNodedSubstrings",value:function(){var b=this._noder.getNodedSubstrings();return this._isScaled&&this.rescale(b),b}},{key:"computeNodes",value:function(b){var w=b;this._isScaled&&(w=this.scale(b)),this._noder.computeNodes(w)}},{key:"interfaces_",get:function(){return[Il]}}],[{key:"constructor_",value:function(){if(this._noder=null,this._scaleFactor=null,this._offsetX=null,this._offsetY=null,this._isScaled=!1,arguments.length===2){var b=arguments[0],w=arguments[1];B.constructor_.call(this,b,w,0,0)}else if(arguments.length===4){var L=arguments[0],G=arguments[1];this._noder=L,this._scaleFactor=G,this._isScaled=!this.isIntegerPrecision()}}}])})(),Qt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"checkEndPtVertexIntersections",value:function(){if(arguments.length===0)for(var b=this._segStrings.iterator();b.hasNext();){var w=b.next().getCoordinates();this.checkEndPtVertexIntersections(w[0],this._segStrings),this.checkEndPtVertexIntersections(w[w.length-1],this._segStrings)}else if(arguments.length===2){for(var L=arguments[0],G=arguments[1].iterator();G.hasNext();)for(var K=G.next().getCoordinates(),le=1;le<K.length-1;le++)if(K[le].equals(L))throw new we("found endpt/interior pt intersection at index "+le+" :pt "+L)}}},{key:"checkInteriorIntersections",value:function(){if(arguments.length===0)for(var b=this._segStrings.iterator();b.hasNext();)for(var w=b.next(),L=this._segStrings.iterator();L.hasNext();){var G=L.next();this.checkInteriorIntersections(w,G)}else if(arguments.length===2)for(var K=arguments[0],le=arguments[1],fe=K.getCoordinates(),_e=le.getCoordinates(),Oe=0;Oe<fe.length-1;Oe++)for(var ut=0;ut<_e.length-1;ut++)this.checkInteriorIntersections(K,Oe,le,ut);else if(arguments.length===4){var _t=arguments[0],St=arguments[1],Mi=arguments[2],an=arguments[3];if(_t===Mi&&St===an)return null;var mn=_t.getCoordinates()[St],tr=_t.getCoordinates()[St+1],Qi=Mi.getCoordinates()[an],vr=Mi.getCoordinates()[an+1];if(this._li.computeIntersection(mn,tr,Qi,vr),this._li.hasIntersection()&&(this._li.isProper()||this.hasInteriorIntersection(this._li,mn,tr)||this.hasInteriorIntersection(this._li,Qi,vr)))throw new we("found non-noded intersection at "+mn+"-"+tr+" and "+Qi+"-"+vr)}}},{key:"checkValid",value:function(){this.checkEndPtVertexIntersections(),this.checkInteriorIntersections(),this.checkCollapses()}},{key:"checkCollapses",value:function(){if(arguments.length===0)for(var b=this._segStrings.iterator();b.hasNext();){var w=b.next();this.checkCollapses(w)}else if(arguments.length===1)for(var L=arguments[0].getCoordinates(),G=0;G<L.length-2;G++)this.checkCollapse(L[G],L[G+1],L[G+2])}},{key:"hasInteriorIntersection",value:function(b,w,L){for(var G=0;G<b.getIntersectionNum();G++){var K=b.getIntersection(G);if(!K.equals(w)&&!K.equals(L))return!0}return!1}},{key:"checkCollapse",value:function(b,w,L){if(b.equals(L))throw new we("found non-noded collapse at "+B.fact.createLineString([b,w,L]))}}],[{key:"constructor_",value:function(){this._li=new ys,this._segStrings=null;var b=arguments[0];this._segStrings=b}}])})();Qt.fact=new qi;var ai=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"intersectsScaled",value:function(b,w){var L=Math.min(b.x,w.x),G=Math.max(b.x,w.x),K=Math.min(b.y,w.y),le=Math.max(b.y,w.y),fe=this._maxx<L||this._minx>G||this._maxy<K||this._miny>le;if(fe)return!1;var _e=this.intersectsToleranceSquare(b,w);return Se.isTrue(!(fe&&_e),"Found bad envelope test"),_e}},{key:"initCorners",value:function(b){var w=.5;this._minx=b.x-w,this._maxx=b.x+w,this._miny=b.y-w,this._maxy=b.y+w,this._corner[0]=new Le(this._maxx,this._maxy),this._corner[1]=new Le(this._minx,this._maxy),this._corner[2]=new Le(this._minx,this._miny),this._corner[3]=new Le(this._maxx,this._miny)}},{key:"intersects",value:function(b,w){return this._scaleFactor===1?this.intersectsScaled(b,w):(this.copyScaled(b,this._p0Scaled),this.copyScaled(w,this._p1Scaled),this.intersectsScaled(this._p0Scaled,this._p1Scaled))}},{key:"scale",value:function(b){return Math.round(b*this._scaleFactor)}},{key:"getCoordinate",value:function(){return this._originalPt}},{key:"copyScaled",value:function(b,w){w.x=this.scale(b.x),w.y=this.scale(b.y)}},{key:"getSafeEnvelope",value:function(){if(this._safeEnv===null){var b=B.SAFE_ENV_EXPANSION_FACTOR/this._scaleFactor;this._safeEnv=new nt(this._originalPt.x-b,this._originalPt.x+b,this._originalPt.y-b,this._originalPt.y+b)}return this._safeEnv}},{key:"intersectsPixelClosure",value:function(b,w){return this._li.computeIntersection(b,w,this._corner[0],this._corner[1]),!!this._li.hasIntersection()||(this._li.computeIntersection(b,w,this._corner[1],this._corner[2]),!!this._li.hasIntersection()||(this._li.computeIntersection(b,w,this._corner[2],this._corner[3]),!!this._li.hasIntersection()||(this._li.computeIntersection(b,w,this._corner[3],this._corner[0]),!!this._li.hasIntersection())))}},{key:"intersectsToleranceSquare",value:function(b,w){var L=!1,G=!1;return this._li.computeIntersection(b,w,this._corner[0],this._corner[1]),!!this._li.isProper()||(this._li.computeIntersection(b,w,this._corner[1],this._corner[2]),!!this._li.isProper()||(this._li.hasIntersection()&&(L=!0),this._li.computeIntersection(b,w,this._corner[2],this._corner[3]),!!this._li.isProper()||(this._li.hasIntersection()&&(G=!0),this._li.computeIntersection(b,w,this._corner[3],this._corner[0]),!!this._li.isProper()||!(!L||!G)||!!b.equals(this._pt)||!!w.equals(this._pt))))}},{key:"addSnappedNode",value:function(b,w){var L=b.getCoordinate(w),G=b.getCoordinate(w+1);return!!this.intersects(L,G)&&(b.addIntersection(this.getCoordinate(),w),!0)}}],[{key:"constructor_",value:function(){this._li=null,this._pt=null,this._originalPt=null,this._ptScaled=null,this._p0Scaled=null,this._p1Scaled=null,this._scaleFactor=null,this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,this._corner=new Array(4).fill(null),this._safeEnv=null;var b=arguments[0],w=arguments[1],L=arguments[2];if(this._originalPt=b,this._pt=b,this._scaleFactor=w,this._li=L,w<=0)throw new Z("Scale factor must be non-zero");w!==1&&(this._pt=new Le(this.scale(b.x),this.scale(b.y)),this._p0Scaled=new Le,this._p1Scaled=new Le),this.initCorners(this._pt)}}])})();ai.SAFE_ENV_EXPANSION_FACTOR=.75;var ue=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"select",value:function(){if(arguments.length!==1){if(arguments.length===2){var B=arguments[1];arguments[0].getLineSegment(B,this.selectedSegment),this.select(this.selectedSegment)}}}}],[{key:"constructor_",value:function(){this.selectedSegment=new bs}}])})(),$=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"snap",value:function(){if(arguments.length===1){var B=arguments[0];return this.snap(B,null,-1)}if(arguments.length===3){var b=arguments[0],w=arguments[1],L=arguments[2],G=b.getSafeEnvelope(),K=new Ue(b,w,L);return this._index.query(G,new((function(){return l((function le(){r(this,le)}),[{key:"interfaces_",get:function(){return[yh]}},{key:"visitItem",value:function(le){le.select(G,K)}}])})())),K.isNodeAdded()}}}],[{key:"constructor_",value:function(){this._index=null;var B=arguments[0];this._index=B}}])})(),Ue=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"isNodeAdded",value:function(){return this._isNodeAdded}},{key:"select",value:function(){if(!(arguments.length===2&&Number.isInteger(arguments[1])&&arguments[0]instanceof lc))return E(b,"select",this,1).apply(this,arguments);var w=arguments[1],L=arguments[0].getContext();if(this._parentEdge===L&&(w===this._hotPixelVertexIndex||w+1===this._hotPixelVertexIndex))return null;this._isNodeAdded|=this._hotPixel.addSnappedNode(L,w)}}],[{key:"constructor_",value:function(){this._hotPixel=null,this._parentEdge=null,this._hotPixelVertexIndex=null,this._isNodeAdded=!1;var w=arguments[0],L=arguments[1],G=arguments[2];this._hotPixel=w,this._parentEdge=L,this._hotPixelVertexIndex=G}}])})(ue);$.HotPixelSnapAction=Ue;var tt=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"processIntersections",value:function(B,b,w,L){if(B===w&&b===L)return null;var G=B.getCoordinates()[b],K=B.getCoordinates()[b+1],le=w.getCoordinates()[L],fe=w.getCoordinates()[L+1];if(this._li.computeIntersection(G,K,le,fe),this._li.hasIntersection()&&this._li.isInteriorIntersection()){for(var _e=0;_e<this._li.getIntersectionNum();_e++)this._interiorIntersections.add(this._li.getIntersection(_e));B.addIntersections(this._li,b,0),w.addIntersections(this._li,L,1)}}},{key:"isDone",value:function(){return!1}},{key:"getInteriorIntersections",value:function(){return this._interiorIntersections}},{key:"interfaces_",get:function(){return[en]}}],[{key:"constructor_",value:function(){this._li=null,this._interiorIntersections=null;var B=arguments[0];this._li=B,this._interiorIntersections=new Pt}}])})(),wt=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"checkCorrectness",value:function(B){var b=new Qt(fa.getNodedSubstrings(B));try{b.checkValid()}catch(w){if(!(w instanceof F))throw w;w.printStackTrace()}}},{key:"getNodedSubstrings",value:function(){return fa.getNodedSubstrings(this._nodedSegStrings)}},{key:"snapRound",value:function(B,b){var w=this.findInteriorIntersections(B,b);this.computeIntersectionSnaps(w),this.computeVertexSnaps(B)}},{key:"findInteriorIntersections",value:function(B,b){var w=new tt(b);return this._noder.setSegmentIntersector(w),this._noder.computeNodes(B),w.getInteriorIntersections()}},{key:"computeVertexSnaps",value:function(){if(Pe(arguments[0],vt))for(var B=arguments[0].iterator();B.hasNext();){var b=B.next();this.computeVertexSnaps(b)}else if(arguments[0]instanceof fa)for(var w=arguments[0],L=w.getCoordinates(),G=0;G<L.length;G++){var K=new ai(L[G],this._scaleFactor,this._li);this._pointSnapper.snap(K,w,G)&&w.addIntersection(L[G],G)}}},{key:"computeNodes",value:function(B){this._nodedSegStrings=B,this._noder=new Tl,this._pointSnapper=new $(this._noder.getIndex()),this.snapRound(B,this._li)}},{key:"computeIntersectionSnaps",value:function(B){for(var b=B.iterator();b.hasNext();){var w=new ai(b.next(),this._scaleFactor,this._li);this._pointSnapper.snap(w)}}},{key:"interfaces_",get:function(){return[Il]}}],[{key:"constructor_",value:function(){this._pm=null,this._li=null,this._scaleFactor=null,this._noder=null,this._pointSnapper=null,this._nodedSegStrings=null;var B=arguments[0];this._pm=B,this._li=new ys,this._li.setPrecisionModel(B),this._scaleFactor=B.getScale()}}])})(),Nt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"bufferFixedPrecision",value:function(b){var w=new Gt(new wt(new yi(1)),b.getScale()),L=new Ht(this._bufParams);L.setWorkingPrecisionModel(b),L.setNoder(w),this._resultGeometry=L.buffer(this._argGeom,this._distance)}},{key:"bufferReducedPrecision",value:function(){if(arguments.length===0){for(var b=B.MAX_PRECISION_DIGITS;b>=0;b--){try{this.bufferReducedPrecision(b)}catch(G){if(!(G instanceof ii))throw G;this._saveException=G}if(this._resultGeometry!==null)return null}throw this._saveException}if(arguments.length===1){var w=arguments[0],L=new yi(B.precisionScaleFactor(this._argGeom,this._distance,w));this.bufferFixedPrecision(L)}}},{key:"computeGeometry",value:function(){if(this.bufferOriginalPrecision(),this._resultGeometry!==null)return null;var b=this._argGeom.getFactory().getPrecisionModel();b.getType()===yi.FIXED?this.bufferFixedPrecision(b):this.bufferReducedPrecision()}},{key:"setQuadrantSegments",value:function(b){this._bufParams.setQuadrantSegments(b)}},{key:"bufferOriginalPrecision",value:function(){try{var b=new Ht(this._bufParams);this._resultGeometry=b.buffer(this._argGeom,this._distance)}catch(w){if(!(w instanceof we))throw w;this._saveException=w}}},{key:"getResultGeometry",value:function(b){return this._distance=b,this.computeGeometry(),this._resultGeometry}},{key:"setEndCapStyle",value:function(b){this._bufParams.setEndCapStyle(b)}}],[{key:"constructor_",value:function(){if(this._argGeom=null,this._distance=null,this._bufParams=new D,this._resultGeometry=null,this._saveException=null,arguments.length===1){var b=arguments[0];this._argGeom=b}else if(arguments.length===2){var w=arguments[0],L=arguments[1];this._argGeom=w,this._bufParams=L}}},{key:"bufferOp",value:function(){if(arguments.length===2){var b=arguments[1];return new B(arguments[0]).getResultGeometry(b)}if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof lt&&typeof arguments[1]=="number"){var w=arguments[1],L=arguments[2],G=new B(arguments[0]);return G.setQuadrantSegments(L),G.getResultGeometry(w)}if(arguments[2]instanceof D&&arguments[0]instanceof lt&&typeof arguments[1]=="number"){var K=arguments[1];return new B(arguments[0],arguments[2]).getResultGeometry(K)}}else if(arguments.length===4){var le=arguments[1],fe=arguments[2],_e=arguments[3],Oe=new B(arguments[0]);return Oe.setQuadrantSegments(fe),Oe.setEndCapStyle(_e),Oe.getResultGeometry(le)}}},{key:"precisionScaleFactor",value:function(b,w,L){var G=b.getEnvelopeInternal(),K=at.max(Math.abs(G.getMaxX()),Math.abs(G.getMaxY()),Math.abs(G.getMinX()),Math.abs(G.getMinY()))+2*(w>0?w:0),le=L-Math.trunc(Math.log(K)/Math.log(10)+1);return Math.pow(10,le)}}])})();Nt.CAP_ROUND=D.CAP_ROUND,Nt.CAP_BUTT=D.CAP_FLAT,Nt.CAP_FLAT=D.CAP_FLAT,Nt.CAP_SQUARE=D.CAP_SQUARE,Nt.MAX_PRECISION_DIGITS=12;var se=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],Dt=(function(){return l((function B(b){r(this,B),this.geometryFactory=b||new qi}),[{key:"read",value:function(B){var b,w=(b=typeof B=="string"?JSON.parse(B):B).type;if(!jt[w])throw new Error("Unknown GeoJSON type: "+b.type);return se.indexOf(w)!==-1?jt[w].call(this,b.coordinates):w==="GeometryCollection"?jt[w].call(this,b.geometries):jt[w].call(this,b)}},{key:"write",value:function(B){var b=B.getGeometryType();if(!Ct[b])throw new Error("Geometry is not supported");return Ct[b].call(this,B)}}])})(),jt={Feature:function(B){var b={};for(var w in B)b[w]=B[w];if(B.geometry){if(!jt[B.geometry.type])throw new Error("Unknown GeoJSON type: "+B.type);b.geometry=this.read(B.geometry)}return B.bbox&&(b.bbox=jt.bbox.call(this,B.bbox)),b},FeatureCollection:function(B){var b={};if(B.features){b.features=[];for(var w=0;w<B.features.length;++w)b.features.push(this.read(B.features[w]))}return B.bbox&&(b.bbox=this.parse.bbox.call(this,B.bbox)),b},coordinates:function(B){for(var b=[],w=0;w<B.length;++w){var L=B[w];b.push(s(Le,S(L)))}return b},bbox:function(B){return this.geometryFactory.createLinearRing([new Le(B[0],B[1]),new Le(B[2],B[1]),new Le(B[2],B[3]),new Le(B[0],B[3]),new Le(B[0],B[1])])},Point:function(B){var b=s(Le,S(B));return this.geometryFactory.createPoint(b)},MultiPoint:function(B){for(var b=[],w=0;w<B.length;++w)b.push(jt.Point.call(this,B[w]));return this.geometryFactory.createMultiPoint(b)},LineString:function(B){var b=jt.coordinates.call(this,B);return this.geometryFactory.createLineString(b)},MultiLineString:function(B){for(var b=[],w=0;w<B.length;++w)b.push(jt.LineString.call(this,B[w]));return this.geometryFactory.createMultiLineString(b)},Polygon:function(B){for(var b=jt.coordinates.call(this,B[0]),w=this.geometryFactory.createLinearRing(b),L=[],G=1;G<B.length;++G){var K=B[G],le=jt.coordinates.call(this,K),fe=this.geometryFactory.createLinearRing(le);L.push(fe)}return this.geometryFactory.createPolygon(w,L)},MultiPolygon:function(B){for(var b=[],w=0;w<B.length;++w){var L=B[w];b.push(jt.Polygon.call(this,L))}return this.geometryFactory.createMultiPolygon(b)},GeometryCollection:function(B){for(var b=[],w=0;w<B.length;++w){var L=B[w];b.push(this.read(L))}return this.geometryFactory.createGeometryCollection(b)}},Ct={coordinate:function(B){var b=[B.x,B.y];return B.z&&b.push(B.z),B.m&&b.push(B.m),b},Point:function(B){return{type:"Point",coordinates:Ct.coordinate.call(this,B.getCoordinate())}},MultiPoint:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=Ct.Point.call(this,L);b.push(G.coordinates)}return{type:"MultiPoint",coordinates:b}},LineString:function(B){for(var b=[],w=B.getCoordinates(),L=0;L<w.length;++L){var G=w[L];b.push(Ct.coordinate.call(this,G))}return{type:"LineString",coordinates:b}},MultiLineString:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=Ct.LineString.call(this,L);b.push(G.coordinates)}return{type:"MultiLineString",coordinates:b}},Polygon:function(B){var b=[],w=Ct.LineString.call(this,B._shell);b.push(w.coordinates);for(var L=0;L<B._holes.length;++L){var G=B._holes[L],K=Ct.LineString.call(this,G);b.push(K.coordinates)}return{type:"Polygon",coordinates:b}},MultiPolygon:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=Ct.Polygon.call(this,L);b.push(G.coordinates)}return{type:"MultiPolygon",coordinates:b}},GeometryCollection:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=L.getGeometryType();b.push(Ct[G].call(this,L))}return{type:"GeometryCollection",geometries:b}}};return{BufferOp:Nt,GeoJSONReader:(function(){return l((function B(b){r(this,B),this.parser=new Dt(b||new qi)}),[{key:"read",value:function(B){return this.parser.read(B)}}])})(),GeoJSONWriter:(function(){return l((function B(){r(this,B),this.parser=new Dt(this.geometryFactory)}),[{key:"write",value:function(B){return this.parser.write(B)}}])})()}}))})(SM)),SM.exports}var Mhe=Vj(She());function p0(){return new mI}function mI(){this.reset()}mI.prototype={constructor:mI,reset:function(){this.s=this.t=0},add:function(e){e$(yE,e,this.t),e$(this,yE.s,this.s),this.s?this.t+=yE.t:this.s=yE.t},valueOf:function(){return this.s}};var yE=new mI;function e$(e,t,i){var n=e.s=t+i,r=n-t;e.t=t-(n-r)+(i-r)}var Yr=1e-6,mr=Math.PI,Fu=mr/2,t$=mr/4,Wu=mr*2,ip=180/mr,rh=mr/180,Ha=Math.abs,Ihe=Math.atan,JA=Math.atan2,Ts=Math.cos,Rs=Math.sin,Cv=Math.sqrt;function Xj(e){return e>1?0:e<-1?mr:Math.acos(e)}function $m(e){return e>1?Fu:e<-1?-Fu:Math.asin(e)}function H1(){}function gI(e,t){e&&n$.hasOwnProperty(e.type)&&n$[e.type](e,t)}var i$={Feature:function(e,t){gI(e.geometry,t)},FeatureCollection:function(e,t){for(var i=e.features,n=-1,r=i.length;++n<r;)gI(i[n].geometry,t)}},n$={Sphere:function(e,t){t.sphere()},Point:function(e,t){e=e.coordinates,t.point(e[0],e[1],e[2])},MultiPoint:function(e,t){for(var i=e.coordinates,n=-1,r=i.length;++n<r;)e=i[n],t.point(e[0],e[1],e[2])},LineString:function(e,t){h6(e.coordinates,t,0)},MultiLineString:function(e,t){for(var i=e.coordinates,n=-1,r=i.length;++n<r;)h6(i[n],t,0)},Polygon:function(e,t){r$(e.coordinates,t)},MultiPolygon:function(e,t){for(var i=e.coordinates,n=-1,r=i.length;++n<r;)r$(i[n],t)},GeometryCollection:function(e,t){for(var i=e.geometries,n=-1,r=i.length;++n<r;)gI(i[n],t)}};function h6(e,t,i){var n=-1,r=e.length-i,s;for(t.lineStart();++n<r;)s=e[n],t.point(s[0],s[1],s[2]);t.lineEnd()}function r$(e,t){var i=-1,n=e.length;for(t.polygonStart();++i<n;)h6(e[i],t,1);t.polygonEnd()}function The(e,t){e&&i$.hasOwnProperty(e.type)?i$[e.type](e,t):gI(e,t)}p0();p0();function u6(e){return[JA(e[1],e[0]),$m(e[2])]}function KA(e){var t=e[0],i=e[1],n=Ts(i);return[n*Ts(t),n*Rs(t),Rs(i)]}function bE(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function _I(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function n8(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function xE(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function d6(e){var t=Cv(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}p0();function Zj(e,t){function i(n,r){return n=e(n,r),t(n[0],n[1])}return e.invert&&t.invert&&(i.invert=function(n,r){return n=t.invert(n,r),n&&e.invert(n[0],n[1])}),i}function f6(e,t){return[e>mr?e-Wu:e<-mr?e+Wu:e,t]}f6.invert=f6;function Rhe(e,t,i){return(e%=Wu)?t||i?Zj(a$(e),o$(t,i)):a$(e):t||i?o$(t,i):f6}function s$(e){return function(t,i){return t+=e,[t>mr?t-Wu:t<-mr?t+Wu:t,i]}}function a$(e){var t=s$(e);return t.invert=s$(-e),t}function o$(e,t){var i=Ts(e),n=Rs(e),r=Ts(t),s=Rs(t);function a(l,h){var d=Ts(h),p=Ts(l)*d,g=Rs(l)*d,v=Rs(h),y=v*i+p*n;return[JA(g*r-y*s,p*i-v*n),$m(y*r+g*s)]}return a.invert=function(l,h){var d=Ts(h),p=Ts(l)*d,g=Rs(l)*d,v=Rs(h),y=v*r-g*s;return[JA(g*r+v*s,p*i+y*n),$m(y*i-p*n)]},a}function Bhe(e,t,i,n,r,s){if(i){var a=Ts(t),l=Rs(t),h=n*i;r==null?(r=t+n*Wu,s=t-h/2):(r=l$(a,r),s=l$(a,s),(n>0?r<s:r>s)&&(r+=n*Wu));for(var d,p=r;n>0?p>s:p<s;p-=h)d=u6([a,-l*Ts(p),-l*Rs(p)]),e.point(d[0],d[1])}}function l$(e,t){t=KA(t),t[0]-=e,d6(t);var i=Xj(-t[1]);return((-t[2]<0?-i:i)+Wu-Yr)%Wu}function qj(){var e=[],t;return{point:function(i,n){t.push([i,n])},lineStart:function(){e.push(t=[])},lineEnd:H1,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var i=e;return e=[],t=null,i}}}function Lhe(e,t,i,n,r,s){var a=e[0],l=e[1],h=t[0],d=t[1],p=0,g=1,v=h-a,y=d-l,E=i-a;if(!(!v&&E>0)){if(E/=v,v<0){if(E<p)return;E<g&&(g=E)}else if(v>0){if(E>g)return;E>p&&(p=E)}if(E=r-a,!(!v&&E<0)){if(E/=v,v<0){if(E>g)return;E>p&&(p=E)}else if(v>0){if(E<p)return;E<g&&(g=E)}if(E=n-l,!(!y&&E>0)){if(E/=y,y<0){if(E<p)return;E<g&&(g=E)}else if(y>0){if(E>g)return;E>p&&(p=E)}if(E=s-l,!(!y&&E<0)){if(E/=y,y<0){if(E>g)return;E>p&&(p=E)}else if(y>0){if(E<p)return;E<g&&(g=E)}return p>0&&(e[0]=a+p*v,e[1]=l+p*y),g<1&&(t[0]=a+g*v,t[1]=l+g*y),!0}}}}}function MM(e,t){return Ha(e[0]-t[0])<Yr&&Ha(e[1]-t[1])<Yr}function wE(e,t,i,n){this.x=e,this.z=t,this.o=i,this.e=n,this.v=!1,this.n=this.p=null}function Yj(e,t,i,n,r){var s=[],a=[],l,h;if(e.forEach(function(E){if(!((S=E.length-1)<=0)){var S,R=E[0],I=E[S],k;if(MM(R,I)){for(r.lineStart(),l=0;l<S;++l)r.point((R=E[l])[0],R[1]);r.lineEnd();return}s.push(k=new wE(R,E,null,!0)),a.push(k.o=new wE(R,null,k,!1)),s.push(k=new wE(I,E,null,!1)),a.push(k.o=new wE(I,null,k,!0))}}),!!s.length){for(a.sort(t),c$(s),c$(a),l=0,h=a.length;l<h;++l)a[l].e=i=!i;for(var d=s[0],p,g;;){for(var v=d,y=!0;v.v;)if((v=v.n)===d)return;p=v.z,r.lineStart();do{if(v.v=v.o.v=!0,v.e){if(y)for(l=0,h=p.length;l<h;++l)r.point((g=p[l])[0],g[1]);else n(v.x,v.n.x,1,r);v=v.n}else{if(y)for(p=v.p.z,l=p.length-1;l>=0;--l)r.point((g=p[l])[0],g[1]);else n(v.x,v.p.x,-1,r);v=v.p}v=v.o,p=v.z,y=!y}while(!v.v);r.lineEnd()}}}function c$(e){if(t=e.length){for(var t,i=0,n=e[0],r;++i<t;)n.n=r=e[i],r.p=n,n=r;n.n=r=e[0],r.p=n}}function jj(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function khe(e){return e.length===1&&(e=Phe(e)),{left:function(t,i,n,r){for(n==null&&(n=0),r==null&&(r=t.length);n<r;){var s=n+r>>>1;e(t[s],i)<0?n=s+1:r=s}return n},right:function(t,i,n,r){for(n==null&&(n=0),r==null&&(r=t.length);n<r;){var s=n+r>>>1;e(t[s],i)>0?r=s:n=s+1}return n}}}function Phe(e){return function(t,i){return jj(e(t),i)}}khe(jj);function Jj(e){for(var t=e.length,i,n=-1,r=0,s,a;++n<t;)r+=e[n].length;for(s=new Array(r);--t>=0;)for(a=e[t],i=a.length;--i>=0;)s[--r]=a[i];return s}var Q1=1e9,CE=-Q1;function Nhe(e,t,i,n){function r(d,p){return e<=d&&d<=i&&t<=p&&p<=n}function s(d,p,g,v){var y=0,E=0;if(d==null||(y=a(d,g))!==(E=a(p,g))||h(d,p)<0^g>0)do v.point(y===0||y===3?e:i,y>1?n:t);while((y=(y+g+4)%4)!==E);else v.point(p[0],p[1])}function a(d,p){return Ha(d[0]-e)<Yr?p>0?0:3:Ha(d[0]-i)<Yr?p>0?2:1:Ha(d[1]-t)<Yr?p>0?1:0:p>0?3:2}function l(d,p){return h(d.x,p.x)}function h(d,p){var g=a(d,1),v=a(p,1);return g!==v?g-v:g===0?p[1]-d[1]:g===1?d[0]-p[0]:g===2?d[1]-p[1]:p[0]-d[0]}return function(d){var p=d,g=qj(),v,y,E,S,R,I,k,D,F,Z,Y,Q={point:V,lineStart:ne,lineEnd:te,polygonStart:H,polygonEnd:W};function V(X,ee){r(X,ee)&&p.point(X,ee)}function U(){for(var X=0,ee=0,ae=y.length;ee<ae;++ee)for(var ce=y[ee],de=1,pe=ce.length,Ie=ce[0],we,Ee,Se=Ie[0],Ve=Ie[1];de<pe;++de)we=Se,Ee=Ve,Ie=ce[de],Se=Ie[0],Ve=Ie[1],Ee<=n?Ve>n&&(Se-we)*(n-Ee)>(Ve-Ee)*(e-we)&&++X:Ve<=n&&(Se-we)*(n-Ee)<(Ve-Ee)*(e-we)&&--X;return X}function H(){p=g,v=[],y=[],Y=!0}function W(){var X=U(),ee=Y&&X,ae=(v=Jj(v)).length;(ee||ae)&&(d.polygonStart(),ee&&(d.lineStart(),s(null,null,1,d),d.lineEnd()),ae&&Yj(v,l,X,s,d),d.polygonEnd()),p=d,v=y=E=null}function ne(){Q.point=oe,y&&y.push(E=[]),Z=!0,F=!1,k=D=NaN}function te(){v&&(oe(S,R),I&&F&&g.rejoin(),v.push(g.result())),Q.point=V,F&&p.lineEnd()}function oe(X,ee){var ae=r(X,ee);if(y&&E.push([X,ee]),Z)S=X,R=ee,I=ae,Z=!1,ae&&(p.lineStart(),p.point(X,ee));else if(ae&&F)p.point(X,ee);else{var ce=[k=Math.max(CE,Math.min(Q1,k)),D=Math.max(CE,Math.min(Q1,D))],de=[X=Math.max(CE,Math.min(Q1,X)),ee=Math.max(CE,Math.min(Q1,ee))];Lhe(ce,de,e,t,i,n)?(F||(p.lineStart(),p.point(ce[0],ce[1])),p.point(de[0],de[1]),ae||p.lineEnd(),Y=!1):ae&&(p.lineStart(),p.point(X,ee),Y=!1)}k=X,D=ee,F=ae}return Q}}var r8=p0();function Fhe(e,t){var i=t[0],n=t[1],r=[Rs(i),-Ts(i),0],s=0,a=0;r8.reset();for(var l=0,h=e.length;l<h;++l)if(p=(d=e[l]).length)for(var d,p,g=d[p-1],v=g[0],y=g[1]/2+t$,E=Rs(y),S=Ts(y),R=0;R<p;++R,v=k,E=F,S=Z,g=I){var I=d[R],k=I[0],D=I[1]/2+t$,F=Rs(D),Z=Ts(D),Y=k-v,Q=Y>=0?1:-1,V=Q*Y,U=V>mr,H=E*F;if(r8.add(JA(H*Q*Rs(V),S*Z+H*Ts(V))),s+=U?Y+Q*Wu:Y,U^v>=i^k>=i){var W=_I(KA(g),KA(I));d6(W);var ne=_I(r,W);d6(ne);var te=(U^Y>=0?-1:1)*$m(ne[2]);(n>te||n===te&&(W[0]||W[1]))&&(a+=U^Y>=0?1:-1)}}return(s<-Yr||s<Yr&&r8<-Yr)^a&1}p0();function h$(e){return e}p0();p0();var ev=1/0,AI=ev,Yb=-ev,vI=Yb,u$={point:Dhe,lineStart:H1,lineEnd:H1,polygonStart:H1,polygonEnd:H1,result:function(){var e=[[ev,AI],[Yb,vI]];return Yb=vI=-(AI=ev=1/0),e}};function Dhe(e,t){e<ev&&(ev=e),e>Yb&&(Yb=e),t<AI&&(AI=t),t>vI&&(vI=t)}p0();function Kj(e,t,i,n){return function(r,s){var a=t(s),l=r.invert(n[0],n[1]),h=qj(),d=t(h),p=!1,g,v,y,E={point:S,lineStart:I,lineEnd:k,polygonStart:function(){E.point=D,E.lineStart=F,E.lineEnd=Z,v=[],g=[]},polygonEnd:function(){E.point=S,E.lineStart=I,E.lineEnd=k,v=Jj(v);var Y=Fhe(g,l);v.length?(p||(s.polygonStart(),p=!0),Yj(v,Uhe,Y,i,s)):Y&&(p||(s.polygonStart(),p=!0),s.lineStart(),i(null,null,1,s),s.lineEnd()),p&&(s.polygonEnd(),p=!1),v=g=null},sphere:function(){s.polygonStart(),s.lineStart(),i(null,null,1,s),s.lineEnd(),s.polygonEnd()}};function S(Y,Q){var V=r(Y,Q);e(Y=V[0],Q=V[1])&&s.point(Y,Q)}function R(Y,Q){var V=r(Y,Q);a.point(V[0],V[1])}function I(){E.point=R,a.lineStart()}function k(){E.point=S,a.lineEnd()}function D(Y,Q){y.push([Y,Q]);var V=r(Y,Q);d.point(V[0],V[1])}function F(){d.lineStart(),y=[]}function Z(){D(y[0][0],y[0][1]),d.lineEnd();var Y=d.clean(),Q=h.result(),V,U=Q.length,H,W,ne;if(y.pop(),g.push(y),y=null,!!U){if(Y&1){if(W=Q[0],(H=W.length-1)>0){for(p||(s.polygonStart(),p=!0),s.lineStart(),V=0;V<H;++V)s.point((ne=W[V])[0],ne[1]);s.lineEnd()}return}U>1&&Y&2&&Q.push(Q.pop().concat(Q.shift())),v.push(Q.filter(Ohe))}}return E}}function Ohe(e){return e.length>1}function Uhe(e,t){return((e=e.x)[0]<0?e[1]-Fu-Yr:Fu-e[1])-((t=t.x)[0]<0?t[1]-Fu-Yr:Fu-t[1])}var d$=Kj(function(){return!0},Ghe,Vhe,[-mr,-Fu]);function Ghe(e){var t=NaN,i=NaN,n=NaN,r;return{lineStart:function(){e.lineStart(),r=1},point:function(s,a){var l=s>0?mr:-mr,h=Ha(s-t);Ha(h-mr)<Yr?(e.point(t,i=(i+a)/2>0?Fu:-Fu),e.point(n,i),e.lineEnd(),e.lineStart(),e.point(l,i),e.point(s,i),r=0):n!==l&&h>=mr&&(Ha(t-n)<Yr&&(t-=n*Yr),Ha(s-l)<Yr&&(s-=l*Yr),i=zhe(t,i,s,a),e.point(n,i),e.lineEnd(),e.lineStart(),e.point(l,i),r=0),e.point(t=s,i=a),n=l},lineEnd:function(){e.lineEnd(),t=i=NaN},clean:function(){return 2-r}}}function zhe(e,t,i,n){var r,s,a=Rs(e-i);return Ha(a)>Yr?Ihe((Rs(t)*(s=Ts(n))*Rs(i)-Rs(n)*(r=Ts(t))*Rs(e))/(r*s*a)):(t+n)/2}function Vhe(e,t,i,n){var r;if(e==null)r=i*Fu,n.point(-mr,r),n.point(0,r),n.point(mr,r),n.point(mr,0),n.point(mr,-r),n.point(0,-r),n.point(-mr,-r),n.point(-mr,0),n.point(-mr,r);else if(Ha(e[0]-t[0])>Yr){var s=e[0]<t[0]?mr:-mr;r=i*s/2,n.point(-s,r),n.point(0,r),n.point(s,r)}else n.point(t[0],t[1])}function $he(e,t){var i=Ts(e),n=i>0,r=Ha(i)>Yr;function s(p,g,v,y){Bhe(y,e,t,v,p,g)}function a(p,g){return Ts(p)*Ts(g)>i}function l(p){var g,v,y,E,S;return{lineStart:function(){E=y=!1,S=1},point:function(R,I){var k=[R,I],D,F=a(R,I),Z=n?F?0:d(R,I):F?d(R+(R<0?mr:-mr),I):0;if(!g&&(E=y=F)&&p.lineStart(),F!==y&&(D=h(g,k),(!D||MM(g,D)||MM(k,D))&&(k[0]+=Yr,k[1]+=Yr,F=a(k[0],k[1]))),F!==y)S=0,F?(p.lineStart(),D=h(k,g),p.point(D[0],D[1])):(D=h(g,k),p.point(D[0],D[1]),p.lineEnd()),g=D;else if(r&&g&&n^F){var Y;!(Z&v)&&(Y=h(k,g,!0))&&(S=0,n?(p.lineStart(),p.point(Y[0][0],Y[0][1]),p.point(Y[1][0],Y[1][1]),p.lineEnd()):(p.point(Y[1][0],Y[1][1]),p.lineEnd(),p.lineStart(),p.point(Y[0][0],Y[0][1])))}F&&(!g||!MM(g,k))&&p.point(k[0],k[1]),g=k,y=F,v=Z},lineEnd:function(){y&&p.lineEnd(),g=null},clean:function(){return S|(E&&y)<<1}}}function h(p,g,v){var y=KA(p),E=KA(g),S=[1,0,0],R=_I(y,E),I=bE(R,R),k=R[0],D=I-k*k;if(!D)return!v&&p;var F=i*I/D,Z=-i*k/D,Y=_I(S,R),Q=xE(S,F);n8(Q,xE(R,Z));var V=Y,U=bE(Q,V),H=bE(V,V),W=U*U-H*(bE(Q,Q)-1);if(!(W<0)){var ne=Cv(W),te=xE(V,(-U-ne)/H);if(n8(te,Q),te=u6(te),!v)return te;var oe=p[0],X=g[0],ee=p[1],ae=g[1],ce;X<oe&&(ce=oe,oe=X,X=ce);var de=X-oe,pe=Ha(de-mr)<Yr,Ie=pe||de<Yr;if(!pe&&ae<ee&&(ce=ee,ee=ae,ae=ce),Ie?pe?ee+ae>0^te[1]<(Ha(te[0]-oe)<Yr?ee:ae):ee<=te[1]&&te[1]<=ae:de>mr^(oe<=te[0]&&te[0]<=X)){var we=xE(V,(-U+ne)/H);return n8(we,Q),[te,u6(we)]}}}function d(p,g){var v=n?e:mr-e,y=0;return p<-v?y|=1:p>v&&(y|=2),g<-v?y|=4:g>v&&(y|=8),y}return Kj(a,l,s,n?[0,-e]:[-mr,e-mr])}function eJ(e){return function(t){var i=new p6;for(var n in e)i[n]=e[n];return i.stream=t,i}}function p6(){}p6.prototype={constructor:p6,point:function(e,t){this.stream.point(e,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function tJ(e,t,i){var n=t[1][0]-t[0][0],r=t[1][1]-t[0][1],s=e.clipExtent&&e.clipExtent();e.scale(150).translate([0,0]),s!=null&&e.clipExtent(null),The(i,e.stream(u$));var a=u$.result(),l=Math.min(n/(a[1][0]-a[0][0]),r/(a[1][1]-a[0][1])),h=+t[0][0]+(n-l*(a[1][0]+a[0][0]))/2,d=+t[0][1]+(r-l*(a[1][1]+a[0][1]))/2;return s!=null&&e.clipExtent(s),e.scale(l*150).translate([h,d])}function Hhe(e,t,i){return tJ(e,[[0,0],t],i)}var f$=16,Qhe=Ts(30*rh);function p$(e,t){return+t?Xhe(e,t):Whe(e)}function Whe(e){return eJ({point:function(t,i){t=e(t,i),this.stream.point(t[0],t[1])}})}function Xhe(e,t){function i(n,r,s,a,l,h,d,p,g,v,y,E,S,R){var I=d-n,k=p-r,D=I*I+k*k;if(D>4*t&&S--){var F=a+v,Z=l+y,Y=h+E,Q=Cv(F*F+Z*Z+Y*Y),V=$m(Y/=Q),U=Ha(Ha(Y)-1)<Yr||Ha(s-g)<Yr?(s+g)/2:JA(Z,F),H=e(U,V),W=H[0],ne=H[1],te=W-n,oe=ne-r,X=k*te-I*oe;(X*X/D>t||Ha((I*te+k*oe)/D-.5)>.3||a*v+l*y+h*E<Qhe)&&(i(n,r,s,a,l,h,W,ne,U,F/=Q,Z/=Q,Y,S,R),R.point(W,ne),i(W,ne,U,F,Z,Y,d,p,g,v,y,E,S,R))}}return function(n){var r,s,a,l,h,d,p,g,v,y,E,S,R={point:I,lineStart:k,lineEnd:F,polygonStart:function(){n.polygonStart(),R.lineStart=Z},polygonEnd:function(){n.polygonEnd(),R.lineStart=k}};function I(V,U){V=e(V,U),n.point(V[0],V[1])}function k(){g=NaN,R.point=D,n.lineStart()}function D(V,U){var H=KA([V,U]),W=e(V,U);i(g,v,p,y,E,S,g=W[0],v=W[1],p=V,y=H[0],E=H[1],S=H[2],f$,n),n.point(g,v)}function F(){R.point=I,n.lineEnd()}function Z(){k(),R.point=Y,R.lineEnd=Q}function Y(V,U){D(r=V,U),s=g,a=v,l=y,h=E,d=S,R.point=D}function Q(){i(g,v,p,y,E,S,s,a,r,l,h,d,f$,n),R.lineEnd=F,F()}return R}}var Zhe=eJ({point:function(e,t){this.stream.point(e*rh,t*rh)}});function qhe(e){return Yhe(function(){return e})()}function Yhe(e){var t,i=150,n=480,r=250,s,a,l=0,h=0,d=0,p=0,g=0,v,y,E=null,S=d$,R=null,I,k,D,F=h$,Z=.5,Y=p$(W,Z),Q,V;function U(oe){return oe=y(oe[0]*rh,oe[1]*rh),[oe[0]*i+s,a-oe[1]*i]}function H(oe){return oe=y.invert((oe[0]-s)/i,(a-oe[1])/i),oe&&[oe[0]*ip,oe[1]*ip]}function W(oe,X){return oe=t(oe,X),[oe[0]*i+s,a-oe[1]*i]}U.stream=function(oe){return Q&&V===oe?Q:Q=Zhe(S(v,Y(F(V=oe))))},U.clipAngle=function(oe){return arguments.length?(S=+oe?$he(E=oe*rh,6*rh):(E=null,d$),te()):E*ip},U.clipExtent=function(oe){return arguments.length?(F=oe==null?(R=I=k=D=null,h$):Nhe(R=+oe[0][0],I=+oe[0][1],k=+oe[1][0],D=+oe[1][1]),te()):R==null?null:[[R,I],[k,D]]},U.scale=function(oe){return arguments.length?(i=+oe,ne()):i},U.translate=function(oe){return arguments.length?(n=+oe[0],r=+oe[1],ne()):[n,r]},U.center=function(oe){return arguments.length?(l=oe[0]%360*rh,h=oe[1]%360*rh,ne()):[l*ip,h*ip]},U.rotate=function(oe){return arguments.length?(d=oe[0]%360*rh,p=oe[1]%360*rh,g=oe.length>2?oe[2]%360*rh:0,ne()):[d*ip,p*ip,g*ip]},U.precision=function(oe){return arguments.length?(Y=p$(W,Z=oe*oe),te()):Cv(Z)},U.fitExtent=function(oe,X){return tJ(U,oe,X)},U.fitSize=function(oe,X){return Hhe(U,oe,X)};function ne(){y=Zj(v=Rhe(d,p,g),t);var oe=t(l,h);return s=n-oe[0]*i,a=r+oe[1]*i,te()}function te(){return Q=V=null,U}return function(){return t=e.apply(this,arguments),U.invert=t.invert&&H,ne()}}function iJ(e){return function(t,i){var n=Ts(t),r=Ts(i),s=e(n*r);return[s*r*Rs(t),s*Rs(i)]}}function nJ(e){return function(t,i){var n=Cv(t*t+i*i),r=e(n),s=Rs(r),a=Ts(r);return[JA(t*s,n*a),$m(n&&i*s/n)]}}var jhe=iJ(function(e){return Cv(2/(1+e))});jhe.invert=nJ(function(e){return 2*$m(e/2)});var rJ=iJ(function(e){return(e=Xj(e))&&e/Rs(e)});rJ.invert=nJ(function(e){return e});function Jhe(){return qhe(rJ).scale(79.4188).clipAngle(179.999)}function m$(e,t){return[e,t]}m$.invert=m$;var{BufferOp:Khe,GeoJSONReader:eue,GeoJSONWriter:tue}=Mhe;function iue(e,t,i){i=i||{};var n=i.units||"kilometers",r=i.steps||8;if(!e)throw new Error("geojson is required");if(typeof i!="object")throw new Error("options must be an object");if(typeof r!="number")throw new Error("steps must be an number");if(t===void 0)throw new Error("radius is required");if(r<=0)throw new Error("steps must be greater than 0");var s=[];switch(e.type){case"GeometryCollection":return f0(e,function(a){var l=IM(a,t,n,r);l&&s.push(l)}),Qn(s);case"FeatureCollection":return Af(e,function(a){var l=IM(a,t,n,r);l&&Af(l,function(h){h&&s.push(h)})}),Qn(s)}return IM(e,t,n,r)}function IM(e,t,i,n){var r=e.properties||{},s=e.type==="Feature"?e.geometry:e;if(s.type==="GeometryCollection"){var a=[];return f0(e,function(v){var y=IM(v,t,i,n);y&&a.push(y)}),Qn(a)}var l=nue(s),h={type:s.type,coordinates:aJ(s.coordinates,l)},d=new eue().read(h),p=YG(Tj(t,i),"meters"),g=Khe.bufferOp(d,p,n);if(g=new tue().write(g),!sJ(g.coordinates))return ic({type:g.type,coordinates:oJ(g.coordinates,l)},r)}function sJ(e){return Array.isArray(e[0])?sJ(e[0]):isNaN(e[0])}function aJ(e,t){return typeof e[0]!="object"?t(e):e.map(function(i){return aJ(i,t)})}function oJ(e,t){return typeof e[0]!="object"?t.invert(e):e.map(function(i){return oJ(i,t)})}function nue(e){var t=Wj(e).geometry.coordinates,i=[-t[0],-t[1]];return Jhe().rotate(i).scale(Ua)}function jb(e,t={}){let i=0,n=0,r=0;return d0(e,function(s){i+=s[0],n+=s[1],r++},!0),aa([i/r,n/r],t.properties)}function Go(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return lJ(e);case"FeatureCollection":return rue(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return rz(e);default:throw new Error("unknown GeoJSON type")}}function lJ(e){const t={type:"Feature"};return Object.keys(e).forEach(i=>{switch(i){case"type":case"properties":case"geometry":return;default:t[i]=e[i]}}),t.properties=cJ(e.properties),e.geometry==null?t.geometry=null:t.geometry=rz(e.geometry),t}function cJ(e){const t={};return e&&Object.keys(e).forEach(i=>{const n=e[i];typeof n=="object"?n===null?t[i]=null:Array.isArray(n)?t[i]=n.map(r=>r):t[i]=cJ(n):t[i]=n}),t}function rue(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(i=>{switch(i){case"type":case"features":return;default:t[i]=e[i]}}),t.features=e.features.map(i=>lJ(i)),t}function rz(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),e.type==="GeometryCollection"?(t.geometries=e.geometries.map(i=>rz(i)),t):(t.coordinates=hJ(e.coordinates),t)}function hJ(e){const t=e;return typeof t[0]!="object"?t.slice():t.map(i=>hJ(i))}var sue=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,s8=Math.ceil,Jc=Math.floor,Ol="[BigNumber Error] ",g$=Ol+"Number primitive has more than 15 significant digits: ",Rh=1e14,Nn=14,a8=9007199254740991,o8=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],np=1e7,Fa=1e9;function uJ(e){var t,i,n,r=k.prototype={constructor:k,toString:null,valueOf:null},s=new k(1),a=20,l=4,h=-7,d=21,p=-1e7,g=1e7,v=!1,y=1,E=0,S={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},R="0123456789abcdefghijklmnopqrstuvwxyz",I=!0;function k(V,U){var H,W,ne,te,oe,X,ee,ae,ce=this;if(!(ce instanceof k))return new k(V,U);if(U==null){if(V&&V._isBigNumber===!0){ce.s=V.s,!V.c||V.e>g?ce.c=ce.e=null:V.e<p?ce.c=[ce.e=0]:(ce.e=V.e,ce.c=V.c.slice());return}if((X=typeof V=="number")&&V*0==0){if(ce.s=1/V<0?(V=-V,-1):1,V===~~V){for(te=0,oe=V;oe>=10;oe/=10,te++);te>g?ce.c=ce.e=null:(ce.e=te,ce.c=[V]);return}ae=String(V)}else{if(!sue.test(ae=String(V)))return n(ce,ae,X);ce.s=ae.charCodeAt(0)==45?(ae=ae.slice(1),-1):1}(te=ae.indexOf("."))>-1&&(ae=ae.replace(".","")),(oe=ae.search(/e/i))>0?(te<0&&(te=oe),te+=+ae.slice(oe+1),ae=ae.substring(0,oe)):te<0&&(te=ae.length)}else{if(xs(U,2,R.length,"Base"),U==10&&I)return ce=new k(V),Y(ce,a+ce.e+1,l);if(ae=String(V),X=typeof V=="number"){if(V*0!=0)return n(ce,ae,X,U);if(ce.s=1/V<0?(ae=ae.slice(1),-1):1,k.DEBUG&&ae.replace(/^0\.0*|\./,"").length>15)throw Error(g$+V)}else ce.s=ae.charCodeAt(0)===45?(ae=ae.slice(1),-1):1;for(H=R.slice(0,U),te=oe=0,ee=ae.length;oe<ee;oe++)if(H.indexOf(W=ae.charAt(oe))<0){if(W=="."){if(oe>te){te=ee;continue}}else if(!ne&&(ae==ae.toUpperCase()&&(ae=ae.toLowerCase())||ae==ae.toLowerCase()&&(ae=ae.toUpperCase()))){ne=!0,oe=-1,te=0;continue}return n(ce,String(V),X,U)}X=!1,ae=i(ae,U,10,ce.s),(te=ae.indexOf("."))>-1?ae=ae.replace(".",""):te=ae.length}for(oe=0;ae.charCodeAt(oe)===48;oe++);for(ee=ae.length;ae.charCodeAt(--ee)===48;);if(ae=ae.slice(oe,++ee)){if(ee-=oe,X&&k.DEBUG&&ee>15&&(V>a8||V!==Jc(V)))throw Error(g$+ce.s*V);if((te=te-oe-1)>g)ce.c=ce.e=null;else if(te<p)ce.c=[ce.e=0];else{if(ce.e=te,ce.c=[],oe=(te+1)%Nn,te<0&&(oe+=Nn),oe<ee){for(oe&&ce.c.push(+ae.slice(0,oe)),ee-=Nn;oe<ee;)ce.c.push(+ae.slice(oe,oe+=Nn));oe=Nn-(ae=ae.slice(oe)).length}else oe-=ee;for(;oe--;ae+="0");ce.c.push(+ae)}}else ce.c=[ce.e=0]}k.clone=uJ,k.ROUND_UP=0,k.ROUND_DOWN=1,k.ROUND_CEIL=2,k.ROUND_FLOOR=3,k.ROUND_HALF_UP=4,k.ROUND_HALF_DOWN=5,k.ROUND_HALF_EVEN=6,k.ROUND_HALF_CEIL=7,k.ROUND_HALF_FLOOR=8,k.EUCLID=9,k.config=k.set=function(V){var U,H;if(V!=null)if(typeof V=="object"){if(V.hasOwnProperty(U="DECIMAL_PLACES")&&(H=V[U],xs(H,0,Fa,U),a=H),V.hasOwnProperty(U="ROUNDING_MODE")&&(H=V[U],xs(H,0,8,U),l=H),V.hasOwnProperty(U="EXPONENTIAL_AT")&&(H=V[U],H&&H.pop?(xs(H[0],-Fa,0,U),xs(H[1],0,Fa,U),h=H[0],d=H[1]):(xs(H,-Fa,Fa,U),h=-(d=H<0?-H:H))),V.hasOwnProperty(U="RANGE"))if(H=V[U],H&&H.pop)xs(H[0],-Fa,-1,U),xs(H[1],1,Fa,U),p=H[0],g=H[1];else if(xs(H,-Fa,Fa,U),H)p=-(g=H<0?-H:H);else throw Error(Ol+U+" cannot be zero: "+H);if(V.hasOwnProperty(U="CRYPTO"))if(H=V[U],H===!!H)if(H)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))v=H;else throw v=!H,Error(Ol+"crypto unavailable");else v=H;else throw Error(Ol+U+" not true or false: "+H);if(V.hasOwnProperty(U="MODULO_MODE")&&(H=V[U],xs(H,0,9,U),y=H),V.hasOwnProperty(U="POW_PRECISION")&&(H=V[U],xs(H,0,Fa,U),E=H),V.hasOwnProperty(U="FORMAT"))if(H=V[U],typeof H=="object")S=H;else throw Error(Ol+U+" not an object: "+H);if(V.hasOwnProperty(U="ALPHABET"))if(H=V[U],typeof H=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(H))I=H.slice(0,10)=="0123456789",R=H;else throw Error(Ol+U+" invalid: "+H)}else throw Error(Ol+"Object expected: "+V);return{DECIMAL_PLACES:a,ROUNDING_MODE:l,EXPONENTIAL_AT:[h,d],RANGE:[p,g],CRYPTO:v,MODULO_MODE:y,POW_PRECISION:E,FORMAT:S,ALPHABET:R}},k.isBigNumber=function(V){if(!V||V._isBigNumber!==!0)return!1;if(!k.DEBUG)return!0;var U,H,W=V.c,ne=V.e,te=V.s;e:if({}.toString.call(W)=="[object Array]"){if((te===1||te===-1)&&ne>=-Fa&&ne<=Fa&&ne===Jc(ne)){if(W[0]===0){if(ne===0&&W.length===1)return!0;break e}if(U=(ne+1)%Nn,U<1&&(U+=Nn),String(W[0]).length==U){for(U=0;U<W.length;U++)if(H=W[U],H<0||H>=Rh||H!==Jc(H))break e;if(H!==0)return!0}}}else if(W===null&&ne===null&&(te===null||te===1||te===-1))return!0;throw Error(Ol+"Invalid BigNumber: "+V)},k.maximum=k.max=function(){return F(arguments,-1)},k.minimum=k.min=function(){return F(arguments,1)},k.random=(function(){var V=9007199254740992,U=Math.random()*V&2097151?function(){return Jc(Math.random()*V)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(H){var W,ne,te,oe,X,ee=0,ae=[],ce=new k(s);if(H==null?H=a:xs(H,0,Fa),oe=s8(H/Nn),v)if(crypto.getRandomValues){for(W=crypto.getRandomValues(new Uint32Array(oe*=2));ee<oe;)X=W[ee]*131072+(W[ee+1]>>>11),X>=9e15?(ne=crypto.getRandomValues(new Uint32Array(2)),W[ee]=ne[0],W[ee+1]=ne[1]):(ae.push(X%1e14),ee+=2);ee=oe/2}else if(crypto.randomBytes){for(W=crypto.randomBytes(oe*=7);ee<oe;)X=(W[ee]&31)*281474976710656+W[ee+1]*1099511627776+W[ee+2]*4294967296+W[ee+3]*16777216+(W[ee+4]<<16)+(W[ee+5]<<8)+W[ee+6],X>=9e15?crypto.randomBytes(7).copy(W,ee):(ae.push(X%1e14),ee+=7);ee=oe/7}else throw v=!1,Error(Ol+"crypto unavailable");if(!v)for(;ee<oe;)X=U(),X<9e15&&(ae[ee++]=X%1e14);for(oe=ae[--ee],H%=Nn,oe&&H&&(X=o8[Nn-H],ae[ee]=Jc(oe/X)*X);ae[ee]===0;ae.pop(),ee--);if(ee<0)ae=[te=0];else{for(te=-1;ae[0]===0;ae.splice(0,1),te-=Nn);for(ee=1,X=ae[0];X>=10;X/=10,ee++);ee<Nn&&(te-=Nn-ee)}return ce.e=te,ce.c=ae,ce}})(),k.sum=function(){for(var V=1,U=arguments,H=new k(U[0]);V<U.length;)H=H.plus(U[V++]);return H},i=(function(){var V="0123456789";function U(H,W,ne,te){for(var oe,X=[0],ee,ae=0,ce=H.length;ae<ce;){for(ee=X.length;ee--;X[ee]*=W);for(X[0]+=te.indexOf(H.charAt(ae++)),oe=0;oe<X.length;oe++)X[oe]>ne-1&&(X[oe+1]==null&&(X[oe+1]=0),X[oe+1]+=X[oe]/ne|0,X[oe]%=ne)}return X.reverse()}return function(H,W,ne,te,oe){var X,ee,ae,ce,de,pe,Ie,we,Ee=H.indexOf("."),Se=a,Ve=l;for(Ee>=0&&(ce=E,E=0,H=H.replace(".",""),we=new k(W),pe=we.pow(H.length-Ee),E=ce,we.c=U(kd(qc(pe.c),pe.e,"0"),10,ne,V),we.e=we.c.length),Ie=U(H,W,ne,oe?(X=R,V):(X=V,R)),ae=ce=Ie.length;Ie[--ce]==0;Ie.pop());if(!Ie[0])return X.charAt(0);if(Ee<0?--ae:(pe.c=Ie,pe.e=ae,pe.s=te,pe=t(pe,we,Se,Ve,ne),Ie=pe.c,de=pe.r,ae=pe.e),ee=ae+Se+1,Ee=Ie[ee],ce=ne/2,de=de||ee<0||Ie[ee+1]!=null,de=Ve<4?(Ee!=null||de)&&(Ve==0||Ve==(pe.s<0?3:2)):Ee>ce||Ee==ce&&(Ve==4||de||Ve==6&&Ie[ee-1]&1||Ve==(pe.s<0?8:7)),ee<1||!Ie[0])H=de?kd(X.charAt(1),-Se,X.charAt(0)):X.charAt(0);else{if(Ie.length=ee,de)for(--ne;++Ie[--ee]>ne;)Ie[ee]=0,ee||(++ae,Ie=[1].concat(Ie));for(ce=Ie.length;!Ie[--ce];);for(Ee=0,H="";Ee<=ce;H+=X.charAt(Ie[Ee++]));H=kd(H,ae,X.charAt(0))}return H}})(),t=(function(){function V(W,ne,te){var oe,X,ee,ae,ce=0,de=W.length,pe=ne%np,Ie=ne/np|0;for(W=W.slice();de--;)ee=W[de]%np,ae=W[de]/np|0,oe=Ie*ee+ae*pe,X=pe*ee+oe%np*np+ce,ce=(X/te|0)+(oe/np|0)+Ie*ae,W[de]=X%te;return ce&&(W=[ce].concat(W)),W}function U(W,ne,te,oe){var X,ee;if(te!=oe)ee=te>oe?1:-1;else for(X=ee=0;X<te;X++)if(W[X]!=ne[X]){ee=W[X]>ne[X]?1:-1;break}return ee}function H(W,ne,te,oe){for(var X=0;te--;)W[te]-=X,X=W[te]<ne[te]?1:0,W[te]=X*oe+W[te]-ne[te];for(;!W[0]&&W.length>1;W.splice(0,1));}return function(W,ne,te,oe,X){var ee,ae,ce,de,pe,Ie,we,Ee,Se,Ve,ze,it,Le,nt,lt,Ae,vt,Ne=W.s==ne.s?1:-1,$t=W.c,It=ne.c;if(!$t||!$t[0]||!It||!It[0])return new k(!W.s||!ne.s||($t?It&&$t[0]==It[0]:!It)?NaN:$t&&$t[0]==0||!It?Ne*0:Ne/0);for(Ee=new k(Ne),Se=Ee.c=[],ae=W.e-ne.e,Ne=te+ae+1,X||(X=Rh,ae=Kc(W.e/Nn)-Kc(ne.e/Nn),Ne=Ne/Nn|0),ce=0;It[ce]==($t[ce]||0);ce++);if(It[ce]>($t[ce]||0)&&ae--,Ne<0)Se.push(1),de=!0;else{for(nt=$t.length,Ae=It.length,ce=0,Ne+=2,pe=Jc(X/(It[0]+1)),pe>1&&(It=V(It,pe,X),$t=V($t,pe,X),Ae=It.length,nt=$t.length),Le=Ae,Ve=$t.slice(0,Ae),ze=Ve.length;ze<Ae;Ve[ze++]=0);vt=It.slice(),vt=[0].concat(vt),lt=It[0],It[1]>=X/2&<++;do{if(pe=0,ee=U(It,Ve,Ae,ze),ee<0){if(it=Ve[0],Ae!=ze&&(it=it*X+(Ve[1]||0)),pe=Jc(it/lt),pe>1)for(pe>=X&&(pe=X-1),Ie=V(It,pe,X),we=Ie.length,ze=Ve.length;U(Ie,Ve,we,ze)==1;)pe--,H(Ie,Ae<we?vt:It,we,X),we=Ie.length,ee=1;else pe==0&&(ee=pe=1),Ie=It.slice(),we=Ie.length;if(we<ze&&(Ie=[0].concat(Ie)),H(Ve,Ie,ze,X),ze=Ve.length,ee==-1)for(;U(It,Ve,Ae,ze)<1;)pe++,H(Ve,Ae<ze?vt:It,ze,X),ze=Ve.length}else ee===0&&(pe++,Ve=[0]);Se[ce++]=pe,Ve[0]?Ve[ze++]=$t[Le]||0:(Ve=[$t[Le]],ze=1)}while((Le++<nt||Ve[0]!=null)&&Ne--);de=Ve[0]!=null,Se[0]||Se.splice(0,1)}if(X==Rh){for(ce=1,Ne=Se[0];Ne>=10;Ne/=10,ce++);Y(Ee,te+(Ee.e=ce+ae*Nn-1)+1,oe,de)}else Ee.e=ae,Ee.r=+de;return Ee}})();function D(V,U,H,W){var ne,te,oe,X,ee;if(H==null?H=l:xs(H,0,8),!V.c)return V.toString();if(ne=V.c[0],oe=V.e,U==null)ee=qc(V.c),ee=W==1||W==2&&(oe<=h||oe>=d)?SE(ee,oe):kd(ee,oe,"0");else if(V=Y(new k(V),U,H),te=V.e,ee=qc(V.c),X=ee.length,W==1||W==2&&(U<=te||te<=h)){for(;X<U;ee+="0",X++);ee=SE(ee,te)}else if(U-=oe+(W===2&&te>oe),ee=kd(ee,te,"0"),te+1>X){if(--U>0)for(ee+=".";U--;ee+="0");}else if(U+=te-X,U>0)for(te+1==X&&(ee+=".");U--;ee+="0");return V.s<0&&ne?"-"+ee:ee}function F(V,U){for(var H,W,ne=1,te=new k(V[0]);ne<V.length;ne++)W=new k(V[ne]),(!W.s||(H=em(te,W))===U||H===0&&te.s===U)&&(te=W);return te}function Z(V,U,H){for(var W=1,ne=U.length;!U[--ne];U.pop());for(ne=U[0];ne>=10;ne/=10,W++);return(H=W+H*Nn-1)>g?V.c=V.e=null:H<p?V.c=[V.e=0]:(V.e=H,V.c=U),V}n=(function(){var V=/^(-?)0([xbo])(?=\w[\w.]*$)/i,U=/^([^.]+)\.$/,H=/^\.([^.]+)$/,W=/^-?(Infinity|NaN)$/,ne=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(te,oe,X,ee){var ae,ce=X?oe:oe.replace(ne,"");if(W.test(ce))te.s=isNaN(ce)?null:ce<0?-1:1;else{if(!X&&(ce=ce.replace(V,function(de,pe,Ie){return ae=(Ie=Ie.toLowerCase())=="x"?16:Ie=="b"?2:8,!ee||ee==ae?pe:de}),ee&&(ae=ee,ce=ce.replace(U,"$1").replace(H,"0.$1")),oe!=ce))return new k(ce,ae);if(k.DEBUG)throw Error(Ol+"Not a"+(ee?" base "+ee:"")+" number: "+oe);te.s=null}te.c=te.e=null}})();function Y(V,U,H,W){var ne,te,oe,X,ee,ae,ce,de=V.c,pe=o8;if(de){e:{for(ne=1,X=de[0];X>=10;X/=10,ne++);if(te=U-ne,te<0)te+=Nn,oe=U,ee=de[ae=0],ce=Jc(ee/pe[ne-oe-1]%10);else if(ae=s8((te+1)/Nn),ae>=de.length)if(W){for(;de.length<=ae;de.push(0));ee=ce=0,ne=1,te%=Nn,oe=te-Nn+1}else break e;else{for(ee=X=de[ae],ne=1;X>=10;X/=10,ne++);te%=Nn,oe=te-Nn+ne,ce=oe<0?0:Jc(ee/pe[ne-oe-1]%10)}if(W=W||U<0||de[ae+1]!=null||(oe<0?ee:ee%pe[ne-oe-1]),W=H<4?(ce||W)&&(H==0||H==(V.s<0?3:2)):ce>5||ce==5&&(H==4||W||H==6&&(te>0?oe>0?ee/pe[ne-oe]:0:de[ae-1])%10&1||H==(V.s<0?8:7)),U<1||!de[0])return de.length=0,W?(U-=V.e+1,de[0]=pe[(Nn-U%Nn)%Nn],V.e=-U||0):de[0]=V.e=0,V;if(te==0?(de.length=ae,X=1,ae--):(de.length=ae+1,X=pe[Nn-te],de[ae]=oe>0?Jc(ee/pe[ne-oe]%pe[oe])*X:0),W)for(;;)if(ae==0){for(te=1,oe=de[0];oe>=10;oe/=10,te++);for(oe=de[0]+=X,X=1;oe>=10;oe/=10,X++);te!=X&&(V.e++,de[0]==Rh&&(de[0]=1));break}else{if(de[ae]+=X,de[ae]!=Rh)break;de[ae--]=0,X=1}for(te=de.length;de[--te]===0;de.pop());}V.e>g?V.c=V.e=null:V.e<p&&(V.c=[V.e=0])}return V}function Q(V){var U,H=V.e;return H===null?V.toString():(U=qc(V.c),U=H<=h||H>=d?SE(U,H):kd(U,H,"0"),V.s<0?"-"+U:U)}return r.absoluteValue=r.abs=function(){var V=new k(this);return V.s<0&&(V.s=1),V},r.comparedTo=function(V,U){return em(this,new k(V,U))},r.decimalPlaces=r.dp=function(V,U){var H,W,ne,te=this;if(V!=null)return xs(V,0,Fa),U==null?U=l:xs(U,0,8),Y(new k(te),V+te.e+1,U);if(!(H=te.c))return null;if(W=((ne=H.length-1)-Kc(this.e/Nn))*Nn,ne=H[ne])for(;ne%10==0;ne/=10,W--);return W<0&&(W=0),W},r.dividedBy=r.div=function(V,U){return t(this,new k(V,U),a,l)},r.dividedToIntegerBy=r.idiv=function(V,U){return t(this,new k(V,U),0,1)},r.exponentiatedBy=r.pow=function(V,U){var H,W,ne,te,oe,X,ee,ae,ce,de=this;if(V=new k(V),V.c&&!V.isInteger())throw Error(Ol+"Exponent not an integer: "+Q(V));if(U!=null&&(U=new k(U)),X=V.e>14,!de.c||!de.c[0]||de.c[0]==1&&!de.e&&de.c.length==1||!V.c||!V.c[0])return ce=new k(Math.pow(+Q(de),X?V.s*(2-EE(V)):+Q(V))),U?ce.mod(U):ce;if(ee=V.s<0,U){if(U.c?!U.c[0]:!U.s)return new k(NaN);W=!ee&&de.isInteger()&&U.isInteger(),W&&(de=de.mod(U))}else{if(V.e>9&&(de.e>0||de.e<-1||(de.e==0?de.c[0]>1||X&&de.c[1]>=24e7:de.c[0]<8e13||X&&de.c[0]<=9999975e7)))return te=de.s<0&&EE(V)?-0:0,de.e>-1&&(te=1/te),new k(ee?1/te:te);E&&(te=s8(E/Nn+2))}for(X?(H=new k(.5),ee&&(V.s=1),ae=EE(V)):(ne=Math.abs(+Q(V)),ae=ne%2),ce=new k(s);;){if(ae){if(ce=ce.times(de),!ce.c)break;te?ce.c.length>te&&(ce.c.length=te):W&&(ce=ce.mod(U))}if(ne){if(ne=Jc(ne/2),ne===0)break;ae=ne%2}else if(V=V.times(H),Y(V,V.e+1,1),V.e>14)ae=EE(V);else{if(ne=+Q(V),ne===0)break;ae=ne%2}de=de.times(de),te?de.c&&de.c.length>te&&(de.c.length=te):W&&(de=de.mod(U))}return W?ce:(ee&&(ce=s.div(ce)),U?ce.mod(U):te?Y(ce,E,l,oe):ce)},r.integerValue=function(V){var U=new k(this);return V==null?V=l:xs(V,0,8),Y(U,U.e+1,V)},r.isEqualTo=r.eq=function(V,U){return em(this,new k(V,U))===0},r.isFinite=function(){return!!this.c},r.isGreaterThan=r.gt=function(V,U){return em(this,new k(V,U))>0},r.isGreaterThanOrEqualTo=r.gte=function(V,U){return(U=em(this,new k(V,U)))===1||U===0},r.isInteger=function(){return!!this.c&&Kc(this.e/Nn)>this.c.length-2},r.isLessThan=r.lt=function(V,U){return em(this,new k(V,U))<0},r.isLessThanOrEqualTo=r.lte=function(V,U){return(U=em(this,new k(V,U)))===-1||U===0},r.isNaN=function(){return!this.s},r.isNegative=function(){return this.s<0},r.isPositive=function(){return this.s>0},r.isZero=function(){return!!this.c&&this.c[0]==0},r.minus=function(V,U){var H,W,ne,te,oe=this,X=oe.s;if(V=new k(V,U),U=V.s,!X||!U)return new k(NaN);if(X!=U)return V.s=-U,oe.plus(V);var ee=oe.e/Nn,ae=V.e/Nn,ce=oe.c,de=V.c;if(!ee||!ae){if(!ce||!de)return ce?(V.s=-U,V):new k(de?oe:NaN);if(!ce[0]||!de[0])return de[0]?(V.s=-U,V):new k(ce[0]?oe:l==3?-0:0)}if(ee=Kc(ee),ae=Kc(ae),ce=ce.slice(),X=ee-ae){for((te=X<0)?(X=-X,ne=ce):(ae=ee,ne=de),ne.reverse(),U=X;U--;ne.push(0));ne.reverse()}else for(W=(te=(X=ce.length)<(U=de.length))?X:U,X=U=0;U<W;U++)if(ce[U]!=de[U]){te=ce[U]<de[U];break}if(te&&(ne=ce,ce=de,de=ne,V.s=-V.s),U=(W=de.length)-(H=ce.length),U>0)for(;U--;ce[H++]=0);for(U=Rh-1;W>X;){if(ce[--W]<de[W]){for(H=W;H&&!ce[--H];ce[H]=U);--ce[H],ce[W]+=Rh}ce[W]-=de[W]}for(;ce[0]==0;ce.splice(0,1),--ae);return ce[0]?Z(V,ce,ae):(V.s=l==3?-1:1,V.c=[V.e=0],V)},r.modulo=r.mod=function(V,U){var H,W,ne=this;return V=new k(V,U),!ne.c||!V.s||V.c&&!V.c[0]?new k(NaN):!V.c||ne.c&&!ne.c[0]?new k(ne):(y==9?(W=V.s,V.s=1,H=t(ne,V,0,3),V.s=W,H.s*=W):H=t(ne,V,0,y),V=ne.minus(H.times(V)),!V.c[0]&&y==1&&(V.s=ne.s),V)},r.multipliedBy=r.times=function(V,U){var H,W,ne,te,oe,X,ee,ae,ce,de,pe,Ie,we,Ee,Se,Ve=this,ze=Ve.c,it=(V=new k(V,U)).c;if(!ze||!it||!ze[0]||!it[0])return!Ve.s||!V.s||ze&&!ze[0]&&!it||it&&!it[0]&&!ze?V.c=V.e=V.s=null:(V.s*=Ve.s,!ze||!it?V.c=V.e=null:(V.c=[0],V.e=0)),V;for(W=Kc(Ve.e/Nn)+Kc(V.e/Nn),V.s*=Ve.s,ee=ze.length,de=it.length,ee<de&&(we=ze,ze=it,it=we,ne=ee,ee=de,de=ne),ne=ee+de,we=[];ne--;we.push(0));for(Ee=Rh,Se=np,ne=de;--ne>=0;){for(H=0,pe=it[ne]%Se,Ie=it[ne]/Se|0,oe=ee,te=ne+oe;te>ne;)ae=ze[--oe]%Se,ce=ze[oe]/Se|0,X=Ie*ae+ce*pe,ae=pe*ae+X%Se*Se+we[te]+H,H=(ae/Ee|0)+(X/Se|0)+Ie*ce,we[te--]=ae%Ee;we[te]=H}return H?++W:we.splice(0,1),Z(V,we,W)},r.negated=function(){var V=new k(this);return V.s=-V.s||null,V},r.plus=function(V,U){var H,W=this,ne=W.s;if(V=new k(V,U),U=V.s,!ne||!U)return new k(NaN);if(ne!=U)return V.s=-U,W.minus(V);var te=W.e/Nn,oe=V.e/Nn,X=W.c,ee=V.c;if(!te||!oe){if(!X||!ee)return new k(ne/0);if(!X[0]||!ee[0])return ee[0]?V:new k(X[0]?W:ne*0)}if(te=Kc(te),oe=Kc(oe),X=X.slice(),ne=te-oe){for(ne>0?(oe=te,H=ee):(ne=-ne,H=X),H.reverse();ne--;H.push(0));H.reverse()}for(ne=X.length,U=ee.length,ne-U<0&&(H=ee,ee=X,X=H,U=ne),ne=0;U;)ne=(X[--U]=X[U]+ee[U]+ne)/Rh|0,X[U]=Rh===X[U]?0:X[U]%Rh;return ne&&(X=[ne].concat(X),++oe),Z(V,X,oe)},r.precision=r.sd=function(V,U){var H,W,ne,te=this;if(V!=null&&V!==!!V)return xs(V,1,Fa),U==null?U=l:xs(U,0,8),Y(new k(te),V,U);if(!(H=te.c))return null;if(ne=H.length-1,W=ne*Nn+1,ne=H[ne]){for(;ne%10==0;ne/=10,W--);for(ne=H[0];ne>=10;ne/=10,W++);}return V&&te.e+1>W&&(W=te.e+1),W},r.shiftedBy=function(V){return xs(V,-a8,a8),this.times("1e"+V)},r.squareRoot=r.sqrt=function(){var V,U,H,W,ne,te=this,oe=te.c,X=te.s,ee=te.e,ae=a+4,ce=new k("0.5");if(X!==1||!oe||!oe[0])return new k(!X||X<0&&(!oe||oe[0])?NaN:oe?te:1/0);if(X=Math.sqrt(+Q(te)),X==0||X==1/0?(U=qc(oe),(U.length+ee)%2==0&&(U+="0"),X=Math.sqrt(+U),ee=Kc((ee+1)/2)-(ee<0||ee%2),X==1/0?U="5e"+ee:(U=X.toExponential(),U=U.slice(0,U.indexOf("e")+1)+ee),H=new k(U)):H=new k(X+""),H.c[0]){for(ee=H.e,X=ee+ae,X<3&&(X=0);;)if(ne=H,H=ce.times(ne.plus(t(te,ne,ae,1))),qc(ne.c).slice(0,X)===(U=qc(H.c)).slice(0,X))if(H.e<ee&&--X,U=U.slice(X-3,X+1),U=="9999"||!W&&U=="4999"){if(!W&&(Y(ne,ne.e+a+2,0),ne.times(ne).eq(te))){H=ne;break}ae+=4,X+=4,W=1}else{(!+U||!+U.slice(1)&&U.charAt(0)=="5")&&(Y(H,H.e+a+2,1),V=!H.times(H).eq(te));break}}return Y(H,H.e+a+1,l,V)},r.toExponential=function(V,U){return V!=null&&(xs(V,0,Fa),V++),D(this,V,U,1)},r.toFixed=function(V,U){return V!=null&&(xs(V,0,Fa),V=V+this.e+1),D(this,V,U)},r.toFormat=function(V,U,H){var W,ne=this;if(H==null)V!=null&&U&&typeof U=="object"?(H=U,U=null):V&&typeof V=="object"?(H=V,V=U=null):H=S;else if(typeof H!="object")throw Error(Ol+"Argument not an object: "+H);if(W=ne.toFixed(V,U),ne.c){var te,oe=W.split("."),X=+H.groupSize,ee=+H.secondaryGroupSize,ae=H.groupSeparator||"",ce=oe[0],de=oe[1],pe=ne.s<0,Ie=pe?ce.slice(1):ce,we=Ie.length;if(ee&&(te=X,X=ee,ee=te,we-=te),X>0&&we>0){for(te=we%X||X,ce=Ie.substr(0,te);te<we;te+=X)ce+=ae+Ie.substr(te,X);ee>0&&(ce+=ae+Ie.slice(te)),pe&&(ce="-"+ce)}W=de?ce+(H.decimalSeparator||"")+((ee=+H.fractionGroupSize)?de.replace(new RegExp("\\d{"+ee+"}\\B","g"),"$&"+(H.fractionGroupSeparator||"")):de):ce}return(H.prefix||"")+W+(H.suffix||"")},r.toFraction=function(V){var U,H,W,ne,te,oe,X,ee,ae,ce,de,pe,Ie=this,we=Ie.c;if(V!=null&&(X=new k(V),!X.isInteger()&&(X.c||X.s!==1)||X.lt(s)))throw Error(Ol+"Argument "+(X.isInteger()?"out of range: ":"not an integer: ")+Q(X));if(!we)return new k(Ie);for(U=new k(s),ae=H=new k(s),W=ee=new k(s),pe=qc(we),te=U.e=pe.length-Ie.e-1,U.c[0]=o8[(oe=te%Nn)<0?Nn+oe:oe],V=!V||X.comparedTo(U)>0?te>0?U:ae:X,oe=g,g=1/0,X=new k(pe),ee.c[0]=0;ce=t(X,U,0,1),ne=H.plus(ce.times(W)),ne.comparedTo(V)!=1;)H=W,W=ne,ae=ee.plus(ce.times(ne=ae)),ee=ne,U=X.minus(ce.times(ne=U)),X=ne;return ne=t(V.minus(H),W,0,1),ee=ee.plus(ne.times(ae)),H=H.plus(ne.times(W)),ee.s=ae.s=Ie.s,te=te*2,de=t(ae,W,te,l).minus(Ie).abs().comparedTo(t(ee,H,te,l).minus(Ie).abs())<1?[ae,W]:[ee,H],g=oe,de},r.toNumber=function(){return+Q(this)},r.toPrecision=function(V,U){return V!=null&&xs(V,1,Fa),D(this,V,U,2)},r.toString=function(V){var U,H=this,W=H.s,ne=H.e;return ne===null?W?(U="Infinity",W<0&&(U="-"+U)):U="NaN":(V==null?U=ne<=h||ne>=d?SE(qc(H.c),ne):kd(qc(H.c),ne,"0"):V===10&&I?(H=Y(new k(H),a+ne+1,l),U=kd(qc(H.c),H.e,"0")):(xs(V,2,R.length,"Base"),U=i(kd(qc(H.c),ne,"0"),10,V,W,!0)),W<0&&H.c[0]&&(U="-"+U)),U},r.valueOf=r.toJSON=function(){return Q(this)},r._isBigNumber=!0,r[Symbol.toStringTag]="BigNumber",r[Symbol.for("nodejs.util.inspect.custom")]=r.valueOf,e!=null&&k.set(e),k}function Kc(e){var t=e|0;return e>0||e===t?t:t-1}function qc(e){for(var t,i,n=1,r=e.length,s=e[0]+"";n<r;){for(t=e[n++]+"",i=Nn-t.length;i--;t="0"+t);s+=t}for(r=s.length;s.charCodeAt(--r)===48;);return s.slice(0,r+1||1)}function em(e,t){var i,n,r=e.c,s=t.c,a=e.s,l=t.s,h=e.e,d=t.e;if(!a||!l)return null;if(i=r&&!r[0],n=s&&!s[0],i||n)return i?n?0:-l:a;if(a!=l)return a;if(i=a<0,n=h==d,!r||!s)return n?0:!r^i?1:-1;if(!n)return h>d^i?1:-1;for(l=(h=r.length)<(d=s.length)?h:d,a=0;a<l;a++)if(r[a]!=s[a])return r[a]>s[a]^i?1:-1;return h==d?0:h>d^i?1:-1}function xs(e,t,i,n){if(e<t||e>i||e!==Jc(e))throw Error(Ol+(n||"Argument")+(typeof e=="number"?e<t||e>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function EE(e){var t=e.c.length-1;return Kc(e.e/Nn)==t&&e.c[t]%2!=0}function SE(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function kd(e,t,i){var n,r;if(t<0){for(r=i+".";++t;r+=i);e=r+e}else if(n=e.length,++t>n){for(r=i,t-=n;--t;r+=i);e+=r}else t<n&&(e=e.slice(0,t)+"."+e.slice(t));return e}var Du=uJ(),aue=class{key;left=null;right=null;constructor(e){this.key=e}},Zy=class extends aue{constructor(e){super(e)}},oue=class{size=0;modificationCount=0;splayCount=0;splay(e){const t=this.root;if(t==null)return this.compare(e,e),-1;let i=null,n=null,r=null,s=null,a=t;const l=this.compare;let h;for(;;)if(h=l(a.key,e),h>0){let d=a.left;if(d==null||(h=l(d.key,e),h>0&&(a.left=d.right,d.right=a,a=d,d=a.left,d==null)))break;i==null?n=a:i.left=a,i=a,a=d}else if(h<0){let d=a.right;if(d==null||(h=l(d.key,e),h<0&&(a.right=d.left,d.left=a,a=d,d=a.right,d==null)))break;r==null?s=a:r.right=a,r=a,a=d}else break;return r!=null&&(r.right=a.left,a.left=s),i!=null&&(i.left=a.right,a.right=n),this.root!==a&&(this.root=a,this.splayCount++),h}splayMin(e){let t=e,i=t.left;for(;i!=null;){const n=i;t.left=n.right,n.right=t,t=n,i=t.left}return t}splayMax(e){let t=e,i=t.right;for(;i!=null;){const n=i;t.right=n.left,n.left=t,t=n,i=t.right}return t}_delete(e){if(this.root==null||this.splay(e)!=0)return null;let t=this.root;const i=t,n=t.left;if(this.size--,n==null)this.root=t.right;else{const r=t.right;t=this.splayMax(n),t.right=r,this.root=t}return this.modificationCount++,i}addNewRoot(e,t){this.size++,this.modificationCount++;const i=this.root;if(i==null){this.root=e;return}t<0?(e.left=i,e.right=i.right,i.right=null):(e.right=i,e.left=i.left,i.left=null),this.root=e}_first(){const e=this.root;return e==null?null:(this.root=this.splayMin(e),this.root)}_last(){const e=this.root;return e==null?null:(this.root=this.splayMax(e),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(e){return this.validKey(e)&&this.splay(e)==0}defaultCompare(){return(e,t)=>e<t?-1:e>t?1:0}wrap(){return{getRoot:()=>this.root,setRoot:e=>{this.root=e},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:e=>{this.splayCount=e},splay:e=>this.splay(e),has:e=>this.has(e)}}},yI=class W1 extends oue{root=null;compare;validKey;constructor(t,i){super(),this.compare=t??this.defaultCompare(),this.validKey=i??(n=>n!=null&&n!=null)}delete(t){return this.validKey(t)?this._delete(t)!=null:!1}deleteAll(t){for(const i of t)this.delete(i)}forEach(t){const i=this[Symbol.iterator]();let n;for(;n=i.next(),!n.done;)t(n.value,n.value,this)}add(t){const i=this.splay(t);return i!=0&&this.addNewRoot(new Zy(t),i),this}addAndReturn(t){const i=this.splay(t);return i!=0&&this.addNewRoot(new Zy(t),i),this.root.key}addAll(t){for(const i of t)this.add(i)}isEmpty(){return this.root==null}isNotEmpty(){return this.root!=null}single(){if(this.size==0)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(this.size==0)throw"Bad state: No element";return this._first().key}last(){if(this.size==0)throw"Bad state: No element";return this._last().key}lastBefore(t){if(t==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(t)<0)return this.root.key;let i=this.root.left;if(i==null)return null;let n=i.right;for(;n!=null;)i=n,n=i.right;return i.key}firstAfter(t){if(t==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(t)>0)return this.root.key;let i=this.root.right;if(i==null)return null;let n=i.left;for(;n!=null;)i=n,n=i.left;return i.key}retainAll(t){const i=new W1(this.compare,this.validKey),n=this.modificationCount;for(const r of t){if(n!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(r)&&this.splay(r)==0&&i.add(this.root.key)}i.size!=this.size&&(this.root=i.root,this.size=i.size,this.modificationCount++)}lookup(t){return!this.validKey(t)||this.splay(t)!=0?null:this.root.key}intersection(t){const i=new W1(this.compare,this.validKey);for(const n of this)t.has(n)&&i.add(n);return i}difference(t){const i=new W1(this.compare,this.validKey);for(const n of this)t.has(n)||i.add(n);return i}union(t){const i=this.clone();return i.addAll(t),i}clone(){const t=new W1(this.compare,this.validKey);return t.size=this.size,t.root=this.copyNode(this.root),t}copyNode(t){if(t==null)return null;function i(r,s){let a,l;do{if(a=r.left,l=r.right,a!=null){const h=new Zy(a.key);s.left=h,i(a,h)}if(l!=null){const h=new Zy(l.key);s.right=h,r=l,s=h}}while(l!=null)}const n=new Zy(t.key);return i(t,n),n}toSet(){return this.clone()}entries(){return new cue(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new lue(this.wrap())}[Symbol.toStringTag]="[object Set]"},dJ=class{tree;path=new Array;modificationCount=null;splayCount;constructor(e){this.tree=e,this.splayCount=e.getSplayCount()}[Symbol.iterator](){return this}next(){return this.moveNext()?{done:!1,value:this.current()}:{done:!0,value:null}}current(){if(!this.path.length)return null;const e=this.path[this.path.length-1];return this.getValue(e)}rebuildPath(e){this.path.splice(0,this.path.length),this.tree.splay(e),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(e){for(;e!=null;)this.path.push(e),e=e.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(this.modificationCount==null){this.modificationCount=this.tree.getModificationCount();let i=this.tree.getRoot();for(;i!=null;)this.path.push(i),i=i.left;return this.path.length>0}throw"Concurrent modification during iteration."}if(!this.path.length)return!1;this.splayCount!=this.tree.getSplayCount()&&this.rebuildPath(this.path[this.path.length-1].key);let e=this.path[this.path.length-1],t=e.right;if(t!=null){for(;t!=null;)this.path.push(t),t=t.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===e;)e=this.path.pop();return this.path.length>0}},lue=class extends dJ{getValue(e){return e.key}},cue=class extends dJ{getValue(e){return[e.key,e.key]}},fJ=e=>()=>e,m6=e=>{const t=e?(i,n)=>n.minus(i).abs().isLessThanOrEqualTo(e):fJ(!1);return(i,n)=>t(i,n)?0:i.comparedTo(n)};function hue(e){const t=e?(i,n,r,s,a)=>i.exponentiatedBy(2).isLessThanOrEqualTo(s.minus(n).exponentiatedBy(2).plus(a.minus(r).exponentiatedBy(2)).times(e)):fJ(!1);return(i,n,r)=>{const s=i.x,a=i.y,l=r.x,h=r.y,d=a.minus(h).times(n.x.minus(l)).minus(s.minus(l).times(n.y.minus(h)));return t(d,s,a,l,h)?0:d.comparedTo(0)}}var uue=e=>e,due=e=>{if(e){const t=new yI(m6(e)),i=new yI(m6(e)),n=(s,a)=>a.addAndReturn(s),r=s=>({x:n(s.x,t),y:n(s.y,i)});return r({x:new Du(0),y:new Du(0)}),r}return uue},g6=e=>({set:t=>{yf=g6(t)},reset:()=>g6(e),compare:m6(e),snap:due(e),orient:hue(e)}),yf=g6(),qy=(e,t)=>e.ll.x.isLessThanOrEqualTo(t.x)&&t.x.isLessThanOrEqualTo(e.ur.x)&&e.ll.y.isLessThanOrEqualTo(t.y)&&t.y.isLessThanOrEqualTo(e.ur.y),_6=(e,t)=>{if(t.ur.x.isLessThan(e.ll.x)||e.ur.x.isLessThan(t.ll.x)||t.ur.y.isLessThan(e.ll.y)||e.ur.y.isLessThan(t.ll.y))return null;const i=e.ll.x.isLessThan(t.ll.x)?t.ll.x:e.ll.x,n=e.ur.x.isLessThan(t.ur.x)?e.ur.x:t.ur.x,r=e.ll.y.isLessThan(t.ll.y)?t.ll.y:e.ll.y,s=e.ur.y.isLessThan(t.ur.y)?e.ur.y:t.ur.y;return{ll:{x:i,y:r},ur:{x:n,y:s}}},TM=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),pJ=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),bI=e=>pJ(e,e).sqrt(),fue=(e,t,i)=>{const n={x:t.x.minus(e.x),y:t.y.minus(e.y)},r={x:i.x.minus(e.x),y:i.y.minus(e.y)};return TM(r,n).div(bI(r)).div(bI(n))},pue=(e,t,i)=>{const n={x:t.x.minus(e.x),y:t.y.minus(e.y)},r={x:i.x.minus(e.x),y:i.y.minus(e.y)};return pJ(r,n).div(bI(r)).div(bI(n))},_$=(e,t,i)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(i.minus(e.y))),y:i},A$=(e,t,i)=>t.x.isZero()?null:{x:i,y:e.y.plus(t.y.div(t.x).times(i.minus(e.x)))},mue=(e,t,i,n)=>{if(t.x.isZero())return A$(i,n,e.x);if(n.x.isZero())return A$(e,t,i.x);if(t.y.isZero())return _$(i,n,e.y);if(n.y.isZero())return _$(e,t,i.y);const r=TM(t,n);if(r.isZero())return null;const s={x:i.x.minus(e.x),y:i.y.minus(e.y)},a=TM(s,t).div(r),l=TM(s,n).div(r),h=e.x.plus(l.times(t.x)),d=i.x.plus(a.times(n.x)),p=e.y.plus(l.times(t.y)),g=i.y.plus(a.times(n.y));return{x:h.plus(d).div(2),y:p.plus(g).div(2)}},Tu=class mJ{point;isLeft;segment;otherSE;consumedBy;static compare(t,i){const n=mJ.comparePoints(t.point,i.point);return n!==0?n:(t.point!==i.point&&t.link(i),t.isLeft!==i.isLeft?t.isLeft?1:-1:xI.compare(t.segment,i.segment))}static comparePoints(t,i){return t.x.isLessThan(i.x)?-1:t.x.isGreaterThan(i.x)?1:t.y.isLessThan(i.y)?-1:t.y.isGreaterThan(i.y)?1:0}constructor(t,i){t.events===void 0?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=i}link(t){if(t.point===this.point)throw new Error("Tried to link already linked events");const i=t.point.events;for(let n=0,r=i.length;n<r;n++){const s=i[n];this.point.events.push(s),s.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let i=0;i<t;i++){const n=this.point.events[i];if(n.segment.consumedBy===void 0)for(let r=i+1;r<t;r++){const s=this.point.events[r];s.consumedBy===void 0&&n.otherSE.point.events===s.otherSE.point.events&&n.segment.consume(s.segment)}}}getAvailableLinkedEvents(){const t=[];for(let i=0,n=this.point.events.length;i<n;i++){const r=this.point.events[i];r!==this&&!r.segment.ringOut&&r.segment.isInResult()&&t.push(r)}return t}getLeftmostComparator(t){const i=new Map,n=r=>{const s=r.otherSE;i.set(r,{sine:fue(this.point,t.point,s.point),cosine:pue(this.point,t.point,s.point)})};return(r,s)=>{i.has(r)||n(r),i.has(s)||n(s);const{sine:a,cosine:l}=i.get(r),{sine:h,cosine:d}=i.get(s);return a.isGreaterThanOrEqualTo(0)&&h.isGreaterThanOrEqualTo(0)?l.isLessThan(d)?1:l.isGreaterThan(d)?-1:0:a.isLessThan(0)&&h.isLessThan(0)?l.isLessThan(d)?-1:l.isGreaterThan(d)?1:0:h.isLessThan(a)?-1:h.isGreaterThan(a)?1:0}}},gue=class A6{events;poly;_isExteriorRing;_enclosingRing;static factory(t){const i=[];for(let n=0,r=t.length;n<r;n++){const s=t[n];if(!s.isInResult()||s.ringOut)continue;let a=null,l=s.leftSE,h=s.rightSE;const d=[l],p=l.point,g=[];for(;a=l,l=h,d.push(l),l.point!==p;)for(;;){const v=l.getAvailableLinkedEvents();if(v.length===0){const S=d[0].point,R=d[d.length-1].point;throw new Error(`Unable to complete output ring starting at [${S.x}, ${S.y}]. Last matching segment found ends at [${R.x}, ${R.y}].`)}if(v.length===1){h=v[0].otherSE;break}let y=null;for(let S=0,R=g.length;S<R;S++)if(g[S].point===l.point){y=S;break}if(y!==null){const S=g.splice(y)[0],R=d.splice(S.index);R.unshift(R[0].otherSE),i.push(new A6(R.reverse()));continue}g.push({index:d.length,point:l.point});const E=l.getLeftmostComparator(a);h=v.sort(E)[0].otherSE;break}i.push(new A6(d))}return i}constructor(t){this.events=t;for(let i=0,n=t.length;i<n;i++)t[i].segment.ringOut=this;this.poly=null}getGeom(){let t=this.events[0].point;const i=[t];for(let d=1,p=this.events.length-1;d<p;d++){const g=this.events[d].point,v=this.events[d+1].point;yf.orient(g,t,v)!==0&&(i.push(g),t=g)}if(i.length===1)return null;const n=i[0],r=i[1];yf.orient(n,t,r)===0&&i.shift(),i.push(i[0]);const s=this.isExteriorRing()?1:-1,a=this.isExteriorRing()?0:i.length-1,l=this.isExteriorRing()?i.length:-1,h=[];for(let d=a;d!=l;d+=s)h.push([i[d].x.toNumber(),i[d].y.toNumber()]);return h}isExteriorRing(){if(this._isExteriorRing===void 0){const t=this.enclosingRing();this._isExteriorRing=t?!t.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let t=this.events[0];for(let r=1,s=this.events.length;r<s;r++){const a=this.events[r];Tu.compare(t,a)>0&&(t=a)}let i=t.segment.prevInResult(),n=i?i.prevInResult():null;for(;;){if(!i)return null;if(!n)return i.ringOut;if(n.ringOut!==i.ringOut)return n.ringOut?.enclosingRing()!==i.ringOut?i.ringOut:i.ringOut?.enclosingRing();i=n.prevInResult(),n=i?i.prevInResult():null}}},v$=class{exteriorRing;interiorRings;constructor(e){this.exteriorRing=e,e.poly=this,this.interiorRings=[]}addInterior(e){this.interiorRings.push(e),e.poly=this}getGeom(){const e=this.exteriorRing.getGeom();if(e===null)return null;const t=[e];for(let i=0,n=this.interiorRings.length;i<n;i++){const r=this.interiorRings[i].getGeom();r!==null&&t.push(r)}return t}},_ue=class{rings;polys;constructor(e){this.rings=e,this.polys=this._composePolys(e)}getGeom(){const e=[];for(let t=0,i=this.polys.length;t<i;t++){const n=this.polys[t].getGeom();n!==null&&e.push(n)}return e}_composePolys(e){const t=[];for(let i=0,n=e.length;i<n;i++){const r=e[i];if(!r.poly)if(r.isExteriorRing())t.push(new v$(r));else{const s=r.enclosingRing();s?.poly||t.push(new v$(s)),s?.poly?.addInterior(r)}}return t}},Aue=class{queue;tree;segments;constructor(e,t=xI.compare){this.queue=e,this.tree=new yI(t),this.segments=[]}process(e){const t=e.segment,i=[];if(e.consumedBy)return e.isLeft?this.queue.delete(e.otherSE):this.tree.delete(t),i;e.isLeft&&this.tree.add(t);let n=t,r=t;do n=this.tree.lastBefore(n);while(n!=null&&n.consumedBy!=null);do r=this.tree.firstAfter(r);while(r!=null&&r.consumedBy!=null);if(e.isLeft){let s=null;if(n){const l=n.getIntersection(t);if(l!==null&&(t.isAnEndpoint(l)||(s=l),!n.isAnEndpoint(l))){const h=this._splitSafely(n,l);for(let d=0,p=h.length;d<p;d++)i.push(h[d])}}let a=null;if(r){const l=r.getIntersection(t);if(l!==null&&(t.isAnEndpoint(l)||(a=l),!r.isAnEndpoint(l))){const h=this._splitSafely(r,l);for(let d=0,p=h.length;d<p;d++)i.push(h[d])}}if(s!==null||a!==null){let l=null;s===null?l=a:a===null?l=s:l=Tu.comparePoints(s,a)<=0?s:a,this.queue.delete(t.rightSE),i.push(t.rightSE);const h=t.split(l);for(let d=0,p=h.length;d<p;d++)i.push(h[d])}i.length>0?(this.tree.delete(t),i.push(e)):(this.segments.push(t),t.prev=n)}else{if(n&&r){const s=n.getIntersection(r);if(s!==null){if(!n.isAnEndpoint(s)){const a=this._splitSafely(n,s);for(let l=0,h=a.length;l<h;l++)i.push(a[l])}if(!r.isAnEndpoint(s)){const a=this._splitSafely(r,s);for(let l=0,h=a.length;l<h;l++)i.push(a[l])}}}this.tree.delete(t)}return i}_splitSafely(e,t){this.tree.delete(e);const i=e.rightSE;this.queue.delete(i);const n=e.split(t);return n.push(i),e.consumedBy===void 0&&this.tree.add(e),n}},vue=class{type;numMultiPolys;run(e,t,i){X1.type=e;const n=[new b$(t,!0)];for(let l=0,h=i.length;l<h;l++)n.push(new b$(i[l],!1));if(X1.numMultiPolys=n.length,X1.type==="difference"){const l=n[0];let h=1;for(;h<n.length;)_6(n[h].bbox,l.bbox)!==null?h++:n.splice(h,1)}if(X1.type==="intersection")for(let l=0,h=n.length;l<h;l++){const d=n[l];for(let p=l+1,g=n.length;p<g;p++)if(_6(d.bbox,n[p].bbox)===null)return[]}const r=new yI(Tu.compare);for(let l=0,h=n.length;l<h;l++){const d=n[l].getSweepEvents();for(let p=0,g=d.length;p<g;p++)r.add(d[p])}const s=new Aue(r);let a=null;for(r.size!=0&&(a=r.first(),r.delete(a));a;){const l=s.process(a);for(let h=0,d=l.length;h<d;h++){const p=l[h];p.consumedBy===void 0&&r.add(p)}r.size!=0?(a=r.first(),r.delete(a)):a=null}return yf.reset(),new _ue(gue.factory(s.segments)).getGeom()}},X1=new vue,Jb=X1,yue=0,xI=class RM{id;leftSE;rightSE;rings;windings;ringOut;consumedBy;prev;_prevInResult;_beforeState;_afterState;_isInResult;static compare(t,i){const n=t.leftSE.point.x,r=i.leftSE.point.x,s=t.rightSE.point.x,a=i.rightSE.point.x;if(a.isLessThan(n))return 1;if(s.isLessThan(r))return-1;const l=t.leftSE.point.y,h=i.leftSE.point.y,d=t.rightSE.point.y,p=i.rightSE.point.y;if(n.isLessThan(r)){if(h.isLessThan(l)&&h.isLessThan(d))return 1;if(h.isGreaterThan(l)&&h.isGreaterThan(d))return-1;const g=t.comparePoint(i.leftSE.point);if(g<0)return 1;if(g>0)return-1;const v=i.comparePoint(t.rightSE.point);return v!==0?v:-1}if(n.isGreaterThan(r)){if(l.isLessThan(h)&&l.isLessThan(p))return-1;if(l.isGreaterThan(h)&&l.isGreaterThan(p))return 1;const g=i.comparePoint(t.leftSE.point);if(g!==0)return g;const v=t.comparePoint(i.rightSE.point);return v<0?1:v>0?-1:1}if(l.isLessThan(h))return-1;if(l.isGreaterThan(h))return 1;if(s.isLessThan(a)){const g=i.comparePoint(t.rightSE.point);if(g!==0)return g}if(s.isGreaterThan(a)){const g=t.comparePoint(i.rightSE.point);if(g<0)return 1;if(g>0)return-1}if(!s.eq(a)){const g=d.minus(l),v=s.minus(n),y=p.minus(h),E=a.minus(r);if(g.isGreaterThan(v)&&y.isLessThan(E))return 1;if(g.isLessThan(v)&&y.isGreaterThan(E))return-1}return s.isGreaterThan(a)?1:s.isLessThan(a)||d.isLessThan(p)?-1:d.isGreaterThan(p)?1:t.id<i.id?-1:t.id>i.id?1:0}constructor(t,i,n,r){this.id=++yue,this.leftSE=t,t.segment=this,t.otherSE=i,this.rightSE=i,i.segment=this,i.otherSE=t,this.rings=n,this.windings=r}static fromRing(t,i,n){let r,s,a;const l=Tu.comparePoints(t,i);if(l<0)r=t,s=i,a=1;else if(l>0)r=i,s=t,a=-1;else throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);return new RM(new Tu(r,!0),new Tu(s,!1),[n],[a])}replaceRightSE(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const t=this.leftSE.point.y,i=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t.isLessThan(i)?t:i},ur:{x:this.rightSE.point.x,y:t.isGreaterThan(i)?t:i}}}vector(){return{x:this.rightSE.point.x.minus(this.leftSE.point.x),y:this.rightSE.point.y.minus(this.leftSE.point.y)}}isAnEndpoint(t){return t.x.eq(this.leftSE.point.x)&&t.y.eq(this.leftSE.point.y)||t.x.eq(this.rightSE.point.x)&&t.y.eq(this.rightSE.point.y)}comparePoint(t){return yf.orient(this.leftSE.point,t,this.rightSE.point)}getIntersection(t){const i=this.bbox(),n=t.bbox(),r=_6(i,n);if(r===null)return null;const s=this.leftSE.point,a=this.rightSE.point,l=t.leftSE.point,h=t.rightSE.point,d=qy(i,l)&&this.comparePoint(l)===0,p=qy(n,s)&&t.comparePoint(s)===0,g=qy(i,h)&&this.comparePoint(h)===0,v=qy(n,a)&&t.comparePoint(a)===0;if(p&&d)return v&&!g?a:!v&&g?h:null;if(p)return g&&s.x.eq(h.x)&&s.y.eq(h.y)?null:s;if(d)return v&&a.x.eq(l.x)&&a.y.eq(l.y)?null:l;if(v&&g)return null;if(v)return a;if(g)return h;const y=mue(s,this.vector(),l,t.vector());return y===null||!qy(r,y)?null:yf.snap(y)}split(t){const i=[],n=t.events!==void 0,r=new Tu(t,!0),s=new Tu(t,!1),a=this.rightSE;this.replaceRightSE(s),i.push(s),i.push(r);const l=new RM(r,a,this.rings.slice(),this.windings.slice());return Tu.comparePoints(l.leftSE.point,l.rightSE.point)>0&&l.swapEvents(),Tu.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),s.checkForConsuming()),i}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let i=0,n=this.windings.length;i<n;i++)this.windings[i]*=-1}consume(t){let i=this,n=t;for(;i.consumedBy;)i=i.consumedBy;for(;n.consumedBy;)n=n.consumedBy;const r=RM.compare(i,n);if(r!==0){if(r>0){const s=i;i=n,n=s}if(i.prev===n){const s=i;i=n,n=s}for(let s=0,a=n.rings.length;s<a;s++){const l=n.rings[s],h=n.windings[s],d=i.rings.indexOf(l);d===-1?(i.rings.push(l),i.windings.push(h)):i.windings[d]+=h}n.rings=null,n.windings=null,n.consumedBy=i,n.leftSE.consumedBy=i.leftSE,n.rightSE.consumedBy=i.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;const t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};const i=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let l=0,h=this.rings.length;l<h;l++){const d=this.rings[l],p=this.windings[l],g=i.indexOf(d);g===-1?(i.push(d),n.push(p)):n[g]+=p}const s=[],a=[];for(let l=0,h=i.length;l<h;l++){if(n[l]===0)continue;const d=i[l],p=d.poly;if(a.indexOf(p)===-1)if(d.isExterior)s.push(p);else{a.indexOf(p)===-1&&a.push(p);const g=s.indexOf(d.poly);g!==-1&&s.splice(g,1)}}for(let l=0,h=s.length;l<h;l++){const d=s[l].multiPoly;r.indexOf(d)===-1&&r.push(d)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;const t=this.beforeState().multiPolys,i=this.afterState().multiPolys;switch(Jb.type){case"union":{const n=t.length===0,r=i.length===0;this._isInResult=n!==r;break}case"intersection":{let n,r;t.length<i.length?(n=t.length,r=i.length):(n=i.length,r=t.length),this._isInResult=r===Jb.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(t.length-i.length);this._isInResult=n%2===1;break}case"difference":{const n=r=>r.length===1&&r[0].isSubject;this._isInResult=n(t)!==n(i);break}}return this._isInResult}},y$=class{poly;isExterior;segments;bbox;constructor(e,t,i){if(!Array.isArray(e)||e.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=t,this.isExterior=i,this.segments=[],typeof e[0][0]!="number"||typeof e[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const n=yf.snap({x:new Du(e[0][0]),y:new Du(e[0][1])});this.bbox={ll:{x:n.x,y:n.y},ur:{x:n.x,y:n.y}};let r=n;for(let s=1,a=e.length;s<a;s++){if(typeof e[s][0]!="number"||typeof e[s][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const l=yf.snap({x:new Du(e[s][0]),y:new Du(e[s][1])});l.x.eq(r.x)&&l.y.eq(r.y)||(this.segments.push(xI.fromRing(r,l,this)),l.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=l.x),l.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=l.y),l.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=l.x),l.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=l.y),r=l)}(!n.x.eq(r.x)||!n.y.eq(r.y))&&this.segments.push(xI.fromRing(r,n,this))}getSweepEvents(){const e=[];for(let t=0,i=this.segments.length;t<i;t++){const n=this.segments[t];e.push(n.leftSE),e.push(n.rightSE)}return e}},bue=class{multiPoly;exteriorRing;interiorRings;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new y$(e[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let i=1,n=e.length;i<n;i++){const r=new y$(e[i],this,!1);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.interiorRings.push(r)}this.multiPoly=t}getSweepEvents(){const e=this.exteriorRing.getSweepEvents();for(let t=0,i=this.interiorRings.length;t<i;t++){const n=this.interiorRings[t].getSweepEvents();for(let r=0,s=n.length;r<s;r++)e.push(n[r])}return e}},b$=class{isSubject;polys;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof e[0][0][0]=="number"&&(e=[e])}catch{}this.polys=[],this.bbox={ll:{x:new Du(Number.POSITIVE_INFINITY),y:new Du(Number.POSITIVE_INFINITY)},ur:{x:new Du(Number.NEGATIVE_INFINITY),y:new Du(Number.NEGATIVE_INFINITY)}};for(let i=0,n=e.length;i<n;i++){const r=new bue(e[i],this);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.polys.push(r)}this.isSubject=t}getSweepEvents(){const e=[];for(let t=0,i=this.polys.length;t<i;t++){const n=this.polys[t].getSweepEvents();for(let r=0,s=n.length;r<s;r++)e.push(n[r])}return e}},xue=(e,...t)=>Jb.run("union",e,t),wue=(e,...t)=>Jb.run("intersection",e,t),Cue=(e,...t)=>Jb.run("difference",e,t);yf.set;function gJ(e){const t=[];if(f0(e,r=>{t.push(r.coordinates)}),t.length<2)throw new Error("Must have at least two features");const i=e.features[0].properties||{},n=Cue(t[0],...t.slice(1));return n.length===0?null:n.length===1?ph(n[0],i):RT(n,i)}function Eue(e,t,i={}){const n=oa(e),r=oa(t);return r[0]+=r[0]-n[0]>180?-360:n[0]-r[0]>180?360:0,Rj(Sue(n,r),"meters",i.units)}function Sue(e,t,i){i=i===void 0?Ua:Number(i);const n=i,r=e[1]*Math.PI/180,s=t[1]*Math.PI/180,a=s-r;let l=Math.abs(t[0]-e[0])*Math.PI/180;l>Math.PI&&(l-=2*Math.PI);const h=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),d=Math.abs(h)>1e-11?a/h:Math.cos(r);return Math.sqrt(a*a+d*d*l*l)*n}function _J(e,t,i,n={}){const r=t<0;let s=Rj(Math.abs(t),n.units,"meters");r&&(s=-Math.abs(s));const a=oa(e),l=Mue(a,s,i);return l[0]+=l[0]-a[0]>180?-360:a[0]-l[0]>180?360:0,aa(l,n.properties)}function Mue(e,t,i,n){n=n===void 0?Ua:Number(n);const r=t/n,s=e[0]*Math.PI/180,a=pl(e[1]),l=pl(i),h=r*Math.cos(l);let d=a+h;Math.abs(d)>Math.PI/2&&(d=d>0?Math.PI-d:-Math.PI-d);const p=Math.log(Math.tan(d/2+Math.PI/4)/Math.tan(a/2+Math.PI/4)),g=Math.abs(p)>1e-11?h/p:Math.cos(a);return[((s+r*Math.sin(l)/g)*180/Math.PI+540)%360-180,d*180/Math.PI]}function Iue(e,t={}){const i=[];if(f0(e,r=>{i.push(r.coordinates)}),i.length<2)throw new Error("Must specify at least 2 geometries");const n=wue(i[0],...i.slice(1));return n.length===0?null:n.length===1?ph(n[0],t.properties):RT(n,t.properties)}function Tue(e,t,i){if(i=i||{},!$x(i))throw new Error("options is invalid");const n=i.origin||"centroid",r=i.mutate||!1;if(!e)throw new Error("geojson required");if(typeof t!="number"||t<=0)throw new Error("invalid factor");const s=Array.isArray(n)||typeof n=="object";return r!==!0&&(e=Go(e)),e.type==="FeatureCollection"&&!s?(Af(e,function(a,l){e.features[l]=x$(a,t,n)}),e):x$(e,t,n)}function x$(e,t,i){const n=dI(e)==="Point",r=Rue(e,i);return t===1||n||(d0(e,function(s){const a=Eue(r,s),l=jle(r,s),h=ho(_J(r,a*t,l));s[0]=h[0],s[1]=h[1],s.length===3&&(s[2]*=t)}),delete e.bbox),e}function Rue(e,t){if(t==null&&(t="centroid"),Array.isArray(t)||typeof t=="object")return oa(t);const i=e.bbox?e.bbox:As(e,{recompute:!0}),n=i[0],r=i[1],s=i[2],a=i[3];switch(t){case"sw":case"southwest":case"westsouth":case"bottomleft":return aa([n,r]);case"se":case"southeast":case"eastsouth":case"bottomright":return aa([s,r]);case"nw":case"northwest":case"westnorth":case"topleft":return aa([n,a]);case"ne":case"northeast":case"eastnorth":case"topright":return aa([s,a]);case"center":return Wj(e);case void 0:case null:case"centroid":return jb(e);default:throw new Error("invalid origin")}}function Bue(e,t){var i=e[0]-t[0],n=e[1]-t[1];return i*i+n*n}function Lue(e,t,i){var n=t[0],r=t[1],s=i[0]-n,a=i[1]-r;if(s!==0||a!==0){var l=((e[0]-n)*s+(e[1]-r)*a)/(s*s+a*a);l>1?(n=i[0],r=i[1]):l>0&&(n+=s*l,r+=a*l)}return s=e[0]-n,a=e[1]-r,s*s+a*a}function kue(e,t){for(var i=e[0],n=[i],r,s=1,a=e.length;s<a;s++)r=e[s],Bue(r,i)>t&&(n.push(r),i=r);return i!==r&&n.push(r),n}function v6(e,t,i,n,r){for(var s=n,a,l=t+1;l<i;l++){var h=Lue(e[l],e[t],e[i]);h>s&&(a=l,s=h)}s>n&&(a-t>1&&v6(e,t,a,n,r),r.push(e[a]),i-a>1&&v6(e,a,i,n,r))}function Pue(e,t){var i=e.length-1,n=[e[0]];return v6(e,0,i,t,n),n.push(e[i]),n}function wI(e,t,i){if(e.length<=2)return e;var n=t!==void 0?t*t:1;return e=i?e:kue(e,n),e=Pue(e,n),e}function y6(e,t={}){var i,n,r;if(t=t??{},!$x(t))throw new Error("options is invalid");const s=(i=t.tolerance)!=null?i:1,a=(n=t.highQuality)!=null?n:!1,l=(r=t.mutate)!=null?r:!1;if(!e)throw new Error("geojson is required");if(s&&s<0)throw new Error("invalid tolerance");return l!==!0&&(e=Go(e)),f0(e,function(h){Nue(h,s,a)}),e}function Nue(e,t,i){const n=e.type;if(n==="Point"||n==="MultiPoint")return e;if(zj(e,{mutate:!0}),n!=="GeometryCollection")switch(n){case"LineString":e.coordinates=wI(e.coordinates,t,i);break;case"MultiLineString":e.coordinates=e.coordinates.map(r=>wI(r,t,i));break;case"Polygon":e.coordinates=w$(e.coordinates,t,i);break;case"MultiPolygon":e.coordinates=e.coordinates.map(r=>w$(r,t,i))}return e}function w$(e,t,i){return e.map(function(n){if(n.length<4)throw new Error("invalid polygon");let r=t,s=wI(n,r,i);for(;!C$(s)&&r>=Number.EPSILON;)r-=r*.01,s=wI(n,r,i);return C$(s)?((s[s.length-1][0]!==s[0][0]||s[s.length-1][1]!==s[0][1])&&s.push(s[0]),s):n})}function C$(e){return e.length<3?!1:!(e.length===3&&e[2][0]===e[0][0]&&e[2][1]===e[0][1])}function b6(e,t,i,n){if(n=n||{},!$x(n))throw new Error("options is invalid");var r=n.units,s=n.zTranslation,a=n.mutate;if(!e)throw new Error("geojson is required");if(t==null||isNaN(t))throw new Error("distance is required");if(s&&typeof s!="number"&&isNaN(s))throw new Error("zTranslation is not a number");if(s=s!==void 0?s:0,t===0&&s===0)return e;if(i==null||isNaN(i))throw new Error("direction is required");return t<0&&(t=-t,i=i+180),(a===!1||a===void 0)&&(e=Go(e)),d0(e,function(l){var h=ho(_J(l,t,i,{units:r}));l[0]=h[0],l[1]=h[1],s&&l.length===3&&(l[2]+=s)}),e}function Fue(e,t={}){const i=[];if(f0(e,r=>{i.push(r.coordinates)}),i.length<2)throw new Error("Must have at least 2 geometries");const n=xue(i[0],...i.slice(1));return n.length===0?null:n.length===1?ph(n[0],t.properties):RT(n,t.properties)}function Due(e,t){if(e.geometry.type!=="Polygon")throw new Error("The input feature must be a Polygon");for(var i=e.geometry.coordinates,n=[],r={},s=[],a=0;a<i.length;a++)for(var l=0;l<i[a].length-1;l++)s.push(v(a,l));var h=new jG;h.load(s);for(var d=0;d<i.length;d++)for(var p=0;p<i[d].length-1;p++)h.search(v(d,p)).forEach(function(y){var E=y.ring,S=y.edge;g(d,p,E,S)});return n;function g(y,E,S,R){var I=i[y][E],k=i[y][E+1],D=i[S][R],F=i[S][R+1],Z=Oue(I,k,D,F);if(Z!==null){var Y,Q;if(k[0]!==I[0]?Y=(Z[0]-I[0])/(k[0]-I[0]):Y=(Z[1]-I[1])/(k[1]-I[1]),F[0]!==D[0]?Q=(Z[0]-D[0])/(F[0]-D[0]):Q=(Z[1]-D[1])/(F[1]-D[1]),!(Y>=1||Y<=0||Q>=1||Q<=0)){var V=Z,U=!r[V.toString()];U&&(r[V.toString()]=!0),t&&n.push(t(Z,y,E,I,k,Y,S,R,D,F,Q,U))}}}function v(y,E){var S=i[y][E],R=i[y][E+1],I,k,D,F;return S[0]<R[0]?(I=S[0],k=R[0]):(I=R[0],k=S[0]),S[1]<R[1]?(D=S[1],F=R[1]):(D=R[1],F=S[1]),{minX:I,minY:D,maxX:k,maxY:F,ring:y,edge:E}}}function Oue(e,t,i,n){if(Z1(e,i)||Z1(e,n)||Z1(t,i)||Z1(n,i))return null;var r=e[0],s=e[1],a=t[0],l=t[1],h=i[0],d=i[1],p=n[0],g=n[1],v=(r-a)*(d-g)-(s-l)*(h-p);return v===0?null:[((r*l-s*a)*(h-p)-(r-a)*(h*g-d*p))/v,((r*l-s*a)*(d-g)-(s-l)*(h*g-d*p))/v]}function Z1(e,t){if(!e||!t||e.length!==t.length)return!1;for(var i=0,n=e.length;i<n;i++)if(e[i]instanceof Array&&t[i]instanceof Array){if(!Z1(e[i],t[i]))return!1}else if(e[i]!==t[i])return!1;return!0}function Uue(e){if(e.type!="Feature")throw new Error("The input must a geojson object of type Feature");if(e.geometry===void 0||e.geometry==null)throw new Error("The input must a geojson object with a non-empty geometry");if(e.geometry.type!="Polygon")throw new Error("The input must be a geojson Polygon");for(var t=e.geometry.coordinates.length,i=[],I=0;I<t;I++){var n=e.geometry.coordinates[I];q1(n[0],n[n.length-1])||n.push(n[0]);for(var r=0;r<n.length-1;r++)i.push(n[r])}if(!zue(i))throw new Error("The input polygon may not have duplicate vertices (except for the first and last vertex of each ring)");var s=i.length,a=Due(e,function(Ee,Se,Ve,ze,it,Le,nt,lt,Ae,vt,Ne,$t){return[Ee,Se,Ve,ze,it,Le,nt,lt,Ae,vt,Ne,$t]}),l=a.length;if(l==0){for(var Y=[],I=0;I<t;I++)Y.push(ph([e.geometry.coordinates[I]],{parent:-1,winding:Gue(e.geometry.coordinates[I])}));let Ee=Qn(Y);return de(Ee),pe(Ee),Ee}for(var h=[],d=[],I=0;I<t;I++){h.push([]);for(var r=0;r<e.geometry.coordinates[I].length-1;r++)h[I].push([new E$(e.geometry.coordinates[I][yA(r+1,e.geometry.coordinates[I].length-1)],1,[I,r],[I,yA(r+1,e.geometry.coordinates[I].length-1)],void 0)]),d.push(new S$(e.geometry.coordinates[I][r],[I,yA(r-1,e.geometry.coordinates[I].length-1)],[I,r],void 0,void 0,!1,!0))}for(var I=0;I<l;I++)h[a[I][1]][a[I][2]].push(new E$(a[I][0],a[I][5],[a[I][1],a[I][2]],[a[I][6],a[I][7]],void 0)),a[I][11]&&d.push(new S$(a[I][0],[a[I][1],a[I][2]],[a[I][6],a[I][7]],void 0,void 0,!0,!0));for(var p=d.length,I=0;I<h.length;I++)for(var r=0;r<h[I].length;r++)h[I][r].sort(function(Se,Ve){return Se.param<Ve.param?-1:1});for(var g=[],I=0;I<p;I++)g.push({minX:d[I].coord[0],minY:d[I].coord[1],maxX:d[I].coord[0],maxY:d[I].coord[1],index:I});var v=new jG;v.load(g);for(var I=0;I<h.length;I++)for(var r=0;r<h[I].length;r++)for(var y=0;y<h[I][r].length;y++){let Se;y==h[I][r].length-1?Se=h[I][yA(r+1,e.geometry.coordinates[I].length-1)][0].coord:Se=h[I][r][y+1].coord;var E=v.search({minX:Se[0],minY:Se[1],maxX:Se[0],maxY:Se[1]})[0];h[I][r][y].nxtIsectAlongEdgeIn=E.index}for(var I=0;I<h.length;I++)for(var r=0;r<h[I].length;r++)for(var y=0;y<h[I][r].length;y++){let Ve=h[I][r][y].coord;var E=v.search({minX:Ve[0],minY:Ve[1],maxX:Ve[0],maxY:Ve[1]})[0],S=E.index;S<s?d[S].nxtIsectAlongRingAndEdge2=h[I][r][y].nxtIsectAlongEdgeIn:q1(d[S].ringAndEdge1,h[I][r][y].ringAndEdgeIn)?d[S].nxtIsectAlongRingAndEdge1=h[I][r][y].nxtIsectAlongEdgeIn:d[S].nxtIsectAlongRingAndEdge2=h[I][r][y].nxtIsectAlongEdgeIn}for(var R=[],I=0,r=0;r<t;r++){for(var k=I,y=0;y<e.geometry.coordinates[r].length-1;y++)d[I].coord[0]<d[k].coord[0]&&(k=I),I++;for(var D=d[k].nxtIsectAlongRingAndEdge2,y=0;y<d.length;y++)if(d[y].nxtIsectAlongRingAndEdge1==k||d[y].nxtIsectAlongRingAndEdge2==k){var F=y;break}var Z=BM([d[F].coord,d[k].coord,d[D].coord],!0)?1:-1;R.push({isect:k,parent:-1,winding:Z})}R.sort(function(we,Ee){return d[we.isect].coord>d[Ee.isect].coord?-1:1});for(var Y=[];R.length>0;){var Q=R.pop(),V=Q.isect,U=Q.parent,H=Q.winding,W=Y.length,ne=[d[V].coord],te=V;if(d[V].ringAndEdge1Walkable)var oe=d[V].ringAndEdge1,X=d[V].nxtIsectAlongRingAndEdge1;else var oe=d[V].ringAndEdge2,X=d[V].nxtIsectAlongRingAndEdge2;for(;!q1(d[V].coord,d[X].coord);){ne.push(d[X].coord);for(var ee=void 0,I=0;I<R.length;I++)if(R[I].isect==X){ee=I;break}if(ee!=null&&R.splice(ee,1),q1(oe,d[X].ringAndEdge1)){if(oe=d[X].ringAndEdge2,d[X].ringAndEdge2Walkable=!1,d[X].ringAndEdge1Walkable){var ae={isect:X};BM([d[te].coord,d[X].coord,d[d[X].nxtIsectAlongRingAndEdge2].coord],H==1)?(ae.parent=U,ae.winding=-H):(ae.parent=W,ae.winding=H),R.push(ae)}te=X,X=d[X].nxtIsectAlongRingAndEdge2}else{if(oe=d[X].ringAndEdge1,d[X].ringAndEdge1Walkable=!1,d[X].ringAndEdge2Walkable){var ae={isect:X};BM([d[te].coord,d[X].coord,d[d[X].nxtIsectAlongRingAndEdge1].coord],H==1)?(ae.parent=U,ae.winding=-H):(ae.parent=W,ae.winding=H),R.push(ae)}te=X,X=d[X].nxtIsectAlongRingAndEdge1}}ne.push(d[X].coord),Y.push(ph([ne],{index:W,parent:U,winding:H,netWinding:void 0}))}let ce=Qn(Y);de(ce),pe(ce);function de(we){for(var Ee=[],Se=0;Se<we.features.length;Se++)we.features[Se].properties.parent==-1&&Ee.push(Se);if(Ee.length>1)for(var Se=0;Se<Ee.length;Se++){for(var Ve=-1,ze=1/0,it=0;it<we.features.length;it++)Ee[Se]!=it&&la(we.features[Ee[Se]].geometry.coordinates[0][0],we.features[it],{ignoreBoundary:!0})&&fI(we.features[it])<ze&&(Ve=it);we.features[Ee[Se]].properties.parent=Ve}}function pe(we){for(var Ee=0;Ee<we.features.length;Ee++)if(we.features[Ee].properties.parent==-1){var Se=we.features[Ee].properties.winding;we.features[Ee].properties.netWinding=Se,Ie(we,Ee,Se)}}function Ie(we,Ee,Se){for(var Ve=0;Ve<we.features.length;Ve++)if(we.features[Ve].properties.parent==Ee){var ze=Se+we.features[Ve].properties.winding;we.features[Ve].properties.netWinding=ze,Ie(we,Ve,ze)}}return ce}var E$=class{constructor(e,t,i,n,r){this.coord=e,this.param=t,this.ringAndEdgeIn=i,this.ringAndEdgeOut=n,this.nxtIsectAlongEdgeIn=r}},S$=class{constructor(e,t,i,n,r,s,a){this.coord=e,this.ringAndEdge1=t,this.ringAndEdge2=i,this.nxtIsectAlongRingAndEdge1=n,this.nxtIsectAlongRingAndEdge2=r,this.ringAndEdge1Walkable=s,this.ringAndEdge2Walkable=a}};function BM(e,t){if(typeof t>"u"&&(t=!0),e.length!=3)throw new Error("This function requires an array of three points [x,y]");return(e[1][0]-e[0][0])*(e[2][1]-e[0][1])-(e[1][1]-e[0][1])*(e[2][0]-e[0][0])>=0==t}function Gue(e){for(var t=0,i=0;i<e.length-1;i++)e[i][0]<e[t][0]&&(t=i);if(BM([e[yA(t-1,e.length-1)],e[t],e[yA(t+1,e.length-1)]],!0))var n=1;else var n=-1;return n}function q1(e,t){if(!e||!t||e.length!=t.length)return!1;for(var i=0,n=e.length;i<n;i++)if(e[i]instanceof Array&&t[i]instanceof Array){if(!q1(e[i],t[i]))return!1}else if(e[i]!=t[i])return!1;return!0}function yA(e,t){return(e%t+t)%t}function zue(e){for(var t={},i=1,n=0,r=e.length;n<r;++n){if(Object.prototype.hasOwnProperty.call(t,e[n].toString())){i=0;break}t[e[n].toString()]=1}return i}function Vue(e){var t=[];return vf(e,function(i){i.geometry.type==="Polygon"&&Af(Uue(i),function(n){t.push(ph(n.geometry.coordinates,i.properties))})}),Qn(t)}var $ue=class{undoStack=[];redoStack=[];maxSize;isExecuting=!1;onHistoryChange;constructor(e=50,t){this.maxSize=e,this.onHistoryChange=t}record(e){if(!this.isExecuting){for(this.undoStack.push(e);this.undoStack.length>this.maxSize;)this.undoStack.shift();this.redoStack=[],this.notifyChange()}}undo(){if(!this.canUndo())return!1;const e=this.undoStack.pop();this.isExecuting=!0;try{e.undo()}finally{this.isExecuting=!1}return this.redoStack.push(e),this.notifyChange(),!0}redo(){if(!this.canRedo())return!1;const e=this.redoStack.pop();this.isExecuting=!0;try{e.execute()}finally{this.isExecuting=!1}return this.undoStack.push(e),this.notifyChange(),!0}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}isExecutingCommand(){return this.isExecuting}getState(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),undoCount:this.undoStack.length,redoCount:this.redoStack.length}}clear(){this.undoStack=[],this.redoStack=[],this.notifyChange()}getUndoDescription(){return this.undoStack.length===0?null:this.undoStack[this.undoStack.length-1].description}getRedoDescription(){return this.redoStack.length===0?null:this.redoStack[this.redoStack.length-1].description}notifyChange(){this.onHistoryChange&&this.onHistoryChange(this.canUndo(),this.canRedo())}},M$=class{description;type="create";feature;featureId=null;context;constructor(e,t){this.feature=Go(e),this.context=t,this.featureId=this.extractFeatureId(e);const i=e.geometry?.type||"feature";this.description=`Create ${i}`}execute(){const e=this.context.featuresApi.importGeoJsonFeature(this.feature);e&&(this.featureId=String(e.id),this.context.onFeatureCreate?.(this.feature))}undo(){if(!this.featureId)return;const e=[];try{this.context.featuresApi.forEach(t=>{const i=String(t.id),n=this.getGeomanFeature(t),r=n?this.extractFeatureId(n):null;(i===this.featureId||r===this.featureId)&&e.push(t)}),e.forEach(t=>{try{this.context.featuresApi.delete(t)}catch{try{t.delete()}catch{}}}),e.length>0&&this.featureId&&this.context.onFeatureDelete?.(this.featureId)}catch{}}extractFeatureId(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}},Hue=class{description;type="edit";oldFeature;newFeature;featureId;context;constructor(e,t,i){this.oldFeature=Go(e),this.newFeature=Go(t),this.context=i,this.featureId=this.extractFeatureId(t)||this.extractFeatureId(e);const n=t.geometry?.type||"feature";this.description=`Edit ${n}`}execute(){this.updateFeatureGeometry(this.newFeature)}undo(){this.updateFeatureGeometry(this.oldFeature)}updateFeatureGeometry(e){if(this.featureId)try{this.context.featuresApi.forEach(t=>{const i=String(t.id),n=this.getGeomanFeature(t),r=n?this.extractFeatureId(n):null;(i===this.featureId||r===this.featureId)&&(t.updateGeometry?t.updateGeometry(e.geometry):t.updateGeoJsonGeometry&&t.updateGeoJsonGeometry(e.geometry))})}catch{this.deleteAndReimport(e)}}deleteAndReimport(e){if(!this.featureId)return;const t=[];try{this.context.featuresApi.forEach(n=>{const r=String(n.id),s=this.getGeomanFeature(n),a=s?this.extractFeatureId(s):null;(r===this.featureId||a===this.featureId)&&t.push(n)}),t.forEach(n=>{try{this.context.featuresApi.delete(n)}catch{try{n.delete()}catch{}}})}catch{}const i=this.context.featuresApi.importGeoJsonFeature(e);i&&(this.featureId=String(i.id))}extractFeatureId(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}},I$=class{description;type="delete";feature;featureId;context;constructor(e,t){this.feature=Go(e),this.context=t,this.featureId=this.extractFeatureId(e);const i=e.geometry?.type||"feature";this.description=`Delete ${i}`}execute(){if(!this.featureId)return;const e=[];try{this.context.featuresApi.forEach(t=>{const i=String(t.id),n=this.getGeomanFeature(t),r=n?this.extractFeatureId(n):null;(i===this.featureId||r===this.featureId)&&e.push(t)}),e.forEach(t=>{try{this.context.featuresApi.delete(t)}catch{try{t.delete()}catch{}}}),e.length>0&&this.featureId&&this.context.onFeatureDelete?.(this.featureId)}catch{}}undo(){const e=this.context.featuresApi.importGeoJsonFeature(this.feature);e&&(this.featureId=String(e.id),this.context.onFeatureCreate?.(this.feature))}extractFeatureId(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}},Que=class{description;type="composite";commands;constructor(e,t){this.commands=e,this.description=t}execute(){for(const e of this.commands)e.execute()}undo(){for(let e=this.commands.length-1;e>=0;e--)this.commands[e].undo()}getCommandCount(){return this.commands.length}},Wue=["polygon","line","rectangle","circle","marker"],Xue=["select","drag","change","rotate","cut","delete","scale","copy","split","union","difference","simplify","lasso"],l8=["select","scale","copy","split","union","difference","simplify","lasso"],Zue=["snapping","measurements"],que=["open","save"],Yue={position:"top-left",collapsed:!1,drawModes:Wue,editModes:Xue,helperModes:Zue,fileModes:que,toolbarOrientation:"vertical",showLabels:!1,simplifyTolerance:.001,snappingEnabled:!0,measurementsEnabled:!1,hideGeomanControl:!0,saveFilename:"features.geojson",onFeatureCreate:()=>{},onFeatureEdit:()=>{},onFeatureDelete:()=>{},onSelectionChange:()=>{},onModeChange:()=>{},onGeoJsonLoad:()=>{},onGeoJsonSave:()=>{},showFeatureProperties:!0,fitBoundsOnLoad:!0,columns:2,enableHistory:!0,maxHistorySize:50,onHistoryChange:()=>{},enableAttributeEditing:!1,attributeSchema:void 0,onAttributeChange:()=>{},attributePanelPosition:"right",attributePanelWidth:300,attributePanelMaxHeight:"80vh",attributePanelTop:10,attributePanelSideOffset:10,attributePanelTitle:"Feature Properties"},Pi="geo-editor",Zi={LASSO_SOURCE:"geo-editor-lasso-source",LASSO_LAYER:"geo-editor-lasso-layer",LASSO_LINE_LAYER:"geo-editor-lasso-line-layer",SCALE_HANDLES_SOURCE:"geo-editor-scale-handles-source",SCALE_HANDLES_LAYER:"geo-editor-scale-handles-layer",SPLIT_LINE_SOURCE:"geo-editor-split-line-source",SPLIT_LINE_LAYER:"geo-editor-split-line-layer",SELECTION_SOURCE:"geo-editor-selection-source",SELECTION_FILL_LAYER:"geo-editor-selection-fill-layer",SELECTION_LINE_LAYER:"geo-editor-selection-line-layer",SELECTION_CIRCLE_LAYER:"geo-editor-selection-circle-layer",FREEHAND_SOURCE:"geo-editor-freehand-source",FREEHAND_FILL_LAYER:"geo-editor-freehand-fill-layer",FREEHAND_LINE_LAYER:"geo-editor-freehand-line-layer"},n_={handleSize:10,handleColor:"#3388ff",handleBorderColor:"#ffffff",handleBorderWidth:2,minScale:.1,maxScale:10},c8={tolerance:.001,highQuality:!1,mutate:!1},T$={offset:[5e-4,5e-4],generateNewIds:!0};function bf(){return`feature_${Date.now()}_${Math.random().toString(36).slice(2,11)}`}function AJ(e){return e.geometry.type==="Polygon"||e.geometry.type==="MultiPolygon"}function jue(e){return e.geometry.type==="LineString"||e.geometry.type==="MultiLineString"}function R$(e,t,i){return Math.min(Math.max(e,t),i)}function Yy(e){return Kle(e).length}var Jue=class{options;constructor(e={}){this.options={offset:e.offset??T$.offset,generateNewIds:e.generateNewIds??T$.generateNewIds}}copy(e,t){const i=Go(e),n=t??this.options.offset;return this.options.generateNewIds&&(i.id=bf(),i.properties&&(i.properties={...i.properties,id:i.id})),n[0]!==0||n[1]!==0?b6(i,Math.sqrt(n[0]**2+n[1]**2)*111,Math.atan2(n[0],n[1])*180/Math.PI,{units:"kilometers"}):i}copyMultiple(e,t){return e.map(i=>this.copy(i,t))}copyToLocation(e,t){if(e.length===0)return[];const i=jb(Qn(e)).geometry.coordinates,n=t[0]-i[0],r=t[1]-i[1];return e.map(s=>{const a=Go(s);return this.options.generateNewIds&&(a.id=bf(),a.properties&&(a.properties={...a.properties,id:a.id})),b6(a,Math.sqrt(n**2+r**2)*111,Math.atan2(n,r)*180/Math.PI,{units:"kilometers"})})}setOffset(e){this.options.offset=e}getOffset(){return this.options.offset}},Kue=class{defaultOptions;constructor(e){this.defaultOptions={tolerance:e?.tolerance??c8.tolerance,highQuality:e?.highQuality??c8.highQuality,mutate:e?.mutate??c8.mutate}}simplify(e,t){return y6(e,{...this.defaultOptions,...t})}simplifyWithStats(e,t){const i={...this.defaultOptions,...t},n=Yy(e),r=y6(e,i),s=Yy(r);return{result:r,original:e,verticesBefore:n,verticesAfter:s,reductionPercent:n>0?(n-s)/n*100:0}}getSimplificationStats(e,t){const i=Yy(e),n=Yy(this.simplify(e,{tolerance:t}));return{before:i,after:n,reduction:i>0?(i-n)/i*100:0}}previewTolerances(e,t){const i=new Map;for(const n of t)i.set(n,this.simplifyWithStats(e,{tolerance:n}));return i}getSuggestedTolerances(e){const t=Yy(e),i=[1e-4,5e-4,.001,.005,.01];return t>1e3?[.001,.005,.01,.05,.1]:t>100?[5e-4,.001,.005,.01,.05]:i}findOptimalTolerance(e,t){const i=[1e-5,5e-5,1e-4,5e-4,.001,.005,.01,.05,.1];let n=i[0],r=this.simplifyWithStats(e,{tolerance:n}),s=Math.abs(r.reductionPercent-t);for(const a of i.slice(1)){const l=this.simplifyWithStats(e,{tolerance:a}),h=Math.abs(l.reductionPercent-t);h<s&&(s=h,n=a,r=l)}return{tolerance:n,result:r}}setDefaultTolerance(e){this.defaultOptions.tolerance=e}getDefaultTolerance(){return this.defaultOptions.tolerance}},ede=class{union(e,t){if(e.length===0)return{result:null,originals:[],success:!1,error:"No features provided"};if(e.length===1){const i=Go(e[0]);return i.id=bf(),t?.properties&&(i.properties={...i.properties,...t.properties}),{result:i,originals:e,success:!0}}try{const i=Fue(Qn(e));return i&&(i.id=bf(),t?.properties&&(i.properties={...i.properties,...t.properties})),{result:i,originals:e,success:i!==null,error:i===null?"Union operation returned null":void 0}}catch(i){return{result:null,originals:e,success:!1,error:`Union operation failed: ${i instanceof Error?i.message:"Unknown error"}`}}}canMerge(e){if(e.length<2)return{canMerge:!1,reason:"Need at least 2 polygons to merge"};for(const t of e)if(t.geometry.type!=="Polygon"&&t.geometry.type!=="MultiPolygon")return{canMerge:!1,reason:"All features must be polygons"};return{canMerge:!0}}hasOverlap(e){for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++)try{if($j(e[t],e[i])||nz(e[t],e[i]))return!0}catch{}return!1}getCombinedArea(e){return e.reduce((t,i)=>{try{return t+fI(i)}catch{return t}},0)}getUnionArea(e){const t=this.union(e);if(t.success&&t.result)try{return fI(t.result)}catch{return null}return null}},tde=class{difference(e,t,i){if(t.length===0){const n=Go(e);return n.id=bf(),{result:n,base:e,subtracted:[],success:!0}}try{let n=Go(e);for(const r of t){if(!n)break;n=gJ(Qn([n,r]))}return n&&(n.id=bf(),i?.properties&&(n.properties={...n.properties,...i.properties})),{result:n,base:e,subtracted:t,success:!0}}catch(n){return{result:null,base:e,subtracted:t,success:!1,error:`Difference operation failed: ${n instanceof Error?n.message:"Unknown error"}`}}}canSubtract(e,t){if(e.geometry.type!=="Polygon"&&e.geometry.type!=="MultiPolygon")return{canSubtract:!1,overlap:!1,reason:"Base must be a polygon"};if(t.geometry.type!=="Polygon"&&t.geometry.type!=="MultiPolygon")return{canSubtract:!1,overlap:!1,reason:"Subtract feature must be a polygon"};try{return $j(e,t)||X9(e,t)||nz(e,t)?{canSubtract:!0,overlap:!0}:{canSubtract:!1,overlap:!1,reason:"Polygons do not overlap"}}catch{return{canSubtract:!1,overlap:!1,reason:"Could not determine overlap"}}}getSubtractedArea(e,t){try{const i=Iue(Qn([e,t]));return i?fI(i):0}catch{return null}}preview(e,t){return this.difference(e,t).result}createHole(e,t){try{return X9(e,t)?this.difference(e,[t]).result:(console.warn("Hole must be completely inside the polygon"),null)}catch{return null}}},ide=class{map=null;options;activeFeature=null;originalFeature=null;handles=[];activeHandle=null;startPoint=null;onScaleCallback=null;constructor(e={}){this.options={maintainAspectRatio:e.maintainAspectRatio??!0,scaleFromCenter:e.scaleFromCenter??!0,minScale:e.minScale??n_.minScale,maxScale:e.maxScale??n_.maxScale}}init(e){this.map=e}scale(e,t,i){const n=Tue(e,R$(t,this.options.minScale,this.options.maxScale),{origin:i||jb(e).geometry.coordinates});return n.id=e.id||bf(),n.properties={...e.properties},n}scaleFromHandle(e,t,i,n){const r=As(e),s=jb(e).geometry.coordinates,a=this.distanceFromCenter(i,s);let l=this.distanceFromCenter(n,s)/a;l=R$(l,this.options.minScale,this.options.maxScale);let h;return this.options.scaleFromCenter?h=s:h=this.getOppositeCorner(r,t),this.scale(e,l,h)}createHandles(e){const[t,i,n,r]=As(e),s=(t+n)/2,a=(i+r)/2;return this.handles=[{position:"nw",coordinates:[t,r]},{position:"n",coordinates:[s,r]},{position:"ne",coordinates:[n,r]},{position:"e",coordinates:[n,a]},{position:"se",coordinates:[n,i]},{position:"s",coordinates:[s,i]},{position:"sw",coordinates:[t,i]},{position:"w",coordinates:[t,a]}],this.handles}startScale(e,t,i,n){this.activeFeature=Go(e),this.originalFeature=Go(e),this.activeHandle=t,this.startPoint=i,this.onScaleCallback=n||null,this.showHandles(e)}showHandlesForFeature(e){this.showHandles(e)}updateScale(e){if(!this.activeFeature||!this.originalFeature||!this.activeHandle||!this.startPoint)return null;const t=this.scaleFromHandle(this.originalFeature,this.activeHandle,this.startPoint,e);this.activeFeature=t,this.updateHandlePositions(t);const i=As(this.originalFeature),n=As(t),r=(n[2]-n[0])/(i[2]-i[0]);return this.onScaleCallback&&this.onScaleCallback(t,r),t}endScale(){if(!this.activeFeature||!this.originalFeature)return null;const e=As(this.originalFeature),t=As(this.activeFeature),i=(t[2]-t[0])/(e[2]-e[0]),n={feature:this.activeFeature,factor:i};return this.hideHandles(),this.activeFeature=null,this.originalFeature=null,this.activeHandle=null,this.startPoint=null,this.onScaleCallback=null,n}cancelScale(){this.hideHandles(),this.activeFeature=null,this.originalFeature=null,this.activeHandle=null,this.startPoint=null,this.onScaleCallback=null}showHandles(e){if(!this.map)return;const t=this.createHandles(e).map(i=>aa(i.coordinates,{position:i.position}));if(!this.map.getSource(Zi.SCALE_HANDLES_SOURCE))this.map.addSource(Zi.SCALE_HANDLES_SOURCE,{type:"geojson",data:Qn(t)}),this.map.addLayer({id:Zi.SCALE_HANDLES_LAYER,type:"circle",source:Zi.SCALE_HANDLES_SOURCE,paint:{"circle-radius":n_.handleSize/2,"circle-color":n_.handleColor,"circle-stroke-color":n_.handleBorderColor,"circle-stroke-width":n_.handleBorderWidth}});else{const i=this.map.getSource(Zi.SCALE_HANDLES_SOURCE);i&&i.setData(Qn(t))}}updateHandlePositions(e){if(!this.map)return;const t=this.createHandles(e).map(n=>aa(n.coordinates,{position:n.position})),i=this.map.getSource(Zi.SCALE_HANDLES_SOURCE);i&&i.setData(Qn(t))}hideHandles(){this.map&&(this.map.getLayer(Zi.SCALE_HANDLES_LAYER)&&this.map.removeLayer(Zi.SCALE_HANDLES_LAYER),this.map.getSource(Zi.SCALE_HANDLES_SOURCE)&&this.map.removeSource(Zi.SCALE_HANDLES_SOURCE))}distanceFromCenter(e,t){return Math.sqrt(Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2))}getOppositeCorner(e,t){const[i,n,r,s]=e,a=(i+r)/2,l=(n+s)/2;return{nw:[r,n],n:[a,n],ne:[i,n],e:[i,l],se:[i,s],s:[a,s],sw:[r,s],w:[r,l]}[t]}getHandleAtPoint(e,t=1e-4){for(const i of this.handles)if(this.distanceFromCenter(e,i.coordinates)<t)return i.position;return null}destroy(){this.cancelScale(),this.map=null}},nde=class{map=null;isDrawing=!1;points=[];options;onCompleteCallback=null;dragPanEnabled=null;boxZoomEnabled=null;doubleClickZoomEnabled=null;handleMouseDown=null;handleMouseMove=null;handleMouseUp=null;constructor(e={}){this.options={mode:e.mode??"intersects"}}init(e){this.map=e}enable(e){this.map&&(this.onCompleteCallback=e||null,this.disableMapInteractions(),this.setupLassoLayers(),this.attachEventListeners(),this.map.getCanvas().style.cursor="crosshair")}disable(){this.removeEventListeners(),this.clearLasso(),this.isDrawing=!1,this.points=[],this.onCompleteCallback=null,this.restoreMapInteractions(),this.map&&(this.map.getCanvas().style.cursor="")}selectWithinLasso(e,t){return t.filter(i=>{try{return this.options.mode==="contains"?mhe(i,e):nz(i,e)}catch{return!1}})}buildLassoPolygon(){if(this.points.length<3)return null;const e=[...this.points,this.points[0]];try{return ph([e])}catch{return null}}setMode(e){this.options.mode=e}isActive(){return this.isDrawing}setupLassoLayers(){this.map&&(this.map.getSource(Zi.LASSO_SOURCE)||this.map.addSource(Zi.LASSO_SOURCE,{type:"geojson",data:Qn([])}),this.map.getLayer(Zi.LASSO_LAYER)||this.map.addLayer({id:Zi.LASSO_LAYER,type:"fill",source:Zi.LASSO_SOURCE,paint:{"fill-color":"#3388ff","fill-opacity":.2}}),this.map.getLayer(Zi.LASSO_LINE_LAYER)||this.map.addLayer({id:Zi.LASSO_LINE_LAYER,type:"line",source:Zi.LASSO_SOURCE,paint:{"line-color":"#3388ff","line-width":2,"line-dasharray":[2,2]}}))}attachEventListeners(){this.map&&(this.handleMouseDown=e=>{e.preventDefault(),this.isDrawing=!0,this.points=[[e.lngLat.lng,e.lngLat.lat]],this.updateLassoVisualization()},this.handleMouseMove=e=>{this.isDrawing&&(e.preventDefault(),this.points.push([e.lngLat.lng,e.lngLat.lat]),this.updateLassoVisualization())},this.handleMouseUp=()=>{this.isDrawing&&(this.isDrawing=!1,this.completeLasso())},this.map.on("mousedown",this.handleMouseDown),this.map.on("mousemove",this.handleMouseMove),this.map.on("mouseup",this.handleMouseUp))}removeEventListeners(){this.map&&(this.handleMouseDown&&this.map.off("mousedown",this.handleMouseDown),this.handleMouseMove&&this.map.off("mousemove",this.handleMouseMove),this.handleMouseUp&&this.map.off("mouseup",this.handleMouseUp),this.handleMouseDown=null,this.handleMouseMove=null,this.handleMouseUp=null)}updateLassoVisualization(){if(!this.map||this.points.length<2)return;const e=this.map.getSource(Zi.LASSO_SOURCE);if(!e)return;const t=[...this.points];if(t.length>=3){t.push(t[0]);const i=ph([t]);e.setData(Qn([i]))}else{const i=Uo(t);e.setData(Qn([i]))}}completeLasso(){const e=this.buildLassoPolygon();if(e&&this.onCompleteCallback){const t={selected:[],lasso:e};this.onCompleteCallback(t)}setTimeout(()=>{this.clearLasso(),this.points=[]},100)}clearLasso(){if(!this.map)return;const e=this.map.getSource(Zi.LASSO_SOURCE);e&&e.setData(Qn([]))}disableMapInteractions(){this.map&&(this.dragPanEnabled=this.map.dragPan.isEnabled(),this.dragPanEnabled&&this.map.dragPan.disable(),this.map.boxZoom&&(this.boxZoomEnabled=this.map.boxZoom.isEnabled(),this.boxZoomEnabled&&this.map.boxZoom.disable()),this.map.doubleClickZoom&&(this.doubleClickZoomEnabled=this.map.doubleClickZoom.isEnabled(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom.disable()))}restoreMapInteractions(){this.map&&(this.dragPanEnabled&&this.map.dragPan.enable(),this.boxZoomEnabled&&this.map.boxZoom&&this.map.boxZoom.enable(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom&&this.map.doubleClickZoom.enable(),this.dragPanEnabled=null,this.boxZoomEnabled=null,this.doubleClickZoomEnabled=null)}removeLayers(){this.map&&(this.map.getLayer(Zi.LASSO_LINE_LAYER)&&this.map.removeLayer(Zi.LASSO_LINE_LAYER),this.map.getLayer(Zi.LASSO_LAYER)&&this.map.removeLayer(Zi.LASSO_LAYER),this.map.getSource(Zi.LASSO_SOURCE)&&this.map.removeSource(Zi.LASSO_SOURCE))}destroy(){this.disable(),this.removeLayers(),this.map=null}},rde=class{map=null;isDrawing=!1;splitLinePoints=[];targetFeature=null;onCompleteCallback=null;handleClick=null;handleMouseMove=null;handleDblClick=null;constructor(){}init(e){this.map=e}splitPolygon(e,t,i){try{if(xv(pI(e),t).features.length<2)return{original:e,parts:[],success:!1,error:"Splitting line must intersect polygon at least twice"};if(!this.clipLineToBbox(t,As(e)))return{original:e,parts:[],success:!1,error:"Could not clip splitting line to polygon"};const n=this.performPolygonSplit(e,t);return n.length===0?{original:e,parts:[],success:!1,error:"Split operation produced no valid parts"}:(n.forEach(r=>{r.id=bf(),r.properties={...e.properties}}),{original:e,parts:n,success:!0})}catch(n){return{original:e,parts:[],success:!1,error:`Split operation failed: ${n instanceof Error?n.message:"Unknown error"}`}}}splitLine(e,t){try{const i=KG(e,t);return i.features.length<=1?{original:e,parts:[],success:!1,error:"Splitter does not intersect the line"}:{original:e,parts:i.features.map(n=>{const r=n;return r.id=bf(),r.properties={...e.properties},r}),success:!0}}catch(i){return{original:e,parts:[],success:!1,error:`Split operation failed: ${i instanceof Error?i.message:"Unknown error"}`}}}startSplit(e,t){this.map&&(this.targetFeature=e,this.onCompleteCallback=t,this.splitLinePoints=[],this.isDrawing=!0,this.setupSplitLineLayers(),this.attachEventListeners(),this.map.getCanvas().style.cursor="crosshair")}cancelSplit(){this.cleanup(),this.targetFeature=null,this.onCompleteCallback=null}isActive(){return this.isDrawing}performPolygonSplit(e,t){try{const i=iue(t,1e-5,{units:"degrees"});if(!i)return[];const n=gJ(Qn([e,i]));if(!n)return[];if(n.geometry.type==="MultiPolygon")return n.geometry.coordinates.map(s=>ph(s));const r=Vue(n);return r.features.length>1?r.features:[n]}catch{return[]}}clipLineToBbox(e,t){try{return sce(e,t)}catch{return null}}setupSplitLineLayers(){this.map&&(this.map.getSource(Zi.SPLIT_LINE_SOURCE)||this.map.addSource(Zi.SPLIT_LINE_SOURCE,{type:"geojson",data:Qn([])}),this.map.getLayer(Zi.SPLIT_LINE_LAYER)||this.map.addLayer({id:Zi.SPLIT_LINE_LAYER,type:"line",source:Zi.SPLIT_LINE_SOURCE,paint:{"line-color":"#ff4444","line-width":3,"line-dasharray":[3,3]}}))}attachEventListeners(){this.map&&(this.handleClick=e=>{this.splitLinePoints.push([e.lngLat.lng,e.lngLat.lat]),this.updateSplitLineVisualization()},this.handleMouseMove=e=>{if(this.splitLinePoints.length===0)return;const t=[...this.splitLinePoints,[e.lngLat.lng,e.lngLat.lat]];this.updateSplitLineVisualization(t)},this.handleDblClick=e=>{e.preventDefault(),this.completeSplit()},this.map.on("click",this.handleClick),this.map.on("mousemove",this.handleMouseMove),this.map.on("dblclick",this.handleDblClick))}removeEventListeners(){this.map&&(this.handleClick&&this.map.off("click",this.handleClick),this.handleMouseMove&&this.map.off("mousemove",this.handleMouseMove),this.handleDblClick&&this.map.off("dblclick",this.handleDblClick),this.handleClick=null,this.handleMouseMove=null,this.handleDblClick=null)}updateSplitLineVisualization(e){if(!this.map)return;const t=this.map.getSource(Zi.SPLIT_LINE_SOURCE);if(!t)return;const i=e||this.splitLinePoints;if(i.length<2){t.setData(Qn([]));return}const n=Uo(i);t.setData(Qn([n]))}completeSplit(){if(!this.targetFeature||!this.onCompleteCallback||this.splitLinePoints.length<2){this.cleanup();return}const e=Uo(this.splitLinePoints);let t;this.targetFeature.geometry.type==="Polygon"?t=this.splitPolygon(this.targetFeature,e):t=this.splitLine(this.targetFeature,e),this.onCompleteCallback(t),this.cleanup()}cleanup(){this.removeEventListeners(),this.clearSplitLine(),this.isDrawing=!1,this.splitLinePoints=[],this.map&&(this.map.getCanvas().style.cursor="")}clearSplitLine(){if(!this.map)return;const e=this.map.getSource(Zi.SPLIT_LINE_SOURCE);e&&e.setData(Qn([]))}removeLayers(){this.map&&(this.map.getLayer(Zi.SPLIT_LINE_LAYER)&&this.map.removeLayer(Zi.SPLIT_LINE_LAYER),this.map.getSource(Zi.SPLIT_LINE_SOURCE)&&this.map.removeSource(Zi.SPLIT_LINE_SOURCE))}destroy(){this.cancelSplit(),this.removeLayers(),this.map=null}},sde=class{map=null;isDrawing=!1;points=[];options;onCompleteCallback=null;dragPanEnabled=null;boxZoomEnabled=null;doubleClickZoomEnabled=null;handleMouseDown=null;handleMouseMove=null;handleMouseUp=null;constructor(e={}){this.options={type:e.type??"polygon",simplifyTolerance:e.simplifyTolerance??1e-5,minPoints:e.minPoints??(e.type==="line"?2:3)}}init(e){this.map=e}enable(e){this.map&&(this.onCompleteCallback=e||null,this.disableMapInteractions(),this.setupFreehandLayers(),this.attachEventListeners(),this.map.getCanvas().style.cursor="crosshair")}disable(){this.removeEventListeners(),this.clearFreehand(),this.isDrawing=!1,this.points=[],this.onCompleteCallback=null,this.restoreMapInteractions(),this.map&&(this.map.getCanvas().style.cursor="")}setType(e){this.options.type=e,this.options.minPoints=e==="line"?2:3}isActive(){return this.isDrawing}buildFeature(){if(this.points.length<this.options.minPoints)return null;try{let e=this.removeDuplicatePoints(this.points);if(e.length<this.options.minPoints)return null;if(e.length>10&&(e=y6(Uo(e),{tolerance:this.options.simplifyTolerance,highQuality:!0}).geometry.coordinates),e=this.removeDuplicatePoints(e),this.options.type==="polygon"){if(e.length<3)return null;for(;e.length>3&&this.arePointsEqual(e[0],e[e.length-1]);)e=e.slice(0,-1);if(e.length<3)return null;const t=e.map(n=>[n[0],n[1]]),i=[t[0][0],t[0][1]];return zj(ph([[...t,i]]))}else return e.length<2?null:Uo(e.map(t=>[t[0],t[1]]))}catch(e){return console.warn("FreehandFeature: Error building feature:",e),null}}removeDuplicatePoints(e){if(e.length<=1)return e;const t=[e[0]];for(let i=1;i<e.length;i++)this.arePointsEqual(e[i],e[i-1])||t.push(e[i]);return t}arePointsEqual(e,t){return Math.abs(e[0]-t[0])<1e-7&&Math.abs(e[1]-t[1])<1e-7}setupFreehandLayers(){this.map&&(this.map.getSource(Zi.FREEHAND_SOURCE)||this.map.addSource(Zi.FREEHAND_SOURCE,{type:"geojson",data:Qn([])}),this.map.getLayer(Zi.FREEHAND_FILL_LAYER)||this.map.addLayer({id:Zi.FREEHAND_FILL_LAYER,type:"fill",source:Zi.FREEHAND_SOURCE,filter:["==",["geometry-type"],"Polygon"],paint:{"fill-color":"#3388ff","fill-opacity":.2}}),this.map.getLayer(Zi.FREEHAND_LINE_LAYER)||this.map.addLayer({id:Zi.FREEHAND_LINE_LAYER,type:"line",source:Zi.FREEHAND_SOURCE,paint:{"line-color":"#3388ff","line-width":3}}))}attachEventListeners(){this.map&&(this.handleMouseDown=e=>{e.preventDefault(),this.isDrawing=!0,this.points=[[e.lngLat.lng,e.lngLat.lat]],this.updateFreehandVisualization()},this.handleMouseMove=e=>{this.isDrawing&&(e.preventDefault(),this.points.push([e.lngLat.lng,e.lngLat.lat]),this.updateFreehandVisualization())},this.handleMouseUp=()=>{this.isDrawing&&(this.isDrawing=!1,this.completeFreehand())},this.map.on("mousedown",this.handleMouseDown),this.map.on("mousemove",this.handleMouseMove),this.map.on("mouseup",this.handleMouseUp))}removeEventListeners(){this.map&&(this.handleMouseDown&&this.map.off("mousedown",this.handleMouseDown),this.handleMouseMove&&this.map.off("mousemove",this.handleMouseMove),this.handleMouseUp&&this.map.off("mouseup",this.handleMouseUp),this.handleMouseDown=null,this.handleMouseMove=null,this.handleMouseUp=null)}updateFreehandVisualization(){if(!this.map||this.points.length<2)return;const e=this.map.getSource(Zi.FREEHAND_SOURCE);if(!e)return;const t=[...this.points];if(this.options.type==="polygon"&&t.length>=3){const i=ph([[...t,t[0]]]);e.setData(Qn([i]))}else{const i=Uo(t);e.setData(Qn([i]))}}completeFreehand(){const e=this.buildFeature(),t={feature:e,success:e!==null,error:e?void 0:`Need at least ${this.options.minPoints} points`};this.onCompleteCallback&&this.onCompleteCallback(t),setTimeout(()=>{this.clearFreehand(),this.points=[]},100)}clearFreehand(){if(!this.map)return;const e=this.map.getSource(Zi.FREEHAND_SOURCE);e&&e.setData(Qn([]))}disableMapInteractions(){this.map&&(this.dragPanEnabled=this.map.dragPan.isEnabled(),this.dragPanEnabled&&this.map.dragPan.disable(),this.map.boxZoom&&(this.boxZoomEnabled=this.map.boxZoom.isEnabled(),this.boxZoomEnabled&&this.map.boxZoom.disable()),this.map.doubleClickZoom&&(this.doubleClickZoomEnabled=this.map.doubleClickZoom.isEnabled(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom.disable()))}restoreMapInteractions(){this.map&&(this.dragPanEnabled&&this.map.dragPan.enable(),this.boxZoomEnabled&&this.map.boxZoom&&this.map.boxZoom.enable(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom&&this.map.doubleClickZoom.enable(),this.dragPanEnabled=null,this.boxZoomEnabled=null,this.doubleClickZoomEnabled=null)}removeLayers(){this.map&&(this.map.getLayer(Zi.FREEHAND_LINE_LAYER)&&this.map.removeLayer(Zi.FREEHAND_LINE_LAYER),this.map.getLayer(Zi.FREEHAND_FILL_LAYER)&&this.map.removeLayer(Zi.FREEHAND_FILL_LAYER),this.map.getSource(Zi.FREEHAND_SOURCE)&&this.map.removeSource(Zi.FREEHAND_SOURCE))}destroy(){this.disable(),this.removeLayers(),this.map=null}};function ME(e){return e.filter(AJ)}var x6=class{map;geoman=null;container;options;state;copyFeature;simplifyFeature;unionFeature;differenceFeature;scaleFeature;lassoFeature;splitFeature;freehandFeature;boundKeyHandler=null;boundClickHandler=null;boundScaleMouseDown=null;boundScaleMouseMove=null;boundScaleMouseUp=null;isSelectMode=!1;pendingOperation=null;snappingEnabled=!1;lastCreatedFeature=null;lastEditedFeature=null;lastDeletedFeature=null;lastDeletedFeatureId=null;isScaling=!1;scaleTargetFeature=null;scaleTargetGeomanData=null;scaleStartFeature=null;scaleDragPanEnabled=null;isMultiDragging=!1;multiDragStartPoint=null;multiDragOriginalFeatures=[];multiDragGeomanData=[];multiDragPanEnabled=null;boundMultiDragMouseDown=null;boundMultiDragMouseMove=null;boundMultiDragMouseUp=null;toolbar=null;fileInput=null;propertiesPopup=null;historyManager=null;pendingEditFeature=null;isPerformingCompositeOperation=!1;attributePanel=null;attributePanelVisible=!1;currentEditingFeature=null;currentEditingGeomanData=null;isNewFeature=!1;originalProperties=null;boundStyleDataHandler=null;_eventHandlers=new globalThis.Map;constructor(e={}){this.options={...Yue,...e},this.state={activeDrawMode:null,activeEditMode:null,selectedFeatures:[],isDrawing:!1,isEditing:!1,clipboard:[],collapsed:this.options.collapsed},this.snappingEnabled=this.options.snappingEnabled,this.copyFeature=new Jue,this.simplifyFeature=new Kue({tolerance:this.options.simplifyTolerance}),this.unionFeature=new ede,this.differenceFeature=new tde,this.scaleFeature=new ide,this.lassoFeature=new nde,this.splitFeature=new rde,this.freehandFeature=new sde,this.options.enableHistory!==!1&&(this.historyManager=new $ue(this.options.maxHistorySize,(t,i)=>{this.updateHistoryButtonStates(t,i),this.options.onHistoryChange?.(t,i)}))}onAdd(e){return this.map=e,this.scaleFeature.init(e),this.lassoFeature.init(e),this.splitFeature.init(e),this.freehandFeature.init(e),this.container=document.createElement("div"),this.container.className=`maplibregl-ctrl maplibregl-ctrl-group ${Pi}-control`,this.createToolbar(),this.setupFileInput(),this.setupKeyboardShortcuts(),this.setupSelectionHandler(),this.setupScaleHandler(),this.setupMultiDragHandler(),this.setupVertexMarkerStyleListener(),this.setupGeomanEvents(),this.options.enableAttributeEditing&&this.createAttributePanel(),this.geoman||this._autoInitGeoman(),this.container}onRemove(){this.removeKeyboardShortcuts(),this.removeSelectionHandler(),this.removeScaleHandler(),this.removeMultiDragHandler(),this.removeVertexMarkerStyleListener(),this.disableAllModes(),this.hideFeaturePropertiesPopup(),this.hideAttributePanel(),this.removeAttributePanel(),this.scaleFeature.destroy(),this.lassoFeature.destroy(),this.splitFeature.destroy(),this.freehandFeature.destroy(),this.fileInput&&this.fileInput.parentNode&&(this.fileInput.parentNode.removeChild(this.fileInput),this.fileInput=null),this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.map=void 0}setGeoman(e){this.geoman=e,this.setupGeomanEvents(),this.applySnappingState(),this.options.hideGeomanControl&&this.hideGeomanControl()}_autoInitGeoman(){Promise.resolve().then(()=>require("./maplibre-geoman.es-D7gaavHL.cjs")).then(({Geoman:e})=>{if(this.map&&!this.geoman){const t=new e(this.map);t.addControls=async()=>{},t.removeControls=()=>{},this.setGeoman(t)}}).catch(()=>{})}hideGeomanControl(){if(this.geoman)try{this.geoman.removeControls()}catch{[".maplibregl-ctrl.geoman-controls",".gm-control",".maplibregl-ctrl-group.geoman",'[class*="geoman"]'].forEach(e=>{document.querySelectorAll(e).forEach(t=>{t.classList.contains("geo-editor-control")||(t.style.display="none")})})}}setupSelectionHandler(){this.boundClickHandler=e=>{if(!this.isSelectMode&&!this.pendingOperation||!this.geoman)return;const t=this.findFeatureByMouseEvent(e)||this.findFeatureAtPoint(e.lngLat.lng,e.lngLat.lat);if(t){const{feature:i,geomanData:n}=t;this.pendingOperation?(i.geometry.type==="Polygon"||i.geometry.type==="MultiPolygon")&&this.addToSelection(i,n):e.originalEvent.shiftKey?this.toggleFeatureSelection(i,n):this.selectFeatures([i],[n])}else!e.originalEvent.shiftKey&&!this.pendingOperation&&this.clearSelection()},this.map.on("click",this.boundClickHandler)}getClickToleranceKm(){const e=this.map.getZoom();return 40075/(512*Math.pow(2,e))*15}findFeatureAtPoint(e,t){if(!this.geoman)return null;const i=aa([e,t]);let n=null;const r=this.getClickToleranceKm();let s=[];const a=new Map;try{let l=0;this.geoman.features.forEach(h=>{const d=this.getGeomanFeature(h);if(!h||!d||!d.geometry){l++;return}const p=String(h.id??d.id??`feature-${l}`);s.push(d),a.set(p,h),a.set(`idx-${l}`,h),l++})}catch{try{s=(this.geoman.features.getAll().features||[]).filter(l=>l&&l.geometry)}catch{return null}}for(let l=0;l<s.length;l++){const h=s[l];if(!h||!h.geometry)continue;const d=String(h.id??`feature-${l}`),p=a.get(d)||a.get(`idx-${l}`);try{let g=!1;if(h.geometry.type==="Point")g=gb(i,aa(h.geometry.coordinates),{units:"kilometers"})<r;else if(h.geometry.type==="Polygon"||h.geometry.type==="MultiPolygon")g=la(i,h);else if(h.geometry.type==="LineString"||h.geometry.type==="MultiLineString"){const v=vA(h,i);g=v.properties.dist!==void 0&&v.properties.dist<r}if(g){const v=p||this.findGeomanDataForFeature(h);if(v){n={feature:h,geomanData:v};break}}}catch{}}return n}findFeatureByMouseEvent(e){if(!this.geoman||!e.originalEvent)return null;try{const t=this.geoman.features.getFeatureByMouseEvent({event:e}),i=this.getGeomanFeature(t);if(i&&t)return{feature:i,geomanData:t}}catch{}return null}findGeomanDataForFeature(e){if(!this.geoman)return null;let t=null;const i=this.getGeomanIdFromFeature(e);try{this.geoman.features.forEach(n=>{if(t)return;const r=this.getGeomanFeature(n);r&&(i&&String(r.id)===i||i&&this.getGeomanIdFromFeature(r)===i||JSON.stringify(r.geometry)===JSON.stringify(e.geometry))&&(t=n)})}catch{}return t}getGeomanIdFromFeature(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}removeSelectionHandler(){this.boundClickHandler&&(this.map.off("click",this.boundClickHandler),this.boundClickHandler=null)}setupScaleHandler(){this.boundScaleMouseDown=e=>{if(this.state.activeEditMode!=="scale")return;const t=this.getScaleHandleFromEvent(e);!t||!this.scaleTargetFeature||!this.scaleTargetGeomanData||(e.preventDefault(),this.isScaling=!0,this.scaleStartFeature=this.scaleTargetFeature,this.disableScaleDragPan(),this.scaleFeature.startScale(this.scaleTargetFeature,t,[e.lngLat.lng,e.lngLat.lat],(i,n)=>{this.applyScaledFeature(i),this.emitEvent("gm:scale",{feature:i,scaleFactor:n})}),this.emitEvent("gm:scalestart",{feature:this.scaleTargetFeature}))},this.boundScaleMouseMove=e=>{if(!this.isScaling)return;const t=this.scaleFeature.updateScale([e.lngLat.lng,e.lngLat.lat]);t&&this.applyScaledFeature(t)},this.boundScaleMouseUp=()=>{if(!this.isScaling)return;this.isScaling=!1;const e=this.scaleFeature.endScale();this.restoreScaleDragPan(),e&&(this.applyScaledFeature(e.feature),this.scaleStartFeature&&this.options.onFeatureEdit?.(e.feature,this.scaleStartFeature),this.lastEditedFeature=e.feature,this.logSelectedFeatureCollection("edited",e.feature),this.scaleFeature.showHandlesForFeature(e.feature),this.bringScaleHandlesToFront(),this.emitEvent("gm:scaleend",{feature:e.feature,scaleFactor:e.factor})),this.scaleStartFeature=null},this.map.on("mousedown",this.boundScaleMouseDown),this.map.on("mousemove",this.boundScaleMouseMove),this.map.on("mouseup",this.boundScaleMouseUp)}removeScaleHandler(){this.boundScaleMouseDown&&(this.map.off("mousedown",this.boundScaleMouseDown),this.boundScaleMouseDown=null),this.boundScaleMouseMove&&(this.map.off("mousemove",this.boundScaleMouseMove),this.boundScaleMouseMove=null),this.boundScaleMouseUp&&(this.map.off("mouseup",this.boundScaleMouseUp),this.boundScaleMouseUp=null)}setupMultiDragHandler(){this.boundMultiDragMouseDown=e=>{if(this.state.activeEditMode!=="drag"||this.state.selectedFeatures.length<2)return;const t=this.findFeatureByMouseEvent(e)||this.findFeatureAtPoint(e.lngLat.lng,e.lngLat.lat);if(!t)return;const i=this.getGeomanIdFromFeature(t.feature);this.state.selectedFeatures.some(n=>this.getGeomanIdFromFeature(n.feature)===i)&&(e.preventDefault(),this.isMultiDragging=!0,this.multiDragStartPoint=[e.lngLat.lng,e.lngLat.lat],this.multiDragOriginalFeatures=this.state.selectedFeatures.map(n=>Go(n.feature)),this.multiDragGeomanData=this.state.selectedFeatures.map(n=>n.geomanData??this.findGeomanDataForFeature(n.feature)),this.disableMultiDragPan())},this.boundMultiDragMouseMove=e=>{if(!this.isMultiDragging||!this.multiDragStartPoint)return;const t=this.multiDragStartPoint,i=[e.lngLat.lng,e.lngLat.lat],n=gb(aa(t),aa(i),{units:"kilometers"}),r=Bj(aa(t),aa(i)),s=[];this.multiDragOriginalFeatures.forEach((a,l)=>{const h=b6(a,n,r,{units:"kilometers"}),d=this.multiDragGeomanData[l];d?.updateGeometry?d.updateGeometry(h.geometry):d?.updateGeoJsonGeometry&&d.updateGeoJsonGeometry(h.geometry),s.push(h)}),this.state.selectedFeatures=this.state.selectedFeatures.map((a,l)=>({...a,feature:s[l]??a.feature})),this.updateSelectionHighlight()},this.boundMultiDragMouseUp=()=>{this.isMultiDragging&&(this.isMultiDragging=!1,this.restoreMultiDragPan(),this.state.selectedFeatures.length>0&&(this.state.selectedFeatures.forEach((e,t)=>{const i=this.multiDragOriginalFeatures[t];i&&this.options.onFeatureEdit?.(e.feature,i)}),this.lastEditedFeature=this.state.selectedFeatures[this.state.selectedFeatures.length-1]?.feature??null,this.logSelectedFeatureCollection("edited",this.lastEditedFeature)),this.multiDragStartPoint=null,this.multiDragOriginalFeatures=[],this.multiDragGeomanData=[])},this.map.on("mousedown",this.boundMultiDragMouseDown),this.map.on("mousemove",this.boundMultiDragMouseMove),this.map.on("mouseup",this.boundMultiDragMouseUp)}removeMultiDragHandler(){this.boundMultiDragMouseDown&&(this.map.off("mousedown",this.boundMultiDragMouseDown),this.boundMultiDragMouseDown=null),this.boundMultiDragMouseMove&&(this.map.off("mousemove",this.boundMultiDragMouseMove),this.boundMultiDragMouseMove=null),this.boundMultiDragMouseUp&&(this.map.off("mouseup",this.boundMultiDragMouseUp),this.boundMultiDragMouseUp=null)}disableMultiDragPan(){this.multiDragPanEnabled=this.map.dragPan.isEnabled(),this.multiDragPanEnabled&&this.map.dragPan.disable()}restoreMultiDragPan(){this.multiDragPanEnabled&&this.map.dragPan.enable(),this.multiDragPanEnabled=null}getScaleHandleFromEvent(e){if(!this.map.getLayer(Zi.SCALE_HANDLES_LAYER))return null;const t=this.map.queryRenderedFeatures(e.point,{layers:[Zi.SCALE_HANDLES_LAYER]});if(!t.length)return null;const i=t[0].properties?.position;return typeof i=="string"?i:null}disableScaleDragPan(){this.scaleDragPanEnabled=this.map.dragPan.isEnabled(),this.scaleDragPanEnabled&&this.map.dragPan.disable()}restoreScaleDragPan(){this.scaleDragPanEnabled&&this.map.dragPan.enable(),this.scaleDragPanEnabled=null}applyScaledFeature(e){if(this.scaleTargetGeomanData?.updateGeometry?this.scaleTargetGeomanData.updateGeometry(e.geometry):this.scaleTargetGeomanData?.updateGeoJsonGeometry&&this.scaleTargetGeomanData.updateGeoJsonGeometry(e.geometry),this.state.selectedFeatures.length>0){const t=this.state.selectedFeatures[0];this.state.selectedFeatures[0]={...t,id:String(this.scaleTargetGeomanData?.id??e.id??t.id),feature:e,geomanData:this.scaleTargetGeomanData??t.geomanData},this.scaleTargetFeature=e}this.updateSelectionHighlight(),this.bringScaleHandlesToFront()}bringScaleHandlesToFront(){if(this.map.getLayer(Zi.SCALE_HANDLES_LAYER))try{this.map.moveLayer(Zi.SCALE_HANDLES_LAYER)}catch{}}logSelectedFeatureCollection(e,t){const i=t?this.getGeomanIdFromFeature(t):null;console.log("GeoEditor",{action:e,featureId:i,feature:t,selection:this.getSelectedFeatureCollection()})}extractFeatureFromEvent(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.getGeoJson=="function")try{return t.getGeoJson()}catch{return null}return t.geoJson?t.geoJson:"geometry"in t?t:null}toggleFeatureSelection(e,t){const i=t??this.findGeomanDataForFeature(e),n=String(i?.id??e.id);this.state.selectedFeatures.some(r=>r.id===n)?this.removeFromSelection(n):this.addToSelection(e,i??void 0)}enableSelectMode(){this.disableAllModes(),this.isSelectMode=!0,this.map.getCanvas().style.cursor="pointer",this.updateToolbarState()}disableSelectMode(){this.isSelectMode=!1,this.map.getCanvas().style.cursor=""}getState(){return{...this.state}}getSelectedFeatures(){return this.state.selectedFeatures.map(e=>e.feature)}getSelectedFeatureCollection(){return{type:"FeatureCollection",features:this.getSelectedFeatures()}}getFeatures(){if(this.geoman)try{return this.geoman.features.getAll()}catch{const e=[];return this.geoman.features.forEach(t=>{const i=this.getGeomanFeature(t);i&&e.push(i)}),{type:"FeatureCollection",features:e}}return{type:"FeatureCollection",features:[]}}getAllFeatureCollection(){return this.getFeatures()}getLastCreatedFeature(){return this.lastCreatedFeature}getLastEditedFeature(){return this.lastEditedFeature}getLastDeletedFeature(){return this.lastDeletedFeature}getLastDeletedFeatureId(){return this.lastDeletedFeatureId}enableDrawMode(e){this.disableAllModes(),e==="freehand"?this.enableFreehandMode():this.geoman&&(this.geoman.enableDraw(e),setTimeout(()=>this.applyVertexMarkerStyles(),50)),this.state.activeDrawMode=e,this.state.isDrawing=!0,this.options.onModeChange?.(e),this.updateToolbarState()}applyVertexMarkerStyles(){if(!this.map)return;const e=this.map.getStyle();if(!(!e||!e.layers))for(const t of e.layers){const i=t.id.toLowerCase();if(t.type==="circle"&&(i.includes("gm-")||i.includes("geoman")||i.includes("marker")||i.includes("vertex")||i.includes("handle")||i.includes("temp")))try{this.map.getLayer(t.id)&&(this.map.setPaintProperty(t.id,"circle-opacity",.5),this.map.setPaintProperty(t.id,"circle-stroke-opacity",.8))}catch{}}}setupVertexMarkerStyleListener(){this.map&&(this.boundStyleDataHandler=()=>{this.state.isDrawing&&this.applyVertexMarkerStyles()},this.map.on("styledata",this.boundStyleDataHandler))}removeVertexMarkerStyleListener(){this.map&&this.boundStyleDataHandler&&(this.map.off("styledata",this.boundStyleDataHandler),this.boundStyleDataHandler=null)}enableFreehandMode(){this.freehandFeature.enable(e=>{e.success&&e.feature&&this.geoman&&this.geoman.features.importGeoJsonFeature(e.feature)&&(this.options.onFeatureCreate?.(e.feature),this.emitEvent("gm:create",{feature:e.feature}))})}disableFreehandMode(){this.freehandFeature.disable()}enableEditMode(e){if(this.disableAllModes(),l8.includes(e))this.enableAdvancedEditMode(e);else if(this.geoman)switch(e){case"drag":this.state.selectedFeatures.length<2&&this.geoman.enableGlobalDragMode();break;case"change":this.geoman.enableGlobalEditMode();break;case"rotate":this.geoman.enableGlobalRotateMode();break;case"cut":this.geoman.enableGlobalCutMode();break;case"delete":if(this.state.selectedFeatures.length>0){this.deleteSelectedFeatures();return}this.geoman.enableGlobalRemovalMode();break}this.state.activeEditMode=e,this.state.isEditing=!0,this.options.onModeChange?.(e),this.updateToolbarState()}disableAllModes(){this.geoman&&this.geoman.disableAllModes(),this.scaleFeature.cancelScale(),this.lassoFeature.disable(),this.splitFeature.cancelSplit(),this.disableFreehandMode(),this.disableSelectMode(),this.restoreScaleDragPan(),this.restoreMultiDragPan(),this.isMultiDragging=!1,this.multiDragStartPoint=null,this.multiDragOriginalFeatures=[],this.multiDragGeomanData=[],this.isScaling=!1,this.scaleTargetFeature=null,this.scaleTargetGeomanData=null,this.scaleStartFeature=null,this.pendingOperation=null,this.map.getCanvas().style.cursor="",this.state.activeDrawMode=null,this.state.activeEditMode=null,this.state.isDrawing=!1,this.state.isEditing=!1,this.updateToolbarState(),this.applySnappingState()}enableAdvancedEditMode(e){switch(e){case"select":this.enableSelectMode();break;case"scale":this.enableScaleMode();break;case"copy":this.enableCopyMode();break;case"split":this.enableSplitMode();break;case"union":this.enableUnionMode();break;case"difference":this.enableDifferenceMode();break;case"simplify":this.executeSimplify();break;case"lasso":this.enableLassoMode();break}}enableUnionMode(){if(ME(this.getSelectedFeatures()).length>=2){this.executeUnion();return}this.pendingOperation="union",this.map.getCanvas().style.cursor="pointer"}enableDifferenceMode(){if(ME(this.getSelectedFeatures()).length>=2){this.executeDifference();return}this.pendingOperation="difference",this.map.getCanvas().style.cursor="pointer"}executePendingOperation(){this.pendingOperation&&(this.pendingOperation==="union"?this.executeUnion():this.pendingOperation==="difference"&&this.executeDifference(),this.pendingOperation=null)}cancelPendingOperation(){this.pendingOperation=null,this.clearSelection(),this.map.getCanvas().style.cursor="",this.updateToolbarState()}setupSelectionHighlight(){if(this.map)if(!this.map.getSource(Zi.SELECTION_SOURCE))this.map.addSource(Zi.SELECTION_SOURCE,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:Zi.SELECTION_FILL_LAYER,type:"fill",source:Zi.SELECTION_SOURCE,filter:["match",["geometry-type"],["Polygon","MultiPolygon"],!0,!1],paint:{"fill-color":"#ffff00","fill-opacity":.3}}),this.map.addLayer({id:Zi.SELECTION_LINE_LAYER,type:"line",source:Zi.SELECTION_SOURCE,paint:{"line-color":"#ff9900","line-width":5,"line-opacity":1,"line-dasharray":[3,2]}}),this.map.addLayer({id:Zi.SELECTION_CIRCLE_LAYER,type:"circle",source:Zi.SELECTION_SOURCE,filter:["==",["geometry-type"],"Point"],paint:{"circle-radius":12,"circle-color":"#ffff00","circle-opacity":.5,"circle-stroke-color":"#ff9900","circle-stroke-width":3,"circle-stroke-opacity":1}});else try{this.map.getLayer(Zi.SELECTION_FILL_LAYER)&&(this.map.setFilter(Zi.SELECTION_FILL_LAYER,["match",["geometry-type"],["Polygon","MultiPolygon"],!0,!1]),this.map.moveLayer(Zi.SELECTION_FILL_LAYER)),this.map.getLayer(Zi.SELECTION_LINE_LAYER)&&this.map.moveLayer(Zi.SELECTION_LINE_LAYER),this.map.getLayer(Zi.SELECTION_CIRCLE_LAYER)&&this.map.moveLayer(Zi.SELECTION_CIRCLE_LAYER)}catch{}}updateSelectionHighlight(){if(!this.map)return;this.setupSelectionHighlight();const e=this.map.getSource(Zi.SELECTION_SOURCE);if(e){const t=this.getSelectedFeatures();e.setData({type:"FeatureCollection",features:t})}}selectFeatures(e,t){const i=t&&t.length?t:e.map(r=>this.findGeomanDataForFeature(r)),n=Date.now();this.state.selectedFeatures=e.map((r,s)=>({id:String(i?.[s]?.id??r.id??`${n}-${s}`),feature:r,layerId:"default",geomanData:i?.[s]??void 0})),this.updateSelectionHighlight(),this.options.onSelectionChange?.(e),this.logSelectedFeatureCollection("selected"),e.length===1&&this.isSelectMode?this.options.enableAttributeEditing?this.showAttributePanel(e[0],i?.[0]??void 0,!1):this.options.showFeatureProperties&&this.showFeaturePropertiesPopup(e[0]):(this.hideAttributePanel(),this.hideFeaturePropertiesPopup())}addToSelection(e,t){const i=t??this.findGeomanDataForFeature(e),n=String(i?.id??e.id);this.state.selectedFeatures.some(r=>r.id===n)||(this.state.selectedFeatures.push({id:n,feature:e,layerId:"default",geomanData:i??void 0}),this.updateSelectionHighlight(),this.options.onSelectionChange?.(this.getSelectedFeatures()),this.logSelectedFeatureCollection("selected"))}removeFromSelection(e){this.state.selectedFeatures=this.state.selectedFeatures.filter(t=>t.id!==e),this.updateSelectionHighlight(),this.options.onSelectionChange?.(this.getSelectedFeatures()),this.logSelectedFeatureCollection("selected")}clearSelection(){this.state.selectedFeatures=[],this.updateSelectionHighlight(),this.hideFeaturePropertiesPopup(),this.hideAttributePanel(),this.options.onSelectionChange?.([]),this.logSelectedFeatureCollection("selected")}showFeaturePropertiesPopup(e){if(!this.options.showFeatureProperties||!e.properties||Object.keys(e.properties).length===0)return;this.hideFeaturePropertiesPopup();const t=jb(e).geometry.coordinates,i=this.formatPropertiesHtml(e.properties);this.propertiesPopup=new ks.default.Popup({maxWidth:"300px",closeButton:!0,closeOnClick:!1,className:"geo-editor-properties-popup"}).setLngLat(t).setHTML(i).addTo(this.map)}hideFeaturePropertiesPopup(){this.propertiesPopup&&(this.propertiesPopup.remove(),this.propertiesPopup=null)}formatPropertiesHtml(e){const t=Object.entries(e).filter(([i])=>!i.startsWith("__"));return t.length===0?'<div class="geo-editor-popup-empty">No properties</div>':`<table class="geo-editor-popup-table"><tbody>${t.map(([i,n])=>{const r=n==null?"<em>null</em>":typeof n=="object"?this.escapeHtml(JSON.stringify(n)):this.escapeHtml(String(n));return`<tr><td class="geo-editor-popup-key">${this.escapeHtml(i)}</td><td class="geo-editor-popup-value">${r}</td></tr>`}).join("")}</tbody></table>`}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}createAttributePanel(){if(this.attributePanel)return;const e=this.options.attributePanelPosition,t=this.options.attributePanelWidth,i=this.options.attributePanelMaxHeight,n=this.options.attributePanelTop,r=this.options.attributePanelSideOffset;this.attributePanel=document.createElement("div"),this.attributePanel.className=`${Pi}-attribute-panel ${Pi}-attribute-panel--${e} ${Pi}-attribute-panel--hidden`,this.attributePanel.style.width=`${t}px`,this.attributePanel.style.maxHeight=typeof i=="number"?`${i}px`:i,this.attributePanel.style.top=`${n}px`,e==="right"?this.attributePanel.style.right=`${r}px`:this.attributePanel.style.left=`${r}px`;const s=document.createElement("div");s.className=`${Pi}-attribute-panel-header`;const a=document.createElement("h3");a.className=`${Pi}-attribute-panel-title`,a.textContent=this.options.attributePanelTitle,s.appendChild(a);const l=document.createElement("button");l.className=`${Pi}-attribute-panel-close`,l.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M1 1l12 12M13 1L1 13"/></svg>',l.title="Close",l.addEventListener("click",()=>this.hideAttributePanel()),s.appendChild(l),this.attributePanel.appendChild(s);const h=document.createElement("div");h.className=`${Pi}-attribute-panel-body`,h.setAttribute("data-panel-body","true"),this.attributePanel.appendChild(h);const d=document.createElement("div");d.className=`${Pi}-attribute-panel-footer`;const p=document.createElement("button");p.className=`${Pi}-btn ${Pi}-btn--secondary`,p.textContent="Cancel",p.addEventListener("click",()=>this.hideAttributePanel()),d.appendChild(p);const g=document.createElement("button");g.className=`${Pi}-btn ${Pi}-btn--primary`,g.textContent="Save",g.setAttribute("data-save-btn","true"),g.addEventListener("click",()=>this.saveAttributeChanges()),d.appendChild(g),this.attributePanel.appendChild(d),this.map.getContainer().appendChild(this.attributePanel)}removeAttributePanel(){this.attributePanel&&this.attributePanel.parentNode&&(this.attributePanel.parentNode.removeChild(this.attributePanel),this.attributePanel=null)}showAttributePanel(e,t,i=!1){this.attributePanel&&(this.currentEditingFeature=e,this.currentEditingGeomanData=t??null,this.isNewFeature=i,this.originalProperties=e.properties?{...e.properties}:{},this.buildAttributeForm(e),this.attributePanel.classList.remove(`${Pi}-attribute-panel--hidden`),this.attributePanelVisible=!0,this.hideFeaturePropertiesPopup())}hideAttributePanel(){this.attributePanel&&(this.attributePanel.classList.add(`${Pi}-attribute-panel--hidden`),this.attributePanelVisible=!1,this.currentEditingFeature=null,this.currentEditingGeomanData=null,this.isNewFeature=!1,this.originalProperties=null)}toggleAttributePanel(){this.attributePanelVisible?this.hideAttributePanel():this.currentEditingFeature&&this.showAttributePanel(this.currentEditingFeature,this.currentEditingGeomanData??void 0,this.isNewFeature)}getSchemaFieldsForGeometry(e){const t=this.options.attributeSchema;if(!t)return[];const i=[];return e==="Polygon"||e==="MultiPolygon"?t.polygon&&i.push(...t.polygon):e==="LineString"||e==="MultiLineString"?t.line&&i.push(...t.line):(e==="Point"||e==="MultiPoint")&&t.point&&i.push(...t.point),t.common&&i.push(...t.common),i}getExtraProperties(e){const t=e.properties||{},i=this.getSchemaFieldsForGeometry(e.geometry.type),n=new Set(i.map(s=>s.name)),r={};for(const[s,a]of Object.entries(t))!s.startsWith("__")&&!n.has(s)&&(r[s]=a);return r}buildAttributeForm(e){if(!this.attributePanel)return;const t=this.attributePanel.querySelector("[data-panel-body]");if(!t)return;t.innerHTML="";const i=e.geometry.type,n=this.getSchemaFieldsForGeometry(i),r=e.properties||{},s=this.attributePanel.querySelector(`.${Pi}-attribute-panel-header`);if(s){const h=s.querySelector(`.${Pi}-attribute-geometry-badge`);h&&h.remove();const d=document.createElement("span");d.className=`${Pi}-attribute-geometry-badge`,d.textContent=this.getGeometryDisplayName(i);const p=s.querySelector(`.${Pi}-attribute-panel-title`);p&&p.appendChild(d)}if(n.length>0)n.forEach(h=>{const d=r[h.name],p=this.createFormField(h,d);t.appendChild(p)});else{const h=document.createElement("div");h.className=`${Pi}-attribute-empty`,h.textContent="No attribute schema defined",t.appendChild(h)}const a=this.getExtraProperties(e),l=Object.keys(a);if(l.length>0){const h=document.createElement("div");h.className=`${Pi}-attribute-extra-section`;const d=document.createElement("div");d.className=`${Pi}-attribute-extra-section-title`,d.textContent="Other Properties",h.appendChild(d),l.forEach(p=>{const g=this.createReadOnlyField(p,a[p]);h.appendChild(g)}),t.appendChild(h)}}getGeometryDisplayName(e){return{Point:"Point",MultiPoint:"Multi-Point",LineString:"Line",MultiLineString:"Multi-Line",Polygon:"Polygon",MultiPolygon:"Multi-Polygon",GeometryCollection:"Collection"}[e]||e}createFormField(e,t){const i=document.createElement("div");i.className=`${Pi}-attribute-form-group`;const n=document.createElement("label");n.className=`${Pi}-attribute-label`,e.required&&n.classList.add(`${Pi}-attribute-label--required`),n.textContent=e.label||e.name,n.setAttribute("for",`attr-${e.name}`),i.appendChild(n);const r=this.createInputForFieldType(e,t);return i.appendChild(r),i}createInputForFieldType(e,t){const i=`attr-${e.name}`;switch(e.type){case"boolean":{const n=document.createElement("div");n.className=`${Pi}-attribute-checkbox-wrapper`;const r=document.createElement("input");r.type="checkbox",r.id=i,r.name=e.name,r.className=`${Pi}-attribute-checkbox`,r.checked=t===!0||t==="true",r.disabled=e.readOnly??!1,n.appendChild(r);const s=document.createElement("label");return s.className=`${Pi}-attribute-checkbox-label`,s.setAttribute("for",i),s.textContent=e.label||e.name,n.appendChild(s),n}case"select":{const n=document.createElement("select");if(n.id=i,n.name=e.name,n.className=`${Pi}-attribute-select`,n.disabled=e.readOnly??!1,!e.required){const r=document.createElement("option");r.value="",r.textContent="-- Select --",n.appendChild(r)}return e.options&&e.options.forEach(r=>{const s=document.createElement("option");s.value=String(r.value),s.textContent=r.label,String(t)===String(r.value)&&(s.selected=!0),n.appendChild(s)}),n}case"textarea":{const n=document.createElement("textarea");return n.id=i,n.name=e.name,n.className=`${Pi}-attribute-textarea`,n.value=t!=null?String(t):"",n.placeholder=e.placeholder||"",n.disabled=e.readOnly??!1,n}case"number":{const n=document.createElement("input");return n.type="number",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"",n.placeholder=e.placeholder||"",n.disabled=e.readOnly??!1,e.min!==void 0&&(n.min=String(e.min)),e.max!==void 0&&(n.max=String(e.max)),e.step!==void 0&&(n.step=String(e.step)),n}case"date":{const n=document.createElement("input");return n.type="date",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"",n.disabled=e.readOnly??!1,n}case"color":{const n=document.createElement("input");return n.type="color",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"#000000",n.disabled=e.readOnly??!1,n}default:{const n=document.createElement("input");return n.type="text",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"",n.placeholder=e.placeholder||"",n.disabled=e.readOnly??!1,n}}}createReadOnlyField(e,t){const i=document.createElement("div");i.className=`${Pi}-attribute-form-group`;const n=document.createElement("label");n.className=`${Pi}-attribute-label`,n.textContent=e,i.appendChild(n);const r=document.createElement("div");return r.className=`${Pi}-attribute-readonly`,t==null?(r.classList.add(`${Pi}-attribute-readonly-null`),r.textContent="null"):typeof t=="object"?r.textContent=JSON.stringify(t):r.textContent=String(t),i.appendChild(r),i}collectFormValues(){if(!this.attributePanel||!this.currentEditingFeature)return{};const e=this.attributePanel.querySelector("[data-panel-body]");if(!e)return{};const t={};return this.getSchemaFieldsForGeometry(this.currentEditingFeature.geometry.type).forEach(i=>{const n=e.querySelector(`[name="${i.name}"]`);if(n)if(i.type==="boolean")t[i.name]=n.checked;else if(i.type==="number"){const r=n.value.trim();t[i.name]=r!==""?parseFloat(r):null}else t[i.name]=n.value||null}),t}validateFormValues(e){if(!this.currentEditingFeature)return{valid:!0,errors:{}};const t=this.getSchemaFieldsForGeometry(this.currentEditingFeature.geometry.type),i={};return t.forEach(n=>{if(n.required){const r=e[n.name];(r==null||r==="")&&(i[n.name]=`${n.label||n.name} is required`)}}),{valid:Object.keys(i).length===0,errors:i}}showValidationErrors(e){if(!this.attributePanel)return;const t=this.attributePanel.querySelector("[data-panel-body]");t&&(t.querySelectorAll(`.${Pi}-attribute-error`).forEach(i=>i.remove()),t.querySelectorAll(`.${Pi}-attribute-input--error, .${Pi}-attribute-select--error, .${Pi}-attribute-textarea--error`).forEach(i=>{i.classList.remove(`${Pi}-attribute-input--error`),i.classList.remove(`${Pi}-attribute-select--error`),i.classList.remove(`${Pi}-attribute-textarea--error`)}),Object.entries(e).forEach(([i,n])=>{const r=t.querySelector(`[name="${i}"]`);if(r){r.classList.add(`${Pi}-attribute-input--error`);const s=document.createElement("div");s.className=`${Pi}-attribute-error`,s.textContent=n,r.parentNode?.appendChild(s)}}))}applyDefaultValues(e){const t=this.getSchemaFieldsForGeometry(e.geometry.type);t.length!==0&&(e.properties||(e.properties={}),t.forEach(i=>{i.defaultValue!==void 0&&e.properties[i.name]===void 0&&(e.properties[i.name]=i.defaultValue)}))}saveAttributeChanges(){if(!this.currentEditingFeature)return;const e=this.collectFormValues(),t=this.validateFormValues(e);if(!t.valid){this.showValidationErrors(t.errors);return}const i={...this.currentEditingFeature.properties,...e};this.currentEditingFeature.properties=i,this.currentEditingGeomanData&&this.updateFeatureProperties(this.currentEditingGeomanData,i);const n={feature:this.currentEditingFeature,previousProperties:this.originalProperties??{},newProperties:i,isNewFeature:this.isNewFeature};this.options.onAttributeChange?.(n),this.hideAttributePanel()}updateFeatureProperties(e,t){const i=e.getGeoJson?e.getGeoJson():e.geoJson;i&&(i.properties=t)}openAttributeEditor(e){if(!this.options.enableAttributeEditing){console.warn("Attribute editing is not enabled");return}const t=this.findGeomanDataForFeature(e);this.showAttributePanel(e,t??void 0,!1)}closeAttributeEditor(){this.hideAttributePanel()}setAttributeSchema(e){this.options.attributeSchema=e,this.attributePanelVisible&&this.currentEditingFeature&&this.buildAttributeForm(this.currentEditingFeature)}getAttributeSchema(){return this.options.attributeSchema}enableScaleMode(){this.scaleTargetFeature=null,this.scaleTargetGeomanData=null;const e=this.getSelectedFeatures();if(e.length===0){console.warn("Select a feature to scale");return}const t=this.findGeomanDataForFeature(e[0]);if(!t){console.warn("Selected feature is not managed by Geoman");return}this.scaleTargetFeature=e[0],this.scaleTargetGeomanData=t,this.scaleFeature.showHandlesForFeature(e[0]),this.bringScaleHandlesToFront(),this.state.selectedFeatures.length>0&&(this.state.selectedFeatures[0]={...this.state.selectedFeatures[0],id:String(t.id),geomanData:t}),this.map.getCanvas().style.cursor="nwse-resize"}enableCopyMode(){this.copySelectedFeatures()}enableSplitMode(){const e=this.getSelectedFeatures();if(e.length===0){console.warn("Select a polygon or line to split");return}const t=e[0];if(!AJ(t)&&!jue(t)){console.warn("Can only split polygons and lines");return}this.splitFeature.startSplit(t,i=>{this.handleSplitResult(i)})}enableLassoMode(){this.lassoFeature.enable(e=>{this.handleLassoResult(e)})}executeUnion(){const e=ME(this.getSelectedFeatures());if(e.length<2){console.warn("Select at least 2 polygons to merge");return}const t=this.unionFeature.union(e);this.handleUnionResult(t)}executeDifference(){const e=ME(this.getSelectedFeatures());if(e.length<2){console.warn("Select at least 2 polygons (first is base, rest are subtracted)");return}const[t,...i]=e,n=this.differenceFeature.difference(t,i);this.handleDifferenceResult(n)}executeSimplify(){let e=this.getSelectedFeatures();if(e.length===0&&this.lastCreatedFeature&&(e=[this.lastCreatedFeature]),e.length===0){console.warn("Select a feature to simplify");return}const t=e.map(n=>this.getSimplifyResult(n)).filter(n=>!!n),i=t.length>1;if(t.length===0){console.warn("Simplify: no vertices removed with current tolerance");return}t.forEach(n=>{this.applySimplifyResult(n,{clearSelection:!i,disableModes:!i}),this.logSelectedFeatureCollection("edited",n.result)}),i&&(this.clearSelection(),this.disableAllModes())}getSimplifyResult(e){const t=this.simplifyFeature.simplifyWithStats(e);if(t.verticesAfter<t.verticesBefore)return t;const i=this.simplifyFeature.getSuggestedTolerances(e);for(const n of i){if(n===this.options.simplifyTolerance)continue;const r=this.simplifyFeature.simplifyWithStats(e,{tolerance:n});if(r.verticesAfter<r.verticesBefore)return r}return null}copySelectedFeatures(){const e=this.getSelectedFeatures();if(e.length===0){console.warn("No features selected to copy");return}this.state.clipboard=this.copyFeature.copyMultiple(e),this.emitEvent("gm:copy",{features:e})}pasteFeatures(){if(this.state.clipboard.length===0){console.warn("Clipboard is empty");return}const e=this.copyFeature.copyMultiple(this.state.clipboard);this.geoman&&e.forEach(t=>{this.geoman?.features.importGeoJsonFeature(t),this.options.onFeatureCreate?.(t),this.lastCreatedFeature=t}),this.emitEvent("gm:paste",{features:e})}deleteFeatureById(e){if(this.geoman)try{const t=[];this.geoman.features.forEach(i=>{const n=this.getGeomanFeature(i),r=n?.properties;(String(i.id)===e||String(n?.id)===e||String(r?.__gm_id)===e)&&t.push(i)}),t.forEach(i=>{this.deleteGeomanFeatureData(i)})}catch{}}deleteSelectedFeatures(){const e=this.state.selectedFeatures;e.length!==0&&(e.forEach(t=>{const i=t.geomanData??this.findGeomanDataForFeature(t.feature);this.deleteGeomanFeatureData(i,t.id),this.options.onFeatureDelete?.(t.id),this.lastDeletedFeature=t.feature,this.lastDeletedFeatureId=t.id,this.logSelectedFeatureCollection("deleted",t.feature)}),this.clearSelection())}deleteGeomanFeatureData(e,t){if(this.geoman){if(e){try{this.geoman.features.delete(e);return}catch{}try{e.delete();return}catch{}}t&&this.deleteFeatureById(t)}}deleteGeomanFeatures(e){e.forEach(t=>{const i=this.findGeomanDataForFeature(t),n=this.getGeomanIdFromFeature(t);this.deleteGeomanFeatureData(i,n??void 0),n&&this.options.onFeatureDelete?.(n),this.lastDeletedFeature=t,this.lastDeletedFeatureId=n??null,this.logSelectedFeatureCollection("deleted",t)})}clearGeomanTemporaryFeatures(){if(this.geoman)try{if(typeof this.geoman.features.tmpForEach=="function"){this.geoman.features.tmpForEach(e=>{try{e.delete()}catch{}});return}this.geoman.features.forEach(e=>{if(e.temporary)try{e.delete()}catch{}})}catch{}}handleSplitResult(e){if(!e.success){console.warn("Split failed:",e.error);return}this.recordCompositeOperation([e.original],e.parts,"Split"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures([e.original]),this.clearGeomanTemporaryFeatures(),this.clearSelection(),this.geoman&&e.parts.forEach(t=>{this.geoman?.features.importGeoJsonFeature(t),this.options.onFeatureCreate?.(t),this.lastCreatedFeature=t,this.logSelectedFeatureCollection("created",t)})}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:split",e),this.disableAllModes()}handleUnionResult(e){if(!e.success||!e.result){console.warn("Union failed:",e.error);return}this.recordCompositeOperation(e.originals,[e.result],"Union"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures(e.originals),this.clearGeomanTemporaryFeatures(),this.clearSelection(),this.geoman&&(this.geoman.features.importGeoJsonFeature(e.result),this.options.onFeatureCreate?.(e.result),this.lastCreatedFeature=e.result,this.logSelectedFeatureCollection("created",e.result))}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:union",e),this.disableAllModes()}handleDifferenceResult(e){if(!e.success){console.warn("Difference failed:",e.error);return}const t=[e.base,...e.subtracted],i=e.result?[e.result]:[];this.recordCompositeOperation(t,i,"Difference"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures([e.base,...e.subtracted]),this.clearGeomanTemporaryFeatures(),this.clearSelection(),e.result&&this.geoman&&(this.geoman.features.importGeoJsonFeature(e.result),this.options.onFeatureCreate?.(e.result),this.lastCreatedFeature=e.result,this.logSelectedFeatureCollection("created",e.result))}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:difference",e),this.disableAllModes()}applySimplifyResult(e,t){this.recordCompositeOperation([e.original],[e.result],"Simplify"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures([e.original]),this.clearGeomanTemporaryFeatures(),this.geoman&&(e.result.id=this.getGeomanIdFromFeature(e.original)??e.result.id,this.geoman.features.importGeoJsonFeature(e.result),this.options.onFeatureEdit?.(e.result,e.original),this.lastEditedFeature=e.result)}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:simplify",e),t.clearSelection&&this.clearSelection(),t.disableModes&&this.disableAllModes()}handleLassoResult(e){const t=this.getFeatures().features,i=this.lassoFeature.selectWithinLasso(e.lasso,t);this.selectFeatures(i),this.emitEvent("gm:lassoend",{...e,selected:i}),this.disableAllModes()}createToolbar(){this.toolbar=document.createElement("div"),this.toolbar.className=`${Pi}-toolbar ${Pi}-toolbar--${this.options.toolbarOrientation}`,this.options.toolbarOrientation==="vertical"&&this.options.columns>1&&this.toolbar.classList.add(`${Pi}-toolbar--columns-${this.options.columns}`),this.state.collapsed&&this.toolbar.classList.add(`${Pi}-toolbar--collapsed`);const e=this.createCollapseButton();this.toolbar.appendChild(e);const t=document.createElement("div");if(t.className=`${Pi}-tools-wrapper`,this.options.drawModes.length>0){const s=this.createToolGroup("Draw",this.options.drawModes,"draw");t.appendChild(s)}const i=this.options.editModes.filter(s=>!l8.includes(s));if(i.length>0){const s=this.createToolGroup("Edit",i,"edit");t.appendChild(s)}const n=this.options.editModes.filter(s=>l8.includes(s));if(n.length>0){const s=this.createToolGroup("Advanced",n,"edit");t.appendChild(s)}if(this.historyManager){const s=this.createHistoryToolsGroup();t.appendChild(s)}if(this.options.helperModes.includes("snapping")){const s=this.createHelperToolsGroup();t.appendChild(s)}if(this.options.fileModes&&this.options.fileModes.length>0){const s=this.createFileToolsGroup();t.appendChild(s)}const r=this.createResetToolsGroup();t.appendChild(r),this.toolbar.appendChild(t),this.state.collapsed&&(t.style.display="none"),this.container.appendChild(this.toolbar)}createCollapseButton(){const e=document.createElement("button");e.className=`${Pi}-tool-button ${Pi}-collapse-btn`,e.title=this.state.collapsed?"Expand toolbar":"Collapse toolbar";const t='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 0 0 0-1.41l-2.34-2.34a1 1 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" fill="currentColor"/></svg>',i='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" fill="currentColor"/></svg>';return e.innerHTML=this.state.collapsed?t:i,e.addEventListener("click",()=>{this.toggleCollapse(),e.innerHTML=this.state.collapsed?t:i,e.title=this.state.collapsed?"Expand toolbar":"Collapse toolbar"}),e}toggleCollapse(){if(this.state.collapsed=!this.state.collapsed,this.toolbar){this.toolbar.classList.toggle(`${Pi}-toolbar--collapsed`,this.state.collapsed);const e=this.toolbar.querySelector(`.${Pi}-tools-wrapper`);e&&(e.style.display=this.state.collapsed?"none":"")}this._emitControlEvent(this.state.collapsed?"collapse":"expand")}isCollapsed(){return this.state.collapsed}setCollapsed(e){this.state.collapsed!==e&&this.toggleCollapse()}expand(){this.setCollapsed(!1)}collapse(){this.setCollapsed(!0)}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}_emitControlEvent(e,t){const i=this._eventHandlers.get(e);i&&i.forEach(n=>n(t))}createHelperToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const n=document.createElement("div");n.className=`${Pi}-tool-group-label`,n.textContent="Helper",e.appendChild(n)}const t=document.createElement("div");t.className=`${Pi}-tool-buttons`;const i=document.createElement("button");return i.className=`${Pi}-tool-button`,i.dataset.helper="snapping",i.title="Toggle Snapping",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M7 3h4v6H7V3zm6 0h4v6h-4V3zM7 9h4v3a3 3 0 0 0 6 0V9h4v3a7 7 0 0 1-14 0V9z" fill="currentColor"/></svg>',this.snappingEnabled&&i.classList.add(`${Pi}-tool-button--active`),i.addEventListener("click",n=>{n.stopPropagation(),this.toggleSnapping(),i.classList.toggle(`${Pi}-tool-button--active`,this.snappingEnabled)}),t.appendChild(i),e.appendChild(t),e}createResetToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const n=document.createElement("div");n.className=`${Pi}-tool-group-label`,n.textContent="Reset",e.appendChild(n)}const t=document.createElement("div");t.className=`${Pi}-tool-buttons`;const i=document.createElement("button");return i.className=`${Pi}-tool-button`,i.title="Clear selection and disable tools",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M12 5a7 7 0 1 1-6.32 4H3l3.5-3.5L10 9H7.74A5 5 0 1 0 12 7v2l3-3-3-3v2z" fill="currentColor"/></svg>',i.addEventListener("click",()=>{this.disableAllModes(),this.clearSelection(),this.updateToolbarState()}),t.appendChild(i),e.appendChild(t),e}createFileToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const i=document.createElement("div");i.className=`${Pi}-tool-group-label`,i.textContent="File",e.appendChild(i)}const t=document.createElement("div");if(t.className=`${Pi}-tool-buttons`,this.options.fileModes.includes("open")){const i=document.createElement("button");i.className=`${Pi}-tool-button`,i.dataset.file="open",i.title="Open GeoJSON file",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M20 6h-8l-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V8h16v10z" fill="currentColor"/></svg>',i.addEventListener("click",()=>this.openFileDialog()),t.appendChild(i)}if(this.options.fileModes.includes("save")){const i=document.createElement("button");i.className=`${Pi}-tool-button`,i.dataset.file="save",i.title="Save GeoJSON file",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M17 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm2 16H5V5h11.17L19 7.83V19zm-7-7c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3zM6 6h9v4H6V6z" fill="currentColor"/></svg>',i.addEventListener("click",()=>this.saveGeoJson()),t.appendChild(i)}return e.appendChild(t),e}setupFileInput(){this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept=".geojson,.json,application/geo+json,application/json",this.fileInput.style.display="none",this.fileInput.addEventListener("change",e=>this.handleFileSelect(e)),document.body.appendChild(this.fileInput)}openFileDialog(){this.fileInput&&this.fileInput.click()}handleFileSelect(e){const t=e.target,i=t.files?.[0];if(!i)return;const n=new FileReader;n.onload=r=>{try{const s=r.target?.result,a=JSON.parse(s);this.loadGeoJson(a,i.name)}catch(s){console.error("GeoEditor: Failed to parse GeoJSON file:",s);const a={filename:i.name,message:s instanceof Error?s.message:String(s),error:s};this.emitEvent("gm:geojsonloaderror",a)}},n.readAsText(i),t.value=""}loadGeoJson(e,t="loaded.geojson"){if(!this.geoman)throw new Error("Geoman not initialized");try{this.geoman.features.deleteAll()}catch{this.geoman.features.forEach(s=>{try{s.delete()}catch{}})}this.clearSelection();let i;if(e.type==="Feature")i={type:"FeatureCollection",features:[e]};else if(e.type==="FeatureCollection")i=e;else throw new Error("Invalid GeoJSON: expected Feature or FeatureCollection");const n=this.geoman.features.importGeoJson(i),r={features:i.features,count:n.success,filename:t};return this.options.fitBoundsOnLoad&&i.features.length>0&&this.fitBoundsToFeatures(i),this.options.onGeoJsonLoad?.(r),this.emitEvent("gm:geojsonload",r),console.log(`GeoEditor: Loaded ${r.count} features from ${t}`),r}fitBoundsToFeatures(e){if(!(!e.features||e.features.length===0))try{const t=As(e);if(!this.isValidBBox(t)){console.warn("GeoEditor: Invalid bounding box for loaded features");return}const i=[[t[0],t[1]],[t[2],t[3]]];this.map.fitBounds(i,{padding:50,maxZoom:18,duration:500})}catch(t){console.warn("GeoEditor: Failed to fit bounds to features:",t)}}isValidBBox(e){return e.every(t=>isFinite(t)&&!isNaN(t))&&e[0]<=e[2]&&e[1]<=e[3]}fitToAllFeatures(){const e=this.getFeatures();if(e.features.length===0){console.warn("GeoEditor: No features to fit bounds to");return}this.fitBoundsToFeatures(e)}saveGeoJson(e){const t=this.getFeatures(),i=e||this.options.saveFilename||"features.geojson",n=new Blob([JSON.stringify(t,null,2)],{type:"application/geo+json"}),r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=i,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r);const a={featureCollection:t,count:t.features.length,filename:i};return this.options.onGeoJsonSave?.(a),this.emitEvent("gm:geojsonsave",a),console.log(`GeoEditor: Saved ${a.count} features to ${i}`),a}toggleSnapping(){this.snappingEnabled=!this.snappingEnabled,this.applySnappingState()}isSnappingEnabled(){return this.snappingEnabled}setSnapping(e){this.snappingEnabled=e,this.applySnappingState()}applySnappingState(){if(this.geoman)try{if(typeof this.geoman.enableMode=="function"){this.snappingEnabled?this.geoman.enableMode("helper","snapping"):this.geoman.disableMode("helper","snapping");return}const e=this.geoman;typeof e.setGlobalOptions=="function"?e.setGlobalOptions({snapping:this.snappingEnabled}):typeof e.enableSnapping=="function"&&this.snappingEnabled?e.enableSnapping():typeof e.disableSnapping=="function"&&!this.snappingEnabled&&e.disableSnapping()}catch{console.info("Snapping toggle: Geoman version does not support snapping.")}}createToolGroup(e,t,i){const n=document.createElement("div");if(n.className=`${Pi}-tool-group`,this.options.showLabels){const s=document.createElement("div");s.className=`${Pi}-tool-group-label`,s.textContent=e,n.appendChild(s)}const r=document.createElement("div");return r.className=`${Pi}-tool-buttons`,t.forEach(s=>{const a=this.createToolButton(s,i);r.appendChild(a)}),n.appendChild(r),n}createToolButton(e,t){const i=document.createElement("button");return i.className=`${Pi}-tool-button`,i.dataset.mode=e,i.dataset.type=t,i.title=this.getModeLabel(e),i.innerHTML=this.getModeIcon(e),i.addEventListener("click",()=>{t==="draw"?this.enableDrawMode(e):this.enableEditMode(e)}),i}updateToolbarState(){this.container.querySelectorAll(`.${Pi}-tool-button`).forEach(e=>{const t=e,i=t.dataset.mode,n=t.dataset.type;if(t.dataset.helper)return;let r=!1;n==="draw"?r=i===this.state.activeDrawMode:n==="edit"&&(i==="select"?r=this.isSelectMode:i==="union"?r=this.pendingOperation==="union":i==="difference"?r=this.pendingOperation==="difference":r=i===this.state.activeEditMode),t.classList.toggle(`${Pi}-tool-button--active`,r);const s=t.querySelector("svg");s&&s.querySelectorAll("path, polygon, rect, circle, ellipse, line, text").forEach(a=>{const l=a;l.style.fill="",l.style.stroke=""})})}getModeLabel(e){return{marker:"Marker",circle:"Circle",circle_marker:"Circle Marker",ellipse:"Ellipse",text_marker:"Text",line:"Line",rectangle:"Rectangle",polygon:"Polygon",freehand:"Freehand",select:"Select (click features)",drag:"Drag",change:"Edit",rotate:"Rotate",cut:"Cut",delete:"Delete",scale:"Scale",copy:"Copy",split:"Split",union:"Union (select 2+ polygons)",difference:"Difference (select 2+ polygons)",simplify:"Simplify",lasso:"Lasso Select"}[e]||e}getModeIcon(e){return{polygon:'<svg viewBox="0 0 24 24" width="18" height="18"><polygon points="12,2 22,8 18,22 6,22 2,8" fill="none" stroke="currentColor" stroke-width="2"/></svg>',line:'<svg viewBox="0 0 24 24" width="18" height="18"><line x1="4" y1="20" x2="20" y2="4" stroke="currentColor" stroke-width="2"/></svg>',rectangle:'<svg viewBox="0 0 24 24" width="18" height="18"><rect x="3" y="5" width="18" height="14" fill="none" stroke="currentColor" stroke-width="2"/></svg>',circle:'<svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/></svg>',marker:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z" fill="none" stroke="currentColor" stroke-width="2"/></svg>',select:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 3l6 14 2-6 6-2L4 3z" fill="currentColor"/><path d="M12.5 13.5l4.5 4.5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',drag:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z" fill="currentColor"/></svg>',change:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 0 0 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" fill="currentColor"/></svg>',rotate:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M17.65 6.35A7.958 7.958 0 0 0 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0 1 12 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" fill="currentColor"/></svg>',cut:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M9.64 7.64c.23-.5.36-1.05.36-1.64 0-2.21-1.79-4-4-4S2 3.79 2 6s1.79 4 4 4c.59 0 1.14-.13 1.64-.36L10 12l-2.36 2.36C7.14 14.13 6.59 14 6 14c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4c0-.59-.13-1.14-.36-1.64L12 14l7 7h3v-1L9.64 7.64z" fill="currentColor"/></svg>',delete:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" fill="currentColor"/></svg>',scale:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M21 15h2v2h-2v-2zm0-4h2v2h-2v-2zm2 8h-2v2c1 0 2-1 2-2zM13 3h2v2h-2V3zm8 4h2v2h-2V7zm0-4v2h2c0-1-1-2-2-2zM1 7h2v2H1V7zm16-4h2v2h-2V3zm0 16h2v2h-2v-2zM3 3C2 3 1 4 1 5h2V3zm6 0h2v2H9V3zM5 3h2v2H5V3zm-4 8v8c0 1.1.9 2 2 2h12V11H1z" fill="currentColor"/></svg>',copy:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" fill="currentColor"/></svg>',split:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M14 4l2.29 2.29-2.88 2.88 1.42 1.42 2.88-2.88L20 10V4h-6zm-4 0H4v6l2.29-2.29 4.71 4.7V20h2v-8.41l-5.29-5.3L10 4z" fill="currentColor"/></svg>',union:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 4h7v7H4V4zm9 0h7v7h-7V4zm-9 9h7v7H4v-7zm9 0h7v7h-7v-7z" fill="currentColor"/></svg>',difference:'<svg viewBox="0 0 24 24" width="18" height="18"><rect x="4" y="4" width="10" height="10" fill="none" stroke="currentColor" stroke-width="2"/><rect x="10" y="10" width="10" height="10" fill="none" stroke="currentColor" stroke-width="2"/><path d="M13 7h6v2h-6z" fill="currentColor"/></svg>',simplify:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 17l5-5 3 3 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M5 6h14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',lasso:'<svg viewBox="0 0 24 24" width="18" height="18"><ellipse cx="12" cy="10" rx="8" ry="6" fill="none" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2"/><circle cx="12" cy="18" r="3" fill="currentColor"/></svg>',freehand:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25z" fill="none" stroke="currentColor" stroke-width="2"/></svg>',circle_marker:'<svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="4" fill="currentColor"/></svg>',ellipse:'<svg viewBox="0 0 24 24" width="18" height="18"><ellipse cx="12" cy="12" rx="10" ry="6" fill="none" stroke="currentColor" stroke-width="2"/></svg>',text_marker:'<svg viewBox="0 0 24 24" width="18" height="18"><text x="12" y="16" text-anchor="middle" font-size="14" fill="currentColor">T</text></svg>'}[e]||`<span>${e[0].toUpperCase()}</span>`}setupKeyboardShortcuts(){this.boundKeyHandler=e=>{const t=e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLElement&&e.target.isContentEditable;if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){this.undo(),e.preventDefault();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey||e.key==="Z"&&e.shiftKey)){this.redo(),e.preventDefault();return}(e.ctrlKey||e.metaKey)&&e.key==="c"&&(this.copySelectedFeatures(),e.preventDefault()),(e.ctrlKey||e.metaKey)&&e.key==="v"&&(this.pasteFeatures(),e.preventDefault()),(e.key==="Delete"||e.key==="Backspace")&&!t&&!(e.target instanceof Element&&e.target.closest(".geo-editor-attribute-panel"))&&(this.deleteSelectedFeatures(),e.preventDefault()),e.key==="Enter"&&this.pendingOperation&&(this.executePendingOperation(),e.preventDefault()),e.key==="Escape"&&(this.pendingOperation?this.cancelPendingOperation():(this.disableAllModes(),this.clearSelection()))},document.addEventListener("keydown",this.boundKeyHandler)}removeKeyboardShortcuts(){this.boundKeyHandler&&(document.removeEventListener("keydown",this.boundKeyHandler),this.boundKeyHandler=null)}setupGeomanEvents(){this.geoman&&this.geoman.setGlobalEventsListener(e=>{const t=e.name??e.type??"",i=this.extractFeatureFromEvent(e.feature),n=e.action??"";if((t==="gm:create"||e.type==="gm:create")&&i&&(this.lastCreatedFeature=i,this.options.onFeatureCreate?.(i),this.logSelectedFeatureCollection("created",i),this.recordCreateOperation(i),this.options.enableAttributeEditing)){this.applyDefaultValues(i);const r=this.findGeomanDataForFeature(i);this.showAttributePanel(i,r??void 0,!0)}n==="feature_edit_start"&&i&&(this.pendingEditFeature=Go(i)),n==="feature_edit_end"&&i&&(this.lastEditedFeature=i,this.logSelectedFeatureCollection("edited",i),this.pendingEditFeature&&(this.recordEditOperation(this.pendingEditFeature,i),this.pendingEditFeature=null)),n==="feature_removed"&&i&&(this.lastDeletedFeature=i,this.lastDeletedFeatureId=this.getGeomanIdFromFeature(i),this.logSelectedFeatureCollection("deleted",i),this.recordDeleteOperation(i)),(t.includes("modetoggled")||e.type?.includes("modetoggled"))&&this.updateToolbarState()})}emitEvent(e,t){const i=new CustomEvent(e,{detail:t});this.map.getContainer().dispatchEvent(i)}undo(){return this.historyManager?this.historyManager.undo():!1}redo(){return this.historyManager?this.historyManager.redo():!1}canUndo(){return this.historyManager?.canUndo()??!1}canRedo(){return this.historyManager?.canRedo()??!1}clearHistory(){this.historyManager?.clear()}getHistoryState(){return this.historyManager?.getState()??null}getCommandContext(){return this.geoman?{featuresApi:this.geoman.features,onFeatureCreate:this.options.onFeatureCreate,onFeatureDelete:this.options.onFeatureDelete,onFeatureEdit:this.options.onFeatureEdit}:null}recordCreateOperation(e){if(!this.historyManager||this.historyManager.isExecutingCommand()||this.isPerformingCompositeOperation)return;const t=this.getCommandContext();if(!t)return;const i=new M$(e,t);this.historyManager.record(i)}recordEditOperation(e,t){if(!this.historyManager||this.historyManager.isExecutingCommand()||this.isPerformingCompositeOperation)return;const i=this.getCommandContext();if(!i)return;const n=new Hue(e,t,i);this.historyManager.record(n)}recordDeleteOperation(e){if(!this.historyManager||this.historyManager.isExecutingCommand()||this.isPerformingCompositeOperation)return;const t=this.getCommandContext();if(!t)return;const i=new I$(e,t);this.historyManager.record(i)}recordCompositeOperation(e,t,i){if(!this.historyManager||this.historyManager.isExecutingCommand())return;const n=this.getCommandContext();if(!n)return;const r=[];for(const a of e)r.push(new I$(a,n));for(const a of t)r.push(new M$(a,n));const s=new Que(r,i);this.historyManager.record(s)}updateHistoryButtonStates(e,t){const i=this.container.querySelector('[data-history="undo"]'),n=this.container.querySelector('[data-history="redo"]');i&&(i.disabled=!e),n&&(n.disabled=!t)}createHistoryToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const r=document.createElement("div");r.className=`${Pi}-tool-group-label`,r.textContent="History",e.appendChild(r)}const t=document.createElement("div");t.className=`${Pi}-tool-buttons`;const i=document.createElement("button");i.className=`${Pi}-tool-button`,i.dataset.history="undo",i.title="Undo (Ctrl+Z)",i.disabled=!0,i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M12.5 8c-2.65 0-5.05 1.04-6.93 2.75L2.5 7.69v7.81h7.81l-3.12-3.12c1.36-1.2 3.13-1.88 5.04-1.88 3.31 0 6.13 2.04 7.31 4.94l2.33-.91C20.32 10.93 16.73 8 12.5 8z" fill="currentColor"/></svg>',i.addEventListener("click",()=>this.undo()),t.appendChild(i);const n=document.createElement("button");return n.className=`${Pi}-tool-button`,n.dataset.history="redo",n.title="Redo (Ctrl+Y)",n.disabled=!0,n.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M18.43 10.75C16.55 9.04 14.15 8 11.5 8c-4.23 0-7.82 2.93-9.37 6.53l2.33.91c1.18-2.9 4-4.94 7.31-4.94 1.91 0 3.68.68 5.04 1.88l-3.12 3.12h7.81V7.69l-3.07 3.06z" fill="currentColor"/></svg>',n.addEventListener("click",()=>this.redo()),t.appendChild(n),e.appendChild(t),e}getPanelElement(){return this.attributePanel??null}},h8="geo-editor-features",vJ=class{type="geo-editor";_control;_changeCallbacks=[];_visible=!0;_opacity=1;_hasFeatures=!1;constructor(e){this._control=e,this._setupEventListeners()}_setupEventListeners(){}getLayerIds(){const e=this._control.getFeatures(),t=e&&e.features&&e.features.length>0;return t&&!this._hasFeatures?(this._hasFeatures=!0,this._changeCallbacks.forEach(i=>i("add",h8))):!t&&this._hasFeatures&&(this._hasFeatures=!1,this._changeCallbacks.forEach(i=>i("remove",h8))),t?[h8]:[]}getLayerState(e){const t=this._control.getFeatures();return!t||!t.features||t.features.length===0?null:{visible:this._visible,opacity:this._opacity,name:this.getName(e),isCustomLayer:!0,customLayerType:"geo-editor"}}setVisibility(e,t){this._visible=t;const i=this._control.map;if(!i)return;const n=i.getStyle();if(n?.layers)for(const r of n.layers)r.source&&typeof r.source=="string"&&r.source.startsWith("geoman")&&i.setLayoutProperty(r.id,"visibility",t?"visible":"none")}setOpacity(e,t){this._opacity=t;const i=this._control.map;if(!i)return;const n=i.getStyle();if(n?.layers)for(const r of n.layers)r.source&&typeof r.source=="string"&&r.source.startsWith("geoman")&&(r.type==="fill"?i.setPaintProperty(r.id,"fill-opacity",t*.3):r.type==="line"?i.setPaintProperty(r.id,"line-opacity",t):r.type==="circle"&&i.setPaintProperty(r.id,"circle-opacity",t))}getName(e){return"Drawn Features"}getSymbolType(e){return"fill"}removeLayer(e){const t=this._control.geoman;t?.features&&t.features.forEach(i=>{i.delete()}),this._hasFeatures=!1}onLayerChange(e){return this._changeCallbacks.push(e),()=>{const t=this._changeCallbacks.indexOf(e);t>=0&&this._changeCallbacks.splice(t,1)}}destroy(){this._changeCallbacks=[]}},Er=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),ade=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.")}),ode=class{_map;_overlay;_layers;constructor(e){this._map=e,this._layers=new Map,this._overlay=new dY.MapboxOverlay({interleaved:!1,layers:[]}),this._map.addControl(this._overlay)}addLayer(e,t){this._layers.set(e,t),this._updateOverlay()}removeLayer(e){this._layers.delete(e),this._updateOverlay()}updateLayer(e,t){this._layers.has(e)&&(this._layers.set(e,t),this._updateOverlay())}getLayers(){return Array.from(this._layers.values())}hasLayer(e){return this._layers.has(e)}clearLayers(){this._layers.clear(),this._updateOverlay()}getMap(){return this._map}destroy(){this._layers.clear();try{this._map.removeControl(this._overlay)}catch{}}_updateOverlay(){const e=Array.from(this._layers.entries()).sort(([t],[i])=>{const n=t.includes("cross-section"),r=i.includes("cross-section");return n&&!r?1:!n&&r?-1:0}).map(([,t])=>t);this._overlay.setProps({layers:e}),this._map.triggerRepaint()}},lde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0})})),cde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Hierarchy=void 0,e.Hierarchy={parse:t};function t(i){return Object.entries(i).reduce((n,[r,s])=>(s===-1?n.pages[r]={}:s&&(n.nodes[r]={pointCount:s}),n),{nodes:{},pages:{}})}})),hde=Er((e=>{var t=e&&e.__createBinding||(Object.create?(function(n,r,s,a){a===void 0&&(a=s);var l=Object.getOwnPropertyDescriptor(r,s);(!l||("get"in l?!r.__esModule:l.writable||l.configurable))&&(l={enumerable:!0,get:function(){return r[s]}}),Object.defineProperty(n,a,l)}):(function(n,r,s,a){a===void 0&&(a=s),n[a]=r[s]})),i=e&&e.__exportStar||function(n,r){for(var s in n)s!=="default"&&!Object.prototype.hasOwnProperty.call(r,s)&&t(r,n,s)};Object.defineProperty(e,"__esModule",{value:!0}),i(lde(),e),i(cde(),e)})),sz=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.hierarchyItemLength=e.infoLength=void 0,e.infoLength=160,e.hierarchyItemLength=32})),az=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.evlrHeaderLength=e.vlrHeaderLength=e.minHeaderLength=void 0,e.minHeaderLength=375,e.vlrHeaderLength=54,e.evlrHeaderLength=60})),ude=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getBigUint64=e.parseBigInt=void 0;function t(n){if(n>BigInt(Number.MAX_SAFE_INTEGER)||n<BigInt(-Number.MAX_SAFE_INTEGER))throw new Error(`Cannot convert bigint to number: ${n}`);return Number(n)}e.parseBigInt=t;function i(n,r,s){if(n.getBigUint64)return n.getBigUint64(r,s);const[a,l]=s?[4,0]:[0,4],h=BigInt(n.getUint32(r+a,s)),d=BigInt(n.getUint32(r+l,s));return(h<<BigInt(32))+d}e.getBigUint64=i})),dde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.toCString=e.toDataView=e.Binary=void 0,e.Binary={toDataView:t,toCString:i};function t(n){return new DataView(n.buffer,n.byteOffset,n.length)}e.toDataView=t;function i(n){const r=t(n);let s="";for(let a=0;a<r.byteLength;++a){const l=r.getInt8(a);if(l===0)return s;s+=String.fromCharCode(l)}return s}e.toCString=i})),fde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Bounds=void 0,e.Bounds={min:t,max:i,mid:n,width:r,depth:s,height:a,cube:l,step:h,stepTo:d,intersection:p};function t(g){return[g[0],g[1],g[2]]}function i(g){return[g[3],g[4],g[5]]}function n([g,v,y,E,S,R]){return[g+(E-g)/2,v+(S-v)/2,y+(R-y)/2]}function r(g){return g[3]-g[0]}function s(g){return g[4]-g[1]}function a(g){return g[5]-g[2]}function l(g){const v=n(g),y=Math.max(r(g),s(g),a(g))/2;return[v[0]-y,v[1]-y,v[2]-y,v[0]+y,v[1]+y,v[2]+y]}function h(g,[v,y,E]){const[S,R,I,k,D,F]=g,[Z,Y,Q]=n(g);return[v?Z:S,y?Y:R,E?Q:I,v?k:Z,y?D:Y,E?F:Q]}function d(g,[v,y,E,S]){for(let R=v-1;R>=0;--R)g=h(g,[y>>R&1,E>>R&1,S>>R&1]);return g}function p(g,v){return[Math.max(g[0],v[0]),Math.max(g[1],v[1]),Math.max(g[2],v[2]),Math.min(g[3],v[3]),Math.min(g[4],v[4]),Math.min(g[5],v[5])]}})),pde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Dimension=void 0,e.Dimension={Type:{int8:{type:"signed",size:1},int16:{type:"signed",size:2},int32:{type:"signed",size:4},int64:{type:"signed",size:8},uint8:{type:"unsigned",size:1},uint16:{type:"unsigned",size:2},uint32:{type:"unsigned",size:4},uint64:{type:"unsigned",size:8},float32:{type:"float",size:4},float64:{type:"float",size:8},float:{type:"float",size:4},double:{type:"float",size:8},bool:{type:"unsigned",size:1},boolean:{type:"unsigned",size:1}},ctype:t};function t({type:i,size:n}){switch(i){case"signed":switch(n){case 1:return"int8";case 2:return"int16";case 4:return"int32";case 8:return"int64"}case"unsigned":switch(n){case 1:return"uint8";case 2:return"uint16";case 4:return"uint32";case 8:return"uint64"}case"float":switch(n){case 4:return"float";case 8:return"double"}}throw new Error(`Invalid dimension type/size: ${i}/${n}`)}})),mde=Er(((e,t)=>{var i=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof global<"u"&&global,n=(function(){function s(){this.fetch=!1,this.DOMException=i.DOMException}return s.prototype=i,new s})();(function(s){(function(a){var l=typeof s<"u"&&s||typeof self<"u"&&self||typeof global<"u"&&global||{},h={searchParams:"URLSearchParams"in l,iterable:"Symbol"in l&&"iterator"in Symbol,blob:"FileReader"in l&&"Blob"in l&&(function(){try{return new Blob,!0}catch{return!1}})(),formData:"FormData"in l,arrayBuffer:"ArrayBuffer"in l};function d(X){return X&&DataView.prototype.isPrototypeOf(X)}if(h.arrayBuffer)var p=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],g=ArrayBuffer.isView||function(X){return X&&p.indexOf(Object.prototype.toString.call(X))>-1};function v(X){if(typeof X!="string"&&(X=String(X)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(X)||X==="")throw new TypeError('Invalid character in header field name: "'+X+'"');return X.toLowerCase()}function y(X){return typeof X!="string"&&(X=String(X)),X}function E(X){var ee={next:function(){var ae=X.shift();return{done:ae===void 0,value:ae}}};return h.iterable&&(ee[Symbol.iterator]=function(){return ee}),ee}function S(X){this.map={},X instanceof S?X.forEach(function(ee,ae){this.append(ae,ee)},this):Array.isArray(X)?X.forEach(function(ee){if(ee.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+ee.length);this.append(ee[0],ee[1])},this):X&&Object.getOwnPropertyNames(X).forEach(function(ee){this.append(ee,X[ee])},this)}S.prototype.append=function(X,ee){X=v(X),ee=y(ee);var ae=this.map[X];this.map[X]=ae?ae+", "+ee:ee},S.prototype.delete=function(X){delete this.map[v(X)]},S.prototype.get=function(X){return X=v(X),this.has(X)?this.map[X]:null},S.prototype.has=function(X){return this.map.hasOwnProperty(v(X))},S.prototype.set=function(X,ee){this.map[v(X)]=y(ee)},S.prototype.forEach=function(X,ee){for(var ae in this.map)this.map.hasOwnProperty(ae)&&X.call(ee,this.map[ae],ae,this)},S.prototype.keys=function(){var X=[];return this.forEach(function(ee,ae){X.push(ae)}),E(X)},S.prototype.values=function(){var X=[];return this.forEach(function(ee){X.push(ee)}),E(X)},S.prototype.entries=function(){var X=[];return this.forEach(function(ee,ae){X.push([ae,ee])}),E(X)},h.iterable&&(S.prototype[Symbol.iterator]=S.prototype.entries);function R(X){if(!X._noBody){if(X.bodyUsed)return Promise.reject(new TypeError("Already read"));X.bodyUsed=!0}}function I(X){return new Promise(function(ee,ae){X.onload=function(){ee(X.result)},X.onerror=function(){ae(X.error)}})}function k(X){var ee=new FileReader,ae=I(ee);return ee.readAsArrayBuffer(X),ae}function D(X){var ee=new FileReader,ae=I(ee),ce=/charset=([A-Za-z0-9_-]+)/.exec(X.type),de=ce?ce[1]:"utf-8";return ee.readAsText(X,de),ae}function F(X){for(var ee=new Uint8Array(X),ae=new Array(ee.length),ce=0;ce<ee.length;ce++)ae[ce]=String.fromCharCode(ee[ce]);return ae.join("")}function Z(X){if(X.slice)return X.slice(0);var ee=new Uint8Array(X.byteLength);return ee.set(new Uint8Array(X)),ee.buffer}function Y(){return this.bodyUsed=!1,this._initBody=function(X){this.bodyUsed=this.bodyUsed,this._bodyInit=X,X?typeof X=="string"?this._bodyText=X:h.blob&&Blob.prototype.isPrototypeOf(X)?this._bodyBlob=X:h.formData&&FormData.prototype.isPrototypeOf(X)?this._bodyFormData=X:h.searchParams&&URLSearchParams.prototype.isPrototypeOf(X)?this._bodyText=X.toString():h.arrayBuffer&&h.blob&&d(X)?(this._bodyArrayBuffer=Z(X.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):h.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(X)||g(X))?this._bodyArrayBuffer=Z(X):this._bodyText=X=Object.prototype.toString.call(X):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof X=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):h.searchParams&&URLSearchParams.prototype.isPrototypeOf(X)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},h.blob&&(this.blob=function(){var X=R(this);if(X)return X;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var X=R(this);return X||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(h.blob)return this.blob().then(k);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var X=R(this);if(X)return X;if(this._bodyBlob)return D(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(F(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},h.formData&&(this.formData=function(){return this.text().then(H)}),this.json=function(){return this.text().then(JSON.parse)},this}var Q=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function V(X){var ee=X.toUpperCase();return Q.indexOf(ee)>-1?ee:X}function U(X,ee){if(!(this instanceof U))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');ee=ee||{};var ae=ee.body;if(X instanceof U){if(X.bodyUsed)throw new TypeError("Already read");this.url=X.url,this.credentials=X.credentials,ee.headers||(this.headers=new S(X.headers)),this.method=X.method,this.mode=X.mode,this.signal=X.signal,!ae&&X._bodyInit!=null&&(ae=X._bodyInit,X.bodyUsed=!0)}else this.url=String(X);if(this.credentials=ee.credentials||this.credentials||"same-origin",(ee.headers||!this.headers)&&(this.headers=new S(ee.headers)),this.method=V(ee.method||this.method||"GET"),this.mode=ee.mode||this.mode||null,this.signal=ee.signal||this.signal||(function(){if("AbortController"in l)return new AbortController().signal})(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&ae)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(ae),(this.method==="GET"||this.method==="HEAD")&&(ee.cache==="no-store"||ee.cache==="no-cache")){var ce=/([?&])_=[^&]*/;if(ce.test(this.url))this.url=this.url.replace(ce,"$1_="+new Date().getTime());else{var de=/\?/;this.url+=(de.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}U.prototype.clone=function(){return new U(this,{body:this._bodyInit})};function H(X){var ee=new FormData;return X.trim().split("&").forEach(function(ae){if(ae){var ce=ae.split("="),de=ce.shift().replace(/\+/g," "),pe=ce.join("=").replace(/\+/g," ");ee.append(decodeURIComponent(de),decodeURIComponent(pe))}}),ee}function W(X){var ee=new S;return X.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(ae){return ae.indexOf(`
|
|
270
|
+
`)}return B.toString()}},{key:"computeEdgeEndLabels",value:function(B){for(var b=this.iterator();b.hasNext();)b.next().computeLabel(B)}},{key:"computeLabelling",value:function(B){this.computeEdgeEndLabels(B[0].getBoundaryNodeRule()),this.propagateSideLabels(0),this.propagateSideLabels(1);for(var b=[!1,!1],w=this.iterator();w.hasNext();)for(var L=w.next().getLabel(),G=0;G<2;G++)L.isLine(G)&&L.getLocation(G)===Ae.BOUNDARY&&(b[G]=!0);for(var K=this.iterator();K.hasNext();)for(var le=K.next(),fe=le.getLabel(),_e=0;_e<2;_e++)if(fe.isAnyNull(_e)){var Oe=Ae.NONE;if(b[_e])Oe=Ae.EXTERIOR;else{var ut=le.getCoordinate();Oe=this.getLocation(_e,ut,B)}fe.setAllLocationsIfNull(_e,Oe)}}},{key:"getDegree",value:function(){return this._edgeMap.size()}},{key:"insertEdgeEnd",value:function(B,b){this._edgeMap.put(B,b),this._edgeList=null}}],[{key:"constructor_",value:function(){this._edgeMap=new Fs,this._edgeList=null,this._ptInAreaLocation=[Ae.NONE,Ae.NONE]}}])})()),bi=(function(B){function b(){return r(this,b),n(this,b)}return g(b,B),l(b,[{key:"createNode",value:function(w){return new qa(w,new zt)}}])})(Ic),wn=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"compareTo",value:function(b){var w=b;return B.compareOriented(this._pts,this._orientation,w._pts,w._orientation)}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){this._pts=null,this._orientation=null;var b=arguments[0];this._pts=b,this._orientation=B.orientation(b)}},{key:"orientation",value:function(b){return $n.increasingDirection(b)===1}},{key:"compareOriented",value:function(b,w,L,G){for(var K=w?1:-1,le=G?1:-1,fe=w?b.length:-1,_e=G?L.length:-1,Oe=w?0:b.length-1,ut=G?0:L.length-1;;){var _t=b[Oe].compareTo(L[ut]);if(_t!==0)return _t;var St=(Oe+=K)===fe,Mi=(ut+=le)===_e;if(St&&!Mi)return-1;if(!St&&Mi)return 1;if(St&&Mi)return 0}}}])})(),dn=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"print",value:function(B){B.print("MULTILINESTRING ( ");for(var b=0;b<this._edges.size();b++){var w=this._edges.get(b);b>0&&B.print(","),B.print("(");for(var L=w.getCoordinates(),G=0;G<L.length;G++)G>0&&B.print(","),B.print(L[G].x+" "+L[G].y);B.println(")")}B.print(") ")}},{key:"addAll",value:function(B){for(var b=B.iterator();b.hasNext();)this.add(b.next())}},{key:"findEdgeIndex",value:function(B){for(var b=0;b<this._edges.size();b++)if(this._edges.get(b).equals(B))return b;return-1}},{key:"iterator",value:function(){return this._edges.iterator()}},{key:"getEdges",value:function(){return this._edges}},{key:"get",value:function(B){return this._edges.get(B)}},{key:"findEqualEdge",value:function(B){var b=new wn(B.getCoordinates());return this._ocaMap.get(b)}},{key:"add",value:function(B){this._edges.add(B);var b=new wn(B.getCoordinates());this._ocaMap.put(b,B)}}],[{key:"constructor_",value:function(){this._edges=new Pt,this._ocaMap=new Fs}}])})(),en=(function(){return l((function B(){r(this,B)}),[{key:"processIntersections",value:function(B,b,w,L){}},{key:"isDone",value:function(){}}])})(),Cn=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"isTrivialIntersection",value:function(b,w,L,G){if(b===L&&this._li.getIntersectionNum()===1){if(B.isAdjacentSegments(w,G))return!0;if(b.isClosed()){var K=b.size()-1;if(w===0&&G===K||G===0&&w===K)return!0}}return!1}},{key:"getProperIntersectionPoint",value:function(){return this._properIntersectionPoint}},{key:"hasProperInteriorIntersection",value:function(){return this._hasProperInterior}},{key:"getLineIntersector",value:function(){return this._li}},{key:"hasProperIntersection",value:function(){return this._hasProper}},{key:"processIntersections",value:function(b,w,L,G){if(b===L&&w===G)return null;this.numTests++;var K=b.getCoordinates()[w],le=b.getCoordinates()[w+1],fe=L.getCoordinates()[G],_e=L.getCoordinates()[G+1];this._li.computeIntersection(K,le,fe,_e),this._li.hasIntersection()&&(this.numIntersections++,this._li.isInteriorIntersection()&&(this.numInteriorIntersections++,this._hasInterior=!0),this.isTrivialIntersection(b,w,L,G)||(this._hasIntersection=!0,b.addIntersections(this._li,w,0),L.addIntersections(this._li,G,1),this._li.isProper()&&(this.numProperIntersections++,this._hasProper=!0,this._hasProperInterior=!0)))}},{key:"hasIntersection",value:function(){return this._hasIntersection}},{key:"isDone",value:function(){return!1}},{key:"hasInteriorIntersection",value:function(){return this._hasInterior}},{key:"interfaces_",get:function(){return[en]}}],[{key:"constructor_",value:function(){this._hasIntersection=!1,this._hasProper=!1,this._hasProperInterior=!1,this._hasInterior=!1,this._properIntersectionPoint=null,this._li=null,this._isSelfIntersection=null,this.numIntersections=0,this.numInteriorIntersections=0,this.numProperIntersections=0,this.numTests=0;var b=arguments[0];this._li=b}},{key:"isAdjacentSegments",value:function(b,w){return Math.abs(b-w)===1}}])})(),pn=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getSegmentIndex",value:function(){return this.segmentIndex}},{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(B){B.print(this.coord),B.print(" seg # = "+this.segmentIndex),B.println(" dist = "+this.dist)}},{key:"compareTo",value:function(B){var b=B;return this.compare(b.segmentIndex,b.dist)}},{key:"isEndPoint",value:function(B){return this.segmentIndex===0&&this.dist===0||this.segmentIndex===B}},{key:"toString",value:function(){return this.coord+" seg # = "+this.segmentIndex+" dist = "+this.dist}},{key:"getDistance",value:function(){return this.dist}},{key:"compare",value:function(B,b){return this.segmentIndex<B?-1:this.segmentIndex>B?1:this.dist<b?-1:this.dist>b?1:0}},{key:"interfaces_",get:function(){return[Q]}}],[{key:"constructor_",value:function(){this.coord=null,this.segmentIndex=null,this.dist=null;var B=arguments[0],b=arguments[1],w=arguments[2];this.coord=new Le(B),this.segmentIndex=b,this.dist=w}}])})(),ma=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"print",value:function(B){B.println("Intersections:");for(var b=this.iterator();b.hasNext();)b.next().print(B)}},{key:"iterator",value:function(){return this._nodeMap.values().iterator()}},{key:"addSplitEdges",value:function(B){this.addEndpoints();for(var b=this.iterator(),w=b.next();b.hasNext();){var L=b.next(),G=this.createSplitEdge(w,L);B.add(G),w=L}}},{key:"addEndpoints",value:function(){var B=this.edge.pts.length-1;this.add(this.edge.pts[0],0,0),this.add(this.edge.pts[B],B,0)}},{key:"createSplitEdge",value:function(B,b){var w=b.segmentIndex-B.segmentIndex+2,L=this.edge.pts[b.segmentIndex],G=b.dist>0||!b.coord.equals2D(L);G||w--;var K=new Array(w).fill(null),le=0;K[le++]=new Le(B.coord);for(var fe=B.segmentIndex+1;fe<=b.segmentIndex;fe++)K[le++]=this.edge.pts[fe];return G&&(K[le]=b.coord),new kt(K,new Jr(this.edge._label))}},{key:"add",value:function(B,b,w){var L=new pn(B,b,w),G=this._nodeMap.get(L);return G!==null?G:(this._nodeMap.put(L,L),L)}},{key:"isIntersection",value:function(B){for(var b=this.iterator();b.hasNext();)if(b.next().coord.equals(B))return!0;return!1}}],[{key:"constructor_",value:function(){this._nodeMap=new Fs,this.edge=null;var B=arguments[0];this.edge=B}}])})(),Kr=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"isIntersects",value:function(){return!this.isDisjoint()}},{key:"isCovers",value:function(){return(B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.INTERIOR][Ae.BOUNDARY])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]))&&this._matrix[Ae.EXTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]===Rt.FALSE}},{key:"isCoveredBy",value:function(){return(B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.INTERIOR][Ae.BOUNDARY])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]))&&this._matrix[Ae.INTERIOR][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]===Rt.FALSE}},{key:"set",value:function(){if(arguments.length===1)for(var b=arguments[0],w=0;w<b.length;w++){var L=Math.trunc(w/3),G=w%3;this._matrix[L][G]=Rt.toDimensionValue(b.charAt(w))}else if(arguments.length===3){var K=arguments[0],le=arguments[1],fe=arguments[2];this._matrix[K][le]=fe}}},{key:"isContains",value:function(){return B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&this._matrix[Ae.EXTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]===Rt.FALSE}},{key:"setAtLeast",value:function(){if(arguments.length===1)for(var b=arguments[0],w=0;w<b.length;w++){var L=Math.trunc(w/3),G=w%3;this.setAtLeast(L,G,Rt.toDimensionValue(b.charAt(w)))}else if(arguments.length===3){var K=arguments[0],le=arguments[1],fe=arguments[2];this._matrix[K][le]<fe&&(this._matrix[K][le]=fe)}}},{key:"setAtLeastIfValid",value:function(b,w,L){b>=0&&w>=0&&this.setAtLeast(b,w,L)}},{key:"isWithin",value:function(){return B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&this._matrix[Ae.INTERIOR][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]===Rt.FALSE}},{key:"isTouches",value:function(b,w){return b>w?this.isTouches(w,b):(b===Rt.A&&w===Rt.A||b===Rt.L&&w===Rt.L||b===Rt.L&&w===Rt.A||b===Rt.P&&w===Rt.A||b===Rt.P&&w===Rt.L)&&this._matrix[Ae.INTERIOR][Ae.INTERIOR]===Rt.FALSE&&(B.isTrue(this._matrix[Ae.INTERIOR][Ae.BOUNDARY])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.INTERIOR])||B.isTrue(this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]))}},{key:"isOverlaps",value:function(b,w){return b===Rt.P&&w===Rt.P||b===Rt.A&&w===Rt.A?B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.EXTERIOR])&&B.isTrue(this._matrix[Ae.EXTERIOR][Ae.INTERIOR]):b===Rt.L&&w===Rt.L&&this._matrix[Ae.INTERIOR][Ae.INTERIOR]===1&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.EXTERIOR])&&B.isTrue(this._matrix[Ae.EXTERIOR][Ae.INTERIOR])}},{key:"isEquals",value:function(b,w){return b===w&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&this._matrix[Ae.INTERIOR][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]===Rt.FALSE}},{key:"toString",value:function(){for(var b=new At("123456789"),w=0;w<3;w++)for(var L=0;L<3;L++)b.setCharAt(3*w+L,Rt.toDimensionSymbol(this._matrix[w][L]));return b.toString()}},{key:"setAll",value:function(b){for(var w=0;w<3;w++)for(var L=0;L<3;L++)this._matrix[w][L]=b}},{key:"get",value:function(b,w){return this._matrix[b][w]}},{key:"transpose",value:function(){var b=this._matrix[1][0];return this._matrix[1][0]=this._matrix[0][1],this._matrix[0][1]=b,b=this._matrix[2][0],this._matrix[2][0]=this._matrix[0][2],this._matrix[0][2]=b,b=this._matrix[2][1],this._matrix[2][1]=this._matrix[1][2],this._matrix[1][2]=b,this}},{key:"matches",value:function(b){if(b.length!==9)throw new Z("Should be length 9: "+b);for(var w=0;w<3;w++)for(var L=0;L<3;L++)if(!B.matches(this._matrix[w][L],b.charAt(3*w+L)))return!1;return!0}},{key:"add",value:function(b){for(var w=0;w<3;w++)for(var L=0;L<3;L++)this.setAtLeast(w,L,b.get(w,L))}},{key:"isDisjoint",value:function(){return this._matrix[Ae.INTERIOR][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.INTERIOR][Ae.BOUNDARY]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.INTERIOR]===Rt.FALSE&&this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]===Rt.FALSE}},{key:"isCrosses",value:function(b,w){return b===Rt.P&&w===Rt.L||b===Rt.P&&w===Rt.A||b===Rt.L&&w===Rt.A?B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&B.isTrue(this._matrix[Ae.INTERIOR][Ae.EXTERIOR]):b===Rt.L&&w===Rt.P||b===Rt.A&&w===Rt.P||b===Rt.A&&w===Rt.L?B.isTrue(this._matrix[Ae.INTERIOR][Ae.INTERIOR])&&B.isTrue(this._matrix[Ae.EXTERIOR][Ae.INTERIOR]):b===Rt.L&&w===Rt.L&&this._matrix[Ae.INTERIOR][Ae.INTERIOR]===0}},{key:"interfaces_",get:function(){return[V]}}],[{key:"constructor_",value:function(){if(this._matrix=null,arguments.length===0)this._matrix=Array(3).fill().map((function(){return Array(3)})),this.setAll(Rt.FALSE);else if(arguments.length===1){if(typeof arguments[0]=="string"){var b=arguments[0];B.constructor_.call(this),this.set(b)}else if(arguments[0]instanceof B){var w=arguments[0];B.constructor_.call(this),this._matrix[Ae.INTERIOR][Ae.INTERIOR]=w._matrix[Ae.INTERIOR][Ae.INTERIOR],this._matrix[Ae.INTERIOR][Ae.BOUNDARY]=w._matrix[Ae.INTERIOR][Ae.BOUNDARY],this._matrix[Ae.INTERIOR][Ae.EXTERIOR]=w._matrix[Ae.INTERIOR][Ae.EXTERIOR],this._matrix[Ae.BOUNDARY][Ae.INTERIOR]=w._matrix[Ae.BOUNDARY][Ae.INTERIOR],this._matrix[Ae.BOUNDARY][Ae.BOUNDARY]=w._matrix[Ae.BOUNDARY][Ae.BOUNDARY],this._matrix[Ae.BOUNDARY][Ae.EXTERIOR]=w._matrix[Ae.BOUNDARY][Ae.EXTERIOR],this._matrix[Ae.EXTERIOR][Ae.INTERIOR]=w._matrix[Ae.EXTERIOR][Ae.INTERIOR],this._matrix[Ae.EXTERIOR][Ae.BOUNDARY]=w._matrix[Ae.EXTERIOR][Ae.BOUNDARY],this._matrix[Ae.EXTERIOR][Ae.EXTERIOR]=w._matrix[Ae.EXTERIOR][Ae.EXTERIOR]}}}},{key:"matches",value:function(){if(Number.isInteger(arguments[0])&&typeof arguments[1]=="string"){var b=arguments[0],w=arguments[1];return w===Rt.SYM_DONTCARE||w===Rt.SYM_TRUE&&(b>=0||b===Rt.TRUE)||w===Rt.SYM_FALSE&&b===Rt.FALSE||w===Rt.SYM_P&&b===Rt.P||w===Rt.SYM_L&&b===Rt.L||w===Rt.SYM_A&&b===Rt.A}if(typeof arguments[0]=="string"&&typeof arguments[1]=="string"){var L=arguments[1];return new B(arguments[0]).matches(L)}}},{key:"isTrue",value:function(b){return b>=0||b===Rt.TRUE}}])})(),me=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"size",value:function(){return this._size}},{key:"addAll",value:function(b){return b===null||b.length===0?null:(this.ensureCapacity(this._size+b.length),Hi.arraycopy(b,0,this._data,this._size,b.length),void(this._size+=b.length))}},{key:"ensureCapacity",value:function(b){if(b<=this._data.length)return null;var w=Math.max(b,2*this._data.length);this._data=Qe.copyOf(this._data,w)}},{key:"toArray",value:function(){var b=new Array(this._size).fill(null);return Hi.arraycopy(this._data,0,b,0,this._size),b}},{key:"add",value:function(b){this.ensureCapacity(this._size+1),this._data[this._size]=b,++this._size}}],[{key:"constructor_",value:function(){if(this._data=null,this._size=0,arguments.length===0)B.constructor_.call(this,10);else if(arguments.length===1){var b=arguments[0];this._data=new Array(b).fill(null)}}}])})(),ge=(function(){function B(){r(this,B)}return l(B,[{key:"getChainStartIndices",value:function(b){var w=0,L=new me(Math.trunc(b.length/2));L.add(w);do{var G=this.findChainEnd(b,w);L.add(G),w=G}while(w<b.length-1);return L.toArray()}},{key:"findChainEnd",value:function(b,w){for(var L=dr.quadrant(b[w],b[w+1]),G=w+1;G<b.length&&dr.quadrant(b[G-1],b[G])===L;)G++;return G-1}},{key:"OLDgetChainStartIndices",value:function(b){var w=0,L=new Pt;L.add(w);do{var G=this.findChainEnd(b,w);L.add(G),w=G}while(w<b.length-1);return B.toIntArray(L)}}],[{key:"toIntArray",value:function(b){for(var w=new Array(b.size()).fill(null),L=0;L<w.length;L++)w[L]=b.get(L).intValue();return w}}])})(),We=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"getCoordinates",value:function(){return this.pts}},{key:"getMaxX",value:function(B){var b=this.pts[this.startIndex[B]].x,w=this.pts[this.startIndex[B+1]].x;return b>w?b:w}},{key:"getMinX",value:function(B){var b=this.pts[this.startIndex[B]].x,w=this.pts[this.startIndex[B+1]].x;return b<w?b:w}},{key:"computeIntersectsForChain",value:function(){if(arguments.length===4){var B=arguments[0],b=arguments[1],w=arguments[2],L=arguments[3];this.computeIntersectsForChain(this.startIndex[B],this.startIndex[B+1],b,b.startIndex[w],b.startIndex[w+1],L)}else if(arguments.length===6){var G=arguments[0],K=arguments[1],le=arguments[2],fe=arguments[3],_e=arguments[4],Oe=arguments[5];if(K-G==1&&_e-fe==1)return Oe.addIntersections(this.e,G,le.e,fe),null;if(!this.overlaps(G,K,le,fe,_e))return null;var ut=Math.trunc((G+K)/2),_t=Math.trunc((fe+_e)/2);G<ut&&(fe<_t&&this.computeIntersectsForChain(G,ut,le,fe,_t,Oe),_t<_e&&this.computeIntersectsForChain(G,ut,le,_t,_e,Oe)),ut<K&&(fe<_t&&this.computeIntersectsForChain(ut,K,le,fe,_t,Oe),_t<_e&&this.computeIntersectsForChain(ut,K,le,_t,_e,Oe))}}},{key:"overlaps",value:function(B,b,w,L,G){return nt.intersects(this.pts[B],this.pts[b],w.pts[L],w.pts[G])}},{key:"getStartIndexes",value:function(){return this.startIndex}},{key:"computeIntersects",value:function(B,b){for(var w=0;w<this.startIndex.length-1;w++)for(var L=0;L<B.startIndex.length-1;L++)this.computeIntersectsForChain(w,B,L,b)}}],[{key:"constructor_",value:function(){this.e=null,this.pts=null,this.startIndex=null;var B=arguments[0];this.e=B,this.pts=B.getCoordinates();var b=new ge;this.startIndex=b.getChainStartIndices(this.pts)}}])})(),gt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"getDepth",value:function(b,w){return this._depth[b][w]}},{key:"setDepth",value:function(b,w,L){this._depth[b][w]=L}},{key:"isNull",value:function(){if(arguments.length===0){for(var b=0;b<2;b++)for(var w=0;w<3;w++)if(this._depth[b][w]!==B.NULL_VALUE)return!1;return!0}if(arguments.length===1){var L=arguments[0];return this._depth[L][1]===B.NULL_VALUE}if(arguments.length===2){var G=arguments[0],K=arguments[1];return this._depth[G][K]===B.NULL_VALUE}}},{key:"normalize",value:function(){for(var b=0;b<2;b++)if(!this.isNull(b)){var w=this._depth[b][1];this._depth[b][2]<w&&(w=this._depth[b][2]),w<0&&(w=0);for(var L=1;L<3;L++){var G=0;this._depth[b][L]>w&&(G=1),this._depth[b][L]=G}}}},{key:"getDelta",value:function(b){return this._depth[b][be.RIGHT]-this._depth[b][be.LEFT]}},{key:"getLocation",value:function(b,w){return this._depth[b][w]<=0?Ae.EXTERIOR:Ae.INTERIOR}},{key:"toString",value:function(){return"A: "+this._depth[0][1]+","+this._depth[0][2]+" B: "+this._depth[1][1]+","+this._depth[1][2]}},{key:"add",value:function(){if(arguments.length===1)for(var b=arguments[0],w=0;w<2;w++)for(var L=1;L<3;L++){var G=b.getLocation(w,L);G!==Ae.EXTERIOR&&G!==Ae.INTERIOR||(this.isNull(w,L)?this._depth[w][L]=B.depthAtLocation(G):this._depth[w][L]+=B.depthAtLocation(G))}else if(arguments.length===3){var K=arguments[0],le=arguments[1];arguments[2]===Ae.INTERIOR&&this._depth[K][le]++}}}],[{key:"constructor_",value:function(){this._depth=Array(2).fill().map((function(){return Array(3)}));for(var b=0;b<2;b++)for(var w=0;w<3;w++)this._depth[b][w]=B.NULL_VALUE}},{key:"depthAtLocation",value:function(b){return b===Ae.EXTERIOR?0:b===Ae.INTERIOR?1:B.NULL_VALUE}}])})();gt.NULL_VALUE=-1;var kt=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"getDepth",value:function(){return this._depth}},{key:"getCollapsedEdge",value:function(){var w=new Array(2).fill(null);return w[0]=this.pts[0],w[1]=this.pts[1],new b(w,Jr.toLineLabel(this._label))}},{key:"isIsolated",value:function(){return this._isIsolated}},{key:"getCoordinates",value:function(){return this.pts}},{key:"setIsolated",value:function(w){this._isIsolated=w}},{key:"setName",value:function(w){this._name=w}},{key:"equals",value:function(w){if(!(w instanceof b))return!1;var L=w;if(this.pts.length!==L.pts.length)return!1;for(var G=!0,K=!0,le=this.pts.length,fe=0;fe<this.pts.length;fe++)if(this.pts[fe].equals2D(L.pts[fe])||(G=!1),this.pts[fe].equals2D(L.pts[--le])||(K=!1),!G&&!K)return!1;return!0}},{key:"getCoordinate",value:function(){if(arguments.length===0)return this.pts.length>0?this.pts[0]:null;if(arguments.length===1){var w=arguments[0];return this.pts[w]}}},{key:"print",value:function(w){w.print("edge "+this._name+": "),w.print("LINESTRING (");for(var L=0;L<this.pts.length;L++)L>0&&w.print(","),w.print(this.pts[L].x+" "+this.pts[L].y);w.print(") "+this._label+" "+this._depthDelta)}},{key:"computeIM",value:function(w){b.updateIM(this._label,w)}},{key:"isCollapsed",value:function(){return!!this._label.isArea()&&this.pts.length===3&&!!this.pts[0].equals(this.pts[2])}},{key:"isClosed",value:function(){return this.pts[0].equals(this.pts[this.pts.length-1])}},{key:"getMaximumSegmentIndex",value:function(){return this.pts.length-1}},{key:"getDepthDelta",value:function(){return this._depthDelta}},{key:"getNumPoints",value:function(){return this.pts.length}},{key:"printReverse",value:function(w){w.print("edge "+this._name+": ");for(var L=this.pts.length-1;L>=0;L--)w.print(this.pts[L]+" ");w.println("")}},{key:"getMonotoneChainEdge",value:function(){return this._mce===null&&(this._mce=new We(this)),this._mce}},{key:"getEnvelope",value:function(){if(this._env===null){this._env=new nt;for(var w=0;w<this.pts.length;w++)this._env.expandToInclude(this.pts[w])}return this._env}},{key:"addIntersection",value:function(w,L,G,K){var le=new Le(w.getIntersection(K)),fe=L,_e=w.getEdgeDistance(G,K),Oe=fe+1;if(Oe<this.pts.length){var ut=this.pts[Oe];le.equals2D(ut)&&(fe=Oe,_e=0)}this.eiList.add(le,fe,_e)}},{key:"toString",value:function(){var w=new At;w.append("edge "+this._name+": "),w.append("LINESTRING (");for(var L=0;L<this.pts.length;L++)L>0&&w.append(","),w.append(this.pts[L].x+" "+this.pts[L].y);return w.append(") "+this._label+" "+this._depthDelta),w.toString()}},{key:"isPointwiseEqual",value:function(w){if(this.pts.length!==w.pts.length)return!1;for(var L=0;L<this.pts.length;L++)if(!this.pts[L].equals2D(w.pts[L]))return!1;return!0}},{key:"setDepthDelta",value:function(w){this._depthDelta=w}},{key:"getEdgeIntersectionList",value:function(){return this.eiList}},{key:"addIntersections",value:function(w,L,G){for(var K=0;K<w.getIntersectionNum();K++)this.addIntersection(w,L,G,K)}}],[{key:"constructor_",value:function(){if(this.pts=null,this._env=null,this.eiList=new ma(this),this._name=null,this._mce=null,this._isIsolated=!0,this._depth=new gt,this._depthDelta=0,arguments.length===1){var w=arguments[0];b.constructor_.call(this,w,null)}else if(arguments.length===2){var L=arguments[0],G=arguments[1];this.pts=L,this._label=G}}},{key:"updateIM",value:function(){if(!(arguments.length===2&&arguments[1]instanceof Kr&&arguments[0]instanceof Jr))return E(b,"updateIM",this).apply(this,arguments);var w=arguments[0],L=arguments[1];L.setAtLeastIfValid(w.getLocation(0,be.ON),w.getLocation(1,be.ON),1),w.isArea()&&(L.setAtLeastIfValid(w.getLocation(0,be.LEFT),w.getLocation(1,be.LEFT),2),L.setAtLeastIfValid(w.getLocation(0,be.RIGHT),w.getLocation(1,be.RIGHT),2))}}])})(ac),Ht=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"setWorkingPrecisionModel",value:function(b){this._workingPrecisionModel=b}},{key:"insertUniqueEdge",value:function(b){var w=this._edgeList.findEqualEdge(b);if(w!==null){var L=w.getLabel(),G=b.getLabel();w.isPointwiseEqual(b)||(G=new Jr(b.getLabel())).flip(),L.merge(G);var K=B.depthDelta(G),le=w.getDepthDelta()+K;w.setDepthDelta(le)}else this._edgeList.add(b),b.setDepthDelta(B.depthDelta(b.getLabel()))}},{key:"buildSubgraphs",value:function(b,w){for(var L=new Pt,G=b.iterator();G.hasNext();){var K=G.next(),le=K.getRightmostCoordinate(),fe=new ie(L).getDepth(le);K.computeDepth(fe),K.findResultEdges(),L.add(K),w.add(K.getDirectedEdges(),K.getNodes())}}},{key:"createSubgraphs",value:function(b){for(var w=new Pt,L=b.getNodes().iterator();L.hasNext();){var G=L.next();if(!G.isVisited()){var K=new ni;K.create(G),w.add(K)}}return bo.sort(w,bo.reverseOrder()),w}},{key:"createEmptyResultGeometry",value:function(){return this._geomFact.createPolygon()}},{key:"getNoder",value:function(b){if(this._workingNoder!==null)return this._workingNoder;var w=new Tl,L=new ys;return L.setPrecisionModel(b),w.setSegmentIntersector(new Cn(L)),w}},{key:"buffer",value:function(b,w){var L=this._workingPrecisionModel;L===null&&(L=b.getPrecisionModel()),this._geomFact=b.getFactory();var G=new ke(b,w,new f(L,this._bufParams)).getCurves();if(G.size()<=0)return this.createEmptyResultGeometry();this.computeNodedEdges(G,L),this._graph=new du(new bi),this._graph.addEdges(this._edgeList.getEdges());var K=this.createSubgraphs(this._graph),le=new ha(this._geomFact);this.buildSubgraphs(K,le);var fe=le.getPolygons();return fe.size()<=0?this.createEmptyResultGeometry():this._geomFact.buildGeometry(fe)}},{key:"computeNodedEdges",value:function(b,w){var L=this.getNoder(w);L.computeNodes(b);for(var G=L.getNodedSubstrings().iterator();G.hasNext();){var K=G.next(),le=K.getCoordinates();if(le.length!==2||!le[0].equals2D(le[1])){var fe=K.getData(),_e=new kt(K.getCoordinates(),new Jr(fe));this.insertUniqueEdge(_e)}}}},{key:"setNoder",value:function(b){this._workingNoder=b}}],[{key:"constructor_",value:function(){this._bufParams=null,this._workingPrecisionModel=null,this._workingNoder=null,this._geomFact=null,this._graph=null,this._edgeList=new dn;var b=arguments[0];this._bufParams=b}},{key:"depthDelta",value:function(b){var w=b.getLocation(0,be.LEFT),L=b.getLocation(0,be.RIGHT);return w===Ae.INTERIOR&&L===Ae.EXTERIOR?1:w===Ae.EXTERIOR&&L===Ae.INTERIOR?-1:0}},{key:"convertSegStrings",value:function(b){for(var w=new qi,L=new Pt;b.hasNext();){var G=b.next(),K=w.createLineString(G.getCoordinates());L.add(K)}return w.buildGeometry(L)}}])})(),Gt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"rescale",value:function(){if(Pe(arguments[0],vt))for(var b=arguments[0].iterator();b.hasNext();){var w=b.next();this.rescale(w.getCoordinates())}else if(arguments[0]instanceof Array){for(var L=arguments[0],G=0;G<L.length;G++)L[G].x=L[G].x/this._scaleFactor+this._offsetX,L[G].y=L[G].y/this._scaleFactor+this._offsetY;L.length===2&&L[0].equals2D(L[1])&&Hi.out.println(L)}}},{key:"scale",value:function(){if(Pe(arguments[0],vt)){for(var b=arguments[0],w=new Pt(b.size()),L=b.iterator();L.hasNext();){var G=L.next();w.add(new fa(this.scale(G.getCoordinates()),G.getData()))}return w}if(arguments[0]instanceof Array){for(var K=arguments[0],le=new Array(K.length).fill(null),fe=0;fe<K.length;fe++)le[fe]=new Le(Math.round((K[fe].x-this._offsetX)*this._scaleFactor),Math.round((K[fe].y-this._offsetY)*this._scaleFactor),K[fe].getZ());return $n.removeRepeatedPoints(le)}}},{key:"isIntegerPrecision",value:function(){return this._scaleFactor===1}},{key:"getNodedSubstrings",value:function(){var b=this._noder.getNodedSubstrings();return this._isScaled&&this.rescale(b),b}},{key:"computeNodes",value:function(b){var w=b;this._isScaled&&(w=this.scale(b)),this._noder.computeNodes(w)}},{key:"interfaces_",get:function(){return[Il]}}],[{key:"constructor_",value:function(){if(this._noder=null,this._scaleFactor=null,this._offsetX=null,this._offsetY=null,this._isScaled=!1,arguments.length===2){var b=arguments[0],w=arguments[1];B.constructor_.call(this,b,w,0,0)}else if(arguments.length===4){var L=arguments[0],G=arguments[1];this._noder=L,this._scaleFactor=G,this._isScaled=!this.isIntegerPrecision()}}}])})(),Qt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"checkEndPtVertexIntersections",value:function(){if(arguments.length===0)for(var b=this._segStrings.iterator();b.hasNext();){var w=b.next().getCoordinates();this.checkEndPtVertexIntersections(w[0],this._segStrings),this.checkEndPtVertexIntersections(w[w.length-1],this._segStrings)}else if(arguments.length===2){for(var L=arguments[0],G=arguments[1].iterator();G.hasNext();)for(var K=G.next().getCoordinates(),le=1;le<K.length-1;le++)if(K[le].equals(L))throw new we("found endpt/interior pt intersection at index "+le+" :pt "+L)}}},{key:"checkInteriorIntersections",value:function(){if(arguments.length===0)for(var b=this._segStrings.iterator();b.hasNext();)for(var w=b.next(),L=this._segStrings.iterator();L.hasNext();){var G=L.next();this.checkInteriorIntersections(w,G)}else if(arguments.length===2)for(var K=arguments[0],le=arguments[1],fe=K.getCoordinates(),_e=le.getCoordinates(),Oe=0;Oe<fe.length-1;Oe++)for(var ut=0;ut<_e.length-1;ut++)this.checkInteriorIntersections(K,Oe,le,ut);else if(arguments.length===4){var _t=arguments[0],St=arguments[1],Mi=arguments[2],an=arguments[3];if(_t===Mi&&St===an)return null;var mn=_t.getCoordinates()[St],tr=_t.getCoordinates()[St+1],Qi=Mi.getCoordinates()[an],vr=Mi.getCoordinates()[an+1];if(this._li.computeIntersection(mn,tr,Qi,vr),this._li.hasIntersection()&&(this._li.isProper()||this.hasInteriorIntersection(this._li,mn,tr)||this.hasInteriorIntersection(this._li,Qi,vr)))throw new we("found non-noded intersection at "+mn+"-"+tr+" and "+Qi+"-"+vr)}}},{key:"checkValid",value:function(){this.checkEndPtVertexIntersections(),this.checkInteriorIntersections(),this.checkCollapses()}},{key:"checkCollapses",value:function(){if(arguments.length===0)for(var b=this._segStrings.iterator();b.hasNext();){var w=b.next();this.checkCollapses(w)}else if(arguments.length===1)for(var L=arguments[0].getCoordinates(),G=0;G<L.length-2;G++)this.checkCollapse(L[G],L[G+1],L[G+2])}},{key:"hasInteriorIntersection",value:function(b,w,L){for(var G=0;G<b.getIntersectionNum();G++){var K=b.getIntersection(G);if(!K.equals(w)&&!K.equals(L))return!0}return!1}},{key:"checkCollapse",value:function(b,w,L){if(b.equals(L))throw new we("found non-noded collapse at "+B.fact.createLineString([b,w,L]))}}],[{key:"constructor_",value:function(){this._li=new ys,this._segStrings=null;var b=arguments[0];this._segStrings=b}}])})();Qt.fact=new qi;var ai=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"intersectsScaled",value:function(b,w){var L=Math.min(b.x,w.x),G=Math.max(b.x,w.x),K=Math.min(b.y,w.y),le=Math.max(b.y,w.y),fe=this._maxx<L||this._minx>G||this._maxy<K||this._miny>le;if(fe)return!1;var _e=this.intersectsToleranceSquare(b,w);return Se.isTrue(!(fe&&_e),"Found bad envelope test"),_e}},{key:"initCorners",value:function(b){var w=.5;this._minx=b.x-w,this._maxx=b.x+w,this._miny=b.y-w,this._maxy=b.y+w,this._corner[0]=new Le(this._maxx,this._maxy),this._corner[1]=new Le(this._minx,this._maxy),this._corner[2]=new Le(this._minx,this._miny),this._corner[3]=new Le(this._maxx,this._miny)}},{key:"intersects",value:function(b,w){return this._scaleFactor===1?this.intersectsScaled(b,w):(this.copyScaled(b,this._p0Scaled),this.copyScaled(w,this._p1Scaled),this.intersectsScaled(this._p0Scaled,this._p1Scaled))}},{key:"scale",value:function(b){return Math.round(b*this._scaleFactor)}},{key:"getCoordinate",value:function(){return this._originalPt}},{key:"copyScaled",value:function(b,w){w.x=this.scale(b.x),w.y=this.scale(b.y)}},{key:"getSafeEnvelope",value:function(){if(this._safeEnv===null){var b=B.SAFE_ENV_EXPANSION_FACTOR/this._scaleFactor;this._safeEnv=new nt(this._originalPt.x-b,this._originalPt.x+b,this._originalPt.y-b,this._originalPt.y+b)}return this._safeEnv}},{key:"intersectsPixelClosure",value:function(b,w){return this._li.computeIntersection(b,w,this._corner[0],this._corner[1]),!!this._li.hasIntersection()||(this._li.computeIntersection(b,w,this._corner[1],this._corner[2]),!!this._li.hasIntersection()||(this._li.computeIntersection(b,w,this._corner[2],this._corner[3]),!!this._li.hasIntersection()||(this._li.computeIntersection(b,w,this._corner[3],this._corner[0]),!!this._li.hasIntersection())))}},{key:"intersectsToleranceSquare",value:function(b,w){var L=!1,G=!1;return this._li.computeIntersection(b,w,this._corner[0],this._corner[1]),!!this._li.isProper()||(this._li.computeIntersection(b,w,this._corner[1],this._corner[2]),!!this._li.isProper()||(this._li.hasIntersection()&&(L=!0),this._li.computeIntersection(b,w,this._corner[2],this._corner[3]),!!this._li.isProper()||(this._li.hasIntersection()&&(G=!0),this._li.computeIntersection(b,w,this._corner[3],this._corner[0]),!!this._li.isProper()||!(!L||!G)||!!b.equals(this._pt)||!!w.equals(this._pt))))}},{key:"addSnappedNode",value:function(b,w){var L=b.getCoordinate(w),G=b.getCoordinate(w+1);return!!this.intersects(L,G)&&(b.addIntersection(this.getCoordinate(),w),!0)}}],[{key:"constructor_",value:function(){this._li=null,this._pt=null,this._originalPt=null,this._ptScaled=null,this._p0Scaled=null,this._p1Scaled=null,this._scaleFactor=null,this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,this._corner=new Array(4).fill(null),this._safeEnv=null;var b=arguments[0],w=arguments[1],L=arguments[2];if(this._originalPt=b,this._pt=b,this._scaleFactor=w,this._li=L,w<=0)throw new Z("Scale factor must be non-zero");w!==1&&(this._pt=new Le(this.scale(b.x),this.scale(b.y)),this._p0Scaled=new Le,this._p1Scaled=new Le),this.initCorners(this._pt)}}])})();ai.SAFE_ENV_EXPANSION_FACTOR=.75;var ue=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"select",value:function(){if(arguments.length!==1){if(arguments.length===2){var B=arguments[1];arguments[0].getLineSegment(B,this.selectedSegment),this.select(this.selectedSegment)}}}}],[{key:"constructor_",value:function(){this.selectedSegment=new bs}}])})(),$=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"snap",value:function(){if(arguments.length===1){var B=arguments[0];return this.snap(B,null,-1)}if(arguments.length===3){var b=arguments[0],w=arguments[1],L=arguments[2],G=b.getSafeEnvelope(),K=new Ue(b,w,L);return this._index.query(G,new((function(){return l((function le(){r(this,le)}),[{key:"interfaces_",get:function(){return[yh]}},{key:"visitItem",value:function(le){le.select(G,K)}}])})())),K.isNodeAdded()}}}],[{key:"constructor_",value:function(){this._index=null;var B=arguments[0];this._index=B}}])})(),Ue=(function(B){function b(){var w;return r(this,b),w=n(this,b),b.constructor_.apply(w,arguments),w}return g(b,B),l(b,[{key:"isNodeAdded",value:function(){return this._isNodeAdded}},{key:"select",value:function(){if(!(arguments.length===2&&Number.isInteger(arguments[1])&&arguments[0]instanceof lc))return E(b,"select",this,1).apply(this,arguments);var w=arguments[1],L=arguments[0].getContext();if(this._parentEdge===L&&(w===this._hotPixelVertexIndex||w+1===this._hotPixelVertexIndex))return null;this._isNodeAdded|=this._hotPixel.addSnappedNode(L,w)}}],[{key:"constructor_",value:function(){this._hotPixel=null,this._parentEdge=null,this._hotPixelVertexIndex=null,this._isNodeAdded=!1;var w=arguments[0],L=arguments[1],G=arguments[2];this._hotPixel=w,this._parentEdge=L,this._hotPixelVertexIndex=G}}])})(ue);$.HotPixelSnapAction=Ue;var tt=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"processIntersections",value:function(B,b,w,L){if(B===w&&b===L)return null;var G=B.getCoordinates()[b],K=B.getCoordinates()[b+1],le=w.getCoordinates()[L],fe=w.getCoordinates()[L+1];if(this._li.computeIntersection(G,K,le,fe),this._li.hasIntersection()&&this._li.isInteriorIntersection()){for(var _e=0;_e<this._li.getIntersectionNum();_e++)this._interiorIntersections.add(this._li.getIntersection(_e));B.addIntersections(this._li,b,0),w.addIntersections(this._li,L,1)}}},{key:"isDone",value:function(){return!1}},{key:"getInteriorIntersections",value:function(){return this._interiorIntersections}},{key:"interfaces_",get:function(){return[en]}}],[{key:"constructor_",value:function(){this._li=null,this._interiorIntersections=null;var B=arguments[0];this._li=B,this._interiorIntersections=new Pt}}])})(),wt=(function(){return l((function B(){r(this,B),B.constructor_.apply(this,arguments)}),[{key:"checkCorrectness",value:function(B){var b=new Qt(fa.getNodedSubstrings(B));try{b.checkValid()}catch(w){if(!(w instanceof F))throw w;w.printStackTrace()}}},{key:"getNodedSubstrings",value:function(){return fa.getNodedSubstrings(this._nodedSegStrings)}},{key:"snapRound",value:function(B,b){var w=this.findInteriorIntersections(B,b);this.computeIntersectionSnaps(w),this.computeVertexSnaps(B)}},{key:"findInteriorIntersections",value:function(B,b){var w=new tt(b);return this._noder.setSegmentIntersector(w),this._noder.computeNodes(B),w.getInteriorIntersections()}},{key:"computeVertexSnaps",value:function(){if(Pe(arguments[0],vt))for(var B=arguments[0].iterator();B.hasNext();){var b=B.next();this.computeVertexSnaps(b)}else if(arguments[0]instanceof fa)for(var w=arguments[0],L=w.getCoordinates(),G=0;G<L.length;G++){var K=new ai(L[G],this._scaleFactor,this._li);this._pointSnapper.snap(K,w,G)&&w.addIntersection(L[G],G)}}},{key:"computeNodes",value:function(B){this._nodedSegStrings=B,this._noder=new Tl,this._pointSnapper=new $(this._noder.getIndex()),this.snapRound(B,this._li)}},{key:"computeIntersectionSnaps",value:function(B){for(var b=B.iterator();b.hasNext();){var w=new ai(b.next(),this._scaleFactor,this._li);this._pointSnapper.snap(w)}}},{key:"interfaces_",get:function(){return[Il]}}],[{key:"constructor_",value:function(){this._pm=null,this._li=null,this._scaleFactor=null,this._noder=null,this._pointSnapper=null,this._nodedSegStrings=null;var B=arguments[0];this._pm=B,this._li=new ys,this._li.setPrecisionModel(B),this._scaleFactor=B.getScale()}}])})(),Nt=(function(){function B(){r(this,B),B.constructor_.apply(this,arguments)}return l(B,[{key:"bufferFixedPrecision",value:function(b){var w=new Gt(new wt(new yi(1)),b.getScale()),L=new Ht(this._bufParams);L.setWorkingPrecisionModel(b),L.setNoder(w),this._resultGeometry=L.buffer(this._argGeom,this._distance)}},{key:"bufferReducedPrecision",value:function(){if(arguments.length===0){for(var b=B.MAX_PRECISION_DIGITS;b>=0;b--){try{this.bufferReducedPrecision(b)}catch(G){if(!(G instanceof ii))throw G;this._saveException=G}if(this._resultGeometry!==null)return null}throw this._saveException}if(arguments.length===1){var w=arguments[0],L=new yi(B.precisionScaleFactor(this._argGeom,this._distance,w));this.bufferFixedPrecision(L)}}},{key:"computeGeometry",value:function(){if(this.bufferOriginalPrecision(),this._resultGeometry!==null)return null;var b=this._argGeom.getFactory().getPrecisionModel();b.getType()===yi.FIXED?this.bufferFixedPrecision(b):this.bufferReducedPrecision()}},{key:"setQuadrantSegments",value:function(b){this._bufParams.setQuadrantSegments(b)}},{key:"bufferOriginalPrecision",value:function(){try{var b=new Ht(this._bufParams);this._resultGeometry=b.buffer(this._argGeom,this._distance)}catch(w){if(!(w instanceof we))throw w;this._saveException=w}}},{key:"getResultGeometry",value:function(b){return this._distance=b,this.computeGeometry(),this._resultGeometry}},{key:"setEndCapStyle",value:function(b){this._bufParams.setEndCapStyle(b)}}],[{key:"constructor_",value:function(){if(this._argGeom=null,this._distance=null,this._bufParams=new D,this._resultGeometry=null,this._saveException=null,arguments.length===1){var b=arguments[0];this._argGeom=b}else if(arguments.length===2){var w=arguments[0],L=arguments[1];this._argGeom=w,this._bufParams=L}}},{key:"bufferOp",value:function(){if(arguments.length===2){var b=arguments[1];return new B(arguments[0]).getResultGeometry(b)}if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof lt&&typeof arguments[1]=="number"){var w=arguments[1],L=arguments[2],G=new B(arguments[0]);return G.setQuadrantSegments(L),G.getResultGeometry(w)}if(arguments[2]instanceof D&&arguments[0]instanceof lt&&typeof arguments[1]=="number"){var K=arguments[1];return new B(arguments[0],arguments[2]).getResultGeometry(K)}}else if(arguments.length===4){var le=arguments[1],fe=arguments[2],_e=arguments[3],Oe=new B(arguments[0]);return Oe.setQuadrantSegments(fe),Oe.setEndCapStyle(_e),Oe.getResultGeometry(le)}}},{key:"precisionScaleFactor",value:function(b,w,L){var G=b.getEnvelopeInternal(),K=at.max(Math.abs(G.getMaxX()),Math.abs(G.getMaxY()),Math.abs(G.getMinX()),Math.abs(G.getMinY()))+2*(w>0?w:0),le=L-Math.trunc(Math.log(K)/Math.log(10)+1);return Math.pow(10,le)}}])})();Nt.CAP_ROUND=D.CAP_ROUND,Nt.CAP_BUTT=D.CAP_FLAT,Nt.CAP_FLAT=D.CAP_FLAT,Nt.CAP_SQUARE=D.CAP_SQUARE,Nt.MAX_PRECISION_DIGITS=12;var se=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],Dt=(function(){return l((function B(b){r(this,B),this.geometryFactory=b||new qi}),[{key:"read",value:function(B){var b,w=(b=typeof B=="string"?JSON.parse(B):B).type;if(!jt[w])throw new Error("Unknown GeoJSON type: "+b.type);return se.indexOf(w)!==-1?jt[w].call(this,b.coordinates):w==="GeometryCollection"?jt[w].call(this,b.geometries):jt[w].call(this,b)}},{key:"write",value:function(B){var b=B.getGeometryType();if(!Ct[b])throw new Error("Geometry is not supported");return Ct[b].call(this,B)}}])})(),jt={Feature:function(B){var b={};for(var w in B)b[w]=B[w];if(B.geometry){if(!jt[B.geometry.type])throw new Error("Unknown GeoJSON type: "+B.type);b.geometry=this.read(B.geometry)}return B.bbox&&(b.bbox=jt.bbox.call(this,B.bbox)),b},FeatureCollection:function(B){var b={};if(B.features){b.features=[];for(var w=0;w<B.features.length;++w)b.features.push(this.read(B.features[w]))}return B.bbox&&(b.bbox=this.parse.bbox.call(this,B.bbox)),b},coordinates:function(B){for(var b=[],w=0;w<B.length;++w){var L=B[w];b.push(s(Le,S(L)))}return b},bbox:function(B){return this.geometryFactory.createLinearRing([new Le(B[0],B[1]),new Le(B[2],B[1]),new Le(B[2],B[3]),new Le(B[0],B[3]),new Le(B[0],B[1])])},Point:function(B){var b=s(Le,S(B));return this.geometryFactory.createPoint(b)},MultiPoint:function(B){for(var b=[],w=0;w<B.length;++w)b.push(jt.Point.call(this,B[w]));return this.geometryFactory.createMultiPoint(b)},LineString:function(B){var b=jt.coordinates.call(this,B);return this.geometryFactory.createLineString(b)},MultiLineString:function(B){for(var b=[],w=0;w<B.length;++w)b.push(jt.LineString.call(this,B[w]));return this.geometryFactory.createMultiLineString(b)},Polygon:function(B){for(var b=jt.coordinates.call(this,B[0]),w=this.geometryFactory.createLinearRing(b),L=[],G=1;G<B.length;++G){var K=B[G],le=jt.coordinates.call(this,K),fe=this.geometryFactory.createLinearRing(le);L.push(fe)}return this.geometryFactory.createPolygon(w,L)},MultiPolygon:function(B){for(var b=[],w=0;w<B.length;++w){var L=B[w];b.push(jt.Polygon.call(this,L))}return this.geometryFactory.createMultiPolygon(b)},GeometryCollection:function(B){for(var b=[],w=0;w<B.length;++w){var L=B[w];b.push(this.read(L))}return this.geometryFactory.createGeometryCollection(b)}},Ct={coordinate:function(B){var b=[B.x,B.y];return B.z&&b.push(B.z),B.m&&b.push(B.m),b},Point:function(B){return{type:"Point",coordinates:Ct.coordinate.call(this,B.getCoordinate())}},MultiPoint:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=Ct.Point.call(this,L);b.push(G.coordinates)}return{type:"MultiPoint",coordinates:b}},LineString:function(B){for(var b=[],w=B.getCoordinates(),L=0;L<w.length;++L){var G=w[L];b.push(Ct.coordinate.call(this,G))}return{type:"LineString",coordinates:b}},MultiLineString:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=Ct.LineString.call(this,L);b.push(G.coordinates)}return{type:"MultiLineString",coordinates:b}},Polygon:function(B){var b=[],w=Ct.LineString.call(this,B._shell);b.push(w.coordinates);for(var L=0;L<B._holes.length;++L){var G=B._holes[L],K=Ct.LineString.call(this,G);b.push(K.coordinates)}return{type:"Polygon",coordinates:b}},MultiPolygon:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=Ct.Polygon.call(this,L);b.push(G.coordinates)}return{type:"MultiPolygon",coordinates:b}},GeometryCollection:function(B){for(var b=[],w=0;w<B._geometries.length;++w){var L=B._geometries[w],G=L.getGeometryType();b.push(Ct[G].call(this,L))}return{type:"GeometryCollection",geometries:b}}};return{BufferOp:Nt,GeoJSONReader:(function(){return l((function B(b){r(this,B),this.parser=new Dt(b||new qi)}),[{key:"read",value:function(B){return this.parser.read(B)}}])})(),GeoJSONWriter:(function(){return l((function B(){r(this,B),this.parser=new Dt(this.geometryFactory)}),[{key:"write",value:function(B){return this.parser.write(B)}}])})()}}))})(SM)),SM.exports}var Mhe=Vj(She());function p0(){return new mI}function mI(){this.reset()}mI.prototype={constructor:mI,reset:function(){this.s=this.t=0},add:function(e){e$(yE,e,this.t),e$(this,yE.s,this.s),this.s?this.t+=yE.t:this.s=yE.t},valueOf:function(){return this.s}};var yE=new mI;function e$(e,t,i){var n=e.s=t+i,r=n-t;e.t=t-(n-r)+(i-r)}var Yr=1e-6,mr=Math.PI,Fu=mr/2,t$=mr/4,Wu=mr*2,ip=180/mr,rh=mr/180,Ha=Math.abs,Ihe=Math.atan,JA=Math.atan2,Ts=Math.cos,Rs=Math.sin,Cv=Math.sqrt;function Xj(e){return e>1?0:e<-1?mr:Math.acos(e)}function $m(e){return e>1?Fu:e<-1?-Fu:Math.asin(e)}function H1(){}function gI(e,t){e&&n$.hasOwnProperty(e.type)&&n$[e.type](e,t)}var i$={Feature:function(e,t){gI(e.geometry,t)},FeatureCollection:function(e,t){for(var i=e.features,n=-1,r=i.length;++n<r;)gI(i[n].geometry,t)}},n$={Sphere:function(e,t){t.sphere()},Point:function(e,t){e=e.coordinates,t.point(e[0],e[1],e[2])},MultiPoint:function(e,t){for(var i=e.coordinates,n=-1,r=i.length;++n<r;)e=i[n],t.point(e[0],e[1],e[2])},LineString:function(e,t){h6(e.coordinates,t,0)},MultiLineString:function(e,t){for(var i=e.coordinates,n=-1,r=i.length;++n<r;)h6(i[n],t,0)},Polygon:function(e,t){r$(e.coordinates,t)},MultiPolygon:function(e,t){for(var i=e.coordinates,n=-1,r=i.length;++n<r;)r$(i[n],t)},GeometryCollection:function(e,t){for(var i=e.geometries,n=-1,r=i.length;++n<r;)gI(i[n],t)}};function h6(e,t,i){var n=-1,r=e.length-i,s;for(t.lineStart();++n<r;)s=e[n],t.point(s[0],s[1],s[2]);t.lineEnd()}function r$(e,t){var i=-1,n=e.length;for(t.polygonStart();++i<n;)h6(e[i],t,1);t.polygonEnd()}function The(e,t){e&&i$.hasOwnProperty(e.type)?i$[e.type](e,t):gI(e,t)}p0();p0();function u6(e){return[JA(e[1],e[0]),$m(e[2])]}function KA(e){var t=e[0],i=e[1],n=Ts(i);return[n*Ts(t),n*Rs(t),Rs(i)]}function bE(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function _I(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function n8(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function xE(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function d6(e){var t=Cv(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}p0();function Zj(e,t){function i(n,r){return n=e(n,r),t(n[0],n[1])}return e.invert&&t.invert&&(i.invert=function(n,r){return n=t.invert(n,r),n&&e.invert(n[0],n[1])}),i}function f6(e,t){return[e>mr?e-Wu:e<-mr?e+Wu:e,t]}f6.invert=f6;function Rhe(e,t,i){return(e%=Wu)?t||i?Zj(a$(e),o$(t,i)):a$(e):t||i?o$(t,i):f6}function s$(e){return function(t,i){return t+=e,[t>mr?t-Wu:t<-mr?t+Wu:t,i]}}function a$(e){var t=s$(e);return t.invert=s$(-e),t}function o$(e,t){var i=Ts(e),n=Rs(e),r=Ts(t),s=Rs(t);function a(l,h){var d=Ts(h),p=Ts(l)*d,g=Rs(l)*d,v=Rs(h),y=v*i+p*n;return[JA(g*r-y*s,p*i-v*n),$m(y*r+g*s)]}return a.invert=function(l,h){var d=Ts(h),p=Ts(l)*d,g=Rs(l)*d,v=Rs(h),y=v*r-g*s;return[JA(g*r+v*s,p*i+y*n),$m(y*i-p*n)]},a}function Bhe(e,t,i,n,r,s){if(i){var a=Ts(t),l=Rs(t),h=n*i;r==null?(r=t+n*Wu,s=t-h/2):(r=l$(a,r),s=l$(a,s),(n>0?r<s:r>s)&&(r+=n*Wu));for(var d,p=r;n>0?p>s:p<s;p-=h)d=u6([a,-l*Ts(p),-l*Rs(p)]),e.point(d[0],d[1])}}function l$(e,t){t=KA(t),t[0]-=e,d6(t);var i=Xj(-t[1]);return((-t[2]<0?-i:i)+Wu-Yr)%Wu}function qj(){var e=[],t;return{point:function(i,n){t.push([i,n])},lineStart:function(){e.push(t=[])},lineEnd:H1,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var i=e;return e=[],t=null,i}}}function Lhe(e,t,i,n,r,s){var a=e[0],l=e[1],h=t[0],d=t[1],p=0,g=1,v=h-a,y=d-l,E=i-a;if(!(!v&&E>0)){if(E/=v,v<0){if(E<p)return;E<g&&(g=E)}else if(v>0){if(E>g)return;E>p&&(p=E)}if(E=r-a,!(!v&&E<0)){if(E/=v,v<0){if(E>g)return;E>p&&(p=E)}else if(v>0){if(E<p)return;E<g&&(g=E)}if(E=n-l,!(!y&&E>0)){if(E/=y,y<0){if(E<p)return;E<g&&(g=E)}else if(y>0){if(E>g)return;E>p&&(p=E)}if(E=s-l,!(!y&&E<0)){if(E/=y,y<0){if(E>g)return;E>p&&(p=E)}else if(y>0){if(E<p)return;E<g&&(g=E)}return p>0&&(e[0]=a+p*v,e[1]=l+p*y),g<1&&(t[0]=a+g*v,t[1]=l+g*y),!0}}}}}function MM(e,t){return Ha(e[0]-t[0])<Yr&&Ha(e[1]-t[1])<Yr}function wE(e,t,i,n){this.x=e,this.z=t,this.o=i,this.e=n,this.v=!1,this.n=this.p=null}function Yj(e,t,i,n,r){var s=[],a=[],l,h;if(e.forEach(function(E){if(!((S=E.length-1)<=0)){var S,R=E[0],I=E[S],k;if(MM(R,I)){for(r.lineStart(),l=0;l<S;++l)r.point((R=E[l])[0],R[1]);r.lineEnd();return}s.push(k=new wE(R,E,null,!0)),a.push(k.o=new wE(R,null,k,!1)),s.push(k=new wE(I,E,null,!1)),a.push(k.o=new wE(I,null,k,!0))}}),!!s.length){for(a.sort(t),c$(s),c$(a),l=0,h=a.length;l<h;++l)a[l].e=i=!i;for(var d=s[0],p,g;;){for(var v=d,y=!0;v.v;)if((v=v.n)===d)return;p=v.z,r.lineStart();do{if(v.v=v.o.v=!0,v.e){if(y)for(l=0,h=p.length;l<h;++l)r.point((g=p[l])[0],g[1]);else n(v.x,v.n.x,1,r);v=v.n}else{if(y)for(p=v.p.z,l=p.length-1;l>=0;--l)r.point((g=p[l])[0],g[1]);else n(v.x,v.p.x,-1,r);v=v.p}v=v.o,p=v.z,y=!y}while(!v.v);r.lineEnd()}}}function c$(e){if(t=e.length){for(var t,i=0,n=e[0],r;++i<t;)n.n=r=e[i],r.p=n,n=r;n.n=r=e[0],r.p=n}}function jj(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function khe(e){return e.length===1&&(e=Phe(e)),{left:function(t,i,n,r){for(n==null&&(n=0),r==null&&(r=t.length);n<r;){var s=n+r>>>1;e(t[s],i)<0?n=s+1:r=s}return n},right:function(t,i,n,r){for(n==null&&(n=0),r==null&&(r=t.length);n<r;){var s=n+r>>>1;e(t[s],i)>0?r=s:n=s+1}return n}}}function Phe(e){return function(t,i){return jj(e(t),i)}}khe(jj);function Jj(e){for(var t=e.length,i,n=-1,r=0,s,a;++n<t;)r+=e[n].length;for(s=new Array(r);--t>=0;)for(a=e[t],i=a.length;--i>=0;)s[--r]=a[i];return s}var Q1=1e9,CE=-Q1;function Nhe(e,t,i,n){function r(d,p){return e<=d&&d<=i&&t<=p&&p<=n}function s(d,p,g,v){var y=0,E=0;if(d==null||(y=a(d,g))!==(E=a(p,g))||h(d,p)<0^g>0)do v.point(y===0||y===3?e:i,y>1?n:t);while((y=(y+g+4)%4)!==E);else v.point(p[0],p[1])}function a(d,p){return Ha(d[0]-e)<Yr?p>0?0:3:Ha(d[0]-i)<Yr?p>0?2:1:Ha(d[1]-t)<Yr?p>0?1:0:p>0?3:2}function l(d,p){return h(d.x,p.x)}function h(d,p){var g=a(d,1),v=a(p,1);return g!==v?g-v:g===0?p[1]-d[1]:g===1?d[0]-p[0]:g===2?d[1]-p[1]:p[0]-d[0]}return function(d){var p=d,g=qj(),v,y,E,S,R,I,k,D,F,Z,Y,Q={point:V,lineStart:ne,lineEnd:te,polygonStart:H,polygonEnd:W};function V(X,ee){r(X,ee)&&p.point(X,ee)}function U(){for(var X=0,ee=0,ae=y.length;ee<ae;++ee)for(var ce=y[ee],de=1,pe=ce.length,Ie=ce[0],we,Ee,Se=Ie[0],Ve=Ie[1];de<pe;++de)we=Se,Ee=Ve,Ie=ce[de],Se=Ie[0],Ve=Ie[1],Ee<=n?Ve>n&&(Se-we)*(n-Ee)>(Ve-Ee)*(e-we)&&++X:Ve<=n&&(Se-we)*(n-Ee)<(Ve-Ee)*(e-we)&&--X;return X}function H(){p=g,v=[],y=[],Y=!0}function W(){var X=U(),ee=Y&&X,ae=(v=Jj(v)).length;(ee||ae)&&(d.polygonStart(),ee&&(d.lineStart(),s(null,null,1,d),d.lineEnd()),ae&&Yj(v,l,X,s,d),d.polygonEnd()),p=d,v=y=E=null}function ne(){Q.point=oe,y&&y.push(E=[]),Z=!0,F=!1,k=D=NaN}function te(){v&&(oe(S,R),I&&F&&g.rejoin(),v.push(g.result())),Q.point=V,F&&p.lineEnd()}function oe(X,ee){var ae=r(X,ee);if(y&&E.push([X,ee]),Z)S=X,R=ee,I=ae,Z=!1,ae&&(p.lineStart(),p.point(X,ee));else if(ae&&F)p.point(X,ee);else{var ce=[k=Math.max(CE,Math.min(Q1,k)),D=Math.max(CE,Math.min(Q1,D))],de=[X=Math.max(CE,Math.min(Q1,X)),ee=Math.max(CE,Math.min(Q1,ee))];Lhe(ce,de,e,t,i,n)?(F||(p.lineStart(),p.point(ce[0],ce[1])),p.point(de[0],de[1]),ae||p.lineEnd(),Y=!1):ae&&(p.lineStart(),p.point(X,ee),Y=!1)}k=X,D=ee,F=ae}return Q}}var r8=p0();function Fhe(e,t){var i=t[0],n=t[1],r=[Rs(i),-Ts(i),0],s=0,a=0;r8.reset();for(var l=0,h=e.length;l<h;++l)if(p=(d=e[l]).length)for(var d,p,g=d[p-1],v=g[0],y=g[1]/2+t$,E=Rs(y),S=Ts(y),R=0;R<p;++R,v=k,E=F,S=Z,g=I){var I=d[R],k=I[0],D=I[1]/2+t$,F=Rs(D),Z=Ts(D),Y=k-v,Q=Y>=0?1:-1,V=Q*Y,U=V>mr,H=E*F;if(r8.add(JA(H*Q*Rs(V),S*Z+H*Ts(V))),s+=U?Y+Q*Wu:Y,U^v>=i^k>=i){var W=_I(KA(g),KA(I));d6(W);var ne=_I(r,W);d6(ne);var te=(U^Y>=0?-1:1)*$m(ne[2]);(n>te||n===te&&(W[0]||W[1]))&&(a+=U^Y>=0?1:-1)}}return(s<-Yr||s<Yr&&r8<-Yr)^a&1}p0();function h$(e){return e}p0();p0();var ev=1/0,AI=ev,Yb=-ev,vI=Yb,u$={point:Dhe,lineStart:H1,lineEnd:H1,polygonStart:H1,polygonEnd:H1,result:function(){var e=[[ev,AI],[Yb,vI]];return Yb=vI=-(AI=ev=1/0),e}};function Dhe(e,t){e<ev&&(ev=e),e>Yb&&(Yb=e),t<AI&&(AI=t),t>vI&&(vI=t)}p0();function Kj(e,t,i,n){return function(r,s){var a=t(s),l=r.invert(n[0],n[1]),h=qj(),d=t(h),p=!1,g,v,y,E={point:S,lineStart:I,lineEnd:k,polygonStart:function(){E.point=D,E.lineStart=F,E.lineEnd=Z,v=[],g=[]},polygonEnd:function(){E.point=S,E.lineStart=I,E.lineEnd=k,v=Jj(v);var Y=Fhe(g,l);v.length?(p||(s.polygonStart(),p=!0),Yj(v,Uhe,Y,i,s)):Y&&(p||(s.polygonStart(),p=!0),s.lineStart(),i(null,null,1,s),s.lineEnd()),p&&(s.polygonEnd(),p=!1),v=g=null},sphere:function(){s.polygonStart(),s.lineStart(),i(null,null,1,s),s.lineEnd(),s.polygonEnd()}};function S(Y,Q){var V=r(Y,Q);e(Y=V[0],Q=V[1])&&s.point(Y,Q)}function R(Y,Q){var V=r(Y,Q);a.point(V[0],V[1])}function I(){E.point=R,a.lineStart()}function k(){E.point=S,a.lineEnd()}function D(Y,Q){y.push([Y,Q]);var V=r(Y,Q);d.point(V[0],V[1])}function F(){d.lineStart(),y=[]}function Z(){D(y[0][0],y[0][1]),d.lineEnd();var Y=d.clean(),Q=h.result(),V,U=Q.length,H,W,ne;if(y.pop(),g.push(y),y=null,!!U){if(Y&1){if(W=Q[0],(H=W.length-1)>0){for(p||(s.polygonStart(),p=!0),s.lineStart(),V=0;V<H;++V)s.point((ne=W[V])[0],ne[1]);s.lineEnd()}return}U>1&&Y&2&&Q.push(Q.pop().concat(Q.shift())),v.push(Q.filter(Ohe))}}return E}}function Ohe(e){return e.length>1}function Uhe(e,t){return((e=e.x)[0]<0?e[1]-Fu-Yr:Fu-e[1])-((t=t.x)[0]<0?t[1]-Fu-Yr:Fu-t[1])}var d$=Kj(function(){return!0},Ghe,Vhe,[-mr,-Fu]);function Ghe(e){var t=NaN,i=NaN,n=NaN,r;return{lineStart:function(){e.lineStart(),r=1},point:function(s,a){var l=s>0?mr:-mr,h=Ha(s-t);Ha(h-mr)<Yr?(e.point(t,i=(i+a)/2>0?Fu:-Fu),e.point(n,i),e.lineEnd(),e.lineStart(),e.point(l,i),e.point(s,i),r=0):n!==l&&h>=mr&&(Ha(t-n)<Yr&&(t-=n*Yr),Ha(s-l)<Yr&&(s-=l*Yr),i=zhe(t,i,s,a),e.point(n,i),e.lineEnd(),e.lineStart(),e.point(l,i),r=0),e.point(t=s,i=a),n=l},lineEnd:function(){e.lineEnd(),t=i=NaN},clean:function(){return 2-r}}}function zhe(e,t,i,n){var r,s,a=Rs(e-i);return Ha(a)>Yr?Ihe((Rs(t)*(s=Ts(n))*Rs(i)-Rs(n)*(r=Ts(t))*Rs(e))/(r*s*a)):(t+n)/2}function Vhe(e,t,i,n){var r;if(e==null)r=i*Fu,n.point(-mr,r),n.point(0,r),n.point(mr,r),n.point(mr,0),n.point(mr,-r),n.point(0,-r),n.point(-mr,-r),n.point(-mr,0),n.point(-mr,r);else if(Ha(e[0]-t[0])>Yr){var s=e[0]<t[0]?mr:-mr;r=i*s/2,n.point(-s,r),n.point(0,r),n.point(s,r)}else n.point(t[0],t[1])}function $he(e,t){var i=Ts(e),n=i>0,r=Ha(i)>Yr;function s(p,g,v,y){Bhe(y,e,t,v,p,g)}function a(p,g){return Ts(p)*Ts(g)>i}function l(p){var g,v,y,E,S;return{lineStart:function(){E=y=!1,S=1},point:function(R,I){var k=[R,I],D,F=a(R,I),Z=n?F?0:d(R,I):F?d(R+(R<0?mr:-mr),I):0;if(!g&&(E=y=F)&&p.lineStart(),F!==y&&(D=h(g,k),(!D||MM(g,D)||MM(k,D))&&(k[0]+=Yr,k[1]+=Yr,F=a(k[0],k[1]))),F!==y)S=0,F?(p.lineStart(),D=h(k,g),p.point(D[0],D[1])):(D=h(g,k),p.point(D[0],D[1]),p.lineEnd()),g=D;else if(r&&g&&n^F){var Y;!(Z&v)&&(Y=h(k,g,!0))&&(S=0,n?(p.lineStart(),p.point(Y[0][0],Y[0][1]),p.point(Y[1][0],Y[1][1]),p.lineEnd()):(p.point(Y[1][0],Y[1][1]),p.lineEnd(),p.lineStart(),p.point(Y[0][0],Y[0][1])))}F&&(!g||!MM(g,k))&&p.point(k[0],k[1]),g=k,y=F,v=Z},lineEnd:function(){y&&p.lineEnd(),g=null},clean:function(){return S|(E&&y)<<1}}}function h(p,g,v){var y=KA(p),E=KA(g),S=[1,0,0],R=_I(y,E),I=bE(R,R),k=R[0],D=I-k*k;if(!D)return!v&&p;var F=i*I/D,Z=-i*k/D,Y=_I(S,R),Q=xE(S,F);n8(Q,xE(R,Z));var V=Y,U=bE(Q,V),H=bE(V,V),W=U*U-H*(bE(Q,Q)-1);if(!(W<0)){var ne=Cv(W),te=xE(V,(-U-ne)/H);if(n8(te,Q),te=u6(te),!v)return te;var oe=p[0],X=g[0],ee=p[1],ae=g[1],ce;X<oe&&(ce=oe,oe=X,X=ce);var de=X-oe,pe=Ha(de-mr)<Yr,Ie=pe||de<Yr;if(!pe&&ae<ee&&(ce=ee,ee=ae,ae=ce),Ie?pe?ee+ae>0^te[1]<(Ha(te[0]-oe)<Yr?ee:ae):ee<=te[1]&&te[1]<=ae:de>mr^(oe<=te[0]&&te[0]<=X)){var we=xE(V,(-U+ne)/H);return n8(we,Q),[te,u6(we)]}}}function d(p,g){var v=n?e:mr-e,y=0;return p<-v?y|=1:p>v&&(y|=2),g<-v?y|=4:g>v&&(y|=8),y}return Kj(a,l,s,n?[0,-e]:[-mr,e-mr])}function eJ(e){return function(t){var i=new p6;for(var n in e)i[n]=e[n];return i.stream=t,i}}function p6(){}p6.prototype={constructor:p6,point:function(e,t){this.stream.point(e,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function tJ(e,t,i){var n=t[1][0]-t[0][0],r=t[1][1]-t[0][1],s=e.clipExtent&&e.clipExtent();e.scale(150).translate([0,0]),s!=null&&e.clipExtent(null),The(i,e.stream(u$));var a=u$.result(),l=Math.min(n/(a[1][0]-a[0][0]),r/(a[1][1]-a[0][1])),h=+t[0][0]+(n-l*(a[1][0]+a[0][0]))/2,d=+t[0][1]+(r-l*(a[1][1]+a[0][1]))/2;return s!=null&&e.clipExtent(s),e.scale(l*150).translate([h,d])}function Hhe(e,t,i){return tJ(e,[[0,0],t],i)}var f$=16,Qhe=Ts(30*rh);function p$(e,t){return+t?Xhe(e,t):Whe(e)}function Whe(e){return eJ({point:function(t,i){t=e(t,i),this.stream.point(t[0],t[1])}})}function Xhe(e,t){function i(n,r,s,a,l,h,d,p,g,v,y,E,S,R){var I=d-n,k=p-r,D=I*I+k*k;if(D>4*t&&S--){var F=a+v,Z=l+y,Y=h+E,Q=Cv(F*F+Z*Z+Y*Y),V=$m(Y/=Q),U=Ha(Ha(Y)-1)<Yr||Ha(s-g)<Yr?(s+g)/2:JA(Z,F),H=e(U,V),W=H[0],ne=H[1],te=W-n,oe=ne-r,X=k*te-I*oe;(X*X/D>t||Ha((I*te+k*oe)/D-.5)>.3||a*v+l*y+h*E<Qhe)&&(i(n,r,s,a,l,h,W,ne,U,F/=Q,Z/=Q,Y,S,R),R.point(W,ne),i(W,ne,U,F,Z,Y,d,p,g,v,y,E,S,R))}}return function(n){var r,s,a,l,h,d,p,g,v,y,E,S,R={point:I,lineStart:k,lineEnd:F,polygonStart:function(){n.polygonStart(),R.lineStart=Z},polygonEnd:function(){n.polygonEnd(),R.lineStart=k}};function I(V,U){V=e(V,U),n.point(V[0],V[1])}function k(){g=NaN,R.point=D,n.lineStart()}function D(V,U){var H=KA([V,U]),W=e(V,U);i(g,v,p,y,E,S,g=W[0],v=W[1],p=V,y=H[0],E=H[1],S=H[2],f$,n),n.point(g,v)}function F(){R.point=I,n.lineEnd()}function Z(){k(),R.point=Y,R.lineEnd=Q}function Y(V,U){D(r=V,U),s=g,a=v,l=y,h=E,d=S,R.point=D}function Q(){i(g,v,p,y,E,S,s,a,r,l,h,d,f$,n),R.lineEnd=F,F()}return R}}var Zhe=eJ({point:function(e,t){this.stream.point(e*rh,t*rh)}});function qhe(e){return Yhe(function(){return e})()}function Yhe(e){var t,i=150,n=480,r=250,s,a,l=0,h=0,d=0,p=0,g=0,v,y,E=null,S=d$,R=null,I,k,D,F=h$,Z=.5,Y=p$(W,Z),Q,V;function U(oe){return oe=y(oe[0]*rh,oe[1]*rh),[oe[0]*i+s,a-oe[1]*i]}function H(oe){return oe=y.invert((oe[0]-s)/i,(a-oe[1])/i),oe&&[oe[0]*ip,oe[1]*ip]}function W(oe,X){return oe=t(oe,X),[oe[0]*i+s,a-oe[1]*i]}U.stream=function(oe){return Q&&V===oe?Q:Q=Zhe(S(v,Y(F(V=oe))))},U.clipAngle=function(oe){return arguments.length?(S=+oe?$he(E=oe*rh,6*rh):(E=null,d$),te()):E*ip},U.clipExtent=function(oe){return arguments.length?(F=oe==null?(R=I=k=D=null,h$):Nhe(R=+oe[0][0],I=+oe[0][1],k=+oe[1][0],D=+oe[1][1]),te()):R==null?null:[[R,I],[k,D]]},U.scale=function(oe){return arguments.length?(i=+oe,ne()):i},U.translate=function(oe){return arguments.length?(n=+oe[0],r=+oe[1],ne()):[n,r]},U.center=function(oe){return arguments.length?(l=oe[0]%360*rh,h=oe[1]%360*rh,ne()):[l*ip,h*ip]},U.rotate=function(oe){return arguments.length?(d=oe[0]%360*rh,p=oe[1]%360*rh,g=oe.length>2?oe[2]%360*rh:0,ne()):[d*ip,p*ip,g*ip]},U.precision=function(oe){return arguments.length?(Y=p$(W,Z=oe*oe),te()):Cv(Z)},U.fitExtent=function(oe,X){return tJ(U,oe,X)},U.fitSize=function(oe,X){return Hhe(U,oe,X)};function ne(){y=Zj(v=Rhe(d,p,g),t);var oe=t(l,h);return s=n-oe[0]*i,a=r+oe[1]*i,te()}function te(){return Q=V=null,U}return function(){return t=e.apply(this,arguments),U.invert=t.invert&&H,ne()}}function iJ(e){return function(t,i){var n=Ts(t),r=Ts(i),s=e(n*r);return[s*r*Rs(t),s*Rs(i)]}}function nJ(e){return function(t,i){var n=Cv(t*t+i*i),r=e(n),s=Rs(r),a=Ts(r);return[JA(t*s,n*a),$m(n&&i*s/n)]}}var jhe=iJ(function(e){return Cv(2/(1+e))});jhe.invert=nJ(function(e){return 2*$m(e/2)});var rJ=iJ(function(e){return(e=Xj(e))&&e/Rs(e)});rJ.invert=nJ(function(e){return e});function Jhe(){return qhe(rJ).scale(79.4188).clipAngle(179.999)}function m$(e,t){return[e,t]}m$.invert=m$;var{BufferOp:Khe,GeoJSONReader:eue,GeoJSONWriter:tue}=Mhe;function iue(e,t,i){i=i||{};var n=i.units||"kilometers",r=i.steps||8;if(!e)throw new Error("geojson is required");if(typeof i!="object")throw new Error("options must be an object");if(typeof r!="number")throw new Error("steps must be an number");if(t===void 0)throw new Error("radius is required");if(r<=0)throw new Error("steps must be greater than 0");var s=[];switch(e.type){case"GeometryCollection":return f0(e,function(a){var l=IM(a,t,n,r);l&&s.push(l)}),Qn(s);case"FeatureCollection":return Af(e,function(a){var l=IM(a,t,n,r);l&&Af(l,function(h){h&&s.push(h)})}),Qn(s)}return IM(e,t,n,r)}function IM(e,t,i,n){var r=e.properties||{},s=e.type==="Feature"?e.geometry:e;if(s.type==="GeometryCollection"){var a=[];return f0(e,function(v){var y=IM(v,t,i,n);y&&a.push(y)}),Qn(a)}var l=nue(s),h={type:s.type,coordinates:aJ(s.coordinates,l)},d=new eue().read(h),p=YG(Tj(t,i),"meters"),g=Khe.bufferOp(d,p,n);if(g=new tue().write(g),!sJ(g.coordinates))return ic({type:g.type,coordinates:oJ(g.coordinates,l)},r)}function sJ(e){return Array.isArray(e[0])?sJ(e[0]):isNaN(e[0])}function aJ(e,t){return typeof e[0]!="object"?t(e):e.map(function(i){return aJ(i,t)})}function oJ(e,t){return typeof e[0]!="object"?t.invert(e):e.map(function(i){return oJ(i,t)})}function nue(e){var t=Wj(e).geometry.coordinates,i=[-t[0],-t[1]];return Jhe().rotate(i).scale(Ua)}function jb(e,t={}){let i=0,n=0,r=0;return d0(e,function(s){i+=s[0],n+=s[1],r++},!0),aa([i/r,n/r],t.properties)}function Go(e){if(!e)throw new Error("geojson is required");switch(e.type){case"Feature":return lJ(e);case"FeatureCollection":return rue(e);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return rz(e);default:throw new Error("unknown GeoJSON type")}}function lJ(e){const t={type:"Feature"};return Object.keys(e).forEach(i=>{switch(i){case"type":case"properties":case"geometry":return;default:t[i]=e[i]}}),t.properties=cJ(e.properties),e.geometry==null?t.geometry=null:t.geometry=rz(e.geometry),t}function cJ(e){const t={};return e&&Object.keys(e).forEach(i=>{const n=e[i];typeof n=="object"?n===null?t[i]=null:Array.isArray(n)?t[i]=n.map(r=>r):t[i]=cJ(n):t[i]=n}),t}function rue(e){const t={type:"FeatureCollection"};return Object.keys(e).forEach(i=>{switch(i){case"type":case"features":return;default:t[i]=e[i]}}),t.features=e.features.map(i=>lJ(i)),t}function rz(e){const t={type:e.type};return e.bbox&&(t.bbox=e.bbox),e.type==="GeometryCollection"?(t.geometries=e.geometries.map(i=>rz(i)),t):(t.coordinates=hJ(e.coordinates),t)}function hJ(e){const t=e;return typeof t[0]!="object"?t.slice():t.map(i=>hJ(i))}var sue=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,s8=Math.ceil,Jc=Math.floor,Ol="[BigNumber Error] ",g$=Ol+"Number primitive has more than 15 significant digits: ",Rh=1e14,Nn=14,a8=9007199254740991,o8=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],np=1e7,Fa=1e9;function uJ(e){var t,i,n,r=k.prototype={constructor:k,toString:null,valueOf:null},s=new k(1),a=20,l=4,h=-7,d=21,p=-1e7,g=1e7,v=!1,y=1,E=0,S={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},R="0123456789abcdefghijklmnopqrstuvwxyz",I=!0;function k(V,U){var H,W,ne,te,oe,X,ee,ae,ce=this;if(!(ce instanceof k))return new k(V,U);if(U==null){if(V&&V._isBigNumber===!0){ce.s=V.s,!V.c||V.e>g?ce.c=ce.e=null:V.e<p?ce.c=[ce.e=0]:(ce.e=V.e,ce.c=V.c.slice());return}if((X=typeof V=="number")&&V*0==0){if(ce.s=1/V<0?(V=-V,-1):1,V===~~V){for(te=0,oe=V;oe>=10;oe/=10,te++);te>g?ce.c=ce.e=null:(ce.e=te,ce.c=[V]);return}ae=String(V)}else{if(!sue.test(ae=String(V)))return n(ce,ae,X);ce.s=ae.charCodeAt(0)==45?(ae=ae.slice(1),-1):1}(te=ae.indexOf("."))>-1&&(ae=ae.replace(".","")),(oe=ae.search(/e/i))>0?(te<0&&(te=oe),te+=+ae.slice(oe+1),ae=ae.substring(0,oe)):te<0&&(te=ae.length)}else{if(xs(U,2,R.length,"Base"),U==10&&I)return ce=new k(V),Y(ce,a+ce.e+1,l);if(ae=String(V),X=typeof V=="number"){if(V*0!=0)return n(ce,ae,X,U);if(ce.s=1/V<0?(ae=ae.slice(1),-1):1,k.DEBUG&&ae.replace(/^0\.0*|\./,"").length>15)throw Error(g$+V)}else ce.s=ae.charCodeAt(0)===45?(ae=ae.slice(1),-1):1;for(H=R.slice(0,U),te=oe=0,ee=ae.length;oe<ee;oe++)if(H.indexOf(W=ae.charAt(oe))<0){if(W=="."){if(oe>te){te=ee;continue}}else if(!ne&&(ae==ae.toUpperCase()&&(ae=ae.toLowerCase())||ae==ae.toLowerCase()&&(ae=ae.toUpperCase()))){ne=!0,oe=-1,te=0;continue}return n(ce,String(V),X,U)}X=!1,ae=i(ae,U,10,ce.s),(te=ae.indexOf("."))>-1?ae=ae.replace(".",""):te=ae.length}for(oe=0;ae.charCodeAt(oe)===48;oe++);for(ee=ae.length;ae.charCodeAt(--ee)===48;);if(ae=ae.slice(oe,++ee)){if(ee-=oe,X&&k.DEBUG&&ee>15&&(V>a8||V!==Jc(V)))throw Error(g$+ce.s*V);if((te=te-oe-1)>g)ce.c=ce.e=null;else if(te<p)ce.c=[ce.e=0];else{if(ce.e=te,ce.c=[],oe=(te+1)%Nn,te<0&&(oe+=Nn),oe<ee){for(oe&&ce.c.push(+ae.slice(0,oe)),ee-=Nn;oe<ee;)ce.c.push(+ae.slice(oe,oe+=Nn));oe=Nn-(ae=ae.slice(oe)).length}else oe-=ee;for(;oe--;ae+="0");ce.c.push(+ae)}}else ce.c=[ce.e=0]}k.clone=uJ,k.ROUND_UP=0,k.ROUND_DOWN=1,k.ROUND_CEIL=2,k.ROUND_FLOOR=3,k.ROUND_HALF_UP=4,k.ROUND_HALF_DOWN=5,k.ROUND_HALF_EVEN=6,k.ROUND_HALF_CEIL=7,k.ROUND_HALF_FLOOR=8,k.EUCLID=9,k.config=k.set=function(V){var U,H;if(V!=null)if(typeof V=="object"){if(V.hasOwnProperty(U="DECIMAL_PLACES")&&(H=V[U],xs(H,0,Fa,U),a=H),V.hasOwnProperty(U="ROUNDING_MODE")&&(H=V[U],xs(H,0,8,U),l=H),V.hasOwnProperty(U="EXPONENTIAL_AT")&&(H=V[U],H&&H.pop?(xs(H[0],-Fa,0,U),xs(H[1],0,Fa,U),h=H[0],d=H[1]):(xs(H,-Fa,Fa,U),h=-(d=H<0?-H:H))),V.hasOwnProperty(U="RANGE"))if(H=V[U],H&&H.pop)xs(H[0],-Fa,-1,U),xs(H[1],1,Fa,U),p=H[0],g=H[1];else if(xs(H,-Fa,Fa,U),H)p=-(g=H<0?-H:H);else throw Error(Ol+U+" cannot be zero: "+H);if(V.hasOwnProperty(U="CRYPTO"))if(H=V[U],H===!!H)if(H)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))v=H;else throw v=!H,Error(Ol+"crypto unavailable");else v=H;else throw Error(Ol+U+" not true or false: "+H);if(V.hasOwnProperty(U="MODULO_MODE")&&(H=V[U],xs(H,0,9,U),y=H),V.hasOwnProperty(U="POW_PRECISION")&&(H=V[U],xs(H,0,Fa,U),E=H),V.hasOwnProperty(U="FORMAT"))if(H=V[U],typeof H=="object")S=H;else throw Error(Ol+U+" not an object: "+H);if(V.hasOwnProperty(U="ALPHABET"))if(H=V[U],typeof H=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(H))I=H.slice(0,10)=="0123456789",R=H;else throw Error(Ol+U+" invalid: "+H)}else throw Error(Ol+"Object expected: "+V);return{DECIMAL_PLACES:a,ROUNDING_MODE:l,EXPONENTIAL_AT:[h,d],RANGE:[p,g],CRYPTO:v,MODULO_MODE:y,POW_PRECISION:E,FORMAT:S,ALPHABET:R}},k.isBigNumber=function(V){if(!V||V._isBigNumber!==!0)return!1;if(!k.DEBUG)return!0;var U,H,W=V.c,ne=V.e,te=V.s;e:if({}.toString.call(W)=="[object Array]"){if((te===1||te===-1)&&ne>=-Fa&&ne<=Fa&&ne===Jc(ne)){if(W[0]===0){if(ne===0&&W.length===1)return!0;break e}if(U=(ne+1)%Nn,U<1&&(U+=Nn),String(W[0]).length==U){for(U=0;U<W.length;U++)if(H=W[U],H<0||H>=Rh||H!==Jc(H))break e;if(H!==0)return!0}}}else if(W===null&&ne===null&&(te===null||te===1||te===-1))return!0;throw Error(Ol+"Invalid BigNumber: "+V)},k.maximum=k.max=function(){return F(arguments,-1)},k.minimum=k.min=function(){return F(arguments,1)},k.random=(function(){var V=9007199254740992,U=Math.random()*V&2097151?function(){return Jc(Math.random()*V)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(H){var W,ne,te,oe,X,ee=0,ae=[],ce=new k(s);if(H==null?H=a:xs(H,0,Fa),oe=s8(H/Nn),v)if(crypto.getRandomValues){for(W=crypto.getRandomValues(new Uint32Array(oe*=2));ee<oe;)X=W[ee]*131072+(W[ee+1]>>>11),X>=9e15?(ne=crypto.getRandomValues(new Uint32Array(2)),W[ee]=ne[0],W[ee+1]=ne[1]):(ae.push(X%1e14),ee+=2);ee=oe/2}else if(crypto.randomBytes){for(W=crypto.randomBytes(oe*=7);ee<oe;)X=(W[ee]&31)*281474976710656+W[ee+1]*1099511627776+W[ee+2]*4294967296+W[ee+3]*16777216+(W[ee+4]<<16)+(W[ee+5]<<8)+W[ee+6],X>=9e15?crypto.randomBytes(7).copy(W,ee):(ae.push(X%1e14),ee+=7);ee=oe/7}else throw v=!1,Error(Ol+"crypto unavailable");if(!v)for(;ee<oe;)X=U(),X<9e15&&(ae[ee++]=X%1e14);for(oe=ae[--ee],H%=Nn,oe&&H&&(X=o8[Nn-H],ae[ee]=Jc(oe/X)*X);ae[ee]===0;ae.pop(),ee--);if(ee<0)ae=[te=0];else{for(te=-1;ae[0]===0;ae.splice(0,1),te-=Nn);for(ee=1,X=ae[0];X>=10;X/=10,ee++);ee<Nn&&(te-=Nn-ee)}return ce.e=te,ce.c=ae,ce}})(),k.sum=function(){for(var V=1,U=arguments,H=new k(U[0]);V<U.length;)H=H.plus(U[V++]);return H},i=(function(){var V="0123456789";function U(H,W,ne,te){for(var oe,X=[0],ee,ae=0,ce=H.length;ae<ce;){for(ee=X.length;ee--;X[ee]*=W);for(X[0]+=te.indexOf(H.charAt(ae++)),oe=0;oe<X.length;oe++)X[oe]>ne-1&&(X[oe+1]==null&&(X[oe+1]=0),X[oe+1]+=X[oe]/ne|0,X[oe]%=ne)}return X.reverse()}return function(H,W,ne,te,oe){var X,ee,ae,ce,de,pe,Ie,we,Ee=H.indexOf("."),Se=a,Ve=l;for(Ee>=0&&(ce=E,E=0,H=H.replace(".",""),we=new k(W),pe=we.pow(H.length-Ee),E=ce,we.c=U(kd(qc(pe.c),pe.e,"0"),10,ne,V),we.e=we.c.length),Ie=U(H,W,ne,oe?(X=R,V):(X=V,R)),ae=ce=Ie.length;Ie[--ce]==0;Ie.pop());if(!Ie[0])return X.charAt(0);if(Ee<0?--ae:(pe.c=Ie,pe.e=ae,pe.s=te,pe=t(pe,we,Se,Ve,ne),Ie=pe.c,de=pe.r,ae=pe.e),ee=ae+Se+1,Ee=Ie[ee],ce=ne/2,de=de||ee<0||Ie[ee+1]!=null,de=Ve<4?(Ee!=null||de)&&(Ve==0||Ve==(pe.s<0?3:2)):Ee>ce||Ee==ce&&(Ve==4||de||Ve==6&&Ie[ee-1]&1||Ve==(pe.s<0?8:7)),ee<1||!Ie[0])H=de?kd(X.charAt(1),-Se,X.charAt(0)):X.charAt(0);else{if(Ie.length=ee,de)for(--ne;++Ie[--ee]>ne;)Ie[ee]=0,ee||(++ae,Ie=[1].concat(Ie));for(ce=Ie.length;!Ie[--ce];);for(Ee=0,H="";Ee<=ce;H+=X.charAt(Ie[Ee++]));H=kd(H,ae,X.charAt(0))}return H}})(),t=(function(){function V(W,ne,te){var oe,X,ee,ae,ce=0,de=W.length,pe=ne%np,Ie=ne/np|0;for(W=W.slice();de--;)ee=W[de]%np,ae=W[de]/np|0,oe=Ie*ee+ae*pe,X=pe*ee+oe%np*np+ce,ce=(X/te|0)+(oe/np|0)+Ie*ae,W[de]=X%te;return ce&&(W=[ce].concat(W)),W}function U(W,ne,te,oe){var X,ee;if(te!=oe)ee=te>oe?1:-1;else for(X=ee=0;X<te;X++)if(W[X]!=ne[X]){ee=W[X]>ne[X]?1:-1;break}return ee}function H(W,ne,te,oe){for(var X=0;te--;)W[te]-=X,X=W[te]<ne[te]?1:0,W[te]=X*oe+W[te]-ne[te];for(;!W[0]&&W.length>1;W.splice(0,1));}return function(W,ne,te,oe,X){var ee,ae,ce,de,pe,Ie,we,Ee,Se,Ve,ze,it,Le,nt,lt,Ae,vt,Ne=W.s==ne.s?1:-1,$t=W.c,It=ne.c;if(!$t||!$t[0]||!It||!It[0])return new k(!W.s||!ne.s||($t?It&&$t[0]==It[0]:!It)?NaN:$t&&$t[0]==0||!It?Ne*0:Ne/0);for(Ee=new k(Ne),Se=Ee.c=[],ae=W.e-ne.e,Ne=te+ae+1,X||(X=Rh,ae=Kc(W.e/Nn)-Kc(ne.e/Nn),Ne=Ne/Nn|0),ce=0;It[ce]==($t[ce]||0);ce++);if(It[ce]>($t[ce]||0)&&ae--,Ne<0)Se.push(1),de=!0;else{for(nt=$t.length,Ae=It.length,ce=0,Ne+=2,pe=Jc(X/(It[0]+1)),pe>1&&(It=V(It,pe,X),$t=V($t,pe,X),Ae=It.length,nt=$t.length),Le=Ae,Ve=$t.slice(0,Ae),ze=Ve.length;ze<Ae;Ve[ze++]=0);vt=It.slice(),vt=[0].concat(vt),lt=It[0],It[1]>=X/2&<++;do{if(pe=0,ee=U(It,Ve,Ae,ze),ee<0){if(it=Ve[0],Ae!=ze&&(it=it*X+(Ve[1]||0)),pe=Jc(it/lt),pe>1)for(pe>=X&&(pe=X-1),Ie=V(It,pe,X),we=Ie.length,ze=Ve.length;U(Ie,Ve,we,ze)==1;)pe--,H(Ie,Ae<we?vt:It,we,X),we=Ie.length,ee=1;else pe==0&&(ee=pe=1),Ie=It.slice(),we=Ie.length;if(we<ze&&(Ie=[0].concat(Ie)),H(Ve,Ie,ze,X),ze=Ve.length,ee==-1)for(;U(It,Ve,Ae,ze)<1;)pe++,H(Ve,Ae<ze?vt:It,ze,X),ze=Ve.length}else ee===0&&(pe++,Ve=[0]);Se[ce++]=pe,Ve[0]?Ve[ze++]=$t[Le]||0:(Ve=[$t[Le]],ze=1)}while((Le++<nt||Ve[0]!=null)&&Ne--);de=Ve[0]!=null,Se[0]||Se.splice(0,1)}if(X==Rh){for(ce=1,Ne=Se[0];Ne>=10;Ne/=10,ce++);Y(Ee,te+(Ee.e=ce+ae*Nn-1)+1,oe,de)}else Ee.e=ae,Ee.r=+de;return Ee}})();function D(V,U,H,W){var ne,te,oe,X,ee;if(H==null?H=l:xs(H,0,8),!V.c)return V.toString();if(ne=V.c[0],oe=V.e,U==null)ee=qc(V.c),ee=W==1||W==2&&(oe<=h||oe>=d)?SE(ee,oe):kd(ee,oe,"0");else if(V=Y(new k(V),U,H),te=V.e,ee=qc(V.c),X=ee.length,W==1||W==2&&(U<=te||te<=h)){for(;X<U;ee+="0",X++);ee=SE(ee,te)}else if(U-=oe+(W===2&&te>oe),ee=kd(ee,te,"0"),te+1>X){if(--U>0)for(ee+=".";U--;ee+="0");}else if(U+=te-X,U>0)for(te+1==X&&(ee+=".");U--;ee+="0");return V.s<0&&ne?"-"+ee:ee}function F(V,U){for(var H,W,ne=1,te=new k(V[0]);ne<V.length;ne++)W=new k(V[ne]),(!W.s||(H=em(te,W))===U||H===0&&te.s===U)&&(te=W);return te}function Z(V,U,H){for(var W=1,ne=U.length;!U[--ne];U.pop());for(ne=U[0];ne>=10;ne/=10,W++);return(H=W+H*Nn-1)>g?V.c=V.e=null:H<p?V.c=[V.e=0]:(V.e=H,V.c=U),V}n=(function(){var V=/^(-?)0([xbo])(?=\w[\w.]*$)/i,U=/^([^.]+)\.$/,H=/^\.([^.]+)$/,W=/^-?(Infinity|NaN)$/,ne=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(te,oe,X,ee){var ae,ce=X?oe:oe.replace(ne,"");if(W.test(ce))te.s=isNaN(ce)?null:ce<0?-1:1;else{if(!X&&(ce=ce.replace(V,function(de,pe,Ie){return ae=(Ie=Ie.toLowerCase())=="x"?16:Ie=="b"?2:8,!ee||ee==ae?pe:de}),ee&&(ae=ee,ce=ce.replace(U,"$1").replace(H,"0.$1")),oe!=ce))return new k(ce,ae);if(k.DEBUG)throw Error(Ol+"Not a"+(ee?" base "+ee:"")+" number: "+oe);te.s=null}te.c=te.e=null}})();function Y(V,U,H,W){var ne,te,oe,X,ee,ae,ce,de=V.c,pe=o8;if(de){e:{for(ne=1,X=de[0];X>=10;X/=10,ne++);if(te=U-ne,te<0)te+=Nn,oe=U,ee=de[ae=0],ce=Jc(ee/pe[ne-oe-1]%10);else if(ae=s8((te+1)/Nn),ae>=de.length)if(W){for(;de.length<=ae;de.push(0));ee=ce=0,ne=1,te%=Nn,oe=te-Nn+1}else break e;else{for(ee=X=de[ae],ne=1;X>=10;X/=10,ne++);te%=Nn,oe=te-Nn+ne,ce=oe<0?0:Jc(ee/pe[ne-oe-1]%10)}if(W=W||U<0||de[ae+1]!=null||(oe<0?ee:ee%pe[ne-oe-1]),W=H<4?(ce||W)&&(H==0||H==(V.s<0?3:2)):ce>5||ce==5&&(H==4||W||H==6&&(te>0?oe>0?ee/pe[ne-oe]:0:de[ae-1])%10&1||H==(V.s<0?8:7)),U<1||!de[0])return de.length=0,W?(U-=V.e+1,de[0]=pe[(Nn-U%Nn)%Nn],V.e=-U||0):de[0]=V.e=0,V;if(te==0?(de.length=ae,X=1,ae--):(de.length=ae+1,X=pe[Nn-te],de[ae]=oe>0?Jc(ee/pe[ne-oe]%pe[oe])*X:0),W)for(;;)if(ae==0){for(te=1,oe=de[0];oe>=10;oe/=10,te++);for(oe=de[0]+=X,X=1;oe>=10;oe/=10,X++);te!=X&&(V.e++,de[0]==Rh&&(de[0]=1));break}else{if(de[ae]+=X,de[ae]!=Rh)break;de[ae--]=0,X=1}for(te=de.length;de[--te]===0;de.pop());}V.e>g?V.c=V.e=null:V.e<p&&(V.c=[V.e=0])}return V}function Q(V){var U,H=V.e;return H===null?V.toString():(U=qc(V.c),U=H<=h||H>=d?SE(U,H):kd(U,H,"0"),V.s<0?"-"+U:U)}return r.absoluteValue=r.abs=function(){var V=new k(this);return V.s<0&&(V.s=1),V},r.comparedTo=function(V,U){return em(this,new k(V,U))},r.decimalPlaces=r.dp=function(V,U){var H,W,ne,te=this;if(V!=null)return xs(V,0,Fa),U==null?U=l:xs(U,0,8),Y(new k(te),V+te.e+1,U);if(!(H=te.c))return null;if(W=((ne=H.length-1)-Kc(this.e/Nn))*Nn,ne=H[ne])for(;ne%10==0;ne/=10,W--);return W<0&&(W=0),W},r.dividedBy=r.div=function(V,U){return t(this,new k(V,U),a,l)},r.dividedToIntegerBy=r.idiv=function(V,U){return t(this,new k(V,U),0,1)},r.exponentiatedBy=r.pow=function(V,U){var H,W,ne,te,oe,X,ee,ae,ce,de=this;if(V=new k(V),V.c&&!V.isInteger())throw Error(Ol+"Exponent not an integer: "+Q(V));if(U!=null&&(U=new k(U)),X=V.e>14,!de.c||!de.c[0]||de.c[0]==1&&!de.e&&de.c.length==1||!V.c||!V.c[0])return ce=new k(Math.pow(+Q(de),X?V.s*(2-EE(V)):+Q(V))),U?ce.mod(U):ce;if(ee=V.s<0,U){if(U.c?!U.c[0]:!U.s)return new k(NaN);W=!ee&&de.isInteger()&&U.isInteger(),W&&(de=de.mod(U))}else{if(V.e>9&&(de.e>0||de.e<-1||(de.e==0?de.c[0]>1||X&&de.c[1]>=24e7:de.c[0]<8e13||X&&de.c[0]<=9999975e7)))return te=de.s<0&&EE(V)?-0:0,de.e>-1&&(te=1/te),new k(ee?1/te:te);E&&(te=s8(E/Nn+2))}for(X?(H=new k(.5),ee&&(V.s=1),ae=EE(V)):(ne=Math.abs(+Q(V)),ae=ne%2),ce=new k(s);;){if(ae){if(ce=ce.times(de),!ce.c)break;te?ce.c.length>te&&(ce.c.length=te):W&&(ce=ce.mod(U))}if(ne){if(ne=Jc(ne/2),ne===0)break;ae=ne%2}else if(V=V.times(H),Y(V,V.e+1,1),V.e>14)ae=EE(V);else{if(ne=+Q(V),ne===0)break;ae=ne%2}de=de.times(de),te?de.c&&de.c.length>te&&(de.c.length=te):W&&(de=de.mod(U))}return W?ce:(ee&&(ce=s.div(ce)),U?ce.mod(U):te?Y(ce,E,l,oe):ce)},r.integerValue=function(V){var U=new k(this);return V==null?V=l:xs(V,0,8),Y(U,U.e+1,V)},r.isEqualTo=r.eq=function(V,U){return em(this,new k(V,U))===0},r.isFinite=function(){return!!this.c},r.isGreaterThan=r.gt=function(V,U){return em(this,new k(V,U))>0},r.isGreaterThanOrEqualTo=r.gte=function(V,U){return(U=em(this,new k(V,U)))===1||U===0},r.isInteger=function(){return!!this.c&&Kc(this.e/Nn)>this.c.length-2},r.isLessThan=r.lt=function(V,U){return em(this,new k(V,U))<0},r.isLessThanOrEqualTo=r.lte=function(V,U){return(U=em(this,new k(V,U)))===-1||U===0},r.isNaN=function(){return!this.s},r.isNegative=function(){return this.s<0},r.isPositive=function(){return this.s>0},r.isZero=function(){return!!this.c&&this.c[0]==0},r.minus=function(V,U){var H,W,ne,te,oe=this,X=oe.s;if(V=new k(V,U),U=V.s,!X||!U)return new k(NaN);if(X!=U)return V.s=-U,oe.plus(V);var ee=oe.e/Nn,ae=V.e/Nn,ce=oe.c,de=V.c;if(!ee||!ae){if(!ce||!de)return ce?(V.s=-U,V):new k(de?oe:NaN);if(!ce[0]||!de[0])return de[0]?(V.s=-U,V):new k(ce[0]?oe:l==3?-0:0)}if(ee=Kc(ee),ae=Kc(ae),ce=ce.slice(),X=ee-ae){for((te=X<0)?(X=-X,ne=ce):(ae=ee,ne=de),ne.reverse(),U=X;U--;ne.push(0));ne.reverse()}else for(W=(te=(X=ce.length)<(U=de.length))?X:U,X=U=0;U<W;U++)if(ce[U]!=de[U]){te=ce[U]<de[U];break}if(te&&(ne=ce,ce=de,de=ne,V.s=-V.s),U=(W=de.length)-(H=ce.length),U>0)for(;U--;ce[H++]=0);for(U=Rh-1;W>X;){if(ce[--W]<de[W]){for(H=W;H&&!ce[--H];ce[H]=U);--ce[H],ce[W]+=Rh}ce[W]-=de[W]}for(;ce[0]==0;ce.splice(0,1),--ae);return ce[0]?Z(V,ce,ae):(V.s=l==3?-1:1,V.c=[V.e=0],V)},r.modulo=r.mod=function(V,U){var H,W,ne=this;return V=new k(V,U),!ne.c||!V.s||V.c&&!V.c[0]?new k(NaN):!V.c||ne.c&&!ne.c[0]?new k(ne):(y==9?(W=V.s,V.s=1,H=t(ne,V,0,3),V.s=W,H.s*=W):H=t(ne,V,0,y),V=ne.minus(H.times(V)),!V.c[0]&&y==1&&(V.s=ne.s),V)},r.multipliedBy=r.times=function(V,U){var H,W,ne,te,oe,X,ee,ae,ce,de,pe,Ie,we,Ee,Se,Ve=this,ze=Ve.c,it=(V=new k(V,U)).c;if(!ze||!it||!ze[0]||!it[0])return!Ve.s||!V.s||ze&&!ze[0]&&!it||it&&!it[0]&&!ze?V.c=V.e=V.s=null:(V.s*=Ve.s,!ze||!it?V.c=V.e=null:(V.c=[0],V.e=0)),V;for(W=Kc(Ve.e/Nn)+Kc(V.e/Nn),V.s*=Ve.s,ee=ze.length,de=it.length,ee<de&&(we=ze,ze=it,it=we,ne=ee,ee=de,de=ne),ne=ee+de,we=[];ne--;we.push(0));for(Ee=Rh,Se=np,ne=de;--ne>=0;){for(H=0,pe=it[ne]%Se,Ie=it[ne]/Se|0,oe=ee,te=ne+oe;te>ne;)ae=ze[--oe]%Se,ce=ze[oe]/Se|0,X=Ie*ae+ce*pe,ae=pe*ae+X%Se*Se+we[te]+H,H=(ae/Ee|0)+(X/Se|0)+Ie*ce,we[te--]=ae%Ee;we[te]=H}return H?++W:we.splice(0,1),Z(V,we,W)},r.negated=function(){var V=new k(this);return V.s=-V.s||null,V},r.plus=function(V,U){var H,W=this,ne=W.s;if(V=new k(V,U),U=V.s,!ne||!U)return new k(NaN);if(ne!=U)return V.s=-U,W.minus(V);var te=W.e/Nn,oe=V.e/Nn,X=W.c,ee=V.c;if(!te||!oe){if(!X||!ee)return new k(ne/0);if(!X[0]||!ee[0])return ee[0]?V:new k(X[0]?W:ne*0)}if(te=Kc(te),oe=Kc(oe),X=X.slice(),ne=te-oe){for(ne>0?(oe=te,H=ee):(ne=-ne,H=X),H.reverse();ne--;H.push(0));H.reverse()}for(ne=X.length,U=ee.length,ne-U<0&&(H=ee,ee=X,X=H,U=ne),ne=0;U;)ne=(X[--U]=X[U]+ee[U]+ne)/Rh|0,X[U]=Rh===X[U]?0:X[U]%Rh;return ne&&(X=[ne].concat(X),++oe),Z(V,X,oe)},r.precision=r.sd=function(V,U){var H,W,ne,te=this;if(V!=null&&V!==!!V)return xs(V,1,Fa),U==null?U=l:xs(U,0,8),Y(new k(te),V,U);if(!(H=te.c))return null;if(ne=H.length-1,W=ne*Nn+1,ne=H[ne]){for(;ne%10==0;ne/=10,W--);for(ne=H[0];ne>=10;ne/=10,W++);}return V&&te.e+1>W&&(W=te.e+1),W},r.shiftedBy=function(V){return xs(V,-a8,a8),this.times("1e"+V)},r.squareRoot=r.sqrt=function(){var V,U,H,W,ne,te=this,oe=te.c,X=te.s,ee=te.e,ae=a+4,ce=new k("0.5");if(X!==1||!oe||!oe[0])return new k(!X||X<0&&(!oe||oe[0])?NaN:oe?te:1/0);if(X=Math.sqrt(+Q(te)),X==0||X==1/0?(U=qc(oe),(U.length+ee)%2==0&&(U+="0"),X=Math.sqrt(+U),ee=Kc((ee+1)/2)-(ee<0||ee%2),X==1/0?U="5e"+ee:(U=X.toExponential(),U=U.slice(0,U.indexOf("e")+1)+ee),H=new k(U)):H=new k(X+""),H.c[0]){for(ee=H.e,X=ee+ae,X<3&&(X=0);;)if(ne=H,H=ce.times(ne.plus(t(te,ne,ae,1))),qc(ne.c).slice(0,X)===(U=qc(H.c)).slice(0,X))if(H.e<ee&&--X,U=U.slice(X-3,X+1),U=="9999"||!W&&U=="4999"){if(!W&&(Y(ne,ne.e+a+2,0),ne.times(ne).eq(te))){H=ne;break}ae+=4,X+=4,W=1}else{(!+U||!+U.slice(1)&&U.charAt(0)=="5")&&(Y(H,H.e+a+2,1),V=!H.times(H).eq(te));break}}return Y(H,H.e+a+1,l,V)},r.toExponential=function(V,U){return V!=null&&(xs(V,0,Fa),V++),D(this,V,U,1)},r.toFixed=function(V,U){return V!=null&&(xs(V,0,Fa),V=V+this.e+1),D(this,V,U)},r.toFormat=function(V,U,H){var W,ne=this;if(H==null)V!=null&&U&&typeof U=="object"?(H=U,U=null):V&&typeof V=="object"?(H=V,V=U=null):H=S;else if(typeof H!="object")throw Error(Ol+"Argument not an object: "+H);if(W=ne.toFixed(V,U),ne.c){var te,oe=W.split("."),X=+H.groupSize,ee=+H.secondaryGroupSize,ae=H.groupSeparator||"",ce=oe[0],de=oe[1],pe=ne.s<0,Ie=pe?ce.slice(1):ce,we=Ie.length;if(ee&&(te=X,X=ee,ee=te,we-=te),X>0&&we>0){for(te=we%X||X,ce=Ie.substr(0,te);te<we;te+=X)ce+=ae+Ie.substr(te,X);ee>0&&(ce+=ae+Ie.slice(te)),pe&&(ce="-"+ce)}W=de?ce+(H.decimalSeparator||"")+((ee=+H.fractionGroupSize)?de.replace(new RegExp("\\d{"+ee+"}\\B","g"),"$&"+(H.fractionGroupSeparator||"")):de):ce}return(H.prefix||"")+W+(H.suffix||"")},r.toFraction=function(V){var U,H,W,ne,te,oe,X,ee,ae,ce,de,pe,Ie=this,we=Ie.c;if(V!=null&&(X=new k(V),!X.isInteger()&&(X.c||X.s!==1)||X.lt(s)))throw Error(Ol+"Argument "+(X.isInteger()?"out of range: ":"not an integer: ")+Q(X));if(!we)return new k(Ie);for(U=new k(s),ae=H=new k(s),W=ee=new k(s),pe=qc(we),te=U.e=pe.length-Ie.e-1,U.c[0]=o8[(oe=te%Nn)<0?Nn+oe:oe],V=!V||X.comparedTo(U)>0?te>0?U:ae:X,oe=g,g=1/0,X=new k(pe),ee.c[0]=0;ce=t(X,U,0,1),ne=H.plus(ce.times(W)),ne.comparedTo(V)!=1;)H=W,W=ne,ae=ee.plus(ce.times(ne=ae)),ee=ne,U=X.minus(ce.times(ne=U)),X=ne;return ne=t(V.minus(H),W,0,1),ee=ee.plus(ne.times(ae)),H=H.plus(ne.times(W)),ee.s=ae.s=Ie.s,te=te*2,de=t(ae,W,te,l).minus(Ie).abs().comparedTo(t(ee,H,te,l).minus(Ie).abs())<1?[ae,W]:[ee,H],g=oe,de},r.toNumber=function(){return+Q(this)},r.toPrecision=function(V,U){return V!=null&&xs(V,1,Fa),D(this,V,U,2)},r.toString=function(V){var U,H=this,W=H.s,ne=H.e;return ne===null?W?(U="Infinity",W<0&&(U="-"+U)):U="NaN":(V==null?U=ne<=h||ne>=d?SE(qc(H.c),ne):kd(qc(H.c),ne,"0"):V===10&&I?(H=Y(new k(H),a+ne+1,l),U=kd(qc(H.c),H.e,"0")):(xs(V,2,R.length,"Base"),U=i(kd(qc(H.c),ne,"0"),10,V,W,!0)),W<0&&H.c[0]&&(U="-"+U)),U},r.valueOf=r.toJSON=function(){return Q(this)},r._isBigNumber=!0,r[Symbol.toStringTag]="BigNumber",r[Symbol.for("nodejs.util.inspect.custom")]=r.valueOf,e!=null&&k.set(e),k}function Kc(e){var t=e|0;return e>0||e===t?t:t-1}function qc(e){for(var t,i,n=1,r=e.length,s=e[0]+"";n<r;){for(t=e[n++]+"",i=Nn-t.length;i--;t="0"+t);s+=t}for(r=s.length;s.charCodeAt(--r)===48;);return s.slice(0,r+1||1)}function em(e,t){var i,n,r=e.c,s=t.c,a=e.s,l=t.s,h=e.e,d=t.e;if(!a||!l)return null;if(i=r&&!r[0],n=s&&!s[0],i||n)return i?n?0:-l:a;if(a!=l)return a;if(i=a<0,n=h==d,!r||!s)return n?0:!r^i?1:-1;if(!n)return h>d^i?1:-1;for(l=(h=r.length)<(d=s.length)?h:d,a=0;a<l;a++)if(r[a]!=s[a])return r[a]>s[a]^i?1:-1;return h==d?0:h>d^i?1:-1}function xs(e,t,i,n){if(e<t||e>i||e!==Jc(e))throw Error(Ol+(n||"Argument")+(typeof e=="number"?e<t||e>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function EE(e){var t=e.c.length-1;return Kc(e.e/Nn)==t&&e.c[t]%2!=0}function SE(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function kd(e,t,i){var n,r;if(t<0){for(r=i+".";++t;r+=i);e=r+e}else if(n=e.length,++t>n){for(r=i,t-=n;--t;r+=i);e+=r}else t<n&&(e=e.slice(0,t)+"."+e.slice(t));return e}var Du=uJ(),aue=class{key;left=null;right=null;constructor(e){this.key=e}},Zy=class extends aue{constructor(e){super(e)}},oue=class{size=0;modificationCount=0;splayCount=0;splay(e){const t=this.root;if(t==null)return this.compare(e,e),-1;let i=null,n=null,r=null,s=null,a=t;const l=this.compare;let h;for(;;)if(h=l(a.key,e),h>0){let d=a.left;if(d==null||(h=l(d.key,e),h>0&&(a.left=d.right,d.right=a,a=d,d=a.left,d==null)))break;i==null?n=a:i.left=a,i=a,a=d}else if(h<0){let d=a.right;if(d==null||(h=l(d.key,e),h<0&&(a.right=d.left,d.left=a,a=d,d=a.right,d==null)))break;r==null?s=a:r.right=a,r=a,a=d}else break;return r!=null&&(r.right=a.left,a.left=s),i!=null&&(i.left=a.right,a.right=n),this.root!==a&&(this.root=a,this.splayCount++),h}splayMin(e){let t=e,i=t.left;for(;i!=null;){const n=i;t.left=n.right,n.right=t,t=n,i=t.left}return t}splayMax(e){let t=e,i=t.right;for(;i!=null;){const n=i;t.right=n.left,n.left=t,t=n,i=t.right}return t}_delete(e){if(this.root==null||this.splay(e)!=0)return null;let t=this.root;const i=t,n=t.left;if(this.size--,n==null)this.root=t.right;else{const r=t.right;t=this.splayMax(n),t.right=r,this.root=t}return this.modificationCount++,i}addNewRoot(e,t){this.size++,this.modificationCount++;const i=this.root;if(i==null){this.root=e;return}t<0?(e.left=i,e.right=i.right,i.right=null):(e.right=i,e.left=i.left,i.left=null),this.root=e}_first(){const e=this.root;return e==null?null:(this.root=this.splayMin(e),this.root)}_last(){const e=this.root;return e==null?null:(this.root=this.splayMax(e),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(e){return this.validKey(e)&&this.splay(e)==0}defaultCompare(){return(e,t)=>e<t?-1:e>t?1:0}wrap(){return{getRoot:()=>this.root,setRoot:e=>{this.root=e},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:e=>{this.splayCount=e},splay:e=>this.splay(e),has:e=>this.has(e)}}},yI=class W1 extends oue{root=null;compare;validKey;constructor(t,i){super(),this.compare=t??this.defaultCompare(),this.validKey=i??(n=>n!=null&&n!=null)}delete(t){return this.validKey(t)?this._delete(t)!=null:!1}deleteAll(t){for(const i of t)this.delete(i)}forEach(t){const i=this[Symbol.iterator]();let n;for(;n=i.next(),!n.done;)t(n.value,n.value,this)}add(t){const i=this.splay(t);return i!=0&&this.addNewRoot(new Zy(t),i),this}addAndReturn(t){const i=this.splay(t);return i!=0&&this.addNewRoot(new Zy(t),i),this.root.key}addAll(t){for(const i of t)this.add(i)}isEmpty(){return this.root==null}isNotEmpty(){return this.root!=null}single(){if(this.size==0)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(this.size==0)throw"Bad state: No element";return this._first().key}last(){if(this.size==0)throw"Bad state: No element";return this._last().key}lastBefore(t){if(t==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(t)<0)return this.root.key;let i=this.root.left;if(i==null)return null;let n=i.right;for(;n!=null;)i=n,n=i.right;return i.key}firstAfter(t){if(t==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(t)>0)return this.root.key;let i=this.root.right;if(i==null)return null;let n=i.left;for(;n!=null;)i=n,n=i.left;return i.key}retainAll(t){const i=new W1(this.compare,this.validKey),n=this.modificationCount;for(const r of t){if(n!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(r)&&this.splay(r)==0&&i.add(this.root.key)}i.size!=this.size&&(this.root=i.root,this.size=i.size,this.modificationCount++)}lookup(t){return!this.validKey(t)||this.splay(t)!=0?null:this.root.key}intersection(t){const i=new W1(this.compare,this.validKey);for(const n of this)t.has(n)&&i.add(n);return i}difference(t){const i=new W1(this.compare,this.validKey);for(const n of this)t.has(n)||i.add(n);return i}union(t){const i=this.clone();return i.addAll(t),i}clone(){const t=new W1(this.compare,this.validKey);return t.size=this.size,t.root=this.copyNode(this.root),t}copyNode(t){if(t==null)return null;function i(r,s){let a,l;do{if(a=r.left,l=r.right,a!=null){const h=new Zy(a.key);s.left=h,i(a,h)}if(l!=null){const h=new Zy(l.key);s.right=h,r=l,s=h}}while(l!=null)}const n=new Zy(t.key);return i(t,n),n}toSet(){return this.clone()}entries(){return new cue(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new lue(this.wrap())}[Symbol.toStringTag]="[object Set]"},dJ=class{tree;path=new Array;modificationCount=null;splayCount;constructor(e){this.tree=e,this.splayCount=e.getSplayCount()}[Symbol.iterator](){return this}next(){return this.moveNext()?{done:!1,value:this.current()}:{done:!0,value:null}}current(){if(!this.path.length)return null;const e=this.path[this.path.length-1];return this.getValue(e)}rebuildPath(e){this.path.splice(0,this.path.length),this.tree.splay(e),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(e){for(;e!=null;)this.path.push(e),e=e.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(this.modificationCount==null){this.modificationCount=this.tree.getModificationCount();let i=this.tree.getRoot();for(;i!=null;)this.path.push(i),i=i.left;return this.path.length>0}throw"Concurrent modification during iteration."}if(!this.path.length)return!1;this.splayCount!=this.tree.getSplayCount()&&this.rebuildPath(this.path[this.path.length-1].key);let e=this.path[this.path.length-1],t=e.right;if(t!=null){for(;t!=null;)this.path.push(t),t=t.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===e;)e=this.path.pop();return this.path.length>0}},lue=class extends dJ{getValue(e){return e.key}},cue=class extends dJ{getValue(e){return[e.key,e.key]}},fJ=e=>()=>e,m6=e=>{const t=e?(i,n)=>n.minus(i).abs().isLessThanOrEqualTo(e):fJ(!1);return(i,n)=>t(i,n)?0:i.comparedTo(n)};function hue(e){const t=e?(i,n,r,s,a)=>i.exponentiatedBy(2).isLessThanOrEqualTo(s.minus(n).exponentiatedBy(2).plus(a.minus(r).exponentiatedBy(2)).times(e)):fJ(!1);return(i,n,r)=>{const s=i.x,a=i.y,l=r.x,h=r.y,d=a.minus(h).times(n.x.minus(l)).minus(s.minus(l).times(n.y.minus(h)));return t(d,s,a,l,h)?0:d.comparedTo(0)}}var uue=e=>e,due=e=>{if(e){const t=new yI(m6(e)),i=new yI(m6(e)),n=(s,a)=>a.addAndReturn(s),r=s=>({x:n(s.x,t),y:n(s.y,i)});return r({x:new Du(0),y:new Du(0)}),r}return uue},g6=e=>({set:t=>{yf=g6(t)},reset:()=>g6(e),compare:m6(e),snap:due(e),orient:hue(e)}),yf=g6(),qy=(e,t)=>e.ll.x.isLessThanOrEqualTo(t.x)&&t.x.isLessThanOrEqualTo(e.ur.x)&&e.ll.y.isLessThanOrEqualTo(t.y)&&t.y.isLessThanOrEqualTo(e.ur.y),_6=(e,t)=>{if(t.ur.x.isLessThan(e.ll.x)||e.ur.x.isLessThan(t.ll.x)||t.ur.y.isLessThan(e.ll.y)||e.ur.y.isLessThan(t.ll.y))return null;const i=e.ll.x.isLessThan(t.ll.x)?t.ll.x:e.ll.x,n=e.ur.x.isLessThan(t.ur.x)?e.ur.x:t.ur.x,r=e.ll.y.isLessThan(t.ll.y)?t.ll.y:e.ll.y,s=e.ur.y.isLessThan(t.ur.y)?e.ur.y:t.ur.y;return{ll:{x:i,y:r},ur:{x:n,y:s}}},TM=(e,t)=>e.x.times(t.y).minus(e.y.times(t.x)),pJ=(e,t)=>e.x.times(t.x).plus(e.y.times(t.y)),bI=e=>pJ(e,e).sqrt(),fue=(e,t,i)=>{const n={x:t.x.minus(e.x),y:t.y.minus(e.y)},r={x:i.x.minus(e.x),y:i.y.minus(e.y)};return TM(r,n).div(bI(r)).div(bI(n))},pue=(e,t,i)=>{const n={x:t.x.minus(e.x),y:t.y.minus(e.y)},r={x:i.x.minus(e.x),y:i.y.minus(e.y)};return pJ(r,n).div(bI(r)).div(bI(n))},_$=(e,t,i)=>t.y.isZero()?null:{x:e.x.plus(t.x.div(t.y).times(i.minus(e.y))),y:i},A$=(e,t,i)=>t.x.isZero()?null:{x:i,y:e.y.plus(t.y.div(t.x).times(i.minus(e.x)))},mue=(e,t,i,n)=>{if(t.x.isZero())return A$(i,n,e.x);if(n.x.isZero())return A$(e,t,i.x);if(t.y.isZero())return _$(i,n,e.y);if(n.y.isZero())return _$(e,t,i.y);const r=TM(t,n);if(r.isZero())return null;const s={x:i.x.minus(e.x),y:i.y.minus(e.y)},a=TM(s,t).div(r),l=TM(s,n).div(r),h=e.x.plus(l.times(t.x)),d=i.x.plus(a.times(n.x)),p=e.y.plus(l.times(t.y)),g=i.y.plus(a.times(n.y));return{x:h.plus(d).div(2),y:p.plus(g).div(2)}},Tu=class mJ{point;isLeft;segment;otherSE;consumedBy;static compare(t,i){const n=mJ.comparePoints(t.point,i.point);return n!==0?n:(t.point!==i.point&&t.link(i),t.isLeft!==i.isLeft?t.isLeft?1:-1:xI.compare(t.segment,i.segment))}static comparePoints(t,i){return t.x.isLessThan(i.x)?-1:t.x.isGreaterThan(i.x)?1:t.y.isLessThan(i.y)?-1:t.y.isGreaterThan(i.y)?1:0}constructor(t,i){t.events===void 0?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=i}link(t){if(t.point===this.point)throw new Error("Tried to link already linked events");const i=t.point.events;for(let n=0,r=i.length;n<r;n++){const s=i[n];this.point.events.push(s),s.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let i=0;i<t;i++){const n=this.point.events[i];if(n.segment.consumedBy===void 0)for(let r=i+1;r<t;r++){const s=this.point.events[r];s.consumedBy===void 0&&n.otherSE.point.events===s.otherSE.point.events&&n.segment.consume(s.segment)}}}getAvailableLinkedEvents(){const t=[];for(let i=0,n=this.point.events.length;i<n;i++){const r=this.point.events[i];r!==this&&!r.segment.ringOut&&r.segment.isInResult()&&t.push(r)}return t}getLeftmostComparator(t){const i=new Map,n=r=>{const s=r.otherSE;i.set(r,{sine:fue(this.point,t.point,s.point),cosine:pue(this.point,t.point,s.point)})};return(r,s)=>{i.has(r)||n(r),i.has(s)||n(s);const{sine:a,cosine:l}=i.get(r),{sine:h,cosine:d}=i.get(s);return a.isGreaterThanOrEqualTo(0)&&h.isGreaterThanOrEqualTo(0)?l.isLessThan(d)?1:l.isGreaterThan(d)?-1:0:a.isLessThan(0)&&h.isLessThan(0)?l.isLessThan(d)?-1:l.isGreaterThan(d)?1:0:h.isLessThan(a)?-1:h.isGreaterThan(a)?1:0}}},gue=class A6{events;poly;_isExteriorRing;_enclosingRing;static factory(t){const i=[];for(let n=0,r=t.length;n<r;n++){const s=t[n];if(!s.isInResult()||s.ringOut)continue;let a=null,l=s.leftSE,h=s.rightSE;const d=[l],p=l.point,g=[];for(;a=l,l=h,d.push(l),l.point!==p;)for(;;){const v=l.getAvailableLinkedEvents();if(v.length===0){const S=d[0].point,R=d[d.length-1].point;throw new Error(`Unable to complete output ring starting at [${S.x}, ${S.y}]. Last matching segment found ends at [${R.x}, ${R.y}].`)}if(v.length===1){h=v[0].otherSE;break}let y=null;for(let S=0,R=g.length;S<R;S++)if(g[S].point===l.point){y=S;break}if(y!==null){const S=g.splice(y)[0],R=d.splice(S.index);R.unshift(R[0].otherSE),i.push(new A6(R.reverse()));continue}g.push({index:d.length,point:l.point});const E=l.getLeftmostComparator(a);h=v.sort(E)[0].otherSE;break}i.push(new A6(d))}return i}constructor(t){this.events=t;for(let i=0,n=t.length;i<n;i++)t[i].segment.ringOut=this;this.poly=null}getGeom(){let t=this.events[0].point;const i=[t];for(let d=1,p=this.events.length-1;d<p;d++){const g=this.events[d].point,v=this.events[d+1].point;yf.orient(g,t,v)!==0&&(i.push(g),t=g)}if(i.length===1)return null;const n=i[0],r=i[1];yf.orient(n,t,r)===0&&i.shift(),i.push(i[0]);const s=this.isExteriorRing()?1:-1,a=this.isExteriorRing()?0:i.length-1,l=this.isExteriorRing()?i.length:-1,h=[];for(let d=a;d!=l;d+=s)h.push([i[d].x.toNumber(),i[d].y.toNumber()]);return h}isExteriorRing(){if(this._isExteriorRing===void 0){const t=this.enclosingRing();this._isExteriorRing=t?!t.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let t=this.events[0];for(let r=1,s=this.events.length;r<s;r++){const a=this.events[r];Tu.compare(t,a)>0&&(t=a)}let i=t.segment.prevInResult(),n=i?i.prevInResult():null;for(;;){if(!i)return null;if(!n)return i.ringOut;if(n.ringOut!==i.ringOut)return n.ringOut?.enclosingRing()!==i.ringOut?i.ringOut:i.ringOut?.enclosingRing();i=n.prevInResult(),n=i?i.prevInResult():null}}},v$=class{exteriorRing;interiorRings;constructor(e){this.exteriorRing=e,e.poly=this,this.interiorRings=[]}addInterior(e){this.interiorRings.push(e),e.poly=this}getGeom(){const e=this.exteriorRing.getGeom();if(e===null)return null;const t=[e];for(let i=0,n=this.interiorRings.length;i<n;i++){const r=this.interiorRings[i].getGeom();r!==null&&t.push(r)}return t}},_ue=class{rings;polys;constructor(e){this.rings=e,this.polys=this._composePolys(e)}getGeom(){const e=[];for(let t=0,i=this.polys.length;t<i;t++){const n=this.polys[t].getGeom();n!==null&&e.push(n)}return e}_composePolys(e){const t=[];for(let i=0,n=e.length;i<n;i++){const r=e[i];if(!r.poly)if(r.isExteriorRing())t.push(new v$(r));else{const s=r.enclosingRing();s?.poly||t.push(new v$(s)),s?.poly?.addInterior(r)}}return t}},Aue=class{queue;tree;segments;constructor(e,t=xI.compare){this.queue=e,this.tree=new yI(t),this.segments=[]}process(e){const t=e.segment,i=[];if(e.consumedBy)return e.isLeft?this.queue.delete(e.otherSE):this.tree.delete(t),i;e.isLeft&&this.tree.add(t);let n=t,r=t;do n=this.tree.lastBefore(n);while(n!=null&&n.consumedBy!=null);do r=this.tree.firstAfter(r);while(r!=null&&r.consumedBy!=null);if(e.isLeft){let s=null;if(n){const l=n.getIntersection(t);if(l!==null&&(t.isAnEndpoint(l)||(s=l),!n.isAnEndpoint(l))){const h=this._splitSafely(n,l);for(let d=0,p=h.length;d<p;d++)i.push(h[d])}}let a=null;if(r){const l=r.getIntersection(t);if(l!==null&&(t.isAnEndpoint(l)||(a=l),!r.isAnEndpoint(l))){const h=this._splitSafely(r,l);for(let d=0,p=h.length;d<p;d++)i.push(h[d])}}if(s!==null||a!==null){let l=null;s===null?l=a:a===null?l=s:l=Tu.comparePoints(s,a)<=0?s:a,this.queue.delete(t.rightSE),i.push(t.rightSE);const h=t.split(l);for(let d=0,p=h.length;d<p;d++)i.push(h[d])}i.length>0?(this.tree.delete(t),i.push(e)):(this.segments.push(t),t.prev=n)}else{if(n&&r){const s=n.getIntersection(r);if(s!==null){if(!n.isAnEndpoint(s)){const a=this._splitSafely(n,s);for(let l=0,h=a.length;l<h;l++)i.push(a[l])}if(!r.isAnEndpoint(s)){const a=this._splitSafely(r,s);for(let l=0,h=a.length;l<h;l++)i.push(a[l])}}}this.tree.delete(t)}return i}_splitSafely(e,t){this.tree.delete(e);const i=e.rightSE;this.queue.delete(i);const n=e.split(t);return n.push(i),e.consumedBy===void 0&&this.tree.add(e),n}},vue=class{type;numMultiPolys;run(e,t,i){X1.type=e;const n=[new b$(t,!0)];for(let l=0,h=i.length;l<h;l++)n.push(new b$(i[l],!1));if(X1.numMultiPolys=n.length,X1.type==="difference"){const l=n[0];let h=1;for(;h<n.length;)_6(n[h].bbox,l.bbox)!==null?h++:n.splice(h,1)}if(X1.type==="intersection")for(let l=0,h=n.length;l<h;l++){const d=n[l];for(let p=l+1,g=n.length;p<g;p++)if(_6(d.bbox,n[p].bbox)===null)return[]}const r=new yI(Tu.compare);for(let l=0,h=n.length;l<h;l++){const d=n[l].getSweepEvents();for(let p=0,g=d.length;p<g;p++)r.add(d[p])}const s=new Aue(r);let a=null;for(r.size!=0&&(a=r.first(),r.delete(a));a;){const l=s.process(a);for(let h=0,d=l.length;h<d;h++){const p=l[h];p.consumedBy===void 0&&r.add(p)}r.size!=0?(a=r.first(),r.delete(a)):a=null}return yf.reset(),new _ue(gue.factory(s.segments)).getGeom()}},X1=new vue,Jb=X1,yue=0,xI=class RM{id;leftSE;rightSE;rings;windings;ringOut;consumedBy;prev;_prevInResult;_beforeState;_afterState;_isInResult;static compare(t,i){const n=t.leftSE.point.x,r=i.leftSE.point.x,s=t.rightSE.point.x,a=i.rightSE.point.x;if(a.isLessThan(n))return 1;if(s.isLessThan(r))return-1;const l=t.leftSE.point.y,h=i.leftSE.point.y,d=t.rightSE.point.y,p=i.rightSE.point.y;if(n.isLessThan(r)){if(h.isLessThan(l)&&h.isLessThan(d))return 1;if(h.isGreaterThan(l)&&h.isGreaterThan(d))return-1;const g=t.comparePoint(i.leftSE.point);if(g<0)return 1;if(g>0)return-1;const v=i.comparePoint(t.rightSE.point);return v!==0?v:-1}if(n.isGreaterThan(r)){if(l.isLessThan(h)&&l.isLessThan(p))return-1;if(l.isGreaterThan(h)&&l.isGreaterThan(p))return 1;const g=i.comparePoint(t.leftSE.point);if(g!==0)return g;const v=t.comparePoint(i.rightSE.point);return v<0?1:v>0?-1:1}if(l.isLessThan(h))return-1;if(l.isGreaterThan(h))return 1;if(s.isLessThan(a)){const g=i.comparePoint(t.rightSE.point);if(g!==0)return g}if(s.isGreaterThan(a)){const g=t.comparePoint(i.rightSE.point);if(g<0)return 1;if(g>0)return-1}if(!s.eq(a)){const g=d.minus(l),v=s.minus(n),y=p.minus(h),E=a.minus(r);if(g.isGreaterThan(v)&&y.isLessThan(E))return 1;if(g.isLessThan(v)&&y.isGreaterThan(E))return-1}return s.isGreaterThan(a)?1:s.isLessThan(a)||d.isLessThan(p)?-1:d.isGreaterThan(p)?1:t.id<i.id?-1:t.id>i.id?1:0}constructor(t,i,n,r){this.id=++yue,this.leftSE=t,t.segment=this,t.otherSE=i,this.rightSE=i,i.segment=this,i.otherSE=t,this.rings=n,this.windings=r}static fromRing(t,i,n){let r,s,a;const l=Tu.comparePoints(t,i);if(l<0)r=t,s=i,a=1;else if(l>0)r=i,s=t,a=-1;else throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);return new RM(new Tu(r,!0),new Tu(s,!1),[n],[a])}replaceRightSE(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const t=this.leftSE.point.y,i=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t.isLessThan(i)?t:i},ur:{x:this.rightSE.point.x,y:t.isGreaterThan(i)?t:i}}}vector(){return{x:this.rightSE.point.x.minus(this.leftSE.point.x),y:this.rightSE.point.y.minus(this.leftSE.point.y)}}isAnEndpoint(t){return t.x.eq(this.leftSE.point.x)&&t.y.eq(this.leftSE.point.y)||t.x.eq(this.rightSE.point.x)&&t.y.eq(this.rightSE.point.y)}comparePoint(t){return yf.orient(this.leftSE.point,t,this.rightSE.point)}getIntersection(t){const i=this.bbox(),n=t.bbox(),r=_6(i,n);if(r===null)return null;const s=this.leftSE.point,a=this.rightSE.point,l=t.leftSE.point,h=t.rightSE.point,d=qy(i,l)&&this.comparePoint(l)===0,p=qy(n,s)&&t.comparePoint(s)===0,g=qy(i,h)&&this.comparePoint(h)===0,v=qy(n,a)&&t.comparePoint(a)===0;if(p&&d)return v&&!g?a:!v&&g?h:null;if(p)return g&&s.x.eq(h.x)&&s.y.eq(h.y)?null:s;if(d)return v&&a.x.eq(l.x)&&a.y.eq(l.y)?null:l;if(v&&g)return null;if(v)return a;if(g)return h;const y=mue(s,this.vector(),l,t.vector());return y===null||!qy(r,y)?null:yf.snap(y)}split(t){const i=[],n=t.events!==void 0,r=new Tu(t,!0),s=new Tu(t,!1),a=this.rightSE;this.replaceRightSE(s),i.push(s),i.push(r);const l=new RM(r,a,this.rings.slice(),this.windings.slice());return Tu.comparePoints(l.leftSE.point,l.rightSE.point)>0&&l.swapEvents(),Tu.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),s.checkForConsuming()),i}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let i=0,n=this.windings.length;i<n;i++)this.windings[i]*=-1}consume(t){let i=this,n=t;for(;i.consumedBy;)i=i.consumedBy;for(;n.consumedBy;)n=n.consumedBy;const r=RM.compare(i,n);if(r!==0){if(r>0){const s=i;i=n,n=s}if(i.prev===n){const s=i;i=n,n=s}for(let s=0,a=n.rings.length;s<a;s++){const l=n.rings[s],h=n.windings[s],d=i.rings.indexOf(l);d===-1?(i.rings.push(l),i.windings.push(h)):i.windings[d]+=h}n.rings=null,n.windings=null,n.consumedBy=i,n.leftSE.consumedBy=i.leftSE,n.rightSE.consumedBy=i.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;const t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};const i=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let l=0,h=this.rings.length;l<h;l++){const d=this.rings[l],p=this.windings[l],g=i.indexOf(d);g===-1?(i.push(d),n.push(p)):n[g]+=p}const s=[],a=[];for(let l=0,h=i.length;l<h;l++){if(n[l]===0)continue;const d=i[l],p=d.poly;if(a.indexOf(p)===-1)if(d.isExterior)s.push(p);else{a.indexOf(p)===-1&&a.push(p);const g=s.indexOf(d.poly);g!==-1&&s.splice(g,1)}}for(let l=0,h=s.length;l<h;l++){const d=s[l].multiPoly;r.indexOf(d)===-1&&r.push(d)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;const t=this.beforeState().multiPolys,i=this.afterState().multiPolys;switch(Jb.type){case"union":{const n=t.length===0,r=i.length===0;this._isInResult=n!==r;break}case"intersection":{let n,r;t.length<i.length?(n=t.length,r=i.length):(n=i.length,r=t.length),this._isInResult=r===Jb.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(t.length-i.length);this._isInResult=n%2===1;break}case"difference":{const n=r=>r.length===1&&r[0].isSubject;this._isInResult=n(t)!==n(i);break}}return this._isInResult}},y$=class{poly;isExterior;segments;bbox;constructor(e,t,i){if(!Array.isArray(e)||e.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=t,this.isExterior=i,this.segments=[],typeof e[0][0]!="number"||typeof e[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const n=yf.snap({x:new Du(e[0][0]),y:new Du(e[0][1])});this.bbox={ll:{x:n.x,y:n.y},ur:{x:n.x,y:n.y}};let r=n;for(let s=1,a=e.length;s<a;s++){if(typeof e[s][0]!="number"||typeof e[s][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const l=yf.snap({x:new Du(e[s][0]),y:new Du(e[s][1])});l.x.eq(r.x)&&l.y.eq(r.y)||(this.segments.push(xI.fromRing(r,l,this)),l.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=l.x),l.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=l.y),l.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=l.x),l.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=l.y),r=l)}(!n.x.eq(r.x)||!n.y.eq(r.y))&&this.segments.push(xI.fromRing(r,n,this))}getSweepEvents(){const e=[];for(let t=0,i=this.segments.length;t<i;t++){const n=this.segments[t];e.push(n.leftSE),e.push(n.rightSE)}return e}},bue=class{multiPoly;exteriorRing;interiorRings;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new y$(e[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let i=1,n=e.length;i<n;i++){const r=new y$(e[i],this,!1);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.interiorRings.push(r)}this.multiPoly=t}getSweepEvents(){const e=this.exteriorRing.getSweepEvents();for(let t=0,i=this.interiorRings.length;t<i;t++){const n=this.interiorRings[t].getSweepEvents();for(let r=0,s=n.length;r<s;r++)e.push(n[r])}return e}},b$=class{isSubject;polys;bbox;constructor(e,t){if(!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof e[0][0][0]=="number"&&(e=[e])}catch{}this.polys=[],this.bbox={ll:{x:new Du(Number.POSITIVE_INFINITY),y:new Du(Number.POSITIVE_INFINITY)},ur:{x:new Du(Number.NEGATIVE_INFINITY),y:new Du(Number.NEGATIVE_INFINITY)}};for(let i=0,n=e.length;i<n;i++){const r=new bue(e[i],this);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.polys.push(r)}this.isSubject=t}getSweepEvents(){const e=[];for(let t=0,i=this.polys.length;t<i;t++){const n=this.polys[t].getSweepEvents();for(let r=0,s=n.length;r<s;r++)e.push(n[r])}return e}},xue=(e,...t)=>Jb.run("union",e,t),wue=(e,...t)=>Jb.run("intersection",e,t),Cue=(e,...t)=>Jb.run("difference",e,t);yf.set;function gJ(e){const t=[];if(f0(e,r=>{t.push(r.coordinates)}),t.length<2)throw new Error("Must have at least two features");const i=e.features[0].properties||{},n=Cue(t[0],...t.slice(1));return n.length===0?null:n.length===1?ph(n[0],i):RT(n,i)}function Eue(e,t,i={}){const n=oa(e),r=oa(t);return r[0]+=r[0]-n[0]>180?-360:n[0]-r[0]>180?360:0,Rj(Sue(n,r),"meters",i.units)}function Sue(e,t,i){i=i===void 0?Ua:Number(i);const n=i,r=e[1]*Math.PI/180,s=t[1]*Math.PI/180,a=s-r;let l=Math.abs(t[0]-e[0])*Math.PI/180;l>Math.PI&&(l-=2*Math.PI);const h=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),d=Math.abs(h)>1e-11?a/h:Math.cos(r);return Math.sqrt(a*a+d*d*l*l)*n}function _J(e,t,i,n={}){const r=t<0;let s=Rj(Math.abs(t),n.units,"meters");r&&(s=-Math.abs(s));const a=oa(e),l=Mue(a,s,i);return l[0]+=l[0]-a[0]>180?-360:a[0]-l[0]>180?360:0,aa(l,n.properties)}function Mue(e,t,i,n){n=n===void 0?Ua:Number(n);const r=t/n,s=e[0]*Math.PI/180,a=pl(e[1]),l=pl(i),h=r*Math.cos(l);let d=a+h;Math.abs(d)>Math.PI/2&&(d=d>0?Math.PI-d:-Math.PI-d);const p=Math.log(Math.tan(d/2+Math.PI/4)/Math.tan(a/2+Math.PI/4)),g=Math.abs(p)>1e-11?h/p:Math.cos(a);return[((s+r*Math.sin(l)/g)*180/Math.PI+540)%360-180,d*180/Math.PI]}function Iue(e,t={}){const i=[];if(f0(e,r=>{i.push(r.coordinates)}),i.length<2)throw new Error("Must specify at least 2 geometries");const n=wue(i[0],...i.slice(1));return n.length===0?null:n.length===1?ph(n[0],t.properties):RT(n,t.properties)}function Tue(e,t,i){if(i=i||{},!$x(i))throw new Error("options is invalid");const n=i.origin||"centroid",r=i.mutate||!1;if(!e)throw new Error("geojson required");if(typeof t!="number"||t<=0)throw new Error("invalid factor");const s=Array.isArray(n)||typeof n=="object";return r!==!0&&(e=Go(e)),e.type==="FeatureCollection"&&!s?(Af(e,function(a,l){e.features[l]=x$(a,t,n)}),e):x$(e,t,n)}function x$(e,t,i){const n=dI(e)==="Point",r=Rue(e,i);return t===1||n||(d0(e,function(s){const a=Eue(r,s),l=jle(r,s),h=ho(_J(r,a*t,l));s[0]=h[0],s[1]=h[1],s.length===3&&(s[2]*=t)}),delete e.bbox),e}function Rue(e,t){if(t==null&&(t="centroid"),Array.isArray(t)||typeof t=="object")return oa(t);const i=e.bbox?e.bbox:As(e,{recompute:!0}),n=i[0],r=i[1],s=i[2],a=i[3];switch(t){case"sw":case"southwest":case"westsouth":case"bottomleft":return aa([n,r]);case"se":case"southeast":case"eastsouth":case"bottomright":return aa([s,r]);case"nw":case"northwest":case"westnorth":case"topleft":return aa([n,a]);case"ne":case"northeast":case"eastnorth":case"topright":return aa([s,a]);case"center":return Wj(e);case void 0:case null:case"centroid":return jb(e);default:throw new Error("invalid origin")}}function Bue(e,t){var i=e[0]-t[0],n=e[1]-t[1];return i*i+n*n}function Lue(e,t,i){var n=t[0],r=t[1],s=i[0]-n,a=i[1]-r;if(s!==0||a!==0){var l=((e[0]-n)*s+(e[1]-r)*a)/(s*s+a*a);l>1?(n=i[0],r=i[1]):l>0&&(n+=s*l,r+=a*l)}return s=e[0]-n,a=e[1]-r,s*s+a*a}function kue(e,t){for(var i=e[0],n=[i],r,s=1,a=e.length;s<a;s++)r=e[s],Bue(r,i)>t&&(n.push(r),i=r);return i!==r&&n.push(r),n}function v6(e,t,i,n,r){for(var s=n,a,l=t+1;l<i;l++){var h=Lue(e[l],e[t],e[i]);h>s&&(a=l,s=h)}s>n&&(a-t>1&&v6(e,t,a,n,r),r.push(e[a]),i-a>1&&v6(e,a,i,n,r))}function Pue(e,t){var i=e.length-1,n=[e[0]];return v6(e,0,i,t,n),n.push(e[i]),n}function wI(e,t,i){if(e.length<=2)return e;var n=t!==void 0?t*t:1;return e=i?e:kue(e,n),e=Pue(e,n),e}function y6(e,t={}){var i,n,r;if(t=t??{},!$x(t))throw new Error("options is invalid");const s=(i=t.tolerance)!=null?i:1,a=(n=t.highQuality)!=null?n:!1,l=(r=t.mutate)!=null?r:!1;if(!e)throw new Error("geojson is required");if(s&&s<0)throw new Error("invalid tolerance");return l!==!0&&(e=Go(e)),f0(e,function(h){Nue(h,s,a)}),e}function Nue(e,t,i){const n=e.type;if(n==="Point"||n==="MultiPoint")return e;if(zj(e,{mutate:!0}),n!=="GeometryCollection")switch(n){case"LineString":e.coordinates=wI(e.coordinates,t,i);break;case"MultiLineString":e.coordinates=e.coordinates.map(r=>wI(r,t,i));break;case"Polygon":e.coordinates=w$(e.coordinates,t,i);break;case"MultiPolygon":e.coordinates=e.coordinates.map(r=>w$(r,t,i))}return e}function w$(e,t,i){return e.map(function(n){if(n.length<4)throw new Error("invalid polygon");let r=t,s=wI(n,r,i);for(;!C$(s)&&r>=Number.EPSILON;)r-=r*.01,s=wI(n,r,i);return C$(s)?((s[s.length-1][0]!==s[0][0]||s[s.length-1][1]!==s[0][1])&&s.push(s[0]),s):n})}function C$(e){return e.length<3?!1:!(e.length===3&&e[2][0]===e[0][0]&&e[2][1]===e[0][1])}function b6(e,t,i,n){if(n=n||{},!$x(n))throw new Error("options is invalid");var r=n.units,s=n.zTranslation,a=n.mutate;if(!e)throw new Error("geojson is required");if(t==null||isNaN(t))throw new Error("distance is required");if(s&&typeof s!="number"&&isNaN(s))throw new Error("zTranslation is not a number");if(s=s!==void 0?s:0,t===0&&s===0)return e;if(i==null||isNaN(i))throw new Error("direction is required");return t<0&&(t=-t,i=i+180),(a===!1||a===void 0)&&(e=Go(e)),d0(e,function(l){var h=ho(_J(l,t,i,{units:r}));l[0]=h[0],l[1]=h[1],s&&l.length===3&&(l[2]+=s)}),e}function Fue(e,t={}){const i=[];if(f0(e,r=>{i.push(r.coordinates)}),i.length<2)throw new Error("Must have at least 2 geometries");const n=xue(i[0],...i.slice(1));return n.length===0?null:n.length===1?ph(n[0],t.properties):RT(n,t.properties)}function Due(e,t){if(e.geometry.type!=="Polygon")throw new Error("The input feature must be a Polygon");for(var i=e.geometry.coordinates,n=[],r={},s=[],a=0;a<i.length;a++)for(var l=0;l<i[a].length-1;l++)s.push(v(a,l));var h=new jG;h.load(s);for(var d=0;d<i.length;d++)for(var p=0;p<i[d].length-1;p++)h.search(v(d,p)).forEach(function(y){var E=y.ring,S=y.edge;g(d,p,E,S)});return n;function g(y,E,S,R){var I=i[y][E],k=i[y][E+1],D=i[S][R],F=i[S][R+1],Z=Oue(I,k,D,F);if(Z!==null){var Y,Q;if(k[0]!==I[0]?Y=(Z[0]-I[0])/(k[0]-I[0]):Y=(Z[1]-I[1])/(k[1]-I[1]),F[0]!==D[0]?Q=(Z[0]-D[0])/(F[0]-D[0]):Q=(Z[1]-D[1])/(F[1]-D[1]),!(Y>=1||Y<=0||Q>=1||Q<=0)){var V=Z,U=!r[V.toString()];U&&(r[V.toString()]=!0),t&&n.push(t(Z,y,E,I,k,Y,S,R,D,F,Q,U))}}}function v(y,E){var S=i[y][E],R=i[y][E+1],I,k,D,F;return S[0]<R[0]?(I=S[0],k=R[0]):(I=R[0],k=S[0]),S[1]<R[1]?(D=S[1],F=R[1]):(D=R[1],F=S[1]),{minX:I,minY:D,maxX:k,maxY:F,ring:y,edge:E}}}function Oue(e,t,i,n){if(Z1(e,i)||Z1(e,n)||Z1(t,i)||Z1(n,i))return null;var r=e[0],s=e[1],a=t[0],l=t[1],h=i[0],d=i[1],p=n[0],g=n[1],v=(r-a)*(d-g)-(s-l)*(h-p);return v===0?null:[((r*l-s*a)*(h-p)-(r-a)*(h*g-d*p))/v,((r*l-s*a)*(d-g)-(s-l)*(h*g-d*p))/v]}function Z1(e,t){if(!e||!t||e.length!==t.length)return!1;for(var i=0,n=e.length;i<n;i++)if(e[i]instanceof Array&&t[i]instanceof Array){if(!Z1(e[i],t[i]))return!1}else if(e[i]!==t[i])return!1;return!0}function Uue(e){if(e.type!="Feature")throw new Error("The input must a geojson object of type Feature");if(e.geometry===void 0||e.geometry==null)throw new Error("The input must a geojson object with a non-empty geometry");if(e.geometry.type!="Polygon")throw new Error("The input must be a geojson Polygon");for(var t=e.geometry.coordinates.length,i=[],I=0;I<t;I++){var n=e.geometry.coordinates[I];q1(n[0],n[n.length-1])||n.push(n[0]);for(var r=0;r<n.length-1;r++)i.push(n[r])}if(!zue(i))throw new Error("The input polygon may not have duplicate vertices (except for the first and last vertex of each ring)");var s=i.length,a=Due(e,function(Ee,Se,Ve,ze,it,Le,nt,lt,Ae,vt,Ne,$t){return[Ee,Se,Ve,ze,it,Le,nt,lt,Ae,vt,Ne,$t]}),l=a.length;if(l==0){for(var Y=[],I=0;I<t;I++)Y.push(ph([e.geometry.coordinates[I]],{parent:-1,winding:Gue(e.geometry.coordinates[I])}));let Ee=Qn(Y);return de(Ee),pe(Ee),Ee}for(var h=[],d=[],I=0;I<t;I++){h.push([]);for(var r=0;r<e.geometry.coordinates[I].length-1;r++)h[I].push([new E$(e.geometry.coordinates[I][yA(r+1,e.geometry.coordinates[I].length-1)],1,[I,r],[I,yA(r+1,e.geometry.coordinates[I].length-1)],void 0)]),d.push(new S$(e.geometry.coordinates[I][r],[I,yA(r-1,e.geometry.coordinates[I].length-1)],[I,r],void 0,void 0,!1,!0))}for(var I=0;I<l;I++)h[a[I][1]][a[I][2]].push(new E$(a[I][0],a[I][5],[a[I][1],a[I][2]],[a[I][6],a[I][7]],void 0)),a[I][11]&&d.push(new S$(a[I][0],[a[I][1],a[I][2]],[a[I][6],a[I][7]],void 0,void 0,!0,!0));for(var p=d.length,I=0;I<h.length;I++)for(var r=0;r<h[I].length;r++)h[I][r].sort(function(Se,Ve){return Se.param<Ve.param?-1:1});for(var g=[],I=0;I<p;I++)g.push({minX:d[I].coord[0],minY:d[I].coord[1],maxX:d[I].coord[0],maxY:d[I].coord[1],index:I});var v=new jG;v.load(g);for(var I=0;I<h.length;I++)for(var r=0;r<h[I].length;r++)for(var y=0;y<h[I][r].length;y++){let Se;y==h[I][r].length-1?Se=h[I][yA(r+1,e.geometry.coordinates[I].length-1)][0].coord:Se=h[I][r][y+1].coord;var E=v.search({minX:Se[0],minY:Se[1],maxX:Se[0],maxY:Se[1]})[0];h[I][r][y].nxtIsectAlongEdgeIn=E.index}for(var I=0;I<h.length;I++)for(var r=0;r<h[I].length;r++)for(var y=0;y<h[I][r].length;y++){let Ve=h[I][r][y].coord;var E=v.search({minX:Ve[0],minY:Ve[1],maxX:Ve[0],maxY:Ve[1]})[0],S=E.index;S<s?d[S].nxtIsectAlongRingAndEdge2=h[I][r][y].nxtIsectAlongEdgeIn:q1(d[S].ringAndEdge1,h[I][r][y].ringAndEdgeIn)?d[S].nxtIsectAlongRingAndEdge1=h[I][r][y].nxtIsectAlongEdgeIn:d[S].nxtIsectAlongRingAndEdge2=h[I][r][y].nxtIsectAlongEdgeIn}for(var R=[],I=0,r=0;r<t;r++){for(var k=I,y=0;y<e.geometry.coordinates[r].length-1;y++)d[I].coord[0]<d[k].coord[0]&&(k=I),I++;for(var D=d[k].nxtIsectAlongRingAndEdge2,y=0;y<d.length;y++)if(d[y].nxtIsectAlongRingAndEdge1==k||d[y].nxtIsectAlongRingAndEdge2==k){var F=y;break}var Z=BM([d[F].coord,d[k].coord,d[D].coord],!0)?1:-1;R.push({isect:k,parent:-1,winding:Z})}R.sort(function(we,Ee){return d[we.isect].coord>d[Ee.isect].coord?-1:1});for(var Y=[];R.length>0;){var Q=R.pop(),V=Q.isect,U=Q.parent,H=Q.winding,W=Y.length,ne=[d[V].coord],te=V;if(d[V].ringAndEdge1Walkable)var oe=d[V].ringAndEdge1,X=d[V].nxtIsectAlongRingAndEdge1;else var oe=d[V].ringAndEdge2,X=d[V].nxtIsectAlongRingAndEdge2;for(;!q1(d[V].coord,d[X].coord);){ne.push(d[X].coord);for(var ee=void 0,I=0;I<R.length;I++)if(R[I].isect==X){ee=I;break}if(ee!=null&&R.splice(ee,1),q1(oe,d[X].ringAndEdge1)){if(oe=d[X].ringAndEdge2,d[X].ringAndEdge2Walkable=!1,d[X].ringAndEdge1Walkable){var ae={isect:X};BM([d[te].coord,d[X].coord,d[d[X].nxtIsectAlongRingAndEdge2].coord],H==1)?(ae.parent=U,ae.winding=-H):(ae.parent=W,ae.winding=H),R.push(ae)}te=X,X=d[X].nxtIsectAlongRingAndEdge2}else{if(oe=d[X].ringAndEdge1,d[X].ringAndEdge1Walkable=!1,d[X].ringAndEdge2Walkable){var ae={isect:X};BM([d[te].coord,d[X].coord,d[d[X].nxtIsectAlongRingAndEdge1].coord],H==1)?(ae.parent=U,ae.winding=-H):(ae.parent=W,ae.winding=H),R.push(ae)}te=X,X=d[X].nxtIsectAlongRingAndEdge1}}ne.push(d[X].coord),Y.push(ph([ne],{index:W,parent:U,winding:H,netWinding:void 0}))}let ce=Qn(Y);de(ce),pe(ce);function de(we){for(var Ee=[],Se=0;Se<we.features.length;Se++)we.features[Se].properties.parent==-1&&Ee.push(Se);if(Ee.length>1)for(var Se=0;Se<Ee.length;Se++){for(var Ve=-1,ze=1/0,it=0;it<we.features.length;it++)Ee[Se]!=it&&la(we.features[Ee[Se]].geometry.coordinates[0][0],we.features[it],{ignoreBoundary:!0})&&fI(we.features[it])<ze&&(Ve=it);we.features[Ee[Se]].properties.parent=Ve}}function pe(we){for(var Ee=0;Ee<we.features.length;Ee++)if(we.features[Ee].properties.parent==-1){var Se=we.features[Ee].properties.winding;we.features[Ee].properties.netWinding=Se,Ie(we,Ee,Se)}}function Ie(we,Ee,Se){for(var Ve=0;Ve<we.features.length;Ve++)if(we.features[Ve].properties.parent==Ee){var ze=Se+we.features[Ve].properties.winding;we.features[Ve].properties.netWinding=ze,Ie(we,Ve,ze)}}return ce}var E$=class{constructor(e,t,i,n,r){this.coord=e,this.param=t,this.ringAndEdgeIn=i,this.ringAndEdgeOut=n,this.nxtIsectAlongEdgeIn=r}},S$=class{constructor(e,t,i,n,r,s,a){this.coord=e,this.ringAndEdge1=t,this.ringAndEdge2=i,this.nxtIsectAlongRingAndEdge1=n,this.nxtIsectAlongRingAndEdge2=r,this.ringAndEdge1Walkable=s,this.ringAndEdge2Walkable=a}};function BM(e,t){if(typeof t>"u"&&(t=!0),e.length!=3)throw new Error("This function requires an array of three points [x,y]");return(e[1][0]-e[0][0])*(e[2][1]-e[0][1])-(e[1][1]-e[0][1])*(e[2][0]-e[0][0])>=0==t}function Gue(e){for(var t=0,i=0;i<e.length-1;i++)e[i][0]<e[t][0]&&(t=i);if(BM([e[yA(t-1,e.length-1)],e[t],e[yA(t+1,e.length-1)]],!0))var n=1;else var n=-1;return n}function q1(e,t){if(!e||!t||e.length!=t.length)return!1;for(var i=0,n=e.length;i<n;i++)if(e[i]instanceof Array&&t[i]instanceof Array){if(!q1(e[i],t[i]))return!1}else if(e[i]!=t[i])return!1;return!0}function yA(e,t){return(e%t+t)%t}function zue(e){for(var t={},i=1,n=0,r=e.length;n<r;++n){if(Object.prototype.hasOwnProperty.call(t,e[n].toString())){i=0;break}t[e[n].toString()]=1}return i}function Vue(e){var t=[];return vf(e,function(i){i.geometry.type==="Polygon"&&Af(Uue(i),function(n){t.push(ph(n.geometry.coordinates,i.properties))})}),Qn(t)}var $ue=class{undoStack=[];redoStack=[];maxSize;isExecuting=!1;onHistoryChange;constructor(e=50,t){this.maxSize=e,this.onHistoryChange=t}record(e){if(!this.isExecuting){for(this.undoStack.push(e);this.undoStack.length>this.maxSize;)this.undoStack.shift();this.redoStack=[],this.notifyChange()}}undo(){if(!this.canUndo())return!1;const e=this.undoStack.pop();this.isExecuting=!0;try{e.undo()}finally{this.isExecuting=!1}return this.redoStack.push(e),this.notifyChange(),!0}redo(){if(!this.canRedo())return!1;const e=this.redoStack.pop();this.isExecuting=!0;try{e.execute()}finally{this.isExecuting=!1}return this.undoStack.push(e),this.notifyChange(),!0}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}isExecutingCommand(){return this.isExecuting}getState(){return{canUndo:this.canUndo(),canRedo:this.canRedo(),undoCount:this.undoStack.length,redoCount:this.redoStack.length}}clear(){this.undoStack=[],this.redoStack=[],this.notifyChange()}getUndoDescription(){return this.undoStack.length===0?null:this.undoStack[this.undoStack.length-1].description}getRedoDescription(){return this.redoStack.length===0?null:this.redoStack[this.redoStack.length-1].description}notifyChange(){this.onHistoryChange&&this.onHistoryChange(this.canUndo(),this.canRedo())}},M$=class{description;type="create";feature;featureId=null;context;constructor(e,t){this.feature=Go(e),this.context=t,this.featureId=this.extractFeatureId(e);const i=e.geometry?.type||"feature";this.description=`Create ${i}`}execute(){const e=this.context.featuresApi.importGeoJsonFeature(this.feature);e&&(this.featureId=String(e.id),this.context.onFeatureCreate?.(this.feature))}undo(){if(!this.featureId)return;const e=[];try{this.context.featuresApi.forEach(t=>{const i=String(t.id),n=this.getGeomanFeature(t),r=n?this.extractFeatureId(n):null;(i===this.featureId||r===this.featureId)&&e.push(t)}),e.forEach(t=>{try{this.context.featuresApi.delete(t)}catch{try{t.delete()}catch{}}}),e.length>0&&this.featureId&&this.context.onFeatureDelete?.(this.featureId)}catch{}}extractFeatureId(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}},Hue=class{description;type="edit";oldFeature;newFeature;featureId;context;constructor(e,t,i){this.oldFeature=Go(e),this.newFeature=Go(t),this.context=i,this.featureId=this.extractFeatureId(t)||this.extractFeatureId(e);const n=t.geometry?.type||"feature";this.description=`Edit ${n}`}execute(){this.updateFeatureGeometry(this.newFeature)}undo(){this.updateFeatureGeometry(this.oldFeature)}updateFeatureGeometry(e){if(this.featureId)try{this.context.featuresApi.forEach(t=>{const i=String(t.id),n=this.getGeomanFeature(t),r=n?this.extractFeatureId(n):null;(i===this.featureId||r===this.featureId)&&(t.updateGeometry?t.updateGeometry(e.geometry):t.updateGeoJsonGeometry&&t.updateGeoJsonGeometry(e.geometry))})}catch{this.deleteAndReimport(e)}}deleteAndReimport(e){if(!this.featureId)return;const t=[];try{this.context.featuresApi.forEach(n=>{const r=String(n.id),s=this.getGeomanFeature(n),a=s?this.extractFeatureId(s):null;(r===this.featureId||a===this.featureId)&&t.push(n)}),t.forEach(n=>{try{this.context.featuresApi.delete(n)}catch{try{n.delete()}catch{}}})}catch{}const i=this.context.featuresApi.importGeoJsonFeature(e);i&&(this.featureId=String(i.id))}extractFeatureId(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}},I$=class{description;type="delete";feature;featureId;context;constructor(e,t){this.feature=Go(e),this.context=t,this.featureId=this.extractFeatureId(e);const i=e.geometry?.type||"feature";this.description=`Delete ${i}`}execute(){if(!this.featureId)return;const e=[];try{this.context.featuresApi.forEach(t=>{const i=String(t.id),n=this.getGeomanFeature(t),r=n?this.extractFeatureId(n):null;(i===this.featureId||r===this.featureId)&&e.push(t)}),e.forEach(t=>{try{this.context.featuresApi.delete(t)}catch{try{t.delete()}catch{}}}),e.length>0&&this.featureId&&this.context.onFeatureDelete?.(this.featureId)}catch{}}undo(){const e=this.context.featuresApi.importGeoJsonFeature(this.feature);e&&(this.featureId=String(e.id),this.context.onFeatureCreate?.(this.feature))}extractFeatureId(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}},Que=class{description;type="composite";commands;constructor(e,t){this.commands=e,this.description=t}execute(){for(const e of this.commands)e.execute()}undo(){for(let e=this.commands.length-1;e>=0;e--)this.commands[e].undo()}getCommandCount(){return this.commands.length}},Wue=["polygon","line","rectangle","circle","marker"],Xue=["select","drag","change","rotate","cut","delete","scale","copy","split","union","difference","simplify","lasso"],l8=["select","scale","copy","split","union","difference","simplify","lasso"],Zue=["snapping","measurements"],que=["open","save"],Yue={position:"top-left",collapsed:!1,drawModes:Wue,editModes:Xue,helperModes:Zue,fileModes:que,toolbarOrientation:"vertical",showLabels:!1,simplifyTolerance:.001,snappingEnabled:!0,measurementsEnabled:!1,hideGeomanControl:!0,saveFilename:"features.geojson",onFeatureCreate:()=>{},onFeatureEdit:()=>{},onFeatureDelete:()=>{},onSelectionChange:()=>{},onModeChange:()=>{},onGeoJsonLoad:()=>{},onGeoJsonSave:()=>{},showFeatureProperties:!0,fitBoundsOnLoad:!0,columns:2,enableHistory:!0,maxHistorySize:50,onHistoryChange:()=>{},enableAttributeEditing:!1,attributeSchema:void 0,onAttributeChange:()=>{},attributePanelPosition:"right",attributePanelWidth:300,attributePanelMaxHeight:"80vh",attributePanelTop:10,attributePanelSideOffset:10,attributePanelTitle:"Feature Properties"},Pi="geo-editor",Zi={LASSO_SOURCE:"geo-editor-lasso-source",LASSO_LAYER:"geo-editor-lasso-layer",LASSO_LINE_LAYER:"geo-editor-lasso-line-layer",SCALE_HANDLES_SOURCE:"geo-editor-scale-handles-source",SCALE_HANDLES_LAYER:"geo-editor-scale-handles-layer",SPLIT_LINE_SOURCE:"geo-editor-split-line-source",SPLIT_LINE_LAYER:"geo-editor-split-line-layer",SELECTION_SOURCE:"geo-editor-selection-source",SELECTION_FILL_LAYER:"geo-editor-selection-fill-layer",SELECTION_LINE_LAYER:"geo-editor-selection-line-layer",SELECTION_CIRCLE_LAYER:"geo-editor-selection-circle-layer",FREEHAND_SOURCE:"geo-editor-freehand-source",FREEHAND_FILL_LAYER:"geo-editor-freehand-fill-layer",FREEHAND_LINE_LAYER:"geo-editor-freehand-line-layer"},n_={handleSize:10,handleColor:"#3388ff",handleBorderColor:"#ffffff",handleBorderWidth:2,minScale:.1,maxScale:10},c8={tolerance:.001,highQuality:!1,mutate:!1},T$={offset:[5e-4,5e-4],generateNewIds:!0};function bf(){return`feature_${Date.now()}_${Math.random().toString(36).slice(2,11)}`}function AJ(e){return e.geometry.type==="Polygon"||e.geometry.type==="MultiPolygon"}function jue(e){return e.geometry.type==="LineString"||e.geometry.type==="MultiLineString"}function R$(e,t,i){return Math.min(Math.max(e,t),i)}function Yy(e){return Kle(e).length}var Jue=class{options;constructor(e={}){this.options={offset:e.offset??T$.offset,generateNewIds:e.generateNewIds??T$.generateNewIds}}copy(e,t){const i=Go(e),n=t??this.options.offset;return this.options.generateNewIds&&(i.id=bf(),i.properties&&(i.properties={...i.properties,id:i.id})),n[0]!==0||n[1]!==0?b6(i,Math.sqrt(n[0]**2+n[1]**2)*111,Math.atan2(n[0],n[1])*180/Math.PI,{units:"kilometers"}):i}copyMultiple(e,t){return e.map(i=>this.copy(i,t))}copyToLocation(e,t){if(e.length===0)return[];const i=jb(Qn(e)).geometry.coordinates,n=t[0]-i[0],r=t[1]-i[1];return e.map(s=>{const a=Go(s);return this.options.generateNewIds&&(a.id=bf(),a.properties&&(a.properties={...a.properties,id:a.id})),b6(a,Math.sqrt(n**2+r**2)*111,Math.atan2(n,r)*180/Math.PI,{units:"kilometers"})})}setOffset(e){this.options.offset=e}getOffset(){return this.options.offset}},Kue=class{defaultOptions;constructor(e){this.defaultOptions={tolerance:e?.tolerance??c8.tolerance,highQuality:e?.highQuality??c8.highQuality,mutate:e?.mutate??c8.mutate}}simplify(e,t){return y6(e,{...this.defaultOptions,...t})}simplifyWithStats(e,t){const i={...this.defaultOptions,...t},n=Yy(e),r=y6(e,i),s=Yy(r);return{result:r,original:e,verticesBefore:n,verticesAfter:s,reductionPercent:n>0?(n-s)/n*100:0}}getSimplificationStats(e,t){const i=Yy(e),n=Yy(this.simplify(e,{tolerance:t}));return{before:i,after:n,reduction:i>0?(i-n)/i*100:0}}previewTolerances(e,t){const i=new Map;for(const n of t)i.set(n,this.simplifyWithStats(e,{tolerance:n}));return i}getSuggestedTolerances(e){const t=Yy(e),i=[1e-4,5e-4,.001,.005,.01];return t>1e3?[.001,.005,.01,.05,.1]:t>100?[5e-4,.001,.005,.01,.05]:i}findOptimalTolerance(e,t){const i=[1e-5,5e-5,1e-4,5e-4,.001,.005,.01,.05,.1];let n=i[0],r=this.simplifyWithStats(e,{tolerance:n}),s=Math.abs(r.reductionPercent-t);for(const a of i.slice(1)){const l=this.simplifyWithStats(e,{tolerance:a}),h=Math.abs(l.reductionPercent-t);h<s&&(s=h,n=a,r=l)}return{tolerance:n,result:r}}setDefaultTolerance(e){this.defaultOptions.tolerance=e}getDefaultTolerance(){return this.defaultOptions.tolerance}},ede=class{union(e,t){if(e.length===0)return{result:null,originals:[],success:!1,error:"No features provided"};if(e.length===1){const i=Go(e[0]);return i.id=bf(),t?.properties&&(i.properties={...i.properties,...t.properties}),{result:i,originals:e,success:!0}}try{const i=Fue(Qn(e));return i&&(i.id=bf(),t?.properties&&(i.properties={...i.properties,...t.properties})),{result:i,originals:e,success:i!==null,error:i===null?"Union operation returned null":void 0}}catch(i){return{result:null,originals:e,success:!1,error:`Union operation failed: ${i instanceof Error?i.message:"Unknown error"}`}}}canMerge(e){if(e.length<2)return{canMerge:!1,reason:"Need at least 2 polygons to merge"};for(const t of e)if(t.geometry.type!=="Polygon"&&t.geometry.type!=="MultiPolygon")return{canMerge:!1,reason:"All features must be polygons"};return{canMerge:!0}}hasOverlap(e){for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++)try{if($j(e[t],e[i])||nz(e[t],e[i]))return!0}catch{}return!1}getCombinedArea(e){return e.reduce((t,i)=>{try{return t+fI(i)}catch{return t}},0)}getUnionArea(e){const t=this.union(e);if(t.success&&t.result)try{return fI(t.result)}catch{return null}return null}},tde=class{difference(e,t,i){if(t.length===0){const n=Go(e);return n.id=bf(),{result:n,base:e,subtracted:[],success:!0}}try{let n=Go(e);for(const r of t){if(!n)break;n=gJ(Qn([n,r]))}return n&&(n.id=bf(),i?.properties&&(n.properties={...n.properties,...i.properties})),{result:n,base:e,subtracted:t,success:!0}}catch(n){return{result:null,base:e,subtracted:t,success:!1,error:`Difference operation failed: ${n instanceof Error?n.message:"Unknown error"}`}}}canSubtract(e,t){if(e.geometry.type!=="Polygon"&&e.geometry.type!=="MultiPolygon")return{canSubtract:!1,overlap:!1,reason:"Base must be a polygon"};if(t.geometry.type!=="Polygon"&&t.geometry.type!=="MultiPolygon")return{canSubtract:!1,overlap:!1,reason:"Subtract feature must be a polygon"};try{return $j(e,t)||X9(e,t)||nz(e,t)?{canSubtract:!0,overlap:!0}:{canSubtract:!1,overlap:!1,reason:"Polygons do not overlap"}}catch{return{canSubtract:!1,overlap:!1,reason:"Could not determine overlap"}}}getSubtractedArea(e,t){try{const i=Iue(Qn([e,t]));return i?fI(i):0}catch{return null}}preview(e,t){return this.difference(e,t).result}createHole(e,t){try{return X9(e,t)?this.difference(e,[t]).result:(console.warn("Hole must be completely inside the polygon"),null)}catch{return null}}},ide=class{map=null;options;activeFeature=null;originalFeature=null;handles=[];activeHandle=null;startPoint=null;onScaleCallback=null;constructor(e={}){this.options={maintainAspectRatio:e.maintainAspectRatio??!0,scaleFromCenter:e.scaleFromCenter??!0,minScale:e.minScale??n_.minScale,maxScale:e.maxScale??n_.maxScale}}init(e){this.map=e}scale(e,t,i){const n=Tue(e,R$(t,this.options.minScale,this.options.maxScale),{origin:i||jb(e).geometry.coordinates});return n.id=e.id||bf(),n.properties={...e.properties},n}scaleFromHandle(e,t,i,n){const r=As(e),s=jb(e).geometry.coordinates,a=this.distanceFromCenter(i,s);let l=this.distanceFromCenter(n,s)/a;l=R$(l,this.options.minScale,this.options.maxScale);let h;return this.options.scaleFromCenter?h=s:h=this.getOppositeCorner(r,t),this.scale(e,l,h)}createHandles(e){const[t,i,n,r]=As(e),s=(t+n)/2,a=(i+r)/2;return this.handles=[{position:"nw",coordinates:[t,r]},{position:"n",coordinates:[s,r]},{position:"ne",coordinates:[n,r]},{position:"e",coordinates:[n,a]},{position:"se",coordinates:[n,i]},{position:"s",coordinates:[s,i]},{position:"sw",coordinates:[t,i]},{position:"w",coordinates:[t,a]}],this.handles}startScale(e,t,i,n){this.activeFeature=Go(e),this.originalFeature=Go(e),this.activeHandle=t,this.startPoint=i,this.onScaleCallback=n||null,this.showHandles(e)}showHandlesForFeature(e){this.showHandles(e)}updateScale(e){if(!this.activeFeature||!this.originalFeature||!this.activeHandle||!this.startPoint)return null;const t=this.scaleFromHandle(this.originalFeature,this.activeHandle,this.startPoint,e);this.activeFeature=t,this.updateHandlePositions(t);const i=As(this.originalFeature),n=As(t),r=(n[2]-n[0])/(i[2]-i[0]);return this.onScaleCallback&&this.onScaleCallback(t,r),t}endScale(){if(!this.activeFeature||!this.originalFeature)return null;const e=As(this.originalFeature),t=As(this.activeFeature),i=(t[2]-t[0])/(e[2]-e[0]),n={feature:this.activeFeature,factor:i};return this.hideHandles(),this.activeFeature=null,this.originalFeature=null,this.activeHandle=null,this.startPoint=null,this.onScaleCallback=null,n}cancelScale(){this.hideHandles(),this.activeFeature=null,this.originalFeature=null,this.activeHandle=null,this.startPoint=null,this.onScaleCallback=null}showHandles(e){if(!this.map)return;const t=this.createHandles(e).map(i=>aa(i.coordinates,{position:i.position}));if(!this.map.getSource(Zi.SCALE_HANDLES_SOURCE))this.map.addSource(Zi.SCALE_HANDLES_SOURCE,{type:"geojson",data:Qn(t)}),this.map.addLayer({id:Zi.SCALE_HANDLES_LAYER,type:"circle",source:Zi.SCALE_HANDLES_SOURCE,paint:{"circle-radius":n_.handleSize/2,"circle-color":n_.handleColor,"circle-stroke-color":n_.handleBorderColor,"circle-stroke-width":n_.handleBorderWidth}});else{const i=this.map.getSource(Zi.SCALE_HANDLES_SOURCE);i&&i.setData(Qn(t))}}updateHandlePositions(e){if(!this.map)return;const t=this.createHandles(e).map(n=>aa(n.coordinates,{position:n.position})),i=this.map.getSource(Zi.SCALE_HANDLES_SOURCE);i&&i.setData(Qn(t))}hideHandles(){this.map&&(this.map.getLayer(Zi.SCALE_HANDLES_LAYER)&&this.map.removeLayer(Zi.SCALE_HANDLES_LAYER),this.map.getSource(Zi.SCALE_HANDLES_SOURCE)&&this.map.removeSource(Zi.SCALE_HANDLES_SOURCE))}distanceFromCenter(e,t){return Math.sqrt(Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2))}getOppositeCorner(e,t){const[i,n,r,s]=e,a=(i+r)/2,l=(n+s)/2;return{nw:[r,n],n:[a,n],ne:[i,n],e:[i,l],se:[i,s],s:[a,s],sw:[r,s],w:[r,l]}[t]}getHandleAtPoint(e,t=1e-4){for(const i of this.handles)if(this.distanceFromCenter(e,i.coordinates)<t)return i.position;return null}destroy(){this.cancelScale(),this.map=null}},nde=class{map=null;isDrawing=!1;points=[];options;onCompleteCallback=null;dragPanEnabled=null;boxZoomEnabled=null;doubleClickZoomEnabled=null;handleMouseDown=null;handleMouseMove=null;handleMouseUp=null;constructor(e={}){this.options={mode:e.mode??"intersects"}}init(e){this.map=e}enable(e){this.map&&(this.onCompleteCallback=e||null,this.disableMapInteractions(),this.setupLassoLayers(),this.attachEventListeners(),this.map.getCanvas().style.cursor="crosshair")}disable(){this.removeEventListeners(),this.clearLasso(),this.isDrawing=!1,this.points=[],this.onCompleteCallback=null,this.restoreMapInteractions(),this.map&&(this.map.getCanvas().style.cursor="")}selectWithinLasso(e,t){return t.filter(i=>{try{return this.options.mode==="contains"?mhe(i,e):nz(i,e)}catch{return!1}})}buildLassoPolygon(){if(this.points.length<3)return null;const e=[...this.points,this.points[0]];try{return ph([e])}catch{return null}}setMode(e){this.options.mode=e}isActive(){return this.isDrawing}setupLassoLayers(){this.map&&(this.map.getSource(Zi.LASSO_SOURCE)||this.map.addSource(Zi.LASSO_SOURCE,{type:"geojson",data:Qn([])}),this.map.getLayer(Zi.LASSO_LAYER)||this.map.addLayer({id:Zi.LASSO_LAYER,type:"fill",source:Zi.LASSO_SOURCE,paint:{"fill-color":"#3388ff","fill-opacity":.2}}),this.map.getLayer(Zi.LASSO_LINE_LAYER)||this.map.addLayer({id:Zi.LASSO_LINE_LAYER,type:"line",source:Zi.LASSO_SOURCE,paint:{"line-color":"#3388ff","line-width":2,"line-dasharray":[2,2]}}))}attachEventListeners(){this.map&&(this.handleMouseDown=e=>{e.preventDefault(),this.isDrawing=!0,this.points=[[e.lngLat.lng,e.lngLat.lat]],this.updateLassoVisualization()},this.handleMouseMove=e=>{this.isDrawing&&(e.preventDefault(),this.points.push([e.lngLat.lng,e.lngLat.lat]),this.updateLassoVisualization())},this.handleMouseUp=()=>{this.isDrawing&&(this.isDrawing=!1,this.completeLasso())},this.map.on("mousedown",this.handleMouseDown),this.map.on("mousemove",this.handleMouseMove),this.map.on("mouseup",this.handleMouseUp))}removeEventListeners(){this.map&&(this.handleMouseDown&&this.map.off("mousedown",this.handleMouseDown),this.handleMouseMove&&this.map.off("mousemove",this.handleMouseMove),this.handleMouseUp&&this.map.off("mouseup",this.handleMouseUp),this.handleMouseDown=null,this.handleMouseMove=null,this.handleMouseUp=null)}updateLassoVisualization(){if(!this.map||this.points.length<2)return;const e=this.map.getSource(Zi.LASSO_SOURCE);if(!e)return;const t=[...this.points];if(t.length>=3){t.push(t[0]);const i=ph([t]);e.setData(Qn([i]))}else{const i=Uo(t);e.setData(Qn([i]))}}completeLasso(){const e=this.buildLassoPolygon();if(e&&this.onCompleteCallback){const t={selected:[],lasso:e};this.onCompleteCallback(t)}setTimeout(()=>{this.clearLasso(),this.points=[]},100)}clearLasso(){if(!this.map)return;const e=this.map.getSource(Zi.LASSO_SOURCE);e&&e.setData(Qn([]))}disableMapInteractions(){this.map&&(this.dragPanEnabled=this.map.dragPan.isEnabled(),this.dragPanEnabled&&this.map.dragPan.disable(),this.map.boxZoom&&(this.boxZoomEnabled=this.map.boxZoom.isEnabled(),this.boxZoomEnabled&&this.map.boxZoom.disable()),this.map.doubleClickZoom&&(this.doubleClickZoomEnabled=this.map.doubleClickZoom.isEnabled(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom.disable()))}restoreMapInteractions(){this.map&&(this.dragPanEnabled&&this.map.dragPan.enable(),this.boxZoomEnabled&&this.map.boxZoom&&this.map.boxZoom.enable(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom&&this.map.doubleClickZoom.enable(),this.dragPanEnabled=null,this.boxZoomEnabled=null,this.doubleClickZoomEnabled=null)}removeLayers(){this.map&&(this.map.getLayer(Zi.LASSO_LINE_LAYER)&&this.map.removeLayer(Zi.LASSO_LINE_LAYER),this.map.getLayer(Zi.LASSO_LAYER)&&this.map.removeLayer(Zi.LASSO_LAYER),this.map.getSource(Zi.LASSO_SOURCE)&&this.map.removeSource(Zi.LASSO_SOURCE))}destroy(){this.disable(),this.removeLayers(),this.map=null}},rde=class{map=null;isDrawing=!1;splitLinePoints=[];targetFeature=null;onCompleteCallback=null;handleClick=null;handleMouseMove=null;handleDblClick=null;constructor(){}init(e){this.map=e}splitPolygon(e,t,i){try{if(xv(pI(e),t).features.length<2)return{original:e,parts:[],success:!1,error:"Splitting line must intersect polygon at least twice"};if(!this.clipLineToBbox(t,As(e)))return{original:e,parts:[],success:!1,error:"Could not clip splitting line to polygon"};const n=this.performPolygonSplit(e,t);return n.length===0?{original:e,parts:[],success:!1,error:"Split operation produced no valid parts"}:(n.forEach(r=>{r.id=bf(),r.properties={...e.properties}}),{original:e,parts:n,success:!0})}catch(n){return{original:e,parts:[],success:!1,error:`Split operation failed: ${n instanceof Error?n.message:"Unknown error"}`}}}splitLine(e,t){try{const i=KG(e,t);return i.features.length<=1?{original:e,parts:[],success:!1,error:"Splitter does not intersect the line"}:{original:e,parts:i.features.map(n=>{const r=n;return r.id=bf(),r.properties={...e.properties},r}),success:!0}}catch(i){return{original:e,parts:[],success:!1,error:`Split operation failed: ${i instanceof Error?i.message:"Unknown error"}`}}}startSplit(e,t){this.map&&(this.targetFeature=e,this.onCompleteCallback=t,this.splitLinePoints=[],this.isDrawing=!0,this.setupSplitLineLayers(),this.attachEventListeners(),this.map.getCanvas().style.cursor="crosshair")}cancelSplit(){this.cleanup(),this.targetFeature=null,this.onCompleteCallback=null}isActive(){return this.isDrawing}performPolygonSplit(e,t){try{const i=iue(t,1e-5,{units:"degrees"});if(!i)return[];const n=gJ(Qn([e,i]));if(!n)return[];if(n.geometry.type==="MultiPolygon")return n.geometry.coordinates.map(s=>ph(s));const r=Vue(n);return r.features.length>1?r.features:[n]}catch{return[]}}clipLineToBbox(e,t){try{return sce(e,t)}catch{return null}}setupSplitLineLayers(){this.map&&(this.map.getSource(Zi.SPLIT_LINE_SOURCE)||this.map.addSource(Zi.SPLIT_LINE_SOURCE,{type:"geojson",data:Qn([])}),this.map.getLayer(Zi.SPLIT_LINE_LAYER)||this.map.addLayer({id:Zi.SPLIT_LINE_LAYER,type:"line",source:Zi.SPLIT_LINE_SOURCE,paint:{"line-color":"#ff4444","line-width":3,"line-dasharray":[3,3]}}))}attachEventListeners(){this.map&&(this.handleClick=e=>{this.splitLinePoints.push([e.lngLat.lng,e.lngLat.lat]),this.updateSplitLineVisualization()},this.handleMouseMove=e=>{if(this.splitLinePoints.length===0)return;const t=[...this.splitLinePoints,[e.lngLat.lng,e.lngLat.lat]];this.updateSplitLineVisualization(t)},this.handleDblClick=e=>{e.preventDefault(),this.completeSplit()},this.map.on("click",this.handleClick),this.map.on("mousemove",this.handleMouseMove),this.map.on("dblclick",this.handleDblClick))}removeEventListeners(){this.map&&(this.handleClick&&this.map.off("click",this.handleClick),this.handleMouseMove&&this.map.off("mousemove",this.handleMouseMove),this.handleDblClick&&this.map.off("dblclick",this.handleDblClick),this.handleClick=null,this.handleMouseMove=null,this.handleDblClick=null)}updateSplitLineVisualization(e){if(!this.map)return;const t=this.map.getSource(Zi.SPLIT_LINE_SOURCE);if(!t)return;const i=e||this.splitLinePoints;if(i.length<2){t.setData(Qn([]));return}const n=Uo(i);t.setData(Qn([n]))}completeSplit(){if(!this.targetFeature||!this.onCompleteCallback||this.splitLinePoints.length<2){this.cleanup();return}const e=Uo(this.splitLinePoints);let t;this.targetFeature.geometry.type==="Polygon"?t=this.splitPolygon(this.targetFeature,e):t=this.splitLine(this.targetFeature,e),this.onCompleteCallback(t),this.cleanup()}cleanup(){this.removeEventListeners(),this.clearSplitLine(),this.isDrawing=!1,this.splitLinePoints=[],this.map&&(this.map.getCanvas().style.cursor="")}clearSplitLine(){if(!this.map)return;const e=this.map.getSource(Zi.SPLIT_LINE_SOURCE);e&&e.setData(Qn([]))}removeLayers(){this.map&&(this.map.getLayer(Zi.SPLIT_LINE_LAYER)&&this.map.removeLayer(Zi.SPLIT_LINE_LAYER),this.map.getSource(Zi.SPLIT_LINE_SOURCE)&&this.map.removeSource(Zi.SPLIT_LINE_SOURCE))}destroy(){this.cancelSplit(),this.removeLayers(),this.map=null}},sde=class{map=null;isDrawing=!1;points=[];options;onCompleteCallback=null;dragPanEnabled=null;boxZoomEnabled=null;doubleClickZoomEnabled=null;handleMouseDown=null;handleMouseMove=null;handleMouseUp=null;constructor(e={}){this.options={type:e.type??"polygon",simplifyTolerance:e.simplifyTolerance??1e-5,minPoints:e.minPoints??(e.type==="line"?2:3)}}init(e){this.map=e}enable(e){this.map&&(this.onCompleteCallback=e||null,this.disableMapInteractions(),this.setupFreehandLayers(),this.attachEventListeners(),this.map.getCanvas().style.cursor="crosshair")}disable(){this.removeEventListeners(),this.clearFreehand(),this.isDrawing=!1,this.points=[],this.onCompleteCallback=null,this.restoreMapInteractions(),this.map&&(this.map.getCanvas().style.cursor="")}setType(e){this.options.type=e,this.options.minPoints=e==="line"?2:3}isActive(){return this.isDrawing}buildFeature(){if(this.points.length<this.options.minPoints)return null;try{let e=this.removeDuplicatePoints(this.points);if(e.length<this.options.minPoints)return null;if(e.length>10&&(e=y6(Uo(e),{tolerance:this.options.simplifyTolerance,highQuality:!0}).geometry.coordinates),e=this.removeDuplicatePoints(e),this.options.type==="polygon"){if(e.length<3)return null;for(;e.length>3&&this.arePointsEqual(e[0],e[e.length-1]);)e=e.slice(0,-1);if(e.length<3)return null;const t=e.map(n=>[n[0],n[1]]),i=[t[0][0],t[0][1]];return zj(ph([[...t,i]]))}else return e.length<2?null:Uo(e.map(t=>[t[0],t[1]]))}catch(e){return console.warn("FreehandFeature: Error building feature:",e),null}}removeDuplicatePoints(e){if(e.length<=1)return e;const t=[e[0]];for(let i=1;i<e.length;i++)this.arePointsEqual(e[i],e[i-1])||t.push(e[i]);return t}arePointsEqual(e,t){return Math.abs(e[0]-t[0])<1e-7&&Math.abs(e[1]-t[1])<1e-7}setupFreehandLayers(){this.map&&(this.map.getSource(Zi.FREEHAND_SOURCE)||this.map.addSource(Zi.FREEHAND_SOURCE,{type:"geojson",data:Qn([])}),this.map.getLayer(Zi.FREEHAND_FILL_LAYER)||this.map.addLayer({id:Zi.FREEHAND_FILL_LAYER,type:"fill",source:Zi.FREEHAND_SOURCE,filter:["==",["geometry-type"],"Polygon"],paint:{"fill-color":"#3388ff","fill-opacity":.2}}),this.map.getLayer(Zi.FREEHAND_LINE_LAYER)||this.map.addLayer({id:Zi.FREEHAND_LINE_LAYER,type:"line",source:Zi.FREEHAND_SOURCE,paint:{"line-color":"#3388ff","line-width":3}}))}attachEventListeners(){this.map&&(this.handleMouseDown=e=>{e.preventDefault(),this.isDrawing=!0,this.points=[[e.lngLat.lng,e.lngLat.lat]],this.updateFreehandVisualization()},this.handleMouseMove=e=>{this.isDrawing&&(e.preventDefault(),this.points.push([e.lngLat.lng,e.lngLat.lat]),this.updateFreehandVisualization())},this.handleMouseUp=()=>{this.isDrawing&&(this.isDrawing=!1,this.completeFreehand())},this.map.on("mousedown",this.handleMouseDown),this.map.on("mousemove",this.handleMouseMove),this.map.on("mouseup",this.handleMouseUp))}removeEventListeners(){this.map&&(this.handleMouseDown&&this.map.off("mousedown",this.handleMouseDown),this.handleMouseMove&&this.map.off("mousemove",this.handleMouseMove),this.handleMouseUp&&this.map.off("mouseup",this.handleMouseUp),this.handleMouseDown=null,this.handleMouseMove=null,this.handleMouseUp=null)}updateFreehandVisualization(){if(!this.map||this.points.length<2)return;const e=this.map.getSource(Zi.FREEHAND_SOURCE);if(!e)return;const t=[...this.points];if(this.options.type==="polygon"&&t.length>=3){const i=ph([[...t,t[0]]]);e.setData(Qn([i]))}else{const i=Uo(t);e.setData(Qn([i]))}}completeFreehand(){const e=this.buildFeature(),t={feature:e,success:e!==null,error:e?void 0:`Need at least ${this.options.minPoints} points`};this.onCompleteCallback&&this.onCompleteCallback(t),setTimeout(()=>{this.clearFreehand(),this.points=[]},100)}clearFreehand(){if(!this.map)return;const e=this.map.getSource(Zi.FREEHAND_SOURCE);e&&e.setData(Qn([]))}disableMapInteractions(){this.map&&(this.dragPanEnabled=this.map.dragPan.isEnabled(),this.dragPanEnabled&&this.map.dragPan.disable(),this.map.boxZoom&&(this.boxZoomEnabled=this.map.boxZoom.isEnabled(),this.boxZoomEnabled&&this.map.boxZoom.disable()),this.map.doubleClickZoom&&(this.doubleClickZoomEnabled=this.map.doubleClickZoom.isEnabled(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom.disable()))}restoreMapInteractions(){this.map&&(this.dragPanEnabled&&this.map.dragPan.enable(),this.boxZoomEnabled&&this.map.boxZoom&&this.map.boxZoom.enable(),this.doubleClickZoomEnabled&&this.map.doubleClickZoom&&this.map.doubleClickZoom.enable(),this.dragPanEnabled=null,this.boxZoomEnabled=null,this.doubleClickZoomEnabled=null)}removeLayers(){this.map&&(this.map.getLayer(Zi.FREEHAND_LINE_LAYER)&&this.map.removeLayer(Zi.FREEHAND_LINE_LAYER),this.map.getLayer(Zi.FREEHAND_FILL_LAYER)&&this.map.removeLayer(Zi.FREEHAND_FILL_LAYER),this.map.getSource(Zi.FREEHAND_SOURCE)&&this.map.removeSource(Zi.FREEHAND_SOURCE))}destroy(){this.disable(),this.removeLayers(),this.map=null}};function ME(e){return e.filter(AJ)}var x6=class{map;geoman=null;container;options;state;copyFeature;simplifyFeature;unionFeature;differenceFeature;scaleFeature;lassoFeature;splitFeature;freehandFeature;boundKeyHandler=null;boundClickHandler=null;boundScaleMouseDown=null;boundScaleMouseMove=null;boundScaleMouseUp=null;isSelectMode=!1;pendingOperation=null;snappingEnabled=!1;lastCreatedFeature=null;lastEditedFeature=null;lastDeletedFeature=null;lastDeletedFeatureId=null;isScaling=!1;scaleTargetFeature=null;scaleTargetGeomanData=null;scaleStartFeature=null;scaleDragPanEnabled=null;isMultiDragging=!1;multiDragStartPoint=null;multiDragOriginalFeatures=[];multiDragGeomanData=[];multiDragPanEnabled=null;boundMultiDragMouseDown=null;boundMultiDragMouseMove=null;boundMultiDragMouseUp=null;toolbar=null;fileInput=null;propertiesPopup=null;historyManager=null;pendingEditFeature=null;isPerformingCompositeOperation=!1;attributePanel=null;attributePanelVisible=!1;currentEditingFeature=null;currentEditingGeomanData=null;isNewFeature=!1;originalProperties=null;boundStyleDataHandler=null;_eventHandlers=new globalThis.Map;constructor(e={}){this.options={...Yue,...e},this.state={activeDrawMode:null,activeEditMode:null,selectedFeatures:[],isDrawing:!1,isEditing:!1,clipboard:[],collapsed:this.options.collapsed},this.snappingEnabled=this.options.snappingEnabled,this.copyFeature=new Jue,this.simplifyFeature=new Kue({tolerance:this.options.simplifyTolerance}),this.unionFeature=new ede,this.differenceFeature=new tde,this.scaleFeature=new ide,this.lassoFeature=new nde,this.splitFeature=new rde,this.freehandFeature=new sde,this.options.enableHistory!==!1&&(this.historyManager=new $ue(this.options.maxHistorySize,(t,i)=>{this.updateHistoryButtonStates(t,i),this.options.onHistoryChange?.(t,i)}))}onAdd(e){return this.map=e,this.scaleFeature.init(e),this.lassoFeature.init(e),this.splitFeature.init(e),this.freehandFeature.init(e),this.container=document.createElement("div"),this.container.className=`maplibregl-ctrl maplibregl-ctrl-group ${Pi}-control`,this.createToolbar(),this.setupFileInput(),this.setupKeyboardShortcuts(),this.setupSelectionHandler(),this.setupScaleHandler(),this.setupMultiDragHandler(),this.setupVertexMarkerStyleListener(),this.setupGeomanEvents(),this.options.enableAttributeEditing&&this.createAttributePanel(),this.geoman||this._autoInitGeoman(),this.container}onRemove(){this.removeKeyboardShortcuts(),this.removeSelectionHandler(),this.removeScaleHandler(),this.removeMultiDragHandler(),this.removeVertexMarkerStyleListener(),this.disableAllModes(),this.hideFeaturePropertiesPopup(),this.hideAttributePanel(),this.removeAttributePanel(),this.scaleFeature.destroy(),this.lassoFeature.destroy(),this.splitFeature.destroy(),this.freehandFeature.destroy(),this.fileInput&&this.fileInput.parentNode&&(this.fileInput.parentNode.removeChild(this.fileInput),this.fileInput=null),this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.map=void 0}setGeoman(e){this.geoman=e,this.setupGeomanEvents(),this.applySnappingState(),this.options.hideGeomanControl&&this.hideGeomanControl()}_autoInitGeoman(){Promise.resolve().then(()=>require("./maplibre-geoman.es-DcHAy9ox.cjs")).then(({Geoman:e})=>{if(this.map&&!this.geoman){const t=new e(this.map);t.addControls=async()=>{},t.removeControls=()=>{},this.setGeoman(t)}}).catch(()=>{})}hideGeomanControl(){if(this.geoman)try{this.geoman.removeControls()}catch{[".maplibregl-ctrl.geoman-controls",".gm-control",".maplibregl-ctrl-group.geoman",'[class*="geoman"]'].forEach(e=>{document.querySelectorAll(e).forEach(t=>{t.classList.contains("geo-editor-control")||(t.style.display="none")})})}}setupSelectionHandler(){this.boundClickHandler=e=>{if(!this.isSelectMode&&!this.pendingOperation||!this.geoman)return;const t=this.findFeatureByMouseEvent(e)||this.findFeatureAtPoint(e.lngLat.lng,e.lngLat.lat);if(t){const{feature:i,geomanData:n}=t;this.pendingOperation?(i.geometry.type==="Polygon"||i.geometry.type==="MultiPolygon")&&this.addToSelection(i,n):e.originalEvent.shiftKey?this.toggleFeatureSelection(i,n):this.selectFeatures([i],[n])}else!e.originalEvent.shiftKey&&!this.pendingOperation&&this.clearSelection()},this.map.on("click",this.boundClickHandler)}getClickToleranceKm(){const e=this.map.getZoom();return 40075/(512*Math.pow(2,e))*15}findFeatureAtPoint(e,t){if(!this.geoman)return null;const i=aa([e,t]);let n=null;const r=this.getClickToleranceKm();let s=[];const a=new Map;try{let l=0;this.geoman.features.forEach(h=>{const d=this.getGeomanFeature(h);if(!h||!d||!d.geometry){l++;return}const p=String(h.id??d.id??`feature-${l}`);s.push(d),a.set(p,h),a.set(`idx-${l}`,h),l++})}catch{try{s=(this.geoman.features.getAll().features||[]).filter(l=>l&&l.geometry)}catch{return null}}for(let l=0;l<s.length;l++){const h=s[l];if(!h||!h.geometry)continue;const d=String(h.id??`feature-${l}`),p=a.get(d)||a.get(`idx-${l}`);try{let g=!1;if(h.geometry.type==="Point")g=gb(i,aa(h.geometry.coordinates),{units:"kilometers"})<r;else if(h.geometry.type==="Polygon"||h.geometry.type==="MultiPolygon")g=la(i,h);else if(h.geometry.type==="LineString"||h.geometry.type==="MultiLineString"){const v=vA(h,i);g=v.properties.dist!==void 0&&v.properties.dist<r}if(g){const v=p||this.findGeomanDataForFeature(h);if(v){n={feature:h,geomanData:v};break}}}catch{}}return n}findFeatureByMouseEvent(e){if(!this.geoman||!e.originalEvent)return null;try{const t=this.geoman.features.getFeatureByMouseEvent({event:e}),i=this.getGeomanFeature(t);if(i&&t)return{feature:i,geomanData:t}}catch{}return null}findGeomanDataForFeature(e){if(!this.geoman)return null;let t=null;const i=this.getGeomanIdFromFeature(e);try{this.geoman.features.forEach(n=>{if(t)return;const r=this.getGeomanFeature(n);r&&(i&&String(r.id)===i||i&&this.getGeomanIdFromFeature(r)===i||JSON.stringify(r.geometry)===JSON.stringify(e.geometry))&&(t=n)})}catch{}return t}getGeomanIdFromFeature(e){const t=e.properties,i=e.id??t?.__gm_id??t?.id;return i!=null?String(i):null}getGeomanFeature(e){if(!e)return null;if(typeof e.getGeoJson=="function")try{return e.getGeoJson()}catch{return null}return e.geoJson??null}removeSelectionHandler(){this.boundClickHandler&&(this.map.off("click",this.boundClickHandler),this.boundClickHandler=null)}setupScaleHandler(){this.boundScaleMouseDown=e=>{if(this.state.activeEditMode!=="scale")return;const t=this.getScaleHandleFromEvent(e);!t||!this.scaleTargetFeature||!this.scaleTargetGeomanData||(e.preventDefault(),this.isScaling=!0,this.scaleStartFeature=this.scaleTargetFeature,this.disableScaleDragPan(),this.scaleFeature.startScale(this.scaleTargetFeature,t,[e.lngLat.lng,e.lngLat.lat],(i,n)=>{this.applyScaledFeature(i),this.emitEvent("gm:scale",{feature:i,scaleFactor:n})}),this.emitEvent("gm:scalestart",{feature:this.scaleTargetFeature}))},this.boundScaleMouseMove=e=>{if(!this.isScaling)return;const t=this.scaleFeature.updateScale([e.lngLat.lng,e.lngLat.lat]);t&&this.applyScaledFeature(t)},this.boundScaleMouseUp=()=>{if(!this.isScaling)return;this.isScaling=!1;const e=this.scaleFeature.endScale();this.restoreScaleDragPan(),e&&(this.applyScaledFeature(e.feature),this.scaleStartFeature&&this.options.onFeatureEdit?.(e.feature,this.scaleStartFeature),this.lastEditedFeature=e.feature,this.logSelectedFeatureCollection("edited",e.feature),this.scaleFeature.showHandlesForFeature(e.feature),this.bringScaleHandlesToFront(),this.emitEvent("gm:scaleend",{feature:e.feature,scaleFactor:e.factor})),this.scaleStartFeature=null},this.map.on("mousedown",this.boundScaleMouseDown),this.map.on("mousemove",this.boundScaleMouseMove),this.map.on("mouseup",this.boundScaleMouseUp)}removeScaleHandler(){this.boundScaleMouseDown&&(this.map.off("mousedown",this.boundScaleMouseDown),this.boundScaleMouseDown=null),this.boundScaleMouseMove&&(this.map.off("mousemove",this.boundScaleMouseMove),this.boundScaleMouseMove=null),this.boundScaleMouseUp&&(this.map.off("mouseup",this.boundScaleMouseUp),this.boundScaleMouseUp=null)}setupMultiDragHandler(){this.boundMultiDragMouseDown=e=>{if(this.state.activeEditMode!=="drag"||this.state.selectedFeatures.length<2)return;const t=this.findFeatureByMouseEvent(e)||this.findFeatureAtPoint(e.lngLat.lng,e.lngLat.lat);if(!t)return;const i=this.getGeomanIdFromFeature(t.feature);this.state.selectedFeatures.some(n=>this.getGeomanIdFromFeature(n.feature)===i)&&(e.preventDefault(),this.isMultiDragging=!0,this.multiDragStartPoint=[e.lngLat.lng,e.lngLat.lat],this.multiDragOriginalFeatures=this.state.selectedFeatures.map(n=>Go(n.feature)),this.multiDragGeomanData=this.state.selectedFeatures.map(n=>n.geomanData??this.findGeomanDataForFeature(n.feature)),this.disableMultiDragPan())},this.boundMultiDragMouseMove=e=>{if(!this.isMultiDragging||!this.multiDragStartPoint)return;const t=this.multiDragStartPoint,i=[e.lngLat.lng,e.lngLat.lat],n=gb(aa(t),aa(i),{units:"kilometers"}),r=Bj(aa(t),aa(i)),s=[];this.multiDragOriginalFeatures.forEach((a,l)=>{const h=b6(a,n,r,{units:"kilometers"}),d=this.multiDragGeomanData[l];d?.updateGeometry?d.updateGeometry(h.geometry):d?.updateGeoJsonGeometry&&d.updateGeoJsonGeometry(h.geometry),s.push(h)}),this.state.selectedFeatures=this.state.selectedFeatures.map((a,l)=>({...a,feature:s[l]??a.feature})),this.updateSelectionHighlight()},this.boundMultiDragMouseUp=()=>{this.isMultiDragging&&(this.isMultiDragging=!1,this.restoreMultiDragPan(),this.state.selectedFeatures.length>0&&(this.state.selectedFeatures.forEach((e,t)=>{const i=this.multiDragOriginalFeatures[t];i&&this.options.onFeatureEdit?.(e.feature,i)}),this.lastEditedFeature=this.state.selectedFeatures[this.state.selectedFeatures.length-1]?.feature??null,this.logSelectedFeatureCollection("edited",this.lastEditedFeature)),this.multiDragStartPoint=null,this.multiDragOriginalFeatures=[],this.multiDragGeomanData=[])},this.map.on("mousedown",this.boundMultiDragMouseDown),this.map.on("mousemove",this.boundMultiDragMouseMove),this.map.on("mouseup",this.boundMultiDragMouseUp)}removeMultiDragHandler(){this.boundMultiDragMouseDown&&(this.map.off("mousedown",this.boundMultiDragMouseDown),this.boundMultiDragMouseDown=null),this.boundMultiDragMouseMove&&(this.map.off("mousemove",this.boundMultiDragMouseMove),this.boundMultiDragMouseMove=null),this.boundMultiDragMouseUp&&(this.map.off("mouseup",this.boundMultiDragMouseUp),this.boundMultiDragMouseUp=null)}disableMultiDragPan(){this.multiDragPanEnabled=this.map.dragPan.isEnabled(),this.multiDragPanEnabled&&this.map.dragPan.disable()}restoreMultiDragPan(){this.multiDragPanEnabled&&this.map.dragPan.enable(),this.multiDragPanEnabled=null}getScaleHandleFromEvent(e){if(!this.map.getLayer(Zi.SCALE_HANDLES_LAYER))return null;const t=this.map.queryRenderedFeatures(e.point,{layers:[Zi.SCALE_HANDLES_LAYER]});if(!t.length)return null;const i=t[0].properties?.position;return typeof i=="string"?i:null}disableScaleDragPan(){this.scaleDragPanEnabled=this.map.dragPan.isEnabled(),this.scaleDragPanEnabled&&this.map.dragPan.disable()}restoreScaleDragPan(){this.scaleDragPanEnabled&&this.map.dragPan.enable(),this.scaleDragPanEnabled=null}applyScaledFeature(e){if(this.scaleTargetGeomanData?.updateGeometry?this.scaleTargetGeomanData.updateGeometry(e.geometry):this.scaleTargetGeomanData?.updateGeoJsonGeometry&&this.scaleTargetGeomanData.updateGeoJsonGeometry(e.geometry),this.state.selectedFeatures.length>0){const t=this.state.selectedFeatures[0];this.state.selectedFeatures[0]={...t,id:String(this.scaleTargetGeomanData?.id??e.id??t.id),feature:e,geomanData:this.scaleTargetGeomanData??t.geomanData},this.scaleTargetFeature=e}this.updateSelectionHighlight(),this.bringScaleHandlesToFront()}bringScaleHandlesToFront(){if(this.map.getLayer(Zi.SCALE_HANDLES_LAYER))try{this.map.moveLayer(Zi.SCALE_HANDLES_LAYER)}catch{}}logSelectedFeatureCollection(e,t){const i=t?this.getGeomanIdFromFeature(t):null;console.log("GeoEditor",{action:e,featureId:i,feature:t,selection:this.getSelectedFeatureCollection()})}extractFeatureFromEvent(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.getGeoJson=="function")try{return t.getGeoJson()}catch{return null}return t.geoJson?t.geoJson:"geometry"in t?t:null}toggleFeatureSelection(e,t){const i=t??this.findGeomanDataForFeature(e),n=String(i?.id??e.id);this.state.selectedFeatures.some(r=>r.id===n)?this.removeFromSelection(n):this.addToSelection(e,i??void 0)}enableSelectMode(){this.disableAllModes(),this.isSelectMode=!0,this.map.getCanvas().style.cursor="pointer",this.updateToolbarState()}disableSelectMode(){this.isSelectMode=!1,this.map.getCanvas().style.cursor=""}getState(){return{...this.state}}getSelectedFeatures(){return this.state.selectedFeatures.map(e=>e.feature)}getSelectedFeatureCollection(){return{type:"FeatureCollection",features:this.getSelectedFeatures()}}getFeatures(){if(this.geoman)try{return this.geoman.features.getAll()}catch{const e=[];return this.geoman.features.forEach(t=>{const i=this.getGeomanFeature(t);i&&e.push(i)}),{type:"FeatureCollection",features:e}}return{type:"FeatureCollection",features:[]}}getAllFeatureCollection(){return this.getFeatures()}getLastCreatedFeature(){return this.lastCreatedFeature}getLastEditedFeature(){return this.lastEditedFeature}getLastDeletedFeature(){return this.lastDeletedFeature}getLastDeletedFeatureId(){return this.lastDeletedFeatureId}enableDrawMode(e){this.disableAllModes(),e==="freehand"?this.enableFreehandMode():this.geoman&&(this.geoman.enableDraw(e),setTimeout(()=>this.applyVertexMarkerStyles(),50)),this.state.activeDrawMode=e,this.state.isDrawing=!0,this.options.onModeChange?.(e),this.updateToolbarState()}applyVertexMarkerStyles(){if(!this.map)return;const e=this.map.getStyle();if(!(!e||!e.layers))for(const t of e.layers){const i=t.id.toLowerCase();if(t.type==="circle"&&(i.includes("gm-")||i.includes("geoman")||i.includes("marker")||i.includes("vertex")||i.includes("handle")||i.includes("temp")))try{this.map.getLayer(t.id)&&(this.map.setPaintProperty(t.id,"circle-opacity",.5),this.map.setPaintProperty(t.id,"circle-stroke-opacity",.8))}catch{}}}setupVertexMarkerStyleListener(){this.map&&(this.boundStyleDataHandler=()=>{this.state.isDrawing&&this.applyVertexMarkerStyles()},this.map.on("styledata",this.boundStyleDataHandler))}removeVertexMarkerStyleListener(){this.map&&this.boundStyleDataHandler&&(this.map.off("styledata",this.boundStyleDataHandler),this.boundStyleDataHandler=null)}enableFreehandMode(){this.freehandFeature.enable(e=>{e.success&&e.feature&&this.geoman&&this.geoman.features.importGeoJsonFeature(e.feature)&&(this.options.onFeatureCreate?.(e.feature),this.emitEvent("gm:create",{feature:e.feature}))})}disableFreehandMode(){this.freehandFeature.disable()}enableEditMode(e){if(this.disableAllModes(),l8.includes(e))this.enableAdvancedEditMode(e);else if(this.geoman)switch(e){case"drag":this.state.selectedFeatures.length<2&&this.geoman.enableGlobalDragMode();break;case"change":this.geoman.enableGlobalEditMode();break;case"rotate":this.geoman.enableGlobalRotateMode();break;case"cut":this.geoman.enableGlobalCutMode();break;case"delete":if(this.state.selectedFeatures.length>0){this.deleteSelectedFeatures();return}this.geoman.enableGlobalRemovalMode();break}this.state.activeEditMode=e,this.state.isEditing=!0,this.options.onModeChange?.(e),this.updateToolbarState()}disableAllModes(){this.geoman&&this.geoman.disableAllModes(),this.scaleFeature.cancelScale(),this.lassoFeature.disable(),this.splitFeature.cancelSplit(),this.disableFreehandMode(),this.disableSelectMode(),this.restoreScaleDragPan(),this.restoreMultiDragPan(),this.isMultiDragging=!1,this.multiDragStartPoint=null,this.multiDragOriginalFeatures=[],this.multiDragGeomanData=[],this.isScaling=!1,this.scaleTargetFeature=null,this.scaleTargetGeomanData=null,this.scaleStartFeature=null,this.pendingOperation=null,this.map.getCanvas().style.cursor="",this.state.activeDrawMode=null,this.state.activeEditMode=null,this.state.isDrawing=!1,this.state.isEditing=!1,this.updateToolbarState(),this.applySnappingState()}enableAdvancedEditMode(e){switch(e){case"select":this.enableSelectMode();break;case"scale":this.enableScaleMode();break;case"copy":this.enableCopyMode();break;case"split":this.enableSplitMode();break;case"union":this.enableUnionMode();break;case"difference":this.enableDifferenceMode();break;case"simplify":this.executeSimplify();break;case"lasso":this.enableLassoMode();break}}enableUnionMode(){if(ME(this.getSelectedFeatures()).length>=2){this.executeUnion();return}this.pendingOperation="union",this.map.getCanvas().style.cursor="pointer"}enableDifferenceMode(){if(ME(this.getSelectedFeatures()).length>=2){this.executeDifference();return}this.pendingOperation="difference",this.map.getCanvas().style.cursor="pointer"}executePendingOperation(){this.pendingOperation&&(this.pendingOperation==="union"?this.executeUnion():this.pendingOperation==="difference"&&this.executeDifference(),this.pendingOperation=null)}cancelPendingOperation(){this.pendingOperation=null,this.clearSelection(),this.map.getCanvas().style.cursor="",this.updateToolbarState()}setupSelectionHighlight(){if(this.map)if(!this.map.getSource(Zi.SELECTION_SOURCE))this.map.addSource(Zi.SELECTION_SOURCE,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),this.map.addLayer({id:Zi.SELECTION_FILL_LAYER,type:"fill",source:Zi.SELECTION_SOURCE,filter:["match",["geometry-type"],["Polygon","MultiPolygon"],!0,!1],paint:{"fill-color":"#ffff00","fill-opacity":.3}}),this.map.addLayer({id:Zi.SELECTION_LINE_LAYER,type:"line",source:Zi.SELECTION_SOURCE,paint:{"line-color":"#ff9900","line-width":5,"line-opacity":1,"line-dasharray":[3,2]}}),this.map.addLayer({id:Zi.SELECTION_CIRCLE_LAYER,type:"circle",source:Zi.SELECTION_SOURCE,filter:["==",["geometry-type"],"Point"],paint:{"circle-radius":12,"circle-color":"#ffff00","circle-opacity":.5,"circle-stroke-color":"#ff9900","circle-stroke-width":3,"circle-stroke-opacity":1}});else try{this.map.getLayer(Zi.SELECTION_FILL_LAYER)&&(this.map.setFilter(Zi.SELECTION_FILL_LAYER,["match",["geometry-type"],["Polygon","MultiPolygon"],!0,!1]),this.map.moveLayer(Zi.SELECTION_FILL_LAYER)),this.map.getLayer(Zi.SELECTION_LINE_LAYER)&&this.map.moveLayer(Zi.SELECTION_LINE_LAYER),this.map.getLayer(Zi.SELECTION_CIRCLE_LAYER)&&this.map.moveLayer(Zi.SELECTION_CIRCLE_LAYER)}catch{}}updateSelectionHighlight(){if(!this.map)return;this.setupSelectionHighlight();const e=this.map.getSource(Zi.SELECTION_SOURCE);if(e){const t=this.getSelectedFeatures();e.setData({type:"FeatureCollection",features:t})}}selectFeatures(e,t){const i=t&&t.length?t:e.map(r=>this.findGeomanDataForFeature(r)),n=Date.now();this.state.selectedFeatures=e.map((r,s)=>({id:String(i?.[s]?.id??r.id??`${n}-${s}`),feature:r,layerId:"default",geomanData:i?.[s]??void 0})),this.updateSelectionHighlight(),this.options.onSelectionChange?.(e),this.logSelectedFeatureCollection("selected"),e.length===1&&this.isSelectMode?this.options.enableAttributeEditing?this.showAttributePanel(e[0],i?.[0]??void 0,!1):this.options.showFeatureProperties&&this.showFeaturePropertiesPopup(e[0]):(this.hideAttributePanel(),this.hideFeaturePropertiesPopup())}addToSelection(e,t){const i=t??this.findGeomanDataForFeature(e),n=String(i?.id??e.id);this.state.selectedFeatures.some(r=>r.id===n)||(this.state.selectedFeatures.push({id:n,feature:e,layerId:"default",geomanData:i??void 0}),this.updateSelectionHighlight(),this.options.onSelectionChange?.(this.getSelectedFeatures()),this.logSelectedFeatureCollection("selected"))}removeFromSelection(e){this.state.selectedFeatures=this.state.selectedFeatures.filter(t=>t.id!==e),this.updateSelectionHighlight(),this.options.onSelectionChange?.(this.getSelectedFeatures()),this.logSelectedFeatureCollection("selected")}clearSelection(){this.state.selectedFeatures=[],this.updateSelectionHighlight(),this.hideFeaturePropertiesPopup(),this.hideAttributePanel(),this.options.onSelectionChange?.([]),this.logSelectedFeatureCollection("selected")}showFeaturePropertiesPopup(e){if(!this.options.showFeatureProperties||!e.properties||Object.keys(e.properties).length===0)return;this.hideFeaturePropertiesPopup();const t=jb(e).geometry.coordinates,i=this.formatPropertiesHtml(e.properties);this.propertiesPopup=new ks.default.Popup({maxWidth:"300px",closeButton:!0,closeOnClick:!1,className:"geo-editor-properties-popup"}).setLngLat(t).setHTML(i).addTo(this.map)}hideFeaturePropertiesPopup(){this.propertiesPopup&&(this.propertiesPopup.remove(),this.propertiesPopup=null)}formatPropertiesHtml(e){const t=Object.entries(e).filter(([i])=>!i.startsWith("__"));return t.length===0?'<div class="geo-editor-popup-empty">No properties</div>':`<table class="geo-editor-popup-table"><tbody>${t.map(([i,n])=>{const r=n==null?"<em>null</em>":typeof n=="object"?this.escapeHtml(JSON.stringify(n)):this.escapeHtml(String(n));return`<tr><td class="geo-editor-popup-key">${this.escapeHtml(i)}</td><td class="geo-editor-popup-value">${r}</td></tr>`}).join("")}</tbody></table>`}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}createAttributePanel(){if(this.attributePanel)return;const e=this.options.attributePanelPosition,t=this.options.attributePanelWidth,i=this.options.attributePanelMaxHeight,n=this.options.attributePanelTop,r=this.options.attributePanelSideOffset;this.attributePanel=document.createElement("div"),this.attributePanel.className=`${Pi}-attribute-panel ${Pi}-attribute-panel--${e} ${Pi}-attribute-panel--hidden`,this.attributePanel.style.width=`${t}px`,this.attributePanel.style.maxHeight=typeof i=="number"?`${i}px`:i,this.attributePanel.style.top=`${n}px`,e==="right"?this.attributePanel.style.right=`${r}px`:this.attributePanel.style.left=`${r}px`;const s=document.createElement("div");s.className=`${Pi}-attribute-panel-header`;const a=document.createElement("h3");a.className=`${Pi}-attribute-panel-title`,a.textContent=this.options.attributePanelTitle,s.appendChild(a);const l=document.createElement("button");l.className=`${Pi}-attribute-panel-close`,l.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M1 1l12 12M13 1L1 13"/></svg>',l.title="Close",l.addEventListener("click",()=>this.hideAttributePanel()),s.appendChild(l),this.attributePanel.appendChild(s);const h=document.createElement("div");h.className=`${Pi}-attribute-panel-body`,h.setAttribute("data-panel-body","true"),this.attributePanel.appendChild(h);const d=document.createElement("div");d.className=`${Pi}-attribute-panel-footer`;const p=document.createElement("button");p.className=`${Pi}-btn ${Pi}-btn--secondary`,p.textContent="Cancel",p.addEventListener("click",()=>this.hideAttributePanel()),d.appendChild(p);const g=document.createElement("button");g.className=`${Pi}-btn ${Pi}-btn--primary`,g.textContent="Save",g.setAttribute("data-save-btn","true"),g.addEventListener("click",()=>this.saveAttributeChanges()),d.appendChild(g),this.attributePanel.appendChild(d),this.map.getContainer().appendChild(this.attributePanel)}removeAttributePanel(){this.attributePanel&&this.attributePanel.parentNode&&(this.attributePanel.parentNode.removeChild(this.attributePanel),this.attributePanel=null)}showAttributePanel(e,t,i=!1){this.attributePanel&&(this.currentEditingFeature=e,this.currentEditingGeomanData=t??null,this.isNewFeature=i,this.originalProperties=e.properties?{...e.properties}:{},this.buildAttributeForm(e),this.attributePanel.classList.remove(`${Pi}-attribute-panel--hidden`),this.attributePanelVisible=!0,this.hideFeaturePropertiesPopup())}hideAttributePanel(){this.attributePanel&&(this.attributePanel.classList.add(`${Pi}-attribute-panel--hidden`),this.attributePanelVisible=!1,this.currentEditingFeature=null,this.currentEditingGeomanData=null,this.isNewFeature=!1,this.originalProperties=null)}toggleAttributePanel(){this.attributePanelVisible?this.hideAttributePanel():this.currentEditingFeature&&this.showAttributePanel(this.currentEditingFeature,this.currentEditingGeomanData??void 0,this.isNewFeature)}getSchemaFieldsForGeometry(e){const t=this.options.attributeSchema;if(!t)return[];const i=[];return e==="Polygon"||e==="MultiPolygon"?t.polygon&&i.push(...t.polygon):e==="LineString"||e==="MultiLineString"?t.line&&i.push(...t.line):(e==="Point"||e==="MultiPoint")&&t.point&&i.push(...t.point),t.common&&i.push(...t.common),i}getExtraProperties(e){const t=e.properties||{},i=this.getSchemaFieldsForGeometry(e.geometry.type),n=new Set(i.map(s=>s.name)),r={};for(const[s,a]of Object.entries(t))!s.startsWith("__")&&!n.has(s)&&(r[s]=a);return r}buildAttributeForm(e){if(!this.attributePanel)return;const t=this.attributePanel.querySelector("[data-panel-body]");if(!t)return;t.innerHTML="";const i=e.geometry.type,n=this.getSchemaFieldsForGeometry(i),r=e.properties||{},s=this.attributePanel.querySelector(`.${Pi}-attribute-panel-header`);if(s){const h=s.querySelector(`.${Pi}-attribute-geometry-badge`);h&&h.remove();const d=document.createElement("span");d.className=`${Pi}-attribute-geometry-badge`,d.textContent=this.getGeometryDisplayName(i);const p=s.querySelector(`.${Pi}-attribute-panel-title`);p&&p.appendChild(d)}if(n.length>0)n.forEach(h=>{const d=r[h.name],p=this.createFormField(h,d);t.appendChild(p)});else{const h=document.createElement("div");h.className=`${Pi}-attribute-empty`,h.textContent="No attribute schema defined",t.appendChild(h)}const a=this.getExtraProperties(e),l=Object.keys(a);if(l.length>0){const h=document.createElement("div");h.className=`${Pi}-attribute-extra-section`;const d=document.createElement("div");d.className=`${Pi}-attribute-extra-section-title`,d.textContent="Other Properties",h.appendChild(d),l.forEach(p=>{const g=this.createReadOnlyField(p,a[p]);h.appendChild(g)}),t.appendChild(h)}}getGeometryDisplayName(e){return{Point:"Point",MultiPoint:"Multi-Point",LineString:"Line",MultiLineString:"Multi-Line",Polygon:"Polygon",MultiPolygon:"Multi-Polygon",GeometryCollection:"Collection"}[e]||e}createFormField(e,t){const i=document.createElement("div");i.className=`${Pi}-attribute-form-group`;const n=document.createElement("label");n.className=`${Pi}-attribute-label`,e.required&&n.classList.add(`${Pi}-attribute-label--required`),n.textContent=e.label||e.name,n.setAttribute("for",`attr-${e.name}`),i.appendChild(n);const r=this.createInputForFieldType(e,t);return i.appendChild(r),i}createInputForFieldType(e,t){const i=`attr-${e.name}`;switch(e.type){case"boolean":{const n=document.createElement("div");n.className=`${Pi}-attribute-checkbox-wrapper`;const r=document.createElement("input");r.type="checkbox",r.id=i,r.name=e.name,r.className=`${Pi}-attribute-checkbox`,r.checked=t===!0||t==="true",r.disabled=e.readOnly??!1,n.appendChild(r);const s=document.createElement("label");return s.className=`${Pi}-attribute-checkbox-label`,s.setAttribute("for",i),s.textContent=e.label||e.name,n.appendChild(s),n}case"select":{const n=document.createElement("select");if(n.id=i,n.name=e.name,n.className=`${Pi}-attribute-select`,n.disabled=e.readOnly??!1,!e.required){const r=document.createElement("option");r.value="",r.textContent="-- Select --",n.appendChild(r)}return e.options&&e.options.forEach(r=>{const s=document.createElement("option");s.value=String(r.value),s.textContent=r.label,String(t)===String(r.value)&&(s.selected=!0),n.appendChild(s)}),n}case"textarea":{const n=document.createElement("textarea");return n.id=i,n.name=e.name,n.className=`${Pi}-attribute-textarea`,n.value=t!=null?String(t):"",n.placeholder=e.placeholder||"",n.disabled=e.readOnly??!1,n}case"number":{const n=document.createElement("input");return n.type="number",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"",n.placeholder=e.placeholder||"",n.disabled=e.readOnly??!1,e.min!==void 0&&(n.min=String(e.min)),e.max!==void 0&&(n.max=String(e.max)),e.step!==void 0&&(n.step=String(e.step)),n}case"date":{const n=document.createElement("input");return n.type="date",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"",n.disabled=e.readOnly??!1,n}case"color":{const n=document.createElement("input");return n.type="color",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"#000000",n.disabled=e.readOnly??!1,n}default:{const n=document.createElement("input");return n.type="text",n.id=i,n.name=e.name,n.className=`${Pi}-attribute-input`,n.value=t!=null?String(t):"",n.placeholder=e.placeholder||"",n.disabled=e.readOnly??!1,n}}}createReadOnlyField(e,t){const i=document.createElement("div");i.className=`${Pi}-attribute-form-group`;const n=document.createElement("label");n.className=`${Pi}-attribute-label`,n.textContent=e,i.appendChild(n);const r=document.createElement("div");return r.className=`${Pi}-attribute-readonly`,t==null?(r.classList.add(`${Pi}-attribute-readonly-null`),r.textContent="null"):typeof t=="object"?r.textContent=JSON.stringify(t):r.textContent=String(t),i.appendChild(r),i}collectFormValues(){if(!this.attributePanel||!this.currentEditingFeature)return{};const e=this.attributePanel.querySelector("[data-panel-body]");if(!e)return{};const t={};return this.getSchemaFieldsForGeometry(this.currentEditingFeature.geometry.type).forEach(i=>{const n=e.querySelector(`[name="${i.name}"]`);if(n)if(i.type==="boolean")t[i.name]=n.checked;else if(i.type==="number"){const r=n.value.trim();t[i.name]=r!==""?parseFloat(r):null}else t[i.name]=n.value||null}),t}validateFormValues(e){if(!this.currentEditingFeature)return{valid:!0,errors:{}};const t=this.getSchemaFieldsForGeometry(this.currentEditingFeature.geometry.type),i={};return t.forEach(n=>{if(n.required){const r=e[n.name];(r==null||r==="")&&(i[n.name]=`${n.label||n.name} is required`)}}),{valid:Object.keys(i).length===0,errors:i}}showValidationErrors(e){if(!this.attributePanel)return;const t=this.attributePanel.querySelector("[data-panel-body]");t&&(t.querySelectorAll(`.${Pi}-attribute-error`).forEach(i=>i.remove()),t.querySelectorAll(`.${Pi}-attribute-input--error, .${Pi}-attribute-select--error, .${Pi}-attribute-textarea--error`).forEach(i=>{i.classList.remove(`${Pi}-attribute-input--error`),i.classList.remove(`${Pi}-attribute-select--error`),i.classList.remove(`${Pi}-attribute-textarea--error`)}),Object.entries(e).forEach(([i,n])=>{const r=t.querySelector(`[name="${i}"]`);if(r){r.classList.add(`${Pi}-attribute-input--error`);const s=document.createElement("div");s.className=`${Pi}-attribute-error`,s.textContent=n,r.parentNode?.appendChild(s)}}))}applyDefaultValues(e){const t=this.getSchemaFieldsForGeometry(e.geometry.type);t.length!==0&&(e.properties||(e.properties={}),t.forEach(i=>{i.defaultValue!==void 0&&e.properties[i.name]===void 0&&(e.properties[i.name]=i.defaultValue)}))}saveAttributeChanges(){if(!this.currentEditingFeature)return;const e=this.collectFormValues(),t=this.validateFormValues(e);if(!t.valid){this.showValidationErrors(t.errors);return}const i={...this.currentEditingFeature.properties,...e};this.currentEditingFeature.properties=i,this.currentEditingGeomanData&&this.updateFeatureProperties(this.currentEditingGeomanData,i);const n={feature:this.currentEditingFeature,previousProperties:this.originalProperties??{},newProperties:i,isNewFeature:this.isNewFeature};this.options.onAttributeChange?.(n),this.hideAttributePanel()}updateFeatureProperties(e,t){const i=e.getGeoJson?e.getGeoJson():e.geoJson;i&&(i.properties=t)}openAttributeEditor(e){if(!this.options.enableAttributeEditing){console.warn("Attribute editing is not enabled");return}const t=this.findGeomanDataForFeature(e);this.showAttributePanel(e,t??void 0,!1)}closeAttributeEditor(){this.hideAttributePanel()}setAttributeSchema(e){this.options.attributeSchema=e,this.attributePanelVisible&&this.currentEditingFeature&&this.buildAttributeForm(this.currentEditingFeature)}getAttributeSchema(){return this.options.attributeSchema}enableScaleMode(){this.scaleTargetFeature=null,this.scaleTargetGeomanData=null;const e=this.getSelectedFeatures();if(e.length===0){console.warn("Select a feature to scale");return}const t=this.findGeomanDataForFeature(e[0]);if(!t){console.warn("Selected feature is not managed by Geoman");return}this.scaleTargetFeature=e[0],this.scaleTargetGeomanData=t,this.scaleFeature.showHandlesForFeature(e[0]),this.bringScaleHandlesToFront(),this.state.selectedFeatures.length>0&&(this.state.selectedFeatures[0]={...this.state.selectedFeatures[0],id:String(t.id),geomanData:t}),this.map.getCanvas().style.cursor="nwse-resize"}enableCopyMode(){this.copySelectedFeatures()}enableSplitMode(){const e=this.getSelectedFeatures();if(e.length===0){console.warn("Select a polygon or line to split");return}const t=e[0];if(!AJ(t)&&!jue(t)){console.warn("Can only split polygons and lines");return}this.splitFeature.startSplit(t,i=>{this.handleSplitResult(i)})}enableLassoMode(){this.lassoFeature.enable(e=>{this.handleLassoResult(e)})}executeUnion(){const e=ME(this.getSelectedFeatures());if(e.length<2){console.warn("Select at least 2 polygons to merge");return}const t=this.unionFeature.union(e);this.handleUnionResult(t)}executeDifference(){const e=ME(this.getSelectedFeatures());if(e.length<2){console.warn("Select at least 2 polygons (first is base, rest are subtracted)");return}const[t,...i]=e,n=this.differenceFeature.difference(t,i);this.handleDifferenceResult(n)}executeSimplify(){let e=this.getSelectedFeatures();if(e.length===0&&this.lastCreatedFeature&&(e=[this.lastCreatedFeature]),e.length===0){console.warn("Select a feature to simplify");return}const t=e.map(n=>this.getSimplifyResult(n)).filter(n=>!!n),i=t.length>1;if(t.length===0){console.warn("Simplify: no vertices removed with current tolerance");return}t.forEach(n=>{this.applySimplifyResult(n,{clearSelection:!i,disableModes:!i}),this.logSelectedFeatureCollection("edited",n.result)}),i&&(this.clearSelection(),this.disableAllModes())}getSimplifyResult(e){const t=this.simplifyFeature.simplifyWithStats(e);if(t.verticesAfter<t.verticesBefore)return t;const i=this.simplifyFeature.getSuggestedTolerances(e);for(const n of i){if(n===this.options.simplifyTolerance)continue;const r=this.simplifyFeature.simplifyWithStats(e,{tolerance:n});if(r.verticesAfter<r.verticesBefore)return r}return null}copySelectedFeatures(){const e=this.getSelectedFeatures();if(e.length===0){console.warn("No features selected to copy");return}this.state.clipboard=this.copyFeature.copyMultiple(e),this.emitEvent("gm:copy",{features:e})}pasteFeatures(){if(this.state.clipboard.length===0){console.warn("Clipboard is empty");return}const e=this.copyFeature.copyMultiple(this.state.clipboard);this.geoman&&e.forEach(t=>{this.geoman?.features.importGeoJsonFeature(t),this.options.onFeatureCreate?.(t),this.lastCreatedFeature=t}),this.emitEvent("gm:paste",{features:e})}deleteFeatureById(e){if(this.geoman)try{const t=[];this.geoman.features.forEach(i=>{const n=this.getGeomanFeature(i),r=n?.properties;(String(i.id)===e||String(n?.id)===e||String(r?.__gm_id)===e)&&t.push(i)}),t.forEach(i=>{this.deleteGeomanFeatureData(i)})}catch{}}deleteSelectedFeatures(){const e=this.state.selectedFeatures;e.length!==0&&(e.forEach(t=>{const i=t.geomanData??this.findGeomanDataForFeature(t.feature);this.deleteGeomanFeatureData(i,t.id),this.options.onFeatureDelete?.(t.id),this.lastDeletedFeature=t.feature,this.lastDeletedFeatureId=t.id,this.logSelectedFeatureCollection("deleted",t.feature)}),this.clearSelection())}deleteGeomanFeatureData(e,t){if(this.geoman){if(e){try{this.geoman.features.delete(e);return}catch{}try{e.delete();return}catch{}}t&&this.deleteFeatureById(t)}}deleteGeomanFeatures(e){e.forEach(t=>{const i=this.findGeomanDataForFeature(t),n=this.getGeomanIdFromFeature(t);this.deleteGeomanFeatureData(i,n??void 0),n&&this.options.onFeatureDelete?.(n),this.lastDeletedFeature=t,this.lastDeletedFeatureId=n??null,this.logSelectedFeatureCollection("deleted",t)})}clearGeomanTemporaryFeatures(){if(this.geoman)try{if(typeof this.geoman.features.tmpForEach=="function"){this.geoman.features.tmpForEach(e=>{try{e.delete()}catch{}});return}this.geoman.features.forEach(e=>{if(e.temporary)try{e.delete()}catch{}})}catch{}}handleSplitResult(e){if(!e.success){console.warn("Split failed:",e.error);return}this.recordCompositeOperation([e.original],e.parts,"Split"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures([e.original]),this.clearGeomanTemporaryFeatures(),this.clearSelection(),this.geoman&&e.parts.forEach(t=>{this.geoman?.features.importGeoJsonFeature(t),this.options.onFeatureCreate?.(t),this.lastCreatedFeature=t,this.logSelectedFeatureCollection("created",t)})}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:split",e),this.disableAllModes()}handleUnionResult(e){if(!e.success||!e.result){console.warn("Union failed:",e.error);return}this.recordCompositeOperation(e.originals,[e.result],"Union"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures(e.originals),this.clearGeomanTemporaryFeatures(),this.clearSelection(),this.geoman&&(this.geoman.features.importGeoJsonFeature(e.result),this.options.onFeatureCreate?.(e.result),this.lastCreatedFeature=e.result,this.logSelectedFeatureCollection("created",e.result))}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:union",e),this.disableAllModes()}handleDifferenceResult(e){if(!e.success){console.warn("Difference failed:",e.error);return}const t=[e.base,...e.subtracted],i=e.result?[e.result]:[];this.recordCompositeOperation(t,i,"Difference"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures([e.base,...e.subtracted]),this.clearGeomanTemporaryFeatures(),this.clearSelection(),e.result&&this.geoman&&(this.geoman.features.importGeoJsonFeature(e.result),this.options.onFeatureCreate?.(e.result),this.lastCreatedFeature=e.result,this.logSelectedFeatureCollection("created",e.result))}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:difference",e),this.disableAllModes()}applySimplifyResult(e,t){this.recordCompositeOperation([e.original],[e.result],"Simplify"),this.isPerformingCompositeOperation=!0;try{this.deleteGeomanFeatures([e.original]),this.clearGeomanTemporaryFeatures(),this.geoman&&(e.result.id=this.getGeomanIdFromFeature(e.original)??e.result.id,this.geoman.features.importGeoJsonFeature(e.result),this.options.onFeatureEdit?.(e.result,e.original),this.lastEditedFeature=e.result)}finally{this.isPerformingCompositeOperation=!1}this.emitEvent("gm:simplify",e),t.clearSelection&&this.clearSelection(),t.disableModes&&this.disableAllModes()}handleLassoResult(e){const t=this.getFeatures().features,i=this.lassoFeature.selectWithinLasso(e.lasso,t);this.selectFeatures(i),this.emitEvent("gm:lassoend",{...e,selected:i}),this.disableAllModes()}createToolbar(){this.toolbar=document.createElement("div"),this.toolbar.className=`${Pi}-toolbar ${Pi}-toolbar--${this.options.toolbarOrientation}`,this.options.toolbarOrientation==="vertical"&&this.options.columns>1&&this.toolbar.classList.add(`${Pi}-toolbar--columns-${this.options.columns}`),this.state.collapsed&&this.toolbar.classList.add(`${Pi}-toolbar--collapsed`);const e=this.createCollapseButton();this.toolbar.appendChild(e);const t=document.createElement("div");if(t.className=`${Pi}-tools-wrapper`,this.options.drawModes.length>0){const s=this.createToolGroup("Draw",this.options.drawModes,"draw");t.appendChild(s)}const i=this.options.editModes.filter(s=>!l8.includes(s));if(i.length>0){const s=this.createToolGroup("Edit",i,"edit");t.appendChild(s)}const n=this.options.editModes.filter(s=>l8.includes(s));if(n.length>0){const s=this.createToolGroup("Advanced",n,"edit");t.appendChild(s)}if(this.historyManager){const s=this.createHistoryToolsGroup();t.appendChild(s)}if(this.options.helperModes.includes("snapping")){const s=this.createHelperToolsGroup();t.appendChild(s)}if(this.options.fileModes&&this.options.fileModes.length>0){const s=this.createFileToolsGroup();t.appendChild(s)}const r=this.createResetToolsGroup();t.appendChild(r),this.toolbar.appendChild(t),this.state.collapsed&&(t.style.display="none"),this.container.appendChild(this.toolbar)}createCollapseButton(){const e=document.createElement("button");e.className=`${Pi}-tool-button ${Pi}-collapse-btn`,e.title=this.state.collapsed?"Expand toolbar":"Collapse toolbar";const t='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 0 0 0-1.41l-2.34-2.34a1 1 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" fill="currentColor"/></svg>',i='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" fill="currentColor"/></svg>';return e.innerHTML=this.state.collapsed?t:i,e.addEventListener("click",()=>{this.toggleCollapse(),e.innerHTML=this.state.collapsed?t:i,e.title=this.state.collapsed?"Expand toolbar":"Collapse toolbar"}),e}toggleCollapse(){if(this.state.collapsed=!this.state.collapsed,this.toolbar){this.toolbar.classList.toggle(`${Pi}-toolbar--collapsed`,this.state.collapsed);const e=this.toolbar.querySelector(`.${Pi}-tools-wrapper`);e&&(e.style.display=this.state.collapsed?"none":"")}this._emitControlEvent(this.state.collapsed?"collapse":"expand")}isCollapsed(){return this.state.collapsed}setCollapsed(e){this.state.collapsed!==e&&this.toggleCollapse()}expand(){this.setCollapsed(!1)}collapse(){this.setCollapsed(!0)}on(e,t){this._eventHandlers.has(e)||this._eventHandlers.set(e,new Set),this._eventHandlers.get(e).add(t)}off(e,t){this._eventHandlers.get(e)?.delete(t)}_emitControlEvent(e,t){const i=this._eventHandlers.get(e);i&&i.forEach(n=>n(t))}createHelperToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const n=document.createElement("div");n.className=`${Pi}-tool-group-label`,n.textContent="Helper",e.appendChild(n)}const t=document.createElement("div");t.className=`${Pi}-tool-buttons`;const i=document.createElement("button");return i.className=`${Pi}-tool-button`,i.dataset.helper="snapping",i.title="Toggle Snapping",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M7 3h4v6H7V3zm6 0h4v6h-4V3zM7 9h4v3a3 3 0 0 0 6 0V9h4v3a7 7 0 0 1-14 0V9z" fill="currentColor"/></svg>',this.snappingEnabled&&i.classList.add(`${Pi}-tool-button--active`),i.addEventListener("click",n=>{n.stopPropagation(),this.toggleSnapping(),i.classList.toggle(`${Pi}-tool-button--active`,this.snappingEnabled)}),t.appendChild(i),e.appendChild(t),e}createResetToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const n=document.createElement("div");n.className=`${Pi}-tool-group-label`,n.textContent="Reset",e.appendChild(n)}const t=document.createElement("div");t.className=`${Pi}-tool-buttons`;const i=document.createElement("button");return i.className=`${Pi}-tool-button`,i.title="Clear selection and disable tools",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M12 5a7 7 0 1 1-6.32 4H3l3.5-3.5L10 9H7.74A5 5 0 1 0 12 7v2l3-3-3-3v2z" fill="currentColor"/></svg>',i.addEventListener("click",()=>{this.disableAllModes(),this.clearSelection(),this.updateToolbarState()}),t.appendChild(i),e.appendChild(t),e}createFileToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const i=document.createElement("div");i.className=`${Pi}-tool-group-label`,i.textContent="File",e.appendChild(i)}const t=document.createElement("div");if(t.className=`${Pi}-tool-buttons`,this.options.fileModes.includes("open")){const i=document.createElement("button");i.className=`${Pi}-tool-button`,i.dataset.file="open",i.title="Open GeoJSON file",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M20 6h-8l-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V8h16v10z" fill="currentColor"/></svg>',i.addEventListener("click",()=>this.openFileDialog()),t.appendChild(i)}if(this.options.fileModes.includes("save")){const i=document.createElement("button");i.className=`${Pi}-tool-button`,i.dataset.file="save",i.title="Save GeoJSON file",i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M17 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm2 16H5V5h11.17L19 7.83V19zm-7-7c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3zM6 6h9v4H6V6z" fill="currentColor"/></svg>',i.addEventListener("click",()=>this.saveGeoJson()),t.appendChild(i)}return e.appendChild(t),e}setupFileInput(){this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept=".geojson,.json,application/geo+json,application/json",this.fileInput.style.display="none",this.fileInput.addEventListener("change",e=>this.handleFileSelect(e)),document.body.appendChild(this.fileInput)}openFileDialog(){this.fileInput&&this.fileInput.click()}handleFileSelect(e){const t=e.target,i=t.files?.[0];if(!i)return;const n=new FileReader;n.onload=r=>{try{const s=r.target?.result,a=JSON.parse(s);this.loadGeoJson(a,i.name)}catch(s){console.error("GeoEditor: Failed to parse GeoJSON file:",s);const a={filename:i.name,message:s instanceof Error?s.message:String(s),error:s};this.emitEvent("gm:geojsonloaderror",a)}},n.readAsText(i),t.value=""}loadGeoJson(e,t="loaded.geojson"){if(!this.geoman)throw new Error("Geoman not initialized");try{this.geoman.features.deleteAll()}catch{this.geoman.features.forEach(s=>{try{s.delete()}catch{}})}this.clearSelection();let i;if(e.type==="Feature")i={type:"FeatureCollection",features:[e]};else if(e.type==="FeatureCollection")i=e;else throw new Error("Invalid GeoJSON: expected Feature or FeatureCollection");const n=this.geoman.features.importGeoJson(i),r={features:i.features,count:n.success,filename:t};return this.options.fitBoundsOnLoad&&i.features.length>0&&this.fitBoundsToFeatures(i),this.options.onGeoJsonLoad?.(r),this.emitEvent("gm:geojsonload",r),console.log(`GeoEditor: Loaded ${r.count} features from ${t}`),r}fitBoundsToFeatures(e){if(!(!e.features||e.features.length===0))try{const t=As(e);if(!this.isValidBBox(t)){console.warn("GeoEditor: Invalid bounding box for loaded features");return}const i=[[t[0],t[1]],[t[2],t[3]]];this.map.fitBounds(i,{padding:50,maxZoom:18,duration:500})}catch(t){console.warn("GeoEditor: Failed to fit bounds to features:",t)}}isValidBBox(e){return e.every(t=>isFinite(t)&&!isNaN(t))&&e[0]<=e[2]&&e[1]<=e[3]}fitToAllFeatures(){const e=this.getFeatures();if(e.features.length===0){console.warn("GeoEditor: No features to fit bounds to");return}this.fitBoundsToFeatures(e)}saveGeoJson(e){const t=this.getFeatures(),i=e||this.options.saveFilename||"features.geojson",n=new Blob([JSON.stringify(t,null,2)],{type:"application/geo+json"}),r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=i,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r);const a={featureCollection:t,count:t.features.length,filename:i};return this.options.onGeoJsonSave?.(a),this.emitEvent("gm:geojsonsave",a),console.log(`GeoEditor: Saved ${a.count} features to ${i}`),a}toggleSnapping(){this.snappingEnabled=!this.snappingEnabled,this.applySnappingState()}isSnappingEnabled(){return this.snappingEnabled}setSnapping(e){this.snappingEnabled=e,this.applySnappingState()}applySnappingState(){if(this.geoman)try{if(typeof this.geoman.enableMode=="function"){this.snappingEnabled?this.geoman.enableMode("helper","snapping"):this.geoman.disableMode("helper","snapping");return}const e=this.geoman;typeof e.setGlobalOptions=="function"?e.setGlobalOptions({snapping:this.snappingEnabled}):typeof e.enableSnapping=="function"&&this.snappingEnabled?e.enableSnapping():typeof e.disableSnapping=="function"&&!this.snappingEnabled&&e.disableSnapping()}catch{console.info("Snapping toggle: Geoman version does not support snapping.")}}createToolGroup(e,t,i){const n=document.createElement("div");if(n.className=`${Pi}-tool-group`,this.options.showLabels){const s=document.createElement("div");s.className=`${Pi}-tool-group-label`,s.textContent=e,n.appendChild(s)}const r=document.createElement("div");return r.className=`${Pi}-tool-buttons`,t.forEach(s=>{const a=this.createToolButton(s,i);r.appendChild(a)}),n.appendChild(r),n}createToolButton(e,t){const i=document.createElement("button");return i.className=`${Pi}-tool-button`,i.dataset.mode=e,i.dataset.type=t,i.title=this.getModeLabel(e),i.innerHTML=this.getModeIcon(e),i.addEventListener("click",()=>{t==="draw"?this.enableDrawMode(e):this.enableEditMode(e)}),i}updateToolbarState(){this.container.querySelectorAll(`.${Pi}-tool-button`).forEach(e=>{const t=e,i=t.dataset.mode,n=t.dataset.type;if(t.dataset.helper)return;let r=!1;n==="draw"?r=i===this.state.activeDrawMode:n==="edit"&&(i==="select"?r=this.isSelectMode:i==="union"?r=this.pendingOperation==="union":i==="difference"?r=this.pendingOperation==="difference":r=i===this.state.activeEditMode),t.classList.toggle(`${Pi}-tool-button--active`,r);const s=t.querySelector("svg");s&&s.querySelectorAll("path, polygon, rect, circle, ellipse, line, text").forEach(a=>{const l=a;l.style.fill="",l.style.stroke=""})})}getModeLabel(e){return{marker:"Marker",circle:"Circle",circle_marker:"Circle Marker",ellipse:"Ellipse",text_marker:"Text",line:"Line",rectangle:"Rectangle",polygon:"Polygon",freehand:"Freehand",select:"Select (click features)",drag:"Drag",change:"Edit",rotate:"Rotate",cut:"Cut",delete:"Delete",scale:"Scale",copy:"Copy",split:"Split",union:"Union (select 2+ polygons)",difference:"Difference (select 2+ polygons)",simplify:"Simplify",lasso:"Lasso Select"}[e]||e}getModeIcon(e){return{polygon:'<svg viewBox="0 0 24 24" width="18" height="18"><polygon points="12,2 22,8 18,22 6,22 2,8" fill="none" stroke="currentColor" stroke-width="2"/></svg>',line:'<svg viewBox="0 0 24 24" width="18" height="18"><line x1="4" y1="20" x2="20" y2="4" stroke="currentColor" stroke-width="2"/></svg>',rectangle:'<svg viewBox="0 0 24 24" width="18" height="18"><rect x="3" y="5" width="18" height="14" fill="none" stroke="currentColor" stroke-width="2"/></svg>',circle:'<svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/></svg>',marker:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z" fill="none" stroke="currentColor" stroke-width="2"/></svg>',select:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 3l6 14 2-6 6-2L4 3z" fill="currentColor"/><path d="M12.5 13.5l4.5 4.5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',drag:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z" fill="currentColor"/></svg>',change:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 0 0 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" fill="currentColor"/></svg>',rotate:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M17.65 6.35A7.958 7.958 0 0 0 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0 1 12 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" fill="currentColor"/></svg>',cut:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M9.64 7.64c.23-.5.36-1.05.36-1.64 0-2.21-1.79-4-4-4S2 3.79 2 6s1.79 4 4 4c.59 0 1.14-.13 1.64-.36L10 12l-2.36 2.36C7.14 14.13 6.59 14 6 14c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4c0-.59-.13-1.14-.36-1.64L12 14l7 7h3v-1L9.64 7.64z" fill="currentColor"/></svg>',delete:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" fill="currentColor"/></svg>',scale:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M21 15h2v2h-2v-2zm0-4h2v2h-2v-2zm2 8h-2v2c1 0 2-1 2-2zM13 3h2v2h-2V3zm8 4h2v2h-2V7zm0-4v2h2c0-1-1-2-2-2zM1 7h2v2H1V7zm16-4h2v2h-2V3zm0 16h2v2h-2v-2zM3 3C2 3 1 4 1 5h2V3zm6 0h2v2H9V3zM5 3h2v2H5V3zm-4 8v8c0 1.1.9 2 2 2h12V11H1z" fill="currentColor"/></svg>',copy:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" fill="currentColor"/></svg>',split:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M14 4l2.29 2.29-2.88 2.88 1.42 1.42 2.88-2.88L20 10V4h-6zm-4 0H4v6l2.29-2.29 4.71 4.7V20h2v-8.41l-5.29-5.3L10 4z" fill="currentColor"/></svg>',union:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 4h7v7H4V4zm9 0h7v7h-7V4zm-9 9h7v7H4v-7zm9 0h7v7h-7v-7z" fill="currentColor"/></svg>',difference:'<svg viewBox="0 0 24 24" width="18" height="18"><rect x="4" y="4" width="10" height="10" fill="none" stroke="currentColor" stroke-width="2"/><rect x="10" y="10" width="10" height="10" fill="none" stroke="currentColor" stroke-width="2"/><path d="M13 7h6v2h-6z" fill="currentColor"/></svg>',simplify:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M4 17l5-5 3 3 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M5 6h14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',lasso:'<svg viewBox="0 0 24 24" width="18" height="18"><ellipse cx="12" cy="10" rx="8" ry="6" fill="none" stroke="currentColor" stroke-width="2" stroke-dasharray="4 2"/><circle cx="12" cy="18" r="3" fill="currentColor"/></svg>',freehand:'<svg viewBox="0 0 24 24" width="18" height="18"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25z" fill="none" stroke="currentColor" stroke-width="2"/></svg>',circle_marker:'<svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="4" fill="currentColor"/></svg>',ellipse:'<svg viewBox="0 0 24 24" width="18" height="18"><ellipse cx="12" cy="12" rx="10" ry="6" fill="none" stroke="currentColor" stroke-width="2"/></svg>',text_marker:'<svg viewBox="0 0 24 24" width="18" height="18"><text x="12" y="16" text-anchor="middle" font-size="14" fill="currentColor">T</text></svg>'}[e]||`<span>${e[0].toUpperCase()}</span>`}setupKeyboardShortcuts(){this.boundKeyHandler=e=>{const t=e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLElement&&e.target.isContentEditable;if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){this.undo(),e.preventDefault();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey||e.key==="Z"&&e.shiftKey)){this.redo(),e.preventDefault();return}(e.ctrlKey||e.metaKey)&&e.key==="c"&&(this.copySelectedFeatures(),e.preventDefault()),(e.ctrlKey||e.metaKey)&&e.key==="v"&&(this.pasteFeatures(),e.preventDefault()),(e.key==="Delete"||e.key==="Backspace")&&!t&&!(e.target instanceof Element&&e.target.closest(".geo-editor-attribute-panel"))&&(this.deleteSelectedFeatures(),e.preventDefault()),e.key==="Enter"&&this.pendingOperation&&(this.executePendingOperation(),e.preventDefault()),e.key==="Escape"&&(this.pendingOperation?this.cancelPendingOperation():(this.disableAllModes(),this.clearSelection()))},document.addEventListener("keydown",this.boundKeyHandler)}removeKeyboardShortcuts(){this.boundKeyHandler&&(document.removeEventListener("keydown",this.boundKeyHandler),this.boundKeyHandler=null)}setupGeomanEvents(){this.geoman&&this.geoman.setGlobalEventsListener(e=>{const t=e.name??e.type??"",i=this.extractFeatureFromEvent(e.feature),n=e.action??"";if((t==="gm:create"||e.type==="gm:create")&&i&&(this.lastCreatedFeature=i,this.options.onFeatureCreate?.(i),this.logSelectedFeatureCollection("created",i),this.recordCreateOperation(i),this.options.enableAttributeEditing)){this.applyDefaultValues(i);const r=this.findGeomanDataForFeature(i);this.showAttributePanel(i,r??void 0,!0)}n==="feature_edit_start"&&i&&(this.pendingEditFeature=Go(i)),n==="feature_edit_end"&&i&&(this.lastEditedFeature=i,this.logSelectedFeatureCollection("edited",i),this.pendingEditFeature&&(this.recordEditOperation(this.pendingEditFeature,i),this.pendingEditFeature=null)),n==="feature_removed"&&i&&(this.lastDeletedFeature=i,this.lastDeletedFeatureId=this.getGeomanIdFromFeature(i),this.logSelectedFeatureCollection("deleted",i),this.recordDeleteOperation(i)),(t.includes("modetoggled")||e.type?.includes("modetoggled"))&&this.updateToolbarState()})}emitEvent(e,t){const i=new CustomEvent(e,{detail:t});this.map.getContainer().dispatchEvent(i)}undo(){return this.historyManager?this.historyManager.undo():!1}redo(){return this.historyManager?this.historyManager.redo():!1}canUndo(){return this.historyManager?.canUndo()??!1}canRedo(){return this.historyManager?.canRedo()??!1}clearHistory(){this.historyManager?.clear()}getHistoryState(){return this.historyManager?.getState()??null}getCommandContext(){return this.geoman?{featuresApi:this.geoman.features,onFeatureCreate:this.options.onFeatureCreate,onFeatureDelete:this.options.onFeatureDelete,onFeatureEdit:this.options.onFeatureEdit}:null}recordCreateOperation(e){if(!this.historyManager||this.historyManager.isExecutingCommand()||this.isPerformingCompositeOperation)return;const t=this.getCommandContext();if(!t)return;const i=new M$(e,t);this.historyManager.record(i)}recordEditOperation(e,t){if(!this.historyManager||this.historyManager.isExecutingCommand()||this.isPerformingCompositeOperation)return;const i=this.getCommandContext();if(!i)return;const n=new Hue(e,t,i);this.historyManager.record(n)}recordDeleteOperation(e){if(!this.historyManager||this.historyManager.isExecutingCommand()||this.isPerformingCompositeOperation)return;const t=this.getCommandContext();if(!t)return;const i=new I$(e,t);this.historyManager.record(i)}recordCompositeOperation(e,t,i){if(!this.historyManager||this.historyManager.isExecutingCommand())return;const n=this.getCommandContext();if(!n)return;const r=[];for(const a of e)r.push(new I$(a,n));for(const a of t)r.push(new M$(a,n));const s=new Que(r,i);this.historyManager.record(s)}updateHistoryButtonStates(e,t){const i=this.container.querySelector('[data-history="undo"]'),n=this.container.querySelector('[data-history="redo"]');i&&(i.disabled=!e),n&&(n.disabled=!t)}createHistoryToolsGroup(){const e=document.createElement("div");if(e.className=`${Pi}-tool-group`,this.options.showLabels){const r=document.createElement("div");r.className=`${Pi}-tool-group-label`,r.textContent="History",e.appendChild(r)}const t=document.createElement("div");t.className=`${Pi}-tool-buttons`;const i=document.createElement("button");i.className=`${Pi}-tool-button`,i.dataset.history="undo",i.title="Undo (Ctrl+Z)",i.disabled=!0,i.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M12.5 8c-2.65 0-5.05 1.04-6.93 2.75L2.5 7.69v7.81h7.81l-3.12-3.12c1.36-1.2 3.13-1.88 5.04-1.88 3.31 0 6.13 2.04 7.31 4.94l2.33-.91C20.32 10.93 16.73 8 12.5 8z" fill="currentColor"/></svg>',i.addEventListener("click",()=>this.undo()),t.appendChild(i);const n=document.createElement("button");return n.className=`${Pi}-tool-button`,n.dataset.history="redo",n.title="Redo (Ctrl+Y)",n.disabled=!0,n.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18"><path d="M18.43 10.75C16.55 9.04 14.15 8 11.5 8c-4.23 0-7.82 2.93-9.37 6.53l2.33.91c1.18-2.9 4-4.94 7.31-4.94 1.91 0 3.68.68 5.04 1.88l-3.12 3.12h7.81V7.69l-3.07 3.06z" fill="currentColor"/></svg>',n.addEventListener("click",()=>this.redo()),t.appendChild(n),e.appendChild(t),e}getPanelElement(){return this.attributePanel??null}},h8="geo-editor-features",vJ=class{type="geo-editor";_control;_changeCallbacks=[];_visible=!0;_opacity=1;_hasFeatures=!1;constructor(e){this._control=e,this._setupEventListeners()}_setupEventListeners(){}getLayerIds(){const e=this._control.getFeatures(),t=e&&e.features&&e.features.length>0;return t&&!this._hasFeatures?(this._hasFeatures=!0,this._changeCallbacks.forEach(i=>i("add",h8))):!t&&this._hasFeatures&&(this._hasFeatures=!1,this._changeCallbacks.forEach(i=>i("remove",h8))),t?[h8]:[]}getLayerState(e){const t=this._control.getFeatures();return!t||!t.features||t.features.length===0?null:{visible:this._visible,opacity:this._opacity,name:this.getName(e),isCustomLayer:!0,customLayerType:"geo-editor"}}setVisibility(e,t){this._visible=t;const i=this._control.map;if(!i)return;const n=i.getStyle();if(n?.layers)for(const r of n.layers)r.source&&typeof r.source=="string"&&r.source.startsWith("geoman")&&i.setLayoutProperty(r.id,"visibility",t?"visible":"none")}setOpacity(e,t){this._opacity=t;const i=this._control.map;if(!i)return;const n=i.getStyle();if(n?.layers)for(const r of n.layers)r.source&&typeof r.source=="string"&&r.source.startsWith("geoman")&&(r.type==="fill"?i.setPaintProperty(r.id,"fill-opacity",t*.3):r.type==="line"?i.setPaintProperty(r.id,"line-opacity",t):r.type==="circle"&&i.setPaintProperty(r.id,"circle-opacity",t))}getName(e){return"Drawn Features"}getSymbolType(e){return"fill"}removeLayer(e){const t=this._control.geoman;t?.features&&t.features.forEach(i=>{i.delete()}),this._hasFeatures=!1}onLayerChange(e){return this._changeCallbacks.push(e),()=>{const t=this._changeCallbacks.indexOf(e);t>=0&&this._changeCallbacks.splice(t,1)}}destroy(){this._changeCallbacks=[]}},Er=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),ade=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.")}),ode=class{_map;_overlay;_layers;constructor(e){this._map=e,this._layers=new Map,this._overlay=new dY.MapboxOverlay({interleaved:!1,layers:[]}),this._map.addControl(this._overlay)}addLayer(e,t){this._layers.set(e,t),this._updateOverlay()}removeLayer(e){this._layers.delete(e),this._updateOverlay()}updateLayer(e,t){this._layers.has(e)&&(this._layers.set(e,t),this._updateOverlay())}getLayers(){return Array.from(this._layers.values())}hasLayer(e){return this._layers.has(e)}clearLayers(){this._layers.clear(),this._updateOverlay()}getMap(){return this._map}destroy(){this._layers.clear();try{this._map.removeControl(this._overlay)}catch{}}_updateOverlay(){const e=Array.from(this._layers.entries()).sort(([t],[i])=>{const n=t.includes("cross-section"),r=i.includes("cross-section");return n&&!r?1:!n&&r?-1:0}).map(([,t])=>t);this._overlay.setProps({layers:e}),this._map.triggerRepaint()}},lde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0})})),cde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Hierarchy=void 0,e.Hierarchy={parse:t};function t(i){return Object.entries(i).reduce((n,[r,s])=>(s===-1?n.pages[r]={}:s&&(n.nodes[r]={pointCount:s}),n),{nodes:{},pages:{}})}})),hde=Er((e=>{var t=e&&e.__createBinding||(Object.create?(function(n,r,s,a){a===void 0&&(a=s);var l=Object.getOwnPropertyDescriptor(r,s);(!l||("get"in l?!r.__esModule:l.writable||l.configurable))&&(l={enumerable:!0,get:function(){return r[s]}}),Object.defineProperty(n,a,l)}):(function(n,r,s,a){a===void 0&&(a=s),n[a]=r[s]})),i=e&&e.__exportStar||function(n,r){for(var s in n)s!=="default"&&!Object.prototype.hasOwnProperty.call(r,s)&&t(r,n,s)};Object.defineProperty(e,"__esModule",{value:!0}),i(lde(),e),i(cde(),e)})),sz=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.hierarchyItemLength=e.infoLength=void 0,e.infoLength=160,e.hierarchyItemLength=32})),az=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.evlrHeaderLength=e.vlrHeaderLength=e.minHeaderLength=void 0,e.minHeaderLength=375,e.vlrHeaderLength=54,e.evlrHeaderLength=60})),ude=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getBigUint64=e.parseBigInt=void 0;function t(n){if(n>BigInt(Number.MAX_SAFE_INTEGER)||n<BigInt(-Number.MAX_SAFE_INTEGER))throw new Error(`Cannot convert bigint to number: ${n}`);return Number(n)}e.parseBigInt=t;function i(n,r,s){if(n.getBigUint64)return n.getBigUint64(r,s);const[a,l]=s?[4,0]:[0,4],h=BigInt(n.getUint32(r+a,s)),d=BigInt(n.getUint32(r+l,s));return(h<<BigInt(32))+d}e.getBigUint64=i})),dde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.toCString=e.toDataView=e.Binary=void 0,e.Binary={toDataView:t,toCString:i};function t(n){return new DataView(n.buffer,n.byteOffset,n.length)}e.toDataView=t;function i(n){const r=t(n);let s="";for(let a=0;a<r.byteLength;++a){const l=r.getInt8(a);if(l===0)return s;s+=String.fromCharCode(l)}return s}e.toCString=i})),fde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Bounds=void 0,e.Bounds={min:t,max:i,mid:n,width:r,depth:s,height:a,cube:l,step:h,stepTo:d,intersection:p};function t(g){return[g[0],g[1],g[2]]}function i(g){return[g[3],g[4],g[5]]}function n([g,v,y,E,S,R]){return[g+(E-g)/2,v+(S-v)/2,y+(R-y)/2]}function r(g){return g[3]-g[0]}function s(g){return g[4]-g[1]}function a(g){return g[5]-g[2]}function l(g){const v=n(g),y=Math.max(r(g),s(g),a(g))/2;return[v[0]-y,v[1]-y,v[2]-y,v[0]+y,v[1]+y,v[2]+y]}function h(g,[v,y,E]){const[S,R,I,k,D,F]=g,[Z,Y,Q]=n(g);return[v?Z:S,y?Y:R,E?Q:I,v?k:Z,y?D:Y,E?F:Q]}function d(g,[v,y,E,S]){for(let R=v-1;R>=0;--R)g=h(g,[y>>R&1,E>>R&1,S>>R&1]);return g}function p(g,v){return[Math.max(g[0],v[0]),Math.max(g[1],v[1]),Math.max(g[2],v[2]),Math.min(g[3],v[3]),Math.min(g[4],v[4]),Math.min(g[5],v[5])]}})),pde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Dimension=void 0,e.Dimension={Type:{int8:{type:"signed",size:1},int16:{type:"signed",size:2},int32:{type:"signed",size:4},int64:{type:"signed",size:8},uint8:{type:"unsigned",size:1},uint16:{type:"unsigned",size:2},uint32:{type:"unsigned",size:4},uint64:{type:"unsigned",size:8},float32:{type:"float",size:4},float64:{type:"float",size:8},float:{type:"float",size:4},double:{type:"float",size:8},bool:{type:"unsigned",size:1},boolean:{type:"unsigned",size:1}},ctype:t};function t({type:i,size:n}){switch(i){case"signed":switch(n){case 1:return"int8";case 2:return"int16";case 4:return"int32";case 8:return"int64"}case"unsigned":switch(n){case 1:return"uint8";case 2:return"uint16";case 4:return"uint32";case 8:return"uint64"}case"float":switch(n){case 4:return"float";case 8:return"double"}}throw new Error(`Invalid dimension type/size: ${i}/${n}`)}})),mde=Er(((e,t)=>{var i=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof global<"u"&&global,n=(function(){function s(){this.fetch=!1,this.DOMException=i.DOMException}return s.prototype=i,new s})();(function(s){(function(a){var l=typeof s<"u"&&s||typeof self<"u"&&self||typeof global<"u"&&global||{},h={searchParams:"URLSearchParams"in l,iterable:"Symbol"in l&&"iterator"in Symbol,blob:"FileReader"in l&&"Blob"in l&&(function(){try{return new Blob,!0}catch{return!1}})(),formData:"FormData"in l,arrayBuffer:"ArrayBuffer"in l};function d(X){return X&&DataView.prototype.isPrototypeOf(X)}if(h.arrayBuffer)var p=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],g=ArrayBuffer.isView||function(X){return X&&p.indexOf(Object.prototype.toString.call(X))>-1};function v(X){if(typeof X!="string"&&(X=String(X)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(X)||X==="")throw new TypeError('Invalid character in header field name: "'+X+'"');return X.toLowerCase()}function y(X){return typeof X!="string"&&(X=String(X)),X}function E(X){var ee={next:function(){var ae=X.shift();return{done:ae===void 0,value:ae}}};return h.iterable&&(ee[Symbol.iterator]=function(){return ee}),ee}function S(X){this.map={},X instanceof S?X.forEach(function(ee,ae){this.append(ae,ee)},this):Array.isArray(X)?X.forEach(function(ee){if(ee.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+ee.length);this.append(ee[0],ee[1])},this):X&&Object.getOwnPropertyNames(X).forEach(function(ee){this.append(ee,X[ee])},this)}S.prototype.append=function(X,ee){X=v(X),ee=y(ee);var ae=this.map[X];this.map[X]=ae?ae+", "+ee:ee},S.prototype.delete=function(X){delete this.map[v(X)]},S.prototype.get=function(X){return X=v(X),this.has(X)?this.map[X]:null},S.prototype.has=function(X){return this.map.hasOwnProperty(v(X))},S.prototype.set=function(X,ee){this.map[v(X)]=y(ee)},S.prototype.forEach=function(X,ee){for(var ae in this.map)this.map.hasOwnProperty(ae)&&X.call(ee,this.map[ae],ae,this)},S.prototype.keys=function(){var X=[];return this.forEach(function(ee,ae){X.push(ae)}),E(X)},S.prototype.values=function(){var X=[];return this.forEach(function(ee){X.push(ee)}),E(X)},S.prototype.entries=function(){var X=[];return this.forEach(function(ee,ae){X.push([ae,ee])}),E(X)},h.iterable&&(S.prototype[Symbol.iterator]=S.prototype.entries);function R(X){if(!X._noBody){if(X.bodyUsed)return Promise.reject(new TypeError("Already read"));X.bodyUsed=!0}}function I(X){return new Promise(function(ee,ae){X.onload=function(){ee(X.result)},X.onerror=function(){ae(X.error)}})}function k(X){var ee=new FileReader,ae=I(ee);return ee.readAsArrayBuffer(X),ae}function D(X){var ee=new FileReader,ae=I(ee),ce=/charset=([A-Za-z0-9_-]+)/.exec(X.type),de=ce?ce[1]:"utf-8";return ee.readAsText(X,de),ae}function F(X){for(var ee=new Uint8Array(X),ae=new Array(ee.length),ce=0;ce<ee.length;ce++)ae[ce]=String.fromCharCode(ee[ce]);return ae.join("")}function Z(X){if(X.slice)return X.slice(0);var ee=new Uint8Array(X.byteLength);return ee.set(new Uint8Array(X)),ee.buffer}function Y(){return this.bodyUsed=!1,this._initBody=function(X){this.bodyUsed=this.bodyUsed,this._bodyInit=X,X?typeof X=="string"?this._bodyText=X:h.blob&&Blob.prototype.isPrototypeOf(X)?this._bodyBlob=X:h.formData&&FormData.prototype.isPrototypeOf(X)?this._bodyFormData=X:h.searchParams&&URLSearchParams.prototype.isPrototypeOf(X)?this._bodyText=X.toString():h.arrayBuffer&&h.blob&&d(X)?(this._bodyArrayBuffer=Z(X.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):h.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(X)||g(X))?this._bodyArrayBuffer=Z(X):this._bodyText=X=Object.prototype.toString.call(X):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof X=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):h.searchParams&&URLSearchParams.prototype.isPrototypeOf(X)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},h.blob&&(this.blob=function(){var X=R(this);if(X)return X;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var X=R(this);return X||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(h.blob)return this.blob().then(k);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var X=R(this);if(X)return X;if(this._bodyBlob)return D(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(F(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},h.formData&&(this.formData=function(){return this.text().then(H)}),this.json=function(){return this.text().then(JSON.parse)},this}var Q=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function V(X){var ee=X.toUpperCase();return Q.indexOf(ee)>-1?ee:X}function U(X,ee){if(!(this instanceof U))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');ee=ee||{};var ae=ee.body;if(X instanceof U){if(X.bodyUsed)throw new TypeError("Already read");this.url=X.url,this.credentials=X.credentials,ee.headers||(this.headers=new S(X.headers)),this.method=X.method,this.mode=X.mode,this.signal=X.signal,!ae&&X._bodyInit!=null&&(ae=X._bodyInit,X.bodyUsed=!0)}else this.url=String(X);if(this.credentials=ee.credentials||this.credentials||"same-origin",(ee.headers||!this.headers)&&(this.headers=new S(ee.headers)),this.method=V(ee.method||this.method||"GET"),this.mode=ee.mode||this.mode||null,this.signal=ee.signal||this.signal||(function(){if("AbortController"in l)return new AbortController().signal})(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&ae)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(ae),(this.method==="GET"||this.method==="HEAD")&&(ee.cache==="no-store"||ee.cache==="no-cache")){var ce=/([?&])_=[^&]*/;if(ce.test(this.url))this.url=this.url.replace(ce,"$1_="+new Date().getTime());else{var de=/\?/;this.url+=(de.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}U.prototype.clone=function(){return new U(this,{body:this._bodyInit})};function H(X){var ee=new FormData;return X.trim().split("&").forEach(function(ae){if(ae){var ce=ae.split("="),de=ce.shift().replace(/\+/g," "),pe=ce.join("=").replace(/\+/g," ");ee.append(decodeURIComponent(de),decodeURIComponent(pe))}}),ee}function W(X){var ee=new S;return X.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(ae){return ae.indexOf(`
|
|
271
271
|
`)===0?ae.substr(1,ae.length):ae}).forEach(function(ae){var ce=ae.split(":"),de=ce.shift().trim();if(de){var pe=ce.join(":").trim();try{ee.append(de,pe)}catch(Ie){console.warn("Response "+Ie.message)}}}),ee}Y.call(U.prototype);function ne(X,ee){if(!(this instanceof ne))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(ee||(ee={}),this.type="default",this.status=ee.status===void 0?200:ee.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=ee.statusText===void 0?"":""+ee.statusText,this.headers=new S(ee.headers),this.url=ee.url||"",this._initBody(X)}Y.call(ne.prototype),ne.prototype.clone=function(){return new ne(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new S(this.headers),url:this.url})},ne.error=function(){var X=new ne(null,{status:200,statusText:""});return X.ok=!1,X.status=0,X.type="error",X};var te=[301,302,303,307,308];ne.redirect=function(X,ee){if(te.indexOf(ee)===-1)throw new RangeError("Invalid status code");return new ne(null,{status:ee,headers:{location:X}})},a.DOMException=l.DOMException;try{new a.DOMException}catch{a.DOMException=function(ee,ae){this.message=ee,this.name=ae;var ce=Error(ee);this.stack=ce.stack},a.DOMException.prototype=Object.create(Error.prototype),a.DOMException.prototype.constructor=a.DOMException}function oe(X,ee){return new Promise(function(ae,ce){var de=new U(X,ee);if(de.signal&&de.signal.aborted)return ce(new a.DOMException("Aborted","AbortError"));var pe=new XMLHttpRequest;function Ie(){pe.abort()}pe.onload=function(){var Se={statusText:pe.statusText,headers:W(pe.getAllResponseHeaders()||"")};de.url.indexOf("file://")===0&&(pe.status<200||pe.status>599)?Se.status=200:Se.status=pe.status,Se.url="responseURL"in pe?pe.responseURL:Se.headers.get("X-Request-URL");var Ve="response"in pe?pe.response:pe.responseText;setTimeout(function(){ae(new ne(Ve,Se))},0)},pe.onerror=function(){setTimeout(function(){ce(new TypeError("Network request failed"))},0)},pe.ontimeout=function(){setTimeout(function(){ce(new TypeError("Network request timed out"))},0)},pe.onabort=function(){setTimeout(function(){ce(new a.DOMException("Aborted","AbortError"))},0)};function we(Se){try{return Se===""&&l.location.href?l.location.href:Se}catch{return Se}}if(pe.open(de.method,we(de.url),!0),de.credentials==="include"?pe.withCredentials=!0:de.credentials==="omit"&&(pe.withCredentials=!1),"responseType"in pe&&(h.blob?pe.responseType="blob":h.arrayBuffer&&(pe.responseType="arraybuffer")),ee&&typeof ee.headers=="object"&&!(ee.headers instanceof S||l.Headers&&ee.headers instanceof l.Headers)){var Ee=[];Object.getOwnPropertyNames(ee.headers).forEach(function(Se){Ee.push(v(Se)),pe.setRequestHeader(Se,y(ee.headers[Se]))}),de.headers.forEach(function(Se,Ve){Ee.indexOf(Ve)===-1&&pe.setRequestHeader(Ve,Se)})}else de.headers.forEach(function(Se,Ve){pe.setRequestHeader(Ve,Se)});de.signal&&(de.signal.addEventListener("abort",Ie),pe.onreadystatechange=function(){pe.readyState===4&&de.signal.removeEventListener("abort",Ie)}),pe.send(typeof de._bodyInit>"u"?null:de._bodyInit)})}return oe.polyfill=!0,l.fetch||(l.fetch=oe,l.Headers=S,l.Request=U,l.Response=ne),a.Headers=S,a.Request=U,a.Response=ne,a.fetch=oe,Object.defineProperty(a,"__esModule",{value:!0}),a})({})})(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var r=i.fetch?i:n;e=r.fetch,e.default=r.fetch,e.fetch=r.fetch,e.Headers=r.Headers,e.Request=r.Request,e.Response=r.Response,t.exports=e})),gde=Er((e=>{var t=e&&e.__createBinding||(Object.create?(function(p,g,v,y){y===void 0&&(y=v);var E=Object.getOwnPropertyDescriptor(g,v);(!E||("get"in E?!g.__esModule:E.writable||E.configurable))&&(E={enumerable:!0,get:function(){return g[v]}}),Object.defineProperty(p,y,E)}):(function(p,g,v,y){y===void 0&&(y=v),p[y]=g[v]})),i=e&&e.__setModuleDefault||(Object.create?(function(p,g){Object.defineProperty(p,"default",{enumerable:!0,value:g})}):function(p,g){p.default=g}),n=e&&e.__importStar||function(p){if(p&&p.__esModule)return p;var g={};if(p!=null)for(var v in p)v!=="default"&&Object.prototype.hasOwnProperty.call(p,v)&&t(g,p,v);return i(g,p),g},r=e&&e.__importDefault||function(p){return p&&p.__esModule?p:{default:p}};Object.defineProperty(e,"__esModule",{value:!0}),e.Getter=void 0;var s=r(mde());e.Getter={create:a,http:l,file:h};function a(p){return typeof p=="function"?p:p.startsWith("http://")||p.startsWith("https://")?l(p):h(p)}function l(p){return async function(v,y){if(v<0||y<0||v>y)throw new Error("Invalid range");const E=await(await(0,s.default)(p,{headers:{Range:`bytes=${v}-${y-1}`}})).arrayBuffer();return new Uint8Array(E)}}function h(p){return async function(v,y){const E=await Promise.resolve().then(()=>n({}));async function S(R=0,I=1/0){if(R<0||I<0||R>I)throw new Error("Invalid range");return await E.promises.access(p),d(E.createReadStream(p,{start:R,end:I-1,autoClose:!0}))}return S(v,y)}}async function d(p){return await new Promise((g,v)=>{const y=[];p.on("data",E=>y.push(E)),p.on("error",v),p.on("end",()=>g(Buffer.concat(y)))})}})),_de=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Key=void 0,e.Key={create:t,parse:i,toString:n,step:r,up:s,compare:a,depth:l};function t(h,d=0,p=0,g=0){return typeof h!="number"?i(h):[h,d,p,g]}function i(h){if(typeof h!="string")return h;const[d,p,g,v,...y]=h.split("-").map(S=>parseInt(S,10)),E=[d,p,g,v];if(y.length!==0||E.some(S=>typeof S!="number"||Number.isNaN(S)))throw new Error(`Invalid key: ${h}`);return E}function n(h){return typeof h=="string"?h:h.join("-")}function r(h,[d,p,g]){const[v,y,E,S]=e.Key.create(h);return[v+1,y*2+d,E*2+p,S*2+g]}function s(h,d=1){const[p,g,v,y]=e.Key.create(h);return[p-d,g>>d,v>>d,y>>d]}function a(h,d){for(let p=0;p<h.length;++p){if(h[p]<d[p])return-1;if(h[p]>d[p])return 1}return 0}function l(h){return h[0]}})),Ade=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Scale=void 0,e.Scale={apply:(t,i=1,n=0)=>(t-n)/i,unapply:(t,i=1,n=0)=>t*i+n}})),vde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Step=void 0,e.Step={fromIndex:t,list:i};function t(n){if(n<0||n>=8)throw new Error(`Invalid step index: ${n}`);return[n>>0&1?1:0,n>>1&1?1:0,n>>2&1?1:0]}function i(){return[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]}})),su=Er((e=>{var t=e&&e.__createBinding||(Object.create?(function(p,g,v,y){y===void 0&&(y=v);var E=Object.getOwnPropertyDescriptor(g,v);(!E||("get"in E?!g.__esModule:E.writable||E.configurable))&&(E={enumerable:!0,get:function(){return g[v]}}),Object.defineProperty(p,y,E)}):(function(p,g,v,y){y===void 0&&(y=v),p[y]=g[v]})),i=e&&e.__exportStar||function(p,g){for(var v in p)v!=="default"&&!Object.prototype.hasOwnProperty.call(g,v)&&t(g,p,v)};Object.defineProperty(e,"__esModule",{value:!0}),e.Step=e.Scale=e.Key=e.Getter=e.Dimension=e.Bounds=e.Binary=void 0,i(ude(),e);var n=dde();Object.defineProperty(e,"Binary",{enumerable:!0,get:function(){return n.Binary}});var r=fde();Object.defineProperty(e,"Bounds",{enumerable:!0,get:function(){return r.Bounds}});var s=pde();Object.defineProperty(e,"Dimension",{enumerable:!0,get:function(){return s.Dimension}});var a=gde();Object.defineProperty(e,"Getter",{enumerable:!0,get:function(){return a.Getter}});var l=_de();Object.defineProperty(e,"Key",{enumerable:!0,get:function(){return l.Key}});var h=Ade();Object.defineProperty(e,"Scale",{enumerable:!0,get:function(){return h.Scale}});var d=vde();Object.defineProperty(e,"Step",{enumerable:!0,get:function(){return d.Step}})})),yJ=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ExtraBytes=void 0;var t=su();e.ExtraBytes={getDimension:n,parse:r,parseOne:s};var i=192;function n({type:h,length:d}){switch(h){case"signed":case"unsigned":switch(d){case 1:case 2:case 4:case 8:return{type:h,size:d}}case"float":switch(d){case 4:case 8:return{type:h,size:d}}}}function r(h){if(h.byteLength%i!==0)throw new Error(`Invalid extra bytes VLR length: ${h.byteLength}`);const d=[];for(let p=0;p<h.byteLength;p+=i)d.push(s(h.slice(p,p+i)));return d}function s(h){if(h.byteLength!==i)throw new Error(`Invalid extra bytes entry length: ${h.byteLength}`);const d=t.Binary.toDataView(h),p=t.Binary.toCString(h.slice(4,36)),g=t.Binary.toCString(h.slice(60,192)),v=d.getUint8(2),y=d.getUint8(3);if(v>=11)throw new Error(`Invalid extra bytes "type" value: ${v}`);if(v===0)return{name:p,description:g,length:y};const E=l(y),S=a(v);if(!S)throw new Error(`Failed to extract dimension type: ${v}`);const{type:R,size:I}=S;function k(F){switch(R){case"signed":return(0,t.parseBigInt)(d.getBigInt64(F,!0));case"unsigned":return(0,t.parseBigInt)((0,t.getBigUint64)(d,F,!0));case"float":return d.getFloat64(F,!0)}}const D={name:p,description:g,type:R,length:I};return E.hasNodata&&(D.nodata=k(40)),E.hasMin&&(D.min=k(64)),E.hasMax&&(D.max=k(88)),E.hasScale&&(D.scale=d.getFloat64(112)),E.hasOffset&&(D.offset=d.getFloat64(136)),D}function a(h){switch(h){case 1:return t.Dimension.Type.uint8;case 2:return t.Dimension.Type.int8;case 3:return t.Dimension.Type.uint16;case 4:return t.Dimension.Type.int16;case 5:return t.Dimension.Type.uint32;case 6:return t.Dimension.Type.int32;case 7:return t.Dimension.Type.uint64;case 8:return t.Dimension.Type.int64;case 9:return t.Dimension.Type.float32;case 10:return t.Dimension.Type.float64}}function l(h){return{hasNodata:!!(h&1),hasMin:!!(h>>1&1),hasMax:!!(h>>2&1),hasScale:!!(h>>3&1),hasOffset:!!(h>>4&1)}}})),bJ=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Dimensions=void 0;var t=su(),i=yJ();e.Dimensions={create:s};var{Type:n}=t.Dimension,r={X:n.float64,Y:n.float64,Z:n.float64,Intensity:n.uint16,ReturnNumber:n.uint8,NumberOfReturns:n.uint8,ScanDirectionFlag:n.boolean,EdgeOfFlightLine:n.boolean,Classification:n.uint8,Synthetic:n.boolean,KeyPoint:n.boolean,Withheld:n.boolean,Overlap:n.boolean,ScanAngle:n.float32,UserData:n.uint8,PointSourceId:n.uint16,GpsTime:n.float64,Red:n.uint16,Green:n.uint16,Blue:n.uint16,ScannerChannel:n.uint8,Infrared:n.uint16};function s(a,l=[]){return Object.keys(a).reduce((h,d)=>{const p=r[d];if(p)return{...h,[d]:p};const g=l.find(y=>y.name===d),v=g&&i.ExtraBytes.getDimension(g);if(v)return{...h,[d]:v};throw new Error(`Failed to look up LAS type: ${d}`)},{})}})),xJ=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Extractor=void 0;var t=su();e.Extractor={create:s};function i(E){switch(E){case 0:return 20;case 1:return 28;case 2:return 26;case 3:return 34;case 6:return 30;case 7:return 36;case 8:return 38;default:throw new Error(`Unsupported point data record format: ${E}`)}}function n(E,S,{type:R,length:I}){const k=y(E);switch(R){case"signed":switch(I){case 1:return(D,F)=>D.getInt8(k(F)+S);case 2:return(D,F)=>D.getInt16(k(F)+S,!0);case 4:return(D,F)=>D.getInt32(k(F)+S,!0);case 8:return(D,F)=>(0,t.parseBigInt)(D.getBigInt64(k(F)+S,!0))}case"unsigned":switch(I){case 1:return(D,F)=>D.getUint8(k(F)+S);case 2:return(D,F)=>D.getUint16(k(F)+S,!0);case 4:return(D,F)=>D.getUint32(k(F)+S,!0);case 8:return(D,F)=>(0,t.parseBigInt)((0,t.getBigUint64)(D,k(F)+S,!0))}case"float":switch(I){case 4:return(D,F)=>D.getFloat32(k(F)+S,!0);case 8:return(D,F)=>D.getFloat64(k(F)+S,!0)}}}function r(E,S){let R=i(E.pointDataRecordFormat);return S.reduce((I,k)=>{const D=R;R+=k.length;const F=n(E,D,k);if(!F)return I;const Z=(Y,Q)=>t.Scale.unapply(F(Y,Q),k.scale,k.offset);return{...I,[k.name]:Z}},{})}function s(E,S=[]){const R=r(E,S);return{...(()=>{const{pointDataRecordFormat:I}=E;switch(I){case 0:return a(E);case 1:return l(E);case 2:return h(E);case 3:return d(E);case 6:return p(E);case 7:return g(E);case 8:return v(E);default:throw new Error(`Unsupported point data record format: ${I}`)}})(),...R}}function a(E){const{scale:S,offset:R}=E,I=y(E);function k(Z,Y){return Z.getUint8(I(Y)+14)}function D(Z,Y){return Z.getUint8(I(Y)+15)}function F(Z,Y){return D(Z,Y)&31}return{X:(Z,Y)=>t.Scale.unapply(Z.getInt32(I(Y),!0),S[0],R[0]),Y:(Z,Y)=>t.Scale.unapply(Z.getInt32(I(Y)+4,!0),S[1],R[1]),Z:(Z,Y)=>t.Scale.unapply(Z.getInt32(I(Y)+8,!0),S[2],R[2]),Intensity:(Z,Y)=>Z.getUint16(I(Y)+12,!0),ReturnNumber:(Z,Y)=>k(Z,Y)&7,NumberOfReturns:(Z,Y)=>(k(Z,Y)&56)>>3,ScanDirectionFlag:(Z,Y)=>(k(Z,Y)&64)>>6,EdgeOfFlightLine:(Z,Y)=>(k(Z,Y)&128)>>7,Classification:(Z,Y)=>{const Q=F(Z,Y);return Q===12?0:Q},Synthetic:(Z,Y)=>(D(Z,Y)&32)>>5,KeyPoint:(Z,Y)=>(D(Z,Y)&64)>>6,Withheld:(Z,Y)=>(D(Z,Y)&128)>>7,Overlap:(Z,Y)=>F(Z,Y)===12?1:0,ScanAngle:(Z,Y)=>Z.getInt8(I(Y)+16),UserData:(Z,Y)=>Z.getUint8(I(Y)+17),PointSourceId:(Z,Y)=>Z.getUint16(I(Y)+18,!0)}}function l(E){const S=y(E);return{...a(E),GpsTime:(R,I)=>R.getFloat64(S(I)+20,!0)}}function h(E){const S=y(E);return{...a(E),Red:(R,I)=>R.getUint16(S(I)+20,!0),Green:(R,I)=>R.getUint16(S(I)+22,!0),Blue:(R,I)=>R.getUint16(S(I)+24,!0)}}function d(E){const S=y(E);return{...a(E),GpsTime:(R,I)=>R.getFloat64(S(I)+20,!0),Red:(R,I)=>R.getUint16(S(I)+28,!0),Green:(R,I)=>R.getUint16(S(I)+30,!0),Blue:(R,I)=>R.getUint16(S(I)+32,!0)}}function p(E){const{scale:S,offset:R}=E,I=y(E);function k(D,F){return D.getUint8(I(F)+15)}return{X:(D,F)=>t.Scale.unapply(D.getInt32(I(F),!0),S[0],R[0]),Y:(D,F)=>t.Scale.unapply(D.getInt32(I(F)+4,!0),S[1],R[1]),Z:(D,F)=>t.Scale.unapply(D.getInt32(I(F)+8,!0),S[2],R[2]),Intensity:(D,F)=>D.getUint16(I(F)+12,!0),ReturnNumber:(D,F)=>D.getUint16(I(F)+14,!0)&15,NumberOfReturns:(D,F)=>(D.getUint16(I(F)+14,!0)&240)>>4,Synthetic:(D,F)=>k(D,F)&1,KeyPoint:(D,F)=>(k(D,F)&2)>>1,Withheld:(D,F)=>(k(D,F)&4)>>2,Overlap:(D,F)=>(k(D,F)&8)>>3,ScannerChannel:(D,F)=>(k(D,F)&48)>>4,ScanDirectionFlag:(D,F)=>(k(D,F)&64)>>6,EdgeOfFlightLine:(D,F)=>(k(D,F)&128)>>7,Classification:(D,F)=>D.getUint8(I(F)+16),UserData:(D,F)=>D.getUint8(I(F)+17),ScanAngle:(D,F)=>D.getInt16(I(F)+18,!0)*.006,PointSourceId:(D,F)=>D.getUint16(I(F)+20,!0),GpsTime:(D,F)=>D.getFloat64(I(F)+22,!0)}}function g(E){const S=y(E);return{...p(E),Red:(R,I)=>R.getUint16(S(I)+30,!0),Green:(R,I)=>R.getUint16(S(I)+32,!0),Blue:(R,I)=>R.getUint16(S(I)+34,!0)}}function v(E){const S=y(E);return{...g(E),Infrared:(R,I)=>R.getUint16(S(I)+36,!0)}}function y(E){const{pointDataRecordLength:S}=E;return function(I){return I*S}}})),yde=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatGuid=e.parsePoint=void 0;var t=su();function i(r){const s=t.Binary.toDataView(r);if(s.byteLength!==24)throw new Error(`Invalid tuple buffer length: ${s.byteLength}`);return[s.getFloat64(0,!0),s.getFloat64(8,!0),s.getFloat64(16,!0)]}e.parsePoint=i;function n(r){const s=t.Binary.toDataView(r);if(s.byteLength!==16)throw new Error(`Invalid GUID buffer length: ${s.byteLength}`);let a="";for(let l=0;l<s.byteLength;l+=4){const h=s.getUint32(l,!0);a+=h.toString(16).padStart(8,"0")}return[a.slice(0,8),a.slice(8,12),a.slice(12,16),a.slice(16,32)].join("-")}e.formatGuid=n})),wJ=Er((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Header=void 0;var t=su(),i=az(),n=yde();e.Header={parse:r};function r(l){if(l.byteLength<i.minHeaderLength)throw new Error(`Invalid header: must be at least ${i.minHeaderLength} bytes`);const h=t.Binary.toDataView(l),d=t.Binary.toCString(l.slice(0,4));if(d!=="LASF")throw new Error(`Invalid file signature: ${d}`);const p=h.getUint8(24),g=h.getUint8(25);if(p!==1||g!==2&&g!==4)throw new Error(`Invalid version (only 1.2 and 1.4 supported): ${p}.${g}`);const v={fileSignature:d,fileSourceId:h.getUint16(4,!0),globalEncoding:h.getUint16(6,!0),projectId:(0,n.formatGuid)(l.slice(8,24)),majorVersion:p,minorVersion:g,systemIdentifier:t.Binary.toCString(l.slice(26,58)),generatingSoftware:t.Binary.toCString(l.slice(58,90)),fileCreationDayOfYear:h.getUint16(90,!0),fileCreationYear:h.getUint16(92,!0),headerLength:h.getUint16(94,!0),pointDataOffset:h.getUint32(96,!0),vlrCount:h.getUint32(100,!0),pointDataRecordFormat:h.getUint8(104)&15,pointDataRecordLength:h.getUint16(105,!0),pointCount:h.getUint32(107,!0),pointCountByReturn:a(l.slice(111,131)),scale:(0,n.parsePoint)(l.slice(131,155)),offset:(0,n.parsePoint)(l.slice(155,179)),min:[h.getFloat64(187,!0),h.getFloat64(203,!0),h.getFloat64(219,!0)],max:[h.getFloat64(179,!0),h.getFloat64(195,!0),h.getFloat64(211,!0)],waveformDataOffset:0,evlrOffset:0,evlrCount:0};return g==2?v:{...v,pointCount:(0,t.parseBigInt)((0,t.getBigUint64)(h,247,!0)),pointCountByReturn:s(l.slice(255,375)),waveformDataOffset:(0,t.parseBigInt)((0,t.getBigUint64)(h,227,!0)),evlrOffset:(0,t.parseBigInt)((0,t.getBigUint64)(h,235,!0)),evlrCount:h.getUint32(243,!0)}}function s(l){const h=t.Binary.toDataView(l),d=[];for(let p=0;p<120;p+=8)d.push((0,t.getBigUint64)(h,p,!0));return d.map(p=>(0,t.parseBigInt)(p))}function a(l){const h=t.Binary.toDataView(l),d=[];for(let p=0;p<20;p+=4)d.push(h.getUint32(p,!0));return d}})),bde=Er(((e,t)=>{var i=(()=>{var n=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return(function(r){r=r||{};var s=typeof r<"u"?r:{},a,l;s.ready=new Promise(function(ue,$){a=ue,l=$}),["_main","___getTypeName","__embind_initialize_bindings","_fflush","onRuntimeInitialized"].forEach(ue=>{Object.getOwnPropertyDescriptor(s.ready,ue)||Object.defineProperty(s.ready,ue,{get:()=>et("You are getting "+ue+" on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js"),set:()=>et("You are setting "+ue+" on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js")})});var h=Object.assign({},s),d=[],p="./this.program",g=!0,v=!1,y=!1,E=!1;if(s.ENVIRONMENT)throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)");var S="";function R(ue){return s.locateFile?s.locateFile(ue,S):S+ue}var I;if(E){if(typeof process=="object"&&typeof ade=="function"||typeof window=="object"||typeof importScripts=="function")throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");I=function($){let Ue;return typeof readbuffer=="function"?new Uint8Array(readbuffer($)):(Ue=read($,"binary"),ne(typeof Ue=="object"),Ue)},typeof scriptArgs<"u"?d=scriptArgs:typeof arguments<"u"&&(d=arguments),typeof print<"u"&&(typeof console>"u"&&(console={}),console.log=print,console.warn=console.error=typeof printErr<"u"?printErr:print)}else if(g||v){if(v?S=self.location.href:typeof document<"u"&&document.currentScript&&(S=document.currentScript.src),n&&(S=n),S.indexOf("blob:")!==0?S=S.substr(0,S.replace(/[?#].*/,"").lastIndexOf("/")+1):S="",!(typeof window=="object"||typeof importScripts=="function"))throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");v&&(I=ue=>{var $=new XMLHttpRequest;return $.open("GET",ue,!1),$.responseType="arraybuffer",$.send(null),new Uint8Array($.response)})}else throw new Error("environment detection error");var k=s.print||console.log.bind(console),D=s.printErr||console.warn.bind(console);Object.assign(s,h),h=null,Cn(),s.arguments&&(d=s.arguments),F("arguments","arguments_"),s.thisProgram&&(p=s.thisProgram),F("thisProgram","thisProgram"),s.quit&&s.quit,F("quit","quit_"),ne(typeof s.memoryInitializerPrefixURL>"u","Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead"),ne(typeof s.pthreadMainPrefixURL>"u","Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead"),ne(typeof s.cdInitializerPrefixURL>"u","Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead"),ne(typeof s.filePackagePrefixURL>"u","Module.filePackagePrefixURL option was removed, use Module.locateFile instead"),ne(typeof s.read>"u","Module.read option was removed (modify read_ in JS)"),ne(typeof s.readAsync>"u","Module.readAsync option was removed (modify readAsync in JS)"),ne(typeof s.readBinary>"u","Module.readBinary option was removed (modify readBinary in JS)"),ne(typeof s.setWindowTitle>"u","Module.setWindowTitle option was removed (modify setWindowTitle in JS)"),ne(typeof s.TOTAL_MEMORY>"u","Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY"),F("read","read_"),F("readAsync","readAsync"),F("readBinary","readBinary"),F("setWindowTitle","setWindowTitle"),ne(!v,"worker environment detected but not enabled at build time. Add 'worker' to `-sENVIRONMENT` to enable."),ne(!y,"node environment detected but not enabled at build time. Add 'node' to `-sENVIRONMENT` to enable."),ne(!E,"shell environment detected but not enabled at build time. Add 'shell' to `-sENVIRONMENT` to enable.");function F(ue,$){Object.getOwnPropertyDescriptor(s,ue)||Object.defineProperty(s,ue,{configurable:!0,get:function(){et("Module."+ue+" has been replaced with plain "+$+" (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)")}})}function Z(ue){Object.getOwnPropertyDescriptor(s,ue)&&et("`Module."+ue+"` was supplied but `"+ue+"` not included in INCOMING_MODULE_JS_API")}function Y(ue){return ue==="FS_createPath"||ue==="FS_createDataFile"||ue==="FS_createPreloadedFile"||ue==="FS_unlink"||ue==="addRunDependency"||ue==="FS_createLazyFile"||ue==="FS_createDevice"||ue==="removeRunDependency"}function Q(ue){typeof globalThis<"u"&&!Object.getOwnPropertyDescriptor(globalThis,ue)&&Object.defineProperty(globalThis,ue,{configurable:!0,get:function(){var $="`"+ue+"` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line";Y(ue)&&($+=". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"),oi($)}})}function V(ue){Object.getOwnPropertyDescriptor(s,ue)||Object.defineProperty(s,ue,{configurable:!0,get:function(){var $="'"+ue+"' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";Y(ue)&&($+=". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"),et($)}})}var U;s.wasmBinary&&(U=s.wasmBinary),F("wasmBinary","wasmBinary"),s.noExitRuntime,F("noExitRuntime","noExitRuntime"),typeof WebAssembly!="object"&&et("no native wasm support detected");var H,W=!1;function ne(ue,$){ue||et("Assertion failed"+($?": "+$:""))}var te=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function oe(ue,$,Ue){for(var tt=$+Ue,wt=$;ue[wt]&&!(wt>=tt);)++wt;if(wt-$>16&&ue.buffer&&te)return te.decode(ue.subarray($,wt));for(var Nt="";$<wt;){var se=ue[$++];if(!(se&128)){Nt+=String.fromCharCode(se);continue}var Dt=ue[$++]&63;if((se&224)==192){Nt+=String.fromCharCode((se&31)<<6|Dt);continue}var jt=ue[$++]&63;if((se&240)==224?se=(se&15)<<12|Dt<<6|jt:((se&248)!=240&&oi("Invalid UTF-8 leading byte 0x"+se.toString(16)+" encountered when deserializing a UTF-8 string in wasm memory to a JS string!"),se=(se&7)<<18|Dt<<12|jt<<6|ue[$++]&63),se<65536)Nt+=String.fromCharCode(se);else{var Ct=se-65536;Nt+=String.fromCharCode(55296|Ct>>10,56320|Ct&1023)}}return Nt}function X(ue,$){return ue?oe(Ie,ue,$):""}function ee(ue,$,Ue,tt){if(!(tt>0))return 0;for(var wt=Ue,Nt=Ue+tt-1,se=0;se<ue.length;++se){var Dt=ue.charCodeAt(se);if(Dt>=55296&&Dt<=57343){var jt=ue.charCodeAt(++se);Dt=65536+((Dt&1023)<<10)|jt&1023}if(Dt<=127){if(Ue>=Nt)break;$[Ue++]=Dt}else if(Dt<=2047){if(Ue+1>=Nt)break;$[Ue++]=192|Dt>>6,$[Ue++]=128|Dt&63}else if(Dt<=65535){if(Ue+2>=Nt)break;$[Ue++]=224|Dt>>12,$[Ue++]=128|Dt>>6&63,$[Ue++]=128|Dt&63}else{if(Ue+3>=Nt)break;Dt>1114111&&oi("Invalid Unicode code point 0x"+Dt.toString(16)+" encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF)."),$[Ue++]=240|Dt>>18,$[Ue++]=128|Dt>>12&63,$[Ue++]=128|Dt>>6&63,$[Ue++]=128|Dt&63}}return $[Ue]=0,Ue-wt}function ae(ue,$,Ue){return ne(typeof Ue=="number","stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!"),ee(ue,Ie,$,Ue)}function ce(ue){for(var $=0,Ue=0;Ue<ue.length;++Ue){var tt=ue.charCodeAt(Ue);tt<=127?$++:tt<=2047?$+=2:tt>=55296&&tt<=57343?($+=4,++Ue):$+=3}return $}var de,pe,Ie,we,Ee,Se,Ve,ze,it;function Le(ue){de=ue,s.HEAP8=pe=new Int8Array(ue),s.HEAP16=we=new Int16Array(ue),s.HEAP32=Se=new Int32Array(ue),s.HEAPU8=Ie=new Uint8Array(ue),s.HEAPU16=Ee=new Uint16Array(ue),s.HEAPU32=Ve=new Uint32Array(ue),s.HEAPF32=ze=new Float32Array(ue),s.HEAPF64=it=new Float64Array(ue)}var nt=65536;s.TOTAL_STACK&&ne(nt===s.TOTAL_STACK,"the stack size can no longer be determined at runtime");var lt=s.INITIAL_MEMORY||262144;F("INITIAL_MEMORY","INITIAL_MEMORY"),ne(lt>=nt,"INITIAL_MEMORY should be larger than TOTAL_STACK, was "+lt+"! (TOTAL_STACK="+nt+")"),ne(typeof Int32Array<"u"&&typeof Float64Array<"u"&&Int32Array.prototype.subarray!=null&&Int32Array.prototype.set!=null,"JS engine does not provide full typed array support"),ne(!s.wasmMemory,"Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally"),ne(lt==262144,"Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically");var Ae;function vt(){var ue=kt();ne((ue&3)==0),Ve[ue>>2]=34821223,Ve[ue+4>>2]=2310721022,Ve[0]=1668509029}function Ne(){if(!W){var ue=kt(),$=Ve[ue>>2],Ue=Ve[ue+4>>2];($!=34821223||Ue!=2310721022)&&et("Stack overflow! Stack cookie has been overwritten at 0x"+ue.toString(16)+", expected hex dwords 0x89BACDFE and 0x2135467, but received 0x"+Ue.toString(16)+" 0x"+$.toString(16)),Ve[0]!==1668509029&&et("Runtime error: The application has corrupted its heap memory area (address zero)!")}}(function(){var ue=new Int16Array(1),$=new Int8Array(ue.buffer);if(ue[0]=25459,$[0]!==115||$[1]!==99)throw"Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)"})();var $t=[],It=[],di=[],Ge=!1;function be(){if(s.preRun)for(typeof s.preRun=="function"&&(s.preRun=[s.preRun]);s.preRun.length;)ti(s.preRun.shift());ei($t)}function rt(){ne(!Ge),Ge=!0,Ne(),ei(It)}function Tt(){if(Ne(),s.postRun)for(typeof s.postRun=="function"&&(s.postRun=[s.postRun]);s.postRun.length;)Pe(s.postRun.shift());ei(di)}function ti(ue){$t.unshift(ue)}function mi(ue){It.unshift(ue)}function Pe(ue){di.unshift(ue)}ne(Math.imul,"This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),ne(Math.fround,"This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),ne(Math.clz32,"This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"),ne(Math.trunc,"This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill");var ve=0,je=null,ht=null,De={};function st(ue){ve++,s.monitorRunDependencies&&s.monitorRunDependencies(ve),ue?(ne(!De[ue]),De[ue]=1,je===null&&typeof setInterval<"u"&&(je=setInterval(function(){if(W){clearInterval(je),je=null;return}var $=!1;for(var Ue in De)$||($=!0,D("still waiting on run dependencies:")),D("dependency: "+Ue);$&&D("(end of list)")},1e4))):D("warning: run dependency added without ID")}function ct(ue){if(ve--,s.monitorRunDependencies&&s.monitorRunDependencies(ve),ue?(ne(De[ue]),delete De[ue]):D("warning: run dependency removed without ID"),ve==0&&(je!==null&&(clearInterval(je),je=null),ht)){var $=ht;ht=null,$()}}function et(ue){s.onAbort&&s.onAbort(ue),ue="Aborted("+ue+")",D(ue),W=!0;var $=new WebAssembly.RuntimeError(ue);throw l($),$}var Mt={error:function(){et("Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM")},init:function(){Mt.error()},createDataFile:function(){Mt.error()},createPreloadedFile:function(){Mt.error()},createLazyFile:function(){Mt.error()},open:function(){Mt.error()},mkdev:function(){Mt.error()},registerDevice:function(){Mt.error()},analyzePath:function(){Mt.error()},loadFilesFromDB:function(){Mt.error()},ErrnoError:function(){Mt.error()}};s.FS_createDataFile=Mt.createDataFile,s.FS_createPreloadedFile=Mt.createPreloadedFile;var ii="data:application/octet-stream;base64,";function Jt(ue){return ue.startsWith(ii)}function Pt(ue){return ue.startsWith("file://")}function Ci(ue,$){return function(){var Ue=ue,tt=$;return $||(tt=s.asm),ne(Ge,"native function `"+Ue+"` called before runtime initialization"),tt[ue]||ne(tt[ue],"exported native function `"+Ue+"` not found"),tt[ue].apply(null,arguments)}}var ni="laz-perf.wasm";Jt(ni)||(ni=R(ni));function hi(ue){try{if(ue==ni&&U)return new Uint8Array(U);if(I)return I(ue);throw"both async and sync fetching of the wasm failed"}catch($){et($)}}function Hi(){return!U&&(g||v)&&typeof fetch=="function"?fetch(ni,{credentials:"same-origin"}).then(function(ue){if(!ue.ok)throw"failed to load wasm binary file at '"+ni+"'";return ue.arrayBuffer()}).catch(function(){return hi(ni)}):Promise.resolve().then(function(){return hi(ni)})}function at(){var ue={env:pn,wasi_snapshot_preview1:pn};function $(se,Dt){s.asm=se.exports,H=s.asm.memory,ne(H,"memory not found in wasm exports"),Le(H.buffer),Ae=s.asm.__indirect_function_table,ne(Ae,"table not found in wasm exports"),mi(s.asm.__wasm_call_ctors),ct("wasm-instantiate")}st("wasm-instantiate");var Ue=s;function tt(se){ne(s===Ue,"the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?"),Ue=null,$(se.instance)}function wt(se){return Hi().then(function(Dt){return WebAssembly.instantiate(Dt,ue)}).then(function(Dt){return Dt}).then(se,function(Dt){D("failed to asynchronously prepare wasm: "+Dt),Pt(ni)&&D("warning: Loading from a file URI ("+ni+") is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing"),et(Dt)})}function Nt(){return!U&&typeof WebAssembly.instantiateStreaming=="function"&&!Jt(ni)&&typeof fetch=="function"?fetch(ni,{credentials:"same-origin"}).then(function(se){return WebAssembly.instantiateStreaming(se,ue).then(tt,function(Dt){return D("wasm streaming compile failed: "+Dt),D("falling back to ArrayBuffer instantiation"),wt(tt)})}):wt(tt)}if(s.instantiateWasm)try{return s.instantiateWasm(ue,$)}catch(se){return D("Module.instantiateWasm callback failed with error: "+se),!1}return Nt().catch(l),{}}function ei(ue){for(;ue.length>0;)ue.shift()(s)}function oi(ue){oi.shown||(oi.shown={}),oi.shown[ue]||(oi.shown[ue]=1,D(ue))}function Li(ue,$){ne(ue.length>=0,"writeArrayToMemory array must have a length (should be an array or typed array)"),pe.set(ue,$)}function si(ue){return ma(ue+24)+24}function Ot(ue){this.excPtr=ue,this.ptr=ue-24,this.set_type=function($){Ve[this.ptr+4>>2]=$},this.get_type=function(){return Ve[this.ptr+4>>2]},this.set_destructor=function($){Ve[this.ptr+8>>2]=$},this.get_destructor=function(){return Ve[this.ptr+8>>2]},this.set_refcount=function($){Se[this.ptr>>2]=$},this.set_caught=function($){$=$?1:0,pe[this.ptr+12>>0]=$},this.get_caught=function(){return pe[this.ptr+12>>0]!=0},this.set_rethrown=function($){$=$?1:0,pe[this.ptr+13>>0]=$},this.get_rethrown=function(){return pe[this.ptr+13>>0]!=0},this.init=function($,Ue){this.set_adjusted_ptr(0),this.set_type($),this.set_destructor(Ue),this.set_refcount(0),this.set_caught(!1),this.set_rethrown(!1)},this.add_ref=function(){var $=Se[this.ptr>>2];Se[this.ptr>>2]=$+1},this.release_ref=function(){var $=Se[this.ptr>>2];return Se[this.ptr>>2]=$-1,ne($>0),$===1},this.set_adjusted_ptr=function($){Ve[this.ptr+16>>2]=$},this.get_adjusted_ptr=function(){return Ve[this.ptr+16>>2]},this.get_exception_ptr=function(){if(Ht(this.get_type()))return Ve[this.excPtr>>2];var $=this.get_adjusted_ptr();return $!==0?$:this.excPtr}}var pi=0;function Rt(ue,$,Ue){throw new Ot(ue).init($,Ue),pi++,ue+" - Exception catching is disabled, this exception cannot be caught. Compile with -sNO_DISABLE_EXCEPTION_CATCHING or -sEXCEPTION_CATCHING_ALLOWED=[..] to catch."}function Ln(ue,$,Ue,tt,wt){}function sn(ue){switch(ue){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+ue)}}function _r(){for(var ue=new Array(256),$=0;$<256;++$)ue[$]=String.fromCharCode($);Ar=ue}var Ar=void 0;function sr(ue){for(var $="",Ue=ue;Ie[Ue];)$+=Ar[Ie[Ue++]];return $}var kr={},Qe={},dt={},yt=48,Bt=57;function Ut(ue){if(ue===void 0)return"_unknown";ue=ue.replace(/[^a-zA-Z0-9_]/g,"$");var $=ue.charCodeAt(0);return $>=yt&&$<=Bt?"_"+ue:ue}function Zt(ue,$){return ue=Ut(ue),new Function("body","return function "+ue+`() {
|
|
272
272
|
"use strict"; return body.apply(this, arguments);
|
|
273
273
|
};
|