@defra/interactive-map 0.0.50-alpha → 0.0.51-apha

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.
Files changed (76) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/docs/api.md +19 -0
  4. package/docs/architecture.md +14 -0
  5. package/docs/getting-started.md +10 -0
  6. package/docs/plugins/datasets.md +9 -3
  7. package/jest.setup.js +8 -0
  8. package/package.json +8 -3
  9. package/plugins/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  10. package/plugins/datasets/dist/esm/im-datasets-ol-adapter.js +1 -0
  11. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  12. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  13. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +2 -0
  14. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js.LICENSE.txt +1 -0
  15. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  16. package/plugins/datasets/dist/umd/index.js +1 -1
  17. package/plugins/datasets/src/adapters/loadLayerAdapter.js +7 -3
  18. package/plugins/datasets/src/adapters/loadLayerAdapter.test.js +17 -0
  19. package/plugins/datasets/src/adapters/mapboxStyleLayerAdapter.js +74 -0
  20. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.js +14 -79
  21. package/plugins/datasets/src/adapters/maplibre/maplibreLayerAdapter.test.js +4 -0
  22. package/plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +3 -89
  23. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.js +111 -0
  24. package/plugins/datasets/src/adapters/openlayers/canvasPatternStyle.test.js +198 -0
  25. package/plugins/datasets/src/adapters/openlayers/layerBuilders.js +205 -0
  26. package/plugins/datasets/src/adapters/openlayers/layerBuilders.test.js +233 -0
  27. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.js +276 -0
  28. package/plugins/datasets/src/adapters/openlayers/openlayersLayerAdapter.test.js +431 -0
  29. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.js +172 -0
  30. package/plugins/datasets/src/adapters/openlayers/registry/openLayersDataset.test.js +262 -0
  31. package/plugins/datasets/src/fetch/createDynamicSource.js +12 -8
  32. package/plugins/datasets/src/fetch/createDynamicSource.test.js +61 -52
  33. package/plugins/datasets/src/initialise/DatasetsInit.jsx +13 -1
  34. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +20 -0
  35. package/plugins/datasets/src/initialise/initialiseDatasets.js +1 -1
  36. package/plugins/datasets/src/initialise/initialiseDatasets.test.js +1 -1
  37. package/plugins/datasets/src/registry/mapboxStyleDataset.js +108 -0
  38. package/plugins/datasets/src/registry/mapboxStyleDataset.test.js +240 -0
  39. package/plugins/datasets/src/utils/bbox.js +5 -7
  40. package/plugins/datasets/src/utils/bbox.test.js +3 -10
  41. package/plugins/draw/dist/css/index.css +1 -0
  42. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  43. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  44. package/plugins/draw/src/index.js +2 -0
  45. package/plugins/draw/src/index.test.js +1 -0
  46. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  47. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  48. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  49. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  50. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  51. package/providers/beta/openlayers/src/index.js +16 -0
  52. package/providers/beta/openlayers/src/openlayersProvider.js +160 -7
  53. package/providers/beta/openlayers/src/openlayersProvider.test.js +13 -0
  54. package/providers/beta/openlayers/src/utils/bngProjection.js +9 -0
  55. package/providers/beta/openlayers/src/utils/filterEvaluator.js +32 -0
  56. package/providers/beta/openlayers/src/utils/filterEvaluator.test.js +36 -0
  57. package/providers/beta/openlayers/src/utils/highlightFeatures.js +38 -23
  58. package/providers/beta/openlayers/src/utils/highlightFeatures.test.js +153 -8
  59. package/providers/beta/openlayers/src/utils/hoverCursor.js +5 -1
  60. package/providers/beta/openlayers/src/utils/hoverCursor.test.js +40 -0
  61. package/providers/beta/openlayers/src/utils/queryFeatures.js +72 -54
  62. package/providers/beta/openlayers/src/utils/queryFeatures.test.js +143 -1
  63. package/providers/beta/openlayers/src/utils/symbolImages.js +79 -5
  64. package/providers/beta/openlayers/src/utils/symbolImages.test.js +111 -1
  65. package/providers/beta/openlayers/src/utils/vtTileFragments.js +20 -8
  66. package/providers/beta/openlayers/src/utils/vtTileFragments.test.js +162 -0
  67. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  68. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  69. package/providers/maplibre/dist/umd/index.js +1 -1
  70. package/providers/maplibre/src/utils/patternImages.js +4 -44
  71. package/rollup.esm.mjs +2 -0
  72. package/src/services/patternRegistry.js +38 -0
  73. package/src/services/patternRegistry.test.js +61 -0
  74. package/src/types.js +11 -0
  75. package/webpack.dev.mjs +1 -0
  76. /package/plugins/datasets/dist/esm/{esriLayerAdapter.js → im-datasets-esri-adapter.js} +0 -0
package/docs/api.md CHANGED
@@ -324,6 +324,25 @@ maplibreProvider({ workerUrl: '/your-assets-path/maplibre-gl-csp-worker.js' })
324
324
  defra.maplibreProvider({ workerUrl: '/your-assets-path/maplibre-gl-csp-worker.js' })
