@nika-js/onlymap 0.13.3 → 0.13.5

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 (71) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +9 -5
  3. package/dist/actions.d.ts +12 -6
  4. package/dist/attribute-resolution.d.ts +32 -4
  5. package/dist/{basemap-5NHR6Gio.js → basemap-CErNEhX6.js} +3 -7
  6. package/dist/basemap.d.ts +1 -5
  7. package/dist/bbox-tokens.d.ts +70 -0
  8. package/dist/{build-DJjheWZ2.js → build-ByNIb4VX.js} +1 -1
  9. package/dist/{client-0mQmDog8.js → client-xe2E4jg4.js} +2 -2
  10. package/dist/clip-box-controller.d.ts +0 -17
  11. package/dist/ctx.d.ts +17 -0
  12. package/dist/data-layer.d.ts +15 -8
  13. package/dist/dom-tile-layer.d.ts +30 -0
  14. package/dist/draw-controller.d.ts +1 -1
  15. package/dist/elements/om-map.d.ts +12 -1
  16. package/dist/feature-service.d.ts +42 -0
  17. package/dist/geodesy.d.ts +6 -5
  18. package/dist/{geoparquet-B_nO2OyP.js → geoparquet-DOhMQl-X.js} +1 -1
  19. package/dist/{globe-view-BFUa9ksE.js → globe-view-84s_uNZX.js} +1 -1
  20. package/dist/grid-tiles.d.ts +117 -0
  21. package/dist/{hillshade-B_CxPhtA.js → hillshade-D8h8CRQq.js} +2 -2
  22. package/dist/{hillshade-shader-r7GxxjXj.js → hillshade-shader-Bm1O0P76.js} +1 -1
  23. package/dist/{index-YMu_yLXO.js → index-4Y4Q7RP4.js} +3 -3
  24. package/dist/{index-DWijIMti.js → index-BG_49YHy.js} +33543 -32098
  25. package/dist/index-BahtHUrg.js +8458 -0
  26. package/dist/{index-ChmxbIdj.js → index-DTN2CcOQ.js} +43 -43
  27. package/dist/{index-BvNxS6dM.js → index-DXxQu9Xi.js} +1 -1
  28. package/dist/{index-A1FYw2dy.js → index-D_EiGesl.js} +1 -1
  29. package/dist/{index-CObPGkze.js → index-DrSCLk9i.js} +22 -22
  30. package/dist/{index-CU7RnKnO.js → index-J_Sj6T0S.js} +32 -32
  31. package/dist/index-bpdGuZR6.js +478 -0
  32. package/dist/{index-CgIuV5Oh.js → index-phbljJTZ.js} +3 -3
  33. package/dist/index.d.ts +1 -1
  34. package/dist/ir-snapshot.d.ts +2 -0
  35. package/dist/ir.d.ts +18 -0
  36. package/dist/layer-registry.d.ts +1 -0
  37. package/dist/layers/warped-bitmap-layer.d.ts +14 -1
  38. package/dist/{lerc-Bl4vym9y.js → lerc-DLWS3sYw.js} +1 -1
  39. package/dist/onlymap.standalone.js +69300 -58870
  40. package/dist/onlymapjs.js +25 -25
  41. package/dist/parse-manifest.d.ts +4 -1
  42. package/dist/plane-gpu/plane-basemap.d.ts +237 -237
  43. package/dist/plane-vector/plane-mvt-layer.d.ts +237 -237
  44. package/dist/plane-warp.d.ts +14 -1
  45. package/dist/pmtiles.d.ts +76 -0
  46. package/dist/{post-process-effect-gFGVlC77.js → post-process-effect-CHsD0-oP.js} +1 -1
  47. package/dist/programmatic.d.ts +21 -1
  48. package/dist/{raster-1ShXyF12.js → raster-B7ILGg0X.js} +4 -4
  49. package/dist/{raster-pipeline-BMS54TX2.js → raster-pipeline-avMAbONM.js} +11 -11
  50. package/dist/react/om-layer.d.ts +4 -0
  51. package/dist/react.js +67 -65
  52. package/dist/runtime-core.d.ts +106 -4
  53. package/dist/serialize/emit.d.ts +2 -0
  54. package/dist/serialize/index.d.ts +2 -0
  55. package/dist/{terrain-inspect-Cndlmxig.js → terrain-inspect-FKTVm7nv.js} +1 -1
  56. package/dist/{text-on-path-QInco4aP.js → text-on-path-CpHM02Fs.js} +19 -18
  57. package/dist/tile-url.d.ts +84 -16
  58. package/dist/time-dimension.d.ts +25 -0
  59. package/dist/vector-style-CPvUSy2F.js +518 -0
  60. package/dist/vector-style.d.ts +59 -0
  61. package/dist/version.d.ts +1 -1
  62. package/dist/{zarr-CYD8fyBe.js → zarr-DpbT4eyF.js} +2 -2
  63. package/dist/zoom-gates.d.ts +60 -0
  64. package/docs/cartograph.md +2 -2
  65. package/llms.txt +4 -3
  66. package/onlymapjs.attributes.json +17 -0
  67. package/onlymapjs.html-data.json +56 -0
  68. package/package.json +5 -2
  69. package/skills/onlymapjs/SKILL.md +10 -3
  70. package/skills/onlymapjs/references/syntax.md +64 -7
  71. package/dist/index-DT5d7kFO.js +0 -459
@@ -16,8 +16,8 @@ Vite/npm project:
16
16
  Static CDN page (raw-file CDNs only — unpkg/jsDelivr; never esm.sh or another rebundling CDN, which duplicates the WebGL runtime and breaks layer shaders):
17
17
 
18
18
  ```html
19
- <link rel="stylesheet" href="https://unpkg.com/@nika-js/onlymap@0.13.3/dist/onlymapjs.css">
20
- <script type="module" src="https://unpkg.com/@nika-js/onlymap@0.13.3"></script>
19
+ <link rel="stylesheet" href="https://unpkg.com/@nika-js/onlymap@0.13.5/dist/onlymapjs.css">
20
+ <script type="module" src="https://unpkg.com/@nika-js/onlymap@0.13.5"></script>
21
21
  ```
22
22
 
