venue-js 1.0.0-next.1 → 1.0.0-next.3

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.js CHANGED
@@ -439,6 +439,26 @@ var createPopulator = ({
439
439
  };
440
440
  };
441
441
 
442
+ // src/data/utils/match-filters.ts
443
+ function isInFilter(filter) {
444
+ return typeof filter === "object" && filter !== null && "$in" in filter && Array.isArray(filter.$in);
445
+ }
446
+ var someIntersect = (a, b) => a.some((v) => b.includes(v));
447
+ function matchFilter(value, filter) {
448
+ if (Array.isArray(value)) {
449
+ if (isInFilter(filter)) return someIntersect(value, filter.$in);
450
+ return value.includes(filter);
451
+ } else {
452
+ if (isInFilter(filter)) return filter.$in.includes(value);
453
+ return value === filter;
454
+ }
455
+ }
456
+ function matchFilters(item, filters) {
457
+ return Object.entries(filters).every(([key, filter]) => {
458
+ return matchFilter(item.properties[key], filter);
459
+ });
460
+ }
461
+
442
462
  // src/data/getDataClient.ts
443
463
  var getDataClient = (options) => {
444
464
  const observers = /* @__PURE__ */ new Map();
@@ -514,7 +534,12 @@ var getDataClient = (options) => {
514
534
  queryKey: [featureType, "list", params],
515
535
  queryFn: async () => {
516
536
  const features = await internalFilterByType(featureType);
517
- return params.populate === true ? await Promise.all(features.map((f) => populator[featureType](f))) : features;
537
+ const filters = params.filters ?? {};
538
+ let result = features;
539
+ if (params.filters) {
540
+ result = features.filter((f) => matchFilters(f, filters));
541
+ }
542
+ return params.populate === true ? await Promise.all(result.map((f) => populator[featureType](f))) : result;
518
543
  },
519
544
  ...options2 ?? {}
520
545
  });
@@ -765,7 +790,7 @@ var turf_bbox_default = bbox;
765
790
  // src/IndoorMap/IndoorMap.ts
766
791
  var import_transform_scale = __toESM(require("@turf/transform-scale"));
767
792
  var import_bbox_polygon = __toESM(require("@turf/bbox-polygon"));
768
- var import_three9 = require("three");
793
+ var import_three8 = require("three");
769
794
  var import_maptalks9 = require("maptalks.three");
770
795
 
771
796
  // src/IndoorMap/constants.ts
@@ -3256,12 +3281,15 @@ var CameraManager = class {
3256
3281
  };
3257
3282
  };
3258
3283
 
3284
+ // src/IndoorMap/renderer/RendererManager.ts
3285
+ var import_min = __toESM(require("lodash/min"));
3286
+ var import_partition = __toESM(require("lodash/partition"));
3287
+
3259
3288
  // src/IndoorMap/renderer/Element3DRenderer.ts
3260
3289
  var maptalks5 = __toESM(require("maptalks"));
3261
3290
  var THREE2 = __toESM(require("three"));
3262
3291
  var import_maptalks7 = require("maptalks.three");
3263
3292
  var import_buffer2 = __toESM(require("@turf/buffer"));
3264
- var import_three8 = require("three");
3265
3293
 
3266
3294
  // src/IndoorMap/object3d/Escalator.ts
3267
3295
  var maptalks4 = __toESM(require("maptalks"));
@@ -3348,6 +3376,31 @@ var Escalator = class extends import_maptalks6.BaseObject {
3348
3376
  }
3349
3377
  };
3350
3378
 
