@npm9912/v-map 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{cesium-provider-CTtu9eTD.js → cesium-provider-eoUKuWMQ.js} +19 -1
- package/dist/cjs/{deck-provider-fNa818HH.js → deck-provider-VE8jCvBE.js} +28 -14
- package/dist/cjs/{index-ChrKyU6i.js → index-CCxwwaJl.js} +2 -2
- package/dist/cjs/{index-C1ubapwF.js → index-CE8CbKgP.js} +2 -2
- package/dist/cjs/{index-9APmzoa2.js → index-CF2WBqZp.js} +4 -4
- package/dist/cjs/{index-BJg0ncfC.js → index-CQEgnWQf.js} +2 -2
- package/dist/cjs/{layer-extension-D3a-1DFI.js → layer-extension-IlBQy451.js} +1 -1
- package/dist/cjs/{leaflet-provider-7Nw-AdV_.js → leaflet-provider-D_wmyi0D.js} +12 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{openlayers-provider-DMxYtFkS.js → openlayers-provider-BkvQVXZX.js} +14 -1
- package/dist/cjs/{polygon-layer-Dx1ZWZP0.js → polygon-layer-D7S9jutU.js} +1 -1
- package/dist/cjs/{scenegraph-layer-ctLehP0q.js → scenegraph-layer-h1u7G3QW.js} +1 -1
- package/dist/cjs/v-map.cjs.js +1 -1
- package/dist/cjs/{v-map.v-map-layer-osm.v-map-layergroup-BJ3_NqAj.js → v-map.v-map-layer-osm.v-map-layergroup-B-JDj4h8.js} +51 -5
- package/dist/cjs/v-map_3.cjs.entry.js +1 -1
- package/dist/collection/components/v-map/v-map.js +47 -1
- package/dist/collection/map-provider/cesium/cesium-provider.js +18 -0
- package/dist/collection/map-provider/deck/deck-provider.js +21 -7
- package/dist/collection/map-provider/leaflet/leaflet-provider.js +11 -0
- package/dist/collection/map-provider/ol/openlayers-provider.js +14 -1
- package/dist/components/cesium-provider.js +1 -1
- package/dist/components/deck-provider.js +1 -1
- package/dist/components/leaflet-provider.js +1 -1
- package/dist/components/openlayers-provider.js +1 -1
- package/dist/components/v-map2.js +1 -1
- package/dist/esm/{cesium-provider-Bh__cBGf.js → cesium-provider-BkuYkY7L.js} +19 -1
- package/dist/esm/{deck-provider-DxIpS4lY.js → deck-provider-Bi-KjKaQ.js} +28 -14
- package/dist/esm/{index-DxbztwCv.js → index-B1rgsDF8.js} +5 -5
- package/dist/esm/{index-C3mnOs0I.js → index-DnYCNw5P.js} +2 -2
- package/dist/esm/{index-Bh2gBu9u.js → index-KNhUl5HI.js} +3 -3
- package/dist/esm/{index-C63kfbil.js → index-W2-A_yhi.js} +4 -4
- package/dist/esm/{layer-extension-C5Y2UES3.js → layer-extension-IuMBMh1z.js} +1 -1
- package/dist/esm/{leaflet-provider-k6JSYiYX.js → leaflet-provider-LXeX9dPk.js} +12 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{openlayers-provider-DIquf3Tx.js → openlayers-provider-BZvqx4li.js} +15 -2
- package/dist/esm/{polygon-layer-ZIT5mJy5.js → polygon-layer-BPJjHK3y.js} +1 -1
- package/dist/esm/{scenegraph-layer-CNIRd2uu.js → scenegraph-layer-_1RQcOYZ.js} +1 -1
- package/dist/esm/v-map.js +1 -1
- package/dist/esm/{v-map.v-map-layer-osm.v-map-layergroup-Zwdvm9PG.js → v-map.v-map-layer-osm.v-map-layergroup-DIfNm6nG.js} +51 -5
- package/dist/esm/v-map_3.entry.js +1 -1
- package/dist/types/components/v-map/v-map.d.ts +15 -0
- package/dist/types/map-provider/cesium/cesium-provider.d.ts +4 -0
- package/dist/types/map-provider/deck/deck-provider.d.ts +5 -0
- package/dist/types/map-provider/leaflet/leaflet-provider.d.ts +4 -0
- package/dist/types/map-provider/ol/openlayers-provider.d.ts +4 -0
- package/dist/types/types/mapprovider.d.ts +11 -0
- package/dist/v-map/p-BFyBu5_1.js +1 -0
- package/dist/v-map/p-BOfJXm8U.js +1 -0
- package/dist/v-map/{p-DuJ_mTaq.js → p-Bl6vQpyl.js} +1 -1
- package/dist/v-map/{p-G6iftXUC.js → p-Bmo2hj1_.js} +1 -1
- package/dist/v-map/{p-Ci70E1EM.js → p-COhBo2OS.js} +1 -1
- package/dist/v-map/{p-9Rt23jlQ.js → p-Cp_e5ebg.js} +1 -1
- package/dist/v-map/{p-C0M0-Kvt.js → p-D5O720HV.js} +1 -1
- package/dist/v-map/{p-DAf4itFZ.js → p-D94rp5ir.js} +1 -1
- package/dist/v-map/{p-BpE6L1g0.js → p-DgXaR8AP.js} +1 -1
- package/dist/v-map/p-fca86e74.entry.js +1 -0
- package/dist/v-map/{p-rCyRSFJb.js → p-ns7UwFY9.js} +2 -2
- package/dist/v-map/{p-BSsFEMZP.js → p-qVwE-Ron.js} +1 -1
- package/dist/v-map/{p-vhbi5XXi.js → p-yoshb-P-.js} +1 -1
- package/dist/v-map/v-map.esm.js +1 -1
- package/package.json +1 -1
- package/dist/v-map/p-05ee633f.entry.js +0 -1
- package/dist/v-map/p-2-mR3oVa.js +0 -1
- package/dist/v-map/p-CbiLpFhO.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{w as t,l as e,e as i}from"./p-QJHuuz0g.js";import{C as s}from"./p-2-mR3oVa.js";import{l as r,a,b as n,G as o,g as h}from"./p-yXLNXXx-.js";import"./p-BoNyIrdq.js";import"./p-CrV_misM.js";import"./p-DVBtCUtQ.js";class c{id;_visible=!0;_basemap=null;_layers=new Map;_originalVisible=new Map;_dirty=!0;constructor(t,e=!0){this.id=t,this._visible=e}get visible(){return this._visible}set visible(t){this._visible!==t&&(this._visible=t,this._dirty=!0)}get basemap(){return this._basemap}set basemap(t){this._basemap!==t&&(this._basemap=t,this._dirty=!0)}isDirty(){return this._dirty}addLayer(t){this._layers.has(t.id)||(this._layers.set(t.id,t),this._originalVisible.set(t.id,t.layer.getVisible()),this._dirty=!0)}setLayerElementId(t,e){const i=this._layers.get(t);i&&i.elementId!==e&&(i.elementId=e??null,this._dirty=!0)}removeLayer(t){const e=this._layers.delete(t);return this._originalVisible.delete(t),e&&(this._dirty=!0),e}clear(){this._layers.clear(),this._originalVisible.clear(),this._dirty=!0}apply(){if(this._dirty){for(const[t,e]of this._layers){const i=this._originalVisible.get(t)??!0;let s=this._visible&&i;s&&this._basemap&&(s=e.elementId===this._basemap),e.layer.getVisible()!==s&&e.layer.setVisible(s)}this._dirty=!1}}}class l{_groups=[];_dirty=!0;get groups(){return[...this._groups]}getGroup(t){return this._groups.find((e=>e.id===t))}hasGroup(t){return this._groups.some((e=>e.id===t))}ensureGroup(t,e=!0){let i=this.getGroup(t);return i||(i=new c(t,e),this._groups.push(i),this._dirty=!0,i)}addLayerToGroup(t,e,i){this.ensureGroup(t,e).addLayer(i),this._dirty=!0}removeLayer(t,e=!0){let i=!1;for(const s of this._groups)if(s.removeLayer(t)&&(i=!0,!e))break;return i&&(this._dirty=!0),i}setGroupVisible(t,e){const i=this.getGroup(t);if(!i)throw new Error(`CesiumLayerGroup "${t}" nicht gefunden`);i.visible=e,this._dirty=!0}setBasemap(t,e){const i=this.getGroup(t);if(!i)throw new Error(`CesiumLayerGroup "${t}" nicht gefunden`);i.basemap=e,this._dirty=!0}apply(){if(this._dirty||this._groups.some((t=>t.isDirty()))){for(const t of this._groups)t.apply();this._dirty=!1}}clear(){this._groups=[],this._dirty=!0}}class u{Cesium;layers=new Map;viewer;constructor(t,e){this.viewer=e,this.Cesium=t}replaceLayer(t,e,i){if(!this.Cesium)throw new Error("Cesium must be initialized first. Call init() method.");const s=e.getZIndex(),r=e.getVisible(),a=e.getOpacity();this.removeLayer(t);const n=this.addLayer(t,i);return n.setZIndex(s),n.setVisible(r),n.setOpacity(a),n}addLayer(t,e){if(!this.Cesium)throw new Error("Cesium must be initialized first. Call init() method.");e instanceof this.Cesium.GeoJsonDataSource||e instanceof this.Cesium.DataSource?this.viewer.dataSources.add(e):e instanceof this.Cesium.Cesium3DTileset?(this.viewer.scene.primitives.add(e),e.style||(e.style=new this.Cesium.Cesium3DTileStyle)):e instanceof this.Cesium.ImageryLayer&&this.viewer.imageryLayers.add(e),e.id=t;const i=this.wrapLayer(e);return this.layers.set(t,i),i}addCustomLayer(t,e){return this.layers.set(t,e),e}getLayer(t){const e=this.layers.get(t);if(!e)throw new Error(`Layer mit ID "${t}" nicht gefunden.`);return e}getLayerById(t){return this.getLayer(t)}removeLayer(t){this.getLayer(t).remove(),this.layers.delete(t)}setVisible(t,e){this.getLayer(t).setVisible(e)}setOpacity(t,e){this.getLayer(t).setOpacity(e)}async setZIndex(t,e){const i=this.getLayer(t);await i.setZIndex(e)}wrapLayer(t){return t instanceof this.Cesium.ImageryLayer?this.wrapImageryLayer(t):t instanceof this.Cesium.Cesium3DTileset?this.wrapTilesetLayer(t):this.wrapDataSourceLayer(t)}async sortImageryLayers(t,e,i){const s=this.sort(t,e,i);t.removeAll(!1),s.forEach((e=>t.add(e)))}async sort3DTileSets(t,e,i){const s=this.sort(t,e,i);t.removeAll(),s.forEach((e=>t.add(e)))}async sortDataSources(t,e,i){const s=this.sort(t,e,i);t.removeAll(!1),s.forEach((async e=>await t.add(e)))}sort(t,e,i){t.remove(e,!1);const s=[];for(let e=0;e<t.length;e++)s.push(t.get(e));return s.sort(((t,e)=>(t.zIndex||0)-(e.zIndex||0))),e.zIndex=i,s.push(e),s.sort(((t,e)=>(t.zIndex||0)-(e.zIndex||0))),s}wrapImageryLayer(t){const e=this.viewer.imageryLayers;let i={};return{getOptions:()=>i,setOptions(t){i=t},getVisible:()=>t.show,setVisible:e=>{t.show=e},getOpacity:()=>t.alpha,setOpacity:e=>{t.alpha=e},getZIndex:()=>{for(let i=0;i<e.length;i++)if(e.get(i)===t)return i;return-1},setZIndex:async i=>{void 0!==i&&await this.sortImageryLayers(e,t,i)},remove:()=>e.remove(t)}}wrapTilesetLayer(t){const e=this.viewer.scene.primitives;let i={};return{getOptions:()=>i,setOptions(t){i=t},getVisible:()=>t.show,setVisible:e=>{t.show=e},getOpacity:()=>{const e=t.style;if(e.color&&"string"==typeof e.color){const t=e.color.match(/color\(.*?,([\d.]+)\)/);return t?parseFloat(t[1]):1}return 1},setOpacity:e=>{const i=t.style.color;let s;if("string"==typeof i){const t=i.replace(/color\((.*?),[\d.]+\)/,`color($1, ${e})`);s=t.includes("color")?t:`color('white', ${e})`}else s=`color('white', ${e})`;t.style=new this.Cesium.Cesium3DTileStyle({color:s,colorBlendMode:this.Cesium.ColorBlendMode.MIX})},getZIndex:()=>{const e=this.viewer.scene.primitives;for(let i=0;i<e.length;i++)if(e.get(i)===t)return i;return-1},setZIndex:async i=>{void 0!==i&&this.sort3DTileSets(e,t,i)},setColor:(e,i=1)=>{const s=e instanceof this.Cesium.Color?e.toCssHexString():e.replace(/[#\s]/g,"");t.style=new this.Cesium.Cesium3DTileStyle({color:`color('${s}', ${i})`,colorBlendMode:this.Cesium.ColorBlendMode.MIX})},setStyle:e=>{t.style=e instanceof this.Cesium.Cesium3DTileStyle?e:new this.Cesium.Cesium3DTileStyle(e)},remove:()=>this.viewer.scene.primitives.remove(t)}}wrapDataSourceLayer(t){const e=this.viewer.dataSources;let i={};return{getOptions:()=>i,setOptions(t){i=t},getVisible:()=>t.show,setVisible:e=>{t.show=e},getOpacity:()=>1,setOpacity:e=>{t.__vmapLockOpacity||t.entities.values.forEach((t=>{const i=(t,i)=>{const{Color:s,JulianDate:r}=this.Cesium,a=t=>s.fromAlpha(t??i,e,new s);if(!t)return new this.Cesium.ConstantProperty(a(i));const n=t;if(n&&"function"==typeof n.getValue){const t=a(n.getValue(this.viewer?.clock?.currentTime??new r,new s));return"function"==typeof n.setValue?(n.setValue(t),n):new this.Cesium.ConstantProperty(t)}return new this.Cesium.ConstantProperty(a(t instanceof this.Cesium.Color?t:i))};if(t.polygon){const e=t.polygon.material;(e instanceof Cesium.ColorMaterialProperty||e instanceof Cesium.ImageMaterialProperty)&&(e.color=i(e.color,Cesium.Color.WHITE))}if(t.polyline){const e=t.polyline.material;(e instanceof Cesium.ColorMaterialProperty||e instanceof Cesium.PolylineOutlineMaterialProperty)&&(e.color=i(e.color,Cesium.Color.WHITE))}t.point&&(t.point.color=i(t.point.color,Cesium.Color.WHITE)),t.billboard&&(t.billboard.color=i(t.billboard.color,Cesium.Color.WHITE)),t.label&&(t.label.fillColor=i(t.label.fillColor,Cesium.Color.BLACK),t.label.outlineColor&&(t.label.outlineColor=i(t.label.outlineColor,Cesium.Color.BLACK))),t.model&&(t.model.color=i(t.model.color,Cesium.Color.WHITE))}))},getZIndex:()=>{for(let i=0;i<e.length;i++)if(e.get(i)===t)return i;return-1},setZIndex:async i=>{void 0!==i&&await this.sortDataSources(e,t,i)},remove:()=>e.remove(t)}}}class w{locked=!1;queue=[];async runExclusive(t){await this.acquire();try{return await t()}finally{this.release()}}acquire(){return this.locked?new Promise((t=>this.queue.push(t))):(this.locked=!0,Promise.resolve())}release(){const t=this.queue.shift();t?t():this.locked=!1}}function p(t,e){if(!t)throw new Error(e)}const m=new w;class d{tileWidth;tileHeight;tilingScheme;rectangle;errorEvent;credit=void 0;tileDiscardPolicy=void 0;proxy=void 0;hasAlphaChannel=!0;minimumLevel;maximumLevel;Cesium;tileProcessor;resolution;resampleMethod;colorStops;readyPromiseInternal;ready=!1;constructor(t){const{Cesium:e,rectangleDegrees:i,tileProcessor:s,tileSize:r,resolution:a,resampleMethod:n,colorStops:o,minimumLevel:h,maximumLevel:c}=t;this.Cesium=e,this.tileProcessor=s,this.tileWidth=r,this.tileHeight=r,this.resolution=a,this.resampleMethod=n,this.colorStops=o,this.minimumLevel=h??0,this.maximumLevel=c,this.rectangle=e.Rectangle.fromDegrees(i[0],i[1],i[2],i[3]),this.tilingScheme=new e.WebMercatorTilingScheme,this.errorEvent=new e.Event,this.ready=!0,this.readyPromiseInternal=Promise.resolve(!0)}get tilingSchemeName(){return this.tilingScheme instanceof this.Cesium.WebMercatorTilingScheme?"WebMercator":void 0}get readyPromise(){return this.readyPromiseInternal}get tileCredits(){}getTileCredits(t,e,i){}get url(){}flipCanvasVertically(e,i,s){const r=document.createElement("canvas");r.width=i,r.height=s;const a=r.getContext("2d");return a?(a.translate(0,s),a.scale(1,-1),a.drawImage(e,0,0),r):(t("v-map - cesium - failed to get 2d context for flip"),e)}async createFlippedImageBitmap(e,i){if("function"==typeof createImageBitmap)try{const t=document.createElement("canvas");t.width=i,t.height=i;const s=t.getContext("2d");if(!s)throw new Error("Failed to get 2d context");const r=s.createImageData(i,i);r.data.set(e),s.putImageData(r,0,0);const a=this.flipCanvasVertically(t,i,i);return await createImageBitmap(a)}catch(e){return void t("v-map - cesium - createImageBitmap failed, falling back",e)}}async createFlippedImageFromRGBA(e){const i=Math.ceil(this.tileWidth*this.resolution),s=await this.createFlippedImageBitmap(e,i);if(s)return s;const r=document.createElement("canvas");r.width=i,r.height=i;const a=r.getContext("2d");if(!a)return void t("v-map - cesium - unable to acquire canvas 2d context");const n=a.createImageData(i,i);return n.data.set(e),a.putImageData(n,0,0),this.flipCanvasVertically(r,i,i)}async requestImage(i,s,r){if(!this.ready)return;if(r<this.minimumLevel||void 0!==this.maximumLevel&&r>this.maximumLevel)return;const a={x:i,y:s,z:r,tileSize:this.tileWidth,resolution:this.resolution,resampleMethod:this.resampleMethod,colorStops:this.colorStops};let n=null;try{if(n=await this.tileProcessor.getTileData(a),!n)return void e(`v-map - cesium - geotiff - requestImage(${i},${s},${r}): no data returned`);e(`v-map - cesium - geotiff - requestImage(${i},${s},${r}): rgba ${n.length} bytes, sampleSize=${Math.ceil(this.tileWidth*this.resolution)}`)}catch(e){return this.errorEvent.raiseEvent(e),void t("v-map - cesium - getTileData - GeoTIFF tile request failed",e)}try{const t=await this.createFlippedImageFromRGBA(n);return e(`v-map - cesium - geotiff - requestImage(${i},${s},${r}): result=${t?.constructor?.name??"undefined"}, size=${t instanceof HTMLCanvasElement||t instanceof ImageBitmap?`${t.width}x${t.height}`:"n/a"}`),t}catch(e){return this.errorEvent.raiseEvent(e),void t("v-map - cesium - createFlippedImageFromRGBA - GeoTIFF tile request failed",e)}}pickFeatures(){}}const y="v-map - cesium - terrain-geotiff - ";class f{Cesium;image;fromProjection="EPSG:4326";sourceBounds=[0,0,0,0];wgs84Bounds=[0,0,0,0];width=0;height=0;noDataValue=0;ready=!1;_readyPromise;heightmapWidth=65;heightmapHeight=65;proj4;tilingScheme;constructor(t){this.Cesium=t.Cesium,this.tilingScheme=new this.Cesium.GeographicTilingScheme,this._readyPromise=this.initialize(t)}async initialize(t){try{e(`${y}loadGeoTIFF: url=${t.url}`);const[i,{default:s},a]=await Promise.all([import("./p-Be3r33VF.js").then((function(t){return t.g})),import("./p-RpJarvr_.js"),import("./p-CXfA_q8m.js").then((function(t){return t.m}))]),n=await r(t.url,{projection:t.projection,forceProjection:t.forceProjection??!1,nodata:t.nodata},{geotiff:i,proj4:s,geokeysToProj4:a});return this.image=n.baseImage,this.fromProjection=n.fromProjection,this.sourceBounds=n.sourceBounds,this.wgs84Bounds=n.wgs84Bounds,this.width=n.width,this.height=n.height,this.noDataValue=n.noDataValue??0,this.proj4=n.proj4,e(`${y}loaded: projection=${this.fromProjection}, bounds=[${this.sourceBounds.map((t=>t.toFixed(0))).join(",")}], wgs84=[${this.wgs84Bounds.map((t=>t.toFixed(4))).join(",")}], size=${this.width}x${this.height}`),this.ready=!0,!0}catch(t){return i(`${y}failed to load GeoTIFF:`,t),this.ready=!1,!1}}get rectangle(){if(!this.ready||!this.wgs84Bounds)return this.Cesium.Rectangle.MAX_VALUE;const[t,e,i,s]=this.wgs84Bounds;return this.Cesium.Rectangle.fromDegrees(t,e,i,s)}async requestTileGeometry(e,i,s){if(this.ready&&this.image)try{const r=this.tilingScheme.tileXYToRectangle(e,i,s);let a=this.Cesium.Math.toDegrees(r.west),n=this.Cesium.Math.toDegrees(r.south),o=this.Cesium.Math.toDegrees(r.east),h=this.Cesium.Math.toDegrees(r.north);const[c,l,u,w]=this.wgs84Bounds;if(o<c||a>u||h<l||n>w)return this.createFlatHeightmap();a=Math.max(c,Math.min(u,a)),o=Math.max(c,Math.min(u,o)),n=Math.max(l,Math.min(w,n)),h=Math.max(l,Math.min(w,h));const p=e=>{try{return this.proj4("EPSG:4326",this.fromProjection,e)}catch(i){return t(`${y}transform failed:`,i),e}},m=p([a,n]),d=p([o,h]),[f,g,v,b]=this.sourceBounds,S=this.width,C=this.height,$=v-f,L=b-g,G=Math.floor((m[0]-f)/$*S),M=Math.floor((b-d[1])/L*C),k=Math.ceil((d[0]-f)/$*S),x=Math.ceil((b-m[1])/L*C),F=Math.max(0,Math.min(G,S)),E=Math.max(0,Math.min(M,C)),I=Math.max(1,Math.min(k-G,S-F)),T=Math.max(1,Math.min(x-M,C-E)),O=(await this.image.readRasters({window:[F,E,F+I,E+T],width:this.heightmapWidth,height:this.heightmapHeight,resampleMethod:"bilinear"}))[0],A=new Float32Array(this.heightmapWidth*this.heightmapHeight);for(let t=0;t<A.length;t++){let e=O[t];e!==this.noDataValue&&isFinite(e)||(e=0),A[t]=e}return new this.Cesium.HeightmapTerrainData({buffer:A,width:this.heightmapWidth,height:this.heightmapHeight,childTileMask:0,structure:{heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:1}})}catch(e){return t(`${y}failed to load tile geometry:`,e),this.createFlatHeightmap()}}createFlatHeightmap(){const t=new Float32Array(this.heightmapWidth*this.heightmapHeight);return t.fill(0),new this.Cesium.HeightmapTerrainData({buffer:t,width:this.heightmapWidth,height:this.heightmapHeight,childTileMask:0})}get availability(){}getTilingScheme(){return this.tilingScheme}getLevelMaximumGeometricError(t){return this.tilingScheme.ellipsoid.maximumRadius/(65*Math.pow(2,t))}loadTileDataAvailability(t,e,i){}getTileDataAvailable(t,e,i){if(!this.ready)return!1;const s=this.tilingScheme.tileXYToRectangle(t,e,i),r=this.Cesium.Math.toDegrees(s.west),a=this.Cesium.Math.toDegrees(s.south),n=this.Cesium.Math.toDegrees(s.east),o=this.Cesium.Math.toDegrees(s.north),[h,c,l,u]=this.wgs84Bounds;return!(n<h||r>l||o<c||a>u)}get readyPromise(){return this._readyPromise}get credit(){return new this.Cesium.Credit("GeoTIFF Terrain")}get hasWaterMask(){return!1}get hasVertexNormals(){return!1}get errorEvent(){return new this.Cesium.Event}}const g="v-map - cesium - terrain-geotiff - ";class v{Cesium;viewer;provider;options;opacity=1;previousProvider;constructor(t,e,i,s){this.Cesium=t,this.viewer=e,this.provider=i,this.options=s??{},this.previousProvider=e.terrainProvider,this.viewer.terrainProvider=this.provider}getOptions(){return this.options}setOptions(t){this.options=t}getVisible(){return this.viewer.scene.globe.show}setVisible(t){this.viewer.scene.globe.show=t}getOpacity(){return this.opacity}setOpacity(e){this.opacity=e;const i=this.viewer.scene.globe;if(!i.translucency)try{i.translucency=new this.Cesium.GlobeTranslucency,i.translucency.enabled=!0}catch(e){return void t("Cesium terrain opacity not supported",e)}i.translucency.enabled=e<1,i.translucency.frontFaceAlpha=e}getZIndex(){return 0}async setZIndex(t){}remove(){try{this.viewer.terrainProvider=this.previousProvider?this.previousProvider:new this.Cesium.EllipsoidTerrainProvider,this.viewer.scene.globe.show=!0}catch(e){t("Cesium terrain reset failed",e)}}}class b{viewer;Cesium;layerManager;shadowRoot;layerGroups=new l;layerManagerMutex=new w;layerErrorCallbacks=new Map;layerErrorCleanups=new Map;async init(t){this.shadowRoot=t.shadowRoot;const e=t.target.getRootNode()instanceof ShadowRoot?t.target.getRootNode():void 0;await async function(t){const e=`https://cdn.jsdelivr.net/npm/cesium@${s.replace(/^[^\d]*/,"")}/Build/Cesium`,i=`${e}/Widgets/widgets.css`,r=(await(await fetch(i)).text()).replace(/url\((?!['"]?data:)(['"]?)([^'")]+)\1\)/g,((t,i,s)=>`url(${e}/Widgets/${s.replace(/^\.?\//,"")})`));if(t)if("adoptedStyleSheets"in Document.prototype){const e=new CSSStyleSheet;await e.replace(r),t.adoptedStyleSheets=[...t.adoptedStyleSheets??[],e]}else{const e=document.createElement("style");e.textContent=r,t.appendChild(e)}}(e),this.Cesium=await async function(t=s){const e=`https://cdn.jsdelivr.net/npm/cesium@${t.replace(/^[^\d]*/,"")}/Build/Cesium`,i=`${e}/Cesium.js`;await m.runExclusive((async()=>{globalThis.Cesium||await new Promise(((t,e)=>{const s="cesium-cdn-script";if(document.getElementById(s))return t();const r=document.createElement("script");r.id=s,r.async=!0,r.src=i,r.addEventListener("load",(()=>t()),{once:!0}),r.addEventListener("error",(()=>e(new Error(`Laden fehlgeschlagen: ${i}`))),{once:!0}),document.head.appendChild(r)}))}));const r=globalThis.Cesium;p(r,"globalThis.Cesium nicht verfügbar.");const a=r.VERSION;var n,o;return p((n=String(t),o=a,n.match(/^\d+\.\d+/)?.[0]===o.match(/^\d+\.\d+/)?.[0]),`Cesium-Version abweichend: erwartet ~${t}, geladen ${a}`),globalThis.CESIUM_BASE_URL=e,r}(),Cesium.Ion.defaultAccessToken=null,this.viewer=new this.Cesium.Viewer(t.target,{baseLayer:!1,baseLayerPicker:!1,terrainProvider:new Cesium.EllipsoidTerrainProvider}),this.viewer.scene.primitives.removeAll(),this.viewer.scene.backgroundColor=this.Cesium.Color.WHITE,this.viewer.scene.globe.baseColor=this.Cesium.Color.WHITE,this.viewer.scene.globe.depthTestAgainstTerrain=!1,this.layerManager=new u(this.Cesium,this.viewer)}async destroy(){!function(t){if(!t)return;const i=Array.from(t.querySelectorAll("style"));for(const t of i)if(t.textContent?.includes(".cesium-credit-lightbox-overlay")){t.remove(),e("v-map - provider - cesium - Cesium‑Widget‑CSS entfernt");break}}(this.shadowRoot),this.viewer?.destroy(),this.viewer=void 0}async createLayer(t,e){let i=null;switch(t.type){case"geojson":{const s={},r=t,a=await this.createGeoJSONLayer(r,s);i=this.layerManager.addLayer(e,a),i.setOptions(s);break}case"osm":{const s=await this.createOSMLayer(t);i=this.layerManager.addLayer(e,s);break}case"google":{const s=await this.createGoogleLayer(t);i=this.layerManager.addLayer(e,s);break}case"terrain":{const s=await this.createTerrainLayer(t);i=this.layerManager.addCustomLayer(e,s);break}case"xyz":{const s=await this.createXYZLayer(t);i=this.layerManager.addLayer(e,s);break}case"wms":{const s=await this.addWMSLayer(t);i=this.layerManager.addLayer(e,s);break}case"wcs":{const s=await this.createWCSLayer(t);i=this.layerManager.addLayer(e,s);break}case"arcgis":await this.addArcGISLayer(t);break;case"wfs":{const s={clampToGround:!0},r=t,a=await this.createWFSLayer(r,s);i=this.layerManager.addLayer(e,a),i.setOptions(s);break}case"wkt":{const s={clampToGround:!0},r=t,a=await this.createWKTLayer(r,s);i=this.layerManager.addLayer(e,a),i.setOptions(s);break}case"geotiff":{const s=await this.createGeoTIFFLayer(t);i=this.layerManager.addLayer(e,s);break}case"tile3d":{const s=await this.createTile3DLayer(t);i=this.layerManager.addLayer(e,s);const r=t;i.setOptions(r.tilesetOptions??{}),r.cesiumStyle&&"setStyle"in i&&i.setStyle(r.cesiumStyle);break}case"terrain-geotiff":{const s=await this.createGeoTIFFTerrainLayer(t);i=this.layerManager.addCustomLayer(e,s);break}default:throw new Error(`Unsupported layer type: ${t.type}`)}if(!i)return null;const s=t;return void 0!==s.zIndex&&await i.setZIndex(s.zIndex),void 0!==s.opacity&&i.setOpacity(s.opacity),void 0!==s.visible&&i.setVisible(s.visible),i}async addLayerToGroup(t){return await this.layerManagerMutex.runExclusive((async()=>{const e=crypto.randomUUID(),i=await this.createLayer(t,e);return this.layerGroups.addLayerToGroup(t.groupId,void 0===typeof t.groupVisible||t.groupVisible,{id:e,elementId:t.layerElementId??t.elementId??null,layer:i}),this.layerGroups.apply(),e}))}async setBaseLayer(t,e){await this.layerManagerMutex.runExclusive((async()=>{this.layerGroups.setBasemap(t,e??null),this.layerGroups.apply()}))}async addBaseLayer(t,e,i){return i&&e?await this.layerManagerMutex.runExclusive((async()=>{const s=crypto.randomUUID(),r=await this.createLayer(t,s);return this.layerGroups.addLayerToGroup(t.groupId,void 0===typeof t.groupVisible||t.groupVisible,{id:s,elementId:i,layer:r}),this.layerGroups.setBasemap(t.groupId??"basemap",e),this.layerGroups.apply(),s})):null}async ensureGroup(t,e,i){this.layerGroups.ensureGroup(t,e)}async setGroupVisible(t,e){this.layerGroups.setGroupVisible(t,e),this.layerGroups.apply()}onLayerError(t,e){this.layerErrorCallbacks.set(t,e),this.attachCesiumErrorListeners(t)}offLayerError(t){this.layerErrorCleanups.get(t)?.(),this.layerErrorCleanups.delete(t),this.layerErrorCallbacks.delete(t)}attachCesiumErrorListeners(t){this.layerErrorCleanups.get(t)?.();const e=this.layerErrorCallbacks.get(t);if(!e)return;const i=this.layerManager.getLayer(t);if(!i)return;const s=[],r=()=>{e({type:"network",message:"Tile load error"})},a=i._imageryLayer;if(a?.imageryProvider?.errorEvent){const t=a.imageryProvider.errorEvent.addEventListener(r);s.push(t)}const n=i._tileset;if(n?.tileFailed){const t=n.tileFailed.addEventListener(r);s.push(t)}s.length>0&&this.layerErrorCleanups.set(t,(()=>s.forEach((t=>t()))))}async removeLayer(t){t&&(this.offLayerError(t),await this.layerManagerMutex.runExclusive((async()=>{this.layerManager.removeLayer(t),this.layerGroups.removeLayer(t,!0),this.layerGroups.apply()})))}async setOpacity(t,e){this.layerManager.setOpacity(t,e),this.layerGroups.apply()}async setVisible(t,e){this.layerManager.setVisible(t,e),this.layerGroups.apply()}async setZIndex(t,e){await this.layerManager.setZIndex(t,e),this.layerGroups.apply()}applyGeostylerStyling(t,i){t.__vmapLockOpacity=!0;const s=(t,e)=>null==t||"object"==typeof t&&null!==t&&"name"in t?e:t,r=(t,e)=>{if(null==t)return e;if("number"==typeof t)return t;const i=Number(t);return Number.isFinite(i)?i:e},a=t.entities.values;if(i.rules)for(const t of i.rules)if(t.symbolizers)for(const i of t.symbolizers)for(let t=0;t<a.length;t++){const n=a[t];switch(i.kind){case"Fill":if(n.polygon){const t=s(i.color,"rgba(0,100,255,0.3)"),a=r(s(i.opacity,.3),.3),o=s(i.outlineColor,"rgba(0,100,255,1)"),h=s(i.outlineWidth,1);let c=this.parseCesiumColor(t,this.Cesium.Color.BLUE.withAlpha(.3));null!=a&&(c=this.applyCesiumOpacity(c,a));const l=this.parseCesiumColor(o,this.Cesium.Color.BLUE);e("v-map - provider - cesium - applyGeostylerStyling: Fill",{fillColor:t,fillOpacity:a,computedFill:c?.toString?.(),outlineColor:o,outlineWidth:h}),n.polygon.fill=new this.Cesium.ConstantProperty(!0),n.polygon.material=new this.Cesium.ColorMaterialProperty(c),n.polygon.outline=new this.Cesium.ConstantProperty(!0),n.polygon.outlineColor=new this.Cesium.ConstantProperty(l),n.polygon.outlineWidth=new this.Cesium.ConstantProperty(h),n.polygon.extrudedHeight=void 0,n.polygon.heightReference=new this.Cesium.ConstantProperty(this.Cesium.HeightReference.CLAMP_TO_GROUND),n.polygon.perPositionHeight=new this.Cesium.ConstantProperty(!1),n.polygon.classificationType=new this.Cesium.ConstantProperty(this.Cesium.ClassificationType.BOTH)}break;case"Line":if(n.polyline){const t=s(i.color,"rgba(0,100,255,1)"),a=r(s(i.width,2),2),o=r(s(i.opacity,1),1);let h=this.parseCesiumColor(t,this.Cesium.Color.BLUE);null!=o&&(h=this.applyCesiumOpacity(h,o)),e("v-map - provider - cesium - applyGeostylerStyling: Line",{lineColor:t,lineOpacity:o,computedColor:h?.toString?.(),lineWidth:a}),n.polyline.material=new this.Cesium.ColorMaterialProperty(h),n.polyline.width=new this.Cesium.ConstantProperty(a)}break;case"Mark":if(n.point){const t=s(i.color,"rgba(0,100,255,1)"),a=r(s(i.radius,6),6),o=r(s(i.opacity,1),1);let h=this.parseCesiumColor(t,this.Cesium.Color.BLUE);null!=o&&(h=this.applyCesiumOpacity(h,o)),e("v-map - provider - cesium - applyGeostylerStyling: Mark",{pointColor:t,pointOpacity:o,computedColor:h?.toString?.(),pointRadius:a}),n.point.color=new this.Cesium.ConstantProperty(h),n.point.pixelSize=new this.Cesium.ConstantProperty(a)}break;case"Icon":if(n.point){const t=s(i.image),a=r(s(i.size,32),32),o=r(s(i.opacity,1),1);t&&"string"==typeof t&&(n.billboard=new this.Cesium.BillboardGraphics({image:new this.Cesium.ConstantProperty(t),width:new this.Cesium.ConstantProperty(a),height:new this.Cesium.ConstantProperty(a),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM),color:null!=o?new this.Cesium.ConstantProperty(this.Cesium.Color.WHITE.withAlpha(o)):void 0}),n.point.show=new this.Cesium.ConstantProperty(!1),e("v-map - provider - cesium - applyGeostylerStyling: Icon",{iconSrc:t,iconSize:a,iconOpacity:o}))}break;case"Text":const t=i.label,a="string"==typeof t?t:void 0;if(a&&n.properties&&n.properties[a]){const t=s(i.color,"#000000"),o=r(s(i.size,12),12),h=r(s(i.opacity,1),1);let c=this.parseCesiumColor(t,this.Cesium.Color.WHITE);null!=h&&(c=this.applyCesiumOpacity(c,h)),e("v-map - provider - cesium - applyGeostylerStyling: Text",{labelProp:a,textColor:t,textOpacity:h,computedColor:c?.toString?.(),textSize:o});const l=n.properties[a]?.getValue?.(this.viewer.clock.currentTime)??n.properties[a]?._value??"";n.label=new this.Cesium.LabelGraphics({text:new this.Cesium.ConstantProperty(String(l)),font:new this.Cesium.ConstantProperty(`${o}px Arial`),fillColor:new this.Cesium.ConstantProperty(c),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM)})}}}}parseCesiumColor(t,e){if(!t)return e;if(t.startsWith("#"))return this.Cesium.Color.fromCssColorString(t);if(t.includes("rgb"))return this.Cesium.Color.fromCssColorString(t);try{return this.Cesium.Color.fromCssColorString(t)}catch{return e}}applyCesiumOpacity(t,e){return t?t.withAlpha(e):t}createCesiumStyle(t={}){const e=this.Cesium.Color.BLUE.withAlpha(.3),i=this.Cesium.Color.BLUE,s=this.Cesium.Color.BLUE,r=this.parseCesiumColor(t.fillColor,e),a=this.parseCesiumColor(t.strokeColor,i),n=this.parseCesiumColor(t.pointColor,s),o=void 0!==t.fillOpacity?this.applyCesiumOpacity(r,t.fillOpacity):r,h=void 0!==t.strokeOpacity?this.applyCesiumOpacity(a,t.strokeOpacity):a,c=void 0!==t.pointOpacity?this.applyCesiumOpacity(n,t.pointOpacity):n;return{fill:!0,fillColor:o,outline:!0,outlineColor:h,outlineWidth:t.strokeWidth??2,extrudedHeight:t.extrudeHeight,heightReference:t.zOffset?this.Cesium.HeightReference.RELATIVE_TO_GROUND:this.Cesium.HeightReference.CLAMP_TO_GROUND,pixelSize:t.pointRadius??8,color:c,scaleByDistance:t.pointRadius?new this.Cesium.NearFarScalar(150,2,15e6,.5):void 0,width:t.strokeWidth??2,clampToGround:!t.zOffset,labelText:t.textProperty,labelFont:t.textSize?`${t.textSize}pt monospace`:"12pt monospace",labelFillColor:t.textColor?this.parseCesiumColor(t.textColor,this.Cesium.Color.WHITE):this.Cesium.Color.WHITE,labelOutlineColor:t.textHaloColor?this.parseCesiumColor(t.textHaloColor,this.Cesium.Color.BLACK):this.Cesium.Color.BLACK,labelOutlineWidth:t.textHaloWidth??1,labelPixelOffset:t.textOffset?new this.Cesium.Cartesian2(t.textOffset[0],t.textOffset[1]):this.Cesium.Cartesian2.ZERO,height:t.zOffset??0}}applyEnhancedStyling(t,e={}){const i=this.createCesiumStyle(e),s=t.entities.values;for(let t=0;t<s.length;t++){const r=s[t];let a=i;if(e.styleFunction&&r.properties){const t={properties:r.properties._propertyNames.reduce(((t,e)=>(t[e]=r.properties[e]?._value,t)),{}),geometry:r},s=e.styleFunction(t);s&&(a={...i,...this.createCesiumStyle(s)})}if(r.polygon&&(r.polygon.fill=new this.Cesium.ConstantProperty(a.fill),r.polygon.material=new this.Cesium.ColorMaterialProperty(a.fillColor),r.polygon.outline=new this.Cesium.ConstantProperty(a.outline),r.polygon.outlineColor=new this.Cesium.ConstantProperty(a.outlineColor),r.polygon.outlineWidth=new this.Cesium.ConstantProperty(a.outlineWidth),r.polygon.height=void 0!==a.height?new this.Cesium.ConstantProperty(a.height):void 0,r.polygon.extrudedHeight=void 0!==a.extrudedHeight?new this.Cesium.ConstantProperty(a.extrudedHeight):void 0,r.polygon.heightReference=void 0!==a.heightReference?new this.Cesium.ConstantProperty(a.heightReference):void 0),r.polyline&&(r.polyline.material=new this.Cesium.ColorMaterialProperty(a.outlineColor),r.polyline.width=new this.Cesium.ConstantProperty(a.width),r.polyline.clampToGround=new this.Cesium.ConstantProperty(a.clampToGround)),r.point){r.point.pixelSize=new this.Cesium.ConstantProperty(a.pixelSize),r.point.color=new this.Cesium.ConstantProperty(a.color);const t=a.scaleByDistance;r.point.scaleByDistance=t?new this.Cesium.ConstantProperty(t):void 0,e.iconUrl&&(r.billboard=new this.Cesium.BillboardGraphics({image:new this.Cesium.ConstantProperty(e.iconUrl),width:new this.Cesium.ConstantProperty(e.iconSize?e.iconSize[0]:32),height:new this.Cesium.ConstantProperty(e.iconSize?e.iconSize[1]:32),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM),scaleByDistance:t?new this.Cesium.ConstantProperty(t):void 0}),r.point.show=new this.Cesium.ConstantProperty(!1))}if(e.textProperty&&r.properties&&r.properties[e.textProperty]){const t=r.properties[e.textProperty]?.getValue?.(this.viewer.clock.currentTime)??r.properties[e.textProperty]?._value??"";r.label=new this.Cesium.LabelGraphics({text:new this.Cesium.ConstantProperty(String(t)),font:new this.Cesium.ConstantProperty(a.labelFont),fillColor:new this.Cesium.ConstantProperty(a.labelFillColor),outlineColor:new this.Cesium.ConstantProperty(a.labelOutlineColor),outlineWidth:new this.Cesium.ConstantProperty(a.labelOutlineWidth),pixelOffset:new this.Cesium.ConstantProperty(a.labelPixelOffset),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM)})}}}async createWKTLayer(t,e){const i=await this.wktToGeoJSON(t),s=await this.Cesium.GeoJsonDataSource.load(i,e);return t.geostylerStyle?this.applyGeostylerStyling(s,t.geostylerStyle):t.style&&this.applyEnhancedStyling(s,t.style),s}async wktToGeoJSON(t){const e=await this.resolveWktText(t),i=await import("./p-DR9McdNX.js").then((function(t){return t.i})),s="function"==typeof i.default?i.default:i.parse;if("function"!=typeof s)throw new Error("wellknown parser not available");const r=s(e);if(!r)throw new Error("Failed to parse WKT");return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:r}]}}async resolveWktText(t){if(t.wkt)return t.wkt;if(t.url){const e=await fetch(t.url);if(!e.ok)throw new Error(`Failed to fetch WKT: ${e.status}`);return await e.text()}throw new Error("Either wkt or url must be provided")}async createGeoJSONLayer(t,e){let i=null;i=t.geojson?JSON.parse(t.geojson):t.url;const s=await this.Cesium.GeoJsonDataSource.load(i,e);return t.geostylerStyle?this.applyGeostylerStyling(s,t.geostylerStyle):t.style&&this.applyEnhancedStyling(s,t.style),s}async createWFSLayer(t,e){const i=await this.fetchWFSFromUrl(t),s=await this.Cesium.GeoJsonDataSource.load(i,e);return t.geostylerStyle?this.applyGeostylerStyling(s,t.geostylerStyle):t.style&&this.applyEnhancedStyling(s,t.style),s}async createOSMLayer(t){return new this.Cesium.ImageryLayer(new this.Cesium.OpenStreetMapImageryProvider({url:t.url||"https://a.tile.openstreetmap.org"}))}async createGoogleLayer(t){if(!t.apiKey)throw new Error("Google-Layer benötigt 'apiKey' (Google Maps Platform).");await this.loadGoogleMapsApi(t.apiKey,{language:t.language,region:t.region,libraries:t.libraries});const e=this.getGoogleMapTypeId(t.mapType||"roadmap"),i=this.Cesium,s=new i.UrlTemplateImageryProvider({url:"https://maps.googleapis.com/maps/api/staticmap?template",maximumLevel:t.maxZoom||19,minimumLevel:0,tilingScheme:new i.WebMercatorTilingScheme,credit:"Google Maps",urlSchemeZeroPadding:{"{x}":"","{y}":"","{z}":""}});return s.buildImageResource=function(s,r,a){const n=(new i.WebMercatorTilingScheme).tileXYToRectangle(s,r,a),o=i.Math.toDegrees(n.west),h=i.Math.toDegrees(n.south),c=i.Math.toDegrees(n.east),l=i.Math.toDegrees(n.north),u=new URLSearchParams({center:`${(h+l)/2},${(o+c)/2}`,zoom:a.toString(),size:"256x256",scale:"scaleFactor1x"===t.scale?"1":"2",maptype:e,key:t.apiKey,format:"png"});t.language&&u.set("language",t.language),t.region&&u.set("region",t.region);const w=`https://maps.googleapis.com/maps/api/staticmap?${u.toString()}`;return new i.Resource({url:w})},this.ensureGoogleLogo(),new this.Cesium.ImageryLayer(s,{alpha:t.opacity??1,show:t.visible??!0})}getGoogleMapTypeId(t){switch(t){case"roadmap":default:return"roadmap";case"satellite":return"satellite";case"terrain":return"terrain";case"hybrid":return"hybrid"}}async loadGoogleMapsApi(t,e){const i=window,s=i.__mockGoogleMapsApi;"function"!=typeof s?i.google?.maps||await new Promise(((s,r)=>{const a="___cesiumGoogleInit___"+Math.random().toString(36).slice(2);i[a]=()=>s();const n=document.createElement("script"),o=new URLSearchParams({key:t,callback:a,v:"weekly"});e?.language&&o.set("language",e.language),e?.region&&o.set("region",e.region),e?.libraries?.length&&o.set("libraries",e.libraries.join(",")),n.src=`https://maps.googleapis.com/maps/api/js?${o.toString()}`,n.async=!0,n.onerror=()=>r(new Error("Google Maps JS API failed to load")),document.head.appendChild(n)})):await s(t,e)}ensureGoogleLogo(){if(!this.viewer?.container||this.viewer.container._googleLogoAdded)return;const t=document.createElement("img");t.src="https://developers.google.com/static/maps/documentation/images/google_on_white.png",t.alt="Google",t.style.position="absolute",t.style.bottom="6px",t.style.left="6px",t.style.height="18px",t.style.pointerEvents="none",t.style.zIndex="1000",this.viewer.container.appendChild(t),this.viewer.container._googleLogoAdded=!0}async createXYZLayer(t){if(!t.url)throw new Error("XYZ layer requires a url");const e=Array.isArray(t.attributions)?t.attributions.join(", "):t.attributions,i={url:t.url,credit:e,maximumLevel:t.maxZoom,...t.options||{}},s=new this.Cesium.UrlTemplateImageryProvider(i);return new this.Cesium.ImageryLayer(s,{alpha:t.opacity??1,show:t.visible??!0})}async createTerrainLayer(t){let e;e=t.elevationData?await this.Cesium.CesiumTerrainProvider.fromUrl(t.elevationData):await this.Cesium.createWorldTerrainAsync();const i=new v(this.Cesium,this.viewer,e,t);return void 0!==t.visible&&i.setVisible(t.visible),void 0!==t.opacity&&i.setOpacity(t.opacity),i}async createGeoTIFFTerrainLayer(t){if(!t.url){e(`${g}layer created without URL, waiting for URL to load`);const i=new this.Cesium.EllipsoidTerrainProvider,s=new v(this.Cesium,this.viewer,i,t);return s.setVisible(!1),s}try{e(`${g}create layer: url=${t.url}`);const i=await async function(t){const e=new f(t);return await e.readyPromise,e}({url:t.url,projection:t.projection,forceProjection:t.forceProjection,nodata:t.nodata,Cesium:this.Cesium}),s=new v(this.Cesium,this.viewer,i,t);return void 0!==t.visible&&s.setVisible(t.visible),void 0!==t.opacity&&s.setOpacity(t.opacity),e(`${g}layer created successfully`),s}catch(e){i(`${g}failed to create terrain layer:`,e);const s=new this.Cesium.EllipsoidTerrainProvider;return new v(this.Cesium,this.viewer,s,t)}}async addWMSLayer(t){return new this.Cesium.ImageryLayer(new this.Cesium.WebMapServiceImageryProvider({url:t.url,layers:t.layers,parameters:t.extraParams}))}async createWCSLayer(t){if(!t.url||!t.coverageName)throw new Error("WCS layer requires url and coverageName");const e=t.version??"2.0.1",i=t.format??"image/tiff",s=t.projection??"EPSG:4326",r=t.tileSize??256,a=this.Cesium,n=new a.UrlTemplateImageryProvider({url:`${t.url}?wcs_placeholder`,maximumLevel:t.maxZoom??18,minimumLevel:t.minZoom??0,tileWidth:r,tileHeight:r,tilingScheme:new a.GeographicTilingScheme,credit:"WCS"});return n.buildImageResource=function(n,o,h){const c=(new a.GeographicTilingScheme).tileXYToRectangle(n,o,h),l=a.Math.toDegrees(c.west),u=a.Math.toDegrees(c.south),w=a.Math.toDegrees(c.east),p=a.Math.toDegrees(c.north),m={SERVICE:"WCS",REQUEST:"GetCoverage",VERSION:e,FORMAT:i};let d;if(e.startsWith("2.0")){const e={...m,coverageId:t.coverageName,...t.params||{}};(i.includes("tiff")||i.includes("geotiff"))&&(e["geotiff:compression"]="LZW");const s=new URLSearchParams;Object.entries(e).forEach((([t,e])=>{null!=e&&s.set(t,String(e))}));const r=s.toString(),a=`subset=X(${l},${w})`,n=`subset=Y(${u},${p})`;d=`${t.url}${t.url.includes("?")?"&":"?"}${r}&${a}&${n}`}else{const e={...m,COVERAGE:t.coverageName,BBOX:`${l},${u},${w},${p}`,CRS:s,WIDTH:String(r),HEIGHT:String(r),...t.params||{}},i=new URLSearchParams;Object.entries(e).forEach((([t,e])=>{null!=e&&i.set(t,String(e))})),d=`${t.url}${t.url.includes("?")?"&":"?"}${i.toString()}`}return new a.Resource({url:d})},new this.Cesium.ImageryLayer(n,{alpha:t.opacity??1,show:t.visible??!0})}async addArcGISLayer(t){const e=await this.Cesium.ArcGisMapServerImageryProvider.fromUrl(t.url);this.viewer.imageryLayers.addImageryProvider(e)}async createGeoTIFFLayer(t){if(!t.url)throw new Error("GeoTIFF layer requires a URL");try{const e=t,i=await a(t.url,e.projection,e.forceProjection,t.nodata),s=await n(i,"EPSG:3857"),r=new o(s);let c;if(r.createGlobalTriangulation(),t.colorMap){const{stops:e}=h(t.colorMap,t.valueRange);c=e}const l=new d({Cesium:this.Cesium,rectangleDegrees:i.wgs84Bounds,tileProcessor:r,tileSize:t.tileSize??256,resolution:t.resolution??1,resampleMethod:t.resampleMethod??"bilinear",colorStops:c}),u=new this.Cesium.ImageryLayer(l,{alpha:t.opacity??1,show:t.visible??!0});return u.__vmapGeoTIFFMeta={url:t.url,width:i.width,height:i.height,samplesPerPixel:i.samplesPerPixel,noData:i.noDataValue},u}catch(t){i("v-map - provider - cesium - Failed to create GeoTIFF layer",t);const e=new this.Cesium.SingleTileImageryProvider({url:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",rectangle:this.Cesium.Rectangle.fromDegrees(-180,-90,180,90)});return new this.Cesium.ImageryLayer(e,{alpha:0,show:!1})}}async createTile3DLayer(t){if(!t.url)throw new Error("Tile3D layer requires a URL");const e=await this.Cesium.Cesium3DTileset.fromUrl(t.url,t.tilesetOptions??{});return t.cesiumStyle&&(e.style=new this.Cesium.Cesium3DTileStyle(t.cesiumStyle)),e}async updateLayer(t,e){return await this.layerManagerMutex.runExclusive((async()=>{const i=this.layerErrorCallbacks.has(t);i&&this.offLayerError(t);const s=this.layerManager.getLayer(t);switch(e.type){case"geojson":{const i=e.data,r=s.getOptions(),a=await this.createGeoJSONLayer({geojson:i.geojson,url:i.url,style:i.style,geostylerStyle:i.geostylerStyle},r);this.layerManager.replaceLayer(t,s,a).setOptions(r)}break;case"wfs":{const i=e.data,r=s.getOptions(),a=await this.createWFSLayer(i,r);this.layerManager.replaceLayer(t,s,a).setOptions(r)}break;case"osm":{const i=s.getOptions(),r=new this.Cesium.ImageryLayer(new this.Cesium.OpenStreetMapImageryProvider({url:e.data.url||"https://a.tile.openstreetmap.org"}));this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"google":{const i=s.getOptions(),r=await this.createGoogleLayer(e.data);this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"xyz":{const i=s.getOptions(),r=await this.createXYZLayer(e.data);this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"wcs":{const i=s.getOptions(),r=await this.createWCSLayer(e.data);this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"wkt":{const i=e.data,r=s.getOptions(),a=await this.createWKTLayer({wkt:i.wkt,url:i.url,style:i.style,geostylerStyle:i.geostylerStyle},r);this.layerManager.replaceLayer(t,s,a).setOptions(r)}break;case"geotiff":{const i=e.data,r=await this.createGeoTIFFLayer({url:i.url});this.layerManager.replaceLayer(t,s,r)}break;case"tile3d":{const i=e.data??{};if(!i.url)throw new Error("tile3d update requires a url");const r=await this.createTile3DLayer({type:"tile3d",url:i.url,tilesetOptions:i.tilesetOptions,cesiumStyle:i.cesiumStyle}),a=this.layerManager.replaceLayer(t,s,r);a.setOptions(i.tilesetOptions??{}),i.cesiumStyle&&"setStyle"in a&&a.setStyle(i.cesiumStyle)}break;case"tile3d-style":"setStyle"in s&&s.setStyle((e.data??{}).style??{});break;case"terrain":{const i=s.getOptions(),r=s.getVisible(),a=s.getOpacity();s.remove();const n=await this.createTerrainLayer({type:"terrain",...i,...e.data??{}}),o=this.layerManager.addCustomLayer(t,n);o.setVisible(r),o.setOpacity(a)}break;case"terrain-geotiff":{s.remove();const i=await this.createGeoTIFFTerrainLayer({type:"terrain-geotiff",...e.data??{}});this.layerManager.addCustomLayer(t,i)}}i&&this.attachCesiumErrorListeners(t)}))}async setView(i,s){if(!this.viewer)return;const[r,a]=i;this.viewer.camera.flyTo({destination:this.Cesium.Cartesian3.fromDegrees(r,a,1e6/s),duration:2,orientation:{heading:this.Cesium.Math.toRadians(0),pitch:this.Cesium.Math.toRadians(-30),roll:0},complete:()=>e("v-map - provider - cesium - Fly‑to finished"),cancel:()=>t("v-map - provider - cesium - Fly‑to cancelled")})}async fetchWFSFromUrl(t){const e={service:"WFS",request:"GetFeature",version:t.version??"1.1.0",typeName:t.typeName,outputFormat:t.outputFormat??"application/json",srsName:t.srsName??"EPSG:4326",...t.params??{}},i=this.appendParams(t.url,e),s=await fetch(i);if(!s.ok)throw new Error(`WFS request failed (${s.status} ${s.statusText})`);const r=(t.outputFormat??"application/json").toLowerCase();if(r.includes("json")||r.includes("geojson")||"application/json"===r){const t=s.headers.get("content-type");if(t?.includes("application/json"))return await s.json();const e=await s.text();return JSON.parse(e)}if(r.includes("gml")||r.includes("xml")){const t=await s.text(),{GmlParser:e}=await import("./p-DhQAXuA7.js"),i=new e;return await i.parse(t)}return await s.json()}appendParams(t,e){const i=new URLSearchParams;return Object.entries(e).forEach((([t,e])=>{null!=e&&i.set(t,String(e))})),i.toString()?`${t}${t.includes("?")?"&":"?"}${i.toString()}`:t}}export{b as CesiumProvider}
|
|
1
|
+
import{w as t,l as e,e as i}from"./p-QJHuuz0g.js";import{C as s}from"./p-BOfJXm8U.js";import{l as r,a,b as n,G as o,g as h}from"./p-yXLNXXx-.js";import"./p-BoNyIrdq.js";import"./p-CrV_misM.js";import"./p-DVBtCUtQ.js";class c{id;_visible=!0;_basemap=null;_layers=new Map;_originalVisible=new Map;_dirty=!0;constructor(t,e=!0){this.id=t,this._visible=e}get visible(){return this._visible}set visible(t){this._visible!==t&&(this._visible=t,this._dirty=!0)}get basemap(){return this._basemap}set basemap(t){this._basemap!==t&&(this._basemap=t,this._dirty=!0)}isDirty(){return this._dirty}addLayer(t){this._layers.has(t.id)||(this._layers.set(t.id,t),this._originalVisible.set(t.id,t.layer.getVisible()),this._dirty=!0)}setLayerElementId(t,e){const i=this._layers.get(t);i&&i.elementId!==e&&(i.elementId=e??null,this._dirty=!0)}removeLayer(t){const e=this._layers.delete(t);return this._originalVisible.delete(t),e&&(this._dirty=!0),e}clear(){this._layers.clear(),this._originalVisible.clear(),this._dirty=!0}apply(){if(this._dirty){for(const[t,e]of this._layers){const i=this._originalVisible.get(t)??!0;let s=this._visible&&i;s&&this._basemap&&(s=e.elementId===this._basemap),e.layer.getVisible()!==s&&e.layer.setVisible(s)}this._dirty=!1}}}class l{_groups=[];_dirty=!0;get groups(){return[...this._groups]}getGroup(t){return this._groups.find((e=>e.id===t))}hasGroup(t){return this._groups.some((e=>e.id===t))}ensureGroup(t,e=!0){let i=this.getGroup(t);return i||(i=new c(t,e),this._groups.push(i),this._dirty=!0,i)}addLayerToGroup(t,e,i){this.ensureGroup(t,e).addLayer(i),this._dirty=!0}removeLayer(t,e=!0){let i=!1;for(const s of this._groups)if(s.removeLayer(t)&&(i=!0,!e))break;return i&&(this._dirty=!0),i}setGroupVisible(t,e){const i=this.getGroup(t);if(!i)throw new Error(`CesiumLayerGroup "${t}" nicht gefunden`);i.visible=e,this._dirty=!0}setBasemap(t,e){const i=this.getGroup(t);if(!i)throw new Error(`CesiumLayerGroup "${t}" nicht gefunden`);i.basemap=e,this._dirty=!0}apply(){if(this._dirty||this._groups.some((t=>t.isDirty()))){for(const t of this._groups)t.apply();this._dirty=!1}}clear(){this._groups=[],this._dirty=!0}}class u{Cesium;layers=new Map;viewer;constructor(t,e){this.viewer=e,this.Cesium=t}replaceLayer(t,e,i){if(!this.Cesium)throw new Error("Cesium must be initialized first. Call init() method.");const s=e.getZIndex(),r=e.getVisible(),a=e.getOpacity();this.removeLayer(t);const n=this.addLayer(t,i);return n.setZIndex(s),n.setVisible(r),n.setOpacity(a),n}addLayer(t,e){if(!this.Cesium)throw new Error("Cesium must be initialized first. Call init() method.");e instanceof this.Cesium.GeoJsonDataSource||e instanceof this.Cesium.DataSource?this.viewer.dataSources.add(e):e instanceof this.Cesium.Cesium3DTileset?(this.viewer.scene.primitives.add(e),e.style||(e.style=new this.Cesium.Cesium3DTileStyle)):e instanceof this.Cesium.ImageryLayer&&this.viewer.imageryLayers.add(e),e.id=t;const i=this.wrapLayer(e);return this.layers.set(t,i),i}addCustomLayer(t,e){return this.layers.set(t,e),e}getLayer(t){const e=this.layers.get(t);if(!e)throw new Error(`Layer mit ID "${t}" nicht gefunden.`);return e}getLayerById(t){return this.getLayer(t)}removeLayer(t){this.getLayer(t).remove(),this.layers.delete(t)}setVisible(t,e){this.getLayer(t).setVisible(e)}setOpacity(t,e){this.getLayer(t).setOpacity(e)}async setZIndex(t,e){const i=this.getLayer(t);await i.setZIndex(e)}wrapLayer(t){return t instanceof this.Cesium.ImageryLayer?this.wrapImageryLayer(t):t instanceof this.Cesium.Cesium3DTileset?this.wrapTilesetLayer(t):this.wrapDataSourceLayer(t)}async sortImageryLayers(t,e,i){const s=this.sort(t,e,i);t.removeAll(!1),s.forEach((e=>t.add(e)))}async sort3DTileSets(t,e,i){const s=this.sort(t,e,i);t.removeAll(),s.forEach((e=>t.add(e)))}async sortDataSources(t,e,i){const s=this.sort(t,e,i);t.removeAll(!1),s.forEach((async e=>await t.add(e)))}sort(t,e,i){t.remove(e,!1);const s=[];for(let e=0;e<t.length;e++)s.push(t.get(e));return s.sort(((t,e)=>(t.zIndex||0)-(e.zIndex||0))),e.zIndex=i,s.push(e),s.sort(((t,e)=>(t.zIndex||0)-(e.zIndex||0))),s}wrapImageryLayer(t){const e=this.viewer.imageryLayers;let i={};return{getOptions:()=>i,setOptions(t){i=t},getVisible:()=>t.show,setVisible:e=>{t.show=e},getOpacity:()=>t.alpha,setOpacity:e=>{t.alpha=e},getZIndex:()=>{for(let i=0;i<e.length;i++)if(e.get(i)===t)return i;return-1},setZIndex:async i=>{void 0!==i&&await this.sortImageryLayers(e,t,i)},remove:()=>e.remove(t)}}wrapTilesetLayer(t){const e=this.viewer.scene.primitives;let i={};return{getOptions:()=>i,setOptions(t){i=t},getVisible:()=>t.show,setVisible:e=>{t.show=e},getOpacity:()=>{const e=t.style;if(e.color&&"string"==typeof e.color){const t=e.color.match(/color\(.*?,([\d.]+)\)/);return t?parseFloat(t[1]):1}return 1},setOpacity:e=>{const i=t.style.color;let s;if("string"==typeof i){const t=i.replace(/color\((.*?),[\d.]+\)/,`color($1, ${e})`);s=t.includes("color")?t:`color('white', ${e})`}else s=`color('white', ${e})`;t.style=new this.Cesium.Cesium3DTileStyle({color:s,colorBlendMode:this.Cesium.ColorBlendMode.MIX})},getZIndex:()=>{const e=this.viewer.scene.primitives;for(let i=0;i<e.length;i++)if(e.get(i)===t)return i;return-1},setZIndex:async i=>{void 0!==i&&this.sort3DTileSets(e,t,i)},setColor:(e,i=1)=>{const s=e instanceof this.Cesium.Color?e.toCssHexString():e.replace(/[#\s]/g,"");t.style=new this.Cesium.Cesium3DTileStyle({color:`color('${s}', ${i})`,colorBlendMode:this.Cesium.ColorBlendMode.MIX})},setStyle:e=>{t.style=e instanceof this.Cesium.Cesium3DTileStyle?e:new this.Cesium.Cesium3DTileStyle(e)},remove:()=>this.viewer.scene.primitives.remove(t)}}wrapDataSourceLayer(t){const e=this.viewer.dataSources;let i={};return{getOptions:()=>i,setOptions(t){i=t},getVisible:()=>t.show,setVisible:e=>{t.show=e},getOpacity:()=>1,setOpacity:e=>{t.__vmapLockOpacity||t.entities.values.forEach((t=>{const i=(t,i)=>{const{Color:s,JulianDate:r}=this.Cesium,a=t=>s.fromAlpha(t??i,e,new s);if(!t)return new this.Cesium.ConstantProperty(a(i));const n=t;if(n&&"function"==typeof n.getValue){const t=a(n.getValue(this.viewer?.clock?.currentTime??new r,new s));return"function"==typeof n.setValue?(n.setValue(t),n):new this.Cesium.ConstantProperty(t)}return new this.Cesium.ConstantProperty(a(t instanceof this.Cesium.Color?t:i))};if(t.polygon){const e=t.polygon.material;(e instanceof Cesium.ColorMaterialProperty||e instanceof Cesium.ImageMaterialProperty)&&(e.color=i(e.color,Cesium.Color.WHITE))}if(t.polyline){const e=t.polyline.material;(e instanceof Cesium.ColorMaterialProperty||e instanceof Cesium.PolylineOutlineMaterialProperty)&&(e.color=i(e.color,Cesium.Color.WHITE))}t.point&&(t.point.color=i(t.point.color,Cesium.Color.WHITE)),t.billboard&&(t.billboard.color=i(t.billboard.color,Cesium.Color.WHITE)),t.label&&(t.label.fillColor=i(t.label.fillColor,Cesium.Color.BLACK),t.label.outlineColor&&(t.label.outlineColor=i(t.label.outlineColor,Cesium.Color.BLACK))),t.model&&(t.model.color=i(t.model.color,Cesium.Color.WHITE))}))},getZIndex:()=>{for(let i=0;i<e.length;i++)if(e.get(i)===t)return i;return-1},setZIndex:async i=>{void 0!==i&&await this.sortDataSources(e,t,i)},remove:()=>e.remove(t)}}}class w{locked=!1;queue=[];async runExclusive(t){await this.acquire();try{return await t()}finally{this.release()}}acquire(){return this.locked?new Promise((t=>this.queue.push(t))):(this.locked=!0,Promise.resolve())}release(){const t=this.queue.shift();t?t():this.locked=!1}}function p(t,e){if(!t)throw new Error(e)}const m=new w;class d{tileWidth;tileHeight;tilingScheme;rectangle;errorEvent;credit=void 0;tileDiscardPolicy=void 0;proxy=void 0;hasAlphaChannel=!0;minimumLevel;maximumLevel;Cesium;tileProcessor;resolution;resampleMethod;colorStops;readyPromiseInternal;ready=!1;constructor(t){const{Cesium:e,rectangleDegrees:i,tileProcessor:s,tileSize:r,resolution:a,resampleMethod:n,colorStops:o,minimumLevel:h,maximumLevel:c}=t;this.Cesium=e,this.tileProcessor=s,this.tileWidth=r,this.tileHeight=r,this.resolution=a,this.resampleMethod=n,this.colorStops=o,this.minimumLevel=h??0,this.maximumLevel=c,this.rectangle=e.Rectangle.fromDegrees(i[0],i[1],i[2],i[3]),this.tilingScheme=new e.WebMercatorTilingScheme,this.errorEvent=new e.Event,this.ready=!0,this.readyPromiseInternal=Promise.resolve(!0)}get tilingSchemeName(){return this.tilingScheme instanceof this.Cesium.WebMercatorTilingScheme?"WebMercator":void 0}get readyPromise(){return this.readyPromiseInternal}get tileCredits(){}getTileCredits(t,e,i){}get url(){}flipCanvasVertically(e,i,s){const r=document.createElement("canvas");r.width=i,r.height=s;const a=r.getContext("2d");return a?(a.translate(0,s),a.scale(1,-1),a.drawImage(e,0,0),r):(t("v-map - cesium - failed to get 2d context for flip"),e)}async createFlippedImageBitmap(e,i){if("function"==typeof createImageBitmap)try{const t=document.createElement("canvas");t.width=i,t.height=i;const s=t.getContext("2d");if(!s)throw new Error("Failed to get 2d context");const r=s.createImageData(i,i);r.data.set(e),s.putImageData(r,0,0);const a=this.flipCanvasVertically(t,i,i);return await createImageBitmap(a)}catch(e){return void t("v-map - cesium - createImageBitmap failed, falling back",e)}}async createFlippedImageFromRGBA(e){const i=Math.ceil(this.tileWidth*this.resolution),s=await this.createFlippedImageBitmap(e,i);if(s)return s;const r=document.createElement("canvas");r.width=i,r.height=i;const a=r.getContext("2d");if(!a)return void t("v-map - cesium - unable to acquire canvas 2d context");const n=a.createImageData(i,i);return n.data.set(e),a.putImageData(n,0,0),this.flipCanvasVertically(r,i,i)}async requestImage(i,s,r){if(!this.ready)return;if(r<this.minimumLevel||void 0!==this.maximumLevel&&r>this.maximumLevel)return;const a={x:i,y:s,z:r,tileSize:this.tileWidth,resolution:this.resolution,resampleMethod:this.resampleMethod,colorStops:this.colorStops};let n=null;try{if(n=await this.tileProcessor.getTileData(a),!n)return void e(`v-map - cesium - geotiff - requestImage(${i},${s},${r}): no data returned`);e(`v-map - cesium - geotiff - requestImage(${i},${s},${r}): rgba ${n.length} bytes, sampleSize=${Math.ceil(this.tileWidth*this.resolution)}`)}catch(e){return this.errorEvent.raiseEvent(e),void t("v-map - cesium - getTileData - GeoTIFF tile request failed",e)}try{const t=await this.createFlippedImageFromRGBA(n);return e(`v-map - cesium - geotiff - requestImage(${i},${s},${r}): result=${t?.constructor?.name??"undefined"}, size=${t instanceof HTMLCanvasElement||t instanceof ImageBitmap?`${t.width}x${t.height}`:"n/a"}`),t}catch(e){return this.errorEvent.raiseEvent(e),void t("v-map - cesium - createFlippedImageFromRGBA - GeoTIFF tile request failed",e)}}pickFeatures(){}}const y="v-map - cesium - terrain-geotiff - ";class f{Cesium;image;fromProjection="EPSG:4326";sourceBounds=[0,0,0,0];wgs84Bounds=[0,0,0,0];width=0;height=0;noDataValue=0;ready=!1;_readyPromise;heightmapWidth=65;heightmapHeight=65;proj4;tilingScheme;constructor(t){this.Cesium=t.Cesium,this.tilingScheme=new this.Cesium.GeographicTilingScheme,this._readyPromise=this.initialize(t)}async initialize(t){try{e(`${y}loadGeoTIFF: url=${t.url}`);const[i,{default:s},a]=await Promise.all([import("./p-Be3r33VF.js").then((function(t){return t.g})),import("./p-RpJarvr_.js"),import("./p-CXfA_q8m.js").then((function(t){return t.m}))]),n=await r(t.url,{projection:t.projection,forceProjection:t.forceProjection??!1,nodata:t.nodata},{geotiff:i,proj4:s,geokeysToProj4:a});return this.image=n.baseImage,this.fromProjection=n.fromProjection,this.sourceBounds=n.sourceBounds,this.wgs84Bounds=n.wgs84Bounds,this.width=n.width,this.height=n.height,this.noDataValue=n.noDataValue??0,this.proj4=n.proj4,e(`${y}loaded: projection=${this.fromProjection}, bounds=[${this.sourceBounds.map((t=>t.toFixed(0))).join(",")}], wgs84=[${this.wgs84Bounds.map((t=>t.toFixed(4))).join(",")}], size=${this.width}x${this.height}`),this.ready=!0,!0}catch(t){return i(`${y}failed to load GeoTIFF:`,t),this.ready=!1,!1}}get rectangle(){if(!this.ready||!this.wgs84Bounds)return this.Cesium.Rectangle.MAX_VALUE;const[t,e,i,s]=this.wgs84Bounds;return this.Cesium.Rectangle.fromDegrees(t,e,i,s)}async requestTileGeometry(e,i,s){if(this.ready&&this.image)try{const r=this.tilingScheme.tileXYToRectangle(e,i,s);let a=this.Cesium.Math.toDegrees(r.west),n=this.Cesium.Math.toDegrees(r.south),o=this.Cesium.Math.toDegrees(r.east),h=this.Cesium.Math.toDegrees(r.north);const[c,l,u,w]=this.wgs84Bounds;if(o<c||a>u||h<l||n>w)return this.createFlatHeightmap();a=Math.max(c,Math.min(u,a)),o=Math.max(c,Math.min(u,o)),n=Math.max(l,Math.min(w,n)),h=Math.max(l,Math.min(w,h));const p=e=>{try{return this.proj4("EPSG:4326",this.fromProjection,e)}catch(i){return t(`${y}transform failed:`,i),e}},m=p([a,n]),d=p([o,h]),[f,g,v,b]=this.sourceBounds,S=this.width,C=this.height,$=v-f,L=b-g,G=Math.floor((m[0]-f)/$*S),M=Math.floor((b-d[1])/L*C),k=Math.ceil((d[0]-f)/$*S),x=Math.ceil((b-m[1])/L*C),F=Math.max(0,Math.min(G,S)),E=Math.max(0,Math.min(M,C)),I=Math.max(1,Math.min(k-G,S-F)),T=Math.max(1,Math.min(x-M,C-E)),O=(await this.image.readRasters({window:[F,E,F+I,E+T],width:this.heightmapWidth,height:this.heightmapHeight,resampleMethod:"bilinear"}))[0],A=new Float32Array(this.heightmapWidth*this.heightmapHeight);for(let t=0;t<A.length;t++){let e=O[t];e!==this.noDataValue&&isFinite(e)||(e=0),A[t]=e}return new this.Cesium.HeightmapTerrainData({buffer:A,width:this.heightmapWidth,height:this.heightmapHeight,childTileMask:0,structure:{heightScale:1,heightOffset:0,elementsPerHeight:1,stride:1,elementMultiplier:1}})}catch(e){return t(`${y}failed to load tile geometry:`,e),this.createFlatHeightmap()}}createFlatHeightmap(){const t=new Float32Array(this.heightmapWidth*this.heightmapHeight);return t.fill(0),new this.Cesium.HeightmapTerrainData({buffer:t,width:this.heightmapWidth,height:this.heightmapHeight,childTileMask:0})}get availability(){}getTilingScheme(){return this.tilingScheme}getLevelMaximumGeometricError(t){return this.tilingScheme.ellipsoid.maximumRadius/(65*Math.pow(2,t))}loadTileDataAvailability(t,e,i){}getTileDataAvailable(t,e,i){if(!this.ready)return!1;const s=this.tilingScheme.tileXYToRectangle(t,e,i),r=this.Cesium.Math.toDegrees(s.west),a=this.Cesium.Math.toDegrees(s.south),n=this.Cesium.Math.toDegrees(s.east),o=this.Cesium.Math.toDegrees(s.north),[h,c,l,u]=this.wgs84Bounds;return!(n<h||r>l||o<c||a>u)}get readyPromise(){return this._readyPromise}get credit(){return new this.Cesium.Credit("GeoTIFF Terrain")}get hasWaterMask(){return!1}get hasVertexNormals(){return!1}get errorEvent(){return new this.Cesium.Event}}const g="v-map - cesium - terrain-geotiff - ";class v{Cesium;viewer;provider;options;opacity=1;previousProvider;constructor(t,e,i,s){this.Cesium=t,this.viewer=e,this.provider=i,this.options=s??{},this.previousProvider=e.terrainProvider,this.viewer.terrainProvider=this.provider}getOptions(){return this.options}setOptions(t){this.options=t}getVisible(){return this.viewer.scene.globe.show}setVisible(t){this.viewer.scene.globe.show=t}getOpacity(){return this.opacity}setOpacity(e){this.opacity=e;const i=this.viewer.scene.globe;if(!i.translucency)try{i.translucency=new this.Cesium.GlobeTranslucency,i.translucency.enabled=!0}catch(e){return void t("Cesium terrain opacity not supported",e)}i.translucency.enabled=e<1,i.translucency.frontFaceAlpha=e}getZIndex(){return 0}async setZIndex(t){}remove(){try{this.viewer.terrainProvider=this.previousProvider?this.previousProvider:new this.Cesium.EllipsoidTerrainProvider,this.viewer.scene.globe.show=!0}catch(e){t("Cesium terrain reset failed",e)}}}class b{viewer;Cesium;layerManager;shadowRoot;layerGroups=new l;layerManagerMutex=new w;layerErrorCallbacks=new Map;layerErrorCleanups=new Map;async init(t){this.shadowRoot=t.shadowRoot;const e=t.target.getRootNode()instanceof ShadowRoot?t.target.getRootNode():void 0;await async function(t){const e=`https://cdn.jsdelivr.net/npm/cesium@${s.replace(/^[^\d]*/,"")}/Build/Cesium`,i=`${e}/Widgets/widgets.css`,r=(await(await fetch(i)).text()).replace(/url\((?!['"]?data:)(['"]?)([^'")]+)\1\)/g,((t,i,s)=>`url(${e}/Widgets/${s.replace(/^\.?\//,"")})`));if(t)if("adoptedStyleSheets"in Document.prototype){const e=new CSSStyleSheet;await e.replace(r),t.adoptedStyleSheets=[...t.adoptedStyleSheets??[],e]}else{const e=document.createElement("style");e.textContent=r,t.appendChild(e)}}(e),this.Cesium=await async function(t=s){const e=`https://cdn.jsdelivr.net/npm/cesium@${t.replace(/^[^\d]*/,"")}/Build/Cesium`,i=`${e}/Cesium.js`;await m.runExclusive((async()=>{globalThis.Cesium||await new Promise(((t,e)=>{const s="cesium-cdn-script";if(document.getElementById(s))return t();const r=document.createElement("script");r.id=s,r.async=!0,r.src=i,r.addEventListener("load",(()=>t()),{once:!0}),r.addEventListener("error",(()=>e(new Error(`Laden fehlgeschlagen: ${i}`))),{once:!0}),document.head.appendChild(r)}))}));const r=globalThis.Cesium;p(r,"globalThis.Cesium nicht verfügbar.");const a=r.VERSION;var n,o;return p((n=String(t),o=a,n.match(/^\d+\.\d+/)?.[0]===o.match(/^\d+\.\d+/)?.[0]),`Cesium-Version abweichend: erwartet ~${t}, geladen ${a}`),globalThis.CESIUM_BASE_URL=e,r}(),Cesium.Ion.defaultAccessToken=null,this.viewer=new this.Cesium.Viewer(t.target,{baseLayer:!1,baseLayerPicker:!1,terrainProvider:new Cesium.EllipsoidTerrainProvider}),this.viewer.scene.primitives.removeAll(),this.viewer.scene.backgroundColor=this.Cesium.Color.WHITE,this.viewer.scene.globe.baseColor=this.Cesium.Color.WHITE,this.viewer.scene.globe.depthTestAgainstTerrain=!1,this.layerManager=new u(this.Cesium,this.viewer)}async destroy(){!function(t){if(!t)return;const i=Array.from(t.querySelectorAll("style"));for(const t of i)if(t.textContent?.includes(".cesium-credit-lightbox-overlay")){t.remove(),e("v-map - provider - cesium - Cesium‑Widget‑CSS entfernt");break}}(this.shadowRoot),this.viewer?.destroy(),this.viewer=void 0}async createLayer(t,e){let i=null;switch(t.type){case"geojson":{const s={},r=t,a=await this.createGeoJSONLayer(r,s);i=this.layerManager.addLayer(e,a),i.setOptions(s);break}case"osm":{const s=await this.createOSMLayer(t);i=this.layerManager.addLayer(e,s);break}case"google":{const s=await this.createGoogleLayer(t);i=this.layerManager.addLayer(e,s);break}case"terrain":{const s=await this.createTerrainLayer(t);i=this.layerManager.addCustomLayer(e,s);break}case"xyz":{const s=await this.createXYZLayer(t);i=this.layerManager.addLayer(e,s);break}case"wms":{const s=await this.addWMSLayer(t);i=this.layerManager.addLayer(e,s);break}case"wcs":{const s=await this.createWCSLayer(t);i=this.layerManager.addLayer(e,s);break}case"arcgis":await this.addArcGISLayer(t);break;case"wfs":{const s={clampToGround:!0},r=t,a=await this.createWFSLayer(r,s);i=this.layerManager.addLayer(e,a),i.setOptions(s);break}case"wkt":{const s={clampToGround:!0},r=t,a=await this.createWKTLayer(r,s);i=this.layerManager.addLayer(e,a),i.setOptions(s);break}case"geotiff":{const s=await this.createGeoTIFFLayer(t);i=this.layerManager.addLayer(e,s);break}case"tile3d":{const s=await this.createTile3DLayer(t);i=this.layerManager.addLayer(e,s);const r=t;i.setOptions(r.tilesetOptions??{}),r.cesiumStyle&&"setStyle"in i&&i.setStyle(r.cesiumStyle);break}case"terrain-geotiff":{const s=await this.createGeoTIFFTerrainLayer(t);i=this.layerManager.addCustomLayer(e,s);break}default:throw new Error(`Unsupported layer type: ${t.type}`)}if(!i)return null;const s=t;return void 0!==s.zIndex&&await i.setZIndex(s.zIndex),void 0!==s.opacity&&i.setOpacity(s.opacity),void 0!==s.visible&&i.setVisible(s.visible),i}async addLayerToGroup(t){return await this.layerManagerMutex.runExclusive((async()=>{const e=crypto.randomUUID(),i=await this.createLayer(t,e);return this.layerGroups.addLayerToGroup(t.groupId,void 0===typeof t.groupVisible||t.groupVisible,{id:e,elementId:t.layerElementId??t.elementId??null,layer:i}),this.layerGroups.apply(),e}))}async setBaseLayer(t,e){await this.layerManagerMutex.runExclusive((async()=>{this.layerGroups.setBasemap(t,e??null),this.layerGroups.apply()}))}async addBaseLayer(t,e,i){return i&&e?await this.layerManagerMutex.runExclusive((async()=>{const s=crypto.randomUUID(),r=await this.createLayer(t,s);return this.layerGroups.addLayerToGroup(t.groupId,void 0===typeof t.groupVisible||t.groupVisible,{id:s,elementId:i,layer:r}),this.layerGroups.setBasemap(t.groupId??"basemap",e),this.layerGroups.apply(),s})):null}async ensureGroup(t,e,i){this.layerGroups.ensureGroup(t,e)}async setGroupVisible(t,e){this.layerGroups.setGroupVisible(t,e),this.layerGroups.apply()}onLayerError(t,e){this.layerErrorCallbacks.set(t,e),this.attachCesiumErrorListeners(t)}offLayerError(t){this.layerErrorCleanups.get(t)?.(),this.layerErrorCleanups.delete(t),this.layerErrorCallbacks.delete(t)}attachCesiumErrorListeners(t){this.layerErrorCleanups.get(t)?.();const e=this.layerErrorCallbacks.get(t);if(!e)return;const i=this.layerManager.getLayer(t);if(!i)return;const s=[],r=()=>{e({type:"network",message:"Tile load error"})},a=i._imageryLayer;if(a?.imageryProvider?.errorEvent){const t=a.imageryProvider.errorEvent.addEventListener(r);s.push(t)}const n=i._tileset;if(n?.tileFailed){const t=n.tileFailed.addEventListener(r);s.push(t)}s.length>0&&this.layerErrorCleanups.set(t,(()=>s.forEach((t=>t()))))}async removeLayer(t){t&&(this.offLayerError(t),await this.layerManagerMutex.runExclusive((async()=>{this.layerManager.removeLayer(t),this.layerGroups.removeLayer(t,!0),this.layerGroups.apply()})))}async setOpacity(t,e){this.layerManager.setOpacity(t,e),this.layerGroups.apply()}async setVisible(t,e){this.layerManager.setVisible(t,e),this.layerGroups.apply()}async setZIndex(t,e){await this.layerManager.setZIndex(t,e),this.layerGroups.apply()}applyGeostylerStyling(t,i){t.__vmapLockOpacity=!0;const s=(t,e)=>null==t||"object"==typeof t&&null!==t&&"name"in t?e:t,r=(t,e)=>{if(null==t)return e;if("number"==typeof t)return t;const i=Number(t);return Number.isFinite(i)?i:e},a=t.entities.values;if(i.rules)for(const t of i.rules)if(t.symbolizers)for(const i of t.symbolizers)for(let t=0;t<a.length;t++){const n=a[t];switch(i.kind){case"Fill":if(n.polygon){const t=s(i.color,"rgba(0,100,255,0.3)"),a=r(s(i.opacity,.3),.3),o=s(i.outlineColor,"rgba(0,100,255,1)"),h=s(i.outlineWidth,1);let c=this.parseCesiumColor(t,this.Cesium.Color.BLUE.withAlpha(.3));null!=a&&(c=this.applyCesiumOpacity(c,a));const l=this.parseCesiumColor(o,this.Cesium.Color.BLUE);e("v-map - provider - cesium - applyGeostylerStyling: Fill",{fillColor:t,fillOpacity:a,computedFill:c?.toString?.(),outlineColor:o,outlineWidth:h}),n.polygon.fill=new this.Cesium.ConstantProperty(!0),n.polygon.material=new this.Cesium.ColorMaterialProperty(c),n.polygon.outline=new this.Cesium.ConstantProperty(!0),n.polygon.outlineColor=new this.Cesium.ConstantProperty(l),n.polygon.outlineWidth=new this.Cesium.ConstantProperty(h),n.polygon.extrudedHeight=void 0,n.polygon.heightReference=new this.Cesium.ConstantProperty(this.Cesium.HeightReference.CLAMP_TO_GROUND),n.polygon.perPositionHeight=new this.Cesium.ConstantProperty(!1),n.polygon.classificationType=new this.Cesium.ConstantProperty(this.Cesium.ClassificationType.BOTH)}break;case"Line":if(n.polyline){const t=s(i.color,"rgba(0,100,255,1)"),a=r(s(i.width,2),2),o=r(s(i.opacity,1),1);let h=this.parseCesiumColor(t,this.Cesium.Color.BLUE);null!=o&&(h=this.applyCesiumOpacity(h,o)),e("v-map - provider - cesium - applyGeostylerStyling: Line",{lineColor:t,lineOpacity:o,computedColor:h?.toString?.(),lineWidth:a}),n.polyline.material=new this.Cesium.ColorMaterialProperty(h),n.polyline.width=new this.Cesium.ConstantProperty(a)}break;case"Mark":if(n.point){const t=s(i.color,"rgba(0,100,255,1)"),a=r(s(i.radius,6),6),o=r(s(i.opacity,1),1);let h=this.parseCesiumColor(t,this.Cesium.Color.BLUE);null!=o&&(h=this.applyCesiumOpacity(h,o)),e("v-map - provider - cesium - applyGeostylerStyling: Mark",{pointColor:t,pointOpacity:o,computedColor:h?.toString?.(),pointRadius:a}),n.point.color=new this.Cesium.ConstantProperty(h),n.point.pixelSize=new this.Cesium.ConstantProperty(a)}break;case"Icon":if(n.point){const t=s(i.image),a=r(s(i.size,32),32),o=r(s(i.opacity,1),1);t&&"string"==typeof t&&(n.billboard=new this.Cesium.BillboardGraphics({image:new this.Cesium.ConstantProperty(t),width:new this.Cesium.ConstantProperty(a),height:new this.Cesium.ConstantProperty(a),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM),color:null!=o?new this.Cesium.ConstantProperty(this.Cesium.Color.WHITE.withAlpha(o)):void 0}),n.point.show=new this.Cesium.ConstantProperty(!1),e("v-map - provider - cesium - applyGeostylerStyling: Icon",{iconSrc:t,iconSize:a,iconOpacity:o}))}break;case"Text":const t=i.label,a="string"==typeof t?t:void 0;if(a&&n.properties&&n.properties[a]){const t=s(i.color,"#000000"),o=r(s(i.size,12),12),h=r(s(i.opacity,1),1);let c=this.parseCesiumColor(t,this.Cesium.Color.WHITE);null!=h&&(c=this.applyCesiumOpacity(c,h)),e("v-map - provider - cesium - applyGeostylerStyling: Text",{labelProp:a,textColor:t,textOpacity:h,computedColor:c?.toString?.(),textSize:o});const l=n.properties[a]?.getValue?.(this.viewer.clock.currentTime)??n.properties[a]?._value??"";n.label=new this.Cesium.LabelGraphics({text:new this.Cesium.ConstantProperty(String(l)),font:new this.Cesium.ConstantProperty(`${o}px Arial`),fillColor:new this.Cesium.ConstantProperty(c),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM)})}}}}parseCesiumColor(t,e){if(!t)return e;if(t.startsWith("#"))return this.Cesium.Color.fromCssColorString(t);if(t.includes("rgb"))return this.Cesium.Color.fromCssColorString(t);try{return this.Cesium.Color.fromCssColorString(t)}catch{return e}}applyCesiumOpacity(t,e){return t?t.withAlpha(e):t}createCesiumStyle(t={}){const e=this.Cesium.Color.BLUE.withAlpha(.3),i=this.Cesium.Color.BLUE,s=this.Cesium.Color.BLUE,r=this.parseCesiumColor(t.fillColor,e),a=this.parseCesiumColor(t.strokeColor,i),n=this.parseCesiumColor(t.pointColor,s),o=void 0!==t.fillOpacity?this.applyCesiumOpacity(r,t.fillOpacity):r,h=void 0!==t.strokeOpacity?this.applyCesiumOpacity(a,t.strokeOpacity):a,c=void 0!==t.pointOpacity?this.applyCesiumOpacity(n,t.pointOpacity):n;return{fill:!0,fillColor:o,outline:!0,outlineColor:h,outlineWidth:t.strokeWidth??2,extrudedHeight:t.extrudeHeight,heightReference:t.zOffset?this.Cesium.HeightReference.RELATIVE_TO_GROUND:this.Cesium.HeightReference.CLAMP_TO_GROUND,pixelSize:t.pointRadius??8,color:c,scaleByDistance:t.pointRadius?new this.Cesium.NearFarScalar(150,2,15e6,.5):void 0,width:t.strokeWidth??2,clampToGround:!t.zOffset,labelText:t.textProperty,labelFont:t.textSize?`${t.textSize}pt monospace`:"12pt monospace",labelFillColor:t.textColor?this.parseCesiumColor(t.textColor,this.Cesium.Color.WHITE):this.Cesium.Color.WHITE,labelOutlineColor:t.textHaloColor?this.parseCesiumColor(t.textHaloColor,this.Cesium.Color.BLACK):this.Cesium.Color.BLACK,labelOutlineWidth:t.textHaloWidth??1,labelPixelOffset:t.textOffset?new this.Cesium.Cartesian2(t.textOffset[0],t.textOffset[1]):this.Cesium.Cartesian2.ZERO,height:t.zOffset??0}}applyEnhancedStyling(t,e={}){const i=this.createCesiumStyle(e),s=t.entities.values;for(let t=0;t<s.length;t++){const r=s[t];let a=i;if(e.styleFunction&&r.properties){const t={properties:r.properties._propertyNames.reduce(((t,e)=>(t[e]=r.properties[e]?._value,t)),{}),geometry:r},s=e.styleFunction(t);s&&(a={...i,...this.createCesiumStyle(s)})}if(r.polygon&&(r.polygon.fill=new this.Cesium.ConstantProperty(a.fill),r.polygon.material=new this.Cesium.ColorMaterialProperty(a.fillColor),r.polygon.outline=new this.Cesium.ConstantProperty(a.outline),r.polygon.outlineColor=new this.Cesium.ConstantProperty(a.outlineColor),r.polygon.outlineWidth=new this.Cesium.ConstantProperty(a.outlineWidth),r.polygon.height=void 0!==a.height?new this.Cesium.ConstantProperty(a.height):void 0,r.polygon.extrudedHeight=void 0!==a.extrudedHeight?new this.Cesium.ConstantProperty(a.extrudedHeight):void 0,r.polygon.heightReference=void 0!==a.heightReference?new this.Cesium.ConstantProperty(a.heightReference):void 0),r.polyline&&(r.polyline.material=new this.Cesium.ColorMaterialProperty(a.outlineColor),r.polyline.width=new this.Cesium.ConstantProperty(a.width),r.polyline.clampToGround=new this.Cesium.ConstantProperty(a.clampToGround)),r.point){r.point.pixelSize=new this.Cesium.ConstantProperty(a.pixelSize),r.point.color=new this.Cesium.ConstantProperty(a.color);const t=a.scaleByDistance;r.point.scaleByDistance=t?new this.Cesium.ConstantProperty(t):void 0,e.iconUrl&&(r.billboard=new this.Cesium.BillboardGraphics({image:new this.Cesium.ConstantProperty(e.iconUrl),width:new this.Cesium.ConstantProperty(e.iconSize?e.iconSize[0]:32),height:new this.Cesium.ConstantProperty(e.iconSize?e.iconSize[1]:32),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM),scaleByDistance:t?new this.Cesium.ConstantProperty(t):void 0}),r.point.show=new this.Cesium.ConstantProperty(!1))}if(e.textProperty&&r.properties&&r.properties[e.textProperty]){const t=r.properties[e.textProperty]?.getValue?.(this.viewer.clock.currentTime)??r.properties[e.textProperty]?._value??"";r.label=new this.Cesium.LabelGraphics({text:new this.Cesium.ConstantProperty(String(t)),font:new this.Cesium.ConstantProperty(a.labelFont),fillColor:new this.Cesium.ConstantProperty(a.labelFillColor),outlineColor:new this.Cesium.ConstantProperty(a.labelOutlineColor),outlineWidth:new this.Cesium.ConstantProperty(a.labelOutlineWidth),pixelOffset:new this.Cesium.ConstantProperty(a.labelPixelOffset),verticalOrigin:new this.Cesium.ConstantProperty(this.Cesium.VerticalOrigin.BOTTOM)})}}}async createWKTLayer(t,e){const i=await this.wktToGeoJSON(t),s=await this.Cesium.GeoJsonDataSource.load(i,e);return t.geostylerStyle?this.applyGeostylerStyling(s,t.geostylerStyle):t.style&&this.applyEnhancedStyling(s,t.style),s}async wktToGeoJSON(t){const e=await this.resolveWktText(t),i=await import("./p-DR9McdNX.js").then((function(t){return t.i})),s="function"==typeof i.default?i.default:i.parse;if("function"!=typeof s)throw new Error("wellknown parser not available");const r=s(e);if(!r)throw new Error("Failed to parse WKT");return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:r}]}}async resolveWktText(t){if(t.wkt)return t.wkt;if(t.url){const e=await fetch(t.url);if(!e.ok)throw new Error(`Failed to fetch WKT: ${e.status}`);return await e.text()}throw new Error("Either wkt or url must be provided")}async createGeoJSONLayer(t,e){let i=null;i=t.geojson?JSON.parse(t.geojson):t.url;const s=await this.Cesium.GeoJsonDataSource.load(i,e);return t.geostylerStyle?this.applyGeostylerStyling(s,t.geostylerStyle):t.style&&this.applyEnhancedStyling(s,t.style),s}async createWFSLayer(t,e){const i=await this.fetchWFSFromUrl(t),s=await this.Cesium.GeoJsonDataSource.load(i,e);return t.geostylerStyle?this.applyGeostylerStyling(s,t.geostylerStyle):t.style&&this.applyEnhancedStyling(s,t.style),s}async createOSMLayer(t){return new this.Cesium.ImageryLayer(new this.Cesium.OpenStreetMapImageryProvider({url:t.url||"https://a.tile.openstreetmap.org"}))}async createGoogleLayer(t){if(!t.apiKey)throw new Error("Google-Layer benötigt 'apiKey' (Google Maps Platform).");await this.loadGoogleMapsApi(t.apiKey,{language:t.language,region:t.region,libraries:t.libraries});const e=this.getGoogleMapTypeId(t.mapType||"roadmap"),i=this.Cesium,s=new i.UrlTemplateImageryProvider({url:"https://maps.googleapis.com/maps/api/staticmap?template",maximumLevel:t.maxZoom||19,minimumLevel:0,tilingScheme:new i.WebMercatorTilingScheme,credit:"Google Maps",urlSchemeZeroPadding:{"{x}":"","{y}":"","{z}":""}});return s.buildImageResource=function(s,r,a){const n=(new i.WebMercatorTilingScheme).tileXYToRectangle(s,r,a),o=i.Math.toDegrees(n.west),h=i.Math.toDegrees(n.south),c=i.Math.toDegrees(n.east),l=i.Math.toDegrees(n.north),u=new URLSearchParams({center:`${(h+l)/2},${(o+c)/2}`,zoom:a.toString(),size:"256x256",scale:"scaleFactor1x"===t.scale?"1":"2",maptype:e,key:t.apiKey,format:"png"});t.language&&u.set("language",t.language),t.region&&u.set("region",t.region);const w=`https://maps.googleapis.com/maps/api/staticmap?${u.toString()}`;return new i.Resource({url:w})},this.ensureGoogleLogo(),new this.Cesium.ImageryLayer(s,{alpha:t.opacity??1,show:t.visible??!0})}getGoogleMapTypeId(t){switch(t){case"roadmap":default:return"roadmap";case"satellite":return"satellite";case"terrain":return"terrain";case"hybrid":return"hybrid"}}async loadGoogleMapsApi(t,e){const i=window,s=i.__mockGoogleMapsApi;"function"!=typeof s?i.google?.maps||await new Promise(((s,r)=>{const a="___cesiumGoogleInit___"+Math.random().toString(36).slice(2);i[a]=()=>s();const n=document.createElement("script"),o=new URLSearchParams({key:t,callback:a,v:"weekly"});e?.language&&o.set("language",e.language),e?.region&&o.set("region",e.region),e?.libraries?.length&&o.set("libraries",e.libraries.join(",")),n.src=`https://maps.googleapis.com/maps/api/js?${o.toString()}`,n.async=!0,n.onerror=()=>r(new Error("Google Maps JS API failed to load")),document.head.appendChild(n)})):await s(t,e)}ensureGoogleLogo(){if(!this.viewer?.container||this.viewer.container._googleLogoAdded)return;const t=document.createElement("img");t.src="https://developers.google.com/static/maps/documentation/images/google_on_white.png",t.alt="Google",t.style.position="absolute",t.style.bottom="6px",t.style.left="6px",t.style.height="18px",t.style.pointerEvents="none",t.style.zIndex="1000",this.viewer.container.appendChild(t),this.viewer.container._googleLogoAdded=!0}async createXYZLayer(t){if(!t.url)throw new Error("XYZ layer requires a url");const e=Array.isArray(t.attributions)?t.attributions.join(", "):t.attributions,i={url:t.url,credit:e,maximumLevel:t.maxZoom,...t.options||{}},s=new this.Cesium.UrlTemplateImageryProvider(i);return new this.Cesium.ImageryLayer(s,{alpha:t.opacity??1,show:t.visible??!0})}async createTerrainLayer(t){let e;e=t.elevationData?await this.Cesium.CesiumTerrainProvider.fromUrl(t.elevationData):await this.Cesium.createWorldTerrainAsync();const i=new v(this.Cesium,this.viewer,e,t);return void 0!==t.visible&&i.setVisible(t.visible),void 0!==t.opacity&&i.setOpacity(t.opacity),i}async createGeoTIFFTerrainLayer(t){if(!t.url){e(`${g}layer created without URL, waiting for URL to load`);const i=new this.Cesium.EllipsoidTerrainProvider,s=new v(this.Cesium,this.viewer,i,t);return s.setVisible(!1),s}try{e(`${g}create layer: url=${t.url}`);const i=await async function(t){const e=new f(t);return await e.readyPromise,e}({url:t.url,projection:t.projection,forceProjection:t.forceProjection,nodata:t.nodata,Cesium:this.Cesium}),s=new v(this.Cesium,this.viewer,i,t);return void 0!==t.visible&&s.setVisible(t.visible),void 0!==t.opacity&&s.setOpacity(t.opacity),e(`${g}layer created successfully`),s}catch(e){i(`${g}failed to create terrain layer:`,e);const s=new this.Cesium.EllipsoidTerrainProvider;return new v(this.Cesium,this.viewer,s,t)}}async addWMSLayer(t){return new this.Cesium.ImageryLayer(new this.Cesium.WebMapServiceImageryProvider({url:t.url,layers:t.layers,parameters:t.extraParams}))}async createWCSLayer(t){if(!t.url||!t.coverageName)throw new Error("WCS layer requires url and coverageName");const e=t.version??"2.0.1",i=t.format??"image/tiff",s=t.projection??"EPSG:4326",r=t.tileSize??256,a=this.Cesium,n=new a.UrlTemplateImageryProvider({url:`${t.url}?wcs_placeholder`,maximumLevel:t.maxZoom??18,minimumLevel:t.minZoom??0,tileWidth:r,tileHeight:r,tilingScheme:new a.GeographicTilingScheme,credit:"WCS"});return n.buildImageResource=function(n,o,h){const c=(new a.GeographicTilingScheme).tileXYToRectangle(n,o,h),l=a.Math.toDegrees(c.west),u=a.Math.toDegrees(c.south),w=a.Math.toDegrees(c.east),p=a.Math.toDegrees(c.north),m={SERVICE:"WCS",REQUEST:"GetCoverage",VERSION:e,FORMAT:i};let d;if(e.startsWith("2.0")){const e={...m,coverageId:t.coverageName,...t.params||{}};(i.includes("tiff")||i.includes("geotiff"))&&(e["geotiff:compression"]="LZW");const s=new URLSearchParams;Object.entries(e).forEach((([t,e])=>{null!=e&&s.set(t,String(e))}));const r=s.toString(),a=`subset=X(${l},${w})`,n=`subset=Y(${u},${p})`;d=`${t.url}${t.url.includes("?")?"&":"?"}${r}&${a}&${n}`}else{const e={...m,COVERAGE:t.coverageName,BBOX:`${l},${u},${w},${p}`,CRS:s,WIDTH:String(r),HEIGHT:String(r),...t.params||{}},i=new URLSearchParams;Object.entries(e).forEach((([t,e])=>{null!=e&&i.set(t,String(e))})),d=`${t.url}${t.url.includes("?")?"&":"?"}${i.toString()}`}return new a.Resource({url:d})},new this.Cesium.ImageryLayer(n,{alpha:t.opacity??1,show:t.visible??!0})}async addArcGISLayer(t){const e=await this.Cesium.ArcGisMapServerImageryProvider.fromUrl(t.url);this.viewer.imageryLayers.addImageryProvider(e)}async createGeoTIFFLayer(t){if(!t.url)throw new Error("GeoTIFF layer requires a URL");try{const e=t,i=await a(t.url,e.projection,e.forceProjection,t.nodata),s=await n(i,"EPSG:3857"),r=new o(s);let c;if(r.createGlobalTriangulation(),t.colorMap){const{stops:e}=h(t.colorMap,t.valueRange);c=e}const l=new d({Cesium:this.Cesium,rectangleDegrees:i.wgs84Bounds,tileProcessor:r,tileSize:t.tileSize??256,resolution:t.resolution??1,resampleMethod:t.resampleMethod??"bilinear",colorStops:c}),u=new this.Cesium.ImageryLayer(l,{alpha:t.opacity??1,show:t.visible??!0});return u.__vmapGeoTIFFMeta={url:t.url,width:i.width,height:i.height,samplesPerPixel:i.samplesPerPixel,noData:i.noDataValue},u}catch(t){i("v-map - provider - cesium - Failed to create GeoTIFF layer",t);const e=new this.Cesium.SingleTileImageryProvider({url:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",rectangle:this.Cesium.Rectangle.fromDegrees(-180,-90,180,90)});return new this.Cesium.ImageryLayer(e,{alpha:0,show:!1})}}async createTile3DLayer(t){if(!t.url)throw new Error("Tile3D layer requires a URL");const e=await this.Cesium.Cesium3DTileset.fromUrl(t.url,t.tilesetOptions??{});return t.cesiumStyle&&(e.style=new this.Cesium.Cesium3DTileStyle(t.cesiumStyle)),e}async updateLayer(t,e){return await this.layerManagerMutex.runExclusive((async()=>{const i=this.layerErrorCallbacks.has(t);i&&this.offLayerError(t);const s=this.layerManager.getLayer(t);switch(e.type){case"geojson":{const i=e.data,r=s.getOptions(),a=await this.createGeoJSONLayer({geojson:i.geojson,url:i.url,style:i.style,geostylerStyle:i.geostylerStyle},r);this.layerManager.replaceLayer(t,s,a).setOptions(r)}break;case"wfs":{const i=e.data,r=s.getOptions(),a=await this.createWFSLayer(i,r);this.layerManager.replaceLayer(t,s,a).setOptions(r)}break;case"osm":{const i=s.getOptions(),r=new this.Cesium.ImageryLayer(new this.Cesium.OpenStreetMapImageryProvider({url:e.data.url||"https://a.tile.openstreetmap.org"}));this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"google":{const i=s.getOptions(),r=await this.createGoogleLayer(e.data);this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"xyz":{const i=s.getOptions(),r=await this.createXYZLayer(e.data);this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"wcs":{const i=s.getOptions(),r=await this.createWCSLayer(e.data);this.layerManager.replaceLayer(t,s,r).setOptions(i)}break;case"wkt":{const i=e.data,r=s.getOptions(),a=await this.createWKTLayer({wkt:i.wkt,url:i.url,style:i.style,geostylerStyle:i.geostylerStyle},r);this.layerManager.replaceLayer(t,s,a).setOptions(r)}break;case"geotiff":{const i=e.data,r=await this.createGeoTIFFLayer({url:i.url});this.layerManager.replaceLayer(t,s,r)}break;case"tile3d":{const i=e.data??{};if(!i.url)throw new Error("tile3d update requires a url");const r=await this.createTile3DLayer({type:"tile3d",url:i.url,tilesetOptions:i.tilesetOptions,cesiumStyle:i.cesiumStyle}),a=this.layerManager.replaceLayer(t,s,r);a.setOptions(i.tilesetOptions??{}),i.cesiumStyle&&"setStyle"in a&&a.setStyle(i.cesiumStyle)}break;case"tile3d-style":"setStyle"in s&&s.setStyle((e.data??{}).style??{});break;case"terrain":{const i=s.getOptions(),r=s.getVisible(),a=s.getOpacity();s.remove();const n=await this.createTerrainLayer({type:"terrain",...i,...e.data??{}}),o=this.layerManager.addCustomLayer(t,n);o.setVisible(r),o.setOpacity(a)}break;case"terrain-geotiff":{s.remove();const i=await this.createGeoTIFFTerrainLayer({type:"terrain-geotiff",...e.data??{}});this.layerManager.addCustomLayer(t,i)}}i&&this.attachCesiumErrorListeners(t)}))}async setView(i,s){if(!this.viewer)return;const[r,a]=i;this.viewer.camera.flyTo({destination:this.Cesium.Cartesian3.fromDegrees(r,a,1e6/s),duration:2,orientation:{heading:this.Cesium.Math.toRadians(0),pitch:this.Cesium.Math.toRadians(-30),roll:0},complete:()=>e("v-map - provider - cesium - Fly‑to finished"),cancel:()=>t("v-map - provider - cesium - Fly‑to cancelled")})}getView(){if(!this.viewer)return null;const t=this.viewer.camera.positionCartographic;if(!t)return null;const e=this.Cesium.Math.toDegrees(t.longitude),i=this.Cesium.Math.toDegrees(t.latitude),s=t.height;return{center:[e,i],zoom:s>0?1e6/s:0}}async fetchWFSFromUrl(t){const e={service:"WFS",request:"GetFeature",version:t.version??"1.1.0",typeName:t.typeName,outputFormat:t.outputFormat??"application/json",srsName:t.srsName??"EPSG:4326",...t.params??{}},i=this.appendParams(t.url,e),s=await fetch(i);if(!s.ok)throw new Error(`WFS request failed (${s.status} ${s.statusText})`);const r=(t.outputFormat??"application/json").toLowerCase();if(r.includes("json")||r.includes("geojson")||"application/json"===r){const t=s.headers.get("content-type");if(t?.includes("application/json"))return await s.json();const e=await s.text();return JSON.parse(e)}if(r.includes("gml")||r.includes("xml")){const t=await s.text(),{GmlParser:e}=await import("./p-DhQAXuA7.js"),i=new e;return await i.parse(t)}return await s.json()}appendParams(t,e){const i=new URLSearchParams;return Object.entries(e).forEach((([t,e])=>{null!=e&&i.set(t,String(e))})),i.toString()?`${t}${t.includes("?")?"&":"?"}${i.toString()}`:t}}export{b as CesiumProvider}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as t,L as e,s,w as i}from"./p-2-mR3oVa.js";import*as r from"leaflet";import{e as o,l as a}from"./p-QJHuuz0g.js";import{D as n}from"./p-B-bAcABs.js";import{l as c,G as l,g as h}from"./p-yXLNXXx-.js";import{w as u}from"./p-DR9McdNX.js";import{GmlParser as f}from"./p-DhQAXuA7.js";import"./p-BoNyIrdq.js";import"./p-CrV_misM.js";import"./p-DVBtCUtQ.js";import"./p-E-ZsRS8r.js";const p=256;class y extends r.GridLayer{apiKey;highDpi;sessionRequest;scaleFactor;sessionToken;sessionPromise;sessionRefreshId;previousViewport;currentAttribution;mapInstance;onMoveEnd;constructor(t){super(),this.applyInitialGridOptions(t);const{apiKey:e,mapType:s,language:i,region:r,imageFormat:o,scale:a,highDpi:n,layerTypes:c,overlay:l,styles:h,apiOptions:u}=t;if(!e)throw new Error("Google Map Tiles layer requires an apiKey");this.apiKey=e,this.highDpi=n??(void 0===a||"scaleFactor1x"!==a),this.scaleFactor=this.mapScaleToFactor(a,this.highDpi);const f={mapType:s??"roadmap",language:i??"en-US",region:r??"US"};o&&(f.imageFormat=o),c?.length&&(f.layerTypes=c),u?.length&&(f.apiOptions=u),Array.isArray(h)&&h.length>0&&(f.styles=h),!0===l&&(f.overlay=!0);const p=a??(this.scaleFactor>1?this.factorToScale(this.scaleFactor):void 0);p&&(f.scale=p),this.highDpi&&(f.highDpi=!0),this.sessionRequest=f,this.onMoveEnd=()=>{this.updateAttribution()},this.sessionPromise=this.startSessionFetch()}onAdd(t){return this.mapInstance=t,t.on("moveend",this.onMoveEnd),t.on("zoomend",this.onMoveEnd),this.ensureSession().then((()=>this.updateAttribution())),super.onAdd(t)}onRemove(t){return t.off("moveend",this.onMoveEnd),t.off("zoomend",this.onMoveEnd),this.clearSessionRefresh(),this.removeCurrentAttribution(),this.mapInstance=void 0,super.onRemove(t)}createTile(t,e){const s=document.createElement("img");s.decoding="async",s.alt="",s.crossOrigin="anonymous";const i=this.resolveTileSize();s.width=i.x,s.height=i.y;const r=t=>{const i=t instanceof Error?t.message:"Google tile load error";e(new Error(i),s)};return s.onload=()=>e(null,s),s.onerror=t=>{const e=t instanceof ErrorEvent?t.error??new Error(t.message):new Error("Google tile failed to load");r(e)},this.ensureSession().then((()=>{this.sessionToken?s.src=this.buildTileUrl(t):r(new Error("Google Maps session unavailable"))})).catch((t=>{r(t)})),s}ensureSession(){return this.sessionToken?Promise.resolve():(this.sessionPromise||(this.sessionPromise=this.startSessionFetch()),this.sessionPromise)}startSessionFetch(t=!1){if(this.sessionPromise&&!t)return this.sessionPromise;const e=this.fetchAndApplySession().catch((t=>{const e=t instanceof Error?t:new Error("Failed to create Google Maps session");throw o("Google Map Tiles session error",e),this.sessionToken=void 0,e})).finally((()=>{this.sessionPromise===e&&(this.sessionPromise=void 0)}));return this.sessionPromise=e,e}async fetchAndApplySession(){const t=`https://tile.googleapis.com/v1/createSession?key=${this.apiKey}`,e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(this.sessionRequest)});if(!e.ok){let t;try{const s=await e.json();t=s?.error?.message}catch{}throw new Error(t??`Google Maps session request failed (${e.status})`)}const s=await e.json();this.sessionToken=s.session,this.applyTileSize(s),this.scheduleSessionRefresh(this.parseExpiry(s.expiry)),this.mapInstance&&(this.updateAttribution(),this.redrawLayer()),a("Google Map Tiles session established")}scheduleSessionRefresh(t){if(!isFinite(t))return;const e=Math.max(t-Date.now()-6e4,1e3);this.clearSessionRefresh(),this.sessionRefreshId=setTimeout((()=>{this.startSessionFetch(!0).then((()=>{this.mapInstance&&(this.updateAttribution(),this.redrawLayer())}))}),e)}clearSessionRefresh(){void 0!==this.sessionRefreshId&&(clearTimeout(this.sessionRefreshId),this.sessionRefreshId=void 0)}async updateAttribution(){if(!this.mapInstance||!this.sessionToken)return;const t=this.mapInstance.getBounds();if(!t?.isValid())return;const e=`zoom=${this.mapInstance.getZoom()}&north=${t.getNorth()}&south=${t.getSouth()}&east=${t.getEast()}&west=${t.getWest()}`;if(this.previousViewport!==e){this.previousViewport=e;try{const t=await fetch(`https://tile.googleapis.com/tile/v1/viewport?session=${this.sessionToken}&key=${this.apiKey}&${e}`);if(!t.ok)throw new Error(`Attribution request failed (${t.status})`);const s=await t.json(),i=s?.copyright;"string"==typeof i&&i.length>0&&this.applyAttribution(i)}catch(t){o("Failed to fetch Google attribution",t)}}}applyAttribution(t){const e=this.mapInstance;e?.attributionControl&&(this.currentAttribution&&this.currentAttribution!==t&&e.attributionControl.removeAttribution(this.currentAttribution),this.currentAttribution&&this.currentAttribution===t||(e.attributionControl.addAttribution(t),this.currentAttribution=t))}removeCurrentAttribution(){const t=this.mapInstance;t?.attributionControl&&this.currentAttribution&&(t.attributionControl.removeAttribution(this.currentAttribution),this.currentAttribution=void 0)}applyTileSize(t){const e=Math.max(1,Math.round(t.tileWidth/this.scaleFactor)),s=Math.max(1,Math.round(t.tileHeight/this.scaleFactor)),i=r.point(e,s);this.setGridOptions({tileSize:i})}parseExpiry(t){const e=parseInt(t,10);return Number.isFinite(e)?1e3*e:Number.NaN}buildTileUrl(t){if(!this.sessionToken)throw new Error("Google Maps session missing");return`https://tile.googleapis.com/v1/2dtiles/${t.z}/${t.x}/${t.y}?session=${this.sessionToken}&key=${this.apiKey}`}mapScaleToFactor(t,e){switch(t){case"scaleFactor4x":return 4;case"scaleFactor2x":return 2;case"scaleFactor1x":return 1;default:return e?2:1}}factorToScale(t){switch(t){case 4:return"scaleFactor4x";case 2:return"scaleFactor2x";case 1:return"scaleFactor1x";default:return}}applyInitialGridOptions(t){const e={},s=["attribution","bounds","className","detectRetina","errorTileUrl","keepBuffer","maxNativeZoom","maxZoom","minNativeZoom","minZoom","noWrap","opacity","pane","reuseTiles","subdomains","tileSize","tms","updateInterval","updateWhenIdle","updateWhenZooming","zIndex","zoomOffset"];for(const i of s){const s=t[i];void 0!==s&&(e[i]=s)}void 0===e.maxZoom&&(e.maxZoom=22),this.setGridOptions(e)}setGridOptions(t){const e=r.Util?.setOptions;if("function"==typeof e)e(this,t);else{const e=this;e.options={...e.options,...t}}}resolveTileSize(){const t=this.options?.tileSize;if(t&&"object"==typeof t){if(Array.isArray(t)&&2===t.length){const[e,s]=t;return r.point(Number(e)||p,Number(s)||p)}if("x"in t&&"y"in t){const e=t;return r.point(Number(e.x)||p,Number(e.y)||p)}}return"number"==typeof t&&Number.isFinite(t)?r.point(t,t):r.point(p,p)}redrawLayer(){this.redraw()}}class d extends r.GridLayer{geotiffOptions;tileProcessor=null;colorStops;loadingPromise;defaultResolution=1;defaultResample="bilinear";constructor(t){super(t),this.geotiffOptions={...t}}onAdd(t){return super.onAdd(t),this.ensureReady().then((()=>this.redraw())),this}createTile(t,e){const s=this.getTileSize(),i=r.DomUtil.create("canvas","leaflet-tile");return i.width=s.x,i.height=s.y,this.ensureReady().then((async()=>{if(this.tileProcessor)try{const r=await this.tileProcessor.getTileData({x:t.x,y:t.y,z:t.z,tileSize:s.x,resolution:this.geotiffOptions.resolution??this.defaultResolution,resampleMethod:this.geotiffOptions.resampleMethod??this.defaultResample,colorStops:this.colorStops});if(!r)return void e(null,i);const o=i.getContext("2d");if(o){const t=o.createImageData(s.x,s.y);t.data.set(r),o.putImageData(t,0,0)}e(null,i)}catch(t){e(t,i)}else e(null,i)})).catch((t=>{e(t,i)})),i}async ensureReady(){return this.loadingPromise||(this.loadingPromise=this.initializeProcessor()),this.loadingPromise}async updateSource(t){Object.assign(this.geotiffOptions,t),this.tileProcessor=null,this.colorStops=void 0,this.loadingPromise=void 0,await this.ensureReady(),this.redraw()}async initializeProcessor(){if(this.tileProcessor)return;const[t,{default:e},s]=await Promise.all([import("./p-Be3r33VF.js").then((function(t){return t.g})),import("./p-RpJarvr_.js"),import("./p-CXfA_q8m.js").then((function(t){return t.m}))]),i=await c(this.geotiffOptions.url,{projection:void 0,forceProjection:!1,nodata:this.geotiffOptions.nodata},{geotiff:t,proj4:e,geokeysToProj4:s}),r=t=>{const e=i.proj4(i.fromProjection,this.geotiffOptions.viewProjection,t);return[Number(e[0]),Number(e[1])]};if(this.tileProcessor=new l({transformViewToSourceMapFn:t=>{const e=i.proj4(this.geotiffOptions.viewProjection,i.fromProjection,t);return[Number(e[0]),Number(e[1])]},transformSourceMapToViewFn:r,sourceBounds:i.sourceBounds,sourceRef:i.sourceRef,resolution:i.resolution,imageWidth:i.width,imageHeight:i.height,fromProjection:i.fromProjection,toProjection:this.geotiffOptions.viewProjection,baseImage:i.baseImage,overviewImages:i.overviewImages??[]}),this.tileProcessor.createGlobalTriangulation(),this.setViewBounds(i.sourceBounds,r),this.geotiffOptions.colorMap){const{stops:t}=h(this.geotiffOptions.colorMap,this.geotiffOptions.valueRange);this.colorStops=t}}setViewBounds(t,e){const[s,i,o,a]=t,n=e([s,i]),c=e([o,i]),l=e([s,a]),h=e([o,a]),u=Math.min(n[0],c[0],l[0],h[0]),f=Math.max(n[0],c[0],l[0],h[0]),p=Math.min(n[1],c[1],l[1],h[1]),y=Math.max(n[1],c[1],l[1],h[1]),d=r.CRS.EPSG3857.unproject(r.point(u,y)),m=r.CRS.EPSG3857.unproject(r.point(f,p));this.options.bounds=r.latLngBounds(d,m)}}const m="v-map - leaflet - wcs - tile - ";class w extends r.GridLayer{wcsOptions;constructor(t){super(t),this.wcsOptions={...t,version:t.version??"2.0.1",format:t.format??"image/tiff",projection:t.projection??"EPSG:4326"}}buildWCSUrl(t){const{url:e,coverageName:s,version:i,format:r,projection:o,params:a}=this.wcsOptions,n=this._tileCoordsToBounds(t),c=n.getSouthWest(),l=n.getNorthEast(),h=c.lng,u=c.lat,f=l.lng,p=l.lat,y={SERVICE:"WCS",REQUEST:"GetCoverage",VERSION:i,FORMAT:r};if(i.startsWith("2.0")){y.coverageId=s;const t=a?{...a}:{},i={...y,...t};(r.includes("tiff")||r.includes("geotiff"))&&(i["geotiff:compression"]="LZW");const o=new URLSearchParams;Object.entries(i).forEach((([t,e])=>{null!=e&&o.set(t,String(e))}));const n=o.toString(),c=`subset=X(${h},${f})`,l=`subset=Y(${u},${p})`;return`${e}${e.includes("?")?"&":"?"}${n}&${c}&${l}`}{y.COVERAGE=s,y.BBOX=`${h},${u},${f},${p}`,y.CRS=o;const t=this.getTileSize();y.WIDTH="number"==typeof t?t:t.x,y.HEIGHT="number"==typeof t?t:t.y;const i=a?{...a}:{},r={...y,...i},n=new URLSearchParams;return Object.entries(r).forEach((([t,e])=>{null!=e&&n.set(t,String(e))})),`${e}${e.includes("?")?"&":"?"}${n.toString()}`}}createTile(t,e){const s=document.createElement("img"),i=this.buildWCSUrl(t);return a(`${m}load: coords=(${t.x},${t.y},${t.z})`),a(`${m}url: ${i}`),s.onload=()=>{e(null,s)},s.onerror=t=>{o(`${m}failed to load tile:`,t),e(t instanceof Error?t:new Error(String(t)),s)},s.crossOrigin="anonymous",s.src=i,s}updateOptions(t){this.wcsOptions={...this.wcsOptions,...t},this.redraw()}}class g{map;layers=[];baseLayers=[];hiddenLayerGroups=[];googleLogoAdded=!1;unsubscribeResize;shadowRoot;injectedStyle;layerErrorCallbacks=new Map;layerErrorCleanups=new Map;async init(o){if(!t())return;this.shadowRoot=o.shadowRoot,this.injectedStyle=function(i,o){if(t()){switch(i){case"cdn":return function(s,i=e,o="jsdelivr"){if(!t())return;const a="unpkg"===o?`https://unpkg.com/leaflet@${i}/dist/leaflet.css`:`https://cdn.jsdelivr.net/npm/leaflet@${i}/dist/leaflet.css`;r.Icon.Default.imagePath="unpkg"===o?`https://unpkg.com/npm/leaflet@${i}/dist/images/`:`https://cdn.jsdelivr.net/npm/leaflet@${i}/dist/images/`;const n=s??document;if(n.querySelector?.(`link[rel="stylesheet"][href="${a}"]`)||document.head.querySelector(`link[rel="stylesheet"][href="${a}"]`))return null;const c=document.createElement("link");return c.rel="stylesheet",c.href=a,(s??document.head).appendChild(c),c}(o);case"inline-min":return function(e){if(!t())return;const i="\n :host { display:block; }\n #map { width:100%; height:100%; display:block; }\n ";if(s()){const t=new CSSStyleSheet;t.replaceSync(i);const s=e??document;return s.adoptedStyleSheets=[...s.adoptedStyleSheets??[],t],null}{const t=document.createElement("style");return t.textContent=i,(e??document.head).appendChild(t),t}}(o)}return null}}(o.cssMode,this.shadowRoot);const[a,n]=o?.mapInitOptions?.center??[0,0];this.map=r.map(o.target,{zoomControl:!0,attributionControl:!0}).setView([n,a],o?.mapInitOptions?.zoom??2),this.unsubscribeResize=i(o.target,(()=>{this.map?.invalidateSize()}),{attributes:!0,attributeFilter:["style","class"]})}async updateLayer(t,e){const s=await this._getLayerById(t);switch(e.type){case"geojson":await this.updateGeoJSONLayer(s,e.data);break;case"osm":await this.updateOSMLayer(s,e.data);break;case"arcgis":await this.updateArcGISLayer(s,e.data);break;case"wkt":await this.updateWKTLayer(s,e.data);break;case"geotiff":await this.updateGeoTIFFLayer(s,e.data);break;case"wcs":await this.updateWCSLayer(s,e.data);break;case"wfs":s instanceof r.GeoJSON&&await this.updateWFSLayer(s,e.data)}}async addLayerToGroup(t){const e=await this._ensureGroup(t.groupId,t.groupVisible),s=await this.createLayer(t);if(null==s)return null;e.addLayer(s);const i=this.getLayerId(s);return s.vmapVisible=!0,s.vmapOpacity=1,void 0!==t.opacity&&this.setOpacityByLayer(s,t.opacity),void 0!==t.zIndex&&s.setZIndex?.(t.zIndex),t.visible?this.setVisibleByLayer(s,!0):!1===t.visible&&this.setVisibleByLayer(s,!1),i}async addBaseLayer(t,e,s){if(null==s)return a("leaflet - addBaseLayer - layerElementId not set."),null;null==e&&a("leaflet - addBaseLayer - basemapid not set.");const i=await this._ensureGroup(t.groupId,t.groupVisible);i.basemap=!0;const r=await this.createLayer(t);if(this.baseLayers.push(r),null==r)return null;r.layerElementId=s;const o=this.getLayerId(r);if(r.vmapVisible=!0,r.vmapOpacity=1,void 0!==t.opacity&&this.setOpacityByLayer(r,t.opacity),void 0!==t.zIndex&&r.setZIndex?.(t.zIndex),t.visible?this.setVisibleByLayer(r,!0):!1===t.visible&&this.setVisibleByLayer(r,!1),e===s){const t=i.getLayers()[0];t&&(this.map.removeLayer(t),i.clearLayers()),i.addLayer(r),i.visible&&r.addTo(this.map)}return o}async setBaseLayer(t,e){if(null===e)return void a("leaflet - setBaseLayer - layerElementId is null.");const s=this.layers.find((e=>e._groupId===t)),i=this.baseLayers.find((t=>t.layerElementId===e));if(void 0===i)return void a("leaflet - setBaseLayer - layer not found. layerElementId: "+e);if(!s)return;const r=s.getLayers()[0];r&&(this.map.removeLayer(r),s.clearLayers()),s.addLayer(i)}getLayerId(t){return String(r.Util.stamp(t))}normalizeAttribution(t){return Array.isArray(t)?t.join(", "):t}async _getLayerById(t){let e=null;return this.map?.eachLayer((s=>{this.getLayerId(s)===t&&(e=s)})),e||(e=this.baseLayers.find((e=>this.getLayerId(e)===t))??null,void 0===e?null:e)}async createLayer(t){switch(t.type){case"geojson":return this.createGeoJSONLayer(t);case"xyz":return this.createXYZLayer(t);case"osm":return this.createOSMLayer(t);case"wms":return this.createWMSLayer(t);case"wcs":return this.createWCSLayer(t);case"wfs":return this.createWFSLayer(t);case"arcgis":return this.createArcGISLayer(t);case"google":return this.createGoogleLayer(t);case"wkt":return this.createWKTLayer(t);case"geotiff":return this.createGeoTIFFLayer(t);default:throw new Error(`Unsupported layer type: ${t.type}`)}}async updateGeoJSONLayer(t,e){if(!(t instanceof r.GeoJSON))return;let s=null;if(e.geojson)s=JSON.parse(e.geojson);else if(e.url){const t=await fetch(e.url);if(!t.ok)throw new Error(`GeoJSON fetch failed: ${t.status} ${t.statusText}`);s=await t.json()}t.clearLayers(),t.addData(s)}async createGeoJSONLayer(t){let e=null;if(t.geojson)e=JSON.parse(t.geojson);else if(t.url){const s=await fetch(t.url);if(!s.ok)throw new Error(`GeoJSON fetch failed: ${s.status} ${s.statusText}`);e=await s.json()}if(e){let s={};if(t.geostylerStyle)s=await this.createGeostylerLeafletOptions(t.geostylerStyle);else{const e=t.style?{...n,...t.style}:n;s={style:this.createLeafletStyle(e),pointToLayer:(t,s)=>this.createLeafletPoint(t,s,e),onEachFeature:(t,s)=>this.bindLeafletPopup(t,s,e)}}return r.geoJSON(e,s)}return null}async createXYZLayer(t){return r.tileLayer(t.url,{attribution:this.normalizeAttribution(t.attributions),maxZoom:t.maxZoom??19,...t.options??{}})}async updateOSMLayer(t,e){if(!("setUrl"in t)||"function"!=typeof t.setUrl)return;let s="https://tile.openstreetmap.org/{z}/{x}/{y}.png";e.url&&(s=e.url+"/{z}/{x}/{y}.png"),t.setUrl(s)}async createOSMLayer(t){let e="https://tile.openstreetmap.org/{z}/{x}/{y}.png";return t.url&&(e=t.url+"/{z}/{x}/{y}.png"),r.tileLayer(e,{attribution:"© OpenStreetMap contributors",maxZoom:19})}async createWMSLayer(t){return r.tileLayer.wms(t.url,{layers:t.layers,format:t.format??"image/png",transparent:t.transparent??!0,...t.extraParams??{}})}buildArcGISUrl(t,e){if(!e||0===Object.keys(e).length)return t;const s=new URLSearchParams;return Object.entries(e).forEach((([t,e])=>{null!=e&&s.set(t,String(e))})),0===s.toString().length?t:`${t}${t.includes("?")?"&":"?"}${s.toString()}`}async createArcGISLayer(t){const e={...t.params??{}};t.token&&(e.token=t.token);const s=this.buildArcGISUrl(t.url,e),i={attribution:this.normalizeAttribution(t.attributions),minZoom:t.minZoom,maxZoom:t.maxZoom,...t.options??{}};return r.tileLayer(s,i)}async updateArcGISLayer(t,e){const s={...e?.params??{}};e?.token&&(s.token=e.token);const i=t,r=this.buildArcGISUrl(e?.url??i.options?.url??"",s);"setUrl"in i&&"function"==typeof i.setUrl&&i.setUrl(r)}async createGoogleLayer(t){if(!this.map)throw new Error("Map not initialized");if(!t.apiKey)throw new Error("Google-Layer benötigt 'apiKey' (Google Maps Platform).");const e="string"==typeof t.styles?this.tryParseStyles(t.styles):t.styles,s=new y({apiKey:t.apiKey,mapType:t.mapType??"roadmap",language:t.language,region:t.region,scale:t.scale,highDpi:t.highDpi,layerTypes:t.layerTypes,overlay:t.overlay,styles:Array.isArray(e)?e:void 0,imageFormat:t.imageFormat,apiOptions:t.apiOptions,maxZoom:t.maxZoom??22});return o=()=>{this.googleLogoAdded=!0,a("v-map - provider - leaflet - googleLogoAdded: ",this.googleLogoAdded)},(i=this.map)._googleLogoAdded||(new(r.Control.extend({onAdd(){const t=r.DomUtil.create("img");return t.src="https://developers.google.com/static/maps/documentation/images/google_on_white.png",t.alt="Google",t.style.pointerEvents="none",t.style.height="18px",t.style.margin="0 0 6px 6px",t},onRemove(){}}))({position:"bottomleft"}).addTo(i),i._googleLogoAdded=!0,o()),s;var i,o}tryParseStyles(t){try{const e=JSON.parse(t);return Array.isArray(e)?e:void 0}catch{return void o("Failed to parse Google styles JSON")}}async destroy(){var t;this.unsubscribeResize?.(),t=this.injectedStyle,this.shadowRoot&&t&&t.remove();for(const t of this.layers)this.map?.removeLayer(t);this.layers=[],this.map?.remove(),this.map=void 0}async setView([t,e],s){this.map?.setView([e,t],s,{animate:!1})}onLayerError(t,e){this.layerErrorCallbacks.set(t,e),this._getLayerById(t).then((s=>{if(!s)return;const i=()=>{e({type:"network",message:"Tile load error"})};s.on("tileerror",i),this.layerErrorCleanups.set(t,(()=>s.off("tileerror",i)))}))}offLayerError(t){this.layerErrorCleanups.get(t)?.(),this.layerErrorCleanups.delete(t),this.layerErrorCallbacks.delete(t)}async removeLayer(t){if(!t)return;this.offLayerError(t);const e=await this._getLayerById(t);e&&this.map.removeLayer(e)}async setZIndex(t,e){if(!t)return;const s=await this._getLayerById(t);s&&"function"==typeof s.setZIndex&&s.setZIndex(e)}async setOpacity(t,e){if(!t)return;const s=await this._getLayerById(t);this.setOpacityByLayer(s,e)}setOpacityByLayer(t,e){t&&(t.vmapOpacity=e,void 0===t.vmapVisible&&(t.vmapVisible=!0),!1!==t.vmapVisible&&this.setLayerOpacity(t,e))}async setVisible(t,e){if(!t)return;const s=await this._getLayerById(t);this.setVisibleByLayer(s,e)}setVisibleByLayer(t,e){t&&(t.vmapVisible=e,void 0===t.vmapOpacity&&(t.vmapOpacity=1),this.setLayerOpacity(t,e?t.vmapOpacity:0))}setLayerOpacity(t,e){if(!t)return;const s="number"==typeof e?e:e.opacity??1,i="number"==typeof e?e:e.fillOpacity??s,o=(t,e)=>{if(!(e in r))return!1;const s=r[e];return"function"==typeof s&&t instanceof s};var a;o(a=t,"GeoJSON")||o(a,"LayerGroup")?t.eachLayer((t=>this.setLayerOpacity(t,e))):(t=>o(t,"Path"))(t)?t.setStyle({opacity:s,fillOpacity:i}):((t=>o(t,"Marker"))(t)||"setOpacity"in t)&&t.setOpacity(s)}async ensureGroup(t,e,s){await this._ensureGroup(t,e)}async _ensureGroup(t,e){let s=await this._getLayerGroupById(t);return s||(s=r.layerGroup(),s._groupId=t,s.visible=!0,s.addTo(this.map),this.layers.push(s)),this.setGroupVisible(t,void 0===e||e),s}async _getLayerGroupById(t){if(!this.map)return null;let e=this.layers.find((e=>e instanceof r.LayerGroup&&e._groupId===t));return e||(e=this.hiddenLayerGroups.find((e=>e._groupId===t)),e)?e:null}async setGroupVisible(t,e){const s=await this._getLayerGroupById(t);if(s){if(s.visible===e)return;!1===s.visible?(s.addTo(this.map),this.hiddenLayerGroups=this.hiddenLayerGroups.filter((e=>e._groupId!==t)),s.visible=e):!0===s.visible&&(this.map.removeLayer(s),s.visible=e,this.hiddenLayerGroups.push(s))}}async updateWKTLayer(t,e){if(!(t instanceof r.GeoJSON))return;let s=null;if(e.wkt)s=await this.wktToGeoJSON(e.wkt);else if(e.url)try{const t=await fetch(e.url);if(!t.ok)throw new Error(`Failed to fetch WKT: ${t.status}`);const i=await t.text();s=await this.wktToGeoJSON(i)}catch(t){return void o("Failed to load WKT from URL:",t)}if(s){t.clearLayers();const i=t;i.options.style=this.createLeafletStyle(e.style),i.options.pointToLayer=(t,s)=>this.createLeafletPoint(t,s,e.style),i.options.onEachFeature=(t,s)=>this.bindLeafletPopup(t,s,e.style),i.addData(s)}}async createWKTLayer(t){let e=null;const s={type:"FeatureCollection",features:[]};if(t.wkt)e=await this.wktToGeoJSON(t.wkt);else if(t.url)try{const s=await fetch(t.url);if(!s.ok)throw new Error(`Failed to fetch WKT: ${s.status}`);const i=await s.text();e=await this.wktToGeoJSON(i)}catch(t){o("Failed to load WKT from URL:",t),e=s}else e=s;a("[Leaflet WKT] Creating layer with GeoJSON data:",e),a("[Leaflet WKT] Config:",t);let i={};if(t.geostylerStyle)i=await this.createGeostylerLeafletOptions(t.geostylerStyle);else{const e=t.style?{...n,...t.style}:n;i={style:this.createLeafletStyle(e),pointToLayer:(t,s)=>this.createLeafletPoint(t,s,e),onEachFeature:(t,s)=>this.bindLeafletPopup(t,s,e)}}a("[Leaflet WKT] Layer options:",i);const c=r.geoJSON(e,i);return a("[Leaflet WKT] Created layer:",c),"function"==typeof c.getBounds&&a("[Leaflet WKT] Layer bounds:",c.getBounds()),c}async wktToGeoJSON(t){try{const e=u.wellknown.parse(t);if(!e)throw new Error("Failed to parse WKT - returned null");const s={type:"Feature",geometry:e,properties:{}};return a("[Leaflet WKT] Input WKT:",t),a("[Leaflet WKT] Generated GeoJSON:",JSON.stringify(s,null,2)),{type:"FeatureCollection",features:[s]}}catch(e){return o("[Leaflet WKT] Failed to parse WKT:",t,e),{type:"FeatureCollection",features:[]}}}async createGeoTIFFLayer(t){if(!t.url)throw new Error("GeoTIFF layer requires a URL");try{const e=new d({url:t.url,tileSize:256,colorMap:t.colorMap,valueRange:t.valueRange,nodata:t.nodata,resolution:t.resolution,resampleMethod:t.resampleMethod,viewProjection:this.map.options.crs.code});return void 0!==t.opacity&&e.setOpacity?.(t.opacity),void 0!==t.zIndex&&e.setZIndex?.(t.zIndex),e}catch(t){return o("Failed to create GeoTIFF layer:",t),r.layerGroup([])}}async updateGeoTIFFLayer(t,e){if(!e.url)throw new Error("GeoTIFF update requires a URL");if(!t)return;if(!(t instanceof d))return;const s=e;await t.updateSource({url:e.url,colorMap:e.colorMap,valueRange:e.valueRange,nodata:e.nodata,resolution:s.resolution,resampleMethod:s.resampleMethod})}async createWCSLayer(t){if(!t.url)throw new Error("WCS layer requires a URL");if(!t.coverageName)throw new Error("WCS layer requires a coverageName");try{const e={url:t.url,coverageName:t.coverageName,version:t.version??"2.0.1",format:t.format??"image/tiff",projection:t.projection??"EPSG:4326",params:t.params};t.tileSize&&(e.tileSize=t.tileSize),void 0!==t.minZoom&&(e.minZoom=t.minZoom),void 0!==t.maxZoom&&(e.maxZoom=t.maxZoom);const s=new w(e);return void 0!==t.opacity&&s.setOpacity?.(t.opacity),void 0!==t.zIndex&&s.setZIndex?.(t.zIndex),s}catch(t){return o("[Leaflet WCS] Failed to create WCS layer:",t),r.layerGroup([])}}async updateWCSLayer(t,e){if(t&&t instanceof w){const s={};e.url&&(s.url=e.url),e.coverageName&&(s.coverageName=e.coverageName),e.version&&(s.version=e.version),e.format&&(s.format=e.format),e.projection&&(s.projection=e.projection),e.params&&(s.params=e.params),t.updateOptions(s)}}async createGeostylerLeafletOptions(t){const e=(t,e)=>null==t||"object"==typeof t&&t.name?e:t;return{style:s=>{const i=s?.geometry?.type;let r={};if(t.rules)for(const s of t.rules)if(s.symbolizers)for(const t of s.symbolizers)switch(t.kind){case"Fill":if("Polygon"===i||"MultiPolygon"===i){const s=e(t.color,"rgba(0,100,255,0.3)"),i=e(t.opacity,.3),o=e(t.outlineColor,"rgba(0,100,255,1)"),a=e(t.outlineWidth,1);r={...r,fillColor:s,fillOpacity:i,color:o,weight:a}}break;case"Line":const s=e(t.color,"rgba(0,100,255,1)"),o=e(t.width,2),a=t.dasharray&&Array.isArray(t.dasharray)?t.dasharray.map((t=>e(t,0))).join(","):void 0;r={...r,color:s,weight:o,dashArray:a}}return r},pointToLayer:(s,i)=>{if(t.rules)for(const s of t.rules)if(s.symbolizers)for(const t of s.symbolizers)switch(t.kind){case"Mark":const s=e(t.color,"rgba(0,100,255,1)"),o=e(t.radius,6),a=e(t.strokeColor,"rgba(0,100,255,1)"),n=e(t.strokeWidth,2);return r.circleMarker(i,{radius:o,fillColor:s,fillOpacity:1,color:a,weight:n});case"Icon":const c=e(t.image),l=e(t.size,32);if(c&&"string"==typeof c){const t=r.icon({iconUrl:c,iconSize:[l,l],iconAnchor:[l/2,l]});return r.marker(i,{icon:t})}}return r.circleMarker(i,{radius:6,fillColor:"rgba(0,100,255,1)",fillOpacity:1,color:"rgba(0,100,255,1)",weight:2})},onEachFeature:(s,i)=>{if(t.rules)for(const r of t.rules)if(r.symbolizers)for(const t of r.symbolizers)if("Text"===t.kind){const r=t.label;if(r&&"string"==typeof r&&s.properties&&s.properties[r]){const o=String(s.properties[r]),a=e(t.color,"#000000"),n=e(t.size,12);i.bindTooltip(`<div style="color: ${a}; font-size: ${n}px; font-family: Arial, sans-serif;">${o}</div>`,{permanent:!0,direction:"center",className:"leaflet-tooltip-custom"})}}}}}createLeafletStyle(t){return e=>{const s=e?.geometry?.type,i=t?.fillColor??"rgba(0,100,255,0.3)",r=t?.fillOpacity??.3,o=t?.strokeColor??"rgba(0,100,255,1)",a=t?.strokeOpacity??1,n=t?.strokeWidth??2;return"Polygon"===s||"MultiPolygon"===s?{fillColor:i,fillOpacity:r,color:o,opacity:a,weight:n,dashArray:t?.strokeDashArray?t.strokeDashArray.join(","):void 0}:"LineString"===s||"MultiLineString"===s?{color:o,opacity:a,weight:n,dashArray:t?.strokeDashArray?t.strokeDashArray.join(","):void 0}:{}}}createLeafletPoint(t,e,s){let i={...s??{}};if(s?.styleFunction){const e=s.styleFunction(t);e&&(i={...s,...e})}if(i?.iconUrl){const t=i.iconSize||[32,32],s=r.icon({iconUrl:i.iconUrl,iconSize:t,iconAnchor:i.iconAnchor||[t[0]/2,t[1]]});return r.marker(e,{icon:s})}{const t=i?.pointColor??"rgba(0,100,255,1)",s=i?.pointOpacity??1;return r.circleMarker(e,{radius:i?.pointRadius??6,fillColor:t,fillOpacity:s,color:i?.strokeColor??"rgba(0,100,255,1)",opacity:i?.strokeOpacity??1,weight:i?.strokeWidth??2})}}bindLeafletPopup(t,e,s){if(s?.textProperty&&t.properties&&t.properties[s.textProperty]){const i=String(t.properties[s.textProperty]);e.bindTooltip(`<div style="color: ${s?.textColor??"#000000"}; font-size: ${s?.textSize??12}px; font-family: Arial, sans-serif;">${i}</div>`,{permanent:!0,direction:"center",className:"leaflet-tooltip-custom"})}}async createWFSLayer(t){const e=await this.fetchWFSFromUrl(t);let s={};if(t.geostylerStyle)s=await this.createGeostylerLeafletOptions(t.geostylerStyle);else{const e=t.style?{...n,...t.style}:n;s={style:this.createLeafletStyle(e),pointToLayer:(t,s)=>this.createLeafletPoint(t,s,e),onEachFeature:(t,s)=>this.bindLeafletPopup(t,s,e)}}return r.geoJSON(e,s)}async updateWFSLayer(t,e){const s=await this.fetchWFSFromUrl(e);t.clearLayers(),t.addData(s)}async fetchWFSFromUrl(t){const e={service:"WFS",request:"GetFeature",version:t.version??"1.1.0",typeName:t.typeName,outputFormat:t.outputFormat??"application/json",srsName:t.srsName??"EPSG:4326",...t.params??{}},s=this.appendParams(t.url,e),i=await fetch(s);if(!i.ok)throw new Error(`WFS request failed (${i.status} ${i.statusText})`);const r=(t.outputFormat??"application/json").toLowerCase();if(r.includes("json")||r.includes("geojson")||"application/json"===r)return await i.json();if(r.includes("gml")||r.includes("xml")){const t=await i.text(),e=new f;return await e.parse(t)}return await i.json()}appendParams(t,e){const s=new URLSearchParams;return Object.entries(e).forEach((([t,e])=>{null!=e&&s.set(t,String(e))})),s.toString()?`${t}${t.includes("?")?"&":"?"}${s.toString()}`:t}getMap(){return this.map}}export{g as LeafletProvider}
|
|
1
|
+
import{i as t,L as e,s,w as i}from"./p-BOfJXm8U.js";import*as r from"leaflet";import{e as o,l as a}from"./p-QJHuuz0g.js";import{D as n}from"./p-B-bAcABs.js";import{l as c,G as l,g as h}from"./p-yXLNXXx-.js";import{w as u}from"./p-DR9McdNX.js";import{GmlParser as f}from"./p-DhQAXuA7.js";import"./p-BoNyIrdq.js";import"./p-CrV_misM.js";import"./p-DVBtCUtQ.js";import"./p-E-ZsRS8r.js";const p=256;class y extends r.GridLayer{apiKey;highDpi;sessionRequest;scaleFactor;sessionToken;sessionPromise;sessionRefreshId;previousViewport;currentAttribution;mapInstance;onMoveEnd;constructor(t){super(),this.applyInitialGridOptions(t);const{apiKey:e,mapType:s,language:i,region:r,imageFormat:o,scale:a,highDpi:n,layerTypes:c,overlay:l,styles:h,apiOptions:u}=t;if(!e)throw new Error("Google Map Tiles layer requires an apiKey");this.apiKey=e,this.highDpi=n??(void 0===a||"scaleFactor1x"!==a),this.scaleFactor=this.mapScaleToFactor(a,this.highDpi);const f={mapType:s??"roadmap",language:i??"en-US",region:r??"US"};o&&(f.imageFormat=o),c?.length&&(f.layerTypes=c),u?.length&&(f.apiOptions=u),Array.isArray(h)&&h.length>0&&(f.styles=h),!0===l&&(f.overlay=!0);const p=a??(this.scaleFactor>1?this.factorToScale(this.scaleFactor):void 0);p&&(f.scale=p),this.highDpi&&(f.highDpi=!0),this.sessionRequest=f,this.onMoveEnd=()=>{this.updateAttribution()},this.sessionPromise=this.startSessionFetch()}onAdd(t){return this.mapInstance=t,t.on("moveend",this.onMoveEnd),t.on("zoomend",this.onMoveEnd),this.ensureSession().then((()=>this.updateAttribution())),super.onAdd(t)}onRemove(t){return t.off("moveend",this.onMoveEnd),t.off("zoomend",this.onMoveEnd),this.clearSessionRefresh(),this.removeCurrentAttribution(),this.mapInstance=void 0,super.onRemove(t)}createTile(t,e){const s=document.createElement("img");s.decoding="async",s.alt="",s.crossOrigin="anonymous";const i=this.resolveTileSize();s.width=i.x,s.height=i.y;const r=t=>{const i=t instanceof Error?t.message:"Google tile load error";e(new Error(i),s)};return s.onload=()=>e(null,s),s.onerror=t=>{const e=t instanceof ErrorEvent?t.error??new Error(t.message):new Error("Google tile failed to load");r(e)},this.ensureSession().then((()=>{this.sessionToken?s.src=this.buildTileUrl(t):r(new Error("Google Maps session unavailable"))})).catch((t=>{r(t)})),s}ensureSession(){return this.sessionToken?Promise.resolve():(this.sessionPromise||(this.sessionPromise=this.startSessionFetch()),this.sessionPromise)}startSessionFetch(t=!1){if(this.sessionPromise&&!t)return this.sessionPromise;const e=this.fetchAndApplySession().catch((t=>{const e=t instanceof Error?t:new Error("Failed to create Google Maps session");throw o("Google Map Tiles session error",e),this.sessionToken=void 0,e})).finally((()=>{this.sessionPromise===e&&(this.sessionPromise=void 0)}));return this.sessionPromise=e,e}async fetchAndApplySession(){const t=`https://tile.googleapis.com/v1/createSession?key=${this.apiKey}`,e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(this.sessionRequest)});if(!e.ok){let t;try{const s=await e.json();t=s?.error?.message}catch{}throw new Error(t??`Google Maps session request failed (${e.status})`)}const s=await e.json();this.sessionToken=s.session,this.applyTileSize(s),this.scheduleSessionRefresh(this.parseExpiry(s.expiry)),this.mapInstance&&(this.updateAttribution(),this.redrawLayer()),a("Google Map Tiles session established")}scheduleSessionRefresh(t){if(!isFinite(t))return;const e=Math.max(t-Date.now()-6e4,1e3);this.clearSessionRefresh(),this.sessionRefreshId=setTimeout((()=>{this.startSessionFetch(!0).then((()=>{this.mapInstance&&(this.updateAttribution(),this.redrawLayer())}))}),e)}clearSessionRefresh(){void 0!==this.sessionRefreshId&&(clearTimeout(this.sessionRefreshId),this.sessionRefreshId=void 0)}async updateAttribution(){if(!this.mapInstance||!this.sessionToken)return;const t=this.mapInstance.getBounds();if(!t?.isValid())return;const e=`zoom=${this.mapInstance.getZoom()}&north=${t.getNorth()}&south=${t.getSouth()}&east=${t.getEast()}&west=${t.getWest()}`;if(this.previousViewport!==e){this.previousViewport=e;try{const t=await fetch(`https://tile.googleapis.com/tile/v1/viewport?session=${this.sessionToken}&key=${this.apiKey}&${e}`);if(!t.ok)throw new Error(`Attribution request failed (${t.status})`);const s=await t.json(),i=s?.copyright;"string"==typeof i&&i.length>0&&this.applyAttribution(i)}catch(t){o("Failed to fetch Google attribution",t)}}}applyAttribution(t){const e=this.mapInstance;e?.attributionControl&&(this.currentAttribution&&this.currentAttribution!==t&&e.attributionControl.removeAttribution(this.currentAttribution),this.currentAttribution&&this.currentAttribution===t||(e.attributionControl.addAttribution(t),this.currentAttribution=t))}removeCurrentAttribution(){const t=this.mapInstance;t?.attributionControl&&this.currentAttribution&&(t.attributionControl.removeAttribution(this.currentAttribution),this.currentAttribution=void 0)}applyTileSize(t){const e=Math.max(1,Math.round(t.tileWidth/this.scaleFactor)),s=Math.max(1,Math.round(t.tileHeight/this.scaleFactor)),i=r.point(e,s);this.setGridOptions({tileSize:i})}parseExpiry(t){const e=parseInt(t,10);return Number.isFinite(e)?1e3*e:Number.NaN}buildTileUrl(t){if(!this.sessionToken)throw new Error("Google Maps session missing");return`https://tile.googleapis.com/v1/2dtiles/${t.z}/${t.x}/${t.y}?session=${this.sessionToken}&key=${this.apiKey}`}mapScaleToFactor(t,e){switch(t){case"scaleFactor4x":return 4;case"scaleFactor2x":return 2;case"scaleFactor1x":return 1;default:return e?2:1}}factorToScale(t){switch(t){case 4:return"scaleFactor4x";case 2:return"scaleFactor2x";case 1:return"scaleFactor1x";default:return}}applyInitialGridOptions(t){const e={},s=["attribution","bounds","className","detectRetina","errorTileUrl","keepBuffer","maxNativeZoom","maxZoom","minNativeZoom","minZoom","noWrap","opacity","pane","reuseTiles","subdomains","tileSize","tms","updateInterval","updateWhenIdle","updateWhenZooming","zIndex","zoomOffset"];for(const i of s){const s=t[i];void 0!==s&&(e[i]=s)}void 0===e.maxZoom&&(e.maxZoom=22),this.setGridOptions(e)}setGridOptions(t){const e=r.Util?.setOptions;if("function"==typeof e)e(this,t);else{const e=this;e.options={...e.options,...t}}}resolveTileSize(){const t=this.options?.tileSize;if(t&&"object"==typeof t){if(Array.isArray(t)&&2===t.length){const[e,s]=t;return r.point(Number(e)||p,Number(s)||p)}if("x"in t&&"y"in t){const e=t;return r.point(Number(e.x)||p,Number(e.y)||p)}}return"number"==typeof t&&Number.isFinite(t)?r.point(t,t):r.point(p,p)}redrawLayer(){this.redraw()}}class d extends r.GridLayer{geotiffOptions;tileProcessor=null;colorStops;loadingPromise;defaultResolution=1;defaultResample="bilinear";constructor(t){super(t),this.geotiffOptions={...t}}onAdd(t){return super.onAdd(t),this.ensureReady().then((()=>this.redraw())),this}createTile(t,e){const s=this.getTileSize(),i=r.DomUtil.create("canvas","leaflet-tile");return i.width=s.x,i.height=s.y,this.ensureReady().then((async()=>{if(this.tileProcessor)try{const r=await this.tileProcessor.getTileData({x:t.x,y:t.y,z:t.z,tileSize:s.x,resolution:this.geotiffOptions.resolution??this.defaultResolution,resampleMethod:this.geotiffOptions.resampleMethod??this.defaultResample,colorStops:this.colorStops});if(!r)return void e(null,i);const o=i.getContext("2d");if(o){const t=o.createImageData(s.x,s.y);t.data.set(r),o.putImageData(t,0,0)}e(null,i)}catch(t){e(t,i)}else e(null,i)})).catch((t=>{e(t,i)})),i}async ensureReady(){return this.loadingPromise||(this.loadingPromise=this.initializeProcessor()),this.loadingPromise}async updateSource(t){Object.assign(this.geotiffOptions,t),this.tileProcessor=null,this.colorStops=void 0,this.loadingPromise=void 0,await this.ensureReady(),this.redraw()}async initializeProcessor(){if(this.tileProcessor)return;const[t,{default:e},s]=await Promise.all([import("./p-Be3r33VF.js").then((function(t){return t.g})),import("./p-RpJarvr_.js"),import("./p-CXfA_q8m.js").then((function(t){return t.m}))]),i=await c(this.geotiffOptions.url,{projection:void 0,forceProjection:!1,nodata:this.geotiffOptions.nodata},{geotiff:t,proj4:e,geokeysToProj4:s}),r=t=>{const e=i.proj4(i.fromProjection,this.geotiffOptions.viewProjection,t);return[Number(e[0]),Number(e[1])]};if(this.tileProcessor=new l({transformViewToSourceMapFn:t=>{const e=i.proj4(this.geotiffOptions.viewProjection,i.fromProjection,t);return[Number(e[0]),Number(e[1])]},transformSourceMapToViewFn:r,sourceBounds:i.sourceBounds,sourceRef:i.sourceRef,resolution:i.resolution,imageWidth:i.width,imageHeight:i.height,fromProjection:i.fromProjection,toProjection:this.geotiffOptions.viewProjection,baseImage:i.baseImage,overviewImages:i.overviewImages??[]}),this.tileProcessor.createGlobalTriangulation(),this.setViewBounds(i.sourceBounds,r),this.geotiffOptions.colorMap){const{stops:t}=h(this.geotiffOptions.colorMap,this.geotiffOptions.valueRange);this.colorStops=t}}setViewBounds(t,e){const[s,i,o,a]=t,n=e([s,i]),c=e([o,i]),l=e([s,a]),h=e([o,a]),u=Math.min(n[0],c[0],l[0],h[0]),f=Math.max(n[0],c[0],l[0],h[0]),p=Math.min(n[1],c[1],l[1],h[1]),y=Math.max(n[1],c[1],l[1],h[1]),d=r.CRS.EPSG3857.unproject(r.point(u,y)),m=r.CRS.EPSG3857.unproject(r.point(f,p));this.options.bounds=r.latLngBounds(d,m)}}const m="v-map - leaflet - wcs - tile - ";class w extends r.GridLayer{wcsOptions;constructor(t){super(t),this.wcsOptions={...t,version:t.version??"2.0.1",format:t.format??"image/tiff",projection:t.projection??"EPSG:4326"}}buildWCSUrl(t){const{url:e,coverageName:s,version:i,format:r,projection:o,params:a}=this.wcsOptions,n=this._tileCoordsToBounds(t),c=n.getSouthWest(),l=n.getNorthEast(),h=c.lng,u=c.lat,f=l.lng,p=l.lat,y={SERVICE:"WCS",REQUEST:"GetCoverage",VERSION:i,FORMAT:r};if(i.startsWith("2.0")){y.coverageId=s;const t=a?{...a}:{},i={...y,...t};(r.includes("tiff")||r.includes("geotiff"))&&(i["geotiff:compression"]="LZW");const o=new URLSearchParams;Object.entries(i).forEach((([t,e])=>{null!=e&&o.set(t,String(e))}));const n=o.toString(),c=`subset=X(${h},${f})`,l=`subset=Y(${u},${p})`;return`${e}${e.includes("?")?"&":"?"}${n}&${c}&${l}`}{y.COVERAGE=s,y.BBOX=`${h},${u},${f},${p}`,y.CRS=o;const t=this.getTileSize();y.WIDTH="number"==typeof t?t:t.x,y.HEIGHT="number"==typeof t?t:t.y;const i=a?{...a}:{},r={...y,...i},n=new URLSearchParams;return Object.entries(r).forEach((([t,e])=>{null!=e&&n.set(t,String(e))})),`${e}${e.includes("?")?"&":"?"}${n.toString()}`}}createTile(t,e){const s=document.createElement("img"),i=this.buildWCSUrl(t);return a(`${m}load: coords=(${t.x},${t.y},${t.z})`),a(`${m}url: ${i}`),s.onload=()=>{e(null,s)},s.onerror=t=>{o(`${m}failed to load tile:`,t),e(t instanceof Error?t:new Error(String(t)),s)},s.crossOrigin="anonymous",s.src=i,s}updateOptions(t){this.wcsOptions={...this.wcsOptions,...t},this.redraw()}}class g{map;layers=[];baseLayers=[];hiddenLayerGroups=[];googleLogoAdded=!1;unsubscribeResize;shadowRoot;injectedStyle;layerErrorCallbacks=new Map;layerErrorCleanups=new Map;async init(o){if(!t())return;this.shadowRoot=o.shadowRoot,this.injectedStyle=function(i,o){if(t()){switch(i){case"cdn":return function(s,i=e,o="jsdelivr"){if(!t())return;const a="unpkg"===o?`https://unpkg.com/leaflet@${i}/dist/leaflet.css`:`https://cdn.jsdelivr.net/npm/leaflet@${i}/dist/leaflet.css`;r.Icon.Default.imagePath="unpkg"===o?`https://unpkg.com/npm/leaflet@${i}/dist/images/`:`https://cdn.jsdelivr.net/npm/leaflet@${i}/dist/images/`;const n=s??document;if(n.querySelector?.(`link[rel="stylesheet"][href="${a}"]`)||document.head.querySelector(`link[rel="stylesheet"][href="${a}"]`))return null;const c=document.createElement("link");return c.rel="stylesheet",c.href=a,(s??document.head).appendChild(c),c}(o);case"inline-min":return function(e){if(!t())return;const i="\n :host { display:block; }\n #map { width:100%; height:100%; display:block; }\n ";if(s()){const t=new CSSStyleSheet;t.replaceSync(i);const s=e??document;return s.adoptedStyleSheets=[...s.adoptedStyleSheets??[],t],null}{const t=document.createElement("style");return t.textContent=i,(e??document.head).appendChild(t),t}}(o)}return null}}(o.cssMode,this.shadowRoot);const[a,n]=o?.mapInitOptions?.center??[0,0];this.map=r.map(o.target,{zoomControl:!0,attributionControl:!0}).setView([n,a],o?.mapInitOptions?.zoom??2),this.unsubscribeResize=i(o.target,(()=>{this.map?.invalidateSize()}),{attributes:!0,attributeFilter:["style","class"]})}async updateLayer(t,e){const s=await this._getLayerById(t);switch(e.type){case"geojson":await this.updateGeoJSONLayer(s,e.data);break;case"osm":await this.updateOSMLayer(s,e.data);break;case"arcgis":await this.updateArcGISLayer(s,e.data);break;case"wkt":await this.updateWKTLayer(s,e.data);break;case"geotiff":await this.updateGeoTIFFLayer(s,e.data);break;case"wcs":await this.updateWCSLayer(s,e.data);break;case"wfs":s instanceof r.GeoJSON&&await this.updateWFSLayer(s,e.data)}}async addLayerToGroup(t){const e=await this._ensureGroup(t.groupId,t.groupVisible),s=await this.createLayer(t);if(null==s)return null;e.addLayer(s);const i=this.getLayerId(s);return s.vmapVisible=!0,s.vmapOpacity=1,void 0!==t.opacity&&this.setOpacityByLayer(s,t.opacity),void 0!==t.zIndex&&s.setZIndex?.(t.zIndex),t.visible?this.setVisibleByLayer(s,!0):!1===t.visible&&this.setVisibleByLayer(s,!1),i}async addBaseLayer(t,e,s){if(null==s)return a("leaflet - addBaseLayer - layerElementId not set."),null;null==e&&a("leaflet - addBaseLayer - basemapid not set.");const i=await this._ensureGroup(t.groupId,t.groupVisible);i.basemap=!0;const r=await this.createLayer(t);if(this.baseLayers.push(r),null==r)return null;r.layerElementId=s;const o=this.getLayerId(r);if(r.vmapVisible=!0,r.vmapOpacity=1,void 0!==t.opacity&&this.setOpacityByLayer(r,t.opacity),void 0!==t.zIndex&&r.setZIndex?.(t.zIndex),t.visible?this.setVisibleByLayer(r,!0):!1===t.visible&&this.setVisibleByLayer(r,!1),e===s){const t=i.getLayers()[0];t&&(this.map.removeLayer(t),i.clearLayers()),i.addLayer(r),i.visible&&r.addTo(this.map)}return o}async setBaseLayer(t,e){if(null===e)return void a("leaflet - setBaseLayer - layerElementId is null.");const s=this.layers.find((e=>e._groupId===t)),i=this.baseLayers.find((t=>t.layerElementId===e));if(void 0===i)return void a("leaflet - setBaseLayer - layer not found. layerElementId: "+e);if(!s)return;const r=s.getLayers()[0];r&&(this.map.removeLayer(r),s.clearLayers()),s.addLayer(i)}getLayerId(t){return String(r.Util.stamp(t))}normalizeAttribution(t){return Array.isArray(t)?t.join(", "):t}async _getLayerById(t){let e=null;return this.map?.eachLayer((s=>{this.getLayerId(s)===t&&(e=s)})),e||(e=this.baseLayers.find((e=>this.getLayerId(e)===t))??null,void 0===e?null:e)}async createLayer(t){switch(t.type){case"geojson":return this.createGeoJSONLayer(t);case"xyz":return this.createXYZLayer(t);case"osm":return this.createOSMLayer(t);case"wms":return this.createWMSLayer(t);case"wcs":return this.createWCSLayer(t);case"wfs":return this.createWFSLayer(t);case"arcgis":return this.createArcGISLayer(t);case"google":return this.createGoogleLayer(t);case"wkt":return this.createWKTLayer(t);case"geotiff":return this.createGeoTIFFLayer(t);default:throw new Error(`Unsupported layer type: ${t.type}`)}}async updateGeoJSONLayer(t,e){if(!(t instanceof r.GeoJSON))return;let s=null;if(e.geojson)s=JSON.parse(e.geojson);else if(e.url){const t=await fetch(e.url);if(!t.ok)throw new Error(`GeoJSON fetch failed: ${t.status} ${t.statusText}`);s=await t.json()}t.clearLayers(),t.addData(s)}async createGeoJSONLayer(t){let e=null;if(t.geojson)e=JSON.parse(t.geojson);else if(t.url){const s=await fetch(t.url);if(!s.ok)throw new Error(`GeoJSON fetch failed: ${s.status} ${s.statusText}`);e=await s.json()}if(e){let s={};if(t.geostylerStyle)s=await this.createGeostylerLeafletOptions(t.geostylerStyle);else{const e=t.style?{...n,...t.style}:n;s={style:this.createLeafletStyle(e),pointToLayer:(t,s)=>this.createLeafletPoint(t,s,e),onEachFeature:(t,s)=>this.bindLeafletPopup(t,s,e)}}return r.geoJSON(e,s)}return null}async createXYZLayer(t){return r.tileLayer(t.url,{attribution:this.normalizeAttribution(t.attributions),maxZoom:t.maxZoom??19,...t.options??{}})}async updateOSMLayer(t,e){if(!("setUrl"in t)||"function"!=typeof t.setUrl)return;let s="https://tile.openstreetmap.org/{z}/{x}/{y}.png";e.url&&(s=e.url+"/{z}/{x}/{y}.png"),t.setUrl(s)}async createOSMLayer(t){let e="https://tile.openstreetmap.org/{z}/{x}/{y}.png";return t.url&&(e=t.url+"/{z}/{x}/{y}.png"),r.tileLayer(e,{attribution:"© OpenStreetMap contributors",maxZoom:19})}async createWMSLayer(t){return r.tileLayer.wms(t.url,{layers:t.layers,format:t.format??"image/png",transparent:t.transparent??!0,...t.extraParams??{}})}buildArcGISUrl(t,e){if(!e||0===Object.keys(e).length)return t;const s=new URLSearchParams;return Object.entries(e).forEach((([t,e])=>{null!=e&&s.set(t,String(e))})),0===s.toString().length?t:`${t}${t.includes("?")?"&":"?"}${s.toString()}`}async createArcGISLayer(t){const e={...t.params??{}};t.token&&(e.token=t.token);const s=this.buildArcGISUrl(t.url,e),i={attribution:this.normalizeAttribution(t.attributions),minZoom:t.minZoom,maxZoom:t.maxZoom,...t.options??{}};return r.tileLayer(s,i)}async updateArcGISLayer(t,e){const s={...e?.params??{}};e?.token&&(s.token=e.token);const i=t,r=this.buildArcGISUrl(e?.url??i.options?.url??"",s);"setUrl"in i&&"function"==typeof i.setUrl&&i.setUrl(r)}async createGoogleLayer(t){if(!this.map)throw new Error("Map not initialized");if(!t.apiKey)throw new Error("Google-Layer benötigt 'apiKey' (Google Maps Platform).");const e="string"==typeof t.styles?this.tryParseStyles(t.styles):t.styles,s=new y({apiKey:t.apiKey,mapType:t.mapType??"roadmap",language:t.language,region:t.region,scale:t.scale,highDpi:t.highDpi,layerTypes:t.layerTypes,overlay:t.overlay,styles:Array.isArray(e)?e:void 0,imageFormat:t.imageFormat,apiOptions:t.apiOptions,maxZoom:t.maxZoom??22});return o=()=>{this.googleLogoAdded=!0,a("v-map - provider - leaflet - googleLogoAdded: ",this.googleLogoAdded)},(i=this.map)._googleLogoAdded||(new(r.Control.extend({onAdd(){const t=r.DomUtil.create("img");return t.src="https://developers.google.com/static/maps/documentation/images/google_on_white.png",t.alt="Google",t.style.pointerEvents="none",t.style.height="18px",t.style.margin="0 0 6px 6px",t},onRemove(){}}))({position:"bottomleft"}).addTo(i),i._googleLogoAdded=!0,o()),s;var i,o}tryParseStyles(t){try{const e=JSON.parse(t);return Array.isArray(e)?e:void 0}catch{return void o("Failed to parse Google styles JSON")}}async destroy(){var t;this.unsubscribeResize?.(),t=this.injectedStyle,this.shadowRoot&&t&&t.remove();for(const t of this.layers)this.map?.removeLayer(t);this.layers=[],this.map?.remove(),this.map=void 0}async setView([t,e],s){this.map?.setView([e,t],s,{animate:!1})}getView(){if(!this.map)return null;const t=this.map.getCenter();return{center:[t.lng,t.lat],zoom:this.map.getZoom()}}onLayerError(t,e){this.layerErrorCallbacks.set(t,e),this._getLayerById(t).then((s=>{if(!s)return;const i=()=>{e({type:"network",message:"Tile load error"})};s.on("tileerror",i),this.layerErrorCleanups.set(t,(()=>s.off("tileerror",i)))}))}offLayerError(t){this.layerErrorCleanups.get(t)?.(),this.layerErrorCleanups.delete(t),this.layerErrorCallbacks.delete(t)}async removeLayer(t){if(!t)return;this.offLayerError(t);const e=await this._getLayerById(t);e&&this.map.removeLayer(e)}async setZIndex(t,e){if(!t)return;const s=await this._getLayerById(t);s&&"function"==typeof s.setZIndex&&s.setZIndex(e)}async setOpacity(t,e){if(!t)return;const s=await this._getLayerById(t);this.setOpacityByLayer(s,e)}setOpacityByLayer(t,e){t&&(t.vmapOpacity=e,void 0===t.vmapVisible&&(t.vmapVisible=!0),!1!==t.vmapVisible&&this.setLayerOpacity(t,e))}async setVisible(t,e){if(!t)return;const s=await this._getLayerById(t);this.setVisibleByLayer(s,e)}setVisibleByLayer(t,e){t&&(t.vmapVisible=e,void 0===t.vmapOpacity&&(t.vmapOpacity=1),this.setLayerOpacity(t,e?t.vmapOpacity:0))}setLayerOpacity(t,e){if(!t)return;const s="number"==typeof e?e:e.opacity??1,i="number"==typeof e?e:e.fillOpacity??s,o=(t,e)=>{if(!(e in r))return!1;const s=r[e];return"function"==typeof s&&t instanceof s};var a;o(a=t,"GeoJSON")||o(a,"LayerGroup")?t.eachLayer((t=>this.setLayerOpacity(t,e))):(t=>o(t,"Path"))(t)?t.setStyle({opacity:s,fillOpacity:i}):((t=>o(t,"Marker"))(t)||"setOpacity"in t)&&t.setOpacity(s)}async ensureGroup(t,e,s){await this._ensureGroup(t,e)}async _ensureGroup(t,e){let s=await this._getLayerGroupById(t);return s||(s=r.layerGroup(),s._groupId=t,s.visible=!0,s.addTo(this.map),this.layers.push(s)),this.setGroupVisible(t,void 0===e||e),s}async _getLayerGroupById(t){if(!this.map)return null;let e=this.layers.find((e=>e instanceof r.LayerGroup&&e._groupId===t));return e||(e=this.hiddenLayerGroups.find((e=>e._groupId===t)),e)?e:null}async setGroupVisible(t,e){const s=await this._getLayerGroupById(t);if(s){if(s.visible===e)return;!1===s.visible?(s.addTo(this.map),this.hiddenLayerGroups=this.hiddenLayerGroups.filter((e=>e._groupId!==t)),s.visible=e):!0===s.visible&&(this.map.removeLayer(s),s.visible=e,this.hiddenLayerGroups.push(s))}}async updateWKTLayer(t,e){if(!(t instanceof r.GeoJSON))return;let s=null;if(e.wkt)s=await this.wktToGeoJSON(e.wkt);else if(e.url)try{const t=await fetch(e.url);if(!t.ok)throw new Error(`Failed to fetch WKT: ${t.status}`);const i=await t.text();s=await this.wktToGeoJSON(i)}catch(t){return void o("Failed to load WKT from URL:",t)}if(s){t.clearLayers();const i=t;i.options.style=this.createLeafletStyle(e.style),i.options.pointToLayer=(t,s)=>this.createLeafletPoint(t,s,e.style),i.options.onEachFeature=(t,s)=>this.bindLeafletPopup(t,s,e.style),i.addData(s)}}async createWKTLayer(t){let e=null;const s={type:"FeatureCollection",features:[]};if(t.wkt)e=await this.wktToGeoJSON(t.wkt);else if(t.url)try{const s=await fetch(t.url);if(!s.ok)throw new Error(`Failed to fetch WKT: ${s.status}`);const i=await s.text();e=await this.wktToGeoJSON(i)}catch(t){o("Failed to load WKT from URL:",t),e=s}else e=s;a("[Leaflet WKT] Creating layer with GeoJSON data:",e),a("[Leaflet WKT] Config:",t);let i={};if(t.geostylerStyle)i=await this.createGeostylerLeafletOptions(t.geostylerStyle);else{const e=t.style?{...n,...t.style}:n;i={style:this.createLeafletStyle(e),pointToLayer:(t,s)=>this.createLeafletPoint(t,s,e),onEachFeature:(t,s)=>this.bindLeafletPopup(t,s,e)}}a("[Leaflet WKT] Layer options:",i);const c=r.geoJSON(e,i);return a("[Leaflet WKT] Created layer:",c),"function"==typeof c.getBounds&&a("[Leaflet WKT] Layer bounds:",c.getBounds()),c}async wktToGeoJSON(t){try{const e=u.wellknown.parse(t);if(!e)throw new Error("Failed to parse WKT - returned null");const s={type:"Feature",geometry:e,properties:{}};return a("[Leaflet WKT] Input WKT:",t),a("[Leaflet WKT] Generated GeoJSON:",JSON.stringify(s,null,2)),{type:"FeatureCollection",features:[s]}}catch(e){return o("[Leaflet WKT] Failed to parse WKT:",t,e),{type:"FeatureCollection",features:[]}}}async createGeoTIFFLayer(t){if(!t.url)throw new Error("GeoTIFF layer requires a URL");try{const e=new d({url:t.url,tileSize:256,colorMap:t.colorMap,valueRange:t.valueRange,nodata:t.nodata,resolution:t.resolution,resampleMethod:t.resampleMethod,viewProjection:this.map.options.crs.code});return void 0!==t.opacity&&e.setOpacity?.(t.opacity),void 0!==t.zIndex&&e.setZIndex?.(t.zIndex),e}catch(t){return o("Failed to create GeoTIFF layer:",t),r.layerGroup([])}}async updateGeoTIFFLayer(t,e){if(!e.url)throw new Error("GeoTIFF update requires a URL");if(!t)return;if(!(t instanceof d))return;const s=e;await t.updateSource({url:e.url,colorMap:e.colorMap,valueRange:e.valueRange,nodata:e.nodata,resolution:s.resolution,resampleMethod:s.resampleMethod})}async createWCSLayer(t){if(!t.url)throw new Error("WCS layer requires a URL");if(!t.coverageName)throw new Error("WCS layer requires a coverageName");try{const e={url:t.url,coverageName:t.coverageName,version:t.version??"2.0.1",format:t.format??"image/tiff",projection:t.projection??"EPSG:4326",params:t.params};t.tileSize&&(e.tileSize=t.tileSize),void 0!==t.minZoom&&(e.minZoom=t.minZoom),void 0!==t.maxZoom&&(e.maxZoom=t.maxZoom);const s=new w(e);return void 0!==t.opacity&&s.setOpacity?.(t.opacity),void 0!==t.zIndex&&s.setZIndex?.(t.zIndex),s}catch(t){return o("[Leaflet WCS] Failed to create WCS layer:",t),r.layerGroup([])}}async updateWCSLayer(t,e){if(t&&t instanceof w){const s={};e.url&&(s.url=e.url),e.coverageName&&(s.coverageName=e.coverageName),e.version&&(s.version=e.version),e.format&&(s.format=e.format),e.projection&&(s.projection=e.projection),e.params&&(s.params=e.params),t.updateOptions(s)}}async createGeostylerLeafletOptions(t){const e=(t,e)=>null==t||"object"==typeof t&&t.name?e:t;return{style:s=>{const i=s?.geometry?.type;let r={};if(t.rules)for(const s of t.rules)if(s.symbolizers)for(const t of s.symbolizers)switch(t.kind){case"Fill":if("Polygon"===i||"MultiPolygon"===i){const s=e(t.color,"rgba(0,100,255,0.3)"),i=e(t.opacity,.3),o=e(t.outlineColor,"rgba(0,100,255,1)"),a=e(t.outlineWidth,1);r={...r,fillColor:s,fillOpacity:i,color:o,weight:a}}break;case"Line":const s=e(t.color,"rgba(0,100,255,1)"),o=e(t.width,2),a=t.dasharray&&Array.isArray(t.dasharray)?t.dasharray.map((t=>e(t,0))).join(","):void 0;r={...r,color:s,weight:o,dashArray:a}}return r},pointToLayer:(s,i)=>{if(t.rules)for(const s of t.rules)if(s.symbolizers)for(const t of s.symbolizers)switch(t.kind){case"Mark":const s=e(t.color,"rgba(0,100,255,1)"),o=e(t.radius,6),a=e(t.strokeColor,"rgba(0,100,255,1)"),n=e(t.strokeWidth,2);return r.circleMarker(i,{radius:o,fillColor:s,fillOpacity:1,color:a,weight:n});case"Icon":const c=e(t.image),l=e(t.size,32);if(c&&"string"==typeof c){const t=r.icon({iconUrl:c,iconSize:[l,l],iconAnchor:[l/2,l]});return r.marker(i,{icon:t})}}return r.circleMarker(i,{radius:6,fillColor:"rgba(0,100,255,1)",fillOpacity:1,color:"rgba(0,100,255,1)",weight:2})},onEachFeature:(s,i)=>{if(t.rules)for(const r of t.rules)if(r.symbolizers)for(const t of r.symbolizers)if("Text"===t.kind){const r=t.label;if(r&&"string"==typeof r&&s.properties&&s.properties[r]){const o=String(s.properties[r]),a=e(t.color,"#000000"),n=e(t.size,12);i.bindTooltip(`<div style="color: ${a}; font-size: ${n}px; font-family: Arial, sans-serif;">${o}</div>`,{permanent:!0,direction:"center",className:"leaflet-tooltip-custom"})}}}}}createLeafletStyle(t){return e=>{const s=e?.geometry?.type,i=t?.fillColor??"rgba(0,100,255,0.3)",r=t?.fillOpacity??.3,o=t?.strokeColor??"rgba(0,100,255,1)",a=t?.strokeOpacity??1,n=t?.strokeWidth??2;return"Polygon"===s||"MultiPolygon"===s?{fillColor:i,fillOpacity:r,color:o,opacity:a,weight:n,dashArray:t?.strokeDashArray?t.strokeDashArray.join(","):void 0}:"LineString"===s||"MultiLineString"===s?{color:o,opacity:a,weight:n,dashArray:t?.strokeDashArray?t.strokeDashArray.join(","):void 0}:{}}}createLeafletPoint(t,e,s){let i={...s??{}};if(s?.styleFunction){const e=s.styleFunction(t);e&&(i={...s,...e})}if(i?.iconUrl){const t=i.iconSize||[32,32],s=r.icon({iconUrl:i.iconUrl,iconSize:t,iconAnchor:i.iconAnchor||[t[0]/2,t[1]]});return r.marker(e,{icon:s})}{const t=i?.pointColor??"rgba(0,100,255,1)",s=i?.pointOpacity??1;return r.circleMarker(e,{radius:i?.pointRadius??6,fillColor:t,fillOpacity:s,color:i?.strokeColor??"rgba(0,100,255,1)",opacity:i?.strokeOpacity??1,weight:i?.strokeWidth??2})}}bindLeafletPopup(t,e,s){if(s?.textProperty&&t.properties&&t.properties[s.textProperty]){const i=String(t.properties[s.textProperty]);e.bindTooltip(`<div style="color: ${s?.textColor??"#000000"}; font-size: ${s?.textSize??12}px; font-family: Arial, sans-serif;">${i}</div>`,{permanent:!0,direction:"center",className:"leaflet-tooltip-custom"})}}async createWFSLayer(t){const e=await this.fetchWFSFromUrl(t);let s={};if(t.geostylerStyle)s=await this.createGeostylerLeafletOptions(t.geostylerStyle);else{const e=t.style?{...n,...t.style}:n;s={style:this.createLeafletStyle(e),pointToLayer:(t,s)=>this.createLeafletPoint(t,s,e),onEachFeature:(t,s)=>this.bindLeafletPopup(t,s,e)}}return r.geoJSON(e,s)}async updateWFSLayer(t,e){const s=await this.fetchWFSFromUrl(e);t.clearLayers(),t.addData(s)}async fetchWFSFromUrl(t){const e={service:"WFS",request:"GetFeature",version:t.version??"1.1.0",typeName:t.typeName,outputFormat:t.outputFormat??"application/json",srsName:t.srsName??"EPSG:4326",...t.params??{}},s=this.appendParams(t.url,e),i=await fetch(s);if(!i.ok)throw new Error(`WFS request failed (${i.status} ${i.statusText})`);const r=(t.outputFormat??"application/json").toLowerCase();if(r.includes("json")||r.includes("geojson")||"application/json"===r)return await i.json();if(r.includes("gml")||r.includes("xml")){const t=await i.text(),e=new f;return await e.parse(t)}return await i.json()}appendParams(t,e){const s=new URLSearchParams;return Object.entries(e).forEach((([t,e])=>{null!=e&&s.set(t,String(e))})),s.toString()?`${t}${t.includes("?")?"&":"?"}${s.toString()}`:t}getMap(){return this.map}}export{g as LeafletProvider}
|