325
325
  ```
326
326
 
327
+ #### OpenLayers provider options
328
+
329
+ `openLayersProvider()` accepts an optional config object. The provider renders in British National Grid (EPSG:27700) — this isn't configurable.
330
+
331
+ ##### `zoomAlignment`
332
+ **Type:** `string`
333
+ **Default:** `'uk'`
334
+
335
+ Which zoom-level sequence the map's view resolutions follow.
336
+
337
+ | Possible values | Description |
338
+ | :--- | :--- |
339
+ | `'uk'` | OS tile grid zoom levels (0–13); zoom 0 shows all of Great Britain. |
340
+ | `'world'` | ESRI LOD sequence, for zoom levels that match the ESRI SDK; full UK visible around zoom 7. |
341
+
342
+ ```js
343
+ openLayersProvider({ zoomAlignment: 'world' })
344
+ ```
345
+
327
346
  ---
328
347
 
329
348
  ### `mapSize`
@@ -88,6 +88,20 @@ An alternative provider with specific advantages:
88
88
  </tr>
89
89
  </table>
90
90
 
91
+ ### OpenLayers (Experimental)
92
+ Another alternative provider, also BNG-native:
93
+
94
+ <table>
95
+ <tr>
96
+ <td><strong>British National Grid</strong></td>
97
+ <td>Native support for BNG coordinate systems (EPSG:27700)</td>
98
+ </tr>
99
+ <tr>
100
+ <td><strong>UMD and ESM</strong></td>
101
+ <td>Unlike Esri, available to both UMD and ESM consumers</td>
102
+ </tr>
103
+ </table>
104
+
91
105
  ## 4. Plugin System
92
106
 
93
107
  ### Declarative by Design
@@ -44,6 +44,16 @@ The ESRI provider is available for ESM projects only. Install `@arcgis/core` sep
44
44
  npm install @arcgis/core
45
45
  ```
46
46
 
47
+ ### OpenLayers provider (optional)
48
+
49
+ An alternative to MapLibre with native support for British National Grid (EPSG:27700) coordinates. Install `ol` and `proj4` separately:
50
+
51
+ ```shell
52
+ npm install ol proj4
53
+ ```
54
+
55
+ **UMD:** `ol` and `proj4` are bundled — no separate install needed.
56
+
47
57
  ## Basic usage
48
58
 
49
59
  **ESM** — add a container element to your HTML and initialise the map in your JavaScript:
@@ -202,7 +202,7 @@ The layer name within the vector tile source to render. Required when using `til
202
202
 
203
203
  **Type:** `string`
204
204
 
205
- Property name used to uniquely identify features in a static `geojson` source. When set, the plugin promotes this property to the MapLibre feature ID (`promoteId`) so that feature IDs are stable and derived from your data rather than auto-generated.
205
+ Property name used to uniquely identify features in a static `geojson` source. When set, the plugin promotes this property to the underlying engine's feature ID (MapLibre's `promoteId`; OpenLayers' `ol/Feature` id) so that feature IDs are stable and derived from your data rather than auto-generated.
206
206
 
207
207
  Required for `setFeatureVisibility` to work correctly — the IDs you pass must match the values of this property in your data.
208
208
 
@@ -226,6 +226,9 @@ Required for `setFeatureVisibility` to work correctly — the IDs you pass must
226
226
 
227
227
  When `true`, MapLibre auto-generates integer IDs for GeoJSON features by their array index position (0-based). Use this when your features have no natural unique ID property and you need `setFeatureVisibility` to work.
228
228
 
229
+ > [!NOTE]
230
+ > MapLibre only. The OpenLayers provider has no equivalent auto-generated ID concept — use `idProperty` instead.
231
+
229
232
  > [!NOTE]
230
233
  > Auto-generated IDs are positional and reset on every `setData` call. If your data changes between calls, the same integer ID may refer to a different feature. Prefer `idProperty` whenever your data has a stable unique field.
231
234
 
@@ -243,7 +246,10 @@ When `true`, MapLibre auto-generates integer IDs for GeoJSON features by their a
243
246
 
244
247
  **Type:** `FilterExpression`
245
248
 
246
- A MapLibre filter expression applied to the dataset's map layers. Features not matching the filter are not rendered.
249
+ A MapLibre-style filter expression applied to the dataset's map layers (also evaluated by the OpenLayers provider's own expression engine). Features not matching the filter are not rendered.
250
+
251
+ > [!NOTE]
252
+ > OpenLayers' expression parser is stricter than MapLibre's in places — e.g. `in`'s second argument must be a real array (`['literal', [...]]`), where MapLibre also accepts a bare scalar.
247
253
 
248
254
  ```js
249
255
  filter: ['==', ['get', 'status'], 'active']
@@ -410,7 +416,7 @@ Sublayer styles merge over the parent's — the sublayer wins on any property it
410
416
  |----------|------|-------------|
411
417
  | `id` | `string` | **Required.** Unique identifier within the dataset |
412
418
  | `label` | `string` | Human-readable name shown in the LayersMenu and Key panels |
413
- | `filter` | `FilterExpression` | MapLibre filter expression to match features for this sublayer |
419
+ | `filter` | `FilterExpression` | MapLibre-style filter expression to match features for this sublayer |
414
420
  | `style` | `Object` | Style overrides. Accepts the same properties as the dataset `style` object |
415
421
  | `showInKey` | `boolean` | Shows this sublayer in the Key panel. Inherits from the dataset when not set; explicit `false` overrides a dataset-level `true` |
