@gisfun/maplibre-gl-components 0.15.0-alpha.5 → 0.15.0-alpha.6

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.
Files changed (28) hide show
  1. package/dist/{ControlGrid-YjkFF0T2.cjs → ControlGrid-BpqcFTDY.cjs} +4 -4
  2. package/dist/{ControlGrid-VA8fIUTM.js → ControlGrid-DBNnUO2W.js} +11 -11
  3. package/dist/{deflate-Cdn2wQQu.cjs → deflate-CWX19deB.cjs} +1 -1
  4. package/dist/{deflate-ByJO2z1n.js → deflate-CX1Kpa5A.js} +1 -1
  5. package/dist/{geotiff-BIFT8xS3.cjs → geotiff-CvcEZK4N.cjs} +2 -2
  6. package/dist/{geotiff-DqXSvdwG.js → geotiff-Nh4TsiWK.js} +8 -8
  7. package/dist/{index-Bv__sxtP.cjs → index-BKl7PKZI.cjs} +1 -1
  8. package/dist/{index-CY8LNC10.cjs → index-BwXW8_tL.cjs} +1 -1
  9. package/dist/{index-Du55lfw1.js → index-C3CQVuZh.js} +2 -2
  10. package/dist/index-CG2tW5eO.js +4 -0
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.mjs +2 -2
  13. package/dist/{jpeg-rFCFB0lO.cjs → jpeg-Bas54mX4.cjs} +1 -1
  14. package/dist/{jpeg-D6kHLueN.js → jpeg-CXtjL2qy.js} +1 -1
  15. package/dist/{lerc-Chhd0m29.cjs → lerc-9yif6D10.cjs} +1 -1
  16. package/dist/{lerc-Bzish31C.js → lerc-Br94Naw-.js} +2 -2
  17. package/dist/{lzw-CkwzzC_2.cjs → lzw-Br2_QLAt.cjs} +1 -1
  18. package/dist/{lzw-SO_vh63k.js → lzw-Cl2Rp7F7.js} +1 -1
  19. package/dist/{packbits-B7NLJTxu.js → packbits-1MGDFVtD.js} +1 -1
  20. package/dist/{packbits-gJwZNJbv.cjs → packbits-LWnSan5q.cjs} +1 -1
  21. package/dist/{raw-Doz18yvn.js → raw-BdlgOmoo.js} +1 -1
  22. package/dist/{raw-DY9SmBT_.cjs → raw-DCKNZG5I.cjs} +1 -1
  23. package/dist/react.cjs +1 -1
  24. package/dist/react.mjs +1 -1
  25. package/dist/{webimage-Dc9vs8_g.cjs → webimage-ChLmoF1-.cjs} +1 -1
  26. package/dist/{webimage-CaGkiUEE.js → webimage-DpqApFsF.js} +1 -1
  27. package/package.json +1 -1
  28. package/dist/index-DB3LUYKq.js +0 -4
