@aibee/crc-bmap 0.0.3-gamma

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.
Files changed (42) hide show
  1. package/README.md +1 -0
  2. package/example/index.css +22 -0
  3. package/example/index.html +54 -0
  4. package/example/src/main.ts +315 -0
  5. package/example/vite.config.ts +28 -0
  6. package/lib/bmap.cjs.min.js +2 -0
  7. package/lib/bmap.cjs.min.js.map +7 -0
  8. package/lib/bmap.esm.js +1957 -0
  9. package/lib/bmap.esm.js.map +7 -0
  10. package/lib/bmap.esm.min.js +2 -0
  11. package/lib/bmap.esm.min.js.map +7 -0
  12. package/lib/bmap.min.js +2 -0
  13. package/lib/bmap.min.js.map +7 -0
  14. package/lib/src/bmap.d.ts +93 -0
  15. package/lib/src/config.d.ts +21 -0
  16. package/lib/src/context.d.ts +105 -0
  17. package/lib/src/elements/base-svg.d.ts +16 -0
  18. package/lib/src/elements/floor.d.ts +25 -0
  19. package/lib/src/elements/graphic.d.ts +46 -0
  20. package/lib/src/elements/heatmap.d.ts +42 -0
  21. package/lib/src/elements/index.d.ts +8 -0
  22. package/lib/src/elements/overlay.d.ts +18 -0
  23. package/lib/src/elements/poi.d.ts +34 -0
  24. package/lib/src/elements/shadow.d.ts +14 -0
  25. package/lib/src/elements/svg-line.d.ts +28 -0
  26. package/lib/src/elements/svg-polygon.d.ts +33 -0
  27. package/lib/src/index.d.ts +4 -0
  28. package/lib/src/layer/graphic-layer.d.ts +16 -0
  29. package/lib/src/layer/index.d.ts +3 -0
  30. package/lib/src/layer/layer.d.ts +7 -0
  31. package/lib/src/layer/poi-layer.d.ts +24 -0
  32. package/lib/src/utils/coordinate.d.ts +19 -0
  33. package/lib/src/utils/dispose.d.ts +2 -0
  34. package/lib/src/utils/index.d.ts +9 -0
  35. package/lib/src/utils/init-helper.d.ts +10 -0
  36. package/lib/src/utils/promise.d.ts +7 -0
  37. package/lib/src/utils/proxy.d.ts +6 -0
  38. package/lib/src/utils/rules.d.ts +1 -0
  39. package/lib/src/utils/svg.d.ts +22 -0
  40. package/lib/src/utils/texture.d.ts +9 -0
  41. package/lib/src/utils/timer.d.ts +20 -0
  42. package/package.json +44 -0
