venue-js 1.3.0 → 1.4.0-next.1

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/dist/index.mjs CHANGED
@@ -322,6 +322,7 @@ import {
322
322
  } from "@tanstack/query-core";
323
323
 
324
324
  // src/data/populator/index.ts
325
+ import { compact as compact2 } from "lodash-es";
325
326
  import { booleanWithin } from "@turf/boolean-within";
326
327
  var createPopulator = ({
327
328
  internalFindById,
@@ -405,7 +406,14 @@ var createPopulator = ({
405
406
  const anchor = await internalFindById(kiosk.properties.anchor_id);
406
407
  const units = await internalFilterByType("unit");
407
408
  const unit = units.find(
408
- (unit2) => unit2.properties.category === "walkway" && unit2.properties.level_id === kiosk.properties.level_id && booleanWithin(kiosk, unit2)
409
+ (unit2) => {
410
+ try {
411
+ return unit2.properties.category === "walkway" && unit2.properties.level_id === kiosk.properties.level_id && booleanWithin(kiosk, unit2);
412
+ } catch (e) {
413
+ console.log(`Cannot find kiosk(${kiosk.id})'s units:`, e.message);
414
+ return false;
415
+ }
416
+ }
409
417
  );
410
418
  let section = null;
411
419
  if (anchor) {
@@ -468,7 +476,7 @@ var createPopulator = ({
468
476
  ...occupant.properties,
469
477
  anchor: anchor ? await populateAnchor(anchor) : null,
470
478
  local_categories: await Promise.all(
471
- localCategories.map(populateTaxonomy)
479
+ compact2(localCategories).map(populateTaxonomy)
472
480
  ),
473
481
  venue,
474
482
  promotions,
@@ -2673,9 +2681,9 @@ var CameraManager = class {
2673
2681
  };
2674
2682
 
2675
2683
  // src/IndoorMap/renderer/RendererManager.ts
2676
- import { min, compact as compact2, isFunction } from "lodash-es";
2684
+ import { min, compact as compact3, isFunction } from "lodash-es";
2677
2685
  import { center as turfCenter2 } from "@turf/center";
2678
- import * as THREE3 from "three";
2686
+ import * as THREE4 from "three";
2679
2687
 
2680
2688
  // src/IndoorMap/renderer/3d/Element3DRenderer.ts
2681
2689
  import * as maptalks4 from "maptalks-gl";
@@ -3024,7 +3032,7 @@ var DEFAULT_POLYGON_OPTION = {
3024
3032
  offset: 0,
3025
3033
  altitude: 0
3026
3034
  };
3027
- var get3DRendererOption = (featureType, category, options) => {
3035
+ var get3DRendererOption = (featureType, category, options = {}) => {
3028
3036
  try {
3029
3037
  const option = options[featureType] ?? element3DRendererOptions[featureType];
3030
3038
  return (category && option.byCategory?.[category]) ?? option?.default ?? DEFAULT_POLYGON_OPTION;
@@ -3485,6 +3493,12 @@ var Marker2DRenderer = class extends EventTarget {
3485
3493
  marker.addTo(this.map);
3486
3494
  return marker;
3487
3495
  };
3496
+ createTextMarker = (position, label, options) => {
3497
+ return null;
3498
+ };
3499
+ createImageMarker = (position, src, options) => {
3500
+ return null;
3501
+ };
3488
3502
  removeMarker = (marker) => {
3489
3503
  marker.remove();
3490
3504
  };
@@ -3496,6 +3510,7 @@ var Marker2DRenderer = class extends EventTarget {
3496
3510
 
3497
3511
  // src/IndoorMap/renderer/3d/Marker3DRenderer.ts
3498
3512
  import * as maptalks7 from "maptalks-gl";
3513
+ import * as THREE3 from "three";
3499
3514
 
3500
3515
  // src/IndoorMap/renderer/3d/objects/TextSpriteMarker.ts
3501
3516
  import { Coordinate as Coordinate2, Util as Util4 } from "maptalks";
@@ -3695,21 +3710,35 @@ var TextSpriteMarker = class extends BaseObject6 {
3695
3710
  };
3696
3711
 
3697
3712
  // src/IndoorMap/renderer/3d/Marker3DRenderer.ts
3698
- var HEIGHT_METER2 = 4;
3699
- var MULTIORDINAL_HEIGHT_METER3 = 9;
3700
3713
  var Marker3DRenderer = class extends EventTarget {
3701
3714
  isReady = false;
3702
3715
  threeLayer;
3703
3716
  map;
3704
- materialByKey;
3705
3717
  constructor(map, options, layer) {
3706
3718
  super();
3707
3719
  this.map = map;
3708
3720
  this.threeLayer = layer;
3709
3721
  }
3710
- createTextMarker = (position, ordinal, label, options) => {
3722
+ createPointMaterialFromSvg(svgPath, size = 40) {
3723
+ return new THREE3.PointsMaterial({
3724
+ size,
3725
+ sizeAttenuation: false,
3726
+ // Always same size in screen pixels (Screen pixel)
3727
+ // color: fillStyle,
3728
+ alphaTest: 0.5,
3729
+ // vertexColors: THREE.VertexColors,
3730
+ // color: 0xffffff,
3731
+ transparent: true,
3732
+ blending: THREE3.NormalBlending,
3733
+ depthTest: true,
3734
+ // POI is hidden behind building
3735
+ depthWrite: true,
3736
+ map: new THREE3.TextureLoader().load(svgPath)
3737
+ });
3738
+ }
3739
+ createTextMarker = (position, label, options) => {
3711
3740
  const combinedOptions = {
3712
- altitude: ordinal * HEIGHT_METER2,
3741
+ altitude: 0,
3713
3742
  text: label,
3714
3743
  ...options ?? {}
3715
3744
  };
@@ -3718,17 +3747,37 @@ var Marker3DRenderer = class extends EventTarget {
3718
3747
  this.threeLayer.addMesh([marker]);
3719
3748
  return marker;
3720
3749
  };
3721
- createImageMarker = () => {
3722
- };
3723
- createMarker = (coordinates, ordinal, label, options) => {
3724
- return this.createTextMarker(coordinates, ordinal, label, options);
3750
+ createImageMarker = (position, src, options) => {
3751
+ const [lng, lat] = position;
3752
+ let meshes = [];
3753
+ const height = options.height ?? 0;
3754
+ const { leg, ...markerOptions } = options;
3755
+ const { color: legColor = "#000000", ...legOptions } = leg ?? {};
3756
+ const material = this.createPointMaterialFromSvg(src, 40);
3757
+ const marker = this.threeLayer.toPoint(new maptalks7.Coordinate(lng, lat), { height, ...markerOptions }, material);
3758
+ marker.getObject3d().renderOrder = 10;
3759
+ meshes.push(marker);
3760
+ if (options.leg) {
3761
+ const legMaterial = new THREE3.MeshLambertMaterial({ color: legColor, transparent: true });
3762
+ const leg2 = this.threeLayer.toBar(new maptalks7.Coordinate(lng, lat), { ...legOptions, height }, legMaterial);
3763
+ const legObj = leg2.getObject3d();
3764
+ legObj.traverse((o) => {
3765
+ if (o.isMesh && o.material) {
3766
+ o.material.depthWrite = false;
3767
+ o.material.depthTest = true;
3768
+ o.renderOrder = 0;
3769
+ }
3770
+ });
3771
+ meshes = [leg2, ...meshes];
3772
+ }
3773
+ this.threeLayer.addMesh(meshes);
3774
+ return meshes;
3725
3775
  };
3726
3776
  removeMarker = (marker) => {
3727
3777
  marker.remove();
3728
3778
  };
3729
3779
  showMarkers(elements, ordinalDiff = 0) {
3730
3780
  elements.forEach((element) => {
3731
- element.setAltitude(ordinalDiff * MULTIORDINAL_HEIGHT_METER3);
3732
3781
  element.show();
3733
3782
  });
3734
3783
  }
@@ -4267,7 +4316,11 @@ function inBBox(pt, bbox2) {
4267
4316
 
4268
4317
  // src/IndoorMap/renderer/utils/findUnitOnPoint.ts
4269
4318
  var findUnitOnPoint = (units, point2) => {
4270
- return units.find((unit) => booleanPointInPolygon(point2, polygon(unit.geometry.coordinates)));
4319
+ try {
4320
+ return units.find((unit) => booleanPointInPolygon(point2, polygon(unit.geometry.coordinates)));
4321
+ } catch (err) {
4322
+ return null;
4323
+ }
4271
4324
  };
4272
4325
 
4273
4326
  // src/IndoorMap/renderer/RendererManager.ts
@@ -4337,13 +4390,13 @@ var RendererManager = class extends EventTarget {
4337
4390
  }
4338
4391
  return bad;
4339
4392
  }
4340
- const ambientLight = new THREE3.AmbientLight(16777215, 0.3);
4393
+ const ambientLight = new THREE4.AmbientLight(16777215, 0.3);
4341
4394
  scene.add(ambientLight);
4342
4395
  const dirColor = 16777215;
4343
- const dllight = new THREE3.DirectionalLight(dirColor, 0.8);
4396
+ const dllight = new THREE4.DirectionalLight(dirColor, 0.8);
4344
4397
  dllight.position.set(0, -10, 20).normalize();
4345
4398
  scene.add(dllight);
4346
- const hemi = new THREE3.HemisphereLight(16777215, 4473924, 0.4);
4399
+ const hemi = new THREE4.HemisphereLight(16777215, 4473924, 0.4);
4347
4400
  scene.add(hemi);
4348
4401
  _this.elementRenderer = new Element3DRenderer(map, options.elements);
4349
4402
  _this.markerRenderer = new Marker3DRenderer(map, {}, threeLayer);
@@ -4421,12 +4474,12 @@ var RendererManager = class extends EventTarget {
4421
4474
  });
4422
4475
  units.filter((u4) => u4.properties.category === "room").forEach((unit) => {
4423
4476
  const openingRelationships = relationships.filter((r) => r.properties.origin?.id === unit.id || r.properties.destination?.id === unit.id);
4424
- const roomOpenings = compact2(openingRelationships.map((rel) => {
4477
+ const roomOpenings = compact3(openingRelationships.map((rel) => {
4425
4478
  const openingId = rel?.properties.intermediary[0].id;
4426
4479
  return openings.find((o) => o.id === openingId);
4427
4480
  }));
4428
4481
  const innerElements = this.elementRenderer.createGeometry(unit);
4429
- const wallElements = this.elementRenderer.createRoomWall(unit, roomOpenings);
4482
+ const wallElements = [];
4430
4483
  if (innerElements || wallElements) {
4431
4484
  const _innerElements = Array.isArray(innerElements) ? innerElements : [innerElements];
4432
4485
  const _wallElements = Array.isArray(wallElements) ? wallElements : [wallElements];
@@ -4481,10 +4534,12 @@ var RendererManager = class extends EventTarget {
4481
4534
  for (const label of groundLabels) {
4482
4535
  const center2 = turfCenter2(polygon(label.geometry.coordinates)).geometry.coordinates;
4483
4536
  const unit = findUnitOnPoint(units, center2);
4484
- const element = this.elementRenderer.createGroundLabel(label, unit);
4485
- if (element) {
4486
- const _elements = Array.isArray(element) ? element : [element];
4487
- this.addElementsToManager(label.id, _elements, label.properties.ordinal);
4537
+ if (unit) {
4538
+ const element = this.elementRenderer.createGroundLabel(label, unit);
4539
+ if (element) {
4540
+ const _elements = Array.isArray(element) ? element : [element];
4541
+ this.addElementsToManager(label.id, _elements, label.properties.ordinal);
4542
+ }
4488
4543
  }
4489
4544
  }
4490
4545
  if (this.options.type === "3D") {
@@ -4566,10 +4621,11 @@ var RendererManager = class extends EventTarget {
4566
4621
  this.markerRenderer.hideMarkers(markers, ordinal);
4567
4622
  }
4568
4623
  };
4569
- createMarker(coordinate, ordinal, text, options) {
4570
- const marker = this.markerRenderer.createMarker(coordinate, ordinal, text, options);
4624
+ createMarker(type, coordinate, ordinal, textOrPath, options) {
4625
+ const meshes = type === "text" ? this.markerRenderer.createTextMarker(coordinate, textOrPath, options) : this.markerRenderer.createImageMarker(coordinate, textOrPath, options);
4571
4626
  const markerId = `${this.markersMap.size + 1}`;
4572
- this._addMarkersToManager(markerId, [marker], ordinal);
4627
+ const markerMeshes = Array.isArray(meshes) ? meshes : [meshes];
4628
+ this._addMarkersToManager(markerId, markerMeshes, ordinal);
4573
4629
  }
4574
4630
  clearMarkers() {
4575
4631
  for (const [markerId, marker] of this.markersMap) {
@@ -4709,6 +4765,7 @@ var IndoorMap = class extends EventTarget {
4709
4765
  this.#dataClient = value;
4710
4766
  if (!this.options.camera?.defaultView?.center) {
4711
4767
  this.#dataClient.filterByType("venue").then((venues) => {
4768
+ this.#venues = venues;
4712
4769
  const venueCenters = turfCenter3(featureCollection(venues));
4713
4770
  const [x, y] = venueCenters.geometry.coordinates;
4714
4771
  const center2 = new Coordinate4(x, y);