@@ -103,7 +103,7 @@
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:i=>({minVal:i.minVal,maxVal:i.maxVal,isSingleBand:i.isSingleBand})};function lT(i,t){return i&&(Array.isArray(i)?i.map(e=>lT(e,t)):typeof i.clone=="function"?i.clone({opacity:t}):i)}function cz(i){let t=i.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 uz(i){const e=new Uint8ClampedArray(1024),n=i.map(s=>({pos:s.position,rgb:cz(s.color)}));for(let s=0;s<256;s++){const r=s/255;let a=n[0],l=n[n.length-1];for(let m=0;m<n.length-1;m++)if(r>=n[m].pos&&r<=n[m+1].pos){a=n[m],l=n[m+1];break}const h=l.pos-a.pos,g=h>0?(r-a.pos)/h:0;e[s*4]=a.rgb[0]+(l.rgb[0]-a.rgb[0])*g,e[s*4+1]=a.rgb[1]+(l.rgb[1]-a.rgb[1])*g,e[s*4+2]=a.rgb[2]+(l.rgb[2]-a.rgb[2])*g,e[s*4+3]=255}return new ImageData(e,256,1)}const hz=["none","bone","bwr","cividis","cool","coolwarm","gray","hot","inferno","jet","magma","ocean","plasma","rainbow","RdBu","RdYlBu","RdYlGn","seismic","spectral","terrain","turbo","viridis"],dz={position:"top-right",className:"",visible:!0,collapsed:!0,beforeId:"",defaultUrl:"",loadDefaultUrl:!1,defaultBands:"1",defaultColormap:"none",defaultRescaleMin:0,defaultRescaleMax:255,defaultNodata: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},fz='<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>';class T_{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_deckOverlay;_cogLayers=new Map;_cogLayerPropsMap=new Map;_layerCounter=0;_activePopup;_mapClickHandler;constructor(t){this._options={...dz,...t},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(t){if(this._map=t,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 e=()=>{this._addLayer()};this._map.isStyleLoaded()?setTimeout(e,100):this._map.once("idle",e)}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(t){this._options={...this._options,...t},t.visible!==void 0&&(this._state.visible=t.visible),t.collapsed!==void 0&&(this._state.collapsed=t.collapsed),this._render(),this._emit("update")}on(t,e){this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e)}off(t,e){this._eventHandlers.get(t)?.delete(e)}async addLayer(t){t&&(this._state.url=t),await this._addLayer()}removeLayer(t){this._removeLayer(t),this._render()}getLayerIds(){return Array.from(this._cogLayers.keys())}getLayerOpacity(t){const e=this._cogLayers.get(t);return!e||!e.props?null:e.props.opacity??1}setLayerOpacity(t,e){const n=this._cogLayers.get(t);if(!n||typeof n.clone!="function")return;const s=Math.max(0,Math.min(1,e)),r=n.clone({opacity:s});this._cogLayers.set(t,r),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}getLayerVisibility(t){const e=this.getLayerOpacity(t);return e!==null&&e>0}setLayerVisibility(t,e,n=1){e?this.setLayerOpacity(t,n):this.setLayerOpacity(t,0)}getLayerUrl(t){return this._cogLayerPropsMap.get(t)?.geotiff??null}_emit(t,e){const n=this._eventHandlers.get(t);if(n){const s={type:t,state:this.getState(),...e};n.forEach(r=>r(s))}}_checkZoomVisibility(){if(!this._map)return;const t=this._map.getZoom(),{minzoom:e,maxzoom:n}=this._options,s=t>=e&&t<=n;s!==this._zoomVisible&&(this._zoomVisible=s,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const t=this._state.visible&&this._zoomVisible;this._container.style.display=t?"block":"none"}_createContainer(){const t=document.createElement("div");return t.className=`maplibregl-ctrl maplibre-gl-cog-layer${this._options.className?` ${this._options.className}`:""}`,this._state.visible&&this._zoomVisible||(t.style.display="none"),Object.assign(t.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&&(t.style.opacity=String(this._options.opacity)),t}_render(){if(!this._container)return;const t=this._container.querySelector(".maplibre-gl-cog-layer-panel"),e=t?t.scrollTop:0;if(this._container.innerHTML="",this._state.collapsed?this._renderCollapsed():this._renderExpanded(),this._updateDisplayState(),e>0){const n=this._container.querySelector(".maplibre-gl-cog-layer-panel");n&&(n.scrollTop=e)}}_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=fz,this._button.addEventListener("click",()=>this.expand()),this._container.appendChild(this._button),this._panel=void 0)}_renderExpanded(){if(!this._container)return;const t=document.createElement("div");t.className="maplibre-gl-cog-layer-panel",t.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(t.style.maxHeight=`${this._options.maxHeight}px`,t.style.overflowY="auto"),this._panel=t;const e=document.createElement("div");e.className="maplibre-gl-cog-layer-header";const n=document.createElement("span");n.className="maplibre-gl-cog-layer-title",n.textContent="COG Layer",e.appendChild(n);const s=document.createElement("button");s.className="maplibre-gl-cog-layer-close",s.innerHTML="&times;",s.title="Close",s.addEventListener("click",()=>this.collapse()),e.appendChild(s),t.appendChild(e);const r=this._createFormGroup("COG URL","url"),a=document.createElement("input");a.type="text",a.className="maplibre-gl-cog-layer-input",a.style.color="#000",a.placeholder="https://example.com/cog.tif",a.value=this._state.url,a.addEventListener("input",()=>{this._state.url=a.value}),r.appendChild(a),t.appendChild(r);const l=this._createFormGroup("Bands (comma-separated)","bands"),h=document.createElement("input");h.type="text",h.className="maplibre-gl-cog-layer-input",h.style.color="#000",h.placeholder="1 or 1,2,3",h.value=this._state.bands,h.addEventListener("input",()=>{this._state.bands=h.value}),l.appendChild(h),t.appendChild(l);const g=this._createFormGroup("Colormap","colormap"),m=document.createElement("select");m.className="maplibre-gl-cog-layer-select",m.style.color="#000";for(const W of hz){const X=document.createElement("option");X.value=W,X.textContent=W,W===this._state.colormap&&(X.selected=!0),m.appendChild(X)}m.addEventListener("change",()=>{this._state.colormap=m.value,this._updateColormapPreview()}),g.appendChild(m);const y=document.createElement("div");y.className="maplibre-gl-cog-layer-colormap-preview",y.id="cog-colormap-preview",this._updateColormapPreviewElement(y),g.appendChild(y),t.appendChild(g);const x=document.createElement("div");x.className="maplibre-gl-cog-layer-row";const A=this._createFormGroup("Rescale Min","rescale-min"),S=document.createElement("input");S.type="number",S.className="maplibre-gl-cog-layer-input",S.style.color="#000",S.value=String(this._state.rescaleMin),S.addEventListener("input",()=>{this._state.rescaleMin=Number(S.value)||0}),A.appendChild(S),x.appendChild(A);const T=this._createFormGroup("Rescale Max","rescale-max"),k=document.createElement("input");k.type="number",k.className="maplibre-gl-cog-layer-input",k.style.color="#000",k.value=String(this._state.rescaleMax),k.addEventListener("input",()=>{this._state.rescaleMax=Number(k.value)||0}),T.appendChild(k),x.appendChild(T),t.appendChild(x);const L=this._createFormGroup("Nodata","nodata"),N=document.createElement("input");N.type="number",N.className="maplibre-gl-cog-layer-input",N.style.color="#000",N.placeholder="e.g. 0 or -9999",N.value=this._state.nodata!==void 0?String(this._state.nodata):"",N.addEventListener("input",()=>{this._state.nodata=N.value!==""?Number(N.value):void 0}),L.appendChild(N),t.appendChild(L);const z=this._createFormGroup("Opacity","opacity"),j=document.createElement("div");j.className="maplibre-gl-cog-layer-slider-row";const Y=document.createElement("input");Y.type="range",Y.className="maplibre-gl-cog-layer-slider",Y.min="0",Y.max="100",Y.value=String(Math.round(this._state.layerOpacity*100));const J=document.createElement("span");J.className="maplibre-gl-cog-layer-slider-value",J.textContent=`${Math.round(this._state.layerOpacity*100)}%`,Y.addEventListener("input",()=>{const W=Number(Y.value);this._state.layerOpacity=W/100,J.textContent=`${W}%`,this._updateOpacity()}),j.appendChild(Y),j.appendChild(J),z.appendChild(j),t.appendChild(z);const ut=document.createElement("div");ut.className="maplibre-gl-cog-layer-form-group maplibre-gl-cog-layer-checkbox-group";const D=document.createElement("label");D.className="maplibre-gl-cog-layer-checkbox-label";const U=document.createElement("input");U.type="checkbox",U.className="maplibre-gl-cog-layer-checkbox",U.checked=this._state.pickable,U.addEventListener("change",()=>{this._state.pickable=U.checked,this._updatePickable()}),D.appendChild(U);const H=document.createElement("span");H.textContent="Pickable (click to show pixel value)",D.appendChild(H),ut.appendChild(D),t.appendChild(ut);const K=this._createFormGroup("Layer Name","layer-name"),et=document.createElement("input");et.type="text",et.className="maplibre-gl-cog-layer-input",et.style.color="#000",et.placeholder="Optional custom layer name",et.value=this._state.layerName,et.addEventListener("input",()=>{this._state.layerName=et.value}),K.appendChild(et),t.appendChild(K);const lt=this._createFormGroup("Before Layer ID (optional)","before-id"),nt=document.createElement("input");nt.type="text",nt.className="maplibre-gl-cog-layer-input",nt.style.color="#000",nt.placeholder="e.g. labels or water",nt.value=this._options.beforeId||"",nt.addEventListener("input",()=>{this._options.beforeId=nt.value||""}),lt.appendChild(nt),t.appendChild(lt);const $=document.createElement("div");$.className="maplibre-gl-cog-layer-buttons";const F=document.createElement("button");if(F.className="maplibre-gl-cog-layer-btn maplibre-gl-cog-layer-btn--primary",F.textContent="Add Layer",F.disabled=this._state.loading,F.addEventListener("click",()=>this._addLayer()),$.appendChild(F),t.appendChild($),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 W=document.createElement("div");W.className="maplibre-gl-cog-layer-list";const X=document.createElement("div");X.className="maplibre-gl-cog-layer-list-header",X.textContent=`Layers (${this._cogLayers.size})`,W.appendChild(X);for(const[it]of this._cogLayers){const rt=this._cogLayerPropsMap.get(it);if(!rt)continue;const dt=document.createElement("div");dt.className="maplibre-gl-cog-layer-list-item";const pt=document.createElement("span");pt.className="maplibre-gl-cog-layer-list-label";const Ct=rt.geotiff,At=rt._layerName;let St;if(At)St=At;else try{St=new URL(Ct).pathname.split("/").pop()||Ct}catch{St=Ct}pt.textContent=St,pt.title=Ct,dt.appendChild(pt);const Kt=document.createElement("button");Kt.className="maplibre-gl-cog-layer-list-remove",Kt.innerHTML="&times;",Kt.title="Remove layer",Kt.addEventListener("click",()=>{this._removeLayer(it),this._render()}),dt.appendChild(Kt),W.appendChild(dt)}t.appendChild(W)}this._container.appendChild(t),this._button=void 0}_createFormGroup(t,e){const n=document.createElement("div");n.className="maplibre-gl-cog-layer-form-group";const s=document.createElement("label");return s.textContent=t,s.htmlFor=`cog-layer-${e}`,n.appendChild(s),n}_appendStatus(t,e){if(!this._panel)return;const n=document.createElement("div");n.className=`maplibre-gl-cog-layer-status maplibre-gl-cog-layer-status--${e}`,n.textContent=t,this._panel.appendChild(n)}_updateColormapPreview(){const t=document.getElementById("cog-colormap-preview");t&&this._updateColormapPreviewElement(t)}_updateColormapPreviewElement(t){if(this._state.colormap==="none")t.style.background="linear-gradient(to right, #888, #888)",t.style.display="none";else{const n=ls(this._state.colormap).map(s=>s.color).join(", ");t.style.background=`linear-gradient(to right, ${n})`,t.style.display="block"}}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:t}=await Promise.resolve().then(()=>require("./index-CY8LNC10.cjs"));this._deckOverlay=new t({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const t=this._map;this._mapClickHandler=e=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:n}=e,s=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(s[0]);let a='<div class="maplibre-gl-cog-layer-popup">';a+='<table class="maplibre-gl-cog-layer-popup-table">',a+=`<tr><td><strong>Layers</strong></td><td>${s.length} COG layer(s)</td></tr>`,a+=`<tr><td><strong>Lng</strong></td><td>${n.lng.toFixed(6)}</td></tr>`,a+=`<tr><td><strong>Lat</strong></td><td>${n.lat.toFixed(6)}</td></tr>`,r&&(a+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(a+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),a+="</table>",a+="</div>",this._activePopup=new Fs.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(n).setHTML(a).addTo(t);const l=this._activePopup.getElement();l&&(l.style.zIndex="1000")},t.on("click",this._mapClickHandler)}_updatePickable(){if(this._deckOverlay){for(const[,t]of this._cogLayerPropsMap)t.pickable=this._state.pickable;this._rebuildLayers()}}async _rebuildLayers(){if(this._deckOverlay)try{const{COGLayer:t}=await Promise.resolve().then(()=>require("./index-Bv__sxtP.cjs"));this._patchCOGLayerForFloat(t),this._patchCOGLayerForOpacity(t);const e=[];for(const[n,s]of this._cogLayerPropsMap){const r=new t(s);this._cogLayers.set(n,r),e.push(r)}this._deckOverlay.setProps({layers:e})}catch(t){console.error("Failed to rebuild layers:",t)}}async _registerCommonProjections(t){t.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"),t.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(t){let e=null;return Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")).then(n=>{e=n.default||n,typeof e=="function"&&this._registerCommonProjections(e)}),async n=>{try{const s=t.toProj4(n);if(s&&s.proj4){let r=s.proj4;if(r=r.replace(/\+axis=\w+\s*/g,""),!e){const l=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs"));e=l.default||l,typeof e=="function"&&await this._registerCommonProjections(e)}let a={};if(typeof e=="function")try{e.defs("custom",r),a=e.defs("custom")||{}}catch{}return{def:r,parsed:a,coordinatesUnits:s.coordinatesUnits||"metre"}}}catch{}return null}}_patchCOGLayerForFloat(t){if(t.__floatPatched)return;t.__floatPatched=!0;const e=t.prototype._parseGeoTIFF;t.prototype._parseGeoTIFF=async function(){try{await e.call(this);const n=this.props._nodata;if(n!=null&&!isNaN(n)){const{FilterNoDataVal:s}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),r=this.state.defaultRenderTile;if(typeof r=="function"){const a=l=>{const g=r(l).filter(m=>m.module!==s);return g.splice(1,0,{module:s,props:{value:n}}),g};this.setState({defaultRenderTile:a})}}}catch(n){if(!(n instanceof Error?n.message:String(n)).includes("non-unsigned integers not yet supported"))throw n;const{fromUrl:r}=await Promise.resolve().then(()=>require("./geotiff-BIFT8xS3.cjs")).then(it=>it.geotiff),{parseCOGTileMatrixSet:a,texture:l}=await Promise.resolve().then(()=>require("./index-Bv__sxtP.cjs")),{CreateTexture:h,FilterNoDataVal:g}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),m=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")),y=m.default||m,x=this.props.geotiff,A=typeof x=="string"?await r(x):x,S=this.props.geoKeysParser,T=await a(A,S),k=await A.getImage(),L=await A.getImageCount(),N=[];for(let it=0;it<L;it++)N.push(await A.getImage(it));const z=await S(k.getGeoKeys());if(!z)throw new Error("Could not determine source projection from GeoTIFF geo keys");const j=y(z.def,"EPSG:4326"),Y=(it,rt)=>j.forward([it,rt],!1),J=(it,rt)=>j.inverse([it,rt],!1);if(this.props.onGeoTIFFLoad){const it=k.getBoundingBox(),rt=[j.forward([it[0],it[1]]),j.forward([it[2],it[1]]),j.forward([it[2],it[3]]),j.forward([it[0],it[3]])],dt=rt.map(At=>At[0]),pt=rt.map(At=>At[1]),Ct={west:Math.min(...dt),south:Math.min(...pt),east:Math.max(...dt),north:Math.max(...pt)};this.props.onGeoTIFFLoad(A,{projection:z,geographicBounds:Ct})}const ut=k.getFileDirectory(),{BitsPerSample:D,SampleFormat:U,SamplesPerPixel:H,GDAL_NODATA:K}=ut;let et=null;if(K){const it=K[K.length-1]==="\0"?K.slice(0,-1):K;it.length>0&&(et=parseFloat(it))}const lt=async(it,rt)=>{const{device:dt}=rt,pt=await it.readRasters({...rt,interleave:!0});let Ct=pt,At=H;if(H===3){const Vt=pt.width*pt.height,xt=new Float32Array(Vt*4);for(let oe=0;oe<Vt;oe++)xt[oe*4]=pt[oe*3],xt[oe*4+1]=pt[oe*3+1],xt[oe*4+2]=pt[oe*3+2],xt[oe*4+3]=1;Ct=xt,Ct.width=pt.width,Ct.height=pt.height,At=4}const St=l.inferTextureFormat(At,D,U);return{texture:dt.createTexture({data:Ct,format:St,width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width}},nt=this;let $=null,F=null;const{Colormap:W}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),X=it=>{const rt=[{module:h,props:{textureName:it.texture}}],dt=nt.props._nodata!==void 0&&nt.props._nodata!==null&&!isNaN(nt.props._nodata)?nt.props._nodata:et;dt!==null&&rt.push({module:g,props:{value:dt}});const pt=nt.props._rescaleMin??0,Ct=nt.props._rescaleMax??255;rt.push({module:lz,props:{minVal:pt,maxVal:Ct,isSingleBand:H===1?1:0}});const At=nt.props._colormap;if(At&&At!=="none"){if(At!==$){const St=ls(At),Kt=uz(St);F=nt.context.device.createTexture({data:Kt.data,format:"rgba8unorm",width:Kt.width,height:Kt.height,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}}),$=At}rt.push({module:W,props:{colormapTexture:F}})}return rt};this.setState({metadata:T,forwardReproject:Y,inverseReproject:J,images:N,defaultGetTileData:lt,defaultRenderTile:X})}}}_patchCOGLayerForOpacity(t){if(t.__opacityPatched)return;t.__opacityPatched=!0;const e=t.prototype._renderSubLayers;t.prototype._renderSubLayers=function(...n){const s=e.apply(this,n),r=this.props.opacity;return r==null?s:lT(s,Math.max(0,Math.min(1,r)))}}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:t}=await Promise.resolve().then(()=>require("./index-Bv__sxtP.cjs"));this._patchCOGLayerForFloat(t),this._patchCOGLayerForOpacity(t);const e=this._map,n={geotiff: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,...(()=>{if(this._options.beforeId){if(e.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:g,south:m,east:y,north:x}=h.geographicBounds;e.fitBounds([[g,m],[y,x]],{padding:50,duration:1e3})}}catch{}}};try{const l=await Promise.resolve().then(()=>require("./main-dist-Bymiy5aM.cjs")),h=l.default||l;h&&typeof h.toProj4=="function"&&(n.geoKeysParser=this._buildGeoKeysParser(h))}catch{}const s=`cog-layer-${this._layerCounter++}`;n.id=s;const r=this._state.layerName?.trim();r&&(n._layerName=r),this._cogLayerPropsMap.set(s,n);const a=new t(n);this._cogLayers.set(s,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:s})}catch(t){this._state.loading=!1,this._state.error=`Failed to load COG: ${t instanceof Error?t.message:String(t)}`,this._render(),this._emit("error",{error:this._state.error})}}_removeLayer(t){t?(this._cogLayers.delete(t),this._cogLayerPropsMap.delete(t),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:t})):(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 t=this._state.layerOpacity;for(const[e,n]of this._cogLayers)typeof n.clone=="function"&&this._cogLayers.set(e,n.clone({opacity:t}));this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}_buildLayerInfoList(){const t=[];for(const[e,n]of this._cogLayerPropsMap)t.push({id:e,name:n._layerName||void 0,url:n.geotiff,bands:"1",colormap:n._colormap||"none",rescaleMin:n._rescaleMin??0,rescaleMax:n._rescaleMax??255,nodata:n._nodata,opacity:n.opacity??1});return t}}const pz={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},gz='<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>',Mf="maplibre-minimap-viewport",mz="maplibre-minimap-viewport-fill",_z="maplibre-minimap-viewport-line";class cT{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_minimapMap;_handleMove;_handleZoom;_zoomVisible=!0;_isDragging=!1;_dragStartLngLat;_dragCleanup;constructor(t){this._options={...pz,...t},this._state={visible:this._options.visible,collapsed:this._options.collapsed}}getDefaultPosition(){return this._options.position}onAdd(t){return this._map=t,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(t,e){return this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e),this}off(t,e){return this._eventHandlers.get(t)?.delete(e),this}_emit(t){const e=this._eventHandlers.get(t);if(e){const n={type:t,state:this.getState()};e.forEach(s=>s(n))}}_createContainer(){const t=document.createElement("div");return t.classList.add("maplibregl-ctrl","maplibre-gl-minimap-control"),this._options.className&&t.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=gz,this._button.addEventListener("click",()=>this.toggle()),t.appendChild(this._button)),t}_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 t=document.createElement("div");t.className="minimap-map",this._panel.appendChild(t),this._container.appendChild(this._panel);const e=this._map.getCenter(),n=this._map.getZoom(),s=Math.max(0,n+this._options.zoomOffset);if(this._minimapMap=new Fs.Map({container:t,style:this._options.style,center:e,zoom:s,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 a=null,l=!1,h=null;const g=x=>{if(!this._minimapMap||!this._map)return;x.preventDefault(),this._isDragging=!0,l=!1,a={x:x.clientX,y:x.clientY},r.style.cursor="grabbing";const A=r.getBoundingClientRect(),S=x.clientX-A.left,T=x.clientY-A.top;this._dragStartLngLat=this._minimapMap.unproject([S,T]),h=this._map.getCenter()},m=x=>{if(!this._isDragging||!this._minimapMap||!this._map||!this._dragStartLngLat||!h)return;if(a&&!l){const z=x.clientX-a.x,j=x.clientY-a.y;(Math.abs(z)>3||Math.abs(j)>3)&&(l=!0)}if(!l)return;const A=r.getBoundingClientRect(),S=x.clientX-A.left,T=x.clientY-A.top,k=this._minimapMap.unproject([S,T]),L=k.lng-this._dragStartLngLat.lng,N=k.lat-this._dragStartLngLat.lat;this._map.setCenter([h.lng+L,h.lat+N]),this._updateViewportRect()},y=x=>{if(this._isDragging&&!l&&this._minimapMap&&this._map){const A=r.getBoundingClientRect(),S=x.clientX-A.left,T=x.clientY-A.top,k=this._minimapMap.unproject([S,T]);this._map.flyTo({center:k})}this._isDragging=!1,l=!1,a=null,h=null,this._dragStartLngLat=void 0,r.style.cursor="pointer",this._syncMinimap(),this._updateViewportRect()};r.addEventListener("mousedown",g),document.addEventListener("mousemove",m),document.addEventListener("mouseup",y),this._dragCleanup=()=>{r.removeEventListener("mousedown",g),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",y)}}}_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 t=this._map.getCenter(),e=Math.max(0,this._map.getZoom()+this._options.zoomOffset);this._minimapMap.jumpTo({center:t,zoom:e})}_addViewportRect(){this._minimapMap&&(this._minimapMap.addSource(Mf,{type:"geojson",data:{type:"Feature",geometry:{type:"Polygon",coordinates:[[]]},properties:{}}}),this._minimapMap.addLayer({id:mz,type:"fill",source:Mf,paint:{"fill-color":this._options.viewportRectColor,"fill-opacity":this._options.viewportRectOpacity}}),this._minimapMap.addLayer({id:_z,type:"line",source:Mf,paint:{"line-color":this._options.viewportRectColor,"line-width":2}}))}_updateViewportRect(){if(!this._minimapMap||!this._map)return;const t=this._minimapMap.getSource(Mf);if(!t||!("setData"in t))return;const e=this._map.getBounds(),n=e.getSouthWest(),s=e.getNorthEast(),r=e.getNorthWest(),a=e.getSouthEast(),l=[[n.lng,n.lat],[a.lng,a.lat],[s.lng,s.lat],[r.lng,r.lat],[n.lng,n.lat]];t.setData({type:"Feature",geometry:{type:"Polygon",coordinates:[l]},properties:{}})}_checkZoomVisibility(){if(!this._map||!this._container)return;const t=this._map.getZoom(),e=this._zoomVisible;this._zoomVisible=t>=this._options.minzoom&&t<=this._options.maxzoom,e!==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}}}const yz={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:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:12,fontColor:"#333",minzoom:0,maxzoom:24},Zw='<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>',Yw='<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>',qw='<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>',Jw='<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>',vz='<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>',fl={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}},Ac={"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 bz(i,t){const n=i.lat*Math.PI/180,s=t.lat*Math.PI/180,r=(t.lat-i.lat)*Math.PI/180,a=(t.lng-i.lng)*Math.PI/180,l=Math.sin(r/2)*Math.sin(r/2)+Math.cos(n)*Math.cos(s)*Math.sin(a/2)*Math.sin(a/2);return 6371e3*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))}function wz(i){if(i.length<3)return 0;const t=6371e3;let e=0;for(let n=0;n<i.length;n++){const s=(n+1)%i.length,r=i[n].lat*Math.PI/180,a=i[s].lat*Math.PI/180,l=i[n].lng*Math.PI/180,h=i[s].lng*Math.PI/180;e+=(h-l)*(2+Math.sin(r)+Math.sin(a))}return e=Math.abs(e*t*t/2),e}class uT{_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(t){this._options={...yz,...t},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 e=fo("measure");this._sourceId=`${e}-source`,this._lineLayerId=`${e}-line`,this._fillLayerId=`${e}-fill`}onAdd(t){return this._map=t,this._container=this._createContainer(),t.isStyleLoaded()?this._setupMapSources():t.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(t,e){return this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e),this}off(t,e){return this._eventHandlers.get(t)?.delete(e),this}_emit(t,e){const n=this._eventHandlers.get(t);if(n){const s={type:t,state:{...this._state},...e};n.forEach(r=>r(s))}}_createContainer(){const t=document.createElement("div");return t.className=`maplibregl-ctrl maplibre-gl-measure-control ${this._options.className}`,t.style.opacity=String(this._options.opacity),this._state.visible||(t.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=Zw,this._button.addEventListener("click",()=>this._togglePanel()),t.appendChild(this._button),t}_createPanel(){const t=document.createElement("div");t.className=`measure-panel ${this._options.position.includes("left")?"right":"left"}`,t.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(t.style.maxHeight=`${this._options.maxHeight}px`,t.style.overflowY="auto"),t.style.background=this._options.backgroundColor,t.style.borderRadius=`${this._options.borderRadius}px`,t.style.fontSize=`${this._options.fontSize}px`,t.style.color=this._options.fontColor;const e=document.createElement("div");e.className="measure-header",e.innerHTML=`
106
+ `},uniformTypes:{minVal:"f32",maxVal:"f32",isSingleBand:"f32"},getUniforms:i=>({minVal:i.minVal,maxVal:i.maxVal,isSingleBand:i.isSingleBand})};function lT(i,t){return i&&(Array.isArray(i)?i.map(e=>lT(e,t)):typeof i.clone=="function"?i.clone({opacity:t}):i)}function cz(i){let t=i.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 uz(i){const e=new Uint8ClampedArray(1024),n=i.map(s=>({pos:s.position,rgb:cz(s.color)}));for(let s=0;s<256;s++){const r=s/255;let a=n[0],l=n[n.length-1];for(let m=0;m<n.length-1;m++)if(r>=n[m].pos&&r<=n[m+1].pos){a=n[m],l=n[m+1];break}const h=l.pos-a.pos,g=h>0?(r-a.pos)/h:0;e[s*4]=a.rgb[0]+(l.rgb[0]-a.rgb[0])*g,e[s*4+1]=a.rgb[1]+(l.rgb[1]-a.rgb[1])*g,e[s*4+2]=a.rgb[2]+(l.rgb[2]-a.rgb[2])*g,e[s*4+3]=255}return new ImageData(e,256,1)}const hz=["none","bone","bwr","cividis","cool","coolwarm","gray","hot","inferno","jet","magma","ocean","plasma","rainbow","RdBu","RdYlBu","RdYlGn","seismic","spectral","terrain","turbo","viridis"],dz={position:"top-right",className:"",visible:!0,collapsed:!0,beforeId:"",defaultUrl:"",loadDefaultUrl:!1,defaultBands:"1",defaultColormap:"none",defaultRescaleMin:0,defaultRescaleMax:255,defaultNodata: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},fz='<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>';class T_{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_deckOverlay;_cogLayers=new Map;_cogLayerPropsMap=new Map;_layerCounter=0;_activePopup;_mapClickHandler;constructor(t){this._options={...dz,...t},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(t){if(this._map=t,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 e=()=>{this._addLayer()};this._map.isStyleLoaded()?setTimeout(e,100):this._map.once("idle",e)}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(t){this._options={...this._options,...t},t.visible!==void 0&&(this._state.visible=t.visible),t.collapsed!==void 0&&(this._state.collapsed=t.collapsed),this._render(),this._emit("update")}on(t,e){this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e)}off(t,e){this._eventHandlers.get(t)?.delete(e)}async addLayer(t){t&&(this._state.url=t),await this._addLayer()}removeLayer(t){this._removeLayer(t),this._render()}getLayerIds(){return Array.from(this._cogLayers.keys())}getLayerOpacity(t){const e=this._cogLayers.get(t);return!e||!e.props?null:e.props.opacity??1}setLayerOpacity(t,e){const n=this._cogLayers.get(t);if(!n||typeof n.clone!="function")return;const s=Math.max(0,Math.min(1,e)),r=n.clone({opacity:s});this._cogLayers.set(t,r),this._deckOverlay&&this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}getLayerVisibility(t){const e=this.getLayerOpacity(t);return e!==null&&e>0}setLayerVisibility(t,e,n=1){e?this.setLayerOpacity(t,n):this.setLayerOpacity(t,0)}getLayerUrl(t){return this._cogLayerPropsMap.get(t)?.geotiff??null}_emit(t,e){const n=this._eventHandlers.get(t);if(n){const s={type:t,state:this.getState(),...e};n.forEach(r=>r(s))}}_checkZoomVisibility(){if(!this._map)return;const t=this._map.getZoom(),{minzoom:e,maxzoom:n}=this._options,s=t>=e&&t<=n;s!==this._zoomVisible&&(this._zoomVisible=s,this._updateDisplayState())}_updateDisplayState(){if(!this._container)return;const t=this._state.visible&&this._zoomVisible;this._container.style.display=t?"block":"none"}_createContainer(){const t=document.createElement("div");return t.className=`maplibregl-ctrl maplibre-gl-cog-layer${this._options.className?` ${this._options.className}`:""}`,this._state.visible&&this._zoomVisible||(t.style.display="none"),Object.assign(t.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&&(t.style.opacity=String(this._options.opacity)),t}_render(){if(!this._container)return;const t=this._container.querySelector(".maplibre-gl-cog-layer-panel"),e=t?t.scrollTop:0;if(this._container.innerHTML="",this._state.collapsed?this._renderCollapsed():this._renderExpanded(),this._updateDisplayState(),e>0){const n=this._container.querySelector(".maplibre-gl-cog-layer-panel");n&&(n.scrollTop=e)}}_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=fz,this._button.addEventListener("click",()=>this.expand()),this._container.appendChild(this._button),this._panel=void 0)}_renderExpanded(){if(!this._container)return;const t=document.createElement("div");t.className="maplibre-gl-cog-layer-panel",t.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(t.style.maxHeight=`${this._options.maxHeight}px`,t.style.overflowY="auto"),this._panel=t;const e=document.createElement("div");e.className="maplibre-gl-cog-layer-header";const n=document.createElement("span");n.className="maplibre-gl-cog-layer-title",n.textContent="COG Layer",e.appendChild(n);const s=document.createElement("button");s.className="maplibre-gl-cog-layer-close",s.innerHTML="&times;",s.title="Close",s.addEventListener("click",()=>this.collapse()),e.appendChild(s),t.appendChild(e);const r=this._createFormGroup("COG URL","url"),a=document.createElement("input");a.type="text",a.className="maplibre-gl-cog-layer-input",a.style.color="#000",a.placeholder="https://example.com/cog.tif",a.value=this._state.url,a.addEventListener("input",()=>{this._state.url=a.value}),r.appendChild(a),t.appendChild(r);const l=this._createFormGroup("Bands (comma-separated)","bands"),h=document.createElement("input");h.type="text",h.className="maplibre-gl-cog-layer-input",h.style.color="#000",h.placeholder="1 or 1,2,3",h.value=this._state.bands,h.addEventListener("input",()=>{this._state.bands=h.value}),l.appendChild(h),t.appendChild(l);const g=this._createFormGroup("Colormap","colormap"),m=document.createElement("select");m.className="maplibre-gl-cog-layer-select",m.style.color="#000";for(const W of hz){const X=document.createElement("option");X.value=W,X.textContent=W,W===this._state.colormap&&(X.selected=!0),m.appendChild(X)}m.addEventListener("change",()=>{this._state.colormap=m.value,this._updateColormapPreview()}),g.appendChild(m);const y=document.createElement("div");y.className="maplibre-gl-cog-layer-colormap-preview",y.id="cog-colormap-preview",this._updateColormapPreviewElement(y),g.appendChild(y),t.appendChild(g);const x=document.createElement("div");x.className="maplibre-gl-cog-layer-row";const A=this._createFormGroup("Rescale Min","rescale-min"),S=document.createElement("input");S.type="number",S.className="maplibre-gl-cog-layer-input",S.style.color="#000",S.value=String(this._state.rescaleMin),S.addEventListener("input",()=>{this._state.rescaleMin=Number(S.value)||0}),A.appendChild(S),x.appendChild(A);const T=this._createFormGroup("Rescale Max","rescale-max"),k=document.createElement("input");k.type="number",k.className="maplibre-gl-cog-layer-input",k.style.color="#000",k.value=String(this._state.rescaleMax),k.addEventListener("input",()=>{this._state.rescaleMax=Number(k.value)||0}),T.appendChild(k),x.appendChild(T),t.appendChild(x);const L=this._createFormGroup("Nodata","nodata"),N=document.createElement("input");N.type="number",N.className="maplibre-gl-cog-layer-input",N.style.color="#000",N.placeholder="e.g. 0 or -9999",N.value=this._state.nodata!==void 0?String(this._state.nodata):"",N.addEventListener("input",()=>{this._state.nodata=N.value!==""?Number(N.value):void 0}),L.appendChild(N),t.appendChild(L);const z=this._createFormGroup("Opacity","opacity"),j=document.createElement("div");j.className="maplibre-gl-cog-layer-slider-row";const Y=document.createElement("input");Y.type="range",Y.className="maplibre-gl-cog-layer-slider",Y.min="0",Y.max="100",Y.value=String(Math.round(this._state.layerOpacity*100));const J=document.createElement("span");J.className="maplibre-gl-cog-layer-slider-value",J.textContent=`${Math.round(this._state.layerOpacity*100)}%`,Y.addEventListener("input",()=>{const W=Number(Y.value);this._state.layerOpacity=W/100,J.textContent=`${W}%`,this._updateOpacity()}),j.appendChild(Y),j.appendChild(J),z.appendChild(j),t.appendChild(z);const ut=document.createElement("div");ut.className="maplibre-gl-cog-layer-form-group maplibre-gl-cog-layer-checkbox-group";const D=document.createElement("label");D.className="maplibre-gl-cog-layer-checkbox-label";const U=document.createElement("input");U.type="checkbox",U.className="maplibre-gl-cog-layer-checkbox",U.checked=this._state.pickable,U.addEventListener("change",()=>{this._state.pickable=U.checked,this._updatePickable()}),D.appendChild(U);const H=document.createElement("span");H.textContent="Pickable (click to show pixel value)",D.appendChild(H),ut.appendChild(D),t.appendChild(ut);const K=this._createFormGroup("Layer Name","layer-name"),et=document.createElement("input");et.type="text",et.className="maplibre-gl-cog-layer-input",et.style.color="#000",et.placeholder="Optional custom layer name",et.value=this._state.layerName,et.addEventListener("input",()=>{this._state.layerName=et.value}),K.appendChild(et),t.appendChild(K);const lt=this._createFormGroup("Before Layer ID (optional)","before-id"),nt=document.createElement("input");nt.type="text",nt.className="maplibre-gl-cog-layer-input",nt.style.color="#000",nt.placeholder="e.g. labels or water",nt.value=this._options.beforeId||"",nt.addEventListener("input",()=>{this._options.beforeId=nt.value||""}),lt.appendChild(nt),t.appendChild(lt);const $=document.createElement("div");$.className="maplibre-gl-cog-layer-buttons";const F=document.createElement("button");if(F.className="maplibre-gl-cog-layer-btn maplibre-gl-cog-layer-btn--primary",F.textContent="Add Layer",F.disabled=this._state.loading,F.addEventListener("click",()=>this._addLayer()),$.appendChild(F),t.appendChild($),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 W=document.createElement("div");W.className="maplibre-gl-cog-layer-list";const X=document.createElement("div");X.className="maplibre-gl-cog-layer-list-header",X.textContent=`Layers (${this._cogLayers.size})`,W.appendChild(X);for(const[it]of this._cogLayers){const rt=this._cogLayerPropsMap.get(it);if(!rt)continue;const dt=document.createElement("div");dt.className="maplibre-gl-cog-layer-list-item";const pt=document.createElement("span");pt.className="maplibre-gl-cog-layer-list-label";const Ct=rt.geotiff,At=rt._layerName;let St;if(At)St=At;else try{St=new URL(Ct).pathname.split("/").pop()||Ct}catch{St=Ct}pt.textContent=St,pt.title=Ct,dt.appendChild(pt);const Kt=document.createElement("button");Kt.className="maplibre-gl-cog-layer-list-remove",Kt.innerHTML="&times;",Kt.title="Remove layer",Kt.addEventListener("click",()=>{this._removeLayer(it),this._render()}),dt.appendChild(Kt),W.appendChild(dt)}t.appendChild(W)}this._container.appendChild(t),this._button=void 0}_createFormGroup(t,e){const n=document.createElement("div");n.className="maplibre-gl-cog-layer-form-group";const s=document.createElement("label");return s.textContent=t,s.htmlFor=`cog-layer-${e}`,n.appendChild(s),n}_appendStatus(t,e){if(!this._panel)return;const n=document.createElement("div");n.className=`maplibre-gl-cog-layer-status maplibre-gl-cog-layer-status--${e}`,n.textContent=t,this._panel.appendChild(n)}_updateColormapPreview(){const t=document.getElementById("cog-colormap-preview");t&&this._updateColormapPreviewElement(t)}_updateColormapPreviewElement(t){if(this._state.colormap==="none")t.style.background="linear-gradient(to right, #888, #888)",t.style.display="none";else{const n=ls(this._state.colormap).map(s=>s.color).join(", ");t.style.background=`linear-gradient(to right, ${n})`,t.style.display="block"}}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:t}=await Promise.resolve().then(()=>require("./index-BwXW8_tL.cjs"));this._deckOverlay=new t({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const t=this._map;this._mapClickHandler=e=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:n}=e,s=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(s[0]);let a='<div class="maplibre-gl-cog-layer-popup">';a+='<table class="maplibre-gl-cog-layer-popup-table">',a+=`<tr><td><strong>Layers</strong></td><td>${s.length} COG layer(s)</td></tr>`,a+=`<tr><td><strong>Lng</strong></td><td>${n.lng.toFixed(6)}</td></tr>`,a+=`<tr><td><strong>Lat</strong></td><td>${n.lat.toFixed(6)}</td></tr>`,r&&(a+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(a+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),a+="</table>",a+="</div>",this._activePopup=new Fs.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(n).setHTML(a).addTo(t);const l=this._activePopup.getElement();l&&(l.style.zIndex="1000")},t.on("click",this._mapClickHandler)}_updatePickable(){if(this._deckOverlay){for(const[,t]of this._cogLayerPropsMap)t.pickable=this._state.pickable;this._rebuildLayers()}}async _rebuildLayers(){if(this._deckOverlay)try{const{COGLayer:t}=await Promise.resolve().then(()=>require("./index-BKl7PKZI.cjs"));this._patchCOGLayerForFloat(t),this._patchCOGLayerForOpacity(t);const e=[];for(const[n,s]of this._cogLayerPropsMap){const r=new t(s);this._cogLayers.set(n,r),e.push(r)}this._deckOverlay.setProps({layers:e})}catch(t){console.error("Failed to rebuild layers:",t)}}async _registerCommonProjections(t){t.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"),t.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(t){let e=null;return Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")).then(n=>{e=n.default||n,typeof e=="function"&&this._registerCommonProjections(e)}),async n=>{try{const s=t.toProj4(n);if(s&&s.proj4){let r=s.proj4;if(r=r.replace(/\+axis=\w+\s*/g,""),!e){const l=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs"));e=l.default||l,typeof e=="function"&&await this._registerCommonProjections(e)}let a={};if(typeof e=="function")try{e.defs("custom",r),a=e.defs("custom")||{}}catch{}return{def:r,parsed:a,coordinatesUnits:s.coordinatesUnits||"metre"}}}catch{}return null}}_patchCOGLayerForFloat(t){if(t.__floatPatched)return;t.__floatPatched=!0;const e=t.prototype._parseGeoTIFF;t.prototype._parseGeoTIFF=async function(){try{await e.call(this);const n=this.props._nodata;if(n!=null&&!isNaN(n)){const{FilterNoDataVal:s}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),r=this.state.defaultRenderTile;if(typeof r=="function"){const a=l=>{const g=r(l).filter(m=>m.module!==s);return g.splice(1,0,{module:s,props:{value:n}}),g};this.setState({defaultRenderTile:a})}}}catch(n){if(!(n instanceof Error?n.message:String(n)).includes("non-unsigned integers not yet supported"))throw n;const{fromUrl:r}=await Promise.resolve().then(()=>require("./geotiff-CvcEZK4N.cjs")).then(it=>it.geotiff),{parseCOGTileMatrixSet:a,texture:l}=await Promise.resolve().then(()=>require("./index-BKl7PKZI.cjs")),{CreateTexture:h,FilterNoDataVal:g}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),m=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")),y=m.default||m,x=this.props.geotiff,A=typeof x=="string"?await r(x):x,S=this.props.geoKeysParser,T=await a(A,S),k=await A.getImage(),L=await A.getImageCount(),N=[];for(let it=0;it<L;it++)N.push(await A.getImage(it));const z=await S(k.getGeoKeys());if(!z)throw new Error("Could not determine source projection from GeoTIFF geo keys");const j=y(z.def,"EPSG:4326"),Y=(it,rt)=>j.forward([it,rt],!1),J=(it,rt)=>j.inverse([it,rt],!1);if(this.props.onGeoTIFFLoad){const it=k.getBoundingBox(),rt=[j.forward([it[0],it[1]]),j.forward([it[2],it[1]]),j.forward([it[2],it[3]]),j.forward([it[0],it[3]])],dt=rt.map(At=>At[0]),pt=rt.map(At=>At[1]),Ct={west:Math.min(...dt),south:Math.min(...pt),east:Math.max(...dt),north:Math.max(...pt)};this.props.onGeoTIFFLoad(A,{projection:z,geographicBounds:Ct})}const ut=k.getFileDirectory(),{BitsPerSample:D,SampleFormat:U,SamplesPerPixel:H,GDAL_NODATA:K}=ut;let et=null;if(K){const it=K[K.length-1]==="\0"?K.slice(0,-1):K;it.length>0&&(et=parseFloat(it))}const lt=async(it,rt)=>{const{device:dt}=rt,pt=await it.readRasters({...rt,interleave:!0});let Ct=pt,At=H;if(H===3){const Vt=pt.width*pt.height,xt=new Float32Array(Vt*4);for(let oe=0;oe<Vt;oe++)xt[oe*4]=pt[oe*3],xt[oe*4+1]=pt[oe*3+1],xt[oe*4+2]=pt[oe*3+2],xt[oe*4+3]=1;Ct=xt,Ct.width=pt.width,Ct.height=pt.height,At=4}const St=l.inferTextureFormat(At,D,U);return{texture:dt.createTexture({data:Ct,format:St,width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width}},nt=this;let $=null,F=null;const{Colormap:W}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),X=it=>{const rt=[{module:h,props:{textureName:it.texture}}],dt=nt.props._nodata!==void 0&&nt.props._nodata!==null&&!isNaN(nt.props._nodata)?nt.props._nodata:et;dt!==null&&rt.push({module:g,props:{value:dt}});const pt=nt.props._rescaleMin??0,Ct=nt.props._rescaleMax??255;rt.push({module:lz,props:{minVal:pt,maxVal:Ct,isSingleBand:H===1?1:0}});const At=nt.props._colormap;if(At&&At!=="none"){if(At!==$){const St=ls(At),Kt=uz(St);F=nt.context.device.createTexture({data:Kt.data,format:"rgba8unorm",width:Kt.width,height:Kt.height,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}}),$=At}rt.push({module:W,props:{colormapTexture:F}})}return rt};this.setState({metadata:T,forwardReproject:Y,inverseReproject:J,images:N,defaultGetTileData:lt,defaultRenderTile:X})}}}_patchCOGLayerForOpacity(t){if(t.__opacityPatched)return;t.__opacityPatched=!0;const e=t.prototype._renderSubLayers;t.prototype._renderSubLayers=function(...n){const s=e.apply(this,n),r=this.props.opacity;return r==null?s:lT(s,Math.max(0,Math.min(1,r)))}}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:t}=await Promise.resolve().then(()=>require("./index-BKl7PKZI.cjs"));this._patchCOGLayerForFloat(t),this._patchCOGLayerForOpacity(t);const e=this._map,n={geotiff: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,...(()=>{if(this._options.beforeId){if(e.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:g,south:m,east:y,north:x}=h.geographicBounds;e.fitBounds([[g,m],[y,x]],{padding:50,duration:1e3})}}catch{}}};try{const l=await Promise.resolve().then(()=>require("./main-dist-Bymiy5aM.cjs")),h=l.default||l;h&&typeof h.toProj4=="function"&&(n.geoKeysParser=this._buildGeoKeysParser(h))}catch{}const s=`cog-layer-${this._layerCounter++}`;n.id=s;const r=this._state.layerName?.trim();r&&(n._layerName=r),this._cogLayerPropsMap.set(s,n);const a=new t(n);this._cogLayers.set(s,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:s})}catch(t){this._state.loading=!1,this._state.error=`Failed to load COG: ${t instanceof Error?t.message:String(t)}`,this._render(),this._emit("error",{error:this._state.error})}}_removeLayer(t){t?(this._cogLayers.delete(t),this._cogLayerPropsMap.delete(t),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:t})):(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 t=this._state.layerOpacity;for(const[e,n]of this._cogLayers)typeof n.clone=="function"&&this._cogLayers.set(e,n.clone({opacity:t}));this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._map&&this._map.triggerRepaint()}_buildLayerInfoList(){const t=[];for(const[e,n]of this._cogLayerPropsMap)t.push({id:e,name:n._layerName||void 0,url:n.geotiff,bands:"1",colormap:n._colormap||"none",rescaleMin:n._rescaleMin??0,rescaleMax:n._rescaleMax??255,nodata:n._nodata,opacity:n.opacity??1});return t}}const pz={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},gz='<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>',Mf="maplibre-minimap-viewport",mz="maplibre-minimap-viewport-fill",_z="maplibre-minimap-viewport-line";class cT{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_minimapMap;_handleMove;_handleZoom;_zoomVisible=!0;_isDragging=!1;_dragStartLngLat;_dragCleanup;constructor(t){this._options={...pz,...t},this._state={visible:this._options.visible,collapsed:this._options.collapsed}}getDefaultPosition(){return this._options.position}onAdd(t){return this._map=t,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(t,e){return this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e),this}off(t,e){return this._eventHandlers.get(t)?.delete(e),this}_emit(t){const e=this._eventHandlers.get(t);if(e){const n={type:t,state:this.getState()};e.forEach(s=>s(n))}}_createContainer(){const t=document.createElement("div");return t.classList.add("maplibregl-ctrl","maplibre-gl-minimap-control"),this._options.className&&t.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=gz,this._button.addEventListener("click",()=>this.toggle()),t.appendChild(this._button)),t}_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 t=document.createElement("div");t.className="minimap-map",this._panel.appendChild(t),this._container.appendChild(this._panel);const e=this._map.getCenter(),n=this._map.getZoom(),s=Math.max(0,n+this._options.zoomOffset);if(this._minimapMap=new Fs.Map({container:t,style:this._options.style,center:e,zoom:s,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 a=null,l=!1,h=null;const g=x=>{if(!this._minimapMap||!this._map)return;x.preventDefault(),this._isDragging=!0,l=!1,a={x:x.clientX,y:x.clientY},r.style.cursor="grabbing";const A=r.getBoundingClientRect(),S=x.clientX-A.left,T=x.clientY-A.top;this._dragStartLngLat=this._minimapMap.unproject([S,T]),h=this._map.getCenter()},m=x=>{if(!this._isDragging||!this._minimapMap||!this._map||!this._dragStartLngLat||!h)return;if(a&&!l){const z=x.clientX-a.x,j=x.clientY-a.y;(Math.abs(z)>3||Math.abs(j)>3)&&(l=!0)}if(!l)return;const A=r.getBoundingClientRect(),S=x.clientX-A.left,T=x.clientY-A.top,k=this._minimapMap.unproject([S,T]),L=k.lng-this._dragStartLngLat.lng,N=k.lat-this._dragStartLngLat.lat;this._map.setCenter([h.lng+L,h.lat+N]),this._updateViewportRect()},y=x=>{if(this._isDragging&&!l&&this._minimapMap&&this._map){const A=r.getBoundingClientRect(),S=x.clientX-A.left,T=x.clientY-A.top,k=this._minimapMap.unproject([S,T]);this._map.flyTo({center:k})}this._isDragging=!1,l=!1,a=null,h=null,this._dragStartLngLat=void 0,r.style.cursor="pointer",this._syncMinimap(),this._updateViewportRect()};r.addEventListener("mousedown",g),document.addEventListener("mousemove",m),document.addEventListener("mouseup",y),this._dragCleanup=()=>{r.removeEventListener("mousedown",g),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",y)}}}_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 t=this._map.getCenter(),e=Math.max(0,this._map.getZoom()+this._options.zoomOffset);this._minimapMap.jumpTo({center:t,zoom:e})}_addViewportRect(){this._minimapMap&&(this._minimapMap.addSource(Mf,{type:"geojson",data:{type:"Feature",geometry:{type:"Polygon",coordinates:[[]]},properties:{}}}),this._minimapMap.addLayer({id:mz,type:"fill",source:Mf,paint:{"fill-color":this._options.viewportRectColor,"fill-opacity":this._options.viewportRectOpacity}}),this._minimapMap.addLayer({id:_z,type:"line",source:Mf,paint:{"line-color":this._options.viewportRectColor,"line-width":2}}))}_updateViewportRect(){if(!this._minimapMap||!this._map)return;const t=this._minimapMap.getSource(Mf);if(!t||!("setData"in t))return;const e=this._map.getBounds(),n=e.getSouthWest(),s=e.getNorthEast(),r=e.getNorthWest(),a=e.getSouthEast(),l=[[n.lng,n.lat],[a.lng,a.lat],[s.lng,s.lat],[r.lng,r.lat],[n.lng,n.lat]];t.setData({type:"Feature",geometry:{type:"Polygon",coordinates:[l]},properties:{}})}_checkZoomVisibility(){if(!this._map||!this._container)return;const t=this._map.getZoom(),e=this._zoomVisible;this._zoomVisible=t>=this._options.minzoom&&t<=this._options.maxzoom,e!==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}}}const yz={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:"rgba(255, 255, 255, 0.95)",borderRadius:4,opacity:1,fontSize:12,fontColor:"#333",minzoom:0,maxzoom:24},Zw='<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>',Yw='<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>',qw='<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>',Jw='<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>',vz='<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>',fl={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}},Ac={"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 bz(i,t){const n=i.lat*Math.PI/180,s=t.lat*Math.PI/180,r=(t.lat-i.lat)*Math.PI/180,a=(t.lng-i.lng)*Math.PI/180,l=Math.sin(r/2)*Math.sin(r/2)+Math.cos(n)*Math.cos(s)*Math.sin(a/2)*Math.sin(a/2);return 6371e3*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))}function wz(i){if(i.length<3)return 0;const t=6371e3;let e=0;for(let n=0;n<i.length;n++){const s=(n+1)%i.length,r=i[n].lat*Math.PI/180,a=i[s].lat*Math.PI/180,l=i[n].lng*Math.PI/180,h=i[s].lng*Math.PI/180;e+=(h-l)*(2+Math.sin(r)+Math.sin(a))}return e=Math.abs(e*t*t/2),e}class uT{_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(t){this._options={...yz,...t},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 e=fo("measure");this._sourceId=`${e}-source`,this._lineLayerId=`${e}-line`,this._fillLayerId=`${e}-fill`}onAdd(t){return this._map=t,this._container=this._createContainer(),t.isStyleLoaded()?this._setupMapSources():t.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(t,e){return this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e),this}off(t,e){return this._eventHandlers.get(t)?.delete(e),this}_emit(t,e){const n=this._eventHandlers.get(t);if(n){const s={type:t,state:{...this._state},...e};n.forEach(r=>r(s))}}_createContainer(){const t=document.createElement("div");return t.className=`maplibregl-ctrl maplibre-gl-measure-control ${this._options.className}`,t.style.opacity=String(this._options.opacity),this._state.visible||(t.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=Zw,this._button.addEventListener("click",()=>this._togglePanel()),t.appendChild(this._button),t}_createPanel(){const t=document.createElement("div");t.className=`measure-panel ${this._options.position.includes("left")?"right":"left"}`,t.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(t.style.maxHeight=`${this._options.maxHeight}px`,t.style.overflowY="auto"),t.style.background=this._options.backgroundColor,t.style.borderRadius=`${this._options.borderRadius}px`,t.style.fontSize=`${this._options.fontSize}px`,t.style.color=this._options.fontColor;const e=document.createElement("div");e.className="measure-header",e.innerHTML=`
107
107
  <span>Measure</span>
108
108
  <button type="button" class="measure-close" title="Close">${Jw}</button>
109
109
  `,e.querySelector(".measure-close")?.addEventListener("click",()=>this._togglePanel()),t.appendChild(e);const n=document.createElement("div");n.className="measure-content";const s=document.createElement("div");s.className="measure-mode-toggle",s.innerHTML=`
@@ -223,12 +223,12 @@
223
223
  </div>
224
224
  <div><strong>Date:</strong> ${this._state.stacItem.properties?.datetime||"N/A"}</div>
225
225
  <div><strong>Assets:</strong> ${this._state.assets.length} available</div>
226
- `,t.appendChild(h)}if(this._cogLayers.size>0){const h=document.createElement("div");h.className="maplibre-gl-stac-layer-list";const g=document.createElement("div");g.className="maplibre-gl-stac-layer-list-header",g.textContent=`Layers (${this._cogLayers.size})`,h.appendChild(g);for(const[m]of this._cogLayers){const y=document.createElement("div");y.className="maplibre-gl-stac-layer-list-item";const x=document.createElement("span");x.className="maplibre-gl-stac-layer-list-label";const S=this._cogLayerPropsMap.get(m)?._layerName;x.textContent=S||m,x.title=m,y.appendChild(x);const T=document.createElement("button");T.className="maplibre-gl-stac-layer-list-remove",T.innerHTML="×",T.title="Remove layer",T.addEventListener("click",()=>{this._removeLayer(m),this._render()}),y.appendChild(T),h.appendChild(y)}t.appendChild(h)}this._container.appendChild(t),this._panel=t,this._button=void 0}_createFormGroup(t,e){const n=document.createElement("div");n.className="maplibre-gl-stac-layer-form-group";const s=document.createElement("label");return s.textContent=t,s.htmlFor=`stac-layer-${e}`,n.appendChild(s),n}_appendStatus(t,e,n){const s=document.createElement("div");s.className=`maplibre-gl-stac-layer-status maplibre-gl-stac-layer-status--${n}`,s.textContent=e,t.appendChild(s)}_autoSetRescale(){if(!this._state.selectedAsset)return;const t=this._state.assets.find(n=>n.key===this._state.selectedAsset);if(!t)return;const e=t.dataType?.toLowerCase();e==="uint16"?(this._state.rescaleMin=0,this._state.rescaleMax=1e4):e==="int16"?(this._state.rescaleMin=-32768,this._state.rescaleMax=32767):e==="float32"||e==="float64"?(this._state.rescaleMin=0,this._state.rescaleMax=1):e==="uint8"&&(this._state.rescaleMin=0,this._state.rescaleMax=255)}_updateColormapPreview(){const t=this._colormapPreview;if(!t)return;if(this._state.colormap==="none"){t.style.display="none";return}const e=ls(this._state.colormap);if(e&&e.length>0){const n=e.map(s=>s.color).join(", ");t.style.background=`linear-gradient(to right, ${n})`,t.style.display="block"}else t.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 t=await fetch(this._state.stacUrl);if(!t.ok)throw new Error(`Failed to fetch: ${t.status} ${t.statusText}`);const e=await t.text(),n=JSON.parse(e);if(n.type!=="Feature"||!n.assets)throw new Error("Invalid STAC item: missing 'type: Feature' or 'assets'");this._state.stacItem=n;const s=[],r=e.match(/"assets"\s*:\s*\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}/);if(r){const g=r[1].matchAll(/"([^"]+)"\s*:\s*\{/g);for(const m of g)s.push(m[1])}const a=s.length>0?s:Object.keys(n.assets),l=[];for(const h of a){const g=n.assets[h];if(!g)continue;const m=g;if(m.type?.includes("geotiff")||m.type?.includes("image/tiff")||m.href?.endsWith(".tif")||m.href?.endsWith(".tiff")){const y=m["raster:bands"]?.[0],x=m["eo:bands"]?.[0];l.push({key:h,href:m.href,type:m.type||"image/tiff",title:m.title||h,dataType:y?.data_type||m.data_type,nodata:y?.nodata??m.nodata,scale:y?.scale,offset:y?.offset,centerWavelength:x?.center_wavelength,commonName:x?.common_name})}}l.sort((h,g)=>h.centerWavelength!==void 0&&g.centerWavelength!==void 0?h.centerWavelength-g.centerWavelength:h.centerWavelength!==void 0?-1:g.centerWavelength!==void 0?1:0),this._state.assets=l,this._state.loading=!1,this._state.status=`Found ${l.length} COG asset(s)`,this._emit("stacload",{url:this._state.stacUrl})}catch(t){this._state.loading=!1,this._state.error=`Failed to load STAC: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:t}=await Promise.resolve().then(()=>require("./index-CY8LNC10.cjs"));this._deckOverlay=new t({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const t=this._map;this._mapClickHandler=e=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:n}=e,s=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(s[0]);let a='<div class="maplibre-gl-stac-layer-popup">';a+='<table class="maplibre-gl-stac-layer-popup-table">',a+=`<tr><td><strong>Layers</strong></td><td>${s.length} STAC layer(s)</td></tr>`,a+=`<tr><td><strong>Lng</strong></td><td>${n.lng.toFixed(6)}</td></tr>`,a+=`<tr><td><strong>Lat</strong></td><td>${n.lat.toFixed(6)}</td></tr>`,r&&(a+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(a+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),a+="</table></div>",this._activePopup=new Fs.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(n).setHTML(a).addTo(t);const l=this._activePopup.getElement();l&&(l.style.zIndex="1000")},t.on("click",this._mapClickHandler)}async _addLayer(){if(!this._map){this._state.error="Map not available.",this._render();return}if(this._state.rgbMode){const[e,n,s]=this._state.rgbAssets;if(!e||!n||!s){this._state.error="Please select assets for all RGB bands.",this._render();return}const r=this._state.assets.find(h=>h.key===e),a=this._state.assets.find(h=>h.key===n),l=this._state.assets.find(h=>h.key===s);if(!r||!a||!l){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:h}=await Promise.resolve().then(()=>require("./index-Bv__sxtP.cjs")),{fromUrl:g}=await Promise.resolve().then(()=>require("./geotiff-BIFT8xS3.cjs")).then(K=>K.geotiff);this._patchCOGLayer(h);const m=`stac-${this._state.stacItem?.id||"layer"}-rgb-${this._layerCounter++}`,[y,x,A]=await Promise.all([g(r.href),g(a.href),g(l.href)]),S=await y.getImageCount(),T=await x.getImageCount(),k=await A.getImageCount(),L=[],N=[],z=[];for(let K=0;K<S;K++)L.push(await y.getImage(K));for(let K=0;K<T;K++)N.push(await x.getImage(K));for(let K=0;K<k;K++)z.push(await A.getImage(K));const j=this._state.rescaleMin,Y=this._state.rescaleMax,J=Y-j,ut={id:m,geotiff:y,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:j,_rescaleMax:Y,_isRgb:!0,_preRescaled:!0,getTileData:async(K,et)=>{const{window:lt,pool:nt,device:$}=et,F=K.getWidth(),W=K.getHeight();let X=N[0],it=z[0];for(const Wt of N)if(Wt.getWidth()===F&&Wt.getHeight()===W){X=Wt;break}for(const Wt of z)if(Wt.getWidth()===F&&Wt.getHeight()===W){it=Wt;break}const rt={window:lt,pool:nt,interleave:!1},[dt,pt,Ct]=await Promise.all([K.readRasters(rt),X.readRasters(rt),it.readRasters(rt)]),At=dt.width,St=dt.height,Kt=dt[0],Vt=pt[0],xt=Ct[0],oe=new Uint8ClampedArray(At*St*4);for(let Wt=0;Wt<At*St;Wt++){const gt=Kt[Wt],Ie=Vt[Wt],Be=xt[Wt];if(gt===0&&Ie===0&&Be===0)oe[Wt*4]=0,oe[Wt*4+1]=0,oe[Wt*4+2]=0,oe[Wt*4+3]=0;else{const ae=Math.max(0,Math.min(255,(gt-j)/J*255)),Fe=Math.max(0,Math.min(255,(Ie-j)/J*255)),on=Math.max(0,Math.min(255,(Be-j)/J*255));oe[Wt*4]=ae,oe[Wt*4+1]=Fe,oe[Wt*4+2]=on,oe[Wt*4+3]=255}}return{texture:$.createTexture({data:oe,format:"rgba8unorm",width:At,height:St,sampler:{magFilter:"nearest",minFilter:"nearest"}}),width:At,height:St,_preRescaled:!0}}},D=await this._buildGeoKeysParser();D&&(ut.geoKeysParser=D);const U=this._state.layerName?.trim();U&&(ut._layerName=U),this._cogLayerPropsMap.set(m,ut);const H=new h(ut);if(this._cogLayers.set(m,H),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[K,et,lt,nt]=this._state.stacItem.bbox;this._map.fitBounds([[K,et],[lt,nt]],{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: ${e}, ${n}, ${s}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:m,assetKey:`${e},${n},${s}`,url:r.href,layerName:U||void 0})}catch(h){this._state.loading=!1,this._state.error=`Failed to add RGB layer: ${h instanceof Error?h.message:String(h)}`,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 t=this._state.assets.find(e=>e.key===this._state.selectedAsset);if(!t){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:e}=await Promise.resolve().then(()=>require("./index-Bv__sxtP.cjs"));this._patchCOGLayer(e);const n=`stac-${this._state.stacItem?.id||"layer"}-${t.key}-${this._layerCounter++}`,s={id:n,geotiff:t.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&&(s._layerName=r);const a=await this._buildGeoKeysParser();a&&(s.geoKeysParser=a),this._cogLayerPropsMap.set(n,s);const l=new e(s);if(this._cogLayers.set(n,l),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[h,g,m,y]=this._state.stacItem.bbox;this._map.fitBounds([[h,g],[m,y]],{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: ${t.title||t.key}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:n,assetKey:t.key,url:t.href,layerName:r||void 0})}catch(e){this._state.loading=!1,this._state.error=`Failed to add layer: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_updateOpacity(){if(!this._deckOverlay)return;for(const[,e]of this._cogLayerPropsMap)e.opacity=this._state.layerOpacity;const t=Array.from(this._cogLayers.entries()).map(([e])=>{const n=this._cogLayerPropsMap.get(e);return this._cogLayers.get(e).clone(n)});this._deckOverlay.setProps({layers:t})}_updateRescaleAndColormap(){if(!this._deckOverlay||this._cogLayers.size===0)return;for(const[,e]of this._cogLayerPropsMap)e._isRgb||(e._rescaleMin=this._state.rescaleMin,e._rescaleMax=this._state.rescaleMax,e._colormap=this._state.colormap);const t=Array.from(this._cogLayers.entries()).map(([e])=>{const n=this._cogLayerPropsMap.get(e);return this._cogLayers.get(e).clone(n)});this._deckOverlay.setProps({layers:t})}_removeLayer(t){this._map&&(this._cogLayers.delete(t),this._cogLayerPropsMap.delete(t),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:t}))}_removeAllLayers(){for(const[t]of this._cogLayers)this._removeLayer(t)}_patchCOGLayer(t){if(t.__stacPatched)return;t.__stacPatched=!0;const e=t.prototype._renderSubLayers;t.prototype._renderSubLayers=function(...n){const s=e.apply(this,n),r=this.props.opacity;return r==null?s:gT(s,Math.max(0,Math.min(1,r)))},t.prototype._parseGeoTIFF=async function(){const{fromUrl:n}=await Promise.resolve().then(()=>require("./geotiff-BIFT8xS3.cjs")).then(it=>it.geotiff),{parseCOGTileMatrixSet:s,texture:r}=await Promise.resolve().then(()=>require("./index-Bv__sxtP.cjs")),{CreateTexture:a,FilterNoDataVal:l,Colormap:h}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),g=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")),m=g.default||g,y=this.props.geotiff,x=typeof y=="string"?await n(y):y,A=this.props.geoKeysParser;let S;try{S=await s(x,A)}catch{S=await s(x,void 0)}const T=await x.getImage(),k=await x.getImageCount(),L=[];for(let it=0;it<k;it++)L.push(await x.getImage(it));const N=A?await A(T.getGeoKeys()):null;let z=null,j=null;if(N&&typeof m=="function"){const it=m(N.def,"EPSG:4326");if(z=(rt,dt)=>it.forward([rt,dt],!1),j=(rt,dt)=>it.inverse([rt,dt],!1),this.props.onGeoTIFFLoad){const rt=T.getBoundingBox(),dt=[it.forward([rt[0],rt[1]]),it.forward([rt[2],rt[1]]),it.forward([rt[2],rt[3]]),it.forward([rt[0],rt[3]])],pt=dt.map(St=>St[0]),Ct=dt.map(St=>St[1]),At={west:Math.min(...pt),south:Math.min(...Ct),east:Math.max(...pt),north:Math.max(...Ct)};this.props.onGeoTIFFLoad(x,{projection:N,geographicBounds:At})}}const Y=T.getFileDirectory(),{BitsPerSample:J,SampleFormat:ut,SamplesPerPixel:D,GDAL_NODATA:U}=Y;let H=null;if(U){const it=U[U.length-1]==="\0"?U.slice(0,-1):U;it.length>0&&(H=parseFloat(it))}const K=this,et=K.props._rescaleMin??0,lt=K.props._rescaleMax??1e4,nt=async(it,rt)=>{const{device:dt}=rt,pt=await it.readRasters({...rt,interleave:!0}),Ct=typeof J=="object"&&J?.[0]!==void 0?J[0]:J,At=pt.width*pt.height;if(D===1&&Ct===16){const Vt=new Uint8ClampedArray(At*4),xt=lt-et,oe=K.props._colormap;let $t=null;oe&&oe!=="none"&&($t=ls(oe));for(let gt=0;gt<At;gt++){const Ie=pt[gt];if(Ie===0||Ie===H)Vt[gt*4]=0,Vt[gt*4+1]=0,Vt[gt*4+2]=0,Vt[gt*4+3]=0;else{const Be=Math.max(0,Math.min(1,(Ie-et)/xt));if($t){const ae=$z($t,Be);Vt[gt*4]=ae[0],Vt[gt*4+1]=ae[1],Vt[gt*4+2]=ae[2],Vt[gt*4+3]=255}else{const ae=Math.round(Be*255);Vt[gt*4]=ae,Vt[gt*4+1]=ae,Vt[gt*4+2]=ae,Vt[gt*4+3]=255}}}return{texture:dt.createTexture({data:Vt,format:"rgba8unorm",width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width,_preRescaled:!0,_colormapApplied:!!$t}}if(D===3){const Vt=new Uint8ClampedArray(At*4);for(let oe=0;oe<At;oe++){const $t=pt[oe*3],Wt=pt[oe*3+1],gt=pt[oe*3+2];$t===0&&Wt===0&&gt===0?(Vt[oe*4]=0,Vt[oe*4+1]=0,Vt[oe*4+2]=0,Vt[oe*4+3]=0):(Vt[oe*4]=$t,Vt[oe*4+1]=Wt,Vt[oe*4+2]=gt,Vt[oe*4+3]=255)}return{texture:dt.createTexture({data:Vt,format:"rgba8unorm",width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width,_preRescaled:!0}}const St=r.inferTextureFormat(D,J,ut);return{texture:dt.createTexture({data:pt,format:St,width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width}},$=this;let F=null,W=null;const X=it=>{const rt=[{module:a,props:{textureName:it.texture}}];if(!it._preRescaled){H!==null&&rt.push({module:l,props:{value:H}});const pt=$.props._rescaleMin??0,Ct=$.props._rescaleMax??255;rt.push({module:zz,props:{minVal:pt,maxVal:Ct,isSingleBand:D===1?1:0}})}const dt=$.props._colormap;if(dt&&dt!=="none"&&!it._colormapApplied){if(dt!==F){const pt=ls(dt),Ct=Vz(pt);W=$.context.device.createTexture({data:Ct.data,format:"rgba8unorm",width:Ct.width,height:Ct.height,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}}),F=dt}rt.push({module:h,props:{colormapTexture:W}})}return rt};$.setState({metadata:S,forwardReproject:z,inverseReproject:j,images:L,defaultGetTileData:nt,defaultRenderTile:X})}}async _registerCommonProjections(t){t.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"),t.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 t=await Promise.resolve().then(()=>require("./main-dist-Bymiy5aM.cjs")),e=t.default||t;if(!e||typeof e.toProj4!="function")return console.warn("geotiff-geokeys-to-proj4 not available or invalid"),null;const n=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")),s=n.default||n;return typeof s=="function"&&await this._registerCommonProjections(s),async r=>{try{const a=e.toProj4(r);if(a&&a.proj4){let l=a.proj4;l=l.replace(/\+axis=\w+\s*/g,"");let h={};if(typeof s=="function")try{s.defs("custom",l),h=s.defs("custom")||{}}catch(g){console.error("STAC proj4 parsing error:",g)}return{def:l,parsed:h,coordinatesUnits:a.coordinatesUnits||"metre"}}}catch(a){console.error("STAC geoKeysParser error:",a)}return null}}catch(t){return console.error("STAC _buildGeoKeysParser error:",t),null}}}const jz=[{name:"Element84 Earth Search",url:"https://earth-search.aws.element84.com/v1"},{name:"Microsoft Planetary Computer",url:"https://planetarycomputer.microsoft.com/api/stac/v1"}],Xz=["viridis","plasma","inferno","magma","cividis","coolwarm","bwr","seismic","RdBu","RdYlBu","RdYlGn","spectral","jet","rainbow","turbo","terrain","ocean","hot","cool","gray","bone"],Zz={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:jz,maxItems:20,defaultRescaleMin:0,defaultRescaleMax:1e4,defaultColormap:"viridis",defaultRgbMode:!0,showFootprints:!0,minzoom:0,maxzoom:24},Yz=`<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">
226
+ `,t.appendChild(h)}if(this._cogLayers.size>0){const h=document.createElement("div");h.className="maplibre-gl-stac-layer-list";const g=document.createElement("div");g.className="maplibre-gl-stac-layer-list-header",g.textContent=`Layers (${this._cogLayers.size})`,h.appendChild(g);for(const[m]of this._cogLayers){const y=document.createElement("div");y.className="maplibre-gl-stac-layer-list-item";const x=document.createElement("span");x.className="maplibre-gl-stac-layer-list-label";const S=this._cogLayerPropsMap.get(m)?._layerName;x.textContent=S||m,x.title=m,y.appendChild(x);const T=document.createElement("button");T.className="maplibre-gl-stac-layer-list-remove",T.innerHTML="×",T.title="Remove layer",T.addEventListener("click",()=>{this._removeLayer(m),this._render()}),y.appendChild(T),h.appendChild(y)}t.appendChild(h)}this._container.appendChild(t),this._panel=t,this._button=void 0}_createFormGroup(t,e){const n=document.createElement("div");n.className="maplibre-gl-stac-layer-form-group";const s=document.createElement("label");return s.textContent=t,s.htmlFor=`stac-layer-${e}`,n.appendChild(s),n}_appendStatus(t,e,n){const s=document.createElement("div");s.className=`maplibre-gl-stac-layer-status maplibre-gl-stac-layer-status--${n}`,s.textContent=e,t.appendChild(s)}_autoSetRescale(){if(!this._state.selectedAsset)return;const t=this._state.assets.find(n=>n.key===this._state.selectedAsset);if(!t)return;const e=t.dataType?.toLowerCase();e==="uint16"?(this._state.rescaleMin=0,this._state.rescaleMax=1e4):e==="int16"?(this._state.rescaleMin=-32768,this._state.rescaleMax=32767):e==="float32"||e==="float64"?(this._state.rescaleMin=0,this._state.rescaleMax=1):e==="uint8"&&(this._state.rescaleMin=0,this._state.rescaleMax=255)}_updateColormapPreview(){const t=this._colormapPreview;if(!t)return;if(this._state.colormap==="none"){t.style.display="none";return}const e=ls(this._state.colormap);if(e&&e.length>0){const n=e.map(s=>s.color).join(", ");t.style.background=`linear-gradient(to right, ${n})`,t.style.display="block"}else t.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 t=await fetch(this._state.stacUrl);if(!t.ok)throw new Error(`Failed to fetch: ${t.status} ${t.statusText}`);const e=await t.text(),n=JSON.parse(e);if(n.type!=="Feature"||!n.assets)throw new Error("Invalid STAC item: missing 'type: Feature' or 'assets'");this._state.stacItem=n;const s=[],r=e.match(/"assets"\s*:\s*\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}/);if(r){const g=r[1].matchAll(/"([^"]+)"\s*:\s*\{/g);for(const m of g)s.push(m[1])}const a=s.length>0?s:Object.keys(n.assets),l=[];for(const h of a){const g=n.assets[h];if(!g)continue;const m=g;if(m.type?.includes("geotiff")||m.type?.includes("image/tiff")||m.href?.endsWith(".tif")||m.href?.endsWith(".tiff")){const y=m["raster:bands"]?.[0],x=m["eo:bands"]?.[0];l.push({key:h,href:m.href,type:m.type||"image/tiff",title:m.title||h,dataType:y?.data_type||m.data_type,nodata:y?.nodata??m.nodata,scale:y?.scale,offset:y?.offset,centerWavelength:x?.center_wavelength,commonName:x?.common_name})}}l.sort((h,g)=>h.centerWavelength!==void 0&&g.centerWavelength!==void 0?h.centerWavelength-g.centerWavelength:h.centerWavelength!==void 0?-1:g.centerWavelength!==void 0?1:0),this._state.assets=l,this._state.loading=!1,this._state.status=`Found ${l.length} COG asset(s)`,this._emit("stacload",{url:this._state.stacUrl})}catch(t){this._state.loading=!1,this._state.error=`Failed to load STAC: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:t}=await Promise.resolve().then(()=>require("./index-BwXW8_tL.cjs"));this._deckOverlay=new t({interleaved:!!this._options.beforeId,layers:[]}),this._map.addControl(this._deckOverlay)}_setupClickHandler(){if(!this._map||this._mapClickHandler)return;const t=this._map;this._mapClickHandler=e=>{if(!this._state.pickable||this._cogLayers.size===0)return;this._activePopup&&this._activePopup.remove();const{lngLat:n}=e,s=Array.from(this._cogLayers.keys()),r=this._cogLayerPropsMap.get(s[0]);let a='<div class="maplibre-gl-stac-layer-popup">';a+='<table class="maplibre-gl-stac-layer-popup-table">',a+=`<tr><td><strong>Layers</strong></td><td>${s.length} STAC layer(s)</td></tr>`,a+=`<tr><td><strong>Lng</strong></td><td>${n.lng.toFixed(6)}</td></tr>`,a+=`<tr><td><strong>Lat</strong></td><td>${n.lat.toFixed(6)}</td></tr>`,r&&(a+=`<tr><td><strong>Rescale</strong></td><td>${r._rescaleMin} - ${r._rescaleMax}</td></tr>`,r._colormap&&r._colormap!=="none"&&(a+=`<tr><td><strong>Colormap</strong></td><td>${r._colormap}</td></tr>`)),a+="</table></div>",this._activePopup=new Fs.Popup({closeButton:!0,maxWidth:"280px"}).setLngLat(n).setHTML(a).addTo(t);const l=this._activePopup.getElement();l&&(l.style.zIndex="1000")},t.on("click",this._mapClickHandler)}async _addLayer(){if(!this._map){this._state.error="Map not available.",this._render();return}if(this._state.rgbMode){const[e,n,s]=this._state.rgbAssets;if(!e||!n||!s){this._state.error="Please select assets for all RGB bands.",this._render();return}const r=this._state.assets.find(h=>h.key===e),a=this._state.assets.find(h=>h.key===n),l=this._state.assets.find(h=>h.key===s);if(!r||!a||!l){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:h}=await Promise.resolve().then(()=>require("./index-BKl7PKZI.cjs")),{fromUrl:g}=await Promise.resolve().then(()=>require("./geotiff-CvcEZK4N.cjs")).then(K=>K.geotiff);this._patchCOGLayer(h);const m=`stac-${this._state.stacItem?.id||"layer"}-rgb-${this._layerCounter++}`,[y,x,A]=await Promise.all([g(r.href),g(a.href),g(l.href)]),S=await y.getImageCount(),T=await x.getImageCount(),k=await A.getImageCount(),L=[],N=[],z=[];for(let K=0;K<S;K++)L.push(await y.getImage(K));for(let K=0;K<T;K++)N.push(await x.getImage(K));for(let K=0;K<k;K++)z.push(await A.getImage(K));const j=this._state.rescaleMin,Y=this._state.rescaleMax,J=Y-j,ut={id:m,geotiff:y,opacity:this._state.layerOpacity,pickable:this._state.pickable,_rescaleMin:j,_rescaleMax:Y,_isRgb:!0,_preRescaled:!0,getTileData:async(K,et)=>{const{window:lt,pool:nt,device:$}=et,F=K.getWidth(),W=K.getHeight();let X=N[0],it=z[0];for(const Wt of N)if(Wt.getWidth()===F&&Wt.getHeight()===W){X=Wt;break}for(const Wt of z)if(Wt.getWidth()===F&&Wt.getHeight()===W){it=Wt;break}const rt={window:lt,pool:nt,interleave:!1},[dt,pt,Ct]=await Promise.all([K.readRasters(rt),X.readRasters(rt),it.readRasters(rt)]),At=dt.width,St=dt.height,Kt=dt[0],Vt=pt[0],xt=Ct[0],oe=new Uint8ClampedArray(At*St*4);for(let Wt=0;Wt<At*St;Wt++){const gt=Kt[Wt],Ie=Vt[Wt],Be=xt[Wt];if(gt===0&&Ie===0&&Be===0)oe[Wt*4]=0,oe[Wt*4+1]=0,oe[Wt*4+2]=0,oe[Wt*4+3]=0;else{const ae=Math.max(0,Math.min(255,(gt-j)/J*255)),Fe=Math.max(0,Math.min(255,(Ie-j)/J*255)),on=Math.max(0,Math.min(255,(Be-j)/J*255));oe[Wt*4]=ae,oe[Wt*4+1]=Fe,oe[Wt*4+2]=on,oe[Wt*4+3]=255}}return{texture:$.createTexture({data:oe,format:"rgba8unorm",width:At,height:St,sampler:{magFilter:"nearest",minFilter:"nearest"}}),width:At,height:St,_preRescaled:!0}}},D=await this._buildGeoKeysParser();D&&(ut.geoKeysParser=D);const U=this._state.layerName?.trim();U&&(ut._layerName=U),this._cogLayerPropsMap.set(m,ut);const H=new h(ut);if(this._cogLayers.set(m,H),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[K,et,lt,nt]=this._state.stacItem.bbox;this._map.fitBounds([[K,et],[lt,nt]],{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: ${e}, ${n}, ${s}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:m,assetKey:`${e},${n},${s}`,url:r.href,layerName:U||void 0})}catch(h){this._state.loading=!1,this._state.error=`Failed to add RGB layer: ${h instanceof Error?h.message:String(h)}`,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 t=this._state.assets.find(e=>e.key===this._state.selectedAsset);if(!t){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:e}=await Promise.resolve().then(()=>require("./index-BKl7PKZI.cjs"));this._patchCOGLayer(e);const n=`stac-${this._state.stacItem?.id||"layer"}-${t.key}-${this._layerCounter++}`,s={id:n,geotiff:t.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&&(s._layerName=r);const a=await this._buildGeoKeysParser();a&&(s.geoKeysParser=a),this._cogLayerPropsMap.set(n,s);const l=new e(s);if(this._cogLayers.set(n,l),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())}),this._state.stacItem?.bbox){const[h,g,m,y]=this._state.stacItem.bbox;this._map.fitBounds([[h,g],[m,y]],{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: ${t.title||t.key}`,this._state.layerName="",this._render(),this._emit("layeradd",{layerId:n,assetKey:t.key,url:t.href,layerName:r||void 0})}catch(e){this._state.loading=!1,this._state.error=`Failed to add layer: ${e instanceof Error?e.message:String(e)}`,this._render(),this._emit("error",{error:this._state.error})}}_updateOpacity(){if(!this._deckOverlay)return;for(const[,e]of this._cogLayerPropsMap)e.opacity=this._state.layerOpacity;const t=Array.from(this._cogLayers.entries()).map(([e])=>{const n=this._cogLayerPropsMap.get(e);return this._cogLayers.get(e).clone(n)});this._deckOverlay.setProps({layers:t})}_updateRescaleAndColormap(){if(!this._deckOverlay||this._cogLayers.size===0)return;for(const[,e]of this._cogLayerPropsMap)e._isRgb||(e._rescaleMin=this._state.rescaleMin,e._rescaleMax=this._state.rescaleMax,e._colormap=this._state.colormap);const t=Array.from(this._cogLayers.entries()).map(([e])=>{const n=this._cogLayerPropsMap.get(e);return this._cogLayers.get(e).clone(n)});this._deckOverlay.setProps({layers:t})}_removeLayer(t){this._map&&(this._cogLayers.delete(t),this._cogLayerPropsMap.delete(t),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:t}))}_removeAllLayers(){for(const[t]of this._cogLayers)this._removeLayer(t)}_patchCOGLayer(t){if(t.__stacPatched)return;t.__stacPatched=!0;const e=t.prototype._renderSubLayers;t.prototype._renderSubLayers=function(...n){const s=e.apply(this,n),r=this.props.opacity;return r==null?s:gT(s,Math.max(0,Math.min(1,r)))},t.prototype._parseGeoTIFF=async function(){const{fromUrl:n}=await Promise.resolve().then(()=>require("./geotiff-CvcEZK4N.cjs")).then(it=>it.geotiff),{parseCOGTileMatrixSet:s,texture:r}=await Promise.resolve().then(()=>require("./index-BKl7PKZI.cjs")),{CreateTexture:a,FilterNoDataVal:l,Colormap:h}=await Promise.resolve().then(()=>require("./index-B-Nr9y7J.cjs")),g=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")),m=g.default||g,y=this.props.geotiff,x=typeof y=="string"?await n(y):y,A=this.props.geoKeysParser;let S;try{S=await s(x,A)}catch{S=await s(x,void 0)}const T=await x.getImage(),k=await x.getImageCount(),L=[];for(let it=0;it<k;it++)L.push(await x.getImage(it));const N=A?await A(T.getGeoKeys()):null;let z=null,j=null;if(N&&typeof m=="function"){const it=m(N.def,"EPSG:4326");if(z=(rt,dt)=>it.forward([rt,dt],!1),j=(rt,dt)=>it.inverse([rt,dt],!1),this.props.onGeoTIFFLoad){const rt=T.getBoundingBox(),dt=[it.forward([rt[0],rt[1]]),it.forward([rt[2],rt[1]]),it.forward([rt[2],rt[3]]),it.forward([rt[0],rt[3]])],pt=dt.map(St=>St[0]),Ct=dt.map(St=>St[1]),At={west:Math.min(...pt),south:Math.min(...Ct),east:Math.max(...pt),north:Math.max(...Ct)};this.props.onGeoTIFFLoad(x,{projection:N,geographicBounds:At})}}const Y=T.getFileDirectory(),{BitsPerSample:J,SampleFormat:ut,SamplesPerPixel:D,GDAL_NODATA:U}=Y;let H=null;if(U){const it=U[U.length-1]==="\0"?U.slice(0,-1):U;it.length>0&&(H=parseFloat(it))}const K=this,et=K.props._rescaleMin??0,lt=K.props._rescaleMax??1e4,nt=async(it,rt)=>{const{device:dt}=rt,pt=await it.readRasters({...rt,interleave:!0}),Ct=typeof J=="object"&&J?.[0]!==void 0?J[0]:J,At=pt.width*pt.height;if(D===1&&Ct===16){const Vt=new Uint8ClampedArray(At*4),xt=lt-et,oe=K.props._colormap;let $t=null;oe&&oe!=="none"&&($t=ls(oe));for(let gt=0;gt<At;gt++){const Ie=pt[gt];if(Ie===0||Ie===H)Vt[gt*4]=0,Vt[gt*4+1]=0,Vt[gt*4+2]=0,Vt[gt*4+3]=0;else{const Be=Math.max(0,Math.min(1,(Ie-et)/xt));if($t){const ae=$z($t,Be);Vt[gt*4]=ae[0],Vt[gt*4+1]=ae[1],Vt[gt*4+2]=ae[2],Vt[gt*4+3]=255}else{const ae=Math.round(Be*255);Vt[gt*4]=ae,Vt[gt*4+1]=ae,Vt[gt*4+2]=ae,Vt[gt*4+3]=255}}}return{texture:dt.createTexture({data:Vt,format:"rgba8unorm",width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width,_preRescaled:!0,_colormapApplied:!!$t}}if(D===3){const Vt=new Uint8ClampedArray(At*4);for(let oe=0;oe<At;oe++){const $t=pt[oe*3],Wt=pt[oe*3+1],gt=pt[oe*3+2];$t===0&&Wt===0&&gt===0?(Vt[oe*4]=0,Vt[oe*4+1]=0,Vt[oe*4+2]=0,Vt[oe*4+3]=0):(Vt[oe*4]=$t,Vt[oe*4+1]=Wt,Vt[oe*4+2]=gt,Vt[oe*4+3]=255)}return{texture:dt.createTexture({data:Vt,format:"rgba8unorm",width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width,_preRescaled:!0}}const St=r.inferTextureFormat(D,J,ut);return{texture:dt.createTexture({data:pt,format:St,width:pt.width,height:pt.height,sampler:{magFilter:"nearest",minFilter:"nearest"}}),height:pt.height,width:pt.width}},$=this;let F=null,W=null;const X=it=>{const rt=[{module:a,props:{textureName:it.texture}}];if(!it._preRescaled){H!==null&&rt.push({module:l,props:{value:H}});const pt=$.props._rescaleMin??0,Ct=$.props._rescaleMax??255;rt.push({module:zz,props:{minVal:pt,maxVal:Ct,isSingleBand:D===1?1:0}})}const dt=$.props._colormap;if(dt&&dt!=="none"&&!it._colormapApplied){if(dt!==F){const pt=ls(dt),Ct=Vz(pt);W=$.context.device.createTexture({data:Ct.data,format:"rgba8unorm",width:Ct.width,height:Ct.height,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}}),F=dt}rt.push({module:h,props:{colormapTexture:W}})}return rt};$.setState({metadata:S,forwardReproject:z,inverseReproject:j,images:L,defaultGetTileData:nt,defaultRenderTile:X})}}async _registerCommonProjections(t){t.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"),t.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 t=await Promise.resolve().then(()=>require("./main-dist-Bymiy5aM.cjs")),e=t.default||t;if(!e||typeof e.toProj4!="function")return console.warn("geotiff-geokeys-to-proj4 not available or invalid"),null;const n=await Promise.resolve().then(()=>require("./index-IrsIiQNM.cjs")),s=n.default||n;return typeof s=="function"&&await this._registerCommonProjections(s),async r=>{try{const a=e.toProj4(r);if(a&&a.proj4){let l=a.proj4;l=l.replace(/\+axis=\w+\s*/g,"");let h={};if(typeof s=="function")try{s.defs("custom",l),h=s.defs("custom")||{}}catch(g){console.error("STAC proj4 parsing error:",g)}return{def:l,parsed:h,coordinatesUnits:a.coordinatesUnits||"metre"}}}catch(a){console.error("STAC geoKeysParser error:",a)}return null}}catch(t){return console.error("STAC _buildGeoKeysParser error:",t),null}}}const jz=[{name:"Element84 Earth Search",url:"https://earth-search.aws.element84.com/v1"},{name:"Microsoft Planetary Computer",url:"https://planetarycomputer.microsoft.com/api/stac/v1"}],Xz=["viridis","plasma","inferno","magma","cividis","coolwarm","bwr","seismic","RdBu","RdYlBu","RdYlGn","spectral","jet","rainbow","turbo","terrain","ocean","hot","cool","gray","bone"],Zz={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:jz,maxItems:20,defaultRescaleMin:0,defaultRescaleMax:1e4,defaultColormap:"viridis",defaultRgbMode:!0,showFootprints:!0,minzoom:0,maxzoom:24},Yz=`<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">
227
227
  <circle cx="11" cy="11" r="8"/>
228
228
  <path d="m21 21-4.3-4.3"/>
229
229
  <path d="M11 8v6"/>
230
230
  <path d="M8 11h6"/>
231
- </svg>`;class _T{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_footprintSourceId="stac-search-footprints";_footprintLayerId="stac-search-footprints-layer";_footprintOutlineLayerId="stac-search-footprints-outline";_footprintHighlightLayerId="stac-search-footprints-highlight";_footprintHighlightOutlineLayerId="stac-search-footprints-highlight-outline";_showCustomUrlInput=!1;_deckOverlay;_cogLayers=new Map;_layerCounter=0;constructor(t){this._options={...Zz,...t},this._state={visible:this._options.visible,collapsed:this._options.collapsed,catalogs:this._options.catalogs,selectedCatalog:this._options.catalogs.length>0?this._options.catalogs[0]:null,collections:[],selectedCollection:null,startDate:null,endDate:null,maxItems:this._options.maxItems,queryFilter:"",items:[],selectedItem:null,rescaleMin:this._options.defaultRescaleMin,rescaleMax:this._options.defaultRescaleMax,isRgbMode:this._options.defaultRgbMode,colormap:this._options.defaultColormap,availableAssets:[],selectedBand:null,rgbBands:{r:null,g:null,b:null},hasLayer:!1,loading:!1,error:null,status:null}}onAdd(t){return this._map=t,this._container=this._createContainer(),this._render(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._container}onRemove(){if(this._removeFootprints(),this._removeAllLayers(),this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=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}getDefaultPosition(){return this._options.position}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()}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",{}))}getState(){return{...this._state}}update(t){this._options={...this._options,...t},t.visible!==void 0&&(this._state.visible=t.visible),t.collapsed!==void 0&&(this._state.collapsed=t.collapsed),t.catalogs&&(this._state.catalogs=t.catalogs,t.catalogs.length>0&&!this._state.selectedCatalog&&(this._state.selectedCatalog=t.catalogs[0])),this._render()}on(t,e){this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e)}off(t,e){this._eventHandlers.get(t)?.delete(e)}getSelectedItem(){return this._state.selectedItem}getItems(){return[...this._state.items]}_emit(t,e){const n=this._eventHandlers.get(t);if(!n)return;const s={type:t,state:this._state,...e};for(const r of n)r(s)}_checkZoomVisibility(){if(!this._map)return;const t=this._map.getZoom(),e=this._zoomVisible;this._zoomVisible=t>=this._options.minzoom&&t<=this._options.maxzoom,e!==this._zoomVisible&&this._updateDisplayState()}_updateDisplayState(){if(!this._container)return;const t=this._state.visible&&this._zoomVisible;this._container.style.display=t?"block":"none"}_createContainer(){const t=document.createElement("div");return t.className=`maplibregl-ctrl maplibre-gl-stac-search ${this._options.className||""}`,this._options.backgroundColor&&(t.style.background=this._options.backgroundColor),this._options.borderRadius!==void 0&&(t.style.borderRadius=`${this._options.borderRadius}px`),this._options.opacity!==1&&(t.style.opacity=String(this._options.opacity)),t}_render(){if(!this._container)return;const e=this._container.querySelector(".maplibre-gl-stac-search-panel")?.scrollTop??0;if(this._container.innerHTML="",this._state.collapsed)this._renderCollapsed();else{this._renderExpanded();const n=this._container.querySelector(".maplibre-gl-stac-search-panel");n&&e>0&&(n.scrollTop=e)}}_renderCollapsed(){if(!this._container)return;const t=document.createElement("button");t.className=`maplibre-gl-stac-search-button${this._state.hasLayer?" maplibre-gl-stac-search-button--active":""}`,t.innerHTML=Yz,t.title="STAC Search",t.addEventListener("click",()=>this.expand()),this._container.appendChild(t),this._button=t}_renderExpanded(){if(!this._container)return;const t=document.createElement("div");t.className="maplibre-gl-stac-search-panel",t.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(t.style.maxHeight=`${this._options.maxHeight}px`,t.style.overflowY="auto"),this._options.fontSize&&(t.style.fontSize=`${this._options.fontSize}px`),this._options.fontColor&&(t.style.color=this._options.fontColor);const e=document.createElement("div");e.className="maplibre-gl-stac-search-header";const n=document.createElement("span");n.className="maplibre-gl-stac-search-title",n.textContent="STAC Search",e.appendChild(n);const s=document.createElement("button");s.className="maplibre-gl-stac-search-close",s.innerHTML="×",s.addEventListener("click",()=>this.collapse()),e.appendChild(s),t.appendChild(e);const r=this._createFormGroup("Catalog","catalog"),a=document.createElement("select");a.id="stac-search-catalog",a.className="maplibre-gl-stac-search-select",a.style.color="#000";for(const U of this._state.catalogs){const H=document.createElement("option");H.value=U.url,H.textContent=U.name,H.selected=this._state.selectedCatalog?.url===U.url,a.appendChild(H)}const l=document.createElement("option");if(l.value="__custom__",l.textContent="── Custom URL ──",l.selected=this._showCustomUrlInput||this._state.selectedCatalog?.name==="__custom__",a.appendChild(l),a.addEventListener("change",()=>{if(a.value==="__custom__"){this._showCustomUrlInput=!0,this._render();return}this._showCustomUrlInput=!1;const U=this._state.catalogs.find(H=>H.url===a.value);U&&(this._state.selectedCatalog=U,this._state.collections=[],this._state.selectedCollection=null,this._state.items=[],this._state.selectedItem=null,this._emit("catalogselect",{catalog:U}),this._render())}),r.appendChild(a),this._showCustomUrlInput||this._state.selectedCatalog?.name==="__custom__"){const U=document.createElement("div");U.className="maplibre-gl-stac-search-custom-url-row";const H=document.createElement("input");H.type="text",H.id="stac-search-custom-url",H.className="maplibre-gl-stac-search-input",H.style.color="#000",H.placeholder="https://stac-api.example.com/v1",H.value=this._state.selectedCatalog?.name==="__custom__"?this._state.selectedCatalog.url:"";const K=document.createElement("button");K.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--secondary",K.textContent="Use",K.addEventListener("click",()=>{const et=H.value.trim();et&&(this._showCustomUrlInput=!1,this._state.selectedCatalog={name:"__custom__",url:et},this._state.collections=[],this._state.selectedCollection=null,this._state.items=[],this._state.selectedItem=null,this._emit("catalogselect",{catalog:this._state.selectedCatalog}),this._render())}),U.appendChild(H),U.appendChild(K),r.appendChild(U)}t.appendChild(r);const h=this._createFormGroup("Collection","collection"),g=document.createElement("div");g.className="maplibre-gl-stac-search-row";const m=document.createElement("button");m.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--secondary",m.textContent="Collections",m.disabled=this._state.loading||!this._state.selectedCatalog,m.addEventListener("click",()=>this._fetchCollections()),g.appendChild(m);const y=document.createElement("select");if(y.id="stac-search-collection",y.className="maplibre-gl-stac-search-select maplibre-gl-stac-search-select--flex",y.style.color="#000",y.disabled=this._state.collections.length===0,this._state.collections.length===0){const U=document.createElement("option");U.value="",U.textContent="-- Click Collections --",y.appendChild(U)}else for(const U of this._state.collections){const H=document.createElement("option");H.value=U.id,H.textContent=U.title||U.id,H.selected=this._state.selectedCollection?.id===U.id,y.appendChild(H)}y.addEventListener("change",()=>{const U=this._state.collections.find(H=>H.id===y.value);U&&(this._state.selectedCollection=U,this._state.items=[],this._state.selectedItem=null,this._emit("collectionselect",{collection:U}),this._render())}),g.appendChild(y),h.appendChild(g),t.appendChild(h);const x=this._createFormGroup("Date Range","date"),A=document.createElement("div");A.className="maplibre-gl-stac-search-date-row";const S=document.createElement("input");S.type="date",S.id="stac-search-start-date",S.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",S.style.color="#000",S.value=this._state.startDate||"",S.addEventListener("change",()=>{this._state.startDate=S.value||null});const T=document.createElement("input");T.type="date",T.id="stac-search-end-date",T.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",T.style.color="#000",T.value=this._state.endDate||"",T.addEventListener("change",()=>{this._state.endDate=T.value||null}),A.appendChild(S),A.appendChild(T),x.appendChild(A),t.appendChild(x);const k=this._createFormGroup("Max Items","maxitems"),L=document.createElement("input");L.type="number",L.id="stac-search-maxitems",L.className="maplibre-gl-stac-search-input",L.style.color="#000",L.min="1",L.max="100",L.value=String(this._state.maxItems),L.addEventListener("change",()=>{this._state.maxItems=Math.max(1,Math.min(100,Number(L.value)||20))}),k.appendChild(L),t.appendChild(k);const N=this._createFormGroup("Query Filter (optional)","query"),z=document.createElement("input");z.type="text",z.id="stac-search-query",z.className="maplibre-gl-stac-search-input",z.style.color="#000",z.placeholder='{"eo:cloud_cover": {"lt": 10}}',z.value=this._state.queryFilter,z.addEventListener("change",()=>{this._state.queryFilter=z.value.trim()}),N.appendChild(z);const j=document.createElement("div");j.className="maplibre-gl-stac-search-hint",j.textContent="JSON filter, e.g., cloud cover < 10%",N.appendChild(j),t.appendChild(N);const Y=document.createElement("div");Y.className="maplibre-gl-stac-search-form-group";const J=document.createElement("button");J.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--primary",J.textContent="Search Items",J.disabled=this._state.loading||!this._state.selectedCollection,J.addEventListener("click",()=>this._searchItems()),Y.appendChild(J);const ut=document.createElement("div");ut.className="maplibre-gl-stac-search-hint-row";const D=document.createElement("div");if(D.className="maplibre-gl-stac-search-hint",D.textContent="Uses current map bounds",ut.appendChild(D),this._state.items.length>0){const U=document.createElement("button");U.className="maplibre-gl-stac-search-btn-clear-footprints",U.textContent="Clear Footprints",U.title="Remove footprints from map",U.addEventListener("click",()=>{this._removeFootprints(),this._state.items=[],this._state.selectedItem=null,this._render()}),ut.appendChild(U)}if(Y.appendChild(ut),t.appendChild(Y),this._state.items.length>0){const U=this._createFormGroup("Select Item","item"),H=document.createElement("select");H.id="stac-search-item",H.className="maplibre-gl-stac-search-select",H.style.color="#000";for(const pt of this._state.items){const Ct=document.createElement("option");Ct.value=pt.id;const At=pt.datetime?new Date(pt.datetime).toLocaleDateString():"";Ct.textContent=`${pt.id}${At?` (${At})`:""}`,Ct.selected=this._state.selectedItem?.id===pt.id,H.appendChild(Ct)}H.addEventListener("change",()=>{const pt=this._state.items.find(Ct=>Ct.id===H.value);pt&&(this._state.selectedItem=pt,this._updateAvailableAssets(pt),this._updateFootprintHighlight(),this._emit("itemselect",{item:pt}),this._render())}),U.appendChild(H),t.appendChild(U);const K=this._createFormGroup("Visualization Mode","mode"),et=document.createElement("div");et.className="maplibre-gl-stac-search-mode-row";const lt=document.createElement("button");lt.className=`maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--toggle ${this._state.isRgbMode?"":"active"}`,lt.textContent="Single Band",lt.addEventListener("click",()=>{this._state.isRgbMode=!1,this._render()});const nt=document.createElement("button");nt.className=`maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--toggle ${this._state.isRgbMode?"active":""}`,nt.textContent="RGB Composite",nt.addEventListener("click",()=>{this._state.isRgbMode=!0,this._render()}),et.appendChild(lt),et.appendChild(nt),K.appendChild(et),t.appendChild(K);const $=this._state.availableAssets;if(this._state.isRgbMode){const pt=this._createFormGroup("RGB Bands","rgb"),Ct=document.createElement("div");Ct.className="maplibre-gl-stac-search-rgb-row";const At=[{key:"r",label:"R"},{key:"g",label:"G"},{key:"b",label:"B"}];for(const St of At){const Kt=document.createElement("div");Kt.className="maplibre-gl-stac-search-rgb-channel";const Vt=document.createElement("label");Vt.textContent=St.label,Vt.className="maplibre-gl-stac-search-rgb-label",Kt.appendChild(Vt);const xt=document.createElement("select");xt.className="maplibre-gl-stac-search-select maplibre-gl-stac-search-select--small",xt.style.color="#000";for(const oe of $){const $t=document.createElement("option");$t.value=oe,$t.textContent=oe,$t.selected=this._state.rgbBands[St.key]===oe,xt.appendChild($t)}xt.addEventListener("change",()=>{this._state.rgbBands[St.key]=xt.value}),Kt.appendChild(xt),Ct.appendChild(Kt)}pt.appendChild(Ct),t.appendChild(pt)}else{const pt=this._createFormGroup("Band","band"),Ct=document.createElement("select");Ct.id="stac-search-band",Ct.className="maplibre-gl-stac-search-select",Ct.style.color="#000";for(const Vt of $){const xt=document.createElement("option");xt.value=Vt,xt.textContent=Vt,xt.selected=this._state.selectedBand===Vt,Ct.appendChild(xt)}Ct.addEventListener("change",()=>{this._state.selectedBand=Ct.value}),pt.appendChild(Ct),t.appendChild(pt);const At=this._createFormGroup("Colormap","colormap"),St=document.createElement("select");St.id="stac-search-colormap",St.className="maplibre-gl-stac-search-select",St.style.color="#000";const Kt=document.createElement("option");Kt.value="none",Kt.textContent="None (Grayscale)",Kt.selected=this._state.colormap==="none",St.appendChild(Kt);for(const Vt of Xz){const xt=document.createElement("option");xt.value=Vt,xt.textContent=Vt,xt.selected=this._state.colormap===Vt,St.appendChild(xt)}St.addEventListener("change",()=>{this._state.colormap=St.value}),At.appendChild(St),t.appendChild(At)}const F=this._createFormGroup("Rescale Range","rescale"),W=document.createElement("div");W.className="maplibre-gl-stac-search-rescale-row";const X=document.createElement("input");X.type="number",X.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",X.style.color="#000",X.placeholder="Min",X.value=String(this._state.rescaleMin),X.addEventListener("change",()=>{this._state.rescaleMin=Number(X.value)||0});const it=document.createElement("input");it.type="number",it.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",it.style.color="#000",it.placeholder="Max",it.value=String(this._state.rescaleMax),it.addEventListener("change",()=>{this._state.rescaleMax=Number(it.value)||1e4}),W.appendChild(X),W.appendChild(it),F.appendChild(W),t.appendChild(F);const rt=document.createElement("div");rt.className="maplibre-gl-stac-search-form-group";const dt=document.createElement("button");dt.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--primary",dt.textContent="Display Item",dt.disabled=this._state.loading||!this._state.selectedItem,dt.addEventListener("click",()=>this._displayItem()),rt.appendChild(dt),t.appendChild(rt)}if(this._state.loading?this._appendStatus(t,"Loading...","info"):this._state.error?this._appendStatus(t,this._state.error,"error"):this._state.status&&this._appendStatus(t,this._state.status,"success"),this._cogLayers.size>0){const U=document.createElement("div");U.className="maplibre-gl-stac-search-list";const H=document.createElement("div");H.className="maplibre-gl-stac-search-list-header-row";const K=document.createElement("div");K.className="maplibre-gl-stac-search-list-header",K.textContent=`Layers (${this._cogLayers.size})`,H.appendChild(K);const et=document.createElement("button");et.className="maplibre-gl-stac-search-btn-clear",et.textContent="Clear All",et.title="Remove all layers",et.addEventListener("click",()=>{this._removeAllLayers(),this._render()}),H.appendChild(et),U.appendChild(H);for(const[lt]of this._cogLayers){const nt=document.createElement("div");nt.className="maplibre-gl-stac-search-list-item";const $=document.createElement("span");$.className="maplibre-gl-stac-search-list-label",$.textContent=lt,nt.appendChild($);const F=document.createElement("button");F.className="maplibre-gl-stac-search-list-remove",F.innerHTML="×",F.title="Remove layer",F.addEventListener("click",()=>{this._removeLayer(lt),this._render()}),nt.appendChild(F),U.appendChild(nt)}t.appendChild(U)}this._container.appendChild(t),this._panel=t,this._button=void 0}_createFormGroup(t,e){const n=document.createElement("div");n.className="maplibre-gl-stac-search-form-group";const s=document.createElement("label");return s.textContent=t,s.htmlFor=`stac-search-${e}`,n.appendChild(s),n}_appendStatus(t,e,n){const s=document.createElement("div");s.className=`maplibre-gl-stac-search-status maplibre-gl-stac-search-status--${n}`,s.textContent=e,t.appendChild(s)}async _fetchCollections(){if(!this._state.selectedCatalog){this._state.error="Please select a catalog.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{const t=`${this._state.selectedCatalog.url}/collections`,e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch: ${e.status} ${e.statusText}`);const s=((await e.json()).collections||[]).map(r=>({id:r.id,title:r.title,description:r.description}));s.sort((r,a)=>{const l=r.title||r.id,h=a.title||a.id;return l.localeCompare(h)}),this._state.collections=s,this._state.selectedCollection=s.length>0?s[0]:null,this._state.loading=!1,this._state.status=`Found ${s.length} collection(s)`,this._emit("collectionsload",{})}catch(t){this._state.loading=!1,this._state.error=`Failed to load collections: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}async _searchItems(){if(!this._state.selectedCatalog||!this._state.selectedCollection){this._state.error="Please select a catalog and collection.",this._render();return}if(!this._map){this._state.error="Map not available.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{const t=this._map.getBounds(),e=[t.getWest(),t.getSouth(),t.getEast(),t.getNorth()],n=`${this._state.selectedCatalog.url}/search`,s={collections:[this._state.selectedCollection.id],bbox:e,limit:this._state.maxItems};if(this._state.startDate||this._state.endDate){const h=this._state.startDate||"1900-01-01",g=this._state.endDate||new Date().toISOString().split("T")[0];s.datetime=`${h}T00:00:00Z/${g}T23:59:59Z`}if(this._state.queryFilter)try{const h=JSON.parse(this._state.queryFilter);s.query=h}catch{console.warn("Invalid query filter JSON:",this._state.queryFilter)}const r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!r.ok)throw new Error(`Search failed: ${r.status} ${r.statusText}`);const a=await r.json(),l=(a.features||[]).map(h=>{const g=h.links?.find(m=>m.rel==="self")?.href;return{id:h.id,datetime:h.properties?.datetime,geometry:h.geometry,bbox:h.bbox,selfLink:g,properties:h.properties,assets:h.assets}});this._state.items=l,this._state.selectedItem=l.length>0?l[0]:null,this._state.selectedItem&&this._updateAvailableAssets(this._state.selectedItem),this._state.loading=!1,this._state.status=`Found ${l.length} item(s)`,this._emit("search",{}),this._options.showFootprints&&l.length>0&&this._addFootprints(a.features||[])}catch(t){this._state.loading=!1,this._state.error=`Search failed: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}_addFootprints(t){if(!this._map)return;this._removeFootprints();const e={type:"FeatureCollection",features:t.map(n=>({type:"Feature",geometry:n.geometry,properties:{id:n.id,datetime:n.properties?.datetime}}))};this._map.addSource(this._footprintSourceId,{type:"geojson",data:e}),this._map.addLayer({id:this._footprintLayerId,type:"fill",source:this._footprintSourceId,paint:{"fill-color":"#0078d7","fill-opacity":.1}}),this._map.addLayer({id:this._footprintOutlineLayerId,type:"line",source:this._footprintSourceId,paint:{"line-color":"#0078d7","line-width":2}}),this._map.addLayer({id:this._footprintHighlightLayerId,type:"fill",source:this._footprintSourceId,paint:{"fill-color":"#ff6b00","fill-opacity":.3},filter:["==",["get","id"],""]}),this._map.addLayer({id:this._footprintHighlightOutlineLayerId,type:"line",source:this._footprintSourceId,paint:{"line-color":"#ff6b00","line-width":3},filter:["==",["get","id"],""]}),this._updateFootprintHighlight(),this._map.on("click",this._footprintLayerId,n=>{if(n.features&&n.features.length>0){const s=n.features[0].properties?.id,r=this._state.items.find(a=>a.id===s);r&&(this._state.selectedItem=r,this._updateFootprintHighlight(),this._emit("itemselect",{item:r}),this._render())}}),this._map.on("mouseenter",this._footprintLayerId,()=>{this._map&&(this._map.getCanvas().style.cursor="pointer")}),this._map.on("mouseleave",this._footprintLayerId,()=>{this._map&&(this._map.getCanvas().style.cursor="")})}_removeFootprints(){this._map&&(this._map.getLayer(this._footprintHighlightOutlineLayerId)&&this._map.removeLayer(this._footprintHighlightOutlineLayerId),this._map.getLayer(this._footprintHighlightLayerId)&&this._map.removeLayer(this._footprintHighlightLayerId),this._map.getLayer(this._footprintOutlineLayerId)&&this._map.removeLayer(this._footprintOutlineLayerId),this._map.getLayer(this._footprintLayerId)&&this._map.removeLayer(this._footprintLayerId),this._map.getSource(this._footprintSourceId)&&this._map.removeSource(this._footprintSourceId))}_updateAvailableAssets(t){const e=[],n=new Set(["red","green","blue","nir","nir08","nir09","swir","swir16","swir22","coastal","data","visual","image","thumbnail","overview","B01","B02","B03","B04","B05","B06","B07","B08","B8A","B09","B10","B11","B12","AOT","WVP","SCL","SR_B1","SR_B2","SR_B3","SR_B4","SR_B5","SR_B6","SR_B7","ST_B10","lwir","lwir11","rgbir","raster","dem","dsm","dtm","elevation"]);if(t.assets)for(const[s,r]of Object.entries(t.assets)){const a=r,l=a.href||"",h=a.type||"",g=h.includes("geotiff")||h.includes("image/tiff")||h.includes("image/")||h.includes("application/x-hdf")||l.endsWith(".tif")||l.endsWith(".tiff")||l.endsWith(".jp2"),m=n.has(s)||n.has(s.toLowerCase()),y=s.includes("metadata")||s.includes("xml")||s.includes("json")||h.includes("application/json")||h.includes("application/xml")||h.includes("text/");(g||m)&&!y&&e.push(s)}if(e.sort(),this._state.availableAssets=e,e.length>0){(!this._state.selectedBand||!e.includes(this._state.selectedBand))&&(this._state.selectedBand=e[0]);const s=this._findDefaultRgbBands(e);(!this._state.rgbBands.r||!e.includes(this._state.rgbBands.r))&&(this._state.rgbBands.r=s.r),(!this._state.rgbBands.g||!e.includes(this._state.rgbBands.g))&&(this._state.rgbBands.g=s.g),(!this._state.rgbBands.b||!e.includes(this._state.rgbBands.b))&&(this._state.rgbBands.b=s.b)}}_findDefaultRgbBands(t){const e=[{r:"B04",g:"B03",b:"B02"},{r:"red",g:"green",b:"blue"},{r:"SR_B4",g:"SR_B3",b:"SR_B2"},{r:"B4",g:"B3",b:"B2"},{r:"visual",g:"visual",b:"visual"}];for(const n of e)if(t.includes(n.r)&&t.includes(n.g)&&t.includes(n.b))return n;return{r:t[0]||"",g:t[1]||t[0]||"",b:t[2]||t[0]||""}}_updateFootprintHighlight(){if(!this._map)return;const t=this._state.selectedItem?.id||"",e=["==",["get","id"],t];this._map.getLayer(this._footprintHighlightLayerId)&&this._map.setFilter(this._footprintHighlightLayerId,e),this._map.getLayer(this._footprintHighlightOutlineLayerId)&&this._map.setFilter(this._footprintHighlightOutlineLayerId,e)}_isPlanetaryComputer(){return this._state.selectedCatalog?.url?.includes("planetarycomputer.microsoft.com")??!1}_getDefaultAssets(t){return t.includes("sentinel-2")?"B04,B03,B02":t.includes("landsat")?"red,green,blue":t.includes("naip")?"image":t.includes("aster")?"VNIR":"data"}_getDefaultRescale(t){return t.includes("sentinel-2")?"0,3000&rescale=0,3000&rescale=0,3000":t.includes("landsat")?"0,20000&rescale=0,20000&rescale=0,20000":t.includes("dem")||t.includes("elevation")||t.includes("cop-dem")?"0,4000":t.includes("naip")||t.includes("aster")?"0,255&rescale=0,255&rescale=0,255":"0,10000"}async _displayItem(){if(!this._state.selectedItem){this._state.error="Please select an item.",this._render();return}if(!this._map){this._state.error="Map not available.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{if(this._isPlanetaryComputer()&&this._state.selectedCollection){await this._displayPlanetaryComputerItem();return}let t=this._state.selectedItem.selfLink;if(!t&&this._state.selectedCatalog&&this._state.selectedCollection&&(t=`${this._state.selectedCatalog.url}/collections/${this._state.selectedCollection.id}/items/${this._state.selectedItem.id}`),!t)throw new Error("Cannot determine item URL");const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch item: ${e.status}`);const n=await e.json();let s=null,r=null;const a=["visual","true-color","rgb","thumbnail"];for(const l of a)if(n.assets?.[l]){const h=n.assets[l];if(h.type?.includes("geotiff")||h.type?.includes("image/tiff")||h.href?.endsWith(".tif")){s=l,r=h.href;break}}if(!r)for(const[l,h]of Object.entries(n.assets||{})){const g=h;if(g.type?.includes("geotiff")||g.type?.includes("image/tiff")||g.href?.endsWith(".tif")){s=l,r=g.href;break}}if(!r)throw new Error("No COG/GeoTIFF asset found in item");if(await this._addCogLayer(r,n,s||"default"),n.bbox){const[l,h,g,m]=n.bbox;this._map.fitBounds([[l,h],[g,m]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.loading=!1,this._state.status=`Displayed: ${this._state.selectedItem.id}`,this._emit("display",{item:this._state.selectedItem})}catch(t){this._state.loading=!1,this._state.error=`Failed to display: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}async _displayPlanetaryComputerItem(){if(!this._map||!this._state.selectedItem||!this._state.selectedCollection)throw new Error("Missing required state for PC display");const t=this._state.selectedCollection.id,e=this._state.selectedItem.id,n="https://planetarycomputer.microsoft.com/api/data/v1";let s,r,a="";if(this._state.isRgbMode){const{r:m,g:y,b:x}=this._state.rgbBands;if(m&&y&&x){s=`assets=${m}&assets=${y}&assets=${x}`;const A=`${this._state.rescaleMin},${this._state.rescaleMax}`;r=`rescale=${A}&rescale=${A}&rescale=${A}`}else s=this._getDefaultAssets(t).split(",").map(S=>`assets=${S}`).join("&"),r=this._getDefaultRescale(t).split("&").map(S=>S.startsWith("rescale=")?S:`rescale=${S}`).join("&")}else s=`assets=${this._state.selectedBand||"data"}`,r=`rescale=${this._state.rescaleMin},${this._state.rescaleMax}`,this._state.colormap&&this._state.colormap!=="none"&&(a=`&colormap_name=${this._state.colormap}`);const l=`${n}/item/tiles/WebMercatorQuad/{z}/{x}/{y}@1x.png?collection=${encodeURIComponent(t)}&item=${encodeURIComponent(e)}&${s}&${r}${a}`,h=`stac-search-pc-${e}-${this._layerCounter++}`,g=`${h}-source`;if(this._map.addSource(g,{type:"raster",tiles:[l],tileSize:256,attribution:"Microsoft Planetary Computer"}),this._map.addLayer({id:h,type:"raster",source:g,paint:{"raster-opacity":1}}),this._cogLayers.set(h,{sourceId:g,layerId:h,type:"raster"}),this._state.selectedItem.bbox){const[m,y,x,A]=this._state.selectedItem.bbox;this._map.fitBounds([[m,y],[x,A]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.loading=!1,this._state.status=`Displayed: ${this._state.selectedItem.id}`,this._emit("display",{item:this._state.selectedItem}),this._render()}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:t}=await Promise.resolve().then(()=>require("./index-CY8LNC10.cjs"));this._deckOverlay=new t({interleaved:!1,layers:[]}),this._map.addControl(this._deckOverlay)}_convertS3ToHttps(t){if(!t.startsWith("s3://"))return t;const e=t.match(/^s3:\/\/([^/]+)\/(.+)$/);if(!e)return t;const[,n,s]=e,a={"deafrica-sentinel-2":"af-south-1","deafrica-landsat":"af-south-1","deafrica-services":"af-south-1","dea-public-data":"ap-southeast-2","dea-public-data-dev":"ap-southeast-2"}[n]||"us-east-1";return`https://${n}.s3.${a}.amazonaws.com/${s}`}async _addCogLayer(t,e,n){await this._ensureOverlay();const s=this._convertS3ToHttps(t),{COGLayer:r}=await Promise.resolve().then(()=>require("./index-Bv__sxtP.cjs")),a=`stac-search-${e.id}-${n}-${this._layerCounter++}`,l=new r({id:a,geotiff:s,opacity:1});this._cogLayers.set(a,l),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())})}_removeLayer(t){const e=this._cogLayers.get(t);if(e&&this._map&&e.type==="raster"&&e.sourceId&&(this._map.getLayer(e.layerId)&&this._map.removeLayer(e.layerId),this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)),this._cogLayers.delete(t),this._deckOverlay){const n=Array.from(this._cogLayers.values()).filter(s=>s.type!=="raster");this._deckOverlay.setProps({layers:n})}this._state.hasLayer=this._cogLayers.size>0,this._cogLayers.size===0&&(this._state.status=null),this._render()}_removeAllLayers(){const t=Array.from(this._cogLayers.keys());for(const e of t)this._removeLayer(e);this._state.status=null,this._render()}}const qz=`<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">
231
+ </svg>`;class _T{_container;_button;_panel;_options;_state;_eventHandlers=new Map;_map;_handleZoom;_zoomVisible=!0;_footprintSourceId="stac-search-footprints";_footprintLayerId="stac-search-footprints-layer";_footprintOutlineLayerId="stac-search-footprints-outline";_footprintHighlightLayerId="stac-search-footprints-highlight";_footprintHighlightOutlineLayerId="stac-search-footprints-highlight-outline";_showCustomUrlInput=!1;_deckOverlay;_cogLayers=new Map;_layerCounter=0;constructor(t){this._options={...Zz,...t},this._state={visible:this._options.visible,collapsed:this._options.collapsed,catalogs:this._options.catalogs,selectedCatalog:this._options.catalogs.length>0?this._options.catalogs[0]:null,collections:[],selectedCollection:null,startDate:null,endDate:null,maxItems:this._options.maxItems,queryFilter:"",items:[],selectedItem:null,rescaleMin:this._options.defaultRescaleMin,rescaleMax:this._options.defaultRescaleMax,isRgbMode:this._options.defaultRgbMode,colormap:this._options.defaultColormap,availableAssets:[],selectedBand:null,rgbBands:{r:null,g:null,b:null},hasLayer:!1,loading:!1,error:null,status:null}}onAdd(t){return this._map=t,this._container=this._createContainer(),this._render(),this._handleZoom=()=>this._checkZoomVisibility(),this._map.on("zoom",this._handleZoom),this._checkZoomVisibility(),this._container}onRemove(){if(this._removeFootprints(),this._removeAllLayers(),this._map&&this._handleZoom&&(this._map.off("zoom",this._handleZoom),this._handleZoom=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}getDefaultPosition(){return this._options.position}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()}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",{}))}getState(){return{...this._state}}update(t){this._options={...this._options,...t},t.visible!==void 0&&(this._state.visible=t.visible),t.collapsed!==void 0&&(this._state.collapsed=t.collapsed),t.catalogs&&(this._state.catalogs=t.catalogs,t.catalogs.length>0&&!this._state.selectedCatalog&&(this._state.selectedCatalog=t.catalogs[0])),this._render()}on(t,e){this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e)}off(t,e){this._eventHandlers.get(t)?.delete(e)}getSelectedItem(){return this._state.selectedItem}getItems(){return[...this._state.items]}_emit(t,e){const n=this._eventHandlers.get(t);if(!n)return;const s={type:t,state:this._state,...e};for(const r of n)r(s)}_checkZoomVisibility(){if(!this._map)return;const t=this._map.getZoom(),e=this._zoomVisible;this._zoomVisible=t>=this._options.minzoom&&t<=this._options.maxzoom,e!==this._zoomVisible&&this._updateDisplayState()}_updateDisplayState(){if(!this._container)return;const t=this._state.visible&&this._zoomVisible;this._container.style.display=t?"block":"none"}_createContainer(){const t=document.createElement("div");return t.className=`maplibregl-ctrl maplibre-gl-stac-search ${this._options.className||""}`,this._options.backgroundColor&&(t.style.background=this._options.backgroundColor),this._options.borderRadius!==void 0&&(t.style.borderRadius=`${this._options.borderRadius}px`),this._options.opacity!==1&&(t.style.opacity=String(this._options.opacity)),t}_render(){if(!this._container)return;const e=this._container.querySelector(".maplibre-gl-stac-search-panel")?.scrollTop??0;if(this._container.innerHTML="",this._state.collapsed)this._renderCollapsed();else{this._renderExpanded();const n=this._container.querySelector(".maplibre-gl-stac-search-panel");n&&e>0&&(n.scrollTop=e)}}_renderCollapsed(){if(!this._container)return;const t=document.createElement("button");t.className=`maplibre-gl-stac-search-button${this._state.hasLayer?" maplibre-gl-stac-search-button--active":""}`,t.innerHTML=Yz,t.title="STAC Search",t.addEventListener("click",()=>this.expand()),this._container.appendChild(t),this._button=t}_renderExpanded(){if(!this._container)return;const t=document.createElement("div");t.className="maplibre-gl-stac-search-panel",t.style.width=`${this._options.panelWidth}px`,this._options.maxHeight&&this._options.maxHeight>0&&(t.style.maxHeight=`${this._options.maxHeight}px`,t.style.overflowY="auto"),this._options.fontSize&&(t.style.fontSize=`${this._options.fontSize}px`),this._options.fontColor&&(t.style.color=this._options.fontColor);const e=document.createElement("div");e.className="maplibre-gl-stac-search-header";const n=document.createElement("span");n.className="maplibre-gl-stac-search-title",n.textContent="STAC Search",e.appendChild(n);const s=document.createElement("button");s.className="maplibre-gl-stac-search-close",s.innerHTML="×",s.addEventListener("click",()=>this.collapse()),e.appendChild(s),t.appendChild(e);const r=this._createFormGroup("Catalog","catalog"),a=document.createElement("select");a.id="stac-search-catalog",a.className="maplibre-gl-stac-search-select",a.style.color="#000";for(const U of this._state.catalogs){const H=document.createElement("option");H.value=U.url,H.textContent=U.name,H.selected=this._state.selectedCatalog?.url===U.url,a.appendChild(H)}const l=document.createElement("option");if(l.value="__custom__",l.textContent="── Custom URL ──",l.selected=this._showCustomUrlInput||this._state.selectedCatalog?.name==="__custom__",a.appendChild(l),a.addEventListener("change",()=>{if(a.value==="__custom__"){this._showCustomUrlInput=!0,this._render();return}this._showCustomUrlInput=!1;const U=this._state.catalogs.find(H=>H.url===a.value);U&&(this._state.selectedCatalog=U,this._state.collections=[],this._state.selectedCollection=null,this._state.items=[],this._state.selectedItem=null,this._emit("catalogselect",{catalog:U}),this._render())}),r.appendChild(a),this._showCustomUrlInput||this._state.selectedCatalog?.name==="__custom__"){const U=document.createElement("div");U.className="maplibre-gl-stac-search-custom-url-row";const H=document.createElement("input");H.type="text",H.id="stac-search-custom-url",H.className="maplibre-gl-stac-search-input",H.style.color="#000",H.placeholder="https://stac-api.example.com/v1",H.value=this._state.selectedCatalog?.name==="__custom__"?this._state.selectedCatalog.url:"";const K=document.createElement("button");K.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--secondary",K.textContent="Use",K.addEventListener("click",()=>{const et=H.value.trim();et&&(this._showCustomUrlInput=!1,this._state.selectedCatalog={name:"__custom__",url:et},this._state.collections=[],this._state.selectedCollection=null,this._state.items=[],this._state.selectedItem=null,this._emit("catalogselect",{catalog:this._state.selectedCatalog}),this._render())}),U.appendChild(H),U.appendChild(K),r.appendChild(U)}t.appendChild(r);const h=this._createFormGroup("Collection","collection"),g=document.createElement("div");g.className="maplibre-gl-stac-search-row";const m=document.createElement("button");m.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--secondary",m.textContent="Collections",m.disabled=this._state.loading||!this._state.selectedCatalog,m.addEventListener("click",()=>this._fetchCollections()),g.appendChild(m);const y=document.createElement("select");if(y.id="stac-search-collection",y.className="maplibre-gl-stac-search-select maplibre-gl-stac-search-select--flex",y.style.color="#000",y.disabled=this._state.collections.length===0,this._state.collections.length===0){const U=document.createElement("option");U.value="",U.textContent="-- Click Collections --",y.appendChild(U)}else for(const U of this._state.collections){const H=document.createElement("option");H.value=U.id,H.textContent=U.title||U.id,H.selected=this._state.selectedCollection?.id===U.id,y.appendChild(H)}y.addEventListener("change",()=>{const U=this._state.collections.find(H=>H.id===y.value);U&&(this._state.selectedCollection=U,this._state.items=[],this._state.selectedItem=null,this._emit("collectionselect",{collection:U}),this._render())}),g.appendChild(y),h.appendChild(g),t.appendChild(h);const x=this._createFormGroup("Date Range","date"),A=document.createElement("div");A.className="maplibre-gl-stac-search-date-row";const S=document.createElement("input");S.type="date",S.id="stac-search-start-date",S.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",S.style.color="#000",S.value=this._state.startDate||"",S.addEventListener("change",()=>{this._state.startDate=S.value||null});const T=document.createElement("input");T.type="date",T.id="stac-search-end-date",T.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",T.style.color="#000",T.value=this._state.endDate||"",T.addEventListener("change",()=>{this._state.endDate=T.value||null}),A.appendChild(S),A.appendChild(T),x.appendChild(A),t.appendChild(x);const k=this._createFormGroup("Max Items","maxitems"),L=document.createElement("input");L.type="number",L.id="stac-search-maxitems",L.className="maplibre-gl-stac-search-input",L.style.color="#000",L.min="1",L.max="100",L.value=String(this._state.maxItems),L.addEventListener("change",()=>{this._state.maxItems=Math.max(1,Math.min(100,Number(L.value)||20))}),k.appendChild(L),t.appendChild(k);const N=this._createFormGroup("Query Filter (optional)","query"),z=document.createElement("input");z.type="text",z.id="stac-search-query",z.className="maplibre-gl-stac-search-input",z.style.color="#000",z.placeholder='{"eo:cloud_cover": {"lt": 10}}',z.value=this._state.queryFilter,z.addEventListener("change",()=>{this._state.queryFilter=z.value.trim()}),N.appendChild(z);const j=document.createElement("div");j.className="maplibre-gl-stac-search-hint",j.textContent="JSON filter, e.g., cloud cover < 10%",N.appendChild(j),t.appendChild(N);const Y=document.createElement("div");Y.className="maplibre-gl-stac-search-form-group";const J=document.createElement("button");J.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--primary",J.textContent="Search Items",J.disabled=this._state.loading||!this._state.selectedCollection,J.addEventListener("click",()=>this._searchItems()),Y.appendChild(J);const ut=document.createElement("div");ut.className="maplibre-gl-stac-search-hint-row";const D=document.createElement("div");if(D.className="maplibre-gl-stac-search-hint",D.textContent="Uses current map bounds",ut.appendChild(D),this._state.items.length>0){const U=document.createElement("button");U.className="maplibre-gl-stac-search-btn-clear-footprints",U.textContent="Clear Footprints",U.title="Remove footprints from map",U.addEventListener("click",()=>{this._removeFootprints(),this._state.items=[],this._state.selectedItem=null,this._render()}),ut.appendChild(U)}if(Y.appendChild(ut),t.appendChild(Y),this._state.items.length>0){const U=this._createFormGroup("Select Item","item"),H=document.createElement("select");H.id="stac-search-item",H.className="maplibre-gl-stac-search-select",H.style.color="#000";for(const pt of this._state.items){const Ct=document.createElement("option");Ct.value=pt.id;const At=pt.datetime?new Date(pt.datetime).toLocaleDateString():"";Ct.textContent=`${pt.id}${At?` (${At})`:""}`,Ct.selected=this._state.selectedItem?.id===pt.id,H.appendChild(Ct)}H.addEventListener("change",()=>{const pt=this._state.items.find(Ct=>Ct.id===H.value);pt&&(this._state.selectedItem=pt,this._updateAvailableAssets(pt),this._updateFootprintHighlight(),this._emit("itemselect",{item:pt}),this._render())}),U.appendChild(H),t.appendChild(U);const K=this._createFormGroup("Visualization Mode","mode"),et=document.createElement("div");et.className="maplibre-gl-stac-search-mode-row";const lt=document.createElement("button");lt.className=`maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--toggle ${this._state.isRgbMode?"":"active"}`,lt.textContent="Single Band",lt.addEventListener("click",()=>{this._state.isRgbMode=!1,this._render()});const nt=document.createElement("button");nt.className=`maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--toggle ${this._state.isRgbMode?"active":""}`,nt.textContent="RGB Composite",nt.addEventListener("click",()=>{this._state.isRgbMode=!0,this._render()}),et.appendChild(lt),et.appendChild(nt),K.appendChild(et),t.appendChild(K);const $=this._state.availableAssets;if(this._state.isRgbMode){const pt=this._createFormGroup("RGB Bands","rgb"),Ct=document.createElement("div");Ct.className="maplibre-gl-stac-search-rgb-row";const At=[{key:"r",label:"R"},{key:"g",label:"G"},{key:"b",label:"B"}];for(const St of At){const Kt=document.createElement("div");Kt.className="maplibre-gl-stac-search-rgb-channel";const Vt=document.createElement("label");Vt.textContent=St.label,Vt.className="maplibre-gl-stac-search-rgb-label",Kt.appendChild(Vt);const xt=document.createElement("select");xt.className="maplibre-gl-stac-search-select maplibre-gl-stac-search-select--small",xt.style.color="#000";for(const oe of $){const $t=document.createElement("option");$t.value=oe,$t.textContent=oe,$t.selected=this._state.rgbBands[St.key]===oe,xt.appendChild($t)}xt.addEventListener("change",()=>{this._state.rgbBands[St.key]=xt.value}),Kt.appendChild(xt),Ct.appendChild(Kt)}pt.appendChild(Ct),t.appendChild(pt)}else{const pt=this._createFormGroup("Band","band"),Ct=document.createElement("select");Ct.id="stac-search-band",Ct.className="maplibre-gl-stac-search-select",Ct.style.color="#000";for(const Vt of $){const xt=document.createElement("option");xt.value=Vt,xt.textContent=Vt,xt.selected=this._state.selectedBand===Vt,Ct.appendChild(xt)}Ct.addEventListener("change",()=>{this._state.selectedBand=Ct.value}),pt.appendChild(Ct),t.appendChild(pt);const At=this._createFormGroup("Colormap","colormap"),St=document.createElement("select");St.id="stac-search-colormap",St.className="maplibre-gl-stac-search-select",St.style.color="#000";const Kt=document.createElement("option");Kt.value="none",Kt.textContent="None (Grayscale)",Kt.selected=this._state.colormap==="none",St.appendChild(Kt);for(const Vt of Xz){const xt=document.createElement("option");xt.value=Vt,xt.textContent=Vt,xt.selected=this._state.colormap===Vt,St.appendChild(xt)}St.addEventListener("change",()=>{this._state.colormap=St.value}),At.appendChild(St),t.appendChild(At)}const F=this._createFormGroup("Rescale Range","rescale"),W=document.createElement("div");W.className="maplibre-gl-stac-search-rescale-row";const X=document.createElement("input");X.type="number",X.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",X.style.color="#000",X.placeholder="Min",X.value=String(this._state.rescaleMin),X.addEventListener("change",()=>{this._state.rescaleMin=Number(X.value)||0});const it=document.createElement("input");it.type="number",it.className="maplibre-gl-stac-search-input maplibre-gl-stac-search-input--half",it.style.color="#000",it.placeholder="Max",it.value=String(this._state.rescaleMax),it.addEventListener("change",()=>{this._state.rescaleMax=Number(it.value)||1e4}),W.appendChild(X),W.appendChild(it),F.appendChild(W),t.appendChild(F);const rt=document.createElement("div");rt.className="maplibre-gl-stac-search-form-group";const dt=document.createElement("button");dt.className="maplibre-gl-stac-search-btn maplibre-gl-stac-search-btn--primary",dt.textContent="Display Item",dt.disabled=this._state.loading||!this._state.selectedItem,dt.addEventListener("click",()=>this._displayItem()),rt.appendChild(dt),t.appendChild(rt)}if(this._state.loading?this._appendStatus(t,"Loading...","info"):this._state.error?this._appendStatus(t,this._state.error,"error"):this._state.status&&this._appendStatus(t,this._state.status,"success"),this._cogLayers.size>0){const U=document.createElement("div");U.className="maplibre-gl-stac-search-list";const H=document.createElement("div");H.className="maplibre-gl-stac-search-list-header-row";const K=document.createElement("div");K.className="maplibre-gl-stac-search-list-header",K.textContent=`Layers (${this._cogLayers.size})`,H.appendChild(K);const et=document.createElement("button");et.className="maplibre-gl-stac-search-btn-clear",et.textContent="Clear All",et.title="Remove all layers",et.addEventListener("click",()=>{this._removeAllLayers(),this._render()}),H.appendChild(et),U.appendChild(H);for(const[lt]of this._cogLayers){const nt=document.createElement("div");nt.className="maplibre-gl-stac-search-list-item";const $=document.createElement("span");$.className="maplibre-gl-stac-search-list-label",$.textContent=lt,nt.appendChild($);const F=document.createElement("button");F.className="maplibre-gl-stac-search-list-remove",F.innerHTML="×",F.title="Remove layer",F.addEventListener("click",()=>{this._removeLayer(lt),this._render()}),nt.appendChild(F),U.appendChild(nt)}t.appendChild(U)}this._container.appendChild(t),this._panel=t,this._button=void 0}_createFormGroup(t,e){const n=document.createElement("div");n.className="maplibre-gl-stac-search-form-group";const s=document.createElement("label");return s.textContent=t,s.htmlFor=`stac-search-${e}`,n.appendChild(s),n}_appendStatus(t,e,n){const s=document.createElement("div");s.className=`maplibre-gl-stac-search-status maplibre-gl-stac-search-status--${n}`,s.textContent=e,t.appendChild(s)}async _fetchCollections(){if(!this._state.selectedCatalog){this._state.error="Please select a catalog.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{const t=`${this._state.selectedCatalog.url}/collections`,e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch: ${e.status} ${e.statusText}`);const s=((await e.json()).collections||[]).map(r=>({id:r.id,title:r.title,description:r.description}));s.sort((r,a)=>{const l=r.title||r.id,h=a.title||a.id;return l.localeCompare(h)}),this._state.collections=s,this._state.selectedCollection=s.length>0?s[0]:null,this._state.loading=!1,this._state.status=`Found ${s.length} collection(s)`,this._emit("collectionsload",{})}catch(t){this._state.loading=!1,this._state.error=`Failed to load collections: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}async _searchItems(){if(!this._state.selectedCatalog||!this._state.selectedCollection){this._state.error="Please select a catalog and collection.",this._render();return}if(!this._map){this._state.error="Map not available.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{const t=this._map.getBounds(),e=[t.getWest(),t.getSouth(),t.getEast(),t.getNorth()],n=`${this._state.selectedCatalog.url}/search`,s={collections:[this._state.selectedCollection.id],bbox:e,limit:this._state.maxItems};if(this._state.startDate||this._state.endDate){const h=this._state.startDate||"1900-01-01",g=this._state.endDate||new Date().toISOString().split("T")[0];s.datetime=`${h}T00:00:00Z/${g}T23:59:59Z`}if(this._state.queryFilter)try{const h=JSON.parse(this._state.queryFilter);s.query=h}catch{console.warn("Invalid query filter JSON:",this._state.queryFilter)}const r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!r.ok)throw new Error(`Search failed: ${r.status} ${r.statusText}`);const a=await r.json(),l=(a.features||[]).map(h=>{const g=h.links?.find(m=>m.rel==="self")?.href;return{id:h.id,datetime:h.properties?.datetime,geometry:h.geometry,bbox:h.bbox,selfLink:g,properties:h.properties,assets:h.assets}});this._state.items=l,this._state.selectedItem=l.length>0?l[0]:null,this._state.selectedItem&&this._updateAvailableAssets(this._state.selectedItem),this._state.loading=!1,this._state.status=`Found ${l.length} item(s)`,this._emit("search",{}),this._options.showFootprints&&l.length>0&&this._addFootprints(a.features||[])}catch(t){this._state.loading=!1,this._state.error=`Search failed: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}_addFootprints(t){if(!this._map)return;this._removeFootprints();const e={type:"FeatureCollection",features:t.map(n=>({type:"Feature",geometry:n.geometry,properties:{id:n.id,datetime:n.properties?.datetime}}))};this._map.addSource(this._footprintSourceId,{type:"geojson",data:e}),this._map.addLayer({id:this._footprintLayerId,type:"fill",source:this._footprintSourceId,paint:{"fill-color":"#0078d7","fill-opacity":.1}}),this._map.addLayer({id:this._footprintOutlineLayerId,type:"line",source:this._footprintSourceId,paint:{"line-color":"#0078d7","line-width":2}}),this._map.addLayer({id:this._footprintHighlightLayerId,type:"fill",source:this._footprintSourceId,paint:{"fill-color":"#ff6b00","fill-opacity":.3},filter:["==",["get","id"],""]}),this._map.addLayer({id:this._footprintHighlightOutlineLayerId,type:"line",source:this._footprintSourceId,paint:{"line-color":"#ff6b00","line-width":3},filter:["==",["get","id"],""]}),this._updateFootprintHighlight(),this._map.on("click",this._footprintLayerId,n=>{if(n.features&&n.features.length>0){const s=n.features[0].properties?.id,r=this._state.items.find(a=>a.id===s);r&&(this._state.selectedItem=r,this._updateFootprintHighlight(),this._emit("itemselect",{item:r}),this._render())}}),this._map.on("mouseenter",this._footprintLayerId,()=>{this._map&&(this._map.getCanvas().style.cursor="pointer")}),this._map.on("mouseleave",this._footprintLayerId,()=>{this._map&&(this._map.getCanvas().style.cursor="")})}_removeFootprints(){this._map&&(this._map.getLayer(this._footprintHighlightOutlineLayerId)&&this._map.removeLayer(this._footprintHighlightOutlineLayerId),this._map.getLayer(this._footprintHighlightLayerId)&&this._map.removeLayer(this._footprintHighlightLayerId),this._map.getLayer(this._footprintOutlineLayerId)&&this._map.removeLayer(this._footprintOutlineLayerId),this._map.getLayer(this._footprintLayerId)&&this._map.removeLayer(this._footprintLayerId),this._map.getSource(this._footprintSourceId)&&this._map.removeSource(this._footprintSourceId))}_updateAvailableAssets(t){const e=[],n=new Set(["red","green","blue","nir","nir08","nir09","swir","swir16","swir22","coastal","data","visual","image","thumbnail","overview","B01","B02","B03","B04","B05","B06","B07","B08","B8A","B09","B10","B11","B12","AOT","WVP","SCL","SR_B1","SR_B2","SR_B3","SR_B4","SR_B5","SR_B6","SR_B7","ST_B10","lwir","lwir11","rgbir","raster","dem","dsm","dtm","elevation"]);if(t.assets)for(const[s,r]of Object.entries(t.assets)){const a=r,l=a.href||"",h=a.type||"",g=h.includes("geotiff")||h.includes("image/tiff")||h.includes("image/")||h.includes("application/x-hdf")||l.endsWith(".tif")||l.endsWith(".tiff")||l.endsWith(".jp2"),m=n.has(s)||n.has(s.toLowerCase()),y=s.includes("metadata")||s.includes("xml")||s.includes("json")||h.includes("application/json")||h.includes("application/xml")||h.includes("text/");(g||m)&&!y&&e.push(s)}if(e.sort(),this._state.availableAssets=e,e.length>0){(!this._state.selectedBand||!e.includes(this._state.selectedBand))&&(this._state.selectedBand=e[0]);const s=this._findDefaultRgbBands(e);(!this._state.rgbBands.r||!e.includes(this._state.rgbBands.r))&&(this._state.rgbBands.r=s.r),(!this._state.rgbBands.g||!e.includes(this._state.rgbBands.g))&&(this._state.rgbBands.g=s.g),(!this._state.rgbBands.b||!e.includes(this._state.rgbBands.b))&&(this._state.rgbBands.b=s.b)}}_findDefaultRgbBands(t){const e=[{r:"B04",g:"B03",b:"B02"},{r:"red",g:"green",b:"blue"},{r:"SR_B4",g:"SR_B3",b:"SR_B2"},{r:"B4",g:"B3",b:"B2"},{r:"visual",g:"visual",b:"visual"}];for(const n of e)if(t.includes(n.r)&&t.includes(n.g)&&t.includes(n.b))return n;return{r:t[0]||"",g:t[1]||t[0]||"",b:t[2]||t[0]||""}}_updateFootprintHighlight(){if(!this._map)return;const t=this._state.selectedItem?.id||"",e=["==",["get","id"],t];this._map.getLayer(this._footprintHighlightLayerId)&&this._map.setFilter(this._footprintHighlightLayerId,e),this._map.getLayer(this._footprintHighlightOutlineLayerId)&&this._map.setFilter(this._footprintHighlightOutlineLayerId,e)}_isPlanetaryComputer(){return this._state.selectedCatalog?.url?.includes("planetarycomputer.microsoft.com")??!1}_getDefaultAssets(t){return t.includes("sentinel-2")?"B04,B03,B02":t.includes("landsat")?"red,green,blue":t.includes("naip")?"image":t.includes("aster")?"VNIR":"data"}_getDefaultRescale(t){return t.includes("sentinel-2")?"0,3000&rescale=0,3000&rescale=0,3000":t.includes("landsat")?"0,20000&rescale=0,20000&rescale=0,20000":t.includes("dem")||t.includes("elevation")||t.includes("cop-dem")?"0,4000":t.includes("naip")||t.includes("aster")?"0,255&rescale=0,255&rescale=0,255":"0,10000"}async _displayItem(){if(!this._state.selectedItem){this._state.error="Please select an item.",this._render();return}if(!this._map){this._state.error="Map not available.",this._render();return}this._state.loading=!0,this._state.error=null,this._state.status=null,this._render();try{if(this._isPlanetaryComputer()&&this._state.selectedCollection){await this._displayPlanetaryComputerItem();return}let t=this._state.selectedItem.selfLink;if(!t&&this._state.selectedCatalog&&this._state.selectedCollection&&(t=`${this._state.selectedCatalog.url}/collections/${this._state.selectedCollection.id}/items/${this._state.selectedItem.id}`),!t)throw new Error("Cannot determine item URL");const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch item: ${e.status}`);const n=await e.json();let s=null,r=null;const a=["visual","true-color","rgb","thumbnail"];for(const l of a)if(n.assets?.[l]){const h=n.assets[l];if(h.type?.includes("geotiff")||h.type?.includes("image/tiff")||h.href?.endsWith(".tif")){s=l,r=h.href;break}}if(!r)for(const[l,h]of Object.entries(n.assets||{})){const g=h;if(g.type?.includes("geotiff")||g.type?.includes("image/tiff")||g.href?.endsWith(".tif")){s=l,r=g.href;break}}if(!r)throw new Error("No COG/GeoTIFF asset found in item");if(await this._addCogLayer(r,n,s||"default"),n.bbox){const[l,h,g,m]=n.bbox;this._map.fitBounds([[l,h],[g,m]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.loading=!1,this._state.status=`Displayed: ${this._state.selectedItem.id}`,this._emit("display",{item:this._state.selectedItem})}catch(t){this._state.loading=!1,this._state.error=`Failed to display: ${t instanceof Error?t.message:String(t)}`,this._emit("error",{error:this._state.error})}this._render()}async _displayPlanetaryComputerItem(){if(!this._map||!this._state.selectedItem||!this._state.selectedCollection)throw new Error("Missing required state for PC display");const t=this._state.selectedCollection.id,e=this._state.selectedItem.id,n="https://planetarycomputer.microsoft.com/api/data/v1";let s,r,a="";if(this._state.isRgbMode){const{r:m,g:y,b:x}=this._state.rgbBands;if(m&&y&&x){s=`assets=${m}&assets=${y}&assets=${x}`;const A=`${this._state.rescaleMin},${this._state.rescaleMax}`;r=`rescale=${A}&rescale=${A}&rescale=${A}`}else s=this._getDefaultAssets(t).split(",").map(S=>`assets=${S}`).join("&"),r=this._getDefaultRescale(t).split("&").map(S=>S.startsWith("rescale=")?S:`rescale=${S}`).join("&")}else s=`assets=${this._state.selectedBand||"data"}`,r=`rescale=${this._state.rescaleMin},${this._state.rescaleMax}`,this._state.colormap&&this._state.colormap!=="none"&&(a=`&colormap_name=${this._state.colormap}`);const l=`${n}/item/tiles/WebMercatorQuad/{z}/{x}/{y}@1x.png?collection=${encodeURIComponent(t)}&item=${encodeURIComponent(e)}&${s}&${r}${a}`,h=`stac-search-pc-${e}-${this._layerCounter++}`,g=`${h}-source`;if(this._map.addSource(g,{type:"raster",tiles:[l],tileSize:256,attribution:"Microsoft Planetary Computer"}),this._map.addLayer({id:h,type:"raster",source:g,paint:{"raster-opacity":1}}),this._cogLayers.set(h,{sourceId:g,layerId:h,type:"raster"}),this._state.selectedItem.bbox){const[m,y,x,A]=this._state.selectedItem.bbox;this._map.fitBounds([[m,y],[x,A]],{padding:50,duration:1e3})}this._state.hasLayer=this._cogLayers.size>0,this._state.loading=!1,this._state.status=`Displayed: ${this._state.selectedItem.id}`,this._emit("display",{item:this._state.selectedItem}),this._render()}async _ensureOverlay(){if(this._deckOverlay||!this._map)return;const{MapboxOverlay:t}=await Promise.resolve().then(()=>require("./index-BwXW8_tL.cjs"));this._deckOverlay=new t({interleaved:!1,layers:[]}),this._map.addControl(this._deckOverlay)}_convertS3ToHttps(t){if(!t.startsWith("s3://"))return t;const e=t.match(/^s3:\/\/([^/]+)\/(.+)$/);if(!e)return t;const[,n,s]=e,a={"deafrica-sentinel-2":"af-south-1","deafrica-landsat":"af-south-1","deafrica-services":"af-south-1","dea-public-data":"ap-southeast-2","dea-public-data-dev":"ap-southeast-2"}[n]||"us-east-1";return`https://${n}.s3.${a}.amazonaws.com/${s}`}async _addCogLayer(t,e,n){await this._ensureOverlay();const s=this._convertS3ToHttps(t),{COGLayer:r}=await Promise.resolve().then(()=>require("./index-BKl7PKZI.cjs")),a=`stac-search-${e.id}-${n}-${this._layerCounter++}`,l=new r({id:a,geotiff:s,opacity:1});this._cogLayers.set(a,l),this._deckOverlay.setProps({layers:Array.from(this._cogLayers.values())})}_removeLayer(t){const e=this._cogLayers.get(t);if(e&&this._map&&e.type==="raster"&&e.sourceId&&(this._map.getLayer(e.layerId)&&this._map.removeLayer(e.layerId),this._map.getSource(e.sourceId)&&this._map.removeSource(e.sourceId)),this._cogLayers.delete(t),this._deckOverlay){const n=Array.from(this._cogLayers.values()).filter(s=>s.type!=="raster");this._deckOverlay.setProps({layers:n})}this._state.hasLayer=this._cogLayers.size>0,this._cogLayers.size===0&&(this._state.status=null),this._render()}_removeAllLayers(){const t=Array.from(this._cogLayers.keys());for(const e of t)this._removeLayer(e);this._state.status=null,this._render()}}const qz=`<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">
232
232
  <circle cx="5" cy="5" r="3" fill="currentColor"/>
233
233
  <polyline points="12 4 20 4 20 12" stroke-width="2"/>
234
234
  <polygon points="4 14 12 11 18 16 14 22 6 22 4 14" fill="currentColor" fill-opacity="0.25"/>
@@ -3296,7 +3296,7 @@ northing meters`+i;var x=y/2,A=0,S=0,T,k,L,N,z;return x>0&&(T=1e5/Math.pow(10,x)
3296
3296
  </div>
3297
3297
  `}).join("")}
3298
3298
  </div>
3299
- `,this._contentEl.querySelectorAll(".pc-layer-item").forEach(e=>{var n,s;const r=e.getAttribute("data-id");if(!r)return;const a=e.querySelector(".pc-layer-visibility"),l=e.querySelector(".pc-opacity-slider"),h=e.querySelector(".pc-opacity-value");a?.addEventListener("change",()=>{this.updateLayer(r,{visible:a.checked})}),l?.addEventListener("input",()=>{const g=parseInt(l.value)/100;h.textContent=`${l.value}%`,this.updateLayer(r,{opacity:g})}),(n=e.querySelector(".pc-zoom-to"))==null||n.addEventListener("click",()=>{this.zoomToLayer(r)}),(s=e.querySelector(".pc-remove-layer"))==null||s.addEventListener("click",()=>{this.removeLayer(r)})})}async _loadCollections(){this._state.collectionsLoading=!0,this._state.error=null,this._emit("statechange"),this._renderContent();try{const t=await this._stacClient.getCollections();return this._options.defaultCollections.length>0?this._state.collections=t.filter(e=>this._options.defaultCollections.includes(e.id)):this._state.collections=t,this._state.collections.sort((e,n)=>(e.title||e.id).localeCompare(n.title||n.id)),this._emit("collections:load"),this._state.collections}catch(t){const e=t instanceof Error?t.message:"Failed to load collections";throw this._state.error=e,this._emit("error"),t}finally{this._state.collectionsLoading=!1,this._emit("statechange"),this._renderContent()}}_updatePanelVisibility(){this._panel&&(this._state.collapsed?this._panel.classList.remove("expanded"):(this._panel.classList.add("expanded"),this._updatePanelPosition()))}_setupEventListeners(){var t;this._clickOutsideHandler=e=>{const n=e.target;this._container&&this._panel&&!this._container.contains(n)&&!this._panel.contains(n)&&this.collapse()},document.addEventListener("click",this._clickOutsideHandler),this._resizeHandler=()=>{this._state.collapsed||this._updatePanelPosition()},window.addEventListener("resize",this._resizeHandler),this._mapResizeHandler=()=>{this._state.collapsed||this._updatePanelPosition()},(t=this._map)==null||t.on("resize",this._mapResizeHandler)}_getControlPosition(){var t;const e=(t=this._container)==null?void 0:t.parentElement;return e?e.classList.contains("maplibregl-ctrl-top-left")?"top-left":e.classList.contains("maplibregl-ctrl-top-right")?"top-right":e.classList.contains("maplibregl-ctrl-bottom-left")?"bottom-left":e.classList.contains("maplibregl-ctrl-bottom-right")?"bottom-right":"top-right":"top-right"}_updatePanelPosition(){if(!this._container||!this._panel||!this._mapContainer)return;const t=this._container.querySelector(".pc-control-toggle");if(!t)return;const e=t.getBoundingClientRect(),n=this._mapContainer.getBoundingClientRect(),s=this._getControlPosition(),r=e.top-n.top,a=n.bottom-e.bottom,l=e.left-n.left,h=n.right-e.right,g=5;switch(this._panel.style.top="",this._panel.style.bottom="",this._panel.style.left="",this._panel.style.right="",s){case"top-left":this._panel.style.top=`${r+e.height+g}px`,this._panel.style.left=`${l}px`;break;case"top-right":this._panel.style.top=`${r+e.height+g}px`,this._panel.style.right=`${h}px`;break;case"bottom-left":this._panel.style.bottom=`${a+e.height+g}px`,this._panel.style.left=`${l}px`;break;case"bottom-right":this._panel.style.bottom=`${a+e.height+g}px`,this._panel.style.right=`${h}px`;break}}getPanelElement(){return this._panel??null}}var Wht=Object.defineProperty,jht=(i,t,e)=>t in i?Wht(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,_p=(i,t,e)=>jht(i,typeof t!="symbol"?t+"":t,e);class EP{constructor(t){_p(this,"type","planetary-computer"),_p(this,"_control"),_p(this,"_changeCallbacks",[]),_p(this,"_unsubscribe"),this._control=t,this._setupEventListeners()}_setupEventListeners(){const t=()=>{const s=this._control.getState().activeLayers;if(s.length>0){const r=s[s.length-1];this._changeCallbacks.forEach(a=>a("add",r.id))}},e=()=>{this._changeCallbacks.forEach(n=>n("remove",""))};this._control.on("layer:add",t),this._control.on("layer:remove",e),this._unsubscribe=()=>{this._control.off("layer:add",t),this._control.off("layer:remove",e)}}getLayerIds(){return this._control.getState().activeLayers.map(e=>e.id)}getLayerState(t){const n=this._control.getState().activeLayers.find(s=>s.id===t);return n?{visible:n.visible,opacity:n.opacity,name:this.getName(t),isCustomLayer:!0,customLayerType:"planetary-computer"}:null}setVisibility(t,e){this._control.updateLayer(t,{visible:e})}setOpacity(t,e){this._control.updateLayer(t,{opacity:e})}getName(t){const n=this._control.getState().activeLayers.find(s=>s.id===t);if(n){if(n.item)return n.item.id;if(n.collection)return n.collection.title||n.collection.id}return t}getSymbolType(t){return"raster"}removeLayer(t){this._control.removeLayer(t)}onLayerChange(t){return this._changeCallbacks.push(t),()=>{const e=this._changeCallbacks.indexOf(t);e>=0&&this._changeCallbacks.splice(e,1)}}destroy(){var t;(t=this._unsubscribe)==null||t.call(this),this._changeCallbacks=[]}}class f3{_options;_container;_realControl=null;_isGaussianSplatProxy=!0;constructor(t){this._options=t,this._container=document.createElement("div")}onAdd(t){return this._container.className="maplibregl-ctrl maplibregl-ctrl-group gaussian-splat-proxy",this._loadRealControl(t),this._container}async _loadRealControl(t){try{if(!t)return;t.loaded()||await new Promise(s=>t.once("load",s));const{GaussianSplatControl:e}=await import("maplibre-gl-splat");this._realControl=new e(this._options);const n=this._realControl.onAdd(t);n&&this._container&&this._container.appendChild(n)}catch(e){console.error("Failed to load GaussianSplatControl dynamically:",e)}}onRemove(t){this._realControl?.onRemove&&this._realControl.onRemove(t),this._container.remove()}}class Xht{_control;_realAdapter=null;type="custom";constructor(t){this._control=t}setVisibility(t,e){this._realAdapter?.setVisibility?.(t,e)}setOpacity(t,e){this._realAdapter?.setOpacity?.(t,e)}getName(){return this._realAdapter?.getName()||"Gaussian Splat"}getLayerIds(){return this._realAdapter?.getLayerIds()||[]}getLayerState(){return this._realAdapter?.getLayerState()||{}}onAdd(t,e){this._loadRealAdapter(t,e)}async _loadRealAdapter(t,e){try{const{GaussianSplatLayerAdapter:n}=await import("maplibre-gl-splat"),s=this._control._realControl||this._control;this._realAdapter=new n(s),this._realAdapter.onAdd(t,e)}catch(n){console.error("Failed to load GaussianSplatLayerAdapter dynamically:",n)}}render(t,e){this._realAdapter?.render(t,e)}onRemove(t,e){this._realAdapter?.onRemove?.(t,e)}}class Zht{_options;_real;_container;constructor(t){this._options=t,this._container=document.createElement("div")}onAdd(t){return this._container.className="maplibregl-ctrl maplibregl-ctrl-group streetview-proxy",this._loadRealControl(t),this._container}async _loadRealControl(t){try{const{StreetViewControl:e}=await import("maplibre-gl-streetview"),s=new e(this._options).onAdd(t);this._container.appendChild(s)}catch(e){console.error("Async load failed",e)}}onRemove(t){this._real?.onRemove(t)}}var Yht=Object.defineProperty,qht=(i,t,e)=>t in i?Yht(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,yi=(i,t,e)=>qht(i,typeof t!="symbol"?t+"":t,e);const Jht={orientation:"vertical",position:50,leftLayers:[],rightLayers:[],showPanel:!0,collapsed:!0,title:"Layer Swipe",panelWidth:280,maxHeight:500,className:"",mousemove:!1,active:!0,basemapStyle:void 0,excludeLayers:[]};class SP{constructor(t){yi(this,"_map"),yi(this,"_comparisonMap"),yi(this,"_mapContainer"),yi(this,"_container"),yi(this,"_panel"),yi(this,"_slider"),yi(this,"_sliderHandle"),yi(this,"_clipContainer"),yi(this,"_comparisonContainer"),yi(this,"_options"),yi(this,"_state"),yi(this,"_basemapLayerIds",new Set),yi(this,"_eventHandlers",new globalThis.Map),yi(this,"_bounds"),yi(this,"_rafHandle",null),yi(this,"_rafPendingPosition",null),yi(this,"_resizeHandler",null),yi(this,"_mapResizeHandler",null),yi(this,"_moveHandler",null),yi(this,"_endHandler",null),yi(this,"_clickOutsideHandler",null),yi(this,"_mouseMoveHandler",null),yi(this,"_syncMoveHandler",null),yi(this,"_syncMoveEndHandler",null),yi(this,"_styleDataHandler",null),yi(this,"_isSyncing",!1),this._options={...Jht,...t},this._state={collapsed:this._options.collapsed,position:this._options.position,orientation:this._options.orientation,leftLayers:[...this._options.leftLayers],rightLayers:[...this._options.rightLayers],isDragging:!1,active:this._options.active}}onAdd(t){return this._map=t,this._mapContainer=t.getContainer(),this._updateBounds(),this._createComparisonMap(),this._container=this._createContainer(),this._slider=this._createSlider(),this._options.basemapStyle?this._loadBasemapStyle(this._options.basemapStyle).then(()=>{this._options.showPanel&&this._mapContainer&&(this._panel=this._createPanel(),this._mapContainer.appendChild(this._panel),this._state.collapsed||(this._panel.classList.add("expanded"),requestAnimationFrame(()=>{this._updatePanelPosition()})))}):this._options.showPanel&&(this._panel=this._createPanel(),this._mapContainer.appendChild(this._panel)),this._mapContainer.appendChild(this._slider),this._setupEventListeners(),this._updateClip(),this._updateLayerVisibility(),this._state.active||(this._slider&&(this._slider.style.display="none"),this._clipContainer&&(this._clipContainer.style.display="none")),!this._options.basemapStyle&&this._panel&&!this._state.collapsed&&(this._panel.classList.add("expanded"),requestAnimationFrame(()=>{this._updatePanelPosition()})),this._container}onRemove(){var t,e,n,s,r,a,l,h,g,m;this._removeEventListeners(),this._rafHandle!==null&&(cancelAnimationFrame(this._rafHandle),this._rafHandle=null),this._rafPendingPosition=null,this._comparisonMap&&(this._comparisonMap.remove(),this._comparisonMap=void 0),(e=(t=this._comparisonContainer)==null?void 0:t.parentNode)==null||e.removeChild(this._comparisonContainer),(s=(n=this._clipContainer)==null?void 0:n.parentNode)==null||s.removeChild(this._clipContainer),(a=(r=this._slider)==null?void 0:r.parentNode)==null||a.removeChild(this._slider),(h=(l=this._panel)==null?void 0:l.parentNode)==null||h.removeChild(this._panel),(m=(g=this._container)==null?void 0:g.parentNode)==null||m.removeChild(this._container),this._map=void 0,this._mapContainer=void 0,this._container=void 0,this._slider=void 0,this._panel=void 0,this._clipContainer=void 0,this._comparisonContainer=void 0,this._eventHandlers.clear()}getPosition(){return this._state.position}setPosition(t){const e=Math.max(0,Math.min(100,t));e!==this._state.position&&(this._state.position=e,this._updateSliderPosition(),this._updateClip(),this._emit("slide"),this._emit("statechange"))}getState(){return{...this._state}}setLeftLayers(t){this._state.leftLayers=[...t],this._updateLayerVisibility(),this._updateLayerCheckboxes(),this._emit("layerchange"),this._emit("statechange")}setRightLayers(t){this._state.rightLayers=[...t],this._updateLayerVisibility(),this._updateLayerCheckboxes(),this._emit("layerchange"),this._emit("statechange")}setOrientation(t){t!==this._state.orientation&&(this._state.orientation=t,this._updateSliderOrientation(),this._updateClip(),this._updateOrientationSelect(),this._emit("orientationchange"),this._emit("statechange"))}async _loadBasemapStyle(t){try{const e=await fetch(t);if(!e.ok){console.warn(`Failed to load basemap style from ${t}`);return}const n=await e.json();n.layers&&Array.isArray(n.layers)&&(this._basemapLayerIds=new Set(n.layers.map(s=>s.id)))}catch(e){console.warn(`Error loading basemap style: ${e}`)}}_isLayerExcluded(t){for(const e of this._options.excludeLayers){const n=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");if(new RegExp(`^${n}$`).test(t))return!0}return!1}getLayers(){if(!this._map)return[];const t=this._map.getStyle();if(!t||!t.layers)return[];const e=[];let n=!1;for(const s of t.layers)if(!this._isLayerExcluded(s.id)){if(this._basemapLayerIds.has(s.id)){n||(n=!0,e.push({id:"__basemap__",type:"basemap",source:"",visible:!0}));continue}e.push({id:s.id,type:s.type,source:s.source||"",visible:this._map.getLayoutProperty(s.id,"visibility")!=="none"})}return e}_getActualLayerIds(t){return t==="__basemap__"?Array.from(this._basemapLayerIds):[t]}on(t,e){this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e)}off(t,e){var n;(n=this._eventHandlers.get(t))==null||n.delete(e)}toggle(){this._state.collapsed=!this._state.collapsed,this._panel&&(this._state.collapsed?this._panel.classList.remove("expanded"):(this._panel.classList.add("expanded"),this._updatePanelPosition())),this._state.collapsed?this._emit("collapse"):this._emit("expand"),this._emit("statechange")}expand(){this._state.collapsed&&this.toggle()}collapse(){this._state.collapsed||this.toggle()}setActive(t){t!==this._state.active&&(this._state.active=t,t?(this._slider&&(this._slider.style.display=""),this._clipContainer&&(this._clipContainer.style.display=""),this._updateClip(),this._emit("activate")):(this._slider&&(this._slider.style.display="none"),this._clipContainer&&(this._clipContainer.style.display="none"),this._emit("deactivate")),this._updateActiveToggle(),this._emit("statechange"))}isActive(){return this._state.active}getMap(){return this._map}getComparisonMap(){return this._comparisonMap}getContainer(){return this._container}_emit(t){const e=this._eventHandlers.get(t);if(e){const n={type:t,state:this.getState(),position:this._state.position};e.forEach(s=>s(n))}}_createComparisonMap(){if(!this._map||!this._mapContainer)return;this._clipContainer=document.createElement("div"),this._clipContainer.className="swipe-clip-container",this._clipContainer.style.cssText=`
3299
+ `,this._contentEl.querySelectorAll(".pc-layer-item").forEach(e=>{var n,s;const r=e.getAttribute("data-id");if(!r)return;const a=e.querySelector(".pc-layer-visibility"),l=e.querySelector(".pc-opacity-slider"),h=e.querySelector(".pc-opacity-value");a?.addEventListener("change",()=>{this.updateLayer(r,{visible:a.checked})}),l?.addEventListener("input",()=>{const g=parseInt(l.value)/100;h.textContent=`${l.value}%`,this.updateLayer(r,{opacity:g})}),(n=e.querySelector(".pc-zoom-to"))==null||n.addEventListener("click",()=>{this.zoomToLayer(r)}),(s=e.querySelector(".pc-remove-layer"))==null||s.addEventListener("click",()=>{this.removeLayer(r)})})}async _loadCollections(){this._state.collectionsLoading=!0,this._state.error=null,this._emit("statechange"),this._renderContent();try{const t=await this._stacClient.getCollections();return this._options.defaultCollections.length>0?this._state.collections=t.filter(e=>this._options.defaultCollections.includes(e.id)):this._state.collections=t,this._state.collections.sort((e,n)=>(e.title||e.id).localeCompare(n.title||n.id)),this._emit("collections:load"),this._state.collections}catch(t){const e=t instanceof Error?t.message:"Failed to load collections";throw this._state.error=e,this._emit("error"),t}finally{this._state.collectionsLoading=!1,this._emit("statechange"),this._renderContent()}}_updatePanelVisibility(){this._panel&&(this._state.collapsed?this._panel.classList.remove("expanded"):(this._panel.classList.add("expanded"),this._updatePanelPosition()))}_setupEventListeners(){var t;this._clickOutsideHandler=e=>{const n=e.target;this._container&&this._panel&&!this._container.contains(n)&&!this._panel.contains(n)&&this.collapse()},document.addEventListener("click",this._clickOutsideHandler),this._resizeHandler=()=>{this._state.collapsed||this._updatePanelPosition()},window.addEventListener("resize",this._resizeHandler),this._mapResizeHandler=()=>{this._state.collapsed||this._updatePanelPosition()},(t=this._map)==null||t.on("resize",this._mapResizeHandler)}_getControlPosition(){var t;const e=(t=this._container)==null?void 0:t.parentElement;return e?e.classList.contains("maplibregl-ctrl-top-left")?"top-left":e.classList.contains("maplibregl-ctrl-top-right")?"top-right":e.classList.contains("maplibregl-ctrl-bottom-left")?"bottom-left":e.classList.contains("maplibregl-ctrl-bottom-right")?"bottom-right":"top-right":"top-right"}_updatePanelPosition(){if(!this._container||!this._panel||!this._mapContainer)return;const t=this._container.querySelector(".pc-control-toggle");if(!t)return;const e=t.getBoundingClientRect(),n=this._mapContainer.getBoundingClientRect(),s=this._getControlPosition(),r=e.top-n.top,a=n.bottom-e.bottom,l=e.left-n.left,h=n.right-e.right,g=5;switch(this._panel.style.top="",this._panel.style.bottom="",this._panel.style.left="",this._panel.style.right="",s){case"top-left":this._panel.style.top=`${r+e.height+g}px`,this._panel.style.left=`${l}px`;break;case"top-right":this._panel.style.top=`${r+e.height+g}px`,this._panel.style.right=`${h}px`;break;case"bottom-left":this._panel.style.bottom=`${a+e.height+g}px`,this._panel.style.left=`${l}px`;break;case"bottom-right":this._panel.style.bottom=`${a+e.height+g}px`,this._panel.style.right=`${h}px`;break}}getPanelElement(){return this._panel??null}}var Wht=Object.defineProperty,jht=(i,t,e)=>t in i?Wht(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,_p=(i,t,e)=>jht(i,typeof t!="symbol"?t+"":t,e);class EP{constructor(t){_p(this,"type","planetary-computer"),_p(this,"_control"),_p(this,"_changeCallbacks",[]),_p(this,"_unsubscribe"),this._control=t,this._setupEventListeners()}_setupEventListeners(){const t=()=>{const s=this._control.getState().activeLayers;if(s.length>0){const r=s[s.length-1];this._changeCallbacks.forEach(a=>a("add",r.id))}},e=()=>{this._changeCallbacks.forEach(n=>n("remove",""))};this._control.on("layer:add",t),this._control.on("layer:remove",e),this._unsubscribe=()=>{this._control.off("layer:add",t),this._control.off("layer:remove",e)}}getLayerIds(){return this._control.getState().activeLayers.map(e=>e.id)}getLayerState(t){const n=this._control.getState().activeLayers.find(s=>s.id===t);return n?{visible:n.visible,opacity:n.opacity,name:this.getName(t),isCustomLayer:!0,customLayerType:"planetary-computer"}:null}setVisibility(t,e){this._control.updateLayer(t,{visible:e})}setOpacity(t,e){this._control.updateLayer(t,{opacity:e})}getName(t){const n=this._control.getState().activeLayers.find(s=>s.id===t);if(n){if(n.item)return n.item.id;if(n.collection)return n.collection.title||n.collection.id}return t}getSymbolType(t){return"raster"}removeLayer(t){this._control.removeLayer(t)}onLayerChange(t){return this._changeCallbacks.push(t),()=>{const e=this._changeCallbacks.indexOf(t);e>=0&&this._changeCallbacks.splice(e,1)}}destroy(){var t;(t=this._unsubscribe)==null||t.call(this),this._changeCallbacks=[]}}class f3{_options;_container;_realControl=null;_isGaussianSplatProxy=!0;constructor(t){this._options=t,this._container=document.createElement("div")}onAdd(t){return this._container.className="maplibregl-ctrl maplibregl-ctrl-group gaussian-splat-proxy",this._loadRealControl(t),this._container}async _loadRealControl(t){try{if(!t)return;typeof t.loaded=="function"&&!t.loaded()&&await new Promise(s=>t.once("load",s));const{GaussianSplatControl:e}=await import("maplibre-gl-splat");this._realControl=new e(this._options);const n=this._realControl.onAdd(t);n&&this._container&&this._container.appendChild(n)}catch(e){console.error("Failed to load GaussianSplatControl dynamically:",e)}}onRemove(t){this._realControl?.onRemove&&this._realControl.onRemove(t),this._container.remove()}}class Xht{_control;_realAdapter=null;type="custom";constructor(t){this._control=t}setVisibility(t,e){this._realAdapter?.setVisibility?.(t,e)}setOpacity(t,e){this._realAdapter?.setOpacity?.(t,e)}getName(){return this._realAdapter?.getName()||"Gaussian Splat"}getLayerIds(){return this._realAdapter?.getLayerIds()||[]}getLayerState(){return this._realAdapter?.getLayerState()||{}}onAdd(t,e){this._loadRealAdapter(t,e)}async _loadRealAdapter(t,e){try{const{GaussianSplatLayerAdapter:n}=await import("maplibre-gl-splat"),s=this._control._realControl||this._control;this._realAdapter=new n(s),this._realAdapter.onAdd(t,e)}catch(n){console.error("Failed to load GaussianSplatLayerAdapter dynamically:",n)}}render(t,e){this._realAdapter?.render(t,e)}onRemove(t,e){this._realAdapter?.onRemove?.(t,e)}}class Zht{_options;_real;_container;constructor(t){this._options=t,this._container=document.createElement("div")}onAdd(t){return this._container.className="maplibregl-ctrl maplibregl-ctrl-group streetview-proxy",this._loadRealControl(t),this._container}async _loadRealControl(t){try{const{StreetViewControl:e}=await import("maplibre-gl-streetview"),s=new e(this._options).onAdd(t);this._container.appendChild(s)}catch(e){console.error("Async load failed",e)}}onRemove(t){this._real?.onRemove(t)}}var Yht=Object.defineProperty,qht=(i,t,e)=>t in i?Yht(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,yi=(i,t,e)=>qht(i,typeof t!="symbol"?t+"":t,e);const Jht={orientation:"vertical",position:50,leftLayers:[],rightLayers:[],showPanel:!0,collapsed:!0,title:"Layer Swipe",panelWidth:280,maxHeight:500,className:"",mousemove:!1,active:!0,basemapStyle:void 0,excludeLayers:[]};class SP{constructor(t){yi(this,"_map"),yi(this,"_comparisonMap"),yi(this,"_mapContainer"),yi(this,"_container"),yi(this,"_panel"),yi(this,"_slider"),yi(this,"_sliderHandle"),yi(this,"_clipContainer"),yi(this,"_comparisonContainer"),yi(this,"_options"),yi(this,"_state"),yi(this,"_basemapLayerIds",new Set),yi(this,"_eventHandlers",new globalThis.Map),yi(this,"_bounds"),yi(this,"_rafHandle",null),yi(this,"_rafPendingPosition",null),yi(this,"_resizeHandler",null),yi(this,"_mapResizeHandler",null),yi(this,"_moveHandler",null),yi(this,"_endHandler",null),yi(this,"_clickOutsideHandler",null),yi(this,"_mouseMoveHandler",null),yi(this,"_syncMoveHandler",null),yi(this,"_syncMoveEndHandler",null),yi(this,"_styleDataHandler",null),yi(this,"_isSyncing",!1),this._options={...Jht,...t},this._state={collapsed:this._options.collapsed,position:this._options.position,orientation:this._options.orientation,leftLayers:[...this._options.leftLayers],rightLayers:[...this._options.rightLayers],isDragging:!1,active:this._options.active}}onAdd(t){return this._map=t,this._mapContainer=t.getContainer(),this._updateBounds(),this._createComparisonMap(),this._container=this._createContainer(),this._slider=this._createSlider(),this._options.basemapStyle?this._loadBasemapStyle(this._options.basemapStyle).then(()=>{this._options.showPanel&&this._mapContainer&&(this._panel=this._createPanel(),this._mapContainer.appendChild(this._panel),this._state.collapsed||(this._panel.classList.add("expanded"),requestAnimationFrame(()=>{this._updatePanelPosition()})))}):this._options.showPanel&&(this._panel=this._createPanel(),this._mapContainer.appendChild(this._panel)),this._mapContainer.appendChild(this._slider),this._setupEventListeners(),this._updateClip(),this._updateLayerVisibility(),this._state.active||(this._slider&&(this._slider.style.display="none"),this._clipContainer&&(this._clipContainer.style.display="none")),!this._options.basemapStyle&&this._panel&&!this._state.collapsed&&(this._panel.classList.add("expanded"),requestAnimationFrame(()=>{this._updatePanelPosition()})),this._container}onRemove(){var t,e,n,s,r,a,l,h,g,m;this._removeEventListeners(),this._rafHandle!==null&&(cancelAnimationFrame(this._rafHandle),this._rafHandle=null),this._rafPendingPosition=null,this._comparisonMap&&(this._comparisonMap.remove(),this._comparisonMap=void 0),(e=(t=this._comparisonContainer)==null?void 0:t.parentNode)==null||e.removeChild(this._comparisonContainer),(s=(n=this._clipContainer)==null?void 0:n.parentNode)==null||s.removeChild(this._clipContainer),(a=(r=this._slider)==null?void 0:r.parentNode)==null||a.removeChild(this._slider),(h=(l=this._panel)==null?void 0:l.parentNode)==null||h.removeChild(this._panel),(m=(g=this._container)==null?void 0:g.parentNode)==null||m.removeChild(this._container),this._map=void 0,this._mapContainer=void 0,this._container=void 0,this._slider=void 0,this._panel=void 0,this._clipContainer=void 0,this._comparisonContainer=void 0,this._eventHandlers.clear()}getPosition(){return this._state.position}setPosition(t){const e=Math.max(0,Math.min(100,t));e!==this._state.position&&(this._state.position=e,this._updateSliderPosition(),this._updateClip(),this._emit("slide"),this._emit("statechange"))}getState(){return{...this._state}}setLeftLayers(t){this._state.leftLayers=[...t],this._updateLayerVisibility(),this._updateLayerCheckboxes(),this._emit("layerchange"),this._emit("statechange")}setRightLayers(t){this._state.rightLayers=[...t],this._updateLayerVisibility(),this._updateLayerCheckboxes(),this._emit("layerchange"),this._emit("statechange")}setOrientation(t){t!==this._state.orientation&&(this._state.orientation=t,this._updateSliderOrientation(),this._updateClip(),this._updateOrientationSelect(),this._emit("orientationchange"),this._emit("statechange"))}async _loadBasemapStyle(t){try{const e=await fetch(t);if(!e.ok){console.warn(`Failed to load basemap style from ${t}`);return}const n=await e.json();n.layers&&Array.isArray(n.layers)&&(this._basemapLayerIds=new Set(n.layers.map(s=>s.id)))}catch(e){console.warn(`Error loading basemap style: ${e}`)}}_isLayerExcluded(t){for(const e of this._options.excludeLayers){const n=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");if(new RegExp(`^${n}$`).test(t))return!0}return!1}getLayers(){if(!this._map)return[];const t=this._map.getStyle();if(!t||!t.layers)return[];const e=[];let n=!1;for(const s of t.layers)if(!this._isLayerExcluded(s.id)){if(this._basemapLayerIds.has(s.id)){n||(n=!0,e.push({id:"__basemap__",type:"basemap",source:"",visible:!0}));continue}e.push({id:s.id,type:s.type,source:s.source||"",visible:this._map.getLayoutProperty(s.id,"visibility")!=="none"})}return e}_getActualLayerIds(t){return t==="__basemap__"?Array.from(this._basemapLayerIds):[t]}on(t,e){this._eventHandlers.has(t)||this._eventHandlers.set(t,new Set),this._eventHandlers.get(t).add(e)}off(t,e){var n;(n=this._eventHandlers.get(t))==null||n.delete(e)}toggle(){this._state.collapsed=!this._state.collapsed,this._panel&&(this._state.collapsed?this._panel.classList.remove("expanded"):(this._panel.classList.add("expanded"),this._updatePanelPosition())),this._state.collapsed?this._emit("collapse"):this._emit("expand"),this._emit("statechange")}expand(){this._state.collapsed&&this.toggle()}collapse(){this._state.collapsed||this.toggle()}setActive(t){t!==this._state.active&&(this._state.active=t,t?(this._slider&&(this._slider.style.display=""),this._clipContainer&&(this._clipContainer.style.display=""),this._updateClip(),this._emit("activate")):(this._slider&&(this._slider.style.display="none"),this._clipContainer&&(this._clipContainer.style.display="none"),this._emit("deactivate")),this._updateActiveToggle(),this._emit("statechange"))}isActive(){return this._state.active}getMap(){return this._map}getComparisonMap(){return this._comparisonMap}getContainer(){return this._container}_emit(t){const e=this._eventHandlers.get(t);if(e){const n={type:t,state:this.getState(),position:this._state.position};e.forEach(s=>s(n))}}_createComparisonMap(){if(!this._map||!this._mapContainer)return;this._clipContainer=document.createElement("div"),this._clipContainer.className="swipe-clip-container",this._clipContainer.style.cssText=`
3300
3300
  position: absolute;
3301
3301
  top: 0;
3302
3302
  left: 0;