venue-js 1.2.0-next.1 → 1.2.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
@@ -593,11 +593,13 @@ import {
593
593
  ui as ui3,
594
594
  Map as Map2,
595
595
  TileLayer,
596
- Extent,
597
596
  LineString as LineString3,
598
597
  Marker as Marker2,
599
- Coordinate as Coordinate4
598
+ Coordinate as Coordinate4,
599
+ GroupGLLayer,
600
+ GLTFLayer
600
601
  } from "maptalks-gl";
602
+ import "@maptalks/transcoders.draco";
601
603
  import TWEEN2 from "@tweenjs/tween.js";
602
604
  import _6 from "lodash";
603
605
 
@@ -679,133 +681,8 @@ function isNumber(num) {
679
681
  // src/IndoorMap/IndoorMap.ts
680
682
  import turfDistance from "@turf/distance";
681
683
  import turfCenter3 from "@turf/center";
682
-
683
- // ../../node_modules/@turf/meta/dist/esm/index.js
684
- function coordEach(geojson, callback, excludeWrapCoord) {
685
- if (geojson === null) return;
686
- var j, k, l, geometry, stopG, coords, geometryMaybeCollection, wrapShrink = 0, coordIndex = 0, isGeometryCollection, type = geojson.type, isFeatureCollection = type === "FeatureCollection", isFeature = type === "Feature", stop = isFeatureCollection ? geojson.features.length : 1;
687
- for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
688
- geometryMaybeCollection = isFeatureCollection ? geojson.features[featureIndex].geometry : isFeature ? geojson.geometry : geojson;
689
- isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;
690
- stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
691
- for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
692
- var multiFeatureIndex = 0;
693
- var geometryIndex = 0;
694
- geometry = isGeometryCollection ? geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;
695
- if (geometry === null) continue;
696
- coords = geometry.coordinates;
697
- var geomType = geometry.type;
698
- wrapShrink = excludeWrapCoord && (geomType === "Polygon" || geomType === "MultiPolygon") ? 1 : 0;
699
- switch (geomType) {
700
- case null:
701
- break;
702
- case "Point":
703
- if (callback(
704
- coords,
705
- coordIndex,
706
- featureIndex,
707
- multiFeatureIndex,
708
- geometryIndex
709
- ) === false)
710
- return false;
711
- coordIndex++;
712
- multiFeatureIndex++;
713
- break;
714
- case "LineString":
715
- case "MultiPoint":
716
- for (j = 0; j < coords.length; j++) {
717
- if (callback(
718
- coords[j],
719
- coordIndex,
720
- featureIndex,
721
- multiFeatureIndex,
722
- geometryIndex
723
- ) === false)
724
- return false;
725
- coordIndex++;
726
- if (geomType === "MultiPoint") multiFeatureIndex++;
727
- }
728
- if (geomType === "LineString") multiFeatureIndex++;
729
- break;
730
- case "Polygon":
731
- case "MultiLineString":
732
- for (j = 0; j < coords.length; j++) {
733
- for (k = 0; k < coords[j].length - wrapShrink; k++) {
734
- if (callback(
735
- coords[j][k],
736
- coordIndex,
737
- featureIndex,
738
- multiFeatureIndex,
739
- geometryIndex
740
- ) === false)
741
- return false;
742
- coordIndex++;
743
- }
744
- if (geomType === "MultiLineString") multiFeatureIndex++;
745
- if (geomType === "Polygon") geometryIndex++;
746
- }
747
- if (geomType === "Polygon") multiFeatureIndex++;
748
- break;
749
- case "MultiPolygon":
750
- for (j = 0; j < coords.length; j++) {
751
- geometryIndex = 0;
752
- for (k = 0; k < coords[j].length; k++) {
753
- for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
754
- if (callback(
755
- coords[j][k][l],
756
- coordIndex,
757
- featureIndex,
758
- multiFeatureIndex,
759
- geometryIndex
760
- ) === false)
761
- return false;
762
- coordIndex++;
763
- }
764
- geometryIndex++;
765
- }
766
- multiFeatureIndex++;
767
- }
768
- break;
769
- case "GeometryCollection":
770
- for (j = 0; j < geometry.geometries.length; j++)
771
- if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false)
772
- return false;
773
- break;
774
- default:
775
- throw new Error("Unknown Geometry Type");
776
- }
777
- }
778
- }
779
- }
780
-
781
- // ../../node_modules/@turf/bbox/dist/esm/index.js
782
- function bbox(geojson, options = {}) {
783
- if (geojson.bbox != null && true !== options.recompute) {
784
- return geojson.bbox;
785
- }
786
- const result = [Infinity, Infinity, -Infinity, -Infinity];
787
- coordEach(geojson, (coord) => {
788
- if (result[0] > coord[0]) {
789
- result[0] = coord[0];
790
- }
791
- if (result[1] > coord[1]) {
792
- result[1] = coord[1];
793
- }
794
- if (result[2] < coord[0]) {
795
- result[2] = coord[0];
796
- }
797
- if (result[3] < coord[1]) {
798
- result[3] = coord[1];
799
- }
800
- });
801
- return result;
802
- }
803
- var index_default = bbox;
804
-
805
- // src/IndoorMap/IndoorMap.ts
806
- import scale from "@turf/transform-scale";
807
- import bboxPolygon from "@turf/bbox-polygon";
808
684
  import { PerspectiveCamera } from "three";
