yxl
2025-01-02 c0ff61d066a9f65aa0cdbeb1e10a249763f1e966
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
import axios from "axios";
import mapConfig from "./mapConfig";
import mapServer from "./mapServer";
import modelLayer from "./modelLayer";
import wfsConfig from "./wfsConfig";
import mapInfo from "./mapInfo";
import layerJson from "./mapJsonLayer";
import * as turf from "@turf/turf";
import mapModel from "./mapModel";
 
const mapViewer = {
  configTooles: null,
  layer: null,
  initMap() {
    window.earthCtrl = new SmartEarth.EarthCtrl("sdkContainer", {
      // 隐藏默认底图
      defaultImagery: false,
      // 隐藏logo
      printLog: false,
      // maxViewHeight: 1200000
      // sceneMode: SmartEarth.Cesium.SceneMode.SCENE2D
    });
    window.Cesium = SmartEarth.Cesium;
    window.Viewer = earthCtrl.viewer;
    Viewer.scene.globe.baseColor = Cesium.Color.fromCssColorString("#A9A9A9"); //设置地球颜色
    var handler = new Cesium.ScreenSpaceEventHandler(Viewer.scene.canvas);
 
    handler.setInputAction(function (clickEvent) {
      var pickedObject = Viewer.scene.pick(clickEvent.position);
      if (Cesium.defined(pickedObject)) {
        // 这里可以获取到点击的实体或其他对象
        var featureId = pickedObject.getProperty("id");
        console.log(featureId);
 
        // pickedObject.color = Cesium.Color.RED;
        console.log("点击的对象:", pickedObject);
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    // earthCtrl.factory.createTerrainLayer({
    //   sourceType: "ctb",
    //   url: "https://tiles1.geovisearth.com/base/v1/terrain?token=486dac3bec56d7d7c2a581c150be2bd937462f1e8f3bc9c78b5658b396122405"
    // });
    this.addImageLayer();
    // this.addqqmap();
    let now2 = new Date();
    let todayNoon = new Date(
      now2.getFullYear(),
      now2.getMonth(),
      now2.getDate(),
      12,
      0,
      0
    );
    var res = {
      longitude: 121.5898036178841,
      latitude: 23.93799083591751,
      height: 2732.163687177577
    };
    Viewer.clock.currentTime = Cesium.JulianDate.fromDate(todayNoon);
    earthCtrl.camera.flyTo(
      res.longitude,
      res.latitude,
      res.height,
      4.501790216143808,
      -32.230361363631324,
      0.001313831409284339,
      2
    );
    // setTimeout(() => {
    //   mapModel.init();
    // }, 5000);
    // mapServer.addServer({
    //   sourceType: "Tileset",
    //   url: "http://103.135.160.14:9038/gisserver/c3dserver/JiashanBase/tileset.json",
    //   id: "c8f3f75d-8730-44ec-81b7-f8ae4c5fd742"
    // });
 
    // this.addGlBModel({
    //   url: "http://localhost/pwyth/modles/通讯设施.glb",
    //   // url: "http://localhost/pwyth/glb/BDZ.glb",
    //   lon: 121.614202387521061,
    //   lat: 23.990136825668284,
    //   alt: 100
    // });
    // this.addTetrahedron({
    //   lon: 121.614202387521061,
    //   lat: 23.990136825668284,
    //   alt: 150
    // })
    // this.addTetrahedron({
    //   lon: 121.58663347489937,
    //   lat: 24.024697711615325,
    //   alt: 100
    // })
 
    // Viewer.scene.postRender.addEventListener(() => {
    //   var cameraHeight = Viewer.camera.positionCartographic.height;
    //   if (cameraHeight / 1000 < 5) {
    //     if (this.layer) {
    //       this.layer.show = false;
    //     }
    //   } else {
    //     if (this.layer) {
    //       this.layer.show = true;
    //     } else {
    //       this.addqqmap();
    //     }
    //   }
    // });
    // mapInfo.setEntityQueryInput();
    // this.addWfsLayer()
    // this.addRaderLayer()
    // this.addModel()
    // this.addTetrahedron({
    //   lon: 121.614202387521061,
    //   lat: 23.990136825668284,
    //   alt: 150
    // })
  },
  addTetrahedron(res) {
    earthCtrl.factory.addTetrahedron({
      position: {
        lon: res.lon,
        lat: res.lat,
        height: res.alt
      },
      multiple: 0.05,
      scale: new SmartEarth.Cesium.Cartesian3(100, 100, 100),
      color: "#FF0000",
      outlineColor: "#FF0000"
    });
  },
  addGlBModel(res) {
    var style = {
      longitude: res.lon,
      latitude: res.lat,
      altitude: 100,
      heading: 0,
      pitch: 0,
      roll: 0
    };
    const modelMatrix = mapConfig.getModelMatrix(style);
    const modelLayer = new Cesium.PrimitiveCollection();
 
    Viewer.scene.primitives.add(modelLayer);
    modelLayer.add(
      Cesium.Model.fromGltf({
        id: res,
        url: res.url,
        scale: 1,
        minimumPixelSize: 20,
        maximumScale: 20,
        modelMatrix: modelMatrix
      })
    );
  },
  createPolygonGeoJsonFeatureLayer() {
    const obj = mapConfig.setCartesian3To84(
      -3053189.741118935,
      4965028.148318093,
      2581134.003585035
    );
    var buffered = turf.circle(obj, 140, {
      units: "kilometers",
      steps: 200,
      properties: { foo: "bar" }
    });
 
    const data = {
      outline: true,
      outlineColor: "#0f0",
      outlineWidth: 5,
      material: "#0000ff80",
      mask: true
    };
    const geom = {
      type: "FeatureCollection",
      features: [
        {
          type: "Feature",
          properties: {
            adcode: 340100,
            name: "合肥市",
            center: [117.283042, 31.86119],
            centroid: [117.360447, 31.762594],
            childrenNum: 9,
            level: "city",
            acroutes: [100000, 340000],
            parent: {
              adcode: 340000
            }
          },
          geometry: {
            type: "MultiPolygon",
            coordinates: buffered.geometry.coordinates
          }
        }
      ]
    };
    const url = config.localUrl + "/data/hefei.json";
    earthCtrl.factory.createPolygonGeoJsonFeatureLayer(
      "",
      [url],
      data,
      "0",
      true,
      function (data) {
        console.log("456", data);
      }
    );
  },
  addImageLayer() {
    mapServer.addServer({
      sourceType: "arcgis",
      url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
    });
  },
  addqqmap() {
    this.layer = earthCtrl.factory.createImageryLayer({
      sourceType: "qqmap",
      url: "https://rt0.map.gtimg.com/tile?z={z}&x={x}&y={reverseY}&styleid=4&scene=0",
      tilingScheme: earthCtrl.core.getOffsetTilingScheme() // 偏移纠正
    });
  },
 
  // 添加wfs
  addWfsLayer() {
    earthCtrl.viewer.camera.flyTo({
      destination: {
        x: -3475710.5684351875,
        y: 5625834.799523204,
        z: 2729961.751894543,
      },
      orientation: {
        heading: 5.73978482494632,
        pitch: -1.2817819264676036,
        roll: 6.282989918773924,
      },
    });
    earthCtrl.factory.createWfsLayer('point', {
      urls: 'https://cim.smartearth.cn/geoserver/JiaShanBase/ows',
      layer: 'JiaShanBase:RadarSpot',
      text: '[JiaShanBase:Type]',
      color: '#de3',
      disableDepthTestDistance: Infinity
    })
    earthCtrl.factory.createWfsLayer('polyline', {
      urls: 'https://cim.smartearth.cn/geoserver/JiaShanBase/ows',
      layer: 'JiaShanBase:RadarL',
      width: 1.5,
      color: '#87CEFA',
    })
    earthCtrl.factory.createWfsLayer('polyline', {
      urls: 'https://cim.smartearth.cn/geoserver/JiaShanBase/ows',
      layer: 'JiaShanBase:RadarM',
      width: 1.5,
      color: '#de3',
    })
 
    earthCtrl.factory.createWfsLayer('polyline', {
      urls: 'https://cim.smartearth.cn/geoserver/JiaShanBase/ows',
      layer: 'JiaShanBase:RadarS',
      width: 1.5,
      color: '#FF0000',
    })
  },
  addRaderLayer() {
    //雷达遮罩扫描(自定义)
    const option = {
      radius: 1000,  //半径
      yaw: 0,  //雷达方向(可选)
      angle: 120,  //雷达夹角(可选)
      scanAngle: 30,  //扫描夹角(可选)
      speed: 5,  //倍速(可选)
      maxLat: 90,  //下维度(可选)
      minLat: 45,  //上维度(可选)
      stackPartitions: 40,  //横向网格数(可选)
      slicePartitions: 80,  //纵向网格数(可选)
      //color: 'rgba(255,255,255,0.5)',  //雷达遮罩颜色(可选)
      //outlineColor: 'rgba(255,255,255,0.5)',  //雷达遮罩边框线颜色(可选)
      //scanColor: 'rgba(255,0,0,0.5)',   //扫描颜色(可选)
    };
    const position1 = [121.614202387521061, 23.990136825668284, 0];
    // 雷达遮罩
    earthCtrl.factory.createRadarMaskScan('雷达遮罩扫描1', position1, option)
  },
  addModel() {
    const entity = earthCtrl.viewer.entities.add({
      position: SmartEarth.Cesium.Cartesian3.fromDegrees(
        121.614202387521061,
        23.990136825668284,
        0
      ),
      model: {
        uri: '/gltf/tank.glb',
        scale: 15,
        heightReference: SmartEarth.Cesium.HeightReference.CLAMP_TO_GROUND,
        disableDepthTestDistance: Number.POSITIVE_INFINITY // 禁用深度测试
      },
      label: {
        show: true,
        text: '经度:121.6142023,纬度:23.9901368',
        color: SmartEarth.Cesium.Color.fromCssColorString("#fff"),
        font: "normal 14px MicroSoft YaHei",
        showBackground: true,
        outlineColor: SmartEarth.Cesium.Color.WHITE,
        pixelOffset: new SmartEarth.Cesium.Cartesian2(10, -30),
        horizontalOrigin: SmartEarth.Cesium.HorizontalOrigin.CENTER,
        verticalOrigin: SmartEarth.Cesium.VerticalOrigin.BOTTOM,
        heightReference: SmartEarth.Cesium.HeightReference.CLAMP_TO_GROUND,
      },
    });
  }
};
export default mapViewer;