isard 1.16.0 → 2.1.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +5 -5
  3. package/dist/basemap/vectortiles/placed.js +7 -4
  4. package/dist/basemap/vectortiles/placed.js.map +1 -1
  5. package/dist/basemap/vectortiles/tiles.d.ts +1 -1
  6. package/dist/basemap/vectortiles/tiles.js.map +1 -1
  7. package/dist/basemap/vectortiles/vectors.d.ts +3 -1
  8. package/dist/basemap/vectortiles/vectors.js +2 -0
  9. package/dist/basemap/vectortiles/vectors.js.map +1 -1
  10. package/dist/basemap/vectortiles.d.ts +1 -3
  11. package/dist/basemap/vectortiles.js +1 -3
  12. package/dist/basemap/vectortiles.js.map +1 -1
  13. package/dist/basemap/workerpool.d.ts +1 -1
  14. package/dist/basemap/workerpool.js.map +1 -1
  15. package/dist/bind/layers.js +2 -2
  16. package/dist/bind/layers.js.map +1 -1
  17. package/dist/decoder.worker.js +4 -5
  18. package/dist/decoder.worker.js.map +6 -6
  19. package/dist/decoding/decoders.d.ts +1 -1
  20. package/dist/decoding/decoders.js.map +1 -1
  21. package/dist/decoding/loader.d.ts +6 -3
  22. package/dist/decoding/loader.js +7 -5
  23. package/dist/decoding/loader.js.map +1 -1
  24. package/dist/decoding/protocol.d.ts +3 -2
  25. package/dist/decoding/protocol.js.map +1 -1
  26. package/dist/engine-loader.d.ts +20 -18
  27. package/dist/engine-loader.js +45 -42
  28. package/dist/engine-loader.js.map +1 -1
  29. package/dist/index.d.ts +3 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/isard_grid_bg.wasm +0 -0
  32. package/dist/isard_tess_bg.wasm +0 -0
  33. package/dist/isard_tiles3d_bg.wasm +0 -0
  34. package/dist/isard_webgl2_bg.wasm +0 -0
  35. package/dist/isard_webgpu_bg.wasm +0 -0
  36. package/dist/layers/custom.d.ts +35 -29
  37. package/dist/layers/custom.js +60 -46
  38. package/dist/layers/custom.js.map +1 -1
  39. package/dist/layers/extrusions.d.ts +6 -1
  40. package/dist/layers/extrusions.js +15 -4
  41. package/dist/layers/extrusions.js.map +1 -1
  42. package/dist/layers/features.js.map +1 -1
  43. package/dist/layers/flow.js.map +1 -1
  44. package/dist/layers/glyphs.d.ts +1 -1
  45. package/dist/layers/glyphs.js.map +1 -1
  46. package/dist/layers/ground.d.ts +21 -14
  47. package/dist/layers/ground.js +30 -9
  48. package/dist/layers/ground.js.map +1 -1
  49. package/dist/layers/icons.d.ts +1 -1
  50. package/dist/layers/icons.js.map +1 -1
  51. package/dist/layers/layers.d.ts +1 -2
  52. package/dist/layers/layers.js +3 -12
  53. package/dist/layers/layers.js.map +1 -1
  54. package/dist/layers/models.d.ts +7 -1
  55. package/dist/layers/models.js +19 -5
  56. package/dist/layers/models.js.map +1 -1
  57. package/dist/layers/network.d.ts +1 -1
  58. package/dist/layers/network.js.map +1 -1
  59. package/dist/layers/panoramas.d.ts +1 -0
  60. package/dist/layers/panoramas.js +3 -2
  61. package/dist/layers/panoramas.js.map +1 -1
  62. package/dist/layers/pointclouds.d.ts +3 -3
  63. package/dist/layers/pointclouds.js +3 -7
  64. package/dist/layers/pointclouds.js.map +1 -1
  65. package/dist/layers/raster.js +5 -0
  66. package/dist/layers/raster.js.map +1 -1
  67. package/dist/layers/symbols.js.map +1 -1
  68. package/dist/layers/tiles3d.d.ts +5 -7
  69. package/dist/layers/tiles3d.js +9 -18
  70. package/dist/layers/tiles3d.js.map +1 -1
  71. package/dist/layers/vectors.d.ts +10 -5
  72. package/dist/layers/vectors.js +25 -16
  73. package/dist/layers/vectors.js.map +1 -1
  74. package/dist/map/engine-settings.d.ts +5 -2
  75. package/dist/map/engine-settings.js +13 -2
  76. package/dist/map/engine-settings.js.map +1 -1
  77. package/dist/map/engines.d.ts +11 -26
  78. package/dist/map/engines.js +10 -48
  79. package/dist/map/engines.js.map +1 -1
  80. package/dist/map/frame-loop.d.ts +1 -3
  81. package/dist/map/frame-loop.js +3 -3
  82. package/dist/map/frame-loop.js.map +1 -1
  83. package/dist/map/hover-pick.d.ts +9 -3
  84. package/dist/map/hover-pick.js +29 -6
  85. package/dist/map/hover-pick.js.map +1 -1
  86. package/dist/map/layer-stack.d.ts +7 -8
  87. package/dist/map/layer-stack.js +6 -9
  88. package/dist/map/layer-stack.js.map +1 -1
  89. package/dist/map/symbol-atlases.d.ts +5 -4
  90. package/dist/map/symbol-atlases.js +8 -13
  91. package/dist/map/symbol-atlases.js.map +1 -1
  92. package/dist/map/viewshed.d.ts +1 -1
  93. package/dist/map/viewshed.js.map +1 -1
  94. package/dist/map.d.ts +45 -26
  95. package/dist/map.js +141 -90
  96. package/dist/map.js.map +1 -1
  97. package/dist/react/IsardMap.d.ts +1 -1
  98. package/dist/react/IsardMap.js.map +1 -1
  99. package/dist/react/VectorGeometry.d.ts +4 -1
  100. package/dist/react/VectorGeometry.js +5 -1
  101. package/dist/react/VectorGeometry.js.map +1 -1
  102. package/dist/react/index.d.ts +1 -1
  103. package/dist/react/index.js.map +1 -1
  104. package/dist/settings.d.ts +2 -0
  105. package/dist/settings.js +1 -1
  106. package/dist/settings.js.map +1 -1
  107. package/dist/types.d.ts +52 -22
  108. package/dist/types.js.map +1 -1
  109. package/dist/ui/interaction.d.ts +1 -1
  110. package/dist/ui/interaction.js.map +1 -1
  111. package/dist/util/animation.d.ts +1 -1
  112. package/dist/util/animation.js.map +1 -1
  113. package/dist/wasm/isard_tiles3d.d.ts +181 -0
  114. package/dist/wasm/isard_tiles3d.js +387 -0
  115. package/dist/wasm/{isard_core.d.ts → isard_webgl2.d.ts} +387 -182
  116. package/dist/wasm/{isard_core.js → isard_webgl2.js} +2087 -324
  117. package/dist/wasm/{isard.d.ts → isard_webgpu.d.ts} +195 -358
  118. package/dist/wasm/{isard.js → isard_webgpu.js} +1320 -1042
  119. package/package.json +4 -3
  120. package/vite.js +5 -4
  121. package/dist/isard_bg.wasm +0 -0
  122. package/dist/isard_core_bg.wasm +0 -0