23
23
  Always include `onlymapjs.css` — it carries the MapLibre basemap styles and the no-JS fallback rules (`<om-fallback>` / default banner). For the fallback to work in script-disabled previews it must load without JavaScript: a real `<link rel="stylesheet">` or inlined `<style>` on no-build pages (a bundler-emitted stylesheet is fine in npm projects).
@@ -89,7 +89,7 @@ Common attributes:
89
89
  - `widgets-dim="off"` disables collision-dim — by default a widget slot dims (`--om-widget-opacity-dimmed`, 0.35) while an open `<om-overlay>` popup covers it, rather than the popup dodging (attribution/toggle slots never dim).
90
90
  - `headless width="800" height="600"` for test harness use
91
91
 
92
- Events: `om-map-ready` (boot complete; `await mapEl.ready` is the promise twin), `om-validation-error`, `om-view-changed` — fires once the camera settles after a move (debounced; `detail = {longitude, latitude, zoom, pitch, bearing}`), the hook for persisting the camera — `om-map-point` (`detail = {coordinate: [lng,lat]|null, kind: "click"|"hover"}` — every click/hover map coordinate, including empty-map clicks; the hook for custom capture tools the built-in draw widget doesn't cover), and `om-tileset-load` (`detail = {layerId, tileset}` — a `Tile3DLayer`'s live deck `Tileset3D`, for tools needing the real tileset such as region export). `om-attributions-changed` bubbles when a basemap style loads; `mapEl.attributions()` then returns its providers as plain text. `MapController` mirrors these as `onViewChange` / `onMapPoint` / `onTilesetLoad` options.
92
+ Events: `om-map-ready` (boot complete; `await mapEl.ready` is the promise twin), `om-validation-error`, `om-view-changed` — fires once the camera settles after a move (debounced; `detail = {longitude, latitude, zoom, pitch, bearing}`), the hook for persisting the camera — `om-map-point` (`detail = {coordinate: [lng,lat]|null, kind: "click"|"hover"}` — every click/hover map coordinate, including empty-map clicks; the hook for custom capture tools the built-in draw widget doesn't cover), `om-tileset-load` (`detail = {layerId, tileset}` — a `Tile3DLayer`'s live deck `Tileset3D`, for tools needing the real tileset such as region export), and `om-layer-error` (`detail = {layerId, severity, cause, status?, host, message, fix}` — a layer's tiles failed; once per cause, validating or not). `om-attributions-changed` bubbles when a basemap style loads; `mapEl.attributions()` then returns its providers as plain text. `MapController` mirrors these as `onViewChange` / `onMapPoint` / `onTilesetLoad` / `onLayerError` options.
93
93
 
94
94
  `await mapEl.snapshot()` (also on `MapController`) returns a canvas-only PNG dataURL of the scene — basemap + layers composited at device pixels (`{as: "blob"}` for files; `type`/`quality` for jpeg/webp). DOM widgets, overlays, and the provider attribution are NOT in the pixels: exports must render credits themselves. Await `ready` first; headless maps reject.
95
95
 
@@ -175,6 +175,33 @@ One `<om-widget type="filter">` per dimension — each moves its own field's ran
175
175
 
176
176
  `visible-zoom-range="[8, 14]"` — scale-dependent visibility, the QGIS/ArcGIS/Mapbox everyday pattern: the layer renders only at min ≤ zoom < max (min inclusive, max exclusive — the minzoom/maxzoom convention). Universal: valid on every layer type, unlike the tile-only `visible-min-zoom`/`visible-max-zoom` deck props. Composes with `visible` (both must allow); a zoom-hidden layer stays a full scene member — legend, layer-switcher, and `ctx` still list it. Malformed values are ignored with a warning (`validate` reports them structurally).
177
177
 
178
+ ## Per-feature minimum zoom (any layer type)
179
+
180
+ `min-zoom-field="minzoom"` — each FEATURE draws only while the camera zoom is ≥ the value in that property (inclusive, against the exact fractional zoom: `12.8` appears at 12.8, not 13). The per-feature twin of `visible-zoom-range`: label staging ("show each label from the zoom where it has room"), detail that fills in as the reader zooms. Evaluated on the GPU against the live camera, so features appear smoothly DURING a zoom; nothing is written to the document, the undo history or a save.
181
+
182
+ ```html
183
+ <om-layer id="parcel-labels" type="TextLayer" min-zoom-field="minzoom"
184
+ get-position="$geometry.coordinates" get-text="$properties.name">
185
+ <script type="application/json">{"type":"FeatureCollection","features":[
186
+ {"type":"Feature","geometry":{"type":"Point","coordinates":[0,0]},"properties":{"name":"A","minzoom":0}},
187
+ {"type":"Feature","geometry":{"type":"Point","coordinates":[0.001,0]},"properties":{"name":"B","minzoom":12.8}}
188
+ ]}</script>
189
+ </om-layer>
190
+ ```
191
+
192
+ - A missing, null or non-numeric value means "always drawn" (numeric strings like `"12"` count as numbers).
193
+ - Composes (AND) with `visible`, `visible-zoom-range` and every `filter-*`. A hidden feature is not pickable.
194
+ - It is presentation, NOT a data filter: `ctx.layers[].filter`, the `filter` widget and `ctx.stats` see only the authored filter and count every row.
195
+ - It takes one of the layer's 4 GPU filter slots: at most 3 `filter-fields` alongside it (`validate` errors at 4; the runtime then ignores `min-zoom-field` with a warning — never the authored filter).
196
+ - `snapshot({ format: "svg" })` leaves out features below their min zoom at the capture zoom.
197
+ - Descriptor (`MapController`) and React: `minZoomField: "minzoom"`.
198
+ - Not on tiled layers (`MVTLayer`, `TileLayer`, …), aggregation layers (`HexagonLayer`, `HeatmapLayer`, …) or with `cluster="true"` — there are no per-row marks to gate there (a cluster bubble would count the hidden rows); the runtime ignores it with a warning and `validate` says so.
199
+ - Never script this with an `om-view-changed` listener rewriting `filter-range` — that writes view state into the document on every zoom step and only updates after the camera settles.
200
+
201
+ ## Keeping a helper layer out of the legend (`listed="false"`)
202
+
203
+ `listed="false"` on an `<om-layer>` keeps it out of the `legend` and `layer-switcher` widgets — for a helper layer that would read as a duplicate (dots marking where a label is still hidden, a halo under the real layer). It stays a full scene member: in `ctx.layers` (with `listed: false`), toggleable and filterable by actions. Descriptor (`MapController`): `listed: false`; React: `listed={false}`.
204
+
178
205
  ## Clustering (`ScatterplotLayer`, `GeoJsonLayer` with Point features, `IconLayer`)
179
206
 
180
207
  `cluster="true"` merges points that would overlap on screen into count bubbles that split apart as the reader zooms in. A TOGGLE on the point layer, never a separate layer type: the layer keeps its id, data, its own `get-*` symbology for the points that stand alone at the current zoom, its picks, behaviors and actions.
@@ -451,14 +478,44 @@ deck's `TileLayer` and `MVTLayer` take their `data` prop as a `{z}/{x}/{y}` URL
451
478
  get-line-color="'#38bdf8'" line-width-min-pixels="1"></om-layer>
452
479
  ```
453
480
 
454
- A WMS, or any service addressed by extent rather than tile index, is a raster `TileLayer` too. Besides deck's `{z}` `{x}` `{y}` `{-y}`, a raster `TileLayer` fills `{bbox-epsg-3857}` (each tile's Web Mercator extent in metres, `minx,miny,maxx,maxy` — WMS 1.1.1/1.3.0 axis order for EPSG:3857), `{width}`/`{height}` (the layer's `tile-size`, default 512) and `{quadkey}` (Bing-style). Ask for EPSG:3857 and name the format (`FORMAT=image/png`, or `format=png` on an ArcGIS export), which is how the layer knows it is imagery:
481
+ A WMS, or any service addressed by extent rather than tile index, is a raster `TileLayer` too. Besides deck's `{z}` `{x}` `{y}` `{-y}`, a raster `TileLayer` fills `{bbox-epsg-3857}` (each tile's Web Mercator extent in metres, `minx,miny,maxx,maxy` — WMS 1.1.1/1.3.0 axis order for EPSG:3857), `{width}`/`{height}` (the layer's `tile-size`, default 512) and `{quadkey}` (Bing-style). Ask for EPSG:3857 and an image format (`FORMAT=image/png`, or `format=png` on an ArcGIS export). A template counts as imagery unless it asks for a vector format (`.pbf`, `.mvt`, `.json`, `f=json`), so an address with no extension at all (an ArcGIS cache's `…/MapServer/tile/{z}/{y}/{x}`) works as written, and a tile that arrives as GeoJSON anyway is drawn as GeoJSON:
455
482
 
456
483
  ```html
457
484
  <om-layer id="wms" type="TileLayer" tile-size="512"
458
485
  data="https://example.org/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=a,b&STYLES=&FORMAT=image/png&TRANSPARENT=true&CRS=EPSG:3857&WIDTH={width}&HEIGHT={height}&BBOX={bbox-epsg-3857}"></om-layer>
459
486
  ```
460
487
 
461
- It works on a projected (`crs`) map as well: the tiles are Web Mercator tiles warped into the plane. Any other token (`{s}`, QGIS's `{q}`) is a validation error, since it would be requested literally. The service must send `Access-Control-Allow-Origin` (`*` for a page opened from `file://`); an `http://` service inside an `https://` page is blocked by the browser. A failed tile is left empty while the rest of the map draws, and each cause — CORS, an HTTP status, a WMS ServiceException (quoted) — is reported once per layer on the validation channel (`om-validation-error`, the on-page panel with `validate`).
488
+ It works on a projected (`crs`) map as well: the tiles are Web Mercator tiles warped into the plane.
489
+
490
+ More tokens, for services as QGIS users meet them:
491
+
492
+ - `{bbox-epsg-XXXX}` — a WMS that offers no Web Mercator: ask in its own CRS (`CRS=EPSG:25832&BBOX={bbox-epsg-25832}`). Each tile asks for the box enclosing it in that CRS, written in the CRS's EPSG axis order (latitude first for EPSG:4326 under WMS 1.3.0; a WMS 1.1.1 `SRS=` request is always x,y), and the picture is warped onto the tile. `{bbox-crs84}` is always longitude first.
493
+ - `{s}` — Leaflet's subdomain token, spread across `subdomains` (`"abc"`, `"a,b,c"` or a JSON array; default a, b, c).
494
+ - `{time}` (or WMTS's `{Time}`) — filled from the layer's `time` (a WMS-T `TIME=`, a WMTS time dimension such as swisstopo's `current`); `<om-widget type="time-slider" layer="wms" times="2024-01-01/2024-03-01/P1D">` steps it through a comma list or a WMS dimension's `start/end/period`, with play, scrub and undo.
495
+ - `{TileMatrix}` `{TileRow}` `{TileCol}` — a WMTS on a national grid, with the grid as `tile-matrix-set` (the OGC tile matrix set, the WMTS `TileMatrixSet` from GetCapabilities, or `{crs, origin, resolutions, tileSize, extent?}` — `extent` keeps requests inside the grid — as JSON). The level nearest the view's resolution is chosen and each tile is warped onto the map:
496
+
497
+ ```html
498
+ <om-layer id="swiss" type="TileLayer"
499
+ data="https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/{Time}/2056/{TileMatrix}/{TileCol}/{TileRow}.jpeg" time="current"
500
+ tile-matrix-set='{"crs":"EPSG:2056","origin":[2420000,1350000],"extent":[2420000,1030000,2900000,1350000],"resolutions":[4000,3750,3500,3250,3000,2750,2500,2250,2000,1750,1500,1250,1000,750,650,500,250,100,50,20,10,5,2.5,2,1.5,1,0.5],"tileSize":256,"matrixIds":["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26"]}'></om-layer>
501
+ ```
502
+
503
+ A PMTiles archive is a `data` URL like any other — `data="./tiles.pmtiles"` on an `MVTLayer` (vector) or `TileLayer` (raster), read with HTTP Range requests; the archive's zoom range is applied, so deep zooms overzoom.
504
+
505
+ An `MVTLayer` can draw with its publisher's MapLibre style: `vector-style="…/style.json"` (and `vector-style-source` when the style has several vector sources). Its fill, line, circle, fill-extrusion and symbol layers draw in the style's order, by its own filters and zoom functions (MapLibre's expression engine); labels are one per feature, avoiding each other by priority, in the browser's fonts. Background, raster, hillshade and heatmap layers are not drawn (a warning lists them), and it is for Web Mercator maps. For the publisher's whole map as the base, `basemap="…/style.json"`.
506
+
507
+ Any other token (QGIS's `{q}`) is a validation error, since it would be requested literally. The service should send `Access-Control-Allow-Origin` (`*` for a page opened from `file://`). One that does not — or an `http://` service inside an `https://` page — cannot be drawn by WebGL; when its tiles load as plain images, the layer is drawn that way, under the map: beneath every other layer (with a basemap, above it), hidden while the map is tilted or rotated, and left out of snapshots and exports. `cors-fallback="off"` leaves it empty instead. A failed tile is left empty while the rest of the map draws, and each cause — CORS, an HTTP status, a WMS ServiceException (quoted) — is reported once per layer: always as an `om-layer-error` event on the map (`detail = {layerId, severity, cause: "network"|"http"|"service-exception"|"other"|"cors-fallback", status?, host, message, fix}` — what a page uses to tell its readers a layer failed or fell back), and on the validation channel (`om-validation-error`, the on-page panel with `validate`). Changing the layer's `data` withdraws the old template's reports.
508
+
509
+ ### Live features for the area in view (WFS, OGC API Features, ArcGIS)
510
+
511
+ An extent token in a NON-tiled layer's `data` makes it a request for the area in view, made again when the view settles somewhere new:
512
+
513
+ ```html
514
+ <om-layer id="parcels" type="GeoJsonLayer" max-features="5000"
515
+ data="https://example.org/ogc/collections/parcels/items?bbox={bbox-crs84}&f=json"></om-layer>
516
+ ```
517
+
518
+ `{bbox-crs84}` is longitude first (OGC API `bbox=`, an ArcGIS `geometry=…&geometryType=esriGeometryEnvelope&inSR=4326`); `{bbox-epsg-4326}` is latitude first, as a WFS 2.0 `BBOX=…,urn:ogc:def:crs:EPSG::4326` wants; `{bbox-epsg-XXXX}` any other CRS. Paging is followed — WFS `STARTINDEX` in steps of `COUNT`, OGC API `next` links, ArcGIS `resultOffset` while `exceededTransferLimit` — up to `max-features` (default 10000); a view with more is reported, not silently cut. Responses must be GeoJSON (`outputFormat=application/json`, `f=geojson`). Requests are made for a padded view, so a small pan asks nothing; `whenSettled()` waits for them; a failure is an `om-layer-error` like a tile's.
462
519
 
463
520
  `$field` accessors on an `MVTLayer` read the tile feature's `properties`. A tiled layer has no local rows, so `ctx.data()`/`ctx.stats()`/`filter-*` do not apply to it. For a raster `TileLayer` pointing at a non-image endpoint (vector tiles, custom decoding), register a custom layer with your own `renderSubLayers` via `OmMap.registerLayer`.
464
521
 
@@ -550,7 +607,7 @@ Do not use full-JS blocks on columnar/Arrow layers.
550
607
  Built-ins:
551
608
 
552
609
  - `legend` — symbology-aware by default: it parses each layer's `get-fill-color`. A `sequential`/`diverging` `scale()` renders as a gradient ramp with the domain ends labeled; a `threshold` scale as discrete class ranges (`< b1`, `b1 – b2`, `≥ bN`); an equality ternary chain (`$f == 'a' ? '#c1' : $f == 'b' ? '#c2' : '#fallback'`) as a category palette with an "other" row. Any other expression falls back to the single `color` swatch — so writing the canonical shapes buys a self-describing legend for free.
553
- - `layer-switcher`
610
+ - `layer-switcher` — one visibility checkbox per layer. Both it and `legend` skip layers marked `listed="false"`.
554
611
  - `zoom-controls`
555
612
  - `scale-bar` — `units="metric|imperial|nautical"` (default metric) picks the length system; snaps to a nice round distance.
556
613
  - `attribution`
@@ -635,7 +692,7 @@ watched token fires:
635
692
  - `ctx.dataInViewport(id)`
636
693
  - `ctx.stats(id, field, { scope: "viewport" })`
637
694
  - `ctx.selection`
638
- - `ctx.viewport`
695
+ - `ctx.viewport` — `{ bounds, zoom, center, metersPerPixel, project(lngLat) }`; `metersPerPixel` is the ground scale across the view centre, measured through the map's own projection (right on a `crs` map and at any latitude) — use it for anything drawn to scale
639
696
  - `ctx.features(layerId)` — the decoded `EXT_structural_metadata` property table of a `pick-features` tileset, one row per element, or `undefined` before the first tile carrying one has landed. This is what a BIM panel groups and counts by; pair it with the `features` watch token, since the table cannot exist on the first render.
640
697
  - `ctx.history` — `{ canUndo, canRedo }`; re-render on changes via the `history` watch token
641
698
  - `ctx.emit(action, payload)`
@@ -1,459 +0,0 @@
1
- import { aQ as B } from "./index-DWijIMti.js";
2
- const V = /* @__PURE__ */ new Set([
3
- "GeoJsonLayer",
4
- "PolygonLayer",
5
- "SolidPolygonLayer",
6
- "PathLayer",
7
- "LineLayer",
8
- "ScatterplotLayer",
9
- "PointCloudLayer",
10
- "ArcLayer",
11
- "TripsLayer",
12
- "Route",
13
- "Tracking"
14
- ]), Z = /* @__PURE__ */ new Set(["TextLayer"]), q = /* @__PURE__ */ new Set(["TextOnPathLayer"]), J = /* @__PURE__ */ new Set([
15
- "COGLayer",
16
- "ZarrLayer",
17
- "BitmapLayer",
18
- "ImageOverlay",
19
- "TileLayer",
20
- "MVTLayer",
21
- "HillshadeLayer",
22
- "Tile3DLayer",
23
- "BIMLayer",
24
- "ScenegraphLayer",
25
- "SimpleMeshLayer",
26
- "TerrainLayer",
27
- "HeatmapLayer",
28
- "HexagonLayer",
29
- "GridLayer",
30
- "ContourLayer",
31
- "ScreenGridLayer"
32
- ]);
33
- function ot(t) {
34
- return q.has(t) ? "path-text" : Z.has(t) ? "text" : V.has(t) ? "vector" : (J.has(t), "raster");
35
- }
36
- function rt(t) {
37
- return V.has(t) || Z.has(t) || q.has(t) || J.has(t);
38
- }
39
- function it(t) {
40
- const e = [];
41
- for (const o of t) {
42
- const r = ot(o.type), n = e[e.length - 1];
43
- n && n.strategy === "raster" && r === "raster" ? n.ids.push(o.id) : e.push({ strategy: r, ids: [o.id] });
44
- }
45
- return e;
46
- }
47
- function W(t, e) {
48
- return e[0] >= t.left && e[0] <= t.right && e[1] >= t.top && e[1] <= t.bottom;
49
- }
50
- function Q(t, e) {
51
- let o = 1 / 0, r = 1 / 0, n = -1 / 0, i = -1 / 0;
52
- for (const [s, c] of t)
53
- s < o && (o = s), s > n && (n = s), c < r && (r = c), c > i && (i = c);
54
- return n < e.left || o > e.right || i < e.top || r > e.bottom;
55
- }
56
- function st(t, e, o) {
57
- const r = e[0] - t[0], n = e[1] - t[1];
58
- let i = 0, s = 1;
59
- const c = (f, u) => {
60
- if (f === 0) return u >= 0;
61
- const p = u / f;
62
- if (f < 0) {
63
- if (p > s) return !1;
64
- p > i && (i = p);
65
- } else {
66
- if (p < i) return !1;
67
- p < s && (s = p);
68
- }
69
- return !0;
70
- };
71
- return !c(-r, t[0] - o.left) || !c(r, o.right - t[0]) || !c(-n, t[1] - o.top) || !c(n, o.bottom - t[1]) ? null : [
72
- [t[0] + i * r, t[1] + i * n],
73
- [t[0] + s * r, t[1] + s * n]
74
- ];
75
- }
76
- function tt(t, e) {
77
- if (t.length < 2) return W(e, t[0] ?? [NaN, NaN]) ? [[...t]] : [];
78
- if (Q(t, e)) return [];
79
- const o = [];
80
- let r = null;
81
- for (let n = 0; n + 1 < t.length; n++) {
82
- const i = st(t[n], t[n + 1], e);
83
- if (!i) {
84
- r = null;
85
- continue;
86
- }
87
- const [s, c] = i;
88
- r && r[r.length - 1][0] === s[0] && r[r.length - 1][1] === s[1] ? r.push(c) : (r = [s, c], o.push(r));
89
- }
90
- return o;
91
- }
92
- function H(t, e, o) {
93
- switch (o) {
94
- case "left":
95
- return t[0] >= e.left;
96
- case "right":
97
- return t[0] <= e.right;
98
- case "top":
99
- return t[1] >= e.top;
100
- case "bottom":
101
- return t[1] <= e.bottom;
102
- }
103
- }
104
- function X(t, e, o, r) {
105
- const n = e[0] - t[0], i = e[1] - t[1];
106
- switch (r) {
107
- case "left":
108
- return [o.left, t[1] + i * (o.left - t[0]) / n];
109
- case "right":
110
- return [o.right, t[1] + i * (o.right - t[0]) / n];
111
- case "top":
112
- return [t[0] + n * (o.top - t[1]) / i, o.top];
113
- case "bottom":
114
- return [t[0] + n * (o.bottom - t[1]) / i, o.bottom];
115
- }
116
- }
117
- function at(t, e) {
118
- if (t.length < 3) return [];
119
- if (Q(t, e)) return [];
120
- let o = t;
121
- for (const r of ["left", "right", "top", "bottom"]) {
122
- const n = o;
123
- if (o = [], n.length === 0) return [];
124
- let i = n[n.length - 1];
125
- for (let s = 0; s < n.length; s++) {
126
- const c = n[s], f = H(c, e, r), u = H(i, e, r);
127
- f ? (u || o.push(X(i, c, e, r)), o.push(c)) : u && o.push(X(i, c, e, r)), i = c;
128
- }
129
- }
130
- return o;
131
- }
132
- const Y = (t) => Math.max(0, Math.min(255, Math.round(t)));
133
- function E(t) {
134
- if (!Array.isArray(t) || t.length < 3) return { color: "#000000", opacity: 1 };
135
- const [e, o, r, n] = t, i = (s) => Y(s).toString(16).padStart(2, "0");
136
- return {
137
- color: `#${i(e)}${i(o)}${i(r)}`,
138
- // deck's alpha DEFAULT is 255, not 0 — an absent fourth component means
139
- // opaque. Reading it as zero would emit a whole invisible sheet.
140
- opacity: n === void 0 ? 1 : Y(n) / 255
141
- };
142
- }
143
- function D(t, e, o, r, n) {
144
- if (typeof t == "function")
145
- try {
146
- return t(e, { index: o, data: r });
147
- } catch {
148
- return n;
149
- }
150
- return t === void 0 ? n : t;
151
- }
152
- const L = (t, e) => typeof t == "number" && Number.isFinite(t) ? t : e, ct = ["getLineColor", "getColor", "getSourceColor"], lt = ["getLineWidth", "getWidth"], ut = ["lineWidthScale", "widthScale"], ft = ["lineWidthUnits", "widthUnits"], dt = ["lineWidthMinPixels", "widthMinPixels"], ht = ["lineWidthMaxPixels", "widthMaxPixels"], pt = ["getRadius", "getPointRadius"], gt = ["radiusScale", "pointRadiusScale"], mt = ["radiusUnits", "pointRadiusUnits"], yt = ["radiusMinPixels", "pointRadiusMinPixels"], xt = ["radiusMaxPixels", "pointRadiusMaxPixels"];
153
- function $(t, e) {
154
- for (const o of e) if (t[o] !== void 0) return t[o];
155
- }
156
- function $t(t, e, o, r) {
157
- const n = t.props, i = L(D($(n, lt), e, o, t.data, 1), 1), s = L($(n, ut), 1);
158
- let u = ($(n, ft) === "meters" ? "meters" : "pixels") === "meters" ? i * s / Math.max(r, 1e-9) : i * s;
159
- u = Math.max(u, L($(n, dt), 0));
160
- const p = $(n, ht);
161
- return typeof p == "number" && Number.isFinite(p) && (u = Math.min(u, p)), u;
162
- }
163
- function Pt(t, e, o, r) {
164
- const n = t.props, i = L(D($(n, pt), e, o, t.data, 1), 1), s = L($(n, gt), 1);
165
- let f = ($(n, mt) === "pixels" ? "pixels" : "meters") === "pixels" ? i * s : i * s / Math.max(r, 1e-9);
166
- f = Math.max(f, L($(n, yt), 0));
167
- const u = $(n, xt);
168
- return typeof u == "number" && Number.isFinite(u) && (f = Math.min(f, u)), f;
169
- }
170
- function bt(t, e) {
171
- const o = t.props.getDashArray ?? t.props.dashArray, r = typeof o == "function" ? void 0 : o;
172
- if (!Array.isArray(r) || r.length < 2) return;
173
- const [n, i] = r;
174
- if (!Number.isFinite(n) || !Number.isFinite(i) || n <= 0 && i <= 0) return;
175
- const s = Math.max(e, 1e-6);
176
- return `${(n * s).toFixed(3)} ${(i * s).toFixed(3)}`;
177
- }
178
- function St(t, e, o, r) {
179
- const n = t.props, i = L(n.opacity, 1), s = E(D(n.getFillColor, e, o, t.data, [0, 0, 0, 255])), c = E(D($(n, ct), e, o, t.data, [0, 0, 0, 255])), f = $t(t, e, o, r);
180
- return {
181
- fill: n.filled === !1 ? "none" : s.color,
182
- fillOpacity: s.opacity * i,
183
- // `stroked: false` is a POLYGON prop. A PathLayer has no such prop and is
184
- // nothing but stroke, so an absent `stroked` must read as "yes", not as
185
- // deck's polygon default.
186
- stroke: n.stroked === !1 ? "none" : c.color,
187
- strokeOpacity: c.opacity * i,
188
- strokeWidth: f,
189
- dashArray: bt(t, f),
190
- radius: Pt(t, e, o, r)
191
- };
192
- }
193
- function N(t, e) {
194
- const o = [];
195
- return e === "area" ? (o.push(`fill="${t.fill}"`), t.fill !== "none" && t.fillOpacity < 1 && o.push(`fill-opacity="${t.fillOpacity.toFixed(4)}"`)) : o.push('fill="none"'), t.stroke !== "none" && t.strokeWidth > 0 && (o.push(`stroke="${t.stroke}"`), o.push(`stroke-width="${t.strokeWidth.toFixed(3)}"`), t.strokeOpacity < 1 && o.push(`stroke-opacity="${t.strokeOpacity.toFixed(4)}"`), t.dashArray && o.push(`stroke-dasharray="${t.dashArray}"`), o.push('stroke-linejoin="round"', 'stroke-linecap="round"')), o.join(" ");
196
- }
197
- function wt(t, e, o) {
198
- return !(t.right + o < e.left || e.right + o < t.left || t.bottom + o < e.top || e.bottom + o < t.top);
199
- }
200
- function At(t, e = 2) {
201
- const o = t.map((i, s) => ({ box: i, index: s })).sort((i, s) => s.box.priority - i.box.priority || i.index - s.index), r = [], n = [];
202
- for (const { box: i, index: s } of o) {
203
- let c = !1;
204
- for (const f of r)
205
- if (wt(i, f, e)) {
206
- c = !0;
207
- break;
208
- }
209
- c || (r.push(i), n.push(s));
210
- }
211
- return n.sort((i, s) => i - s);
212
- }
213
- function Tt(t, e, o, r, n = "middle", i = "center") {
214
- const s = t.length * r * 0.6, c = r * 1.2, f = n === "start" ? e : n === "end" ? e - s : e - s / 2, u = i === "top" ? o : i === "bottom" ? o - c : o - c / 2;
215
- return { left: f, top: u, right: f + s, bottom: u + c };
216
- }
217
- const G = 32, z = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), S = (t) => z(t).replace(/"/g, "&quot;"), y = (t) => (Math.round(t * 100) / 100).toString();
218
- function j(t, e) {
219
- const o = [];
220
- for (const r of t)
221
- if (!(r.length < 2)) {
222
- o.push(`M${y(r[0][0])} ${y(r[0][1])}`);
223
- for (let n = 1; n < r.length; n++) o.push(`L${y(r[n][0])} ${y(r[n][1])}`);
224
- e && o.push("Z");
225
- }
226
- return o.join("");
227
- }
228
- const et = { rings: [], kind: "line" };
229
- function Lt(t) {
230
- const e = t, o = e?.type ?? "", r = e?.coordinates;
231
- switch (o) {
232
- case "Polygon":
233
- return { rings: r, kind: "area" };
234
- case "MultiPolygon":
235
- return { rings: r.flat(), kind: "area" };
236
- case "LineString":
237
- return { rings: [r], kind: "line" };
238
- case "MultiLineString":
239
- return { rings: r, kind: "line" };
240
- case "Point":
241
- return { rings: [[r]], kind: "point" };
242
- case "MultiPoint":
243
- return { rings: [r], kind: "point" };
244
- default:
245
- return et;
246
- }
247
- }
248
- const C = (t) => Array.isArray(t) && typeof t[0] == "number" && typeof t[1] == "number", U = (t) => Array.isArray(t) && C(t[0]);
249
- function kt(t, e, o, r) {
250
- const n = (p) => {
251
- const d = t[p];
252
- if (d !== void 0) {
253
- if (typeof d != "function") return d;
254
- try {
255
- return d(e, { index: o, data: r });
256
- } catch {
257
- return;
258
- }
259
- }
260
- }, i = n("getPolygon");
261
- if (U(i)) return { rings: [i], kind: "area" };
262
- if (Array.isArray(i) && U(i[0])) return { rings: i, kind: "area" };
263
- const s = n("getPath");
264
- if (U(s)) return { rings: [s], kind: "line" };
265
- const c = n("getSourcePosition"), f = n("getTargetPosition");
266
- if (C(c) && C(f)) return { rings: [[c, f]], kind: "line" };
267
- const u = n("getPosition");
268
- return C(u) ? { rings: [[u]], kind: "point" } : et;
269
- }
270
- function vt(t, e) {
271
- const o = B(t.data);
272
- if (o.length === 0) return { markup: "", elementCount: 0 };
273
- const r = [];
274
- let n = 0;
275
- for (let i = 0; i < o.length; i++) {
276
- const s = o[i], c = s.geometry ?? s;
277
- let { rings: f, kind: u } = Lt(c);
278
- if (f.length === 0 && ({ rings: f, kind: u } = kt(t.props, s, i, t.data)), f.length === 0) continue;
279
- const p = St(t, s, i, e.metresPerPixel);
280
- if (u === "point") {
281
- for (const l of f)
282
- for (const a of l) {
283
- const h = e.project([a[0], a[1]]);
284
- if (!W(e.frame, h)) continue;
285
- const m = Math.max(p.radius ?? 1, 0.1);
286
- r.push(
287
- `<circle cx="${y(h[0])}" cy="${y(h[1])}" r="${y(m)}" ${N(p, "area")}/>`
288
- ), n++;
289
- }
290
- continue;
291
- }
292
- const d = f.map((l) => l.map((a) => e.project([a[0], a[1]])));
293
- if (u === "area") {
294
- const l = d.map((a) => at(a, e.frame)).filter((a) => a.length >= 3);
295
- if (l.length === 0) continue;
296
- r.push(
297
- `<path d="${j(l, !0)}" fill-rule="evenodd" ${N(p, "area")}/>`
298
- ), n++;
299
- } else {
300
- const l = d.flatMap((a) => tt(a, e.frame));
301
- if (l.length === 0) continue;
302
- r.push(`<path d="${j(l, !1)}" ${N(p, "line")}/>`), n++;
303
- }
304
- }
305
- return {
306
- markup: r.length ? `<g id="${S(t.id)}">${r.join("")}</g>` : "",
307
- elementCount: n
308
- };
309
- }
310
- function Mt(t, e, o) {
311
- const r = B(t.data);
312
- if (r.length === 0) return { markup: "", elementCount: 0 };
313
- const n = t.props, i = (l, a, h, m) => {
314
- if (typeof l != "function") return l ?? m;
315
- try {
316
- return l(a, { index: h, data: t.data });
317
- } catch {
318
- return m;
319
- }
320
- }, s = String(n.fontFamily ?? "sans-serif"), c = typeof n.getTextAnchor == "string" ? n.getTextAnchor : "middle", f = typeof n.getAlignmentBaseline == "string" ? n.getAlignmentBaseline : "center", u = [];
321
- for (let l = 0; l < r.length; l++) {
322
- const a = r[l], h = String(i(n.getText, a, l, "") ?? "");
323
- if (!h) continue;
324
- const m = i(n.getPosition, a, l, void 0);
325
- if (!Array.isArray(m)) continue;
326
- const g = e.project([m[0], m[1]]);
327
- if (!W(e.frame, g)) continue;
328
- const w = Number(i(n.getSize, a, l, G)), v = Number(n.sizeScale ?? 1), M = (Number.isFinite(w) && w > 0 ? w : G) * (Number.isFinite(v) && v > 0 ? v : 1), k = E(i(n.getColor, a, l, [0, 0, 0, 255])), R = Number(i(n.getCollisionPriority, a, l, 0)) || 0, A = i(n.getPixelOffset, a, l, void 0), _ = Array.isArray(A) && typeof A[0] == "number" ? A[0] : 0, F = Array.isArray(A) && typeof A[1] == "number" ? A[1] : 0;
329
- g[0] += _, g[1] += F;
330
- const O = String(i(n.getTextAnchor, a, l, c) ?? c), T = O === "start" || O === "end" ? O : "middle", I = String(i(n.getAlignmentBaseline, a, l, f) ?? f), x = I === "top" || I === "bottom" ? I : "center", P = o ? o(h, M, s) : void 0, b = Tt(h, g[0], g[1], M, T, x), nt = P === void 0 ? { id: `${t.id}:${l}`, priority: R, ...b } : {
331
- id: `${t.id}:${l}`,
332
- priority: R,
333
- left: T === "start" ? g[0] : T === "end" ? g[0] - P : g[0] - P / 2,
334
- top: b.top,
335
- right: (T === "start" ? g[0] : T === "end" ? g[0] - P : g[0] - P / 2) + P,
336
- bottom: b.bottom
337
- };
338
- u.push({ text: h, p: g, size: M, colour: k, anchor: T, baseline: x, box: nt });
339
- }
340
- const d = (n.collisionEnabled === !1 ? u.map((l, a) => a) : At(u.map((l) => l.box))).map((l) => {
341
- const a = u[l], h = a.baseline === "top" ? "hanging" : a.baseline === "bottom" ? "alphabetic" : "central", m = a.colour.opacity < 1 ? ` fill-opacity="${a.colour.opacity.toFixed(4)}"` : "";
342
- return `<text x="${y(a.p[0])}" y="${y(a.p[1])}" font-family="${S(s)}" font-size="${y(a.size)}" text-anchor="${a.anchor}" dominant-baseline="${h}" fill="${a.colour.color}"${m}>${z(a.text)}</text>`;
343
- });
344
- return {
345
- markup: d.length ? `<g id="${S(t.id)}">${d.join("")}</g>` : "",
346
- elementCount: d.length
347
- };
348
- }
349
- function Rt(t, e) {
350
- const o = B(t.data);
351
- if (o.length === 0) return { markup: "", elementCount: 0 };
352
- const r = t.props, n = (h, m, g, w) => {
353
- if (typeof h != "function") return h ?? w;
354
- try {
355
- return h(m, { index: g, data: t.data });
356
- } catch {
357
- return w;
358
- }
359
- }, i = String(r.fontFamily ?? "sans-serif"), s = String(r.fontWeight ?? "normal"), c = Number(r.letterSpacing ?? 0) || 0, f = Number(r.offset ?? 0) || 0, u = String(r.placement ?? "middle"), p = u === "start" ? "0%" : u === "end" ? "100%" : "50%", d = u === "start" ? "start" : u === "end" ? "end" : "middle", l = [], a = [];
360
- for (let h = 0; h < o.length; h++) {
361
- const m = o[h], g = n(r.getPath, m, h, void 0), w = String(n(r.getText, m, h, "") ?? "");
362
- if (!Array.isArray(g) || g.length < 2 || !w) continue;
363
- const v = g.map((x) => e.project([x[0], x[1]])), M = tt(v, e.frame);
364
- let k = null, R = 0;
365
- for (const x of M) {
366
- let P = 0;
367
- for (let b = 1; b < x.length; b++) P += Math.hypot(x[b][0] - x[b - 1][0], x[b][1] - x[b - 1][1]);
368
- P > R && (R = P, k = x);
369
- }
370
- if (!k || k.length < 2) continue;
371
- const A = Number(n(r.getSize, m, h, 14)) || 14, _ = E(n(r.getColor, m, h, [30, 30, 30, 255])), F = `${t.id}-path-${h}`;
372
- l.push(`<path id="${S(F)}" d="${j([k], !1)}" fill="none"/>`);
373
- const O = _.opacity < 1 ? ` fill-opacity="${_.opacity.toFixed(4)}"` : "", T = c !== 0 ? ` letter-spacing="${y(c)}"` : "", I = f !== 0 ? ` dy="${y(-f)}"` : "";
374
- a.push(
375
- `<text font-family="${S(i)}" font-weight="${S(s)}" font-size="${y(A)}" fill="${_.color}"${O}${T}><textPath href="#${S(F)}" startOffset="${p}" text-anchor="${d}"${I}>${z(w)}</textPath></text>`
376
- );
377
- }
378
- return a.length === 0 ? { markup: "", elementCount: 0 } : {
379
- markup: `<defs>${l.join("")}</defs><g id="${S(t.id)}">${a.join("")}</g>`,
380
- elementCount: a.length
381
- };
382
- }
383
- function K(t, e, o) {
384
- return `<image id="${S(`band:${o.join("+")}`)}" x="${y(e.left)}" y="${y(e.top)}" width="${y(e.right - e.left)}" height="${y(e.bottom - e.top)}" preserveAspectRatio="none" href="${S(t)}"/>`;
385
- }
386
- const _t = 600, Ot = 5e4;
387
- function Ft(t) {
388
- return Math.max(1, t / 96);
389
- }
390
- async function Ct(t, e) {
391
- const o = [], r = { left: 0, top: 0, right: e.width, bottom: e.height }, n = e.effectDpi ?? _t, i = {
392
- project: e.project,
393
- frame: r,
394
- metresPerPixel: e.metresPerPixel,
395
- featureBudget: e.featureBudget ?? Ot
396
- }, s = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${e.width}" height="${e.height}" viewBox="0 0 ${e.width} ${e.height}">`;
397
- if (e.hasPostProcessPass) {
398
- const d = await e.captureBand(null, n);
399
- return o.push({
400
- code: "rasterised-by-effect",
401
- message: `The map frame was rasterised at ${n} dpi because a post-process pass${e.postProcessLabel ? ` (${e.postProcessLabel})` : ""} treats the finished frame, and there is no vector equivalent.`,
402
- fix: "Remove the finish for fully editable linework, or raise effect-dpi if the type needs to be sharper."
403
- }), {
404
- svg: `${s}${K(d, r, ["frame"])}</svg>`,
405
- notices: o,
406
- elementCount: 1
407
- };
408
- }
409
- const c = it(t.map((d) => ({ id: d.id, type: d.type }))), f = new Map(t.map((d) => [d.id, d])), u = [];
410
- let p = 0;
411
- for (const d of c) {
412
- if (d.strategy === "raster") {
413
- for (const l of d.ids) {
414
- const a = f.get(l);
415
- a && !rt(a.type) && o.push({
416
- code: "unknown-layer-type",
417
- message: `Layer "${l}" has type "${a.type}", which the serializer does not recognise — it was drawn into a raster band.`,
418
- fix: "It renders correctly but is not editable. If it should be vector, register its type with the serializer."
419
- });
420
- }
421
- u.push(K(await e.captureBand(d.ids, n), r, d.ids)), p++;
422
- continue;
423
- }
424
- for (const l of d.ids) {
425
- const a = f.get(l);
426
- if (!a || a.props.visible === !1) continue;
427
- const h = d.strategy === "path-text" ? Rt(a, i) : d.strategy === "text" ? Mt(a, i, e.measureText) : vt(a, i);
428
- h.markup && u.push(h.markup), p += h.elementCount;
429
- }
430
- }
431
- return p > i.featureBudget && o.push({
432
- code: "feature-budget",
433
- message: `The sheet emitted ${p} elements, past the ${i.featureBudget} budget — editors slow to a crawl well before this.`,
434
- fix: 'Add <om-transform type="simplify" tolerance="0.15mm"> to the densest layer, or raise the budget deliberately.'
435
- }), { svg: `${s}${u.join("")}</svg>`, notices: o, elementCount: p };
436
- }
437
- export {
438
- _t as DEFAULT_EFFECT_DPI,
439
- Ot as DEFAULT_FEATURE_BUDGET,
440
- Ft as bandScaleFor,
441
- tt as clipPolyline,
442
- at as clipRing,
443
- st as clipSegment,
444
- E as deckColorToSvg,
445
- At as declutter,
446
- K as emitRasterBand,
447
- Mt as emitTextLayer,
448
- Rt as emitTextOnPathLayer,
449
- vt as emitVectorLayer,
450
- Tt as estimateLabelBox,
451
- it as groupIntoRuns,
452
- rt as isKnownType,
453
- bt as resolveDashArray,
454
- St as resolveFeatureStyle,
455
- $t as resolveLineWidth,
456
- Pt as resolveRadius,
457
- Ct as serializeToSvg,
458
- ot as strategyFor
459
- };