@nika-js/onlymap 0.9.0 → 0.9.1

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 (44) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +25 -2
  3. package/dist/{LercDecode.es-BMcxSLhD.js → LercDecode.es-IEPCRZOv.js} +1 -1
  4. package/dist/{basemap-m98j2wxG.js → basemap-DL0mk9Bf.js} +1 -1
  5. package/dist/dem-decode.d.ts +58 -0
  6. package/dist/elements/om-map.d.ts +2 -0
  7. package/dist/{geoparquet-XOwOmChh.js → geoparquet-DJxZA0if.js} +1 -1
  8. package/dist/hillshade-DR3TxO1a.js +186 -0
  9. package/dist/hillshade-apron-Bem3DWyJ.js +40 -0
  10. package/dist/hillshade-apron.d.ts +54 -0
  11. package/dist/hillshade-shader-n_zManfZ.js +160 -0
  12. package/dist/hillshade-shader.d.ts +152 -0
  13. package/dist/hillshade.d.ts +133 -0
  14. package/dist/html-data.d.ts +1 -1
  15. package/dist/{index-HZWdgtm4.js → index-BjcPjICh.js} +59 -59
  16. package/dist/{index-DzOvV-O7.js → index-CvuDsvnk.js} +22 -22
  17. package/dist/{index-CfPbQUqO.js → index-DO_w0tqR.js} +86 -83
  18. package/dist/{index-DDNElBTs.js → index-DdTZSuAb.js} +106 -106
  19. package/dist/{index-BSAY6CWm.js → index-oY3XHIux.js} +9843 -9623
  20. package/dist/{index-BMbpftvm.js → index-vLXZuog4.js} +1 -1
  21. package/dist/lerc-Bph62dCb.js +22 -0
  22. package/dist/onlymap.standalone.js +21279 -20558
  23. package/dist/onlymapjs.js +37 -37
  24. package/dist/{raster-Dg5p_99H.js → raster-D-eTzCE3.js} +609 -499
  25. package/dist/raster-hillshade.d.ts +119 -0
  26. package/dist/{raster-pipeline-DhjkqDYd.js → raster-pipeline-BlOnMPJe.js} +510 -484
  27. package/dist/raster-pipeline.d.ts +10 -0
  28. package/dist/raster.d.ts +5 -0
  29. package/dist/terrain-heightfield.d.ts +0 -16
  30. package/dist/terrain-sample.d.ts +0 -13
  31. package/dist/version.d.ts +1 -1
  32. package/dist/volumetrics.d.ts +7 -0
  33. package/dist/{zarr-D3CzK1Zm.js → zarr-BGDoEtFb.js} +2 -2
  34. package/docs/cartograph.md +2 -2
  35. package/docs/design/hillshade.md +290 -0
  36. package/docs/effects.md +11 -0
  37. package/docs/hillshade.md +203 -0
  38. package/llms.txt +2 -1
  39. package/onlymapjs.attributes.json +27 -2
  40. package/onlymapjs.html-data.json +44 -6
  41. package/package.json +13 -9
  42. package/skills/onlymapjs/SKILL.md +3 -2
  43. package/skills/onlymapjs/references/syntax.md +11 -3
  44. package/dist/lerc-qK-nhCaB.js +0 -30
package/CHANGELOG.md CHANGED
@@ -8,6 +8,26 @@ Note: npm collapsed a few closely-spaced releases — the GPX/FlatGeobuf (0.5.4)
8
8
  and GeoParquet (0.5.5) work shipped to npm together as **0.5.6**, so npm's
9
9
  version list jumps 0.5.3 → 0.5.6. Each logical version is listed here regardless.
10
10
 
11
+ ## 0.9.1 — 2026-09-22
12
+
13
+ ### Added
14
+ - **Shaded relief, as a layer.** `<om-layer type="HillshadeLayer" src="terrarium">` draws shaded terrain from keyless global elevation tiles — no data of your own, no 3D terrain, and it works on a flat map at any angle. Because it is an ordinary layer it sits underneath your data in document order, is captured by `snapshot()`, and is treated by a `<om-effect>` print finish.
15
+ - **Or shade the elevation raster you already have.** `shading="hillshade"` on a `COGLayer` or `ZarrLayer` turns your own DEM into relief. Paired with `colormap`, the relief shows *through* the colours rather than covering them, so a hypsometric map with shaded terrain is one layer instead of two stacked ones.
16
+ - **Up to four suns.** `sun-azimuth="315 45 135"` blends several light directions — the difference between the flat single-light shading most web maps ship and the Swiss-style relief used in printed atlases. `sun-weight`, `sun-elevation` and `z-factor` tune it, and all of them are instant: moving the sun redraws without downloading anything.
17
+ - **Details you would otherwise have to fix yourself.** Tile edges are seamless rather than showing a faint grid. Relief keeps its true shape at every latitude instead of flattening near the equator and exaggerating near the poles, and on your own DEM that correction is read from the file's own coordinate system. A high-resolution export gets genuinely sharper relief rather than an enlarged screen image.
18
+ - Two runnable examples: **Shaded relief** (global tiles) and **Shade your own DEM** (your GeoTIFF).
19
+ - **A finish switcher you can drop on a map.** `<om-widget type="effects">` lists every preset plus Off, and picking one writes the document through `set-effect` — so a viewer's choice is undoable, travels in a story, and is there when the map is saved. The widget holds no state of its own, which means a hand edit or an undo moves the radio too.
20
+
21
+ ### Fixed
22
+ - **Elevation is now read exactly.** Terrain heights are stored in the colour channels of an image, and the browser was allowed to colour-adjust them on the way in. The error was far too small to notice in a single elevation reading, but big enough to band a whole hillside once slopes are calculated from it — so cut/fill volumes and elevation queries are more accurate too.
23
+ - **A terrain source in a lossy image format now says so, once.** Heights live in the colour bytes, so lossy compression invents terrain that looks plausible and is wrong.
24
+ - **A finish no longer bleeds colour into empty space.** Grain and tint were being applied to fully transparent pixels, so the texture spilled over whatever sat behind the map — the page background, most visibly. Transparent areas now stay transparent, and semi-transparent ones blend correctly.
25
+ - **The `newsprint` screen is legible on screen.** Its dot cell was sized for a press (0.55mm ≈ two pixels on a normal display), which read as noise and erased small symbols. It is coarser and lighter now; take `halftone-cell` back down when you are exporting at 300 dpi.
26
+
27
+ ### Notes
28
+ - `identify="off"` no longer frees memory on a raster while `shading="hillshade"` is set — seamless relief needs neighbouring pixels kept to hand. The validator points this out rather than letting the setting look like it worked.
29
+ - Relief reads a single band as elevation, so it is not meant for multi-band colour composites; the validator says so if you select one.
30
+
11
31
  ## 0.9.0 — 2026-09-21