@@ -0,0 +1,1957 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __pow = Math.pow;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __spreadValues = (a, b) => {
8
+ for (var prop in b || (b = {}))
9
+ if (__hasOwnProp.call(b, prop))
10
+ __defNormalProp(a, prop, b[prop]);
11
+ if (__getOwnPropSymbols)
12
+ for (var prop of __getOwnPropSymbols(b)) {
13
+ if (__propIsEnum.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ }
16
+ return a;
17
+ };
18
+ var __publicField = (obj, key, value) => {
19
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
20
+ return value;
21
+ };
22
+ var __async = (__this, __arguments, generator) => {
23
+ return new Promise((resolve, reject) => {
24
+ var fulfilled = (value) => {
25
+ try {
26
+ step(generator.next(value));
27
+ } catch (e) {
28
+ reject(e);
29
+ }
30
+ };
31
+ var rejected = (value) => {
32
+ try {
33
+ step(generator.throw(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
39
+ step((generator = generator.apply(__this, __arguments)).next());
40
+ });
41
+ };
42
+
43
+ // src/bmap.ts
44
+ import { EventDispatcher as EventDispatcher4 } from "three";
45
+
46
+ // src/utils/timer.ts
47
+ var Timer = class {
48
+ constructor() {
49
+ __publicField(this, "tasks", {
50
+ requestAnimation: /* @__PURE__ */ new Set(),
51
+ timeout: /* @__PURE__ */ new Set(),
52
+ interval: /* @__PURE__ */ new Set()
53
+ });
54
+ }
55
+ requestAnimationFrame(fn) {
56
+ const timer = window.requestAnimationFrame(() => {
57
+ this.tasks.requestAnimation.delete(timer);
58
+ fn();
59
+ });
60
+ this.tasks.requestAnimation.add(timer);
61
+ return timer;
62
+ }
63
+ cancelAnimationFrame(timer) {
64
+ this.tasks.requestAnimation.delete(timer);
65
+ window.cancelAnimationFrame(timer);
66
+ }
67
+ setTimeout(fn, wait) {
68
+ const timer = window.setTimeout(() => {
69
+ this.tasks.timeout.delete(timer);
70
+ fn();
71
+ }, wait);
72
+ this.tasks.timeout.add(timer);
73
+ return timer;
74
+ }
75
+ clearTimeout(timer) {
76
+ this.tasks.timeout.delete(timer);
77
+ window.clearTimeout(timer);
78
+ }
79
+ setInterval(fn, wait) {
80
+ const timer = window.setInterval(() => {
81
+ this.tasks.interval.delete(timer);
82
+ fn();
83
+ }, wait);
84
+ this.tasks.interval.add(timer);
85
+ return timer;
86
+ }
87
+ clearInterval(timer) {
88
+ this.tasks.interval.delete(timer);
89
+ window.clearInterval(timer);
90
+ }
91
+ dispose() {
92
+ this.tasks.requestAnimation.forEach((timer) => {
93
+ window.cancelAnimationFrame(timer);
94
+ });
95
+ this.tasks.requestAnimation.clear();
96
+ this.tasks.timeout.forEach((timer) => {
97
+ window.clearTimeout(timer);
98
+ });
99
+ this.tasks.timeout.clear();
100
+ this.tasks.interval.forEach((timer) => {
101
+ window.clearInterval(timer);
102
+ });
103
+ this.tasks.interval.clear();
104
+ }
105
+ };
106
+
107
+ // src/utils/init-helper.ts
108
+ import {
109
+ Scene,
110
+ WebGLRenderer,
111
+ OrthographicCamera,
112
+ HemisphereLight,
113
+ Shape,
114
+ PCFSoftShadowMap,
115
+ Group,
116
+ Color,
117
+ DirectionalLight,
118
+ AmbientLight
119
+ } from "three";
120
+ import { MapControls } from "three/examples/jsm/controls/MapControls";
121
+ function initScene() {
122
+ const scene = new Scene();
123
+ scene.background = new Color(16777215);
124
+ return scene;
125
+ }
126
+ function initRenderer() {
127
+ const renderer = new WebGLRenderer({ antialias: true });
128
+ renderer.setClearColor(16777215);
129
+ renderer.setPixelRatio(window.devicePixelRatio);
130
+ renderer.shadowMap.enabled = true;
131
+ renderer.shadowMap.autoUpdate = true;
132
+ renderer.shadowMap.type = PCFSoftShadowMap;
133
+ return renderer;
134
+ }
135
+ function initCamera(width, height) {
136
+ const camera = new OrthographicCamera(-width / 2, width / 2, height / 2, -height / 2, -1e3, 5e3);
137
+ camera.up.set(0, 0, 1);
138
+ camera.position.set(0, 0, 100);
139
+ camera.lookAt(0, 0, 0);
140
+ return camera;
141
+ }
142
+ function initLight() {
143
+ const lights = new Group();
144
+ const hemisphereLight = new HemisphereLight(16777215, 15658734, 1);
145
+ hemisphereLight.intensity = 1;
146
+ hemisphereLight.position.set(0, 0, 10);
147
+ hemisphereLight.up.set(0, 0, 1);
148
+ lights.add(hemisphereLight);
149
+ const ambientLight = new AmbientLight(16777215);
150
+ lights.add(ambientLight);
151
+ return lights;
152
+ }
153
+ function initControl(camera, domElement) {
154
+ const control = new MapControls(camera, domElement);
155
+ control.enableDamping = false;
156
+ control.maxPolarAngle = 0;
157
+ control.minPolarAngle = 0;
158
+ control.maxAzimuthAngle = 0;
159
+ control.minAzimuthAngle = 0;
160
+ return control;
161
+ }
162
+ function initShape(path) {
163
+ const shape = new Shape();
164
+ if (Array.isArray(path[0])) {
165
+ shape.moveTo(...path[0]);
166
+ for (let i = 1; i < path.length; i++) {
167
+ shape.lineTo(...path[i]);
168
+ }
169
+ }
170
+ return shape;
171
+ }
172
+ function initDirectionalLight(color = 16777215, intensity = 1) {
173
+ const directionalLight = new DirectionalLight(color, intensity);
174
+ directionalLight.castShadow = true;
175
+ directionalLight.shadow.radius = 8;
176
+ directionalLight.shadow.mapSize.set(64, 64);
177
+ directionalLight.shadow.camera.left = -200;
178
+ directionalLight.shadow.camera.right = 200;
179
+ directionalLight.shadow.camera.top = 200;
180
+ directionalLight.shadow.camera.bottom = -200;
181
+ return directionalLight;
182
+ }
183
+
184
+ // src/utils/dispose.ts
185
+ function dispose(o, recursive) {
186
+ var _a;
187
+ if (recursive && o.children && o.children.length) {
188
+ o.children.forEach((child) => {
189
+ dispose(child, recursive);
190
+ });
191
+ }
192
+ if (o.isMesh) {
193
+ const m = o;
194
+ if (m.geometry)
195
+ m.geometry.dispose();
196
+ if (m.material) {
197
+ if (Array.isArray(m.material)) {
198
+ m.material.forEach((mat) => {
199
+ mat.dispose();
200
+ });
201
+ } else {
202
+ m.material.dispose();
203
+ }
204
+ }
205
+ }
206
+ if (o.isLight) {
207
+ (_a = o.dispose) == null ? void 0 : _a.call(o);
208
+ }
209
+ }
210
+
211
+ // src/utils/rules.ts
212
+ function hasChinese(str) {
213
+ return /[\u4E00-\u9FA5]+/g.test(str);
214
+ }
215
+
216
+ // src/utils/texture.ts
217
+ import { DataTexture, RGBAFormat, LinearFilter } from "three";
218
+ var textTextureMap = /* @__PURE__ */ new Map();
219
+ function initCanvas() {
220
+ const canvas2 = document.createElement("canvas");
221
+ canvas2.width = 1024;
222
+ canvas2.height = 64;
223
+ const ctx2 = canvas2.getContext("2d", {
224
+ willReadFrequently: true
225
+ });
226
+ ctx2.font = "54px sans-serif";
227
+ ctx2.textBaseline = "hanging";
228
+ ctx2.lineWidth = 12;
229
+ ctx2.fillStyle = "rgba(0,0,0,1)";
230
+ ctx2.strokeStyle = "white";
231
+ return { canvas: canvas2, ctx: ctx2 };
232
+ }
233
+ var canvas;
234
+ var ctx;
235
+ function createCanvas() {
236
+ if (!canvas) {
237
+ const { canvas: c, ctx: t } = initCanvas();
238
+ canvas = c;
239
+ ctx = t;
240
+ }
241
+ }
242
+ function getTextureByText(text) {
243
+ if (textTextureMap.has(text)) {
244
+ return textTextureMap.get(text);
245
+ }
246
+ createCanvas();
247
+ ctx.clearRect(0, 0, 1024, 64);
248
+ const y = hasChinese(text) ? 4 : 8;
249
+ ctx.strokeText(text, 2, y);
250
+ ctx.fillText(text, 2, y);
251
+ let width = Math.ceil(ctx.measureText(text).width);
252
+ width = width % 2 === 0 ? width : width + 1;
253
+ width += 2;
254
+ const imageData = ctx.getImageData(0, 0, width, 64);
255
+ const texture = new DataTexture(
256
+ Uint8Array.from(imageData.data),
257
+ width,
258
+ 64,
259
+ RGBAFormat
260
+ );
261
+ texture.flipY = true;
262
+ texture.minFilter = LinearFilter;
263
+ texture.magFilter = LinearFilter;
264
+ textTextureMap.set(text, texture);
265
+ return texture;
266
+ }
267
+ function clearTextTexture() {
268
+ textTextureMap.clear();
269
+ }
270
+ function clearCanvas() {
271
+ ctx = null;
272
+ canvas = null;
273
+ }
274
+
275
+ // src/utils/coordinate.ts
276
+ import { point, featureCollection, center } from "@turf/turf";
277
+ function vector3ToDevice(vector, camera, w, h) {
278
+ const _vector = vector.clone().project(camera);
279
+ const _w = w / 2;
280
+ const _h = h / 2;
281
+ const x = Math.round(_vector.x * _w + _w);
282
+ const y = Math.round(-_vector.y * _h + _h);
283
+ return { x, y };
284
+ }
285
+ function getCenter(coordinates) {
286
+ const features = featureCollection(coordinates.map((item) => point(item)));
287
+ const cent = center(features);
288
+ return cent.geometry.coordinates;
289
+ }
290
+
291
+ // src/utils/proxy.ts
292
+ function proxyOptions(target, master) {
293
+ return new Proxy(target, {
294
+ get: (target2, p, receiver) => {
295
+ return Reflect.get(target2, p, receiver);
296
+ },
297
+ set: (target2, p, newValue, receiver) => {
298
+ const res = Reflect.set(target2, p, newValue, receiver);
299
+ master.dispatchEvent({ type: `change-${p}`, value: newValue });
300
+ return res;
301
+ }
302
+ });
303
+ }
304
+
305
+ // src/utils/promise.ts
306
+ function timeoutPromise(promise, timeout) {
307
+ return Promise.race([
308
+ promise,
309
+ new Promise((resolve, reject) => {
310
+ setTimeout(() => reject(new Error("Promise timeout")), timeout);
311
+ })
312
+ ]);
313
+ }
314
+
315
+ // src/utils/svg.ts
316
+ function createSvgElement(tag) {
317
+ return document.createElementNS("http://www.w3.org/2000/svg", tag);
318
+ }
319
+ function createSvg(w, h) {
320
+ const svg = createSvgElement("svg");
321
+ svg.setAttribute("width", w);
322
+ svg.setAttribute("height", h);
323
+ svg.style.cssText = "position: absolute; left: 0; top: 0; pointer-events: none;";
324
+ return svg;
325
+ }
326
+ function createCircle(radius = "2", fill) {
327
+ const circle = createSvgElement("circle");
328
+ circle.setAttribute("r", radius);
329
+ circle.setAttribute("fill", fill);
330
+ return circle;
331
+ }
332
+ function createLine(stroke) {
333
+ const line = createSvgElement("line");
334
+ line.setAttribute("stroke", stroke);
335
+ return line;
336
+ }
337
+ function setCirclePosition(circle, x, y) {
338
+ circle.setAttribute("cx", `${x}`);
339
+ circle.setAttribute("cy", `${y}`);
340
+ }
341
+ function setLineStartEnd(line, start, end) {
342
+ if (start) {
343
+ line.setAttribute("x1", `${start.x}`);
344
+ line.setAttribute("y1", `${start.y}`);
345
+ }
346
+ if (end) {
347
+ line.setAttribute("x2", `${end.x}`);
348
+ line.setAttribute("y2", `${end.y}`);
349
+ }
350
+ }
351
+
352
+ // src/context.ts
353
+ import {
354
+ EventDispatcher,
355
+ Box2,
356
+ Vector3,
357
+ Vector2,
358
+ Raycaster,
359
+ Box3,
360
+ Color as Color2,
361
+ AmbientLight as AmbientLight2
362
+ } from "three";
363
+ import { Group as TweenGroup, Tween } from "@tweenjs/tween.js";
364
+ var Context = class extends EventDispatcher {
365
+ // zoom=1的时候,100M对应的像素个数
366
+ constructor(container, config) {
367
+ super();
368
+ this.container = container;
369
+ this.config = config;
370
+ __publicField(this, "scene", initScene());
371
+ __publicField(this, "renderer", initRenderer());
372
+ __publicField(this, "camera");
373
+ __publicField(this, "control");
374
+ __publicField(this, "lights", initLight());
375
+ // 管理任务,防止内存泄漏
376
+ __publicField(this, "timer", new Timer());
377
+ __publicField(this, "tweenGroup", new TweenGroup());
378
+ __publicField(this, "currentFloor");
379
+ __publicField(this, "basicRatio");
380
+ __publicField(this, "onWindowResize", () => {
381
+ const { container, camera, renderer } = this;
382
+ const { clientWidth: w, clientHeight: h } = container;
383
+ camera.left = -w / 2;
384
+ camera.right = w / 2;
385
+ camera.top = h / 2;
386
+ camera.bottom = -h / 2;
387
+ camera.updateProjectionMatrix();
388
+ renderer.setSize(window.innerWidth, window.innerHeight);
389
+ });
390
+ __publicField(this, "onClick", (e) => {
391
+ const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
392
+ if (graphics.length) {
393
+ this.dispatchEvent({
394
+ type: "graphic-click",
395
+ graphics,
396
+ position
397
+ });
398
+ }
399
+ const pois = this.getPoisByDeviceXy(e.clientX, e.clientY);
400
+ if (pois.length) {
401
+ this.dispatchEvent({ type: "poi-click", pois });
402
+ }
403
+ });
404
+ __publicField(this, "onPointerover", (e) => {
405
+ const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
406
+ const pois = this.getPoisByDeviceXy(e.clientX, e.clientY);
407
+ this.dispatchEvent({ type: "pointer-over", graphics, pois, position });
408
+ });
409
+ __publicField(this, "onPointermove", (e) => {
410
+ const { graphics, position } = this.getGraphicsByDeviceXy(e.offsetX, e.offsetY);
411
+ const pois = this.getPoisByDeviceXy(e.clientX, e.clientY);
412
+ this.dispatchEvent({ type: "pointer-move", graphics, pois, position });
413
+ });
414
+ __publicField(this, "onPointerleave", () => {
415
+ this.dispatchEvent({ type: "pointer-level" });
416
+ });
417
+ this.container.style.position = "relative";
418
+ this.container.style.overflow = "hidden";
419
+ this.init();
420
+ this.registryEvent();
421
+ }
422
+ init() {
423
+ const { clientWidth: w, clientHeight: h } = this.container;
424
+ this.camera = initCamera(w, h);
425
+ this.renderer.setSize(w, h);
426
+ this.control = initControl(this.camera, this.renderer.domElement);
427
+ this.container.appendChild(this.renderer.domElement);
428
+ this.scene.add(this.lights);
429
+ this.basicRatio = this.getRatio();
430
+ this.control.addEventListener("change", () => {
431
+ var _a;
432
+ const polarAngle = this.control.getPolarAngle();
433
+ (_a = this.currentFloor) == null ? void 0 : _a.setShadowOpacity(polarAngle / this.config.control.maxPolar);
434
+ this.dispatchEvent({ type: "change-ratio", px: (this.basicRatio || 0) * this.camera.zoom });
435
+ });
436
+ }
437
+ /**
438
+ * 获取两个点之间的像素数
439
+ */
440
+ getRatio(point1 = new Vector3(0, 0, 0), point22 = new Vector3(100, 0, 0)) {
441
+ const { clientWidth, clientHeight } = this.container;
442
+ const device1 = vector3ToDevice(point1, this.camera, clientWidth, clientHeight);
443
+ const device2 = vector3ToDevice(point22, this.camera, clientWidth, clientHeight);
444
+ return Math.ceil(Math.sqrt(__pow(device2.x - device1.x, 2) + __pow(device2.y - device1.y, 2)));
445
+ }
446
+ changeAmbientLightColor(color) {
447
+ this.lights.children.forEach((item) => {
448
+ if (item instanceof AmbientLight2) {
449
+ item.color = new Color2(color);
450
+ }
451
+ });
452
+ }
453
+ switchFloor(floor) {
454
+ var _a;
455
+ if (this.currentFloor) {
456
+ this.scene.remove(floor);
457
+ floor.dispose();
458
+ }
459
+ this.currentFloor = floor;
460
+ this.scene.add(floor);
461
+ const position = (_a = floor.ground) == null ? void 0 : _a.getCenter();
462
+ if (position) {
463
+ this.lights.position.x = position.x;
464
+ this.lights.position.y = position.y;
465
+ }
466
+ }
467
+ /**
468
+ * 获取屏幕坐标对应的graphic
469
+ * @param x
470
+ * @param y
471
+ * @returns
472
+ */
473
+ getGraphicsByDeviceXy(x, y) {
474
+ var _a;
475
+ const point3 = new Vector2();
476
+ point3.x = x / this.container.clientWidth * 2 - 1;
477
+ point3.y = y / this.container.clientHeight * -2 + 1;
478
+ const raycaster = new Raycaster();
479
+ raycaster.setFromCamera(point3, this.camera);
480
+ const res = (_a = this.currentFloor) == null ? void 0 : _a.graphicLayer.getGraphicByRaycaster(raycaster);
481
+ return res || { graphics: [], position: null };
482
+ }
483
+ /**
484
+ * 获取屏幕坐标对应的poi
485
+ * @param x
486
+ * @param y
487
+ * @returns
488
+ */
489
+ getPoisByDeviceXy(x, y) {
490
+ var _a;
491
+ const pois = (_a = this.currentFloor) == null ? void 0 : _a.poiLayer.getPoiByDeviceXy(x, y);
492
+ return pois || [];
493
+ }
494
+ registryEvent() {
495
+ window.addEventListener("resize", this.onWindowResize);
496
+ this.container.addEventListener("click", this.onClick);
497
+ this.container.addEventListener("pointerover", this.onPointerover);
498
+ this.container.addEventListener("pointermove", this.onPointermove);
499
+ this.container.addEventListener("pointerleave", this.onPointerleave);
500
+ }
501
+ unRegistryEvent() {
502
+ window.removeEventListener("resize", this.onWindowResize);
503
+ this.container.removeEventListener("click", this.onClick);
504
+ this.container.removeEventListener("pointerover", this.onPointerover);
505
+ this.container.removeEventListener("pointermove", this.onPointermove);
506
+ this.container.removeEventListener("pointerleave", this.onPointerleave);
507
+ }
508
+ /**
509
+ * 设置纵向旋转角度
510
+ * @param polar 弧度
511
+ */
512
+ setPolarAngle(polar, duration = 500) {
513
+ return timeoutPromise(
514
+ new Promise((resolve) => {
515
+ const start = { polar: this.control.getPolarAngle() };
516
+ const end = { polar };
517
+ const tween = new Tween(start, this.tweenGroup).to(end, duration).onUpdate(() => {
518
+ this.control.maxPolarAngle = start.polar;
519
+ this.control.minPolarAngle = start.polar;
520
+ this.control.update();
521
+ }).onComplete(() => {
522
+ this.control.enabled = true;
523
+ this.tweenGroup.remove(tween);
524
+ resolve(true);
525
+ }).onStart(() => {
526
+ this.control.enabled = false;
527
+ }).start();
528
+ }),
529
+ duration + 500
530
+ );
531
+ }
532
+ getCameraLookAt() {
533
+ return new Vector3().subVectors(this.control.target, this.camera.position);
534
+ }
535
+ /**
536
+ * 按照一个中心点设置相机的放大缩小
537
+ * @param zoom
538
+ * @param center
539
+ * @returns
540
+ */
541
+ setZoom(zoom, center2, duration = 500) {
542
+ return timeoutPromise(
543
+ new Promise((resolve) => {
544
+ const start = {
545
+ zoom: this.camera.zoom,
546
+ target: this.control.target.clone()
547
+ };
548
+ const lookAtVector = this.getCameraLookAt();
549
+ const tween = new Tween(start, this.tweenGroup).to(
550
+ {
551
+ zoom,
552
+ target: center2
553
+ },
554
+ duration
555
+ ).onUpdate(() => {
556
+ this.camera.position.copy(start.target.clone().sub(lookAtVector));
557
+ this.control.target.copy(start.target);
558
+ this.camera.zoom = start.zoom;
559
+ this.control.update();
560
+ }).onComplete(() => {
561
+ this.tweenGroup.remove(tween);
562
+ this.control.enabled = true;
563
+ resolve(true);
564
+ }).onStart(() => {
565
+ this.control.enabled = false;
566
+ }).start();
567
+ }),
568
+ duration + 500
569
+ );
570
+ }
571
+ /**
572
+ * 放大相机到物体占全屏
573
+ * @param object
574
+ * @param padding
575
+ * @param duration
576
+ * @returns
577
+ */
578
+ fitCameraToObject(object, padding = [20, 20, 20, 20], duration = 500) {
579
+ const [top, right, bottom, left] = padding;
580
+ const { clientWidth, clientHeight } = this.container;
581
+ const boundingBox = new Box3().setFromObject(object);
582
+ const { max, min } = boundingBox;
583
+ const max2d = vector3ToDevice(max, this.camera, clientWidth, clientHeight);
584
+ const min2d = vector3ToDevice(min, this.camera, clientWidth, clientHeight);
585
+ const boundingBox2d = new Box2().setFromPoints([
586
+ new Vector2(max2d.x, max2d.y),
587
+ new Vector2(min2d.x, min2d.y)
588
+ ]);
589
+ const size = boundingBox2d.getSize(new Vector2());
590
+ const xScale = (clientWidth - right - left) / size.x;
591
+ const yScale = (clientHeight - top - bottom) / size.y;
592
+ const scale = Math.min(xScale, yScale);
593
+ const center2 = new Vector3((max.x + min.x) / 2, (max.y + min.y) / 2, max.z);
594
+ return this.setZoom(scale * this.camera.zoom, center2, duration);
595
+ }
596
+ fitCameraToGround(padding = [20, 20, 20, 20], duration = 500) {
597
+ var _a;
598
+ const ground = (_a = this.currentFloor) == null ? void 0 : _a.ground;
599
+ if (ground) {
600
+ return this.fitCameraToObject(ground, padding, duration);
601
+ } else {
602
+ return Promise.resolve(false);
603
+ }
604
+ }
605
+ /**
606
+ * 修改相机位置
607
+ * @param position 修改后的相机的位置
608
+ * @param duration 动画持续时间
609
+ */
610
+ setCameraPosition(position, duration) {
611
+ return timeoutPromise(
612
+ new Promise((resolve) => {
613
+ const start = this.camera.position.clone();
614
+ const lookAtVector = this.getCameraLookAt();
615
+ const tween = new Tween(start, this.tweenGroup).to(position, duration).onUpdate(() => {
616
+ this.camera.position.copy(start);
617
+ this.control.target.copy(position.clone().add(lookAtVector));
618
+ }).onComplete(() => {
619
+ this.tweenGroup.remove(tween);
620
+ this.control.update();
621
+ this.control.enabled = true;
622
+ resolve(true);
623
+ }).onStart(() => {
624
+ this.control.enabled = false;
625
+ }).start();
626
+ }),
627
+ duration + 500
628
+ );
629
+ }
630
+ render() {
631
+ this.renderer.render(this.scene, this.camera);
632
+ this.dispatchEvent({ type: "update" });
633
+ this.timer.requestAnimationFrame(() => {
634
+ this.render();
635
+ });
636
+ this.tweenGroup.update();
637
+ }
638
+ dispose() {
639
+ this.tweenGroup.getAll().forEach((item) => item.stop());
640
+ this.tweenGroup.removeAll();
641
+ this.unRegistryEvent();
642
+ this.container.removeChild(this.renderer.domElement);
643
+ this.timer.dispose();
644
+ this.renderer.dispose();
645
+ this.lights.children.forEach(
646
+ (light) => light.dispose()
647
+ );
648
+ dispose(this.scene);
649
+ }
650
+ };
651
+
652
+ // src/config.ts
653
+ import { merge } from "lodash";
654
+ var defaultConfig = {
655
+ apiDomain: "",
656
+ apiInfo: {},
657
+ heatMap: {
658
+ radius: 50,
659
+ gradient: {
660
+ 0: "#8F9FCD",
661
+ 0.5: "#6284FF",
662
+ 1: "#F95D5D"
663
+ }
664
+ },
665
+ useFloorCache: true,
666
+ control: {
667
+ maxPolar: 1.2
668
+ },
669
+ svg: {
670
+ circle: {
671
+ radius: "2",
672
+ fill: "#EFF4FB"
673
+ },
674
+ line: {
675
+ stroke: "#EFF4FB"
676
+ }
677
+ }
678
+ };
679
+ function getConfig(config) {
680
+ return merge({}, defaultConfig, config);
681
+ }
682
+
683
+ // src/elements/graphic.ts
684
+ import {
685
+ Object3D as Object3D2,
686
+ ExtrudeGeometry,
687
+ MeshStandardMaterial,
688
+ Mesh,
689
+ Color as Color3,
690
+ Box3 as Box32,
691
+ LineSegments,
692
+ EdgesGeometry,
693
+ LineBasicMaterial,
694
+ Vector3 as Vector32
695
+ } from "three";
696
+ import { merge as merge2 } from "lodash";
697
+ var defaultOptions = {
698
+ id: "",
699
+ // 图形id
700
+ height: 0.1,
701
+ // 图形高度
702
+ airHeight: 0,
703
+ // 悬空高度
704
+ area: 0,
705
+ // 面积
706
+ group: "",
707
+ // 分组
708
+ fillColor: "#EFF4FB",
709
+ // 颜色
710
+ strokeColor: "#ffffff",
711
+ // 边框
712
+ fillOpacity: 1,
713
+ // 透明度
714
+ strokeOpacity: 1,
715
+ // 描边透明度
716
+ doors: [],
717
+ // 门配置
718
+ locked: false,
719
+ visible: true,
720
+ geometry: {
721
+ type: "polygon",
722
+ cds: [],
723
+ curveCpt: [],
724
+ curveIndex: []
725
+ },
726
+ layerType: "",
727
+ zIndex: 0
728
+ };
729
+ var Graphic = class extends Object3D2 {
730
+ constructor(context, options) {
731
+ super();
732
+ this.context = context;
733
+ __publicField(this, "geometry");
734
+ __publicField(this, "material");
735
+ __publicField(this, "mesh");
736
+ __publicField(this, "line");
737
+ __publicField(this, "options");
738
+ this.options = proxyOptions(merge2({}, defaultOptions, options), this);
739
+ this.init();
740
+ this.visible = this.options.visible;
741
+ this.addEventListener("change-fillColor", ({ value }) => {
742
+ this.material.color = new Color3(value);
743
+ });
744
+ this.addEventListener("change-fillOpacity", ({ value }) => {
745
+ this.material.opacity = value;
746
+ });
747
+ this.addEventListener("change-height", ({ value }) => {
748
+ this.dispose();
749
+ this.init();
750
+ });
751
+ this.addEventListener("change-strokeColor", ({ value }) => {
752
+ this.line.material.color = new Color3(value);
753
+ });
754
+ this.addEventListener("change-strokeOpacity", ({ value }) => {
755
+ this.line.material.opacity = value;
756
+ });
757
+ this.addEventListener("change-airHeight", ({ value }) => {
758
+ this.position.z = value;
759
+ });
760
+ this.addEventListener("change-visible", ({ value }) => {
761
+ this.visible = value;
762
+ });
763
+ }
764
+ getCenter() {
765
+ const center2 = new Vector32();
766
+ const box = new Box32();
767
+ box.setFromObject(this);
768
+ box.getCenter(center2);
769
+ return center2;
770
+ }
771
+ init() {
772
+ this.geometry = this.initGeometry();
773
+ this.material = this.initMaterial();
774
+ this.mesh = this.initMesh();
775
+ this.mesh.position.z = this.options.airHeight;
776
+ this.mesh.castShadow = true;
777
+ this.add(this.mesh);
778
+ this.line = this.createBorder();
779
+ this.add(this.line);
780
+ }
781
+ initGeometry() {
782
+ const shape = initShape(this.options.geometry.cds[0]);
783
+ const geometry = new ExtrudeGeometry(shape, {
784
+ steps: 1,
785
+ bevelEnabled: false,
786
+ depth: this.options.height,
787
+ curveSegments: 4
788
+ });
789
+ return geometry;
790
+ }
791
+ initMaterial() {
792
+ const material = new MeshStandardMaterial({
793
+ color: this.options.fillColor,
794
+ roughness: 1,
795
+ transparent: true,
796
+ opacity: this.options.fillOpacity,
797
+ depthWrite: true
798
+ });
799
+ return material;
800
+ }
801
+ initLineMaterial() {
802
+ const lineMaterial = new LineBasicMaterial({
803
+ color: this.options.strokeColor,
804
+ opacity: this.options.strokeOpacity,
805
+ transparent: true,
806
+ depthWrite: true
807
+ });
808
+ return lineMaterial;
809
+ }
810
+ initMesh() {
811
+ return new Mesh(this.geometry, this.material);
812
+ }
813
+ createBorder() {
814
+ const material = this.initLineMaterial();
815
+ const geometry = new EdgesGeometry(this.geometry);
816
+ const line = new LineSegments(geometry, material);
817
+ return line;
818
+ }
819
+ raycast(raycaster) {
820
+ if (!this.visible) {
821
+ return false;
822
+ }
823
+ const intersects = raycaster.intersectObject(this.mesh);
824
+ if (intersects[0]) {
825
+ const position = intersects[0].point;
826
+ return position;
827
+ }
828
+ return false;
829
+ }
830
+ dispose() {
831
+ dispose(this);
832
+ this.clear();
833
+ }
834
+ };
835
+
836
+ // src/elements/shadow.ts
837
+ import {
838
+ Object3D as Object3D3,
839
+ PlaneGeometry,
840
+ Mesh as Mesh2,
841
+ ShadowMaterial,
842
+ Color as Color4,
843
+ DirectionalLightHelper,
844
+ BoxGeometry,
845
+ MeshBasicMaterial
846
+ } from "three";
847
+ var Shadow = class extends Object3D3 {
848
+ constructor() {
849
+ super();
850
+ __publicField(this, "directionalLight");
851
+ __publicField(this, "plane");
852
+ __publicField(this, "basicOpacity", 0.39);
853
+ this.directionalLight = this.initLight();
854
+ this.plane = this.initPlane();
855
+ }
856
+ // 创建光源
857
+ initLight() {
858
+ const directionalLight = initDirectionalLight(16777215, 0.23);
859
+ directionalLight.position.set(0, 0, 100);
860
+ const helper = new DirectionalLightHelper(directionalLight, 100);
861
+ const geometry = new BoxGeometry(10, 10, 10);
862
+ const material = new MeshBasicMaterial({ color: 16773120 });
863
+ const mesh = new Mesh2(geometry, material);
864
+ mesh.position.set(0, 0, 100);
865
+ this.add(directionalLight);
866
+ this.add(helper);
867
+ this.add(mesh);
868
+ return directionalLight;
869
+ }
870
+ changeLightColor(color) {
871
+ this.directionalLight.color = new Color4(color);
872
+ }
873
+ // 创建平面白色
874
+ initPlane() {
875
+ const geometry = new PlaneGeometry(2e3, 2e3);
876
+ const material = new ShadowMaterial({
877
+ transparent: true,
878
+ opacity: 0,
879
+ color: 16773120
880
+ });
881
+ const mesh = new Mesh2(geometry, material);
882
+ mesh.receiveShadow = true;
883
+ mesh.position.z = -1;
884
+ this.add(mesh);
885
+ return mesh;
886
+ }
887
+ setTarget(target) {
888
+ this.directionalLight.target = target;
889
+ }
890
+ transformOpacity(opacity) {
891
+ return opacity * this.basicOpacity;
892
+ }
893
+ setOpacity(opacity) {
894
+ this.plane.material.opacity = 1;
895
+ }
896
+ dispose() {
897
+ dispose(this, true);
898
+ }
899
+ };
900
+
901
+ // src/elements/poi.ts
902
+ import { Object3D as Object3D5 } from "three";
903
+ import { merge as merge3 } from "lodash";
904
+
905
+ // src/elements/overlay.ts
906
+ import { EventDispatcher as EventDispatcher2, Vector3 as Vector33 } from "three";
907
+ var Overlay = class extends EventDispatcher2 {
908
+ constructor(context) {
909
+ super();
910
+ this.context = context;
911
+ __publicField(this, "div");
912
+ __publicField(this, "element");
913
+ __publicField(this, "position", new Vector33());
914
+ __publicField(this, "onUpdate", () => {
915
+ const vector = this.getPosition();
916
+ const { clientWidth, clientHeight } = this.context.container;
917
+ const { x, y } = vector3ToDevice(vector, this.context.camera, clientWidth, clientHeight);
918
+ this.div.style.left = `${x}px`;
919
+ this.div.style.top = `${y}px`;
920
+ });
921
+ this.registryEvent();
922
+ this.div = this.initDiv();
923
+ this.context.container.appendChild(this.div);
924
+ }
925
+ initDiv() {
926
+ const div = document.createElement("div");
927
+ div.style.position = "absolute";
928
+ return div;
929
+ }
930
+ bindElement(element) {
931
+ this.element = element;
932
+ }
933
+ unBindElement() {
934
+ this.element = void 0;
935
+ }
936
+ setVisible(visible, display = "block") {
937
+ this.div.style.display = visible ? display : "none";
938
+ }
939
+ getPosition() {
940
+ return this.element ? this.element.position.clone().setFromMatrixPosition(this.element.matrixWorld) : this.position;
941
+ }
942
+ registryEvent() {
943
+ this.context.addEventListener("update", this.onUpdate);
944
+ }
945
+ unRegistryEvent() {
946
+ this.context.removeEventListener("update", this.onUpdate);
947
+ }
948
+ dispose() {
949
+ this.unRegistryEvent();
950
+ this.unBindElement();
951
+ this.context.container.removeChild(this.div);
952
+ this.div = null;
953
+ }
954
+ };
955
+
956
+ // src/elements/poi.ts
957
+ var defaultOptions2 = {
958
+ text: "",
959
+ level: 1,
960
+ collision_enable: true
961
+ };
962
+ var Poi = class extends Object3D5 {
963
+ constructor(context, options) {
964
+ super();
965
+ this.context = context;
966
+ __publicField(this, "span");
967
+ __publicField(this, "img");
968
+ __publicField(this, "overlay");
969
+ __publicField(this, "options");
970
+ __publicField(this, "_changePosition", () => {
971
+ this.overlay.div.style.transform = `translate3d(-50%, ${this.options.icon ? "-100%" : "-50%"}, 0)`;
972
+ });
973
+ this.options = proxyOptions(merge3({}, defaultOptions2, options), this);
974
+ this.overlay = new Overlay(this.context);
975
+ this.overlay.bindElement(this);
976
+ this._changePosition();
977
+ this.registryEvent();
978
+ this.initDiv();
979
+ this.addEventListener("change-icon", ({ value }) => {
980
+ if (value) {
981
+ if (!this.img) {
982
+ this.overlay.div.appendChild(this.initIcon());
983
+ } else {
984
+ this.img.setAttribute("src", value);
985
+ }
986
+ } else {
987
+ this.img && this.overlay.div.removeChild(this.img);
988
+ this.img = void 0;
989
+ }
990
+ });
991
+ this.addEventListener("change-text", ({ value }) => {
992
+ this.span.textContent = value;
993
+ });
994
+ }
995
+ initDiv() {
996
+ const div = this.overlay.div;
997
+ div.appendChild(this.initText());
998
+ if (this.options.icon) {
999
+ div.appendChild(this.initIcon());
1000
+ }
1001
+ div.style.fontSize = `12px`;
1002
+ div.style.display = `flex`;
1003
+ div.style.flexDirection = `column`;
1004
+ div.style.justifyContent = `center`;
1005
+ div.style.alignItems = `center`;
1006
+ div.style.pointerEvents = `none`;
1007
+ return div;
1008
+ }
1009
+ initText() {
1010
+ const span = document.createElement("span");
1011
+ span.style.whiteSpace = "nowrap";
1012
+ span.textContent = this.options.text;
1013
+ this.span = span;
1014
+ return span;
1015
+ }
1016
+ initIcon() {
1017
+ var _a, _b;
1018
+ const img = document.createElement("img");
1019
+ img.setAttribute("src", this.options.icon);
1020
+ img.style.width = `${((_a = this.options.icon_size) == null ? void 0 : _a[0]) || 32}px`;
1021
+ img.style.height = `${((_b = this.options.icon_size) == null ? void 0 : _b[1]) || 32}px`;
1022
+ this.img = img;
1023
+ return img;
1024
+ }
1025
+ registryEvent() {
1026
+ this.context.addEventListener("update", this._changePosition);
1027
+ }
1028
+ unRegistryEvent() {
1029
+ this.context.removeEventListener("update", this._changePosition);
1030
+ }
1031
+ setVisible(visible) {
1032
+ this.overlay.setVisible(visible, "flex");
1033
+ }
1034
+ getBox() {
1035
+ return this.overlay.div.getBoundingClientRect();
1036
+ }
1037
+ isContain(x, y) {
1038
+ const box = this.getBox();
1039
+ return x >= box.left && x <= box.right && y >= box.top && y <= box.bottom;
1040
+ }
1041
+ dispose() {
1042
+ this.unRegistryEvent();
1043
+ this.overlay.dispose();
1044
+ this.span = null;
1045
+ this.img = void 0;
1046
+ }
1047
+ };
1048
+
1049
+ // src/elements/floor.ts
1050
+ import { Object3D as Object3D8 } from "three";
1051
+
1052
+ // src/layer/layer.ts
1053
+ import { Object3D as Object3D6 } from "three";
1054
+ var Layer = class extends Object3D6 {
1055
+ constructor(context) {
1056
+ super();
1057
+ this.context = context;
1058
+ }
1059
+ dispose() {
1060
+ dispose(this);
1061
+ this.clear();
1062
+ }
1063
+ };
1064
+
1065
+ // src/layer/graphic-layer.ts
1066
+ var GraphicLayer = class extends Layer {
1067
+ constructor(context) {
1068
+ super(context);
1069
+ }
1070
+ createGraphic(options) {
1071
+ const graphic = new Graphic(this.context, options);
1072
+ this.add(graphic);
1073
+ return graphic;
1074
+ }
1075
+ /**
1076
+ * 获取射线相交的元素
1077
+ * @param raycaster
1078
+ */
1079
+ getGraphicByRaycaster(raycaster) {
1080
+ let position = null;
1081
+ const graphics = this.children.filter((item) => {
1082
+ if (item instanceof Graphic) {
1083
+ const pos = item.raycast(raycaster);
1084
+ if (pos) {
1085
+ if (position) {
1086
+ if (pos.z > position.z) {
1087
+ position = pos;
1088
+ }
1089
+ } else {
1090
+ position = pos;
1091
+ }
1092
+ }
1093
+ return !!pos;
1094
+ }
1095
+ });
1096
+ return { graphics, position };
1097
+ }
1098
+ };
1099
+
1100
+ // src/layer/poi-layer.ts
1101
+ var PoiLayer = class extends Layer {
1102
+ constructor(context) {
1103
+ super(context);
1104
+ __publicField(this, "pois", []);
1105
+ __publicField(this, "onUpdate", () => {
1106
+ this.collisionDetection();
1107
+ });
1108
+ this.registryEvent();
1109
+ }
1110
+ createPoi(options) {
1111
+ const poi = new Poi(this.context, options);
1112
+ this.add(poi);
1113
+ this.pushPoi(poi);
1114
+ poi.addEventListener("change-level", () => this.changePoiLevelOrCollisionEnable(poi));
1115
+ poi.addEventListener("change-collision_enable", () => this.changePoiLevelOrCollisionEnable(poi));
1116
+ return poi;
1117
+ }
1118
+ changePoiLevelOrCollisionEnable(poi) {
1119
+ const index = this.pois.findIndex((item) => item === poi);
1120
+ if (index === -1) {
1121
+ return;
1122
+ }
1123
+ this.pois.splice(index, 1);
1124
+ this.pushPoi(poi);
1125
+ }
1126
+ removePoi(poi) {
1127
+ const index = this.pois.findIndex((item) => item === poi);
1128
+ if (index === -1) {
1129
+ return;
1130
+ }
1131
+ this.pois.splice(index, 1);
1132
+ this.remove(poi);
1133
+ poi.dispose();
1134
+ }
1135
+ /**
1136
+ * 保存poi按照level排序
1137
+ * @param poi
1138
+ */
1139
+ pushPoi(poi) {
1140
+ if (!poi.options.collision_enable) {
1141
+ this.pois.unshift(poi);
1142
+ return;
1143
+ }
1144
+ if (poi.options.level === 1) {
1145
+ this.pois.push(poi);
1146
+ return;
1147
+ }
1148
+ for (let i = 0; i < this.pois.length; i++) {
1149
+ const item = this.pois[i];
1150
+ if (!item.options.collision_enable) {
1151
+ continue;
1152
+ }
1153
+ if (item.options.level <= poi.options.level) {
1154
+ this.pois.splice(i, 0, poi);
1155
+ return;
1156
+ }
1157
+ }
1158
+ this.pois.push(poi);
1159
+ }
1160
+ getPoiByDeviceXy(x, y) {
1161
+ const pois = this.children.filter((item) => {
1162
+ return item instanceof Poi && item.isContain(x, y);
1163
+ });
1164
+ return pois;
1165
+ }
1166
+ /**
1167
+ * 碰撞检测
1168
+ */
1169
+ collisionDetection() {
1170
+ const range = [];
1171
+ this.pois.forEach((item, index) => {
1172
+ item.setVisible(true);
1173
+ const { left, right, top, bottom } = item.getBox();
1174
+ if (index === 0) {
1175
+ range.push({ left, right, top, bottom });
1176
+ return;
1177
+ }
1178
+ const valid = range.some((box) => {
1179
+ const xIntersect = right < box.left || left > box.right;
1180
+ const yIntersect = top > box.bottom || bottom < box.top;
1181
+ return xIntersect || yIntersect;
1182
+ });
1183
+ item.setVisible(valid);
1184
+ });
1185
+ }
1186
+ registryEvent() {
1187
+ this.context.addEventListener("update", this.onUpdate);
1188
+ }
1189
+ unRegistryEvent() {
1190
+ this.context.removeEventListener("update", this.onUpdate);
1191
+ }
1192
+ dispose() {
1193
+ super.dispose();
1194
+ this.unRegistryEvent();
1195
+ this.pois.forEach((item) => item.dispose());
1196
+ this.pois.length = 0;
1197
+ }
1198
+ };
1199
+
1200
+ // src/elements/heatmap.ts
1201
+ import {
1202
+ MeshBasicMaterial as MeshBasicMaterial2,
1203
+ Object3D as Object3D7,
1204
+ PlaneGeometry as PlaneGeometry2,
1205
+ Texture,
1206
+ DoubleSide,
1207
+ Mesh as Mesh3,
1208
+ Matrix3,
1209
+ Vector2 as Vector22
1210
+ } from "three";
1211
+ import { create } from "@mars3d/heatmap.js";
1212
+ import { featureCollection as featureCollection2, point as point2, bbox, center as getCenter2 } from "@turf/turf";
1213
+ var HeatmapElement = class extends Object3D7 {
1214
+ constructor(context) {
1215
+ super();
1216
+ this.context = context;
1217
+ __publicField(this, "heatmap");
1218
+ __publicField(this, "div");
1219
+ __publicField(this, "plane");
1220
+ this.div = document.createElement("div");
1221
+ }
1222
+ clearHeatmap() {
1223
+ if (this.div.firstChild) {
1224
+ this.div.removeChild(this.div.firstChild);
1225
+ }
1226
+ this.heatmap = void 0;
1227
+ }
1228
+ loadData(data) {
1229
+ this.clearHeatmap();
1230
+ const { width, height, leftTop, center: center2 } = this.getBox(data);
1231
+ this.heatmap = create(__spreadValues({
1232
+ width,
1233
+ height,
1234
+ container: this.div
1235
+ }, this.context.config.heatMap));
1236
+ this.heatmap.setData(this.transformData(data, leftTop));
1237
+ this.initPlane(width, height);
1238
+ this.position.set(center2[0], center2[1], this.position.z);
1239
+ }
1240
+ initPlane(width, height) {
1241
+ if (this.plane) {
1242
+ this.remove(this.plane);
1243
+ }
1244
+ const geometry = new PlaneGeometry2(width, height);
1245
+ const texture = new Texture(this.div.firstChild);
1246
+ texture.needsUpdate = true;
1247
+ const material = new MeshBasicMaterial2({
1248
+ transparent: true,
1249
+ side: DoubleSide,
1250
+ map: texture
1251
+ });
1252
+ material.needsUpdate = true;
1253
+ this.plane = new Mesh3(geometry, material);
1254
+ this.add(this.plane);
1255
+ }
1256
+ getTransMatrix({ x, y }) {
1257
+ return new Matrix3().makeScale(1, -1).multiply(new Matrix3().makeTranslation(0 - x, 0 - y));
1258
+ }
1259
+ /**
1260
+ * 所有点的坐标减去左上角从00点开始画canvas
1261
+ * @param data
1262
+ * @param leftTop
1263
+ * @returns
1264
+ */
1265
+ transformData(data, leftTop) {
1266
+ const matrix = this.getTransMatrix(leftTop);
1267
+ const $data = data.data.map((item) => {
1268
+ const vector = new Vector22(item.x, item.y).applyMatrix3(matrix);
1269
+ return {
1270
+ x: vector.x,
1271
+ y: vector.y,
1272
+ value: item.value
1273
+ };
1274
+ });
1275
+ return {
1276
+ data: $data,
1277
+ max: data.max,
1278
+ min: data.min
1279
+ };
1280
+ }
1281
+ getBox(data) {
1282
+ const features = featureCollection2(data.data.map((item) => point2([item.x, item.y])));
1283
+ const box = bbox(features);
1284
+ const width = box[2] - box[0];
1285
+ const height = box[3] - box[1];
1286
+ const leftTop = { x: box[0], y: box[3] };
1287
+ const center2 = getCenter2(features);
1288
+ return { width, height, leftTop, center: center2.geometry.coordinates };
1289
+ }
1290
+ dispose() {
1291
+ this.div = null;
1292
+ this.heatmap = void 0;
1293
+ }
1294
+ };
1295
+
1296
+ // src/elements/floor.ts
1297
+ var Floor = class extends Object3D8 {
1298
+ constructor(context) {
1299
+ super();
1300
+ this.context = context;
1301
+ __publicField(this, "graphicLayer");
1302
+ __publicField(this, "poiLayer");
1303
+ __publicField(this, "ground");
1304
+ __publicField(this, "shadow", new Shadow());
1305
+ __publicField(this, "heatmap");
1306
+ this.graphicLayer = new GraphicLayer(this.context);
1307
+ this.poiLayer = new PoiLayer(this.context);
1308
+ this.add(this.graphicLayer);
1309
+ this.add(this.poiLayer);
1310
+ this.add(this.shadow);
1311
+ }
1312
+ addGround(ground) {
1313
+ this.ground = ground;
1314
+ this.add(ground);
1315
+ const center2 = ground.getCenter();
1316
+ this.shadow.position.x = center2.x;
1317
+ this.shadow.position.y = center2.y;
1318
+ this.shadow.setTarget(ground);
1319
+ }
1320
+ addGraphic(graphicOptions) {
1321
+ return this.graphicLayer.createGraphic(graphicOptions);
1322
+ }
1323
+ addPoi(poiOptions) {
1324
+ return this.poiLayer.createPoi(poiOptions);
1325
+ }
1326
+ addHeatmap(data) {
1327
+ var _a, _b;
1328
+ if (!this.heatmap) {
1329
+ this.heatmap = new HeatmapElement(this.context);
1330
+ this.add(this.heatmap);
1331
+ }
1332
+ this.heatmap.loadData(data);
1333
+ if (this.ground) {
1334
+ this.heatmap.position.setZ(((_a = this.ground) == null ? void 0 : _a.options.airHeight) + ((_b = this.ground) == null ? void 0 : _b.options.height));
1335
+ }
1336
+ return this.heatmap;
1337
+ }
1338
+ removeHeatMap() {
1339
+ if (this.heatmap) {
1340
+ this.remove(this.heatmap);
1341
+ this.heatmap.dispose();
1342
+ this.heatmap = void 0;
1343
+ }
1344
+ }
1345
+ setShadowOpacity(opacity) {
1346
+ this.shadow.setOpacity(opacity);
1347
+ }
1348
+ setShadowVisible(visible) {
1349
+ this.shadow.visible = visible;
1350
+ }
1351
+ dispose() {
1352
+ var _a, _b;
1353
+ this.shadow.dispose();
1354
+ this.graphicLayer.dispose();
1355
+ this.poiLayer.dispose();
1356
+ (_a = this.ground) == null ? void 0 : _a.dispose();
1357
+ (_b = this.heatmap) == null ? void 0 : _b.dispose();
1358
+ this.clear();
1359
+ }
1360
+ };
1361
+
1362
+ // src/elements/base-svg.ts
1363
+ import { EventDispatcher as EventDispatcher3, Raycaster as Raycaster3, Vector2 as Vector23 } from "three";
1364
+ var BaseSvg = class extends EventDispatcher3 {
1365
+ constructor(context) {
1366
+ super();
1367
+ this.context = context;
1368
+ __publicField(this, "points", []);
1369
+ __publicField(this, "svg");
1370
+ __publicField(this, "enable", true);
1371
+ this.svg = createSvg(`${context.container.clientWidth}`, `${context.container.clientHeight}`);
1372
+ context.container.appendChild(this.svg);
1373
+ }
1374
+ setEnable(enable) {
1375
+ this.enable = enable;
1376
+ if (enable) {
1377
+ this.svg.style.display = "block";
1378
+ } else {
1379
+ this.svg.style.display = "none";
1380
+ }
1381
+ }
1382
+ getIntersectByPointerEvent(e) {
1383
+ var _a;
1384
+ if (!((_a = this.context.currentFloor) == null ? void 0 : _a.ground)) {
1385
+ return;
1386
+ }
1387
+ const { offsetX: x, offsetY: y } = e;
1388
+ const point3 = new Vector23();
1389
+ point3.x = x / this.context.container.clientWidth * 2 - 1;
1390
+ point3.y = y / this.context.container.clientHeight * -2 + 1;
1391
+ const raycaster = new Raycaster3();
1392
+ raycaster.setFromCamera(point3, this.context.camera);
1393
+ const intersects = raycaster.intersectObjects(this.context.currentFloor.ground.children, true);
1394
+ return intersects[0];
1395
+ }
1396
+ getSvgCoordinate(vector) {
1397
+ const { camera, container } = this.context;
1398
+ const coord = vector3ToDevice(vector, camera, container.clientWidth, container.clientHeight);
1399
+ return coord;
1400
+ }
1401
+ dispose() {
1402
+ this.context.container.removeChild(this.svg);
1403
+ this.svg = null;
1404
+ }
1405
+ };
1406
+
1407
+ // src/elements/svg-line.ts
1408
+ var SvgLine = class extends BaseSvg {
1409
+ constructor(context) {
1410
+ super(context);
1411
+ this.context = context;
1412
+ __publicField(this, "circles");
1413
+ __publicField(this, "line");
1414
+ __publicField(this, "onUpdate", () => {
1415
+ if (this.points[0]) {
1416
+ const point1 = this.getSvgCoordinate(this.points[0]);
1417
+ setCirclePosition(this.circles[0], point1.x, point1.y);
1418
+ setLineStartEnd(this.line, point1);
1419
+ }
1420
+ if (this.points[1]) {
1421
+ const point22 = this.getSvgCoordinate(this.points[1]);
1422
+ setCirclePosition(this.circles[1], point22.x, point22.y);
1423
+ setLineStartEnd(this.line, void 0, point22);
1424
+ }
1425
+ });
1426
+ __publicField(this, "onPointermove", (e) => {
1427
+ if (this.points.length !== 1) {
1428
+ return;
1429
+ }
1430
+ this.line.style.display = "block";
1431
+ setLineStartEnd(this.line, void 0, { x: e.offsetX, y: e.offsetY });
1432
+ });
1433
+ __publicField(this, "onPointerleave", () => {
1434
+ if (this.points[1]) {
1435
+ return;
1436
+ }
1437
+ this.line.style.display = "none";
1438
+ });
1439
+ __publicField(this, "onPointerdown", (e) => {
1440
+ if (this.points[1]) {
1441
+ return;
1442
+ }
1443
+ const intersect = this.getIntersectByPointerEvent(e);
1444
+ if (intersect == null ? void 0 : intersect.point) {
1445
+ const { offsetX: x, offsetY: y } = e;
1446
+ const circle = this.circles[this.points.length];
1447
+ setCirclePosition(circle, x, y);
1448
+ if (!this.points.length) {
1449
+ setLineStartEnd(this.line, { x, y }, { x, y });
1450
+ }
1451
+ this.addPoint(intersect.point);
1452
+ }
1453
+ });
1454
+ const { config: { svg: { circle, line } } } = context;
1455
+ this.circles = [createCircle(circle.radius, circle.fill), createCircle(circle.radius, circle.fill)];
1456
+ this.line = createLine(line.stroke);
1457
+ this.svg.appendChild(this.circles[0]);
1458
+ this.svg.appendChild(this.circles[1]);
1459
+ this.svg.appendChild(this.line);
1460
+ this.registryEvent();
1461
+ }
1462
+ setEnable(enable) {
1463
+ super.setEnable(enable);
1464
+ if (enable) {
1465
+ this.registryEvent();
1466
+ } else {
1467
+ this.unRegistryEvent();
1468
+ }
1469
+ }
1470
+ registryEvent() {
1471
+ this.context.container.addEventListener("pointerenter", this.onPointermove);
1472
+ this.context.container.addEventListener("pointermove", this.onPointermove);
1473
+ this.context.container.addEventListener("pointerleave", this.onPointerleave);
1474
+ this.context.container.addEventListener("pointerdown", this.onPointerdown);
1475
+ this.context.addEventListener("update", this.onUpdate);
1476
+ }
1477
+ unRegistryEvent() {
1478
+ this.context.container.removeEventListener("pointerenter", this.onPointermove);
1479
+ this.context.container.removeEventListener("pointermove", this.onPointermove);
1480
+ this.context.container.removeEventListener("pointerleave", this.onPointerleave);
1481
+ this.context.container.removeEventListener("pointerdown", this.onPointerdown);
1482
+ this.context.removeEventListener("update", this.onUpdate);
1483
+ }
1484
+ addPoint(vector) {
1485
+ this.points.push(vector);
1486
+ if (this.points.length >= 2) {
1487
+ const distance = this.calculatedDistance();
1488
+ this.dispatchEvent({ type: "distance", distance });
1489
+ }
1490
+ }
1491
+ /**
1492
+ * 计算两个点之间的距离
1493
+ */
1494
+ calculatedDistance() {
1495
+ const [{ x: x1, y: y1 }, { x: x2, y: y2 }] = this.points;
1496
+ return Math.sqrt(__pow(x2 - x1, 2) + __pow(y2 - y1, 2));
1497
+ }
1498
+ dispose() {
1499
+ super.dispose();
1500
+ this.unRegistryEvent();
1501
+ this.line = null;
1502
+ this.circles = [];
1503
+ }
1504
+ };
1505
+
1506
+ // src/elements/svg-polygon.ts
1507
+ var SvgPolygon = class extends BaseSvg {
1508
+ constructor(context) {
1509
+ super(context);
1510
+ __publicField(this, "circles", []);
1511
+ __publicField(this, "lines", []);
1512
+ __publicField(this, "isClose", false);
1513
+ __publicField(this, "onUpdate", () => {
1514
+ if (this.points.length) {
1515
+ this.points.forEach((point3, index) => {
1516
+ const devicePoint = this.getSvgCoordinate(point3);
1517
+ if (this.circles[index]) {
1518
+ setCirclePosition(this.circles[index], devicePoint.x, devicePoint.y);
1519
+ }
1520
+ if (index !== 0) {
1521
+ setLineStartEnd(this.lines[index - 1], void 0, devicePoint);
1522
+ }
1523
+ if (this.lines[index]) {
1524
+ setLineStartEnd(this.lines[index], devicePoint);
1525
+ }
1526
+ });
1527
+ }
1528
+ });
1529
+ __publicField(this, "onPointermove", (e) => {
1530
+ if (!this.lastLine || this.isClose) {
1531
+ return;
1532
+ }
1533
+ this.lastLine.style.display = "block";
1534
+ setLineStartEnd(this.lastLine, void 0, { x: e.offsetX, y: e.offsetY });
1535
+ });
1536
+ __publicField(this, "onPointerleave", () => {
1537
+ if (this.isClose) {
1538
+ return;
1539
+ }
1540
+ this.lastLine.style.display = "none";
1541
+ });
1542
+ __publicField(this, "onPointerdown", (e) => {
1543
+ if (this.isClose) {
1544
+ return;
1545
+ }
1546
+ const intersect = this.getIntersectByPointerEvent(e);
1547
+ if (intersect == null ? void 0 : intersect.point) {
1548
+ const { offsetX: x, offsetY: y } = e;
1549
+ if (this.checkAdsorb(x, y)) {
1550
+ this.isClose = true;
1551
+ this.addPoint(this.points[0]);
1552
+ } else {
1553
+ this.addPoint(intersect.point);
1554
+ }
1555
+ const { circle: { fill, radius }, line: { stroke } } = this.context.config.svg;
1556
+ if (!this.isClose) {
1557
+ const circle = createCircle(radius, fill);
1558
+ setCirclePosition(circle, x, y);
1559
+ this.addCircle(circle);
1560
+ }
1561
+ if (this.lines.length) {
1562
+ setLineStartEnd(this.lastLine, void 0, { x, y });
1563
+ }
1564
+ if (!this.isClose) {
1565
+ const line = createLine(stroke);
1566
+ setLineStartEnd(line, { x, y }, { x, y });
1567
+ this.addLine(line);
1568
+ }
1569
+ }
1570
+ });
1571
+ this.registryEvent();
1572
+ }
1573
+ setEnable(enable) {
1574
+ super.setEnable(enable);
1575
+ if (enable) {
1576
+ this.registryEvent();
1577
+ } else {
1578
+ this.unRegistryEvent();
1579
+ }
1580
+ }
1581
+ get lastLine() {
1582
+ return this.lines.slice(-1)[0];
1583
+ }
1584
+ addCircle(circle) {
1585
+ this.circles.push(circle);
1586
+ this.svg.appendChild(circle);
1587
+ }
1588
+ addLine(line) {
1589
+ this.lines.push(line);
1590
+ this.svg.appendChild(line);
1591
+ }
1592
+ registryEvent() {
1593
+ this.context.container.addEventListener("pointerenter", this.onPointermove);
1594
+ this.context.container.addEventListener("pointermove", this.onPointermove);
1595
+ this.context.container.addEventListener("pointerleave", this.onPointerleave);
1596
+ this.context.container.addEventListener("pointerdown", this.onPointerdown);
1597
+ this.context.addEventListener("update", this.onUpdate);
1598
+ }
1599
+ unRegistryEvent() {
1600
+ this.context.container.removeEventListener("pointerenter", this.onPointermove);
1601
+ this.context.container.removeEventListener("pointermove", this.onPointermove);
1602
+ this.context.container.removeEventListener("pointerleave", this.onPointerleave);
1603
+ this.context.container.removeEventListener("pointerdown", this.onPointerdown);
1604
+ this.context.removeEventListener("update", this.onUpdate);
1605
+ }
1606
+ /**
1607
+ * 检测是否可以吸附
1608
+ * 坐标点最少3个 传入的坐标点和第一个坐标的像素相差不超过5个像素
1609
+ */
1610
+ checkAdsorb(x, y) {
1611
+ if (this.points.length < 3) {
1612
+ return false;
1613
+ }
1614
+ const circle = this.circles[0];
1615
+ const cx = +circle.getAttribute("cx");
1616
+ const cy = +circle.getAttribute("cy");
1617
+ return Math.sqrt(__pow(x - cx, 2) + __pow(y - cy, 2)) <= 5;
1618
+ }
1619
+ addPoint(vector) {
1620
+ this.points.push(vector);
1621
+ if (this.isClose) {
1622
+ const area = this.calculatedArea();
1623
+ this.dispatchEvent({ type: "area", area });
1624
+ }
1625
+ }
1626
+ // 计算面积
1627
+ calculatedArea() {
1628
+ const cds = this.points.map((item) => [item.x, item.y]);
1629
+ let area = 0;
1630
+ const numPoints = cds.length;
1631
+ for (let i = 0; i < numPoints; i++) {
1632
+ const j = (i + 1) % numPoints;
1633
+ area += cds[i][0] * cds[j][1] - cds[j][0] * cds[i][1];
1634
+ }
1635
+ return Math.abs(area / 2);
1636
+ }
1637
+ dispose() {
1638
+ super.dispose();
1639
+ this.unRegistryEvent();
1640
+ this.lines = [];
1641
+ this.circles = [];
1642
+ }
1643
+ };
1644
+
1645
+ // src/bmap.ts
1646
+ var BMap = class extends EventDispatcher4 {
1647
+ constructor(container, config = {}) {
1648
+ super();
1649
+ this.container = container;
1650
+ __publicField(this, "config");
1651
+ __publicField(this, "context");
1652
+ __publicField(this, "polarKeys", []);
1653
+ __publicField(this, "azimuthalKeys", []);
1654
+ __publicField(this, "svgLine");
1655
+ __publicField(this, "svgPolygon");
1656
+ __publicField(this, "floorDataMap", /* @__PURE__ */ new Map());
1657
+ __publicField(this, "onKeydown", (e) => {
1658
+ if (this.polarKeys.includes(e.code)) {
1659
+ this.context.control.maxPolarAngle = 1.2;
1660
+ this.context.control.minPolarAngle = 0;
1661
+ }
1662
+ if (this.azimuthalKeys.includes(e.code)) {
1663
+ this.context.control.maxAzimuthAngle = Infinity;
1664
+ this.context.control.minAzimuthAngle = Infinity;
1665
+ }
1666
+ });
1667
+ __publicField(this, "onKeyUp", (e) => {
1668
+ if (this.polarKeys.includes(e.code)) {
1669
+ const polar = this.context.control.getPolarAngle();
1670
+ this.context.control.maxPolarAngle = polar;
1671
+ this.context.control.minPolarAngle = polar;
1672
+ }
1673
+ if (this.azimuthalKeys.includes(e.code)) {
1674
+ const azimuthal = this.context.control.getAzimuthalAngle();
1675
+ this.context.control.maxAzimuthAngle = azimuthal;
1676
+ this.context.control.minAzimuthAngle = azimuthal;
1677
+ }
1678
+ });
1679
+ this.config = getConfig(config);
1680
+ this.context = new Context(container, this.config);
1681
+ this.registryEvent();
1682
+ this.context.render();
1683
+ }
1684
+ loadGraphics(_0) {
1685
+ return __async(this, arguments, function* ({ brand, project, phase, building, floor, ts }) {
1686
+ const { apiDomain } = this.config;
1687
+ const url = `${apiDomain}/api/floor/get?brand=${brand}&project=${project}&phase=${phase}&building=${building}&floor=${floor}&ts=${ts}&resource_type_list=`;
1688
+ const data = yield fetch(url).then((res) => res.json()).then((res) => res.data).then((res) => {
1689
+ res.map((item) => item.info = JSON.parse(item.info));
1690
+ return res;
1691
+ });
1692
+ return data;
1693
+ });
1694
+ }
1695
+ loadBuildingGround(_0) {
1696
+ return __async(this, arguments, function* ({ brand, project, phase, building }) {
1697
+ const { apiDomain } = this.config;
1698
+ const url = `${apiDomain}/api/range/get?brand=${brand}&project=${project}&phase=${phase}&building=${building}`;
1699
+ const data = yield fetch(url).then((res) => res.json()).then((res) => res.data).then((res) => {
1700
+ res.map((item) => item.info = JSON.parse(item.info));
1701
+ return res;
1702
+ });
1703
+ return data[0];
1704
+ });
1705
+ }
1706
+ load(_0) {
1707
+ return __async(this, arguments, function* ({ brand, project, phase, building, floor, ts }) {
1708
+ if (this.floorDataMap.get(floor)) {
1709
+ return;
1710
+ }
1711
+ const [data, buildGround] = yield Promise.all([
1712
+ this.loadGraphics({ brand, project, phase, building, floor, ts }),
1713
+ this.loadBuildingGround({ brand, project, phase, building })
1714
+ ]);
1715
+ const center2 = getCenter(buildGround.info.geometry.cds[0]);
1716
+ data.forEach((item) => {
1717
+ item.info.geometry.cds.map((cds) => {
1718
+ if (Array.isArray(cds)) {
1719
+ cds.forEach((coord) => {
1720
+ coord[0] -= center2[0];
1721
+ coord[1] -= center2[1];
1722
+ });
1723
+ }
1724
+ });
1725
+ });
1726
+ if (!this.config.useFloorCache) {
1727
+ this.floorDataMap.clear();
1728
+ }
1729
+ this.floorDataMap.set(floor, data);
1730
+ return data;
1731
+ });
1732
+ }
1733
+ createFloor(data) {
1734
+ const curFloor = new Floor(this.context);
1735
+ let groundIndex = data.findIndex((item) => item.info.group === "floor");
1736
+ if (groundIndex === -1) {
1737
+ groundIndex = 0;
1738
+ }
1739
+ const ground = data[groundIndex];
1740
+ const list = [...data];
1741
+ list.splice(groundIndex, 1);
1742
+ const groundGraphic = new Graphic(this.context, ground.info);
1743
+ curFloor.addGround(groundGraphic);
1744
+ const graphics = [];
1745
+ return { curFloor, ground: groundGraphic, graphics };
1746
+ }
1747
+ switchFloor(floor) {
1748
+ const curFloorData = this.floorDataMap.get(floor);
1749
+ if (curFloorData) {
1750
+ const { curFloor } = this.createFloor(curFloorData);
1751
+ this.context.switchFloor(curFloor);
1752
+ this.context.fitCameraToGround(void 0, 0);
1753
+ } else {
1754
+ console.warn("[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42");
1755
+ }
1756
+ }
1757
+ addHeatmap(data) {
1758
+ var _a;
1759
+ return (_a = this.context.currentFloor) == null ? void 0 : _a.addHeatmap(data);
1760
+ }
1761
+ removeHeatMap() {
1762
+ var _a;
1763
+ (_a = this.context.currentFloor) == null ? void 0 : _a.removeHeatMap();
1764
+ }
1765
+ /**
1766
+ * 移动相机位置让选中的元素居中显示
1767
+ * @param ele { Graphic | Poi }
1768
+ * @param duration
1769
+ */
1770
+ translateElementToCenter(ele, duration = 500) {
1771
+ const position = ele.position.clone().setFromMatrixPosition(ele.matrixWorld);
1772
+ return this.context.setCameraPosition(position, duration);
1773
+ }
1774
+ /**
1775
+ * 获取物体的屏幕坐标
1776
+ */
1777
+ getElementDeviceCoordinate(ele) {
1778
+ const vector = ele.position.clone();
1779
+ const { clientWidth, clientHeight } = this.container;
1780
+ return vector3ToDevice(
1781
+ vector,
1782
+ this.context.camera,
1783
+ clientWidth,
1784
+ clientHeight
1785
+ );
1786
+ }
1787
+ /**
1788
+ * 切换2d、3d视角
1789
+ * @param type
1790
+ * @param duration
1791
+ */
1792
+ changeMapType(type, duration = 500) {
1793
+ if (type === "2d") {
1794
+ this.context.setPolarAngle(0);
1795
+ } else {
1796
+ this.context.setPolarAngle(1.2);
1797
+ }
1798
+ }
1799
+ /**
1800
+ * 缩小地图
1801
+ * @param zoom
1802
+ * @param duration
1803
+ * @returns
1804
+ */
1805
+ reduceMap(zoom = 0.5, duration = 500) {
1806
+ const cameraZoom = this.context.camera.zoom;
1807
+ return this.context.setZoom(
1808
+ cameraZoom - zoom,
1809
+ this.context.control.target,
1810
+ duration
1811
+ );
1812
+ }
1813
+ /**
1814
+ * 放大地图
1815
+ * @param zoom
1816
+ * @param duration
1817
+ * @returns
1818
+ */
1819
+ enlargeMap(zoom = 0.5, duration = 500) {
1820
+ const cameraZoom = this.context.camera.zoom;
1821
+ return this.context.setZoom(
1822
+ cameraZoom + zoom,
1823
+ this.context.control.target,
1824
+ duration
1825
+ );
1826
+ }
1827
+ registryEvent() {
1828
+ window.addEventListener("keydown", this.onKeydown);
1829
+ window.addEventListener("keyup", this.onKeyUp);
1830
+ }
1831
+ unRegistryEvent() {
1832
+ window.removeEventListener("keydown", this.onKeydown);
1833
+ window.removeEventListener("keyup", this.onKeyUp);
1834
+ }
1835
+ /**
1836
+ * 配置坐标定点 2D/3D线性切换的快捷键
1837
+ * @param key
1838
+ */
1839
+ configurePolarShortcutKeys(keys) {
1840
+ this.polarKeys = keys;
1841
+ }
1842
+ configureAzimuthalShortcutKeys(keys) {
1843
+ this.azimuthalKeys = keys;
1844
+ }
1845
+ rotateMap(radius = 0.1) {
1846
+ const azimuthal = this.context.control.getAzimuthalAngle();
1847
+ this.context.control.maxAzimuthAngle = azimuthal + radius;
1848
+ this.context.control.minAzimuthAngle = azimuthal + radius;
1849
+ this.context.control.update();
1850
+ }
1851
+ /**
1852
+ * 测量距离
1853
+ * @returns
1854
+ */
1855
+ measureDistance() {
1856
+ return __async(this, null, function* () {
1857
+ this.cancelDistance();
1858
+ return new Promise((resolve, reject) => {
1859
+ this.changeMapType("2d", 0);
1860
+ this.context.control.enableRotate = false;
1861
+ this.svgLine = new SvgLine(this.context);
1862
+ const dispose2 = this.svgLine.dispose.bind(this.svgLine);
1863
+ this.svgLine.dispose = function() {
1864
+ dispose2();
1865
+ reject("cancel");
1866
+ };
1867
+ this.svgLine.addEventListener("distance", ({ distance }) => {
1868
+ resolve(distance);
1869
+ });
1870
+ });
1871
+ });
1872
+ }
1873
+ /**
1874
+ * 取消测量长度
1875
+ */
1876
+ cancelDistance() {
1877
+ if (this.svgLine) {
1878
+ this.svgLine.dispose();
1879
+ this.svgLine = void 0;
1880
+ this.context.control.enableRotate = true;
1881
+ }
1882
+ }
1883
+ /**
1884
+ * 测量面积
1885
+ */
1886
+ measureArea() {
1887
+ this.cancelArea();
1888
+ return new Promise((resolve, reject) => {
1889
+ this.changeMapType("2d", 0);
1890
+ this.context.control.enableRotate = false;
1891
+ this.svgPolygon = new SvgPolygon(this.context);
1892
+ const dispose2 = this.svgPolygon.dispose.bind(this.svgPolygon);
1893
+ this.svgPolygon.dispose = function() {
1894
+ dispose2();
1895
+ reject("cancel");
1896
+ };
1897
+ this.svgPolygon.addEventListener("area", ({ area }) => {
1898
+ resolve(area);
1899
+ });
1900
+ });
1901
+ }
1902
+ /**
1903
+ * 取消测量面积
1904
+ */
1905
+ cancelArea() {
1906
+ if (this.svgPolygon) {
1907
+ this.svgPolygon.dispose();
1908
+ this.svgPolygon = void 0;
1909
+ this.context.control.enableRotate = true;
1910
+ }
1911
+ }
1912
+ dispose() {
1913
+ this.context.dispose();
1914
+ clearTextTexture();
1915
+ clearCanvas();
1916
+ this.unRegistryEvent();
1917
+ }
1918
+ };
1919
+ export {
1920
+ BMap,
1921
+ Floor,
1922
+ Graphic,
1923
+ HeatmapElement,
1924
+ Overlay,
1925
+ Poi,
1926
+ Shadow,
1927
+ SvgLine,
1928
+ SvgPolygon,
1929
+ Timer,
1930
+ clearCanvas,
1931
+ clearTextTexture,
1932
+ createCanvas,
1933
+ createCircle,
1934
+ createLine,
1935
+ createSvg,
1936
+ createSvgElement,
1937
+ defaultConfig,
1938
+ dispose,
1939
+ getCenter,
1940
+ getConfig,
1941
+ getTextureByText,
1942
+ hasChinese,
1943
+ initCamera,
1944
+ initCanvas,
1945
+ initControl,
1946
+ initDirectionalLight,
1947
+ initLight,
1948
+ initRenderer,
1949
+ initScene,
1950
+ initShape,
1951
+ proxyOptions,
1952
+ setCirclePosition,
1953
+ setLineStartEnd,
1954
+ timeoutPromise,
1955
+ vector3ToDevice
1956
+ };
1957
+ //# sourceMappingURL=bmap.esm.js.map