月球大数据地理空间分析展示平台-【中台】
Surpriseplus
2023-06-14 a7ceb07fdcbcac1edcecb8c96bfa7808ea7670c5
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<template>
  <div id="cesiumContainer"></div>
</template>
 
<script>
export default {
  props: {
    open: Boolean,
    mapData: Array,
  },
  data() {
    return {
      viewer: {},
      handler: {},
      entity: null,
      element: {},
    };
  },
  watch: {
    open(val) {
      // if()
      // this.makeBill();
      if (val) {
        // 移除事件
        this.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
        this.handler.setInputAction((movement) => {
          var position = this.viewer.scene.camera.pickEllipsoid(
            movement.position,
            this.viewer.scene.globe.ellipsoid
          );
          var cartographic = Cesium.Cartographic.fromCartesian(position);
          let lng = Cesium.Math.toDegrees(cartographic.longitude);
          let lat = Cesium.Math.toDegrees(cartographic.latitude);
          this.$emit('fromChlid', { lng, lat });
          if (this.entity !== null) {
            this.entity.position = Cesium.Cartesian3.fromDegrees(lng, lat);
          } else {
            this.makeBill(lng, lat);
          }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
      } else {
        // 移除事件
        this.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
      }
    },
    mapData(val) {
      let content;
      val.forEach((e) => {
        if (e.content !== null) {
          content = JSON.parse(e.content);
        }
      });
      // console.log(content);
      this.redrawPlotting(content);
    },
  },
  mounted() {
    this.viewer = new Cesium.Viewer('cesiumContainer', {
      animation: false, //是否创建动画小器件,左下角仪表
      baseLayerPicker: false, //是否显示图层选择器
      fullscreenButton: false, //是否显示全屏按钮
      geocoder: false, //是否显示geocoder小器件,右上角查询按钮
      homeButton: false, //是否显示Home按钮
      infoBox: false, //是否显示信息框
      sceneModePicker: false, //是否显示3D/2D选择器
      selectionIndicator: false, //是否显示选取指示器组件
      timeline: false, //是否显示时间轴
      navigationHelpButton: false, //是否显示右上角的帮助按钮
      scene3DOnly: true, //如果设置为true,则所有几何图形以3D模式绘制以节约GPU资源
      CreditsDisplay: false, //展示数据版权属性
      imageryProvider: new Cesium.UrlTemplateImageryProvider({
        url: './earth/{z}/{x}/{reverseY}.jpeg',
        minimumLevel: 0,
        maximumLevel: 6,
      }),
      // imageryProvider: new this.Cesium.SingleTileImageryProvider({
      //   //  url: 'http://103.85.171.154:60080/gisserver/tmsserver/earth_tms/{z}/{x}/{reverseY}.jpeg"'
      //   // }),
    });
    this.viewer._cesiumWidget._creditContainer.style.display = 'none';
    this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
    var urls1 = `./beijingmtg`;
    var urls2 = `./map`;
    // layer = this.viewer.Creator.createUrlTemplateImageryProvider(
    //   "tms服务",
    //   {
    //     url: Cesium.buildModuleUrl(urls1 + "/{z}/{x}/{y}.png"),
    //   },
    //   "0",
    //   undefined,
    //   true,
    //   ""
    // );
    var urlTemplateImageryProvider = new Cesium.UrlTemplateImageryProvider({
      url: urls1 + '/{z}/{x}/{y}.png',
    });
    this.viewer.imageryLayers.addImageryProvider(urlTemplateImageryProvider);
 
    var layers = this.viewer.scene.imageryLayers;
    var blackMarble = layers.addImageryProvider(
      new Cesium.createTileMapServiceImageryProvider({
        url: urls2, //url为文件夹地址
      })
    );
    //     var layers = this.viewer.scene.imageryLayers;
    // var tmsLayer = layers.addImageryProvider(
    //        new Cesium.TileMapServiceImageryProvider({
    //             url : 'http://127.0.0.1:8020/spgisgdp/preData/BIGMAP_TMS'     //url为文件夹地址
    //        })
    // );
  },
  methods: {
    /* 获取camera中心点坐标 */
    getCenterPosition() {
      var result = this.viewer.camera.pickEllipsoid(
        new Cesium.Cartesian2(
          this.viewer.canvas.clientWidth / 2,
          this.viewer.canvas.clientHeight / 2
        )
      );
      var curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result);
      var lon = (curPosition.longitude * 180) / Math.PI;
      var lat = (curPosition.latitude * 180) / Math.PI;
      return {
        lon: lon,
        lat: lat,
      };
    },
    makeBill(lng, lat) {
      this.entity = this.viewer.entities.add({
        name: '点',
        position: Cesium.Cartesian3.fromDegrees(lng, lat),
        billboard: {
          image: './img/jjd.png',
          scale: 1,
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.1),
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直位置
          horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
        },
      });
    },
    //重新绘制对象
    redrawPlotting(node) {
      this.element = node;
      if (this.element.type == 'polyline') {
        //定义折线几何
        var mypolyline = new Cesium.PolylineGraphics({
          positions: Cesium.Cartesian3.fromDegreesArray(this.element.positions),
          width: this.element.linewidth,
          // height: 0,
          material: new Cesium.Color(
            this.element.fillcolor[0],
            this.element.fillcolor[1],
            this.element.fillcolor[2],
            this.element.fillalpha
          ),
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
            this.element.mindistance,
            this.element.maxdistance
          ),
        });
        if (this.element.isborder) {
          mypolyline = new Cesium.PolylineGraphics({
            positions: Cesium.Cartesian3.fromDegreesArray(
              this.element.positions
            ),
            width: this.element.linewidth,
            // height: 0,
            material: new Cesium.PolylineOutlineMaterialProperty({
              color: new Cesium.Color(
                this.element.fillcolor[0],
                this.element.fillcolor[1],
                this.element.fillcolor[2],
                this.element.fillalpha
              ),
              outlineWidth: this.element.bordersize,
              outlineColor: new Cesium.Color(
                this.element.bordercolor[0],
                this.element.bordercolor[1],
                this.element.bordercolor[2],
                this.element.borderalpha
              ),
            }),
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
              this.element.mindistance,
              this.element.maxdistance
            ),
          });
        }
        var polylineshow = this.viewer.entities.add({
          name: this.element.name,
          polyline: mypolyline,
        });
        // this.viewer.Creator.SimpleGraphic.SimpleGraphicObj.push(
        //   polylineshow.id
        // );
        this.viewer.flyTo(polylineshow, {
          // offset: {
          //   heading: Cesium.Math.toRadians(0.0),
          //   pitch: Cesium.Math.toRadians(-25),
          //   range: alt,
          // },
        });
      } else if (this.element.type == 'label') {
        let entity = this.viewer.entities.add({
          name: this.element.name,
          position: Cesium.Cartesian3.fromDegrees(
            this.element.positions[0],
            this.element.positions[1],
            this.element.positions[2]
          ),
          label: {
            text: this.element.text,
            font: this.element.fontszie, //字体样式
            scale: this.element.scale,
            fillColor: new Cesium.Color(
              this.element.fillcolor[0],
              this.element.fillcolor[1],
              this.element.fillcolor[2],
              this.element.fillalpha
            ),
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
              this.element.mindistance,
              this.element.maxdistance
            ), //字体颜色
            backgroundColor: Cesium.Color.AQUA, //背景颜色
            // showBackground: true, //是否显示背景颜色
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            // style: Cesium.LabelStyle.FILL, //label样式
            // outlineWidth: 2,
            verticalOrigin: Cesium.VerticalOrigin.CENTER, //垂直位置
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
          },
        });
        this.viewer.flyTo(entity, {
          // offset: {
          //   heading: Cesium.Math.toRadians(0.0),
          //   pitch: Cesium.Math.toRadians(-25),
          //   range: alt,
          // },
        });
        if (this.element.isborder) {
          entity.label.outline = this.element.isborder;
          entity.label.outlineWidth = this.element.bordersize;
          entity.label.outlineColor = new Cesium.Color(
            this.element.bordercolor[0],
            this.element.bordercolor[1],
            this.element.bordercolor[2],
            this.element.borderalpha
          );
        }
        if (this.element.isbackground) {
          entity.label.showBackground = this.element.isbackground;
          entity.label.backgroundColor = new Cesium.Color(
            this.element.backcolor[0],
            this.element.backcolor[1],
            this.element.backcolor[2],
            this.element.backalpha
          );
        }
        // this.viewer.Creator.SimpleGraphic.SimpleGraphicObj.push(entity.id);
      } else if (this.element.type == 'billboard') {
        let entity = this.viewer.entities.add({
          name: this.element.name,
          position: Cesium.Cartesian3.fromDegrees(
            this.element.positions[0],
            this.element.positions[1],
            this.element.positions[2]
          ),
          billboard: {
            image: this.element.image,
            scale: this.element.imagescale,
            color: new Cesium.Color(
              this.element.fillcolor[0],
              this.element.fillcolor[1],
              this.element.fillcolor[2],
              this.element.fillalpha
            ),
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
              this.element.mindistance,
              this.element.maxdistance
            ),
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直位置
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
          },
        });
        this.viewer.flyTo(entity, {
          // offset: {
          //   heading: Cesium.Math.toRadians(0.0),
          //   pitch: Cesium.Math.toRadians(-25),
          //   range: alt,
          // },
        });
        if (this.element.width != '')
          entity.billboard.width = this.element.width;
        if (this.element.height != '')
          entity.billboard.width = this.element.height;
        if (this.element.rotate != '')
          entity.billboard.rotation = this.element.rotate;
        // this.viewer.Creator.SimpleGraphic.SimpleGraphicObj.push(entity.id);
      } else if (this.element.type == 'polygon') {
        var myPolygon1 = new Cesium.PolygonGraphics({
          hierarchy: Cesium.Cartesian3.fromDegreesArray(this.element.positions),
          material: new Cesium.Color(
            this.element.fillcolor[0],
            this.element.fillcolor[1],
            this.element.fillcolor[2],
            this.element.fillalpha
          ),
          height: 0,
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
            this.element.mindistance,
            this.element.maxdistance
          ),
        });
        var polygonshow = this.viewer.Viewer.entities.add({
          name: this.element.name,
          polygon: myPolygon1,
        });
        this.viewer.flyTo(polygonshow, {
          // offset: {
          //   heading: Cesium.Math.toRadians(0.0),
          //   pitch: Cesium.Math.toRadians(-25),
          //   range: alt,
          // },
        });
        if (this.element.isborder) {
          polygonshow.polygon.outline = true;
          if (this.element.bordersize == '')
            polygonshow.polygon.outlineWidth = 1;
          else polygonshow.polygon.outlineWidth = this.element.bordersize;
          polygonshow.polygon.outlineColor = new Cesium.Color(
            this.element.bordercolor[0],
            this.element.bordercolor[1],
            this.element.bordercolor[2],
            this.element.borderalpha
          );
        }
        // this.viewer.Creator.SimpleGraphic.SimpleGraphicObj.push(polygonshow.id);
      } else if (
        this.element.type == 'SwallowtailArrow' ||
        this.element.type == 'StraightArrow' ||
        this.element.type == 'PincerArrow' ||
        this.element.type == 'GatheringPlace'
      ) {
        var myPolygon1 = new Cesium.PolygonGraphics({
          hierarchy: Cesium.Cartesian3.fromDegreesArray(this.element.positions),
          material: new Cesium.Color(
            this.element.fillcolor[0],
            this.element.fillcolor[1],
            this.element.fillcolor[2],
            this.element.fillalpha
          ),
          height: 0,
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
            this.element.mindistance,
            this.element.maxdistance
          ),
        });
        var polygonArrowShow = this.viewer.entities.add({
          name: this.element.name,
          polygon: myPolygon1,
        });
        this.viewer.flyTo(polygonArrowShow, {
          // offset: {
          //   heading: Cesium.Math.toRadians(0.0),
          //   pitch: Cesium.Math.toRadians(-25),
          //   range: alt,
          // },
        });
 
        // polygonArrowShow.GeoType = this.element.type; //平尾箭头等
        // polygonArrowShow.pottingPoint = this.element.plottingpoints;
        // this.viewer.Creator.SimpleGraphic.SimpleGraphicObj.push(
        //   polygonArrowShow.id
        // );
      }
      // this.plotData = sgworld.Viewer.entities._entities;
      // console.log( sgworld.Creator);
    },
  },
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.cesium-widget-credits {
  display: none !important;
}
</style>