| | |
| | | import server from "./server"; |
| | | |
| | | const InitMap = { |
| | | earthCtrl: null, |
| | | Viewer: null, |
| | | //地图初始化 |
| | | init3DMap() { |
| | | //设置月球坐标系 |
| | | SmartEarth.Cesium.Ellipsoid.WGS84 = new SmartEarth.Cesium.Ellipsoid( |
| | | 1737400.0, |
| | | 1737400.0, |
| | | 1737400.0 |
| | | ); |
| | | //页面初始化 |
| | | this.earthCtrl = new SmartEarth.EarthCtrl("cesiumContainer", { |
| | | licenseServer: "https://cim.smartearth.cn/", |
| | | StaticFileBaseUrl: "/CIMSDK/" |
| | | }); |
| | | earthCtrl: null, |
| | | Viewer: null, |
| | | //地图初始化 |
| | | init3DMap() { |
| | | //设置月球坐标系 |
| | | SmartEarth.Cesium.Ellipsoid.WGS84 = new SmartEarth.Cesium.Ellipsoid( |
| | | 1737400.0, |
| | | 1737400.0, |
| | | 1737400.0 |
| | | ); |
| | | //页面初始化 |
| | | this.earthCtrl = new SmartEarth.EarthCtrl("cesiumContainer", { |
| | | licenseServer: "https://cim.smartearth.cn/", |
| | | StaticFileBaseUrl: "/CIMSDK/", |
| | | }); |
| | | // this.earthCtrl.environment.disableAllEffect(); |
| | | |
| | | this.Viewer = this.earthCtrl._Viewer; |
| | | window.earthCtrl = this.earthCtrl; |
| | | window.Viewer = this.earthCtrl._Viewer; |
| | | this.Viewer = this.earthCtrl._Viewer; |
| | | this.Viewer.scene.skyAtmosphere.show = false; |
| | | window.earthCtrl = this.earthCtrl; |
| | | window.Viewer = this.earthCtrl._Viewer; |
| | | |
| | | Viewer.imageryLayers.removeAll(); |
| | | Viewer.imageryLayers.removeAll(); |
| | | |
| | | Viewer.scene.globe.showGroundAtmosphere = false; |
| | | Viewer.scene.globe.showGroundAtmosphere = false; |
| | | |
| | | // var terrain = new SmartEarth.Cesium.CesiumTerrainProvider({ |
| | | // url: config.moonTerrain, |
| | | // tilingScheme: new SmartEarth.Cesium.GeographicTilingScheme({ |
| | | // ellipsoid: SmartEarth.Cesium.Ellipsoid.MOON, |
| | | // }), |
| | | // }); |
| | | // Viewer.terrainProvider = terrain; |
| | | // Viewer.scene.globe.terrainExaggeration = 5; |
| | | // server.AddWmtesLayer(config.moonWmts); |
| | | // var param = { |
| | | // name: labelName, |
| | | // id: earthCtrl.factory.createUUID(), |
| | | // text: "文字工具", |
| | | // font: '50pt monospace', |
| | | // outlineWidth: 2, |
| | | // fillColor: SmartEarth.Cesium.Color.RED, |
| | | // lon: 47.5087, |
| | | // lat: 23.6963, |
| | | // alt: 10 |
| | | // }; |
| | | // labelEntity = earthCtrl.factory.createLabel(param); |
| | | server.AddTmsLayer(config.moonTms); |
| | | // var terrain = new SmartEarth.Cesium.CesiumTerrainProvider({ |
| | | // url: config.moonTerrain, |
| | | // tilingScheme: new SmartEarth.Cesium.GeographicTilingScheme({ |
| | | // ellipsoid: SmartEarth.Cesium.Ellipsoid.MOON, |
| | | // }), |
| | | // }); |
| | | // Viewer.terrainProvider = terrain; |
| | | // Viewer.scene.globe.terrainExaggeration = 5; |
| | | // server.AddWmtesLayer(config.moonWmts); |
| | | // var param = { |
| | | // name: labelName, |
| | | // id: earthCtrl.factory.createUUID(), |
| | | // text: "文字工具", |
| | | // font: '50pt monospace', |
| | | // outlineWidth: 2, |
| | | // fillColor: SmartEarth.Cesium.Color.RED, |
| | | // lon: 47.5087, |
| | | // lat: 23.6963, |
| | | // alt: 10 |
| | | // }; |
| | | // labelEntity = earthCtrl.factory.createLabel(param); |
| | | server.AddTmsLayer(config.moonTms); |
| | | |
| | | // server.AddTmsLayer('http://localhost:8080/abc'); |
| | | // server.AddTmsLayer('http://localhost:8080/abc'); |
| | | |
| | | // earthCtrl.camera.flyTo(47.5087, 23.6963, 300, 9.5, -45, 0.0, 5); |
| | | // earthCtrl.camera.flyTo(47.5087, 23.6963, 300, 9.5, -45, 0.0, 5); |
| | | |
| | | // //添加鼠标左击事件 |
| | | // this.addMouseLeftClickEvents(); |
| | | // this.addMouseMouseMoveEvents(); |
| | | }, |
| | | //鼠标左键点击事件添加 |
| | | addMouseLeftClickEvents() { |
| | | if (window.handleLeftClick) { |
| | | window.handleLeftClick.removeInputAction( |
| | | Cesium.ScreenSpaceEventType.LEFT_CLICK |
| | | ); //移除事件 |
| | | window.handleLeftClick = null; |
| | | } |
| | | window.handleLeftClick = new Cesium.ScreenSpaceEventHandler( |
| | | window.Viewer.scene.canvas |
| | | ); |
| | | window.handleLeftClick.setInputAction(function (event) { |
| | | let cartesian = window.Viewer.camera.pickEllipsoid(event.position); |
| | | if (cartesian) { |
| | | let cartographic = Cesium.Cartographic.fromCartesian(cartesian); |
| | | let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度 |
| | | let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度 |
| | | let alt = cartographic.height; // 高度,椭球面height永远等于0 |
| | | let coordinate = { |
| | | longitude: Number(lng.toFixed(6)), |
| | | latitude: Number(lat.toFixed(6)), |
| | | altitude: Number(alt.toFixed(2)), |
| | | // //添加鼠标左击事件 |
| | | // this.addMouseLeftClickEvents(); |
| | | // this.addMouseMouseMoveEvents(); |
| | | }, |
| | | //鼠标左键点击事件添加 |
| | | addMouseLeftClickEvents() { |
| | | if (window.handleLeftClick) { |
| | | window.handleLeftClick.removeInputAction( |
| | | Cesium.ScreenSpaceEventType.LEFT_CLICK |
| | | ); //移除事件 |
| | | window.handleLeftClick = null; |
| | | } |
| | | window.handleLeftClick = new Cesium.ScreenSpaceEventHandler( |
| | | window.Viewer.scene.canvas |
| | | ); |
| | | window.handleLeftClick.setInputAction(function (event) { |
| | | let cartesian = window.Viewer.camera.pickEllipsoid(event.position); |
| | | if (cartesian) { |
| | | let cartographic = Cesium.Cartographic.fromCartesian(cartesian); |
| | | let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度 |
| | | let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度 |
| | | let alt = cartographic.height; // 高度,椭球面height永远等于0 |
| | | let coordinate = { |
| | | longitude: Number(lng.toFixed(6)), |
| | | latitude: Number(lat.toFixed(6)), |
| | | altitude: Number(alt.toFixed(2)), |
| | | }; |
| | | } |
| | | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); |
| | | }, |
| | | |
| | | }; |
| | | addMouseMouseMoveEvents() { |
| | | if (window.handleMouseMove) { |
| | | window.handleMouseMove.removeInputAction( |
| | | Cesium.ScreenSpaceEventType.MOUSE_MOVE |
| | | ); //移除事件 |
| | | window.handleMouseMove = null; |
| | | } |
| | | window.handleMouseMove = new Cesium.ScreenSpaceEventHandler( |
| | | window.Viewer.scene.canvas |
| | | ); |
| | | window.handleMouseMove.setInputAction(function (movement) { |
| | | let cartesian = window.Viewer.camera.pickEllipsoid( |
| | | movement.endPosition, |
| | | window.Viewer.scene.globe.ellipsoid |
| | | ); |
| | | if (cartesian) { |
| | | //将笛卡尔坐标转换为地理坐标 |
| | | var cartographic = |
| | | window.Viewer.scene.globe.ellipsoid.cartesianToCartographic( |
| | | cartesian |
| | | ); |
| | | //将弧度转为度的十进制度表示 |
| | | var lng = Cesium.Math.toDegrees(cartographic.longitude); |
| | | var lat = Cesium.Math.toDegrees(cartographic.latitude); |
| | | //获取相机高度 |
| | | var alt = Math.ceil(window.Viewer.camera.positionCartographic.height); |
| | | |
| | | } |
| | | let coordinate = { |
| | | longitude: Number(lng.toFixed(6)), |
| | | latitude: Number(lat.toFixed(6)), |
| | | altitude: Number(alt.toFixed(2)), |
| | | type: "MOUSE_MOVE", |
| | | }; |
| | | window.addMouseEvents(coordinate); |
| | | } |
| | | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); |
| | | }, |
| | | |
| | | }, Cesium.ScreenSpaceEventType.LEFT_CLICK); |
| | | }, |
| | | //CGCS2000转月球坐标---待验证 |
| | | Cjcs2000ToMoon() { |
| | | // 定义待转换的经纬度坐标和高度 |
| | | const longitude = 110.5; |
| | | const latitude = 34.5; |
| | | const height = 0; |
| | | |
| | | addMouseMouseMoveEvents() { |
| | | if (window.handleMouseMove) { |
| | | window.handleMouseMove.removeInputAction( |
| | | Cesium.ScreenSpaceEventType.MOUSE_MOVE |
| | | ); //移除事件 |
| | | window.handleMouseMove = null; |
| | | } |
| | | window.handleMouseMove = new Cesium.ScreenSpaceEventHandler(window.Viewer.scene.canvas); |
| | | window.handleMouseMove.setInputAction(function (movement) { |
| | | let cartesian = window.Viewer.camera.pickEllipsoid( |
| | | movement.endPosition, |
| | | window.Viewer.scene.globe.ellipsoid |
| | | ); |
| | | if (cartesian) { |
| | | //将笛卡尔坐标转换为地理坐标 |
| | | var cartographic = |
| | | window.Viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian); |
| | | //将弧度转为度的十进制度表示 |
| | | var lng = Cesium.Math.toDegrees(cartographic.longitude); |
| | | var lat = Cesium.Math.toDegrees(cartographic.latitude); |
| | | //获取相机高度 |
| | | var alt = Math.ceil(window.Viewer.camera.positionCartographic.height); |
| | | // 定义CGCS2000坐标系 |
| | | const cgcs2000 = new Cesium.Ellipsoid( |
| | | 6378137.0, |
| | | 6378137.0, |
| | | 6356752.3142451793 |
| | | ); |
| | | |
| | | let coordinate = { |
| | | longitude: Number(lng.toFixed(6)), |
| | | latitude: Number(lat.toFixed(6)), |
| | | altitude: Number(alt.toFixed(2)), |
| | | type: 'MOUSE_MOVE' |
| | | }; |
| | | window.addMouseEvents(coordinate) |
| | | } |
| | | }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); |
| | | }, |
| | | // 定义Moon2000坐标系 |
| | | const moon2000 = new Cesium.Ellipsoid(1737400.0, 1737400.0, 1737400.0); |
| | | |
| | | //CGCS2000转月球坐标---待验证 |
| | | Cjcs2000ToMoon() { |
| | | // 定义待转换的经纬度坐标和高度 |
| | | const longitude = 110.5; |
| | | const latitude = 34.5; |
| | | const height = 0; |
| | | |
| | | // 定义CGCS2000坐标系 |
| | | const cgcs2000 = new Cesium.Ellipsoid( |
| | | 6378137.0, |
| | | 6378137.0, |
| | | 6356752.3142451793 |
| | | ); |
| | | |
| | | // 定义Moon2000坐标系 |
| | | const moon2000 = new Cesium.Ellipsoid(1737400.0, 1737400.0, 1737400.0); |
| | | |
| | | // 将经纬度坐标转换为笛卡尔坐标系 |
| | | const cartesian3 = Cesium.Cartesian3.fromDegrees( |
| | | longitude, |
| | | latitude, |
| | | height, |
| | | cgcs2000 |
| | | ); |
| | | // 将笛卡尔坐标系转换为Moon2000坐标系 |
| | | const moonCartesian3 = Cesium.Transforms.eastNorthUpToFixedFrame( |
| | | cartesian3, |
| | | cgcs2000, |
| | | moon2000 |
| | | ); |
| | | // 输出转换后的经纬度坐标和高度 |
| | | console.log(moonCartesian3); |
| | | // 将Moon2000坐标系的笛卡尔坐标转换为经纬度坐标 |
| | | const moonPosition = Cesium.Cartographic.fromCartesian(moonCartesian3); |
| | | // 输出转换后的经纬度坐标和高度 |
| | | console.log(moonPosition); |
| | | }, |
| | | // 将经纬度坐标转换为笛卡尔坐标系 |
| | | const cartesian3 = Cesium.Cartesian3.fromDegrees( |
| | | longitude, |
| | | latitude, |
| | | height, |
| | | cgcs2000 |
| | | ); |
| | | // 将笛卡尔坐标系转换为Moon2000坐标系 |
| | | const moonCartesian3 = Cesium.Transforms.eastNorthUpToFixedFrame( |
| | | cartesian3, |
| | | cgcs2000, |
| | | moon2000 |
| | | ); |
| | | // 输出转换后的经纬度坐标和高度 |
| | | console.log(moonCartesian3); |
| | | // 将Moon2000坐标系的笛卡尔坐标转换为经纬度坐标 |
| | | const moonPosition = Cesium.Cartographic.fromCartesian(moonCartesian3); |
| | | // 输出转换后的经纬度坐标和高度 |
| | | console.log(moonPosition); |
| | | }, |
| | | }; |
| | | export default InitMap; |