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
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
 
let graphic
let waterLayer
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 29.791718, lng: 121.479859, alt: 29, heading: 187, pitch: -14 }
  },
  layers: [
    {
      type: "3dtiles",
      name: "整体模型",
      url: "//data.mars3d.cn/3dtiles/max-fsdzm/tileset.json",
      position: { alt: 15.2 },
      maximumScreenSpaceError: 1,
      maximumMemoryUsage: 1024,
      show: true
    },
    {
      type: "geojson",
      name: "河流(面状)",
      url: "//data.mars3d.cn/file/geojson/hedao-nei.json",
      symbol: {
        type: "waterCombine",
        styleOptions: {
          height: 17, // 水面高度
          normalMap: "img/textures/waterNormals.jpg", // 水正常扰动的法线图
          frequency: 8000.0, // 控制波数的数字。
          animationSpeed: 0.02, // 控制水的动画速度的数字。
          amplitude: 5.0, // 控制水波振幅的数字。
          specularIntensity: 0.8, // 控制镜面反射强度的数字。
          baseWaterColor: "#006ab4", // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4
          blendColor: "#006ab4", // 从水中混合到非水域时使用的rgba颜色对象。
          opacity: 0.4, // 透明度
          clampToGround: false // 是否贴地
        }
      },
      show: true
    }
  ]
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录首次创建的map
 
  waterLayer = new mars3d.layer.GeoJsonLayer({
    name: "河流(面状)",
    url: "//data.mars3d.cn/file/geojson/hedao-wai.json",
    symbol: {
      type: "waterCombine",
      styleOptions: {
        height: 16, // 水面高度
        normalMap: "img/textures/waterNormals.jpg", // 水正常扰动的法线图
        frequency: 8000.0, // 控制波数的数字。
        animationSpeed: 0.02, // 控制水的动画速度的数字。
        amplitude: 5.0, // 控制水波振幅的数字。
        specularIntensity: 0.8, // 控制镜面反射强度的数字。
        baseWaterColor: "#006ab4", // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4
        blendColor: "#006ab4", // 从水中混合到非水域时使用的rgba颜色对象。
        opacity: 0.4, // 透明度
        clampToGround: false // 是否贴地
      }
    }
  })
  map.addLayer(waterLayer)
 
  // 绑定事件
  waterLayer.on(mars3d.EventType.load, function (event) {
    console.log("数据加载完成", event)
  })
  waterLayer.on(mars3d.EventType.click, function (event) {
    console.log("单击了图层", event)
  })
 
  // 闸门的控制
  graphic = new mars3d.graphic.ModelEntity({
    name: "闸门",
    position: [121.479813, 29.791278, 16],
    style: {
      url: "//data.mars3d.cn/gltf/mars/zhamen.glb",
      heading: 105
    }
  })
  map.graphicLayer.addGraphic(graphic)
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
const minHeight = 16
let timeInv
// 高度更新
 function updateHeight(height) {
  graphic.height = height // 阀门高度
  waterLayer.eachGraphic((graphic) => {
    graphic.updateHeight(height) // 水域高度变化
  })
}
 
/**
 * 开启阀门
 *
 * @export
 * @param {number} height  阀门高度  单位: m
 * @param {number} time //时间 单位:s
 * @returns {void} 无
 */
export function openZm(height, time) {
  let thisHeight = minHeight // 当前高度
  const endHeight = height + minHeight // 结束高度
 
  const step = time / 0.1 // 步长
  const stepHeight = (endHeight - thisHeight) / step // 每次阀门、水面上移高度
 
  // 再次点击"开启"时从当前位置开启
  updateHeight(thisHeight)
 
  clearInterval(timeInv)
  timeInv = setInterval(() => {
    thisHeight += stepHeight // 上移后的当前高度,相当于时实更新
 
    if (thisHeight >= endHeight) {
      thisHeight = endHeight
      clearInterval(timeInv) // 清除定时器,当前阀门的高度值等于结束时阀门的高度值时,停止上移,关闭定时器
    }
    updateHeight(thisHeight)
  }, 100)
}
 
/**
 * 关闭阀门
 *
 * @export
 * @param {number} height  阀门高度 单位: m
 * @param {number} time //时间 单位:s
 * @returns {void} 无
 */
export function closeZm(height, time) {
  let thisHeight = height + minHeight
  const endHeight = minHeight
 
  const step = time / 0.1
  const stepHeight = (endHeight - thisHeight) / step
 
  updateHeight(thisHeight)
 
  clearInterval(timeInv)
  timeInv = setInterval(() => {
    thisHeight += stepHeight
 
    if (thisHeight <= endHeight) {
      thisHeight = endHeight
      clearInterval(timeInv)
    }
    updateHeight(thisHeight)
  }, 100)
}