@nika-js/onlymap 0.8.4 → 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 (53) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +56 -3
  3. package/dist/{LercDecode.es-BKustV-1.js → LercDecode.es-IEPCRZOv.js} +1 -1
  4. package/dist/{basemap-B0SwrOqQ.js → basemap-DL0mk9Bf.js} +780 -780
  5. package/dist/dem-decode.d.ts +58 -0
  6. package/dist/elements/om-map.d.ts +12 -0
  7. package/dist/{geoparquet-C5E6N6G0.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 +2 -2
  15. package/dist/{index-BLIjrGOE.js → index-BjcPjICh.js} +28 -28
  16. package/dist/{index-xUVMTGZG.js → index-CvuDsvnk.js} +23 -23
  17. package/dist/index-DO_w0tqR.js +514 -0
  18. package/dist/{index-BnQDfKfE.js → index-DdTZSuAb.js} +1 -1
  19. package/dist/{index-D5Fqn_eZ.js → index-oY3XHIux.js} +13145 -12484
  20. package/dist/{index-CaM1C93G.js → index-vLXZuog4.js} +1 -1
  21. package/dist/index.d.ts +3 -0
  22. package/dist/lerc-Bph62dCb.js +22 -0
  23. package/dist/onlymap.standalone.js +28919 -27259
  24. package/dist/onlymapjs.js +95 -92
  25. package/dist/post-process/catalogue.d.ts +61 -0
  26. package/dist/post-process/compile.d.ts +37 -0
  27. package/dist/post-process/index.d.ts +71 -0
  28. package/dist/post-process/ops.d.ts +22 -0
  29. package/dist/post-process/presets.d.ts +33 -0
  30. package/dist/post-process/validate.d.ts +8 -0
  31. package/dist/programmatic.d.ts +11 -0
  32. package/dist/{raster-B_wekCHv.js → raster-D-eTzCE3.js} +609 -499
  33. package/dist/raster-hillshade.d.ts +119 -0
  34. package/dist/{raster-pipeline-Dn2fkLYx.js → raster-pipeline-BlOnMPJe.js} +510 -484
  35. package/dist/raster-pipeline.d.ts +10 -0
  36. package/dist/raster.d.ts +5 -0
  37. package/dist/runtime-core.d.ts +39 -1
  38. package/dist/terrain-heightfield.d.ts +0 -16
  39. package/dist/terrain-sample.d.ts +0 -13
  40. package/dist/version.d.ts +1 -1
  41. package/dist/volumetrics.d.ts +7 -0
  42. package/dist/{zarr-Dan2ab-l.js → zarr-BGDoEtFb.js} +2 -2
  43. package/docs/cartograph.md +2 -2
  44. package/docs/design/hillshade.md +290 -0
  45. package/docs/effects.md +208 -0
  46. package/docs/hillshade.md +203 -0
  47. package/llms.txt +3 -1
  48. package/onlymapjs.attributes.json +27 -2
  49. package/onlymapjs.html-data.json +207 -6
  50. package/package.json +13 -9
  51. package/skills/onlymapjs/SKILL.md +4 -2
  52. package/skills/onlymapjs/references/syntax.md +17 -2
  53. package/dist/lerc-TxsFLMlC.js +0 -30
@@ -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. */
@@ -403,6 +405,16 @@ export declare class OmMapElement extends HTMLElementBase {
403
405
  * shouldn't trigger a reconcile per edit.
404
406
  */
405
407
  private scheduleReconcile;
408
+ /**
409
+ * Hand the runtime this map's `<om-effect>` chain.
410
+ *
411
+ * The presence check is eager and the PARSE is not: the op catalogue and its
412
+ * GLSL live in a lazy chunk, so a map with no effects — which is almost
413
+ * every map — never downloads a line of it. The runtime compares the chain
414
+ * by value, so re-parsing on every reconcile costs nothing when nothing
415
+ * changed.
416
+ */
417
+ private reconcileEffects;
406
418
  private reconcile;
407
419
  /**
408
420
  * Re-runs on every reconcile when the `validate` attribute is present —
@@ -1,4 +1,4 @@
1
- import { r as p, n as d } from "./index-D5Fqn_eZ.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
+ };
@@ -0,0 +1,152 @@
1
+ /**
2
+ * The hillshade GPU module and its arithmetic — shared by BOTH entry points.
3
+ *
4
+ * `HillshadeLayer` (tiled DEM, Web Mercator) and `shading="hillshade"` on a
5
+ * raster source (the author's own DEM, in its own CRS) run THIS module, with
6
+ * the same uniforms. They do not produce identical pixels over the same
7
+ * ground and should not be asked to: the tile path is integer-encoded height
8
+ * in Web Mercator at a tile zoom, the raster path is float bands in the
9
+ * source CRS at the source resolution, so pixel ground size, reprojection and
10
+ * nodata all differ before the shader runs. What is shared is the ARITHMETIC,
11
+ * which is the part that could silently drift.
12
+ *
13
+ * WHY THIS IS NOT IN `raster-pipeline.ts`. That pipeline's modules inject at
14
+ * `DECKGL_FILTER_COLOR`, which is POINTWISE — a module there is handed
15
+ * `color`, not the means to sample its neighbours. Hillshade is the first
16
+ * neighbourhood operation anyone has wanted, and a neighbourhood operation
17
+ * needs its own sampler and texel size. Declaring the sampler here (via
18
+ * `fs:#decl`, exactly as upstream's `CompositeBands` declares `band0`–
19
+ * `band3`) also frees the module from any host layer's declaration order —
20
+ * which is not a nicety but the only thing that compiles: a module's
21
+ * `DECKGL_FILTER_COLOR` injection becomes a function emitted ABOVE the host
22
+ * layer's own source, so reaching for BitmapLayer's `bitmapTexture` there
23
+ * gives "undeclared identifier" on every tap.
24
+ */
25
+ /** Equatorial circumference (m) — the Web Mercator scale numerator. */
26
+ export declare const EARTH_CIRCUMFERENCE = 40075016.686;
27
+ /** Metres per degree of latitude (mean). Latitude degrees barely vary; longitude degrees do, which is the whole point of `latMode`. */
28
+ export declare const METRES_PER_DEGREE_LAT = 110574;
29
+ /** Metres per degree of longitude AT THE EQUATOR — scaled by cos(latitude) per fragment. */
30
+ export declare const METRES_PER_DEGREE_LNG = 111320;
31
+ export declare const DEG: number;
32
+ /**
33
+ * How ground scale varies with latitude across one tile.
34
+ *
35
+ * This is the one place the two entry points genuinely differ, and getting it
36
+ * wrong does not look like a bug — it looks like SHEARED terrain, with every
37
+ * shadow falling at a consistently wrong angle.
38
+ *
39
+ * - `none` — a projected CRS whose units are already linear ground distance
40
+ * (UTM metres, state-plane feet). The scale is constant across the tile.
41
+ * - `mercator` — Web Mercator. Conformal, so ONE scale serves both axes, and
42
+ * the falloff is exact via cos φ = 1 / cosh(y) with y the Mercator
43
+ * ordinate. No inverse projection in the shader.
44
+ * - `geographic` — a lng/lat CRS (EPSG:4326). ANISOTROPIC: a degree of
45
+ * latitude is ~constant while a degree of longitude shrinks with cos φ, so
46
+ * only the X axis scales. At 36°N that is a 1.23x difference between the
47
+ * axes — ignore it and east-west slopes come out ~23% too gentle.
48
+ */
49
+ export type LatitudeMode = "none" | "mercator" | "geographic";
50
+ /**
51
+ * Parses `sun-azimuth` / `sun-weight`: one to four numbers, space- or
52
+ * comma-separated.
53
+ *
54
+ * `multi-directional` is deliberately NOT a boolean anywhere in this feature.
55
+ * A preset must be expressible in the tier below it (the rule `presets.ts`
56
+ * states for `<om-effect>`), and a boolean that blended azimuths the author
57
+ * could not otherwise name would be capability reachable only from the
58
+ * shorthand. Swiss-style relief wants the azimuths CHOSEN for the terrain,
59
+ * which is a tuning job, not a toggle.
60
+ */
61
+ export declare function parseLights(azimuth: string | number | null | undefined, weight: string | number | null | undefined, label?: string): {
62
+ azimuths: number[];
63
+ weights: number[];
64
+ };
65
+ /** The luma shader module. Identical object for both entry points — only the uniforms differ. */
66
+ export declare const hillshadeModule: {
67
+ name: string;
68
+ fs: string;
69
+ inject: {
70
+ "fs:#decl": string;
71
+ "fs:DECKGL_FILTER_COLOR": string;
72
+ };
73
+ uniformTypes: {
74
+ azimuths: string;
75
+ weights: string;
76
+ interiorOffset: string;
77
+ interiorScale: string;
78
+ texel: string;
79
+ metresPerTexel: string;
80
+ latBounds: string;
81
+ latMode: string;
82
+ sunElevation: string;
83
+ zFactor: string;
84
+ composite: string;
85
+ };
86
+ getUniforms: (props: Record<string, unknown>) => Record<string, unknown>;
87
+ };
88
+ export interface HillshadeUniformValues {
89
+ azimuths: [number, number, number, number];
90
+ weights: [number, number, number, number];
91
+ interiorOffset: [number, number];
92
+ interiorScale: [number, number];
93
+ texel: [number, number];
94
+ metresPerTexel: [number, number];
95
+ latBounds: [number, number];
96
+ latMode: number;
97
+ sunElevation: number;
98
+ zFactor: number;
99
+ composite: number;
100
+ }
101
+ /** Mercator ordinate (radians) of a latitude, clamped to the projection's own limit. */
102
+ export declare function mercatorY(lat: number): number;
103
+ /**
104
+ * Ground scale for one Web Mercator tile, stated AT THE EQUATOR — the shader
105
+ * applies the cos φ falloff per fragment, which is why this number is
106
+ * deliberately latitude-free.
107
+ */
108
+ export declare function mercatorTileScale(zoom: number, width: number, height: number): {
109
+ metresPerTexel: [number, number];
110
+ latMode: LatitudeMode;
111
+ };
112
+ /**
113
+ * Ground scale for one raster tile from a source with a known pixel size.
114
+ *
115
+ * `unitsPerPixel` is in the CRS's own units — degrees for a geographic CRS,
116
+ * metres or feet for a projected one. A geographic source keeps its X scale
117
+ * stated at the equator (the shader scales it by cos φ); everything else is
118
+ * already linear and converts once, here.
119
+ */
120
+ export declare function rasterTileScale(opts: {
121
+ unitsPerPixelX: number;
122
+ unitsPerPixelY: number;
123
+ /** Pixels of the SOURCE covered by this tile, per axis. */
124
+ tileWidth: number;
125
+ tileHeight: number;
126
+ crsUnits: "degree" | "metre" | "foot";
127
+ }): {
128
+ metresPerTexel: [number, number];
129
+ latMode: LatitudeMode;
130
+ };
131
+ /**
132
+ * Every uniform for one tile. Pure, so the arithmetic that decides what the
133
+ * relief MEANS is unit-testable without a GPU.
134
+ *
135
+ * `north`/`south` are the tile's latitude bounds in degrees, and are read
136
+ * only when `latMode` needs them — a projected source may pass anything.
137
+ */
138
+ export declare function hillshadeUniformsForTile(opts: {
139
+ /** INTERIOR size of the padded heightfield; the apron is one pixel outside it. */
140
+ width: number;
141
+ height: number;
142
+ metresPerTexel: [number, number];
143
+ latMode: LatitudeMode;
144
+ north: number;
145
+ south: number;
146
+ azimuths: number[];
147
+ weights: number[];
148
+ sunElevation: number;
149
+ zFactor: number;
150
+ /** true multiplies the shade into the existing colour; false replaces it. */
151
+ composite: boolean;
152
+ }): HillshadeUniformValues;