12
32
 
13
33
  ### Added
package/README.md CHANGED
@@ -337,10 +337,33 @@ Presets: `vintage`, `engraved`, `night`, `blueprint`, `riso`, `newsprint`, `mute
337
337
 
338
338
  **Spatial knobs are in millimetres** (`size="0.12mm"`, `width="0.08mm"`) and resolve against the live pixel density, so a look keeps its physical texture when a cartograph frame captures it at 300 or 600 dpi. A pixel value is a validation error, because it would silently render finer every time the dpi went up.
339
339
 
340
- Consecutive pointwise ops compile into a **single** GPU pass; only a neighbourhood op — one that samples its surroundings — costs a pass of its own. `set-effect {preset}` swaps the finish live from a behavior or widget. Guide: [docs/effects.md](docs/effects.md). It writes the document, so undo/redo treat it like any other edit; a story step can apply it, but seeking back does not yet remove an effect a step added (the rewind machinery restores `<om-map>` attributes, and this action adds a child element).
340
+ Consecutive pointwise ops compile into a **single** GPU pass; only a neighbourhood op — one that samples its surroundings — costs a pass of its own. `set-effect {preset}` swaps the finish live from a behavior or widget, and `<om-widget type="effects">` is that switcher as chrome — every preset plus Off, holding no state of its own, so a hand edit or an undo moves the radio with it. Guide: [docs/effects.md](docs/effects.md). It writes the document, so undo/redo treat it like any other edit; a story step can apply it, but seeking back does not yet remove an effect a step added (the rewind machinery restores `<om-map>` attributes, and this action adds a child element).
341
341
 
342
342
  An effect runs over deck's own frame. With a MapLibre basemap, which composites underneath, the data layers are treated and the basemap is not — the validator warns and suggests drawing the base as layers with `basemap="none"`.
343
343
 
344
+ ## Shaded relief
345
+
346
+ `<om-layer type="HillshadeLayer" src="terrarium">` shades a global DEM on the GPU — keyless, and with no data of your own:
347
+
348
+ ```html
349
+ <om-map center="[7.65, 45.98]" zoom="9" basemap="none">
350
+ <om-layer id="relief" type="HillshadeLayer" src="terrarium"
351
+ sun-azimuth="315 45 135" sun-elevation="45" z-factor="1.4"></om-layer>
352
+ <om-layer id="trails" type="GeoJsonLayer" data="./trails.geojson"></om-layer>
353
+ <om-effect preset="vintage"></om-effect>
354
+ </om-map>
355
+ ```
356
+
357
+ This is a **layer, not a mode of `terrain=`**. `terrain=` raises a 3D surface, replaces the basemap and means nothing at pitch 0; relief on a flat sheet has to compose underneath the data like any other layer. Being a layer is also what puts it inside deck's framebuffer, so `snapshot()` captures it and `<om-effect>` treats it — relief a print finish couldn't reach would be worth very little on a print sheet.
358
+
359
+ **The sun is a list, not a switch.** `sun-azimuth="315 45 135"` blends up to four lights, which is what separates Swiss-style relief from the single-light shading every slippy map already ships; `sun-weight` weights them. There is deliberately no `multi-directional` boolean — a shorthand must never reach a look you have no other way to write. Azimuths are ° clockwise from north, the same convention `lighting-sun-azimuth` uses (they are not coupled). `z-factor` exaggerates the relief, `blend="multiply"` lets it read *under* your fills instead of greying them, and `opacity` fades it.
360
+
361
+ Sources are the `terrain=` registry: `terrarium` and `mapterhorn` are keyless, or give a raw `{z}/{x}/{y}` template plus `decoder="terrarium"|"mapbox-rgb"`. `src` is required even for the keyless default, the same way `basemap="positron"` and `terrain="terrarium"` are named — keyless means no key, not no attribute.
362
+
363
+ **Or shade a DEM you already have.** `shading="hillshade"` on a `COGLayer`/`ZarrLayer` shades that raster in place, with the same `sun-*`/`z-factor` attributes — and because relief runs last in the styling chain it multiplies onto a `colormap` rather than replacing it, so `colormap="terrain" shading="hillshade"` is a hypsometric tint with relief through it as **one layer, not two**. Ground scale comes from the file's own geotransform and CRS, so a DEM in UTM metres, state-plane feet or degrees is all handled — including the fact that a geographic pixel is not square on the ground. (`identify="off"` cannot free memory while shading is on: the seamless edges need neighbouring pixels on the CPU, and the validator says so.)
364
+
365
+ Two things it gets right that hand-rolled hillshades usually don't. **Tile edges are seamless**: a hillshade is a derivative, so each tile is decoded with a one-pixel apron from its eight neighbours rather than clamping at the border and drawing a pale grid over the world. And **latitude is corrected per fragment**, so relief doesn't flatten toward the equator and exaggerate toward the poles. Tile zoom follows the capture pixel ratio, so a 300 dpi plate gets sharper relief rather than an upscaled screen image. The shader chunk is lazy — a map with no relief never downloads it. Examples: `dev/examples/features/styling/shade-the-terrain.html` (global tiles) and `dev/examples/features/rasters/shade-your-own-dem.html` (your own GeoTIFF). Guide: [docs/hillshade.md](docs/hillshade.md).
366
+
344
367
  ## Programmatic surface
345
368
 
346
369
  - **`OmMap.*`** — `validate`, `snapshotIR`, `snapshotDescriptorIR`, `resolveImageOverlay`, `registerLayer`, `registerWidget`, `registerAction`, `registerSource`, `registerFormat`, `registerBasemap`, `configureBasemap`, `configureData`, `configureTelemetry`, `configureLicense`, `getLayerSchema`
@@ -391,7 +414,7 @@ Mapbox GL basemaps, depth-interleaved 3D compositing, globe projection, SSE tran
391
414
 
392
415
  | | |
393
416
  |---|---|
394
- | [docs/react.md](docs/react.md) · [docs/basemaps.md](docs/basemaps.md) · [docs/testing.md](docs/testing.md) · [docs/live-data.md](docs/live-data.md) · [docs/image-overlays.md](docs/image-overlays.md) · [docs/3d-assets.md](docs/3d-assets.md) · [docs/stories.md](docs/stories.md) · [docs/routing.md](docs/routing.md) · [docs/telemetry.md](docs/telemetry.md) | Consumer guides |
417
+ | [docs/react.md](docs/react.md) · [docs/basemaps.md](docs/basemaps.md) · [docs/testing.md](docs/testing.md) · [docs/live-data.md](docs/live-data.md) · [docs/image-overlays.md](docs/image-overlays.md) · [docs/3d-assets.md](docs/3d-assets.md) · [docs/stories.md](docs/stories.md) · [docs/routing.md](docs/routing.md) · [docs/effects.md](docs/effects.md) · [docs/hillshade.md](docs/hillshade.md) · [docs/telemetry.md](docs/telemetry.md) | Consumer guides |
395
418
  | [CHANGELOG.md](CHANGELOG.md) | Version-by-version release notes |
396
419
  | [llms.txt](llms.txt) | The agent-facing quick reference |
397
420
  | `skills/onlymapjs` | Installable LLM skill for OnlyMapJS authoring |
@@ -19,7 +19,7 @@ async function v(N = {}) {
19
19
  if (n) {
20
20
  const { createRequire: I } = await import(
21
21
  /*webpackIgnore:true*/
22
- "./lerc-qK-nhCaB.js"
22
+ "./hillshade-apron-Bem3DWyJ.js"
23
23
  ).then((g) => g._);
24
24
  var O = I(import.meta.url);
25
25
  }
@@ -1,4 +1,4 @@
1
- import { f as ny, L as sy, g as oy, m as ay, h as ka, j as Sd, z as oc, k as sm, V as ly, W as cy, l as uy, p as hy, q as Vu, s as Ed, t as dy, v as py, w as fy, D as Qf, x as my } from "./index-BSAY6CWm.js";
1
+ import { k as ny, L as sy, l as oy, m as ay, p as ka, q as Sd, z as oc, s as sm, V as ly, W as cy, t as uy, v as hy, w as Vu, x as Ed, y as dy, A as py, F as fy, H as Qf, I as my } from "./index-oY3XHIux.js";
2
2
  const Cd = Math.PI / 180, gy = 180 / Math.PI;
3
3
  function em(Pe, K = 0) {
4
4
  const pe = Math.min(180, Pe) * Cd;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * DEM tile decode — the ONE place an RGB-encoded elevation tile becomes
3
+ * numbers.
4
+ *
5
+ * WHY THIS EXISTS. A DEM tile is not a picture. Its bytes are a big-endian
6
+ * integer split across the R, G and B channels, so every step of the normal
7
+ * image path that is *allowed* to adjust a colour is, here, allowed to adjust
8
+ * a height. Two of them do, and both are off by default:
9
+ *
10
+ * - `colorSpaceConversion` — a PNG carrying an `sRGB`, `gAMA` or `iCCP` chunk
11
+ * gets converted toward the display's colour space on decode. That is
12
+ * correct for a photograph and catastrophic for a height: the channel
13
+ * values move.
14
+ * - `premultiplyAlpha` — premultiplying and then un-premultiplying a tile
15
+ * that has any alpha below 255 is a lossy round trip through integers.
16
+ *
17
+ * Both sites that read DEM pixels used to call bare
18
+ * `createImageBitmap(blob)`, which leaves these at "default" — i.e. the
19
+ * browser's choice. For a single point query the resulting ±1 LSB is
20
+ * sub-metre noise nobody sees. But a derivative (hillshade, slope, any
21
+ * neighbour difference) amplifies exactly that error, and a ±1 LSB wobble
22
+ * across a smooth slope becomes visible banding. Fixing it once, here, is
23
+ * also what makes a GPU hillshade and a CPU line-of-sight agree about the
24
+ * same ground.
25
+ *
26
+ * The canvas is the second half of the same problem: an `alpha: true` 2D
27
+ * canvas stores premultiplied and un-premultiplies on `getImageData`, so the
28
+ * context is pinned to `alpha: false` and `colorSpace: "srgb"` — an opaque
29
+ * surface in a fixed space performs no conversion on the way in or out.
30
+ */
31
+ /** Reset for tests — the lossy notice is once-per-host for the session. */
32
+ export declare function resetDemDecodeWarningsForTests(): void;
33
+ /**
34
+ * Decoded DEM tile pixels: RGBA bytes, row-major, `width * height * 4` long.
35
+ * Deliberately the raw `Uint8ClampedArray` rather than an `ImageData` —
36
+ * volumetrics' worker postMessages these, and the decoder that turns the
37
+ * bytes into metres lives with the caller.
38
+ */
39
+ export interface DemPixels {
40
+ width: number;
41
+ height: number;
42
+ data: Uint8ClampedArray;
43
+ }
44
+ /**
45
+ * Fetch and decode one DEM tile. `null` on any failure — the caller's
46
+ * contract everywhere is "treat as no terrain", never a thrown error.
47
+ *
48
+ * `init` carries the abort signal for callers that bound tile latency.
49
+ */
50
+ export declare function fetchDemTile(url: string, init?: RequestInit): Promise<DemPixels | null>;
51
+ /**
52
+ * Decode an already-fetched DEM image to exact RGBA bytes.
53
+ *
54
+ * Split out from `fetchDemTile` so the decode path is testable without a
55
+ * network, and so a caller holding a blob from somewhere else cannot
56
+ * accidentally reintroduce the bare `createImageBitmap` call.
57
+ */
58
+ export declare function decodeDemBlob(blob: Blob): Promise<DemPixels | null>;
@@ -32,6 +32,8 @@ export declare class OmMapElement extends HTMLElementBase {
32
32
  private contextmenuHandler?;
33
33
  private mount;
34
34
  private reconcilePending;
35
+ /** Last seen `<om-effect>` markup, so the `effects` watch token fires on real changes only. */
36
+ private effectSignature;
35
37
  private readonly dataOwner;
36
38
  private dataReleasePending;
37
39
  /** Decoded property tables per pick-features layer — see RuntimeCoreCallbacks.onFeatureTable. */
@@ -1,4 +1,4 @@
1
- import { r as p, n as d } from "./index-BSAY6CWm.js";
1
+ import { r as p, n as d } from "./index-oY3XHIux.js";
2
2
  function g(t) {
3
3
  if (t == null) return !0;
4
4
  const e = t, n = e.id?.code;
@@ -0,0 +1,186 @@
1
+ import { C as S, T as b, g as z, D as p, B as w, f as L, d as T } from "./index-oY3XHIux.js";
2
+ import { N as F, c as M } from "./hillshade-apron-Bem3DWyJ.js";
3
+ import { p as $, h as E, m as H, a as D } from "./hillshade-shader-n_zManfZ.js";
4
+ const O = 64, u = /* @__PURE__ */ new Map();
5
+ function g(t) {
6
+ const e = u.get(t);
7
+ if (e) return e;
8
+ const r = L(t);
9
+ if (u.set(t, r), u.size > O) {
10
+ const i = u.keys().next().value;
11
+ i !== void 0 && u.delete(i);
12
+ }
13
+ return r;
14
+ }
15
+ function x(t, e, r, i) {
16
+ return t.replace("{z}", String(i)).replace("{x}", String(e)).replace("{y}", String(r));
17
+ }
18
+ async function P(t, e, r) {
19
+ const i = await g(x(t, r.x, r.y, r.z));
20
+ if (!i) return null;
21
+ const l = (o) => ({
22
+ width: o.width,
23
+ height: o.height,
24
+ at: (n, s) => {
25
+ const a = (s * o.width + n) * 4;
26
+ return T(e, o.data[a], o.data[a + 1], o.data[a + 2]);
27
+ }
28
+ }), d = 2 ** r.z, h = /* @__PURE__ */ new Map();
29
+ return await Promise.all(
30
+ F.map(async ({ dx: o, dy: n }) => {
31
+ const s = r.y + n;
32
+ if (s < 0 || s >= d) return;
33
+ const a = ((r.x + o) % d + d) % d;
34
+ h.set(`${o},${n}`, await g(x(t, a, s, r.z)));
35
+ })
36
+ ), M(l(i), (o, n) => {
37
+ const s = h.get(`${o},${n}`);
38
+ return s ? l(s) : null;
39
+ });
40
+ }
41
+ const N = {
42
+ blendColorSrcFactor: "dst",
43
+ blendColorDstFactor: "zero",
44
+ blendAlphaSrcFactor: "zero",
45
+ blendAlphaDstFactor: "one"
46
+ };
47
+ class C extends w {
48
+ static layerName = "HillshadeBitmapLayer";
49
+ getShaders() {
50
+ const e = super.getShaders();
51
+ return { ...e, modules: [...e.modules, D] };
52
+ }
53
+ draw(e) {
54
+ const r = this.props, i = { ...r.hillshadeUniforms, hillshadeHeights: r.image };
55
+ for (const l of this.getModels()) l.shaderInputs.setProps({ hillshade: i });
56
+ super.draw(e);
57
+ }
58
+ }
59
+ function R(t, e) {
60
+ if (!t) return e;
61
+ if (typeof t != "string") return t;
62
+ if (t in p) return p[t];
63
+ try {
64
+ const r = JSON.parse(t);
65
+ if ([r?.rScaler, r?.gScaler, r?.bScaler, r?.offset].every((i) => typeof i == "number" && Number.isFinite(i))) return r;
66
+ } catch {
67
+ }
68
+ return console.warn(`[onlymapjs] HillshadeLayer: decoder="${t}" is not "terrarium", "mapbox-rgb" or {rScaler,gScaler,bScaler,offset} JSON — using terrarium.`), e;
69
+ }
70
+ function U(t) {
71
+ const e = z(t.src);
72
+ return e ? e.requiresKey ? (console.warn(`[onlymapjs] HillshadeLayer: src="${t.src}" needs a ${e.requiresKey} key, which this layer does not plumb — use a keyless source such as "terrarium".`), null) : {
73
+ template: e.elevationData,
74
+ decoder: typeof e.decoder == "string" ? p[e.decoder] : e.decoder,
75
+ maxZoom: t.maxZoom ?? e.maxZoom
76
+ } : !t.src || !t.src.includes("{z}") ? (console.warn(`[onlymapjs] HillshadeLayer: src="${t.src}" is neither a registered terrain preset nor a {z}/{x}/{y} DEM URL template.`), null) : { template: t.src, decoder: R(t.decoder, p.terrarium), maxZoom: t.maxZoom ?? 14 };
77
+ }
78
+ function Z(t, e) {
79
+ return !Number.isFinite(t) || !Number.isFinite(e) || e <= 0 ? 0 : Math.max(0, Math.round(Math.log2(Math.max(1, t / e))));
80
+ }
81
+ class j extends S {
82
+ static layerName = "OmHillshadeLayer";
83
+ static defaultProps = {
84
+ src: { type: "string", value: "terrarium" },
85
+ decoder: { type: "string", value: null, optional: !0 },
86
+ sunAzimuth: { type: "string", value: "315" },
87
+ sunWeight: { type: "string", value: null, optional: !0 },
88
+ sunElevation: { type: "number", value: 45 },
89
+ zFactor: { type: "number", value: 1 },
90
+ blend: { type: "string", value: "normal" },
91
+ maxZoom: { type: "number", value: null, optional: !0 },
92
+ zoomOffset: { type: "number", value: 0 }
93
+ };
94
+ renderLayers() {
95
+ const e = U(this.props);
96
+ if (!e) return null;
97
+ const { azimuths: r, weights: i } = $(this.props.sunAzimuth, this.props.sunWeight), l = this.props.blend === "multiply", d = this.context.device, h = d?.canvasContext?.cssToDeviceRatio?.() ?? 1, o = typeof devicePixelRatio == "number" && devicePixelRatio > 0 ? devicePixelRatio : 1, n = this.state.textures;
98
+ return new b(
99
+ this.getSubLayerProps({ id: "tiles" }),
100
+ {
101
+ data: e.template,
102
+ tileSize: 256,
103
+ maxZoom: e.maxZoom,
104
+ zoomOffset: (this.props.zoomOffset ?? 0) + Z(h, o),
105
+ // deck compares FUNCTION props by their update triggers, never by
106
+ // identity — inline closures would otherwise invalidate everything on
107
+ // every render. So anything a closure captures is invisible to deck
108
+ // unless it is declared here, which is why moving the sun with no
109
+ // trigger produced a byte-identical frame.
110
+ //
111
+ // The split is exactly the one we want. `getTileData` names only what
112
+ // changes the HEIGHTS, so a new decoder or source refetches; the
113
+ // illumination names `renderSubLayers`, which regenerates the draw
114
+ // calls and refetches nothing — moving the sun costs no network at
115
+ // all, because every knob below is a uniform.
116
+ updateTriggers: {
117
+ getTileData: [e.template, JSON.stringify(e.decoder)],
118
+ renderSubLayers: [r.join(","), i.join(","), this.props.sunElevation, this.props.zFactor, l]
119
+ },
120
+ getTileData: async (s) => {
121
+ const a = await P(e.template, e.decoder, s.index);
122
+ if (!a || !d) return null;
123
+ const c = `${s.index.z}/${s.index.x}/${s.index.y}`;
124
+ n.get(c)?.destroy();
125
+ const m = d.createTexture({
126
+ data: a.data,
127
+ format: "r32float",
128
+ width: a.width + 2,
129
+ height: a.height + 2,
130
+ // NEAREST, because linear filtering of a float texture needs
131
+ // OES_texture_float_linear, which is not universal (the same
132
+ // constraint raster-pipeline.ts documents).
133
+ sampler: { minFilter: "nearest", magFilter: "nearest", addressModeU: "clamp-to-edge", addressModeV: "clamp-to-edge" }
134
+ });
135
+ return n.set(c, m), { texture: m, width: a.width, height: a.height, key: c };
136
+ },
137
+ onTileUnload: (s) => {
138
+ const a = `${s.index.z}/${s.index.x}/${s.index.y}`;
139
+ n.get(a)?.destroy(), n.delete(a);
140
+ },
141
+ renderSubLayers: (s) => {
142
+ const a = s.data;
143
+ if (!a) return null;
144
+ const c = s.tile, [[m, y], [v, f]] = c.boundingBox;
145
+ return new C(s, {
146
+ id: `${s.id}-bitmap`,
147
+ data: void 0,
148
+ image: a.texture,
149
+ bounds: [m, y, v, f],
150
+ multiply: l,
151
+ parameters: l ? N : {},
152
+ hillshadeUniforms: E({
153
+ width: a.width,
154
+ height: a.height,
155
+ // Web Mercator: one scale for both axes, stated at the equator
156
+ // and given its cos-phi falloff per fragment by the shader.
157
+ ...H(c.index.z, a.width, a.height),
158
+ north: f,
159
+ south: y,
160
+ azimuths: r,
161
+ weights: i,
162
+ sunElevation: this.props.sunElevation ?? 45,
163
+ zFactor: this.props.zFactor ?? 1,
164
+ // A multiply-blended layer multiplies the shade into the
165
+ // FRAMEBUFFER; a normal one draws relief as its own image.
166
+ composite: l
167
+ })
168
+ });
169
+ }
170
+ }
171
+ );
172
+ }
173
+ initializeState() {
174
+ this.setState({ textures: /* @__PURE__ */ new Map() });
175
+ }
176
+ finalizeState() {
177
+ for (const e of this.state.textures.values()) e.destroy();
178
+ this.state.textures.clear();
179
+ }
180
+ }
181
+ export {
182
+ j as OmHillshadeLayer,
183
+ P as buildPaddedHeights,
184
+ Z as captureZoomOffset,
185
+ U as resolveHillshadeSource
186
+ };
@@ -0,0 +1,40 @@
1
+ const _ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2
+ __proto__: null
3
+ }, Symbol.toStringTag, { value: "Module" }));
4
+ function i(c, r, t) {
5
+ return (t + 1) * (c + 2) + (r + 1);
6
+ }
7
+ function g(c, r) {
8
+ const { width: t, height: e } = c, f = new Float32Array((t + 2) * (e + 2));
9
+ for (let o = 0; o < e; o++)
10
+ for (let n = 0; n < t; n++) f[i(t, n, o)] = c.at(n, o);
11
+ for (let o = -1; o <= e; o++)
12
+ for (let n = -1; n <= t; n++) {
13
+ if (n >= 0 && n < t && o >= 0 && o < e) continue;
14
+ const s = Math.min(t - 1, Math.max(0, n)), u = Math.min(e - 1, Math.max(0, o));
15
+ f[i(t, n, o)] = f[i(t, s, u)];
16
+ }
17
+ for (let o = -1; o <= 1; o++)
18
+ for (let n = -1; n <= 1; n++) {
19
+ if (n === 0 && o === 0) continue;
20
+ const s = r(n, o);
21
+ if (!s || s.width !== t || s.height !== e) continue;
22
+ const u = n === 0 ? null : [n === -1 ? t - 1 : 0], x = o === 0 ? null : [o === -1 ? e - 1 : 0], y = u ?? Array.from({ length: t }, (l, a) => a), d = x ?? Array.from({ length: e }, (l, a) => a);
23
+ for (const l of d)
24
+ for (const a of y) {
25
+ const h = n === 0 ? a : n === -1 ? -1 : t, p = o === 0 ? l : o === -1 ? -1 : e;
26
+ f[i(t, h, p)] = s.at(a, l);
27
+ }
28
+ }
29
+ return { width: t, height: e, data: f };
30
+ }
31
+ const m = (() => {
32
+ const c = [];
33
+ for (let r = -1; r <= 1; r++) for (let t = -1; t <= 1; t++) (t !== 0 || r !== 0) && c.push({ dx: t, dy: r });
34
+ return c;
35
+ })();
36
+ export {
37
+ m as N,
38
+ _,
39
+ g as c
40
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The one-pixel apron — shared by both hillshade entry points.
3
+ *
4
+ * A hillshade is a DERIVATIVE, so a fragment at a tile's edge needs heights
5
+ * that live in the next tile. Sampling with clamp-to-edge instead makes the
6
+ * gradient collapse along every boundary and draws a pale grid over the whole
7
+ * world: the single most recognisable way a hand-rolled hillshade looks
8
+ * broken, and invisible to any test that only asks "did something render".
9
+ *
10
+ * So every tile is composed into a heightfield one pixel larger on each side,
11
+ * with that border taken from its eight neighbours. The shader then samples
12
+ * ONE texture with no edge case at all — it never learns that tiles exist.
13
+ *
14
+ * This module is deliberately ignorant of WHERE heights come from. The tiled
15
+ * DEM path decodes RGB-encoded bytes; the raster path reads a float band out
16
+ * of a retained decode. Both hand this a `HeightSource`, which is the only
17
+ * thing the apron logic has ever needed.
18
+ */
19
+ /** A tile's heights, addressed in its own pixel grid. */
20
+ export interface HeightSource {
21
+ width: number;
22
+ height: number;
23
+ at(px: number, py: number): number;
24
+ }
25
+ /** A tile's heights with a one-pixel apron: `(width + 2) * (height + 2)` floats. */
26
+ export interface PaddedHeights {
27
+ /** The INTERIOR size — the apron is one pixel outside this on every side. */
28
+ width: number;
29
+ height: number;
30
+ data: Float32Array;
31
+ }
32
+ /** Index into the padded grid from INTERIOR coordinates, which may be -1 or width/height (the apron). */
33
+ export declare function paddedIndex(width: number, px: number, py: number): number;
34
+ /**
35
+ * Composes `own` plus its eight neighbours into a padded heightfield.
36
+ *
37
+ * `neighbour(dx, dy)` returns the tile at that offset, or null when there
38
+ * genuinely isn't one — off the edge of the world or of the source's extent,
39
+ * a failed fetch, or a tile whose dimensions don't line up with this one
40
+ * (which happens at a raster's clipped edge, where a strip could only be
41
+ * copied into the wrong rows).
42
+ *
43
+ * A missing neighbour falls back to CLAMPING that border — the artifact this
44
+ * whole module exists to avoid, but confined to the one edge that has no
45
+ * honest answer. The clamp is seeded BEFORE the neighbour pass on purpose: a
46
+ * zero left there would decode as a sea-level cliff and draw a HARD black
47
+ * line, which is worse than the pale one.
48
+ */
49
+ export declare function composeApron(own: HeightSource, neighbour: (dx: number, dy: number) => HeightSource | null): PaddedHeights;
50
+ /** The eight neighbour offsets, in a stable order. */
51
+ export declare const NEIGHBOUR_OFFSETS: readonly {
52
+ dx: number;
53
+ dy: number;
54
+ }[];
@@ -0,0 +1,160 @@
1
+ const d = 40075016686e-3, u = 110574, m = 111320, o = Math.PI / 180, f = { none: 0, mercator: 1, geographic: 2 };
2
+ function E(e, a, s = "HillshadeLayer") {
3
+ const h = (l) => l == null || l === "" ? [] : typeof l == "number" ? Number.isFinite(l) ? [l] : [] : String(l).split(/[\s,]+/).filter(Boolean).map(Number).filter((r) => Number.isFinite(r));
4
+ let t = h(e);
5
+ t.length === 0 && (t = [315]), t.length > 4 && (console.warn(`[onlymapjs] ${s}: sun-azimuth takes at most 4 azimuths — using the first 4 of ${t.length}.`), t = t.slice(0, 4));
6
+ let i = h(a);
7
+ (i.length !== t.length || i.some((l) => l < 0)) && (i.length > 0 && console.warn(`[onlymapjs] ${s}: sun-weight must give one non-negative number per sun-azimuth (${t.length}) — using equal weights.`), i = t.map(() => 1));
8
+ const n = i.reduce((l, r) => l + r, 0);
9
+ return i = n > 0 ? i.map((l) => l / n) : t.map(() => 1 / t.length), { azimuths: t, weights: i };
10
+ }
11
+ const g = `uniform hillshadeUniforms {
12
+ vec4 azimuths;
13
+ vec4 weights;
14
+ vec2 interiorOffset;
15
+ vec2 interiorScale;
16
+ vec2 texel;
17
+ vec2 metresPerTexel;
18
+ vec2 latBounds;
19
+ float latMode;
20
+ float sunElevation;
21
+ float zFactor;
22
+ float composite;
23
+ } hillshade;
24
+ `, z = (
25
+ /* glsl */
26
+ `
27
+ uniform sampler2D hillshadeHeights;
28
+
29
+ float hillshade_light(vec3 normal, float azimuth, float elevation) {
30
+ float ce = cos(elevation);
31
+ vec3 sun = vec3(sin(azimuth) * ce, cos(azimuth) * ce, sin(elevation));
32
+ return max(dot(normal, sun), 0.0);
33
+ }
34
+ `
35
+ ), v = (
36
+ /* glsl */
37
+ `
38
+ vec2 hsUV = hillshade.interiorOffset + geometry.uv * hillshade.interiorScale;
39
+ vec2 hsT = hillshade.texel;
40
+ float z00 = texture(hillshadeHeights, hsUV + vec2(-hsT.x, -hsT.y)).r;
41
+ float z01 = texture(hillshadeHeights, hsUV + vec2(0.0, -hsT.y)).r;
42
+ float z02 = texture(hillshadeHeights, hsUV + vec2(hsT.x, -hsT.y)).r;
43
+ float z10 = texture(hillshadeHeights, hsUV + vec2(-hsT.x, 0.0)).r;
44
+ float z12 = texture(hillshadeHeights, hsUV + vec2(hsT.x, 0.0)).r;
45
+ float z20 = texture(hillshadeHeights, hsUV + vec2(-hsT.x, hsT.y)).r;
46
+ float z21 = texture(hillshadeHeights, hsUV + vec2(0.0, hsT.y)).r;
47
+ float z22 = texture(hillshadeHeights, hsUV + vec2(hsT.x, hsT.y)).r;
48
+
49
+ float dzdu = ((z02 + 2.0 * z12 + z22) - (z00 + 2.0 * z10 + z20)) / 8.0;
50
+ float dzdv = ((z20 + 2.0 * z21 + z22) - (z00 + 2.0 * z01 + z02)) / 8.0;
51
+
52
+ // Ground scale per texel, corrected for latitude where the CRS requires it.
53
+ vec2 mpt = hillshade.metresPerTexel;
54
+ if (hillshade.latMode > 0.5) {
55
+ float t = mix(hillshade.latBounds.x, hillshade.latBounds.y, geometry.uv.y);
56
+ if (hillshade.latMode < 1.5) {
57
+ // Mercator: conformal, so the same factor applies to both axes.
58
+ float cosLat = 1.0 / cosh(t);
59
+ mpt *= cosLat;
60
+ } else {
61
+ // Geographic: only longitude degrees shrink toward the poles.
62
+ mpt.x *= cos(t);
63
+ }
64
+ }
65
+
66
+ float gradEast = dzdu / mpt.x;
67
+ float gradNorth = -dzdv / mpt.y; // v increases southward
68
+ vec3 normal = normalize(vec3(-gradEast * hillshade.zFactor, -gradNorth * hillshade.zFactor, 1.0));
69
+
70
+ float shade =
71
+ hillshade.weights.x * hillshade_light(normal, hillshade.azimuths.x, hillshade.sunElevation)
72
+ + hillshade.weights.y * hillshade_light(normal, hillshade.azimuths.y, hillshade.sunElevation)
73
+ + hillshade.weights.z * hillshade_light(normal, hillshade.azimuths.z, hillshade.sunElevation)
74
+ + hillshade.weights.w * hillshade_light(normal, hillshade.azimuths.w, hillshade.sunElevation);
75
+ shade = clamp(shade, 0.0, 1.0);
76
+
77
+ if (hillshade.composite > 0.5) {
78
+ // Multiply into whatever the chain produced — a hypsometric colormap, or
79
+ // (with the layer's multiply blend parameters) the framebuffer itself,
80
+ // where white is the identity and opacity fades toward it.
81
+ color = vec4(color.rgb * mix(1.0, shade, layer.opacity), color.a);
82
+ } else {
83
+ // deck's framebuffer is PREMULTIPLIED (the 0.9.1 lesson), so the colour is
84
+ // scaled by its own alpha on the way out.
85
+ color = vec4(vec3(shade) * layer.opacity, layer.opacity);
86
+ }
87
+ `
88
+ ), p = {
89
+ name: "hillshade",
90
+ fs: g,
91
+ inject: {
92
+ "fs:#decl": z,
93
+ "fs:DECKGL_FILTER_COLOR": v
94
+ },
95
+ uniformTypes: {
96
+ azimuths: "vec4<f32>",
97
+ weights: "vec4<f32>",
98
+ interiorOffset: "vec2<f32>",
99
+ interiorScale: "vec2<f32>",
100
+ texel: "vec2<f32>",
101
+ metresPerTexel: "vec2<f32>",
102
+ latBounds: "vec2<f32>",
103
+ latMode: "f32",
104
+ sunElevation: "f32",
105
+ zFactor: "f32",
106
+ composite: "f32"
107
+ },
108
+ // The sampler rides alongside the uniform block, exactly as CompositeBands
109
+ // binds band0-band3: a texture is a BINDING, never a member of a UBO.
110
+ getUniforms: (e) => e
111
+ };
112
+ function c(e, a) {
113
+ return [e[0] ?? a, e[1] ?? a, e[2] ?? a, e[3] ?? a];
114
+ }
115
+ function x(e) {
116
+ return Math.log(Math.tan(Math.PI / 4 + Math.max(-85.0511, Math.min(85.0511, e)) * o / 2));
117
+ }
118
+ function y(e, a, s) {
119
+ const h = d / 2 ** e;
120
+ return { metresPerTexel: [h / a, h / s], latMode: "mercator" };
121
+ }
122
+ function T(e) {
123
+ const { unitsPerPixelX: a, unitsPerPixelY: s, crsUnits: h } = e;
124
+ if (h === "degree")
125
+ return {
126
+ metresPerTexel: [a * m, s * u],
127
+ latMode: "geographic"
128
+ };
129
+ const t = h === "foot" ? 0.3048 : 1;
130
+ return { metresPerTexel: [a * t, s * t], latMode: "none" };
131
+ }
132
+ function w(e) {
133
+ const a = e.width + 2, s = e.height + 2, h = (t) => e.latMode === "mercator" ? x(t) : t * o;
134
+ return {
135
+ azimuths: c(
136
+ e.azimuths.map((t) => t * o),
137
+ 0
138
+ ),
139
+ // A light that does not exist contributes nothing: the unused slots carry
140
+ // weight 0, which is why the shader can unroll to four unconditional
141
+ // multiply-adds and never branch on a light count.
142
+ weights: c(e.weights, 0),
143
+ interiorOffset: [1 / a, 1 / s],
144
+ interiorScale: [e.width / a, e.height / s],
145
+ texel: [1 / a, 1 / s],
146
+ metresPerTexel: e.metresPerTexel,
147
+ latBounds: [h(e.north), h(e.south)],
148
+ latMode: f[e.latMode],
149
+ sunElevation: e.sunElevation * o,
150
+ zFactor: e.zFactor,
151
+ composite: e.composite ? 1 : 0
152
+ };
153
+ }
154
+ export {
155
+ p as a,
156
+ w as h,
157
+ y as m,
158
+ E as p,
159
+ T as r
160
+ };