venue-js 1.0.0-0 → 1.0.0-2

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
@@ -142,7 +142,6 @@ var createPopulator = ({
142
142
  const populateAddress = (address) => Promise.resolve(address);
143
143
  const populateBuilding = (building) => Promise.resolve(building);
144
144
  const populateDetail = (detail) => Promise.resolve(detail);
145
- const populateFixture = (fixture) => Promise.resolve(fixture);
146
145
  const populateFootprint = (footprint) => Promise.resolve(footprint);
147
146
  const populateGeofence = (geofence) => Promise.resolve(geofence);
148
147
  const populateOpening = (opening) => Promise.resolve(opening);
@@ -198,6 +197,21 @@ var createPopulator = ({
198
197
  }
199
198
  };
200
199
  };
200
+ const populateFixture = async (fixture) => {
201
+ const level = await internalFindById(fixture.properties.level_id);
202
+ const venue = await internalFindById(fixture.properties.venue_id);
203
+ const anchor = await internalFindById(fixture.properties.anchor_id);
204
+ return {
205
+ ...fixture,
206
+ properties: {
207
+ ...fixture.properties,
208
+ anchor: anchor ? await populateAnchor(anchor) : null,
209
+ level: await populateLevel(level),
210
+ venue: await populateVenue(venue),
211
+ ordinal: level.properties.ordinal
212
+ }
213
+ };
214
+ };
201
215
  const populateKiosk = async (kiosk) => {
202
216
  const level = await internalFindById(kiosk.properties.level_id);
203
217
  const venue = await internalFindById(kiosk.properties.venue_id);
@@ -397,7 +411,7 @@ var getDataClient = (options) => {
397
411
  });
398
412
  observers.set(featureType, observer);
399
413
  } else {
400
- console.error(
414
+ console.warn(
401
415
  `An observer for featureType ${featureType} already exists, fail to register new one`
402
416
  );
403
417
  }
@@ -461,7 +475,8 @@ import {
461
475
  Extent,
462
476
  LineString as LineString3,
463
477
  animation,
464
- Marker as Marker2
478
+ Marker as Marker2,
479
+ Coordinate as Coordinate3
465
480
  } from "maptalks";
466
481
  import TWEEN2 from "@tweenjs/tween.js";
467
482
  import _6 from "lodash";
@@ -3114,50 +3129,16 @@ var createHighlighExtrudeObjectController = (obj, { color }) => {
3114
3129
  };
3115
3130
 
3116
3131
  // src/IndoorMap/camera/CameraManager.ts
3132
+ var ZOOM_OUT_LEVEL = 21;
3133
+ var ZOOM_IN_LEVEL = 24;
3117
3134
  var CameraManager = class {
3118
3135
  map;
3119
- // Use for various animation view
3120
- #defaultCenter;
3121
- #defaultZoom;
3122
- #defaultBearing = 0;
3123
- #defaultPitch = 45;
3124
- // Store current map zoomlevel
3125
- constructor(map, { defaultCenter, defaultZoom }) {
3136
+ constructor(map, options) {
3126
3137
  this.map = map;
3127
- this.#defaultCenter = defaultCenter;
3128
- if (defaultZoom) {
3129
- this.#defaultZoom = defaultZoom;
3130
- this.map.setZoom(defaultZoom);
3138
+ if (options?.defaultView) {
3139
+ this.setView(options?.defaultView);
3131
3140
  }
3132
3141
  }
3133
- set defaultBearing(value) {
3134
- this.#defaultBearing = value;
3135
- }
3136
- set defaultPitch(value) {
3137
- this.#defaultPitch = value;
3138
- }
3139
- set defaultCenter(value) {
3140
- this.#defaultCenter = value;
3141
- }
3142
- set defaultZoom(value) {
3143
- this.#defaultZoom = value;
3144
- }
3145
- get defaultCenter() {
3146
- return this.#defaultCenter;
3147
- }
3148
- get defaultZoom() {
3149
- return this.#defaultZoom;
3150
- }
3151
- get defaultBearing() {
3152
- return this.#defaultBearing;
3153
- }
3154
- get defaultPitch() {
3155
- return this.#defaultPitch;
3156
- }
3157
- getBearing = () => this.map.getBearing();
3158
- getPitch = () => this.map.getPitch();
3159
- getZoom = () => this.map.getZoom();
3160
- setBearing = (bearing) => this.map.setBearing(bearing);
3161
3142
  /** Private method */
3162
3143
  #animateflyTo(viewOptions = {}, options = {}, callbackOption = () => {
3163
3144
  }) {
@@ -3175,13 +3156,23 @@ var CameraManager = class {
3175
3156
  });
3176
3157
  }
3177
3158
  /** Public methods */
3159
+ getView = () => {
3160
+ return this.map.getView();
3161
+ };
3162
+ getZoom = () => {
3163
+ return this.map.getView().zoom;
3164
+ };
3165
+ setView = (value) => {
3166
+ this.map.setView(value);
3167
+ };
3178
3168
  flyTo = (center2, options = {}) => {
3169
+ const currentView = this.getView();
3179
3170
  const {
3180
- zoom = this.#defaultZoom,
3171
+ zoom = ZOOM_OUT_LEVEL,
3181
3172
  pitch = 60,
3182
3173
  duration = 600,
3183
3174
  easing = "out",
3184
- bearing = this.getBearing()
3175
+ bearing = currentView.bearing
3185
3176
  } = options;
3186
3177
  this.#animateflyTo(
3187
3178
  {
@@ -3195,7 +3186,7 @@ var CameraManager = class {
3195
3186
  };
3196
3187
  flyToAndZoomIn = (centerPoint, options = {}) => {
3197
3188
  const {
3198
- zoom = this.#defaultZoom + 3,
3189
+ zoom = ZOOM_IN_LEVEL,
3199
3190
  pitch = 60,
3200
3191
  duration = 600,
3201
3192
  easing = "out"
@@ -3375,7 +3366,7 @@ var DEFAULT_POLYGON_OPTION = {
3375
3366
  offset: 0,
3376
3367
  altitude: 0
3377
3368
  };
3378
- var HEIGHT_METER = 16;
3369
+ var HEIGHT_METER = 4;
3379
3370
  var getGeometryOption = (feature2, options) => {
3380
3371
  try {
3381
3372
  const option = options[feature2.feature_type];
@@ -3413,7 +3404,7 @@ var Element3DRenderer = class extends EventTarget {
3413
3404
  const hemi = new THREE2.HemisphereLight(16777215, 4473924, 0.4);
3414
3405
  scene.add(hemi);
3415
3406
  this.isReady = true;
3416
- _this.dispatchEvent(new CustomEvent("renderer:ready"));
3407
+ _this.dispatchEvent(new CustomEvent("threelayer:ready"));
3417
3408
  };
3418
3409
  this.lineMaterial = new THREE2.LineBasicMaterial({ color: "#000" });
3419
3410
  this.threeLayer.addTo(this.map);
@@ -3445,7 +3436,7 @@ var Element3DRenderer = class extends EventTarget {
3445
3436
  markerPath: [
3446
3437
  {
3447
3438
  path: "M21.75 0H0.25V21.5H8.35L11.3 24L14.2 21.5H21.75V0Z",
3448
- fill: "#044B7F"
3439
+ fill: "#ff0000"
3449
3440
  }
3450
3441
  ],
3451
3442
  markerPathWidth: 24,
@@ -3474,33 +3465,55 @@ var Element3DRenderer = class extends EventTarget {
3474
3465
  }
3475
3466
  createGeometry = (feature2) => {
3476
3467
  const options = getGeometryOption(feature2, this.options);
3477
- const offset = options.offset ?? 0;
3468
+ const offset = options?.offset ?? 0;
3469
+ const createPolygon = (geometry, feature3) => {
3470
+ const [outerRing, ...innerRings] = geometry.coordinates;
3471
+ const offsetFeature = offset !== 0 ? turfBuffer2(geometry, offset, { units: "meters" }) : feature3;
3472
+ const color = options.color ?? feature3.properties.style.polygonFill ?? "#ffffff";
3473
+ if (color === "transparent") return;
3474
+ const material = this.getOrCreateMaterialByColor(color);
3475
+ const altitude = feature3.properties.ordinal * HEIGHT_METER;
3476
+ const bottomHeight = options.bottomHeight ?? 0;
3477
+ const polygon = this.threeLayer.toExtrudePolygon(
3478
+ offsetFeature,
3479
+ { asynchronous: true, ...options, altitude },
3480
+ material
3481
+ );
3482
+ const topLineStrings = [
3483
+ new maptalks5.LineString(outerRing),
3484
+ ...innerRings.map((innerRing) => new maptalks5.LineString(innerRing))
3485
+ ];
3486
+ const topLines = this.threeLayer.toLines(
3487
+ topLineStrings,
3488
+ { altitude: altitude + options.height + 1e-3, bottomHeight, interactive: false },
3489
+ this.lineMaterial
3490
+ );
3491
+ const bottomLineStrings = [
3492
+ new maptalks5.LineString(outerRing),
3493
+ ...innerRings.map((innerRing) => new maptalks5.LineString(innerRing))
3494
+ ];
3495
+ const bottomLines = this.threeLayer.toLines(
3496
+ bottomLineStrings,
3497
+ { altitude, bottomHeight, interactive: false },
3498
+ this.lineMaterial
3499
+ );
3500
+ return [polygon, topLines, bottomLines];
3501
+ };
3478
3502
  try {
3479
3503
  switch (feature2.geometry.type) {
3480
- case "Polygon": {
3481
- const offsetFeature = offset !== 0 ? turfBuffer2(feature2.geometry, offset, { units: "meters" }) : feature2;
3482
- const color = options.color ?? feature2.properties.style.polygonFill ?? "#ffffff";
3483
- if (color === "transparent") return;
3484
- const material = this.getOrCreateMaterialByColor(color);
3485
- const altitude = feature2.properties.ordinal * HEIGHT_METER;
3486
- const polygon = this.threeLayer.toExtrudePolygon(
3487
- offsetFeature,
3488
- { asynchronous: true, ...options, altitude },
3489
- material
3490
- );
3491
- const lineString2 = new maptalks5.LineString(
3492
- feature2.geometry.coordinates[0]
3493
- );
3494
- const line = this.threeLayer.toLine(
3495
- lineString2,
3496
- { altitude: altitude + options.height + 1e-3, interactive: false },
3497
- this.lineMaterial
3498
- );
3499
- this.threeLayer.addMesh([polygon, line]);
3500
- return [polygon, line];
3501
- }
3502
3504
  case "MultiPolygon": {
3503
- throw new Error("Dost not support MultiPolygon");
3505
+ const { coordinates } = feature2.geometry;
3506
+ const multiMeshes = coordinates.flatMap((polygonCoordinates) => {
3507
+ const meshes = createPolygon({ type: "Polygon", coordinates: polygonCoordinates }, feature2);
3508
+ this.threeLayer.addMesh(meshes);
3509
+ return meshes;
3510
+ });
3511
+ return multiMeshes;
3512
+ }
3513
+ case "Polygon": {
3514
+ const meshes = createPolygon(feature2.geometry, feature2);
3515
+ this.threeLayer.addMesh(meshes);
3516
+ return meshes;
3504
3517
  }
3505
3518
  }
3506
3519
  } catch (err) {
@@ -3510,7 +3523,7 @@ var Element3DRenderer = class extends EventTarget {
3510
3523
  createMarker = (coordinates, ordinal, label) => {
3511
3524
  const options = {
3512
3525
  scale: 0.05,
3513
- altitude: ordinal * HEIGHT_METER + 4,
3526
+ altitude: ordinal * HEIGHT_METER,
3514
3527
  // highlight: highlightOptions,
3515
3528
  interactive: true
3516
3529
  };
@@ -3662,7 +3675,8 @@ var Element2DRenderer = class extends EventTarget {
3662
3675
  };
3663
3676
 
3664
3677
  // src/IndoorMap/renderer/RendererManager.ts
3665
- var RendererManager = class {
3678
+ var RendererManager = class extends EventTarget {
3679
+ map;
3666
3680
  options;
3667
3681
  // Client for fetching data
3668
3682
  #dataClient;
@@ -3671,6 +3685,8 @@ var RendererManager = class {
3671
3685
  elementsMap;
3672
3686
  elementsByOrdinal;
3673
3687
  constructor(map, options) {
3688
+ super();
3689
+ this.map = map;
3674
3690
  this.options = options;
3675
3691
  this.elementsMap = /* @__PURE__ */ new Map();
3676
3692
  this.elementsByOrdinal = /* @__PURE__ */ new Map();
@@ -3681,17 +3697,31 @@ var RendererManager = class {
3681
3697
  if (this.elementRenderer.isReady) {
3682
3698
  this.#createElements();
3683
3699
  } else {
3684
- this.elementRenderer.addEventListener("renderer:ready", (e) => {
3700
+ this.elementRenderer.addEventListener("threelayer:ready", (e) => {
3701
+ this.dispatchEvent(new CustomEvent("renderermanager:ready"));
3685
3702
  this.#createElements();
3686
3703
  });
3687
3704
  }
3688
3705
  }
3706
+ getElementsByOrdinal = (ordinal) => {
3707
+ const exist = this.elementsByOrdinal.get(ordinal);
3708
+ if (!exist) this.elementsByOrdinal.set(ordinal, []);
3709
+ return this.elementsByOrdinal.get(ordinal);
3710
+ };
3689
3711
  async #createElements() {
3690
3712
  const levels = await this.#dataClient.filterByType("level", {
3691
3713
  populate: true
3692
3714
  });
3693
- levels.forEach((level) => {
3694
- this.elementsByOrdinal.set(level.properties.ordinal, []);
3715
+ const fixtures = await this.#dataClient.filterByType("fixture", { populate: true });
3716
+ fixtures.forEach((fixture) => {
3717
+ const element = this.elementRenderer.createGeometry(fixture);
3718
+ if (element) {
3719
+ const _elements = Array.isArray(element) ? element : [element];
3720
+ _elements.forEach((el) => {
3721
+ this.elementsMap.set(fixture.id, el);
3722
+ this.getElementsByOrdinal(fixture.properties.level.properties.ordinal).push(el);
3723
+ });
3724
+ }
3695
3725
  });
3696
3726
  const units = await this.#dataClient.filterByType("unit", {
3697
3727
  populate: true
@@ -3704,7 +3734,7 @@ var RendererManager = class {
3704
3734
  const _elements = Array.isArray(element) ? element : [element];
3705
3735
  _elements.forEach((el) => {
3706
3736
  this.elementsMap.set(unit.id, el);
3707
- this.elementsByOrdinal.get(unit.properties.level.properties.ordinal).push(el);
3737
+ this.getElementsByOrdinal(unit.properties.level.properties.ordinal).push(el);
3708
3738
  });
3709
3739
  }
3710
3740
  });
@@ -3717,10 +3747,11 @@ var RendererManager = class {
3717
3747
  const _elements = Array.isArray(element) ? element : [element];
3718
3748
  _elements.forEach((el) => {
3719
3749
  this.elementsMap.set(kiosk.id, el);
3720
- this.elementsByOrdinal.get(kiosk.properties.level.properties.ordinal).push(el);
3750
+ this.getElementsByOrdinal(kiosk.properties.level.properties.ordinal).push(el);
3721
3751
  });
3722
3752
  }
3723
3753
  });
3754
+ this.dispatchEvent(new CustomEvent("renderermanager:elements_created"));
3724
3755
  }
3725
3756
  changeLevelByOrdinal(targetOrdinal) {
3726
3757
  for (const [ordinal, elements] of this.elementsByOrdinal) {
@@ -3739,19 +3770,19 @@ var RendererManager = class {
3739
3770
  createMarker(coordinate, ordinal, label) {
3740
3771
  const marker = this.elementRenderer.createMarker(coordinate, ordinal, label);
3741
3772
  this.elementsMap.set(label, marker);
3742
- this.elementsByOrdinal.get(ordinal).push(marker);
3773
+ this.getElementsByOrdinal(ordinal).push(marker);
3743
3774
  }
3744
3775
  };
3745
3776
 
3746
3777
  // src/IndoorMap/IndoorMap.ts
3778
+ var INITIAL_CENTER = [100.5017051, 13.7572619];
3779
+ var INITIAL_ZOOM = 18.5;
3780
+ var CLICK_TOLERANCE = 20;
3747
3781
  var defaultOptions = {
3748
- center: [100.5017051, 13.7572619],
3749
- defaultZoom: 18.5,
3750
3782
  pixelRatio: 1,
3751
3783
  locale: DEFAULT_LOCALE
3752
3784
  };
3753
- var CLICK_TOLERANCE = 20;
3754
- var IndoorMap = class {
3785
+ var IndoorMap = class extends EventTarget {
3755
3786
  //TODO: refac functions; let them do only 1 thing in a function
3756
3787
  /** Note: "#" means private variables */
3757
3788
  #styler = null;
@@ -3793,7 +3824,7 @@ var IndoorMap = class {
3793
3824
  #animationsToRun = [];
3794
3825
  map = null;
3795
3826
  #dataClient;
3796
- cameraManager;
3827
+ camera;
3797
3828
  rendererManager;
3798
3829
  showVenueObject = false;
3799
3830
  threeLayer = null;
@@ -3802,9 +3833,8 @@ var IndoorMap = class {
3802
3833
  onMapLoading = () => {
3803
3834
  };
3804
3835
  constructor(elementId, options) {
3836
+ super();
3805
3837
  const {
3806
- center: center2,
3807
- defaultZoom,
3808
3838
  onMapReady,
3809
3839
  onMapLoading,
3810
3840
  pixelRatio,
@@ -3812,13 +3842,13 @@ var IndoorMap = class {
3812
3842
  } = _6.merge({}, defaultOptions, options);
3813
3843
  this.map = new Map2(elementId, {
3814
3844
  attribution: false,
3815
- center: center2,
3816
- zoom: defaultZoom,
3845
+ center: INITIAL_CENTER,
3846
+ zoom: INITIAL_ZOOM,
3817
3847
  clickTimeThreshold: 600,
3818
3848
  baseLayer: new TileLayer("base", {
3819
3849
  urlTemplate: "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
3820
3850
  subdomains: ["a", "b", "c", "d"],
3821
- opacity: 0.6,
3851
+ opacity: 1,
3822
3852
  attribution: "",
3823
3853
  hitDetect: false,
3824
3854
  decodeImageInWorker: true,
@@ -3826,11 +3856,14 @@ var IndoorMap = class {
3826
3856
  }),
3827
3857
  layers: []
3828
3858
  });
3829
- this.cameraManager = new CameraManager(this.map, {
3830
- defaultCenter: center2,
3831
- defaultZoom
3832
- });
3833
3859
  this.rendererManager = new RendererManager(this.map, options.renderer);
3860
+ this.rendererManager.addEventListener("renderermanager:ready", (e) => {
3861
+ this.dispatchEvent(new CustomEvent("renderer:ready"));
3862
+ });
3863
+ this.rendererManager.addEventListener("renderermanager:elements_created", (e) => {
3864
+ this.dispatchEvent(new CustomEvent("renderer:elements_created"));
3865
+ });
3866
+ this.camera = new CameraManager(this.map);
3834
3867
  this.locale = locale;
3835
3868
  this.pixelRatio = pixelRatio;
3836
3869
  this.onMapReady = onMapReady;
@@ -3841,7 +3874,13 @@ var IndoorMap = class {
3841
3874
  }
3842
3875
  set dataClient(value) {
3843
3876
  this.#dataClient = value;
3844
- if (this.rendererManager) this.rendererManager.dataClient = this.#dataClient;
3877
+ this.#dataClient.filterByType("venue").then((venues) => {
3878
+ const venueCenters = turfCenter2(featureCollection(venues));
3879
+ const [x, y] = venueCenters.geometry.coordinates;
3880
+ const center2 = new Coordinate3(x, y);
3881
+ this.camera.setView({ center: center2, pitch: 60, zoom: 19 });
3882
+ });
3883
+ this.rendererManager.dataClient = this.#dataClient;
3845
3884
  }
3846
3885
  /**
3847
3886
  * Events
@@ -3870,30 +3909,6 @@ var IndoorMap = class {
3870
3909
  /**
3871
3910
  * Getters & Setters
3872
3911
  */
3873
- set defaultBearing(value) {
3874
- this.cameraManager.defaultBearing = value;
3875
- }
3876
- set defaultPitch(value) {
3877
- this.cameraManager.defaultPitch = value;
3878
- }
3879
- set defaultCenter(value) {
3880
- this.cameraManager.defaultCenter = value;
3881
- }
3882
- set defaultZoom(value) {
3883
- this.cameraManager.defaultZoom = value;
3884
- }
3885
- get defaultBearing() {
3886
- return this.cameraManager.defaultBearing;
3887
- }
3888
- get defaultPitch() {
3889
- return this.cameraManager.defaultPitch;
3890
- }
3891
- get defaultCenter() {
3892
- return this.cameraManager.defaultCenter;
3893
- }
3894
- get defaultZoom() {
3895
- return this.cameraManager.defaultZoom;
3896
- }
3897
3912
  get elementsLoaded() {
3898
3913
  return this.#elementsLoaded;
3899
3914
  }
@@ -4325,7 +4340,7 @@ var IndoorMap = class {
4325
4340
  const {
4326
4341
  geometry: { coordinates }
4327
4342
  } = turfCenter2(feature2);
4328
- this.cameraManager.flyToAndZoomIn(coordinates, { pitch: 45 });
4343
+ this.camera.flyToAndZoomIn(coordinates, { pitch: 45 });
4329
4344
  });
4330
4345
  object3ds.push(object);
4331
4346
  this.#objects.push(object);
@@ -4476,7 +4491,7 @@ var IndoorMap = class {
4476
4491
  return result;
4477
4492
  };
4478
4493
  flyTo = (center2, options) => {
4479
- this.cameraManager.flyTo(center2, options);
4494
+ this.camera.flyTo(center2, options);
4480
4495
  };
4481
4496
  getLineStringBearing = (feature2) => {
4482
4497
  const { geometry } = feature2;
@@ -5028,7 +5043,7 @@ var IndoorMap = class {
5028
5043
  this.threeLayer.redraw();
5029
5044
  }
5030
5045
  if (this.threeLayer) {
5031
- const objectOpacity = _6.clamp(38 - 2 * this.cameraManager.getZoom(), 0, 1);
5046
+ const objectOpacity = _6.clamp(38 - 2 * this.camera.getZoom(), 0, 1);
5032
5047
  this.#objects.forEach((object) => {
5033
5048
  object.getObject3d().traverse((child) => {
5034
5049
  if (child.isMesh) child.material.opacity = objectOpacity;
@@ -5039,7 +5054,7 @@ var IndoorMap = class {
5039
5054
  if (this.#billboardObjects) {
5040
5055
  this.#billboardObjects.forEach((object) => {
5041
5056
  const objectScale = _6.clamp(
5042
- 20 - 1 * this.cameraManager.getZoom(),
5057
+ 20 - 1 * this.camera.getZoom(),
5043
5058
  1,
5044
5059
  1.05
5045
5060
  );