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.mjs CHANGED
@@ -360,6 +360,26 @@ var createPopulator = ({
360
360
  };
361
361
  };
362
362
 
363
+ // src/data/utils/match-filters.ts
364
+ function isInFilter(filter) {
365
+ return typeof filter === "object" && filter !== null && "$in" in filter && Array.isArray(filter.$in);
366
+ }
367
+ var someIntersect = (a, b) => a.some((v) => b.includes(v));
368
+ function matchFilter(value, filter) {
369
+ if (Array.isArray(value)) {
370
+ if (isInFilter(filter)) return someIntersect(value, filter.$in);
371
+ return value.includes(filter);
372
+ } else {
373
+ if (isInFilter(filter)) return filter.$in.includes(value);
374
+ return value === filter;
375
+ }
376
+ }
377
+ function matchFilters(item, filters) {
378
+ return Object.entries(filters).every(([key, filter]) => {
379
+ return matchFilter(item.properties[key], filter);
380
+ });
381
+ }
382
+
363
383
  // src/data/getDataClient.ts
364
384
  var getDataClient = (options) => {
365
385
  const observers = /* @__PURE__ */ new Map();
@@ -435,7 +455,12 @@ var getDataClient = (options) => {
435
455
  queryKey: [featureType, "list", params],
436
456
  queryFn: async () => {
437
457
  const features = await internalFilterByType(featureType);
438
- return params.populate === true ? await Promise.all(features.map((f) => populator[featureType](f))) : features;
458
+ const filters = params.filters ?? {};
459
+ let result = features;
460
+ if (params.filters) {
461
+ result = features.filter((f) => matchFilters(f, filters));
462
+ }
463
+ return params.populate === true ? await Promise.all(result.map((f) => populator[featureType](f))) : result;
439
464
  },
440
465
  ...options2 ?? {}
441
466
  });
@@ -3213,12 +3238,15 @@ var CameraManager = class {
3213
3238
  };
3214
3239
  };
3215
3240
 
3241
+ // src/IndoorMap/renderer/RendererManager.ts
3242
+ import _min from "lodash/min";
3243
+ import _partition from "lodash/partition";
3244
+
3216
3245
  // src/IndoorMap/renderer/Element3DRenderer.ts
3217
3246
  import * as maptalks5 from "maptalks";
3218
3247
  import * as THREE2 from "three";
3219
3248
  import { ThreeLayer as ThreeLayer3 } from "maptalks.three";
3220
3249
  import turfBuffer2 from "@turf/buffer";
3221
- import { MeshLambertMaterial as MeshLambertMaterial3 } from "three";
3222
3250
 
3223
3251
  // src/IndoorMap/object3d/Escalator.ts
3224
3252
  import * as maptalks4 from "maptalks";
@@ -3305,6 +3333,31 @@ var Escalator = class extends BaseObject5 {
3305
3333
  }
3306
3334
  };
3307
3335
 
3336
+ // src/IndoorMap/renderer/default/element3DRendererOptions.ts
3337
+ var element3DRendererOptions = {
3338
+ unit: {
3339
+ default: { color: "#ffffff", height: 4 },
3340
+ byCategory: {
3341
+ walkway: { color: "#cccccc", height: 0.1 },
3342
+ terrace: { color: "#cccccc", height: 0.1 },
3343
+ unenclosedarea: { color: "#cccccc", height: 0.2 },
3344
+ nonpublic: { color: "#999999", height: 0.3 },
3345
+ escalator: { height: 0.2 },
3346
+ room: { color: "#ffffff", height: 4, bottomHeight: 0.12 }
3347
+ }
3348
+ },
3349
+ kiosk: {
3350
+ default: { color: "#666666", height: 0.6, bottomHeight: 0.12 }
3351
+ },
3352
+ fixture: {
3353
+ default: { color: "#ffffff", height: 0.5 },
3354
+ byCategory: {
3355
+ water: { color: "#ACD7EC", height: 0.5 },
3356
+ vegetation: { color: "#91C499", height: 0.5 }
3357
+ }
3358
+ }
3359
+ };
3360
+
3308
3361
  // src/IndoorMap/renderer/Element3DRenderer/utils/svg2material.ts