3379
+ // src/IndoorMap/renderer/default/element3DRendererOptions.ts
3380
+ var element3DRendererOptions = {
3381
+ unit: {
3382
+ default: { color: "#ffffff", height: 4 },
3383
+ byCategory: {
3384
+ walkway: { color: "#cccccc", height: 0.1 },
3385
+ terrace: { color: "#cccccc", height: 0.1 },
3386
+ unenclosedarea: { color: "#cccccc", height: 0.2 },
3387
+ nonpublic: { color: "#999999", height: 0.3 },
3388
+ escalator: { height: 0.2 },
3389
+ room: { color: "#ffffff", height: 4, bottomHeight: 0.12 }
3390
+ }
3391
+ },
3392
+ kiosk: {
3393
+ default: { color: "#666666", height: 0.6, bottomHeight: 0.12 }
3394
+ },
3395
+ fixture: {
3396
+ default: { color: "#ffffff", height: 0.5 },
3397
+ byCategory: {
3398
+ water: { color: "#ACD7EC", height: 0.5 },
3399
+ vegetation: { color: "#91C499", height: 0.5 }
3400
+ }
3401
+ }
3402
+ };
3403
+
3351
3404
  // src/IndoorMap/renderer/Element3DRenderer/utils/svg2material.ts
3352
3405
  var import_three7 = require("three");
