isard 1.6.0 → 1.8.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 (131) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/basemap/furniture.d.ts +20 -2
  3. package/dist/basemap/furniture.js +72 -3
  4. package/dist/basemap/furniture.js.map +1 -1
  5. package/dist/basemap/meshes.d.ts +21 -0
  6. package/dist/basemap/meshes.js +159 -0
  7. package/dist/basemap/meshes.js.map +1 -0
  8. package/dist/basemap/placed.d.ts +13 -0
  9. package/dist/basemap/placed.js +14 -0
  10. package/dist/basemap/placed.js.map +1 -0
  11. package/dist/basemap/trees.d.ts +4 -14
  12. package/dist/basemap/trees.js +12 -93
  13. package/dist/basemap/trees.js.map +1 -1
  14. package/dist/basemap/vectortiles/context.d.ts +4 -2
  15. package/dist/basemap/vectortiles/context.js.map +1 -1
  16. package/dist/basemap/vectortiles/extrusions.d.ts +1 -1
  17. package/dist/basemap/vectortiles/extrusions.js +7 -16
  18. package/dist/basemap/vectortiles/extrusions.js.map +1 -1
  19. package/dist/basemap/vectortiles/furniture.d.ts +19 -0
  20. package/dist/basemap/vectortiles/furniture.js +29 -0
  21. package/dist/basemap/vectortiles/furniture.js.map +1 -0
  22. package/dist/basemap/vectortiles/labels.js +8 -1
  23. package/dist/basemap/vectortiles/labels.js.map +1 -1
  24. package/dist/basemap/vectortiles/lamps.js +11 -76
  25. package/dist/basemap/vectortiles/lamps.js.map +1 -1
  26. package/dist/basemap/vectortiles/placed.d.ts +38 -0
  27. package/dist/basemap/vectortiles/placed.js +143 -0
  28. package/dist/basemap/vectortiles/placed.js.map +1 -0
  29. package/dist/basemap/vectortiles/street-wind.js +4 -6
  30. package/dist/basemap/vectortiles/street-wind.js.map +1 -1
  31. package/dist/basemap/vectortiles/trees.d.ts +2 -9
  32. package/dist/basemap/vectortiles/trees.js +34 -165
  33. package/dist/basemap/vectortiles/trees.js.map +1 -1
  34. package/dist/basemap/vectortiles/vectors.d.ts +4 -5
  35. package/dist/basemap/vectortiles/vectors.js +17 -16
  36. package/dist/basemap/vectortiles/vectors.js.map +1 -1
  37. package/dist/basemap/vectortiles.d.ts +14 -4
  38. package/dist/basemap/vectortiles.js +40 -12
  39. package/dist/basemap/vectortiles.js.map +1 -1
  40. package/dist/basemap/wmts.js +2 -2
  41. package/dist/basemap/wmts.js.map +1 -1
  42. package/dist/basemap.worker.js +2 -2
  43. package/dist/basemap.worker.js.map +18 -14
  44. package/dist/bind/layers.d.ts +10 -3
  45. package/dist/bind/layers.js +11 -4
  46. package/dist/bind/layers.js.map +1 -1
  47. package/dist/data/collada.js +3 -17
  48. package/dist/data/collada.js.map +1 -1
  49. package/dist/data/crs.js +1 -1
  50. package/dist/data/crs.js.map +1 -1
  51. package/dist/data/ifc.js +21 -22
  52. package/dist/data/ifc.js.map +1 -1
  53. package/dist/geoplateforme.d.ts +16 -4
  54. package/dist/geoplateforme.js +26 -4
  55. package/dist/geoplateforme.js.map +1 -1
  56. package/dist/index.d.ts +5 -4
  57. package/dist/index.js +3 -3
  58. package/dist/index.js.map +1 -1
  59. package/dist/isard_bg.wasm +0 -0
  60. package/dist/isard_core_bg.wasm +0 -0
  61. package/dist/isard_grid_bg.wasm +0 -0
  62. package/dist/isard_tess_bg.wasm +0 -0
  63. package/dist/layers/extrusions.js +5 -4
  64. package/dist/layers/extrusions.js.map +1 -1
  65. package/dist/layers/features.d.ts +0 -2
  66. package/dist/layers/features.js +5 -6
  67. package/dist/layers/features.js.map +1 -1
  68. package/dist/layers/layers.d.ts +2 -0
  69. package/dist/layers/layers.js +11 -0
  70. package/dist/layers/layers.js.map +1 -1
  71. package/dist/layers/panoramas.d.ts +32 -10
  72. package/dist/layers/panoramas.js +55 -28
  73. package/dist/layers/panoramas.js.map +1 -1
  74. package/dist/layers/photos.js +5 -6
  75. package/dist/layers/photos.js.map +1 -1
  76. package/dist/layers/trees.js +7 -7
  77. package/dist/layers/trees.js.map +1 -1
  78. package/dist/layers/vectors.d.ts +1 -0
  79. package/dist/layers/vectors.js +23 -8
  80. package/dist/layers/vectors.js.map +1 -1
  81. package/dist/map/frame-loop.d.ts +2 -0
  82. package/dist/map/frame-loop.js +3 -3
  83. package/dist/map/frame-loop.js.map +1 -1
  84. package/dist/map.js +17 -0
  85. package/dist/map.js.map +1 -1
  86. package/dist/panoramax.d.ts +19 -0
  87. package/dist/panoramax.js +48 -3
  88. package/dist/panoramax.js.map +1 -1
  89. package/dist/react/CustomLayer.js +5 -4
  90. package/dist/react/CustomLayer.js.map +1 -1
  91. package/dist/react/Layer.d.ts +1 -1
  92. package/dist/react/Layer.js +6 -5
  93. package/dist/react/Layer.js.map +1 -1
  94. package/dist/react/VectorGeometry.d.ts +18 -9
  95. package/dist/react/VectorGeometry.js +30 -15
  96. package/dist/react/VectorGeometry.js.map +1 -1
  97. package/dist/react/VectorTiles.d.ts +65 -0
  98. package/dist/react/VectorTiles.js +112 -0
  99. package/dist/react/VectorTiles.js.map +1 -0
  100. package/dist/react/context.d.ts +12 -0
  101. package/dist/react/context.js +40 -1
  102. package/dist/react/context.js.map +1 -1
  103. package/dist/react/index.d.ts +7 -1
  104. package/dist/react/index.js +7 -1
  105. package/dist/react/index.js.map +1 -1
  106. package/dist/types.d.ts +2 -0
  107. package/dist/types.js.map +1 -1
  108. package/dist/util/geo.d.ts +8 -0
  109. package/dist/util/geo.js +8 -0
  110. package/dist/util/geo.js.map +1 -1
  111. package/dist/util/gltf.d.ts +18 -1
  112. package/dist/util/gltf.js +26 -1
  113. package/dist/util/gltf.js.map +1 -1
  114. package/dist/util/roofs.d.ts +8 -0
  115. package/dist/util/roofs.js +16 -2
  116. package/dist/util/roofs.js.map +1 -1
  117. package/dist/util/style-floats.d.ts +33 -0
  118. package/dist/util/style-floats.js +34 -0
  119. package/dist/util/style-floats.js.map +1 -0
  120. package/dist/util/sun.js +1 -1
  121. package/dist/util/sun.js.map +1 -1
  122. package/dist/workers/basemap/furniture.d.ts +13 -0
  123. package/dist/workers/basemap/geometry.d.ts +2 -5
  124. package/dist/workers/basemap/labels.d.ts +5 -2
  125. package/dist/workers/basemap/lamps.d.ts +3 -3
  126. package/dist/workers/basemap/tiles.d.ts +2 -0
  127. package/dist/workers/basemap/trees.d.ts +3 -0
  128. package/dist/workers/basemap.worker.d.ts +17 -1
  129. package/dist/workers/basemap.worker.js +12 -1
  130. package/dist/workers/basemap.worker.js.map +1 -1
  131. package/package.json +1 -1
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { loadSprites, readPixels, spriteSources } from "../layers/icons.js";
15
15
  import { extrusions } from "./vectortiles/extrusions.js";
16
+ import { furniture } from "./vectortiles/furniture.js";
16
17
  import { labels, size, tileLabels } from "./vectortiles/labels.js";
17
18
  import { lamps } from "./vectortiles/lamps.js";
18
19
  import { streetWind } from "./vectortiles/street-wind.js";
