mobility-toolbox-js 3.0.0-beta.15 → 3.0.0-beta.17

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/mbt.js CHANGED
@@ -44485,7 +44485,7 @@ uniform ${i3} ${s3} u_${a3};
44485
44485
  })
44486
44486
  );
44487
44487
  this.options = options;
44488
- this.children = options.children || [];
44488
+ this.set("children", options.children || []);
44489
44489
  }
44490
44490
  /** @deprecated */
44491
44491
  get children() {
@@ -44613,7 +44613,7 @@ uniform ${i3} ${s3} u_${a3};
44613
44613
  (oldValue || []).forEach((child) => {
44614
44614
  child.set("parent", void 0);
44615
44615
  });
44616
- (this.children || []).forEach((child) => {
44616
+ (this.get("children") || []).forEach((child) => {
44617
44617
  child.set("parent", this);
44618
44618
  });
44619
44619
  }
@@ -44664,13 +44664,20 @@ uniform ${i3} ${s3} u_${a3};
44664
44664
  var MobilityLayerMixin_default = MobilityLayerMixin;
44665
44665
 
44666
44666
  // src/ol/layers/MaplibreLayer.ts
44667
+ var buildStyleUrl = (url, style, apiKey, apiKeyName) => {
44668
+ return getUrlWithParams_default(`${url}/styles/${style}/style.json`, {
44669
+ [apiKeyName]: apiKey
44670
+ }).toString();
44671
+ };
44667
44672
  var MaplibreLayer = class _MaplibreLayer extends MobilityLayerMixin_default(MapLibreLayer) {
44668
44673
  get mbMap() {
44669
- console.warn("Deprecated. Use layer.maplibreMap.");
44674
+ console.warn("MaplibreLayer.mbMap is deprecated. Use layer.maplibreMap.");
44670
44675
  return this.maplibreMap;
44671
44676
  }
44672
44677
  get maplibreMap() {
44673
- console.warn("Deprecated. Use layer.mapLibreMap.");
44678
+ console.warn(
44679
+ "MaplibreLayer.maplibreMap is deprecated. Use layer.mapLibreMap."
44680
+ );
44674
44681
  return this.mapLibreMap;
44675
44682
  }
44676
44683
  // get queryRenderedFeaturesOptions(): maplibregl.QueryRenderedFeaturesOptions {
@@ -44704,7 +44711,7 @@ uniform ${i3} ${s3} u_${a3};
44704
44711
  * @param {string} [options.url="https://maps.geops.io"] The geOps Maps API url.
44705
44712
  */
44706
44713
  constructor(options) {
44707
- super({
44714
+ const newOptions = {
44708
44715
  apiKeyName: "key",
44709
44716
  style: "travic_v2",
44710
44717
  url: "https://maps.geops.io",
@@ -44712,7 +44719,16 @@ uniform ${i3} ${s3} u_${a3};
44712
44719
  mapLibreOptions: {
44713
44720
  ...options.mapLibreOptions || {}
44714
44721
  }
44715
- });
44722
+ };
44723
+ if (!newOptions.mapLibreOptions.style && newOptions.apiKey) {
44724
+ newOptions.mapLibreOptions.style = buildStyleUrl(
44725
+ newOptions.url,
44726
+ newOptions.style,
44727
+ newOptions.apiKey,
44728
+ newOptions.apiKeyName
44729
+ );
44730
+ }
44731
+ super(newOptions);
44716
44732
  }
44717
44733
  /**
44718
44734
  * Initialize the layer and listen to feature clicks.
@@ -44740,19 +44756,15 @@ uniform ${i3} ${s3} u_${a3};
44740
44756
  if (this.url.includes("style.json")) {
44741
44757
  return this.url;
44742
44758
  }
44743
- return getUrlWithParams_default(`${this.url}/styles/${this.style}/style.json`, {
44744
- [this.get("apiKeyName")]: this.get("apiKey")
44745
- }).toString();
44759
+ return buildStyleUrl(
44760
+ this.url,
44761
+ this.style,
44762
+ this.get("apiKey"),
44763
+ this.get("apiKeyName")
44764
+ );
44746
44765
  }
44747
- // eslint-disable-next-line class-methods-use-this
44748
- // createMap(options: MapOptions): Map {
44749
- // return new Map(options);
44750
- // }
44751
- // createRenderer(): MaplibreLayerRenderer {
44752
- // return new MaplibreLayerRenderer(this);
44753
- // }
44754
44766
  updateMaplibreMap() {
44755
- this.maplibreMap?.setStyle(this.getStyle(), { diff: false });
44767
+ this.mapLibreMap?.setStyle(this.getStyle(), { diff: false });
44756
44768
  }
44757
44769
  /**
44758
44770
  * Create a copy of the MaplibreLayer.
@@ -44972,12 +44984,12 @@ uniform ${i3} ${s3} u_${a3};
44972
44984
  );
44973
44985
  return;
44974
44986
  }
44975
- const { maplibreMap } = this.maplibreLayer;
44976
- if (maplibreMap) {
44977
- if (maplibreMap.loaded()) {
44987
+ const { mapLibreMap } = this.maplibreLayer;
44988
+ if (mapLibreMap) {
44989
+ if (mapLibreMap.loaded()) {
44978
44990
  this.onLoad();
44979
44991
  } else {
44980
- maplibreMap.once("load", this.onLoad);
44992
+ mapLibreMap.once("load", this.onLoad);
44981
44993
  }
44982
44994
  }
44983
44995
  this.olEventsKeys.push(
@@ -44999,8 +45011,8 @@ uniform ${i3} ${s3} u_${a3};
44999
45011
  * @override
45000
45012
  */
45001
45013
  detachFromMap() {
45002
- if (this.maplibreLayer?.maplibreMap) {
45003
- this.maplibreLayer.maplibreMap.off("load", this.onLoad);
45014
+ if (this.maplibreLayer?.mapLibreMap) {
45015
+ this.maplibreLayer.mapLibreMap.off("load", this.onLoad);
45004
45016
  this.removeLayers();
45005
45017
  this.removeSources();
45006
45018
  }
@@ -45008,43 +45020,43 @@ uniform ${i3} ${s3} u_${a3};
45008
45020
  }
45009
45021
  /** @private */
45010
45022
  addSources() {
45011
- if (!this.maplibreLayer?.maplibreMap || !this.sources) {
45023
+ if (!this.maplibreLayer?.mapLibreMap || !this.sources) {
45012
45024
  return;
45013
45025
  }
45014
- const { maplibreMap } = this.maplibreLayer;
45015
- if (maplibreMap) {
45026
+ const { mapLibreMap } = this.maplibreLayer;
45027
+ if (mapLibreMap) {
45016
45028
  Object.entries(this.sources).forEach(([id, source]) => {
45017
- if (!maplibreMap.getSource(id)) {
45018
- maplibreMap.addSource(id, source);
45029
+ if (!mapLibreMap.getSource(id)) {
45030
+ mapLibreMap.addSource(id, source);
45019
45031
  }
45020
45032
  });
45021
45033
  }
45022
45034
  }
45023
45035
  /** @private */
45024
45036
  removeSources() {
45025
- if (!this.maplibreLayer?.maplibreMap || !this.sources) {
45037
+ if (!this.maplibreLayer?.mapLibreMap || !this.sources) {
45026
45038
  return;
45027
45039
  }
45028
- const { maplibreMap } = this.maplibreLayer;
45029
- if (maplibreMap) {
45040
+ const { mapLibreMap } = this.maplibreLayer;
45041
+ if (mapLibreMap) {
45030
45042
  Object.keys(this.sources).forEach((id) => {
45031
- if (maplibreMap.getSource(id)) {
45032
- maplibreMap.removeSource(id);
45043
+ if (mapLibreMap.getSource(id)) {
45044
+ mapLibreMap.removeSource(id);
45033
45045
  }
45034
45046
  });
45035
45047
  }
45036
45048
  }
45037
45049
  /** @private */
45038
45050
  addLayers() {
45039
- if (!this.maplibreLayer?.maplibreMap || !Array.isArray(this.layers)) {
45051
+ if (!this.maplibreLayer?.mapLibreMap || !Array.isArray(this.layers)) {
45040
45052
  return;
45041
45053
  }
45042
- const { maplibreMap } = this.maplibreLayer;
45043
- if (maplibreMap) {
45054
+ const { mapLibreMap } = this.maplibreLayer;
45055
+ if (mapLibreMap) {
45044
45056
  this.layers.forEach((layer) => {
45045
45057
  const { id, source } = layer;
45046
- if ((!source || source && maplibreMap.getSource(source)) && id && !maplibreMap.getLayer(id)) {
45047
- maplibreMap.addLayer(layer, this.beforeId);
45058
+ if ((!source || source && mapLibreMap.getSource(source)) && id && !mapLibreMap.getLayer(id)) {
45059
+ mapLibreMap.addLayer(layer, this.beforeId);
45048
45060
  }
45049
45061
  });
45050
45062
  this.applyLayoutVisibility();
@@ -45052,15 +45064,15 @@ uniform ${i3} ${s3} u_${a3};
45052
45064
  }
45053
45065
  /** @private */
45054
45066
  removeLayers() {
45055
- if (!this.maplibreLayer?.maplibreMap || !Array.isArray(this.layers)) {
45067
+ if (!this.maplibreLayer?.mapLibreMap || !Array.isArray(this.layers)) {
45056
45068
  return;
45057
45069
  }
45058
- const { maplibreMap } = this.maplibreLayer;
45059
- if (maplibreMap) {
45070
+ const { mapLibreMap } = this.maplibreLayer;
45071
+ if (mapLibreMap) {
45060
45072
  this.layers.forEach((styleLayer) => {
45061
45073
  const { id } = styleLayer;
45062
- if (id && maplibreMap.getLayer(id)) {
45063
- maplibreMap.removeLayer(id);
45074
+ if (id && mapLibreMap.getLayer(id)) {
45075
+ mapLibreMap.removeLayer(id);
45064
45076
  }
45065
45077
  });
45066
45078
  }
@@ -45070,17 +45082,18 @@ uniform ${i3} ${s3} u_${a3};
45070
45082
  * @private
45071
45083
  */
45072
45084
  onLoad() {
45073
- if (!this.maplibreLayer?.maplibreMap) {
45085
+ if (!this.maplibreLayer?.mapLibreMap) {
45074
45086
  return;
45075
45087
  }
45076
45088
  this.addSources();
45077
45089
  this.addLayers();
45078
- const { maplibreMap } = this.maplibreLayer;
45079
- const style = maplibreMap.getStyle();
45090
+ const { mapLibreMap } = this.maplibreLayer;
45091
+ const style = mapLibreMap.getStyle();
45080
45092
  if (style?.layers && this.layersFilter) {
45081
45093
  const styles = style.layers.filter(this.layersFilter);
45082
- this.disabled = !styles.length;
45094
+ this.set("disabled", !styles.length);
45083
45095
  }
45096
+ this.applyLayoutVisibility();
45084
45097
  }
45085
45098
  /**
45086
45099
  * Set the feature state of the features.
@@ -45089,10 +45102,10 @@ uniform ${i3} ${s3} u_${a3};
45089
45102
  * @public
45090
45103
  */
45091
45104
  setFeatureState(features, state) {
45092
- if (!this.maplibreLayer?.maplibreMap || !features.length) {
45105
+ if (!this.maplibreLayer?.mapLibreMap || !features.length) {
45093
45106
  return;
45094
45107
  }
45095
- const { maplibreMap } = this.maplibreLayer;
45108
+ const { mapLibreMap } = this.maplibreLayer;
45096
45109
  features.forEach((feature2) => {
45097
45110
  const { source, sourceLayer } = feature2.get(VECTOR_TILE_FEATURE_PROPERTY) || {};
45098
45111
  if (!source && !sourceLayer || !feature2.getId()) {
@@ -45105,7 +45118,7 @@ uniform ${i3} ${s3} u_${a3};
45105
45118
  }
45106
45119
  return;
45107
45120
  }
45108
- maplibreMap.setFeatureState(
45121
+ mapLibreMap.setFeatureState(
45109
45122
  {
45110
45123
  id: feature2.getId(),
45111
45124
  source,
@@ -45124,19 +45137,19 @@ uniform ${i3} ${s3} u_${a3};
45124
45137
  console.warn(
45125
45138
  `Deprecated. getFeatureInfoAtCoordinate([layer], coordinate) from ol package instead.`
45126
45139
  );
45127
- if (!this.maplibreLayer?.maplibreMap) {
45140
+ if (!this.maplibreLayer?.mapLibreMap) {
45128
45141
  return Promise.resolve({ coordinate, features: [], layer: this });
45129
45142
  }
45130
- const { maplibreMap } = this.maplibreLayer;
45131
- if (!maplibreMap.isStyleLoaded()) {
45143
+ const { mapLibreMap } = this.maplibreLayer;
45144
+ if (!mapLibreMap.isStyleLoaded()) {
45132
45145
  return Promise.resolve({ coordinate, features: [], layer: this });
45133
45146
  }
45134
45147
  let layers = this.layers || [];
45135
45148
  if (this.layersFilter) {
45136
- layers = maplibreMap.getStyle().layers.filter(this.layersFilter);
45149
+ layers = mapLibreMap.getStyle().layers.filter(this.layersFilter);
45137
45150
  }
45138
45151
  if (this.queryRenderedLayersFilter) {
45139
- layers = maplibreMap.getStyle().layers.filter(this.queryRenderedLayersFilter);
45152
+ layers = mapLibreMap.getStyle().layers.filter(this.queryRenderedLayersFilter);
45140
45153
  }
45141
45154
  return Promise.resolve({
45142
45155
  features: [],
@@ -45149,14 +45162,14 @@ uniform ${i3} ${s3} u_${a3};
45149
45162
  // * @param {maplibregl.filter} filter Determines which features should be rendered in a style layer.
45150
45163
  // */
45151
45164
  // setFilter(filter: { [key: string]: any }) {
45152
- // if (!this.maplibreLayer?.maplibreMap) {
45165
+ // if (!this.maplibreLayer?.mapLibreMap) {
45153
45166
  // return;
45154
45167
  // }
45155
- // const { maplibreMap } = this.maplibreLayer;
45168
+ // const { mapLibreMap } = this.maplibreLayer;
45156
45169
  // this.styleLayers.forEach(({ id }) => {
45157
- // if (id && filter && maplibreMap.getLayer(id)) {
45170
+ // if (id && filter && mapLibreMap.getLayer(id)) {
45158
45171
  // // @ts-ignore
45159
- // maplibreMap.setFilter(id, filter);
45172
+ // mapLibreMap.setFilter(id, filter);
45160
45173
  // }
45161
45174
  // });
45162
45175
  // }
@@ -45206,21 +45219,21 @@ uniform ${i3} ${s3} u_${a3};
45206
45219
  */
45207
45220
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
45208
45221
  applyLayoutVisibility(evt) {
45209
- if (!this.maplibreLayer?.maplibreMap?.getStyle() || !this.layersFilter) {
45222
+ if (!this.maplibreLayer?.mapLibreMap?.getStyle() || !this.layersFilter) {
45210
45223
  return;
45211
45224
  }
45212
- const { maplibreMap } = this.maplibreLayer;
45213
- const style = maplibreMap.getStyle();
45225
+ const { mapLibreMap } = this.maplibreLayer;
45226
+ const style = mapLibreMap.getStyle();
45214
45227
  const visibilityValue = this.getVisible() ? "visible" : "none";
45215
45228
  const layers = style.layers || [];
45216
45229
  for (let i = 0; i < layers.length; i += 1) {
45217
45230
  const layer = layers[i];
45218
45231
  if (this.layersFilter(layer)) {
45219
45232
  const { id } = layer;
45220
- if (maplibreMap.getLayer(id)) {
45221
- maplibreMap.setLayoutProperty(id, "visibility", visibilityValue);
45233
+ if (mapLibreMap.getLayer(id)) {
45234
+ mapLibreMap.setLayoutProperty(id, "visibility", visibilityValue);
45222
45235
  if (this.getMinZoom() || this.getMaxZoom()) {
45223
- maplibreMap.setLayerZoomRange(
45236
+ mapLibreMap.setLayerZoomRange(
45224
45237
  id,
45225
45238
  this.getMinZoom() ? this.getMinZoom() - 1 : 0,
45226
45239
  // Maplibre zoom = ol zoom - 1