416
422
  | `showInMenu` | `boolean` | Shows this sublayer in the LayersMenu panel. Inherits from the dataset when not set; explicit `false` overrides a dataset-level `true` |
package/jest.setup.js CHANGED
@@ -1,10 +1,18 @@
1
1
  import '@testing-library/jest-dom'
2
+ import { TextEncoder, TextDecoder } from 'node:util'
2
3
 
3
4
  // structuredClone is not exposed by jsdom; polyfill it using JSON round-trip
4
5
  if (typeof structuredClone === 'undefined') {
5
6
  global.structuredClone = (obj) => JSON.parse(JSON.stringify(obj))
6
7
  }
7
8
 
9
+ // TextEncoder/TextDecoder aren't exposed by jsdom either — OL 10.10's WebGL text rendering
10
+ // module references TextEncoder at load time, so importing any WebGL layer throws without this.
11
+ if (!global.TextEncoder) {
12
+ global.TextEncoder = TextEncoder
13
+ global.TextDecoder = TextDecoder
14
+ }
15
+
8
16
  // Global mock for window.matchMedia
9
17
  if (!window.matchMedia) {
10
18
  Object.defineProperty(window, 'matchMedia', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/interactive-map",
3
- "version": "0.0.50-alpha",
3
+ "version": "0.0.51-apha",
4
4
  "description": "An accessible map component",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,12 +67,17 @@
67
67
  "./plugins/draw-es": {
68
68
  "import": "./plugins/beta/draw-es/dist/esm/index.js"
69
69
  },
70
+ "./plugins/draw": {
71
+ "import": "./plugins/draw/dist/esm/index.js",
72
+ "require": "./plugins/draw/dist/umd/index.js"
73
+ },
70
74
  "./plugins/frame": {
71
75
  "import": "./plugins/beta/frame/dist/esm/index.js",
72
76
  "require": "./plugins/beta/frame/dist/umd/index.js"
73
77
  },
74
78
  "./css": "./dist/css/index.css",
75
79
  "./plugins/draw-ml/css": "./plugins/beta/draw-ml/dist/css/index.css",
80
+ "./plugins/draw/css": "./plugins/draw/dist/css/index.css",
76
81
  "./plugins/scale-bar/css": "./plugins/beta/scale-bar/dist/css/index.css",
77
82
  "./plugins/datasets/css": "./plugins/datasets/dist/css/index.css",
78
83
  "./plugins/menu/css": "./plugins/menu/dist/css/index.css",
@@ -129,7 +134,7 @@
129
134
  },
130
135
  "peerDependencies": {
131
136
  "@arcgis/core": "^5.0.9",
132
- "ol": "^10.9.0",
137
+ "ol": "^10.10.0",
133
138
  "proj4": "^2.20.8"
134
139
  },
135
140
  "peerDependenciesMeta": {
@@ -188,7 +193,7 @@
188
193
  "mini-css-extract-plugin": "^2.9.2",
189
194
  "node-fetch": "^3.3.2",
190
195
  "npm-run-all": "^4.1.5",
191
- "ol": "^10.9.0",
196
+ "ol": "^10.10.0",
192
197
  "ol-mapbox-style": "^13.4.1",
193
198
  "proj4": "^2.20.8",
194
199
  "react": "^19.2.4",
@@ -1 +1 @@
1
- import t from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/defineProperty";import{D as r,h as a,l as i,d as s}from"./im-datasets-plugin.js";class o{attachDynamicSources(t){this._dynamicSources=t}get dynamicSources(){return this._dynamicSources}}var l=(t,e)=>{if(!t)return null;if("string"==typeof t)return t.trim();if("object"==typeof t){if(e&&t[e])return t[e];var r=Object.values(t)[0];return null!=r?r:null}return null};function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,a)}return r}var y=(t,r,a)=>{var{hasStroke:i,strokeLayerId:s}=r;if(i&&!t.getLayer(s)){var o=function(t){for(var r=1;r<arguments.length;r++){var a=null!=arguments[r]?arguments[r]:{};r%2?n(Object(a),!0).forEach(function(r){e(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))})}return t}({"line-color":l(r.style.stroke,a),"line-width":r.style.strokeWidth||1,"line-opacity":r.opacity},r.style.strokeDashArray?{"line-dasharray":r.style.strokeDashArray}:{}),y=r.getStrokeSource(o);t.addLayer(y)}},h=(t,e,r,a,i,s)=>{var o,{sourceId:n,source:d}=e;d&&!t.getSource(n)&&t.addSource(n,d);var p=r.id;return((t,e,r,a,i)=>{var{hasSymbol:s,symbolLayerId:o}=e;if(s&&a&&o&&!t.getLayer(o)){var l=a.getSymbolDef(e.style);if(l){var n=a.getSymbolImageId(e.style,r,!1,i);if(n){var y=((t,e)=>{var r;return t.symbolAnchor?t.symbolAnchor:null!==(r=null==e?void 0:e.anchor)&&void 0!==r?r:[.5,.5]})(e.style,l);t.addLayer(e.getSymbolSource(n,y,l))}}}})(t,e,r,a,s),function(t,e,r,a){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1,{hasFill:s,fillLayerId:o}=e;if(s&&o&&!t.getLayer(o)){var n=a.getPatternImageId(e.style,r,i),y=n?{"fill-pattern":n,"fill-opacity":e.opacity}:{"fill-color":l(e.style.fill,r),"fill-opacity":e.opacity};t.addLayer(e.getFillSource(y))}}(t,e,p,i,s),y(t,e,p),null!==(o=e.sublayers)&&void 0!==o&&o.length?(e.sublayers.forEach(e=>{h(t,e,r,a,i,s)}),n):e.isSublayer?void 0:n},d=t=>{var[e,r]=t,a=(t=>t<=.25?"left":t>=.75?"right":"")(e),i=(t=>t<=.25?"top":t>=.75?"bottom":"")(r);return i+(a&&i?"-":"")+a||"center"};function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,a)}return r}function u(t){for(var r=1;r<arguments.length;r++){var a=null!=arguments[r]?arguments[r]:{};r%2?p(Object(a),!0).forEach(function(r){e(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):p(Object(a)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))})}return t}class c extends r{get fillLayerId(){return this.hasSublayers||this.hasSymbol?null:this.hasFill?this.id:null}get strokeLayerId(){return this.hasSublayers||this.hasSymbol?null:this.hasStroke?this.hasFill?"".concat(this.id,"-stroke"):this.id:null}get symbolLayerId(){return this.hasSublayers?null:this.hasSymbol?this.id:null}get layerIds(){return this.hasSublayers?this.sublayers.flatMap(t=>t.layerIds).filter(Boolean):[this.symbolLayerId,this.fillLayerId,this.strokeLayerId].filter(Boolean)}getLayersWithValue(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=[];if(!1===e||this[e]){var a=[this.symbolLayerId,this.fillLayerId,this.strokeLayerId].filter(Boolean);if(a.length){var i=this[t];r.push({layerIds:a,[t]:i})}}return this.hasSublayers&&this.sublayers.forEach(a=>{(!1===e||a[e])&&r.push(a.getLayersWithValue(t)[0])}),r}getLayersWithVisibility(){return this.getLayersWithValue("visibility")}getLayersWithOpacity(){return this.getLayersWithValue("opacity")}getLayersWithFilters(){return this.getLayersWithValue("filter","hasHiddenFeatures")}get sourceId(){if(this.isSublayer)return this.parent.sourceId;if(this.hasDynamicGeoJSON)return this.dynamicGeoJSON.sourceId;if(this.tiles){var t=Array.isArray(this.tiles)?this.tiles.join(","):this.tiles;return"tiles-".concat(a(t))}return this.geojson?"string"==typeof this.geojson?"geojson-".concat(a(this.geojson)):"geojson-".concat(this.id):"source-".concat(this.id)}_geojsonIdStrategy(){var t;return this.idProperty?{promoteId:this.idProperty}:this.generateIds?{generateId:!0}:(null!==(t=this.geojson)&&void 0!==t&&null!==(t=t.features)&&void 0!==t&&t.some(t=>"string"==typeof t.id)&&i.warn('Dataset "'.concat(this.id,'" has GeoJSON features with string native IDs. MapLibre only surfaces integer native feature IDs through queryRenderedFeatures. Use idProperty to promote a string property instead.')),{})}get source(){if(this.hasDynamicGeoJSON)return this.dynamicGeoJSON.source;if(this.tiles){var t={type:"vector",tiles:this.tiles,minzoom:this.minZoom||0,maxzoom:this.maxZoom||22};return this.idProperty&&this.sourceLayer&&(t.promoteId={[this.sourceLayer]:this.idProperty}),t}return this.geojson?u({type:"geojson",data:this.geojson},this._geojsonIdStrategy()):null}getSymbolSource(t,e,r){return u({id:this.symbolLayerId,type:"symbol",source:this.sourceId,"source-layer":this.sourceLayer,minzoom:this.minZoom,maxzoom:this.maxZoom,layout:{visibility:this.visibility,"icon-image":t,"icon-anchor":d(e||(null==r?void 0:r.anchor)||[.5,.5]),"icon-allow-overlap":!0}},this.filter?{filter:this.filter}:{})}getFillSource(t){return u({id:this.fillLayerId,type:"fill",source:this.sourceId,"source-layer":this.sourceLayer,minzoom:this.minZoom,maxzoom:this.maxZoom,layout:{visibility:this.visibility},paint:t},this.filter?{filter:this.filter}:{})}getStrokeSource(t){return u({id:this.strokeLayerId,type:"line",source:this.sourceId,"source-layer":this.sourceLayer,minzoom:this.minZoom,maxzoom:this.maxZoom,layout:{visibility:this.visibility},paint:t},this.filter?{filter:this.filter}:{})}get _hiddenFeaturesIdExpression(){return this.hasDynamicGeoJSON?this.dynamicGeoJSON.hiddenFeaturesIdExpression:this.idProperty?["to-string",["get",this.idProperty]]:["to-string",["id"]]}get _hiddenFeaturesFilter(){var t,e=null===(t=this.hiddenFeatures)||void 0===t?void 0:t.filter(t=>-1!==t);return null!=e&&e.length?["!",["in",this._hiddenFeaturesIdExpression,["literal",e.map(String)]]]:null}get filter(){var t,e=["all"];null!==(t=this.parent)&&void 0!==t&&t.filter&&e.push(this.parent.filter),this._datasetDefinition.filter&&e.push(this._datasetDefinition.filter);var r=this._hiddenFeaturesFilter;return r&&e.push(r),1===e.length?null:e.length>2?e:e[1]}}var m=Object.freeze({__proto__:null,default:class extends o{constructor(t,e,r){super(),this._mapProvider=t,this._map=t.map,this._symbolRegistry=e,this._patternRegistry=r,this._datasetSourceMap=new Map,window._datasetSourceMap=this._datasetSourceMap,this._symbolLayerIds=new Set}createDataset(t){return new c(t)}init(){var e=this;return t(function*(){var{patternConfigs:t,symbolConfigs:r}=s.getPatternAndSymbolConfigs();yield e.addPatternsAndSymbolsToMap(t,r),e._symbolLayerIds.clear(),s.forEachDataset(t=>e._addLayers(t)),yield new Promise(t=>e._map.once("idle",t))})()}removeLayer(t){this._map.getLayer(t)&&this._map.removeLayer(t),this._symbolLayerIds.delete(t)}addPatternsAndSymbolsToMap(e,r){var a=this;return t(function*(){var t=s.mapStyle,i=t.id;return Promise.all([a._mapProvider.addPatternsToMap(e,i,a._patternRegistry),a._mapProvider.addSymbolsToMap(r,t,a._symbolRegistry)])})()}destroy(){var t=new Set;s.forEachDataset(e=>{var r=e.sourceId;this._getLayersUsingSource(r).forEach(t=>this.removeLayer(t)),!t.has(r)&&this._map.getSource(r)&&(this._map.removeSource(r),t.add(r))}),this._datasetSourceMap.clear()}onMapStyleChange(){var e=this;return t(function*(){yield new Promise(t=>e._map.once("idle",t));var{patternConfigs:t,symbolConfigs:r}=s.getPatternAndSymbolConfigs();yield e.addPatternsAndSymbolsToMap(t,r),e._symbolLayerIds.clear(),s.forEachDataset(t=>{e._addLayers(t),e._applyFeatureFilter(t)}),e.dynamicSources.forEach(t=>t.reapply())})()}onMapSizeChange(){var e=this;return t(function*(){var{mapStyle:t}=s,{patternConfigs:r,symbolConfigs:a}=s.getPatternAndSymbolConfigs();yield e.addPatternsAndSymbolsToMap(r,a),s.forEach(r=>{var{fillLayerId:a,symbolLayerId:i}=r;if(i&&e._symbolLayerIds.has(i)&&e._map.getLayer(i)){var s=e._symbolRegistry.getSymbolImageId(r.style,t,!1,e._pixelRatio);s&&e._map.setLayoutProperty(i,"icon-image",s)}else if(a&&e._map.getLayer(a)){var o=e._patternRegistry.getPatternImageId(r.style,t.id,e._pixelRatio);o&&e._map.setPaintProperty(a,"fill-pattern",o)}})})()}addDataset(e){var r=this;return t(function*(){var t=s.getDataset(e);yield r.addPatternsAndSymbolsToMap(t.patternConfigs,t.symbolConfigs),r._addLayers(t)})()}removeDataset(t){var e=s.getDataset(t);if(e){var{sourceId:r,layerIds:a}=e;a.forEach(t=>this.removeLayer(t)),!s.topLevelDatasets().some(e=>e.id!==t&&e.sourceId===r)&&this._map.getSource(r)&&this._map.removeSource(r),this._datasetSourceMap.delete(t)}}applyFeatureFilter(t){var e=s.getDataset(t);e&&this._applyFeatureFilter(e)}applyStyle(e){var r=this;return t(function*(){var t=s.getDataset(e);t.layerIds.forEach(t=>r.removeLayer(t)),yield r.addPatternsAndSymbolsToMap(t.patternConfigs,t.symbolConfigs),r._addLayers(t)})()}applyDatasetOpacity(t){var e=s.getDataset(t);e&&this._applyRegistryDatasetOpacity(e)}_applyRegistryDatasetOpacity(t){t.getLayersWithOpacity().forEach(t=>{var{layerIds:e,opacity:r}=t;e.forEach(t=>this._setPaintOpacity(t,r))})}applyGlobalOpacity(){s.forEachDataset(t=>this._applyRegistryDatasetOpacity(t))}setData(t,e){var r=this._datasetSourceMap.get(t);if(r){var a=this._map.getSource(r);a&&"function"==typeof a.setData&&a.setData(e)}}get _pixelRatio(){return this._mapProvider.map.getPixelRatio()}_addLayers(t){var{mapStyle:e}=s,r=h(this._map,t,e,this._symbolRegistry,this._patternRegistry,this._pixelRatio);this._datasetSourceMap.set(t.id,r),this._maintainSymbolOrdering(t)}_getFirstSymbolLayerId(){var t,e=this._map.getStyle();if(null==e||!e.layers)return null;var r=e.layers.find(t=>this._symbolLayerIds.has(t.id));return null!==(t=null==r?void 0:r.id)&&void 0!==t?t:null}_maintainSymbolOrdering(t){var e=(t=t.isSublayer?t.parent:t).layerIds.filter(t=>t&&this._map.getLayer(t));e.forEach(t=>{var e;"symbol"===(null===(e=this._map.getLayer(t))||void 0===e?void 0:e.type)?this._symbolLayerIds.add(t):this._symbolLayerIds.delete(t)});var r=this._getFirstSymbolLayerId();r&&e.forEach(t=>{this._symbolLayerIds.has(t)||this._map.moveLayer(t,r)})}applyDatasetVisibility(t){var e=s.getDataset(t);e&&this._applyRegistryDatasetVisibility(e)}_applyRegistryDatasetVisibility(t){t.getLayersWithVisibility().forEach(t=>{var{layerIds:e,visibility:r}=t;e.forEach(t=>{this._map.getLayer(t)&&this._map.setLayoutProperty(t,"visibility",r)})})}applyGlobalVisibility(){s.forEachDataset(t=>this._applyRegistryDatasetVisibility(t))}_applyFeatureFilter(t){t.getLayersWithFilters().forEach(t=>{var{layerIds:e,filter:r}=t;e.forEach(t=>{this._map.getLayer(t)&&this._map.setFilter(t,r)})})}_setPaintOpacity(t,e){var r=this._map.getLayer(t);if(r){var a={line:"line-opacity",symbol:"icon-opacity"}[r.type]||"fill-opacity";this._map.setPaintProperty(t,a,e)}}_getLayersUsingSource(t){var e=this._map.getStyle();return null!=e&&e.layers?e.layers.filter(e=>e.source===t).map(t=>t.id):[]}}});export{o as L,l as g,m};
1
+ import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";import{D as r,h as a,l as i,d as s}from"./im-datasets-plugin.js";var o=(e,t)=>{if(!e)return null;if("string"==typeof e)return e.trim();if("object"==typeof e){if(t&&e[t])return e[t];var r=Object.values(e)[0];return null!=r?r:null}return null},l=new Set(["symbolBackgroundColor","symbolForegroundColor","symbolHaloWidth","symbolGraphic"]),n=e=>{if(!(e=>!(!e.symbol&&!e.symbolSvgContent))(e))return{};var t={};return l.forEach(r=>{if(null!=e[r]){var a=r.charAt(6).toLowerCase()+r.slice(7);t[a]=e[r]}}),t},y=(e,t)=>{var r;return e.symbolViewBox?e.symbolViewBox:null!==(r=null==t?void 0:t.viewBox)&&void 0!==r?r:"0 0 38 38"},h=(e,t)=>{var r;return e.symbolAnchor?e.symbolAnchor:null!==(r=null==t?void 0:t.anchor)&&void 0!==r?r:[.5,.5]};function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,a)}return r}var u=(e,r,a)=>{var{hasStroke:i,strokeLayerId:s}=r;if(i&&!e.getLayer(s)){var l=function(e){for(var r=1;r<arguments.length;r++){var a=null!=arguments[r]?arguments[r]:{};r%2?d(Object(a),!0).forEach(function(r){t(e,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):d(Object(a)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}({"line-color":o(r.style.stroke,a),"line-width":r.style.strokeWidth||1,"line-opacity":r.opacity},r.style.strokeDashArray?{"line-dasharray":r.style.strokeDashArray}:{}),n=r.getStrokeSource(l);e.addLayer(n)}},c=(e,t,r,a,i,s)=>{var l,{sourceId:n,source:y}=t;y&&!e.getSource(n)&&e.addSource(n,y);var d=r.id;return((e,t,r,a,i)=>{var{hasSymbol:s,symbolLayerId:o}=t;if(s&&a&&o&&!e.getLayer(o)){var l=a.getSymbolDef(t.style);if(l){var n=a.getSymbolImageId(t.style,r,!1,i);if(n){var y=h(t.style,l);e.addLayer(t.getSymbolSource(n,y,l))}}}})(e,t,r,a,s),function(e,t,r,a){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1,{hasFill:s,fillLayerId:l}=t;if(s&&l&&!e.getLayer(l)){var n=a.getPatternImageId(t.style,r,i),y=n?{"fill-pattern":n,"fill-opacity":t.opacity}:{"fill-color":o(t.style.fill,r),"fill-opacity":t.opacity};e.addLayer(t.getFillSource(y))}}(e,t,d,i,s),u(e,t,d),null!==(l=t.sublayers)&&void 0!==l&&l.length?(t.sublayers.forEach(t=>{c(e,t,r,a,i,s)}),n):t.isSublayer?void 0:n};class p extends r{get _hiddenFeaturesIdExpression(){return this.hasDynamicGeoJSON?this.dynamicGeoJSON.hiddenFeaturesIdExpression:this.idProperty?["to-string",["get",this.idProperty]]:["to-string",["id"]]}get _hiddenFeaturesFilter(){var e,t=null===(e=this.hiddenFeatures)||void 0===e?void 0:e.filter(e=>-1!==e);return null!=t&&t.length?["!",["in",this._hiddenFeaturesIdExpression,["literal",t.map(String)]]]:null}get filter(){var e,t=["all"];null!==(e=this.parent)&&void 0!==e&&e.filter&&t.push(this.parent.filter),this._datasetDefinition.filter&&t.push(this._datasetDefinition.filter);var r=this._hiddenFeaturesFilter;return r&&t.push(r),1===t.length?null:t.length>2?t:t[1]}get leafLayerIds(){return[]}get layerIds(){return this.hasSublayers?this.sublayers.flatMap(e=>e.layerIds).filter(Boolean):this.leafLayerIds}getLayersWithValue(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=[];if(!1===t||this[t]){var a=this.leafLayerIds;if(a.length){var i=this[e];r.push({layerIds:a,[e]:i})}}return this.hasSublayers&&this.sublayers.forEach(a=>{if(!1===t||a[t]){var[i]=a.getLayersWithValue(e);i&&r.push(i)}}),r}getLayersWithVisibility(){return this.getLayersWithValue("visibility")}getLayersWithOpacity(){return this.getLayersWithValue("opacity")}getLayersWithFilters(){return this.getLayersWithValue("filter","hasHiddenFeatures")}get sourceId(){if(this.isSublayer)return this.parent.sourceId;if(this.hasDynamicGeoJSON)return this.dynamicGeoJSON.sourceId;if(this.tiles){var e=Array.isArray(this.tiles)?this.tiles.join(","):this.tiles;return"tiles-".concat(a(e))}return this.geojson?"string"==typeof this.geojson?"geojson-".concat(a(this.geojson)):"geojson-".concat(this.id):"source-".concat(this.id)}}var m=e=>{var[t,r]=e,a=(e=>e<=.25?"left":e>=.75?"right":"")(t),i=(e=>e<=.25?"top":e>=.75?"bottom":"")(r);return i+(a&&i?"-":"")+a||"center"};function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,a)}return r}function f(e){for(var r=1;r<arguments.length;r++){var a=null!=arguments[r]?arguments[r]:{};r%2?g(Object(a),!0).forEach(function(r){t(e,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):g(Object(a)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}class b extends p{get fillLayerId(){return this.hasSublayers||this.hasSymbol?null:this.hasFill?this.id:null}get strokeLayerId(){return this.hasSublayers||this.hasSymbol?null:this.hasStroke?this.hasFill?"".concat(this.id,"-stroke"):this.id:null}get symbolLayerId(){return this.hasSublayers?null:this.hasSymbol?this.id:null}get leafLayerIds(){return[this.symbolLayerId,this.fillLayerId,this.strokeLayerId].filter(Boolean)}_geojsonIdStrategy(){var e;return this.idProperty?{promoteId:this.idProperty}:this.generateIds?{generateId:!0}:(null!==(e=this.geojson)&&void 0!==e&&null!==(e=e.features)&&void 0!==e&&e.some(e=>"string"==typeof e.id)&&i.warn('Dataset "'.concat(this.id,'" has GeoJSON features with string native IDs. MapLibre only surfaces integer native feature IDs through queryRenderedFeatures. Use idProperty to promote a string property instead.')),{})}get source(){if(this.hasDynamicGeoJSON)return this.dynamicGeoJSON.source;if(this.tiles){var e={type:"vector",tiles:this.tiles,minzoom:this.minZoom||0,maxzoom:this.maxZoom||22};return this.idProperty&&this.sourceLayer&&(e.promoteId={[this.sourceLayer]:this.idProperty}),e}return this.geojson?f({type:"geojson",data:this.geojson},this._geojsonIdStrategy()):null}getSymbolSource(e,t,r){return f({id:this.symbolLayerId,type:"symbol",source:this.sourceId,"source-layer":this.sourceLayer,minzoom:this.minZoom,maxzoom:this.maxZoom,layout:{visibility:this.visibility,"icon-image":e,"icon-anchor":m(t||(null==r?void 0:r.anchor)||[.5,.5]),"icon-allow-overlap":!0}},this.filter?{filter:this.filter}:{})}getFillSource(e){return f({id:this.fillLayerId,type:"fill",source:this.sourceId,"source-layer":this.sourceLayer,minzoom:this.minZoom,maxzoom:this.maxZoom,layout:{visibility:this.visibility},paint:e},this.filter?{filter:this.filter}:{})}getStrokeSource(e){return f({id:this.strokeLayerId,type:"line",source:this.sourceId,"source-layer":this.sourceLayer,minzoom:this.minZoom,maxzoom:this.maxZoom,layout:{visibility:this.visibility},paint:e},this.filter?{filter:this.filter}:{})}}class v{attachDynamicSources(e){this._dynamicSources=e}get dynamicSources(){return this._dynamicSources}}class _ extends v{constructor(e,t,r){super(),this._mapProvider=e,this._map=e.map,this._symbolRegistry=t,this._patternRegistry=r}get _pixelRatio(){return this._map.getPixelRatio()}addDataset(t){var r=this;return e(function*(){var e=s.getDataset(t);e&&(yield r._registerPatternsAndSymbols(e),r._addLayers(e))})()}applyDatasetOpacity(e){var t=s.getDataset(e);t&&this._applyRegistryDatasetOpacity(t)}_applyRegistryDatasetOpacity(e){e.getLayersWithOpacity().forEach(e=>{var{layerIds:t,opacity:r}=e;t.forEach(e=>this._setLayerOpacity(e,r))})}applyGlobalOpacity(){s.forEachDataset(e=>this._applyRegistryDatasetOpacity(e))}applyDatasetVisibility(e){var t=s.getDataset(e);t&&this._applyRegistryDatasetVisibility(t)}_applyRegistryDatasetVisibility(e){e.getLayersWithVisibility().forEach(e=>{var{layerIds:t,visibility:r}=e;t.forEach(e=>this._setLayerVisibility(e,r))})}applyGlobalVisibility(){s.forEachDataset(e=>this._applyRegistryDatasetVisibility(e))}}var S=Object.freeze({__proto__:null,default:class extends _{constructor(e,t,r){super(e,t,r),this._datasetSourceMap=new Map,window._datasetSourceMap=this._datasetSourceMap,this._symbolLayerIds=new Set}createDataset(e){return new b(e)}init(){var t=this;return e(function*(){var{patternConfigs:e,symbolConfigs:r}=s.getPatternAndSymbolConfigs();yield t.addPatternsAndSymbolsToMap(e,r),t._symbolLayerIds.clear(),s.forEachDataset(e=>t._addLayers(e)),yield new Promise(e=>t._map.once("idle",e))})()}removeLayer(e){this._map.getLayer(e)&&this._map.removeLayer(e),this._symbolLayerIds.delete(e)}addPatternsAndSymbolsToMap(t,r){var a=this;return e(function*(){var e=s.mapStyle,i=e.id;return Promise.all([a._mapProvider.addPatternsToMap(t,i,a._patternRegistry),a._mapProvider.addSymbolsToMap(r,e,a._symbolRegistry)])})()}destroy(){var e=new Set;s.forEachDataset(t=>{var r=t.sourceId;this._getLayersUsingSource(r).forEach(e=>this.removeLayer(e)),!e.has(r)&&this._map.getSource(r)&&(this._map.removeSource(r),e.add(r))}),this._datasetSourceMap.clear()}onMapStyleChange(){var t=this;return e(function*(){yield new Promise(e=>t._map.once("idle",e));var{patternConfigs:e,symbolConfigs:r}=s.getPatternAndSymbolConfigs();yield t.addPatternsAndSymbolsToMap(e,r),t._symbolLayerIds.clear(),s.forEachDataset(e=>{t._addLayers(e),t._applyFeatureFilter(e)}),t.dynamicSources.forEach(e=>e.reapply())})()}onMapSizeChange(){var t=this;return e(function*(){var{mapStyle:e}=s,{patternConfigs:r,symbolConfigs:a}=s.getPatternAndSymbolConfigs();yield t.addPatternsAndSymbolsToMap(r,a),s.forEach(r=>{var{fillLayerId:a,symbolLayerId:i}=r;if(i&&t._symbolLayerIds.has(i)&&t._map.getLayer(i)){var s=t._symbolRegistry.getSymbolImageId(r.style,e,!1,t._pixelRatio);s&&t._map.setLayoutProperty(i,"icon-image",s)}else if(a&&t._map.getLayer(a)){var o=t._patternRegistry.getPatternImageId(r.style,e.id,t._pixelRatio);o&&t._map.setPaintProperty(a,"fill-pattern",o)}})})()}_registerPatternsAndSymbols(e){return this.addPatternsAndSymbolsToMap(e.patternConfigs,e.symbolConfigs)}removeDataset(e){var t=s.getDataset(e);if(t){var{sourceId:r,layerIds:a}=t;a.forEach(e=>this.removeLayer(e)),!s.topLevelDatasets().some(t=>t.id!==e&&t.sourceId===r)&&this._map.getSource(r)&&this._map.removeSource(r),this._datasetSourceMap.delete(e)}}applyFeatureFilter(e){var t=s.getDataset(e);t&&this._applyFeatureFilter(t)}applyStyle(t){var r=this;return e(function*(){var e=s.getDataset(t);e.layerIds.forEach(e=>r.removeLayer(e)),yield r._registerPatternsAndSymbols(e),r._addLayers(e)})()}setData(e,t){var r=this._datasetSourceMap.get(e);if(r){var a=this._map.getSource(r);a&&"function"==typeof a.setData&&a.setData(t)}}_addLayers(e){var{mapStyle:t}=s,r=c(this._map,e,t,this._symbolRegistry,this._patternRegistry,this._pixelRatio);this._datasetSourceMap.set(e.id,r),this._maintainSymbolOrdering(e)}_getFirstSymbolLayerId(){var e,t=this._map.getStyle();if(null==t||!t.layers)return null;var r=t.layers.find(e=>this._symbolLayerIds.has(e.id));return null!==(e=null==r?void 0:r.id)&&void 0!==e?e:null}_maintainSymbolOrdering(e){var t=(e=e.isSublayer?e.parent:e).layerIds.filter(e=>e&&this._map.getLayer(e));t.forEach(e=>{var t;"symbol"===(null===(t=this._map.getLayer(e))||void 0===t?void 0:t.type)?this._symbolLayerIds.add(e):this._symbolLayerIds.delete(e)});var r=this._getFirstSymbolLayerId();r&&t.forEach(e=>{this._symbolLayerIds.has(e)||this._map.moveLayer(e,r)})}_setLayerVisibility(e,t){this._map.getLayer(e)&&this._map.setLayoutProperty(e,"visibility",t)}_applyFeatureFilter(e){e.getLayersWithFilters().forEach(e=>{var{layerIds:t,filter:r}=e;t.forEach(e=>{this._map.getLayer(e)&&this._map.setFilter(e,r)})})}_setLayerOpacity(e,t){var r=this._map.getLayer(e);if(r){var a={line:"line-opacity",symbol:"icon-opacity"}[r.type]||"fill-opacity";this._map.setPaintProperty(e,a,t)}}_getLayersUsingSource(e){var t=this._map.getStyle();return null!=t&&t.layers?t.layers.filter(t=>t.source===e).map(e=>e.id):[]}}});export{v as L,p as M,n as a,y as b,h as c,_ as d,o as g,S as m};