@@ -75,11 +76,14 @@ export class VectorTiles {
75
76
  this.pool.broadcast(message);
76
77
  },
77
78
  request: (vz, vx, vy, work, signal) => this.request(vz, vx, vy, work, signal),
78
- renderer: (select, extra, again) => this.renderer(select, extra, again),
79
+ renderer: (select, extra, again) => this.renderer(select, extra, { again }),
79
80
  loadSprites: (sprite) => this.loadSprites(sprite),
80
81
  addSprites: () => this.addSprites(),
81
- followView: (update, requests, moving) => {
82
- this.followView(update, requests, moving);
82
+ followView: (layer, update, requests, moving) => {
83
+ this.followView(layer, update, requests, moving);
84
+ },
85
+ stopWith: (layer, stop) => {
86
+ this.stopWith(layer, stop);
83
87
  },
84
88
  };
85
89
  }
@@ -124,12 +128,11 @@ export class VectorTiles {
124
128
  request(vz, vx, vy, work, signal) {
125
129
  if (this.destroyed)
126
130
  return Promise.reject(new DOMException('isard: vector tiles destroyed', 'AbortError'));
127
- return this.pool.request(this.pool.worker(vz, vx, vy), work, this, signal);
131
+ return this.map.track(this.pool.request(this.pool.worker(vz, vx, vy), work, this, signal));
128
132
  }
129
- /** Sends a renderer of these layers to every worker (again under `again`, restyled), with the style's sprites if it
130
- * `draws` the tiles into images with patterns (the raster path: the others take their images in the page); returns
131
- * its key */
132
- async renderer(select, extra, again, draws = false) {
133
+ /** Sends a renderer of these layers to every worker (`again`: under that key, restyled), with the style's sprites if
134
+ * it `draws` the tiles into images with patterns (the raster path: the others take their images in the page) */
135
+ async renderer(select, extra, { again, draws = false } = {}) {
133
136
  const { style, tiles, maxzoom, rasters } = await this.ready;
134
137
  const key = again ?? rendererKey(this.namespace, this.keys++);
135
138
  const layers = [...style.layers.filter(select), ...extra];
@@ -150,7 +153,7 @@ export class VectorTiles {
150
153
  raster(options = {}) {
151
154
  const { layers = () => true, extraLayers = [], size: texture = 512, opacity = 1, before } = options;
152
155
  const drawn = (l) => l.type !== 'symbol' && layers(l);
153
- const renderer = this.renderer(drawn, extraLayers, undefined, true);
156
+ const renderer = this.renderer(drawn, extraLayers, { draws: true });
154
157
  // Its failure is reported by `ready` and each tile
155
158
  renderer.catch(() => undefined);
156
159
  const loader = async (z, x, y, signal) => {
@@ -223,6 +226,16 @@ export class VectorTiles {
223
226
  lamps(options = {}) {
224
227
  return lamps(this.context, options);
225
228
  }
229
+ /**
230
+ * The street furniture as 3D models, from OpenMapTiles' points of interest of the street: bus shelters at the bus
231
+ * stops, waste baskets, post boxes, drinking fountains (Wallace's in Paris), bicycle racks, each facing its street;
232
+ * benches along the pedestrian streets and the paths of the parks and gardens. Placed by the workers, one instanced
233
+ * draw a kind, all of them near the camera and fewer away from it. The layer returned holds the other kinds' (its
234
+ * `companions`); removed with it
235
+ */
236
+ furniture(options = {}) {
237
+ return furniture(this.context, options);
238
+ }
226
239
  /**
227
240
  * A layer drawing the style's fills, lines and buildings (or those `layers` keeps; backgrounds as fills, the
228
241
  * `fill-extrusion` layers raised into buildings by their height and base height) as geometry instead of images: the
@@ -257,9 +270,9 @@ export class VectorTiles {
257
270
  }
258
271
  /**
259
272
  * Makes a layer's tiles follow the view: `update` now and where the camera stops (`moveend`), `moving` every
260
- * `VECTOR_MOVE_REFRESH_MS` while it moves; the `requests` aborted when destroyed
273
+ * `VECTOR_MOVE_REFRESH_MS` while it moves; the `requests` aborted when destroyed or the layer removed
261
274
  */
262
- followView(update, requests, moving) {
275
+ followView(layer, update, requests, moving) {
263
276
  const refresh = () => {
264
277
  update().catch(() => undefined);
265
278
  };
@@ -272,12 +285,27 @@ export class VectorTiles {
272
285
  Promise.resolve(moving()).catch(() => undefined);
273
286
  }, VECTOR_MOVE_REFRESH_MS);
274
287
  };
275
- this.cleanup.push(this.map.on('move', follow), this.map.on('moveend', refresh), () => {
288
+ const [offMove, offEnd] = [this.map.on('move', follow), this.map.on('moveend', refresh)];
289
+ this.stopWith(layer, () => {
290
+ offMove();
291
+ offEnd();
276
292
  clearTimeout(pace.timer);
277
293
  requests.abortAll();
278
294
  });
279
295
  refresh();
280
296
  }
297
+ /** Calls `stop` when destroyed or once `layer` is removed, whichever comes first */
298
+ stopWith(layer, stop) {
299
+ const once = { done: false };
300
+ const run = () => {
301
+ if (once.done)
302
+ return;
303
+ once.done = true;
304
+ stop();
305
+ };
306
+ this.cleanup.push(run);
307
+ layer.whenRemoved.push(run);
308
+ }
281
309
  /** Stops its workers' work and removes its raster and label layers from the map (those still there) */
282
310
  destroy() {
283
311
  if (this.destroyed)
@@ -1 +1 @@
1
- {"version":3,"file":"vectortiles.js","sourceRoot":"","sources":["../../src/basemap/vectortiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAqB,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQ/F,OAAO,EAAE,UAAU,EAA+B,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAsB,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAqB,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAgD,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACxG,OAAO,EAEL,SAAS,EACT,kBAAkB,EAClB,WA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AK,CAAC,MAAM,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC/B,4EAA4E;QAC5E,IAAI,CAAC,OAAO;YACV,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;YACjB,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;gBACzB,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACvB,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC1B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,8DAA8D;YAC9D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC7B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5B,CAAC;CACF","sourcesContent":["/**\n * Vector basemaps from a MapLibre style (OpenFreeMap's Positron by default): the fills, lines, circles and raster\n * layers drawn tile by tile in workers into the raster pool, so that they lie on the relief like any basemap and\n * composite with the hillshade in one pass; and the labels of the style's symbol layers in a symbol layer of their own,\n * kept above the application's layers (as MapLibre's `beforeId: firstSymbol` does), listed by the workers, shaped in\n * the page once per vector tile, placed by the engine.\n *\n * Any subset of the style can be drawn on its own raster layer (`raster({ layers })`), at its own place in the stack:\n * rivers from the basemap's data over a flood layer, for instance, restyled with `extraLayers`.\n *\n * The layers other than the raster ones are made in `vectortiles/` (one module each), from what they use of the\n * instance (`VectorTilesContext`); the style's loading is in `vectortiles/style.ts`.\n */\n\nimport type { ExtrusionLayer } from '../layers/extrusions.ts';\nimport { type LoadedSprite, loadSprites, readPixels, spriteSources } from '../layers/icons.ts';\nimport type { Layer, ModelLayer, RasterLayer } from '../layers/layers.ts';\nimport type { SymbolLayer } from '../layers/symbols.ts';\nimport type { VectorLayer } from '../layers/vectors.ts';\nimport type { GeoMap } from '../map.ts';\nimport type { BasemapWork, Sprite } from '../workers/basemap.worker.ts';\nimport type { LabelCandidate, Style, StyleLayer } from './vectorstyle.ts';\nimport type { Renderer, VectorTilesContext } from './vectortiles/context.ts';\nimport { extrusions, type VectorExtrusionOptions } from './vectortiles/extrusions.ts';\nimport { type LabelsOptions, labels, size, tileLabels } from './vectortiles/labels.ts';\nimport { type LampsOptions, lamps } from './vectortiles/lamps.ts';\nimport type { TileRequests } from './vectortiles/requests.ts';\nimport { type StreetWindLayer, type StreetWindOptions, streetWind } from './vectortiles/street-wind.ts';\nimport {\n type LoadedStyle,\n loadStyle,\n OPENFREEMAP_STYLES,\n PLAN_STYLES,\n styleAttribution,\n VECTOR_BASEMAPS,\n} from './vectortiles/style.ts';\nimport { VECTOR_MOVE_REFRESH_MS } from './vectortiles/tiles.ts';\nimport { type TreesOptions, trees } from './vectortiles/trees.ts';\nimport { dashes, type VectorsOptions, vectors } from './vectortiles/vectors.ts';\nimport { type BasemapWorkers, rendererKey, tilePriority } from './workerpool.ts';\n\n// The names the package and its tests import from here, now made in `vectortiles/`\nexport { dashes, OPENFREEMAP_STYLES, PLAN_STYLES, size, styleAttribution, tileLabels, VECTOR_BASEMAPS };\n\nexport interface VectorTilesOptions {\n /** A style URL or object (default OpenFreeMap's Positron) */\n style?: string | Style;\n /** Workers drawing the tiles (default cores - 1, 1 to 4). The vector tiles of a map share its workers (and their\n * decoded tiles); another count gives these tiles workers of their own */\n workers?: number;\n /** Where to load the worker from, when a bundler does not resolve the default URL (default the map's\n * `basemapWorkerUrl`); another URL than the map's gives these tiles workers of their own */\n workerUrl?: string | URL;\n /** Credits of the tiles, shown while its raster layers are on the map (default: OpenFreeMap's for its styles, the\n * IGN's for PLAN.IGN's) */\n attribution?: string;\n}\n\nexport class VectorTiles {\n private readonly pool: BasemapWorkers;\n /** The pool is this instance's own (a worker count or URL other than the map's): stopped with it */\n private readonly ownPool: boolean;\n /** Prefix of its renderer keys in the pool's workers */\n private readonly namespace: string;\n private destroyed = false;\n private keys = 0;\n /** Renderers sent to the workers, dropped on destroy */\n private readonly renderers: string[] = [];\n private readonly cleanup: (() => void)[] = [];\n /** Credits of its raster layers */\n private readonly attribution: string | undefined;\n /** Its raster and label layers, removed with it */\n private readonly layers: Layer[] = [];\n /** Its first raster layer: the ground its labels follow */\n private ground: RasterLayer | undefined;\n /** What its layers made in `vectortiles/` use of it */\n private readonly context: VectorTilesContext;\n /** The style once loaded, with its source resolved */\n readonly ready: Promise<LoadedStyle>;\n\n /**\n * Its workers are the map's (shared by every `VectorTiles` of the map, a vector tile decoded once for all of them),\n * unless `workers` or `workerUrl` asks for others than the map's: then it has workers of its own\n */\n constructor(\n private readonly map: GeoMap,\n options: VectorTilesOptions = {},\n ) {\n const { pool, own } = map.basemapWorkers(options.workers, options.workerUrl);\n\n this.pool = pool;\n this.ownPool = own;\n this.namespace = pool.namespace();\n\n const style = options.style ?? OPENFREEMAP_STYLES.positron;\n\n this.attribution = options.attribution ?? styleAttribution(style);\n this.ready = loadStyle(style);\n // Reported once here; `ready`, the raster tiles and the labels fail with it\n this.ready.catch((error: unknown) => {\n if (!this.destroyed) console.warn('isard: vector tiles', error);\n });\n this.context = {\n map,\n ready: this.ready,\n layers: this.layers,\n cleanup: this.cleanup,\n iconPrefix: this.iconPrefix,\n destroyed: () => this.destroyed,\n ground: () => this.ground,\n broadcast: (message) => {\n this.pool.broadcast(message);\n },\n request: (vz, vx, vy, work, signal) => this.request(vz, vx, vy, work, signal),\n renderer: (select, extra, again) => this.renderer(select, extra, again),\n loadSprites: (sprite) => this.loadSprites(sprite),\n addSprites: () => this.addSprites(),\n followView: (update, requests, moving) => {\n this.followView(update, requests, moving);\n },\n };\n }\n\n /** The style's sprites (their JSON and their images), loaded once, for the fill patterns and the icons */\n private sprites: Promise<LoadedSprite[]> | undefined;\n\n /** The style's sprites, kept once all of them came: one that failed is asked for again by the next layer */\n private loadSprites(sprite: Style['sprite']): Promise<LoadedSprite[]> {\n if (this.sprites) return this.sprites;\n\n const wanted = spriteSources(sprite).length;\n const loading: Promise<LoadedSprite[]> = loadSprites(sprite)\n .catch(() => [])\n .then((loaded) => {\n if (loaded.length < wanted && this.sprites === loading) {\n console.warn(\n `isard: ${wanted - loaded.length} of the style's sprites not loaded, its icons and patterns missing`,\n );\n this.sprites = undefined;\n }\n\n return loaded;\n });\n\n this.sprites = loading;\n\n return loading;\n }\n\n /** The style's sprites added to the map's icons, once */\n private spritesAdded: Promise<void> | undefined;\n\n /** The style's sprites among the map's icons (under `iconPrefix`), added once: the labels' icons, the fills'\n * patterns */\n private addSprites(): Promise<void> {\n this.spritesAdded ??= this.ready.then(async ({ style }) => {\n if (!style.sprite) return;\n (await this.loadSprites(style.sprite)).forEach((sprite) => {\n if (!this.destroyed) this.map.icons.addSprite(this.iconPrefix, sprite.icons, () => readPixels(sprite.image));\n });\n });\n\n return this.spritesAdded;\n }\n\n /** Prefix of the names of its sprites' images among the map's icons */\n private get iconPrefix(): string {\n return `${this.namespace}/`;\n }\n\n private request(vz: number, vx: number, vy: number, work: BasemapWork, signal?: AbortSignal) {\n if (this.destroyed) return Promise.reject(new DOMException('isard: vector tiles destroyed', 'AbortError'));\n\n return this.pool.request(this.pool.worker(vz, vx, vy), work, this, signal);\n }\n\n /** Sends a renderer of these layers to every worker (again under `again`, restyled), with the style's sprites if it\n * `draws` the tiles into images with patterns (the raster path: the others take their images in the page); returns\n * its key */\n private async renderer(\n select: (layer: StyleLayer) => boolean,\n extra: StyleLayer[],\n again?: string,\n draws = false,\n ): Promise<Renderer> {\n const { style, tiles, maxzoom, rasters } = await this.ready;\n const key = again ?? rendererKey(this.namespace, this.keys++);\n const layers = [...style.layers.filter(select), ...extra];\n const patterns = draws && layers.some((l) => l.paint?.['fill-pattern'] !== undefined);\n // The images are downloaded once, copied to each worker\n const sprites: Sprite[] = patterns && style.sprite ? await this.loadSprites(style.sprite) : [];\n\n if (this.destroyed) throw new DOMException('isard: vector tiles destroyed', 'AbortError');\n this.pool.broadcast({ type: 'init', key, tiles, maxzoom, layers, rasters, ...(sprites.length ? { sprites } : {}) });\n if (!again) this.renderers.push(key);\n\n return { key, maxzoom, layers };\n }\n\n /**\n * A raster layer drawing the style's fills, lines and circles (or those `layers` keeps, then `extraLayers`, of the\n * same source); `size`: texture size of its tiles (512 by default: sharp lines)\n */\n raster(\n options: {\n layers?: (layer: StyleLayer) => boolean;\n extraLayers?: StyleLayer[];\n size?: number;\n opacity?: number;\n minZoom?: number;\n maxZoom?: number;\n before?: Parameters<GeoMap['addRaster']>[0]['before'];\n } = {},\n ): RasterLayer {\n const { layers = () => true, extraLayers = [], size: texture = 512, opacity = 1, before } = options;\n const drawn = (l: StyleLayer) => l.type !== 'symbol' && layers(l);\n const renderer = this.renderer(drawn, extraLayers, undefined, true);\n\n // Its failure is reported by `ready` and each tile\n renderer.catch(() => undefined);\n\n const loader = async (z: number, x: number, y: number, signal: AbortSignal) => {\n const { key, maxzoom } = await renderer;\n // The vector tile it is drawn from (see the worker)\n const vz = Math.max(0, Math.min(z - 1, maxzoom));\n const shift = z - vz;\n const priority = tilePriority(z, x, y, this.map.getCamera());\n const response = await this.request(\n vz,\n x >> shift,\n y >> shift,\n { type: 'render', key, z, x, y, size: texture, priority },\n signal,\n );\n\n return 'image' in response ? response.image : null;\n };\n const layer = this.map.addRaster({\n url: '',\n size: texture,\n opacity,\n minZoom: options.minZoom ?? 0,\n maxZoom: options.maxZoom ?? 20,\n loader,\n ...(this.attribution ? { attribution: this.attribution } : {}),\n ...(before ? { before } : {}),\n });\n\n this.layers.push(layer);\n this.ground ??= layer;\n\n return layer;\n }\n\n /**\n * An extrusion layer of the polygons of the style's fill layers that `layers` keeps (by default its buildings: the\n * fill or fill-extrusion layers of PLAN IGN's `bati_surf` or OpenMapTiles' `building`), raised by the style\n * given (`height`, `base`, `color`, `ramp`…; the properties of the tiles' features). Its tiles follow the view: at\n * the source's deepest level, the `maxTiles` nearest to the center, from `minZoom` on (15 by default); the tiles\n * leaving the view are dropped.\n */\n extrusions<P = Record<string, unknown>>(options: VectorExtrusionOptions<P> = {}): ExtrusionLayer<P> {\n return extrusions<P>(this.context, options);\n }\n\n /**\n * The wind through the streets around the view, as particles at street level (`height`, default 3 metres) between\n * the style's buildings (`layers`, default its `building` and `bati_surf` layers): their footprints laid on a grid of\n * `cell` metres (default 4) over a square of `size` metres (default 1200) around the view's center, the flow of the\n * air round them a potential flow (it goes round the blocks and faster through the narrow streets; no wake behind\n * them), computed in a worker by the grid module from street level (`minZoom`, default 15) and again when the view\n * leaves the square's middle. `wind` is the wind far away (east and north, m/s, default a light breeze from the\n * south-west); `setWind` changes it at once (the flow is linear in it: nothing computed again), from a model's hour\n * (`windAt`) for instance; `computed` resolves once the first square's flow is there. The other options are the flow\n * layer's (`addFlow`)\n */\n streetWind(options: StreetWindOptions = {}): StreetWindLayer {\n return streetWind(this.context, options);\n }\n\n /**\n * Trees on the style's woods, forests and grass (or the fill layers `layers` keeps) as 3D models, from street level\n * (`minZoom`, default 15): the workers scatter them over the polygons of the vector tiles around the view, `spacing`\n * metres apart (by style layer: 9 in woods, 25 on grass, by default) on a jittered grid, the same trees whenever a\n * tile comes back; the engine draws them all in one instanced draw, on the relief. A low-poly tree by default (its\n * `colors`), or your own glTF (`url`, `data`, about 10 metres high, standing on its origin). Dense around the\n * view's center, fewer and fewer away from it (as the camera moves too), at most `maxInstances` drawn (default\n * 25000); at most `maxTiles` tiles (default 9) and `maxTrees` trees in each (default 30000). The models load the\n * engine with 3D Tiles.\n */\n trees(options: TreesOptions = {}): ModelLayer {\n return trees(this.context, options);\n }\n\n /**\n * Street lamps along the style's streets (the road line layers, or those `layers` keeps) as 3D models, from street\n * level (`minZoom`, default 16): the workers place them `spacing` metres apart (default 30) along each street, every\n * other one on its other side, as far from its middle as its class says; their heads lit at night (`light`). All of\n * them near the ground under the camera, fewer and fewer away from it, at most `maxInstances` drawn (default 15000).\n * The models load the engine with 3D Tiles.\n */\n lamps(options: LampsOptions = {}): ModelLayer {\n return lamps(this.context, options);\n }\n\n /**\n * A layer drawing the style's fills, lines and buildings (or those `layers` keeps; backgrounds as fills, the\n * `fill-extrusion` layers raised into buildings by their height and base height) as geometry instead of images: the\n * workers cut the vector tiles in view into polygons and lines, which the engine draws on the globe and the relief,\n * in the style's order, each style layer over its zoom range. Sharp at any zoom\n * and pitch, picked by feature (`pick` gives its properties and style layer), restyled without cutting the tiles\n * again (`setPaintProperty`, `setLayoutProperty`). Its tiles follow the view, while it moves too, coarser far away in a\n * tilted view, and those leaving it stay until the ones replacing them are there; past the source's deepest level,\n * cut again from its tiles down to level 18 (overzoom: their styles those of their level; a filter reading the zoom\n * holds at the whole zoom under the camera's, as MapLibre evaluates it). The fills' outlines are drawn one\n * pixel wide, the lines' ends as their `line-cap` says, their joins as their `line-join` says (and `line-miter-limit`),\n * offset by `line-offset`; the colors follow the camera's zoom; the fills', lines' and buildings' patterns from the\n * style's sprite (the fills' over the relief too; on the globe, their average color there), the circle layers' points\n * as circles facing the screen, the lines' blur, the fills' and lines' translations. The buildings' roofs (`roofs`)\n * as their data says (`roof:shape`, `roof:height`; flat without, the default), generated from their outline where\n * they have none (`'generated'`), or all flat. `raster` stays the lighter path for heavy styles and small devices.\n * At night (`setSun`) the line layers `streets` keeps glow (by default those whose id names\n * a road, not its casing, a railway, a path or a tunnel).\n */\n vectors(options: VectorsOptions = {}): VectorLayer {\n return vectors(this.context, options);\n }\n\n /**\n * A symbol layer with the labels of the style's symbol layers (or those `layers` keeps), updated as the view\n * moves: the labels of the vector tiles in view, the higher style layers placed first. With a raster layer of\n * the style (`raster`), the tiles follow the levels the ground is drawn at: a tilted view takes coarser tiles far\n * away, with the few labels of a lower zoom, as near the camera it takes the fine ones. Without, the tiles around\n * the center at the zoom of the view. It stays above the layers added after it unless one is moved over it.\n */\n labels(options: LabelsOptions = {}): SymbolLayer<LabelCandidate> {\n return labels(this.context, options);\n }\n\n /**\n * Makes a layer's tiles follow the view: `update` now and where the camera stops (`moveend`), `moving` every\n * `VECTOR_MOVE_REFRESH_MS` while it moves; the `requests` aborted when destroyed\n */\n private followView(update: () => Promise<unknown>, requests: TileRequests, moving: () => unknown): void {\n const refresh = () => {\n update().catch(() => undefined);\n };\n const pace = { timer: 0 };\n const follow = () => {\n if (pace.timer) return;\n pace.timer = window.setTimeout(() => {\n pace.timer = 0;\n Promise.resolve(moving()).catch(() => undefined);\n }, VECTOR_MOVE_REFRESH_MS);\n };\n\n this.cleanup.push(this.map.on('move', follow), this.map.on('moveend', refresh), () => {\n clearTimeout(pace.timer);\n requests.abortAll();\n });\n refresh();\n }\n\n /** Stops its workers' work and removes its raster and label layers from the map (those still there) */\n destroy(): void {\n if (this.destroyed) return;\n this.destroyed = true;\n this.cleanup.forEach((off) => {\n off();\n });\n this.cleanup.length = 0;\n this.layers.forEach((layer) => {\n if (this.map.hasLayer(layer)) layer.remove();\n });\n this.layers.length = 0;\n this.map.dropVectorTiles(this);\n // The page's copy of the sprites (the workers have theirs), and their icons\n this.sprites\n ?.then((sprites) => {\n sprites.forEach((sprite) => {\n sprite.image.close();\n });\n this.map.icons.remove(this.iconPrefix, true);\n })\n .catch(() => undefined);\n if (this.ownPool) {\n this.pool.terminate();\n } else {\n // Shared workers: only its requests stop and its renderers go\n this.pool.cancel(this);\n this.renderers.forEach((key) => {\n this.pool.broadcast({ type: 'drop', key });\n });\n }\n this.renderers.length = 0;\n }\n}\n"]}
1
+ {"version":3,"file":"vectortiles.js","sourceRoot":"","sources":["../../src/basemap/vectortiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAqB,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQ/F,OAAO,EAAE,UAAU,EAA+B,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAyB,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAsB,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAqB,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAgD,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACxG,OAAO,EAEL,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAqB,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAuB,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAuB,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEjF,mFAAmF;AACnF,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;AAgBxG,MAAM,OAAO,WAAW;IA2BH;IA1BF,IAAI,CAAiB;IACtC,oGAAoG;IACnF,OAAO,CAAU;IAClC,wDAAwD;IACvC,SAAS,CAAS;IAC3B,SAAS,GAAG,KAAK,CAAC;IAClB,IAAI,GAAG,CAAC,CAAC;IACjB,wDAAwD;IACvC,SAAS,GAAa,EAAE,CAAC;IACzB,OAAO,GAAmB,EAAE,CAAC;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CACF","sourcesContent":["/**\n * Vector basemaps from a MapLibre style (OpenFreeMap's Positron by default): the fills, lines, circles and raster\n * layers drawn tile by tile in workers into the raster pool, so that they lie on the relief like any basemap and\n * composite with the hillshade in one pass; and the labels of the style's symbol layers in a symbol layer of their own,\n * kept above the application's layers (as MapLibre's `beforeId: firstSymbol` does), listed by the workers, shaped in\n * the page once per vector tile, placed by the engine.\n *\n * Any subset of the style can be drawn on its own raster layer (`raster({ layers })`), at its own place in the stack:\n * rivers from the basemap's data over a flood layer, for instance, restyled with `extraLayers`.\n *\n * The layers other than the raster ones are made in `vectortiles/` (one module each), from what they use of the\n * instance (`VectorTilesContext`); the style's loading is in `vectortiles/style.ts`.\n */\n\nimport type { ExtrusionLayer } from '../layers/extrusions.ts';\nimport { type LoadedSprite, loadSprites, readPixels, spriteSources } from '../layers/icons.ts';\nimport type { Layer, ModelLayer, RasterLayer } from '../layers/layers.ts';\nimport type { SymbolLayer } from '../layers/symbols.ts';\nimport type { VectorLayer } from '../layers/vectors.ts';\nimport type { GeoMap } from '../map.ts';\nimport type { BasemapWork, Sprite } from '../workers/basemap.worker.ts';\nimport type { LabelCandidate, Style, StyleLayer } from './vectorstyle.ts';\nimport type { Renderer, VectorTilesContext } from './vectortiles/context.ts';\nimport { extrusions, type VectorExtrusionOptions } from './vectortiles/extrusions.ts';\nimport { type FurnitureOptions, furniture } from './vectortiles/furniture.ts';\nimport { type LabelsOptions, labels, size, tileLabels } from './vectortiles/labels.ts';\nimport { type LampsOptions, lamps } from './vectortiles/lamps.ts';\nimport type { TileRequests } from './vectortiles/requests.ts';\nimport { type StreetWindLayer, type StreetWindOptions, streetWind } from './vectortiles/street-wind.ts';\nimport {\n type LoadedStyle,\n loadStyle,\n OPENFREEMAP_STYLES,\n PLAN_STYLES,\n styleAttribution,\n VECTOR_BASEMAPS,\n} from './vectortiles/style.ts';\nimport { VECTOR_MOVE_REFRESH_MS } from './vectortiles/tiles.ts';\nimport { type TreesOptions, trees } from './vectortiles/trees.ts';\nimport { dashes, type VectorsOptions, vectors } from './vectortiles/vectors.ts';\nimport { type BasemapWorkers, rendererKey, tilePriority } from './workerpool.ts';\n\n// The names the package and its tests import from here, now made in `vectortiles/`\nexport { dashes, OPENFREEMAP_STYLES, PLAN_STYLES, size, styleAttribution, tileLabels, VECTOR_BASEMAPS };\n\nexport interface VectorTilesOptions {\n /** A style URL or object (default OpenFreeMap's Positron) */\n style?: string | Style;\n /** Workers drawing the tiles (default cores - 1, 1 to 4). The vector tiles of a map share its workers (and their\n * decoded tiles); another count gives these tiles workers of their own */\n workers?: number;\n /** Where to load the worker from, when a bundler does not resolve the default URL (default the map's\n * `basemapWorkerUrl`); another URL than the map's gives these tiles workers of their own */\n workerUrl?: string | URL;\n /** Credits of the tiles, shown while its raster layers are on the map (default: OpenFreeMap's for its styles, the\n * IGN's for PLAN.IGN's) */\n attribution?: string;\n}\n\nexport class VectorTiles {\n private readonly pool: BasemapWorkers;\n /** The pool is this instance's own (a worker count or URL other than the map's): stopped with it */\n private readonly ownPool: boolean;\n /** Prefix of its renderer keys in the pool's workers */\n private readonly namespace: string;\n private destroyed = false;\n private keys = 0;\n /** Renderers sent to the workers, dropped on destroy */\n private readonly renderers: string[] = [];\n private readonly cleanup: (() => void)[] = [];\n /** Credits of its raster layers */\n private readonly attribution: string | undefined;\n /** Its raster and label layers, removed with it */\n private readonly layers: Layer[] = [];\n /** Its first raster layer: the ground its labels follow */\n private ground: RasterLayer | undefined;\n /** What its layers made in `vectortiles/` use of it */\n private readonly context: VectorTilesContext;\n /** The style once loaded, with its source resolved */\n readonly ready: Promise<LoadedStyle>;\n\n /**\n * Its workers are the map's (shared by every `VectorTiles` of the map, a vector tile decoded once for all of them),\n * unless `workers` or `workerUrl` asks for others than the map's: then it has workers of its own\n */\n constructor(\n private readonly map: GeoMap,\n options: VectorTilesOptions = {},\n ) {\n const { pool, own } = map.basemapWorkers(options.workers, options.workerUrl);\n\n this.pool = pool;\n this.ownPool = own;\n this.namespace = pool.namespace();\n\n const style = options.style ?? OPENFREEMAP_STYLES.positron;\n\n this.attribution = options.attribution ?? styleAttribution(style);\n this.ready = loadStyle(style);\n // Reported once here; `ready`, the raster tiles and the labels fail with it\n this.ready.catch((error: unknown) => {\n if (!this.destroyed) console.warn('isard: vector tiles', error);\n });\n this.context = {\n map,\n ready: this.ready,\n layers: this.layers,\n cleanup: this.cleanup,\n iconPrefix: this.iconPrefix,\n destroyed: () => this.destroyed,\n ground: () => this.ground,\n broadcast: (message) => {\n this.pool.broadcast(message);\n },\n request: (vz, vx, vy, work, signal) => this.request(vz, vx, vy, work, signal),\n renderer: (select, extra, again) => this.renderer(select, extra, { again }),\n loadSprites: (sprite) => this.loadSprites(sprite),\n addSprites: () => this.addSprites(),\n followView: (layer, update, requests, moving) => {\n this.followView(layer, update, requests, moving);\n },\n stopWith: (layer, stop) => {\n this.stopWith(layer, stop);\n },\n };\n }\n\n /** The style's sprites (their JSON and their images), loaded once, for the fill patterns and the icons */\n private sprites: Promise<LoadedSprite[]> | undefined;\n\n /** The style's sprites, kept once all of them came: one that failed is asked for again by the next layer */\n private loadSprites(sprite: Style['sprite']): Promise<LoadedSprite[]> {\n if (this.sprites) return this.sprites;\n\n const wanted = spriteSources(sprite).length;\n const loading: Promise<LoadedSprite[]> = loadSprites(sprite)\n .catch(() => [])\n .then((loaded) => {\n if (loaded.length < wanted && this.sprites === loading) {\n console.warn(\n `isard: ${wanted - loaded.length} of the style's sprites not loaded, its icons and patterns missing`,\n );\n this.sprites = undefined;\n }\n\n return loaded;\n });\n\n this.sprites = loading;\n\n return loading;\n }\n\n /** The style's sprites added to the map's icons, once */\n private spritesAdded: Promise<void> | undefined;\n\n /** The style's sprites among the map's icons (under `iconPrefix`), added once: the labels' icons, the fills'\n * patterns */\n private addSprites(): Promise<void> {\n this.spritesAdded ??= this.ready.then(async ({ style }) => {\n if (!style.sprite) return;\n (await this.loadSprites(style.sprite)).forEach((sprite) => {\n if (!this.destroyed) this.map.icons.addSprite(this.iconPrefix, sprite.icons, () => readPixels(sprite.image));\n });\n });\n\n return this.spritesAdded;\n }\n\n /** Prefix of the names of its sprites' images among the map's icons */\n private get iconPrefix(): string {\n return `${this.namespace}/`;\n }\n\n private request(vz: number, vx: number, vy: number, work: BasemapWork, signal?: AbortSignal) {\n if (this.destroyed) return Promise.reject(new DOMException('isard: vector tiles destroyed', 'AbortError'));\n\n return this.map.track(this.pool.request(this.pool.worker(vz, vx, vy), work, this, signal));\n }\n\n /** Sends a renderer of these layers to every worker (`again`: under that key, restyled), with the style's sprites if\n * it `draws` the tiles into images with patterns (the raster path: the others take their images in the page) */\n private async renderer(\n select: (layer: StyleLayer) => boolean,\n extra: StyleLayer[],\n { again, draws = false }: { again?: string | undefined; draws?: boolean } = {},\n ): Promise<Renderer> {\n const { style, tiles, maxzoom, rasters } = await this.ready;\n const key = again ?? rendererKey(this.namespace, this.keys++);\n const layers = [...style.layers.filter(select), ...extra];\n const patterns = draws && layers.some((l) => l.paint?.['fill-pattern'] !== undefined);\n // The images are downloaded once, copied to each worker\n const sprites: Sprite[] = patterns && style.sprite ? await this.loadSprites(style.sprite) : [];\n\n if (this.destroyed) throw new DOMException('isard: vector tiles destroyed', 'AbortError');\n this.pool.broadcast({ type: 'init', key, tiles, maxzoom, layers, rasters, ...(sprites.length ? { sprites } : {}) });\n if (!again) this.renderers.push(key);\n\n return { key, maxzoom, layers };\n }\n\n /**\n * A raster layer drawing the style's fills, lines and circles (or those `layers` keeps, then `extraLayers`, of the\n * same source); `size`: texture size of its tiles (512 by default: sharp lines)\n */\n raster(\n options: {\n layers?: (layer: StyleLayer) => boolean;\n extraLayers?: StyleLayer[];\n size?: number;\n opacity?: number;\n minZoom?: number;\n maxZoom?: number;\n before?: Parameters<GeoMap['addRaster']>[0]['before'];\n } = {},\n ): RasterLayer {\n const { layers = () => true, extraLayers = [], size: texture = 512, opacity = 1, before } = options;\n const drawn = (l: StyleLayer) => l.type !== 'symbol' && layers(l);\n const renderer = this.renderer(drawn, extraLayers, { draws: true });\n\n // Its failure is reported by `ready` and each tile\n renderer.catch(() => undefined);\n\n const loader = async (z: number, x: number, y: number, signal: AbortSignal) => {\n const { key, maxzoom } = await renderer;\n // The vector tile it is drawn from (see the worker)\n const vz = Math.max(0, Math.min(z - 1, maxzoom));\n const shift = z - vz;\n const priority = tilePriority(z, x, y, this.map.getCamera());\n const response = await this.request(\n vz,\n x >> shift,\n y >> shift,\n { type: 'render', key, z, x, y, size: texture, priority },\n signal,\n );\n\n return 'image' in response ? response.image : null;\n };\n const layer = this.map.addRaster({\n url: '',\n size: texture,\n opacity,\n minZoom: options.minZoom ?? 0,\n maxZoom: options.maxZoom ?? 20,\n loader,\n ...(this.attribution ? { attribution: this.attribution } : {}),\n ...(before ? { before } : {}),\n });\n\n this.layers.push(layer);\n this.ground ??= layer;\n\n return layer;\n }\n\n /**\n * An extrusion layer of the polygons of the style's fill layers that `layers` keeps (by default its buildings: the\n * fill or fill-extrusion layers of PLAN IGN's `bati_surf` or OpenMapTiles' `building`), raised by the style\n * given (`height`, `base`, `color`, `ramp`…; the properties of the tiles' features). Its tiles follow the view: at\n * the source's deepest level, the `maxTiles` nearest to the center, from `minZoom` on (15 by default); the tiles\n * leaving the view are dropped.\n */\n extrusions<P = Record<string, unknown>>(options: VectorExtrusionOptions<P> = {}): ExtrusionLayer<P> {\n return extrusions<P>(this.context, options);\n }\n\n /**\n * The wind through the streets around the view, as particles at street level (`height`, default 3 metres) between\n * the style's buildings (`layers`, default its `building` and `bati_surf` layers): their footprints laid on a grid of\n * `cell` metres (default 4) over a square of `size` metres (default 1200) around the view's center, the flow of the\n * air round them a potential flow (it goes round the blocks and faster through the narrow streets; no wake behind\n * them), computed in a worker by the grid module from street level (`minZoom`, default 15) and again when the view\n * leaves the square's middle. `wind` is the wind far away (east and north, m/s, default a light breeze from the\n * south-west); `setWind` changes it at once (the flow is linear in it: nothing computed again), from a model's hour\n * (`windAt`) for instance; `computed` resolves once the first square's flow is there. The other options are the flow\n * layer's (`addFlow`)\n */\n streetWind(options: StreetWindOptions = {}): StreetWindLayer {\n return streetWind(this.context, options);\n }\n\n /**\n * Trees on the style's woods, forests and grass (or the fill layers `layers` keeps) as 3D models, from street level\n * (`minZoom`, default 15): the workers scatter them over the polygons of the vector tiles around the view, `spacing`\n * metres apart (by style layer: 9 in woods, 25 on grass, by default) on a jittered grid, the same trees whenever a\n * tile comes back; the engine draws them all in one instanced draw, on the relief. A low-poly tree by default (its\n * `colors`), or your own glTF (`url`, `data`, about 10 metres high, standing on its origin). Dense around the\n * view's center, fewer and fewer away from it (as the camera moves too), at most `maxInstances` drawn (default\n * 25000); at most `maxTiles` tiles (default 9) and `maxTrees` trees in each (default 30000). The models load the\n * engine with 3D Tiles.\n */\n trees(options: TreesOptions = {}): ModelLayer {\n return trees(this.context, options);\n }\n\n /**\n * Street lamps along the style's streets (the road line layers, or those `layers` keeps) as 3D models, from street\n * level (`minZoom`, default 16): the workers place them `spacing` metres apart (default 30) along each street, every\n * other one on its other side, as far from its middle as its class says; their heads lit at night (`light`). All of\n * them near the ground under the camera, fewer and fewer away from it, at most `maxInstances` drawn (default 15000).\n * The models load the engine with 3D Tiles.\n */\n lamps(options: LampsOptions = {}): ModelLayer {\n return lamps(this.context, options);\n }\n\n /**\n * The street furniture as 3D models, from OpenMapTiles' points of interest of the street: bus shelters at the bus\n * stops, waste baskets, post boxes, drinking fountains (Wallace's in Paris), bicycle racks, each facing its street;\n * benches along the pedestrian streets and the paths of the parks and gardens. Placed by the workers, one instanced\n * draw a kind, all of them near the camera and fewer away from it. The layer returned holds the other kinds' (its\n * `companions`); removed with it\n */\n furniture(options: FurnitureOptions = {}): ModelLayer {\n return furniture(this.context, options);\n }\n\n /**\n * A layer drawing the style's fills, lines and buildings (or those `layers` keeps; backgrounds as fills, the\n * `fill-extrusion` layers raised into buildings by their height and base height) as geometry instead of images: the\n * workers cut the vector tiles in view into polygons and lines, which the engine draws on the globe and the relief,\n * in the style's order, each style layer over its zoom range. Sharp at any zoom\n * and pitch, picked by feature (`pick` gives its properties and style layer), restyled without cutting the tiles\n * again (`setPaintProperty`, `setLayoutProperty`). Its tiles follow the view, while it moves too, coarser far away in a\n * tilted view, and those leaving it stay until the ones replacing them are there; past the source's deepest level,\n * cut again from its tiles down to level 18 (overzoom: their styles those of their level; a filter reading the zoom\n * holds at the whole zoom under the camera's, as MapLibre evaluates it). The fills' outlines are drawn one\n * pixel wide, the lines' ends as their `line-cap` says, their joins as their `line-join` says (and `line-miter-limit`),\n * offset by `line-offset`; the colors follow the camera's zoom; the fills', lines' and buildings' patterns from the\n * style's sprite (the fills' over the relief too; on the globe, their average color there), the circle layers' points\n * as circles facing the screen, the lines' blur, the fills' and lines' translations. The buildings' roofs (`roofs`)\n * as their data says (`roof:shape`, `roof:height`; flat without, the default), generated from their outline where\n * they have none (`'generated'`), or all flat. `raster` stays the lighter path for heavy styles and small devices.\n * At night (`setSun`) the line layers `streets` keeps glow (by default those whose id names\n * a road, not its casing, a railway, a path or a tunnel).\n */\n vectors(options: VectorsOptions = {}): VectorLayer {\n return vectors(this.context, options);\n }\n\n /**\n * A symbol layer with the labels of the style's symbol layers (or those `layers` keeps), updated as the view\n * moves: the labels of the vector tiles in view, the higher style layers placed first. With a raster layer of\n * the style (`raster`), the tiles follow the levels the ground is drawn at: a tilted view takes coarser tiles far\n * away, with the few labels of a lower zoom, as near the camera it takes the fine ones. Without, the tiles around\n * the center at the zoom of the view. It stays above the layers added after it unless one is moved over it.\n */\n labels(options: LabelsOptions = {}): SymbolLayer<LabelCandidate> {\n return labels(this.context, options);\n }\n\n /**\n * Makes a layer's tiles follow the view: `update` now and where the camera stops (`moveend`), `moving` every\n * `VECTOR_MOVE_REFRESH_MS` while it moves; the `requests` aborted when destroyed or the layer removed\n */\n private followView(\n layer: Layer,\n update: () => Promise<unknown>,\n requests: TileRequests,\n moving: () => unknown,\n ): void {\n const refresh = () => {\n update().catch(() => undefined);\n };\n const pace = { timer: 0 };\n const follow = () => {\n if (pace.timer) return;\n pace.timer = window.setTimeout(() => {\n pace.timer = 0;\n Promise.resolve(moving()).catch(() => undefined);\n }, VECTOR_MOVE_REFRESH_MS);\n };\n const [offMove, offEnd] = [this.map.on('move', follow), this.map.on('moveend', refresh)];\n\n this.stopWith(layer, () => {\n offMove();\n offEnd();\n clearTimeout(pace.timer);\n requests.abortAll();\n });\n refresh();\n }\n\n /** Calls `stop` when destroyed or once `layer` is removed, whichever comes first */\n private stopWith(layer: Layer, stop: () => void): void {\n const once = { done: false };\n const run = () => {\n if (once.done) return;\n once.done = true;\n stop();\n };\n\n this.cleanup.push(run);\n layer.whenRemoved.push(run);\n }\n\n /** Stops its workers' work and removes its raster and label layers from the map (those still there) */\n destroy(): void {\n if (this.destroyed) return;\n this.destroyed = true;\n this.cleanup.forEach((off) => {\n off();\n });\n this.cleanup.length = 0;\n this.layers.forEach((layer) => {\n if (this.map.hasLayer(layer)) layer.remove();\n });\n this.layers.length = 0;\n this.map.dropVectorTiles(this);\n // The page's copy of the sprites (the workers have theirs), and their icons\n this.sprites\n ?.then((sprites) => {\n sprites.forEach((sprite) => {\n sprite.image.close();\n });\n this.map.icons.remove(this.iconPrefix, true);\n })\n .catch(() => undefined);\n if (this.ownPool) {\n this.pool.terminate();\n } else {\n // Shared workers: only its requests stop and its renderers go\n this.pool.cancel(this);\n this.renderers.forEach((key) => {\n this.pool.broadcast({ type: 'drop', key });\n });\n }\n this.renderers.length = 0;\n }\n}\n"]}
@@ -5,8 +5,7 @@
5
5
  import { epsgCode, isGeographic } from "../data/crs.js";
6
6
  import { child, children, childText, parseXml } from "../data/xml.js";
7
7
  import { withHeaders } from "../engine/requests.js";
8
- /** Metres per degree, as WMTS counts the scale of a grid in degrees (OGC 07-057r7, 6.1) */
9
- const METRES_PER_DEGREE = (2 * Math.PI * 6378137) / 360;
8
+ import { METRES_PER_DEGREE } from "../util/geo.js";
10
9
  /** The size of a pixel by which WMTS turns scale denominators into resolutions, metres */
11
10
  const PIXEL = 0.00028;
12
11
  const numbers = (text) => (text ?? '').trim().split(/\s+/).map(Number);
@@ -29,6 +28,7 @@ export const parseWmtsGrid = (xml, layer, matrixSet) => {
29
28
  const geographic = isGeographic(crs);
30
29
  // EPSG's geographic CRSs have their latitude first (CRS:84 and the IGN's WGS84G do not)
31
30
  const latFirst = geographic && epsgCode(crs) === 4326 && /EPSG/i.test(crs);
31
+ // Metres per degree, as WMTS counts the scale of a grid in degrees (OGC 07-057r7, 6.1)
32
32
  const unit = geographic ? METRES_PER_DEGREE : 1;
33
33
  const limits = new Map();
34
34
  children(child(link, 'TileMatrixSetLimits'), 'TileMatrixLimits').forEach((l) => {
@@ -1 +1 @@
1
- {"version":3,"file":"wmts.js","sourceRoot":"","sources":["../../src/basemap/wmts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,2FAA2F;AAC3F,MAAM,iBAAiB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG,CAAC;AACxD,0FAA0F;AAC1F,MAAM,KAAK,GAAG,OAAO,CAAC;AAEtB,MAAM,OAAO,GAAG,CAAC,IAAwB,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAE3F;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,KAAa,EAAE,SAAkB,EAAY,EAAE;IACxF,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;IAClD,MAAM,KA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AG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,YAA0B,EAC1B,KAAa,EACb,SAAkB,EAClB,UAAoC,EAAE,EACnB,EAAE;IACrB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,YAAY,EACZ,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC5E,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,UAAU,QAAQ,CAAC,MAAM,4BAA4B,CAAC,CAAC;IAEzF,OAAO,aAAa,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAChE,CAAC,CAAC","sourcesContent":["/**\n * The tile grid of a WMTS layer, read from the service's capabilities: its tile matrix set (CRS, levels, origin, tile\n * sizes), the layer's limits in it and its extent, for `addRaster({ url, grid })`.\n */\nimport { epsgCode, isGeographic } from '../data/crs.ts';\nimport { child, children, childText, parseXml } from '../data/xml.ts';\nimport { withHeaders } from '../engine/requests.ts';\nimport type { TileGrid, TileMatrix } from './grid.ts';\n\n/** Metres per degree, as WMTS counts the scale of a grid in degrees (OGC 07-057r7, 6.1) */\nconst METRES_PER_DEGREE = (2 * Math.PI * 6378137) / 360;\n/** The size of a pixel by which WMTS turns scale denominators into resolutions, metres */\nconst PIXEL = 0.00028;\n\nconst numbers = (text: string | undefined) => (text ?? '').trim().split(/\\s+/).map(Number);\n\n/**\n * The tile grid of `layer` in the capabilities document `xml`: its tile matrix set `matrixSet` (default the layer's\n * first), with the layer's tile limits and longitude-latitude extent. Throws if the layer or the set is missing\n */\nexport const parseWmtsGrid = (xml: string, layer: string, matrixSet?: string): TileGrid => {\n const contents = child(parseXml(xml), 'Contents');\n const entry = children(contents, 'Layer').find((l) => childText(l, 'Identifier') === layer);\n\n if (!entry) throw new Error(`isard: no WMTS layer ${layer}`);\n\n const links = children(entry, 'TileMatrixSetLink');\n const link = matrixSet === undefined ? links[0] : links.find((l) => childText(l, 'TileMatrixSet') === matrixSet);\n const name = childText(link, 'TileMatrixSet');\n const set = children(contents, 'TileMatrixSet').find((s) => childText(s, 'Identifier') === name);\n\n if (!name || !set) throw new Error(`isard: no tile matrix set ${matrixSet ?? ''} for the WMTS layer ${layer}`);\n\n const crs = childText(set, 'SupportedCRS') ?? '';\n const geographic = isGeographic(crs);\n // EPSG's geographic CRSs have their latitude first (CRS:84 and the IGN's WGS84G do not)\n const latFirst = geographic && epsgCode(crs) === 4326 && /EPSG/i.test(crs);\n const unit = geographic ? METRES_PER_DEGREE : 1;\n const limits = new Map<string, TileMatrix['limits']>();\n\n children(child(link, 'TileMatrixSetLimits'), 'TileMatrixLimits').forEach((l) => {\n const limit = (k: string) => Number(childText(l, k));\n\n limits.set(childText(l, 'TileMatrix') ?? '', [\n limit('MinTileCol'),\n limit('MinTileRow'),\n limit('MaxTileCol'),\n limit('MaxTileRow'),\n ]);\n });\n\n const matrices = children(set, 'TileMatrix').map((m): TileMatrix => {\n const id = childText(m, 'Identifier') ?? '';\n const [a = 0, b = 0] = numbers(childText(m, 'TopLeftCorner'));\n const limit = limits.get(id);\n\n return {\n id,\n resolution: (Number(childText(m, 'ScaleDenominator')) * PIXEL) / unit,\n origin: latFirst ? [b, a] : [a, b],\n tileWidth: Number(childText(m, 'TileWidth') ?? 256),\n tileHeight: Number(childText(m, 'TileHeight') ?? 256),\n matrixWidth: Number(childText(m, 'MatrixWidth') ?? Infinity),\n matrixHeight: Number(childText(m, 'MatrixHeight') ?? Infinity),\n ...(limit ? { limits: limit } : {}),\n };\n });\n // A layer's limits leave out the matrices it does not have\n const served = limits.size > 0 ? matrices.filter((m) => limits.has(String(m.id))) : matrices;\n const box = child(entry, 'WGS84BoundingBox');\n const [west = Number.NaN, south = Number.NaN] = numbers(childText(box, 'LowerCorner'));\n const [east = Number.NaN, north = Number.NaN] = numbers(childText(box, 'UpperCorner'));\n const bounds: [number, number, number, number] = [west, south, east, north];\n\n return {\n crs,\n matrices: served,\n name,\n ...(bounds.every(Number.isFinite) ? { bounds } : {}),\n };\n};\n\n/**\n * The tile grid of a WMTS layer, from the service's capabilities at `capabilities` (fetched with CORS), for\n * `addRaster`: `await wmtsGrid('https://…/wmts?SERVICE=WMTS&REQUEST=GetCapabilities', 'LAYER', 'MATRIXSET')`. The\n * raster's URL writes the matrix set, {z} for the matrix, {x} and {y} for the column and the row\n */\nexport const wmtsGrid = async (\n capabilities: string | URL,\n layer: string,\n matrixSet?: string,\n options: { signal?: AbortSignal } = {},\n): Promise<TileGrid> => {\n const response = await fetch(\n capabilities,\n withHeaders(capabilities, options.signal ? { signal: options.signal } : {}),\n );\n\n if (!response.ok) throw new Error(`isard: ${response.status} for the WMTS capabilities`);\n\n return parseWmtsGrid(await response.text(), layer, matrixSet);\n};\n"]}
1
+ {"version":3,"file":"wmts.js","sourceRoot":"","sources":["../../src/basemap/wmts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,0FAA0F;AAC1F,MAAM,KAAK,GAAG,OAAO,CAAC;AAEtB,MAAM,OAAO,GAAG,CAAC,IAAwB,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI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C;IACvF,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IACvF,MAAM,MAAM,GAAqC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAE5E,OAAO;QACL,GAAG;QACH,QAAQ,EAAE,MAAM;QAChB,IAAI;QACJ,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,YAA0B,EAC1B,KAAa,EACb,SAAkB,EAClB,UAAoC,EAAE,EACnB,EAAE;IACrB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,YAAY,EACZ,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC5E,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,UAAU,QAAQ,CAAC,MAAM,4BAA4B,CAAC,CAAC;IAEzF,OAAO,aAAa,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAChE,CAAC,CAAC","sourcesContent":["/**\n * The tile grid of a WMTS layer, read from the service's capabilities: its tile matrix set (CRS, levels, origin, tile\n * sizes), the layer's limits in it and its extent, for `addRaster({ url, grid })`.\n */\nimport { epsgCode, isGeographic } from '../data/crs.ts';\nimport { child, children, childText, parseXml } from '../data/xml.ts';\nimport { withHeaders } from '../engine/requests.ts';\nimport { METRES_PER_DEGREE } from '../util/geo.ts';\nimport type { TileGrid, TileMatrix } from './grid.ts';\n\n/** The size of a pixel by which WMTS turns scale denominators into resolutions, metres */\nconst PIXEL = 0.00028;\n\nconst numbers = (text: string | undefined) => (text ?? '').trim().split(/\\s+/).map(Number);\n\n/**\n * The tile grid of `layer` in the capabilities document `xml`: its tile matrix set `matrixSet` (default the layer's\n * first), with the layer's tile limits and longitude-latitude extent. Throws if the layer or the set is missing\n */\nexport const parseWmtsGrid = (xml: string, layer: string, matrixSet?: string): TileGrid => {\n const contents = child(parseXml(xml), 'Contents');\n const entry = children(contents, 'Layer').find((l) => childText(l, 'Identifier') === layer);\n\n if (!entry) throw new Error(`isard: no WMTS layer ${layer}`);\n\n const links = children(entry, 'TileMatrixSetLink');\n const link = matrixSet === undefined ? links[0] : links.find((l) => childText(l, 'TileMatrixSet') === matrixSet);\n const name = childText(link, 'TileMatrixSet');\n const set = children(contents, 'TileMatrixSet').find((s) => childText(s, 'Identifier') === name);\n\n if (!name || !set) throw new Error(`isard: no tile matrix set ${matrixSet ?? ''} for the WMTS layer ${layer}`);\n\n const crs = childText(set, 'SupportedCRS') ?? '';\n const geographic = isGeographic(crs);\n // EPSG's geographic CRSs have their latitude first (CRS:84 and the IGN's WGS84G do not)\n const latFirst = geographic && epsgCode(crs) === 4326 && /EPSG/i.test(crs);\n // Metres per degree, as WMTS counts the scale of a grid in degrees (OGC 07-057r7, 6.1)\n const unit = geographic ? METRES_PER_DEGREE : 1;\n const limits = new Map<string, TileMatrix['limits']>();\n\n children(child(link, 'TileMatrixSetLimits'), 'TileMatrixLimits').forEach((l) => {\n const limit = (k: string) => Number(childText(l, k));\n\n limits.set(childText(l, 'TileMatrix') ?? '', [\n limit('MinTileCol'),\n limit('MinTileRow'),\n limit('MaxTileCol'),\n limit('MaxTileRow'),\n ]);\n });\n\n const matrices = children(set, 'TileMatrix').map((m): TileMatrix => {\n const id = childText(m, 'Identifier') ?? '';\n const [a = 0, b = 0] = numbers(childText(m, 'TopLeftCorner'));\n const limit = limits.get(id);\n\n return {\n id,\n resolution: (Number(childText(m, 'ScaleDenominator')) * PIXEL) / unit,\n origin: latFirst ? [b, a] : [a, b],\n tileWidth: Number(childText(m, 'TileWidth') ?? 256),\n tileHeight: Number(childText(m, 'TileHeight') ?? 256),\n matrixWidth: Number(childText(m, 'MatrixWidth') ?? Infinity),\n matrixHeight: Number(childText(m, 'MatrixHeight') ?? Infinity),\n ...(limit ? { limits: limit } : {}),\n };\n });\n // A layer's limits leave out the matrices it does not have\n const served = limits.size > 0 ? matrices.filter((m) => limits.has(String(m.id))) : matrices;\n const box = child(entry, 'WGS84BoundingBox');\n const [west = Number.NaN, south = Number.NaN] = numbers(childText(box, 'LowerCorner'));\n const [east = Number.NaN, north = Number.NaN] = numbers(childText(box, 'UpperCorner'));\n const bounds: [number, number, number, number] = [west, south, east, north];\n\n return {\n crs,\n matrices: served,\n name,\n ...(bounds.every(Number.isFinite) ? { bounds } : {}),\n };\n};\n\n/**\n * The tile grid of a WMTS layer, from the service's capabilities at `capabilities` (fetched with CORS), for\n * `addRaster`: `await wmtsGrid('https://…/wmts?SERVICE=WMTS&REQUEST=GetCapabilities', 'LAYER', 'MATRIXSET')`. The\n * raster's URL writes the matrix set, {z} for the matrix, {x} and {y} for the column and the row\n */\nexport const wmtsGrid = async (\n capabilities: string | URL,\n layer: string,\n matrixSet?: string,\n options: { signal?: AbortSignal } = {},\n): Promise<TileGrid> => {\n const response = await fetch(\n capabilities,\n withHeaders(capabilities, options.signal ? { signal: options.signal } : {}),\n );\n\n if (!response.ok) throw new Error(`isard: ${response.status} for the WMTS capabilities`);\n\n return parseWmtsGrid(await response.text(), layer, matrixSet);\n};\n"]}