isard 0.2.0 → 0.2.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.
- package/CHANGELOG.md +76 -14
- package/dist/basemap.worker.d.ts +10 -0
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +3 -3
- package/dist/basemaps.d.ts +5 -3
- package/dist/basemaps.js +5 -3
- package/dist/basemaps.js.map +1 -1
- package/dist/decoder.worker.js +3 -3
- package/dist/decoder.worker.js.map +3 -3
- package/dist/equirectangular.d.ts +6 -6
- package/dist/equirectangular.js +54 -24
- package/dist/equirectangular.js.map +1 -1
- package/dist/extrusions.js +11 -2
- package/dist/extrusions.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +3 -0
- package/dist/interaction.js +19 -3
- package/dist/interaction.js.map +1 -1
- package/dist/isard_bg.wasm +0 -0
- package/dist/isard_core_bg.wasm +0 -0
- package/dist/layers.d.ts +4 -1
- package/dist/layers.js +14 -5
- package/dist/layers.js.map +1 -1
- package/dist/map.d.ts +10 -2
- package/dist/map.js +172 -33
- package/dist/map.js.map +1 -1
- package/dist/terrain.js +30 -18
- package/dist/terrain.js.map +1 -1
- package/dist/types.d.ts +11 -3
- package/dist/types.js.map +1 -1
- package/dist/vectortiles.d.ts +3 -0
- package/dist/vectortiles.js +21 -5
- package/dist/vectortiles.js.map +1 -1
- package/dist/wasm/isard.d.ts +6 -5
- package/dist/wasm/isard.js +27 -10
- package/dist/wasm/isard_core.d.ts +6 -5
- package/dist/wasm/isard_core.js +35 -10
- package/package.json +1 -1
|
@@ -22,14 +22,14 @@ export interface Plan {
|
|
|
22
22
|
strips: Strip[];
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* The strips filling Mercator tile `z`/`x`/`y` (`size` pixels a side) from equirectangular tiles of levels
|
|
26
|
-
* `maxLevel`. The source level has the same pixel size along the parallels (one less than `z`: the source is twice
|
|
27
|
-
* wide at level 0), finer towards the poles, where the Mercator pixels shrink along the meridians.
|
|
25
|
+
* The strips filling Mercator tile `z`/`x`/`y` (`size` pixels a side) from equirectangular tiles of levels `minLevel`
|
|
26
|
+
* to `maxLevel`. The source level has the same pixel size along the parallels (one less than `z`: the source is twice
|
|
27
|
+
* as wide at level 0), finer towards the poles, where the Mercator pixels shrink along the meridians.
|
|
28
28
|
*/
|
|
29
|
-
export declare function plan(z: number, x: number, y: number, size: number, maxLevel: number): Plan;
|
|
29
|
+
export declare function plan(z: number, x: number, y: number, size: number, maxLevel: number, minLevel?: number): Plan;
|
|
30
30
|
/**
|
|
31
31
|
* A raster loader drawing Web Mercator tiles of `size` pixels from the equirectangular tiles of `url` ({z}, {x}, {y};
|
|
32
|
-
* levels
|
|
32
|
+
* levels `minLevel` to `maxLevel`). A missing source tile (404) leaves its part empty; a tile with no source at all is
|
|
33
33
|
* missing; other errors reject (retried by the engine).
|
|
34
34
|
*/
|
|
35
|
-
export declare function equirectangularLoader(url: string, maxLevel: number, size: number): (z: number, x: number, y: number, signal: AbortSignal) => Promise<ImageBitmap | null>;
|
|
35
|
+
export declare function equirectangularLoader(url: string, maxLevel: number, size: number, minLevel?: number): (z: number, x: number, y: number, signal: AbortSignal) => Promise<ImageBitmap | null>;
|
package/dist/equirectangular.js
CHANGED
|
@@ -13,15 +13,15 @@ const CACHE = 96;
|
|
|
13
13
|
/** Latitude (degrees) of a Mercator y in [0, 1] (towards the south) */
|
|
14
14
|
const latitude = (y) => (Math.atan(Math.sinh(Math.PI * (1 - 2 * y))) * 180) / Math.PI;
|
|
15
15
|
/**
|
|
16
|
-
* The strips filling Mercator tile `z`/`x`/`y` (`size` pixels a side) from equirectangular tiles of levels
|
|
17
|
-
* `maxLevel`. The source level has the same pixel size along the parallels (one less than `z`: the source is twice
|
|
18
|
-
* wide at level 0), finer towards the poles, where the Mercator pixels shrink along the meridians.
|
|
16
|
+
* The strips filling Mercator tile `z`/`x`/`y` (`size` pixels a side) from equirectangular tiles of levels `minLevel`
|
|
17
|
+
* to `maxLevel`. The source level has the same pixel size along the parallels (one less than `z`: the source is twice
|
|
18
|
+
* as wide at level 0), finer towards the poles, where the Mercator pixels shrink along the meridians.
|
|
19
19
|
*/
|
|
20
|
-
export function plan(z, x, y, size, maxLevel) {
|
|
20
|
+
export function plan(z, x, y, size, maxLevel, minLevel = 0) {
|
|
21
21
|
const n = 2 ** z;
|
|
22
22
|
const center = latitude((y + 0.5) / n);
|
|
23
23
|
const boost = Math.min(MAX_BOOST, Math.max(0, Math.round(-Math.log2(Math.cos((center * Math.PI) / 180)))));
|
|
24
|
-
const level = Math.max(0, Math.min(maxLevel, z - 1 + boost));
|
|
24
|
+
const level = Math.max(0, minLevel, Math.min(maxLevel, z - 1 + boost));
|
|
25
25
|
// The source in pixels at that level: 360° across, 180° down
|
|
26
26
|
const width = 2 * SOURCE * 2 ** level;
|
|
27
27
|
const height = SOURCE * 2 ** level;
|
|
@@ -56,12 +56,29 @@ export function plan(z, x, y, size, maxLevel) {
|
|
|
56
56
|
const tileUrl = (template, z, x, y) => template.replaceAll('{z}', String(z)).replaceAll('{x}', String(x)).replaceAll('{y}', String(y));
|
|
57
57
|
/**
|
|
58
58
|
* A raster loader drawing Web Mercator tiles of `size` pixels from the equirectangular tiles of `url` ({z}, {x}, {y};
|
|
59
|
-
* levels
|
|
59
|
+
* levels `minLevel` to `maxLevel`). A missing source tile (404) leaves its part empty; a tile with no source at all is
|
|
60
60
|
* missing; other errors reject (retried by the engine).
|
|
61
61
|
*/
|
|
62
|
-
export function equirectangularLoader(url, maxLevel, size) {
|
|
62
|
+
export function equirectangularLoader(url, maxLevel, size, minLevel = 0) {
|
|
63
63
|
// Source tiles by key, oldest first: a request is shared by the tiles that need it, its signal is not theirs
|
|
64
64
|
const cache = new Map();
|
|
65
|
+
/** Tiles being drawn from each source tile: an evicted one is closed once none is */
|
|
66
|
+
const users = new Map();
|
|
67
|
+
const evicted = new Set();
|
|
68
|
+
const close = (tile) => {
|
|
69
|
+
evicted.delete(tile);
|
|
70
|
+
tile.then((image) => image?.close(), () => undefined);
|
|
71
|
+
};
|
|
72
|
+
const release = (tile) => {
|
|
73
|
+
const count = (users.get(tile) ?? 1) - 1;
|
|
74
|
+
if (count > 0)
|
|
75
|
+
users.set(tile, count);
|
|
76
|
+
else {
|
|
77
|
+
users.delete(tile);
|
|
78
|
+
if (evicted.has(tile))
|
|
79
|
+
close(tile);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
65
82
|
const source = (z, x, y) => {
|
|
66
83
|
const key = `${z}/${x}/${y}`;
|
|
67
84
|
let tile = cache.get(key);
|
|
@@ -81,33 +98,46 @@ export function equirectangularLoader(url, maxLevel, size) {
|
|
|
81
98
|
tile.catch(() => cache.delete(key));
|
|
82
99
|
}
|
|
83
100
|
cache.set(key, tile);
|
|
84
|
-
|
|
101
|
+
users.set(tile, (users.get(tile) ?? 0) + 1);
|
|
102
|
+
for (const [old, image] of cache) {
|
|
85
103
|
if (cache.size <= CACHE)
|
|
86
104
|
break;
|
|
87
105
|
cache.delete(old);
|
|
106
|
+
// Its image freed now, or once the tiles drawing from it are done
|
|
107
|
+
if (users.has(image))
|
|
108
|
+
evicted.add(image);
|
|
109
|
+
else
|
|
110
|
+
close(image);
|
|
88
111
|
}
|
|
89
112
|
return tile;
|
|
90
113
|
};
|
|
91
114
|
return async (z, x, y, signal) => {
|
|
92
|
-
const { level, strips } = plan(z, x, y, size, maxLevel);
|
|
115
|
+
const { level, strips } = plan(z, x, y, size, maxLevel, minLevel);
|
|
93
116
|
const keys = [...new Set(strips.map((s) => `${s.tx}/${s.ty}`))];
|
|
94
|
-
const
|
|
117
|
+
const tiles = keys.map((key) => {
|
|
95
118
|
const [tx, ty] = key.split('/').map(Number);
|
|
96
|
-
return [key,
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
119
|
+
return [key, source(level, tx, ty)];
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
const images = new Map(await Promise.all(tiles.map(async ([key, tile]) => [key, await tile])));
|
|
123
|
+
signal.throwIfAborted();
|
|
124
|
+
if (![...images.values()].some(Boolean))
|
|
125
|
+
return null;
|
|
126
|
+
const canvas = new OffscreenCanvas(size, size);
|
|
127
|
+
const context = canvas.getContext('2d');
|
|
128
|
+
if (!context)
|
|
129
|
+
throw new Error('isard: no 2D canvas to reproject the tiles');
|
|
130
|
+
for (const s of strips) {
|
|
131
|
+
const image = images.get(`${s.tx}/${s.ty}`);
|
|
132
|
+
if (image)
|
|
133
|
+
context.drawImage(image, s.sx, s.sy, s.sw, 1, s.dx, s.dy, s.dw, 1);
|
|
134
|
+
}
|
|
135
|
+
return canvas.transferToImageBitmap();
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
for (const [, tile] of tiles)
|
|
139
|
+
release(tile);
|
|
109
140
|
}
|
|
110
|
-
return canvas.transferToImageBitmap();
|
|
111
141
|
};
|
|
112
142
|
}
|
|
113
143
|
//# sourceMappingURL=equirectangular.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"equirectangular.js","sourceRoot":"","sources":["../src/equirectangular.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uCAAuC;AACvC,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,gGAAgG;AAChG,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,8EAA8E;AAC9E,MAAM,KAAK,GAAG,EAAE,CAAC;AAqBjB,uEAAuE;AACvE,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GA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AAE,EAAE,EAAE,CAAC,CAAU,CAAC;QACrD,CAAC,CAAC,CACH,CACF,CAAC;QACF,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;QACrD,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC5E,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,KAAK;gBAAE,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAChF,CAAC;QACD,OAAO,MAAM,CAAC,qBAAqB,EAAE,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Equirectangular tiles (longitudes and latitudes, two 256 px tiles side by side at level 0, rows from the north)\n * reprojected into the Web Mercator tiles the engine draws: a raster loader that fetches the source tiles a Mercator\n * tile spans and draws them into it, one row of pixels at a time (along a row the latitude is constant, so each row is\n * a horizontal strip of the source, scaled). The planetary services (NASA's Trek, USGS) serve this grid only.\n */\n\n/** Side of the source tiles, pixels */\nconst SOURCE = 256;\n/** Source levels added at most towards the poles, where Web Mercator stretches the latitudes */\nconst MAX_BOOST = 3;\n/** Source tiles kept decoded: the neighbours of a Mercator tile share them */\nconst CACHE = 96;\n\n/** One strip drawn: from source tile (`tx`, `ty`) at the plan's level, the source rectangle (`sx`, `sy`, `sw`, one\n * row high) to the destination rectangle (`dx`, `dy`, `dw`, one row high) */\nexport interface Strip {\n tx: number;\n ty: number;\n sx: number;\n sy: number;\n sw: number;\n dx: number;\n dy: number;\n dw: number;\n}\n\n/** Where the pixels of a Mercator tile come from: the source level, and a strip per row and source column */\nexport interface Plan {\n level: number;\n strips: Strip[];\n}\n\n/** Latitude (degrees) of a Mercator y in [0, 1] (towards the south) */\nconst latitude = (y: number) => (Math.atan(Math.sinh(Math.PI * (1 - 2 * y))) * 180) / Math.PI;\n\n/**\n * The strips filling Mercator tile `z`/`x`/`y` (`size` pixels a side) from equirectangular tiles of levels 0 to\n * `maxLevel`. The source level has the same pixel size along the parallels (one less than `z`: the source is twice as\n * wide at level 0), finer towards the poles, where the Mercator pixels shrink along the meridians.\n */\nexport function plan(z: number, x: number, y: number, size: number, maxLevel: number): Plan {\n const n = 2 ** z;\n const center = latitude((y + 0.5) / n);\n const boost = Math.min(MAX_BOOST, Math.max(0, Math.round(-Math.log2(Math.cos((center * Math.PI) / 180)))));\n const level = Math.max(0, Math.min(maxLevel, z - 1 + boost));\n // The source in pixels at that level: 360° across, 180° down\n const width = 2 * SOURCE * 2 ** level;\n const height = SOURCE * 2 ** level;\n const west = (x / n) * width;\n const east = ((x + 1) / n) * width;\n const scale = size / (east - west);\n const strips: Strip[] = [];\n for (let row = 0; row < size; row += 1) {\n const lat = latitude((y + (row + 0.5) / size) / n);\n const v = Math.max(0, Math.min(height - 1e-6, ((90 - lat) / 180) * height));\n const ty = Math.floor(v / SOURCE);\n // The source row centered on the destination row's latitude, kept inside its tile (no bleeding into the next)\n const sy = Math.max(0, Math.min(SOURCE - 1, v - ty * SOURCE - 0.5));\n for (let tx = Math.floor(west / SOURCE); tx * SOURCE < east; tx += 1) {\n const from = Math.max(west, tx * SOURCE);\n const to = Math.min(east, (tx + 1) * SOURCE);\n strips.push({\n tx,\n ty,\n sx: from - tx * SOURCE,\n sy,\n sw: to - from,\n dx: (from - west) * scale,\n dy: row,\n dw: (to - from) * scale,\n });\n }\n }\n return { level, strips };\n}\n\n/** A tile URL of the source: {z}, {x} and {y} replaced */\nconst tileUrl = (template: string, z: number, x: number, y: number) =>\n template.replaceAll('{z}', String(z)).replaceAll('{x}', String(x)).replaceAll('{y}', String(y));\n\n/**\n * A raster loader drawing Web Mercator tiles of `size` pixels from the equirectangular tiles of `url` ({z}, {x}, {y};\n * levels 0 to `maxLevel`). A missing source tile (404) leaves its part empty; a tile with no source at all is\n * missing; other errors reject (retried by the engine).\n */\nexport function equirectangularLoader(\n url: string,\n maxLevel: number,\n size: number,\n): (z: number, x: number, y: number, signal: AbortSignal) => Promise<ImageBitmap | null> {\n // Source tiles by key, oldest first: a request is shared by the tiles that need it, its signal is not theirs\n const cache = new Map<string, Promise<ImageBitmap | null>>();\n const source = (z: number, x: number, y: number): Promise<ImageBitmap | null> => {\n const key = `${z}/${x}/${y}`;\n let tile = cache.get(key);\n if (tile) {\n cache.delete(key);\n } else {\n tile = (async () => {\n const response = await fetch(tileUrl(url, z, x, y));\n if (response.status === 404 || response.status === 204 || response.status === 410) return null;\n if (!response.ok) throw new Error(`isard: ${response.status} for an equirectangular tile`);\n return createImageBitmap(await response.blob());\n })();\n // A failure is not kept: the engine's retry fetches again\n tile.catch(() => cache.delete(key));\n }\n cache.set(key, tile);\n for (const old of cache.keys()) {\n if (cache.size <= CACHE) break;\n cache.delete(old);\n }\n return tile;\n };\n return async (z, x, y, signal) => {\n const { level, strips } = plan(z, x, y, size, maxLevel);\n const keys = [...new Set(strips.map((s) => `${s.tx}/${s.ty}`))];\n const images = new Map(\n await Promise.all(\n keys.map(async (key) => {\n const [tx, ty] = key.split('/').map(Number) as [number, number];\n return [key, await source(level, tx, ty)] as const;\n }),\n ),\n );\n signal.throwIfAborted();\n if (![...images.values()].some(Boolean)) return null;\n const canvas = new OffscreenCanvas(size, size);\n const context = canvas.getContext('2d');\n if (!context) throw new Error('isard: no 2D canvas to reproject the tiles');\n for (const s of strips) {\n const image = images.get(`${s.tx}/${s.ty}`);\n if (image) context.drawImage(image, s.sx, s.sy, s.sw, 1, s.dx, s.dy, s.dw, 1);\n }\n return canvas.transferToImageBitmap();\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"equirectangular.js","sourceRoot":"","sources":["../src/equirectangular.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uCAAuC;AACvC,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,gGAAgG;AAChG,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,8EAA8E;AAC9E,MAAM,KAAK,GAAG,EAAE,CAAC;AAqBjB,uEAAuE;AACvE,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;AAE9F;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,IAAY,EAAE,QAAgB,EAAE,QAAQ,GAAG,CAAC;IAChG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjB,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CA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AI,MAAM,EAAE,CAAC;gBACvB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC5C,IAAI,KAAK;oBAAE,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YAChF,CAAC;YACD,OAAO,MAAM,CAAC,qBAAqB,EAAE,CAAC;QACxC,CAAC;gBAAS,CAAC;YACT,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,KAAK;gBAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Equirectangular tiles (longitudes and latitudes, two 256 px tiles side by side at level 0, rows from the north)\n * reprojected into the Web Mercator tiles the engine draws: a raster loader that fetches the source tiles a Mercator\n * tile spans and draws them into it, one row of pixels at a time (along a row the latitude is constant, so each row is\n * a horizontal strip of the source, scaled). The planetary services (NASA's Trek, USGS) serve this grid only.\n */\n\n/** Side of the source tiles, pixels */\nconst SOURCE = 256;\n/** Source levels added at most towards the poles, where Web Mercator stretches the latitudes */\nconst MAX_BOOST = 3;\n/** Source tiles kept decoded: the neighbours of a Mercator tile share them */\nconst CACHE = 96;\n\n/** One strip drawn: from source tile (`tx`, `ty`) at the plan's level, the source rectangle (`sx`, `sy`, `sw`, one\n * row high) to the destination rectangle (`dx`, `dy`, `dw`, one row high) */\nexport interface Strip {\n tx: number;\n ty: number;\n sx: number;\n sy: number;\n sw: number;\n dx: number;\n dy: number;\n dw: number;\n}\n\n/** Where the pixels of a Mercator tile come from: the source level, and a strip per row and source column */\nexport interface Plan {\n level: number;\n strips: Strip[];\n}\n\n/** Latitude (degrees) of a Mercator y in [0, 1] (towards the south) */\nconst latitude = (y: number) => (Math.atan(Math.sinh(Math.PI * (1 - 2 * y))) * 180) / Math.PI;\n\n/**\n * The strips filling Mercator tile `z`/`x`/`y` (`size` pixels a side) from equirectangular tiles of levels `minLevel`\n * to `maxLevel`. The source level has the same pixel size along the parallels (one less than `z`: the source is twice\n * as wide at level 0), finer towards the poles, where the Mercator pixels shrink along the meridians.\n */\nexport function plan(z: number, x: number, y: number, size: number, maxLevel: number, minLevel = 0): Plan {\n const n = 2 ** z;\n const center = latitude((y + 0.5) / n);\n const boost = Math.min(MAX_BOOST, Math.max(0, Math.round(-Math.log2(Math.cos((center * Math.PI) / 180)))));\n const level = Math.max(0, minLevel, Math.min(maxLevel, z - 1 + boost));\n // The source in pixels at that level: 360° across, 180° down\n const width = 2 * SOURCE * 2 ** level;\n const height = SOURCE * 2 ** level;\n const west = (x / n) * width;\n const east = ((x + 1) / n) * width;\n const scale = size / (east - west);\n const strips: Strip[] = [];\n for (let row = 0; row < size; row += 1) {\n const lat = latitude((y + (row + 0.5) / size) / n);\n const v = Math.max(0, Math.min(height - 1e-6, ((90 - lat) / 180) * height));\n const ty = Math.floor(v / SOURCE);\n // The source row centered on the destination row's latitude, kept inside its tile (no bleeding into the next)\n const sy = Math.max(0, Math.min(SOURCE - 1, v - ty * SOURCE - 0.5));\n for (let tx = Math.floor(west / SOURCE); tx * SOURCE < east; tx += 1) {\n const from = Math.max(west, tx * SOURCE);\n const to = Math.min(east, (tx + 1) * SOURCE);\n strips.push({\n tx,\n ty,\n sx: from - tx * SOURCE,\n sy,\n sw: to - from,\n dx: (from - west) * scale,\n dy: row,\n dw: (to - from) * scale,\n });\n }\n }\n return { level, strips };\n}\n\n/** A tile URL of the source: {z}, {x} and {y} replaced */\nconst tileUrl = (template: string, z: number, x: number, y: number) =>\n template.replaceAll('{z}', String(z)).replaceAll('{x}', String(x)).replaceAll('{y}', String(y));\n\n/**\n * A raster loader drawing Web Mercator tiles of `size` pixels from the equirectangular tiles of `url` ({z}, {x}, {y};\n * levels `minLevel` to `maxLevel`). A missing source tile (404) leaves its part empty; a tile with no source at all is\n * missing; other errors reject (retried by the engine).\n */\nexport function equirectangularLoader(\n url: string,\n maxLevel: number,\n size: number,\n minLevel = 0,\n): (z: number, x: number, y: number, signal: AbortSignal) => Promise<ImageBitmap | null> {\n // Source tiles by key, oldest first: a request is shared by the tiles that need it, its signal is not theirs\n const cache = new Map<string, Promise<ImageBitmap | null>>();\n /** Tiles being drawn from each source tile: an evicted one is closed once none is */\n const users = new Map<Promise<ImageBitmap | null>, number>();\n const evicted = new Set<Promise<ImageBitmap | null>>();\n const close = (tile: Promise<ImageBitmap | null>) => {\n evicted.delete(tile);\n tile.then(\n (image) => image?.close(),\n () => undefined,\n );\n };\n const release = (tile: Promise<ImageBitmap | null>) => {\n const count = (users.get(tile) ?? 1) - 1;\n if (count > 0) users.set(tile, count);\n else {\n users.delete(tile);\n if (evicted.has(tile)) close(tile);\n }\n };\n const source = (z: number, x: number, y: number): Promise<ImageBitmap | null> => {\n const key = `${z}/${x}/${y}`;\n let tile = cache.get(key);\n if (tile) {\n cache.delete(key);\n } else {\n tile = (async () => {\n const response = await fetch(tileUrl(url, z, x, y));\n if (response.status === 404 || response.status === 204 || response.status === 410) return null;\n if (!response.ok) throw new Error(`isard: ${response.status} for an equirectangular tile`);\n return createImageBitmap(await response.blob());\n })();\n // A failure is not kept: the engine's retry fetches again\n tile.catch(() => cache.delete(key));\n }\n cache.set(key, tile);\n users.set(tile, (users.get(tile) ?? 0) + 1);\n for (const [old, image] of cache) {\n if (cache.size <= CACHE) break;\n cache.delete(old);\n // Its image freed now, or once the tiles drawing from it are done\n if (users.has(image)) evicted.add(image);\n else close(image);\n }\n return tile;\n };\n return async (z, x, y, signal) => {\n const { level, strips } = plan(z, x, y, size, maxLevel, minLevel);\n const keys = [...new Set(strips.map((s) => `${s.tx}/${s.ty}`))];\n const tiles = keys.map((key) => {\n const [tx, ty] = key.split('/').map(Number) as [number, number];\n return [key, source(level, tx, ty)] as const;\n });\n try {\n const images = new Map(await Promise.all(tiles.map(async ([key, tile]) => [key, await tile] as const)));\n signal.throwIfAborted();\n if (![...images.values()].some(Boolean)) return null;\n const canvas = new OffscreenCanvas(size, size);\n const context = canvas.getContext('2d');\n if (!context) throw new Error('isard: no 2D canvas to reproject the tiles');\n for (const s of strips) {\n const image = images.get(`${s.tx}/${s.ty}`);\n if (image) context.drawImage(image, s.sx, s.sy, s.sw, 1, s.dx, s.dy, s.dw, 1);\n }\n return canvas.transferToImageBitmap();\n } finally {\n for (const [, tile] of tiles) release(tile);\n }\n };\n}\n"]}
|
package/dist/extrusions.js
CHANGED
|
@@ -185,7 +185,9 @@ export class ExtrusionLayer extends Layer {
|
|
|
185
185
|
}
|
|
186
186
|
sendLink(engine, id) {
|
|
187
187
|
const n = this.network;
|
|
188
|
-
|
|
188
|
+
// A network removed (or not created) links to nothing
|
|
189
|
+
const network = n && n.layer.id >= 0 ? n.layer.id : undefined;
|
|
190
|
+
engine.linkExtrusionNetwork(id, network, n ? Math.min(n.max, 1e29) : 0);
|
|
189
191
|
}
|
|
190
192
|
/** @internal */
|
|
191
193
|
create(engine) {
|
|
@@ -193,9 +195,16 @@ export class ExtrusionLayer extends Layer {
|
|
|
193
195
|
this.sendLayer(engine, id);
|
|
194
196
|
for (const tile of this.tiles.values())
|
|
195
197
|
this.sendTile(engine, id, tile);
|
|
196
|
-
|
|
198
|
+
// A network created before (on a new engine, the map relinks once every layer is there)
|
|
199
|
+
if (!this.network || this.network.layer.id >= 0)
|
|
200
|
+
this.sendLink(engine, id);
|
|
197
201
|
return id;
|
|
198
202
|
}
|
|
203
|
+
/** @internal On a new engine, the network may come after the buildings: linked once both are there */
|
|
204
|
+
relink(engine) {
|
|
205
|
+
if (this.network)
|
|
206
|
+
this.sendLink(engine, this.id);
|
|
207
|
+
}
|
|
199
208
|
}
|
|
200
209
|
export function extrusionStyle(options) {
|
|
201
210
|
const { data: _, before: __, ...rest } = options;
|
package/dist/extrusions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extrusions.js","sourceRoot":"","sources":["../src/extrusions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,QAAQ,EAIR,MAAM,EACN,UAAU,EAGV,UAAU,EACV,eAAe,EACf,UAAU,EAEV,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAqB,MAAM,aAAa,CAAC;AA4CvD,yCAAyC;AACzC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAE5B,MAAM,OAAO,cAA+B,SAAQ,KAAK;IAS7C;IARO,KAAK,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC3D,SAAS,GAAG,CAAC,CAAC;IACd,OAAO,CAAmD;IAElE,gBAAgB;IAChB,YACE,GAAc,EACd,IAAgC,EACxB,KAAwB;QAEhC,KAAK,CAAC,GAAG,CAAC,CAAC;QAFH,UAAK,GAAL,KAAK,CAAmB;QAGhC,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;YAClC,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;YACrD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE;gBACnB,KAAK,EAAE,CAAC;gBACR,UAAU;gBACV,QAAQ;gBACR,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,SAAS;aACnB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,uCAAuC;IACvC,OAAO,CAAC,IAAoB;QAC1B,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,GAAG,CACN,IAAI,EACJ,QAAQ,CAAC,GAAG,CAA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,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QACxE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC1B,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAI,OAA4B;IAC5D,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACjD,OAAO;QACL,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,CAAC;QACT,IAAI,EAAE,CAAC;QACP,GAAG,IAAI;KACR,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Extruded polygons (buildings), styled per feature like the other feature layers, coming in tiles (or one set): an\n * application loading a tiled source (BD TOPO vector tiles…) hands each tile's buildings to `setTile` and drops them\n * with `removeTile`. Colored by their color, by a value per building through the ramp (water at a building), or by\n * the node values of a network layer (`linkNetwork`: the travel time to each building, recolored with the network).\n */\nimport {\n evaluate,\n type Feature,\n type FeatureData,\n type FeatureLayerStyle,\n FLOATS,\n featuresOf,\n type Placement,\n type Properties,\n parseColor,\n polygonGeometry,\n rampTexels,\n type Styled,\n stops,\n} from './features.ts';\nimport { Layer, type NetworkLayer } from './layers.ts';\nimport type { LayerHost } from './types.ts';\nimport type { Engine } from './wasm/isard.js';\n\nexport interface ExtrusionStyle<P = Properties> extends FeatureLayerStyle<P> {\n /** CSS color (default `#e4e1dc`) */\n color: Styled<string, P>;\n /** Height of the roof over the ground, metres (default 6) */\n height: Styled<number, P>;\n /** Height of the foot of the walls, metres (default 0) */\n base: Styled<number, P>;\n}\n\nexport interface ExtrusionOptions<P = Properties> extends Partial<ExtrusionStyle<P>>, Placement {\n /** Polygon and MultiPolygon features, as one set (tiles come with `setTile`) */\n data?: FeatureData<P>;\n}\n\n/** Key of a tile of extrusions (see `ExtrusionLayer.setTile`) */\nexport type TileKey = string | number;\n\n/**\n * Polygons as typed arrays, for tiles decoded in a worker (no GeoJSON in between): points in Mercator [0, 1] (x, y\n * interleaved, y towards the south), the first point of each ring and the first ring of each polygon (one more entry\n * than rings and polygons; the first ring of a polygon is its outline), the feature of each polygon\n */\nexport interface PolygonArrays {\n points: Float64Array;\n ringStart: Uint32Array;\n polygonStart: Uint32Array;\n feature: Uint32Array;\n}\n\ninterface Tile<P> {\n /** Batch number in the engine: tiles are drawn, and their features numbered for picking, in this order */\n batch: number;\n /** The properties of the features, which the style reads */\n properties: P[];\n features: Feature<P>[] | undefined;\n arrays: PolygonArrays | undefined;\n values: Float32Array | undefined;\n anchors: Float32Array | undefined;\n}\n\n/** TileKey of the set given as `data` */\nconst DATA = Symbol('data');\n\nexport class ExtrusionLayer<P = Properties> extends Layer {\n private readonly tiles = new Map<TileKey | typeof DATA, Tile<P>>();\n private nextBatch = 1;\n private network: { layer: NetworkLayer; max: number } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n data: FeatureData<P> | undefined,\n private style: ExtrusionStyle<P>,\n ) {\n super(map);\n if (data) {\n const features = featuresOf(data);\n const properties = features.map((f) => f.properties);\n this.tiles.set(DATA, {\n batch: 0,\n properties,\n features,\n arrays: undefined,\n values: undefined,\n anchors: undefined,\n });\n }\n }\n\n /** Replaces the set given as `data` */\n setData(data: FeatureData<P>): void {\n const features = featuresOf(data);\n this.put(\n DATA,\n features.map((f) => f.properties),\n features,\n undefined,\n );\n }\n\n /** Adds or replaces the buildings of a tile: GeoJSON, or typed arrays with the properties of each feature */\n setTile(key: TileKey, data: FeatureData<P> | { arrays: PolygonArrays; properties: P[] }): void {\n if ('arrays' in data) this.put(key, data.properties, undefined, data.arrays);\n else {\n const features = featuresOf(data);\n this.put(\n key,\n features.map((f) => f.properties),\n features,\n undefined,\n );\n }\n }\n\n removeTile(key: TileKey): void {\n const tile = this.tiles.get(key);\n if (!tile) return;\n this.tiles.delete(key);\n this.map.engine.removeExtrusionBatch(this.id, tile.batch);\n this.map.requestRender();\n }\n\n /** Keys of the tiles held */\n get tileKeys(): TileKey[] {\n return [...this.tiles.keys()].filter((k): k is TileKey => k !== DATA);\n }\n\n /** The properties of the features of a tile (or of the data) */\n properties(key?: TileKey): readonly P[] {\n return this.tiles.get(key ?? DATA)?.properties ?? [];\n }\n\n /** The feature of a picked index (its geometry if given as GeoJSON): tiles are numbered one after the other, in the\n * order they were added */\n featureAt(index: number): Feature<P> | undefined {\n let rest = index;\n for (const tile of [...this.tiles.values()].sort((a, b) => a.batch - b.batch)) {\n const n = tile.properties.length;\n if (rest < n) {\n const properties = tile.properties[rest] as P;\n return tile.features?.[rest] ?? { type: 'Feature', properties, geometry: null };\n }\n rest -= n;\n }\n return undefined;\n }\n\n /** The tile and the index in it of a picked index */\n tileAt(index: number): { key: TileKey | undefined; index: number } | undefined {\n let rest = index;\n for (const [key, tile] of [...this.tiles].sort((a, b) => a[1].batch - b[1].batch)) {\n if (rest < tile.properties.length) return { key: key === DATA ? undefined : key, index: rest };\n rest -= tile.properties.length;\n }\n return undefined;\n }\n\n setStyle(style: Partial<ExtrusionStyle<P>>): void {\n this.style = { ...this.style, ...style };\n const engine = this.map.engine;\n for (const tile of this.tiles.values()) this.sendStyle(engine, this.id, tile);\n this.sendLayer(engine, this.id);\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.setStyle({ visible } as Partial<ExtrusionStyle<P>>);\n }\n\n setFilter(filter: ((properties: P, index: number) => boolean) | undefined): void {\n this.style = { ...this.style, filter };\n for (const tile of this.tiles.values()) this.map.engine.setFeatureMask(this.id, this.mask(tile), tile.batch);\n this.map.requestRender();\n }\n\n /** One value per building of a tile (or of the data), colored through the ramp; NaN keeps a building's color */\n setValues(values: Float32Array | undefined, key?: TileKey): void {\n const tile = this.tiles.get(key ?? DATA);\n if (!tile) return;\n tile.values = values;\n this.map.engine.setFeatureValues(\n this.id,\n values ?? new Float32Array(tile.properties.length).fill(Number.NaN),\n tile.batch,\n );\n this.map.requestRender();\n }\n\n /**\n * Colors the buildings by the node values of a network layer, recolored with it: each building takes min(value(A)\n * + cost from A, value(B) + cost from B) from its anchors (`setAnchors`), through the ramp, up to `max` (above, or\n * unreached: its own color). Undefined: back to the buildings' own values.\n */\n linkNetwork(network: NetworkLayer | undefined, max = Number.POSITIVE_INFINITY): void {\n this.network = network && { layer: network, max };\n this.sendLink(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n /** Per building of a tile (or of the data): node A, node B, cost from A, cost from B (4 floats each) */\n setAnchors(anchors: Float32Array, key?: TileKey): void {\n const tile = this.tiles.get(key ?? DATA);\n if (!tile) return;\n tile.anchors = anchors;\n this.map.engine.setExtrusionAnchors(this.id, tile.batch, anchors);\n this.map.requestRender();\n }\n\n private put(\n key: TileKey | typeof DATA,\n properties: P[],\n features: Feature<P>[] | undefined,\n arrays: PolygonArrays | undefined,\n ): void {\n const old = this.tiles.get(key);\n const tile: Tile<P> = {\n batch: old?.batch ?? (key === DATA ? 0 : this.nextBatch++),\n properties,\n features,\n arrays,\n values: undefined,\n anchors: undefined,\n };\n this.tiles.set(key, tile);\n this.sendTile(this.map.engine, this.id, tile);\n this.map.requestRender();\n }\n\n private mask(tile: Tile<P>): Uint8Array {\n const { filter } = this.style;\n const mask = new Uint8Array(tile.properties.length).fill(255);\n if (filter)\n tile.properties.forEach((p, i) => {\n if (!filter(p, i)) mask[i] = 0;\n });\n return mask;\n }\n\n private sendTile(engine: Engine, id: number, tile: Tile<P>): void {\n const g = tile.arrays ?? polygonGeometry(tile.features ?? []);\n const n = tile.properties.length;\n engine.setExtrusionBatch(id, tile.batch, g.points, g.ringStart, g.polygonStart, g.feature, n);\n this.sendStyle(engine, id, tile);\n if (tile.values) engine.setFeatureValues(id, tile.values, tile.batch);\n if (tile.anchors) engine.setExtrusionAnchors(id, tile.batch, tile.anchors);\n }\n\n private sendStyle(engine: Engine, id: number, tile: Tile<P>): void {\n const { color, height, base } = this.style;\n const out = new Float32Array(tile.properties.length * FLOATS);\n // Constant colors parsed once: a tile has thousands of buildings\n const fixed = typeof color === 'string' ? parseColor(color) : undefined;\n tile.properties.forEach((p, i) => {\n const o = i * FLOATS;\n out.set(fixed ?? parseColor(evaluate(color, p, i)), o);\n out.set(stops(evaluate(height, p, i)), o + 8);\n out.set(stops(evaluate(base, p, i)), o + 16);\n });\n engine.setFeatureStyle(id, out, tile.batch);\n engine.setFeatureMask(id, this.mask(tile), tile.batch);\n }\n\n private sendLayer(engine: Engine, id: number): void {\n const { ramp, opacity, minZoom, maxZoom, visible } = this.style;\n const r = ramp && rampTexels(ramp);\n engine.setFeatureRamp(id, r?.rgba, r?.min ?? 0, r?.max ?? 1);\n engine.setFeatureLayer(id, Float32Array.from(stops(opacity)), minZoom, maxZoom, visible);\n }\n\n private sendLink(engine: Engine, id: number): void {\n const n = this.network;\n engine.linkExtrusionNetwork(id, n?.layer.id, n ? Math.min(n.max, 1e29) : 0);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addExtrusions();\n this.sendLayer(engine, id);\n for (const tile of this.tiles.values()) this.sendTile(engine, id, tile);\n this.sendLink(engine, id);\n return id;\n }\n}\n\nexport function extrusionStyle<P>(options: ExtrusionOptions<P>): ExtrusionStyle<P> {\n const { data: _, before: __, ...rest } = options;\n return {\n opacity: 1,\n minZoom: 0,\n maxZoom: 24,\n visible: true,\n filter: undefined,\n ramp: undefined,\n color: '#e4e1dc',\n height: 6,\n base: 0,\n ...rest,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"extrusions.js","sourceRoot":"","sources":["../src/extrusions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG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,EAAE,EAAE,CAAC,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QACxE,wFAAwF;QACxF,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;YAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3E,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,sGAAsG;IAC7F,MAAM,CAAC,MAAc;QAC5B,IAAI,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAI,OAA4B;IAC5D,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACjD,OAAO;QACL,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,CAAC;QACT,IAAI,EAAE,CAAC;QACP,GAAG,IAAI;KACR,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Extruded polygons (buildings), styled per feature like the other feature layers, coming in tiles (or one set): an\n * application loading a tiled source (BD TOPO vector tiles…) hands each tile's buildings to `setTile` and drops them\n * with `removeTile`. Colored by their color, by a value per building through the ramp (water at a building), or by\n * the node values of a network layer (`linkNetwork`: the travel time to each building, recolored with the network).\n */\nimport {\n evaluate,\n type Feature,\n type FeatureData,\n type FeatureLayerStyle,\n FLOATS,\n featuresOf,\n type Placement,\n type Properties,\n parseColor,\n polygonGeometry,\n rampTexels,\n type Styled,\n stops,\n} from './features.ts';\nimport { Layer, type NetworkLayer } from './layers.ts';\nimport type { LayerHost } from './types.ts';\nimport type { Engine } from './wasm/isard.js';\n\nexport interface ExtrusionStyle<P = Properties> extends FeatureLayerStyle<P> {\n /** CSS color (default `#e4e1dc`) */\n color: Styled<string, P>;\n /** Height of the roof over the ground, metres (default 6) */\n height: Styled<number, P>;\n /** Height of the foot of the walls, metres (default 0) */\n base: Styled<number, P>;\n}\n\nexport interface ExtrusionOptions<P = Properties> extends Partial<ExtrusionStyle<P>>, Placement {\n /** Polygon and MultiPolygon features, as one set (tiles come with `setTile`) */\n data?: FeatureData<P>;\n}\n\n/** Key of a tile of extrusions (see `ExtrusionLayer.setTile`) */\nexport type TileKey = string | number;\n\n/**\n * Polygons as typed arrays, for tiles decoded in a worker (no GeoJSON in between): points in Mercator [0, 1] (x, y\n * interleaved, y towards the south), the first point of each ring and the first ring of each polygon (one more entry\n * than rings and polygons; the first ring of a polygon is its outline), the feature of each polygon\n */\nexport interface PolygonArrays {\n points: Float64Array;\n ringStart: Uint32Array;\n polygonStart: Uint32Array;\n feature: Uint32Array;\n}\n\ninterface Tile<P> {\n /** Batch number in the engine: tiles are drawn, and their features numbered for picking, in this order */\n batch: number;\n /** The properties of the features, which the style reads */\n properties: P[];\n features: Feature<P>[] | undefined;\n arrays: PolygonArrays | undefined;\n values: Float32Array | undefined;\n anchors: Float32Array | undefined;\n}\n\n/** TileKey of the set given as `data` */\nconst DATA = Symbol('data');\n\nexport class ExtrusionLayer<P = Properties> extends Layer {\n private readonly tiles = new Map<TileKey | typeof DATA, Tile<P>>();\n private nextBatch = 1;\n private network: { layer: NetworkLayer; max: number } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n data: FeatureData<P> | undefined,\n private style: ExtrusionStyle<P>,\n ) {\n super(map);\n if (data) {\n const features = featuresOf(data);\n const properties = features.map((f) => f.properties);\n this.tiles.set(DATA, {\n batch: 0,\n properties,\n features,\n arrays: undefined,\n values: undefined,\n anchors: undefined,\n });\n }\n }\n\n /** Replaces the set given as `data` */\n setData(data: FeatureData<P>): void {\n const features = featuresOf(data);\n this.put(\n DATA,\n features.map((f) => f.properties),\n features,\n undefined,\n );\n }\n\n /** Adds or replaces the buildings of a tile: GeoJSON, or typed arrays with the properties of each feature */\n setTile(key: TileKey, data: FeatureData<P> | { arrays: PolygonArrays; properties: P[] }): void {\n if ('arrays' in data) this.put(key, data.properties, undefined, data.arrays);\n else {\n const features = featuresOf(data);\n this.put(\n key,\n features.map((f) => f.properties),\n features,\n undefined,\n );\n }\n }\n\n removeTile(key: TileKey): void {\n const tile = this.tiles.get(key);\n if (!tile) return;\n this.tiles.delete(key);\n this.map.engine.removeExtrusionBatch(this.id, tile.batch);\n this.map.requestRender();\n }\n\n /** Keys of the tiles held */\n get tileKeys(): TileKey[] {\n return [...this.tiles.keys()].filter((k): k is TileKey => k !== DATA);\n }\n\n /** The properties of the features of a tile (or of the data) */\n properties(key?: TileKey): readonly P[] {\n return this.tiles.get(key ?? DATA)?.properties ?? [];\n }\n\n /** The feature of a picked index (its geometry if given as GeoJSON): tiles are numbered one after the other, in the\n * order they were added */\n featureAt(index: number): Feature<P> | undefined {\n let rest = index;\n for (const tile of [...this.tiles.values()].sort((a, b) => a.batch - b.batch)) {\n const n = tile.properties.length;\n if (rest < n) {\n const properties = tile.properties[rest] as P;\n return tile.features?.[rest] ?? { type: 'Feature', properties, geometry: null };\n }\n rest -= n;\n }\n return undefined;\n }\n\n /** The tile and the index in it of a picked index */\n tileAt(index: number): { key: TileKey | undefined; index: number } | undefined {\n let rest = index;\n for (const [key, tile] of [...this.tiles].sort((a, b) => a[1].batch - b[1].batch)) {\n if (rest < tile.properties.length) return { key: key === DATA ? undefined : key, index: rest };\n rest -= tile.properties.length;\n }\n return undefined;\n }\n\n setStyle(style: Partial<ExtrusionStyle<P>>): void {\n this.style = { ...this.style, ...style };\n const engine = this.map.engine;\n for (const tile of this.tiles.values()) this.sendStyle(engine, this.id, tile);\n this.sendLayer(engine, this.id);\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.setStyle({ visible } as Partial<ExtrusionStyle<P>>);\n }\n\n setFilter(filter: ((properties: P, index: number) => boolean) | undefined): void {\n this.style = { ...this.style, filter };\n for (const tile of this.tiles.values()) this.map.engine.setFeatureMask(this.id, this.mask(tile), tile.batch);\n this.map.requestRender();\n }\n\n /** One value per building of a tile (or of the data), colored through the ramp; NaN keeps a building's color */\n setValues(values: Float32Array | undefined, key?: TileKey): void {\n const tile = this.tiles.get(key ?? DATA);\n if (!tile) return;\n tile.values = values;\n this.map.engine.setFeatureValues(\n this.id,\n values ?? new Float32Array(tile.properties.length).fill(Number.NaN),\n tile.batch,\n );\n this.map.requestRender();\n }\n\n /**\n * Colors the buildings by the node values of a network layer, recolored with it: each building takes min(value(A)\n * + cost from A, value(B) + cost from B) from its anchors (`setAnchors`), through the ramp, up to `max` (above, or\n * unreached: its own color). Undefined: back to the buildings' own values.\n */\n linkNetwork(network: NetworkLayer | undefined, max = Number.POSITIVE_INFINITY): void {\n this.network = network && { layer: network, max };\n this.sendLink(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n /** Per building of a tile (or of the data): node A, node B, cost from A, cost from B (4 floats each) */\n setAnchors(anchors: Float32Array, key?: TileKey): void {\n const tile = this.tiles.get(key ?? DATA);\n if (!tile) return;\n tile.anchors = anchors;\n this.map.engine.setExtrusionAnchors(this.id, tile.batch, anchors);\n this.map.requestRender();\n }\n\n private put(\n key: TileKey | typeof DATA,\n properties: P[],\n features: Feature<P>[] | undefined,\n arrays: PolygonArrays | undefined,\n ): void {\n const old = this.tiles.get(key);\n const tile: Tile<P> = {\n batch: old?.batch ?? (key === DATA ? 0 : this.nextBatch++),\n properties,\n features,\n arrays,\n values: undefined,\n anchors: undefined,\n };\n this.tiles.set(key, tile);\n this.sendTile(this.map.engine, this.id, tile);\n this.map.requestRender();\n }\n\n private mask(tile: Tile<P>): Uint8Array {\n const { filter } = this.style;\n const mask = new Uint8Array(tile.properties.length).fill(255);\n if (filter)\n tile.properties.forEach((p, i) => {\n if (!filter(p, i)) mask[i] = 0;\n });\n return mask;\n }\n\n private sendTile(engine: Engine, id: number, tile: Tile<P>): void {\n const g = tile.arrays ?? polygonGeometry(tile.features ?? []);\n const n = tile.properties.length;\n engine.setExtrusionBatch(id, tile.batch, g.points, g.ringStart, g.polygonStart, g.feature, n);\n this.sendStyle(engine, id, tile);\n if (tile.values) engine.setFeatureValues(id, tile.values, tile.batch);\n if (tile.anchors) engine.setExtrusionAnchors(id, tile.batch, tile.anchors);\n }\n\n private sendStyle(engine: Engine, id: number, tile: Tile<P>): void {\n const { color, height, base } = this.style;\n const out = new Float32Array(tile.properties.length * FLOATS);\n // Constant colors parsed once: a tile has thousands of buildings\n const fixed = typeof color === 'string' ? parseColor(color) : undefined;\n tile.properties.forEach((p, i) => {\n const o = i * FLOATS;\n out.set(fixed ?? parseColor(evaluate(color, p, i)), o);\n out.set(stops(evaluate(height, p, i)), o + 8);\n out.set(stops(evaluate(base, p, i)), o + 16);\n });\n engine.setFeatureStyle(id, out, tile.batch);\n engine.setFeatureMask(id, this.mask(tile), tile.batch);\n }\n\n private sendLayer(engine: Engine, id: number): void {\n const { ramp, opacity, minZoom, maxZoom, visible } = this.style;\n const r = ramp && rampTexels(ramp);\n engine.setFeatureRamp(id, r?.rgba, r?.min ?? 0, r?.max ?? 1);\n engine.setFeatureLayer(id, Float32Array.from(stops(opacity)), minZoom, maxZoom, visible);\n }\n\n private sendLink(engine: Engine, id: number): void {\n const n = this.network;\n // A network removed (or not created) links to nothing\n const network = n && n.layer.id >= 0 ? n.layer.id : undefined;\n engine.linkExtrusionNetwork(id, network, n ? Math.min(n.max, 1e29) : 0);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addExtrusions();\n this.sendLayer(engine, id);\n for (const tile of this.tiles.values()) this.sendTile(engine, id, tile);\n // A network created before (on a new engine, the map relinks once every layer is there)\n if (!this.network || this.network.layer.id >= 0) this.sendLink(engine, id);\n return id;\n }\n\n /** @internal On a new engine, the network may come after the buildings: linked once both are there */\n override relink(engine: Engine): void {\n if (this.network) this.sendLink(engine, this.id);\n }\n}\n\nexport function extrusionStyle<P>(options: ExtrusionOptions<P>): ExtrusionStyle<P> {\n const { data: _, before: __, ...rest } = options;\n return {\n opacity: 1,\n minZoom: 0,\n maxZoom: 24,\n visible: true,\n filter: undefined,\n ramp: undefined,\n color: '#e4e1dc',\n height: 6,\n base: 0,\n ...rest,\n };\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export { GeoMap } from './map.ts';
|
|
|
27
27
|
export { type Anchor, Marker, type MarkerEvent, type MarkerEvents, type MarkerOptions, Popup, type PopupEvents, type PopupOptions, } from './overlay.ts';
|
|
28
28
|
export type { SymbolOptions, SymbolStyle } from './symbols.ts';
|
|
29
29
|
export { SymbolLayer } from './symbols.ts';
|
|
30
|
-
export type { AnimationOptions, AtmosphereOptions, Basemap, BasemapName, BodyOptions, CelestialBody, FeatureHit, FlyToOptions, GeoMapOptions, LegacyBasemap, LoadingMode, LonLat, MapEvents, MapHoverFeatureEvent, MapPointerEvent, NetworkOptions, NetworkStyle, Point, Projection, RasterGrid, RasterOptions, TerrainEncoding, TerrainModel, TerrainOptions, Tiles3dOptions, Tiles3dStyle, } from './types.ts';
|
|
30
|
+
export type { AnimationOptions, AtmosphereOptions, Basemap, BasemapName, BodyOptions, CelestialBody, FeatureHit, FlyToOptions, GeoMapOptions, LegacyBasemap, LoadingMode, LonLat, MapEvents, MapHoverFeatureEvent, MapPointerEvent, NetworkOptions, NetworkStyle, Point, Projection, RasterGrid, RasterOptions, RasterStyle, TerrainEncoding, TerrainModel, TerrainOptions, Tiles3dOptions, Tiles3dStyle, } from './types.ts';
|
|
31
31
|
export type { Json, LabelCandidate, RasterSource, Style, StyleLayer } from './vectorstyle.ts';
|
|
32
32
|
export type { VectorTilesOptions } from './vectortiles.ts';
|
|
33
33
|
export { OPENFREEMAP_STYLES, PLAN_STYLES, VectorTiles } from './vectortiles.ts';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EACL,kBAAkB,EAIlB,mBAAmB,EACnB,iBAAiB,GAElB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAqBjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE5G,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAEL,MAAM,EAIN,KAAK,GAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EACL,kBAAkB,EAIlB,mBAAmB,EACnB,iBAAiB,GAElB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAqBjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE5G,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAEL,MAAM,EAIN,KAAK,GAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAgC3C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * isard: a WebGL2 map engine for large, interactive data layers, labels and 3D Tiles.\n *\n * ```ts\n * import { GeoMap } from 'isard';\n * const map = await GeoMap.create(container, { center: [2.4246, 48.8457], zoom: 13 });\n * const network = map.addNetwork({ nodes, edges, max: 1800, contour: 300 });\n * map.on('hover', ({ lonLat }) => lonLat && network.setValues(travelTimes(lonLat)));\n * map.addTiles3d({ url: 'https://…/tileset.json' });\n * map.addControl(new NavigationControl());\n * new Marker().setLonLat([2.4246, 48.8457]).setPopup(new Popup({ offset: [0, -34] }).setText('Here')).addTo(map);\n * ```\n */\nexport { OPENFREEMAP_ATTRIBUTION, TERRAIN_TILES_ATTRIBUTION } from './basemaps.ts';\nexport {\n AttributionControl,\n type AttributionOptions,\n type Control,\n type ControlPosition,\n DEFAULT_ATTRIBUTION,\n NavigationControl,\n type NavigationOptions,\n} from './controls.ts';\nexport type { DecoderUrls } from './decoders.ts';\nexport type { ExtrusionOptions, ExtrusionStyle, PolygonArrays, TileKey } from './extrusions.ts';\nexport { ExtrusionLayer } from './extrusions.ts';\nexport type {\n CircleOptions,\n CircleStyle,\n Feature,\n FeatureCollection,\n FeatureData,\n FeatureLayerStyle,\n FillOptions,\n FillStyle,\n Geometry,\n LineOptions,\n LineStyle,\n Placement,\n Position,\n Properties,\n Ramp,\n Size,\n Stops,\n Styled,\n} from './features.ts';\nexport { CircleLayer, FeatureLayer, FillLayer, interpolate, LineLayer, parseColor } from './features.ts';\nexport { geoplateformeWfs, geoplateformeWms, geoplateformeWmts, IGN_ATTRIBUTION } from './geoplateforme.ts';\nexport type { TextPart } from './glyphs.ts';\nexport { DEFAULT_FONT, GLYPHS_URL } from './glyphs.ts';\nexport type { GroundOptions, GroundTexture } from './layers.ts';\nexport { GroundLayer, Layer, NetworkLayer, RasterLayer, Tiles3dLayer } from './layers.ts';\nexport { GeoMap } from './map.ts';\nexport {\n type Anchor,\n Marker,\n type MarkerEvent,\n type MarkerEvents,\n type MarkerOptions,\n Popup,\n type PopupEvents,\n type PopupOptions,\n} from './overlay.ts';\nexport type { SymbolOptions, SymbolStyle } from './symbols.ts';\nexport { SymbolLayer } from './symbols.ts';\nexport type {\n AnimationOptions,\n AtmosphereOptions,\n Basemap,\n BasemapName,\n BodyOptions,\n CelestialBody,\n FeatureHit,\n FlyToOptions,\n GeoMapOptions,\n LegacyBasemap,\n LoadingMode,\n LonLat,\n MapEvents,\n MapHoverFeatureEvent,\n MapPointerEvent,\n NetworkOptions,\n NetworkStyle,\n Point,\n Projection,\n RasterGrid,\n RasterOptions,\n RasterStyle,\n TerrainEncoding,\n TerrainModel,\n TerrainOptions,\n Tiles3dOptions,\n Tiles3dStyle,\n} from './types.ts';\nexport type { Json, LabelCandidate, RasterSource, Style, StyleLayer } from './vectorstyle.ts';\nexport type { VectorTilesOptions } from './vectortiles.ts';\nexport { OPENFREEMAP_STYLES, PLAN_STYLES, VectorTiles } from './vectortiles.ts';\nexport type { Camera, NetworkStats, PickHit, PickResult, RasterLayerStats, Tiles3dStats } from './wasm/isard.js';\n"]}
|
package/dist/interaction.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ export declare class Interaction {
|
|
|
31
31
|
/** Recent pan moves, for the release speed: [time, dx, dy] */
|
|
32
32
|
private trail;
|
|
33
33
|
private moved;
|
|
34
|
+
/** The canvas's place on the page, read once: reading it on every pointer move would force a layout each time.
|
|
35
|
+
* Read again after a resize, a scroll, and when a pointer comes in or goes down */
|
|
36
|
+
private rect;
|
|
34
37
|
constructor(map: GeoMap, options?: {
|
|
35
38
|
keyboard?: boolean;
|
|
36
39
|
});
|
package/dist/interaction.js
CHANGED
|
@@ -78,6 +78,9 @@ export class Interaction {
|
|
|
78
78
|
/** Recent pan moves, for the release speed: [time, dx, dy] */
|
|
79
79
|
trail = [];
|
|
80
80
|
moved = false;
|
|
81
|
+
/** The canvas's place on the page, read once: reading it on every pointer move would force a layout each time.
|
|
82
|
+
* Read again after a resize, a scroll, and when a pointer comes in or goes down */
|
|
83
|
+
rect;
|
|
81
84
|
constructor(map, options = {}) {
|
|
82
85
|
this.map = map;
|
|
83
86
|
const canvas = map.canvas;
|
|
@@ -85,7 +88,20 @@ export class Interaction {
|
|
|
85
88
|
canvas.addEventListener(type, handler, options);
|
|
86
89
|
this.cleanup.push(() => canvas.removeEventListener(type, handler));
|
|
87
90
|
};
|
|
88
|
-
|
|
91
|
+
const moved = () => {
|
|
92
|
+
this.rect = undefined;
|
|
93
|
+
};
|
|
94
|
+
listen('pointerenter', moved);
|
|
95
|
+
// Scrolls of the page or of any element holding the map
|
|
96
|
+
if (typeof addEventListener === 'function') {
|
|
97
|
+
addEventListener('scroll', moved, { capture: true, passive: true });
|
|
98
|
+
this.cleanup.push(() => removeEventListener('scroll', moved, { capture: true }));
|
|
99
|
+
}
|
|
100
|
+
this.cleanup.push(map.on('resize', moved));
|
|
101
|
+
listen('pointerdown', (e) => {
|
|
102
|
+
this.rect = undefined;
|
|
103
|
+
this.down(e);
|
|
104
|
+
});
|
|
89
105
|
listen('pointermove', (e) => this.move(e));
|
|
90
106
|
listen('pointerup', (e) => this.up(e));
|
|
91
107
|
listen('pointercancel', (e) => this.up(e));
|
|
@@ -118,8 +134,8 @@ export class Interaction {
|
|
|
118
134
|
return this.pointers.size > 0;
|
|
119
135
|
}
|
|
120
136
|
local(e) {
|
|
121
|
-
|
|
122
|
-
return [e.clientX -
|
|
137
|
+
this.rect ??= this.map.canvas.getBoundingClientRect();
|
|
138
|
+
return [e.clientX - this.rect.left, e.clientY - this.rect.top];
|
|
123
139
|
}
|
|
124
140
|
down(e) {
|
|
125
141
|
this.map.canvas.setPointerCapture(e.pointerId);
|
package/dist/interaction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interaction.js","sourceRoot":"","sources":["../src/interaction.ts"],"names":[],"mappings":"AAQA,kFAAkF;AAClF,MAAM,UAAU,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3B,2FAA2F;AAC3F,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,gEAAgE;AAChE,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,gEAAgE;AAChE,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,uEAAuE;AACvE,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,qCAAqC;AACrC,MAAM,OAAO,GAAG,GAAG,CAAC;AACpB,8CAA8C;AAC9C,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,2CAA2C;AAC3C,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,uDAAuD;AACvD,MAAM,YAAY,GAAG,GAAG,CAAC;AAKzB;iEACiE;AACjE,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,KAAc;IACnD,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,WAAW;YACd,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;QACpE,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M,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACjE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/**\n * Mouse, touch and keyboard controls. Every gesture only updates the camera and asks for a frame: the engine draws at most\n * once per display refresh, whatever the event rate of the device.\n */\nimport type { GeoMap } from './map.ts';\nimport type { Point } from './types.ts';\nimport type { Camera } from './wasm/isard.js';\n\n/** Zoom levels per wheel pixel (a mouse notch is about 100 px: 1/3 of a level) */\nconst WHEEL_RATE = 1 / 300;\n/** Share of the remaining wheel zoom applied per frame (smooth, about 150 ms to settle) */\nconst WHEEL_EASE = 0.3;\n/** Degrees per pixel when rotating or tilting with the mouse */\nconst ROTATE_RATE = 0.4;\n/** A press that moves less than this (CSS pixels) is a click */\nconst CLICK_TOLERANCE = 4;\n/** Pan speed kept on release, decaying with this time constant (ms) */\nconst INERTIA_DECAY = 280;\n\n/** CSS pixels per arrow key press */\nconst KEY_PAN = 100;\n/** Degrees per Shift + left or right arrow */\nconst KEY_BEARING = 15;\n/** Degrees per Shift + up or down arrow */\nconst KEY_PITCH = 10;\n/** Duration of the moves made by keys, milliseconds */\nconst KEY_DURATION = 300;\n\n/** What a key does to the camera: a pan in CSS pixels, a zoom, rotation or tilt step, or facing north */\nexport type KeyAction = { pan: Point } | { zoom: number } | { bearing: number } | { pitch: number } | { reset: true };\n\n/** The action of a key (`KeyboardEvent.key`), as MapLibre's: arrows pan (with Shift: rotate and tilt), + and - zoom\n * (with Shift: two levels), 0 faces north and levels the view */\nexport function keyAction(key: string, shift: boolean): KeyAction | undefined {\n switch (key) {\n case 'ArrowLeft':\n return shift ? { bearing: -KEY_BEARING } : { pan: [-KEY_PAN, 0] };\n case 'ArrowRight':\n return shift ? { bearing: KEY_BEARING } : { pan: [KEY_PAN, 0] };\n case 'ArrowUp':\n return shift ? { pitch: KEY_PITCH } : { pan: [0, -KEY_PAN] };\n case 'ArrowDown':\n return shift ? { pitch: -KEY_PITCH } : { pan: [0, KEY_PAN] };\n case '+':\n case '=':\n return { zoom: shift ? 2 : 1 };\n case '-':\n case '_':\n return { zoom: shift ? -2 : -1 };\n case '0':\n return { reset: true };\n default:\n return undefined;\n }\n}\n\n/** The camera after a key's action: a pan moves the center by that many CSS pixels on screen (the ground in view,\n * turned with the bearing, stretched by the tilt) */\nexport function keyCamera(action: KeyAction, camera: Camera): Partial<Camera> {\n if ('zoom' in action) return { zoom: camera.zoom + action.zoom };\n if ('bearing' in action) return { bearing: camera.bearing + action.bearing };\n if ('pitch' in action) return { pitch: Math.max(0, camera.pitch + action.pitch) };\n if ('reset' in action) return { bearing: 0, pitch: 0 };\n const b = (camera.bearing * Math.PI) / 180;\n const [sx, sy] = [action.pan[0], action.pan[1] / Math.max(0.25, Math.cos((camera.pitch * Math.PI) / 180))];\n // Web Mercator units (0 to 1 across the world, y down); the world is 512 CSS pixels at zoom 0\n const world = 512 * 2 ** camera.zoom;\n const dx = (sx * Math.cos(b) - sy * Math.sin(b)) / world;\n const dy = (sx * Math.sin(b) + sy * Math.cos(b)) / world;\n const [lon, lat] = camera.center;\n const phi = (Math.max(-85.0511, Math.min(85.0511, lat)) * Math.PI) / 180;\n const x = (lon + 180) / 360 + dx;\n const y = Math.max(0, Math.min(1, (1 - Math.log(Math.tan(phi) + 1 / Math.cos(phi)) / Math.PI) / 2 + dy));\n const wrapped = ((((x * 360) % 360) + 360) % 360) - 180;\n return { center: [wrapped, (Math.atan(Math.sinh(Math.PI * (1 - 2 * y))) * 180) / Math.PI] };\n}\n\n/** An element that takes the keys typed in it */\nfunction editable(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLElement)) return false;\n return target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName);\n}\n\ninterface Pointer {\n point: Point;\n start: Point;\n button: number;\n rotate: boolean;\n}\n\nexport class Interaction {\n private readonly pointers = new Map<number, Pointer>();\n private readonly cleanup: (() => void)[] = [];\n private wheel = { pending: 0, at: [0, 0] as Point };\n /** Recent pan moves, for the release speed: [time, dx, dy] */\n private trail: [number, number, number][] = [];\n private moved = false;\n\n constructor(\n private readonly map: GeoMap,\n options: { keyboard?: boolean } = {},\n ) {\n const canvas = map.canvas;\n const listen = <K extends keyof HTMLElementEventMap>(\n type: K,\n handler: (e: HTMLElementEventMap[K]) => void,\n options?: AddEventListenerOptions,\n ) => {\n canvas.addEventListener(type, handler, options);\n this.cleanup.push(() => canvas.removeEventListener(type, handler));\n };\n listen('pointerdown', (e) => this.down(e));\n listen('pointermove', (e) => this.move(e));\n listen('pointerup', (e) => this.up(e));\n listen('pointercancel', (e) => this.up(e));\n listen('pointerleave', (e) => {\n if (e.pointerType !== 'mouse') return;\n map.hover(undefined);\n map.emit('leave', {});\n });\n // On the container, the wheel zooms over markers and popups too\n const container = map.getContainer();\n const wheel = (e: WheelEvent) => this.onWheel(e);\n container.addEventListener('wheel', wheel, { passive: false });\n this.cleanup.push(() => container.removeEventListener('wheel', wheel));\n listen('dblclick', (e) => this.zoomBy(e.shiftKey ? -1 : 1, this.local(e)));\n listen('contextmenu', (e) => e.preventDefault());\n if (options.keyboard ?? true) {\n // On the container: the keys work with the focus on a marker or a control too\n const key = (e: KeyboardEvent) => this.onKey(e);\n container.addEventListener('keydown', key);\n this.cleanup.push(() => container.removeEventListener('keydown', key));\n }\n }\n\n destroy(): void {\n for (const off of this.cleanup) off();\n }\n\n /** A gesture holds the map (pointers down): the camera has not stopped moving */\n get active(): boolean {\n return this.pointers.size > 0;\n }\n\n private local(e: MouseEvent): Point {\n const r = this.map.canvas.getBoundingClientRect();\n return [e.clientX - r.left, e.clientY - r.top];\n }\n\n private down(e: PointerEvent): void {\n this.map.canvas.setPointerCapture(e.pointerId);\n const point = this.local(e);\n const rotate = e.button === 2 || e.ctrlKey || e.shiftKey;\n this.pointers.set(e.pointerId, { point, start: point, button: e.button, rotate });\n this.trail = [];\n this.moved = false;\n // Grabbing the map stops any running animation (inertia, wheel zoom, easeTo)\n this.wheel.pending = 0;\n this.map.animate(undefined);\n }\n\n private move(e: PointerEvent): void {\n const point = this.local(e);\n const p = this.pointers.get(e.pointerId);\n if (!p) {\n if (e.pointerType === 'mouse') this.map.hover(point);\n return;\n }\n const [dx, dy] = [point[0] - p.point[0], point[1] - p.point[1]];\n if (Math.hypot(point[0] - p.start[0], point[1] - p.start[1]) > CLICK_TOLERANCE) this.moved = true;\n const engine = this.map.engine;\n const other = [...this.pointers.values()].find((q) => q !== p);\n if (this.pointers.size === 2 && other) {\n // Pinch: zoom by the change of spread, turn by the change of angle, pan by the midpoint\n const before = Math.hypot(p.point[0] - other.point[0], p.point[1] - other.point[1]);\n const after = Math.hypot(point[0] - other.point[0], point[1] - other.point[1]);\n const angle = (q: Point) => Math.atan2(q[1] - other.point[1], q[0] - other.point[0]);\n const mid = (q: Point): Point => [(q[0] + other.point[0]) / 2, (q[1] + other.point[1]) / 2];\n engine.pan(...mid(p.point), ...mid(point));\n if (before > 0 && after > 0) engine.zoomAt(Math.log2(after / before), ...mid(point));\n engine.rotate((-(angle(point) - angle(p.point)) * 180) / Math.PI, 0);\n } else if (p.rotate) {\n engine.rotate(-dx * ROTATE_RATE, -dy * ROTATE_RATE);\n } else {\n engine.pan(p.point[0], p.point[1], point[0], point[1]);\n this.trail.push([e.timeStamp, dx, dy]);\n }\n p.point = point;\n this.map.requestRender();\n }\n\n private up(e: PointerEvent): void {\n const p = this.pointers.get(e.pointerId);\n if (!p) return;\n this.pointers.delete(e.pointerId);\n // The next frame sends 'moveend' if the camera stays\n this.map.requestRender();\n if (!this.moved && e.type === 'pointerup' && p.button === 0 && this.pointers.size === 0) {\n this.map.emit('click', { point: p.point, lonLat: this.map.unproject(p.point) });\n return;\n }\n if (!p.rotate && this.pointers.size === 0) this.inertia(e.timeStamp, p.point);\n }\n\n /** Keeps panning at the release speed (last 50 ms), decaying exponentially */\n private inertia(now: number, from: Point): void {\n const recent = this.trail.filter(([t]) => now - t < 50);\n const first = recent[0];\n if (!first || recent.length < 2) return;\n const span = Math.max(16, now - first[0]);\n let vx = recent.reduce((s, [, dx]) => s + dx, 0) / span;\n let vy = recent.reduce((s, [, , dy]) => s + dy, 0) / span;\n if (Math.hypot(vx, vy) < 0.1) return;\n let last = performance.now();\n let point = from;\n this.map.animate((t) => {\n const dt = Math.min(64, t - last);\n last = t;\n const decay = Math.exp(-dt / INERTIA_DECAY);\n const next: Point = [point[0] + vx * dt, point[1] + vy * dt];\n this.map.engine.pan(point[0], point[1], next[0], next[1]);\n point = next;\n vx *= decay;\n vy *= decay;\n return Math.hypot(vx, vy) > 0.02;\n });\n }\n\n private onWheel(e: WheelEvent): void {\n e.preventDefault();\n // Lines (Firefox mouse wheels) are about 33 px\n const pixels = e.deltaMode === 1 ? e.deltaY * 33 : e.deltaY;\n this.zoomBy(\n Math.max(-1, Math.min(1, -pixels * WHEEL_RATE)),\n this.local(e),\n e.deltaMode === 0 && Math.abs(pixels) < 40,\n );\n }\n\n private onKey(e: KeyboardEvent): void {\n if (e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || editable(e.target)) return;\n const action = keyAction(e.key, e.shiftKey);\n if (!action) return;\n e.preventDefault();\n this.wheel.pending = 0;\n const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n this.map.easeTo(keyCamera(action, this.map.getCamera()), reduced ? 0 : KEY_DURATION);\n }\n\n /** Smooth zoom around a screen point; touchpads (`direct`) follow the fingers without easing */\n private zoomBy(delta: number, at: Point, direct = false): void {\n if (direct) {\n this.map.engine.zoomAt(delta, at[0], at[1]);\n this.map.requestRender();\n return;\n }\n // Accumulate: a second notch before the end of the first one adds to it\n this.wheel.pending += delta;\n this.wheel.at = at;\n this.map.animate(() => {\n const step = Math.abs(this.wheel.pending) < 0.002 ? this.wheel.pending : this.wheel.pending * WHEEL_EASE;\n this.wheel.pending -= step;\n this.map.engine.zoomAt(step, this.wheel.at[0], this.wheel.at[1]);\n return this.wheel.pending !== 0;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interaction.js","sourceRoot":"","sources":["../src/interaction.ts"],"names":[],"mappings":"AAQA,kFAAkF;AAClF,MAAM,UAAU,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3B,2FAA2F;AAC3F,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,gEAAgE;AAChE,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,gEAAgE;AAChE,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,uEAAuE;AACvE,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,qCAAqC;AACrC,MAAM,OAAO,GAAG,GAAG,CAAC;AACpB,8CAA8C;AAC9C,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,2CAA2C;AAC3C,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,uDAAuD;AACvD,MAAM,YAAY,GAAG,GAAG,CAAC;AAKzB;iEACiE;AACjE,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,KAAc;IACnD,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,WAAW;YACd,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;QACpE,KAAK,YAAY;YACf,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;QAClE,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAA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C;QAC5B,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE;YACpB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,UAAU,CAAC;YACzG,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACjE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/**\n * Mouse, touch and keyboard controls. Every gesture only updates the camera and asks for a frame: the engine draws at most\n * once per display refresh, whatever the event rate of the device.\n */\nimport type { GeoMap } from './map.ts';\nimport type { Point } from './types.ts';\nimport type { Camera } from './wasm/isard.js';\n\n/** Zoom levels per wheel pixel (a mouse notch is about 100 px: 1/3 of a level) */\nconst WHEEL_RATE = 1 / 300;\n/** Share of the remaining wheel zoom applied per frame (smooth, about 150 ms to settle) */\nconst WHEEL_EASE = 0.3;\n/** Degrees per pixel when rotating or tilting with the mouse */\nconst ROTATE_RATE = 0.4;\n/** A press that moves less than this (CSS pixels) is a click */\nconst CLICK_TOLERANCE = 4;\n/** Pan speed kept on release, decaying with this time constant (ms) */\nconst INERTIA_DECAY = 280;\n\n/** CSS pixels per arrow key press */\nconst KEY_PAN = 100;\n/** Degrees per Shift + left or right arrow */\nconst KEY_BEARING = 15;\n/** Degrees per Shift + up or down arrow */\nconst KEY_PITCH = 10;\n/** Duration of the moves made by keys, milliseconds */\nconst KEY_DURATION = 300;\n\n/** What a key does to the camera: a pan in CSS pixels, a zoom, rotation or tilt step, or facing north */\nexport type KeyAction = { pan: Point } | { zoom: number } | { bearing: number } | { pitch: number } | { reset: true };\n\n/** The action of a key (`KeyboardEvent.key`), as MapLibre's: arrows pan (with Shift: rotate and tilt), + and - zoom\n * (with Shift: two levels), 0 faces north and levels the view */\nexport function keyAction(key: string, shift: boolean): KeyAction | undefined {\n switch (key) {\n case 'ArrowLeft':\n return shift ? { bearing: -KEY_BEARING } : { pan: [-KEY_PAN, 0] };\n case 'ArrowRight':\n return shift ? { bearing: KEY_BEARING } : { pan: [KEY_PAN, 0] };\n case 'ArrowUp':\n return shift ? { pitch: KEY_PITCH } : { pan: [0, -KEY_PAN] };\n case 'ArrowDown':\n return shift ? { pitch: -KEY_PITCH } : { pan: [0, KEY_PAN] };\n case '+':\n case '=':\n return { zoom: shift ? 2 : 1 };\n case '-':\n case '_':\n return { zoom: shift ? -2 : -1 };\n case '0':\n return { reset: true };\n default:\n return undefined;\n }\n}\n\n/** The camera after a key's action: a pan moves the center by that many CSS pixels on screen (the ground in view,\n * turned with the bearing, stretched by the tilt) */\nexport function keyCamera(action: KeyAction, camera: Camera): Partial<Camera> {\n if ('zoom' in action) return { zoom: camera.zoom + action.zoom };\n if ('bearing' in action) return { bearing: camera.bearing + action.bearing };\n if ('pitch' in action) return { pitch: Math.max(0, camera.pitch + action.pitch) };\n if ('reset' in action) return { bearing: 0, pitch: 0 };\n const b = (camera.bearing * Math.PI) / 180;\n const [sx, sy] = [action.pan[0], action.pan[1] / Math.max(0.25, Math.cos((camera.pitch * Math.PI) / 180))];\n // Web Mercator units (0 to 1 across the world, y down); the world is 512 CSS pixels at zoom 0\n const world = 512 * 2 ** camera.zoom;\n const dx = (sx * Math.cos(b) - sy * Math.sin(b)) / world;\n const dy = (sx * Math.sin(b) + sy * Math.cos(b)) / world;\n const [lon, lat] = camera.center;\n const phi = (Math.max(-85.0511, Math.min(85.0511, lat)) * Math.PI) / 180;\n const x = (lon + 180) / 360 + dx;\n const y = Math.max(0, Math.min(1, (1 - Math.log(Math.tan(phi) + 1 / Math.cos(phi)) / Math.PI) / 2 + dy));\n const wrapped = ((((x * 360) % 360) + 360) % 360) - 180;\n return { center: [wrapped, (Math.atan(Math.sinh(Math.PI * (1 - 2 * y))) * 180) / Math.PI] };\n}\n\n/** An element that takes the keys typed in it */\nfunction editable(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLElement)) return false;\n return target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName);\n}\n\ninterface Pointer {\n point: Point;\n start: Point;\n button: number;\n rotate: boolean;\n}\n\nexport class Interaction {\n private readonly pointers = new Map<number, Pointer>();\n private readonly cleanup: (() => void)[] = [];\n private wheel = { pending: 0, at: [0, 0] as Point };\n /** Recent pan moves, for the release speed: [time, dx, dy] */\n private trail: [number, number, number][] = [];\n private moved = false;\n /** The canvas's place on the page, read once: reading it on every pointer move would force a layout each time.\n * Read again after a resize, a scroll, and when a pointer comes in or goes down */\n private rect: DOMRect | undefined;\n\n constructor(\n private readonly map: GeoMap,\n options: { keyboard?: boolean } = {},\n ) {\n const canvas = map.canvas;\n const listen = <K extends keyof HTMLElementEventMap>(\n type: K,\n handler: (e: HTMLElementEventMap[K]) => void,\n options?: AddEventListenerOptions,\n ) => {\n canvas.addEventListener(type, handler, options);\n this.cleanup.push(() => canvas.removeEventListener(type, handler));\n };\n const moved = () => {\n this.rect = undefined;\n };\n listen('pointerenter', moved);\n // Scrolls of the page or of any element holding the map\n if (typeof addEventListener === 'function') {\n addEventListener('scroll', moved, { capture: true, passive: true });\n this.cleanup.push(() => removeEventListener('scroll', moved, { capture: true }));\n }\n this.cleanup.push(map.on('resize', moved));\n listen('pointerdown', (e) => {\n this.rect = undefined;\n this.down(e);\n });\n listen('pointermove', (e) => this.move(e));\n listen('pointerup', (e) => this.up(e));\n listen('pointercancel', (e) => this.up(e));\n listen('pointerleave', (e) => {\n if (e.pointerType !== 'mouse') return;\n map.hover(undefined);\n map.emit('leave', {});\n });\n // On the container, the wheel zooms over markers and popups too\n const container = map.getContainer();\n const wheel = (e: WheelEvent) => this.onWheel(e);\n container.addEventListener('wheel', wheel, { passive: false });\n this.cleanup.push(() => container.removeEventListener('wheel', wheel));\n listen('dblclick', (e) => this.zoomBy(e.shiftKey ? -1 : 1, this.local(e)));\n listen('contextmenu', (e) => e.preventDefault());\n if (options.keyboard ?? true) {\n // On the container: the keys work with the focus on a marker or a control too\n const key = (e: KeyboardEvent) => this.onKey(e);\n container.addEventListener('keydown', key);\n this.cleanup.push(() => container.removeEventListener('keydown', key));\n }\n }\n\n destroy(): void {\n for (const off of this.cleanup) off();\n }\n\n /** A gesture holds the map (pointers down): the camera has not stopped moving */\n get active(): boolean {\n return this.pointers.size > 0;\n }\n\n private local(e: MouseEvent): Point {\n this.rect ??= this.map.canvas.getBoundingClientRect();\n return [e.clientX - this.rect.left, e.clientY - this.rect.top];\n }\n\n private down(e: PointerEvent): void {\n this.map.canvas.setPointerCapture(e.pointerId);\n const point = this.local(e);\n const rotate = e.button === 2 || e.ctrlKey || e.shiftKey;\n this.pointers.set(e.pointerId, { point, start: point, button: e.button, rotate });\n this.trail = [];\n this.moved = false;\n // Grabbing the map stops any running animation (inertia, wheel zoom, easeTo)\n this.wheel.pending = 0;\n this.map.animate(undefined);\n }\n\n private move(e: PointerEvent): void {\n const point = this.local(e);\n const p = this.pointers.get(e.pointerId);\n if (!p) {\n if (e.pointerType === 'mouse') this.map.hover(point);\n return;\n }\n const [dx, dy] = [point[0] - p.point[0], point[1] - p.point[1]];\n if (Math.hypot(point[0] - p.start[0], point[1] - p.start[1]) > CLICK_TOLERANCE) this.moved = true;\n const engine = this.map.engine;\n const other = [...this.pointers.values()].find((q) => q !== p);\n if (this.pointers.size === 2 && other) {\n // Pinch: zoom by the change of spread, turn by the change of angle, pan by the midpoint\n const before = Math.hypot(p.point[0] - other.point[0], p.point[1] - other.point[1]);\n const after = Math.hypot(point[0] - other.point[0], point[1] - other.point[1]);\n const angle = (q: Point) => Math.atan2(q[1] - other.point[1], q[0] - other.point[0]);\n const mid = (q: Point): Point => [(q[0] + other.point[0]) / 2, (q[1] + other.point[1]) / 2];\n engine.pan(...mid(p.point), ...mid(point));\n if (before > 0 && after > 0) engine.zoomAt(Math.log2(after / before), ...mid(point));\n engine.rotate((-(angle(point) - angle(p.point)) * 180) / Math.PI, 0);\n } else if (p.rotate) {\n engine.rotate(-dx * ROTATE_RATE, -dy * ROTATE_RATE);\n } else {\n engine.pan(p.point[0], p.point[1], point[0], point[1]);\n this.trail.push([e.timeStamp, dx, dy]);\n }\n p.point = point;\n this.map.requestRender();\n }\n\n private up(e: PointerEvent): void {\n const p = this.pointers.get(e.pointerId);\n if (!p) return;\n this.pointers.delete(e.pointerId);\n // The next frame sends 'moveend' if the camera stays\n this.map.requestRender();\n if (!this.moved && e.type === 'pointerup' && p.button === 0 && this.pointers.size === 0) {\n this.map.emit('click', { point: p.point, lonLat: this.map.unproject(p.point) });\n return;\n }\n if (!p.rotate && this.pointers.size === 0) this.inertia(e.timeStamp, p.point);\n }\n\n /** Keeps panning at the release speed (last 50 ms), decaying exponentially */\n private inertia(now: number, from: Point): void {\n const recent = this.trail.filter(([t]) => now - t < 50);\n const first = recent[0];\n if (!first || recent.length < 2) return;\n const span = Math.max(16, now - first[0]);\n let vx = recent.reduce((s, [, dx]) => s + dx, 0) / span;\n let vy = recent.reduce((s, [, , dy]) => s + dy, 0) / span;\n if (Math.hypot(vx, vy) < 0.1) return;\n let last = performance.now();\n let point = from;\n this.map.animate((t) => {\n const dt = Math.min(64, t - last);\n last = t;\n const decay = Math.exp(-dt / INERTIA_DECAY);\n const next: Point = [point[0] + vx * dt, point[1] + vy * dt];\n this.map.engine.pan(point[0], point[1], next[0], next[1]);\n point = next;\n vx *= decay;\n vy *= decay;\n return Math.hypot(vx, vy) > 0.02;\n });\n }\n\n private onWheel(e: WheelEvent): void {\n e.preventDefault();\n // Lines (Firefox mouse wheels) are about 33 px\n const pixels = e.deltaMode === 1 ? e.deltaY * 33 : e.deltaY;\n this.zoomBy(\n Math.max(-1, Math.min(1, -pixels * WHEEL_RATE)),\n this.local(e),\n e.deltaMode === 0 && Math.abs(pixels) < 40,\n );\n }\n\n private onKey(e: KeyboardEvent): void {\n if (e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || editable(e.target)) return;\n const action = keyAction(e.key, e.shiftKey);\n if (!action) return;\n e.preventDefault();\n this.wheel.pending = 0;\n const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n this.map.easeTo(keyCamera(action, this.map.getCamera()), reduced ? 0 : KEY_DURATION);\n }\n\n /** Smooth zoom around a screen point; touchpads (`direct`) follow the fingers without easing */\n private zoomBy(delta: number, at: Point, direct = false): void {\n if (direct) {\n this.map.engine.zoomAt(delta, at[0], at[1]);\n this.map.requestRender();\n return;\n }\n // Accumulate: a second notch before the end of the first one adds to it\n this.wheel.pending += delta;\n this.wheel.at = at;\n this.map.animate(() => {\n const step = Math.abs(this.wheel.pending) < 0.002 ? this.wheel.pending : this.wheel.pending * WHEEL_EASE;\n this.wheel.pending -= step;\n this.map.engine.zoomAt(step, this.wheel.at[0], this.wheel.at[1]);\n return this.wheel.pending !== 0;\n });\n }\n}\n"]}
|
package/dist/isard_bg.wasm
CHANGED
|
Binary file
|
package/dist/isard_core_bg.wasm
CHANGED
|
Binary file
|
package/dist/layers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LonLat, NetworkStyle, Tiles3dStyle } from './types.ts';
|
|
1
|
+
import type { LonLat, NetworkStyle, RasterStyle, Tiles3dStyle } from './types.ts';
|
|
2
2
|
import type { NetworkStats, Tiles3dStats } from './wasm/isard.js';
|
|
3
3
|
export declare abstract class Layer {
|
|
4
4
|
#private;
|
|
@@ -11,6 +11,9 @@ export declare abstract class Layer {
|
|
|
11
11
|
/** Raster tiles (basemaps, overlays) */
|
|
12
12
|
export declare class RasterLayer extends Layer {
|
|
13
13
|
private readonly options;
|
|
14
|
+
/** Changes the opacity or saturation, the other kept */
|
|
15
|
+
setStyle(style: Partial<RasterStyle>): void;
|
|
16
|
+
/** @deprecated Positional form (saturation back to 1 when not given): `setStyle({ opacity, saturation })` */
|
|
14
17
|
setStyle(opacity: number, saturation?: number): void;
|
|
15
18
|
}
|
|
16
19
|
/** Line network colored by a value per node (travel time, water depth…) */
|
package/dist/layers.js
CHANGED
|
@@ -15,14 +15,22 @@ export class Layer {
|
|
|
15
15
|
get id() {
|
|
16
16
|
return this.#id;
|
|
17
17
|
}
|
|
18
|
-
/** @internal Creates the layer in an engine (again after a context loss) */
|
|
18
|
+
/** @internal Creates the layer in an engine (again after a context loss); its id is -1 if that fails */
|
|
19
19
|
attach(engine) {
|
|
20
|
+
this.#id = -1;
|
|
20
21
|
this.#id = this.create(engine);
|
|
21
22
|
}
|
|
23
|
+
/** @internal Forgets its id in an engine that is gone (before the layers are created in a new one) */
|
|
24
|
+
forgetEngine() {
|
|
25
|
+
this.#id = -1;
|
|
26
|
+
}
|
|
27
|
+
/** @internal Sends what refers to other layers, once every layer of a new engine has its id */
|
|
28
|
+
relink(_engine) { }
|
|
22
29
|
remove() {
|
|
23
30
|
// Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles
|
|
24
31
|
if (this.#id >= 0)
|
|
25
32
|
this.map.engine.removeLayer(this.#id);
|
|
33
|
+
this.#id = -1;
|
|
26
34
|
this.map.detach(this);
|
|
27
35
|
this.map.requestRender();
|
|
28
36
|
}
|
|
@@ -39,10 +47,11 @@ export class RasterLayer extends Layer {
|
|
|
39
47
|
super(map);
|
|
40
48
|
this.options = options;
|
|
41
49
|
}
|
|
42
|
-
setStyle(
|
|
43
|
-
|
|
44
|
-
this.options.
|
|
45
|
-
this.
|
|
50
|
+
setStyle(style, saturation = 1) {
|
|
51
|
+
const changed = typeof style === 'number' ? { opacity: style, saturation } : style;
|
|
52
|
+
this.options.opacity = changed.opacity ?? this.options.opacity;
|
|
53
|
+
this.options.saturation = changed.saturation ?? this.options.saturation;
|
|
54
|
+
this.map.engine.setRasterStyle(this.id, this.options.opacity, this.options.saturation);
|
|
46
55
|
this.map.requestRender();
|
|
47
56
|
}
|
|
48
57
|
/** @internal */
|