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.js CHANGED
@@ -221,7 +221,6 @@ var createPopulator = ({
221
221
  const populateAddress = (address) => Promise.resolve(address);
222
222
  const populateBuilding = (building) => Promise.resolve(building);
223
223
  const populateDetail = (detail) => Promise.resolve(detail);
224
- const populateFixture = (fixture) => Promise.resolve(fixture);
225
224
  const populateFootprint = (footprint) => Promise.resolve(footprint);
226
225
  const populateGeofence = (geofence) => Promise.resolve(geofence);
227
226
  const populateOpening = (opening) => Promise.resolve(opening);
@@ -277,6 +276,21 @@ var createPopulator = ({
277
276
  }
278
277
  };
279
278
  };
279
+ const populateFixture = async (fixture) => {
280
+ const level = await internalFindById(fixture.properties.level_id);
281
+ const venue = await internalFindById(fixture.properties.venue_id);
282
+ const anchor = await internalFindById(fixture.properties.anchor_id);
283
+ return {
284
+ ...fixture,
285
+ properties: {
286
+ ...fixture.properties,
287
+ anchor: anchor ? await populateAnchor(anchor) : null,
288
+ level: await populateLevel(level),
289
+ venue: await populateVenue(venue),
290
+ ordinal: level.properties.ordinal
291
+ }
292
+ };
293
+ };
280
294
  const populateKiosk = async (kiosk) => {
281
295
  const level = await internalFindById(kiosk.properties.level_id);
282
296
  const venue = await internalFindById(kiosk.properties.venue_id);
@@ -476,7 +490,7 @@ var getDataClient = (options) => {
476
490
  });
477
491
  observers.set(featureType, observer);
478
492
  } else {
479
- console.error(
493
+ console.warn(
480
494
  `An observer for featureType ${featureType} already exists, fail to register new one`
481
495
  );
482
496
  }
@@ -3158,50 +3172,16 @@ var createHighlighExtrudeObjectController = (obj, { color }) => {
3158
3172
  };
3159
3173
 
3160
3174
  // src/IndoorMap/camera/CameraManager.ts
3175
+ var ZOOM_OUT_LEVEL = 21;
3176
+ var ZOOM_IN_LEVEL = 24;
3161
3177
  var CameraManager = class {
3162
3178
  map;
3163
- // Use for various animation view
3164
- #defaultCenter;
3165
- #defaultZoom;
3166
- #defaultBearing = 0;
3167
- #defaultPitch = 45;
3168
- // Store current map zoomlevel
3169
- constructor(map, { defaultCenter, defaultZoom }) {
3179
+ constructor(map, options) {
3170
3180
  this.map = map;
3171
- this.#defaultCenter = defaultCenter;
3172
- if (defaultZoom) {
3173
- this.#defaultZoom = defaultZoom;
3174
- this.map.setZoom(defaultZoom);
3181
+ if (options?.defaultView) {
3182
+ this.setView(options?.defaultView);
3175
3183
  }
3176
3184
  }
3177
- set defaultBearing(value) {
3178
- this.#defaultBearing = value;
3179
- }
3180
- set defaultPitch(value) {
3181
- this.#defaultPitch = value;
3182
- }
3183
- set defaultCenter(value) {
3184
- this.#defaultCenter = value;
3185
- }
3186
- set defaultZoom(value) {
3187
- this.#defaultZoom = value;
3188
- }
3189
- get defaultCenter() {
3190
- return this.#defaultCenter;
3191
- }
3192
- get defaultZoom() {
3193
- return this.#defaultZoom;
3194
- }
3195
- get defaultBearing() {
3196
- return this.#defaultBearing;
3197
- }
3198
- get defaultPitch() {
3199
- return this.#defaultPitch;
3200
- }
3201
- getBearing = () => this.map.getBearing();
3202
- getPitch = () => this.map.getPitch();
3203
- getZoom = () => this.map.getZoom();
3204
- setBearing = (bearing) => this.map.setBearing(bearing);
3205
3185
  /** Private method */
3206
3186
  #animateflyTo(viewOptions = {}, options = {}, callbackOption = () => {
3207
3187
  }) {
@@ -3219,13 +3199,23 @@ var CameraManager = class {
3219
3199
  });
3220
3200
  }
3221
3201
  /** Public methods */
3202
+ getView = () => {
3203
+ return this.map.getView();
3204
+ };
3205
+ getZoom = () => {
3206
+ return this.map.getView().zoom;
3207
+ };
3208
+ setView = (value) => {
3209
+ this.map.setView(value);
3210
+ };
3222
3211
  flyTo = (center2, options = {}) => {
3212
+ const currentView = this.getView();
3223
3213
  const {
3224
- zoom = this.#defaultZoom,
3214
+ zoom = ZOOM_OUT_LEVEL,
3225
3215
  pitch = 60,
3226
3216
  duration = 600,
3227
3217
  easing = "out",
3228
- bearing = this.getBearing()
3218
+ bearing = currentView.bearing
3229
3219
  } = options;
3230
3220
  this.#animateflyTo(
3231
3221
  {
@@ -3239,7 +3229,7 @@ var CameraManager = class {
3239
3229
  };
3240
3230
  flyToAndZoomIn = (centerPoint, options = {}) => {
3241
3231
  const {
3242
- zoom = this.#defaultZoom + 3,
3232
+ zoom = ZOOM_IN_LEVEL,
3243
3233
  pitch = 60,
3244
3234
  duration = 600,
3245
3235
  easing = "out"
@@ -3419,7 +3409,7 @@ var DEFAULT_POLYGON_OPTION = {
3419
3409
  offset: 0,
3420
3410
  altitude: 0
3421
3411
  };
3422
- var HEIGHT_METER = 16;
3412
+ var HEIGHT_METER = 4;
3423
3413
  var getGeometryOption = (feature2, options) => {
3424
3414
  try {
3425
3415
  const option = options[feature2.feature_type];
@@ -3457,7 +3447,7 @@ var Element3DRenderer = class extends EventTarget {
3457
3447
  const hemi = new THREE2.HemisphereLight(16777215, 4473924, 0.4);
3458
3448
  scene.add(hemi);
3459
3449
  this.isReady = true;
3460
- _this.dispatchEvent(new CustomEvent("renderer:ready"));
3450
+ _this.dispatchEvent(new CustomEvent("threelayer:ready"));
3461
3451
  };
3462
3452
  this.lineMaterial = new THREE2.LineBasicMaterial({ color: "#000" });
3463
3453
  this.threeLayer.addTo(this.map);
@@ -3489,7 +3479,7 @@ var Element3DRenderer = class extends EventTarget {
3489
3479
  markerPath: [
3490
3480
  {
3491
3481
  path: "M21.75 0H0.25V21.5H8.35L11.3 24L14.2 21.5H21.75V0Z",
3492
- fill: "#044B7F"
3482
+ fill: "#ff0000"
3493
3483
  }
3494
3484
  ],
3495
3485
  markerPathWidth: 24,
@@ -3518,33 +3508,55 @@ var Element3DRenderer = class extends EventTarget {
3518
3508
  }
3519
3509
  createGeometry = (feature2) => {
3520
3510
  const options = getGeometryOption(feature2, this.options);
3521
- const offset = options.offset ?? 0;
3511
+ const offset = options?.offset ?? 0;
3512
+ const createPolygon = (geometry, feature3) => {
3513
+ const [outerRing, ...innerRings] = geometry.coordinates;
3514
+ const offsetFeature = offset !== 0 ? (0, import_buffer2.default)(geometry, offset, { units: "meters" }) : feature3;
3515
+ const color = options.color ?? feature3.properties.style.polygonFill ?? "#ffffff";
3516
+ if (color === "transparent") return;
3517
+ const material = this.getOrCreateMaterialByColor(color);
3518
+ const altitude = feature3.properties.ordinal * HEIGHT_METER;
3519
+ const bottomHeight = options.bottomHeight ?? 0;
3520
+ const polygon = this.threeLayer.toExtrudePolygon(
3521
+ offsetFeature,
3522
+ { asynchronous: true, ...options, altitude },
3523
+ material
3524
+ );
3525
+ const topLineStrings = [
3526
+ new maptalks5.LineString(outerRing),
3527
+ ...innerRings.map((innerRing) => new maptalks5.LineString(innerRing))
3528
+ ];
3529
+ const topLines = this.threeLayer.toLines(
3530
+ topLineStrings,
3531
+ { altitude: altitude + options.height + 1e-3, bottomHeight, interactive: false },
3532
+ this.lineMaterial
3533
+ );
3534
+ const bottomLineStrings = [
3535
+ new maptalks5.LineString(outerRing),
3536
+ ...innerRings.map((innerRing) => new maptalks5.LineString(innerRing))
3537
+ ];
3538
+ const bottomLines = this.threeLayer.toLines(
3539
+ bottomLineStrings,
3540
+ { altitude, bottomHeight, interactive: false },
3541
+ this.lineMaterial
3542
+ );
3543
+ return [polygon, topLines, bottomLines];
3544
+ };
3522
3545
  try {
3523
3546
  switch (feature2.geometry.type) {
3524
- case "Polygon": {
3525
- const offsetFeature = offset !== 0 ? (0, import_buffer2.default)(feature2.geometry, offset, { units: "meters" }) : feature2;
3526
- const color = options.color ?? feature2.properties.style.polygonFill ?? "#ffffff";
3527
- if (color === "transparent") return;
3528
- const material = this.getOrCreateMaterialByColor(color);
3529
- const altitude = feature2.properties.ordinal * HEIGHT_METER;
3530
- const polygon = this.threeLayer.toExtrudePolygon(
3531
- offsetFeature,
3532
- { asynchronous: true, ...options, altitude },
3533
- material
3534
- );
3535
- const lineString2 = new maptalks5.LineString(
3536
- feature2.geometry.coordinates[0]
3537
- );
3538
- const line = this.threeLayer.toLine(
3539
- lineString2,
3540
- { altitude: altitude + options.height + 1e-3, interactive: false },
3541
- this.lineMaterial
3542
- );
3543
- this.threeLayer.addMesh([polygon, line]);
3544
- return [polygon, line];
3545
- }
3546
3547
  case "MultiPolygon": {
3547
- throw new Error("Dost not support MultiPolygon");
3548
+ const { coordinates } = feature2.geometry;
3549
+ const multiMeshes = coordinates.flatMap((polygonCoordinates) => {
3550
+ const meshes = createPolygon({ type: "Polygon", coordinates: polygonCoordinates }, feature2);
3551
+ this.threeLayer.addMesh(meshes);
3552
+ return meshes;
3553
+ });
3554
+ return multiMeshes;
3555
+ }
3556
+ case "Polygon": {
3557
+ const meshes = createPolygon(feature2.geometry, feature2);
3558
+ this.threeLayer.addMesh(meshes);
3559
+ return meshes;
3548
3560
  }
3549
3561
  }
3550
3562
  } catch (err) {
@@ -3554,7 +3566,7 @@ var Element3DRenderer = class extends EventTarget {
3554
3566
  createMarker = (coordinates, ordinal, label) => {
3555
3567
  const options = {
3556
3568
  scale: 0.05,
3557
- altitude: ordinal * HEIGHT_METER + 4,
3569
+ altitude: ordinal * HEIGHT_METER,
3558
3570
  // highlight: highlightOptions,
3559
3571
  interactive: true
3560
3572
  };
@@ -3706,7 +3718,8 @@ var Element2DRenderer = class extends EventTarget {
3706
3718
  };
3707
3719
 
3708
3720
  // src/IndoorMap/renderer/RendererManager.ts
3709
- var RendererManager = class {
3721
+ var RendererManager = class extends EventTarget {
3722
+ map;
3710
3723
  options;
3711
3724
  // Client for fetching data
3712
3725
  #dataClient;
@@ -3715,6 +3728,8 @@ var RendererManager = class {
3715
3728
  elementsMap;
3716
3729
  elementsByOrdinal;
3717
3730
  constructor(map, options) {
3731
+ super();
3732
+ this.map = map;
3718
3733
  this.options = options;
3719
3734
  this.elementsMap = /* @__PURE__ */ new Map();
3720
3735
  this.elementsByOrdinal = /* @__PURE__ */ new Map();
@@ -3725,17 +3740,31 @@ var RendererManager = class {
3725
3740
  if (this.elementRenderer.isReady) {
3726
3741
  this.#createElements();
3727
3742
  } else {
3728
- this.elementRenderer.addEventListener("renderer:ready", (e) => {
3743
+ this.elementRenderer.addEventListener("threelayer:ready", (e) => {
3744
+ this.dispatchEvent(new CustomEvent("renderermanager:ready"));
3729
3745
  this.#createElements();
3730
3746
  });
3731
3747
  }
3732
3748
  }
3749
+ getElementsByOrdinal = (ordinal) => {
3750
+ const exist = this.elementsByOrdinal.get(ordinal);
3751
+ if (!exist) this.elementsByOrdinal.set(ordinal, []);
3752
+ return this.elementsByOrdinal.get(ordinal);
3753
+ };
3733
3754
  async #createElements() {
3734
3755
  const levels = await this.#dataClient.filterByType("level", {
3735
3756
  populate: true
3736
3757
  });
3737
- levels.forEach((level) => {
3738
- this.elementsByOrdinal.set(level.properties.ordinal, []);
3758
+ const fixtures = await this.#dataClient.filterByType("fixture", { populate: true });
3759
+ fixtures.forEach((fixture) => {
3760
+ const element = this.elementRenderer.createGeometry(fixture);
3761
+ if (element) {
3762
+ const _elements = Array.isArray(element) ? element : [element];
3763
+ _elements.forEach((el) => {
3764
+ this.elementsMap.set(fixture.id, el);
3765
+ this.getElementsByOrdinal(fixture.properties.level.properties.ordinal).push(el);
3766
+ });
3767
+ }
3739
3768
  });
3740
3769
  const units = await this.#dataClient.filterByType("unit", {
3741
3770
  populate: true
@@ -3748,7 +3777,7 @@ var RendererManager = class {
3748
3777
  const _elements = Array.isArray(element) ? element : [element];
3749
3778
  _elements.forEach((el) => {
3750
3779
  this.elementsMap.set(unit.id, el);
3751
- this.elementsByOrdinal.get(unit.properties.level.properties.ordinal).push(el);
3780
+ this.getElementsByOrdinal(unit.properties.level.properties.ordinal).push(el);
3752
3781
  });
3753
3782
  }
3754
3783
  });
@@ -3761,10 +3790,11 @@ var RendererManager = class {
3761
3790
  const _elements = Array.isArray(element) ? element : [element];
3762
3791
  _elements.forEach((el) => {
3763
3792
  this.elementsMap.set(kiosk.id, el);
3764
- this.elementsByOrdinal.get(kiosk.properties.level.properties.ordinal).push(el);
3793
+ this.getElementsByOrdinal(kiosk.properties.level.properties.ordinal).push(el);
3765
3794
  });
3766
3795
  }
3767
3796
  });
3797
+ this.dispatchEvent(new CustomEvent("renderermanager:elements_created"));
3768
3798
  }
3769
3799
  changeLevelByOrdinal(targetOrdinal) {
3770
3800
  for (const [ordinal, elements] of this.elementsByOrdinal) {
@@ -3783,19 +3813,19 @@ var RendererManager = class {
3783
3813
  createMarker(coordinate, ordinal, label) {
3784
3814
  const marker = this.elementRenderer.createMarker(coordinate, ordinal, label);
3785
3815
  this.elementsMap.set(label, marker);
3786
- this.elementsByOrdinal.get(ordinal).push(marker);
3816
+ this.getElementsByOrdinal(ordinal).push(marker);
3787
3817
  }
3788
3818
  };
3789
3819
 
3790
3820
  // src/IndoorMap/IndoorMap.ts
3821
+ var INITIAL_CENTER = [100.5017051, 13.7572619];
3822
+ var INITIAL_ZOOM = 18.5;
3823
+ var CLICK_TOLERANCE = 20;
3791
3824
  var defaultOptions = {
3792
- center: [100.5017051, 13.7572619],
3793
- defaultZoom: 18.5,
3794
3825
  pixelRatio: 1,
3795
3826
  locale: DEFAULT_LOCALE
3796
3827
  };
3797
- var CLICK_TOLERANCE = 20;
3798
- var IndoorMap = class {
3828
+ var IndoorMap = class extends EventTarget {
3799
3829
  //TODO: refac functions; let them do only 1 thing in a function
3800
3830
  /** Note: "#" means private variables */
3801
3831
  #styler = null;
@@ -3837,7 +3867,7 @@ var IndoorMap = class {
3837
3867
  #animationsToRun = [];
3838
3868
  map = null;
3839
3869
  #dataClient;
3840
- cameraManager;
3870
+ camera;
3841
3871
  rendererManager;
3842
3872
  showVenueObject = false;
3843
3873
  threeLayer = null;
@@ -3846,9 +3876,8 @@ var IndoorMap = class {
3846
3876
  onMapLoading = () => {
3847
3877
  };
3848
3878
  constructor(elementId, options) {
3879
+ super();
3849
3880
  const {
3850
- center: center2,
3851
- defaultZoom,
3852
3881
  onMapReady,
3853
3882
  onMapLoading,
3854
3883
  pixelRatio,
@@ -3856,13 +3885,13 @@ var IndoorMap = class {
3856
3885
  } = import_lodash6.default.merge({}, defaultOptions, options);
3857
3886
  this.map = new import_maptalks8.Map(elementId, {
3858
3887
  attribution: false,
3859
- center: center2,
3860
- zoom: defaultZoom,
3888
+ center: INITIAL_CENTER,
3889
+ zoom: INITIAL_ZOOM,
3861
3890
  clickTimeThreshold: 600,
3862
3891
  baseLayer: new import_maptalks8.TileLayer("base", {
3863
3892
  urlTemplate: "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
3864
3893
  subdomains: ["a", "b", "c", "d"],
3865
- opacity: 0.6,
3894
+ opacity: 1,
3866
3895
  attribution: "",
3867
3896
  hitDetect: false,
3868
3897
  decodeImageInWorker: true,
@@ -3870,11 +3899,14 @@ var IndoorMap = class {
3870
3899
  }),
3871
3900
  layers: []
3872
3901
  });
3873
- this.cameraManager = new CameraManager(this.map, {
3874
- defaultCenter: center2,
3875
- defaultZoom
3876
- });
3877
3902
  this.rendererManager = new RendererManager(this.map, options.renderer);
3903
+ this.rendererManager.addEventListener("renderermanager:ready", (e) => {
3904
+ this.dispatchEvent(new CustomEvent("renderer:ready"));
3905
+ });
3906
+ this.rendererManager.addEventListener("renderermanager:elements_created", (e) => {
3907
+ this.dispatchEvent(new CustomEvent("renderer:elements_created"));
3908
+ });
3909
+ this.camera = new CameraManager(this.map);
3878
3910
  this.locale = locale;
3879
3911
  this.pixelRatio = pixelRatio;
3880
3912
  this.onMapReady = onMapReady;
@@ -3885,7 +3917,13 @@ var IndoorMap = class {
3885
3917
  }
3886
3918
  set dataClient(value) {
3887
3919
  this.#dataClient = value;
3888
- if (this.rendererManager) this.rendererManager.dataClient = this.#dataClient;
3920
+ this.#dataClient.filterByType("venue").then((venues) => {
3921
+ const venueCenters = (0, import_center3.default)(featureCollection(venues));
3922
+ const [x, y] = venueCenters.geometry.coordinates;
3923
+ const center2 = new import_maptalks8.Coordinate(x, y);
3924
+ this.camera.setView({ center: center2, pitch: 60, zoom: 19 });
3925
+ });
3926
+ this.rendererManager.dataClient = this.#dataClient;
3889
3927
  }
3890
3928
  /**
3891
3929
  * Events
@@ -3914,30 +3952,6 @@ var IndoorMap = class {
3914
3952
  /**
3915
3953
  * Getters & Setters
3916
3954
  */
3917
- set defaultBearing(value) {
3918
- this.cameraManager.defaultBearing = value;
3919
- }
3920
- set defaultPitch(value) {
3921
- this.cameraManager.defaultPitch = value;
3922
- }
3923
- set defaultCenter(value) {
3924
- this.cameraManager.defaultCenter = value;
3925
- }
3926
- set defaultZoom(value) {
3927
- this.cameraManager.defaultZoom = value;
3928
- }
3929
- get defaultBearing() {
3930
- return this.cameraManager.defaultBearing;
3931
- }
3932
- get defaultPitch() {
3933
- return this.cameraManager.defaultPitch;
3934
- }
3935
- get defaultCenter() {
3936
- return this.cameraManager.defaultCenter;
3937
- }
3938
- get defaultZoom() {
3939
- return this.cameraManager.defaultZoom;
3940
- }
3941
3955
  get elementsLoaded() {
3942
3956
  return this.#elementsLoaded;
3943
3957
  }
@@ -4369,7 +4383,7 @@ var IndoorMap = class {
4369
4383
  const {
4370
4384
  geometry: { coordinates }
4371
4385
  } = (0, import_center3.default)(feature2);
4372
- this.cameraManager.flyToAndZoomIn(coordinates, { pitch: 45 });
4386
+ this.camera.flyToAndZoomIn(coordinates, { pitch: 45 });
4373
4387
  });
4374
4388
  object3ds.push(object);
4375
4389
  this.#objects.push(object);
@@ -4520,7 +4534,7 @@ var IndoorMap = class {
4520
4534
  return result;
4521
4535
  };
4522
4536
  flyTo = (center2, options) => {
4523
- this.cameraManager.flyTo(center2, options);
4537
+ this.camera.flyTo(center2, options);
4524
4538
  };
4525
4539
  getLineStringBearing = (feature2) => {
4526
4540
  const { geometry } = feature2;
@@ -5072,7 +5086,7 @@ var IndoorMap = class {
5072
5086
  this.threeLayer.redraw();
5073
5087
  }
5074
5088
  if (this.threeLayer) {
5075
- const objectOpacity = import_lodash6.default.clamp(38 - 2 * this.cameraManager.getZoom(), 0, 1);
5089
+ const objectOpacity = import_lodash6.default.clamp(38 - 2 * this.camera.getZoom(), 0, 1);
5076
5090
  this.#objects.forEach((object) => {
5077
5091
  object.getObject3d().traverse((child) => {
5078
5092
  if (child.isMesh) child.material.opacity = objectOpacity;
@@ -5083,7 +5097,7 @@ var IndoorMap = class {
5083
5097
  if (this.#billboardObjects) {
5084
5098
  this.#billboardObjects.forEach((object) => {
5085
5099
  const objectScale = import_lodash6.default.clamp(
5086
- 20 - 1 * this.cameraManager.getZoom(),
5100
+ 20 - 1 * this.camera.getZoom(),
5087
5101
  1,
5088
5102
  1.05
5089
5103
  );