685
+ import { ThreeLayer as ThreeLayer3 } from "maptalks.three";
809
686
 
810
687
  // src/IndoorMap/constants.ts
811
688
  var defaultLayerOption = { enableAltitude: true };
@@ -3010,8 +2887,133 @@ var createHighlighExtrudeObjectController = (obj, { color }) => {
3010
2887
  };
3011
2888
 
3012
2889
  // src/IndoorMap/camera/CameraManager.ts
3013
- var ZOOM_OUT_LEVEL = 21;
3014
- var ZOOM_IN_LEVEL = 24;
2890
+ import { Extent } from "maptalks";
2891
+
2892
+ // ../../node_modules/@turf/meta/dist/esm/index.js
2893
+ function coordEach(geojson, callback, excludeWrapCoord) {
2894
+ if (geojson === null) return;
2895
+ var j, k, l, geometry, stopG, coords, geometryMaybeCollection, wrapShrink = 0, coordIndex = 0, isGeometryCollection, type = geojson.type, isFeatureCollection = type === "FeatureCollection", isFeature = type === "Feature", stop = isFeatureCollection ? geojson.features.length : 1;
2896
+ for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
2897
+ geometryMaybeCollection = isFeatureCollection ? geojson.features[featureIndex].geometry : isFeature ? geojson.geometry : geojson;
2898
+ isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;
2899
+ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
2900
+ for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
2901
+ var multiFeatureIndex = 0;
2902
+ var geometryIndex = 0;
2903
+ geometry = isGeometryCollection ? geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;
2904
+ if (geometry === null) continue;
2905
+ coords = geometry.coordinates;
2906
+ var geomType = geometry.type;
2907
+ wrapShrink = excludeWrapCoord && (geomType === "Polygon" || geomType === "MultiPolygon") ? 1 : 0;
2908
+ switch (geomType) {
2909
+ case null:
2910
+ break;
2911
+ case "Point":
2912
+ if (callback(
2913
+ coords,
2914
+ coordIndex,
2915
+ featureIndex,
2916
+ multiFeatureIndex,
2917
+ geometryIndex
2918
+ ) === false)
2919
+ return false;
2920
+ coordIndex++;
2921
+ multiFeatureIndex++;
2922
+ break;
2923
+ case "LineString":
2924
+ case "MultiPoint":
2925
+ for (j = 0; j < coords.length; j++) {
2926
+ if (callback(
2927
+ coords[j],
2928
+ coordIndex,
2929
+ featureIndex,
2930
+ multiFeatureIndex,
2931
+ geometryIndex
2932
+ ) === false)
2933
+ return false;
2934
+ coordIndex++;
2935
+ if (geomType === "MultiPoint") multiFeatureIndex++;
2936
+ }
2937
+ if (geomType === "LineString") multiFeatureIndex++;
2938
+ break;
2939
+ case "Polygon":
2940
+ case "MultiLineString":
2941
+ for (j = 0; j < coords.length; j++) {
2942
+ for (k = 0; k < coords[j].length - wrapShrink; k++) {
2943
+ if (callback(
2944
+ coords[j][k],
2945
+ coordIndex,
2946
+ featureIndex,
2947
+ multiFeatureIndex,
2948
+ geometryIndex
2949
+ ) === false)
2950
+ return false;
2951
+ coordIndex++;
2952
+ }
2953
+ if (geomType === "MultiLineString") multiFeatureIndex++;
2954
+ if (geomType === "Polygon") geometryIndex++;
2955
+ }
2956
+ if (geomType === "Polygon") multiFeatureIndex++;
2957
+ break;
2958
+ case "MultiPolygon":
2959
+ for (j = 0; j < coords.length; j++) {
2960
+ geometryIndex = 0;
2961
+ for (k = 0; k < coords[j].length; k++) {
2962
+ for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
2963
+ if (callback(
2964
+ coords[j][k][l],
2965
+ coordIndex,
2966
+ featureIndex,
2967
+ multiFeatureIndex,
2968
+ geometryIndex
2969
+ ) === false)
2970
+ return false;
2971
+ coordIndex++;
2972
+ }
2973
+ geometryIndex++;
2974
+ }
2975
+ multiFeatureIndex++;
2976
+ }
2977
+ break;
2978
+ case "GeometryCollection":
2979
+ for (j = 0; j < geometry.geometries.length; j++)
2980
+ if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false)
2981
+ return false;
2982
+ break;
2983
+ default:
2984
+ throw new Error("Unknown Geometry Type");
2985
+ }
2986
+ }
2987
+ }
2988
+ }
2989
+
2990
+ // ../../node_modules/@turf/bbox/dist/esm/index.js
2991
+ function bbox(geojson, options = {}) {
2992
+ if (geojson.bbox != null && true !== options.recompute) {
2993
+ return geojson.bbox;
2994
+ }
2995
+ const result = [Infinity, Infinity, -Infinity, -Infinity];
2996
+ coordEach(geojson, (coord) => {
2997
+ if (result[0] > coord[0]) {
2998
+ result[0] = coord[0];
2999
+ }
3000
+ if (result[1] > coord[1]) {
3001
+ result[1] = coord[1];
3002
+ }
3003
+ if (result[2] < coord[0]) {
3004
+ result[2] = coord[0];
3005
+ }
3006
+ if (result[3] < coord[1]) {
3007
+ result[3] = coord[1];
3008
+ }
3009
+ });
3010
+ return result;
3011
+ }
3012
+ var index_default = bbox;
3013
+
3014
+ // src/IndoorMap/camera/CameraManager.ts
3015
+ import scale from "@turf/transform-scale";
3016
+ import bboxPolygon from "@turf/bbox-polygon";
3015
3017
  var CameraManager = class {
3016
3018
  map;
3017
3019
  constructor(map, options) {
@@ -3020,80 +3022,65 @@ var CameraManager = class {
3020
3022
  this.setView(options?.defaultView);
3021
3023
  }
3022
3024
  }
3023
- /** Private method */
3024
- #animateflyTo(viewOptions = {}, options = {}, callbackOption = () => {
3025
- }) {
3026
- const { start, end } = {
3027
- start: (frame) => {
3028
- },
3029
- end: (frame) => {
3030
- },
3031
- ...callbackOption
3032
- };
3033
- this.map.flyTo(viewOptions, options, (frame) => {
3034
- if (frame.state.playState === "running" && frame.state.progress === 0)
3035
- start(frame);
3036
- if (frame.state.playState === "finished") end(frame);
3037
- });
3038
- }
3039
3025
  /** Public methods */
