@xingm/vmap-cesium-toolbar 0.0.1-alpha.3 → 0.0.1-alpha.4

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/index.umd.js CHANGED
@@ -193,5 +193,5 @@
193
193
  `;const N=document.createElement("span");N.textContent=h.name,N.style.cssText=`
194
194
  font-size: 14px;
195
195
  color: #fff;
196
- `,c.appendChild(d),c.appendChild(w),c.appendChild(N),c.addEventListener("mouseenter",()=>{c.style.backgroundColor="#023C61"}),c.addEventListener("mouseleave",()=>{c.style.backgroundColor="transparent"}),c.addEventListener("click",()=>{const g=this.isNoFlyZoneChecked;g?(d.style.background="transparent",d.innerHTML=""):(d.style.background="#023C61",d.innerHTML="✓",d.style.color="#ffffff",d.style.fontWeight="bold",d.style.fontSize="12px"),this.isNoFlyZoneChecked=!this.isNoFlyZoneChecked,t?.(!g,this)}),u.appendChild(c)}),s.appendChild(a),s.appendChild(u),this.toolbarElement.insertBefore(s,e),this.isNoFlyZoneVisible||setTimeout(()=>{this.showNoFlyZones().catch(h=>{console.error("加载禁飞区失败:",h)})},100);const b=()=>{s.remove()};s.addEventListener("mouseleave",b)}switchMapType(e){const t=this.mapTypes.find(s=>s.id===e);if(!t)return;if(this.viewer.camera.position.clone(),this.viewer.camera.heading,this.viewer.camera.pitch,this.viewer.camera.roll,this.viewer.camera.positionCartographic.height,this.currentGeoWTFS){try{typeof this.currentGeoWTFS.destroy=="function"?this.currentGeoWTFS.destroy():typeof this.currentGeoWTFS.remove=="function"&&this.currentGeoWTFS.remove()}catch(s){console.warn("清理三维地名服务失败:",s)}this.currentGeoWTFS=null}this.viewer.imageryLayers.removeAll(),t.provider(this.TD_Token).forEach(s=>{this.viewer.imageryLayers.addImageryProvider(s)}),this.currentMapType=e}resetLocation(){if(!this.initialCenter){console.warn("未设置初始中心点,无法执行复位操作");return}this.viewer.camera.flyTo({destination:i.Cartesian3.fromDegrees(this.initialCenter.longitude,this.initialCenter.latitude,this.initialCenter.height),duration:1})}getCurrentZoomLevel(){const e=this.viewer.camera.positionCartographic.height;return L(e)}setZoomLevel(e){try{const t=Math.max(1,Math.min(18,e)),n=O(t);if(!isFinite(n)||isNaN(n)||n<=0){console.warn(`无效的目标高度: ${n},使用默认层级 ${t}`);return}let s;try{s=this.viewer.camera.positionCartographic.clone(),(!isFinite(s.longitude)||!isFinite(s.latitude))&&(s=i.Cartographic.fromDegrees(120.2052342,30.2489634))}catch(a){console.warn("获取当前相机位置失败,使用默认位置",a),s=i.Cartographic.fromDegrees(120.2052342,30.2489634)}this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(s.longitude,s.latitude,n),orientation:{heading:this.viewer.camera.heading,pitch:this.viewer.camera.pitch,roll:this.viewer.camera.roll}})}catch(t){console.error("设置地图层级失败:",t);try{const n=O(10),s=i.Cartographic.fromDegrees(120.2052342,30.2489634);this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(s.longitude,s.latitude,n)})}catch(n){console.error("恢复地图层级失败:",n)}}}zoomIn(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e>=18)return;const n=e+1;this.setZoomLevel(n);const s=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomIn&&this.zoomCallback.onZoomIn(t,s)}zoomOut(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e<=1)return;const n=e-1;this.setZoomLevel(n);const s=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomOut&&this.zoomCallback.onZoomOut(t,s)}toggleFullscreen(){this.isFullscreen?this.exitFullscreen():this.enterFullscreen()}enterFullscreen(){const e=this.viewer.container;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen(),this.isFullscreen=!0;const t=()=>{!document.fullscreenElement&&!document.webkitFullscreenElement&&!document.msFullscreenElement&&(this.isFullscreen=!1,document.removeEventListener("fullscreenchange",t),document.removeEventListener("webkitfullscreenchange",t),document.removeEventListener("msfullscreenchange",t))};document.addEventListener("fullscreenchange",t),document.addEventListener("webkitfullscreenchange",t),document.addEventListener("msfullscreenchange",t)}exitFullscreen(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen(),this.isFullscreen=!1}async showNoFlyZones(){if(!this.isNoFlyZoneVisible)try{const e=await I();this.hideNoFlyZones(),e.forEach(t=>{const s=t.feature.geometry.coordinates[0].map(r=>{const[o,u]=r;return i.Cartesian3.fromDegrees(o,u,0)}),a=this.viewer.entities.add({name:t.name,polygon:this.createNoFlyZonePolygonOptions(s),description:`机场禁飞区: ${t.name}`});a.disableDepthTestDistance=Number.POSITIVE_INFINITY,this.noFlyZoneEntities.push(a)}),this.isNoFlyZoneVisible=!0,console.log(`已加载 ${e.length} 个机场禁飞区`)}catch(e){console.error("加载机场禁飞区失败:",e)}}hideNoFlyZones(){this.noFlyZoneEntities.forEach(e=>{this.viewer.entities.remove(e)}),this.noFlyZoneEntities=[],this.isNoFlyZoneVisible=!1}createNoFlyZonePolygonOptions(e){const t=this.viewer.scene.mode===i.SceneMode.SCENE3D;return{hierarchy:new i.PolygonHierarchy(e),material:i.Color.RED.withAlpha(.3),outline:!0,outlineColor:i.Color.RED,outlineWidth:2,perPositionHeight:t,closeTop:!0,closeBottom:!0,classificationType:i.ClassificationType.BOTH,heightReference:t?i.HeightReference.NONE:i.HeightReference.CLAMP_TO_GROUND,height:t?0:void 0,extrudedHeight:t?this.noFlyZoneExtrudedHeight:void 0}}toggleNoFlyZones(){return this.isNoFlyZoneVisible?(this.hideNoFlyZones(),Promise.resolve()):this.showNoFlyZones()}getNoFlyZoneVisible(){return this.isNoFlyZoneVisible}async autoLoadNoFlyZones(){this.isNoFlyZoneVisible||setTimeout(()=>{this.showNoFlyZones().catch(e=>{console.error("自动加载禁飞区失败:",e)})},500)}destroy(){if(this.hideNoFlyZones(),this.currentGeoWTFS){try{typeof this.currentGeoWTFS.destroy=="function"?this.currentGeoWTFS.destroy():typeof this.currentGeoWTFS.remove=="function"&&this.currentGeoWTFS.remove()}catch(e){console.warn("销毁三维地名服务失败:",e)}this.currentGeoWTFS=null}this.toolbarElement&&this.toolbarElement.parentNode&&this.toolbarElement.parentNode.removeChild(this.toolbarElement),this.drawHelper.destroy()}}async function j(l,e,t={longitude:120.2052342,latitude:30.2489634,height:1e3,pitch:-45,heading:0}){v.Ion.defaultAccessToken="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3M2M3NWU1Ni0xZmJkLTRkNjAtOTk4NC0wZDZhNWFiOWJlZDEiLCJpZCI6MzMxNTg1LCJpYXQiOjE3NTUyMjQ2MzB9.WBUG7ctHKtOrnay1ng8JNfaNgngbkNgOmRXP59OJ7ME";const n=new v.Viewer(l,{animation:!1,baseLayerPicker:!1,fullscreenButton:!1,geocoder:!1,homeButton:!1,infoBox:!1,sceneModePicker:!1,selectionIndicator:!1,timeline:!1,navigationHelpButton:!1,navigationInstructionsInitiallyVisible:!1,...e});n.cesiumWidget.creditContainer.style.display="none",n.scene.postProcessStages.fxaa.enabled=!1,n.scene.globe.depthTestAgainstTerrain=!0,!e.terrainProvider&&!e.terrain&&(n.terrainProvider=await v.createWorldTerrainAsync());const s=e.token||A();return e.mapType==="tiandi"&&(n.imageryLayers.removeAll(),p.find(a=>a.id==="imagery")?.provider(s).forEach(a=>{n.imageryLayers.addImageryProvider(a)})),t&&!e.isFly&&n.camera.setView({destination:i.Cartesian3.fromDegrees(t.longitude,t.latitude,t.height),orientation:{heading:i.Math.toRadians(t.heading||0),pitch:i.Math.toRadians(t.pitch||0)}}),t&&e.isFly&&n.camera.flyTo({destination:i.Cartesian3.fromDegrees(t.longitude,t.latitude,t.height),orientation:{heading:i.Math.toRadians(t.heading||0),pitch:i.Math.toRadians(t.pitch||0)}}),{viewer:n,initialCenter:t}}const E={CesiumMapToolbar:z,DrawHelper:D,initCesium:j,initCesiumMap:j};f.CesiumMapToolbar=z,f.DrawHelper=D,f.default=E,f.initCesium=j,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
196
+ `,c.appendChild(d),c.appendChild(w),c.appendChild(N),c.addEventListener("mouseenter",()=>{c.style.backgroundColor="#023C61"}),c.addEventListener("mouseleave",()=>{c.style.backgroundColor="transparent"}),c.addEventListener("click",()=>{const g=this.isNoFlyZoneChecked;g?(d.style.background="transparent",d.innerHTML=""):(d.style.background="#023C61",d.innerHTML="✓",d.style.color="#ffffff",d.style.fontWeight="bold",d.style.fontSize="12px"),this.isNoFlyZoneChecked=!this.isNoFlyZoneChecked,t?.(!g,this)}),u.appendChild(c)}),s.appendChild(a),s.appendChild(u),this.toolbarElement.insertBefore(s,e),!this.isNoFlyZoneVisible&&this.isNoFlyZoneChecked&&setTimeout(()=>{this.showNoFlyZones().catch(h=>{console.error("加载禁飞区失败:",h)})},100);const b=()=>{s.remove()};s.addEventListener("mouseleave",b)}switchMapType(e){const t=this.mapTypes.find(s=>s.id===e);if(!t)return;if(this.viewer.camera.position.clone(),this.viewer.camera.heading,this.viewer.camera.pitch,this.viewer.camera.roll,this.viewer.camera.positionCartographic.height,this.currentGeoWTFS){try{typeof this.currentGeoWTFS.destroy=="function"?this.currentGeoWTFS.destroy():typeof this.currentGeoWTFS.remove=="function"&&this.currentGeoWTFS.remove()}catch(s){console.warn("清理三维地名服务失败:",s)}this.currentGeoWTFS=null}this.viewer.imageryLayers.removeAll(),t.provider(this.TD_Token).forEach(s=>{this.viewer.imageryLayers.addImageryProvider(s)}),this.currentMapType=e}resetLocation(){if(!this.initialCenter){console.warn("未设置初始中心点,无法执行复位操作");return}this.viewer.camera.flyTo({destination:i.Cartesian3.fromDegrees(this.initialCenter.longitude,this.initialCenter.latitude,this.initialCenter.height),duration:1})}getCurrentZoomLevel(){const e=this.viewer.camera.positionCartographic.height;return L(e)}setZoomLevel(e){try{const t=Math.max(1,Math.min(18,e)),n=O(t);if(!isFinite(n)||isNaN(n)||n<=0){console.warn(`无效的目标高度: ${n},使用默认层级 ${t}`);return}let s;try{s=this.viewer.camera.positionCartographic.clone(),(!isFinite(s.longitude)||!isFinite(s.latitude))&&(s=i.Cartographic.fromDegrees(120.2052342,30.2489634))}catch(a){console.warn("获取当前相机位置失败,使用默认位置",a),s=i.Cartographic.fromDegrees(120.2052342,30.2489634)}this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(s.longitude,s.latitude,n),orientation:{heading:this.viewer.camera.heading,pitch:this.viewer.camera.pitch,roll:this.viewer.camera.roll}})}catch(t){console.error("设置地图层级失败:",t);try{const n=O(10),s=i.Cartographic.fromDegrees(120.2052342,30.2489634);this.viewer.camera.setView({destination:i.Cartesian3.fromRadians(s.longitude,s.latitude,n)})}catch(n){console.error("恢复地图层级失败:",n)}}}zoomIn(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e>=18)return;const n=e+1;this.setZoomLevel(n);const s=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomIn&&this.zoomCallback.onZoomIn(t,s)}zoomOut(){const e=this.getCurrentZoomLevel(),t=this.viewer.camera.positionCartographic.height;if(e<=1)return;const n=e-1;this.setZoomLevel(n);const s=this.viewer.camera.positionCartographic.height;this.zoomCallback?.onZoomOut&&this.zoomCallback.onZoomOut(t,s)}toggleFullscreen(){this.isFullscreen?this.exitFullscreen():this.enterFullscreen()}enterFullscreen(){const e=this.viewer.container;e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen(),this.isFullscreen=!0;const t=()=>{!document.fullscreenElement&&!document.webkitFullscreenElement&&!document.msFullscreenElement&&(this.isFullscreen=!1,document.removeEventListener("fullscreenchange",t),document.removeEventListener("webkitfullscreenchange",t),document.removeEventListener("msfullscreenchange",t))};document.addEventListener("fullscreenchange",t),document.addEventListener("webkitfullscreenchange",t),document.addEventListener("msfullscreenchange",t)}exitFullscreen(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen(),this.isFullscreen=!1}async showNoFlyZones(){if(!this.isNoFlyZoneVisible)try{const e=await I();this.hideNoFlyZones(),e.forEach(t=>{const s=t.feature.geometry.coordinates[0].map(r=>{const[o,u]=r;return i.Cartesian3.fromDegrees(o,u,0)}),a=this.viewer.entities.add({name:t.name,polygon:this.createNoFlyZonePolygonOptions(s),description:`机场禁飞区: ${t.name}`});a.disableDepthTestDistance=Number.POSITIVE_INFINITY,this.noFlyZoneEntities.push(a)}),this.isNoFlyZoneVisible=!0,console.log(`已加载 ${e.length} 个机场禁飞区`)}catch(e){console.error("加载机场禁飞区失败:",e)}}hideNoFlyZones(){this.noFlyZoneEntities.forEach(e=>{this.viewer.entities.remove(e)}),this.noFlyZoneEntities=[],this.isNoFlyZoneVisible=!1}createNoFlyZonePolygonOptions(e){const t=this.viewer.scene.mode===i.SceneMode.SCENE3D;return{hierarchy:new i.PolygonHierarchy(e),material:i.Color.RED.withAlpha(.3),outline:!0,outlineColor:i.Color.RED,outlineWidth:2,perPositionHeight:t,closeTop:!0,closeBottom:!0,classificationType:i.ClassificationType.BOTH,heightReference:t?i.HeightReference.NONE:i.HeightReference.CLAMP_TO_GROUND,height:t?0:void 0,extrudedHeight:t?this.noFlyZoneExtrudedHeight:void 0}}toggleNoFlyZones(){return this.isNoFlyZoneVisible?(this.hideNoFlyZones(),Promise.resolve()):this.showNoFlyZones()}getNoFlyZoneVisible(){return this.isNoFlyZoneVisible}async autoLoadNoFlyZones(){this.isNoFlyZoneChecked&&!this.isNoFlyZoneVisible&&setTimeout(()=>{this.showNoFlyZones().catch(t=>{console.error("自动加载禁飞区失败:",t)})},500)}destroy(){if(this.hideNoFlyZones(),this.currentGeoWTFS){try{typeof this.currentGeoWTFS.destroy=="function"?this.currentGeoWTFS.destroy():typeof this.currentGeoWTFS.remove=="function"&&this.currentGeoWTFS.remove()}catch(e){console.warn("销毁三维地名服务失败:",e)}this.currentGeoWTFS=null}this.toolbarElement&&this.toolbarElement.parentNode&&this.toolbarElement.parentNode.removeChild(this.toolbarElement),this.drawHelper.destroy()}}async function j(l,e,t={longitude:120.2052342,latitude:30.2489634,height:1e3,pitch:-45,heading:0},n="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3M2M3NWU1Ni0xZmJkLTRkNjAtOTk4NC0wZDZhNWFiOWJlZDEiLCJpZCI6MzMxNTg1LCJpYXQiOjE3NTUyMjQ2MzB9.WBUG7ctHKtOrnay1ng8JNfaNgngbkNgOmRXP59OJ7ME"){v.Ion.defaultAccessToken=n;const s=new v.Viewer(l,{animation:!1,baseLayerPicker:!1,fullscreenButton:!1,geocoder:!1,homeButton:!1,infoBox:!1,sceneModePicker:!1,selectionIndicator:!1,timeline:!1,navigationHelpButton:!1,navigationInstructionsInitiallyVisible:!1,...e});s.cesiumWidget.creditContainer.style.display="none",s.scene.postProcessStages.fxaa.enabled=!1,s.scene.globe.depthTestAgainstTerrain=!0,!e.terrainProvider&&!e.terrain&&(s.terrainProvider=await v.createWorldTerrainAsync());const a=e.token||A();return e.mapType==="tiandi"&&(s.imageryLayers.removeAll(),p.find(r=>r.id==="imagery")?.provider(a).forEach(r=>{s.imageryLayers.addImageryProvider(r)})),t&&!e.isFly&&s.camera.setView({destination:i.Cartesian3.fromDegrees(t.longitude,t.latitude,t.height),orientation:{heading:i.Math.toRadians(t.heading||0),pitch:i.Math.toRadians(t.pitch||0)}}),t&&e.isFly&&s.camera.flyTo({destination:i.Cartesian3.fromDegrees(t.longitude,t.latitude,t.height),orientation:{heading:i.Math.toRadians(t.heading||0),pitch:i.Math.toRadians(t.pitch||0)}}),{viewer:s,initialCenter:t}}const E={CesiumMapToolbar:z,DrawHelper:D,initCesium:j,initCesiumMap:j};f.CesiumMapToolbar=z,f.DrawHelper=D,f.default=E,f.initCesium=j,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
197
197
  //# sourceMappingURL=index.umd.js.map