@aibee/crc-bmap 0.0.47 → 0.0.48

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.esm.js CHANGED
@@ -128,7 +128,14 @@ function initScene() {
128
128
  return scene;
129
129
  }
130
130
  function initRenderer() {
131
- const renderer = new WebGLRenderer({ antialias: true });
131
+ const renderer = new WebGLRenderer({
132
+ antialias: true
133
+ // logarithmicDepthBuffer: true,
134
+ // alpha: false,
135
+ // premultipliedAlpha: false
136
+ });
137
+ renderer.autoClear = true;
138
+ renderer.setClearAlpha(1);
132
139
  renderer.setClearColor(16777215);
133
140
  renderer.setPixelRatio(window.devicePixelRatio);
134
141
  renderer.shadowMap.enabled = true;
@@ -370,6 +377,16 @@ function sleepOnePromise() {
370
377
  function strToNumber(str) {
371
378
  return parseInt(str.replace("#", "0x"), 16);
372
379
  }
380
+ function addAlphaToHexColor(hexColor, alpha) {
381
+ let r = parseInt(hexColor.substring(1, 3), 16);
382
+ let g = parseInt(hexColor.substring(3, 5), 16);
383
+ let b = parseInt(hexColor.substring(5, 7), 16);
384
+ let newR = Math.round(r * alpha);
385
+ let newG = Math.round(g * alpha);
386
+ let newB = Math.round(b * alpha);
387
+ let newHexColor = `#${(1 << 24 | newR << 16 | newG << 8 | newB).toString(16).slice(1)}`;
388
+ return newHexColor;
389
+ }
373
390
 
374
391
  // src/context.ts
375
392
  import {
@@ -391,16 +408,12 @@ import { EventDispatcher as EventDispatcher3 } from "three";
391
408
  import {
392
409
  Object3D,
393
410
  ExtrudeGeometry,
394
- MeshStandardMaterial,
395
411
  Mesh,
396
- Color as Color2,
397
412
  Box3,
398
- Vector3
413
+ Vector3,
414
+ BufferGeometry,
415
+ LineSegments
399
416
  } from "three";
400
- import { merge } from "lodash";
401
- import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
402
- import { LineSegmentsGeometry } from "three/examples/jsm/lines/LineSegmentsGeometry.js";
403
- import { LineSegments2 } from "three/examples/jsm/lines/LineSegments2.js";
404
417
  var defaultOptions = {
405
418
  id: "",
406
419
  // 图形id
@@ -433,7 +446,9 @@ var defaultOptions = {
433
446
  curveIndex: []
434
447
  },
435
448
  layerType: "",
436
- zIndex: 0
449
+ zIndex: 0,
450
+ stroke: true,
451
+ userData: {}
437
452
  };
438
453
  var Graphic = class extends Object3D {
439
454
  constructor(context, options) {
@@ -443,8 +458,10 @@ var Graphic = class extends Object3D {
443
458
  __publicField(this, "material");
444
459
  __publicField(this, "mesh");
445
460
  __publicField(this, "line");
461
+ __publicField(this, "lineMaterial");
462
+ __publicField(this, "lineGeometry");
446
463
  __publicField(this, "options");
447
- this.options = proxyOptions(merge({}, defaultOptions, options), this);
464
+ this.options = proxyOptions(__spreadValues(__spreadValues({}, defaultOptions), options), this);
448
465
  if (this.options.geometry.type === "point") {
449
466
  const [x, y] = this.options.geometry.cds;
450
467
  this.position.set(x, y, this.options.height + this.options.airHeight);
@@ -453,23 +470,24 @@ var Graphic = class extends Object3D {
453
470
  this.init();
454
471
  this.visible = this.options.visible;
455
472
  this.addEventListener("change-fillColor", ({ value }) => {
456
- this.material.color = new Color2(value);
473
+ this.initMaterial();
474
+ this.initMesh();
457
475
  });
458
476
  this.addEventListener("change-fillOpacity", ({ value }) => {
459
- this.material.opacity = value;
477
+ this.initMaterial();
478
+ this.initMesh();
460
479
  });
461
480
  this.addEventListener("change-height", ({ value }) => {
462
481
  this.dispose();
463
482
  this.init();
464
483
  });
465
484
  this.addEventListener("change-strokeColor", ({ value }) => {
466
- this.line.material.color = new Color2(value);
485
+ this.initLineMaterial();
486
+ this.createBorder();
467
487
  });
468
488
  this.addEventListener("change-strokeOpacity", ({ value }) => {
469
- this.line.material.opacity = value;
470
- });
471
- this.addEventListener("change-strokeWidth", ({ value }) => {
472
- this.line.material.linewidth = value;
489
+ this.initLineMaterial();
490
+ this.createBorder();
473
491
  });
474
492
  this.addEventListener("change-airHeight", ({ value }) => {
475
493
  this.position.z = value;
@@ -477,6 +495,20 @@ var Graphic = class extends Object3D {
477
495
  this.addEventListener("change-visible", ({ value }) => {
478
496
  this.visible = value;
479
497
  });
498
+ this.addEventListener("change-stroke", ({ value }) => {
499
+ var _a;
500
+ if (value) {
501
+ if (this.line) {
502
+ return;
503
+ }
504
+ this.initLineGeometry();
505
+ this.initLineMaterial();
506
+ this.createBorder();
507
+ } else if (this.line) {
508
+ this.remove(this.line);
509
+ (_a = this.lineGeometry) == null ? void 0 : _a.dispose();
510
+ }
511
+ });
480
512
  }
481
513
  getCenter() {
482
514
  if (this.options.geometry.type === "point") {
@@ -505,13 +537,14 @@ var Graphic = class extends Object3D {
505
537
  }
506
538
  init() {
507
539
  this.geometry = this.initGeometry();
508
- this.material = this.initMaterial();
509
- this.mesh = this.initMesh();
540
+ this.initMaterial();
541
+ this.initMesh();
510
542
  this.mesh.position.z = this.options.airHeight;
511
- this.mesh.castShadow = true;
512
- this.add(this.mesh);
513
- this.line = this.createBorder();
514
- this.add(this.line);
543
+ if (this.options.stroke) {
544
+ this.initLineMaterial();
545
+ this.initLineGeometry();
546
+ this.createBorder();
547
+ }
515
548
  }
516
549
  initGeometry() {
517
550
  const shape = initShape(
@@ -527,31 +560,27 @@ var Graphic = class extends Object3D {
527
560
  return geometry;
528
561
  }
529
562
  initMaterial() {
530
- const material = new MeshStandardMaterial({
563
+ const material = this.context.materialFactory.createMeshStandardMaterial({
531
564
  color: this.options.fillColor,
532
- roughness: 1,
533
- transparent: true,
534
- opacity: this.options.fillOpacity,
535
- depthWrite: true
565
+ opacity: this.options.fillOpacity
536
566
  });
567
+ this.material = material;
537
568
  return material;
538
569
  }
539
570
  initLineMaterial() {
540
- const lineMaterial = new LineMaterial({
541
- color: new Color2(this.options.strokeColor).getHex(),
542
- opacity: this.options.strokeOpacity,
543
- transparent: true,
544
- depthWrite: true,
545
- linewidth: this.options.strokeWidth,
546
- wireframe: false,
547
- dashed: false
571
+ const lineMaterial = this.context.materialFactory.createLineMaterial({
572
+ color: this.options.strokeColor,
573
+ opacity: this.options.strokeOpacity
548
574
  });
549
- const { clientSize: { width, height } } = this.context;
550
- lineMaterial.resolution.set(width, height);
575
+ this.lineMaterial = lineMaterial;
551
576
  return lineMaterial;
552
577
  }
553
578
  initMesh() {
554
- return new Mesh(this.geometry, this.material);
579
+ if (this.mesh) {
580
+ this.remove(this.mesh);
581
+ }
582
+ this.mesh = new Mesh(this.geometry, this.material);
583
+ this.add(this.mesh);
555
584
  }
556
585
  getBorderPoints() {
557
586
  const points = [];
@@ -562,35 +591,28 @@ var Graphic = class extends Object3D {
562
591
  for (let i = 0; i < curCds.length; i++) {
563
592
  const cur = curCds[i];
564
593
  const next = i + 1 === curCds.length ? curCds[0] : curCds[i + 1];
565
- points.push(cur[0], cur[1], 0);
566
- points.push(next[0], next[1], 0);
567
- points.push(cur[0], cur[1], height);
568
- points.push(next[0], next[1], height);
569
- if (j > 0) {
570
- points.push(cur[0], cur[1], 0);
571
- points.push(cur[0], cur[1], height);
572
- } else {
573
- if (curveIndex.length) {
574
- if (curveIndex.includes(i)) {
575
- points.push(cur[0], cur[1], 0);
576
- points.push(cur[0], cur[1], height);
577
- }
578
- } else {
579
- points.push(cur[0], cur[1], 0);
580
- points.push(cur[0], cur[1], height);
581
- }
582
- }
594
+ points.push(new Vector3(cur[0], cur[1], height));
595
+ points.push(new Vector3(next[0], next[1], height));
583
596
  }
584
597
  }
585
598
  return points;
586
599
  }
587
- createBorder() {
588
- const material = this.initLineMaterial();
600
+ initLineGeometry() {
601
+ if (this.lineGeometry) {
602
+ this.lineGeometry.dispose();
603
+ }
589
604
  const points = this.getBorderPoints();
590
- const lineGeometry = new LineSegmentsGeometry();
591
- lineGeometry.setPositions(points);
592
- const line = new LineSegments2(lineGeometry, material);
593
- line.position.z = this.options.airHeight;
605
+ const lineGeometry = new BufferGeometry().setFromPoints(points);
606
+ this.lineGeometry = lineGeometry;
607
+ }
608
+ createBorder() {
609
+ if (this.line) {
610
+ this.remove(this.line);
611
+ }
612
+ const line = new LineSegments(this.lineGeometry, this.lineMaterial);
613
+ line.position.z = this.options.airHeight + 0.01;
614
+ this.line = line;
615
+ this.add(line);
594
616
  return line;
595
617
  }
596
618
  raycast(raycaster) {
@@ -608,7 +630,9 @@ var Graphic = class extends Object3D {
608
630
  return false;
609
631
  }
610
632
  dispose() {
611
- dispose(this);
633
+ var _a;
634
+ this.geometry.dispose();
635
+ (_a = this.line) == null ? void 0 : _a.geometry.dispose();
612
636
  this.clear();
613
637
  }
614
638
  };
@@ -619,7 +643,7 @@ import {
619
643
  PlaneGeometry,
620
644
  Mesh as Mesh2,
621
645
  ShadowMaterial,
622
- Color as Color3,
646
+ Color as Color2,
623
647
  DoubleSide
624
648
  } from "three";
625
649
  var Shadow = class extends Object3D2 {
@@ -649,7 +673,7 @@ var Shadow = class extends Object3D2 {
649
673
  this.directionalLight.shadow.camera.far = Math.max(x, y);
650
674
  }
651
675
  changeLightColor(color) {
652
- this.directionalLight.color = new Color3(color);
676
+ this.directionalLight.color = new Color2(color);
653
677
  }
654
678
  setPosition(position) {
655
679
  this.position.copy(position);
@@ -686,7 +710,6 @@ var Shadow = class extends Object3D2 {
686
710
 
687
711
  // src/elements/poi.ts
688
712
  import { Object3D as Object3D4 } from "three";
689
- import { merge as merge2 } from "lodash";
690
713
 
691
714
  // src/elements/overlay.ts
692
715
  import { Box3 as Box32, EventDispatcher, Vector3 as Vector33 } from "three";
@@ -789,7 +812,7 @@ var Poi = class extends Object3D4 {
789
812
  __publicField(this, "_changePosition", () => {
790
813
  this.overlay.div.style.transform = `translate3d(-50%, ${this.options.icon ? "-100%" : "-50%"}, 0)`;
791
814
  });
792
- this.options = proxyOptions(merge2({}, defaultOptions2, options), this);
815
+ this.options = proxyOptions(__spreadValues(__spreadValues({}, defaultOptions2), options), this);
793
816
  this.position.set(((_a = options.position) == null ? void 0 : _a.x) || 0, ((_b = options.position) == null ? void 0 : _b.y) || 0, ((_c = options.position) == null ? void 0 : _c.z) || 0);
794
817
  this.overlay = new Overlay(this.context);
795
818
  this.overlay.bindElement(this);
@@ -851,7 +874,7 @@ var Poi = class extends Object3D4 {
851
874
  if (this.options.icon) {
852
875
  div.appendChild(this.initIcon());
853
876
  }
854
- div.style.fontSize = `14px`;
877
+ div.style.fontSize = `12px`;
855
878
  div.style.textShadow = `#fff 1px 0 0, #fff 0 1px 0, #fff -1px 0 0, #fff 0 -1px 0`;
856
879
  div.style.display = `flex`;
857
880
  div.style.flexDirection = `column`;
@@ -1269,6 +1292,7 @@ var Floor = class extends Object3D7 {
1269
1292
  grounds.forEach((ground) => {
1270
1293
  if (!this.grounds.has(ground)) {
1271
1294
  ground.options.height += ground.options.zIndex / 1e4;
1295
+ ground.mesh.castShadow = true;
1272
1296
  this.grounds.add(ground);
1273
1297
  this.groundUpper.add(ground);
1274
1298
  }
@@ -2024,6 +2048,53 @@ var HoverHelper = class extends EventDispatcher4 {
2024
2048
  }
2025
2049
  };
2026
2050
 
2051
+ // src/factory/material.ts
2052
+ import { LineBasicMaterial as LineBasicMaterial2, MeshStandardMaterial as MeshStandardMaterial3 } from "three";
2053
+ var MaterialFactory = class {
2054
+ constructor(context) {
2055
+ this.context = context;
2056
+ __publicField(this, "lineMaterialMap", /* @__PURE__ */ new Map());
2057
+ __publicField(this, "meshStandardMaterialMap", /* @__PURE__ */ new Map());
2058
+ }
2059
+ generateLineMaterialKey({ color, opacity }) {
2060
+ return `${color}-${opacity}`;
2061
+ }
2062
+ createLineMaterial({ color, opacity }) {
2063
+ const key = this.generateLineMaterialKey({ color, opacity });
2064
+ if (this.lineMaterialMap.has(key)) {
2065
+ return this.lineMaterialMap.get(key);
2066
+ }
2067
+ const lineMaterial = new LineBasicMaterial2({
2068
+ color,
2069
+ transparent: true,
2070
+ opacity
2071
+ });
2072
+ this.lineMaterialMap.set(key, lineMaterial);
2073
+ return lineMaterial;
2074
+ }
2075
+ createMeshStandardMaterial({ color, opacity }) {
2076
+ const key = `${color}-${opacity}`;
2077
+ if (this.meshStandardMaterialMap.has(key)) {
2078
+ return this.meshStandardMaterialMap.get(key);
2079
+ }
2080
+ const material = new MeshStandardMaterial3({
2081
+ color,
2082
+ roughness: 1,
2083
+ transparent: true,
2084
+ opacity,
2085
+ depthWrite: true
2086
+ });
2087
+ this.meshStandardMaterialMap.set(key, material);
2088
+ return material;
2089
+ }
2090
+ dispose() {
2091
+ this.lineMaterialMap.forEach((val, _) => {
2092
+ val.dispose();
2093
+ });
2094
+ this.lineMaterialMap.clear();
2095
+ }
2096
+ };
2097
+
2027
2098
  // src/context.ts
2028
2099
  var Context = class extends EventDispatcher5 {
2029
2100
  constructor(container, config) {
@@ -2043,6 +2114,7 @@ var Context = class extends EventDispatcher5 {
2043
2114
  __publicField(this, "hoverHelper");
2044
2115
  __publicField(this, "basicRatio");
2045
2116
  // zoom=1的时候,100M对应的像素个数
2117
+ __publicField(this, "materialFactory");
2046
2118
  __publicField(this, "clientSize", {
2047
2119
  width: 0,
2048
2120
  height: 0
@@ -2096,6 +2168,7 @@ var Context = class extends EventDispatcher5 {
2096
2168
  this.init();
2097
2169
  this.selection = new Selection(this);
2098
2170
  this.hoverHelper = new HoverHelper(this);
2171
+ this.materialFactory = new MaterialFactory(this);
2099
2172
  this.resizeClientSize();
2100
2173
  this.registryEvent();
2101
2174
  }
@@ -2241,6 +2314,7 @@ var Context = class extends EventDispatcher5 {
2241
2314
  this.control.update();
2242
2315
  this.control.maxAzimuthAngle = Infinity;
2243
2316
  this.control.minAzimuthAngle = Infinity;
2317
+ return;
2244
2318
  }
2245
2319
  return timeoutPromise(
2246
2320
  new Promise((resolve) => {
@@ -2389,12 +2463,13 @@ var Context = class extends EventDispatcher5 {
2389
2463
  this.lights.children.forEach(
2390
2464
  (light) => light.dispose()
2391
2465
  );
2466
+ this.materialFactory.dispose();
2392
2467
  dispose(this.scene);
2393
2468
  }
2394
2469
  };
2395
2470
 
2396
2471
  // src/config.ts
2397
- import { merge as merge3 } from "lodash";
2472
+ import { merge } from "lodash";
2398
2473
  var defaultConfig = {
2399
2474
  apiDomain: "",
2400
2475
  apiInfo: {},
@@ -2412,7 +2487,8 @@ var defaultConfig = {
2412
2487
  },
2413
2488
  useFloorCache: true,
2414
2489
  control: {
2415
- maxPolar: 0.9
2490
+ maxPolar: 1.2,
2491
+ defaultPolar: 0.9
2416
2492
  },
2417
2493
  svg: {
2418
2494
  circle: {
@@ -2429,10 +2505,26 @@ var defaultConfig = {
2429
2505
  },
2430
2506
  hover: {
2431
2507
  time: 500
2508
+ },
2509
+ ground: {
2510
+ color: "#ffffff",
2511
+ opacity: 1,
2512
+ height: 5,
2513
+ stroke: true,
2514
+ strokeColor: "#E6E6E6",
2515
+ strokeOpacity: 1
2516
+ },
2517
+ markGraphic: {
2518
+ color: "#ecf0f7",
2519
+ opacity: 1,
2520
+ height: 1e-3,
2521
+ stroke: false,
2522
+ strokeColor: "#000",
2523
+ strokeOpacity: 1
2432
2524
  }
2433
2525
  };
2434
2526
  function getConfig(config) {
2435
- return merge3({}, defaultConfig, config);
2527
+ return merge({}, defaultConfig, config);
2436
2528
  }
2437
2529
 
2438
2530
  // src/bmap.ts
@@ -2562,6 +2654,26 @@ var BMap = class extends EventDispatcher6 {
2562
2654
  item.info.transformToBuildingGround = true;
2563
2655
  });
2564
2656
  }
2657
+ const { ground, markGraphic } = this.config;
2658
+ for (const item of data) {
2659
+ if (item.info.group === "ground") {
2660
+ item.info.fillColor = ground.color;
2661
+ item.info.fillOpacity = ground.opacity;
2662
+ item.info.height = ground.height;
2663
+ item.info.stroke = ground.stroke;
2664
+ item.info.strokeColor = ground.strokeColor;
2665
+ item.info.strokeOpacity = ground.strokeOpacity;
2666
+ } else {
2667
+ if (item.info.userData.mark) {
2668
+ item.info.height = markGraphic.height;
2669
+ item.info.fillColor = markGraphic.color;
2670
+ item.info.fillOpacity = markGraphic.opacity;
2671
+ item.info.stroke = markGraphic.stroke;
2672
+ item.info.strokeColor = markGraphic.strokeColor;
2673
+ item.info.strokeOpacity = markGraphic.strokeOpacity;
2674
+ }
2675
+ }
2676
+ }
2565
2677
  if (!this.config.useFloorCache) {
2566
2678
  this.floorDataMap.clear();
2567
2679
  }
@@ -2574,23 +2686,18 @@ var BMap = class extends EventDispatcher6 {
2574
2686
  if (!data.length) {
2575
2687
  return { curFloor, graphics: [] };
2576
2688
  }
2577
- const grounds = data.filter((item) => item.info.group === "ground");
2578
- grounds.forEach((item) => {
2579
- item.info.fillColor = "#F2F6FC";
2580
- item.info.fillOpacity = 1;
2581
- item.info.strokeOpacity = 0;
2582
- item.info.height = 5;
2583
- });
2584
- const groundGraphics = grounds.map((ground) => new Graphic(this.context, ground.info));
2585
- curFloor.addGrounds(groundGraphics);
2586
- const graphicData = data.filter((item) => item.info.group !== "ground");
2587
2689
  const legacyToGraphicMap = /* @__PURE__ */ new Map();
2588
- const graphics = graphicData.map((item) => {
2589
- const graphic = curFloor.addGraphic(item.info);
2590
- graphic.userData.data = item;
2591
- legacyToGraphicMap.set(item.legacy_id, graphic);
2592
- return graphic;
2593
- });
2690
+ const graphics = [];
2691
+ for (const item of data) {
2692
+ if (item.info.group === "ground") {
2693
+ curFloor.addGrounds([new Graphic(this.context, item.info)]);
2694
+ } else {
2695
+ const graphic = curFloor.addGraphic(item.info);
2696
+ graphic.userData.data = item;
2697
+ legacyToGraphicMap.set(item.legacy_id, graphic);
2698
+ graphics.push(graphic);
2699
+ }
2700
+ }
2594
2701
  curFloor.addShadow();
2595
2702
  curFloor.userData.legacyToGraphicMap = legacyToGraphicMap;
2596
2703
  return { curFloor, graphics };
@@ -2894,6 +3001,7 @@ export {
2894
3001
  SvgLine,
2895
3002
  SvgPolygon,
2896
3003
  Timer,
3004
+ addAlphaToHexColor,
2897
3005
  clearCanvas,
2898
3006
  clearTextTexture,
2899
3007
  createCanvas,