| | |
| | | <template> |
| | | <div class="mouseBox" @setMouseMove="setMouseMove"> |
| | | <div |
| | | class="earthImage" |
| | | :class="{ active: gridIsshow }" |
| | | @click="gridSwitch" |
| | | ></div> |
| | | <div class="earthImage" :class="{ active: gridIsshow }" @click="gridSwitch"></div> |
| | | <div class="earthLable">经度 :</div> |
| | | <div class="earthLable">{{ longitude }}</div> |
| | | <div class="earthLable">纬度 :</div> |
| | | <div class="earthLable">{{ latitude }}</div> |
| | | <div class="earthLable">地形高度 :</div> |
| | | <div class="earthLable">{{ altHeight }} </div> |
| | | <div class="earthLable">米</div> |
| | | <div class="earthLable">视角高度 :</div> |
| | | <div class="earthLable">{{ alt }} </div> |
| | | <div class="earthLable">千米</div> |
| | | <div class="earthLable">分辨率 :</div> |
| | | <div class="earthLable">{{ rate }}</div> |
| | | <div class="earthLable">m/px</div> |
| | |
| | | </template> |
| | | |
| | | <script lang="ts" setup> |
| | | import InitMap from "@/assets/js/Map"; |
| | | import server from "@/assets/js/Map/server"; |
| | | import { |
| | | ref, |
| | | onMounted, |
| | |
| | | const longitude = ref("0.00"); |
| | | const latitude = ref("0.00"); |
| | | const rate = ref("0.00"); |
| | | const alt = ref("0.00"); |
| | | const altHeight = ref("0.00"); |
| | | |
| | | let entitiesObj = reactive({ |
| | | lonLine: [], |
| | | latLine: [], |
| | |
| | | let handlerPoint = new SmartEarth.Cesium.ScreenSpaceEventHandler( |
| | | window.Viewer.scene.canvas |
| | | ); |
| | | const pickGlobeSlope = new SmartEarth.Cesium.PickGlobeSlope(earthCtrl.Viewer) |
| | | var ellipsoid = window.Viewer.scene.globe.ellipsoid; |
| | | handlerPoint.setInputAction(function (movement) { |
| | | handlerPoint.setInputAction((movement) => { |
| | | //捕获椭球体,将笛卡尔二维平面坐标转为椭球体的笛卡尔三维坐标,返回球体表面的点 |
| | | var cartesian = window.Viewer.camera.pickEllipsoid( |
| | | movement.endPosition, |
| | | ellipsoid |
| | | ); |
| | | |
| | | if (cartesian) { |
| | | //将笛卡尔三维坐标转为地图坐标(弧度) |
| | | var cartographic = |
| | |
| | | latitude.value = SmartEarth.Cesium.Math.toDegrees( |
| | | cartographic.latitude |
| | | ).toFixed(6); |
| | | let scene = window.Viewer.scene; |
| | | // 获取画布的大小 |
| | | var width = scene.canvas.clientWidth; |
| | | var height = scene.canvas.clientHeight; |
| | | //获取画布中心两个像素的坐标(默认地图渲染在画布中心位置) |
| | | var left = scene.camera.getPickRay( |
| | | new SmartEarth.Cesium.Cartesian2((width / 2) | 0, (height - 1) / 2) |
| | | altHeight.value = window.Viewer.scene.globe.getHeight( |
| | | Cesium.Cartographic.fromDegrees(longitude.value, latitude.value, 0) |
| | | ); |
| | | var right = scene.camera.getPickRay( |
| | | new SmartEarth.Cesium.Cartesian2((1 + width / 2) | 0, (height - 1) / 2) |
| | | ); |
| | | |
| | | var globe = scene.globe; |
| | | var leftPosition = globe.pick(left, scene); |
| | | var rightPosition = globe.pick(right, scene); |
| | | |
| | | if (!Cesium.defined(leftPosition) || !Cesium.defined(rightPosition)) { |
| | | return; |
| | | if (altHeight.value) { |
| | | altHeight.value = altHeight.value.toFixed(2); |
| | | } |
| | | |
| | | var leftCartographic = |
| | | globe.ellipsoid.cartesianToCartographic(leftPosition); |
| | | var rightCartographic = |
| | | globe.ellipsoid.cartesianToCartographic(rightPosition); |
| | | var geodesic = new SmartEarth.Cesium.EllipsoidGeodesic(); |
| | | geodesic.setEndPoints(leftCartographic, rightCartographic); |
| | | rate.value = geodesic.surfaceDistance.toFixed(6); //分辨率 |
| | | } |
| | | }, SmartEarth.Cesium.ScreenSpaceEventType.MOUSE_MOVE); |
| | | }; |
| | | const gridSwitch = () => { |
| | | gridIsshow.value = !gridIsshow.value; |
| | | if (gridIsshow.value) { |
| | | grid(10); |
| | | // getHeight(); |
| | | // createPrimitives(); |
| | | } else { |
| | | gridDel(); |
| | | |
| | | Viewer.camera.changed.addEventListener(() => { |
| | | // 视高 km |
| | | let camera_alt = (Viewer.camera.positionCartographic.height / 1000).toFixed( |
| | | 2 |
| | | ); |
| | | |
| | | alt.value = camera_alt; |
| | | let scene = window.Viewer.scene; |
| | | // 获取画布的大小 |
| | | var width = scene.canvas.clientWidth; |
| | | var height = scene.canvas.clientHeight; |
| | | //获取画布中心两个像素的坐标(默认地图渲染在画布中心位置) |
| | | var left = scene.camera.getPickRay( |
| | | new SmartEarth.Cesium.Cartesian2((width / 2) | 0, (height - 1) / 2) |
| | | ); |
| | | var right = scene.camera.getPickRay( |
| | | new SmartEarth.Cesium.Cartesian2((1 + width / 2) | 0, (height - 1) / 2) |
| | | ); |
| | | var globe = scene.globe; |
| | | var leftPosition = globe.pick(left, scene); |
| | | var rightPosition = globe.pick(right, scene); |
| | | if (!Cesium.defined(leftPosition) || !Cesium.defined(rightPosition)) { |
| | | return; |
| | | } |
| | | var ellipsoid = SmartEarth.Cesium.Ellipsoid.MOON200; |
| | | var leftCartographic = |
| | | globe.ellipsoid.cartesianToCartographic(leftPosition); |
| | | var rightCartographic = |
| | | globe.ellipsoid.cartesianToCartographic(rightPosition); |
| | | var geodesic = new SmartEarth.Cesium.EllipsoidGeodesic(); |
| | | |
| | | geodesic.setEndPoints(leftCartographic, rightCartographic, ellipsoid); |
| | | // rate.value = geodesic.surfaceDistance.toFixed(2); //分辨率 |
| | | }); |
| | | Viewer.camera.moveEnd.addEventListener(() => { |
| | | const height = Viewer.camera.positionCartographic.height; |
| | | const zoom = getZoomLevel(height) |
| | | rate.value = zoom; |
| | | // console.log('缩放层级是--', zoom) |
| | | }) |
| | | const getZoomLevel = (height) => { |
| | | const A = 40487.57; |
| | | const B = 0.00007096758; |
| | | const C = 91610.74; |
| | | const D = -40467.74; |
| | | var obj= Math.round(D + (A - D) / (1 + Math.pow(height / C, B))); |
| | | var fgis = [0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125, 0.02197265625, 0.010986328125, 0.0054931640625, 0.00274658203125, 0.001373291015625, 0.0006866455078125, 0.00034332275390625, 0.00017166137695312, 0.000085830688476562, 0.000042915344238281, 0.000021457672119141, 0.00001072883605957, 0.0000053644180297852, 0.0000026822090148926, 0.0000013411045074463, 0.00000067055225372314, 0.00000033527612686157] |
| | | |
| | | return( fgis[obj]*30318.4).toFixed(2); |
| | | } |
| | | |
| | | |
| | | |
| | | Viewer.scene.postRender.addEventListener(() => { |
| | | // // 获取画布的大小 |
| | | let scene = earthCtrl.Viewer.scene; |
| | | var width = scene.canvas.clientWidth; |
| | | var height = scene.canvas.clientHeight; |
| | | //获取画布中心两个像素的坐标(默认地图渲染在画布中心位置) |
| | | var left = scene.camera.getPickRay(new SmartEarth.Cesium.Cartesian2((width / 2) | 0, (height - 1) / 2)); |
| | | var right = scene.camera.getPickRay(new SmartEarth.Cesium.Cartesian2(1 + (width / 2) | 0, (height - 1) / 2)); |
| | | |
| | | var leftPosition = scene.globe.pick(left, scene); |
| | | var rightPosition = scene.globe.pick(right, scene); |
| | | if (!SmartEarth.Cesium.defined(leftPosition) || !SmartEarth.Cesium.defined(rightPosition)) { |
| | | return; |
| | | } |
| | | const dpi = getDPI(); |
| | | const ellipsoid = SmartEarth.Cesium.Ellipsoid.MOON2000 |
| | | var leftCartographic = ellipsoid.cartesianToCartographic(leftPosition); |
| | | var rightCartographic = ellipsoid.cartesianToCartographic(rightPosition); |
| | | var geodesic = new SmartEarth.Cesium.EllipsoidGeodesic(leftCartographic, rightCartographic, ellipsoid); |
| | | var distance = geodesic.surfaceDistance * dpi;// 分辨率 |
| | | // rate.value = distance.toFixed(2); //分辨率 |
| | | }) |
| | | }; |
| | | const getDPI = () => { |
| | | |
| | | var arrDPI = new Array(); |
| | | if (window.screen.deviceXDPI != undefined) { |
| | | arrDPI[0] = window.screen.deviceXDPI; |
| | | arrDPI[1] = window.screen.deviceYDPI; |
| | | } |
| | | else { |
| | | var tmpNode = document.createElement("DIV"); |
| | | tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden"; |
| | | document.body.appendChild(tmpNode); |
| | | arrDPI[0] = parseInt(tmpNode.offsetWidth); |
| | | arrDPI[1] = parseInt(tmpNode.offsetHeight); |
| | | |
| | | } |
| | | return arrDPI[0] |
| | | |
| | | } |
| | | const gridSwitch = () => { |
| | | server.showlonlatLine(); |
| | | }; |
| | | const getHeight = () => { |
| | | let removeListener = Viewer.camera.changed.addEventListener(() => { |
| | | // 当前高度 |
| | | let height = Viewer.camera.positionCartographic.height; |
| | | heightlevel = getLevel(height); |
| | | console.log(heightlevel); |
| | | |
| | | if (heightlevel == 6) { |
| | | gridDel(); |
| | | grid(5); |
| | |
| | | return levelArray.length - 1; |
| | | }; |
| | | const createPrimitives = (degree) => { |
| | | // let ps = []; |
| | | // for (let longitude = -180; longitude <= 180; longitude += 10) { |
| | | // ps.push( |
| | | // Cesium.Cartesian3.fromDegreesArray([ |
| | | // longitude, |
| | | // -90, |
| | | // longitude, |
| | | // 0, |
| | | // longitude, |
| | | // 90, |
| | | // ]) |
| | | // ); |
| | | // } |
| | | // console.log(ps); |
| | | // let polylineGeometry = new Cesium.PolylineGeometry({ |
| | | // positions: ps, |
| | | // width: 5, |
| | | // id: "polylineGeometry", |
| | | // }); |
| | | // Viewer.scene.primitives.add( |
| | | // new Cesium.Primitive({ |
| | | // geometryInstances: new Cesium.GeometryInstance({ |
| | | // geometry: polylineGeometry, |
| | | // }), |
| | | // // vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT, |
| | | // appearance: new Cesium.EllipsoidSurfaceAppearance({ |
| | | // material: Cesium.Material.fromType("Stripe"), |
| | | // }), |
| | | // }) |
| | | // ); |
| | | var GridImagery = new Cesium.GridImageryProvider(); |
| | | var imageryLayers = Viewer.imageryLayers; |
| | | var GridImageryLayer = imageryLayers.addImageryProvider(GridImagery); // 添加网格图层 |
| | |
| | | const grid = (degree) => { |
| | | const entities = Viewer.entities; |
| | | for (let longitude = -180; longitude <= 180; longitude += degree) { |
| | | console.log( |
| | | Cesium.Cartesian3.fromDegreesArray([ |
| | | longitude, |
| | | -90, |
| | | longitude, |
| | | 0, |
| | | longitude, |
| | | 90, |
| | | ]) |
| | | ); |
| | | let text = ""; |
| | | if (longitude === 0) { |
| | | text = "0"; |
| | |
| | | if (lat === 0) { |
| | | text = ""; |
| | | } |
| | | // console.log(lat, "---lat"); |
| | | |
| | | let obj = entities.add({ |
| | | position: Cesium.Cartesian3.fromDegrees(0, lat), |
| | | polyline: { |
| | |
| | | }); |
| | | entitiesObj.latLine.push(obj); |
| | | } |
| | | console.log(entitiesObj); |
| | | |
| | | // 抗锯齿 |
| | | if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) { |
| | | //判断是否支持图像渲染像素化处理 |
| | |
| | | |
| | | <style lang="less" scoped> |
| | | .mouseBox { |
| | | height: 47px; |
| | | height: 30px; |
| | | background: rgba(1, 0, 28, 0.3); |
| | | |
| | | left: 128px; |
| | | bottom: 20px; |
| | | width: 596px; |
| | | left: 153px; |
| | | bottom: 23px; |
| | | |
| | | position: absolute; |
| | | z-index: 30; |
| | | padding-left: 10px; |
| | | padding-left: 5px; |
| | | padding-right: 10px; |
| | | display: flex; |
| | | align-items: center; |
| | | |
| | | .earthImage { |
| | | width: 20px; |
| | | height: 20px; |
| | |
| | | margin-left: 10px; |
| | | cursor: pointer; |
| | | } |
| | | |
| | | .earthLable { |
| | | font-size: 16px; |
| | | font-size: 14px; |
| | | font-family: Source Han Sans CN; |
| | | font-weight: 400; |
| | | color: #ffffff; |
| | | color: rgba(214, 228, 255, 0.8); |
| | | line-height: 5px; |
| | | margin-left: 10px; |
| | | margin-left: 5px; |
| | | } |
| | | |
| | | .active { |
| | | background-color: #171e2e; |
| | | border: 1px solid; |