3309
3362
  import { SpriteMaterial as SpriteMaterial4, TextureLoader as TextureLoader3 } from "three";
3310
3363
  var svgToDataURL = (svgString, scaleFactor = 1) => {
@@ -3379,9 +3432,10 @@ var DEFAULT_POLYGON_OPTION = {
3379
3432
  altitude: 0
3380
3433
  };
3381
3434
  var HEIGHT_METER = 4;
3435
+ var MULTIORDINAL_HEIGHT_METER = 10;
3382
3436
  var getGeometryOption = (feature2, options) => {
3383
3437
  try {
3384
- const option = options[feature2.feature_type];
3438
+ const option = options[feature2.feature_type] ?? element3DRendererOptions[feature2.feature_type];
3385
3439
  const category = feature2.properties.category;
3386
3440
  return (category && option.byCategory?.[category]) ?? option?.default ?? DEFAULT_POLYGON_OPTION;
3387
3441
  } catch (err) {
@@ -3434,45 +3488,11 @@ var Element3DRenderer = class extends EventTarget {
3434
3488
  if (!this.materialByColorMap) this.materialByColorMap = /* @__PURE__ */ new Map();
3435
3489
  const existingMaterial = this.materialByColorMap.get(color);
3436
3490
  if (existingMaterial) return existingMaterial;
3437
- const created = new MeshLambertMaterial3({ color, transparent: true });
3491
+ const created = new THREE2.MeshLambertMaterial({ color, transparent: true });
3438
3492
  created.toneMapped = false;
3439
3493
  this.materialByColorMap.set(color, created);
3440
3494
  return created;
3441
3495
  }
3442
- getOrCreateIconMaterial(key) {
3443
- if (!this.materialByKey) this.materialByKey = /* @__PURE__ */ new Map();
3444
- const existingMaterial = this.materialByKey.get(key);
3445
- if (existingMaterial) return existingMaterial;
3446
- const baseSymbol = {
3447
- markerType: "path",
3448
- markerPath: [
3449
- {
3450
- path: "M20.775 1.2H1.225V20.35H8.215L11.3 22.8L14.385 20.35H20.775V1.2Z",
3451
- fill: "#ff0000"
3452
- }
3453
- ],
3454
- markerPathWidth: 24,
3455
- markerPathHeight: 24
3456
- };
3457
- const markerSymbol = {
3458
- markerType: "path",
3459
- markerPath: [],
3460
- // TODO: Get Path by featureType.category
3461
- // 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" }],
3462
- markerPathWidth: 24,
3463
- markerPathHeight: 24,
3464
- markerWidth: 24,
3465
- markerHeight: 24,
3466
- markerDy: 1.5,
3467
- markerDx: 1.5
3468
- };
3469
- const created = createSpriteMaterialByLabelSymbol2([
3470
- baseSymbol,
3471
- markerSymbol
3472
- ]);
3473
- this.materialByKey.set(key, created);
3474
- return created;
3475
- }
3476
3496
  createGeometry = (feature2) => {
3477
3497
  const options = getGeometryOption(feature2, this.options);
3478
3498
  const offset = options?.offset ?? 0;
@@ -3495,7 +3515,7 @@ var Element3DRenderer = class extends EventTarget {
3495
3515
  ];
3496
3516
  const topLines = this.threeLayer.toLines(
3497
3517
  topLineStrings,
3498
- { altitude: altitude + options.height + 1e-3, bottomHeight, interactive: false },
3518
+ { altitude, bottomHeight: bottomHeight + options.height + 1e-3, interactive: false },
3499
3519
  this.lineMaterial
3500
3520
  );
3501
3521
  const bottomLineStrings = [
@@ -3530,6 +3550,41 @@ var Element3DRenderer = class extends EventTarget {
3530
3550
  console.log(`error createGeometry`, { feature: feature2, options });
3531
3551
  }
3532
3552
  };
3553
+ /** Marker */
3554
+ getOrCreateIconMaterial(key) {
3555
+ if (!this.materialByKey) this.materialByKey = /* @__PURE__ */ new Map();
3556
+ const existingMaterial = this.materialByKey.get(key);
3557
+ if (existingMaterial) return existingMaterial;
3558
+ const baseSymbol = {
3559
+ markerType: "path",
3560
+ markerPath: [
3561
+ {
3562
+ path: "M20.775 1.2H1.225V20.35H8.215L11.3 22.8L14.385 20.35H20.775V1.2Z",
3563
+ fill: "#ff0000"
3564
+ }
3565
+ ],
3566
+ markerPathWidth: 24,
3567
+ markerPathHeight: 24
3568
+ };
3569
+ const markerSymbol = {
3570
+ markerType: "path",
3571
+ markerPath: [],
3572
+ // TODO: Get Path by featureType.category
3573
+ // 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" }],
3574
+ markerPathWidth: 24,
3575
+ markerPathHeight: 24,
3576
+ markerWidth: 24,
3577
+ markerHeight: 24,
3578
+ markerDy: 1.5,
3579
+ markerDx: 1.5
3580
+ };
3581
+ const created = createSpriteMaterialByLabelSymbol2([
3582
+ baseSymbol,
3583
+ markerSymbol
3584
+ ]);
3585
+ this.materialByKey.set(key, created);
3586
+ return created;
3587
+ }
3533
3588
  createMarker = (coordinates, ordinal, label) => {
3534
3589
  const options = {
3535
3590
  scale: 0.05,
@@ -3573,6 +3628,17 @@ var Element3DRenderer = class extends EventTarget {
3573
3628
  return null;
3574
3629
  }
3575
3630
  }
3631
+ showElements(elements, ordinalDiff = 0) {
3632
+ elements.forEach((element) => {
3633
+ element.setAltitude(ordinalDiff * MULTIORDINAL_HEIGHT_METER);
3634
+ element.show();
3635
+ });
3636
+ }
3637
+ hideElements(elements, ordinalDiff = 0) {
3638
+ elements.forEach((element) => {
3639
+ element.hide();
3640
+ });
3641
+ }
3576
3642
  render() {
3577
3643
  this.threeLayer._needsUpdate = !this.threeLayer._needsUpdate;
3578
3644
  if (this.threeLayer._needsUpdate) {
@@ -3584,7 +3650,32 @@ var Element3DRenderer = class extends EventTarget {
3584
3650
 
3585
3651
  // src/IndoorMap/renderer/Element2DRenderer.ts
3586
3652
  import * as maptalks6 from "maptalks";
3587
- var OCCUPANT_TEXT_MARKER_CLASSNAME2 = "mtk-occupant-text-marker";
3653
+
3654
+ // src/IndoorMap/renderer/default/element2DRendererOptions.ts
3655
+ var element2DRendererOptions = {
3656
+ unit: {
3657
+ default: { symbol: { polygonFill: "#cccccc" } },
3658
+ byCategory: {
3659
+ room: { symbol: { polygonFill: "#fff" } },
3660
+ walkway: { symbol: { polygonFill: "#efefef", lineColor: "#dadada", lineWidth: 2 } },
3661
+ terrace: { symbol: { polygonFill: "#efefef" } },
3662
+ unenclosedarea: { symbol: { polygonFill: "#fff" } },
3663
+ nonpublic: { symbol: { polygonFill: "#999999" } }
3664
+ }
3665
+ },
3666
+ kiosk: {
3667
+ default: {}
3668
+ },
3669
+ fixture: {
3670
+ default: { symbol: { polygonFill: "#ffffff" } },
3671
+ byCategory: {
3672
+ water: { symbol: { polygonFill: "#ACD7EC" } },
3673
+ vegetation: { symbol: { polygonFill: "#91C499" } }
3674
+ }
3675
+ }
3676
+ };
3677
+
3678
+ // src/IndoorMap/renderer/Element2DRenderer.ts
3588
3679
  var DEFAULT_POLYGON_OPTION2 = {
3589
3680
  zIndex: 0,
3590
3681
  symbol: {
@@ -3594,6 +3685,7 @@ var DEFAULT_POLYGON_OPTION2 = {
3594
3685
  lineWidth: 2
3595
3686
  }
3596
3687
  };
3688
+ var MULTIORDINAL_HEIGHT_METER2 = 10;
3597
3689
  var getGeometryProperties = (feature2) => ({
3598
3690
  // Core
3599
3691
  type: "Feature",
@@ -3603,11 +3695,11 @@ var getGeometryProperties = (feature2) => ({
3603
3695
  // Extra
3604
3696
  feature_type: feature2.feature_type,
3605
3697
  category: feature2.properties.category,
3606
- name: feature2.properties.name.en
3698
+ name: feature2.properties.name?.en
3607
3699
  });
3608
3700
  var getGeometryOption2 = (feature2, options) => {
3609
3701
  try {
3610
- const option = options[feature2.feature_type];
3702
+ const option = options[feature2.feature_type] ?? element2DRendererOptions[feature2.feature_type];
3611
3703
  const category = feature2.properties.category;
3612
3704
  return (category && option.byCategory?.[category]) ?? option?.default ?? DEFAULT_POLYGON_OPTION2;
3613
3705
  } catch (err) {
@@ -3652,36 +3744,63 @@ var Element2DRenderer = class extends EventTarget {
3652
3744
  return geometry;
3653
3745
  }
3654
3746
  };
3655
- createMarker = (coordinates, ordinal, label) => {
3656
- const createStyledUIMarkerElement2 = ({ style: style2, textContent, className }) => {
3657
- const element = document.createElement("div");
3658
- for (const key in style2) {
3659
- element.style[key] = style2[key];
3660
- }
3661
- element.className = className;
3662
- element.textContent = textContent;
3663
- return element.outerHTML;
3664
- };
3665
- const style = {};
3666
- const marker = new maptalks6.ui.UIMarker(coordinates, {
3667
- content: createStyledUIMarkerElement2({
3668
- style,
3669
- textContent: label,
3670
- className: OCCUPANT_TEXT_MARKER_CLASSNAME2
3671
- }),
3672
- collision: true,
3673
- collisionFadeIn: true
3674
- // altitude: getAltitude(f.properties) + markerHeight,
3675
- });
3676
- marker.addTo(this.map);
3677
- return marker;
3678
- };
3679
3747
  createElement = (imdfFeature) => {
3680
3748
  switch (imdfFeature.feature_type) {
3681
3749
  default:
3682
3750
  return null;
3683
3751
  }
3684
3752
  };
3753
+ showElements(elements, ordinalDiff = 0) {
3754
+ elements.forEach((element) => {
3755
+ element.setAltitude(ordinalDiff * MULTIORDINAL_HEIGHT_METER2);
3756
+ element.show();
3757
+ });
3758
+ }
3759
+ hideElements(elements, ordinalDiff = 0) {
3760
+ elements.forEach((element) => {
3761
+ element.hide();
3762
+ });
3763
+ }
3764
+ // createMarker = (
3765
+ // coordinates: Position,
3766
+ // ordinal: number,
3767
+ // label: string
3768
+ // ): maptalks.ui.UIMarker => {
3769
+ // const createStyledUIMarkerElement = ({ style, textContent, className }) => {
3770
+ // const element = document.createElement("div")
3771
+ // for (const key in style) {
3772
+ // element.style[key] = style[key]
3773
+ // }
3774
+ // element.className = className
3775
+ // element.textContent = textContent
3776
+ // //! Use outerHTML to return HTML string instead of element object to avoid DOM event warnings from Maptalks.js.
3777
+ // return element.outerHTML
3778
+ // }
3779
+ // const style = {}
3780
+ // // const markerHeight = 0
3781
+ // const marker = new maptalks.ui.UIMarker(coordinates, {
3782
+ // content: createStyledUIMarkerElement({
3783
+ // style,
3784
+ // textContent: label,
3785
+ // className: OCCUPANT_TEXT_MARKER_CLASSNAME,
3786
+ // }),
3787
+ // collision: true,
3788
+ // collisionFadeIn: true,
3789
+ // altitude: MULTIORDINAL_HEIGHT_METER * ordinal,
3790
+ // })
3791
+ // marker.addTo(this.map)
3792
+ // return marker
3793
+ // }
3794
+ createMarker = (coordinates, ordinal, content) => {
3795
+ const marker = new maptalks6.ui.UIMarker(coordinates, {
3796
+ content,
3797
+ collision: true,
3798
+ collisionFadeIn: true,
3799
+ altitude: MULTIORDINAL_HEIGHT_METER2 * ordinal
3800
+ });
3801
+ marker.addTo(this.map);
3802
+ return marker;
3803
+ };
3685
3804
  };
3686
3805
 
3687
3806
  // src/IndoorMap/renderer/RendererManager.ts
@@ -3705,6 +3824,7 @@ var RendererManager = class extends EventTarget {
3705
3824
  set dataClient(value) {
3706
3825
  this.#dataClient = value;
3707
3826
  if (this.elementRenderer.isReady) {
3827
+ this.dispatchEvent(new CustomEvent("renderermanager:ready"));
3708
3828
  this.#createElements();
3709
3829
  } else {
3710
3830
  this.elementRenderer.addEventListener("threelayer:ready", (e) => {
@@ -3736,7 +3856,18 @@ var RendererManager = class extends EventTarget {
3736
3856
  const units = await this.#dataClient.filterByType("unit", {
3737
3857
  populate: true
3738
3858
  });
3739
- units.filter(
3859
+ const [walkways, otherUnits] = _partition(units, (u) => ["walkway"].includes(u.properties.category));
3860
+ walkways.forEach((unit) => {
3861
+ const element = this.elementRenderer.createGeometry(unit);
3862
+ if (element) {
3863
+ const _elements = Array.isArray(element) ? element : [element];
3864
+ _elements.forEach((el) => {
3865
+ this.elementsMap.set(unit.id, el);
3866
+ this.getElementsByOrdinal(unit.properties.level.properties.ordinal).push(el);
3867
+ });
3868
+ }
3869
+ });
3870
+ otherUnits.filter(
3740
3871
  (u) => !["opentobelow", "escalator"].includes(u.properties.category)
3741
3872
  ).forEach((unit) => {
3742
3873
  const element = this.elementRenderer.createGeometry(unit);
@@ -3764,22 +3895,30 @@ var RendererManager = class extends EventTarget {
3764
3895
  this.dispatchEvent(new CustomEvent("renderermanager:elements_created"));
3765
3896
  }
3766
3897
  changeLevelByOrdinal(targetOrdinal) {
3767
- for (const [ordinal, elements] of this.elementsByOrdinal) {
3768
- const inOrdinal = targetOrdinal === null ? true : Array.isArray(targetOrdinal) ? targetOrdinal.includes(ordinal) : ordinal === targetOrdinal;
3769
- if (inOrdinal) {
3770
- elements.forEach((element, i) => {
3771
- element.show();
3772
- });
3773
- } else {
3774
- elements.forEach((element) => {
3775
- element.hide();
3776
- });
3898
+ if (targetOrdinal === null) {
3899
+ const baseOrdinal = 0;
3900
+ for (const [ordinal, elements] of this.elementsByOrdinal) {
3901
+ this.elementRenderer.showElements(elements, ordinal - baseOrdinal);
3902
+ }
3903
+ } else {
3904
+ const baseOrdinal = Array.isArray(targetOrdinal) ? _min(targetOrdinal) : targetOrdinal;
3905
+ for (const [ordinal, elements] of this.elementsByOrdinal) {
3906
+ const inOrdinal = Array.isArray(targetOrdinal) ? targetOrdinal.includes(ordinal) : ordinal === targetOrdinal;
3907
+ if (inOrdinal) {
3908
+ this.elementRenderer.showElements(elements, ordinal - baseOrdinal);
3909
+ } else {
3910
+ this.elementRenderer.hideElements(elements, ordinal - baseOrdinal);
3911
+ }
3777
3912
  }
3778
3913
  }
3779
3914
  }
3780
- createMarker(coordinate, ordinal, label) {
3781
- const marker = this.elementRenderer.createMarker(coordinate, ordinal, label);
3782
- this.elementsMap.set(label, marker);
3915
+ /**
3916
+ * ========================================================================
3917
+ * Markers
3918
+ * ======================================================================== */
3919
+ createMarker(coordinate, ordinal, markerSymbol) {
3920
+ console.log(`createMarker`, { coordinate, ordinal, markerSymbol });
3921
+ const marker = this.elementRenderer.createMarker(coordinate, ordinal, markerSymbol);
3783
3922
  this.getElementsByOrdinal(ordinal).push(marker);
3784
3923
  }
3785
3924
  };