3040
3026
  getView = () => {
3041
3027
  return this.map.getView();
3042
3028
  };
3043
- getZoom = () => {
3044
- return this.map.getView().zoom;
3045
- };
3046
3029
  setView = (value) => {
3047
3030
  this.map.setView(value);
3048
3031
  };
3049
- flyTo = (center2, options = {}) => {
3050
- const currentView = this.getView();
3051
- const {
3052
- zoom = ZOOM_OUT_LEVEL,
3053
- pitch = 60,
3054
- duration = 600,
3055
- easing = "out",
3056
- bearing = currentView.bearing
3057
- } = options;
3058
- this.#animateflyTo(
3059
- {
3060
- center: center2,
3061
- zoom,
3062
- pitch,
3063
- bearing
3064
- },
3065
- { duration, easing }
3066
- );
3032
+ animateTo = (view, options = {}, step) => {
3033
+ this.map.animateTo(view, options, step);
3067
3034
  };
3068
- flyToAndZoomIn = (centerPoint, options = {}) => {
3069
- const {
3070
- zoom = ZOOM_IN_LEVEL,
3071
- pitch = 60,
3072
- duration = 600,
3073
- easing = "out"
3074
- } = options;
3075
- this.#animateflyTo(
3076
- {
3077
- center: centerPoint,
3078
- zoom,
3079
- pitch
3080
- },
3081
- { duration, easing }
3035
+ setMaxExtent(extent) {
3036
+ return this.map.setMaxExtent(extent);
3037
+ }
3038
+ getFeatureExtent = (feature2, scaleFactor = 1) => {
3039
+ const [minX, minY, maxX, maxY] = index_default(
3040
+ scale(bboxPolygon(index_default(feature2)), scaleFactor)
3082
3041
  );
3042
+ return new Extent(minX, minY, maxX, maxY);
3043
+ };
3044
+ getExtentZoom = (extent, options = {
3045
+ isFraction: false,
3046
+ padding: {
3047
+ paddingLeft: 0,
3048
+ paddingRight: 0,
3049
+ paddingTop: 0,
3050
+ paddingBottom: 0
3051
+ }
3052
+ }) => {
3053
+ const { isFraction = false, padding } = options;
3054
+ return this.map.getFitZoom(extent, isFraction, padding);
3083
3055
  };
3056
+ set maxZoom(value) {
3057
+ this.map.setMaxZoom(value);
3058
+ const spatialReference = {
3059
+ projection: "EPSG:3857",
3060
+ resolutions: (function() {
3061
+ const resolutions = [];
3062
+ const d = 2 * 6378137 * Math.PI;
3063
+ for (let i = 0; i < value; i++) {
3064
+ resolutions[i] = d / (256 * Math.pow(2, i));
3065
+ }
3066
+ return resolutions;
3067
+ })()
3068
+ };
3069
+ this.map.setSpatialReference(spatialReference);
3070
+ }
3071
+ set minZoom(value) {
3072
+ this.map.setMinZoom(value);
3073
+ }
3084
3074
  };
3085
3075
 
3086
3076
  // src/IndoorMap/renderer/RendererManager.ts
3087
3077
  import _min from "lodash/min";
3088
3078
  import { center as turfCenter2 } from "@turf/center";
3089
- import { ThreeLayer as ThreeLayer3 } from "maptalks.three";
3090
3079
  import * as THREE3 from "three";
3091
3080
 
3092
3081
  // src/IndoorMap/renderer/3d/Element3DRenderer.ts
3093
- import * as maptalks4 from "maptalks";
3082
+ import * as maptalks4 from "maptalks-gl";
3094
3083
  import * as THREE2 from "three";
