fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
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
import * as mars3d from "mars3d"
 
export let map
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
const color = "#363635"
export const mapOptions = {
  scene: {
    center: { lat: 25.845231, lng: 117.57678, alt: 488175, heading: 358, pitch: -42 },
    showSun: false,
    showMoon: false,
    showSkyBox: false,
    showSkyAtmosphere: false,
    fog: false,
    backgroundColor: color, // 天空背景色
    globe: {
      baseColor: color, // 地球地面背景色
      showGroundAtmosphere: false,
      enableLighting: false
    }
  },
  control: {
    baseLayerPicker: false
  },
  terrain: { show: false },
  basemaps: [],
  layers: []
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  // 添加矢量图层
  const graphicLayer = new mars3d.layer.GraphicLayer()
  map.addLayer(graphicLayer)
 
  // 添加对象
  addAnhui(graphicLayer)
  addCenterCity(graphicLayer)
  addOutCircle(graphicLayer)
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
// 添加安徽省底图和墙
function addAnhui() {
  // 安徽省卫星底图
  const tileLayer = new mars3d.layer.XyzLayer({
    url: "//data.mars3d.cn/tile/anhui/{z}/{x}/{y}.png",
    minimumLevel: 0,
    maximumLevel: 12,
    rectangle: { xmin: 114.883371, xmax: 119.649144, ymin: 29.395253, ymax: 34.650809 }
  })
  map.addLayer(tileLayer)
 
  // 安徽省边界线墙
  const anhuiWall = new mars3d.layer.GeoJsonLayer({
    name: "安徽省边界墙",
    url: "//data.mars3d.cn/file/geojson/areas/340000.json",
    // 自定义解析数据
    onCreateGraphic: function (options) {
      const points = options.positions[0] // 坐标
      const attr = options.attr // 属性信息
 
      console.log("边界墙原始坐标", points)
 
      mars3d.PolyUtil.computeSurfaceLine({
        map: map,
        positions: points,
        has3dtiles: false,
        splitNum: 300
      }).then((result) => {
        console.log("边界墙插值计算完成坐标", result.positions)
 
        const primitive = new mars3d.graphic.WallPrimitive({
          positions: result.positions,
          style: {
            addHeight: -15000,
            diffHeight: 15000, // 墙高
            materialType: mars3d.MaterialType.Image2,
            image: "./img/textures/fence-top.png",
            color: "rgba(0,255,255,0.6)"
            // renderState: Cesium.RenderState.fromCache({
            //   blending: Cesium.BlendingState.ALPHA_BLEND,
            //   depthTest: {
            //     enabled: true,
            //     func: Cesium.DepthFunction.LESS
            //   },
            //   cull: {
            //     enabled: true,
            //     face: Cesium.CullFace.BACK
            //   },
            //   depthMask: true
            // })
          },
          attr: attr
        })
        anhuiWall.addGraphic(primitive)
      })
    }
  })
  map.addLayer(anhuiWall)
 
  // 安徽各市边界线和名称
  const shiLayer = new mars3d.layer.GeoJsonLayer({
    name: "安徽各市边界线",
    url: "//data.mars3d.cn/file/geojson/areas/340000_full.json",
    symbol: {
      type: "polyline",
      styleOptions: {
        color: "rgba(255,255,255,0.3)",
        width: 2,
        label: {
          text: "{name}",
          position: "center",
          font_size: 18,
          color: "black",
          font_family: "楷体",
          outline: true,
          outlineColor: "#f1f3f4",
          outlineWidth: 3,
          // 视距的设置
          scaleByDistance: true,
          scaleByDistance_far: 20000000,
          scaleByDistance_farValue: 0.1,
          scaleByDistance_near: 1000,
          scaleByDistance_nearValue: 1
        }
      },
      styleField: "name",
      styleFieldOptions: {
        合肥市: { color: "rgba(0,255,255,0.3)" }
      }
    },
    popup: "{name}"
  })
  map.addLayer(shiLayer)
}
 
// 添加示范城市的相关对象
function addCenterCity(graphicLayer) {
  const point = [117.234218, 31.814155, 0]
 
  // divgraphic标注
  const divgraphic = new mars3d.graphic.DivGraphic({
    position: point,
    style: {
      html: `<div class="marsBlackPanel">
                <div class="marsBlackPanel-text">示范城市</div>
            </div>`,
      horizontalOrigin: Cesium.HorizontalOrigin.LEFT, // 横向定位
      verticalOrigin: Cesium.VerticalOrigin.CENTER // 垂直定位
    }
  })
  graphicLayer.addGraphic(divgraphic)
 
  // 圆形动态扩散图
  const cicle = new mars3d.graphic.CirclePrimitive({
    position: point,
    style: {
      radius: 16000,
      material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.CircleWave, {
        color: "rgba(0,255,255,0.6)",
        count: 2,
        speed: 10
      })
    }
  })
  graphicLayer.addGraphic(cicle)
}
 
// 添加周边的圆圈刻度尺等对象
function addOutCircle(graphicLayer) {
  const arrImg = [
    {
      // 刻度
      image: "./img/icon/calib.png",
      positions: [
        [113.564329, 35.654741],
        [120.802219, 28.844016]
      ]
    },
    {
      // 刻度尺
      image: "./img/icon/calib-value.png",
      positions: [
        [114.162597, 29.256489],
        [120.216593, 35.055444]
      ]
    },
    {
      // 方向
      image: "./img/icon/calib-dir.png",
      positions: [
        [114.162597, 29.256489],
        [120.216593, 35.055444]
      ]
    }
  ]
 
  for (let i = 0; i < arrImg.length; i++) {
    const item = arrImg[i]
    const primitive = new mars3d.graphic.RectanglePrimitive({
      positions: item.positions,
      style: {
        materialType: mars3d.MaterialType.Image2,
        image: item.image,
        opacity: 0.4
      }
    })
    graphicLayer.addGraphic(primitive)
  }
 
  // 自转的半椭圆
  // let rotation = Cesium.Math.toRadians(50);
  // function getRotationValue() {
  //   rotation += 0.005;
  //   return rotation;
  // }
  // let primitive1 = new mars3d.graphic.RectangleEntity({
  //   positions: [
  //     [114.642444, 34.789658],
  //     [119.814361, 29.425181],
  //   ],
  //   style: {
  //     materialType: mars3d.MaterialType.Image2,
  //     image: "./img/icon/calib-semicircle.png",
  //     opacity: 0.2,
  //     clampToGround: true,
  //     rotation: new Cesium.CallbackProperty(getRotationValue, false),
  //     stRotation: new Cesium.CallbackProperty(getRotationValue, false),
  //   },
  // });
  // graphicLayer.addGraphic(primitive1);
}