yio-map 0.15.0 → 0.15.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/yio-map.js CHANGED
@@ -765,6 +765,18 @@ var LayerControl = class extends Control {
765
765
  }, 150);
766
766
  }
767
767
  };
768
+ // src/controls/selectableFeatures.js
769
+ /**
770
+ * The selectable features of the content map at a pixel: those with an `id` property.
771
+ * They are reported in `userSelect`; other content features (e.g. a fill without `id`) are not selectable.
772
+ * @param {import('ol/Map.js').default} map
773
+ * @param {import('ol/layer/Group.js').default} contentLayer
774
+ * @param {import('ol/pixel.js').Pixel} pixel
775
+ * @returns {Array<import('ol/Feature.js').FeatureLike>}
776
+ */
777
+ function getSelectableFeaturesAtPixel(map, contentLayer, pixel) {
778
+ return map.getFeaturesAtPixel(pixel, { layerFilter: (layer) => contentLayer.getLayers().getArray().includes(layer) }).filter((feature) => feature.get("id") !== void 0);
779
+ }
768
780
  // src/controls/UserSelectInteraction.js
769
781
  /**
770
782
  * @typedef {Object} Options
@@ -796,8 +808,7 @@ var UserSelectInteraction = class extends Interaction {
796
808
  */
797
809
  #handlePointerMove(event) {
798
810
  const map = this.getMap();
799
- const contentLayer = this.#yioMap._getContentLayer();
800
- if (map.getFeaturesAtPixel(event.pixel, { layerFilter: (layer) => contentLayer.getLayers().getArray().includes(layer) }).filter((feature) => feature.get("id") !== void 0).length) map.getTargetElement().classList.add("cursor-pointer");
811
+ if (getSelectableFeaturesAtPixel(map, this.#yioMap._getContentLayer(), event.pixel).length) map.getTargetElement().classList.add("cursor-pointer");
801
812
  else map.getTargetElement().classList.remove("cursor-pointer");
802
813
  }
803
814
  /**
@@ -805,10 +816,8 @@ var UserSelectInteraction = class extends Interaction {
805
816
  * @returns {boolean} Propageate the event further
806
817
  */
807
818
  #handleClick(event) {
808
- const map = this.getMap();
809
- const contentLayer = this.#yioMap._getContentLayer();
810
819
  const userSelectSource = this.#layer.getSource();
811
- const features = map.getFeaturesAtPixel(event.pixel, { layerFilter: (layer) => contentLayer.getLayers().getArray().includes(layer) }).filter((feature) => feature.get("id") !== void 0);
820
+ const features = getSelectableFeaturesAtPixel(this.getMap(), this.#yioMap._getContentLayer(), event.pixel);
812
821
  userSelectSource.clear();
813
822
  userSelectSource.addFeatures(features.map(
814
823
  /** @param {import('ol/render/Feature.js').default} featureOrRenderFeature */
@@ -1174,9 +1183,7 @@ var UserPinInteraction = class extends Interaction {
1174
1183
  * @param {import('ol').MapBrowserEvent} event
1175
1184
  */
1176
1185
  #handleClick(event) {
1177
- const map = this.getMap();
1178
- const contentLayer = this.#yioMap._getContentLayer();
1179
- if (map.getFeaturesAtPixel(event.pixel, { layerFilter: (layer) => contentLayer.getLayers().getArray().includes(layer) }).length === 0) this.#placePin(event.coordinate);
1186
+ this.#placePin(event.coordinate);
1180
1187
  }
1181
1188
  setActive(active) {
1182
1189
  if (!active) this.#layer.getSource().clear();
@@ -1209,7 +1216,7 @@ var package_default = {
1209
1216
  "type": "git",
1210
1217
  "url": "https://github.com/yiogmbh/yio-map"
1211
1218
  },
1212
- version: "0.15.0",
1219
+ version: "0.15.2",
1213
1220
  type: "module",
1214
1221
  files: ["dist"],
1215
1222
  exports: { ".": {
@@ -1756,6 +1763,10 @@ var YioMap = class extends i {
1756
1763
  * @type {Object|string} GeoJSON data or URL to overlay on the map
1757
1764
  */
1758
1765
  #geojsonSources = null;
1766
+ /**
1767
+ * @type {Set<string>} keys of `geojsonSources` without a layer in the content map, warned about once per content map
1768
+ */
1769
+ #missingGeojsonSources = /* @__PURE__ */ new Set();
1759
1770
  #sourceLayerVisibility = null;
1760
1771
  /**
1761
1772
  * @type {boolean} whether search is enabled
@@ -1872,6 +1883,7 @@ var YioMap = class extends i {
1872
1883
  if (version !== this.#contentMapVersion) return;
1873
1884
  this.#contentLayer.getLayers().clear();
1874
1885
  this.#contentLayerPromise = null;
1886
+ this.#missingGeojsonSources.clear();
1875
1887
  if (this.contentMap) {
1876
1888
  this.#contentLayerPromise = apply(this.#contentLayer, this.contentMap).catch((error) => {
1877
1889
  console.error("Error applying content to yiomap:", error);
@@ -1888,22 +1900,26 @@ var YioMap = class extends i {
1888
1900
  const layer = await this.#contentLayerPromise;
1889
1901
  if (!layer) return;
1890
1902
  const sources = Object.keys(this.#geojsonSources);
1891
- try {
1892
- await Promise.all(sources.map((source) => {
1893
- const data = this.#geojsonSources[source];
1894
- if (!getSource(layer, source)) throw new Error("Geojson source '" + source + "' does not exist.");
1895
- return updateMapboxSource(layer, source, {
1903
+ await Promise.all(sources.map(async (source) => {
1904
+ if (!getSource(layer, source)) {
1905
+ if (!this.#missingGeojsonSources.has(source)) {
1906
+ this.#missingGeojsonSources.add(source);
1907
+ console.warn(`Geojson source '${source}' is not used by any layer of the content map, ignored.`);
1908
+ }
1909
+ return;
1910
+ }
1911
+ try {
1912
+ const newSource = await updateMapboxSource(layer, source, {
1896
1913
  type: "geojson",
1897
- data
1898
- }).then((newSource) => {
1899
- getLayers(layer, source).forEach((sourceLayer) => {
1900
- if (sourceLayer.getSource() !== newSource) sourceLayer.setSource(newSource);
1901
- });
1914
+ data: this.#geojsonSources[source]
1902
1915
  });
1903
- }));
1904
- } catch (error) {
1905
- console.error("Error updating GeoJSON sources:", error);
1906
- }
1916
+ getLayers(layer, source).forEach((sourceLayer) => {
1917
+ if (sourceLayer.getSource() !== newSource) sourceLayer.setSource(newSource);
1918
+ });
1919
+ } catch (error) {
1920
+ console.error(`Error updating GeoJSON source '${source}':`, error);
1921
+ }
1922
+ }));
1907
1923
  }
1908
1924
  async #updateSourceLayerVisibility() {
1909
1925
  if (!this.#sourceLayerVisibility) return;