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
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 31.810597, lng: 117.220617, alt: 1038, heading: 13, pitch: -30 }
  },
  terrain: {
    show: false
  },
  // 方式1:在创建地球前的参数中配置
  layers: [
    {
      name: "兴趣点",
      type: "arcgis_wfs",
      url: "//server.mars3d.cn/arcgis/rest/services/mars/hefei/MapServer/1",
      where: " 1=1 ",
      minimumLevel: 16,
      symbol: {
        type: "billboardP",
        styleOptions: {
          image: "img/marker/mark3.png",
          scale: 0.7,
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
          clampToGround: true,
          label: {
            text: "{NAME}",
            font_size: 15,
            color: "#ffffff",
            outline: true,
            outlineColor: "#000000",
            pixelOffsetY: -30,
            distanceDisplayCondition: true,
            distanceDisplayCondition_far: 1500,
            distanceDisplayCondition_near: 0
          }
        }
      },
      popup: "名称:{NAME}<br />地址:{address}",
      show: true
    }
  ]
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录首次创建的map
 
  map.basemap = 2017 // 蓝色底图
 
  // 添加演示图层
  addArcGisWFSLayer1()
  addArcGisWFSLayer2()
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
// 方式2:在创建地球后调用addLayer添加图层(直接new对应type类型的图层类)
function addArcGisWFSLayer1() {
  const changeLevel = 15
 
  // 瓦片图,对比参考用
  const tileLayer = new mars3d.layer.ArcGisLayer({
    name: "瓦片图层",
    url: "//server.mars3d.cn/arcgis/rest/services/mars/hefei/MapServer",
    layers: "37",
    popup: "数据:瓦片图层<br />名称:{NAME}<br />层数:{floor}",
    maximumLevel: changeLevel - 1,
    maximumTerrainLevel: changeLevel - 1
  })
  map.addLayer(tileLayer)
 
  // 动态矢量图
  const wfsLayer = new mars3d.layer.ArcGisWfsLayer({
    name: "建筑物面矢量图层",
    url: "//server.mars3d.cn/arcgis/rest/services/mars/hefei/MapServer/37",
    where: " NAME like '%合肥%' ",
    minimumLevel: changeLevel,
    symbol: {
      type: "polygonP",
      styleOptions: {
        color: "#FED976",
        outline: false,
        opacity: 1
      }
    },
    buildings: {
      cloumn: "floor"
    },
    debuggerTileInfo: false,
    popup: "数据:矢量图层<br />名称:{NAME}<br />层数:{floor}"
  })
  map.addLayer(wfsLayer)
 
  // 绑定事件
  wfsLayer.on(mars3d.EventType.loadConfig, function (event) {
    console.log("加载完成服务信息", event)
  })
 
  wfsLayer.on(mars3d.EventType.click, function (event) {
    console.log("单击了图层", event)
  })
 
  let timeTik
  wfsLayer.on(mars3d.EventType.update, function (event) {
    console.log(`图层内数据更新了`, event)
 
    clearTimeout(timeTik)
    timeTik = setTimeout(() => {
      if (!wfsLayer.isLoading) {
        console.log(`本批次数据加载完成`)
      }
    }, 1000)
  })
 
  setTimeout(function () {
    // 测试更换条件
    wfsLayer.setWhere(" 1=1 ")
  }, 10000)
}
 
// 适合少于1000条的少量数据,一次性请求加载
function addArcGisWFSLayer2() {
  // 一次性加载的wfs图层
  const wfsLayer = new mars3d.layer.ArcGisWfsSingleLayer({
    name: "合肥边界线",
    url: "//server.mars3d.cn/arcgis/rest/services/mars/hefei/MapServer/41",
    symbol: {
      type: "polyline",
      styleOptions: {
        color: "#39E09B",
        width: 8,
        opacity: 0.8
      }
    },
    popup: "all"
  })
  map.addLayer(wfsLayer)
}
 
// 图层状态 在组件中进行管理的图层
export function getManagerLayer() {
  return map.getLayer("建筑物面矢量图层", "name")
}