@aibee/crc-bmap 0.0.75 → 0.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/example/index.css +22 -22
- package/example/index.html +63 -63
- package/example/src/main.ts +581 -577
- package/example/vite.config.ts +28 -28
- package/lib/bmap.cjs.min.js +1 -1
- package/lib/bmap.cjs.min.js.map +3 -3
- package/lib/bmap.esm.js +23 -11
- package/lib/bmap.esm.js.map +3 -3
- package/lib/bmap.esm.min.js +1 -1
- package/lib/bmap.esm.min.js.map +3 -3
- package/lib/bmap.min.js +1 -1
- package/lib/bmap.min.js.map +3 -3
- package/lib/src/context.d.ts +2 -0
- package/lib/src/operations/hover/hover-helper.d.ts +2 -1
- package/package.json +47 -47
package/example/src/main.ts
CHANGED
|
@@ -1,577 +1,581 @@
|
|
|
1
|
-
import { BMap, Graphic, Overlay, SelectBox } from '../../src'
|
|
2
|
-
import Stats from 'three/examples/jsm/libs/stats.module.js'
|
|
3
|
-
|
|
4
|
-
// 创建性能监视器
|
|
5
|
-
let stats = new Stats()
|
|
6
|
-
|
|
7
|
-
// 设置监视器面板,传入面板id(0: fps, 1: ms, 2: mb)
|
|
8
|
-
stats.showPanel(0)
|
|
9
|
-
|
|
10
|
-
// 设置监视器位置
|
|
11
|
-
stats.dom.style.position = 'absolute'
|
|
12
|
-
stats.dom.style.left = '10vh'
|
|
13
|
-
stats.dom.style.top = '10vh'
|
|
14
|
-
stats.dom.style.zIndex = "100"
|
|
15
|
-
|
|
16
|
-
// 将监视器添加到页面中
|
|
17
|
-
document.body.appendChild(stats.dom)
|
|
18
|
-
|
|
19
|
-
function render() {
|
|
20
|
-
// 更新帧数
|
|
21
|
-
stats.update()
|
|
22
|
-
requestAnimationFrame(render)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
render()
|
|
26
|
-
|
|
27
|
-
const bmap = new BMap(document.getElementById('app')!, {
|
|
28
|
-
apiInfo: {
|
|
29
|
-
headers: {
|
|
30
|
-
"Authorization": localStorage.getItem("Authorization_token") || "Bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzNzIwYjNhOGU3MGM0NGU3YTdkYzdiMTE4NDNhZjFhMyIsInN1YiI6IllVV0VJWEkiLCJpc3MiOiJtaXhjIiwiaWF0IjoxNzAwNzI2NTA4fQ.su7smca9cVeMQ9u-NyT_3NKa6kYfoLIGsOtNZLOnXXI"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
resizeObserver: true
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
(async () => {
|
|
37
|
-
// 加载图元数据
|
|
38
|
-
await bmap.load({
|
|
39
|
-
brand: "crc",
|
|
40
|
-
project: "0202A501",
|
|
41
|
-
phase: "themixctd01",
|
|
42
|
-
building: "A",
|
|
43
|
-
floor: "L1",
|
|
44
|
-
ts: "2024-01-03",
|
|
45
|
-
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
46
|
-
});
|
|
47
|
-
// 切换楼层
|
|
48
|
-
await bmap.switchFloor({
|
|
49
|
-
brand: "crc",
|
|
50
|
-
project: "0202A501",
|
|
51
|
-
phase: "themixctd01",
|
|
52
|
-
building: "A",
|
|
53
|
-
floor: "L1",
|
|
54
|
-
ts: "2024-01-03",
|
|
55
|
-
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
56
|
-
})
|
|
57
|
-
bmap.changeMapType("3d")
|
|
58
|
-
|
|
59
|
-
const poi = bmap.createGraphicPoi(bmap.getGraphicByNodeId("3e72f56e")!, {
|
|
60
|
-
texts: [{ text: "文字" }],
|
|
61
|
-
icon: "https://robot-vr-public.cdn.bcebos.com/navigation_images/614c4cb0a949526cf91aa42f5e6cb2c9.svg",
|
|
62
|
-
icon_size: [14, 14],
|
|
63
|
-
// background: "#000000",
|
|
64
|
-
icon_border: { width: 2, color: "#000000" }
|
|
65
|
-
})
|
|
66
|
-
// poi!.options.background = "#000000"
|
|
67
|
-
bmap.context.addEventListener("select-graphic", (...args) => {
|
|
68
|
-
console.log(args)
|
|
69
|
-
})
|
|
70
|
-
// bmap.getGraphicByNodeId("700fae09")!.options.strokeWidth = 2;
|
|
71
|
-
// bmap.getGraphicByNodeId("b0846107")!.options.strokeWidth = 0.5;
|
|
72
|
-
// bmap.getGraphicByNodeId("654cf0a2")!.options.fillColor = '#45E583';
|
|
73
|
-
// bmap.getGraphicByNodeId("0b245fa9")!.options.fillColor = '#FFB166';
|
|
74
|
-
// bmap.getGraphicByNodeId("9cd3408c")!.options.fillColor = '#FF4D4D';
|
|
75
|
-
// bmap.getFloorAllGraphics().forEach(graphic => {
|
|
76
|
-
// if (graphic.options.userData.mark) {
|
|
77
|
-
// graphic.options.fillColor = '#F2F6FC'
|
|
78
|
-
// graphic.options.height = 0.1
|
|
79
|
-
// }
|
|
80
|
-
// })
|
|
81
|
-
|
|
82
|
-
// bmap.getGraphicByNodeId("996d97a6")!.options.stroke = false;
|
|
83
|
-
// bmap.getGraphicByNodeId("996d97a6")!.options.height = 0.001;
|
|
84
|
-
// bmap.getGraphicByNodeId("996d97a6")!.options.strokeColor = "#000000";
|
|
85
|
-
// bmap.getGraphicByNodeId("996d97a6")!.options.strokeOpacity = 1;
|
|
86
|
-
|
|
87
|
-
})();
|
|
88
|
-
|
|
89
|
-
const graphicId = "9338ca4b"
|
|
90
|
-
|
|
91
|
-
// 图元点击
|
|
92
|
-
bmap.context.addEventListener('graphic-click', (data) => {
|
|
93
|
-
console.log('graphic-click', data.graphics)
|
|
94
|
-
// const div = document.createElement("div")
|
|
95
|
-
// div.style.cssText = "position: fixed; top: 25%; left: 25%; bottom: 25%; right: 25%; background: red; z-index: 99;"
|
|
96
|
-
// div.addEventListener("click", () => {
|
|
97
|
-
// document.body.removeChild(div)
|
|
98
|
-
// })
|
|
99
|
-
// document.body.appendChild(div)
|
|
100
|
-
data.graphics[0] && bmap.translateElementToCenter(data.graphics[0], 200)
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// 图元选中
|
|
104
|
-
bmap.context.addEventListener('select-graphic', (data) => {
|
|
105
|
-
console.log('select-graphic', data.graphics)
|
|
106
|
-
data.graphics.forEach(item => item.options.fillColor = '#ff0000')
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// poi点击
|
|
110
|
-
bmap.context.addEventListener('poi-click', (data) => {
|
|
111
|
-
console.log('poi-click', data.pois)
|
|
112
|
-
bmap.translateElementToCenter(data.pois[0], 500)
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
(window as any).bmap = bmap;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 显示比例尺
|
|
120
|
-
*/
|
|
121
|
-
const ratioDiv = document.createElement("div")
|
|
122
|
-
ratioDiv.style.cssText = "position: absolute; bottom: 10vh; left: 10vw; z-index: 2; background: blue; color: red;"
|
|
123
|
-
ratioDiv.textContent = "100M";
|
|
124
|
-
document.body.appendChild(ratioDiv)
|
|
125
|
-
bmap.context.addEventListener('change-ratio', ({ px }) => {
|
|
126
|
-
// px 一百米对应的像素点
|
|
127
|
-
let m = 100;
|
|
128
|
-
let scale = 1
|
|
129
|
-
// 让px保持在50-100中间的一个米的整数
|
|
130
|
-
if (px < 50) {
|
|
131
|
-
scale = Math.ceil(100 / px)
|
|
132
|
-
px *= scale
|
|
133
|
-
m *= scale
|
|
134
|
-
} else if (px > 100) {
|
|
135
|
-
scale = Math.floor(px / 100)
|
|
136
|
-
while (m % scale != 0) {
|
|
137
|
-
scale--;
|
|
138
|
-
}
|
|
139
|
-
px /= scale
|
|
140
|
-
m /= scale
|
|
141
|
-
}
|
|
142
|
-
ratioDiv.style.width = `${px}px`;
|
|
143
|
-
ratioDiv.textContent = `${m}米`
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 按钮操作
|
|
148
|
-
*/
|
|
149
|
-
// 修改容器大小
|
|
150
|
-
document.getElementById("changeContainerSize")?.addEventListener('click', () => {
|
|
151
|
-
// 获取legacyId 和 图元 的map
|
|
152
|
-
// const graphic = bmap.getGraphicByNodeId("45f9ff75")!
|
|
153
|
-
// const poi = bmap.createGraphicPoi(graphic, {
|
|
154
|
-
// texts: [
|
|
155
|
-
// { text: "店铺名称" }
|
|
156
|
-
// ]
|
|
157
|
-
// })
|
|
158
|
-
document.getElementById("app1")!.style.width = "500px"
|
|
159
|
-
})
|
|
160
|
-
// 添加poi
|
|
161
|
-
document.getElementById("createPoi")?.addEventListener('click', () => {
|
|
162
|
-
// 获取legacyId 和 图元 的map
|
|
163
|
-
// const graphic = bmap.getGraphicByNodeId("45f9ff75")!
|
|
164
|
-
// const poi = bmap.createGraphicPoi(graphic, {
|
|
165
|
-
// texts: [
|
|
166
|
-
// { text: "店铺名称" }
|
|
167
|
-
// ]
|
|
168
|
-
// })
|
|
169
|
-
const graphics: Graphic[] = bmap.getFloorAllGraphics()
|
|
170
|
-
// bmap.context.control.zoomSpeed = 2
|
|
171
|
-
graphics.forEach(graphic => {
|
|
172
|
-
// 在图元上添加poi
|
|
173
|
-
const poi = bmap.createGraphicPoi(graphic, {
|
|
174
|
-
texts: [{ text: "店铺名称", styles: { fontWeight: "bold" } }]
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
// return
|
|
178
|
-
// 监听放大缩小的变化
|
|
179
|
-
bmap.addEventListener("zoom-change", ({ basicZoom, cameraZoom }) => {
|
|
180
|
-
const zoomScale = cameraZoom / basicZoom
|
|
181
|
-
// console.log(zoomScale, basicZoom, cameraZoom)
|
|
182
|
-
bmap.getPois().forEach(poi => {
|
|
183
|
-
if (zoomScale > 2) {
|
|
184
|
-
poi!.options.texts = [
|
|
185
|
-
{ text: "店铺名称" },
|
|
186
|
-
{ text: "店铺名称" },
|
|
187
|
-
{ text: "店铺名称" },
|
|
188
|
-
{ text: "店铺名称" },
|
|
189
|
-
]
|
|
190
|
-
} else if (zoomScale > 1.6) {
|
|
191
|
-
poi!.options.texts = [
|
|
192
|
-
{ text: "店铺名称" },
|
|
193
|
-
{ text: "店铺名称" },
|
|
194
|
-
{ text: "店铺名称" },
|
|
195
|
-
]
|
|
196
|
-
} else if (zoomScale > 1.3) {
|
|
197
|
-
poi!.options.texts = [
|
|
198
|
-
{ text: "店铺名称" },
|
|
199
|
-
{ text: "店铺名称" },
|
|
200
|
-
]
|
|
201
|
-
} else {
|
|
202
|
-
poi!.options.texts = [
|
|
203
|
-
{ text: "店铺名称" },
|
|
204
|
-
]
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
// 删除poi
|
|
210
|
-
document.getElementById("removePoi")?.addEventListener('click', () => {
|
|
211
|
-
bmap.removePoiById(graphicId)
|
|
212
|
-
})
|
|
213
|
-
// 删除在创建
|
|
214
|
-
document.getElementById("deleteAnCreateGraphic")?.addEventListener('click', () => {
|
|
215
|
-
const graphic = bmap.getGraphicByNodeId(graphicId)!
|
|
216
|
-
console.log(graphic)
|
|
217
|
-
const options = graphic.options
|
|
218
|
-
bmap.deleteGraphic(graphic)
|
|
219
|
-
setTimeout(() => {
|
|
220
|
-
bmap.createGraphicByOptions(options)
|
|
221
|
-
}, 1000)
|
|
222
|
-
})
|
|
223
|
-
// 获取全部图元
|
|
224
|
-
document.getElementById("getAllGraphics")?.addEventListener('click', () => {
|
|
225
|
-
console.log(bmap.getFloorAllGraphics())
|
|
226
|
-
})
|
|
227
|
-
// 添加选中块儿
|
|
228
|
-
document.getElementById("addSelectBox")?.addEventListener('click', () => {
|
|
229
|
-
const selectBox = new SelectBox(bmap.context)
|
|
230
|
-
selectBox.selectGraphic(bmap.getGraphicByNodeId(graphicId)!)
|
|
231
|
-
setTimeout(() => {
|
|
232
|
-
selectBox.setEnable(false)
|
|
233
|
-
}, 1000)
|
|
234
|
-
})
|
|
235
|
-
// 切换楼层
|
|
236
|
-
document.getElementById("switchFloor")?.addEventListener('click', async () => {
|
|
237
|
-
await bmap.load({
|
|
238
|
-
brand: "crc",
|
|
239
|
-
project: "0202A501",
|
|
240
|
-
phase: "themixctd01",
|
|
241
|
-
building: "A",
|
|
242
|
-
floor: "L1",
|
|
243
|
-
ts: "2024-01-12",
|
|
244
|
-
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
245
|
-
|
|
246
|
-
});
|
|
247
|
-
// 切换楼层
|
|
248
|
-
bmap.switchFloor({
|
|
249
|
-
brand: "crc",
|
|
250
|
-
project: "0202A501",
|
|
251
|
-
phase: "themixctd01",
|
|
252
|
-
building: "A",
|
|
253
|
-
floor: "L1",
|
|
254
|
-
ts: "2024-01-12",
|
|
255
|
-
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
256
|
-
})
|
|
257
|
-
})
|
|
258
|
-
// hover显示覆盖物
|
|
259
|
-
document.getElementById("hoverShowOverlay")?.addEventListener('click', async () => {
|
|
260
|
-
const overlaysMap = new Map<Graphic, Overlay>()
|
|
261
|
-
const overlayState = new Map<Overlay, { graphicHover: boolean, divHover: boolean }>()
|
|
262
|
-
bmap.context.addEventListener("hover", ({ graphics }) => {
|
|
263
|
-
// console.log("hover", graphics)
|
|
264
|
-
// overlaysMap.forEach(item => item.dispose())
|
|
265
|
-
// graphics.forEach(graphic => {
|
|
266
|
-
// const overlay = new Overlay(bmap.context)
|
|
267
|
-
// overlay.bindElement(graphic)
|
|
268
|
-
// const div = document.createElement("div")
|
|
269
|
-
// div.style.cssText = "width: 100px; height: 100px; background: red;transform: translate(-50%, -100%);"
|
|
270
|
-
// div.textContent = "显示一段文本"
|
|
271
|
-
// })
|
|
272
|
-
// 没有hover的元素要删除
|
|
273
|
-
overlaysMap.forEach((overlay, graphic) => {
|
|
274
|
-
if (!graphics.includes(graphic)) {
|
|
275
|
-
// overlay.dispose();
|
|
276
|
-
// overlaysMap.delete(graphic)
|
|
277
|
-
overlayState.get(overlay)!.graphicHover = false
|
|
278
|
-
window.requestAnimationFrame(() => {
|
|
279
|
-
// 鼠标即不在div上也不再graphic上就销毁这个overlay
|
|
280
|
-
if (!overlayState.get(overlay)!.divHover) {
|
|
281
|
-
overlay.dispose();
|
|
282
|
-
overlaysMap.delete(graphic)
|
|
283
|
-
}
|
|
284
|
-
})
|
|
285
|
-
}
|
|
286
|
-
})
|
|
287
|
-
graphics.forEach(graphic => {
|
|
288
|
-
if (overlaysMap.has(graphic)) {
|
|
289
|
-
return
|
|
290
|
-
}
|
|
291
|
-
const overlay = new Overlay(bmap.context, { autoUpdate: false });
|
|
292
|
-
overlay.addEventListener(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
overlayState.get(overlay)
|
|
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
|
-
// TODO 获取图源的资源id
|
|
338
|
-
})
|
|
339
|
-
document.getElementById("
|
|
340
|
-
graphic.options.
|
|
341
|
-
// TODO 获取图源的资源id 然后获取poi 还需要修改对应poi的高度 airHeight + height
|
|
342
|
-
})
|
|
343
|
-
document.getElementById("
|
|
344
|
-
graphic.options.
|
|
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
|
-
bmap.
|
|
382
|
-
})
|
|
383
|
-
document.getElementById("
|
|
384
|
-
bmap.
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
document.getElementById("
|
|
409
|
-
bmap.context.
|
|
410
|
-
bmap.context.
|
|
411
|
-
})
|
|
412
|
-
document.getElementById("
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
document.getElementById("
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
overlay
|
|
442
|
-
overlay.
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
bmap.
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
bmap.
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
// TODO
|
|
478
|
-
//
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
// TODO
|
|
482
|
-
//
|
|
483
|
-
//
|
|
484
|
-
//
|
|
485
|
-
//
|
|
486
|
-
// poi.options.
|
|
487
|
-
|
|
488
|
-
// TODO
|
|
489
|
-
//
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
// TODO
|
|
493
|
-
// const overlay = new
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
// TODO
|
|
497
|
-
// const overlay = new
|
|
498
|
-
// overlay.position.copy(position)
|
|
499
|
-
// overlay.
|
|
500
|
-
// TODO
|
|
501
|
-
// bmap.
|
|
502
|
-
//
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
//
|
|
507
|
-
// TODO
|
|
508
|
-
//
|
|
509
|
-
// TODO
|
|
510
|
-
// bmap.
|
|
511
|
-
// TODO
|
|
512
|
-
//
|
|
513
|
-
// TODO
|
|
514
|
-
//
|
|
515
|
-
//
|
|
516
|
-
//
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
1
|
+
import { BMap, Graphic, Overlay, SelectBox } from '../../src'
|
|
2
|
+
import Stats from 'three/examples/jsm/libs/stats.module.js'
|
|
3
|
+
|
|
4
|
+
// 创建性能监视器
|
|
5
|
+
let stats = new Stats()
|
|
6
|
+
|
|
7
|
+
// 设置监视器面板,传入面板id(0: fps, 1: ms, 2: mb)
|
|
8
|
+
stats.showPanel(0)
|
|
9
|
+
|
|
10
|
+
// 设置监视器位置
|
|
11
|
+
stats.dom.style.position = 'absolute'
|
|
12
|
+
stats.dom.style.left = '10vh'
|
|
13
|
+
stats.dom.style.top = '10vh'
|
|
14
|
+
stats.dom.style.zIndex = "100"
|
|
15
|
+
|
|
16
|
+
// 将监视器添加到页面中
|
|
17
|
+
document.body.appendChild(stats.dom)
|
|
18
|
+
|
|
19
|
+
function render() {
|
|
20
|
+
// 更新帧数
|
|
21
|
+
stats.update()
|
|
22
|
+
requestAnimationFrame(render)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
render()
|
|
26
|
+
|
|
27
|
+
const bmap = new BMap(document.getElementById('app')!, {
|
|
28
|
+
apiInfo: {
|
|
29
|
+
headers: {
|
|
30
|
+
"Authorization": localStorage.getItem("Authorization_token") || "Bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzNzIwYjNhOGU3MGM0NGU3YTdkYzdiMTE4NDNhZjFhMyIsInN1YiI6IllVV0VJWEkiLCJpc3MiOiJtaXhjIiwiaWF0IjoxNzAwNzI2NTA4fQ.su7smca9cVeMQ9u-NyT_3NKa6kYfoLIGsOtNZLOnXXI"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
resizeObserver: true
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
(async () => {
|
|
37
|
+
// 加载图元数据
|
|
38
|
+
await bmap.load({
|
|
39
|
+
brand: "crc",
|
|
40
|
+
project: "0202A501",
|
|
41
|
+
phase: "themixctd01",
|
|
42
|
+
building: "A",
|
|
43
|
+
floor: "L1",
|
|
44
|
+
ts: "2024-01-03",
|
|
45
|
+
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
46
|
+
});
|
|
47
|
+
// 切换楼层
|
|
48
|
+
await bmap.switchFloor({
|
|
49
|
+
brand: "crc",
|
|
50
|
+
project: "0202A501",
|
|
51
|
+
phase: "themixctd01",
|
|
52
|
+
building: "A",
|
|
53
|
+
floor: "L1",
|
|
54
|
+
ts: "2024-01-03",
|
|
55
|
+
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
56
|
+
})
|
|
57
|
+
bmap.changeMapType("3d")
|
|
58
|
+
|
|
59
|
+
const poi = bmap.createGraphicPoi(bmap.getGraphicByNodeId("3e72f56e")!, {
|
|
60
|
+
texts: [{ text: "文字" }],
|
|
61
|
+
icon: "https://robot-vr-public.cdn.bcebos.com/navigation_images/614c4cb0a949526cf91aa42f5e6cb2c9.svg",
|
|
62
|
+
icon_size: [14, 14],
|
|
63
|
+
// background: "#000000",
|
|
64
|
+
icon_border: { width: 2, color: "#000000" }
|
|
65
|
+
})
|
|
66
|
+
// poi!.options.background = "#000000"
|
|
67
|
+
bmap.context.addEventListener("select-graphic", (...args) => {
|
|
68
|
+
console.log(args)
|
|
69
|
+
})
|
|
70
|
+
// bmap.getGraphicByNodeId("700fae09")!.options.strokeWidth = 2;
|
|
71
|
+
// bmap.getGraphicByNodeId("b0846107")!.options.strokeWidth = 0.5;
|
|
72
|
+
// bmap.getGraphicByNodeId("654cf0a2")!.options.fillColor = '#45E583';
|
|
73
|
+
// bmap.getGraphicByNodeId("0b245fa9")!.options.fillColor = '#FFB166';
|
|
74
|
+
// bmap.getGraphicByNodeId("9cd3408c")!.options.fillColor = '#FF4D4D';
|
|
75
|
+
// bmap.getFloorAllGraphics().forEach(graphic => {
|
|
76
|
+
// if (graphic.options.userData.mark) {
|
|
77
|
+
// graphic.options.fillColor = '#F2F6FC'
|
|
78
|
+
// graphic.options.height = 0.1
|
|
79
|
+
// }
|
|
80
|
+
// })
|
|
81
|
+
|
|
82
|
+
// bmap.getGraphicByNodeId("996d97a6")!.options.stroke = false;
|
|
83
|
+
// bmap.getGraphicByNodeId("996d97a6")!.options.height = 0.001;
|
|
84
|
+
// bmap.getGraphicByNodeId("996d97a6")!.options.strokeColor = "#000000";
|
|
85
|
+
// bmap.getGraphicByNodeId("996d97a6")!.options.strokeOpacity = 1;
|
|
86
|
+
|
|
87
|
+
})();
|
|
88
|
+
|
|
89
|
+
const graphicId = "9338ca4b"
|
|
90
|
+
|
|
91
|
+
// 图元点击
|
|
92
|
+
bmap.context.addEventListener('graphic-click', (data) => {
|
|
93
|
+
console.log('graphic-click', data.graphics)
|
|
94
|
+
// const div = document.createElement("div")
|
|
95
|
+
// div.style.cssText = "position: fixed; top: 25%; left: 25%; bottom: 25%; right: 25%; background: red; z-index: 99;"
|
|
96
|
+
// div.addEventListener("click", () => {
|
|
97
|
+
// document.body.removeChild(div)
|
|
98
|
+
// })
|
|
99
|
+
// document.body.appendChild(div)
|
|
100
|
+
data.graphics[0] && bmap.translateElementToCenter(data.graphics[0], 200)
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// 图元选中
|
|
104
|
+
bmap.context.addEventListener('select-graphic', (data) => {
|
|
105
|
+
console.log('select-graphic', data.graphics)
|
|
106
|
+
data.graphics.forEach(item => item.options.fillColor = '#ff0000')
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// poi点击
|
|
110
|
+
bmap.context.addEventListener('poi-click', (data) => {
|
|
111
|
+
console.log('poi-click', data.pois)
|
|
112
|
+
bmap.translateElementToCenter(data.pois[0], 500)
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
(window as any).bmap = bmap;
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 显示比例尺
|
|
120
|
+
*/
|
|
121
|
+
const ratioDiv = document.createElement("div")
|
|
122
|
+
ratioDiv.style.cssText = "position: absolute; bottom: 10vh; left: 10vw; z-index: 2; background: blue; color: red;"
|
|
123
|
+
ratioDiv.textContent = "100M";
|
|
124
|
+
document.body.appendChild(ratioDiv)
|
|
125
|
+
bmap.context.addEventListener('change-ratio', ({ px }) => {
|
|
126
|
+
// px 一百米对应的像素点
|
|
127
|
+
let m = 100;
|
|
128
|
+
let scale = 1
|
|
129
|
+
// 让px保持在50-100中间的一个米的整数
|
|
130
|
+
if (px < 50) {
|
|
131
|
+
scale = Math.ceil(100 / px)
|
|
132
|
+
px *= scale
|
|
133
|
+
m *= scale
|
|
134
|
+
} else if (px > 100) {
|
|
135
|
+
scale = Math.floor(px / 100)
|
|
136
|
+
while (m % scale != 0) {
|
|
137
|
+
scale--;
|
|
138
|
+
}
|
|
139
|
+
px /= scale
|
|
140
|
+
m /= scale
|
|
141
|
+
}
|
|
142
|
+
ratioDiv.style.width = `${px}px`;
|
|
143
|
+
ratioDiv.textContent = `${m}米`
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 按钮操作
|
|
148
|
+
*/
|
|
149
|
+
// 修改容器大小
|
|
150
|
+
document.getElementById("changeContainerSize")?.addEventListener('click', () => {
|
|
151
|
+
// 获取legacyId 和 图元 的map
|
|
152
|
+
// const graphic = bmap.getGraphicByNodeId("45f9ff75")!
|
|
153
|
+
// const poi = bmap.createGraphicPoi(graphic, {
|
|
154
|
+
// texts: [
|
|
155
|
+
// { text: "店铺名称" }
|
|
156
|
+
// ]
|
|
157
|
+
// })
|
|
158
|
+
document.getElementById("app1")!.style.width = "500px"
|
|
159
|
+
})
|
|
160
|
+
// 添加poi
|
|
161
|
+
document.getElementById("createPoi")?.addEventListener('click', () => {
|
|
162
|
+
// 获取legacyId 和 图元 的map
|
|
163
|
+
// const graphic = bmap.getGraphicByNodeId("45f9ff75")!
|
|
164
|
+
// const poi = bmap.createGraphicPoi(graphic, {
|
|
165
|
+
// texts: [
|
|
166
|
+
// { text: "店铺名称" }
|
|
167
|
+
// ]
|
|
168
|
+
// })
|
|
169
|
+
const graphics: Graphic[] = bmap.getFloorAllGraphics()
|
|
170
|
+
// bmap.context.control.zoomSpeed = 2
|
|
171
|
+
graphics.forEach(graphic => {
|
|
172
|
+
// 在图元上添加poi
|
|
173
|
+
const poi = bmap.createGraphicPoi(graphic, {
|
|
174
|
+
texts: [{ text: "店铺名称", styles: { fontWeight: "bold" } }]
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
// return
|
|
178
|
+
// 监听放大缩小的变化
|
|
179
|
+
bmap.addEventListener("zoom-change", ({ basicZoom, cameraZoom }) => {
|
|
180
|
+
const zoomScale = cameraZoom / basicZoom
|
|
181
|
+
// console.log(zoomScale, basicZoom, cameraZoom)
|
|
182
|
+
bmap.getPois().forEach(poi => {
|
|
183
|
+
if (zoomScale > 2) {
|
|
184
|
+
poi!.options.texts = [
|
|
185
|
+
{ text: "店铺名称" },
|
|
186
|
+
{ text: "店铺名称" },
|
|
187
|
+
{ text: "店铺名称" },
|
|
188
|
+
{ text: "店铺名称" },
|
|
189
|
+
]
|
|
190
|
+
} else if (zoomScale > 1.6) {
|
|
191
|
+
poi!.options.texts = [
|
|
192
|
+
{ text: "店铺名称" },
|
|
193
|
+
{ text: "店铺名称" },
|
|
194
|
+
{ text: "店铺名称" },
|
|
195
|
+
]
|
|
196
|
+
} else if (zoomScale > 1.3) {
|
|
197
|
+
poi!.options.texts = [
|
|
198
|
+
{ text: "店铺名称" },
|
|
199
|
+
{ text: "店铺名称" },
|
|
200
|
+
]
|
|
201
|
+
} else {
|
|
202
|
+
poi!.options.texts = [
|
|
203
|
+
{ text: "店铺名称" },
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
// 删除poi
|
|
210
|
+
document.getElementById("removePoi")?.addEventListener('click', () => {
|
|
211
|
+
bmap.removePoiById(graphicId)
|
|
212
|
+
})
|
|
213
|
+
// 删除在创建
|
|
214
|
+
document.getElementById("deleteAnCreateGraphic")?.addEventListener('click', () => {
|
|
215
|
+
const graphic = bmap.getGraphicByNodeId(graphicId)!
|
|
216
|
+
console.log(graphic)
|
|
217
|
+
const options = graphic.options
|
|
218
|
+
bmap.deleteGraphic(graphic)
|
|
219
|
+
setTimeout(() => {
|
|
220
|
+
bmap.createGraphicByOptions(options)
|
|
221
|
+
}, 1000)
|
|
222
|
+
})
|
|
223
|
+
// 获取全部图元
|
|
224
|
+
document.getElementById("getAllGraphics")?.addEventListener('click', () => {
|
|
225
|
+
console.log(bmap.getFloorAllGraphics())
|
|
226
|
+
})
|
|
227
|
+
// 添加选中块儿
|
|
228
|
+
document.getElementById("addSelectBox")?.addEventListener('click', () => {
|
|
229
|
+
const selectBox = new SelectBox(bmap.context)
|
|
230
|
+
selectBox.selectGraphic(bmap.getGraphicByNodeId(graphicId)!)
|
|
231
|
+
setTimeout(() => {
|
|
232
|
+
selectBox.setEnable(false)
|
|
233
|
+
}, 1000)
|
|
234
|
+
})
|
|
235
|
+
// 切换楼层
|
|
236
|
+
document.getElementById("switchFloor")?.addEventListener('click', async () => {
|
|
237
|
+
await bmap.load({
|
|
238
|
+
brand: "crc",
|
|
239
|
+
project: "0202A501",
|
|
240
|
+
phase: "themixctd01",
|
|
241
|
+
building: "A",
|
|
242
|
+
floor: "L1",
|
|
243
|
+
ts: "2024-01-12",
|
|
244
|
+
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
245
|
+
|
|
246
|
+
});
|
|
247
|
+
// 切换楼层
|
|
248
|
+
bmap.switchFloor({
|
|
249
|
+
brand: "crc",
|
|
250
|
+
project: "0202A501",
|
|
251
|
+
phase: "themixctd01",
|
|
252
|
+
building: "A",
|
|
253
|
+
floor: "L1",
|
|
254
|
+
ts: "2024-01-12",
|
|
255
|
+
resource_type_list: [1, 2, 3, 4, 6].join(",")
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
// hover显示覆盖物
|
|
259
|
+
document.getElementById("hoverShowOverlay")?.addEventListener('click', async () => {
|
|
260
|
+
const overlaysMap = new Map<Graphic, Overlay>()
|
|
261
|
+
const overlayState = new Map<Overlay, { graphicHover: boolean, divHover: boolean }>()
|
|
262
|
+
bmap.context.addEventListener("hover", ({ graphics }) => {
|
|
263
|
+
// console.log("hover", graphics)
|
|
264
|
+
// overlaysMap.forEach(item => item.dispose())
|
|
265
|
+
// graphics.forEach(graphic => {
|
|
266
|
+
// const overlay = new Overlay(bmap.context)
|
|
267
|
+
// overlay.bindElement(graphic)
|
|
268
|
+
// const div = document.createElement("div")
|
|
269
|
+
// div.style.cssText = "width: 100px; height: 100px; background: red;transform: translate(-50%, -100%);"
|
|
270
|
+
// div.textContent = "显示一段文本"
|
|
271
|
+
// })
|
|
272
|
+
// 没有hover的元素要删除
|
|
273
|
+
overlaysMap.forEach((overlay, graphic) => {
|
|
274
|
+
if (!graphics.includes(graphic)) {
|
|
275
|
+
// overlay.dispose();
|
|
276
|
+
// overlaysMap.delete(graphic)
|
|
277
|
+
overlayState.get(overlay)!.graphicHover = false
|
|
278
|
+
window.requestAnimationFrame(() => {
|
|
279
|
+
// 鼠标即不在div上也不再graphic上就销毁这个overlay
|
|
280
|
+
if (!overlayState.get(overlay)!.divHover) {
|
|
281
|
+
overlay.dispose();
|
|
282
|
+
overlaysMap.delete(graphic)
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
graphics.forEach(graphic => {
|
|
288
|
+
if (overlaysMap.has(graphic)) {
|
|
289
|
+
return
|
|
290
|
+
}
|
|
291
|
+
const overlay = new Overlay(bmap.context, { autoUpdate: false });
|
|
292
|
+
overlay.addEventListener(
|
|
293
|
+
"update-position",
|
|
294
|
+
({ x, y, height }: { x: number; y: number; height: number }) => {
|
|
295
|
+
overlay.div.style.transform = `translate3d(calc(${x}px - 50%), calc(${
|
|
296
|
+
-height + y - 20
|
|
297
|
+
}px - 100%), 0)`;
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
overlay.bindElement(graphic)
|
|
301
|
+
const div = document.createElement("div")
|
|
302
|
+
// console.log(overlay)
|
|
303
|
+
div.style.cssText = "width: 100px; height: 100px; background: red;point-event: none; "
|
|
304
|
+
div.textContent = "显示一段文本"
|
|
305
|
+
overlay.div.addEventListener("mouseover", () => {
|
|
306
|
+
console.log("进入额")
|
|
307
|
+
overlayState.get(overlay)!.divHover = true
|
|
308
|
+
console.log(overlayState.get(overlay))
|
|
309
|
+
})
|
|
310
|
+
overlay.div.addEventListener("mouseout", () => {
|
|
311
|
+
console.log("移除了")
|
|
312
|
+
overlayState.get(overlay)!.divHover = false
|
|
313
|
+
if (!overlayState.get(overlay)!.graphicHover) {
|
|
314
|
+
overlay.dispose();
|
|
315
|
+
overlaysMap.delete(graphic)
|
|
316
|
+
}
|
|
317
|
+
})
|
|
318
|
+
overlay.div.appendChild(div)
|
|
319
|
+
overlaysMap.set(graphic, overlay)
|
|
320
|
+
overlayState.set(overlay, {graphicHover: true, divHover: false})
|
|
321
|
+
})
|
|
322
|
+
})
|
|
323
|
+
})
|
|
324
|
+
document.getElementById("changeGraphicColor")?.addEventListener('click', () => {
|
|
325
|
+
graphic.options.fillColor = "#000fff";
|
|
326
|
+
})
|
|
327
|
+
document.getElementById("changeGraphicOpacity")?.addEventListener('click', () => {
|
|
328
|
+
graphic.options.fillOpacity = 0.5;
|
|
329
|
+
})
|
|
330
|
+
document.getElementById("changeGraphicBorder")?.addEventListener('click', () => {
|
|
331
|
+
graphic.options.strokeColor = "#00ff00";
|
|
332
|
+
})
|
|
333
|
+
document.getElementById("changeGraphicBorderOpacity")?.addEventListener('click', () => {
|
|
334
|
+
graphic.options.strokeOpacity = 0.5;
|
|
335
|
+
})
|
|
336
|
+
document.getElementById("changeGraphicHighlight")?.addEventListener('click', () => {
|
|
337
|
+
// TODO 获取图源的资源id 在graphicLayer 和 poiLayer 中判断不是这些资源id的都改小透明度,是的透明度都设置成1
|
|
338
|
+
})
|
|
339
|
+
document.getElementById("changeGraphicAirHeight")?.addEventListener('click', () => {
|
|
340
|
+
graphic.options.airHeight = 10
|
|
341
|
+
// TODO 获取图源的资源id 然后获取poi 还需要修改对应poi的高度 airHeight + height
|
|
342
|
+
})
|
|
343
|
+
document.getElementById("changeGraphicHeight")?.addEventListener('click', () => {
|
|
344
|
+
graphic.options.height = 20
|
|
345
|
+
// TODO 获取图源的资源id 然后获取poi 还需要修改对应poi的高度 airHeight + height
|
|
346
|
+
})
|
|
347
|
+
document.getElementById("changeGraphicVisible")?.addEventListener('click', () => {
|
|
348
|
+
graphic.options.visible = false
|
|
349
|
+
})
|
|
350
|
+
document.getElementById("changePoiIcon")?.addEventListener('click', () => {
|
|
351
|
+
poi.options.icon = 'https://prod-deployment.oss-cn-hangzhou.aliyuncs.com/dd932d4d105e453ea93dd1787dcae6eb_icon-%E5%A4%A7%E5%B1%8F.svg'
|
|
352
|
+
})
|
|
353
|
+
document.getElementById("changePoiText")?.addEventListener('click', () => {
|
|
354
|
+
poi.options.text = '修改后文本'
|
|
355
|
+
})
|
|
356
|
+
document.getElementById("changePoiVisible")?.addEventListener('click', () => {
|
|
357
|
+
bmap.context.currentFloor?.poiLayer.removePoi(poi)
|
|
358
|
+
})
|
|
359
|
+
document.getElementById("changeLightColor")?.addEventListener('click', () => {
|
|
360
|
+
bmap.context.changeAmbientLightColor(0xcccccc)
|
|
361
|
+
})
|
|
362
|
+
// document.getElementById("changeShadowLightColor")?.addEventListener('click', () => {
|
|
363
|
+
// bmap.context.shadow.changeLightColor(0x111000)
|
|
364
|
+
// })
|
|
365
|
+
document.getElementById("openMouseDrag")?.addEventListener('click', () => {
|
|
366
|
+
bmap.context.control.enablePan = true
|
|
367
|
+
})
|
|
368
|
+
document.getElementById("closeMouseDrag")?.addEventListener('click', () => {
|
|
369
|
+
bmap.context.control.enablePan = false
|
|
370
|
+
})
|
|
371
|
+
document.getElementById("openMouseZoom")?.addEventListener('click', () => {
|
|
372
|
+
bmap.context.control.enableZoom = true
|
|
373
|
+
})
|
|
374
|
+
document.getElementById("closeMouseZoom")?.addEventListener('click', () => {
|
|
375
|
+
bmap.context.control.enableZoom = false
|
|
376
|
+
})
|
|
377
|
+
document.getElementById("reduceMap")?.addEventListener('click', () => {
|
|
378
|
+
bmap.reduceMap(0.5, 100)
|
|
379
|
+
})
|
|
380
|
+
document.getElementById("enlargeMap")?.addEventListener('click', () => {
|
|
381
|
+
bmap.enlargeMap(0.3, 0)
|
|
382
|
+
})
|
|
383
|
+
document.getElementById("centerView")?.addEventListener('click', () => {
|
|
384
|
+
bmap.resize()
|
|
385
|
+
bmap.resetView()
|
|
386
|
+
})
|
|
387
|
+
document.getElementById("centerGraphic")?.addEventListener('click', () => {
|
|
388
|
+
bmap.context.fitCameraToObject(graphic)
|
|
389
|
+
})
|
|
390
|
+
document.getElementById("change2d")?.addEventListener('click', () => {
|
|
391
|
+
bmap.changeMapType('2d')
|
|
392
|
+
})
|
|
393
|
+
document.getElementById("change3d")?.addEventListener('click', () => {
|
|
394
|
+
bmap.changeMapType('3d')
|
|
395
|
+
})
|
|
396
|
+
document.getElementById("configurePolarShortcutKeys")?.addEventListener('click', () => {
|
|
397
|
+
bmap.configurePolarShortcutKeys(['ControlLeft', 'MetaLeft', 'KeyC'])
|
|
398
|
+
})
|
|
399
|
+
document.getElementById("configureAzimuthShortcutKeys")?.addEventListener('click', () => {
|
|
400
|
+
bmap.configureAzimuthalShortcutKeys(['KeyV'])
|
|
401
|
+
})
|
|
402
|
+
document.getElementById("changeAzimuth")?.addEventListener('click', () => {
|
|
403
|
+
bmap.rotateMap()
|
|
404
|
+
})
|
|
405
|
+
const fn = (data) => {
|
|
406
|
+
console.log(data.graphics, data.pois)
|
|
407
|
+
}
|
|
408
|
+
document.getElementById("openHover")?.addEventListener('click', () => {
|
|
409
|
+
bmap.context.addEventListener("pointer-over", fn)
|
|
410
|
+
bmap.context.addEventListener("pointer-move", fn)
|
|
411
|
+
})
|
|
412
|
+
document.getElementById("closeHover")?.addEventListener('click', () => {
|
|
413
|
+
bmap.context.removeEventListener("pointer-over", fn)
|
|
414
|
+
bmap.context.removeEventListener("pointer-move", fn)
|
|
415
|
+
})
|
|
416
|
+
document.getElementById("mousePickup")?.addEventListener('click', () => {
|
|
417
|
+
// TODO
|
|
418
|
+
})
|
|
419
|
+
document.getElementById("mouseMulPickup")?.addEventListener('click', () => {
|
|
420
|
+
// TODO
|
|
421
|
+
})
|
|
422
|
+
document.getElementById("overlayText")?.addEventListener('click', () => {
|
|
423
|
+
const overlay = new Overlay(bmap.context)
|
|
424
|
+
overlay.bindElement(graphic)
|
|
425
|
+
overlay.div.textContent = "显示覆盖物文本"
|
|
426
|
+
document.getElementById("hideOverlayText")?.addEventListener("click", () => {
|
|
427
|
+
overlay.dispose()
|
|
428
|
+
})
|
|
429
|
+
})
|
|
430
|
+
document.getElementById("clickOverlayText")?.addEventListener('click', () => {
|
|
431
|
+
bmap.context.addEventListener('graphic-click', ({ graphics, position }) => {
|
|
432
|
+
console.log(graphics, position)
|
|
433
|
+
if (position) {
|
|
434
|
+
const overlay = new Overlay(bmap.context)
|
|
435
|
+
overlay.position.copy(position)
|
|
436
|
+
overlay.div.textContent = "点击显示覆盖物文本"
|
|
437
|
+
}
|
|
438
|
+
})
|
|
439
|
+
})
|
|
440
|
+
document.getElementById("overlayImage")?.addEventListener('click', () => {
|
|
441
|
+
const overlay = new Overlay(bmap.context)
|
|
442
|
+
overlay.bindElement(graphic)
|
|
443
|
+
const img = document.createElement("img")
|
|
444
|
+
img.src = "https://robot-vr-public.cdn.bcebos.com/navigation_images/8c591818844be70fd93bd5817c7d3d50.png"
|
|
445
|
+
overlay.div.style.transform = 'translate3d(-50%, -50%, 0)'
|
|
446
|
+
overlay.div.appendChild(img)
|
|
447
|
+
})
|
|
448
|
+
document.getElementById("heatmap")?.addEventListener('click', () => {
|
|
449
|
+
bmap.addHeatmap({
|
|
450
|
+
data: [
|
|
451
|
+
{ x: -100, y: 100, value: 1 },
|
|
452
|
+
{ x: 100, y: 100, value: 100 },
|
|
453
|
+
{ x: 100, y: -100, value: 50 },
|
|
454
|
+
{ x: -100, y: -100, value: 25 },
|
|
455
|
+
],
|
|
456
|
+
max: 100,
|
|
457
|
+
min: 1
|
|
458
|
+
})
|
|
459
|
+
})
|
|
460
|
+
document.getElementById("measureDistance")?.addEventListener('click', async () => {
|
|
461
|
+
bmap.context.currentFloor?.addGround(graphic)
|
|
462
|
+
const distance = await bmap.measureDistance()
|
|
463
|
+
console.log("测量距离是" + distance + "米")
|
|
464
|
+
})
|
|
465
|
+
document.getElementById("cancelMeasureDistance")?.addEventListener('click', async () => {
|
|
466
|
+
bmap.cancelDistance()
|
|
467
|
+
})
|
|
468
|
+
document.getElementById("measureArea")?.addEventListener('click', async () => {
|
|
469
|
+
bmap.context.currentFloor?.addGround(graphic)
|
|
470
|
+
const distance = await bmap.measureArea()
|
|
471
|
+
console.log("测量面积是" + distance + "平方米")
|
|
472
|
+
})
|
|
473
|
+
document.getElementById("cancelMeasureArea")?.addEventListener('click', async () => {
|
|
474
|
+
bmap.cancelArea()
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
// TODO - 「<键」顺时针旋转,「>键」逆时针旋转
|
|
478
|
+
// TODO - 配置坐标定点旋转快捷键的接口
|
|
479
|
+
// - 选中某图元,可以当前图元为中心进行旋转
|
|
480
|
+
// bmap.setRotateTarget(element: Object3D)
|
|
481
|
+
// TODO 选中某图元,可以当前图元为中心进行2D/3D切换
|
|
482
|
+
// bmap.setChangeTarget(element: Object3D)
|
|
483
|
+
// TODO 居中视图
|
|
484
|
+
// bmap.context.fitCameraToView()
|
|
485
|
+
// TODO 修改poi的字体颜色和字体大小
|
|
486
|
+
// poi.options.color = "#fff000"
|
|
487
|
+
// poi.options.fontSize = 100
|
|
488
|
+
// TODO 可以设置字体背景颜色、字体背景描边颜色
|
|
489
|
+
// poi.options.textBackgroundColor = "#000fff"
|
|
490
|
+
// poi.options.textBackgroundStrokeColor = "#000fff"
|
|
491
|
+
|
|
492
|
+
// TODO 连线覆盖物
|
|
493
|
+
// const overlay = new LinkOverlay(bmap.context)
|
|
494
|
+
// overlay.position.copy(position)
|
|
495
|
+
// overlay.div.appendChild()
|
|
496
|
+
// TODO 弹窗覆盖物
|
|
497
|
+
// const overlay = new ModalOverlay(bmap.context)
|
|
498
|
+
// overlay.position.copy(position)
|
|
499
|
+
// overlay.div.appendChild()
|
|
500
|
+
// TODO 数据可视化图表
|
|
501
|
+
// const overlay = new EchartsOverlay(bmap.context, width, height)
|
|
502
|
+
// overlay.position.copy(position)
|
|
503
|
+
// overlay.setEchartsOptions({...})
|
|
504
|
+
// TODO 显示图层弹窗
|
|
505
|
+
// bmap.showLayerPanel(bool)
|
|
506
|
+
// bmap.switchLayer(layer)
|
|
507
|
+
// TODO 显示比例尺
|
|
508
|
+
// bmap.showScale(bool)
|
|
509
|
+
// TODO 定位
|
|
510
|
+
// const position = bmap.getCurrentPosition()
|
|
511
|
+
// TODO 路线规划
|
|
512
|
+
// const route = bmap.getRoute(start, end)
|
|
513
|
+
// TODO 切换楼层
|
|
514
|
+
// bmap.switchFloor("B1")
|
|
515
|
+
// TODO 加载地图
|
|
516
|
+
// await bmap.load({ project, phase, building, floor });
|
|
517
|
+
// TODO 资源数据渲染地图的调用
|
|
518
|
+
// 传入资源图层类型ID,向后台请求数据,铺位:10001, 库房:10002,广告位:10003
|
|
519
|
+
// showResourceLayerByLayerType
|
|
520
|
+
// TODO 加载主题
|
|
521
|
+
/**
|
|
522
|
+
* interface Theme {
|
|
523
|
+
id: number, // 主题样式
|
|
524
|
+
globalThemeConfig: {
|
|
525
|
+
lightConfig: {
|
|
526
|
+
hemisphereLight: [0xffffff, 0xeeeeee, 1], // 半球光
|
|
527
|
+
ambientLight: [0xffffff] // 环境光
|
|
528
|
+
},
|
|
529
|
+
backgroundConfig: {
|
|
530
|
+
fillColor: string, // 背景色
|
|
531
|
+
fillOpacity: number, // 填充透明度
|
|
532
|
+
},
|
|
533
|
+
polygonStyleConfig: {
|
|
534
|
+
strokeColor: string,
|
|
535
|
+
strokeOpacity: number,
|
|
536
|
+
fillColor: string,
|
|
537
|
+
fillOpacity: number,
|
|
538
|
+
selectedColor: string,
|
|
539
|
+
},
|
|
540
|
+
pointStyleConfig: {
|
|
541
|
+
poiFontSize: number,
|
|
542
|
+
poiFontColor: string,
|
|
543
|
+
poiIconSize: number,
|
|
544
|
+
},
|
|
545
|
+
floorFillColor: string, // 地面颜色
|
|
546
|
+
floorShadow: boolean, // 地面阴影
|
|
547
|
+
},
|
|
548
|
+
businessThemeConfig: [{
|
|
549
|
+
rule: 'userData.category_name = "母婴"',
|
|
550
|
+
polygonStyleConfig: {
|
|
551
|
+
strokeColor: string | null,
|
|
552
|
+
strokeOpacity: number | null,
|
|
553
|
+
fillColor: string | null,
|
|
554
|
+
fillOpacity: number | null,
|
|
555
|
+
selectedColor: string | null,
|
|
556
|
+
},
|
|
557
|
+
pointStyleConfig: {
|
|
558
|
+
poiFontSize: number | null,
|
|
559
|
+
poiFontColor: string | null,
|
|
560
|
+
poiIconSize: number | null,
|
|
561
|
+
},
|
|
562
|
+
}, {
|
|
563
|
+
rule: 'layerType = "铺位"',
|
|
564
|
+
polygonStyleConfig: {
|
|
565
|
+
strokeColor: string | null,
|
|
566
|
+
strokeOpacity: number | null,
|
|
567
|
+
fillColor: string | null,
|
|
568
|
+
fillOpacity: number | null,
|
|
569
|
+
selectedColor: string | null,
|
|
570
|
+
},
|
|
571
|
+
pointStyleConfig: {
|
|
572
|
+
poiFontSize: number | null,
|
|
573
|
+
poiFontColor: string | null,
|
|
574
|
+
poiIconSize: number | null,
|
|
575
|
+
},
|
|
576
|
+
}]
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
bmap.loadThemeById(themeid)
|
|
580
|
+
*/
|
|
581
|
+
// bmap.loadThemeById(themeid)
|