@ndwnu/map 2.1.0 → 3.0.0
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/README.md +74 -2
- package/fesm2022/ndwnu-map.mjs +1249 -144
- package/fesm2022/ndwnu-map.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assets/sprites/custom_ndw.json +3628 -0
- package/src/assets/sprites/custom_ndw.png +0 -0
- package/src/assets/sprites/custom_ndw@2x.json +3628 -0
- package/src/assets/sprites/custom_ndw@2x.png +0 -0
- package/src/assets/sprites/sdf.json +834 -0
- package/src/assets/sprites/sdf.png +0 -0
- package/src/assets/sprites/sdf@2x.json +834 -0
- package/src/assets/sprites/sdf@2x.png +0 -0
- package/src/lib/style/style.json +970 -155
- package/types/ndwnu-map.d.ts +3 -2306
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ndwnu/map
|
|
2
2
|
|
|
3
|
-
A facade pattern library for MapLibre GL that simplifies the management of complex map sources and layers. Built by NDW (Nationaal
|
|
3
|
+
A facade pattern library for MapLibre GL that simplifies the management of complex map sources and layers. Built by NDW (Nationaal Dataportaal Wegverkeer) for easier development with MapLibre. It also contains the style json file that contains the NDW Basemap styling.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
@@ -11,8 +11,9 @@ This library provides a structured approach to managing MapLibre GL maps by intr
|
|
|
11
11
|
- **MapElement Pattern**: Groups multiple sources and layers into logical units
|
|
12
12
|
- **Visibility Management**: Easy show/hide functionality for complex map elements
|
|
13
13
|
- **Repository Pattern**: Centralized management of all map elements
|
|
14
|
+
- **NDW Basemap style**: A json file with the NDW basemap
|
|
14
15
|
|
|
15
|
-
## Installation
|
|
16
|
+
## Installation of @ndwnu/map
|
|
16
17
|
|
|
17
18
|
```bash
|
|
18
19
|
npm install @ndwnu/map maplibre-gl
|
|
@@ -291,6 +292,77 @@ Container for related sources and layers.
|
|
|
291
292
|
- `sources`: Array of MapSource instances
|
|
292
293
|
- `isVisible`: Current visibility state
|
|
293
294
|
|
|
295
|
+
## NDW Basemap style
|
|
296
|
+
|
|
297
|
+
The NDW modular basemap is a single MapLibre style file that lets developers compose the right map for their application by toggling grouped layers on and off. The core idea: separate **context** (the quiet reference map you pan and zoom across) from **relevant** (the bold, thematic overlay that tells the story).
|
|
298
|
+
|
|
299
|
+
### Context / relevant
|
|
300
|
+
|
|
301
|
+
- **Context layers** are unobtrusive — light, desaturated colors meant to support, not distract. Basemap, roads, admin boundaries, labels.
|
|
302
|
+
- **Relevant layers** are saturated and bold. They carry the data the user actually came for: accessibility, road safety, parking, your own datasets.
|
|
303
|
+
|
|
304
|
+
### Composition
|
|
305
|
+
|
|
306
|
+
Each layer carries a `metadata` block — group, sub-group, type, legend name, description. Metadata doesn't affect rendering, but it lets the app reason about layers at runtime:
|
|
307
|
+
|
|
308
|
+
```json
|
|
309
|
+
"metadata": {
|
|
310
|
+
"group": "context-roads",
|
|
311
|
+
"sub-group": "WKD-parking-areas",
|
|
312
|
+
"type": "context",
|
|
313
|
+
"legendName": "Parking areas",
|
|
314
|
+
"desc": ""
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Example of how to use groups / subgroups to display / hide a subset of layers with the @ndwnu/map MapElement structure:
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
export class NdwElement extends ApiElement<MapElementEnum, MapFilter, GrgLegendItem> {
|
|
322
|
+
constructor(config: GrgMapElementConfig, http: HttpClient) {
|
|
323
|
+
const layerFilter: NdwLayerFilterFunction = (layer) => {
|
|
324
|
+
return (
|
|
325
|
+
layer.metadata.group === 'context-map' ||
|
|
326
|
+
(layer.metadata.group === 'context-roads' &&
|
|
327
|
+
layer.metadata['sub-group'] !== 'NWB-hectometersigns' &&
|
|
328
|
+
layer.metadata.group === 'context-roads' &&
|
|
329
|
+
layer.metadata['sub-group'] !== 'WKD-parking-areas' &&
|
|
330
|
+
layer.metadata.group === 'context-roads' &&
|
|
331
|
+
layer.metadata['sub-group'] !== 'FCD-segments')
|
|
332
|
+
);
|
|
333
|
+
};
|
|
334
|
+
super(
|
|
335
|
+
config,
|
|
336
|
+
http,
|
|
337
|
+
environment.mapStyles.ndw,
|
|
338
|
+
layerFilter as (layer: LayerSpecification) => boolean,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
When you don't use the MapElement structure, toggle a whole group with plain JavaScript:
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
function toggleGroupLayers(group: string) {
|
|
348
|
+
const style = map.getStyle();
|
|
349
|
+
style.layers.forEach((layer) => {
|
|
350
|
+
if (layer.metadata?.group === group) {
|
|
351
|
+
const visibility = map.getLayoutProperty(layer.id, 'visibility') || 'visible';
|
|
352
|
+
map.setLayoutProperty(layer.id, 'visibility', visibility === 'none' ? 'visible' : 'none');
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Include in your project
|
|
359
|
+
|
|
360
|
+
You can either import the style file via `import` and provide it to MapLibre, or you can use the url on maps.ndw.nu:
|
|
361
|
+
|
|
362
|
+
https://maps.ndw.nu/styles/ndw-basemap/dev/style.json
|
|
363
|
+
|
|
364
|
+
TODO when style.json hosting task is done by NLS update URL here. [NLS story](https://dev.azure.com/ndwnu/NLS/_workitems/edit/115149)
|
|
365
|
+
|
|
294
366
|
## License
|
|
295
367
|
|
|
296
368
|
MIT
|