1
lxl
2022-09-16 2d9ddf8269640309f22053d3c92a38fd77e84358
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<template>
  <div id="sdkContainer"></div>
</template>
 
<script>
import Vue from "vue";
import * as turf from "@turf/turf";
 
// import { getNextLayer, getPelByGraphEntityId } from "../../api/api";
var handler;
export default {
  name: "CESIUMmap",
  data() {
    return {
      dataSourceArr: [],
      properyiesObj: {
        entityArea: "",
        entityLength: "",
        elemId: "",
        relationType: "",
        entityName: "",
        producer: "",
        createTime: "",
        updateTime: "",
        entityId: "",
      },
      renderStyle: {
        "0101": Cesium.Color.AQUA, //'水系'
        "0102": Cesium.Color.LIGHTSLATEGRAY, //'交通',
        "0103": Cesium.Color.DARKSALMON, //'建筑',
        "0104": Cesium.Color.GREY, //'/管线',
        "0105": Cesium.Color.ORANGE, //'院落',
        "0106": Cesium.Color.BALCK, //'地名',
        "0107": Cesium.Color.fromCssColorString("rgba(86,112,198,1)"), //'地貌',
        "0108": Cesium.Color.SEAGREEN, //'植被与土质',
        "0109": Cesium.Color.fromCssColorString("rgba(158,204,50,1)"), //'定位基础',
        "0201": Cesium.Color.NAVAJOWHITE, //'行政区域单元',
        "0202": Cesium.Color.fromCssColorString("rgba(151,152,2,1)"), //'自然地理单元',
      },
      loadingCount: 0,
      imageryProviderLayers: [],
    };
  },
  methods: {
    init3DMap() {
      // window.sgworld = Vue.prototype.$earthCtrl = new SmartEarth.SGWorld(
      //   "sdkContainer"
      // );
      // 使用单张地图图片
      window.sgworld = new SmartEarth.SGWorld(
        "sdkContainer",
        Cesium,
        SmartEarthRootUrl + "Workers/image/earth.jpg"
      );
 
      sgworld.Viewer.scene.globe.depthTestAgainstTerrain = false;
      window.Viewer = sgworld._Viewer;
 
      //抚顺图层
      let urls = BASE_URL + "/tmsserver/fssh_dom_10_20";
      let layer = sgworld.Creator.createUrlTemplateImageryProvider(
        "tms服务",
        {
          url: Cesium.buildModuleUrl(urls + "/{z}/{x}/{reverseY}.png"),
          minimumLevel: 10,
          maximumLevel: 20,
          rectangle: Cesium.Rectangle.fromDegrees(
            123.1842,
            41.698,
            124.1864,
            41.9207
          ),
        },
        "0",
        undefined,
        true,
        ""
      );
      sgworld.Navigate.Stop(); //取消飞行状态
      sgworld.Navigate.jumpTo({
        //跳转视角
        destination: new Cesium.Cartesian3.fromDegrees(
          124.041921763,
          41.832088564,
          5000
        ),
      });
      this.senderStartMessage();
    },
    senderStartMessage() {
      var jsonData = {
        funName: "loadMap",
        data: [{ name: "数据加载完成" }],
      };
      window.onload = function () {
        window.parent.postMessage(jsonData, "*");
      };
    },
    // //显隐图层
    // cesiumMapControl(data, value) {
    //   // 每次勾选恢复初始状态
    //   this.removeAllEntity();
    //   this.imageryProviderLayers = [];
    //   // this.dataSourceArr = []
    //   // sgworld.Viewer.dataSources.removeAll()
    //   var index = this.dataSourceArr.indexOf(data);
    //   if (index >= 0) {
    //     var cesiumData = sgworld.Viewer.dataSources.get(index);
    //     cesiumData.show = value;
    //     sgworld.Viewer.flyTo(cesiumData);
    //   } else {
    //     this.getFour(data);
    //     this.dataSourceArr.push(data);
    //   }
    // },
    // 主实体接口请求
    // getFour(val) {
    //   getNextLayer(val)
    //     .then((response) => {
    //       var a = response.itselfPel;
    //       this.addCesiumMap(a, val);
    //     })
    //     .catch((error) => {
    //       console.log(error);
    //     });
    // },
    // //三维实体绘制
    // addCesiumMap(data, value) {
    //   const properyiesObj = data.features[0].properties;
    //   this.$emit("addProperites", properyiesObj);
    //   var geojsonData = new Cesium.GeoJsonDataSource(value);
    //   geojsonData
    //     .load(data, {
    //       stroke: Cesium.Color.BLACK,
    //       fill: Cesium.Color.ORANGE.withAlpha(0),
    //       markerSymbol: ".",
    //       strokeWidth: 5,
    //       markerSize: 20,
    //       outlineWidth: 6,
    //       markerColor: Cesium.Color.BLUE,
    //       clampToGround: false,
    //     })
    //     .then((res) => {
    //       sgworld.Viewer.dataSources.add(res);
    //       //sgworld.Viewer.zoomTo(res);
    //       var entity = res.entities.values;
    //       if (entity.length > 1) {
    //         for (var i = 0, len = entity.length; i < len; i++) {
    //           console.log(entity[i].properties);
    //           if (entity[i].properties.elemId) {
    //             let id = entity[i].properties.elemId._value.substr(0, 4);
    //             if (entity[i].position) {
    //               entity[i].billboard = {};
    //             }
    //             if (entity[i].polyline) {
    //               entity[i].polyline.material = this.renderStyle[id];
    //             }
    //             if (entity[i].polygon) {
    //               entity[i].polygon.material = this.renderStyle[id];
    //             }
    //           } else {
    //             if (entity[i].position) {
    //               entity[i].billboard = {};
    //               entity[i].point = {
    //                 pixelSize: 10,
    //                 color: Cesium.Color.fromCssColorString("#4B0082"),
    //                 show: true,
    //                 disableDepthTestDistance: 100.0,
    //               };
    //               this.handerLabel(entity[i]);
    //             }
    //             if (entity[i].polyline) {
    //               entity[i].polyline.material = Cesium.Color.BLUE;
    //             }
    //             if (entity[i].polygon) {
    //               entity[i].polygon.material = Cesium.Color.ORANGE;
    //             }
    //           }
    //         }
    //       } else {
    //         this.randerSelfEntity(entity);
    //       }
    //     });
    //   sgworld.Viewer.flyTo(geojsonData);
    // },
    // //主实体渲染
    // randerSelfEntity(entity) {
    //   for (var i = 0, len = entity.length; i < len; i++) {
    //     let id = entity[i].properties.elemId._value.substr(0, 4);
    //     if (entity[i].position) {
    //       entity[i].billboard = {};
    //       entity[i].point = {
    //         pixelSize: 10,
    //         color: Cesium.Color.fromCssColorString("#4B0082"),
    //         show: true,
    //         disableDepthTestDistance: 100.0,
    //       };
    //       this.handerLabel(entity[i]);
    //     }
    //     if (entity[i].polyline) {
    //       var polylinepos = entity[i].polyline.positions.getValue();
    //       var polylineCenter = polylinepos[parseInt(polylinepos.length / 2)];
    //       entity[i].position = polylineCenter;
    //       entity[i].polyline.material = this.renderStyle[id];
    //       this.handerLabel(entity[i]);
    //     }
    //     if (entity[i].polygon) {
    //       var polygonpos = entity[i].polygon.hierarchy.getValue().positions;
    //       var polygeonCenter =
    //         Cesium.BoundingSphere.fromPoints(polygonpos).center;
    //       entity[i].position = polygeonCenter;
    //       // entity[i].polygon.outline = false
    //       // entity[i].polygon.outlineColor = Cesium.Color.BLACK
    //       // entity[i].polygon.outlineWidth = 50
    //       // entity[i].polygon.closeTop = false
    //       this.handerLabel(entity[i]);
    //       // entity[i].polygon.material = this.renderStyle[id].withAlpha(0.3)
    //       entity[i].polygon.outline = true;
    //       entity[i].polygon.outlineColor = this.renderStyle[id];
    //       entity[i].polygon.outlineWidth = 6;
    //       //  entity[i].polygon.material = require('@/assets/background.png')
    //       entity[i].polyline = {
    //         positions: polygonpos,
    //         width: 6,
    //         material: this.renderStyle[id],
    //       };
    //     }
    //   }
    // },
    // //主实体名称处理
    // handerLabel(data) {
    //   data.label = {
    //     text: data.name,
    //     showBackground: true,
    //     scale: 0.5,
    //     horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
    //     verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
    //     distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
    //       10.0,
    //       5000.0
    //     ),
    //     disableDepthTestDistance: 100.0,
    //   };
    // },
    //高亮显示
    // inputAction() {
    //   let highlightedFeature = {
    //     feature: undefined,
    //     originColor: new Cesium.Color(),
    //   };
    //   let highlightedPoint = {
    //     feature: undefined,
    //     originColor: new Cesium.Color(),
    //   };
    //   let heightEntity = null;
    //   handler = new Cesium.ScreenSpaceEventHandler(sgworld.Viewer.scene.canvas);
    //   handler.setInputAction((e) => {
    //     if (Cesium.defined(highlightedFeature.feature)) {
    //       highlightedFeature.feature.material.color =
    //         highlightedFeature.originColor;
    //       highlightedFeature.feature = undefined;
    //     }
    //     if (Cesium.defined(highlightedPoint.feature)) {
    //       highlightedPoint.feature.color = highlightedPoint.originColor;
    //       highlightedPoint.feature = undefined;
    //     }
    //     // const feature = sgworld.Viewer._Viewer.scene.pick(e.position);
    //     const feature = sgworld.Viewer.scene.pick(e.position);
    //     if (feature) {
    //       if (feature.id.point) {
    //         highlightedPoint.originColor = feature.id.point.color;
    //         feature.id.point.color = Cesium.Color.RED;
    //         highlightedPoint.feature = feature.id.point;
    //       }
    //       if (feature.id.polyline) {
    //         highlightedFeature.originColor = feature.id.polyline.material.color;
    //         feature.id.polyline.material.color = Cesium.Color.RED;
    //         highlightedFeature.feature = feature.id.polyline;
    //       }
    //       if (feature.id.polygon) {
    //         highlightedFeature.originColor = feature.id.polygon.material.color;
    //         feature.id.polygon.material.color = Cesium.Color.RED;
    //         highlightedFeature.feature = feature.id.polygon;
    //       }
    //       const properties = feature.id.properties;
    //       // 三维实体点击处理
    //       this.handelGeojson(properties);
    //     }
    //   }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    // },
    //判断实体是否存在
    // isExitFeature(id) {
    //   var index = this.dataSourceArr.indexOf(id);
    //   if (index >= 0) {
    //     var cesiumData = sgworld.Viewer.dataSources.get(index);
    //     sgworld.Viewer.dataSources.remove(cesiumData, true);
    //     this.dataSourceArr.splice(index, 1);
    //   }
    //   this.dataSourceArr.push(id);
    // },
    // //处理属性数据
    // handelGeojson(data) {
    //   var len1 = Object.keys(this.properyiesObj);
    //   for (var i = 0, len = len1.length; i < len; i++) {
    //     if (data[len1[i]]) {
    //       this.properyiesObj[len1[i]] = data[len1[i]]._value;
    //     }
    //   }
 
    //   this.$emit("addProperites", this.properyiesObj);
    //   //增加左侧实体树选中更新
    //   this.$bus.$emit("updateRightTree", this.properyiesObj.entityId);
    //   let entitydata = {
    //     entityId: this.properyiesObj.entityId,
    //     name: this.properyiesObj.entityName,
    //   };
    //   this.$bus.$emit("updateEntitySearchName", entitydata);
    //   this.$bus.$emit("updateAtlas", entitydata.entityId);
    //   this.$bus.$emit("updateCount", entitydata.entityId);
    //   const renderThreeIndex = this.dataSourceArr.indexOf("Entity_ID");
    //   if (renderThreeIndex <= -1) return;
    //   this.dataSourceArr = [];
    //   sgworld.Viewer.dataSources.removeAll();
    //   this.$bus.$emit("clearChecked", entitydata.entityId);
 
    //   this.cesiumMapControl(entitydata.entityId, true);
    // },
    // //获取右侧树数据
    // getRightTree(data, id = "Entity_ID") {
    //   this.isExitFeature(id);
    //   if (data.length == 0) {
    //     return;
    //   }
    //   getPelByGraphEntityId(data).then((res) => {
    //     let feature = res.data.pel;
    //     this.addCesiumMap(feature, id);
    //     // this.dealSonData1(feature, id);
    //   });
    // },
    // //显示覆盖地图
    // showCoverageMap(data, id) {
    //   this.isExitFeature(id);
    //   this.addCesiumMap(data, id);
    // },
    // //清除Cesium地图
    // clearCesium() {
    //   this.$bus.$emit("clearChecked");
    //   this.$emit("rightDown");
    //   this.$emit("addProperites", {});
    //   sgworld.Viewer.dataSources.removeAll();
    //   this.dataSourceArr = [];
    // },
    // addGltfModel(showModel) {
    //   var gltf2 = sgworld.Viewer.entities.add({
    //     name: "gltf",
    //     position: new Cesium.Cartesian3.fromDegrees(
    //       106.27898940713537,
    //       29.595215690167116,
    //       0
    //     ),
    //     model: {
    //       uri: "./data/{45E48FBD-D0BD-437F-810B-AB6CCB27BD01}.gltf",
    //     },
    //   });
 
    //   if (!showModel) {
    //     // gltf2.show = false
    //     sgworld.Viewer.entities.values.forEach((item) => {
    //       item.show = false;
    //     });
    //   }
    //   sgworld.Viewer.zoomTo(gltf2);
    // },
    // removeAllEntity() {
    //   sgworld.Viewer.entities.values.forEach((item) => {
    //     item.show = false;
    //   });
    // },
  },
  mounted() {
    this.init3DMap();
 
    // 添加交互
    // this.inputAction();
    // //左侧树绘制
    // this.$bus.$on("getLayer", (param, id) => {
    //   this.addCesiumMap(param, id);
    // });
    // //判断显隐
    // this.$bus.$on("layerControl", (param, id) => {
    //   this.cesiumMapControl(param, id);
    // });
    // //覆盖率图表点击绘制
    // this.$bus.$on("showCoverageMap", (param) => {
    //   this.showCoverageMap(param, "CoverageMap");
    // });
    // //按类型的覆盖率图表点击绘制
    // this.$bus.$on("showCoverageMapByType", (param) => {
    //   this.showCoverageMap(param, "CoverageMapByType");
    // });
    // //右侧实体树绘制
    // this.$bus.$on("renderAllEntity", (params, state) => {
    //   this.getRightTree(params, state);
    // });
    // //清楚图层
    // this.$bus.$on("clearLayer", () => {
    //   this.clearCesium();
    // });
    // //展示LOD4层数据
    // this.$bus.$on("showLOD4", (param) => {
    //   // var url = "../../../public/data/3dtiles/tileset.json";
    //   // this.add3DTileSource(url);
    //   this.addGltfModel(param);
    // });
  },
  // beforeDestroy() {},
};
</script>
 
<style scoped>
#sdkContainer {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
</style>