isard 0.3.0 → 0.4.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 +35 -0
- package/README.md +6 -2
- package/dist/basemap.worker.d.ts +10 -3
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +4 -4
- package/dist/decoder.worker.js +4 -4
- package/dist/decoder.worker.js.map +4 -4
- package/dist/engine-loader.d.ts +2 -1
- package/dist/engine-loader.js.map +1 -1
- package/dist/glyphs.d.ts +3 -0
- package/dist/glyphs.js +12 -2
- package/dist/glyphs.js.map +1 -1
- package/dist/icons.d.ts +146 -0
- package/dist/icons.js +333 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +5 -4
- 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.d.ts +88 -1
- package/dist/layers.js +163 -2
- package/dist/layers.js.map +1 -1
- package/dist/map.d.ts +29 -3
- package/dist/map.js +66 -8
- package/dist/map.js.map +1 -1
- package/dist/symbols.d.ts +42 -8
- package/dist/symbols.js +160 -35
- package/dist/symbols.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.js.map +1 -1
- package/dist/vectorstyle.d.ts +32 -3
- package/dist/vectorstyle.js.map +1 -1
- package/dist/vectortiles.d.ts +10 -5
- package/dist/vectortiles.js +54 -29
- package/dist/vectortiles.js.map +1 -1
- package/dist/wasm/isard.d.ts +46 -4
- package/dist/wasm/isard.js +110 -5
- package/dist/wasm/isard_core.d.ts +28 -3
- package/dist/wasm/isard_core.js +77 -4
- package/package.json +1 -1
package/dist/layers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Handles of the layers added to a map. Each one keeps what it needs to be created again: after a WebGL context loss,
|
|
3
|
-
* the map recreates its engine and every layer in order, with the same handle (its id is updated).
|
|
3
|
+
* the map recreates its engine and every layer in order, with the same handle (its id is updated). Also the page's
|
|
4
|
+
* own 3D content: custom layers (its WebGL code called in every frame) and glTF models drawn at positions.
|
|
4
5
|
*/
|
|
5
6
|
import { parseColor, rampTexels, stops } from "./features.js";
|
|
6
7
|
import { mercatorX, mercatorY, toMercator } from "./geo.js";
|
|
@@ -27,8 +28,14 @@ export class Layer {
|
|
|
27
28
|
}
|
|
28
29
|
/** @internal Sends what refers to other layers, once every layer of a new engine has its id */
|
|
29
30
|
relink(_engine) { }
|
|
31
|
+
/** @internal Drawn by the engine with 3D Tiles only (3D Tiles, models): on the core engine, it waits for that one */
|
|
32
|
+
get needsFullEngine() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
/** @internal The layer is removed or its map destroyed: frees what it holds outside the engine */
|
|
36
|
+
dispose() { }
|
|
30
37
|
remove() {
|
|
31
|
-
// Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles
|
|
38
|
+
// Not created yet: a 3D Tiles layer or a model waiting for the engine with 3D Tiles
|
|
32
39
|
if (this.#id >= 0)
|
|
33
40
|
this.map.engine.removeLayer(this.#id);
|
|
34
41
|
this.#id = -1;
|
|
@@ -200,6 +207,10 @@ export class Tiles3dLayer extends Layer {
|
|
|
200
207
|
this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);
|
|
201
208
|
this.map.requestRender();
|
|
202
209
|
}
|
|
210
|
+
/** @internal */
|
|
211
|
+
get needsFullEngine() {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
203
214
|
/** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see
|
|
204
215
|
* `GeoMapOptions.tiles3d`) */
|
|
205
216
|
stats() {
|
|
@@ -282,4 +293,154 @@ function mercatorBox([west, south, east, north]) {
|
|
|
282
293
|
const [x1, y0] = toMercator([east, north]);
|
|
283
294
|
return [x0, y0, x1, y1];
|
|
284
295
|
}
|
|
296
|
+
// ── The page's own 3D content: custom layers, glTF models ──
|
|
297
|
+
/** Reports an error of the page without throwing it here: the console shows it, as an uncaught one */
|
|
298
|
+
function report(error) {
|
|
299
|
+
if (typeof reportError === 'function')
|
|
300
|
+
reportError(error);
|
|
301
|
+
else
|
|
302
|
+
queueMicrotask(() => {
|
|
303
|
+
throw error;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/** A layer drawn by the page's WebGL code (see `CustomLayerInterface`) */
|
|
307
|
+
export class CustomLayer extends Layer {
|
|
308
|
+
implementation;
|
|
309
|
+
canvas;
|
|
310
|
+
owner;
|
|
311
|
+
/** The map's WebGL context, and whether `onAdd` made the layer's objects there (until `onRemove`) */
|
|
312
|
+
gl;
|
|
313
|
+
added = false;
|
|
314
|
+
/** The context was lost since `onAdd`: its objects are gone */
|
|
315
|
+
stale = false;
|
|
316
|
+
lost = () => {
|
|
317
|
+
this.stale = true;
|
|
318
|
+
};
|
|
319
|
+
frame;
|
|
320
|
+
/** @internal */
|
|
321
|
+
constructor(map,
|
|
322
|
+
/** The application's object */
|
|
323
|
+
implementation, canvas, owner, matrix, camera) {
|
|
324
|
+
super(map);
|
|
325
|
+
this.implementation = implementation;
|
|
326
|
+
this.canvas = canvas;
|
|
327
|
+
this.owner = owner;
|
|
328
|
+
// The context the engine made on the canvas
|
|
329
|
+
this.gl = canvas.getContext('webgl2');
|
|
330
|
+
this.frame = {
|
|
331
|
+
matrixAt: ([lon, lat], altitude = 0) => {
|
|
332
|
+
const m = matrix(lon, lat, altitude);
|
|
333
|
+
if (!m)
|
|
334
|
+
throw new Error('isard: frame.matrixAt is only available during render');
|
|
335
|
+
return m;
|
|
336
|
+
},
|
|
337
|
+
get camera() {
|
|
338
|
+
return camera();
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/** @internal */
|
|
343
|
+
create(engine) {
|
|
344
|
+
// Once, and again on a context restored (not when the map moves onto another engine: the same context)
|
|
345
|
+
if (!this.added || this.stale) {
|
|
346
|
+
if (!this.added)
|
|
347
|
+
this.canvas.addEventListener('webglcontextlost', this.lost);
|
|
348
|
+
this.added = true;
|
|
349
|
+
this.stale = false;
|
|
350
|
+
this.implementation.onAdd?.(this.gl, this.owner);
|
|
351
|
+
}
|
|
352
|
+
return engine.addCustomLayer(this.draw, this.implementation.renderingMode === '3d');
|
|
353
|
+
}
|
|
354
|
+
/** Called by the engine at the layer's place in the frame; the page's errors are reported, the frame goes on */
|
|
355
|
+
draw = () => {
|
|
356
|
+
try {
|
|
357
|
+
this.implementation.render(this.gl, this.frame);
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
report(error);
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
remove() {
|
|
364
|
+
super.remove();
|
|
365
|
+
this.dispose();
|
|
366
|
+
}
|
|
367
|
+
/** @internal The layer is removed or the map destroyed: `onRemove`, unless the context is lost */
|
|
368
|
+
dispose() {
|
|
369
|
+
if (!this.added)
|
|
370
|
+
return;
|
|
371
|
+
this.added = false;
|
|
372
|
+
this.canvas.removeEventListener('webglcontextlost', this.lost);
|
|
373
|
+
if (this.stale)
|
|
374
|
+
return;
|
|
375
|
+
try {
|
|
376
|
+
this.implementation.onRemove?.(this.gl, this.owner);
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
report(error);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/** The numbers of instances for the engine: longitude, latitude, altitude, heading, pitch, roll, scale */
|
|
384
|
+
export function instanceNumbers(instances) {
|
|
385
|
+
const out = new Float64Array(instances.length * 7);
|
|
386
|
+
instances.forEach(({ lonLat, altitude = 0, heading = 0, pitch = 0, roll = 0, scale = 1 }, i) => {
|
|
387
|
+
out.set([lonLat[0], lonLat[1], altitude, heading, pitch, roll, scale], i * 7);
|
|
388
|
+
});
|
|
389
|
+
return out;
|
|
390
|
+
}
|
|
391
|
+
/** A glTF model drawn at positions, in one instanced draw; `pickFeature` gives the instance's index */
|
|
392
|
+
export class ModelLayer extends Layer {
|
|
393
|
+
url;
|
|
394
|
+
/** The `blob:` URL of the page's bytes, revoked once the layer is gone */
|
|
395
|
+
blob;
|
|
396
|
+
instances;
|
|
397
|
+
ground;
|
|
398
|
+
/** @internal */
|
|
399
|
+
constructor(map, options) {
|
|
400
|
+
super(map);
|
|
401
|
+
const { url, data } = options;
|
|
402
|
+
if (data) {
|
|
403
|
+
this.blob = URL.createObjectURL(new Blob([data], { type: 'model/gltf-binary' }));
|
|
404
|
+
this.url = this.blob;
|
|
405
|
+
}
|
|
406
|
+
else if (url) {
|
|
407
|
+
// Against the page: the decoding workers fetch it, and a relative URL would be theirs
|
|
408
|
+
const base = typeof document === 'undefined' ? undefined : document.baseURI;
|
|
409
|
+
this.url = base ? new URL(url, base).href : url;
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
throw new Error('isard: a model needs a url or data');
|
|
413
|
+
}
|
|
414
|
+
this.instances = instanceNumbers(options.instances);
|
|
415
|
+
this.ground = options.altitudeReference !== 'sea';
|
|
416
|
+
}
|
|
417
|
+
/** @internal The engine with 3D Tiles decodes and draws the models */
|
|
418
|
+
get needsFullEngine() {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
/** Replaces the instances (and what their altitudes are above, kept if not given) */
|
|
422
|
+
setInstances(instances, altitudeReference) {
|
|
423
|
+
this.instances = instanceNumbers(instances);
|
|
424
|
+
if (altitudeReference)
|
|
425
|
+
this.ground = altitudeReference === 'ground';
|
|
426
|
+
// Kept for its creation while the engine with 3D Tiles loads
|
|
427
|
+
if (this.id < 0)
|
|
428
|
+
return;
|
|
429
|
+
this.map.engine.setModelInstances(this.id, this.instances, this.ground);
|
|
430
|
+
this.map.requestRender();
|
|
431
|
+
}
|
|
432
|
+
remove() {
|
|
433
|
+
super.remove();
|
|
434
|
+
this.dispose();
|
|
435
|
+
}
|
|
436
|
+
/** @internal */
|
|
437
|
+
dispose() {
|
|
438
|
+
if (this.blob)
|
|
439
|
+
URL.revokeObjectURL(this.blob);
|
|
440
|
+
}
|
|
441
|
+
/** @internal */
|
|
442
|
+
create(engine) {
|
|
443
|
+
return engine.addModels(this.url, this.instances, this.ground);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
285
446
|
//# sourceMappingURL=layers.js.map
|
package/dist/layers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAY5D,MAAM,OAAgB,KAAK;IACzB,GAAG,GAAG,CAAC,CAAC,CAAC;IAET,gBAAgB;IACG,GAAG,CAAY;IAElC,gBAAgB;IAChB,YAAY,GAAc;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,oCAAoC;IACpC,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,wGAAwG;IACxG,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACd,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,sGAAsG;IACtG,YAAY;QACV,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,+FAA+F;IAC/F,MAAM,CAAC,OAAe,IAAS,CAAC;IAKhC,MAAM;QACJ,yEAAyE;QACzE,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACd,IAAI,CAAC,GAA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: after a WebGL context loss,\n * the map recreates its engine and every layer in order, with the same handle (its id is updated).\n */\nimport { parseColor, rampTexels, stops } from './features.ts';\nimport { mercatorX, mercatorY, toMercator } from './geo.ts';\nimport type {\n LayerHost,\n LonLat,\n NetworkOptions,\n NetworkStyle,\n RasterOptions,\n RasterStyle,\n Tiles3dStyle,\n} from './types.ts';\nimport type { Engine, NetworkStats, Tiles3dStats } from './wasm/isard.js';\n\nexport abstract class Layer {\n #id = -1;\n\n /** @internal */\n protected readonly map: LayerHost;\n\n /** @internal */\n constructor(map: LayerHost) {\n this.map = map;\n }\n\n /** Id of the layer in the engine */\n get id(): number {\n return this.#id;\n }\n\n /** @internal Creates the layer in an engine (again after a context loss); its id is -1 if that fails */\n attach(engine: Engine): void {\n this.#id = -1;\n this.#id = this.create(engine);\n }\n\n /** @internal Forgets its id in an engine that is gone (before the layers are created in a new one) */\n forgetEngine(): void {\n this.#id = -1;\n }\n\n /** @internal Sends what refers to other layers, once every layer of a new engine has its id */\n relink(_engine: Engine): void {}\n\n /** @internal */\n protected abstract create(engine: Engine): number;\n\n remove(): void {\n // Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles\n if (this.#id >= 0) this.map.engine.removeLayer(this.#id);\n this.#id = -1;\n this.map.detach(this);\n this.map.requestRender();\n }\n\n /** Moves the layer under `other`, or on top of every layer (above the labels of a vector basemap too) */\n moveBefore(other: Layer | undefined): void {\n this.map.moveLayer(this, other);\n }\n}\n\n/** Raster tiles (basemaps, overlays) */\nexport class RasterLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: Required<Omit<RasterOptions, 'size' | 'loader' | 'grid' | 'attribution'>> & {\n size: number | undefined;\n loader: RasterOptions['loader'] | undefined;\n },\n ) {\n super(map);\n }\n\n /** Changes the opacity or saturation, the other kept */\n setStyle(style: Partial<RasterStyle>): void;\n /** @deprecated Positional form (saturation back to 1 when not given): `setStyle({ opacity, saturation })` */\n setStyle(opacity: number, saturation?: number): void;\n setStyle(style: Partial<RasterStyle> | number, saturation = 1): void {\n const changed = typeof style === 'number' ? { opacity: style, saturation } : style;\n this.options.opacity = changed.opacity ?? this.options.opacity;\n this.options.saturation = changed.saturation ?? this.options.saturation;\n this.map.engine.setRasterStyle(this.id, this.options.opacity, this.options.saturation);\n this.map.requestRender();\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { url, minZoom, maxZoom, opacity, saturation, size, loader } = this.options;\n return engine.addRaster(url, minZoom, maxZoom, opacity, saturation, size, loader);\n }\n}\n\n/** Line network colored by a value per node (travel time, water depth…) */\nexport class NetworkLayer extends Layer {\n private values: Float32Array | undefined;\n /** Node and line positions in Mercator, kept for a context loss: f32 offsets from an origin (exact to the centimetre\n * across a region, half the memory of f64) */\n private kept: { origin: [number, number]; nodes: Float32Array; lines: Float32Array | undefined } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private geometry: { nodes: Float64Array; edges: Uint32Array; lines: NetworkOptions['lines'] | undefined },\n private costs: Float32Array | undefined,\n private style: NetworkStyle,\n private edgeWidths: Float32Array | undefined,\n ) {\n super(map);\n }\n\n /** One value per node, in node order; negative (or 1e30 and above) = unreached. Costs one texture upload, drawn\n * next frame. */\n setValues(values: Float32Array): void {\n this.values = values;\n this.map.engine.setNetworkValues(this.id, values);\n this.map.requestRender();\n }\n\n /** Costs of the edges, A → B then B → A (see `NetworkOptions.costs`), when the way the network is travelled\n * changes; undefined: values interpolated along the edges. The geometry stays on the graphics card. */\n setCosts(costs: Float32Array | undefined): void {\n this.costs = costs;\n this.map.engine.setNetworkCosts(this.id, costs);\n this.map.requestRender();\n }\n\n setStyle(style: Partial<NetworkStyle>): void {\n const ramp = this.style.ramp;\n this.style = { ...this.style, ...style };\n this.map.engine.setNetworkStyle(this.id, networkStyle(this.style));\n if (this.style.ramp !== ramp)\n this.map.engine.setNetworkRamp(this.id, this.style.ramp && rampTexels(this.style.ramp).rgba);\n this.map.requestRender();\n }\n\n /** Width factor of each edge (undefined: 1 for all) */\n setEdgeWidths(widths: Float32Array | undefined): void {\n this.edgeWidths = widths;\n this.map.engine.setNetworkScales(this.id, widths);\n this.map.requestRender();\n }\n\n /** Pieces in all and drawn in the last frame */\n stats(): NetworkStats | undefined {\n return this.map.engine.networkStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { nodes, edges, lines } = this.geometry;\n let mercator: { nodes: Float64Array; lines: Float64Array | undefined };\n if (this.kept) {\n const { origin, nodes: n, lines: l } = this.kept;\n mercator = { nodes: unpack(n, origin), lines: l && unpack(l, origin) };\n } else {\n // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly\n mercator = { nodes: mercatorPoints(nodes), lines: lines && mercatorPoints(lines.points) };\n const origin: [number, number] = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];\n this.kept = {\n origin,\n nodes: pack(mercator.nodes, origin),\n lines: mercator.lines && pack(mercator.lines, origin),\n };\n // The degrees are not needed again: millions of points for a region\n this.geometry = { nodes: EMPTY, edges, lines: lines && { start: lines.start, points: EMPTY } };\n }\n const id = engine.addNetwork(\n mercator.nodes,\n edges,\n lines?.start,\n mercator.lines,\n this.costs,\n networkStyle(this.style),\n );\n if (this.style.ramp) engine.setNetworkRamp(id, rampTexels(this.style.ramp).rgba);\n if (this.edgeWidths) engine.setNetworkScales(id, this.edgeWidths);\n if (this.values) engine.setNetworkValues(id, this.values);\n return id;\n }\n}\n\n/** The 25 numbers of a network style for the engine */\nfunction networkStyle(style: NetworkStyle): Float32Array {\n const { width, halo, max, contour, opacity, haloOpacity, unreachedColor, fade } = style;\n return Float32Array.from([\n ...stops(width),\n ...stops(halo),\n max,\n contour,\n opacity,\n haloOpacity,\n ...parseColor(unreachedColor),\n fade,\n ]);\n}\n\nconst EMPTY = new Float64Array(0);\n\n/** Interleaved points as f32 offsets from an origin, and back */\nfunction pack(points: Float64Array, [ox, oy]: [number, number]): Float32Array {\n const out = new Float32Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) - ox;\n out[i + 1] = (points[i + 1] ?? 0) - oy;\n }\n return out;\n}\n\nfunction unpack(points: Float32Array, [ox, oy]: [number, number]): Float64Array {\n const out = new Float64Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) + ox;\n out[i + 1] = (points[i + 1] ?? 0) + oy;\n }\n return out;\n}\n\n/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */\nfunction mercatorPoints(lonLat: Float64Array): Float64Array {\n const out = new Float64Array(lonLat.length);\n for (let i = 0; i < lonLat.length; i += 2) {\n out[i] = mercatorX(lonLat[i] ?? 0);\n out[i + 1] = mercatorY(lonLat[i + 1] ?? 0);\n }\n return out;\n}\n\n/** Textured meshes in 3D Tiles */\nexport class Tiles3dLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly url: string,\n private style: Tiles3dStyle,\n ) {\n super(map);\n }\n\n setStyle(style: Partial<Tiles3dStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);\n this.map.requestRender();\n }\n\n /** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see\n * `GeoMapOptions.tiles3d`) */\n stats(): Tiles3dStats | undefined {\n return this.id < 0 ? undefined : this.map.engine.tiles3dStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addTiles3d(this.url, this.style.maxScreenSpaceError);\n engine.setTiles3dStyle(id, this.style.maxScreenSpaceError, this.style.opacity);\n return id;\n }\n}\n\n/** A texture of a ground layer (see `GroundLayer`) */\nexport interface GroundTexture {\n /** `r8`, `r8ui`, `r16ui`, `r16i`, `r32ui`, `r32f`, `rg16ui`, `rg32f`, `rgba8`, `rgba8ui`, `rgba16ui`, `rgba32f`:\n * integer formats are read with `usampler2D` / `isampler2D` and `texelFetch` */\n format: string;\n width: number;\n height: number;\n /** Layers of a 2D array (`sampler2DArray`, `usampler2DArray`…); 0 or undefined: a 2D texture */\n depth?: number;\n /** Linear filtering (non-integer formats); default nearest */\n linear?: boolean;\n /** Texels row after row (layer after layer), any typed array; undefined: left empty */\n data?: ArrayBufferView;\n}\n\nexport interface GroundOptions {\n /**\n * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at\n * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_CIRCUMFERENCE`: metres of EPSG:3857), exact to\n * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,\n * `u_pixel_ratio`\n */\n code: string;\n /** Where the offsets are taken from */\n anchor: LonLat;\n /** Box it shows in, `[west, south, east, north]` (default the world): only the ground there is drawn again */\n bounds?: [west: number, south: number, east: number, north: number];\n textures?: Record<string, GroundTexture>;\n uniforms?: Record<string, number | readonly number[]>;\n}\n\nconst bytesOf = (data: ArrayBufferView) => new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n\n/** The application's fragment shader run over the ground, draped on the relief (water depth, heat maps…) */\nexport class GroundLayer extends Layer {\n private readonly textures = new Map<string, GroundTexture>();\n private readonly uniforms = new Map<string, number[]>();\n private visible = true;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: GroundOptions,\n ) {\n super(map);\n for (const [name, texture] of Object.entries(options.textures ?? {})) this.textures.set(name, texture);\n for (const [name, value] of Object.entries(options.uniforms ?? {})) this.uniforms.set(name, [value].flat());\n }\n\n /** Creates or replaces a texture of the code's sampler `name` */\n setTexture(name: string, texture: GroundTexture): void {\n this.textures.set(name, texture);\n this.sendTexture(this.map.engine, this.id, name, texture);\n this.map.requestRender();\n }\n\n /**\n * Replaces a region of a texture: `data` holds `width` × `height` texels for (`x`, `y`) of `layer` (2D arrays).\n * Keep the texture's own `data` up to date too if it must survive a WebGL context loss.\n */\n updateTexture(\n name: string,\n data: ArrayBufferView,\n region: { x?: number; y?: number; layer?: number; width: number; height: number },\n ): void {\n const { x = 0, y = 0, layer = 0, width, height } = region;\n this.map.engine.updateGroundTexture(this.id, name, x, y, layer, width, height, bytesOf(data));\n this.map.requestRender();\n }\n\n /** A uniform of the code: a number, or numbers for vectors, arrays and matrices (column major) */\n setUniform(name: string, value: number | readonly number[]): void {\n const values = [value].flat();\n this.uniforms.set(name, values);\n this.map.engine.setGroundUniform(this.id, name, Float64Array.from(values));\n this.map.requestRender();\n }\n\n setBounds(bounds: [west: number, south: number, east: number, north: number]): void {\n this.options.bounds = bounds;\n this.map.engine.setGroundBounds(this.id, ...mercatorBox(bounds));\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.visible = visible;\n this.map.engine.setGroundVisible(this.id, visible);\n this.map.requestRender();\n }\n\n private sendTexture(engine: Engine, id: number, name: string, t: GroundTexture): void {\n const data = t.data && bytesOf(t.data);\n engine.setGroundTexture(id, name, t.format, t.width, t.height, t.depth ?? 0, t.linear ?? false, data);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const [ax, ay] = toMercator(this.options.anchor);\n const id = engine.addGround(\n this.options.code,\n ax,\n ay,\n ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]),\n );\n for (const [name, texture] of this.textures) this.sendTexture(engine, id, name, texture);\n for (const [name, values] of this.uniforms) engine.setGroundUniform(id, name, Float64Array.from(values));\n engine.setGroundVisible(id, this.visible);\n return id;\n }\n}\n\n/** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */\nfunction mercatorBox([west, south, east, north]: [number, number, number, number]): [number, number, number, number] {\n const [x0, y1] = toMercator([west, south]);\n const [x1, y0] = toMercator([east, north]);\n return [x0, y0, x1, y1];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EA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,CAAC;IACjE,CAAC;CACF","sourcesContent":["/**\n * Handles of the layers added to a map. Each one keeps what it needs to be created again: after a WebGL context loss,\n * the map recreates its engine and every layer in order, with the same handle (its id is updated). Also the page's\n * own 3D content: custom layers (its WebGL code called in every frame) and glTF models drawn at positions.\n */\nimport { parseColor, rampTexels, stops } from './features.ts';\nimport { mercatorX, mercatorY, toMercator } from './geo.ts';\nimport type { GeoMap } from './map.ts';\nimport type {\n LayerHost,\n LonLat,\n NetworkOptions,\n NetworkStyle,\n RasterOptions,\n RasterStyle,\n Tiles3dStyle,\n} from './types.ts';\nimport type { Camera, Engine, NetworkStats, Tiles3dStats } from './wasm/isard.js';\n\nexport abstract class Layer {\n #id = -1;\n\n /** @internal */\n protected readonly map: LayerHost;\n\n /** @internal */\n constructor(map: LayerHost) {\n this.map = map;\n }\n\n /** Id of the layer in the engine */\n get id(): number {\n return this.#id;\n }\n\n /** @internal Creates the layer in an engine (again after a context loss); its id is -1 if that fails */\n attach(engine: Engine): void {\n this.#id = -1;\n this.#id = this.create(engine);\n }\n\n /** @internal Forgets its id in an engine that is gone (before the layers are created in a new one) */\n forgetEngine(): void {\n this.#id = -1;\n }\n\n /** @internal Sends what refers to other layers, once every layer of a new engine has its id */\n relink(_engine: Engine): void {}\n\n /** @internal Drawn by the engine with 3D Tiles only (3D Tiles, models): on the core engine, it waits for that one */\n get needsFullEngine(): boolean {\n return false;\n }\n\n /** @internal The layer is removed or its map destroyed: frees what it holds outside the engine */\n dispose(): void {}\n\n /** @internal */\n protected abstract create(engine: Engine): number;\n\n remove(): void {\n // Not created yet: a 3D Tiles layer or a model waiting for the engine with 3D Tiles\n if (this.#id >= 0) this.map.engine.removeLayer(this.#id);\n this.#id = -1;\n this.map.detach(this);\n this.map.requestRender();\n }\n\n /** Moves the layer under `other`, or on top of every layer (above the labels of a vector basemap too) */\n moveBefore(other: Layer | undefined): void {\n this.map.moveLayer(this, other);\n }\n}\n\n/** Raster tiles (basemaps, overlays) */\nexport class RasterLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: Required<Omit<RasterOptions, 'size' | 'loader' | 'grid' | 'attribution'>> & {\n size: number | undefined;\n loader: RasterOptions['loader'] | undefined;\n },\n ) {\n super(map);\n }\n\n /** Changes the opacity or saturation, the other kept */\n setStyle(style: Partial<RasterStyle>): void;\n /** @deprecated Positional form (saturation back to 1 when not given): `setStyle({ opacity, saturation })` */\n setStyle(opacity: number, saturation?: number): void;\n setStyle(style: Partial<RasterStyle> | number, saturation = 1): void {\n const changed = typeof style === 'number' ? { opacity: style, saturation } : style;\n this.options.opacity = changed.opacity ?? this.options.opacity;\n this.options.saturation = changed.saturation ?? this.options.saturation;\n this.map.engine.setRasterStyle(this.id, this.options.opacity, this.options.saturation);\n this.map.requestRender();\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { url, minZoom, maxZoom, opacity, saturation, size, loader } = this.options;\n return engine.addRaster(url, minZoom, maxZoom, opacity, saturation, size, loader);\n }\n}\n\n/** Line network colored by a value per node (travel time, water depth…) */\nexport class NetworkLayer extends Layer {\n private values: Float32Array | undefined;\n /** Node and line positions in Mercator, kept for a context loss: f32 offsets from an origin (exact to the centimetre\n * across a region, half the memory of f64) */\n private kept: { origin: [number, number]; nodes: Float32Array; lines: Float32Array | undefined } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private geometry: { nodes: Float64Array; edges: Uint32Array; lines: NetworkOptions['lines'] | undefined },\n private costs: Float32Array | undefined,\n private style: NetworkStyle,\n private edgeWidths: Float32Array | undefined,\n ) {\n super(map);\n }\n\n /** One value per node, in node order; negative (or 1e30 and above) = unreached. Costs one texture upload, drawn\n * next frame. */\n setValues(values: Float32Array): void {\n this.values = values;\n this.map.engine.setNetworkValues(this.id, values);\n this.map.requestRender();\n }\n\n /** Costs of the edges, A → B then B → A (see `NetworkOptions.costs`), when the way the network is travelled\n * changes; undefined: values interpolated along the edges. The geometry stays on the graphics card. */\n setCosts(costs: Float32Array | undefined): void {\n this.costs = costs;\n this.map.engine.setNetworkCosts(this.id, costs);\n this.map.requestRender();\n }\n\n setStyle(style: Partial<NetworkStyle>): void {\n const ramp = this.style.ramp;\n this.style = { ...this.style, ...style };\n this.map.engine.setNetworkStyle(this.id, networkStyle(this.style));\n if (this.style.ramp !== ramp)\n this.map.engine.setNetworkRamp(this.id, this.style.ramp && rampTexels(this.style.ramp).rgba);\n this.map.requestRender();\n }\n\n /** Width factor of each edge (undefined: 1 for all) */\n setEdgeWidths(widths: Float32Array | undefined): void {\n this.edgeWidths = widths;\n this.map.engine.setNetworkScales(this.id, widths);\n this.map.requestRender();\n }\n\n /** Pieces in all and drawn in the last frame */\n stats(): NetworkStats | undefined {\n return this.map.engine.networkStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { nodes, edges, lines } = this.geometry;\n let mercator: { nodes: Float64Array; lines: Float64Array | undefined };\n if (this.kept) {\n const { origin, nodes: n, lines: l } = this.kept;\n mercator = { nodes: unpack(n, origin), lines: l && unpack(l, origin) };\n } else {\n // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly\n mercator = { nodes: mercatorPoints(nodes), lines: lines && mercatorPoints(lines.points) };\n const origin: [number, number] = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];\n this.kept = {\n origin,\n nodes: pack(mercator.nodes, origin),\n lines: mercator.lines && pack(mercator.lines, origin),\n };\n // The degrees are not needed again: millions of points for a region\n this.geometry = { nodes: EMPTY, edges, lines: lines && { start: lines.start, points: EMPTY } };\n }\n const id = engine.addNetwork(\n mercator.nodes,\n edges,\n lines?.start,\n mercator.lines,\n this.costs,\n networkStyle(this.style),\n );\n if (this.style.ramp) engine.setNetworkRamp(id, rampTexels(this.style.ramp).rgba);\n if (this.edgeWidths) engine.setNetworkScales(id, this.edgeWidths);\n if (this.values) engine.setNetworkValues(id, this.values);\n return id;\n }\n}\n\n/** The 25 numbers of a network style for the engine */\nfunction networkStyle(style: NetworkStyle): Float32Array {\n const { width, halo, max, contour, opacity, haloOpacity, unreachedColor, fade } = style;\n return Float32Array.from([\n ...stops(width),\n ...stops(halo),\n max,\n contour,\n opacity,\n haloOpacity,\n ...parseColor(unreachedColor),\n fade,\n ]);\n}\n\nconst EMPTY = new Float64Array(0);\n\n/** Interleaved points as f32 offsets from an origin, and back */\nfunction pack(points: Float64Array, [ox, oy]: [number, number]): Float32Array {\n const out = new Float32Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) - ox;\n out[i + 1] = (points[i + 1] ?? 0) - oy;\n }\n return out;\n}\n\nfunction unpack(points: Float32Array, [ox, oy]: [number, number]): Float64Array {\n const out = new Float64Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) + ox;\n out[i + 1] = (points[i + 1] ?? 0) + oy;\n }\n return out;\n}\n\n/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */\nfunction mercatorPoints(lonLat: Float64Array): Float64Array {\n const out = new Float64Array(lonLat.length);\n for (let i = 0; i < lonLat.length; i += 2) {\n out[i] = mercatorX(lonLat[i] ?? 0);\n out[i + 1] = mercatorY(lonLat[i + 1] ?? 0);\n }\n return out;\n}\n\n/** Textured meshes in 3D Tiles */\nexport class Tiles3dLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly url: string,\n private style: Tiles3dStyle,\n ) {\n super(map);\n }\n\n setStyle(style: Partial<Tiles3dStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);\n this.map.requestRender();\n }\n\n /** @internal */\n override get needsFullEngine(): boolean {\n return true;\n }\n\n /** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see\n * `GeoMapOptions.tiles3d`) */\n stats(): Tiles3dStats | undefined {\n return this.id < 0 ? undefined : this.map.engine.tiles3dStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addTiles3d(this.url, this.style.maxScreenSpaceError);\n engine.setTiles3dStyle(id, this.style.maxScreenSpaceError, this.style.opacity);\n return id;\n }\n}\n\n/** A texture of a ground layer (see `GroundLayer`) */\nexport interface GroundTexture {\n /** `r8`, `r8ui`, `r16ui`, `r16i`, `r32ui`, `r32f`, `rg16ui`, `rg32f`, `rgba8`, `rgba8ui`, `rgba16ui`, `rgba32f`:\n * integer formats are read with `usampler2D` / `isampler2D` and `texelFetch` */\n format: string;\n width: number;\n height: number;\n /** Layers of a 2D array (`sampler2DArray`, `usampler2DArray`…); 0 or undefined: a 2D texture */\n depth?: number;\n /** Linear filtering (non-integer formats); default nearest */\n linear?: boolean;\n /** Texels row after row (layer after layer), any typed array; undefined: left empty */\n data?: ArrayBufferView;\n}\n\nexport interface GroundOptions {\n /**\n * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at\n * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_CIRCUMFERENCE`: metres of EPSG:3857), exact to\n * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,\n * `u_pixel_ratio`\n */\n code: string;\n /** Where the offsets are taken from */\n anchor: LonLat;\n /** Box it shows in, `[west, south, east, north]` (default the world): only the ground there is drawn again */\n bounds?: [west: number, south: number, east: number, north: number];\n textures?: Record<string, GroundTexture>;\n uniforms?: Record<string, number | readonly number[]>;\n}\n\nconst bytesOf = (data: ArrayBufferView) => new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n\n/** The application's fragment shader run over the ground, draped on the relief (water depth, heat maps…) */\nexport class GroundLayer extends Layer {\n private readonly textures = new Map<string, GroundTexture>();\n private readonly uniforms = new Map<string, number[]>();\n private visible = true;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: GroundOptions,\n ) {\n super(map);\n for (const [name, texture] of Object.entries(options.textures ?? {})) this.textures.set(name, texture);\n for (const [name, value] of Object.entries(options.uniforms ?? {})) this.uniforms.set(name, [value].flat());\n }\n\n /** Creates or replaces a texture of the code's sampler `name` */\n setTexture(name: string, texture: GroundTexture): void {\n this.textures.set(name, texture);\n this.sendTexture(this.map.engine, this.id, name, texture);\n this.map.requestRender();\n }\n\n /**\n * Replaces a region of a texture: `data` holds `width` × `height` texels for (`x`, `y`) of `layer` (2D arrays).\n * Keep the texture's own `data` up to date too if it must survive a WebGL context loss.\n */\n updateTexture(\n name: string,\n data: ArrayBufferView,\n region: { x?: number; y?: number; layer?: number; width: number; height: number },\n ): void {\n const { x = 0, y = 0, layer = 0, width, height } = region;\n this.map.engine.updateGroundTexture(this.id, name, x, y, layer, width, height, bytesOf(data));\n this.map.requestRender();\n }\n\n /** A uniform of the code: a number, or numbers for vectors, arrays and matrices (column major) */\n setUniform(name: string, value: number | readonly number[]): void {\n const values = [value].flat();\n this.uniforms.set(name, values);\n this.map.engine.setGroundUniform(this.id, name, Float64Array.from(values));\n this.map.requestRender();\n }\n\n setBounds(bounds: [west: number, south: number, east: number, north: number]): void {\n this.options.bounds = bounds;\n this.map.engine.setGroundBounds(this.id, ...mercatorBox(bounds));\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.visible = visible;\n this.map.engine.setGroundVisible(this.id, visible);\n this.map.requestRender();\n }\n\n private sendTexture(engine: Engine, id: number, name: string, t: GroundTexture): void {\n const data = t.data && bytesOf(t.data);\n engine.setGroundTexture(id, name, t.format, t.width, t.height, t.depth ?? 0, t.linear ?? false, data);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const [ax, ay] = toMercator(this.options.anchor);\n const id = engine.addGround(\n this.options.code,\n ax,\n ay,\n ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]),\n );\n for (const [name, texture] of this.textures) this.sendTexture(engine, id, name, texture);\n for (const [name, values] of this.uniforms) engine.setGroundUniform(id, name, Float64Array.from(values));\n engine.setGroundVisible(id, this.visible);\n return id;\n }\n}\n\n/** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */\nfunction mercatorBox([west, south, east, north]: [number, number, number, number]): [number, number, number, number] {\n const [x0, y1] = toMercator([west, south]);\n const [x1, y0] = toMercator([east, north]);\n return [x0, y0, x1, y1];\n}\n\n// ── The page's own 3D content: custom layers, glTF models ──\n\n/** Reports an error of the page without throwing it here: the console shows it, as an uncaught one */\nfunction report(error: unknown): void {\n if (typeof reportError === 'function') reportError(error);\n else\n queueMicrotask(() => {\n throw error;\n });\n}\n\n/** What a custom layer gets to draw a frame (`CustomLayerInterface.render`) */\nexport interface CustomFrame {\n /**\n * The model-view-projection matrix of a local frame at a position and altitude (metres above the ellipsoid, as the\n * relief is drawn: times its exaggeration), column-major for `uniformMatrix4fv` or a three.js camera: x east, y\n * north, z up, in metres. Made in double precision relative to the camera, so that what is drawn stays exact at\n * any zoom; draw within a few kilometres of the position (or take one matrix per object far apart). Only during\n * `render`.\n */\n matrixAt(lonLat: LonLat, altitude?: number): Float32Array;\n /** The camera of the frame */\n readonly camera: Camera;\n}\n\n/**\n * A layer drawn by the page with its own WebGL code, as MapLibre's `CustomLayerInterface`: `render` is called at the\n * layer's place in every frame drawn. It starts with the canvas bound, its viewport set, blending on (`SRC_ALPHA`,\n * `ONE_MINUS_SRC_ALPHA`), no culling, and in `'3d'` mode the depth test on (`LEQUAL`, depth written): the relief, the\n * buildings and the 3D Tiles hide what it draws and what it draws hides them. Whatever WebGL state it changes is set\n * back afterwards; a library that caches the WebGL state (three.js) must forget it first (`renderer.resetState()`).\n *\n * The map is busy drawing meanwhile: `render` reads the frame, not the map (`getCamera` excepted); it may call\n * `requestRender` for an animation.\n */\nexport interface CustomLayerInterface {\n /** A name for the application (the map numbers its layers) */\n id?: string;\n /** `'2d'` (the default): drawn over what is under it; `'3d'`: with the depth buffer of the 3D layers */\n renderingMode?: '2d' | '3d';\n /** Creates the WebGL objects: once added, and again after the WebGL context was lost and restored */\n onAdd?(gl: WebGL2RenderingContext, map: GeoMap): void;\n render(gl: WebGL2RenderingContext, frame: CustomFrame): void;\n /** Frees the WebGL objects: the layer is removed, or the map destroyed */\n onRemove?(gl: WebGL2RenderingContext, map: GeoMap): void;\n}\n\n/** The model-view-projection of a local frame in the engine running the map (`Engine.customMatrix`) */\n/** @internal */\nexport type CustomMatrix = (lon: number, lat: number, altitude: number) => Float32Array | undefined;\n\n/** A layer drawn by the page's WebGL code (see `CustomLayerInterface`) */\nexport class CustomLayer extends Layer {\n /** The map's WebGL context, and whether `onAdd` made the layer's objects there (until `onRemove`) */\n private readonly gl: WebGL2RenderingContext;\n private added = false;\n /** The context was lost since `onAdd`: its objects are gone */\n private stale = false;\n private readonly lost = () => {\n this.stale = true;\n };\n private readonly frame: CustomFrame;\n\n /** @internal */\n constructor(\n map: LayerHost,\n /** The application's object */\n readonly implementation: CustomLayerInterface,\n private readonly canvas: HTMLCanvasElement,\n private readonly owner: GeoMap,\n matrix: CustomMatrix,\n camera: () => Camera,\n ) {\n super(map);\n // The context the engine made on the canvas\n this.gl = canvas.getContext('webgl2') as WebGL2RenderingContext;\n this.frame = {\n matrixAt: ([lon, lat], altitude = 0) => {\n const m = matrix(lon, lat, altitude);\n if (!m) throw new Error('isard: frame.matrixAt is only available during render');\n return m;\n },\n get camera() {\n return camera();\n },\n };\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n // Once, and again on a context restored (not when the map moves onto another engine: the same context)\n if (!this.added || this.stale) {\n if (!this.added) this.canvas.addEventListener('webglcontextlost', this.lost);\n this.added = true;\n this.stale = false;\n this.implementation.onAdd?.(this.gl, this.owner);\n }\n return engine.addCustomLayer(this.draw, this.implementation.renderingMode === '3d');\n }\n\n /** Called by the engine at the layer's place in the frame; the page's errors are reported, the frame goes on */\n private readonly draw = (): void => {\n try {\n this.implementation.render(this.gl, this.frame);\n } catch (error) {\n report(error);\n }\n };\n\n override remove(): void {\n super.remove();\n this.dispose();\n }\n\n /** @internal The layer is removed or the map destroyed: `onRemove`, unless the context is lost */\n override dispose(): void {\n if (!this.added) return;\n this.added = false;\n this.canvas.removeEventListener('webglcontextlost', this.lost);\n if (this.stale) return;\n try {\n this.implementation.onRemove?.(this.gl, this.owner);\n } catch (error) {\n report(error);\n }\n }\n}\n\n/** Where and how a model stands */\nexport interface ModelInstance {\n lonLat: LonLat;\n /** Metres above the ground (or above the ellipsoid, `altitudeReference: 'sea'`); 0 by default */\n altitude?: number;\n /** Degrees clockwise from the north of the model's front (glTF +Z); 0 by default */\n heading?: number;\n /** Degrees, nose up */\n pitch?: number;\n /** Degrees, right side down */\n roll?: number;\n /** 1 by default: the model's metres */\n scale?: number;\n}\n\nexport interface ModelOptions {\n /** URL of a glTF binary (`.glb`): meshes, textures, Draco, meshopt, KTX2, as in 3D Tiles; or its bytes (`data`) */\n url?: string;\n data?: ArrayBuffer | ArrayBufferView<ArrayBuffer>;\n instances: readonly ModelInstance[];\n /** What the altitudes are above: `'ground'` (the relief, the default) or `'sea'` (the ellipsoid) */\n altitudeReference?: 'ground' | 'sea';\n}\n\n/** The numbers of instances for the engine: longitude, latitude, altitude, heading, pitch, roll, scale */\nexport function instanceNumbers(instances: readonly ModelInstance[]): Float64Array {\n const out = new Float64Array(instances.length * 7);\n instances.forEach(({ lonLat, altitude = 0, heading = 0, pitch = 0, roll = 0, scale = 1 }, i) => {\n out.set([lonLat[0], lonLat[1], altitude, heading, pitch, roll, scale], i * 7);\n });\n return out;\n}\n\n/** A glTF model drawn at positions, in one instanced draw; `pickFeature` gives the instance's index */\nexport class ModelLayer extends Layer {\n private readonly url: string;\n /** The `blob:` URL of the page's bytes, revoked once the layer is gone */\n private readonly blob: string | undefined;\n private instances: Float64Array;\n private ground: boolean;\n\n /** @internal */\n constructor(map: LayerHost, options: ModelOptions) {\n super(map);\n const { url, data } = options;\n if (data) {\n this.blob = URL.createObjectURL(new Blob([data], { type: 'model/gltf-binary' }));\n this.url = this.blob;\n } else if (url) {\n // Against the page: the decoding workers fetch it, and a relative URL would be theirs\n const base = typeof document === 'undefined' ? undefined : document.baseURI;\n this.url = base ? new URL(url, base).href : url;\n } else {\n throw new Error('isard: a model needs a url or data');\n }\n this.instances = instanceNumbers(options.instances);\n this.ground = options.altitudeReference !== 'sea';\n }\n\n /** @internal The engine with 3D Tiles decodes and draws the models */\n override get needsFullEngine(): boolean {\n return true;\n }\n\n /** Replaces the instances (and what their altitudes are above, kept if not given) */\n setInstances(instances: readonly ModelInstance[], altitudeReference?: 'ground' | 'sea'): void {\n this.instances = instanceNumbers(instances);\n if (altitudeReference) this.ground = altitudeReference === 'ground';\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.map.engine.setModelInstances(this.id, this.instances, this.ground);\n this.map.requestRender();\n }\n\n override remove(): void {\n super.remove();\n this.dispose();\n }\n\n /** @internal */\n override dispose(): void {\n if (this.blob) URL.revokeObjectURL(this.blob);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n return engine.addModels(this.url, this.instances, this.ground);\n }\n}\n"]}
|
package/dist/map.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Control, type ControlPosition } from './controls.ts';
|
|
2
2
|
import { ExtrusionLayer, type ExtrusionOptions } from './extrusions.ts';
|
|
3
3
|
import { CircleLayer, type CircleOptions, FillLayer, type FillOptions, LineLayer, type LineOptions } from './features.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { type ImageOptions, type Pixels } from './icons.ts';
|
|
5
|
+
import { CustomLayer, type CustomLayerInterface, GroundLayer, type GroundOptions, type Layer, ModelLayer, type ModelOptions, NetworkLayer, RasterLayer, Tiles3dLayer } from './layers.ts';
|
|
5
6
|
import { SymbolLayer, type SymbolOptions } from './symbols.ts';
|
|
6
7
|
import type { AnimationOptions, AtmosphereOptions, Basemap, FeatureHit, FlyToOptions, GeoMapOptions, LoadingMode, LonLat, MapEvents, NetworkOptions, Point, Projection, RasterOptions, TerrainModel, TerrainOptions, Tiles3dOptions } from './types.ts';
|
|
7
8
|
import { VectorTiles, type VectorTilesOptions } from './vectortiles.ts';
|
|
@@ -72,6 +73,8 @@ export declare class GeoMap {
|
|
|
72
73
|
/** The last frame found everything loaded ('idle' sent) */
|
|
73
74
|
private settled;
|
|
74
75
|
private inFrame;
|
|
76
|
+
/** The camera of the frame being drawn: what `getCamera` gives the custom layers while the engine is busy */
|
|
77
|
+
private frameCamera;
|
|
75
78
|
/** Vector tiles made by `vectorTiles()`, destroyed with the map */
|
|
76
79
|
private readonly vectorSets;
|
|
77
80
|
/** The workers drawing vector tiles, shared by every `VectorTiles` of the map; created on first use */
|
|
@@ -92,8 +95,8 @@ export declare class GeoMap {
|
|
|
92
95
|
private createEngine;
|
|
93
96
|
/** The decoding workers of 3D Tiles, with the engine that has them (they run its module) and unless turned off */
|
|
94
97
|
private startLoader;
|
|
95
|
-
/** A 3D Tiles layer on the core engine: loads the engine with 3D Tiles, then rebuilds the map on it
|
|
96
|
-
* settings and layers kept, as after a context loss); the layer is created then */
|
|
98
|
+
/** A 3D Tiles layer or a model on the core engine: loads the engine with 3D Tiles, then rebuilds the map on it
|
|
99
|
+
* (camera, settings and layers kept, as after a context loss); the layer is created then */
|
|
97
100
|
private upgrade;
|
|
98
101
|
/** Downloads and compiles the engine with 3D Tiles once the map is idle (`tiles3d: 'preload'`), without running
|
|
99
102
|
* it: the first 3D Tiles layer then only instantiates it */
|
|
@@ -193,6 +196,18 @@ export declare class GeoMap {
|
|
|
193
196
|
addExtrusions<P = Record<string, unknown>>(options?: ExtrusionOptions<P>): ExtrusionLayer<P>;
|
|
194
197
|
/** Text labels from GeoJSON (points, the middle of lines, the center of polygons), placed without overlaps */
|
|
195
198
|
addSymbols<P = Record<string, unknown>>(options: SymbolOptions<P>): SymbolLayer<P>;
|
|
199
|
+
/**
|
|
200
|
+
* An image for the symbol layers' icons (`icon: name`), as MapLibre's `addImage`: its pixels (an image, a canvas,
|
|
201
|
+
* `ImageData`, or RGBA bytes with their size), `pixelRatio` 2 for an image drawn at twice its CSS size; `sdf` for a
|
|
202
|
+
* signed distance field drawn in the `iconColor`; `stretchX`, `stretchY` and `content` for an icon stretched around its
|
|
203
|
+
* text. An image of the same name is replaced
|
|
204
|
+
*/
|
|
205
|
+
addImage(name: string, image: Pixels | (CanvasImageSource & {
|
|
206
|
+
width: number;
|
|
207
|
+
height: number;
|
|
208
|
+
}), options?: ImageOptions): void;
|
|
209
|
+
hasImage(name: string): boolean;
|
|
210
|
+
removeImage(name: string): void;
|
|
196
211
|
/**
|
|
197
212
|
* Vector tiles with a MapLibre style (OpenFreeMap's Positron by default): `tiles.raster(…)` draws its fills and lines
|
|
198
213
|
* (or a subset) as a raster layer, `tiles.labels(…)` its labels. `setBasemap('osm-positron')` does both for the
|
|
@@ -212,6 +227,17 @@ export declare class GeoMap {
|
|
|
212
227
|
private place;
|
|
213
228
|
/** Textured meshes in 3D Tiles (photogrammetry, buildings), drawn with depth over the basemap */
|
|
214
229
|
addTiles3d(options: Tiles3dOptions): Tiles3dLayer;
|
|
230
|
+
/** A glTF model drawn at positions (see `ModelOptions`), with depth; on the engine with 3D Tiles, as they are */
|
|
231
|
+
addModels(options: ModelOptions & {
|
|
232
|
+
before?: Layer;
|
|
233
|
+
}): ModelLayer;
|
|
234
|
+
/**
|
|
235
|
+
* The page's own WebGL drawing at its place among the layers, in every frame (see `CustomLayerInterface`): raw
|
|
236
|
+
* WebGL, three.js… with the matrices of the frame (`frame.matrixAt`); under `before` if given
|
|
237
|
+
*/
|
|
238
|
+
addCustomLayer(layer: CustomLayerInterface, options?: {
|
|
239
|
+
before?: Layer;
|
|
240
|
+
}): CustomLayer;
|
|
215
241
|
/** Asks for a frame; several calls before the next frame draw it once */
|
|
216
242
|
requestRender(): void;
|
|
217
243
|
private frame;
|
package/dist/map.js
CHANGED
|
@@ -12,8 +12,9 @@ import { ExtrusionLayer, extrusionStyle } from "./extrusions.js";
|
|
|
12
12
|
import { CircleLayer, circleStyle, FillLayer, fillStyle, LineLayer, lineStyle, } from "./features.js";
|
|
13
13
|
import { Glyphs } from "./glyphs.js";
|
|
14
14
|
import { equirectangularGrid, gridLoader, gridZooms, resolveGrid } from "./grid.js";
|
|
15
|
+
import { Icons, readPixels } from "./icons.js";
|
|
15
16
|
import { Interaction } from "./interaction.js";
|
|
16
|
-
import { GroundLayer, NetworkLayer, RasterLayer, Tiles3dLayer } from "./layers.js";
|
|
17
|
+
import { CustomLayer, GroundLayer, ModelLayer, NetworkLayer, RasterLayer, Tiles3dLayer, } from "./layers.js";
|
|
17
18
|
import { atmosphereSettings, bodySettings, haloSettings, rgb, terrainSettings, } from "./settings.js";
|
|
18
19
|
import { injectStyle } from "./style.js";
|
|
19
20
|
import { SymbolLayer, symbolStyle } from "./symbols.js";
|
|
@@ -56,6 +57,7 @@ function checkBasemap(basemap) {
|
|
|
56
57
|
export class GeoMap {
|
|
57
58
|
canvas;
|
|
58
59
|
#glyphs;
|
|
60
|
+
#icons;
|
|
59
61
|
/** Layers new layers go under */
|
|
60
62
|
onTop = new Set();
|
|
61
63
|
/** The vector basemap, if any: its tiles' workers and its labels */
|
|
@@ -127,6 +129,8 @@ export class GeoMap {
|
|
|
127
129
|
/** The last frame found everything loaded ('idle' sent) */
|
|
128
130
|
settled = false;
|
|
129
131
|
inFrame = false;
|
|
132
|
+
/** The camera of the frame being drawn: what `getCamera` gives the custom layers while the engine is busy */
|
|
133
|
+
frameCamera;
|
|
130
134
|
/** Vector tiles made by `vectorTiles()`, destroyed with the map */
|
|
131
135
|
vectorSets = new Set();
|
|
132
136
|
/** The workers drawing vector tiles, shared by every `VectorTiles` of the map; created on first use */
|
|
@@ -270,8 +274,8 @@ export class GeoMap {
|
|
|
270
274
|
startLoader(engine) {
|
|
271
275
|
return this.tiles3dModule && startTileLoader(this.tiles3dModule, this.tiles3dOptions, engine);
|
|
272
276
|
}
|
|
273
|
-
/** A 3D Tiles layer on the core engine: loads the engine with 3D Tiles, then rebuilds the map on it
|
|
274
|
-
* settings and layers kept, as after a context loss); the layer is created then */
|
|
277
|
+
/** A 3D Tiles layer or a model on the core engine: loads the engine with 3D Tiles, then rebuilds the map on it
|
|
278
|
+
* (camera, settings and layers kept, as after a context loss); the layer is created then */
|
|
275
279
|
upgrade() {
|
|
276
280
|
this.upgrading ??= loadFullEngineLater(engineUrl('full', this.tiles3dOptions)).then(({ module, Engine }) => {
|
|
277
281
|
this.upgrading = undefined;
|
|
@@ -316,13 +320,14 @@ export class GeoMap {
|
|
|
316
320
|
this.lost = false;
|
|
317
321
|
this.setCamera(camera);
|
|
318
322
|
this.#glyphs?.attach(this.#engine);
|
|
323
|
+
this.#icons?.attach(this.#engine);
|
|
319
324
|
const engine = this.#engine;
|
|
320
325
|
// No layer refers to an id of the old engine while the others are created
|
|
321
326
|
for (const layer of this.layers)
|
|
322
327
|
layer.forgetEngine();
|
|
323
328
|
for (const layer of this.layers) {
|
|
324
329
|
// Still waiting for the engine with 3D Tiles (loading, or failed): created with it
|
|
325
|
-
if (layer
|
|
330
|
+
if (layer.needsFullEngine && !this.tiles3dModule)
|
|
326
331
|
continue;
|
|
327
332
|
// A layer that fails is reported and left out; the others are created
|
|
328
333
|
try {
|
|
@@ -363,8 +368,9 @@ export class GeoMap {
|
|
|
363
368
|
this.layers.splice(index, 1);
|
|
364
369
|
}
|
|
365
370
|
add(layer) {
|
|
366
|
-
// On the core engine, a 3D Tiles layer waits for the engine with 3D Tiles: it is created with the
|
|
367
|
-
|
|
371
|
+
// On the core engine, a 3D Tiles layer or a model waits for the engine with 3D Tiles: it is created with the
|
|
372
|
+
// others on it
|
|
373
|
+
if (layer.needsFullEngine && !this.tiles3dModule)
|
|
368
374
|
this.upgrade();
|
|
369
375
|
else
|
|
370
376
|
layer.attach(this.engine);
|
|
@@ -433,7 +439,7 @@ export class GeoMap {
|
|
|
433
439
|
}
|
|
434
440
|
// ── Camera ──
|
|
435
441
|
getCamera() {
|
|
436
|
-
return this.engine.camera();
|
|
442
|
+
return this.frameCamera ?? this.engine.camera();
|
|
437
443
|
}
|
|
438
444
|
setCamera(camera) {
|
|
439
445
|
const c = { ...this.getCamera(), ...camera };
|
|
@@ -758,6 +764,34 @@ export class GeoMap {
|
|
|
758
764
|
}
|
|
759
765
|
return this.#glyphs;
|
|
760
766
|
}
|
|
767
|
+
/** @internal The icons of the symbol layers: the application's images and the vector basemaps' sprites */
|
|
768
|
+
get icons() {
|
|
769
|
+
if (!this.#icons) {
|
|
770
|
+
const gl = this.canvas.getContext('webgl2');
|
|
771
|
+
const max = gl?.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
772
|
+
this.#icons = new Icons(typeof max === 'number' ? max : undefined);
|
|
773
|
+
this.#icons.attach(this.engine);
|
|
774
|
+
}
|
|
775
|
+
return this.#icons;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* An image for the symbol layers' icons (`icon: name`), as MapLibre's `addImage`: its pixels (an image, a canvas,
|
|
779
|
+
* `ImageData`, or RGBA bytes with their size), `pixelRatio` 2 for an image drawn at twice its CSS size; `sdf` for a
|
|
780
|
+
* signed distance field drawn in the `iconColor`; `stretchX`, `stretchY` and `content` for an icon stretched around its
|
|
781
|
+
* text. An image of the same name is replaced
|
|
782
|
+
*/
|
|
783
|
+
addImage(name, image, options = {}) {
|
|
784
|
+
const pixels = 'data' in image ? image : readPixels(image);
|
|
785
|
+
if (!pixels)
|
|
786
|
+
throw new Error(`isard: the image ${name} has no pixels`);
|
|
787
|
+
this.icons.add(name, pixels, options);
|
|
788
|
+
}
|
|
789
|
+
hasImage(name) {
|
|
790
|
+
return this.#icons?.has(name) ?? false;
|
|
791
|
+
}
|
|
792
|
+
removeImage(name) {
|
|
793
|
+
this.#icons?.remove(name);
|
|
794
|
+
}
|
|
761
795
|
/**
|
|
762
796
|
* Vector tiles with a MapLibre style (OpenFreeMap's Positron by default): `tiles.raster(…)` draws its fills and lines
|
|
763
797
|
* (or a subset) as a raster layer, `tiles.labels(…)` its labels. `setBasemap('osm-positron')` does both for the
|
|
@@ -827,6 +861,18 @@ export class GeoMap {
|
|
|
827
861
|
const { url, maxScreenSpaceError = 16, opacity = 1 } = options;
|
|
828
862
|
return this.add(new Tiles3dLayer(this, url, { maxScreenSpaceError, opacity }));
|
|
829
863
|
}
|
|
864
|
+
/** A glTF model drawn at positions (see `ModelOptions`), with depth; on the engine with 3D Tiles, as they are */
|
|
865
|
+
addModels(options) {
|
|
866
|
+
return this.place(new ModelLayer(this, options), options.before);
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* The page's own WebGL drawing at its place among the layers, in every frame (see `CustomLayerInterface`): raw
|
|
870
|
+
* WebGL, three.js… with the matrices of the frame (`frame.matrixAt`); under `before` if given
|
|
871
|
+
*/
|
|
872
|
+
addCustomLayer(layer, options = {}) {
|
|
873
|
+
const custom = new CustomLayer(this, layer, this.canvas, this, (lon, lat, altitude) => this.engineClass.customMatrix(lon, lat, altitude), () => this.getCamera());
|
|
874
|
+
return this.place(custom, options.before);
|
|
875
|
+
}
|
|
830
876
|
// ── Frames ──
|
|
831
877
|
/** Asks for a frame; several calls before the next frame draw it once */
|
|
832
878
|
requestRender() {
|
|
@@ -899,7 +945,15 @@ export class GeoMap {
|
|
|
899
945
|
const t0 = performance.now();
|
|
900
946
|
// The engine asks for the next frame while it draws (uploads past the frame budget, fades): not ignored
|
|
901
947
|
this.inFrame = false;
|
|
902
|
-
|
|
948
|
+
// As the engine has it now (a listener may have moved it), for the custom layers drawn in the frame
|
|
949
|
+
this.frameCamera = this.layers.some((layer) => layer instanceof CustomLayer) ? this.engine.camera() : undefined;
|
|
950
|
+
let loading;
|
|
951
|
+
try {
|
|
952
|
+
loading = this.engine.render();
|
|
953
|
+
}
|
|
954
|
+
finally {
|
|
955
|
+
this.frameCamera = undefined;
|
|
956
|
+
}
|
|
903
957
|
this.inFrame = true;
|
|
904
958
|
// The picking pass sees the frame just drawn; its answer comes on a later frame
|
|
905
959
|
if (hovered && this.listeners.hoverfeature.size > 0)
|
|
@@ -970,12 +1024,16 @@ export class GeoMap {
|
|
|
970
1024
|
this.resizeObserver.disconnect();
|
|
971
1025
|
this.interaction?.destroy();
|
|
972
1026
|
this.loader?.destroy();
|
|
1027
|
+
// Custom layers free their WebGL objects, models their data, while the context is there
|
|
1028
|
+
for (const layer of this.layers)
|
|
1029
|
+
layer.dispose();
|
|
973
1030
|
this.engine.free();
|
|
974
1031
|
// Work still under way (labels being shaped, tiles arriving, timers) may call the engine after this: it finds one
|
|
975
1032
|
// that does nothing, and nothing is drawn again
|
|
976
1033
|
this.#engine = destroyedEngine(camera);
|
|
977
1034
|
// Glyph ranges still arriving upload to it, not to the freed engine
|
|
978
1035
|
this.#glyphs?.attach(this.#engine);
|
|
1036
|
+
this.#icons?.attach(this.#engine);
|
|
979
1037
|
this.lost = true;
|
|
980
1038
|
for (const control of [...this.controls.keys()])
|
|
981
1039
|
this.removeControl(control);
|