月球大数据地理空间分析展示平台-【前端】-月球2期前端
surprise
2023-10-19 9f51306b10520a2be30bedfe1b34c288cf770f43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<template>
  <div class="mouseBox" @setMouseMove="setMouseMove">
    <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>
  </div>
</template>
 
<script lang="ts" setup>
import InitMap from "@/assets/js/Map";
import server from "@/assets/js/Map/server";
import {
  ref,
  onMounted,
  onBeforeUnmount,
  reactive,
  defineProps,
  defineEmits,
} from "vue";
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 gridIsshow = ref(false);
let levelArray = [
  0, 40000000, 20000000, 10000000, 5000000, 2000000, 1000000, 500000, 250000,
  200000, 100000, 50000, 17000, 9000, 5000, 2000, 1000, 500, 200, 100, 50, 25,
  10, 0,
];
let heightlevel = "";
const setMouseMove = (res) => {
  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((movement) => {
    //捕获椭球体,将笛卡尔二维平面坐标转为椭球体的笛卡尔三维坐标,返回球体表面的点
    var cartesian = window.Viewer.camera.pickEllipsoid(
      movement.endPosition,
      ellipsoid
    );
   
    if (cartesian) {
      //将笛卡尔三维坐标转为地图坐标(弧度)
      var cartographic =
        window.Viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
      //将地图坐标(弧度)转为十进制的度数
      longitude.value = SmartEarth.Cesium.Math.toDegrees(
        cartographic.longitude
      ).toFixed(6);
      latitude.value = SmartEarth.Cesium.Math.toDegrees(
        cartographic.latitude
      ).toFixed(6);
      altHeight.value = window.Viewer.scene.globe.getHeight(
        Cesium.Cartographic.fromDegrees(longitude.value, latitude.value, 0)
      );
      if (altHeight.value) {
        altHeight.value = altHeight.value.toFixed(2);
      }
    }
  }, SmartEarth.Cesium.ScreenSpaceEventType.MOUSE_MOVE);
 
  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.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 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;// 分辨率
    rate.value = distance.toFixed(2); //分辨率
  })
};
const gridSwitch = () => {
  server.showlonlatLine();
};
const getHeight = () => {
  let removeListener = Viewer.camera.changed.addEventListener(() => {
    // 当前高度
    let height = Viewer.camera.positionCartographic.height;
    heightlevel = getLevel(height);
 
    if (heightlevel == 6) {
      gridDel();
      grid(5);
    }
    // if (heightlevel <= 6) {
    //   gridDel();
    //   grid(10);
    // }
    if (heightlevel == 8) {
      gridDel();
      grid(1);
    }
  });
};
const getLevel = (height) => {
  for (var i = 1, len = levelArray.length; i < len - 1; i++) {
    if (height >= (levelArray[i] + levelArray[i + 1]) / 2) {
      return i;
    }
  }
  return levelArray.length - 1;
};
const createPrimitives = (degree) => {
  var GridImagery = new Cesium.GridImageryProvider();
  var imageryLayers = Viewer.imageryLayers;
  var GridImageryLayer = imageryLayers.addImageryProvider(GridImagery); // 添加网格图层
  imageryLayers.raiseToTop(GridImageryLayer); // 将网格图层置顶
};
const grid = (degree) => {
  const entities = Viewer.entities;
  for (let longitude = -180; longitude <= 180; longitude += degree) {
    let text = "";
    if (longitude === 0) {
      text = "0";
    }
    text += longitude === 0 ? "" : "" + longitude + "°";
    if (longitude === -180) {
      text = "";
    }
    let obj = entities.add({
      position: Cesium.Cartesian3.fromDegrees(longitude, 0),
      polyline: {
        positions: Cesium.Cartesian3.fromDegreesArray([
          longitude,
          -90,
          longitude,
          0,
          longitude,
          90,
        ]),
        width: 4.0,
        material: new Cesium.Color.fromCssColorString("#c8b284"),
        clampToGround: true, //开启贴地
      },
      label: {
        text: text,
        verticalOrigin: Cesium.VerticalOrigin.LEFT,
        font: "16px sans-serif",
        fillColor: new Cesium.Color.fromCssColorString("#000"),
        outlineWidth: "6px sans-serif", // 字体外圈线宽度(同样也有颜色可设置)
        outlineColor: new Cesium.Color.fromCssColorString("#000"),
        // 这里设置了就不会被遮盖了,设为负值则在更上层
        eyeOffset: new Cesium.Cartesian3(0, 0, -10000),
      },
    });
    entitiesObj.lonLine.push(obj);
  }
  let langS = [];
  for (let longitude = -180; longitude <= 180; longitude += 5) {
    langS.push(longitude);
  }
  //每隔10读绘制一条纬度线和纬度标注,自己控制间隔
  for (let lat = -80; lat <= 80; lat += degree) {
    let text = "";
    text += "" + lat + "°";
    if (lat === 0) {
      text = "";
    }
 
    let obj = entities.add({
      position: Cesium.Cartesian3.fromDegrees(0, lat),
      polyline: {
        positions: Cesium.Cartesian3.fromDegreesArray(
          langS
            .map((long) => {
              return [long, lat].join(",");
            })
            .join(",")
            .split(",")
            .map((item) => Number(item))
        ),
        width: 4.0,
        material: new Cesium.Color.fromCssColorString("#c8b284"),
        clampToGround: true, //开启贴地
      },
      label: {
        text: text,
        font: "18px sans-serif",
        fillColor: new Cesium.Color.fromCssColorString("#000"),
        outlineWidth: 6, // 字体外圈线宽度(同样也有颜色可设置)
        outlineColor: new Cesium.Color.fromCssColorString("#000"),
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 垂直位置
        pixelOffset: new Cesium.Cartesian2(0, 15), // 中心位置
        // 这里设置了就不会被遮盖了,设为负值则在更上层
        eyeOffset: new Cesium.Cartesian3(0, 0, -10000),
      },
    });
    entitiesObj.latLine.push(obj);
  }
 
  // 抗锯齿
  if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
    //判断是否支持图像渲染像素化处理
    Viewer.resolutionScale = window.devicePixelRatio;
  }
  //开启抗锯齿
  Viewer.scene.fxaa = true;
  Viewer.scene.postProcessStages.fxaa.enabled = true;
};
const gridDel = () => {
  if (entitiesObj.lonLine.length > 0) {
    entitiesObj.lonLine.forEach((e) => {
      Viewer.entities.remove(e);
    });
    entitiesObj.lonLine = [];
  }
  if (entitiesObj.latLine.length > 0) {
    entitiesObj.latLine.forEach((e) => {
      Viewer.entities.remove(e);
    });
    entitiesObj.latLine = [];
  }
};
onMounted(() => {
  window.setMouseMove = setMouseMove;
  //   const handleMouseMove =
});
</script>
 
<style lang="less" scoped>
.mouseBox {
  height: 47px;
  background: rgba(1, 0, 28, 0.3);
 
  left: 128px;
  bottom: 20px;
 
  position: absolute;
  z-index: 30;
  padding-left: 10px;
  padding-right: 20px;
  display: flex;
  align-items: center;
 
  .earthImage {
    width: 20px;
    height: 20px;
    background: url("../assets/img/形状 9.png") no-repeat;
    background-size: 100% 100%;
    margin-left: 10px;
    cursor: pointer;
  }
 
  .earthLable {
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    line-height: 5px;
    margin-left: 10px;
  }
 
  .active {
    background-color: #171e2e;
    border: 1px solid;
    border-image: linear-gradient(47deg, #397bc9, #77a5cd, #397bc9) 1 1;
    box-shadow: 0px 0px 6px 0px #080c13, 0px 7px 8px 0px rgba(38, 47, 71, 0.68);
  }
}
</style>