venue-js 1.2.0-next.2 → 1.2.0-next.4

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
@@ -595,8 +595,11 @@ import {
595
595
  TileLayer,
596
596
  LineString as LineString3,
597
597
  Marker as Marker2,
598
- Coordinate as Coordinate4
598
+ Coordinate as Coordinate4,
599
+ GroupGLLayer,
600
+ GLTFLayer
599
601
  } from "maptalks-gl";
602
+ import "@maptalks/transcoders.draco";
600
603
  import TWEEN2 from "@tweenjs/tween.js";
601
604
  import _6 from "lodash";
602
605
 
@@ -679,6 +682,7 @@ function isNumber(num) {
679
682
  import turfDistance from "@turf/distance";
680
683
  import turfCenter3 from "@turf/center";
681
684
  import { PerspectiveCamera } from "three";
685
+ import { ThreeLayer as ThreeLayer3 } from "maptalks.three";
682
686
 
683
687
  // src/IndoorMap/constants.ts
684
688
  var defaultLayerOption = { enableAltitude: true };
@@ -3023,7 +3027,9 @@ var CameraManager = class {
3023
3027
  return this.map.getView();
3024
3028
  };
3025
3029
  setView = (value) => {
3026
- this.map.setView(value);
3030
+ if (this.map) {
3031
+ this.map.setView(value);
3032
+ }
3027
3033
  };
3028
3034
  animateTo = (view, options = {}, step) => {
3029
3035
  this.map.animateTo(view, options, step);
@@ -3072,14 +3078,11 @@ var CameraManager = class {
3072
3078
  // src/IndoorMap/renderer/RendererManager.ts
3073
3079
  import _min from "lodash/min";
3074
3080
  import { center as turfCenter2 } from "@turf/center";
3075
- import { ThreeLayer as ThreeLayer3 } from "maptalks.three";
3076
3081
  import * as THREE3 from "three";
3077
3082
 
3078
3083
  // src/IndoorMap/renderer/3d/Element3DRenderer.ts
3079
- import * as maptalks4 from "maptalks";
3084
+ import * as maptalks4 from "maptalks-gl";
3080
3085
  import * as THREE2 from "three";
3081
- import { GLTFLoader as GLTFLoader2 } from "three/examples/jsm/loaders/GLTFLoader";
3082
- import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
3083
3086
  import turfBuffer2 from "@turf/buffer";
3084
3087
 
3085
3088
  // src/IndoorMap/renderer/3d/element3DRendererOptions.ts
@@ -3324,21 +3327,22 @@ var getGeometryOption = (feature2, options) => {
3324
3327
  var Element3DRenderer = class extends EventTarget {
3325
3328
  options;
3326
3329
  map;
3330
+ gltfLayer;
3327
3331
  threeLayer;
3328
- dracoLoader;
3332
+ // private dracoLoader: DRACOLoader
3329
3333
  lineMaterial;
3330
3334
  materialByColorMap;
3331
3335
  markerRenderer;
3332
3336
  // Renderer is Ready
3333
3337
  isReady = false;
3334
- constructor(map, options, layer) {
3338
+ constructor(map, options) {
3335
3339
  super();
3336
3340
  this.options = options;
3337
3341
  this.map = map;
3338
- this.dracoLoader = new DRACOLoader();
3339
- this.dracoLoader.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.7/");
3342
+ const groupLayer = this.map.getLayer("group");
3343
+ this.threeLayer = groupLayer.getLayer("three");
3344
+ this.gltfLayer = groupLayer.getLayer("gltf");
3340
3345
  this.lineMaterial = new THREE2.LineBasicMaterial({ color: "#000" });
3341
- this.threeLayer = layer;
3342
3346
  this.render();
3343
3347
  }
3344
3348
  animation() {
@@ -3374,7 +3378,7 @@ var Element3DRenderer = class extends EventTarget {
3374
3378
  const color = feature3.properties.style.polygonFill ?? colorOptions ?? "#ffffff";
3375
3379
  if (color === "transparent") return;
3376
3380
  const material = this.getOrCreateMaterialByColor(color);
3377
- const altitude = feature3.properties.ordinal * HEIGHT_METER;
3381
+ const altitude = 0;
3378
3382
  const height = feature3.properties.height ?? heightOptions ?? HEIGHT_METER;
3379
3383
  const bottomHeight = feature3.properties.bottomHeight ?? bottomHeightOptions ?? 0;
3380
3384
  const extrudedPolygon = this.threeLayer.toExtrudePolygon(
@@ -3382,9 +3386,6 @@ var Element3DRenderer = class extends EventTarget {
3382
3386
  { asynchronous: true, ...options, height, bottomHeight, altitude },
3383
3387
  material
3384
3388
  );
3385
- extrudedPolygon.on("click", (e) => {
3386
- console.log(e.target.options.polygon.id);
3387
- });
3388
3389
  const topLineStrings = [
3389
3390
  new maptalks4.LineString(outerRing),
3390
3391
  ...innerRings.map((innerRing) => new maptalks4.LineString(innerRing))
@@ -3405,7 +3406,7 @@ var Element3DRenderer = class extends EventTarget {
3405
3406
  );
3406
3407
  return [extrudedPolygon, topLines, bottomLines];
3407
3408
  } catch (err) {
3408
- throw new Error(`Cannot create polygon, ${err.message}`);
3409
+ return [];
3409
3410
  }
3410
3411
  };
3411
3412
  try {
@@ -3430,60 +3431,32 @@ var Element3DRenderer = class extends EventTarget {
3430
3431
  }
3431
3432
  };
3432
3433
  async createEscalator(f, coordinate, options) {
3434
+ const model = {
3435
+ url: "https://cdn.venue.in.th/static/glb/escalator.glb",
3436
+ size: 4.4
3437
+ };
3433
3438
  const { direction: dir, angle } = options;
3434
- const model = await this.loadModel3d({
3435
- url: "https://dashboard.situm.com/uploads/3dmodels/demoaccount/new_escalator.glb",
3436
- properties: {
3437
- rotation: {
3438
- x: 0.5 * Math.PI,
3439
- // Rotate the model up (new_escalator.glb)
3440
- y: 0,
3441
- z: 0
3442
- },
3443
- position: { x: 0, y: 0, z: 0 },
3444
- scale: 0.01
3439
+ const rotationZ = dir === "up" ? 180 + angle : angle;
3440
+ var escalatorMarker = new maptalks4.GLTFMarker(coordinate, {
3441
+ symbol: {
3442
+ url: model.url,
3443
+ rotationZ,
3444
+ translationX: dir === "up" ? 0 : model.size * Math.cos(Math.PI * rotationZ / 180),
3445
+ translationY: dir === "up" ? 0 : model.size * Math.sin(Math.PI * rotationZ / 180),
3446
+ translationZ: dir === "up" ? -0.05 * model.size : -0.5 * model.size
3445
3447
  }
3446
3448
  });
3447
- model.rotation.y += dir === "up" ? Math.PI + angle : angle;
3448
- const box = new THREE2.Box3().setFromObject(model);
3449
- const pivotPoint = dir === "up" ? new THREE2.Vector3(0, 0, 0) : new THREE2.Vector3(
3450
- 1 * (box.min.x + box.max.x),
3451
- 1 * (box.min.y + box.max.y),
3452
- 0.6 * box.max.z
3453
- );
3454
- const pivot = new THREE2.Group();
3455
- pivot.add(model);
3456
- model.position.sub(pivotPoint);
3457
- model.updateMatrixWorld(true);
3458
- const altitude = f.properties.ordinal * HEIGHT_METER;
3459
- const baseObjectModel = this.threeLayer.toModel(pivot, {
3460
- coordinate,
3461
- altitude
3462
- });
3463
- this.threeLayer.addMesh(baseObjectModel);
3464
- return baseObjectModel;
3449
+ escalatorMarker.addTo(this.gltfLayer);
3450
+ return escalatorMarker;
3465
3451
  }
3466
3452
  async createTree(coordinate, ordinal) {
3467
- const model = await this.loadModel3d({
3468
- url: "https://dashboard.situm.com/uploads/3dmodels/demoaccount/arbol.glb",
3469
- properties: {
3470
- rotation: {
3471
- x: 0.5 * Math.PI,
3472
- // Rotate the model up (new_escalator.glb)
3473
- y: 0,
3474
- z: 0
3475
- },
3476
- position: { x: 0, y: 0, z: 0 },
3477
- scale: 0.01
3453
+ const treeMarker = new maptalks4.GLTFMarker(coordinate, {
3454
+ symbol: {
3455
+ url: "https://dashboard.situm.com/uploads/3dmodels/demoaccount/new_escalator.glb"
3478
3456
  }
3479
3457
  });
3480
- const altitude = ordinal * HEIGHT_METER;
3481
- const baseObjectModel = this.threeLayer.toModel(model, {
3482
- coordinate,
3483
- altitude
3484
- });
3485
- this.threeLayer.addMesh(baseObjectModel);
3486
- return baseObjectModel;
3458
+ treeMarker.addTo(this.gltfLayer);
3459
+ return treeMarker;
3487
3460
  }
3488
3461
  createElement(f) {
3489
3462
  switch (f.feature_type) {
@@ -3506,21 +3479,6 @@ var Element3DRenderer = class extends EventTarget {
3506
3479
  }
3507
3480
  });
3508
3481
  }
3509
- async loadModel3d(model3d) {
3510
- const loader = new GLTFLoader2();
3511
- loader.setDRACOLoader(this.dracoLoader);
3512
- const { url, properties: modelProperties } = model3d;
3513
- const gltf = await loader.loadAsync(url);
3514
- const model = gltf.scene;
3515
- model.rotation.x = modelProperties.rotation.x;
3516
- model.rotation.y = modelProperties.rotation.y;
3517
- model.position.x = modelProperties.position.x;
3518
- model.position.y = modelProperties.position.y;
3519
- model.position.z = modelProperties.position.z;
3520
- const scale2 = modelProperties.scale;
3521
- model.scale.set(scale2, scale2, scale2);
3522
- return model;
3523
- }
3524
3482
  createMarker = (coordinates, ordinal, text) => {
3525
3483
  const options = {
3526
3484
  // scale: 0.05,
@@ -3886,12 +3844,10 @@ var RendererManager = class extends EventTarget {
3886
3844
  this.markersMap = /* @__PURE__ */ new Map();
3887
3845
  this.markersByOrdinal = /* @__PURE__ */ new Map();
3888
3846
  this.#dataClient = dataClient;
3847
+ const _this = this;
3889
3848
  if (options.type === "3D") {
3890
- const threeLayer = new ThreeLayer3("elements", {
3891
- forceRenderOnMoving: true,
3892
- forceRenderOnRotating: true
3893
- });
3894
- const _this = this;
3849
+ const groupLayer = this.map.getLayer("group");
3850
+ const threeLayer = groupLayer.getLayer("three");
3895
3851
  threeLayer.prepareToDraw = function(gl, scene, camera) {
3896
3852
  const ambientLight = new THREE3.AmbientLight(16777215, 0.3);
3897
3853
  scene.add(ambientLight);
@@ -3901,14 +3857,13 @@ var RendererManager = class extends EventTarget {
3901
3857
  scene.add(dllight);
3902
3858
  const hemi = new THREE3.HemisphereLight(16777215, 4473924, 0.4);
3903
3859
  scene.add(hemi);
3904
- _this.elementRenderer = new Element3DRenderer(map, options.elements, threeLayer);
3860
+ _this.elementRenderer = new Element3DRenderer(map, options.elements);
3905
3861
  _this.markerRenderer = new Marker3DRenderer(map, {}, threeLayer);
3906
3862
  if (typeof options.onRendererReady === "function") {
3907
3863
  options.onRendererReady();
3908
3864
  }
3909
3865
  _this.#createElements();
3910
3866
  };
3911
- threeLayer.addTo(this.map);
3912
3867
  } else {
3913
3868
  this.elementRenderer = new Element2DRenderer(map, options.elements);
3914
3869
  this.markerRenderer = new Marker2DRenderer(map);
@@ -4004,7 +3959,7 @@ var RendererManager = class extends EventTarget {
4004
3959
  );
4005
3960
  const thisLevelOpening = bothOpenings.find((opening) => opening.properties.ordinal === thisOrdinal);
4006
3961
  const thatLevelOpening = bothOpenings.find((opening) => opening.properties.ordinal !== thisOrdinal);
4007
- const angle = angleBetweenLineStrings(thisLevelOpening.geometry.coordinates, thatLevelOpening.geometry.coordinates);
3962
+ const angle = 180 * (1 / Math.PI) * angleBetweenLineStrings(thisLevelOpening.geometry.coordinates, thatLevelOpening.geometry.coordinates);
4008
3963
  const direction = thisOrdinal < thatLevelOpening.properties.ordinal ? "up" : "down";
4009
3964
  const escalatorEntryPoint = turfCenter2(thisLevelOpening).geometry.coordinates;
4010
3965
  const element = await this.elementRenderer.createEscalator(escalator, escalatorEntryPoint, { direction, angle });
@@ -4013,7 +3968,7 @@ var RendererManager = class extends EventTarget {
4013
3968
  this.addElementsToManager(escalator.id, _elements, escalator.properties.ordinal);
4014
3969
  }
4015
3970
  } catch (err) {
4016
- console.log(`cannot create escalator`, err.message);
3971
+ console.warn(`cannot create escalator`, err.message);
4017
3972
  }
4018
3973
  }
4019
3974
  this.changeLevelByOrdinal(this.currentOrdinals);
@@ -4074,6 +4029,7 @@ var defaultOptions = {
4074
4029
  locale: DEFAULT_LOCALE
4075
4030
  };
4076
4031
  var IndoorMap = class extends EventTarget {
4032
+ options;
4077
4033
  //TODO: refac functions; let them do only 1 thing in a function
4078
4034
  /** Note: "#" means private variables */
4079
4035
  #styler = null;
@@ -4125,14 +4081,18 @@ var IndoorMap = class extends EventTarget {
4125
4081
  };
4126
4082
  constructor(elementId, options) {
4127
4083
  super();
4084
+ const combinedOptions = _6.merge({}, defaultOptions, options);
4085
+ this.options = options;
4128
4086
  const {
4129
4087
  onMapReady,
4130
4088
  onMapLoading,
4131
4089
  pixelRatio,
4132
4090
  locale
4133
- } = _6.merge({}, defaultOptions, options);
4091
+ } = combinedOptions;
4134
4092
  this.map = new Map2(elementId, {
4135
4093
  attribution: false,
4094
+ // Temporart set, not really default view
4095
+ // Default view is set in camera manager
4136
4096
  center: INITIAL_CENTER,
4137
4097
  zoom: INITIAL_ZOOM,
4138
4098
  clickTimeThreshold: 600,
@@ -4148,6 +4108,14 @@ var IndoorMap = class extends EventTarget {
4148
4108
  }),
4149
4109
  layers: []
4150
4110
  });
4111
+ const groupLayer = new GroupGLLayer("group", [], {}).addTo(this.map);
4112
+ const threeLayer = new ThreeLayer3("three", {
4113
+ forceRenderOnMoving: true,
4114
+ forceRenderOnRotating: true
4115
+ });
4116
+ groupLayer.addLayer(threeLayer);
4117
+ const gltfLayer = new GLTFLayer("gltf");
4118
+ groupLayer.addLayer(gltfLayer);
4151
4119
  this.rendererManager = new RendererManager(this.map, options.dataClient, options.renderer);
4152
4120
  this.camera = new CameraManager(this.map, options.camera);
4153
4121
  this.locale = locale;
@@ -4160,12 +4128,14 @@ var IndoorMap = class extends EventTarget {
4160
4128
  }
4161
4129
  set dataClient(value) {
4162
4130
  this.#dataClient = value;
4163
- this.#dataClient.filterByType("venue").then((venues) => {
4164
- const venueCenters = turfCenter3(featureCollection(venues));
4165
- const [x, y] = venueCenters.geometry.coordinates;
4166
- const center2 = new Coordinate4(x, y);
4167
- this.camera.setView({ center: center2, pitch: 60, zoom: 19 });
4168
- });
4131
+ if (!this.options.camera.defaultView.center) {
4132
+ this.#dataClient.filterByType("venue").then((venues) => {
4133
+ const venueCenters = turfCenter3(featureCollection(venues));
4134
+ const [x, y] = venueCenters.geometry.coordinates;
4135
+ const center2 = new Coordinate4(x, y);
4136
+ this.camera.setView({ center: center2, pitch: 60, zoom: 19 });
4137
+ });
4138
+ }
4169
4139
  }
4170
4140
  /**
4171
4141
  * Events