@aibee/crc-bmap 0.0.66 → 0.0.68
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/lib/bmap.cjs.min.js +1 -1
- package/lib/bmap.cjs.min.js.map +4 -4
- package/lib/bmap.esm.js +133 -28
- package/lib/bmap.esm.js.map +4 -4
- package/lib/bmap.esm.min.js +1 -1
- package/lib/bmap.esm.min.js.map +4 -4
- package/lib/bmap.min.js +1 -1
- package/lib/bmap.min.js.map +4 -4
- package/lib/src/bmap.d.ts +2 -4
- package/lib/src/config.d.ts +3 -0
- package/lib/src/context.d.ts +2 -1
- package/lib/src/elements/model.d.ts +3 -1
- package/lib/src/utils/camera-bound.d.ts +31 -0
- package/lib/src/utils/model.d.ts +1 -1
- package/package.json +1 -1
package/lib/bmap.esm.js
CHANGED
|
@@ -44,7 +44,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
// src/bmap.ts
|
|
47
|
-
import { EventDispatcher as EventDispatcher7, Vector3 as
|
|
47
|
+
import { EventDispatcher as EventDispatcher7, Vector3 as Vector313 } from "three";
|
|
48
48
|
|
|
49
49
|
// src/utils/timer.ts
|
|
50
50
|
var Timer = class {
|
|
@@ -303,6 +303,7 @@ function getLongestSideDir(cds) {
|
|
|
303
303
|
const point_1 = new Vector3(cds[i][0], cds[i][1], 0);
|
|
304
304
|
const distance = point_1.distanceTo(point_0);
|
|
305
305
|
if (distance > maxDistance) {
|
|
306
|
+
maxDistance = distance;
|
|
306
307
|
dir = point_1.clone().sub(point_0).normalize();
|
|
307
308
|
}
|
|
308
309
|
}
|
|
@@ -420,18 +421,22 @@ var loader = null;
|
|
|
420
421
|
var modelMap = /* @__PURE__ */ new Map();
|
|
421
422
|
function loadModel(url) {
|
|
422
423
|
if (modelMap.has(url)) {
|
|
423
|
-
|
|
424
|
+
const gltf = modelMap.get(url).then((gltf2) => {
|
|
425
|
+
gltf2.scene = gltf2.scene.clone();
|
|
426
|
+
return gltf2;
|
|
427
|
+
});
|
|
424
428
|
}
|
|
425
429
|
if (!loader) {
|
|
426
430
|
loader = createLoader();
|
|
427
431
|
}
|
|
428
432
|
const p = new Promise((resolve, reject) => {
|
|
429
|
-
loader.load(url,
|
|
430
|
-
resolve(gltf);
|
|
431
|
-
}, void 0, reject);
|
|
433
|
+
loader.load(url, resolve, void 0, reject);
|
|
432
434
|
});
|
|
433
435
|
modelMap.set(url, p);
|
|
434
|
-
return p
|
|
436
|
+
return p.then((gltf) => {
|
|
437
|
+
gltf.scene = gltf.scene.clone();
|
|
438
|
+
return gltf;
|
|
439
|
+
});
|
|
435
440
|
}
|
|
436
441
|
function disposeLoader() {
|
|
437
442
|
loader = null;
|
|
@@ -442,10 +447,10 @@ function disposeLoader() {
|
|
|
442
447
|
import {
|
|
443
448
|
EventDispatcher as EventDispatcher6,
|
|
444
449
|
Box2,
|
|
445
|
-
Vector3 as
|
|
450
|
+
Vector3 as Vector312,
|
|
446
451
|
Vector2 as Vector23,
|
|
447
452
|
Raycaster as Raycaster3,
|
|
448
|
-
Box3 as
|
|
453
|
+
Box3 as Box38,
|
|
449
454
|
Color as Color4,
|
|
450
455
|
AmbientLight as AmbientLight2
|
|
451
456
|
} from "three";
|
|
@@ -1388,6 +1393,7 @@ var Model = class extends Object3D7 {
|
|
|
1388
1393
|
this.options = options;
|
|
1389
1394
|
__publicField(this, "overlay", null);
|
|
1390
1395
|
__publicField(this, "model", null);
|
|
1396
|
+
this.position.copy(options.position || new Vector37(0, 0, 0));
|
|
1391
1397
|
this.loadModel();
|
|
1392
1398
|
}
|
|
1393
1399
|
loadModel() {
|
|
@@ -1401,17 +1407,25 @@ var Model = class extends Object3D7 {
|
|
|
1401
1407
|
});
|
|
1402
1408
|
}
|
|
1403
1409
|
initOverlay() {
|
|
1410
|
+
var _a, _b;
|
|
1404
1411
|
if (!this.options.icon) {
|
|
1405
1412
|
return;
|
|
1406
1413
|
}
|
|
1407
1414
|
if (this.model) {
|
|
1408
|
-
const
|
|
1409
|
-
const
|
|
1410
|
-
const
|
|
1411
|
-
overlay
|
|
1415
|
+
const w = ((_a = this.options.icon_size) == null ? void 0 : _a[0]) || 14;
|
|
1416
|
+
const h = ((_b = this.options.icon_size) == null ? void 0 : _b[1]) || 14;
|
|
1417
|
+
const box = new Box34().setFromObject(this);
|
|
1418
|
+
const overlay = new Overlay(this.context, { autoUpdate: false });
|
|
1419
|
+
overlay.addEventListener("update-position", ({ x, y, height }) => {
|
|
1420
|
+
overlay.div.style.transform = `translate3d(${x - w / 2}px, ${-height + y - h}px, 0)`;
|
|
1421
|
+
});
|
|
1412
1422
|
const img = document.createElement("img");
|
|
1413
1423
|
img.src = this.options.icon;
|
|
1424
|
+
img.style.width = `${w}px`;
|
|
1425
|
+
img.style.height = `${h}px`;
|
|
1414
1426
|
overlay.div.appendChild(img);
|
|
1427
|
+
const center2 = box.getCenter(new Vector37());
|
|
1428
|
+
overlay.position = center2;
|
|
1415
1429
|
this.overlay = overlay;
|
|
1416
1430
|
}
|
|
1417
1431
|
}
|
|
@@ -2284,6 +2298,93 @@ var MaterialFactory = class {
|
|
|
2284
2298
|
}
|
|
2285
2299
|
};
|
|
2286
2300
|
|
|
2301
|
+
// src/utils/camera-bound.ts
|
|
2302
|
+
import { Box3 as Box37, Vector3 as Vector311 } from "three";
|
|
2303
|
+
var CameraBound = class {
|
|
2304
|
+
constructor(context) {
|
|
2305
|
+
this.context = context;
|
|
2306
|
+
__publicField(this, "prevCamera", {
|
|
2307
|
+
position: new Vector311(),
|
|
2308
|
+
zoom: 1,
|
|
2309
|
+
target: new Vector311()
|
|
2310
|
+
});
|
|
2311
|
+
__publicField(this, "enable", true);
|
|
2312
|
+
__publicField(this, "onCameraChange", () => {
|
|
2313
|
+
const bound = this.getCurFloorScreenPosition();
|
|
2314
|
+
if (bound) {
|
|
2315
|
+
const { left, right, top, bottom } = bound;
|
|
2316
|
+
const isInBound = this.checkDistanceToScreenEdge({ left, right, top, bottom });
|
|
2317
|
+
if (isInBound) {
|
|
2318
|
+
this.changePrevCamera();
|
|
2319
|
+
} else {
|
|
2320
|
+
this.backToPrevCamera();
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
});
|
|
2324
|
+
this.registryEvent();
|
|
2325
|
+
this.changePrevCamera();
|
|
2326
|
+
}
|
|
2327
|
+
setEnable(enable) {
|
|
2328
|
+
this.enable = enable;
|
|
2329
|
+
if (enable) {
|
|
2330
|
+
this.registryEvent();
|
|
2331
|
+
} else {
|
|
2332
|
+
this.unRegistryEvent();
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
changePrevCamera() {
|
|
2336
|
+
this.prevCamera = {
|
|
2337
|
+
position: this.context.camera.position.clone(),
|
|
2338
|
+
zoom: this.context.camera.zoom,
|
|
2339
|
+
target: this.context.control.target.clone()
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
backToPrevCamera() {
|
|
2343
|
+
this.setEnable(false);
|
|
2344
|
+
this.context.camera.position.copy(this.prevCamera.position);
|
|
2345
|
+
this.context.camera.zoom = this.prevCamera.zoom;
|
|
2346
|
+
this.context.control.target.copy(this.prevCamera.target);
|
|
2347
|
+
this.context.control.update();
|
|
2348
|
+
this.setEnable(true);
|
|
2349
|
+
}
|
|
2350
|
+
registryEvent() {
|
|
2351
|
+
this.context.addEventListener("control-change", this.onCameraChange);
|
|
2352
|
+
}
|
|
2353
|
+
unRegistryEvent() {
|
|
2354
|
+
this.context.removeEventListener("control-change", this.onCameraChange);
|
|
2355
|
+
}
|
|
2356
|
+
getCurFloorScreenPosition() {
|
|
2357
|
+
if (!this.context.currentFloor) {
|
|
2358
|
+
return null;
|
|
2359
|
+
}
|
|
2360
|
+
const box = new Box37().setFromObject(this.context.currentFloor.groundUpper);
|
|
2361
|
+
const { camera, container: { clientWidth: w, clientHeight: h } } = this.context;
|
|
2362
|
+
const { min, max } = box;
|
|
2363
|
+
const lb = vector3ToDevice(min, camera, w, h);
|
|
2364
|
+
const rt = vector3ToDevice(max, camera, w, h);
|
|
2365
|
+
const lt = vector3ToDevice(new Vector311(min.x, max.y, max.z), camera, w, h);
|
|
2366
|
+
const rb = vector3ToDevice(new Vector311(max.x, min.y, min.z), camera, w, h);
|
|
2367
|
+
const left = Math.min(lb.x, rt.x, lt.x, rb.x);
|
|
2368
|
+
const right = Math.max(lb.x, rt.x, lt.x, rb.x);
|
|
2369
|
+
const top = Math.min(lb.y, rt.y, lt.y, rb.y);
|
|
2370
|
+
const bottom = Math.max(lb.y, rt.y, lt.y, rb.y);
|
|
2371
|
+
return { left, right, top, bottom };
|
|
2372
|
+
}
|
|
2373
|
+
/**
|
|
2374
|
+
* 检测地图是不是在显示范围
|
|
2375
|
+
* @param param0
|
|
2376
|
+
* @returns
|
|
2377
|
+
*/
|
|
2378
|
+
checkDistanceToScreenEdge({ left, right, top, bottom }) {
|
|
2379
|
+
const { width, height } = this.context.clientSize;
|
|
2380
|
+
const [pt, pr, pb, pl] = this.context.config.cameraBound.padding;
|
|
2381
|
+
return left <= pl && width - right <= pr && top <= pt && height - bottom <= pb;
|
|
2382
|
+
}
|
|
2383
|
+
dispose() {
|
|
2384
|
+
this.unRegistryEvent();
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2387
|
+
|
|
2287
2388
|
// src/context.ts
|
|
2288
2389
|
var Context = class extends EventDispatcher6 {
|
|
2289
2390
|
constructor(container, config) {
|
|
@@ -2304,7 +2405,7 @@ var Context = class extends EventDispatcher6 {
|
|
|
2304
2405
|
__publicField(this, "basicRatio");
|
|
2305
2406
|
// zoom=1的时候,100M对应的像素个数
|
|
2306
2407
|
__publicField(this, "materialFactory");
|
|
2307
|
-
__publicField(this, "
|
|
2408
|
+
__publicField(this, "cameraBound");
|
|
2308
2409
|
__publicField(this, "clientSize", {
|
|
2309
2410
|
width: 0,
|
|
2310
2411
|
height: 0
|
|
@@ -2387,11 +2488,12 @@ var Context = class extends EventDispatcher6 {
|
|
|
2387
2488
|
this.dispatchEvent({ type: "change-ratio", px: (this.basicRatio || 0) * this.camera.zoom });
|
|
2388
2489
|
this.dispatchEvent({ type: "control-change" });
|
|
2389
2490
|
});
|
|
2491
|
+
this.cameraBound = new CameraBound(this);
|
|
2390
2492
|
}
|
|
2391
2493
|
/**
|
|
2392
2494
|
* 获取两个点之间的像素数
|
|
2393
2495
|
*/
|
|
2394
|
-
getRatio(point1 = new
|
|
2496
|
+
getRatio(point1 = new Vector312(0, 0, 0), point22 = new Vector312(100, 0, 0)) {
|
|
2395
2497
|
const { clientWidth, clientHeight } = this.container;
|
|
2396
2498
|
const device1 = vector3ToDevice(point1, this.camera, clientWidth, clientHeight);
|
|
2397
2499
|
const device2 = vector3ToDevice(point22, this.camera, clientWidth, clientHeight);
|
|
@@ -2531,7 +2633,7 @@ var Context = class extends EventDispatcher6 {
|
|
|
2531
2633
|
);
|
|
2532
2634
|
}
|
|
2533
2635
|
getCameraLookAt() {
|
|
2534
|
-
return new
|
|
2636
|
+
return new Vector312().subVectors(this.control.target, this.camera.position);
|
|
2535
2637
|
}
|
|
2536
2638
|
/**
|
|
2537
2639
|
* 按照一个中心点设置相机的放大缩小
|
|
@@ -2590,7 +2692,7 @@ var Context = class extends EventDispatcher6 {
|
|
|
2590
2692
|
if (force2DView) {
|
|
2591
2693
|
this.setPolarAngle(0, 0);
|
|
2592
2694
|
}
|
|
2593
|
-
const boundingBox = new
|
|
2695
|
+
const boundingBox = new Box38().setFromObject(object);
|
|
2594
2696
|
this.setPolarAngle(polar, 0);
|
|
2595
2697
|
const { max, min } = boundingBox;
|
|
2596
2698
|
const max2d = vector3ToDevice(max, this.camera, width, height);
|
|
@@ -2603,7 +2705,7 @@ var Context = class extends EventDispatcher6 {
|
|
|
2603
2705
|
const xScale = (width - right - left) / size.x;
|
|
2604
2706
|
const yScale = (height - top - bottom) / size.y;
|
|
2605
2707
|
const scale = Math.min(xScale, yScale);
|
|
2606
|
-
const center2 = new
|
|
2708
|
+
const center2 = new Vector312((max.x + min.x) / 2, (max.y + min.y) / 2, max.z);
|
|
2607
2709
|
return this.setZoom(scale * this.camera.zoom, center2, duration);
|
|
2608
2710
|
}
|
|
2609
2711
|
fitCameraToGround(padding = [20, 20, 20, 20], duration = 500, force2DView = true) {
|
|
@@ -2649,6 +2751,7 @@ var Context = class extends EventDispatcher6 {
|
|
|
2649
2751
|
this.tweenGroup.update();
|
|
2650
2752
|
}
|
|
2651
2753
|
dispose() {
|
|
2754
|
+
this.cameraBound.dispose();
|
|
2652
2755
|
this.selection.dispose();
|
|
2653
2756
|
this.hoverHelper.dispose();
|
|
2654
2757
|
this.tweenGroup.getAll().forEach((item) => item.stop());
|
|
@@ -2723,6 +2826,9 @@ var defaultConfig = {
|
|
|
2723
2826
|
},
|
|
2724
2827
|
graphic: {
|
|
2725
2828
|
fillOpacity: 1
|
|
2829
|
+
},
|
|
2830
|
+
cameraBound: {
|
|
2831
|
+
padding: [150, 150, 150, 150]
|
|
2726
2832
|
}
|
|
2727
2833
|
};
|
|
2728
2834
|
function getConfig(config) {
|
|
@@ -2787,6 +2893,7 @@ var BMap = class extends EventDispatcher7 {
|
|
|
2787
2893
|
}
|
|
2788
2894
|
});
|
|
2789
2895
|
__publicField(this, "resize", () => {
|
|
2896
|
+
this.context.cameraBound.setEnable(false);
|
|
2790
2897
|
this.context.onWindowResize();
|
|
2791
2898
|
const azimuthal = this.context.control.getAzimuthalAngle();
|
|
2792
2899
|
const zoom = this.context.camera.zoom;
|
|
@@ -2801,6 +2908,7 @@ var BMap = class extends EventDispatcher7 {
|
|
|
2801
2908
|
this.context.camera.zoom = zoom;
|
|
2802
2909
|
this.context.control.addEventListener("change", this.onControlChange);
|
|
2803
2910
|
this.context.setAzimuthalAngle(azimuthal, 0);
|
|
2911
|
+
this.context.cameraBound.setEnable(true);
|
|
2804
2912
|
});
|
|
2805
2913
|
this.config = getConfig(config);
|
|
2806
2914
|
this.context = new Context(container, this.config);
|
|
@@ -2940,6 +3048,7 @@ var BMap = class extends EventDispatcher7 {
|
|
|
2940
3048
|
this.currentBuildGround = this.buildingGroundMap.get(buildingKey) || null;
|
|
2941
3049
|
const createdFloor = this.createFloor(curFloorData);
|
|
2942
3050
|
if (createdFloor) {
|
|
3051
|
+
this.context.cameraBound.setEnable(false);
|
|
2943
3052
|
this.context.switchFloor(createdFloor.curFloor);
|
|
2944
3053
|
this.context.control.minZoom = 0;
|
|
2945
3054
|
this.context.control.maxZoom = Infinity;
|
|
@@ -2954,6 +3063,7 @@ var BMap = class extends EventDispatcher7 {
|
|
|
2954
3063
|
this.context.fitCameraToGround([80, 20, 80, 20], 0, false);
|
|
2955
3064
|
}
|
|
2956
3065
|
this.onControlChange();
|
|
3066
|
+
this.context.cameraBound.setEnable(true);
|
|
2957
3067
|
} else {
|
|
2958
3068
|
console.warn("[switchFloor error] [" + floor + "] \u697C\u5C42\u6CA1\u6709\u6570\u636E");
|
|
2959
3069
|
}
|
|
@@ -2962,24 +3072,19 @@ var BMap = class extends EventDispatcher7 {
|
|
|
2962
3072
|
}
|
|
2963
3073
|
}
|
|
2964
3074
|
// 扶梯
|
|
2965
|
-
|
|
3075
|
+
addModel(graphic, options) {
|
|
2966
3076
|
var _a;
|
|
2967
3077
|
if (graphic.options.geometry.type === "polygon") {
|
|
2968
|
-
const
|
|
2969
|
-
|
|
3078
|
+
const model = (_a = this.context.currentFloor) == null ? void 0 : _a.addModel(__spreadProps(__spreadValues({}, options), {
|
|
3079
|
+
position: graphic.getPosition().setZ(0.1)
|
|
3080
|
+
}));
|
|
2970
3081
|
if (model) {
|
|
2971
|
-
|
|
2972
|
-
const angleY = dir.angleTo(new
|
|
3082
|
+
const dir = getLongestSideDir(graphic.options.geometry.cds[0]);
|
|
3083
|
+
const angleY = dir.angleTo(new Vector313(0, 1, 0));
|
|
2973
3084
|
model.rotateZ(angleY);
|
|
2974
3085
|
}
|
|
2975
3086
|
}
|
|
2976
3087
|
}
|
|
2977
|
-
// 电梯
|
|
2978
|
-
addLiftModel(graphic) {
|
|
2979
|
-
}
|
|
2980
|
-
// 楼梯
|
|
2981
|
-
addStairwayModel(graphic) {
|
|
2982
|
-
}
|
|
2983
3088
|
addHeatmap(data) {
|
|
2984
3089
|
var _a;
|
|
2985
3090
|
return (_a = this.context.currentFloor) == null ? void 0 : _a.addHeatmap(data);
|