3095
- import { GLTFLoader as GLTFLoader2 } from "three/examples/jsm/loaders/GLTFLoader";
3096
- import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
3097
3084
  import turfBuffer2 from "@turf/buffer";
3098
3085
 
3099
3086
  // src/IndoorMap/renderer/3d/element3DRendererOptions.ts
@@ -3338,21 +3325,22 @@ var getGeometryOption = (feature2, options) => {
3338
3325
  var Element3DRenderer = class extends EventTarget {
3339
3326
  options;
3340
3327
  map;
3328
+ gltfLayer;
3341
3329
  threeLayer;
3342
- dracoLoader;
3330
+ // private dracoLoader: DRACOLoader
3343
3331
  lineMaterial;
3344
3332
  materialByColorMap;
3345
3333
  markerRenderer;
3346
3334
  // Renderer is Ready
3347
3335
  isReady = false;
3348
- constructor(map, options, layer) {
3336
+ constructor(map, options) {
3349
3337
  super();
3350
3338
  this.options = options;
3351
3339
  this.map = map;
3352
- this.dracoLoader = new DRACOLoader();
3353
- this.dracoLoader.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.7/");
3340
+ const groupLayer = this.map.getLayer("group");
3341
+ this.threeLayer = groupLayer.getLayer("three");
3342
+ this.gltfLayer = groupLayer.getLayer("gltf");
3354
3343
  this.lineMaterial = new THREE2.LineBasicMaterial({ color: "#000" });
3355
- this.threeLayer = layer;
3356
3344
  this.render();
3357
3345
  }
3358
3346
  animation() {
@@ -3382,41 +3370,45 @@ var Element3DRenderer = class extends EventTarget {
3382
3370
  } = getGeometryOption(feature2, this.options);
3383
3371
  const _this = this;
3384
3372
  const createPolygon = (geometry, feature3) => {
3385
- const [outerRing, ...innerRings] = geometry.coordinates;
3386
- const offsetFeature = offset !== 0 ? turfBuffer2(geometry, offset, { units: "meters" }) : feature3;
3387
- const color = feature3.properties.style.polygonFill ?? colorOptions ?? "#ffffff";
3388
- if (color === "transparent") return;
3389
- const material = this.getOrCreateMaterialByColor(color);
3390
- const altitude = feature3.properties.ordinal * HEIGHT_METER;
3391
- const height = feature3.properties.height ?? heightOptions ?? HEIGHT_METER;
3392
- const bottomHeight = feature3.properties.bottomHeight ?? bottomHeightOptions ?? 0;
3393
- const extrudedPolygon = this.threeLayer.toExtrudePolygon(
3394
- offsetFeature,
3395
- { asynchronous: true, ...options, height, bottomHeight, altitude },
3396
- material
3397
- );
3398
- extrudedPolygon.on("click", (e) => {
3399
- console.log(e.target.options.polygon.id);
3400
- });
3401
- const topLineStrings = [
3402
- new maptalks4.LineString(outerRing),
3403
- ...innerRings.map((innerRing) => new maptalks4.LineString(innerRing))
3404
- ];
3405
- const topLines = this.threeLayer.toLines(
3406
- topLineStrings,
3407
- { altitude, bottomHeight: bottomHeight + height + 1e-3, interactive: false },
3408
- this.lineMaterial
3409
- );
3410
- const bottomLineStrings = [
3411
- new maptalks4.LineString(outerRing),
3412
- ...innerRings.map((innerRing) => new maptalks4.LineString(innerRing))
3413
- ];
3414
- const bottomLines = this.threeLayer.toLines(
3415
- bottomLineStrings,
3416
- { altitude, bottomHeight, interactive: false },
3417
- this.lineMaterial
3418
- );
3419
- return [extrudedPolygon, topLines, bottomLines];
3373
+ try {
3374
+ const [outerRing, ...innerRings] = geometry.coordinates;
3375
+ const offsetFeature = offset !== 0 ? turfBuffer2(geometry, offset, { units: "meters" }) : feature3;
3376
+ const color = feature3.properties.style.polygonFill ?? colorOptions ?? "#ffffff";
3377
+ if (color === "transparent") return;
3378
+ const material = this.getOrCreateMaterialByColor(color);
3379
+ const altitude = feature3.properties.ordinal * HEIGHT_METER;
3380
+ const height = feature3.properties.height ?? heightOptions ?? HEIGHT_METER;
3381
+ const bottomHeight = feature3.properties.bottomHeight ?? bottomHeightOptions ?? 0;
3382
+ const extrudedPolygon = this.threeLayer.toExtrudePolygon(
3383
+ offsetFeature,
3384
+ { asynchronous: true, ...options, height, bottomHeight, altitude },
3385
+ material
3386
+ );
3387
+ extrudedPolygon.on("click", (e) => {
3388
+ console.log(e.target.options.polygon.id);
3389
+ });
3390
+ const topLineStrings = [
3391
+ new maptalks4.LineString(outerRing),
3392
+ ...innerRings.map((innerRing) => new maptalks4.LineString(innerRing))
3393
+ ];
3394
+ const topLines = this.threeLayer.toLines(
3395
+ topLineStrings,
3396
+ { altitude, bottomHeight: bottomHeight + height + 1e-3, interactive: false },
3397
+ this.lineMaterial
3398
+ );
3399
+ const bottomLineStrings = [
3400
+ new maptalks4.LineString(outerRing),
3401
+ ...innerRings.map((innerRing) => new maptalks4.LineString(innerRing))
3402
+ ];
3403
+ const bottomLines = this.threeLayer.toLines(
3404
+ bottomLineStrings,
3405
+ { altitude, bottomHeight, interactive: false },
3406
+ this.lineMaterial
3407
+ );
3408
+ return [extrudedPolygon, topLines, bottomLines];
3409
+ } catch (err) {
3410
+ throw new Error(`Cannot create polygon, ${err.message}`);
3411
+ }
3420
3412
  };
3421
3413
  try {
3422
3414
  switch (feature2.geometry.type) {
@@ -3436,64 +3428,36 @@ var Element3DRenderer = class extends EventTarget {
3436
3428
  }
3437
3429
  }
3438
3430
  } catch (err) {
3439
- console.log(`error createGeometry`, { feature: feature2, options });
3431
+ console.log(`error createGeometry`, err, { feature: feature2, options });
3440
3432
  }
3441
3433
  };
3442
3434
  async createEscalator(f, coordinate, options) {
3435
+ const model = {
3436
+ url: "https://cdn.venue.in.th/static/glb/escalator.glb",
3437
+ size: 4.4
3438
+ };
3443
3439
  const { direction: dir, angle } = options;
3444
- const model = await this.loadModel3d({
3445
- url: "https://dashboard.situm.com/uploads/3dmodels/demoaccount/new_escalator.glb",
3446
- properties: {
3447
- rotation: {
3448
- x: 0.5 * Math.PI,
3449
- // Rotate the model up (new_escalator.glb)
3450
- y: 0,
3451
- z: 0
3452
- },
3453
- position: { x: 0, y: 0, z: 0 },
3454
- scale: 0.01
3440
+ const rotationZ = dir === "up" ? 180 + angle : angle;
3441
+ var escalatorMarker = new maptalks4.GLTFMarker(coordinate, {
3442
+ symbol: {
3443
+ url: model.url,
3444
+ rotationZ,
3445
+ translationX: dir === "up" ? 0 : model.size * Math.cos(Math.PI * rotationZ / 180),
3446
+ translationY: dir === "up" ? 0 : model.size * Math.sin(Math.PI * rotationZ / 180),
3447
+ translationZ: dir === "up" ? -0.05 * model.size : -0.5 * model.size
3455
3448
  }
3456
3449
  });
3457
- model.rotation.y += dir === "up" ? Math.PI + angle : angle;
3458
- const box = new THREE2.Box3().setFromObject(model);
3459
- const pivotPoint = dir === "up" ? new THREE2.Vector3(0, 0, 0) : new THREE2.Vector3(
3460
- 1 * (box.min.x + box.max.x),
3461
- 1 * (box.min.y + box.max.y),
3462
- 0.6 * box.max.z
3463
- );
3464
- const pivot = new THREE2.Group();
3465
- pivot.add(model);
3466
- model.position.sub(pivotPoint);
3467
- model.updateMatrixWorld(true);
3468
- const altitude = f.properties.ordinal * HEIGHT_METER;
3469
- const baseObjectModel = this.threeLayer.toModel(pivot, {
3470
- coordinate,
3471
- altitude
3472
- });
3473
- this.threeLayer.addMesh(baseObjectModel);
3474
- return baseObjectModel;
3450
+ escalatorMarker.addTo(this.gltfLayer);
3451
+ return escalatorMarker;
3475
3452
  }
3476
3453
  async createTree(coordinate, ordinal) {
3477
- const model = await this.loadModel3d({
3478
- url: "https://dashboard.situm.com/uploads/3dmodels/demoaccount/arbol.glb",
3479
- properties: {
3480
- rotation: {
3481
- x: 0.5 * Math.PI,
3482
- // Rotate the model up (new_escalator.glb)
3483
- y: 0,
3484
- z: 0
3485
- },
3486
- position: { x: 0, y: 0, z: 0 },
3487
- scale: 0.01
3454
+ const treeMarker = new maptalks4.GLTFMarker(coordinate, {
3455
+ symbol: {
3456
+ url: "https://dashboard.situm.com/uploads/3dmodels/demoaccount/new_escalator.glb"
3488
3457
  }
3489
3458
  });
3490
- const altitude = ordinal * HEIGHT_METER;
3491
- const baseObjectModel = this.threeLayer.toModel(model, {
3492
- coordinate,
3493
- altitude
3494
- });
3495
- this.threeLayer.addMesh(baseObjectModel);
3496
- return baseObjectModel;
3459
+ treeMarker.addTo(this.gltfLayer);
3460
+ return treeMarker;
3497
3461
  }
3498
3462
  createElement(f) {
3499
3463
  switch (f.feature_type) {
@@ -3516,21 +3480,6 @@ var Element3DRenderer = class extends EventTarget {
3516
3480
  }
3517
3481
  });
3518
3482
  }
3519
- async loadModel3d(model3d) {
3520
- const loader = new GLTFLoader2();
3521
- loader.setDRACOLoader(this.dracoLoader);
3522
- const { url, properties: modelProperties } = model3d;
3523
- const gltf = await loader.loadAsync(url);
3524
- const model = gltf.scene;
3525
- model.rotation.x = modelProperties.rotation.x;
3526
- model.rotation.y = modelProperties.rotation.y;
3527
- model.position.x = modelProperties.position.x;
3528
- model.position.y = modelProperties.position.y;
3529
- model.position.z = modelProperties.position.z;
3530
- const scale2 = modelProperties.scale;
3531
- model.scale.set(scale2, scale2, scale2);
3532
- return model;
3533
- }
3534
3483
  createMarker = (coordinates, ordinal, text) => {
3535
3484
  const options = {
3536
3485
  // scale: 0.05,
@@ -3896,12 +3845,10 @@ var RendererManager = class extends EventTarget {
3896
3845
  this.markersMap = /* @__PURE__ */ new Map();
3897
3846
  this.markersByOrdinal = /* @__PURE__ */ new Map();
3898
3847
  this.#dataClient = dataClient;
3848
+ const _this = this;
3899
3849
  if (options.type === "3D") {
3900
- const threeLayer = new ThreeLayer3("elements", {
3901
- forceRenderOnMoving: true,
3902
- forceRenderOnRotating: true
3903
- });
3904
- const _this = this;
3850
+ const groupLayer = this.map.getLayer("group");
3851
+ const threeLayer = groupLayer.getLayer("three");
3905
3852
  threeLayer.prepareToDraw = function(gl, scene, camera) {
3906
3853
  const ambientLight = new THREE3.AmbientLight(16777215, 0.3);
3907
3854
  scene.add(ambientLight);
@@ -3911,14 +3858,13 @@ var RendererManager = class extends EventTarget {
3911
3858
  scene.add(dllight);
3912
3859
  const hemi = new THREE3.HemisphereLight(16777215, 4473924, 0.4);
3913
3860
  scene.add(hemi);
3914
- _this.elementRenderer = new Element3DRenderer(map, options.elements, threeLayer);
3861
+ _this.elementRenderer = new Element3DRenderer(map, options.elements);
3915
3862
  _this.markerRenderer = new Marker3DRenderer(map, {}, threeLayer);
3916
3863
  if (typeof options.onRendererReady === "function") {
3917
3864
  options.onRendererReady();
3918
3865
  }
3919
3866
  _this.#createElements();
3920
3867
  };
3921
- threeLayer.addTo(this.map);
3922
3868
  } else {
3923
3869
  this.elementRenderer = new Element2DRenderer(map, options.elements);
3924
3870
  this.markerRenderer = new Marker2DRenderer(map);
@@ -4006,13 +3952,15 @@ var RendererManager = class extends EventTarget {
4006
3952
  }
4007
3953
  const thisOrdinal = escalator.properties.ordinal;
4008
3954
  const relationship = escalatorRelationships[0];
3955
+ if (!relationship.properties.origin?.id) throw new Error(`relationship (id=${relationship.id}) - origin not exists`);
3956
+ if (!relationship.properties.destination?.id) throw new Error(`relationship (id=${relationship.id}) - destination not exists`);
4009
3957
  const bothOpeningIds = [relationship.properties.origin.id, relationship.properties.destination.id];
4010
3958
  const bothOpenings = await Promise.all(
4011
3959
  bothOpeningIds.map((id) => this.#dataClient.findById("opening", id, { populate: true }))
4012
3960
  );
4013
3961
  const thisLevelOpening = bothOpenings.find((opening) => opening.properties.ordinal === thisOrdinal);
4014
3962
  const thatLevelOpening = bothOpenings.find((opening) => opening.properties.ordinal !== thisOrdinal);
4015
- const angle = angleBetweenLineStrings(thisLevelOpening.geometry.coordinates, thatLevelOpening.geometry.coordinates);
3963
+ const angle = 180 * (1 / Math.PI) * angleBetweenLineStrings(thisLevelOpening.geometry.coordinates, thatLevelOpening.geometry.coordinates);
4016
3964
  const direction = thisOrdinal < thatLevelOpening.properties.ordinal ? "up" : "down";
4017
3965
  const escalatorEntryPoint = turfCenter2(thisLevelOpening).geometry.coordinates;
4018
3966
  const element = await this.elementRenderer.createEscalator(escalator, escalatorEntryPoint, { direction, angle });
@@ -4021,7 +3969,7 @@ var RendererManager = class extends EventTarget {
4021
3969
  this.addElementsToManager(escalator.id, _elements, escalator.properties.ordinal);
4022
3970
  }
4023
3971
  } catch (err) {
4024
- console.log(`cannot create escalator`, err);
3972
+ console.log(`cannot create escalator`, err.message);
4025
3973
  }
4026
3974
  }
4027
3975
  this.changeLevelByOrdinal(this.currentOrdinals);
@@ -4082,6 +4030,7 @@ var defaultOptions = {
4082
4030
  locale: DEFAULT_LOCALE
4083
4031
  };
4084
4032
  var IndoorMap = class extends EventTarget {
4033
+ options;
4085
4034
  //TODO: refac functions; let them do only 1 thing in a function
4086
4035
  /** Note: "#" means private variables */
4087
4036
  #styler = null;
@@ -4133,14 +4082,18 @@ var IndoorMap = class extends EventTarget {
4133
4082
  };
4134
4083
  constructor(elementId, options) {
4135
4084
  super();
4085
+ const combinedOptions = _6.merge({}, defaultOptions, options);
4086
+ this.options = options;
4136
4087
  const {
4137
4088
  onMapReady,
4138
4089
  onMapLoading,
4139
4090
  pixelRatio,
4140
4091
  locale
4141
- } = _6.merge({}, defaultOptions, options);
4092
+ } = combinedOptions;
4142
4093
  this.map = new Map2(elementId, {
4143
4094
  attribution: false,
4095
+ // Temporart set, not really default view
4096
+ // Default view is set in camera manager
4144
4097
  center: INITIAL_CENTER,
4145
4098
  zoom: INITIAL_ZOOM,
4146
4099
  clickTimeThreshold: 600,
@@ -4156,8 +4109,16 @@ var IndoorMap = class extends EventTarget {
4156
4109
  }),
4157
4110
  layers: []
4158
4111
  });
4112
+ const groupLayer = new GroupGLLayer("group", [], {}).addTo(this.map);
4113
+ const threeLayer = new ThreeLayer3("three", {
4114
+ forceRenderOnMoving: true,
4115
+ forceRenderOnRotating: true
4116
+ });
4117
+ groupLayer.addLayer(threeLayer);
4118
+ const gltfLayer = new GLTFLayer("gltf");
4119
+ groupLayer.addLayer(gltfLayer);
4159
4120
  this.rendererManager = new RendererManager(this.map, options.dataClient, options.renderer);
4160
- this.camera = new CameraManager(this.map);
4121
+ this.camera = new CameraManager(this.map, options.camera);
4161
4122
  this.locale = locale;
4162
4123
  this.pixelRatio = pixelRatio;
4163
4124
  this.onMapReady = onMapReady;
@@ -4168,19 +4129,21 @@ var IndoorMap = class extends EventTarget {
4168
4129
  }
4169
4130
  set dataClient(value) {
4170
4131
  this.#dataClient = value;
4171
- this.#dataClient.filterByType("venue").then((venues) => {
4172
- const venueCenters = turfCenter3(featureCollection(venues));
4173
- const [x, y] = venueCenters.geometry.coordinates;
4174
- const center2 = new Coordinate4(x, y);
4175
- this.camera.setView({ center: center2, pitch: 60, zoom: 19 });
4176
- });
4177
- }
4178
- on(eventName, handler) {
4179
- this.map.on(eventName, handler);
4132
+ if (!this.options.camera.defaultView.center) {
4133
+ this.#dataClient.filterByType("venue").then((venues) => {
4134
+ const venueCenters = turfCenter3(featureCollection(venues));
4135
+ const [x, y] = venueCenters.geometry.coordinates;
4136
+ const center2 = new Coordinate4(x, y);
4137
+ this.camera.setView({ center: center2, pitch: 60, zoom: 19 });
4138
+ });
4139
+ }
4180
4140
  }
4181
4141
  /**
4182
4142
  * Events
4183
4143
  */
4144
+ on(eventName, handler) {
4145
+ this.map.on(eventName, handler);
4146
+ }
4184
4147
  handleMapClick = ({ coordinate }) => {
4185
4148
  const { x, y } = coordinate;
4186
4149
  console.log(
@@ -4236,40 +4199,12 @@ var IndoorMap = class extends EventTarget {
4236
4199
  this.map.off("moveend", this.#findAndSetVenueInView);
4237
4200
  }
4238
4201
  }
4239
- get ordinals() {
4240
- return this.#ordinals || [];
4241
- }
4242
- set ordinals(value) {
4243
- if (!Array.isArray(value)) throw new Error("ordinals must be Array");
4244
- this.#ordinals = value;
4245
- }
4246
4202
  set billboards(value) {
4247
4203
  this.#billboards = value;
4248
4204
  }
4249
- set mapConfig(value) {
4250
- this.#mapConfig = value;
4251
- }
4252
4205
  set mapDecorations(value) {
4253
4206
  this.#mapDecorations = value;
4254
4207
  }
4255
- set maxZoom(value) {
4256
- this.map.setMaxZoom(value);
4257
- const spatialReference = {
4258
- projection: "EPSG:3857",
4259
- resolutions: (function() {
4260
- const resolutions = [];
4261
- const d = 2 * 6378137 * Math.PI;
4262
- for (let i = 0; i < value; i++) {
4263
- resolutions[i] = d / (256 * Math.pow(2, i));
4264
- }
4265
- return resolutions;
4266
- })()
4267
- };
4268
- this.map.setSpatialReference(spatialReference);
4269
- }
4270
- set minZoom(value) {
4271
- this.map.setMinZoom(value);
4272
- }
4273
4208
  set groundLabels(value) {
4274
4209
  this.#groundLabels = value;
4275
4210
  }
@@ -4305,9 +4240,6 @@ var IndoorMap = class extends EventTarget {
4305
4240
  this.#onClickElement(e);
4306
4241
  this.#isClicked = false;
4307
4242
  };
4308
- setCenter(center2, padding) {
4309
- this.map.setCenter(center2, padding);
4310
- }
4311
4243
  async #legacy_createElements() {
4312
4244
  const {
4313
4245
  // 2D
@@ -4529,7 +4461,7 @@ var IndoorMap = class extends EventTarget {
4529
4461
  const {
4530
4462
  geometry: { coordinates }
4531
4463
  } = turfCenter3(feature2);
4532
- this.camera.flyToAndZoomIn(coordinates, { pitch: 45 });
4464
+ this.camera.animateTo({ center: coordinates, pitch: 45 });
4533
4465
  });
4534
4466
  object3ds.push(object);
4535
4467
  this.#objects.push(object);
@@ -4612,27 +4544,6 @@ var IndoorMap = class extends EventTarget {
4612
4544
  changeLevelByOrdinal(ordinal) {
4613
4545
  this.rendererManager.changeLevelByOrdinal(ordinal);
4614
4546
  }
4615
- getFeatureExtent = (feature2, scaleFactor = 1) => {
4616
- const [minX, minY, maxX, maxY] = index_default(
4617
- scale(bboxPolygon(index_default(feature2)), scaleFactor)
4618
- );
4619
- return new Extent(minX, minY, maxX, maxY);
4620
- };
4621
- getExtentCenter = (extent) => {
4622
- return extent.getCenter();
4623
- };
4624
- getExtentZoom = (extent, options = {
4625
- isFraction: false,
4626
- padding: {
4627
- paddingLeft: 0,
4628
- paddingRight: 0,
4629
- paddingTop: 0,
4630
- paddingBottom: 0
4631
- }
4632
- }) => {
4633
- const { isFraction = false, padding } = options;
4634
- return this.map.getFitZoom(extent, isFraction, padding);
4635
- };
4636
4547
  findVenueInView = () => {
4637
4548
  const mapCenter = this.map.getCenter();
4638
4549
  const result = this.#venues.reduce((closest, venue) => {
@@ -4645,9 +4556,6 @@ var IndoorMap = class extends EventTarget {
4645
4556
  }, null);
4646
4557
  return result;
4647
4558
  };
4648
- flyTo = (center2, options) => {
4649
- this.camera.flyTo(center2, options);
4650
- };
4651
4559
  getLineStringBearing = (feature2) => {
4652
4560
  const { geometry } = feature2;
4653
4561
  const path = new LineString3(geometry.coordinates);
@@ -5163,33 +5071,6 @@ var IndoorMap = class extends EventTarget {
5163
5071
  /**
5164
5072
  * render (frame)
5165
5073
  */
5166
- getTargetViewCenter = (targetView, options = { offset: { top: 0, left: 0, right: 0, bottom: 0 } }) => {
5167
- const map = this.map;
5168
- const { offset } = options;
5169
- const { top = 0, left = 0, right = 0, bottom = 0 } = offset;
5170
- const originalState = {
5171
- bearing: map.getBearing(),
5172
- center: map.getCenter(),
5173
- pitch: map.getPitch(),
5174
- zoom: map.getZoom()
5175
- };
5176
- const finalView = {
5177
- bearing: _6.isNil(targetView.bearing) ? map.getBearing() : targetView.bearing,
5178
- center: _6.isNil(targetView.center) ? map.getCenter() : targetView.center,
5179
- pitch: _6.isNil(targetView.pitch) ? map.getPitch() : targetView.pitch,
5180
- zoom: _6.isNil(targetView.zoom) ? map.getZoom() : targetView.zoom
5181
- };
5182
- map.setView(finalView);
5183
- const projectedTargetCenter = map.coordinateToContainerPoint(finalView.center).add(right / 2 - left / 2, bottom / 2 - top / 2);
5184
- const adjustedTargetCenter = map.containerPointToCoordinate(
5185
- projectedTargetCenter
5186
- );
5187
- map.setView(originalState);
5188
- return adjustedTargetCenter;
5189
- };
5190
- setMaxExtent(extent) {
5191
- return this.map.setMaxExtent(extent);
5192
- }
5193
5074
  render() {
5194
5075
  const view = this.map.getView();
5195
5076
  const currBearing = view.bearing;
@@ -5198,7 +5079,8 @@ var IndoorMap = class extends EventTarget {
5198
5079
  this.threeLayer.redraw();
5199
5080
  }
5200
5081
  if (this.threeLayer) {
5201
- const objectOpacity = _6.clamp(38 - 2 * this.camera.getZoom(), 0, 1);
5082
+ const currentView = this.camera.getView();
5083
+ const objectOpacity = _6.clamp(38 - 2 * currentView.zoom, 0, 1);
5202
5084
  this.#objects.forEach((object) => {
5203
5085
  object.getObject3d().traverse((child) => {
5204
5086
  if (child.isMesh) child.material.opacity = objectOpacity;
@@ -5209,7 +5091,7 @@ var IndoorMap = class extends EventTarget {
5209
5091
  if (this.#billboardObjects) {
5210
5092
  this.#billboardObjects.forEach((object) => {
5211
5093
  const objectScale = _6.clamp(
5212
- 20 - 1 * this.camera.getZoom(),
5094
+ 20 - 1 * currentView.zoom,
5213
5095
  1,
5214
5096
  1.05
5215
5097
  );