isard 1.4.0 → 1.5.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 +55 -1
- package/README.md +22 -7
- package/dist/basemap/vectortiles/context.d.ts +43 -0
- package/dist/basemap/vectortiles/context.js +6 -0
- package/dist/basemap/vectortiles/context.js.map +1 -0
- package/dist/basemap/vectortiles/extrusions.d.ts +11 -0
- package/dist/basemap/vectortiles/extrusions.js +46 -0
- package/dist/basemap/vectortiles/extrusions.js.map +1 -0
- package/dist/basemap/vectortiles/labels.d.ts +22 -0
- package/dist/basemap/vectortiles/labels.js +225 -0
- package/dist/basemap/vectortiles/labels.js.map +1 -0
- package/dist/basemap/vectortiles/requests.d.ts +24 -0
- package/dist/basemap/vectortiles/requests.js +61 -0
- package/dist/basemap/vectortiles/requests.js.map +1 -0
- package/dist/basemap/vectortiles/street-wind.d.ts +19 -0
- package/dist/basemap/vectortiles/street-wind.js +133 -0
- package/dist/basemap/vectortiles/street-wind.js.map +1 -0
- package/dist/basemap/vectortiles/style.d.ts +47 -0
- package/dist/basemap/vectortiles/style.js +141 -0
- package/dist/basemap/vectortiles/style.js.map +1 -0
- package/dist/basemap/vectortiles/tiles.d.ts +34 -0
- package/dist/basemap/vectortiles/tiles.js +62 -0
- package/dist/basemap/vectortiles/tiles.js.map +1 -0
- package/dist/basemap/vectortiles/trees.d.ts +19 -0
- package/dist/basemap/vectortiles/trees.js +93 -0
- package/dist/basemap/vectortiles/trees.js.map +1 -0
- package/dist/basemap/vectortiles/vectors.d.ts +20 -0
- package/dist/basemap/vectortiles/vectors.js +167 -0
- package/dist/basemap/vectortiles/vectors.js.map +1 -0
- package/dist/basemap/vectortiles.d.ts +23 -90
- package/dist/basemap/vectortiles.js +57 -765
- package/dist/basemap/vectortiles.js.map +1 -1
- package/dist/basemap/workerpool.js +25 -6
- package/dist/basemap/workerpool.js.map +1 -1
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +4 -4
- package/dist/decoder.worker.js +5 -4
- package/dist/decoder.worker.js.map +8 -6
- package/dist/engine/decoders.d.ts +4 -8
- package/dist/engine/decoders.js +29 -2
- package/dist/engine/decoders.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/isard_bg.wasm +0 -0
- package/dist/isard_core_bg.wasm +0 -0
- package/dist/layers/flow.d.ts +9 -2
- package/dist/layers/flow.js +51 -10
- package/dist/layers/flow.js.map +1 -1
- package/dist/layers/panoramas.d.ts +2 -0
- package/dist/layers/panoramas.js +27 -6
- package/dist/layers/panoramas.js.map +1 -1
- package/dist/map/workers.js +3 -0
- package/dist/map/workers.js.map +1 -1
- package/dist/util/read.d.ts +4 -0
- package/dist/util/read.js +28 -0
- package/dist/util/read.js.map +1 -0
- package/dist/wasm/isard.d.ts +18 -5
- package/dist/wasm/isard.js +25 -4
- package/dist/wasm/isard_core.d.ts +18 -5
- package/dist/wasm/isard_core.js +25 -4
- package/dist/workers/basemap/street.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** The trees of a vector basemap (`VectorTiles.trees`): 3D models scattered by the workers over its woods and grass */
|
|
2
|
+
import { isWoodland, TREE_NUMBERS, treeModel, treeSpacing } from "../trees.js";
|
|
3
|
+
import { TileRequests } from "./requests.js";
|
|
4
|
+
import { nearPriority, STREET_ZOOM, tileKey, tilesAround } from "./tiles.js";
|
|
5
|
+
/** Metres around the view's center where every tree is drawn at zoom 16 (twice as far a zoom level out) */
|
|
6
|
+
const TREES_NEAR_METRES = 350;
|
|
7
|
+
/** Metres in a degree of latitude (and of longitude at the equator), near enough for the trees' distances */
|
|
8
|
+
const METRES_PER_DEGREE = 111320;
|
|
9
|
+
export const trees = (context, options = {}) => {
|
|
10
|
+
const { map } = context;
|
|
11
|
+
const { layers = isWoodland, spacing = treeSpacing, minZoom = STREET_ZOOM, maxTiles = 9, maxTrees = 30000, maxInstances = 25000, } = options;
|
|
12
|
+
const model = options.url ? { url: options.url } : { data: options.data ?? treeModel(options.colors) };
|
|
13
|
+
const layer = map.addModels({
|
|
14
|
+
...model,
|
|
15
|
+
instances: [],
|
|
16
|
+
...(options.before ? { before: options.before } : {}),
|
|
17
|
+
});
|
|
18
|
+
const renderer = context.renderer((l) => l.type === 'fill' && layers(l), []);
|
|
19
|
+
renderer.catch(() => undefined);
|
|
20
|
+
context.layers.push(layer);
|
|
21
|
+
/** The tiles held or asked for, by key, and the trees of those that came */
|
|
22
|
+
const requests = new TileRequests();
|
|
23
|
+
const found = new Map();
|
|
24
|
+
/** The trees drawn to the engine (longitude, latitude, altitude, heading, pitch, roll, scale each): all of them
|
|
25
|
+
* near the view's center, past `near` metres those of a rank under (near / distance)², at most `maxInstances` */
|
|
26
|
+
const send = () => {
|
|
27
|
+
const { center, zoom } = map.getCamera();
|
|
28
|
+
const near = TREES_NEAR_METRES * 2 ** (16 - zoom);
|
|
29
|
+
const cos = Math.cos((center[1] * Math.PI) / 180);
|
|
30
|
+
const chosen = [];
|
|
31
|
+
found.forEach((t) => {
|
|
32
|
+
for (let i = 0; i < t.length / TREE_NUMBERS; i += 1) {
|
|
33
|
+
const dx = ((t[i * TREE_NUMBERS] ?? 0) - center[0]) * METRES_PER_DEGREE * cos;
|
|
34
|
+
const dy = ((t[i * TREE_NUMBERS + 1] ?? 0) - center[1]) * METRES_PER_DEGREE;
|
|
35
|
+
const far = (dx * dx + dy * dy) / (near * near);
|
|
36
|
+
const score = (t[i * TREE_NUMBERS + 4] ?? 0) * Math.max(1, far);
|
|
37
|
+
if (score < 1)
|
|
38
|
+
chosen.push([score, t, i]);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (chosen.length > maxInstances)
|
|
42
|
+
chosen.sort((a, b) => a[0] - b[0]).splice(maxInstances);
|
|
43
|
+
const out = new Float64Array(chosen.length * 7);
|
|
44
|
+
chosen.forEach(([, t, i], k) => {
|
|
45
|
+
const at = i * TREE_NUMBERS;
|
|
46
|
+
out.set([t[at] ?? 0, t[at + 1] ?? 0, 0, t[at + 3] ?? 0, 0, 0, t[at + 2] ?? 1], k * 7);
|
|
47
|
+
});
|
|
48
|
+
layer.setInstanceNumbers(out);
|
|
49
|
+
};
|
|
50
|
+
const update = async () => {
|
|
51
|
+
if (context.destroyed())
|
|
52
|
+
return;
|
|
53
|
+
const { key, maxzoom, layers: list } = await renderer;
|
|
54
|
+
const camera = map.getCamera();
|
|
55
|
+
const z = maxzoom;
|
|
56
|
+
const wanted = camera.zoom < minZoom ? [] : tilesAround(map, camera, z, maxTiles);
|
|
57
|
+
const keys = new Set(wanted.map(([x, y]) => tileKey(z, x, y)));
|
|
58
|
+
const metres = list.map((l) => (typeof spacing === 'number' ? spacing : spacing(l)));
|
|
59
|
+
const dropped = requests.keys().filter((k) => !keys.has(k));
|
|
60
|
+
// Out of view: dropped, or no longer asked for
|
|
61
|
+
dropped.forEach((k) => {
|
|
62
|
+
requests.drop(k);
|
|
63
|
+
found.delete(k);
|
|
64
|
+
});
|
|
65
|
+
// Dense around the new center
|
|
66
|
+
send();
|
|
67
|
+
wanted.forEach(([x, y], index) => {
|
|
68
|
+
const k = tileKey(z, x, y);
|
|
69
|
+
if (requests.has(k))
|
|
70
|
+
return;
|
|
71
|
+
const work = {
|
|
72
|
+
type: 'trees',
|
|
73
|
+
key,
|
|
74
|
+
z,
|
|
75
|
+
x,
|
|
76
|
+
y,
|
|
77
|
+
spacing: metres,
|
|
78
|
+
maxTrees,
|
|
79
|
+
priority: nearPriority(index),
|
|
80
|
+
};
|
|
81
|
+
requests.ask(k, (signal) => context.request(z, x, y, work, signal), (r) => {
|
|
82
|
+
if (!('trees' in r))
|
|
83
|
+
return;
|
|
84
|
+
found.set(k, r.trees);
|
|
85
|
+
send();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
// While the camera moves, the trees drawn follow its center (dense near it)
|
|
90
|
+
context.followView(update, requests, send);
|
|
91
|
+
return layer;
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=trees.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trees.js","sourceRoot":"","sources":["../../../src/basemap/vectortiles/trees.ts"],"names":[],"mappings":"AAAA,uHAAuH;AAIvH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAmB,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhG,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7E,2GAA2G;AAC3G,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,6GAA6G;AAC7G,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAgBjC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAA2B,EAAE,UAAwB,EAAE,EAAc,EAAE;IAC3F,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACxB,MAAM,EACJ,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,WAAW,EACrB,OAAO,GAAG,WAAW,EACrB,QAAQ,GAAG,CAAC,EACZ,QAAQ,GAAG,KAAK,EAChB,YAAY,GAAG,KAAK,GACrB,GAAG,OAAO,CAAC;IACZ,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IACvG,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC;QAC1B,GAAG,KAAK;QACR,SAAS,EAAE,EAAE;QACb,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAA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AC,CAAC,CAAC,CAAC;YACjB,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,8BAA8B;QAC9B,IAAI,EAAE,CAAC;QACP,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YAC/B,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAE3B,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,OAAO;YAE5B,MAAM,IAAI,GAAgB;gBACxB,IAAI,EAAE,OAAO;gBACb,GAAG;gBACH,CAAC;gBACD,CAAC;gBACD,CAAC;gBACD,OAAO,EAAE,MAAM;gBACf,QAAQ;gBACR,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC;aAC9B,CAAC;YAEF,QAAQ,CAAC,GAAG,CACV,CAAC,EACD,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAClD,CAAC,CAAC,EAAE,EAAE;gBACJ,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC;oBAAE,OAAO;gBAC5B,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;gBACtB,IAAI,EAAE,CAAC;YACT,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,4EAA4E;IAC5E,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAE3C,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["/** The trees of a vector basemap (`VectorTiles.trees`): 3D models scattered by the workers over its woods and grass */\n\nimport type { Layer, ModelLayer } from '../../layers/layers.ts';\nimport type { BasemapWork } from '../../workers/basemap.worker.ts';\nimport { isWoodland, TREE_NUMBERS, type TreeColors, treeModel, treeSpacing } from '../trees.ts';\nimport type { StyleLayer } from '../vectorstyle.ts';\nimport type { VectorTilesContext } from './context.ts';\nimport { TileRequests } from './requests.ts';\nimport { nearPriority, STREET_ZOOM, tileKey, tilesAround } from './tiles.ts';\n\n/** Metres around the view's center where every tree is drawn at zoom 16 (twice as far a zoom level out) */\nconst TREES_NEAR_METRES = 350;\n\n/** Metres in a degree of latitude (and of longitude at the equator), near enough for the trees' distances */\nconst METRES_PER_DEGREE = 111320;\n\n/** The options of `VectorTiles.trees` */\nexport interface TreesOptions {\n layers?: (layer: StyleLayer) => boolean;\n spacing?: number | ((layer: StyleLayer) => number);\n minZoom?: number;\n maxTiles?: number;\n maxTrees?: number;\n maxInstances?: number;\n colors?: Partial<TreeColors>;\n url?: string;\n data?: ArrayBuffer | ArrayBufferView<ArrayBuffer>;\n before?: Layer;\n}\n\nexport const trees = (context: VectorTilesContext, options: TreesOptions = {}): ModelLayer => {\n const { map } = context;\n const {\n layers = isWoodland,\n spacing = treeSpacing,\n minZoom = STREET_ZOOM,\n maxTiles = 9,\n maxTrees = 30000,\n maxInstances = 25000,\n } = options;\n const model = options.url ? { url: options.url } : { data: options.data ?? treeModel(options.colors) };\n const layer = map.addModels({\n ...model,\n instances: [],\n ...(options.before ? { before: options.before } : {}),\n });\n const renderer = context.renderer((l) => l.type === 'fill' && layers(l), []);\n\n renderer.catch(() => undefined);\n context.layers.push(layer);\n\n /** The tiles held or asked for, by key, and the trees of those that came */\n const requests = new TileRequests();\n const found = new Map<string, Float64Array>();\n /** The trees drawn to the engine (longitude, latitude, altitude, heading, pitch, roll, scale each): all of them\n * near the view's center, past `near` metres those of a rank under (near / distance)², at most `maxInstances` */\n const send = () => {\n const { center, zoom } = map.getCamera();\n const near = TREES_NEAR_METRES * 2 ** (16 - zoom);\n const cos = Math.cos((center[1] * Math.PI) / 180);\n const chosen: [score: number, tile: Float64Array, i: number][] = [];\n\n found.forEach((t) => {\n for (let i = 0; i < t.length / TREE_NUMBERS; i += 1) {\n const dx = ((t[i * TREE_NUMBERS] ?? 0) - center[0]) * METRES_PER_DEGREE * cos;\n const dy = ((t[i * TREE_NUMBERS + 1] ?? 0) - center[1]) * METRES_PER_DEGREE;\n const far = (dx * dx + dy * dy) / (near * near);\n const score = (t[i * TREE_NUMBERS + 4] ?? 0) * Math.max(1, far);\n\n if (score < 1) chosen.push([score, t, i]);\n }\n });\n if (chosen.length > maxInstances) chosen.sort((a, b) => a[0] - b[0]).splice(maxInstances);\n\n const out = new Float64Array(chosen.length * 7);\n\n chosen.forEach(([, t, i], k) => {\n const at = i * TREE_NUMBERS;\n\n out.set([t[at] ?? 0, t[at + 1] ?? 0, 0, t[at + 3] ?? 0, 0, 0, t[at + 2] ?? 1], k * 7);\n });\n layer.setInstanceNumbers(out);\n };\n const update = async () => {\n if (context.destroyed()) return;\n\n const { key, maxzoom, layers: list } = await renderer;\n const camera = map.getCamera();\n const z = maxzoom;\n const wanted = camera.zoom < minZoom ? [] : tilesAround(map, camera, z, maxTiles);\n const keys = new Set(wanted.map(([x, y]) => tileKey(z, x, y)));\n const metres = list.map((l) => (typeof spacing === 'number' ? spacing : spacing(l)));\n const dropped = requests.keys().filter((k) => !keys.has(k));\n\n // Out of view: dropped, or no longer asked for\n dropped.forEach((k) => {\n requests.drop(k);\n found.delete(k);\n });\n // Dense around the new center\n send();\n wanted.forEach(([x, y], index) => {\n const k = tileKey(z, x, y);\n\n if (requests.has(k)) return;\n\n const work: BasemapWork = {\n type: 'trees',\n key,\n z,\n x,\n y,\n spacing: metres,\n maxTrees,\n priority: nearPriority(index),\n };\n\n requests.ask(\n k,\n (signal) => context.request(z, x, y, work, signal),\n (r) => {\n if (!('trees' in r)) return;\n found.set(k, r.trees);\n send();\n },\n );\n });\n };\n // While the camera moves, the trees drawn follow its center (dense near it)\n context.followView(update, requests, send);\n\n return layer;\n};\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vector layer of a vector basemap (`VectorTiles.vectors`): its fills, lines and buildings cut by the workers
|
|
3
|
+
* into geometry the engine draws, the tiles following the view, and how its style layers are read for the engine.
|
|
4
|
+
*/
|
|
5
|
+
import type { Layer } from '../../layers/layers.ts';
|
|
6
|
+
import type { VectorLayer } from '../../layers/vectors.ts';
|
|
7
|
+
import { type Json, type StyleLayer } from '../vectorstyle.ts';
|
|
8
|
+
import type { VectorTilesContext } from './context.ts';
|
|
9
|
+
/**
|
|
10
|
+
* A `line-dasharray` as the engine takes it: two dashes and gaps in line widths (an odd count repeated, as the
|
|
11
|
+
* canvas's `setLineDash`; past four, the first four), zeros for a solid line
|
|
12
|
+
*/
|
|
13
|
+
export declare const dashes: (value: Json | undefined, zoom: number) => [number, number, number, number];
|
|
14
|
+
/** The options of `VectorTiles.vectors` */
|
|
15
|
+
export interface VectorsOptions {
|
|
16
|
+
layers?: (layer: StyleLayer) => boolean;
|
|
17
|
+
streets?: (layer: StyleLayer) => boolean;
|
|
18
|
+
before?: Layer;
|
|
19
|
+
}
|
|
20
|
+
export declare const vectors: (context: VectorTilesContext, options?: VectorsOptions) => VectorLayer;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vector layer of a vector basemap (`VectorTiles.vectors`): its fills, lines and buildings cut by the workers
|
|
3
|
+
* into geometry the engine draws, the tiles following the view, and how its style layers are read for the engine.
|
|
4
|
+
*/
|
|
5
|
+
import { evaluate, isExpression, vectorKind, zoomOnly } from "../vectorstyle.js";
|
|
6
|
+
import { TileRequests } from "./requests.js";
|
|
7
|
+
import { nearPriority, parseTileKey, tileKey, tileTriples } from "./tiles.js";
|
|
8
|
+
/** The deepest level `vectors()` cuts its tiles at: past the source's deepest level, its tiles cut again into deeper
|
|
9
|
+
* ones (overzoom, as MapLibre does) down to level 18, their filters and styles those of their level, smaller tiles
|
|
10
|
+
* drawn in a closer view; past it, the tiles of that level stretched */
|
|
11
|
+
const OVERZOOM_LEVEL = 18;
|
|
12
|
+
/** The deepest level of the tiles of `vectors()` over a source whose deepest is `maxzoom` */
|
|
13
|
+
const deepestLevel = (maxzoom) => Math.max(maxzoom, OVERZOOM_LEVEL);
|
|
14
|
+
/**
|
|
15
|
+
* A `line-dasharray` as the engine takes it: two dashes and gaps in line widths (an odd count repeated, as the
|
|
16
|
+
* canvas's `setLineDash`; past four, the first four), zeros for a solid line
|
|
17
|
+
*/
|
|
18
|
+
export const dashes = (value, zoom) => {
|
|
19
|
+
const v = isExpression(value) ? evaluate(value, { zoom, properties: {}, type: 'Unknown' }) : value;
|
|
20
|
+
const list = Array.isArray(v) ? v.map(Number).filter((d) => Number.isFinite(d) && d >= 0) : [];
|
|
21
|
+
const even = list.length % 2 === 1 ? [...list, ...list] : list;
|
|
22
|
+
const [a = 0, b = 0, c = 0, d = 0] = even.length >= 2 && even.some((x) => x > 0) ? even : [];
|
|
23
|
+
return [a, b, c, d];
|
|
24
|
+
};
|
|
25
|
+
/** Whether a style layer draws streets, which glow at night: its id names a road (OpenMapTiles' styles, PLAN IGN's),
|
|
26
|
+
* not its casing, a railway, a path or a tunnel */
|
|
27
|
+
const isStreet = (layer) => /road|highway|street|motorway|trunk|primary|secondary|tertiary|minor|routier/i.test(layer.id) &&
|
|
28
|
+
!/casing|outline|rail|path|track|ferry|tunnel|pier|area|pattern|label/i.test(layer.id);
|
|
29
|
+
/** A `line-cap` as the engine draws it, at the camera's zoom (MapLibre's default: butt) */
|
|
30
|
+
const lineCap = (value, zoom) => {
|
|
31
|
+
const v = isExpression(value) ? evaluate(value, { zoom, properties: {}, type: 'Unknown' }) : value;
|
|
32
|
+
return v === 'round' || v === 'square' ? v : 'butt';
|
|
33
|
+
};
|
|
34
|
+
export const vectors = (context, options = {}) => {
|
|
35
|
+
const { map } = context;
|
|
36
|
+
const { layers = () => true, streets = isStreet, before } = options;
|
|
37
|
+
const vector = map.addVectorLayer(before);
|
|
38
|
+
const state = { renderer: context.renderer((l) => vectorKind(l) !== undefined && layers(l), []), update: 0, style: 0 };
|
|
39
|
+
state.renderer.catch(() => undefined);
|
|
40
|
+
context.layers.push(vector);
|
|
41
|
+
const sublayers = (list) => {
|
|
42
|
+
const zoom = map.getCamera().zoom;
|
|
43
|
+
return list.map((l) => ({
|
|
44
|
+
id: l.id,
|
|
45
|
+
sourceLayer: l['source-layer'],
|
|
46
|
+
kind: vectorKind(l) ?? 'fill',
|
|
47
|
+
minZoom: l.minzoom ?? 0,
|
|
48
|
+
maxZoom: l.maxzoom ?? 24,
|
|
49
|
+
visible: l.layout?.visibility !== 'none',
|
|
50
|
+
opacity: zoomOnly(l.paint?.[`${l.type}-opacity`], 1) ?? 1,
|
|
51
|
+
cap: lineCap(l.layout?.['line-cap'], zoom),
|
|
52
|
+
lit: l.type === 'line' && streets(l),
|
|
53
|
+
dash: l.type === 'line' ? dashes(l.paint?.['line-dasharray'], zoom) : [0, 0, 0, 0],
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
56
|
+
/** The tiles held or asked for, by `z/x/y` */
|
|
57
|
+
const requests = new TileRequests();
|
|
58
|
+
/** A tile's geometry, or its styles alone, asked of the worker of its tile of the source's level (which keeps the
|
|
59
|
+
* decoded tile its deeper tiles are cut from) */
|
|
60
|
+
const ask = ({ key, maxzoom }, [z, x, y], styles, priority, signal) => {
|
|
61
|
+
const d = Math.max(0, z - maxzoom);
|
|
62
|
+
const work = { type: 'vectors', key, z, x, y, deepest: deepestLevel(maxzoom), priority };
|
|
63
|
+
// The geometry made ready for the GPU in the workers, with the prisms the relief needs
|
|
64
|
+
return context.request(z - d, Math.floor(x / 2 ** d), Math.floor(y / 2 ** d), styles ? { ...work, styles } : { ...work, prism: map.hasRelief }, signal);
|
|
65
|
+
};
|
|
66
|
+
// The workers tessellate the tiles (the main thread only uploads them), once they know the module
|
|
67
|
+
context.broadcast({ type: 'tess', url: map.tessUrl });
|
|
68
|
+
/** Asks the workers again for the styles of a tile held, under the current style; the tile's geometry stays as it
|
|
69
|
+
* is */
|
|
70
|
+
const restyleTile = async (renderer, k) => {
|
|
71
|
+
const r = await ask(renderer, parseTileKey(k), true, 'auto').catch(() => undefined);
|
|
72
|
+
if (r && 'styles' in r)
|
|
73
|
+
vector.setTileStyles(k, r.styles);
|
|
74
|
+
};
|
|
75
|
+
const update = async () => {
|
|
76
|
+
if (context.destroyed())
|
|
77
|
+
return;
|
|
78
|
+
const generation = ++state.update;
|
|
79
|
+
const { key, maxzoom, layers: list } = await state.renderer;
|
|
80
|
+
vector.setSublayers(sublayers(state.own ?? list));
|
|
81
|
+
const wanted = tileTriples(map.engine.vectorTilesInView(0, deepestLevel(maxzoom)));
|
|
82
|
+
const keys = new Set(wanted.map((t) => tileKey(...t)));
|
|
83
|
+
const loads = wanted.flatMap((t, index) => {
|
|
84
|
+
const k = tileKey(...t);
|
|
85
|
+
if (requests.has(k))
|
|
86
|
+
return [];
|
|
87
|
+
const style = state.style;
|
|
88
|
+
return [
|
|
89
|
+
requests.ask(k, (signal) => ask({ key, maxzoom }, t, false, nearPriority(index, 'high', 'auto'), signal), async (r) => {
|
|
90
|
+
if (!('vectors' in r))
|
|
91
|
+
return;
|
|
92
|
+
vector.setTile(k, r.vectors);
|
|
93
|
+
// Cut under a style changed since: its styles asked for again
|
|
94
|
+
if (style !== state.style)
|
|
95
|
+
await restyleTile(await state.renderer, k);
|
|
96
|
+
}),
|
|
97
|
+
];
|
|
98
|
+
});
|
|
99
|
+
// Out of view: those still asked for go at once, those drawn once their replacements are there (no hole). The
|
|
100
|
+
// drawn ones are those the engine shows, held or not (a recut forgets what it held, not what is drawn)
|
|
101
|
+
const drop = (drawn) => {
|
|
102
|
+
const shown = new Set(vector.tileKeys);
|
|
103
|
+
const known = new Set([...requests.keys(), ...(drawn ? shown : [])]);
|
|
104
|
+
known.forEach((k) => {
|
|
105
|
+
if (keys.has(k) || shown.has(k) !== drawn)
|
|
106
|
+
return;
|
|
107
|
+
requests.drop(k);
|
|
108
|
+
vector.removeTile(k);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
drop(false);
|
|
112
|
+
await Promise.all(loads);
|
|
113
|
+
// A later update (the view moved again meanwhile) drops for its own view: these keys are no longer the view
|
|
114
|
+
if (!context.destroyed() && generation === state.update)
|
|
115
|
+
drop(true);
|
|
116
|
+
};
|
|
117
|
+
const refresh = () => {
|
|
118
|
+
update().catch(() => undefined);
|
|
119
|
+
};
|
|
120
|
+
/** The style layers changed: the workers' copy, then the styles of the tiles held */
|
|
121
|
+
const restyle = async (list) => {
|
|
122
|
+
state.own = list;
|
|
123
|
+
state.style++;
|
|
124
|
+
state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, list, key));
|
|
125
|
+
const renderer = await state.renderer;
|
|
126
|
+
vector.setSublayers(sublayers(list));
|
|
127
|
+
await Promise.all(vector.tileKeys.map((k) => restyleTile(renderer, k)));
|
|
128
|
+
};
|
|
129
|
+
vector.restyle = (id, group, name, value) => {
|
|
130
|
+
state.renderer
|
|
131
|
+
.then(({ layers: list }) => {
|
|
132
|
+
const next = (state.own ?? list).map((l) => l.id === id ? { ...l, [group]: { ...l[group], [name]: value } } : l);
|
|
133
|
+
// Visibility and dashes are the engine's: the tiles stay as they are
|
|
134
|
+
if ((group === 'layout' && name === 'visibility') || name === 'line-dasharray') {
|
|
135
|
+
state.own = next;
|
|
136
|
+
vector.setSublayers(sublayers(next));
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
// An outline added or taken away: a feature more or less in each tile, cut again
|
|
140
|
+
if (name === 'fill-outline-color' || name === 'fill-antialias') {
|
|
141
|
+
state.own = next;
|
|
142
|
+
state.style++;
|
|
143
|
+
state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, next, key));
|
|
144
|
+
vector.setSublayers(sublayers(next));
|
|
145
|
+
vector.recut?.();
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
return restyle(next);
|
|
149
|
+
})
|
|
150
|
+
.catch(() => undefined);
|
|
151
|
+
};
|
|
152
|
+
vector.recut = () => {
|
|
153
|
+
requests.abortAll();
|
|
154
|
+
refresh();
|
|
155
|
+
};
|
|
156
|
+
vector.styled = state.renderer.then(({ layers: list }) => {
|
|
157
|
+
if (!context.destroyed())
|
|
158
|
+
vector.setSublayers(sublayers(state.own ?? list));
|
|
159
|
+
});
|
|
160
|
+
// Reported by the style's `ready`
|
|
161
|
+
vector.styled.catch(() => undefined);
|
|
162
|
+
// While the camera moves, the tiles follow it (as the labels do: a long drag or flight does not leave the view of
|
|
163
|
+
// its start drawn)
|
|
164
|
+
context.followView(update, requests, update);
|
|
165
|
+
return vector;
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=vectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectors.js","sourceRoot":"","sources":["../../../src/basemap/vectortiles/vectors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAA8B,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7G,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAmB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F;;wEAEwE;AACxE,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,6FAA6F;AAC7F,MAAM,YAAY,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAEpF;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAuB,EAAE,IAAY,EAAoC,EAAE;IAChG,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,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AAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC5F,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBACrC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;gBAEjB,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAC;IACF,MAAM,CAAC,KAAK,GAAG,GAAG,EAAE;QAClB,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;QACvD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAAE,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IACH,kCAAkC;IAClC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAErC,kHAAkH;IAClH,mBAAmB;IACnB,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE7C,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/**\n * The vector layer of a vector basemap (`VectorTiles.vectors`): its fills, lines and buildings cut by the workers\n * into geometry the engine draws, the tiles following the view, and how its style layers are read for the engine.\n */\n\nimport type { Layer } from '../../layers/layers.ts';\nimport type { VectorLayer, VectorSublayer } from '../../layers/vectors.ts';\nimport type { BasemapWork, Priority } from '../../workers/basemap.worker.ts';\nimport { evaluate, isExpression, type Json, type StyleLayer, vectorKind, zoomOnly } from '../vectorstyle.ts';\nimport type { Renderer, VectorTilesContext } from './context.ts';\nimport { TileRequests } from './requests.ts';\nimport { nearPriority, parseTileKey, type TileTriple, tileKey, tileTriples } from './tiles.ts';\n\n/** The deepest level `vectors()` cuts its tiles at: past the source's deepest level, its tiles cut again into deeper\n * ones (overzoom, as MapLibre does) down to level 18, their filters and styles those of their level, smaller tiles\n * drawn in a closer view; past it, the tiles of that level stretched */\nconst OVERZOOM_LEVEL = 18;\n\n/** The deepest level of the tiles of `vectors()` over a source whose deepest is `maxzoom` */\nconst deepestLevel = (maxzoom: number): number => Math.max(maxzoom, OVERZOOM_LEVEL);\n\n/**\n * A `line-dasharray` as the engine takes it: two dashes and gaps in line widths (an odd count repeated, as the\n * canvas's `setLineDash`; past four, the first four), zeros for a solid line\n */\nexport const dashes = (value: Json | undefined, zoom: number): [number, number, number, number] => {\n const v = isExpression(value) ? evaluate(value, { zoom, properties: {}, type: 'Unknown' }) : value;\n const list = Array.isArray(v) ? v.map(Number).filter((d) => Number.isFinite(d) && d >= 0) : [];\n const even = list.length % 2 === 1 ? [...list, ...list] : list;\n const [a = 0, b = 0, c = 0, d = 0] = even.length >= 2 && even.some((x) => x > 0) ? even : [];\n\n return [a, b, c, d];\n};\n\n/** Whether a style layer draws streets, which glow at night: its id names a road (OpenMapTiles' styles, PLAN IGN's),\n * not its casing, a railway, a path or a tunnel */\nconst isStreet = (layer: StyleLayer): boolean =>\n /road|highway|street|motorway|trunk|primary|secondary|tertiary|minor|routier/i.test(layer.id) &&\n !/casing|outline|rail|path|track|ferry|tunnel|pier|area|pattern|label/i.test(layer.id);\n\n/** A `line-cap` as the engine draws it, at the camera's zoom (MapLibre's default: butt) */\nconst lineCap = (value: Json | undefined, zoom: number): 'butt' | 'round' | 'square' => {\n const v = isExpression(value) ? evaluate(value, { zoom, properties: {}, type: 'Unknown' }) : value;\n\n return v === 'round' || v === 'square' ? v : 'butt';\n};\n\n/** The options of `VectorTiles.vectors` */\nexport interface VectorsOptions {\n layers?: (layer: StyleLayer) => boolean;\n streets?: (layer: StyleLayer) => boolean;\n before?: Layer;\n}\n\nexport const vectors = (context: VectorTilesContext, options: VectorsOptions = {}): VectorLayer => {\n const { map } = context;\n const { layers = () => true, streets = isStreet, before } = options;\n const vector = map.addVectorLayer(before);\n const state: {\n renderer: Promise<Renderer>;\n /** The style layers as the application changed them (`setPaintProperty`…): a copy, its style left as it is */\n own?: StyleLayer[];\n /** Bumped by each update: only the last one drops the tiles out of its view */\n update: number;\n /** Bumped by each restyle: a tile cut under an older style is restyled once it is there */\n style: number;\n } = { renderer: context.renderer((l) => vectorKind(l) !== undefined && layers(l), []), update: 0, style: 0 };\n\n state.renderer.catch(() => undefined);\n context.layers.push(vector);\n\n const sublayers = (list: StyleLayer[]): VectorSublayer[] => {\n const zoom = map.getCamera().zoom;\n\n return list.map((l) => ({\n id: l.id,\n sourceLayer: l['source-layer'],\n kind: vectorKind(l) ?? 'fill',\n minZoom: l.minzoom ?? 0,\n maxZoom: l.maxzoom ?? 24,\n visible: l.layout?.visibility !== 'none',\n opacity: zoomOnly(l.paint?.[`${l.type}-opacity`], 1) ?? 1,\n cap: lineCap(l.layout?.['line-cap'], zoom),\n lit: l.type === 'line' && streets(l),\n dash: l.type === 'line' ? dashes(l.paint?.['line-dasharray'], zoom) : [0, 0, 0, 0],\n }));\n };\n\n /** The tiles held or asked for, by `z/x/y` */\n const requests = new TileRequests();\n /** A tile's geometry, or its styles alone, asked of the worker of its tile of the source's level (which keeps the\n * decoded tile its deeper tiles are cut from) */\n const ask = (\n { key, maxzoom }: { key: string; maxzoom: number },\n [z, x, y]: TileTriple,\n styles: boolean,\n priority: Priority,\n signal?: AbortSignal,\n ) => {\n const d = Math.max(0, z - maxzoom);\n const work: BasemapWork = { type: 'vectors', key, z, x, y, deepest: deepestLevel(maxzoom), priority };\n\n // The geometry made ready for the GPU in the workers, with the prisms the relief needs\n return context.request(\n z - d,\n Math.floor(x / 2 ** d),\n Math.floor(y / 2 ** d),\n styles ? { ...work, styles } : { ...work, prism: map.hasRelief },\n signal,\n );\n };\n\n // The workers tessellate the tiles (the main thread only uploads them), once they know the module\n context.broadcast({ type: 'tess', url: map.tessUrl });\n /** Asks the workers again for the styles of a tile held, under the current style; the tile's geometry stays as it\n * is */\n const restyleTile = async (renderer: { key: string; maxzoom: number }, k: string) => {\n const r = await ask(renderer, parseTileKey(k), true, 'auto').catch(() => undefined);\n\n if (r && 'styles' in r) vector.setTileStyles(k, r.styles);\n };\n const update = async () => {\n if (context.destroyed()) return;\n\n const generation = ++state.update;\n const { key, maxzoom, layers: list } = await state.renderer;\n\n vector.setSublayers(sublayers(state.own ?? list));\n\n const wanted = tileTriples(map.engine.vectorTilesInView(0, deepestLevel(maxzoom)));\n const keys = new Set(wanted.map((t) => tileKey(...t)));\n const loads = wanted.flatMap((t, index) => {\n const k = tileKey(...t);\n\n if (requests.has(k)) return [];\n\n const style = state.style;\n\n return [\n requests.ask(\n k,\n (signal) => ask({ key, maxzoom }, t, false, nearPriority(index, 'high', 'auto'), signal),\n async (r) => {\n if (!('vectors' in r)) return;\n vector.setTile(k, r.vectors);\n // Cut under a style changed since: its styles asked for again\n if (style !== state.style) await restyleTile(await state.renderer, k);\n },\n ),\n ];\n });\n // Out of view: those still asked for go at once, those drawn once their replacements are there (no hole). The\n // drawn ones are those the engine shows, held or not (a recut forgets what it held, not what is drawn)\n const drop = (drawn: boolean) => {\n const shown = new Set(vector.tileKeys);\n const known = new Set([...requests.keys(), ...(drawn ? shown : [])]);\n\n known.forEach((k) => {\n if (keys.has(k) || shown.has(k) !== drawn) return;\n requests.drop(k);\n vector.removeTile(k);\n });\n };\n\n drop(false);\n await Promise.all(loads);\n // A later update (the view moved again meanwhile) drops for its own view: these keys are no longer the view\n if (!context.destroyed() && generation === state.update) drop(true);\n };\n const refresh = () => {\n update().catch(() => undefined);\n };\n /** The style layers changed: the workers' copy, then the styles of the tiles held */\n const restyle = async (list: StyleLayer[]) => {\n state.own = list;\n state.style++;\n state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, list, key));\n\n const renderer = await state.renderer;\n\n vector.setSublayers(sublayers(list));\n await Promise.all(vector.tileKeys.map((k) => restyleTile(renderer, k)));\n };\n\n vector.restyle = (id, group, name, value) => {\n state.renderer\n .then(({ layers: list }) => {\n const next = (state.own ?? list).map((l) =>\n l.id === id ? { ...l, [group]: { ...l[group], [name]: value } } : l,\n );\n\n // Visibility and dashes are the engine's: the tiles stay as they are\n if ((group === 'layout' && name === 'visibility') || name === 'line-dasharray') {\n state.own = next;\n vector.setSublayers(sublayers(next));\n\n return undefined;\n }\n // An outline added or taken away: a feature more or less in each tile, cut again\n if (name === 'fill-outline-color' || name === 'fill-antialias') {\n state.own = next;\n state.style++;\n state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, next, key));\n vector.setSublayers(sublayers(next));\n vector.recut?.();\n\n return undefined;\n }\n\n return restyle(next);\n })\n .catch(() => undefined);\n };\n vector.recut = () => {\n requests.abortAll();\n refresh();\n };\n vector.styled = state.renderer.then(({ layers: list }) => {\n if (!context.destroyed()) vector.setSublayers(sublayers(state.own ?? list));\n });\n // Reported by the style's `ready`\n vector.styled.catch(() => undefined);\n\n // While the camera moves, the tiles follow it (as the labels do: a long drag or flight does not leave the view of\n // its start drawn)\n context.followView(update, requests, update);\n\n return vector;\n};\n"]}
|
|
@@ -7,38 +7,23 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Any subset of the style can be drawn on its own raster layer (`raster({ layers })`), at its own place in the stack:
|
|
9
9
|
* rivers from the basemap's data over a flood layer, for instance, restyled with `extraLayers`.
|
|
10
|
+
*
|
|
11
|
+
* The layers other than the raster ones are made in `vectortiles/` (one module each), from what they use of the
|
|
12
|
+
* instance (`VectorTilesContext`); the style's loading is in `vectortiles/style.ts`.
|
|
10
13
|
*/
|
|
11
|
-
import type { ExtrusionLayer
|
|
12
|
-
import type {
|
|
13
|
-
import type { FlowLayer, FlowOptions } from '../layers/flow.ts';
|
|
14
|
-
import type { Layer, ModelLayer, RasterLayer } from '../layers/layers.ts';
|
|
14
|
+
import type { ExtrusionLayer } from '../layers/extrusions.ts';
|
|
15
|
+
import type { ModelLayer, RasterLayer } from '../layers/layers.ts';
|
|
15
16
|
import type { SymbolLayer } from '../layers/symbols.ts';
|
|
16
17
|
import type { VectorLayer } from '../layers/vectors.ts';
|
|
17
18
|
import type { GeoMap } from '../map.ts';
|
|
18
|
-
import {
|
|
19
|
-
import { type
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
readonly fiord: "https://tiles.openfreemap.org/styles/fiord";
|
|
27
|
-
};
|
|
28
|
-
/** PLAN.IGN vector styles of the Géoplateforme (France) */
|
|
29
|
-
export declare const PLAN_STYLES: {
|
|
30
|
-
readonly standard: "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/standard.json";
|
|
31
|
-
readonly grey: "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/gris.json";
|
|
32
|
-
};
|
|
33
|
-
/** Vector basemaps by name (see `BasemapName`) */
|
|
34
|
-
export declare const VECTOR_BASEMAPS: {
|
|
35
|
-
readonly 'osm-positron': "https://tiles.openfreemap.org/styles/positron";
|
|
36
|
-
readonly 'osm-liberty': "https://tiles.openfreemap.org/styles/liberty";
|
|
37
|
-
readonly 'osm-bright': "https://tiles.openfreemap.org/styles/bright";
|
|
38
|
-
readonly 'osm-dark': "https://tiles.openfreemap.org/styles/dark";
|
|
39
|
-
readonly 'ign-plan-vector': "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/standard.json";
|
|
40
|
-
readonly 'ign-plan-grey-vector': "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/gris.json";
|
|
41
|
-
};
|
|
19
|
+
import type { LabelCandidate, Style, StyleLayer } from './vectorstyle.ts';
|
|
20
|
+
import { type VectorExtrusionOptions } from './vectortiles/extrusions.ts';
|
|
21
|
+
import { type LabelsOptions, size, tileLabels } from './vectortiles/labels.ts';
|
|
22
|
+
import { type StreetWindLayer, type StreetWindOptions } from './vectortiles/street-wind.ts';
|
|
23
|
+
import { type LoadedStyle, OPENFREEMAP_STYLES, PLAN_STYLES, styleAttribution, VECTOR_BASEMAPS } from './vectortiles/style.ts';
|
|
24
|
+
import { type TreesOptions } from './vectortiles/trees.ts';
|
|
25
|
+
import { dashes, type VectorsOptions } from './vectortiles/vectors.ts';
|
|
26
|
+
export { dashes, OPENFREEMAP_STYLES, PLAN_STYLES, size, styleAttribution, tileLabels, VECTOR_BASEMAPS };
|
|
42
27
|
export interface VectorTilesOptions {
|
|
43
28
|
/** A style URL or object (default OpenFreeMap's Positron) */
|
|
44
29
|
style?: string | Style;
|
|
@@ -52,15 +37,6 @@ export interface VectorTilesOptions {
|
|
|
52
37
|
* IGN's for PLAN.IGN's) */
|
|
53
38
|
attribution?: string;
|
|
54
39
|
}
|
|
55
|
-
/** The credits of a known style: OpenFreeMap's, PLAN.IGN's */
|
|
56
|
-
export declare const styleAttribution: (style: string | Style) => string | undefined;
|
|
57
|
-
/** Text or icon size of a style (a number, legacy stops, or the stops of a zoom expression made by the worker) as a
|
|
58
|
-
* size for the symbol layer */
|
|
59
|
-
export declare const size: (value: Json, fallback?: number) => Size;
|
|
60
|
-
/** The labels of a vector tile: features by style layer (its index in the style), the higher layers first */
|
|
61
|
-
type TileLabels = [layer: number, features: Feature<LabelCandidate>[]][];
|
|
62
|
-
/** A tile's label candidates as features, by style layer */
|
|
63
|
-
export declare const tileLabels: (candidates: readonly LabelCandidate[]) => TileLabels;
|
|
64
40
|
export declare class VectorTiles {
|
|
65
41
|
private readonly map;
|
|
66
42
|
private readonly pool;
|
|
@@ -79,23 +55,18 @@ export declare class VectorTiles {
|
|
|
79
55
|
private readonly layers;
|
|
80
56
|
/** Its first raster layer: the ground its labels follow */
|
|
81
57
|
private ground;
|
|
58
|
+
/** What its layers made in `vectortiles/` use of it */
|
|
59
|
+
private readonly context;
|
|
82
60
|
/** The style once loaded, with its source resolved */
|
|
83
|
-
readonly ready: Promise<
|
|
84
|
-
style: Style;
|
|
85
|
-
tiles: string;
|
|
86
|
-
maxzoom: number;
|
|
87
|
-
rasters: Record<string, RasterSource>;
|
|
88
|
-
}>;
|
|
61
|
+
readonly ready: Promise<LoadedStyle>;
|
|
89
62
|
/**
|
|
90
63
|
* Its workers are the map's (shared by every `VectorTiles` of the map, a vector tile decoded once for all of them),
|
|
91
64
|
* unless `workers` or `workerUrl` asks for others than the map's: then it has workers of its own
|
|
92
65
|
*/
|
|
93
66
|
constructor(map: GeoMap, options?: VectorTilesOptions);
|
|
94
|
-
private load;
|
|
95
|
-
/** The fonts of the style's labels, for its glyphs (the first of each `text-font`, as the workers take it) */
|
|
96
|
-
private static fonts;
|
|
97
67
|
/** The style's sprites (their JSON and their images), loaded once, for the fill patterns and the icons */
|
|
98
68
|
private sprites;
|
|
69
|
+
/** The style's sprites, kept once all of them came: one that failed is asked for again by the next layer */
|
|
99
70
|
private loadSprites;
|
|
100
71
|
/** Prefix of the names of its sprites' images among the map's icons */
|
|
101
72
|
private get iconPrefix();
|
|
@@ -122,11 +93,7 @@ export declare class VectorTiles {
|
|
|
122
93
|
* the source's deepest level, the `maxTiles` nearest to the center, from `minZoom` on (15 by default); the tiles
|
|
123
94
|
* leaving the view are dropped.
|
|
124
95
|
*/
|
|
125
|
-
extrusions<P = Record<string, unknown>>(options?:
|
|
126
|
-
layers?: (layer: StyleLayer) => boolean;
|
|
127
|
-
minZoom?: number;
|
|
128
|
-
maxTiles?: number;
|
|
129
|
-
}): ExtrusionLayer<P>;
|
|
96
|
+
extrusions<P = Record<string, unknown>>(options?: VectorExtrusionOptions<P>): ExtrusionLayer<P>;
|
|
130
97
|
/**
|
|
131
98
|
* The wind through the streets around the view, as particles at street level (`height`, default 3 metres) between
|
|
132
99
|
* the style's buildings (`layers`, default its `building` and `bati_surf` layers): their footprints laid on a grid of
|
|
@@ -138,17 +105,7 @@ export declare class VectorTiles {
|
|
|
138
105
|
* (`windAt`) for instance; `computed` resolves once the first square's flow is there. The other options are the flow
|
|
139
106
|
* layer's (`addFlow`)
|
|
140
107
|
*/
|
|
141
|
-
streetWind(options?:
|
|
142
|
-
wind?: [u: number, v: number];
|
|
143
|
-
size?: number;
|
|
144
|
-
cell?: number;
|
|
145
|
-
iterations?: number;
|
|
146
|
-
layers?: (layer: StyleLayer) => boolean;
|
|
147
|
-
minZoom?: number;
|
|
148
|
-
}): FlowLayer & {
|
|
149
|
-
setWind(wind: [u: number, v: number]): void;
|
|
150
|
-
computed: Promise<void>;
|
|
151
|
-
};
|
|
108
|
+
streetWind(options?: StreetWindOptions): StreetWindLayer;
|
|
152
109
|
/**
|
|
153
110
|
* Trees on the style's woods, forests and grass (or the fill layers `layers` keeps) as 3D models, from street level
|
|
154
111
|
* (`minZoom`, default 15): the workers scatter them over the polygons of the vector tiles around the view, `spacing`
|
|
@@ -159,18 +116,7 @@ export declare class VectorTiles {
|
|
|
159
116
|
* 25000); at most `maxTiles` tiles (default 9) and `maxTrees` trees in each (default 30000). The models load the
|
|
160
117
|
* engine with 3D Tiles.
|
|
161
118
|
*/
|
|
162
|
-
trees(options?:
|
|
163
|
-
layers?: (layer: StyleLayer) => boolean;
|
|
164
|
-
spacing?: number | ((layer: StyleLayer) => number);
|
|
165
|
-
minZoom?: number;
|
|
166
|
-
maxTiles?: number;
|
|
167
|
-
maxTrees?: number;
|
|
168
|
-
maxInstances?: number;
|
|
169
|
-
colors?: Partial<TreeColors>;
|
|
170
|
-
url?: string;
|
|
171
|
-
data?: ArrayBuffer | ArrayBufferView<ArrayBuffer>;
|
|
172
|
-
before?: Layer;
|
|
173
|
-
}): ModelLayer;
|
|
119
|
+
trees(options?: TreesOptions): ModelLayer;
|
|
174
120
|
/**
|
|
175
121
|
* A layer drawing the style's fills, lines and buildings (or those `layers` keeps; backgrounds as fills, the
|
|
176
122
|
* `fill-extrusion` layers raised into buildings by their height and base height) as geometry instead of images: the
|
|
@@ -186,11 +132,7 @@ export declare class VectorTiles {
|
|
|
186
132
|
* styles and small devices. At night (`setSun`) the line layers `streets` keeps glow (by default those whose id names
|
|
187
133
|
* a road, not its casing, a railway, a path or a tunnel).
|
|
188
134
|
*/
|
|
189
|
-
vectors(options?:
|
|
190
|
-
layers?: (layer: StyleLayer) => boolean;
|
|
191
|
-
streets?: (layer: StyleLayer) => boolean;
|
|
192
|
-
before?: Layer;
|
|
193
|
-
}): VectorLayer;
|
|
135
|
+
vectors(options?: VectorsOptions): VectorLayer;
|
|
194
136
|
/**
|
|
195
137
|
* A symbol layer with the labels of the style's symbol layers (or those `layers` keeps), updated as the view
|
|
196
138
|
* moves: the labels of the vector tiles in view, the higher style layers placed first. With a raster layer of
|
|
@@ -198,21 +140,12 @@ export declare class VectorTiles {
|
|
|
198
140
|
* away, with the few labels of a lower zoom, as near the camera it takes the fine ones. Without, the tiles around
|
|
199
141
|
* the center at the zoom of the view. It stays above the layers added after it unless one is moved over it.
|
|
200
142
|
*/
|
|
201
|
-
labels(options?:
|
|
202
|
-
layers?: (layer: StyleLayer) => boolean;
|
|
203
|
-
maxTiles?: number;
|
|
204
|
-
}): SymbolLayer<LabelCandidate>;
|
|
143
|
+
labels(options?: LabelsOptions): SymbolLayer<LabelCandidate>;
|
|
205
144
|
/**
|
|
206
145
|
* Makes a layer's tiles follow the view: `update` now and where the camera stops (`moveend`), `moving` every
|
|
207
|
-
* `VECTOR_MOVE_REFRESH_MS` while it moves; the requests
|
|
146
|
+
* `VECTOR_MOVE_REFRESH_MS` while it moves; the `requests` aborted when destroyed
|
|
208
147
|
*/
|
|
209
148
|
private followView;
|
|
210
149
|
/** Stops its workers' work and removes its raster and label layers from the map (those still there) */
|
|
211
150
|
destroy(): void;
|
|
212
151
|
}
|
|
213
|
-
/**
|
|
214
|
-
* A `line-dasharray` as the engine takes it: two dashes and gaps in line widths (an odd count repeated, as the
|
|
215
|
-
* canvas's `setLineDash`; past four, the first four), zeros for a solid line
|
|
216
|
-
*/
|
|
217
|
-
export declare const dashes: (value: Json | undefined, zoom: number) => [number, number, number, number];
|
|
218
|
-
export {};
|