@nika-js/onlymap 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +50 -3
- package/dist/{LercDecode.es-BMcxSLhD.js → LercDecode.es-IEPCRZOv.js} +1 -1
- package/dist/{basemap-m98j2wxG.js → basemap-9lXclX9H.js} +3882 -3980
- package/dist/cartograph/elements/om-frame.d.ts +67 -1
- package/dist/cartograph/georef.d.ts +18 -4
- package/dist/cartograph/schema.d.ts +11 -0
- package/dist/cartograph.js +1480 -1311
- package/dist/cartograph.standalone.js +1808 -1615
- package/dist/{cityjson-D_V5GY8b.js → cityjson-k-z1r6c0.js} +1 -1
- package/dist/{crs-DsDQ4Q4i.js → crs-BzE_KP4M.js} +25 -2
- package/dist/{crs-Ciu7Xs7a.js → crs-ChglCB3O.js} +39 -16
- package/dist/dem-decode.d.ts +58 -0
- package/dist/elements/om-map.d.ts +12 -0
- package/dist/{geoparquet-XOwOmChh.js → geoparquet-DFDZDBun.js} +10 -10
- package/dist/globe-view-D9wjfL0T.js +104 -0
- package/dist/hillshade-C2BQr6pd.js +298 -0
- package/dist/hillshade-apron-Bem3DWyJ.js +40 -0
- package/dist/hillshade-apron.d.ts +54 -0
- package/dist/hillshade-shader-DI2uLSNU.js +165 -0
- package/dist/hillshade-shader.d.ts +168 -0
- package/dist/hillshade.d.ts +163 -0
- package/dist/html-data.d.ts +1 -1
- package/dist/{ifc-Dc-TdSJr.js → ifc-DXwePQRv.js} +131 -131
- package/dist/{index-DzOvV-O7.js → index-4Tvlt0iO.js} +57 -57
- package/dist/{index-HZWdgtm4.js → index-Bn66l3KG.js} +1 -1
- package/dist/index-BuXrMq5D.js +322 -0
- package/dist/index-CNRbZHkK.js +459 -0
- package/dist/{index-DDNElBTs.js → index-CkovmN47.js} +1 -1
- package/dist/index-CmuOizAF.js +641 -0
- package/dist/index-CvT5QHBS.js +65 -0
- package/dist/{index-BMbpftvm.js → index-DnVHKI61.js} +1 -1
- package/dist/{index-BSAY6CWm.js → index-JjyDEqAS.js} +18911 -17456
- package/dist/index.d.ts +4 -0
- package/dist/layer-registry.d.ts +27 -0
- package/dist/lerc-C1mQ_Kqq.js +22 -0
- package/dist/onlymap.standalone.js +49075 -45717
- package/dist/onlymapjs.js +73 -70
- package/dist/parse-manifest.d.ts +6 -0
- package/dist/plane-camera.d.ts +59 -0
- package/dist/plane-layers.d.ts +56 -0
- package/dist/plane-tiles.d.ts +99 -0
- package/dist/plane-tileset.d.ts +31 -0
- package/dist/plane-warp.d.ts +91 -0
- package/dist/post-process-effect-DfslKPM6.js +197 -0
- package/dist/programmatic.d.ts +16 -1
- package/dist/projection.d.ts +118 -0
- package/dist/{raster-Dg5p_99H.js → raster-D2NzdjZE.js} +609 -499
- package/dist/raster-hillshade.d.ts +119 -0
- package/dist/{raster-pipeline-DhjkqDYd.js → raster-pipeline-qnD1icOv.js} +511 -484
- package/dist/raster-pipeline.d.ts +10 -0
- package/dist/raster.d.ts +5 -0
- package/dist/runtime-core.d.ts +140 -1
- package/dist/serialize/clip.d.ts +50 -0
- package/dist/serialize/declutter.d.ts +44 -0
- package/dist/serialize/emit.d.ts +60 -0
- package/dist/serialize/index.d.ts +64 -0
- package/dist/serialize/strategy.d.ts +30 -0
- package/dist/serialize/style.d.ts +77 -0
- package/dist/snapshot.d.ts +46 -0
- package/dist/surface-anchor.d.ts +6 -0
- package/dist/terrain-heightfield.d.ts +0 -16
- package/dist/terrain-sample.d.ts +0 -13
- package/dist/text-on-path-Dm7vtNqt.js +146 -0
- package/dist/text-on-path.d.ts +157 -0
- package/dist/transform/buffer.d.ts +63 -0
- package/dist/transform/contour.d.ts +37 -0
- package/dist/transform/dot-density.d.ts +19 -0
- package/dist/transform/field.d.ts +80 -0
- package/dist/transform/geometry.d.ts +20 -0
- package/dist/transform/index.d.ts +29 -0
- package/dist/transform/simplify.d.ts +10 -0
- package/dist/transform/smooth.d.ts +12 -0
- package/dist/transform-stage.d.ts +92 -0
- package/dist/version.d.ts +1 -1
- package/dist/volumetrics.d.ts +7 -0
- package/dist/{zarr-D3CzK1Zm.js → zarr-D5e5agMG.js} +2 -2
- package/docs/cartograph.md +12 -4
- package/docs/cartography.md +328 -0
- package/docs/design/arrows.md +182 -0
- package/docs/design/carto-substrate.md +1055 -0
- package/docs/design/extensions.md +250 -0
- package/docs/design/hillshade.md +290 -0
- package/docs/effects.md +11 -0
- package/docs/hillshade.md +203 -0
- package/llms.txt +4 -2
- package/onlymapjs.attributes.json +45 -2
- package/onlymapjs.html-data.json +213 -25
- package/package.json +13 -9
- package/skills/onlymapjs/SKILL.md +7 -2
- package/skills/onlymapjs/references/syntax.md +31 -3
- package/dist/index-CfPbQUqO.js +0 -511
- package/dist/lerc-qK-nhCaB.js +0 -30
package/dist/terrain-sample.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One-shot terrain elevation sampling (spec: "Cut/fill volume measurement").
|
|
3
|
-
* Kept separate from terrain.ts, whose header documents it as PURE and
|
|
4
|
-
* unit-testable without a GPU — this module is deliberately the DOM-touching
|
|
5
|
-
* half (fetch + canvas), for the one thing nothing else in this codebase
|
|
6
|
-
* needed before: "what is the real ground height at this lng/lat".
|
|
7
|
-
*
|
|
8
|
-
* Fetches the DEM tile as a blob (never an `<img src>`) so the canvas read
|
|
9
|
-
* below is never tainted regardless of the provider's CORS posture — and
|
|
10
|
-
* since deck.gl's own TerrainLayer already fetches this exact URL template
|
|
11
|
-
* cross-origin to RENDER the surface, a caller only ever reaches this with a
|
|
12
|
-
* URL that's already proven fetchable.
|
|
13
|
-
*/
|
|
14
1
|
import type { LngLat } from "./geodesy";
|
|
15
2
|
import type { TerrainIR } from "./terrain";
|
|
16
3
|
/** Slippy-map tile + fractional pixel covering `lngLat` at `zoom` (256px tiles). Exported for `terrain-heightfield.ts`'s bulk loader — same tile math, no reason to duplicate it. */
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { c as S, a3 as b } from "./index-JjyDEqAS.js";
|
|
2
|
+
const A = Math.PI / 180, P = /* @__PURE__ */ new Map();
|
|
3
|
+
let d = null;
|
|
4
|
+
function T(t) {
|
|
5
|
+
if (typeof document > "u") return null;
|
|
6
|
+
if (!d) {
|
|
7
|
+
const r = document.createElement("canvas");
|
|
8
|
+
r.width = 8, r.height = 8, d = r.getContext("2d");
|
|
9
|
+
}
|
|
10
|
+
return d && (d.font = t), d;
|
|
11
|
+
}
|
|
12
|
+
function C(t, r, e) {
|
|
13
|
+
const n = `${e} 100px ${r}`;
|
|
14
|
+
let s = P.get(n);
|
|
15
|
+
s || (s = /* @__PURE__ */ new Map(), P.set(n, s));
|
|
16
|
+
const c = s.get(t);
|
|
17
|
+
if (c !== void 0) return c;
|
|
18
|
+
const l = T(n), a = l ? l.measureText(t).width / 100 : 0.6;
|
|
19
|
+
return s.set(t, a), a;
|
|
20
|
+
}
|
|
21
|
+
function L(t) {
|
|
22
|
+
const r = [0];
|
|
23
|
+
let e = 0;
|
|
24
|
+
for (let n = 1; n < t.length; n++)
|
|
25
|
+
e += Math.hypot(t[n][0] - t[n - 1][0], t[n][1] - t[n - 1][1]), r.push(e);
|
|
26
|
+
return { cumulative: r, total: e };
|
|
27
|
+
}
|
|
28
|
+
function x(t, r, e) {
|
|
29
|
+
const { cumulative: n } = r;
|
|
30
|
+
if (t.length < 2) return null;
|
|
31
|
+
let s = 1;
|
|
32
|
+
for (; s < n.length - 1 && n[s] < e; ) s++;
|
|
33
|
+
const c = n[s] - n[s - 1], l = c > 0 ? (e - n[s - 1]) / c : 0, a = t[s - 1], o = t[s];
|
|
34
|
+
return {
|
|
35
|
+
position: [a[0] + (o[0] - a[0]) * l, a[1] + (o[1] - a[1]) * l],
|
|
36
|
+
angle: Math.atan2(-(o[1] - a[1]), o[0] - a[0]) * 180 / Math.PI
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function M(t, r, e) {
|
|
40
|
+
if (e === 0) return t;
|
|
41
|
+
const n = (r + 90) * A;
|
|
42
|
+
return [t[0] + Math.cos(n) * e, t[1] - Math.sin(n) * e];
|
|
43
|
+
}
|
|
44
|
+
function z(t) {
|
|
45
|
+
return t === "start" ? "end" : t === "end" ? "start" : "middle";
|
|
46
|
+
}
|
|
47
|
+
function w(t, r, e) {
|
|
48
|
+
if (t.length < 2 || !r) return [];
|
|
49
|
+
const n = L(t);
|
|
50
|
+
if (!(n.total > 0)) return [];
|
|
51
|
+
const s = [...r], c = s.map((i) => C(i, e.fontFamily, e.fontWeight) * e.sizePx + e.letterSpacing), l = c.reduce((i, u) => i + u, 0) - e.letterSpacing;
|
|
52
|
+
if (l > n.total) return [];
|
|
53
|
+
const a = n.total - l, o = e.placement === "start" ? 0 : e.placement === "end" ? a : a / 2, g = x(t, n, o), h = x(t, n, o + l);
|
|
54
|
+
if (g && h && h.position[0] < g.position[0]) {
|
|
55
|
+
const i = [...t].reverse();
|
|
56
|
+
return w(i, r, { ...e, placement: z(e.placement), offsetPx: -e.offsetPx });
|
|
57
|
+
}
|
|
58
|
+
let p = o;
|
|
59
|
+
const m = [];
|
|
60
|
+
for (let i = 0; i < s.length; i++) {
|
|
61
|
+
const u = x(t, n, p + (c[i] - e.letterSpacing) / 2);
|
|
62
|
+
if (!u) break;
|
|
63
|
+
m.push({ position: M(u.position, u.angle, e.offsetPx), angle: u.angle, char: s[i] }), p += c[i];
|
|
64
|
+
}
|
|
65
|
+
return m;
|
|
66
|
+
}
|
|
67
|
+
function y(t, r, e, n, s) {
|
|
68
|
+
if (typeof t != "function") return t ?? s;
|
|
69
|
+
try {
|
|
70
|
+
return t(r, { index: e, data: n });
|
|
71
|
+
} catch {
|
|
72
|
+
return s;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class O extends S {
|
|
76
|
+
static layerName = "OmTextOnPathLayer";
|
|
77
|
+
static defaultProps = {
|
|
78
|
+
getPath: { type: "accessor", value: (r) => r.path },
|
|
79
|
+
getText: { type: "accessor", value: (r) => r.text },
|
|
80
|
+
getSize: { type: "accessor", value: 14 },
|
|
81
|
+
getColor: { type: "accessor", value: [30, 30, 30, 255] },
|
|
82
|
+
fontFamily: { type: "string", value: "sans-serif" },
|
|
83
|
+
fontWeight: { type: "string", value: "normal" },
|
|
84
|
+
letterSpacing: { type: "number", value: 0 },
|
|
85
|
+
offset: { type: "number", value: 0 },
|
|
86
|
+
placement: { type: "string", value: "middle" },
|
|
87
|
+
maxLabels: { type: "number", value: 2e3 }
|
|
88
|
+
};
|
|
89
|
+
/** Recompute on a viewport change: a glyph advance is pixels and a path is world distance. */
|
|
90
|
+
shouldUpdateState({ changeFlags: r }) {
|
|
91
|
+
return !!r.somethingChanged;
|
|
92
|
+
}
|
|
93
|
+
renderLayers() {
|
|
94
|
+
const r = this.context.viewport;
|
|
95
|
+
if (!r || !r.width) return null;
|
|
96
|
+
const e = Array.isArray(this.props.data) ? this.props.data : [], n = ["start", "middle", "end"].includes(this.props.placement) ? this.props.placement : "middle", s = this.props.fontFamily ?? "sans-serif", c = this.props.fontWeight ?? "normal", l = this.props.maxLabels ?? 2e3, a = [];
|
|
97
|
+
for (let o = 0; o < e.length && a.length < l; o++) {
|
|
98
|
+
const g = e[o], h = y(this.props.getPath, g, o, e, void 0), p = String(y(this.props.getText, g, o, e, "") ?? "");
|
|
99
|
+
if (!Array.isArray(h) || h.length < 2 || !p) continue;
|
|
100
|
+
const m = Number(y(this.props.getSize, g, o, e, 14)) || 14, i = y(this.props.getColor, g, o, e, [30, 30, 30, 255]), u = h.map((f) => r.project([f[0], f[1]]).slice(0, 2));
|
|
101
|
+
for (const f of w(u, p, {
|
|
102
|
+
fontFamily: s,
|
|
103
|
+
fontWeight: c,
|
|
104
|
+
sizePx: m,
|
|
105
|
+
letterSpacing: this.props.letterSpacing ?? 0,
|
|
106
|
+
offsetPx: this.props.offset ?? 0,
|
|
107
|
+
placement: n
|
|
108
|
+
})) {
|
|
109
|
+
const v = r.unproject([f.position[0], f.position[1]]);
|
|
110
|
+
if (a.push({
|
|
111
|
+
char: f.char,
|
|
112
|
+
position: [v[0], v[1]],
|
|
113
|
+
angle: f.angle,
|
|
114
|
+
size: m,
|
|
115
|
+
color: Array.isArray(i) ? i : [30, 30, 30, 255]
|
|
116
|
+
}), a.length >= l) break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return a.length === 0 ? null : new b(
|
|
120
|
+
this.getSubLayerProps({ id: "glyphs" }),
|
|
121
|
+
{
|
|
122
|
+
data: a,
|
|
123
|
+
getText: (o) => o.char,
|
|
124
|
+
getPosition: (o) => o.position,
|
|
125
|
+
getAngle: (o) => o.angle,
|
|
126
|
+
getSize: (o) => o.size,
|
|
127
|
+
getColor: (o) => o.color,
|
|
128
|
+
fontFamily: s,
|
|
129
|
+
fontWeight: c,
|
|
130
|
+
getTextAnchor: "middle",
|
|
131
|
+
getAlignmentBaseline: "center",
|
|
132
|
+
characterSet: "auto",
|
|
133
|
+
// Every glyph is its own instance, so deck's own collision would fight
|
|
134
|
+
// the word it belongs to. The whole label is placed or dropped.
|
|
135
|
+
updateTriggers: { getText: a.length, getPosition: a.length }
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
+
O as OmTextOnPathLayer,
|
|
142
|
+
C as charAdvance,
|
|
143
|
+
L as pathMetrics,
|
|
144
|
+
w as placeTextOnPath,
|
|
145
|
+
x as pointAtDistance
|
|
146
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `TextOnPathLayer` — a label that follows the line it names.
|
|
3
|
+
*
|
|
4
|
+
* The oldest label convention there is: a river's name runs along the river, a
|
|
5
|
+
* coastline's along the coast, a contour's along the contour. deck has no such
|
|
6
|
+
* layer, so this is a composite that explodes each string into ONE TEXT
|
|
7
|
+
* INSTANCE PER GLYPH, each placed at its own arc-length position along the path
|
|
8
|
+
* and rotated to the local tangent. The rendering is therefore an ordinary
|
|
9
|
+
* `TextLayer` — same font atlas, same collision behaviour, same picking.
|
|
10
|
+
*
|
|
11
|
+
* **Placement is recomputed when the camera moves, and cannot not be.** A glyph
|
|
12
|
+
* advance is a length in PIXELS while a path is a length in the world, so the
|
|
13
|
+
* mapping between them is the current scale. On a print sheet, where the camera
|
|
14
|
+
* is fixed, that resolves once and stays put — which is the case this exists
|
|
15
|
+
* for. On a live map it follows the zoom, which is why the work is bounded by
|
|
16
|
+
* `maxLabels` rather than by the data.
|
|
17
|
+
*
|
|
18
|
+
* Measured with a real canvas rather than an estimate, for the reason
|
|
19
|
+
* `cartograph/textlayout.ts` already states: two measurers disagree at the
|
|
20
|
+
* margins, so everything that has to agree must read the SAME numbers. The
|
|
21
|
+
* serializer emits SVG `<textPath>` from the same path and string, which is the
|
|
22
|
+
* one output where the browser re-measures — and it is also the output where
|
|
23
|
+
* `<textPath>` is exactly the right primitive.
|
|
24
|
+
*/
|
|
25
|
+
import { CompositeLayer, type Layer } from "@deck.gl/core";
|
|
26
|
+
export type PathPlacement = "start" | "middle" | "end";
|
|
27
|
+
export interface OmTextOnPathLayerProps {
|
|
28
|
+
data?: unknown;
|
|
29
|
+
getPath?: unknown;
|
|
30
|
+
getText?: unknown;
|
|
31
|
+
getSize?: unknown;
|
|
32
|
+
getColor?: unknown;
|
|
33
|
+
fontFamily?: string;
|
|
34
|
+
fontWeight?: string | number;
|
|
35
|
+
/** Extra tracking between glyphs, in pixels. Letter-spaced names are a cartographic convention, not a flourish. */
|
|
36
|
+
letterSpacing?: number;
|
|
37
|
+
/** Perpendicular offset in pixels — positive is to the LEFT of the path's direction. */
|
|
38
|
+
offset?: number;
|
|
39
|
+
placement?: PathPlacement;
|
|
40
|
+
/** Ceiling on emitted glyphs, so one enormous label set cannot wedge a frame. */
|
|
41
|
+
maxLabels?: number;
|
|
42
|
+
opacity?: number;
|
|
43
|
+
visible?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Advance width of one character at 100px, which scales linearly to any size. */
|
|
46
|
+
export declare function charAdvance(char: string, fontFamily: string, fontWeight: string | number): number;
|
|
47
|
+
/**
|
|
48
|
+
* Placement happens in SCREEN PIXELS, and that is the whole design.
|
|
49
|
+
*
|
|
50
|
+
* The first version worked in ground metres and was wrong in a way that only a
|
|
51
|
+
* projected sheet revealed: a glyph advance is a length in PIXELS, so turning
|
|
52
|
+
* it into a world distance needs a scale — and "the world" is lng/lat on a
|
|
53
|
+
* Mercator map and plane metres on a projected one, with the layer's own data
|
|
54
|
+
* already converted to whichever by the time it arrives. Two spaces, one set
|
|
55
|
+
* of arithmetic, and it produced label lengths off by seven orders of
|
|
56
|
+
* magnitude on an Albers plate.
|
|
57
|
+
*
|
|
58
|
+
* Projecting the path first removes the question entirely: advances are
|
|
59
|
+
* already pixels, the path is already pixels, and each glyph's centre is
|
|
60
|
+
* unprojected back into whatever space the viewport uses. Correct in every
|
|
61
|
+
* projection, and shorter.
|
|
62
|
+
*/
|
|
63
|
+
export type ScreenPoint = [number, number];
|
|
64
|
+
/** Cumulative pixel length along a projected path. */
|
|
65
|
+
export declare function pathMetrics(path: readonly ScreenPoint[]): {
|
|
66
|
+
cumulative: number[];
|
|
67
|
+
total: number;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The screen point and tangent angle at a pixel distance along the path.
|
|
71
|
+
*
|
|
72
|
+
* The angle is in deck's `getAngle` convention: DEGREES COUNTERCLOCKWISE with
|
|
73
|
+
* 0 pointing east. Screen y runs DOWN, so the sign is flipped on the way out —
|
|
74
|
+
* without that every label reads mirrored, which looks like a broken font
|
|
75
|
+
* rather than a wrong angle.
|
|
76
|
+
*/
|
|
77
|
+
export declare function pointAtDistance(path: readonly ScreenPoint[], metrics: {
|
|
78
|
+
cumulative: number[];
|
|
79
|
+
}, distance: number): {
|
|
80
|
+
position: ScreenPoint;
|
|
81
|
+
angle: number;
|
|
82
|
+
} | null;
|
|
83
|
+
export interface PlaceOptions {
|
|
84
|
+
fontFamily: string;
|
|
85
|
+
fontWeight: string | number;
|
|
86
|
+
sizePx: number;
|
|
87
|
+
letterSpacing: number;
|
|
88
|
+
offsetPx: number;
|
|
89
|
+
placement: PathPlacement;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Lay one string along one projected path. Returns nothing when the label is
|
|
93
|
+
* longer than the path — a name that does not fit is DROPPED rather than
|
|
94
|
+
* compressed or run off the end, which is what a cartographer would do and the
|
|
95
|
+
* only option that never leaves a label pointing at nothing.
|
|
96
|
+
*/
|
|
97
|
+
export declare function placeTextOnPath(path: readonly ScreenPoint[], text: string, opts: PlaceOptions): {
|
|
98
|
+
position: ScreenPoint;
|
|
99
|
+
angle: number;
|
|
100
|
+
char: string;
|
|
101
|
+
}[];
|
|
102
|
+
export declare class OmTextOnPathLayer extends CompositeLayer<OmTextOnPathLayerProps> {
|
|
103
|
+
static layerName: string;
|
|
104
|
+
static defaultProps: {
|
|
105
|
+
getPath: {
|
|
106
|
+
type: string;
|
|
107
|
+
value: (d: {
|
|
108
|
+
path?: number[][];
|
|
109
|
+
}) => number[][] | undefined;
|
|
110
|
+
};
|
|
111
|
+
getText: {
|
|
112
|
+
type: string;
|
|
113
|
+
value: (d: {
|
|
114
|
+
text?: string;
|
|
115
|
+
}) => string | undefined;
|
|
116
|
+
};
|
|
117
|
+
getSize: {
|
|
118
|
+
type: string;
|
|
119
|
+
value: number;
|
|
120
|
+
};
|
|
121
|
+
getColor: {
|
|
122
|
+
type: string;
|
|
123
|
+
value: number[];
|
|
124
|
+
};
|
|
125
|
+
fontFamily: {
|
|
126
|
+
type: string;
|
|
127
|
+
value: string;
|
|
128
|
+
};
|
|
129
|
+
fontWeight: {
|
|
130
|
+
type: string;
|
|
131
|
+
value: string;
|
|
132
|
+
};
|
|
133
|
+
letterSpacing: {
|
|
134
|
+
type: string;
|
|
135
|
+
value: number;
|
|
136
|
+
};
|
|
137
|
+
offset: {
|
|
138
|
+
type: string;
|
|
139
|
+
value: number;
|
|
140
|
+
};
|
|
141
|
+
placement: {
|
|
142
|
+
type: string;
|
|
143
|
+
value: string;
|
|
144
|
+
};
|
|
145
|
+
maxLabels: {
|
|
146
|
+
type: string;
|
|
147
|
+
value: number;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
/** Recompute on a viewport change: a glyph advance is pixels and a path is world distance. */
|
|
151
|
+
shouldUpdateState({ changeFlags }: {
|
|
152
|
+
changeFlags: {
|
|
153
|
+
somethingChanged?: boolean;
|
|
154
|
+
};
|
|
155
|
+
}): boolean;
|
|
156
|
+
renderLayers(): Layer | null;
|
|
157
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buffer` — the coastal vignette (docs/design/carto-substrate.md §5).
|
|
3
|
+
*
|
|
4
|
+
* A cartographic ORNAMENT, not an analytic product. The distinction is the
|
|
5
|
+
* same one shaded relief settled: a vignette is measured by eye, a 500 m
|
|
6
|
+
* setback is a number somebody acts on. The first is in scope; the second is a
|
|
7
|
+
* non-goal, and the validator says so rather than letting an author discover
|
|
8
|
+
* it from a wrong answer.
|
|
9
|
+
*
|
|
10
|
+
* `repeat` and `fade` are what the feature is FOR. Once a signed distance
|
|
11
|
+
* field exists, N bands are N thresholds of one field — not N offset
|
|
12
|
+
* operations — so the classic engraved shoreline costs one transform.
|
|
13
|
+
*/
|
|
14
|
+
import { type Ring } from "./field";
|
|
15
|
+
export interface BufferOptions {
|
|
16
|
+
/** Band width in ground metres. Negative buffers inward. */
|
|
17
|
+
distanceMetres: number;
|
|
18
|
+
/** How many bands. 1 is a single outline; 5 is the engraved shoreline. */
|
|
19
|
+
repeat: number;
|
|
20
|
+
/** Fade the bands' opacity outward, as a `_bandOpacity` property per feature. */
|
|
21
|
+
fade: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Cells across the band width. The whole error budget is one cell, so this
|
|
24
|
+
* is the only accuracy knob — and refining it costs memory quadratically for
|
|
25
|
+
* accuracy linearly, which is why the design doc says to improve the SEEDING
|
|
26
|
+
* rather than the grid if it ever matters.
|
|
27
|
+
*/
|
|
28
|
+
cellsPerBand: number;
|
|
29
|
+
/** Hard ceiling on grid cells, so one enormous feature cannot wedge the tab. */
|
|
30
|
+
maxCells: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The grid-cell ceiling, and why it is where it is.
|
|
34
|
+
*
|
|
35
|
+
* `signedDistanceField` holds five arrays at once — `inside` and `outside`
|
|
36
|
+
* (1 byte each) plus `toInside`, `toOutside` and the result (8 bytes each) —
|
|
37
|
+
* which is **26 bytes per cell**. The first ceiling was 40 million, i.e. just
|
|
38
|
+
* over a GIGABYTE of typed arrays before marching squares allocates anything:
|
|
39
|
+
* the tab-wedging the ceiling exists to prevent rather than a guard against
|
|
40
|
+
* it. Four million cells is ~104 MB — large, survivable, and still far more
|
|
41
|
+
* resolution than a band whose whole error budget is one cell ever needs.
|
|
42
|
+
*/
|
|
43
|
+
export declare const BUFFER_MAX_CELLS = 4000000;
|
|
44
|
+
export declare function isPolygonalGeometry(type: unknown): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Buffer one feature's geometry into `repeat` bands.
|
|
47
|
+
*
|
|
48
|
+
* Works in the feature's own local metric frame for the same reason `simplify`
|
|
49
|
+
* does: a band authored in metres must be the same width at every latitude,
|
|
50
|
+
* and a degree of longitude is not a fixed distance.
|
|
51
|
+
*/
|
|
52
|
+
export declare function bufferGeometry(coords: unknown, opts: BufferOptions): {
|
|
53
|
+
rings: Ring[];
|
|
54
|
+
band: number;
|
|
55
|
+
}[];
|
|
56
|
+
/**
|
|
57
|
+
* Buffer every row into band features, OUTERMOST FIRST.
|
|
58
|
+
*
|
|
59
|
+
* Order is the whole visual effect: drawn in this order with a fill, the bands
|
|
60
|
+
* stack into the engraved shoreline of a nineteenth-century chart. Reversed,
|
|
61
|
+
* the widest band covers all the others and the sheet shows one flat halo.
|
|
62
|
+
*/
|
|
63
|
+
export declare function bufferRows(rows: readonly unknown[], opts: BufferOptions, onSkip?: (type: string) => void): unknown[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Grid } from "./field";
|
|
2
|
+
export interface ElevationDecoderSpec {
|
|
3
|
+
rScaler: number;
|
|
4
|
+
gScaler: number;
|
|
5
|
+
bScaler: number;
|
|
6
|
+
offset: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ContourOptions {
|
|
9
|
+
/** `{z}/{x}/{y}` DEM template. */
|
|
10
|
+
template: string;
|
|
11
|
+
decoder: ElevationDecoderSpec;
|
|
12
|
+
/** Tile zoom. Higher is sharper and quadratically more tiles. */
|
|
13
|
+
zoom: number;
|
|
14
|
+
/** `[west, south, east, north]`. */
|
|
15
|
+
bounds: [number, number, number, number];
|
|
16
|
+
/** Contour interval in metres. */
|
|
17
|
+
intervalMetres: number;
|
|
18
|
+
/** Ceiling on tiles fetched, so a careless zoom cannot issue a thousand requests. */
|
|
19
|
+
maxTiles: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Assemble the DEM tiles covering `bounds` into one height grid.
|
|
23
|
+
*
|
|
24
|
+
* The grid is in MERCATOR pixel space — x is longitude-linear and y is the
|
|
25
|
+
* Mercator ordinate — because that is the space the tiles are already in, and
|
|
26
|
+
* resampling them into anything else before contouring would put the
|
|
27
|
+
* resampler's own error into every isoline. The vertices come back out as
|
|
28
|
+
* lng/lat, where the y conversion undoes the ordinate exactly.
|
|
29
|
+
*/
|
|
30
|
+
export declare function assembleHeightGrid(opts: ContourOptions): Promise<{
|
|
31
|
+
heights: Float32Array;
|
|
32
|
+
covered: Uint8Array;
|
|
33
|
+
grid: Grid;
|
|
34
|
+
toLngLat: (x: number, y: number) => [number, number];
|
|
35
|
+
} | null>;
|
|
36
|
+
/** A contour level's features, as GeoJSON LineStrings carrying their own elevation. */
|
|
37
|
+
export declare function contourFromDem(opts: ContourOptions): Promise<unknown[]>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { coordinateCentre } from "./geometry";
|
|
2
|
+
export interface DotDensityOptions {
|
|
3
|
+
/** Row property holding the count to scatter. */
|
|
4
|
+
field: string;
|
|
5
|
+
/** Units of that field per dot. 1000 people per dot, say. */
|
|
6
|
+
per: number;
|
|
7
|
+
seed: number;
|
|
8
|
+
/** Hard ceiling per feature, so one bad row cannot emit a million points. */
|
|
9
|
+
maxPerFeature: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Scatter one feature. Returns Point features carrying the source row's own
|
|
13
|
+
* properties, so every accessor the author already wrote — colour by party,
|
|
14
|
+
* tooltip by county name — keeps working against the dots.
|
|
15
|
+
*/
|
|
16
|
+
export declare function scatterFeature(row: unknown, index: number, opts: DotDensityOptions): unknown[];
|
|
17
|
+
export declare function scatterRows(rows: readonly unknown[], opts: DotDensityOptions): unknown[];
|
|
18
|
+
/** Re-exported for the tests that check the frame's origin choice is irrelevant here. */
|
|
19
|
+
export { coordinateCentre };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared machinery behind `buffer` and `contour`
|
|
3
|
+
* (docs/design/carto-substrate.md §5): rasterize, distance-transform,
|
|
4
|
+
* iso-contour. One piece of code, because a buffer of *d* is exactly "the
|
|
5
|
+
* *d* isoline of a signed distance field", and an isoline is what `contour`
|
|
6
|
+
* wants anyway.
|
|
7
|
+
*
|
|
8
|
+
* **Why a field and not a clipper.** An exact polygon offsetter has zero error
|
|
9
|
+
* and unbounded failure modes on precisely this input — self-intersections,
|
|
10
|
+
* slivers, collapse. A distance field has bounded, MEASURED, sub-visual error
|
|
11
|
+
* and cannot self-intersect, because it never performs polygon arithmetic. It
|
|
12
|
+
* also adds no dependency and needs no licence review. The line this library
|
|
13
|
+
* already drew for relief applies again: a coastal vignette is an ornament
|
|
14
|
+
* measured by eye; a 500 m setback is a number somebody acts on. The first is
|
|
15
|
+
* in scope and the second is a non-goal.
|
|
16
|
+
*/
|
|
17
|
+
export interface Grid {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
/** World units per cell — the whole error budget is proportional to this. */
|
|
21
|
+
cell: number;
|
|
22
|
+
/** World coordinate of cell (0, 0)'s CENTRE. */
|
|
23
|
+
originX: number;
|
|
24
|
+
originY: number;
|
|
25
|
+
}
|
|
26
|
+
export type Ring = number[][];
|
|
27
|
+
/**
|
|
28
|
+
* Even-odd scanline fill of a polygon (outer ring plus holes) into a byte mask.
|
|
29
|
+
*
|
|
30
|
+
* Even-odd rather than nonzero because GeoJSON does not guarantee ring winding,
|
|
31
|
+
* so a hole wound the same way as its outer would fill solid under nonzero. The
|
|
32
|
+
* same reason the serializer emits `fill-rule="evenodd"`.
|
|
33
|
+
*
|
|
34
|
+
* Samples at cell CENTRES. A feature thinner than a cell therefore vanishes —
|
|
35
|
+
* stated rather than fixed: at 300 dpi a cell is 0.085 mm, below a printable
|
|
36
|
+
* hairline, but it is a silent change to the data and the caller should know.
|
|
37
|
+
*/
|
|
38
|
+
export declare function rasterizeRings(rings: readonly Ring[], grid: Grid): Uint8Array;
|
|
39
|
+
/** Distance in CELLS from every cell to the nearest set cell in `mask`. */
|
|
40
|
+
export declare function distanceTransform(mask: Uint8Array, width: number, height: number): Float64Array;
|
|
41
|
+
/**
|
|
42
|
+
* A SIGNED field: positive outside the shape, negative inside.
|
|
43
|
+
*
|
|
44
|
+
* Built by transforming from BOTH SIDES and subtracting — which is what makes
|
|
45
|
+
* a buffer a threshold rather than an operation. `field <= d` is the outward
|
|
46
|
+
* buffer, `field <= -d` the inward one, and `repeat` is several thresholds of
|
|
47
|
+
* one field rather than several offsets of one polygon.
|
|
48
|
+
*
|
|
49
|
+
* **The half-cell correction is not cosmetic.** A cell centre `t` outside the
|
|
50
|
+
* boundary has its nearest INSIDE cell centre about `t + ½` away, and its
|
|
51
|
+
* nearest outside centre at zero — so the raw difference is `t + ½` on one side
|
|
52
|
+
* and `−(t + ½)` on the other. Left uncorrected the zero crossing still lands
|
|
53
|
+
* in the right place (the biases cancel across the boundary), but every level
|
|
54
|
+
* ABOVE zero — which is every buffer anyone actually asks for — sits half a
|
|
55
|
+
* cell too far out. It showed up as a maximum vertex error of exactly 1.000
|
|
56
|
+
* cell widths, and "exactly" is the tell: noise is never round.
|
|
57
|
+
*
|
|
58
|
+
* An earlier version seeded only the inside boundary cells instead. That is
|
|
59
|
+
* cheaper and biased the whole field inward, which is the same class of error
|
|
60
|
+
* with none of the cancellation.
|
|
61
|
+
*/
|
|
62
|
+
export declare function signedDistanceField(rings: readonly Ring[], grid: Grid): Float64Array;
|
|
63
|
+
/**
|
|
64
|
+
* Iso-contour a scalar field at `level`, returning closed rings in world
|
|
65
|
+
* coordinates.
|
|
66
|
+
*
|
|
67
|
+
* Standard marching squares with the saddle resolved by the cell's own mean,
|
|
68
|
+
* which is the choice that keeps a contour from crossing itself. Segments are
|
|
69
|
+
* emitted first and then chained into rings — chaining rather than walking,
|
|
70
|
+
* because a field can carry several disjoint contours at one level and a
|
|
71
|
+
* walker has to be told where to start each time.
|
|
72
|
+
*
|
|
73
|
+
* Measured contribution to the error: about a THOUSANDTH of a cell on a
|
|
74
|
+
* distance field, because such a field is locally linear and linear
|
|
75
|
+
* interpolation reconstructs that almost exactly. Virtually all the error in
|
|
76
|
+
* the pipeline is the rasterization step.
|
|
77
|
+
*/
|
|
78
|
+
export declare function marchingSquares(field: Float64Array | Float32Array, grid: Grid, level: number, covered?: Uint8Array): Ring[];
|
|
79
|
+
/** A grid covering `rings` plus `pad` world units of margin, at `cell` resolution. */
|
|
80
|
+
export declare function gridFor(rings: readonly Ring[], cell: number, pad: number): Grid | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Position = number[];
|
|
2
|
+
export type Ring = Position[];
|
|
3
|
+
/** An equirectangular frame about one latitude: metres east/north of an arbitrary origin. */
|
|
4
|
+
export interface MetricFrame {
|
|
5
|
+
toMetres(p: Position): [number, number];
|
|
6
|
+
toLngLat(x: number, y: number): [number, number];
|
|
7
|
+
}
|
|
8
|
+
export declare function metricFrame(lng0: number, lat0: number): MetricFrame;
|
|
9
|
+
export declare function isRing(c: unknown): c is Ring;
|
|
10
|
+
/** Centre of a geometry's coordinate extent — the local frame's origin, and cheap enough to take per feature. */
|
|
11
|
+
export declare function coordinateCentre(coords: unknown): [number, number] | null;
|
|
12
|
+
/**
|
|
13
|
+
* Rebuild a coordinate tree, handing every innermost RING to `fn`. Returns a
|
|
14
|
+
* new tree; the input is never mutated, because the Data Layer keeps source
|
|
15
|
+
* arrays reference-stable and a transform that edited them in place would
|
|
16
|
+
* make a second chain entry operate on the first one's output.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mapRings(coords: unknown, fn: (ring: Ring) => Ring): unknown;
|
|
19
|
+
/** Whether a ring is closed (first position equals last) — a polygon ring is, a LineString is not. */
|
|
20
|
+
export declare function isClosed(ring: Ring): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<om-transform>` — the lazy half (spec: cartographic substrate, Part B).
|
|
3
|
+
*
|
|
4
|
+
* Everything here is a pure function of `(geometry, params, metresPerMm)`:
|
|
5
|
+
* no DOM, no deck, no map state. That is what makes the chain cacheable by
|
|
6
|
+
* data identity plus params, testable headless, and safe to move to a worker
|
|
7
|
+
* later without changing a line of the primitives.
|
|
8
|
+
*
|
|
9
|
+
* `src/transform-stage.ts` is the eager counterpart — it decides WHEN to call
|
|
10
|
+
* this, and holds the cache.
|
|
11
|
+
*/
|
|
12
|
+
import type { Shape } from "../expr";
|
|
13
|
+
import { TRANSFORM_TYPES, type TransformSpec } from "../transform-stage";
|
|
14
|
+
/** `[west, south, east, north]`, as JSON or four bare numbers. */
|
|
15
|
+
export declare function parseBounds(raw: string | undefined): [number, number, number, number] | null;
|
|
16
|
+
/**
|
|
17
|
+
* Run the authored chain in order. A step that cannot run is skipped LOUDLY
|
|
18
|
+
* and the rest of the chain still runs — one bad tolerance should not cost
|
|
19
|
+
* the author the smoothing below it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runTransforms(rows: readonly unknown[], shape: Shape, specs: readonly TransformSpec[], metresPerMm: number | null, warnLabel: string): Promise<unknown[]>;
|
|
22
|
+
export { TRANSFORM_TYPES };
|
|
23
|
+
export { simplifyGeometry, simplifyRing } from "./simplify";
|
|
24
|
+
export { smoothGeometry, chaikinRing } from "./smooth";
|
|
25
|
+
export { scatterRows, scatterFeature } from "./dot-density";
|
|
26
|
+
export { bufferRows, bufferGeometry } from "./buffer";
|
|
27
|
+
export { contourFromDem, assembleHeightGrid } from "./contour";
|
|
28
|
+
export { signedDistanceField, marchingSquares, rasterizeRings, distanceTransform, gridFor } from "./field";
|
|
29
|
+
export { metricFrame, coordinateCentre, mapRings } from "./geometry";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `simplify` — Douglas-Peucker on a metric frame, tolerance in ground metres.
|
|
3
|
+
*
|
|
4
|
+
* Iterative rather than recursive: a densely-digitized coastline ring is
|
|
5
|
+
* routinely 50,000 vertices, and the recursive form stack-overflows on the
|
|
6
|
+
* degenerate inputs (a near-straight run) that real data is full of.
|
|
7
|
+
*/
|
|
8
|
+
import { type Ring } from "./geometry";
|
|
9
|
+
export declare function simplifyRing(ring: Ring, toleranceMetres: number, lng0: number, lat0: number): Ring;
|
|
10
|
+
export declare function simplifyGeometry(coords: unknown, toleranceMetres: number): unknown;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `smooth` — Chaikin corner cutting. One iteration removes the loudest "web
|
|
3
|
+
* map" tell (a coastline that is visibly a chain of straight segments);
|
|
4
|
+
* three is about where the shape stops being the shape.
|
|
5
|
+
*
|
|
6
|
+
* Purely topological, so it needs no metric frame and no reference scale:
|
|
7
|
+
* every new vertex is a convex combination of two old ones, which is the
|
|
8
|
+
* same point whether the numbers are degrees or metres.
|
|
9
|
+
*/
|
|
10
|
+
import { type Ring } from "./geometry";
|
|
11
|
+
export declare function chaikinRing(ring: Ring, iterations: number): Ring;
|
|
12
|
+
export declare function smoothGeometry(coords: unknown, iterations: number): unknown;
|