isard 0.2.1 → 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 +93 -0
- package/README.md +8 -4
- package/dist/animation.d.ts +18 -0
- package/dist/animation.js +84 -0
- package/dist/animation.js.map +1 -0
- package/dist/basemap.worker.d.ts +26 -4
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +9 -5
- package/dist/crs.d.ts +72 -0
- package/dist/crs.js +243 -0
- package/dist/crs.js.map +1 -0
- package/dist/decoder.worker.js +4 -4
- package/dist/decoder.worker.js.map +4 -4
- package/dist/engine-loader.d.ts +28 -0
- package/dist/engine-loader.js +112 -0
- package/dist/engine-loader.js.map +1 -0
- package/dist/features.d.ts +8 -0
- package/dist/features.js +17 -10
- package/dist/features.js.map +1 -1
- package/dist/geo.d.ts +16 -0
- package/dist/geo.js +32 -0
- package/dist/geo.js.map +1 -0
- package/dist/geoplateforme.d.ts +21 -5
- package/dist/geoplateforme.js +47 -12
- package/dist/geoplateforme.js.map +1 -1
- package/dist/glyphs.d.ts +13 -3
- package/dist/glyphs.js +26 -4
- package/dist/glyphs.js.map +1 -1
- package/dist/gpx.d.ts +11 -0
- package/dist/gpx.js +74 -0
- package/dist/gpx.js.map +1 -0
- package/dist/grid.d.ts +81 -0
- package/dist/grid.js +270 -0
- package/dist/grid.js.map +1 -0
- 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 +11 -4
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +0 -4
- package/dist/interaction.js +8 -4
- package/dist/interaction.js.map +1 -1
- package/dist/isard_bg.wasm +0 -0
- package/dist/isard_core_bg.wasm +0 -0
- package/dist/kml.d.ts +12 -0
- package/dist/kml.js +159 -0
- package/dist/kml.js.map +1 -0
- package/dist/layers.d.ts +89 -2
- package/dist/layers.js +171 -15
- package/dist/layers.js.map +1 -1
- package/dist/lru.d.ts +22 -0
- package/dist/lru.js +52 -0
- package/dist/lru.js.map +1 -0
- package/dist/map.d.ts +45 -7
- package/dist/map.js +138 -310
- package/dist/map.js.map +1 -1
- package/dist/resample.d.ts +41 -0
- package/dist/resample.js +164 -0
- package/dist/resample.js.map +1 -0
- package/dist/settings.d.ts +39 -0
- package/dist/settings.js +104 -0
- package/dist/settings.js.map +1 -0
- package/dist/symbols.d.ts +54 -9
- package/dist/symbols.js +278 -55
- package/dist/symbols.js.map +1 -1
- package/dist/terrain.d.ts +19 -7
- package/dist/terrain.js +40 -28
- package/dist/terrain.js.map +1 -1
- package/dist/topojson.d.ts +29 -0
- package/dist/topojson.js +66 -0
- package/dist/topojson.js.map +1 -0
- package/dist/types.d.ts +14 -6
- 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 +19 -7
- package/dist/vectortiles.js +117 -69
- package/dist/vectortiles.js.map +1 -1
- package/dist/wasm/isard.d.ts +55 -7
- package/dist/wasm/isard.js +117 -6
- package/dist/wasm/isard_core.d.ts +29 -4
- package/dist/wasm/isard_core.js +84 -5
- package/dist/wmts.d.ts +14 -0
- package/dist/wmts.js +76 -0
- package/dist/wmts.js.map +1 -0
- package/dist/xml.d.ts +26 -0
- package/dist/xml.js +109 -0
- package/dist/xml.js.map +1 -0
- package/package.json +1 -1
- package/dist/equirectangular.d.ts +0 -35
- package/dist/equirectangular.js +0 -143
- package/dist/equirectangular.js.map +0 -1
package/dist/layers.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
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";
|
|
7
|
+
import { mercatorX, mercatorY, toMercator } from "./geo.js";
|
|
6
8
|
export class Layer {
|
|
7
9
|
#id = -1;
|
|
8
10
|
/** @internal */
|
|
@@ -26,8 +28,14 @@ export class Layer {
|
|
|
26
28
|
}
|
|
27
29
|
/** @internal Sends what refers to other layers, once every layer of a new engine has its id */
|
|
28
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() { }
|
|
29
37
|
remove() {
|
|
30
|
-
// 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
|
|
31
39
|
if (this.#id >= 0)
|
|
32
40
|
this.map.engine.removeLayer(this.#id);
|
|
33
41
|
this.#id = -1;
|
|
@@ -120,7 +128,7 @@ export class NetworkLayer extends Layer {
|
|
|
120
128
|
}
|
|
121
129
|
else {
|
|
122
130
|
// Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly
|
|
123
|
-
mercator = { nodes:
|
|
131
|
+
mercator = { nodes: mercatorPoints(nodes), lines: lines && mercatorPoints(lines.points) };
|
|
124
132
|
const origin = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];
|
|
125
133
|
this.kept = {
|
|
126
134
|
origin,
|
|
@@ -172,14 +180,12 @@ function unpack(points, [ox, oy]) {
|
|
|
172
180
|
}
|
|
173
181
|
return out;
|
|
174
182
|
}
|
|
175
|
-
const MAX_LAT = 85.051128779806589;
|
|
176
183
|
/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */
|
|
177
|
-
function
|
|
184
|
+
function mercatorPoints(lonLat) {
|
|
178
185
|
const out = new Float64Array(lonLat.length);
|
|
179
186
|
for (let i = 0; i < lonLat.length; i += 2) {
|
|
180
|
-
|
|
181
|
-
out[i] = (
|
|
182
|
-
out[i + 1] = 0.5 - Math.log(Math.tan(Math.PI / 4 + lat / 2)) / (2 * Math.PI);
|
|
187
|
+
out[i] = mercatorX(lonLat[i] ?? 0);
|
|
188
|
+
out[i + 1] = mercatorY(lonLat[i + 1] ?? 0);
|
|
183
189
|
}
|
|
184
190
|
return out;
|
|
185
191
|
}
|
|
@@ -201,6 +207,10 @@ export class Tiles3dLayer extends Layer {
|
|
|
201
207
|
this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);
|
|
202
208
|
this.map.requestRender();
|
|
203
209
|
}
|
|
210
|
+
/** @internal */
|
|
211
|
+
get needsFullEngine() {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
204
214
|
/** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see
|
|
205
215
|
* `GeoMapOptions.tiles3d`) */
|
|
206
216
|
stats() {
|
|
@@ -267,7 +277,7 @@ export class GroundLayer extends Layer {
|
|
|
267
277
|
}
|
|
268
278
|
/** @internal */
|
|
269
279
|
create(engine) {
|
|
270
|
-
const [ax, ay] =
|
|
280
|
+
const [ax, ay] = toMercator(this.options.anchor);
|
|
271
281
|
const id = engine.addGround(this.options.code, ax, ay, ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]));
|
|
272
282
|
for (const [name, texture] of this.textures)
|
|
273
283
|
this.sendTexture(engine, id, name, texture);
|
|
@@ -277,14 +287,160 @@ export class GroundLayer extends Layer {
|
|
|
277
287
|
return id;
|
|
278
288
|
}
|
|
279
289
|
}
|
|
280
|
-
function mercatorPoint([lon, lat]) {
|
|
281
|
-
const out = toMercator(Float64Array.of(lon, lat));
|
|
282
|
-
return [out[0] ?? 0, out[1] ?? 0];
|
|
283
|
-
}
|
|
284
290
|
/** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */
|
|
285
291
|
function mercatorBox([west, south, east, north]) {
|
|
286
|
-
const [x0, y1] =
|
|
287
|
-
const [x1, y0] =
|
|
292
|
+
const [x0, y1] = toMercator([west, south]);
|
|
293
|
+
const [x1, y0] = toMercator([east, north]);
|
|
288
294
|
return [x0, y0, x1, y1];
|
|
289
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
|
+
}
|
|
290
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;AAY9D,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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I,CAAC,MAAM,CAAC,CAAC,CAAC;QACzG,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAED,SAAS,aAAa,CAAC,CAAC,GAAG,EAAE,GAAG,CAAS;IACvC,MAAM,GAAG,GAAG,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,iFAAiF;AACjF,SAAS,WAAW,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAmC;IAC/E,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,CAAC","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).\n */\nimport { parseColor, rampTexels, stops } from './features.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: toMercator(nodes), lines: lines && toMercator(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\nconst MAX_LAT = 85.051128779806589;\n\n/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */\nfunction toMercator(lonLat: Float64Array): Float64Array {\n const out = new Float64Array(lonLat.length);\n for (let i = 0; i < lonLat.length; i += 2) {\n const lat = (Math.max(-MAX_LAT, Math.min(MAX_LAT, lonLat[i + 1] ?? 0)) * Math.PI) / 180;\n out[i] = ((lonLat[i] ?? 0) + 180) / 360;\n out[i + 1] = 0.5 - Math.log(Math.tan(Math.PI / 4 + lat / 2)) / (2 * Math.PI);\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_EARTH`: 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] = mercatorPoint(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\nfunction mercatorPoint([lon, lat]: LonLat): [number, number] {\n const out = toMercator(Float64Array.of(lon, lat));\n return [out[0] ?? 0, out[1] ?? 0];\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] = mercatorPoint([west, south]);\n const [x1, y0] = mercatorPoint([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,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAa5D,MAAM,OAAgB,KAAK;IACzB,GAAG,GAAG,CAAC,CAAC,CAAC;IAET,gBAAgB;IACG,GAAG,CAAY;IAElC,gBAAgB;IAChB,YAAY,GAAc;QACxB,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;QACD,IAAI,CAAC,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,iBAAiB,KAAK,KAAK,CAAC;IACpD,CAAC;IAED,sEAAsE;IACtE,IAAa,eAAe;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qFAAqF;IACrF,YAAY,CAAC,SAAmC,EAAE,iBAAoC;QACpF,IAAI,CAAC,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,iBAAiB;YAAE,IAAI,CAAC,MAAM,GAAG,iBAAiB,KAAK,QAAQ,CAAC;QACpE,6DAA6D;QAC7D,IAAI,IAAI,CAAC,EAAE,GAAG,CAAC;YAAE,OAAO;QACxB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACxE,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IAC3B,CAAC;IAEQ,MAAM;QACb,KAAK,CAAC,MAAM,EAAE,CAAC;QACf,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,gBAAgB;IACP,OAAO;QACd,IAAI,IAAI,CAAC,IAAI;YAAE,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,gBAAgB;IACN,MAAM,CAAC,MAAc;QAC7B,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,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/lru.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cache keeping its most recently used entries (the decoded tiles and images of the workers, the source tiles of a
|
|
3
|
+
* reprojection, the labels of the vector tiles): a `Map` in order of use, the least recent dropped past `capacity`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Lru<K, V> {
|
|
6
|
+
capacity: number;
|
|
7
|
+
private readonly evict?;
|
|
8
|
+
private readonly entries;
|
|
9
|
+
/** `evict`: told of each entry dropped for room (not of those deleted) */
|
|
10
|
+
constructor(capacity: number, evict?: ((value: V, key: K) => void) | undefined);
|
|
11
|
+
get size(): number;
|
|
12
|
+
/** The value of a key, now the most recently used; undefined if absent */
|
|
13
|
+
get(key: K): V | undefined;
|
|
14
|
+
/** Whether a key is kept, without using it */
|
|
15
|
+
has(key: K): boolean;
|
|
16
|
+
/** Adds or replaces a value, the most recently used; drops the least recent ones past the capacity */
|
|
17
|
+
set(key: K, value: V): void;
|
|
18
|
+
delete(key: K): boolean;
|
|
19
|
+
/** The values, least recently used first */
|
|
20
|
+
values(): IterableIterator<V>;
|
|
21
|
+
clear(): void;
|
|
22
|
+
}
|
package/dist/lru.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cache keeping its most recently used entries (the decoded tiles and images of the workers, the source tiles of a
|
|
3
|
+
* reprojection, the labels of the vector tiles): a `Map` in order of use, the least recent dropped past `capacity`.
|
|
4
|
+
*/
|
|
5
|
+
export class Lru {
|
|
6
|
+
capacity;
|
|
7
|
+
evict;
|
|
8
|
+
entries = new Map();
|
|
9
|
+
/** `evict`: told of each entry dropped for room (not of those deleted) */
|
|
10
|
+
constructor(capacity, evict) {
|
|
11
|
+
this.capacity = capacity;
|
|
12
|
+
this.evict = evict;
|
|
13
|
+
}
|
|
14
|
+
get size() {
|
|
15
|
+
return this.entries.size;
|
|
16
|
+
}
|
|
17
|
+
/** The value of a key, now the most recently used; undefined if absent */
|
|
18
|
+
get(key) {
|
|
19
|
+
const value = this.entries.get(key);
|
|
20
|
+
if (value !== undefined) {
|
|
21
|
+
this.entries.delete(key);
|
|
22
|
+
this.entries.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
/** Whether a key is kept, without using it */
|
|
27
|
+
has(key) {
|
|
28
|
+
return this.entries.has(key);
|
|
29
|
+
}
|
|
30
|
+
/** Adds or replaces a value, the most recently used; drops the least recent ones past the capacity */
|
|
31
|
+
set(key, value) {
|
|
32
|
+
this.entries.delete(key);
|
|
33
|
+
this.entries.set(key, value);
|
|
34
|
+
for (const [oldest, old] of this.entries) {
|
|
35
|
+
if (this.entries.size <= this.capacity)
|
|
36
|
+
break;
|
|
37
|
+
this.entries.delete(oldest);
|
|
38
|
+
this.evict?.(old, oldest);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
delete(key) {
|
|
42
|
+
return this.entries.delete(key);
|
|
43
|
+
}
|
|
44
|
+
/** The values, least recently used first */
|
|
45
|
+
values() {
|
|
46
|
+
return this.entries.values();
|
|
47
|
+
}
|
|
48
|
+
clear() {
|
|
49
|
+
this.entries.clear();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=lru.js.map
|
package/dist/lru.js.map
ADDED
|
@@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CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,MAAM,CAAC,GAAM;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,4CAA4C;IAC5C,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF","sourcesContent":["/**\n * A cache keeping its most recently used entries (the decoded tiles and images of the workers, the source tiles of a\n * reprojection, the labels of the vector tiles): a `Map` in order of use, the least recent dropped past `capacity`.\n */\nexport class Lru<K, V> {\n private readonly entries = new Map<K, V>();\n\n /** `evict`: told of each entry dropped for room (not of those deleted) */\n constructor(\n public capacity: number,\n private readonly evict?: (value: V, key: K) => void,\n ) {}\n\n get size(): number {\n return this.entries.size;\n }\n\n /** The value of a key, now the most recently used; undefined if absent */\n get(key: K): V | undefined {\n const value = this.entries.get(key);\n if (value !== undefined) {\n this.entries.delete(key);\n this.entries.set(key, value);\n }\n return value;\n }\n\n /** Whether a key is kept, without using it */\n has(key: K): boolean {\n return this.entries.has(key);\n }\n\n /** Adds or replaces a value, the most recently used; drops the least recent ones past the capacity */\n set(key: K, value: V): void {\n this.entries.delete(key);\n this.entries.set(key, value);\n for (const [oldest, old] of this.entries) {\n if (this.entries.size <= this.capacity) break;\n this.entries.delete(oldest);\n this.evict?.(old, oldest);\n }\n }\n\n delete(key: K): boolean {\n return this.entries.delete(key);\n }\n\n /** The values, least recently used first */\n values(): IterableIterator<V> {\n return this.entries.values();\n }\n\n clear(): void {\n this.entries.clear();\n }\n}\n"]}
|
package/dist/map.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
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';
|
|
8
9
|
import type { Camera, PickHit, RasterLayerStats } from './wasm/isard.js';
|
|
9
|
-
/** MapLibre's default easing: cubic Bézier (0.25, 0.1, 0.25, 1) */
|
|
10
|
-
export declare function defaultEasing(t: number): number;
|
|
11
10
|
/** A map (see `GeoMap.create`); layers take it as their host */
|
|
12
11
|
export declare class GeoMap {
|
|
13
12
|
#private;
|
|
@@ -18,6 +17,8 @@ export declare class GeoMap {
|
|
|
18
17
|
private vector;
|
|
19
18
|
private readonly glyphsUrl;
|
|
20
19
|
private readonly basemapWorkerUrl;
|
|
20
|
+
/** Texture size of the vector basemap's tiles */
|
|
21
|
+
private readonly basemapTileSize;
|
|
21
22
|
private readonly container;
|
|
22
23
|
/** Markers and popups, over the canvas */
|
|
23
24
|
private readonly overlay;
|
|
@@ -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 */
|
|
@@ -80,6 +83,9 @@ export declare class GeoMap {
|
|
|
80
83
|
private unwatchRatio;
|
|
81
84
|
/** Stops listening to the canvas's context loss and restoration */
|
|
82
85
|
private readonly unwatchContext;
|
|
86
|
+
/** The loaders of the relief by encoding, URL and floor: the same loader for the same tiles (the engine keeps its
|
|
87
|
+
* tiles when only the exaggeration changes) */
|
|
88
|
+
private readonly terrainLoaders;
|
|
83
89
|
/** Loads the engine (once per page) and creates a map filling `container` */
|
|
84
90
|
static create(container: HTMLElement, options?: GeoMapOptions): Promise<GeoMap>;
|
|
85
91
|
private constructor();
|
|
@@ -89,8 +95,8 @@ export declare class GeoMap {
|
|
|
89
95
|
private createEngine;
|
|
90
96
|
/** The decoding workers of 3D Tiles, with the engine that has them (they run its module) and unless turned off */
|
|
91
97
|
private startLoader;
|
|
92
|
-
/** A 3D Tiles layer on the core engine: loads the engine with 3D Tiles, then rebuilds the map on it
|
|
93
|
-
* 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 */
|
|
94
100
|
private upgrade;
|
|
95
101
|
/** Downloads and compiles the engine with 3D Tiles once the map is idle (`tiles3d: 'preload'`), without running
|
|
96
102
|
* it: the first 3D Tiles layer then only instantiates it */
|
|
@@ -169,8 +175,8 @@ export declare class GeoMap {
|
|
|
169
175
|
/** Replaces the basemap and the IGN hillshade, under the other layers (hillshade by default: 0, none). The former
|
|
170
176
|
* names of the Géoplateforme basemaps (`LegacyBasemap`) are taken under their new ones */
|
|
171
177
|
setBasemap(basemap: Basemap, hillshade?: number): void;
|
|
172
|
-
/** Raster tiles ({z}, {x}, {y} URL; Web Mercator, or reprojected from
|
|
173
|
-
* already added */
|
|
178
|
+
/** Raster tiles ({z}, {x}, {y} URL; Web Mercator, or reprojected from another `grid`: longitudes and latitudes,
|
|
179
|
+
* Lambert-93, UTM…), over the layers already added */
|
|
174
180
|
addRaster(options: RasterOptions & {
|
|
175
181
|
before?: Layer;
|
|
176
182
|
}): RasterLayer;
|
|
@@ -190,16 +196,48 @@ export declare class GeoMap {
|
|
|
190
196
|
addExtrusions<P = Record<string, unknown>>(options?: ExtrusionOptions<P>): ExtrusionLayer<P>;
|
|
191
197
|
/** Text labels from GeoJSON (points, the middle of lines, the center of polygons), placed without overlaps */
|
|
192
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;
|
|
193
211
|
/**
|
|
194
212
|
* Vector tiles with a MapLibre style (OpenFreeMap's Positron by default): `tiles.raster(…)` draws its fills and lines
|
|
195
213
|
* (or a subset) as a raster layer, `tiles.labels(…)` its labels. `setBasemap('osm-positron')` does both for the
|
|
196
214
|
* basemap.
|
|
197
215
|
*/
|
|
198
216
|
vectorTiles(options?: VectorTilesOptions): VectorTiles;
|
|
217
|
+
/**
|
|
218
|
+
* The workers decoding the relief and reprojecting rasters: the map's pool, unless the map has no workers
|
|
219
|
+
* (`workers: false` or 0, or none in this browser): that is done in the page then
|
|
220
|
+
*/
|
|
221
|
+
private decodingPool;
|
|
222
|
+
private readonly remoteHeights;
|
|
223
|
+
private readonly remoteReprojection;
|
|
224
|
+
/** The loader of the relief tiles of `url` in a PNG encoding (one per URL, encoding and floor) */
|
|
225
|
+
private readonly terrainLoader;
|
|
199
226
|
/** Adds a layer, under `before` if given */
|
|
200
227
|
private place;
|
|
201
228
|
/** Textured meshes in 3D Tiles (photogrammetry, buildings), drawn with depth over the basemap */
|
|
202
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;
|
|
203
241
|
/** Asks for a frame; several calls before the next frame draw it once */
|
|
204
242
|
requestRender(): void;
|
|
205
243
|
private frame;
|