@@ -1,9 +1,9 @@
1
1
  /**
2
- * The drawing order of a map's layers, kept beside the engine's: the layers waiting for the engine with 3D Tiles are
3
- * in the order but not in the engine yet, and the order recreates the layers in a new engine after a context loss.
2
+ * The drawing order of a map's layers, kept beside the engine's: it recreates the layers in a new engine after a
3
+ * context loss; a layer whose creation failed stays in the order, not in the engine.
4
4
  */
5
5
  import type { Layer } from '../layers/layers.ts';
6
- import type { Engine } from '../wasm/isard.js';
6
+ import type { Engine } from '../wasm/isard_webgpu.js';
7
7
  /** A map's layers in drawing order, bottom first, and those kept on top */
8
8
  export declare class LayerStack {
9
9
  /** Layers in drawing order (bottom first), to recreate them after a context loss */
@@ -24,13 +24,12 @@ export declare class LayerStack {
24
24
  replace(layer: Layer, old: number): void;
25
25
  /** Moves a layer under all the others */
26
26
  toBottom(layer: Layer): void;
27
- /** Creates the layers in a new engine, in order, but those still `waiting` (for the engine with 3D Tiles); a layer
28
- * that fails is reported and left out */
29
- reattach(engine: Engine, waiting: (layer: Layer) => boolean): void;
30
- /** Frees what the layers hold beside the engine (custom layers' WebGL objects, models' data) */
27
+ /** Creates the layers in a new engine, in order; a layer that fails is reported and left out */
28
+ reattach(engine: Engine): void;
29
+ /** Frees what the layers hold beside the engine (custom layers' GPU objects, models' data) */
31
30
  dispose(): void;
32
31
  /** Takes a layer out of the drawing order (to put it back elsewhere, or for good) */
33
32
  private unlist;
34
- /** Index in the engine of the layer at `index`: the layers waiting for the engine with 3D Tiles are not in it yet */
33
+ /** Index in the engine of the layer at `index`: the layers without an id (their creation failed) are not in it */
35
34
  private engineIndex;
36
35
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The drawing order of a map's layers, kept beside the engine's: the layers waiting for the engine with 3D Tiles are
3
- * in the order but not in the engine yet, and the order recreates the layers in a new engine after a context loss.
2
+ * The drawing order of a map's layers, kept beside the engine's: it recreates the layers in a new engine after a
3
+ * context loss; a layer whose creation failed stays in the order, not in the engine.
4
4
  */
5
5
  import { report } from "./checks.js";
6
6
  /** A map's layers in drawing order, bottom first, and those kept on top */
@@ -52,16 +52,13 @@ export class LayerStack {
52
52
  this.unlist(layer);
53
53
  this.layers.unshift(layer);
54
54
  }
55
- /** Creates the layers in a new engine, in order, but those still `waiting` (for the engine with 3D Tiles); a layer
56
- * that fails is reported and left out */
57
- reattach(engine, waiting) {
55
+ /** Creates the layers in a new engine, in order; a layer that fails is reported and left out */
56
+ reattach(engine) {
58
57
  // No layer refers to an id of the old engine while the others are created
59
58
  this.layers.forEach((layer) => {
60
59
  layer.forgetEngine();
61
60
  });
62
61
  this.layers.forEach((layer) => {
63
- if (waiting(layer))
64
- return;
65
62
  try {
66
63
  layer.attach(engine);
67
64
  }
@@ -81,7 +78,7 @@ export class LayerStack {
81
78
  }
82
79
  });
83
80
  }
84
- /** Frees what the layers hold beside the engine (custom layers' WebGL objects, models' data) */
81
+ /** Frees what the layers hold beside the engine (custom layers' GPU objects, models' data) */
85
82
  dispose() {
86
83
  this.layers.forEach((layer) => {
87
84
  layer.dispose();
@@ -93,7 +90,7 @@ export class LayerStack {
93
90
  if (index >= 0)
94
91
  this.layers.splice(index, 1);
95
92
  }
96
- /** Index in the engine of the layer at `index`: the layers waiting for the engine with 3D Tiles are not in it yet */
93
+ /** Index in the engine of the layer at `index`: the layers without an id (their creation failed) are not in it */
97
94
  engineIndex(index) {
98
95
  return this.layers.slice(0, index).filter((layer) => layer.id >= 0).length;
99
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"layer-stack.js","sourceRoot":"","sources":["../../src/map/layer-stack.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,2EAA2E;AAC3E,MAAM,OAAO,UAAU;IACrB,oFAAoF;IAC3E,MAAM,GAAY,EAAE,CAAC;IAC9B,iCAAiC;IACxB,KAAK,GAAG,IAAI,GAAG,EAAS,CAAC;IACjB,MAAM,CAAe;IAEtC,+CAA+C;IAC/C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AAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC5B,IAAI,KAAK,CAAC,EAAE,GAAG,CAAC;gBAAE,OAAO;YACzB,IAAI,CAAC;gBACH,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,gGAAgG;IAChG,OAAO;QACL,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC5B,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,qFAAqF;IAC7E,MAAM,CAAC,KAAY;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEzC,IAAI,KAAK,IAAI,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,qHAAqH;IAC7G,WAAW,CAAC,KAAa;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IAC7E,CAAC;CACF","sourcesContent":["/**\n * The drawing order of a map's layers, kept beside the engine's: the layers waiting for the engine with 3D Tiles are\n * in the order but not in the engine yet, and the order recreates the layers in a new engine after a context loss.\n */\n\nimport type { Layer } from '../layers/layers.ts';\nimport type { Engine } from '../wasm/isard.js';\nimport { report } from './checks.ts';\n\n/** A map's layers in drawing order, bottom first, and those kept on top */\nexport class LayerStack {\n /** Layers in drawing order (bottom first), to recreate them after a context loss */\n readonly layers: Layer[] = [];\n /** Layers new layers go under */\n readonly onTop = new Set<Layer>();\n private readonly engine: () => Engine;\n\n /** `engine`: the map's engine of the moment */\n constructor(engine: () => Engine) {\n this.engine = engine;\n }\n\n has(layer: Layer): boolean {\n return this.layers.includes(layer);\n }\n\n /** Puts a new layer on top, under the layers kept on top (the basemap's labels) */\n add(layer: Layer): void {\n this.layers.push(layer);\n\n const top = this.layers.find((l) => this.onTop.has(l) && l !== layer);\n\n if (top) this.move(layer, top);\n }\n\n /** Forgets a removed layer */\n forget(layer: Layer): void {\n this.unlist(layer);\n this.onTop.delete(layer);\n }\n\n /** Moves a layer under `before`, or on top of all */\n move(layer: Layer, before: Layer | undefined): void {\n this.unlist(layer);\n\n const index = before ? this.layers.indexOf(before) : -1;\n const at = index < 0 ? this.layers.length : index;\n\n this.layers.splice(at, 0, layer);\n if (layer.id >= 0) this.engine().moveLayer(layer.id, this.engineIndex(at));\n }\n\n /** A layer made again in the engine under a new id: `old` removed, the new one moved to the layer's place */\n replace(layer: Layer, old: number): void {\n const engine = this.engine();\n\n engine.removeLayer(old);\n\n const index = this.layers.indexOf(layer);\n\n if (index >= 0) engine.moveLayer(layer.id, this.engineIndex(index));\n }\n\n /** Moves a layer under all the others */\n toBottom(layer: Layer): void {\n this.engine().moveLayer(layer.id, 0);\n this.unlist(layer);\n this.layers.unshift(layer);\n }\n\n /** Creates the layers in a new engine, in order, but those still `waiting` (for the engine with 3D Tiles); a layer\n * that fails is reported and left out */\n reattach(engine: Engine, waiting: (layer: Layer) => boolean): void {\n // No layer refers to an id of the old engine while the others are created\n this.layers.forEach((layer) => {\n layer.forgetEngine();\n });\n this.layers.forEach((layer) => {\n if (waiting(layer)) return;\n try {\n layer.attach(engine);\n } catch (error) {\n report(error);\n }\n });\n // Links between layers, once every layer has its new id (buildings colored by a network above them)\n this.layers.forEach((layer) => {\n if (layer.id < 0) return;\n try {\n layer.relink(engine);\n } catch (error) {\n report(error);\n }\n });\n }\n\n /** Frees what the layers hold beside the engine (custom layers' WebGL objects, models' data) */\n dispose(): void {\n this.layers.forEach((layer) => {\n layer.dispose();\n });\n }\n\n /** Takes a layer out of the drawing order (to put it back elsewhere, or for good) */\n private unlist(layer: Layer): void {\n const index = this.layers.indexOf(layer);\n\n if (index >= 0) this.layers.splice(index, 1);\n }\n\n /** Index in the engine of the layer at `index`: the layers waiting for the engine with 3D Tiles are not in it yet */\n private engineIndex(index: number): number {\n return this.layers.slice(0, index).filter((layer) => layer.id >= 0).length;\n }\n}\n"]}
1
+ {"version":3,"file":"layer-stack.js","sourceRoot":"","sources":["../../src/map/layer-stack.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,2EAA2E;AAC3E,MAAM,OAAO,UAAU;IACrB,oFAAoF;IAC3E,MAAM,GAAY,EAAE,CAAC;IAC9B,iCAAiC;IACxB,KAAK,GAAG,IAAI,GAAG,EAAS,CAAC;IACjB,MAAM,CAAe;IAEtC,+CAA+C;IAC/C,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,GAAG,CAAC,KAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,mFAAmF;IACnF,GAAG,CAAC,KAAY;QACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAExB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;QAEtE,IAAI,GAAG;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,8BAA8B;IAC9B,MAAM,CAAC,KAAY;QACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnB,IAAI,CAAC,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C1G,WAAW,CAAC,KAAa;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IAC7E,CAAC;CACF","sourcesContent":["/**\n * The drawing order of a map's layers, kept beside the engine's: it recreates the layers in a new engine after a\n * context loss; a layer whose creation failed stays in the order, not in the engine.\n */\n\nimport type { Layer } from '../layers/layers.ts';\nimport type { Engine } from '../wasm/isard_webgpu.js';\nimport { report } from './checks.ts';\n\n/** A map's layers in drawing order, bottom first, and those kept on top */\nexport class LayerStack {\n /** Layers in drawing order (bottom first), to recreate them after a context loss */\n readonly layers: Layer[] = [];\n /** Layers new layers go under */\n readonly onTop = new Set<Layer>();\n private readonly engine: () => Engine;\n\n /** `engine`: the map's engine of the moment */\n constructor(engine: () => Engine) {\n this.engine = engine;\n }\n\n has(layer: Layer): boolean {\n return this.layers.includes(layer);\n }\n\n /** Puts a new layer on top, under the layers kept on top (the basemap's labels) */\n add(layer: Layer): void {\n this.layers.push(layer);\n\n const top = this.layers.find((l) => this.onTop.has(l) && l !== layer);\n\n if (top) this.move(layer, top);\n }\n\n /** Forgets a removed layer */\n forget(layer: Layer): void {\n this.unlist(layer);\n this.onTop.delete(layer);\n }\n\n /** Moves a layer under `before`, or on top of all */\n move(layer: Layer, before: Layer | undefined): void {\n this.unlist(layer);\n\n const index = before ? this.layers.indexOf(before) : -1;\n const at = index < 0 ? this.layers.length : index;\n\n this.layers.splice(at, 0, layer);\n if (layer.id >= 0) this.engine().moveLayer(layer.id, this.engineIndex(at));\n }\n\n /** A layer made again in the engine under a new id: `old` removed, the new one moved to the layer's place */\n replace(layer: Layer, old: number): void {\n const engine = this.engine();\n\n engine.removeLayer(old);\n\n const index = this.layers.indexOf(layer);\n\n if (index >= 0) engine.moveLayer(layer.id, this.engineIndex(index));\n }\n\n /** Moves a layer under all the others */\n toBottom(layer: Layer): void {\n this.engine().moveLayer(layer.id, 0);\n this.unlist(layer);\n this.layers.unshift(layer);\n }\n\n /** Creates the layers in a new engine, in order; a layer that fails is reported and left out */\n reattach(engine: Engine): void {\n // No layer refers to an id of the old engine while the others are created\n this.layers.forEach((layer) => {\n layer.forgetEngine();\n });\n this.layers.forEach((layer) => {\n try {\n layer.attach(engine);\n } catch (error) {\n report(error);\n }\n });\n // Links between layers, once every layer has its new id (buildings colored by a network above them)\n this.layers.forEach((layer) => {\n if (layer.id < 0) return;\n try {\n layer.relink(engine);\n } catch (error) {\n report(error);\n }\n });\n }\n\n /** Frees what the layers hold beside the engine (custom layers' GPU objects, models' data) */\n dispose(): void {\n this.layers.forEach((layer) => {\n layer.dispose();\n });\n }\n\n /** Takes a layer out of the drawing order (to put it back elsewhere, or for good) */\n private unlist(layer: Layer): void {\n const index = this.layers.indexOf(layer);\n\n if (index >= 0) this.layers.splice(index, 1);\n }\n\n /** Index in the engine of the layer at `index`: the layers without an id (their creation failed) are not in it */\n private engineIndex(index: number): number {\n return this.layers.slice(0, index).filter((layer) => layer.id >= 0).length;\n }\n}\n"]}
@@ -1,15 +1,16 @@
1
1
  /** The atlases of a map's symbol layers, the glyphs and the icons: created on first use, moved to each new engine. */
2
2
  import { Glyphs } from '../layers/glyphs.ts';
3
3
  import { Icons, type ImageOptions, type Pixels } from '../layers/icons.ts';
4
- import type { Engine } from '../wasm/isard.js';
4
+ import type { Engine } from '../wasm/isard_webgpu.js';
5
5
  /** The glyphs and icons of a map */
6
6
  export declare class SymbolAtlases {
7
7
  #private;
8
- private readonly canvas;
8
+ private readonly maxSize;
9
9
  private readonly glyphsUrl;
10
10
  private readonly engine;
11
- /** `canvas`: the engine's; `glyphsUrl`: the map's option; `engine`: the map's engine of the moment */
12
- constructor(canvas: HTMLCanvasElement, glyphsUrl: string | undefined, engine: () => Engine);
11
+ /** `maxSize`: the largest texture the engine takes (undefined if unknown); `glyphsUrl`: the map's option; `engine`:
12
+ * the map's engine of the moment */
13
+ constructor(maxSize: () => number | undefined, glyphsUrl: string | undefined, engine: () => Engine);
13
14
  /** The glyphs of the symbol layers, loaded on first use */
14
15
  get glyphs(): Glyphs;
15
16
  /** The icons of the symbol layers: the application's images and the vector basemaps' sprites */
@@ -1,30 +1,25 @@
1
1
  /** The atlases of a map's symbol layers, the glyphs and the icons: created on first use, moved to each new engine. */
2
2
  import { Glyphs } from "../layers/glyphs.js";
3
3
  import { Icons, readPixels } from "../layers/icons.js";
4
- /** The largest texture the canvas's WebGL context takes, undefined if unknown: the atlases stay within it */
5
- const maxTextureSize = (canvas) => {
6
- const gl = canvas.getContext('webgl2');
7
- const max = gl?.getParameter(gl.MAX_TEXTURE_SIZE);
8
- return typeof max === 'number' ? max : undefined;
9
- };
10
4
  /** The glyphs and icons of a map */
11
5
  export class SymbolAtlases {
12
- canvas;
6
+ maxSize;
13
7
  glyphsUrl;
14
8
  engine;
15
9
  #glyphs;
16
10
  #icons;
17
- /** `canvas`: the engine's; `glyphsUrl`: the map's option; `engine`: the map's engine of the moment */
18
- constructor(canvas, glyphsUrl, engine) {
19
- this.canvas = canvas;
11
+ /** `maxSize`: the largest texture the engine takes (undefined if unknown); `glyphsUrl`: the map's option; `engine`:
12
+ * the map's engine of the moment */
13
+ constructor(maxSize, glyphsUrl, engine) {
14
+ this.maxSize = maxSize;
20
15
  this.glyphsUrl = glyphsUrl;
21
16
  this.engine = engine;
22
17
  }
23
18
  /** The glyphs of the symbol layers, loaded on first use */
24
19
  get glyphs() {
25
20
  if (!this.#glyphs) {
26
- // The engine's context: the atlas stays within its texture size limit
27
- this.#glyphs = new Glyphs(this.glyphsUrl, maxTextureSize(this.canvas));
21
+ // The engine's device: the atlas stays within its texture size limit
22
+ this.#glyphs = new Glyphs(this.glyphsUrl, this.maxSize());
28
23
  this.#glyphs.attach(this.engine());
29
24
  }
30
25
  return this.#glyphs;
@@ -32,7 +27,7 @@ export class SymbolAtlases {
32
27
  /** The icons of the symbol layers: the application's images and the vector basemaps' sprites */
33
28
  get icons() {
34
29
  if (!this.#icons) {
35
- this.#icons = new Icons(maxTextureSize(this.canvas));
30
+ this.#icons = new Icons(this.maxSize());
36
31
  this.#icons.attach(this.engine());
37
32
  }
38
33
  return this.#icons;
@@ -1 +1 @@
1
- {"version":3,"file":"symbol-atlases.js","sourceRoot":"","sources":["../../src/map/symbol-atlases.ts"],"names":[],"mappings":"AAAA,sHAAsH;AAEtH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAkC,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvF,6GAA6G;AAC7G,MAAM,cAAc,GAAG,CAAC,MAAyB,EAAsB,EAAE;IACvE,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,EAAE,EAAE,YAAY,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC;IAElD,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC,CAAC;AAEF,oCAAoC;AACpC,MAAM,OAAO,aAAa;IACP,MAAM,CAAoB;IAC1B,SAAS,CAAqB;IAC9B,MAAM,CAAe;IACtC,OAAO,CAAqB;IAC5B,MAAM,CAAoB;IAE1B,sGAAsG;IACtG,YAAY,MAAyB,EAAE,SAA6B,EAAE,MAAoB;QACxF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,2DAA2D;IAC3D,IAAI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,sEAAsE;YACtE,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,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,CAAC;CACF","sourcesContent":["/** The atlases of a map's symbol layers, the glyphs and the icons: created on first use, moved to each new engine. */\n\nimport { Glyphs } from '../layers/glyphs.ts';\nimport { Icons, type ImageOptions, type Pixels, readPixels } from '../layers/icons.ts';\nimport type { Engine } from '../wasm/isard.js';\n\n/** The largest texture the canvas's WebGL context takes, undefined if unknown: the atlases stay within it */\nconst maxTextureSize = (canvas: HTMLCanvasElement): number | undefined => {\n const gl = canvas.getContext('webgl2');\n const max = gl?.getParameter(gl.MAX_TEXTURE_SIZE);\n\n return typeof max === 'number' ? max : undefined;\n};\n\n/** The glyphs and icons of a map */\nexport class SymbolAtlases {\n private readonly canvas: HTMLCanvasElement;\n private readonly glyphsUrl: string | undefined;\n private readonly engine: () => Engine;\n #glyphs: Glyphs | undefined;\n #icons: Icons | undefined;\n\n /** `canvas`: the engine's; `glyphsUrl`: the map's option; `engine`: the map's engine of the moment */\n constructor(canvas: HTMLCanvasElement, glyphsUrl: string | undefined, engine: () => Engine) {\n this.canvas = canvas;\n this.glyphsUrl = glyphsUrl;\n this.engine = engine;\n }\n\n /** The glyphs of the symbol layers, loaded on first use */\n get glyphs(): Glyphs {\n if (!this.#glyphs) {\n // The engine's context: the atlas stays within its texture size limit\n this.#glyphs = new Glyphs(this.glyphsUrl, maxTextureSize(this.canvas));\n this.#glyphs.attach(this.engine());\n }\n\n return this.#glyphs;\n }\n\n /** The icons of the symbol layers: the application's images and the vector basemaps' sprites */\n get icons(): Icons {\n if (!this.#icons) {\n this.#icons = new Icons(maxTextureSize(this.canvas));\n this.#icons.attach(this.engine());\n }\n\n return this.#icons;\n }\n\n /** An image for the icons, from its pixels or from an image; one without pixels throws */\n addImage(\n name: string,\n image: Pixels | (CanvasImageSource & { width: number; height: number }),\n options: ImageOptions,\n ): void {\n const pixels = 'data' in image ? image : readPixels(image);\n\n if (!pixels) throw new Error(`isard: the image ${name} has no pixels`);\n this.icons.add(name, pixels, options);\n }\n\n hasImage(name: string): boolean {\n return this.#icons?.has(name) ?? false;\n }\n\n removeImage(name: string): void {\n this.#icons?.remove(name);\n }\n\n /** Uploads the atlases made so far to a new engine (after a context loss, or the one left once the map is gone) */\n attach(engine: Engine): void {\n this.#glyphs?.attach(engine);\n this.#icons?.attach(engine);\n }\n}\n"]}
1
+ {"version":3,"file":"symbol-atlases.js","sourceRoot":"","sources":["../../src/map/symbol-atlases.ts"],"names":[],"mappings":"AAAA,sHAAsH;AAEtH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAkC,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvF,oCAAoC;AACpC,MAAM,OAAO,aAAa;IACP,OAAO,CAA2B;IAClC,SAAS,CAAqB;IAC9B,MAAM,CAAe;IACtC,OAAO,CAAqB;IAC5B,MAAM,CAAoB;IAE1B;wCACoC;IACpC,YAAY,OAAiC,EAAE,SAA6B,EAAE,MAAoB;QAChG,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,2DAA2D;IAC3D,IAAI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,qEAAqE;YACrE,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1D,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,gGAAgG;IAChG,IAAI,KAAK;QACP,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YACxC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,0FAA0F;IAC1F,QAAQ,CACN,IAAY,EACZ,KAAuE,EACvE,OAAqB;QAErB,MAAM,MAAM,GAAG,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAE3D,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,gBAAgB,CAAC,CAAC;QACvE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC;IACzC,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,mHAAmH;IACnH,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["/** The atlases of a map's symbol layers, the glyphs and the icons: created on first use, moved to each new engine. */\n\nimport { Glyphs } from '../layers/glyphs.ts';\nimport { Icons, type ImageOptions, type Pixels, readPixels } from '../layers/icons.ts';\nimport type { Engine } from '../wasm/isard_webgpu.js';\n\n/** The glyphs and icons of a map */\nexport class SymbolAtlases {\n private readonly maxSize: () => number | undefined;\n private readonly glyphsUrl: string | undefined;\n private readonly engine: () => Engine;\n #glyphs: Glyphs | undefined;\n #icons: Icons | undefined;\n\n /** `maxSize`: the largest texture the engine takes (undefined if unknown); `glyphsUrl`: the map's option; `engine`:\n * the map's engine of the moment */\n constructor(maxSize: () => number | undefined, glyphsUrl: string | undefined, engine: () => Engine) {\n this.maxSize = maxSize;\n this.glyphsUrl = glyphsUrl;\n this.engine = engine;\n }\n\n /** The glyphs of the symbol layers, loaded on first use */\n get glyphs(): Glyphs {\n if (!this.#glyphs) {\n // The engine's device: the atlas stays within its texture size limit\n this.#glyphs = new Glyphs(this.glyphsUrl, this.maxSize());\n this.#glyphs.attach(this.engine());\n }\n\n return this.#glyphs;\n }\n\n /** The icons of the symbol layers: the application's images and the vector basemaps' sprites */\n get icons(): Icons {\n if (!this.#icons) {\n this.#icons = new Icons(this.maxSize());\n this.#icons.attach(this.engine());\n }\n\n return this.#icons;\n }\n\n /** An image for the icons, from its pixels or from an image; one without pixels throws */\n addImage(\n name: string,\n image: Pixels | (CanvasImageSource & { width: number; height: number }),\n options: ImageOptions,\n ): void {\n const pixels = 'data' in image ? image : readPixels(image);\n\n if (!pixels) throw new Error(`isard: the image ${name} has no pixels`);\n this.icons.add(name, pixels, options);\n }\n\n hasImage(name: string): boolean {\n return this.#icons?.has(name) ?? false;\n }\n\n removeImage(name: string): void {\n this.#icons?.remove(name);\n }\n\n /** Uploads the atlases made so far to a new engine (after a context loss, or the one left once the map is gone) */\n attach(engine: Engine): void {\n this.#glyphs?.attach(engine);\n this.#icons?.attach(engine);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /** The viewshed's observers given to the engine, in the arrays it reads. */
2
2
  import type { ViewshedOptions } from '../types.ts';
3
- import type { Engine } from '../wasm/isard.js';
3
+ import type { Engine } from '../wasm/isard_webgpu.js';
4
4
  /** Sets the viewshed of the engine, or clears it without observers; true if one is set (a frame to draw) */
5
5
  export declare const applyViewshed: (engine: Engine, options: ViewshedOptions | readonly ViewshedOptions[] | undefined) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"viewshed.js","sourceRoot":"","sources":["../../src/map/viewshed.ts"],"names":[],"mappings":"AAAA,4EAA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IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,SAAS,CAAC,CAAC,EACrD,KAAK,CAAC,OAAO,IAAI,GAAG,EACpB,IAAI,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAC9D,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["/** The viewshed's observers given to the engine, in the arrays it reads. */\n\nimport { rgb } from '../settings.ts';\nimport type { ViewshedOptions } from '../types.ts';\nimport type { Engine } from '../wasm/isard.js';\n\n/** The observers of a viewshed option: none, one, or several */\nconst observersOf = (options: ViewshedOptions | readonly ViewshedOptions[] | undefined): readonly ViewshedOptions[] => {\n if (!options) return [];\n\n return 'position' in options ? [options] : options;\n};\n\n/** Sets the viewshed of the engine, or clears it without observers; true if one is set (a frame to draw) */\nexport const applyViewshed = (\n engine: Engine,\n options: ViewshedOptions | readonly ViewshedOptions[] | undefined,\n): boolean => {\n const observers = observersOf(options);\n const [first] = observers;\n\n if (!first) {\n engine.clearViewshed();\n\n return false;\n }\n engine.setViewshed(\n new Float64Array(\n observers.flatMap((o) => [\n o.position[0],\n o.position[1],\n o.height ?? 1.7,\n o.range ?? 1000,\n ...(o.direction === undefined\n ? [Number.NaN, 0, 0, 0]\n : [o.direction, o.tilt ?? 0, o.fov ?? 60, o.verticalFov ?? 40]),\n ]),\n ),\n new Float32Array(rgb(first.visibleColor ?? '#2f9e44')),\n new Float32Array(rgb(first.hiddenColor ?? '#e03131')),\n first.opacity ?? 0.7,\n new Float32Array(first.coneColor ? rgb(first.coneColor) : []),\n );\n\n return true;\n};\n"]}
1
+ {"version":3,"file":"viewshed.js","sourceRoot":"","sources":["../../src/map/viewshed.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAIrC,gEAAgE;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,EACrD,KAAK,CAAC,OAAO,IAAI,GAAG,EACpB,IAAI,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAC9D,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["/** The viewshed's observers given to the engine, in the arrays it reads. */\n\nimport { rgb } from '../settings.ts';\nimport type { ViewshedOptions } from '../types.ts';\nimport type { Engine } from '../wasm/isard_webgpu.js';\n\n/** The observers of a viewshed option: none, one, or several */\nconst observersOf = (options: ViewshedOptions | readonly ViewshedOptions[] | undefined): readonly ViewshedOptions[] => {\n if (!options) return [];\n\n return 'position' in options ? [options] : options;\n};\n\n/** Sets the viewshed of the engine, or clears it without observers; true if one is set (a frame to draw) */\nexport const applyViewshed = (\n engine: Engine,\n options: ViewshedOptions | readonly ViewshedOptions[] | undefined,\n): boolean => {\n const observers = observersOf(options);\n const [first] = observers;\n\n if (!first) {\n engine.clearViewshed();\n\n return false;\n }\n engine.setViewshed(\n new Float64Array(\n observers.flatMap((o) => [\n o.position[0],\n o.position[1],\n o.height ?? 1.7,\n o.range ?? 1000,\n ...(o.direction === undefined\n ? [Number.NaN, 0, 0, 0]\n : [o.direction, o.tilt ?? 0, o.fov ?? 60, o.verticalFov ?? 40]),\n ]),\n ),\n new Float32Array(rgb(first.visibleColor ?? '#2f9e44')),\n new Float32Array(rgb(first.hiddenColor ?? '#e03131')),\n first.opacity ?? 0.7,\n new Float32Array(first.coneColor ? rgb(first.coneColor) : []),\n );\n\n return true;\n};\n"]}
package/dist/map.d.ts CHANGED
@@ -26,15 +26,16 @@ import { Tiles3dLayer } from './layers/tiles3d.ts';
26
26
  import { type TreeOptions } from './layers/trees.ts';
27
27
  import { type HoverPicking } from './map/hover-pick.ts';
28
28
  import { type LayerSpec } from './map/layer-spec.ts';
29
- import type { AnimationOptions, AtmosphereOptions, Basemap, FeatureHit, FirstPersonView, FlyToOptions, GeoMapOptions, LoadingMode, LonLat, MapEvents, NetworkOptions, PickOptions, Point, Projection, Quality, RasterOptions, SunOptions, SwipeOptions, TerrainModel, TerrainOptions, Tiles3dOptions, ViewshedOptions } from './types.ts';
29
+ import type { AnimationOptions, AtmosphereOptions, Basemap, FeatureHit, FirstPersonView, FlyToOptions, GeoMapOptions, LoadingMode, LonLat, MapEvents, MapGpuTimings, MapMemory, NetworkOptions, PickOptions, Point, Projection, Quality, RasterOptions, SunOptions, SwipeOptions, TerrainModel, TerrainOptions, Tiles3dOptions, ViewshedOptions } from './types.ts';
30
30
  import { type Control, type ControlPosition } from './ui/controls.ts';
31
- import type { Camera, PickHit, RasterLayerStats } from './wasm/isard.js';
31
+ import type { Camera, PickHit, RasterLayerStats } from './wasm/isard_webgpu.js';
32
32
  export type { LayerSpec } from './map/layer-spec.ts';
33
- /** A map (see `GeoMap.create`); layers take it as their host */
34
33
  export declare class GeoMap {
35
34
  #private;
36
35
  readonly canvas: HTMLCanvasElement;
37
- /** The engine class (core, or with 3D Tiles) and the engine with 3D Tiles loaded when needed */
36
+ /** The frames' parts timed on the GPU (`setGpuTiming`), again on a new engine */
37
+ private gpuTiming;
38
+ /** The engine, made asynchronously, and the workers decoding its 3D Tiles */
38
39
  private readonly engines;
39
40
  /** The layers in drawing order and those kept on top */
40
41
  private readonly stack;
@@ -48,7 +49,7 @@ export declare class GeoMap {
48
49
  /** The canvas in the container, the markers and popups over it, the controls in its corners */
49
50
  private readonly overlays;
50
51
  private readonly settings;
51
- /** The WebGL context is lost: nothing is drawn until it is restored */
52
+ /** The GPU is lost (the WebGL context, the WebGPU device): nothing is drawn until a new engine is there */
52
53
  private lost;
53
54
  private gone;
54
55
  private readonly listeners;
@@ -84,13 +85,15 @@ export declare class GeoMap {
84
85
  private get layers();
85
86
  /** Layers new layers go under */
86
87
  private get onTop();
87
- private createEngine;
88
- /** A 3D Tiles layer or a model on the core engine: loads the engine with 3D Tiles, then rebuilds the map on it
89
- * (camera, settings and layers kept, as after a context loss); the layer is created then */
90
- private upgrade;
91
- /** Downloads and compiles the engine with 3D Tiles once the map is idle (`tiles3d: 'preload'`), without running
92
- * it: the first 3D Tiles layer then only instantiates it */
93
- private preloadTiles3d;
88
+ /** The GPU is lost: nothing drawn, the engine dropped (`dropLostEngine`) */
89
+ private gpuLost;
90
+ /**
91
+ * Follows the loss of `engine`'s WebGPU device (a phone taking its memory back, a driver reset, the GPU process
92
+ * gone): while it is the map's, the map drops it and makes a new one at once, WebGPU having no event for the GPU
93
+ * given back. The device of an engine the map freed itself (replaced, the map destroyed) is lost too: not the map's
94
+ * any more, left be
95
+ */
96
+ private watchDevice;
94
97
  /**
95
98
  * The context is lost: its engine freed at once, the map's calls going to one that does nothing until `restore`
96
99
  * builds the next. The old engine's GPU objects went with the context: deleted now, it is silent (on the context
@@ -98,8 +101,12 @@ export declare class GeoMap {
98
101
  * would fail on the lost context, whose limits read 0
99
102
  */
100
103
  private dropLostEngine;
101
- /** After a context loss: a new engine with the same camera, settings and layers (same handles, same order) */
104
+ /** After the GPU lost: a new engine with the same camera, settings and layers (same handles, same order); the engine
105
+ * made asynchronously, adopted once there */
102
106
  private restore;
107
+ /** A new engine in place of the map's (a placeholder, or a lost one): the same camera, settings and layers (same
108
+ * handles, same order) */
109
+ private adopt;
103
110
  /** The street-level eye, if the camera is one */
104
111
  get firstPerson(): Readonly<Required<FirstPersonView>> | undefined;
105
112
  /**
@@ -180,20 +187,30 @@ export declare class GeoMap {
180
187
  setTerrain(terrain: boolean | TerrainModel | TerrainOptions): void;
181
188
  /** Color behind the map, a CSS color (its alpha ignored) */
182
189
  setBackground(color: string): void;
190
+ /** The GPU memory its layers hold (bytes): the tiles of the 3D Tiles and point clouds, kept within the budget
191
+ * (`GeoMapOptions.memory`), the rasters' pools */
192
+ memory(): MapMemory;
183
193
  /** Tile counters of the raster layers, for diagnostics */
184
194
  stats(): RasterLayerStats[];
195
+ /** Times the parts of each frame on the GPU, for profiling (`gpuTimings`): timer queries, read a few frames later.
196
+ * An engine built to profile only (`PROFILE=1 bun run build`); false without one, or if the browser cannot
197
+ * (`EXT_disjoint_timer_query_webgl2`) */
198
+ setGpuTiming(on: boolean): boolean;
199
+ /** The GPU time of the last frame measured (`setGpuTiming`), in all and by part: the backdrop, the ground (the raster
200
+ * layers over the relief), each layer, the shadows, the panorama, the viewshed (ms) */
201
+ gpuTimings(): MapGpuTimings | undefined;
185
202
  /**
186
- * The feature under a screen point (CSS pixels), undefined if none: its layer id and index. Reads one pixel of an
187
- * offscreen picking pass, whatever the number of features, but waits for the GPU to finish the frame (a stall): for
188
- * clicks and one-off queries. On hover, listen to 'hoverfeature' instead, which picks without waiting.
203
+ * The feature under a screen point (CSS pixels), undefined if none: its layer id and index. Reads the pixels around
204
+ * the point of an offscreen picking pass, whatever the number of features, once the GPU is done (a frame or two
205
+ * later: the GPU is not waited for). On hover, listen to 'hoverfeature' instead.
189
206
  */
190
- pick(point: Point, { radius, layers }?: PickOptions): PickHit | undefined;
207
+ pick(point: Point, { radius, layers }?: PickOptions): Promise<PickHit | undefined>;
191
208
  /**
192
209
  * The feature under a screen point (CSS pixels), or the nearest one within `radius` pixels: its layer handle, its
193
210
  * index there and, for line, circle and fill layers, the feature itself; undefined if none. `layers` restricts the
194
211
  * search to some layers (the others hide nothing).
195
212
  */
196
- pickFeature(point: Point, options?: PickOptions): FeatureHit | undefined;
213
+ pickFeature(point: Point, options?: PickOptions): Promise<FeatureHit | undefined>;
197
214
  /** A hit with its layer handle and feature; undefined if the layer is gone */
198
215
  private featureHit;
199
216
  /** Screen point (CSS pixels) of a position on the ground (the relief), or `height` metres above it, undefined
@@ -220,15 +237,16 @@ export declare class GeoMap {
220
237
  * where it starts, a roof or a mesh as the relief (on by default), or around the screen center */
221
238
  setRotateAroundPointer(enabled: boolean): void;
222
239
  /** What is drawn under a screen point (CSS pixels), on the relief or standing on it (a roof, a wall, a mesh): its
223
- * position and its height above the relief, in metres; undefined where nothing was drawn. The last frame's scene is
224
- * drawn again and read back, waiting for the GPU (a stall): for clicks and drags */
240
+ * position and its height above the relief, in metres; undefined where nothing was drawn. Read from the last copy of
241
+ * the scene's depth (a frame or two old, a pixel every 4 CSS pixels): at once, without waiting for the GPU */
225
242
  pickSurface(point: Point): {
226
243
  lonLat: LonLat;
227
244
  height: number;
228
245
  } | undefined;
229
246
  /** The height above the relief, in metres, of the top of what stands at a position: a roof, a mesh, 0 on the bare
230
- * ground; undefined where nothing of the last frame is there. The scene is drawn from above into a single pixel and
231
- * read back: cheap, but it waits for the GPU */
247
+ * ground; undefined where nothing of the last frame is there, or until measured: the scene is drawn looking down at
248
+ * it after a frame and read back a frame or two later, the answer kept and measured again every 250 ms at most (ask
249
+ * again on the next `render` event) */
232
250
  surfaceAt(lonLat: LonLat): number | undefined;
233
251
  /** Adds a control in a corner of the map; controls stack from the corner inward */
234
252
  addControl(control: Control, position?: ControlPosition): this;
@@ -290,7 +308,7 @@ export declare class GeoMap {
290
308
  addTiles3d(options: Tiles3dOptions): Tiles3dLayer;
291
309
  /**
292
310
  * A point cloud (see `PointCloudOptions`): a COPC file read by range requests (IGN's LiDAR HD…), or 3D Tiles
293
- * points; with depth, on the engine with 3D Tiles; under `before` if given
311
+ * points; with depth; under `before` if given
294
312
  */
295
313
  addPointCloud(options: PointCloudOptions): PointCloudLayer;
296
314
  /**
@@ -305,7 +323,7 @@ export declare class GeoMap {
305
323
  /** Particles carried by a field of velocities (a wind, a current), their trails animated and colored by speed on
306
324
  * the globe and the relief (see `FlowOptions`) */
307
325
  addFlow(options: FlowOptions): FlowLayer;
308
- /** A glTF model drawn at positions (see `ModelOptions`), with depth; on the engine with 3D Tiles, as they are */
326
+ /** A glTF model drawn at positions (see `ModelOptions`), with depth */
309
327
  addModels(options: ModelOptions): ModelLayer;
310
328
  /** Trees at the points of a source that has them (a city's street trees), broadleaved or conifers by their data,
311
329
  * scaled to their height (see `TreeOptions`); the conifers on a layer that goes with the one returned */
@@ -314,8 +332,9 @@ export declare class GeoMap {
314
332
  * view, a 360° one on a band round its camera; resolves once its image is read */
315
333
  addPhoto(options: PhotoOptions): Promise<ModelLayer>;
316
334
  /**
317
- * The page's own WebGL drawing at its place among the layers, in every frame (see `CustomLayerInterface`): raw
318
- * WebGL, three.js… with the matrices of the frame (`frame.matrixAt`); under `before` if given
335
+ * The page's own WebGPU drawing at its place among the layers, in every frame (see `CustomLayerInterface`): raw
336
+ * WebGPU, three.js's WebGPU renderer… with the map's device and the matrices of the frame (`frame.matrixAt`); under
337
+ * `before` if given. Not drawn on the WebGL2 fallback
319
338
  */
320
339
  addCustomLayer(layer: CustomLayerInterface, options?: {
321
340
  before?: Layer;