3353
3406
  var svgToDataURL = (svgString, scaleFactor = 1) => {
@@ -3422,9 +3475,10 @@ var DEFAULT_POLYGON_OPTION = {
3422
3475
  altitude: 0
3423
3476
  };
3424
3477
  var HEIGHT_METER = 4;
3478
+ var MULTIORDINAL_HEIGHT_METER = 10;
3425
3479
  var getGeometryOption = (feature2, options) => {
3426
3480
  try {
3427
- const option = options[feature2.feature_type];
3481
+ const option = options[feature2.feature_type] ?? element3DRendererOptions[feature2.feature_type];
3428
3482
  const category = feature2.properties.category;
3429
3483
  return (category && option.byCategory?.[category]) ?? option?.default ?? DEFAULT_POLYGON_OPTION;
3430
3484
  } catch (err) {
@@ -3477,45 +3531,11 @@ var Element3DRenderer = class extends EventTarget {
3477
3531
  if (!this.materialByColorMap) this.materialByColorMap = /* @__PURE__ */ new Map();
3478
3532
  const existingMaterial = this.materialByColorMap.get(color);
3479
3533
  if (existingMaterial) return existingMaterial;
3480
- const created = new import_three8.MeshLambertMaterial({ color, transparent: true });
3534
+ const created = new THREE2.MeshLambertMaterial({ color, transparent: true });
3481
3535
  created.toneMapped = false;
3482
3536
  this.materialByColorMap.set(color, created);
3483
3537
  return created;
3484
3538
  }
3485
- getOrCreateIconMaterial(key) {
3486
- if (!this.materialByKey) this.materialByKey = /* @__PURE__ */ new Map();
3487
- const existingMaterial = this.materialByKey.get(key);
3488
- if (existingMaterial) return existingMaterial;
3489
- const baseSymbol = {
3490
- markerType: "path",
3491
- markerPath: [
3492
- {
3493
- path: "M20.775 1.2H1.225V20.35H8.215L11.3 22.8L14.385 20.35H20.775V1.2Z",
3494
- fill: "#ff0000"
3495
- }
3496
- ],
3497
- markerPathWidth: 24,
3498
- markerPathHeight: 24
3499
- };
3500
- const markerSymbol = {
3501
- markerType: "path",
3502
- markerPath: [],
3503
- // TODO: Get Path by featureType.category
3504
- // markerPath: [{ fill: "#FFFFFF", path: "M 19 3 H 5 c -1.1 0 -2 0.9 -2 2 v 14 c 0 1.1 0.9 2 2 2 h 14 c 1.1 0 2 -0.9 2 -2 V 5 c 0 -1.1 -0.9 -2 -2 -2 Z m -2 6 h -1.7 l -5 9 H 7 c -0.83 0 -1.5 -0.67 -1.5 -1.5 S 6.17 15 7 15 h 1.7 l 5 -9 H 17 c 0.83 0 1.5 0.67 1.5 1.5 S 17.83 9 17 9 Z" }],
3505
- markerPathWidth: 24,
3506
- markerPathHeight: 24,
3507
- markerWidth: 24,
3508
- markerHeight: 24,
3509
- markerDy: 1.5,
3510
- markerDx: 1.5
3511
- };
3512
- const created = createSpriteMaterialByLabelSymbol2([
3513
- baseSymbol,
3514
- markerSymbol
3515
- ]);
3516
- this.materialByKey.set(key, created);
3517
- return created;
3518
- }
3519
3539
  createGeometry = (feature2) => {
3520
3540
  const options = getGeometryOption(feature2, this.options);
3521
3541
  const offset = options?.offset ?? 0;
@@ -3538,7 +3558,7 @@ var Element3DRenderer = class extends EventTarget {
3538
3558
  ];
3539
3559
  const topLines = this.threeLayer.toLines(
3540
3560
  topLineStrings,
3541
- { altitude: altitude + options.height + 1e-3, bottomHeight, interactive: false },
3561
+ { altitude, bottomHeight: bottomHeight + options.height + 1e-3, interactive: false },
3542
3562
  this.lineMaterial
3543
3563
  );
3544
3564
  const bottomLineStrings = [
@@ -3573,6 +3593,41 @@ var Element3DRenderer = class extends EventTarget {
3573
3593
  console.log(`error createGeometry`, { feature: feature2, options });
3574
3594
  }
3575
3595
  };
3596
+ /** Marker */
3597
+ getOrCreateIconMaterial(key) {
3598
+ if (!this.materialByKey) this.materialByKey = /* @__PURE__ */ new Map();
3599
+ const existingMaterial = this.materialByKey.get(key);
3600
+ if (existingMaterial) return existingMaterial;
3601
+ const baseSymbol = {
3602
+ markerType: "path",
3603
+ markerPath: [
3604
+ {
3605
+ path: "M20.775 1.2H1.225V20.35H8.215L11.3 22.8L14.385 20.35H20.775V1.2Z",
3606
+ fill: "#ff0000"
3607
+ }
3608
+ ],
3609
+ markerPathWidth: 24,
3610
+ markerPathHeight: 24
3611
+ };
3612
+ const markerSymbol = {
3613
+ markerType: "path",
3614
+ markerPath: [],
3615
+ // TODO: Get Path by featureType.category
3616
+ // markerPath: [{ fill: "#FFFFFF", path: "M 19 3 H 5 c -1.1 0 -2 0.9 -2 2 v 14 c 0 1.1 0.9 2 2 2 h 14 c 1.1 0 2 -0.9 2 -2 V 5 c 0 -1.1 -0.9 -2 -2 -2 Z m -2 6 h -1.7 l -5 9 H 7 c -0.83 0 -1.5 -0.67 -1.5 -1.5 S 6.17 15 7 15 h 1.7 l 5 -9 H 17 c 0.83 0 1.5 0.67 1.5 1.5 S 17.83 9 17 9 Z" }],
3617
+ markerPathWidth: 24,
3618
+ markerPathHeight: 24,
3619
+ markerWidth: 24,
3620
+ markerHeight: 24,
3621
+ markerDy: 1.5,
3622
+ markerDx: 1.5
3623
+ };
3624
+ const created = createSpriteMaterialByLabelSymbol2([
3625
+ baseSymbol,
3626
+ markerSymbol
3627
+ ]);
3628
+ this.materialByKey.set(key, created);
3629
+ return created;
3630
+ }
3576
3631
  createMarker = (coordinates, ordinal, label) => {
3577
3632
  const options = {
3578
3633
  scale: 0.05,
@@ -3616,6 +3671,17 @@ var Element3DRenderer = class extends EventTarget {
3616
3671
  return null;
3617
3672
  }
3618
3673
  }
3674
+ showElements(elements, ordinalDiff = 0) {
3675
+ elements.forEach((element) => {
3676
+ element.setAltitude(ordinalDiff * MULTIORDINAL_HEIGHT_METER);
3677
+ element.show();
3678
+ });
3679
+ }
3680
+ hideElements(elements, ordinalDiff = 0) {
3681
+ elements.forEach((element) => {
3682
+ element.hide();
3683
+ });
3684
+ }
3619
3685
  render() {
3620
3686
  this.threeLayer._needsUpdate = !this.threeLayer._needsUpdate;
3621
3687
  if (this.threeLayer._needsUpdate) {
@@ -3627,7 +3693,32 @@ var Element3DRenderer = class extends EventTarget {
3627
3693
 
3628
3694
  // src/IndoorMap/renderer/Element2DRenderer.ts
3629
3695
  var maptalks6 = __toESM(require("maptalks"));
3630
- var OCCUPANT_TEXT_MARKER_CLASSNAME2 = "mtk-occupant-text-marker";
3696
+
3697
+ // src/IndoorMap/renderer/default/element2DRendererOptions.ts
3698
+ var element2DRendererOptions = {
3699
+ unit: {
3700
+ default: { symbol: { polygonFill: "#cccccc" } },
3701
+ byCategory: {
3702
+ room: { symbol: { polygonFill: "#fff" } },
3703
+ walkway: { symbol: { polygonFill: "#efefef", lineColor: "#dadada", lineWidth: 2 } },
3704
+ terrace: { symbol: { polygonFill: "#efefef" } },
3705
+ unenclosedarea: { symbol: { polygonFill: "#fff" } },
3706
+ nonpublic: { symbol: { polygonFill: "#999999" } }
3707
+ }
3708
+ },
3709
+ kiosk: {
3710
+ default: {}
3711
+ },
3712
+ fixture: {
3713
+ default: { symbol: { polygonFill: "#ffffff" } },
3714
+ byCategory: {
3715
+ water: { symbol: { polygonFill: "#ACD7EC" } },
3716
+ vegetation: { symbol: { polygonFill: "#91C499" } }
3717
+ }
3718
+ }
3719
+ };
3720
+
3721
+ // src/IndoorMap/renderer/Element2DRenderer.ts
3631
3722
  var DEFAULT_POLYGON_OPTION2 = {
3632
3723
  zIndex: 0,
3633
3724
  symbol: {
@@ -3637,6 +3728,7 @@ var DEFAULT_POLYGON_OPTION2 = {
3637
3728
  lineWidth: 2
3638
3729
  }
3639
3730
  };
3731
+ var MULTIORDINAL_HEIGHT_METER2 = 10;
3640
3732
  var getGeometryProperties = (feature2) => ({
3641
3733
  // Core
3642
3734
  type: "Feature",
@@ -3646,11 +3738,11 @@ var getGeometryProperties = (feature2) => ({
3646
3738
  // Extra
3647
3739
  feature_type: feature2.feature_type,
3648
3740
  category: feature2.properties.category,
3649
- name: feature2.properties.name.en
3741
+ name: feature2.properties.name?.en
3650
3742
  });
3651
3743
  var getGeometryOption2 = (feature2, options) => {
3652
3744
  try {
3653
- const option = options[feature2.feature_type];
3745
+ const option = options[feature2.feature_type] ?? element2DRendererOptions[feature2.feature_type];
3654
3746
  const category = feature2.properties.category;
3655
3747
  return (category && option.byCategory?.[category]) ?? option?.default ?? DEFAULT_POLYGON_OPTION2;
3656
3748
  } catch (err) {
@@ -3695,36 +3787,63 @@ var Element2DRenderer = class extends EventTarget {
3695
3787
  return geometry;
3696
3788
  }
3697
3789
  };
3698
- createMarker = (coordinates, ordinal, label) => {
3699
- const createStyledUIMarkerElement2 = ({ style: style2, textContent, className }) => {
3700
- const element = document.createElement("div");
3701
- for (const key in style2) {
3702
- element.style[key] = style2[key];
3703
- }
3704
- element.className = className;
3705
- element.textContent = textContent;
3706
- return element.outerHTML;
3707
- };
3708
- const style = {};
3709
- const marker = new maptalks6.ui.UIMarker(coordinates, {
3710
- content: createStyledUIMarkerElement2({
3711
- style,
3712
- textContent: label,
3713
- className: OCCUPANT_TEXT_MARKER_CLASSNAME2
3714
- }),
3715
- collision: true,
3716
- collisionFadeIn: true
3717
- // altitude: getAltitude(f.properties) + markerHeight,
3718
- });
3719
- marker.addTo(this.map);
3720
- return marker;
3721
- };
3722
3790
  createElement = (imdfFeature) => {
3723
3791
  switch (imdfFeature.feature_type) {
3724
3792
  default:
3725
3793
  return null;
3726
3794
  }
3727
3795
  };
3796
+ showElements(elements, ordinalDiff = 0) {
3797
+ elements.forEach((element) => {
3798
+ element.setAltitude(ordinalDiff * MULTIORDINAL_HEIGHT_METER2);
3799
+ element.show();
3800
+ });
3801
+ }
3802
+ hideElements(elements, ordinalDiff = 0) {
3803
+ elements.forEach((element) => {
3804
+ element.hide();
3805
+ });
3806
+ }
3807
+ // createMarker = (
3808
+ // coordinates: Position,
3809
+ // ordinal: number,
3810
+ // label: string
3811
+ // ): maptalks.ui.UIMarker => {
3812
+ // const createStyledUIMarkerElement = ({ style, textContent, className }) => {
3813
+ // const element = document.createElement("div")
3814
+ // for (const key in style) {
3815
+ // element.style[key] = style[key]
3816
+ // }
3817
+ // element.className = className
3818
+ // element.textContent = textContent
3819
+ // //! Use outerHTML to return HTML string instead of element object to avoid DOM event warnings from Maptalks.js.
3820
+ // return element.outerHTML
3821
+ // }
3822
+ // const style = {}
3823
+ // // const markerHeight = 0
3824
+ // const marker = new maptalks.ui.UIMarker(coordinates, {
3825
+ // content: createStyledUIMarkerElement({
3826
+ // style,
3827
+ // textContent: label,
3828
+ // className: OCCUPANT_TEXT_MARKER_CLASSNAME,
3829
+ // }),
3830
+ // collision: true,
3831
+ // collisionFadeIn: true,
3832
+ // altitude: MULTIORDINAL_HEIGHT_METER * ordinal,
3833
+ // })
3834
+ // marker.addTo(this.map)
3835
+ // return marker
3836
+ // }
3837
+ createMarker = (coordinates, ordinal, content) => {
3838
+ const marker = new maptalks6.ui.UIMarker(coordinates, {
3839
+ content,
3840
+ collision: true,
3841
+ collisionFadeIn: true,
3842
+ altitude: MULTIORDINAL_HEIGHT_METER2 * ordinal
3843
+ });
3844
+ marker.addTo(this.map);
3845
+ return marker;
3846
+ };
3728
3847
  };
3729
3848
 
3730
3849
  // src/IndoorMap/renderer/RendererManager.ts
@@ -3748,6 +3867,7 @@ var RendererManager = class extends EventTarget {
3748
3867
  set dataClient(value) {
3749
3868
  this.#dataClient = value;
3750
3869
  if (this.elementRenderer.isReady) {
3870
+ this.dispatchEvent(new CustomEvent("renderermanager:ready"));
3751
3871
  this.#createElements();
3752
3872
  } else {
3753
3873
  this.elementRenderer.addEventListener("threelayer:ready", (e) => {
@@ -3779,7 +3899,18 @@ var RendererManager = class extends EventTarget {
3779
3899
  const units = await this.#dataClient.filterByType("unit", {
3780
3900
  populate: true
3781
3901
  });
3782
- units.filter(
3902
+ const [walkways, otherUnits] = (0, import_partition.default)(units, (u) => ["walkway"].includes(u.properties.category));
3903
+ walkways.forEach((unit) => {
3904
+ const element = this.elementRenderer.createGeometry(unit);
3905
+ if (element) {
3906
+ const _elements = Array.isArray(element) ? element : [element];
3907
+ _elements.forEach((el) => {
3908
+ this.elementsMap.set(unit.id, el);
3909
+ this.getElementsByOrdinal(unit.properties.level.properties.ordinal).push(el);
3910
+ });
3911
+ }
3912
+ });
3913
+ otherUnits.filter(
3783
3914
  (u) => !["opentobelow", "escalator"].includes(u.properties.category)
3784
3915
  ).forEach((unit) => {
3785
3916
  const element = this.elementRenderer.createGeometry(unit);
@@ -3807,22 +3938,30 @@ var RendererManager = class extends EventTarget {
3807
3938
  this.dispatchEvent(new CustomEvent("renderermanager:elements_created"));
3808
3939
  }
3809
3940
  changeLevelByOrdinal(targetOrdinal) {
3810
- for (const [ordinal, elements] of this.elementsByOrdinal) {
3811
- const inOrdinal = targetOrdinal === null ? true : Array.isArray(targetOrdinal) ? targetOrdinal.includes(ordinal) : ordinal === targetOrdinal;
3812
- if (inOrdinal) {
3813
- elements.forEach((element, i) => {
3814
- element.show();
3815
- });
3816
- } else {
3817
- elements.forEach((element) => {
3818
- element.hide();
3819
- });
3941
+ if (targetOrdinal === null) {
3942
+ const baseOrdinal = 0;
3943
+ for (const [ordinal, elements] of this.elementsByOrdinal) {
3944
+ this.elementRenderer.showElements(elements, ordinal - baseOrdinal);
3945
+ }
3946
+ } else {
3947
+ const baseOrdinal = Array.isArray(targetOrdinal) ? (0, import_min.default)(targetOrdinal) : targetOrdinal;
3948
+ for (const [ordinal, elements] of this.elementsByOrdinal) {
3949
+ const inOrdinal = Array.isArray(targetOrdinal) ? targetOrdinal.includes(ordinal) : ordinal === targetOrdinal;
3950
+ if (inOrdinal) {
3951
+ this.elementRenderer.showElements(elements, ordinal - baseOrdinal);
3952
+ } else {
3953
+ this.elementRenderer.hideElements(elements, ordinal - baseOrdinal);
3954
+ }
3820
3955
  }
3821
3956
  }
3822
3957
  }
3823
- createMarker(coordinate, ordinal, label) {
3824
- const marker = this.elementRenderer.createMarker(coordinate, ordinal, label);
3825
- this.elementsMap.set(label, marker);
3958
+ /**
3959
+ * ========================================================================
3960
+ * Markers
3961
+ * ======================================================================== */
3962
+ createMarker(coordinate, ordinal, markerSymbol) {
3963
+ console.log(`createMarker`, { coordinate, ordinal, markerSymbol });
3964
+ const marker = this.elementRenderer.createMarker(coordinate, ordinal, markerSymbol);
3826
3965
  this.getElementsByOrdinal(ordinal).push(marker);
3827
3966
  }
3828
3967
  };
@@ -4050,7 +4189,7 @@ var IndoorMap = class extends EventTarget {
4050
4189
  const scene = this.threeLayer.getScene();
4051
4190
  if (scene) {
4052
4191
  scene.children = scene.children.filter(
4053
- (children) => children instanceof import_three9.PerspectiveCamera
4192
+ (children) => children instanceof import_three8.PerspectiveCamera
4054
4193
  );
4055
4194
  }
4056
4195
  }