isard 0.2.1 → 0.3.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 (88) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +2 -2
  3. package/dist/animation.d.ts +18 -0
  4. package/dist/animation.js +84 -0
  5. package/dist/animation.js.map +1 -0
  6. package/dist/basemap.worker.d.ts +16 -1
  7. package/dist/basemap.worker.js +2 -2
  8. package/dist/basemap.worker.js.map +8 -4
  9. package/dist/crs.d.ts +72 -0
  10. package/dist/crs.js +243 -0
  11. package/dist/crs.js.map +1 -0
  12. package/dist/decoder.worker.js +4 -4
  13. package/dist/decoder.worker.js.map +4 -4
  14. package/dist/engine-loader.d.ts +27 -0
  15. package/dist/engine-loader.js +112 -0
  16. package/dist/engine-loader.js.map +1 -0
  17. package/dist/features.d.ts +8 -0
  18. package/dist/features.js +17 -10
  19. package/dist/features.js.map +1 -1
  20. package/dist/geo.d.ts +16 -0
  21. package/dist/geo.js +32 -0
  22. package/dist/geo.js.map +1 -0
  23. package/dist/geoplateforme.d.ts +21 -5
  24. package/dist/geoplateforme.js +47 -12
  25. package/dist/geoplateforme.js.map +1 -1
  26. package/dist/glyphs.d.ts +10 -3
  27. package/dist/glyphs.js +14 -2
  28. package/dist/glyphs.js.map +1 -1
  29. package/dist/gpx.d.ts +11 -0
  30. package/dist/gpx.js +74 -0
  31. package/dist/gpx.js.map +1 -0
  32. package/dist/grid.d.ts +81 -0
  33. package/dist/grid.js +270 -0
  34. package/dist/grid.js.map +1 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.js +5 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/interaction.d.ts +0 -4
  39. package/dist/interaction.js +8 -4
  40. package/dist/interaction.js.map +1 -1
  41. package/dist/isard_bg.wasm +0 -0
  42. package/dist/isard_core_bg.wasm +0 -0
  43. package/dist/kml.d.ts +12 -0
  44. package/dist/kml.js +159 -0
  45. package/dist/kml.js.map +1 -0
  46. package/dist/layers.d.ts +1 -1
  47. package/dist/layers.js +8 -13
  48. package/dist/layers.js.map +1 -1
  49. package/dist/lru.d.ts +22 -0
  50. package/dist/lru.js +52 -0
  51. package/dist/lru.js.map +1 -0
  52. package/dist/map.d.ts +16 -4
  53. package/dist/map.js +72 -302
  54. package/dist/map.js.map +1 -1
  55. package/dist/resample.d.ts +41 -0
  56. package/dist/resample.js +164 -0
  57. package/dist/resample.js.map +1 -0
  58. package/dist/settings.d.ts +39 -0
  59. package/dist/settings.js +104 -0
  60. package/dist/settings.js.map +1 -0
  61. package/dist/symbols.d.ts +12 -1
  62. package/dist/symbols.js +124 -26
  63. package/dist/symbols.js.map +1 -1
  64. package/dist/terrain.d.ts +19 -7
  65. package/dist/terrain.js +40 -28
  66. package/dist/terrain.js.map +1 -1
  67. package/dist/topojson.d.ts +29 -0
  68. package/dist/topojson.js +66 -0
  69. package/dist/topojson.js.map +1 -0
  70. package/dist/types.d.ts +12 -4
  71. package/dist/types.js.map +1 -1
  72. package/dist/vectortiles.d.ts +10 -3
  73. package/dist/vectortiles.js +64 -41
  74. package/dist/vectortiles.js.map +1 -1
  75. package/dist/wasm/isard.d.ts +9 -3
  76. package/dist/wasm/isard.js +8 -2
  77. package/dist/wasm/isard_core.d.ts +1 -1
  78. package/dist/wasm/isard_core.js +8 -2
  79. package/dist/wmts.d.ts +14 -0
  80. package/dist/wmts.js +76 -0
  81. package/dist/wmts.js.map +1 -0
  82. package/dist/xml.d.ts +26 -0
  83. package/dist/xml.js +109 -0
  84. package/dist/xml.js.map +1 -0
  85. package/package.json +1 -1
  86. package/dist/equirectangular.d.ts +0 -35
  87. package/dist/equirectangular.js +0 -143
  88. package/dist/equirectangular.js.map +0 -1
package/dist/kml.js ADDED
@@ -0,0 +1,159 @@
1
+ import { child, children, childText, descendants, parseXml } from "./xml.js";
2
+ /** Positions of a `coordinates` element: `lon,lat[,alt]` tuples separated by spaces */
3
+ function positions(element) {
4
+ const out = [];
5
+ for (const tuple of (element?.text ?? '').trim().split(/\s+/)) {
6
+ const values = tuple.split(',').map(Number);
7
+ if (values.length >= 2 && values.every(Number.isFinite))
8
+ out.push(values);
9
+ }
10
+ return out;
11
+ }
12
+ /** The geometries of an element (a Placemark, a MultiGeometry), in order */
13
+ function geometries(parent) {
14
+ const out = [];
15
+ for (const g of parent.children) {
16
+ if (g.name === 'Point') {
17
+ const [p] = positions(child(g, 'coordinates'));
18
+ if (p)
19
+ out.push({ type: 'Point', coordinates: p });
20
+ }
21
+ else if (g.name === 'LineString' || g.name === 'LinearRing') {
22
+ const line = positions(child(g, 'coordinates'));
23
+ if (line.length >= 2)
24
+ out.push({ type: 'LineString', coordinates: line });
25
+ }
26
+ else if (g.name === 'Polygon') {
27
+ const ring = (b) => positions(child(child(b, 'LinearRing'), 'coordinates'));
28
+ const outer = child(g, 'outerBoundaryIs');
29
+ const rings = [...(outer ? [ring(outer)] : []), ...children(g, 'innerBoundaryIs').map(ring)];
30
+ if ((rings[0]?.length ?? 0) >= 4)
31
+ out.push({ type: 'Polygon', coordinates: rings.filter((r) => r.length >= 4) });
32
+ }
33
+ else if (g.name === 'Track') {
34
+ // gx:Track: its gx:coord, `lon lat alt`
35
+ const line = children(g, 'coord')
36
+ .map((c) => c.text.trim().split(/\s+/).map(Number))
37
+ .filter((p) => p.length >= 2 && p.every(Number.isFinite));
38
+ if (line.length >= 2)
39
+ out.push({ type: 'LineString', coordinates: line });
40
+ }
41
+ else if (g.name === 'MultiGeometry' || g.name === 'MultiTrack') {
42
+ out.push(...geometries(g));
43
+ }
44
+ }
45
+ return out;
46
+ }
47
+ /** One geometry of several: a Multi… of one type, else a collection */
48
+ function merge(list) {
49
+ const [first] = list;
50
+ if (!first)
51
+ return null;
52
+ if (list.length === 1)
53
+ return first;
54
+ const same = list.every((g) => g.type === first.type);
55
+ if (same && first.type === 'Point') {
56
+ return { type: 'MultiPoint', coordinates: list.map((g) => g.coordinates) };
57
+ }
58
+ if (same && first.type === 'LineString') {
59
+ return { type: 'MultiLineString', coordinates: list.map((g) => g.coordinates) };
60
+ }
61
+ if (same && first.type === 'Polygon') {
62
+ return { type: 'MultiPolygon', coordinates: list.map((g) => g.coordinates) };
63
+ }
64
+ return { type: 'GeometryCollection', geometries: list };
65
+ }
66
+ /** A KML color (`aabbggrr`, hexadecimal) as a CSS color and an opacity */
67
+ function color(element) {
68
+ const value = childText(element, 'color')?.replace(/^#/, '');
69
+ if (!value || !/^[\da-f]{8}$/i.test(value))
70
+ return undefined;
71
+ const [a, b, g, r] = [0, 2, 4, 6].map((i) => value.slice(i, i + 2));
72
+ return [`#${r}${g}${b}`.toLowerCase(), Math.round((Number.parseInt(a, 16) / 255) * 1000) / 1000];
73
+ }
74
+ /** The properties of a style (simplestyle's names, as togeojson): stroke, stroke-opacity, stroke-width, fill,
75
+ * fill-opacity, marker-color */
76
+ function styleProperties(style) {
77
+ const out = {};
78
+ if (!style)
79
+ return out;
80
+ const line = child(style, 'LineStyle');
81
+ const stroke = color(line);
82
+ if (stroke)
83
+ [out.stroke, out['stroke-opacity']] = stroke;
84
+ const width = Number(childText(line, 'width'));
85
+ if (childText(line, 'width') !== undefined && Number.isFinite(width))
86
+ out['stroke-width'] = width;
87
+ const poly = child(style, 'PolyStyle');
88
+ const fill = color(poly);
89
+ if (fill)
90
+ [out.fill, out['fill-opacity']] = fill;
91
+ if (childText(poly, 'fill') === '0')
92
+ out['fill-opacity'] = 0;
93
+ if (childText(poly, 'outline') === '0')
94
+ out['stroke-opacity'] = 0;
95
+ const icon = color(child(style, 'IconStyle'));
96
+ if (icon)
97
+ out['marker-color'] = icon[0];
98
+ return out;
99
+ }
100
+ /**
101
+ * The placemarks of a KML document as GeoJSON features: their points, lines (and gx:Track), polygons (with their
102
+ * holes) and MultiGeometry (a Multi… of one type, else a GeometryCollection); their `name`, `description`, extended
103
+ * data (`Data`, `SimpleData`) as properties, and the colors of their style (inline, or shared through `styleUrl` and
104
+ * `StyleMap`) as `stroke`, `stroke-opacity`, `stroke-width`, `fill`, `fill-opacity`, `marker-color`. A placemark
105
+ * without geometry has a null one
106
+ */
107
+ export function parseKml(text) {
108
+ const root = parseXml(text);
109
+ const styles = new Map();
110
+ for (const s of descendants(root, 'Style'))
111
+ if (s.attributes.id)
112
+ styles.set(s.attributes.id, s);
113
+ const maps = new Map();
114
+ for (const m of descendants(root, 'StyleMap')) {
115
+ const normal = children(m, 'Pair').find((p) => childText(p, 'key') === 'normal');
116
+ const url = childText(normal, 'styleUrl');
117
+ if (m.attributes.id && url)
118
+ maps.set(m.attributes.id, url);
119
+ }
120
+ /** The style of a `styleUrl` in this document (`#id`, through a StyleMap) */
121
+ const shared = (url, depth = 0) => {
122
+ const id = url?.slice(url.indexOf('#') + 1);
123
+ if (id === undefined || depth > 4)
124
+ return undefined;
125
+ return styles.get(id) ?? shared(maps.get(id), depth + 1);
126
+ };
127
+ const features = descendants(root, 'Placemark').map((placemark) => {
128
+ const properties = { ...styleProperties(shared(childText(placemark, 'styleUrl'))) };
129
+ Object.assign(properties, styleProperties(child(placemark, 'Style')));
130
+ for (const key of ['name', 'description', 'address', 'styleUrl']) {
131
+ const value = childText(placemark, key);
132
+ if (value !== undefined)
133
+ properties[key] = value;
134
+ }
135
+ const time = childText(child(placemark, 'TimeStamp'), 'when');
136
+ if (time !== undefined)
137
+ properties.time = time;
138
+ const extended = child(placemark, 'ExtendedData');
139
+ for (const data of children(extended, 'Data')) {
140
+ if (data.attributes.name)
141
+ properties[data.attributes.name] = childText(data, 'value') ?? '';
142
+ }
143
+ for (const schema of children(extended, 'SchemaData')) {
144
+ for (const data of children(schema, 'SimpleData')) {
145
+ if (data.attributes.name)
146
+ properties[data.attributes.name] = data.text.trim();
147
+ }
148
+ }
149
+ const id = placemark.attributes.id;
150
+ return {
151
+ type: 'Feature',
152
+ geometry: merge(geometries(placemark)),
153
+ properties: properties,
154
+ ...(id === undefined ? {} : { id }),
155
+ };
156
+ });
157
+ return { type: 'FeatureCollection', features };
158
+ }
159
+ //# source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AAE,YAAY,CAAC,EAAE,CAAC;gBAClD,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI;oBAAE,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAChF,CAAC;QACH,CAAC;QACD,MAAM,EAAE,GAAG,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,OAAO;YACL,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YACtC,UAAU,EAAE,UAAe;YAC3B,GAAG,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;SACpC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,CAAC;AACjD,CAAC","sourcesContent":["/**\n * KML to GeoJSON, for the feature layers: `map.addLines({ data: parseKml(await (await fetch(url)).text()) })`.\n */\nimport type { Feature, FeatureCollection, Geometry, Position, Properties } from './features.ts';\nimport { child, children, childText, descendants, parseXml, type XmlElement } from './xml.ts';\n\n/** Positions of a `coordinates` element: `lon,lat[,alt]` tuples separated by spaces */\nfunction positions(element: XmlElement | undefined): Position[] {\n const out: Position[] = [];\n for (const tuple of (element?.text ?? '').trim().split(/\\s+/)) {\n const values = tuple.split(',').map(Number);\n if (values.length >= 2 && values.every(Number.isFinite)) out.push(values as Position);\n }\n return out;\n}\n\n/** The geometries of an element (a Placemark, a MultiGeometry), in order */\nfunction geometries(parent: XmlElement): Geometry[] {\n const out: Geometry[] = [];\n for (const g of parent.children) {\n if (g.name === 'Point') {\n const [p] = positions(child(g, 'coordinates'));\n if (p) out.push({ type: 'Point', coordinates: p });\n } else if (g.name === 'LineString' || g.name === 'LinearRing') {\n const line = positions(child(g, 'coordinates'));\n if (line.length >= 2) out.push({ type: 'LineString', coordinates: line });\n } else if (g.name === 'Polygon') {\n const ring = (b: XmlElement) => positions(child(child(b, 'LinearRing'), 'coordinates'));\n const outer = child(g, 'outerBoundaryIs');\n const rings = [...(outer ? [ring(outer)] : []), ...children(g, 'innerBoundaryIs').map(ring)];\n if ((rings[0]?.length ?? 0) >= 4) out.push({ type: 'Polygon', coordinates: rings.filter((r) => r.length >= 4) });\n } else if (g.name === 'Track') {\n // gx:Track: its gx:coord, `lon lat alt`\n const line = children(g, 'coord')\n .map((c) => c.text.trim().split(/\\s+/).map(Number))\n .filter((p) => p.length >= 2 && p.every(Number.isFinite)) as Position[];\n if (line.length >= 2) out.push({ type: 'LineString', coordinates: line });\n } else if (g.name === 'MultiGeometry' || g.name === 'MultiTrack') {\n out.push(...geometries(g));\n }\n }\n return out;\n}\n\n/** One geometry of several: a Multi… of one type, else a collection */\nfunction merge(list: Geometry[]): Geometry | null {\n const [first] = list;\n if (!first) return null;\n if (list.length === 1) return first;\n const same = list.every((g) => g.type === first.type);\n if (same && first.type === 'Point') {\n return { type: 'MultiPoint', coordinates: list.map((g) => (g as { coordinates: Position }).coordinates) };\n }\n if (same && first.type === 'LineString') {\n return { type: 'MultiLineString', coordinates: list.map((g) => (g as { coordinates: Position[] }).coordinates) };\n }\n if (same && first.type === 'Polygon') {\n return { type: 'MultiPolygon', coordinates: list.map((g) => (g as { coordinates: Position[][] }).coordinates) };\n }\n return { type: 'GeometryCollection', geometries: list };\n}\n\n/** A KML color (`aabbggrr`, hexadecimal) as a CSS color and an opacity */\nfunction color(element: XmlElement | undefined): [css: string, opacity: number] | undefined {\n const value = childText(element, 'color')?.replace(/^#/, '');\n if (!value || !/^[\\da-f]{8}$/i.test(value)) return undefined;\n const [a, b, g, r] = [0, 2, 4, 6].map((i) => value.slice(i, i + 2));\n return [`#${r}${g}${b}`.toLowerCase(), Math.round((Number.parseInt(a as string, 16) / 255) * 1000) / 1000];\n}\n\n/** The properties of a style (simplestyle's names, as togeojson): stroke, stroke-opacity, stroke-width, fill,\n * fill-opacity, marker-color */\nfunction styleProperties(style: XmlElement | undefined): Properties {\n const out: Properties = {};\n if (!style) return out;\n const line = child(style, 'LineStyle');\n const stroke = color(line);\n if (stroke) [out.stroke, out['stroke-opacity']] = stroke;\n const width = Number(childText(line, 'width'));\n if (childText(line, 'width') !== undefined && Number.isFinite(width)) out['stroke-width'] = width;\n const poly = child(style, 'PolyStyle');\n const fill = color(poly);\n if (fill) [out.fill, out['fill-opacity']] = fill;\n if (childText(poly, 'fill') === '0') out['fill-opacity'] = 0;\n if (childText(poly, 'outline') === '0') out['stroke-opacity'] = 0;\n const icon = color(child(style, 'IconStyle'));\n if (icon) out['marker-color'] = icon[0];\n return out;\n}\n\n/**\n * The placemarks of a KML document as GeoJSON features: their points, lines (and gx:Track), polygons (with their\n * holes) and MultiGeometry (a Multi… of one type, else a GeometryCollection); their `name`, `description`, extended\n * data (`Data`, `SimpleData`) as properties, and the colors of their style (inline, or shared through `styleUrl` and\n * `StyleMap`) as `stroke`, `stroke-opacity`, `stroke-width`, `fill`, `fill-opacity`, `marker-color`. A placemark\n * without geometry has a null one\n */\nexport function parseKml<P = Properties>(text: string): FeatureCollection<P> {\n const root = parseXml(text);\n const styles = new Map<string, XmlElement>();\n for (const s of descendants(root, 'Style')) if (s.attributes.id) styles.set(s.attributes.id, s);\n const maps = new Map<string, string>();\n for (const m of descendants(root, 'StyleMap')) {\n const normal = children(m, 'Pair').find((p) => childText(p, 'key') === 'normal');\n const url = childText(normal, 'styleUrl');\n if (m.attributes.id && url) maps.set(m.attributes.id, url);\n }\n /** The style of a `styleUrl` in this document (`#id`, through a StyleMap) */\n const shared = (url: string | undefined, depth = 0): XmlElement | undefined => {\n const id = url?.slice(url.indexOf('#') + 1);\n if (id === undefined || depth > 4) return undefined;\n return styles.get(id) ?? shared(maps.get(id), depth + 1);\n };\n const features = descendants(root, 'Placemark').map((placemark): Feature<P> => {\n const properties: Properties = { ...styleProperties(shared(childText(placemark, 'styleUrl'))) };\n Object.assign(properties, styleProperties(child(placemark, 'Style')));\n for (const key of ['name', 'description', 'address', 'styleUrl']) {\n const value = childText(placemark, key);\n if (value !== undefined) properties[key] = value;\n }\n const time = childText(child(placemark, 'TimeStamp'), 'when');\n if (time !== undefined) properties.time = time;\n const extended = child(placemark, 'ExtendedData');\n for (const data of children(extended, 'Data')) {\n if (data.attributes.name) properties[data.attributes.name] = childText(data, 'value') ?? '';\n }\n for (const schema of children(extended, 'SchemaData')) {\n for (const data of children(schema, 'SimpleData')) {\n if (data.attributes.name) properties[data.attributes.name] = data.text.trim();\n }\n }\n const id = placemark.attributes.id;\n return {\n type: 'Feature',\n geometry: merge(geometries(placemark)),\n properties: properties as P,\n ...(id === undefined ? {} : { id }),\n };\n });\n return { type: 'FeatureCollection', features };\n}\n"]}
package/dist/layers.d.ts CHANGED
@@ -64,7 +64,7 @@ export interface GroundTexture {
64
64
  export interface GroundOptions {
65
65
  /**
66
66
  * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at
67
- * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_EARTH`: metres of EPSG:3857), exact to
67
+ * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_CIRCUMFERENCE`: metres of EPSG:3857), exact to
68
68
  * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,
69
69
  * `u_pixel_ratio`
70
70
  */
package/dist/layers.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * the map recreates its engine and every layer in order, with the same handle (its id is updated).
4
4
  */
5
5
  import { parseColor, rampTexels, stops } from "./features.js";
6
+ import { mercatorX, mercatorY, toMercator } from "./geo.js";
6
7
  export class Layer {
7
8
  #id = -1;
8
9
  /** @internal */
@@ -120,7 +121,7 @@ export class NetworkLayer extends Layer {
120
121
  }
121
122
  else {
122
123
  // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly
123
- mercator = { nodes: toMercator(nodes), lines: lines && toMercator(lines.points) };
124
+ mercator = { nodes: mercatorPoints(nodes), lines: lines && mercatorPoints(lines.points) };
124
125
  const origin = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];
125
126
  this.kept = {
126
127
  origin,
@@ -172,14 +173,12 @@ function unpack(points, [ox, oy]) {
172
173
  }
173
174
  return out;
174
175
  }
175
- const MAX_LAT = 85.051128779806589;
176
176
  /** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */
177
- function toMercator(lonLat) {
177
+ function mercatorPoints(lonLat) {
178
178
  const out = new Float64Array(lonLat.length);
179
179
  for (let i = 0; i < lonLat.length; i += 2) {
180
- const lat = (Math.max(-MAX_LAT, Math.min(MAX_LAT, lonLat[i + 1] ?? 0)) * Math.PI) / 180;
181
- out[i] = ((lonLat[i] ?? 0) + 180) / 360;
182
- out[i + 1] = 0.5 - Math.log(Math.tan(Math.PI / 4 + lat / 2)) / (2 * Math.PI);
180
+ out[i] = mercatorX(lonLat[i] ?? 0);
181
+ out[i + 1] = mercatorY(lonLat[i + 1] ?? 0);
183
182
  }
184
183
  return out;
185
184
  }
@@ -267,7 +266,7 @@ export class GroundLayer extends Layer {
267
266
  }
268
267
  /** @internal */
269
268
  create(engine) {
270
- const [ax, ay] = mercatorPoint(this.options.anchor);
269
+ const [ax, ay] = toMercator(this.options.anchor);
271
270
  const id = engine.addGround(this.options.code, ax, ay, ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]));
272
271
  for (const [name, texture] of this.textures)
273
272
  this.sendTexture(engine, id, name, texture);
@@ -277,14 +276,10 @@ export class GroundLayer extends Layer {
277
276
  return id;
278
277
  }
279
278
  }
280
- function mercatorPoint([lon, lat]) {
281
- const out = toMercator(Float64Array.of(lon, lat));
282
- return [out[0] ?? 0, out[1] ?? 0];
283
- }
284
279
  /** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */
285
280
  function mercatorBox([west, south, east, north]) {
286
- const [x0, y1] = mercatorPoint([west, south]);
287
- const [x1, y0] = mercatorPoint([east, north]);
281
+ const [x0, y1] = toMercator([west, south]);
282
+ const [x1, y0] = toMercator([east, north]);
288
283
  return [x0, y0, x1, y1];
289
284
  }
290
285
  //# sourceMappingURL=layers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAY9D,MAAM,OAAgB,KAAK;IACzB,GAAG,GAAG,CAAC,CAAC,CAAC;IAET,gBAAgB;IACG,GAAG,CAAY;IAElC,gBAAgB;IAChB,YAAY,GAAc;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,oCAAoC;IACpC,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,wGAAwG;IACxG,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACd,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,sGAAsG;IACtG,YAAY;QACV,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,+FAA+F;IAC/F,MAAM,CAAC,OAAe,IAAS,CAAC;IAKhC,MAAM;QACJ,yEAAyE;QACzE,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACd,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IAC3B,CAAC;IAED,yGAAyG;IACzG,UAAU,CAAC,KAAwB;QACjC,IAAI,CAAC,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CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,iFAAiF;AACjF,SAAS,WAAW,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAmC;IAC/E,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Handles of the layers added to a map. Each one keeps what it needs to be created again: after a WebGL context loss,\n * the map recreates its engine and every layer in order, with the same handle (its id is updated).\n */\nimport { parseColor, rampTexels, stops } from './features.ts';\nimport type {\n LayerHost,\n LonLat,\n NetworkOptions,\n NetworkStyle,\n RasterOptions,\n RasterStyle,\n Tiles3dStyle,\n} from './types.ts';\nimport type { Engine, NetworkStats, Tiles3dStats } from './wasm/isard.js';\n\nexport abstract class Layer {\n #id = -1;\n\n /** @internal */\n protected readonly map: LayerHost;\n\n /** @internal */\n constructor(map: LayerHost) {\n this.map = map;\n }\n\n /** Id of the layer in the engine */\n get id(): number {\n return this.#id;\n }\n\n /** @internal Creates the layer in an engine (again after a context loss); its id is -1 if that fails */\n attach(engine: Engine): void {\n this.#id = -1;\n this.#id = this.create(engine);\n }\n\n /** @internal Forgets its id in an engine that is gone (before the layers are created in a new one) */\n forgetEngine(): void {\n this.#id = -1;\n }\n\n /** @internal Sends what refers to other layers, once every layer of a new engine has its id */\n relink(_engine: Engine): void {}\n\n /** @internal */\n protected abstract create(engine: Engine): number;\n\n remove(): void {\n // Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles\n if (this.#id >= 0) this.map.engine.removeLayer(this.#id);\n this.#id = -1;\n this.map.detach(this);\n this.map.requestRender();\n }\n\n /** Moves the layer under `other`, or on top of every layer (above the labels of a vector basemap too) */\n moveBefore(other: Layer | undefined): void {\n this.map.moveLayer(this, other);\n }\n}\n\n/** Raster tiles (basemaps, overlays) */\nexport class RasterLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: Required<Omit<RasterOptions, 'size' | 'loader' | 'grid' | 'attribution'>> & {\n size: number | undefined;\n loader: RasterOptions['loader'] | undefined;\n },\n ) {\n super(map);\n }\n\n /** Changes the opacity or saturation, the other kept */\n setStyle(style: Partial<RasterStyle>): void;\n /** @deprecated Positional form (saturation back to 1 when not given): `setStyle({ opacity, saturation })` */\n setStyle(opacity: number, saturation?: number): void;\n setStyle(style: Partial<RasterStyle> | number, saturation = 1): void {\n const changed = typeof style === 'number' ? { opacity: style, saturation } : style;\n this.options.opacity = changed.opacity ?? this.options.opacity;\n this.options.saturation = changed.saturation ?? this.options.saturation;\n this.map.engine.setRasterStyle(this.id, this.options.opacity, this.options.saturation);\n this.map.requestRender();\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { url, minZoom, maxZoom, opacity, saturation, size, loader } = this.options;\n return engine.addRaster(url, minZoom, maxZoom, opacity, saturation, size, loader);\n }\n}\n\n/** Line network colored by a value per node (travel time, water depth…) */\nexport class NetworkLayer extends Layer {\n private values: Float32Array | undefined;\n /** Node and line positions in Mercator, kept for a context loss: f32 offsets from an origin (exact to the centimetre\n * across a region, half the memory of f64) */\n private kept: { origin: [number, number]; nodes: Float32Array; lines: Float32Array | undefined } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private geometry: { nodes: Float64Array; edges: Uint32Array; lines: NetworkOptions['lines'] | undefined },\n private costs: Float32Array | undefined,\n private style: NetworkStyle,\n private edgeWidths: Float32Array | undefined,\n ) {\n super(map);\n }\n\n /** One value per node, in node order; negative (or 1e30 and above) = unreached. Costs one texture upload, drawn\n * next frame. */\n setValues(values: Float32Array): void {\n this.values = values;\n this.map.engine.setNetworkValues(this.id, values);\n this.map.requestRender();\n }\n\n /** Costs of the edges, A → B then B → A (see `NetworkOptions.costs`), when the way the network is travelled\n * changes; undefined: values interpolated along the edges. The geometry stays on the graphics card. */\n setCosts(costs: Float32Array | undefined): void {\n this.costs = costs;\n this.map.engine.setNetworkCosts(this.id, costs);\n this.map.requestRender();\n }\n\n setStyle(style: Partial<NetworkStyle>): void {\n const ramp = this.style.ramp;\n this.style = { ...this.style, ...style };\n this.map.engine.setNetworkStyle(this.id, networkStyle(this.style));\n if (this.style.ramp !== ramp)\n this.map.engine.setNetworkRamp(this.id, this.style.ramp && rampTexels(this.style.ramp).rgba);\n this.map.requestRender();\n }\n\n /** Width factor of each edge (undefined: 1 for all) */\n setEdgeWidths(widths: Float32Array | undefined): void {\n this.edgeWidths = widths;\n this.map.engine.setNetworkScales(this.id, widths);\n this.map.requestRender();\n }\n\n /** Pieces in all and drawn in the last frame */\n stats(): NetworkStats | undefined {\n return this.map.engine.networkStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { nodes, edges, lines } = this.geometry;\n let mercator: { nodes: Float64Array; lines: Float64Array | undefined };\n if (this.kept) {\n const { origin, nodes: n, lines: l } = this.kept;\n mercator = { nodes: unpack(n, origin), lines: l && unpack(l, origin) };\n } else {\n // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly\n mercator = { nodes: toMercator(nodes), lines: lines && toMercator(lines.points) };\n const origin: [number, number] = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];\n this.kept = {\n origin,\n nodes: pack(mercator.nodes, origin),\n lines: mercator.lines && pack(mercator.lines, origin),\n };\n // The degrees are not needed again: millions of points for a region\n this.geometry = { nodes: EMPTY, edges, lines: lines && { start: lines.start, points: EMPTY } };\n }\n const id = engine.addNetwork(\n mercator.nodes,\n edges,\n lines?.start,\n mercator.lines,\n this.costs,\n networkStyle(this.style),\n );\n if (this.style.ramp) engine.setNetworkRamp(id, rampTexels(this.style.ramp).rgba);\n if (this.edgeWidths) engine.setNetworkScales(id, this.edgeWidths);\n if (this.values) engine.setNetworkValues(id, this.values);\n return id;\n }\n}\n\n/** The 25 numbers of a network style for the engine */\nfunction networkStyle(style: NetworkStyle): Float32Array {\n const { width, halo, max, contour, opacity, haloOpacity, unreachedColor, fade } = style;\n return Float32Array.from([\n ...stops(width),\n ...stops(halo),\n max,\n contour,\n opacity,\n haloOpacity,\n ...parseColor(unreachedColor),\n fade,\n ]);\n}\n\nconst EMPTY = new Float64Array(0);\n\n/** Interleaved points as f32 offsets from an origin, and back */\nfunction pack(points: Float64Array, [ox, oy]: [number, number]): Float32Array {\n const out = new Float32Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) - ox;\n out[i + 1] = (points[i + 1] ?? 0) - oy;\n }\n return out;\n}\n\nfunction unpack(points: Float32Array, [ox, oy]: [number, number]): Float64Array {\n const out = new Float64Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) + ox;\n out[i + 1] = (points[i + 1] ?? 0) + oy;\n }\n return out;\n}\n\nconst MAX_LAT = 85.051128779806589;\n\n/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */\nfunction toMercator(lonLat: Float64Array): Float64Array {\n const out = new Float64Array(lonLat.length);\n for (let i = 0; i < lonLat.length; i += 2) {\n const lat = (Math.max(-MAX_LAT, Math.min(MAX_LAT, lonLat[i + 1] ?? 0)) * Math.PI) / 180;\n out[i] = ((lonLat[i] ?? 0) + 180) / 360;\n out[i + 1] = 0.5 - Math.log(Math.tan(Math.PI / 4 + lat / 2)) / (2 * Math.PI);\n }\n return out;\n}\n\n/** Textured meshes in 3D Tiles */\nexport class Tiles3dLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly url: string,\n private style: Tiles3dStyle,\n ) {\n super(map);\n }\n\n setStyle(style: Partial<Tiles3dStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);\n this.map.requestRender();\n }\n\n /** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see\n * `GeoMapOptions.tiles3d`) */\n stats(): Tiles3dStats | undefined {\n return this.id < 0 ? undefined : this.map.engine.tiles3dStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addTiles3d(this.url, this.style.maxScreenSpaceError);\n engine.setTiles3dStyle(id, this.style.maxScreenSpaceError, this.style.opacity);\n return id;\n }\n}\n\n/** A texture of a ground layer (see `GroundLayer`) */\nexport interface GroundTexture {\n /** `r8`, `r8ui`, `r16ui`, `r16i`, `r32ui`, `r32f`, `rg16ui`, `rg32f`, `rgba8`, `rgba8ui`, `rgba16ui`, `rgba32f`:\n * integer formats are read with `usampler2D` / `isampler2D` and `texelFetch` */\n format: string;\n width: number;\n height: number;\n /** Layers of a 2D array (`sampler2DArray`, `usampler2DArray`…); 0 or undefined: a 2D texture */\n depth?: number;\n /** Linear filtering (non-integer formats); default nearest */\n linear?: boolean;\n /** Texels row after row (layer after layer), any typed array; undefined: left empty */\n data?: ArrayBufferView;\n}\n\nexport interface GroundOptions {\n /**\n * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at\n * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_EARTH`: metres of EPSG:3857), exact to\n * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,\n * `u_pixel_ratio`\n */\n code: string;\n /** Where the offsets are taken from */\n anchor: LonLat;\n /** Box it shows in, `[west, south, east, north]` (default the world): only the ground there is drawn again */\n bounds?: [west: number, south: number, east: number, north: number];\n textures?: Record<string, GroundTexture>;\n uniforms?: Record<string, number | readonly number[]>;\n}\n\nconst bytesOf = (data: ArrayBufferView) => new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n\n/** The application's fragment shader run over the ground, draped on the relief (water depth, heat maps…) */\nexport class GroundLayer extends Layer {\n private readonly textures = new Map<string, GroundTexture>();\n private readonly uniforms = new Map<string, number[]>();\n private visible = true;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: GroundOptions,\n ) {\n super(map);\n for (const [name, texture] of Object.entries(options.textures ?? {})) this.textures.set(name, texture);\n for (const [name, value] of Object.entries(options.uniforms ?? {})) this.uniforms.set(name, [value].flat());\n }\n\n /** Creates or replaces a texture of the code's sampler `name` */\n setTexture(name: string, texture: GroundTexture): void {\n this.textures.set(name, texture);\n this.sendTexture(this.map.engine, this.id, name, texture);\n this.map.requestRender();\n }\n\n /**\n * Replaces a region of a texture: `data` holds `width` × `height` texels for (`x`, `y`) of `layer` (2D arrays).\n * Keep the texture's own `data` up to date too if it must survive a WebGL context loss.\n */\n updateTexture(\n name: string,\n data: ArrayBufferView,\n region: { x?: number; y?: number; layer?: number; width: number; height: number },\n ): void {\n const { x = 0, y = 0, layer = 0, width, height } = region;\n this.map.engine.updateGroundTexture(this.id, name, x, y, layer, width, height, bytesOf(data));\n this.map.requestRender();\n }\n\n /** A uniform of the code: a number, or numbers for vectors, arrays and matrices (column major) */\n setUniform(name: string, value: number | readonly number[]): void {\n const values = [value].flat();\n this.uniforms.set(name, values);\n this.map.engine.setGroundUniform(this.id, name, Float64Array.from(values));\n this.map.requestRender();\n }\n\n setBounds(bounds: [west: number, south: number, east: number, north: number]): void {\n this.options.bounds = bounds;\n this.map.engine.setGroundBounds(this.id, ...mercatorBox(bounds));\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.visible = visible;\n this.map.engine.setGroundVisible(this.id, visible);\n this.map.requestRender();\n }\n\n private sendTexture(engine: Engine, id: number, name: string, t: GroundTexture): void {\n const data = t.data && bytesOf(t.data);\n engine.setGroundTexture(id, name, t.format, t.width, t.height, t.depth ?? 0, t.linear ?? false, data);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const [ax, ay] = mercatorPoint(this.options.anchor);\n const id = engine.addGround(\n this.options.code,\n ax,\n ay,\n ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]),\n );\n for (const [name, texture] of this.textures) this.sendTexture(engine, id, name, texture);\n for (const [name, values] of this.uniforms) engine.setGroundUniform(id, name, Float64Array.from(values));\n engine.setGroundVisible(id, this.visible);\n return id;\n }\n}\n\nfunction mercatorPoint([lon, lat]: LonLat): [number, number] {\n const out = toMercator(Float64Array.of(lon, lat));\n return [out[0] ?? 0, out[1] ?? 0];\n}\n\n/** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */\nfunction mercatorBox([west, south, east, north]: [number, number, number, number]): [number, number, number, number] {\n const [x0, y1] = mercatorPoint([west, south]);\n const [x1, y0] = mercatorPoint([east, north]);\n return [x0, y0, x1, y1];\n}\n"]}
1
+ {"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAY5D,MAAM,OAAgB,KAAK;IACzB,GAAG,GAAG,CAAC,CAAC,CAAC;IAET,gBAAgB;IACG,GAAG,CAAY;IAElC,gBAAgB;IAChB,YAAY,GAAc;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,oCAAoC;IACpC,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,wGAAwG;IACxG,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACd,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,sGAAsG;IACtG,YAAY;QACV,IAAI,CAAC,GAAG,GAAG,CAAC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,GAAG,UAAU,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3C,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Handles of the layers added to a map. Each one keeps what it needs to be created again: after a WebGL context loss,\n * the map recreates its engine and every layer in order, with the same handle (its id is updated).\n */\nimport { parseColor, rampTexels, stops } from './features.ts';\nimport { mercatorX, mercatorY, toMercator } from './geo.ts';\nimport type {\n LayerHost,\n LonLat,\n NetworkOptions,\n NetworkStyle,\n RasterOptions,\n RasterStyle,\n Tiles3dStyle,\n} from './types.ts';\nimport type { Engine, NetworkStats, Tiles3dStats } from './wasm/isard.js';\n\nexport abstract class Layer {\n #id = -1;\n\n /** @internal */\n protected readonly map: LayerHost;\n\n /** @internal */\n constructor(map: LayerHost) {\n this.map = map;\n }\n\n /** Id of the layer in the engine */\n get id(): number {\n return this.#id;\n }\n\n /** @internal Creates the layer in an engine (again after a context loss); its id is -1 if that fails */\n attach(engine: Engine): void {\n this.#id = -1;\n this.#id = this.create(engine);\n }\n\n /** @internal Forgets its id in an engine that is gone (before the layers are created in a new one) */\n forgetEngine(): void {\n this.#id = -1;\n }\n\n /** @internal Sends what refers to other layers, once every layer of a new engine has its id */\n relink(_engine: Engine): void {}\n\n /** @internal */\n protected abstract create(engine: Engine): number;\n\n remove(): void {\n // Not created yet: a 3D Tiles layer waiting for the engine with 3D Tiles\n if (this.#id >= 0) this.map.engine.removeLayer(this.#id);\n this.#id = -1;\n this.map.detach(this);\n this.map.requestRender();\n }\n\n /** Moves the layer under `other`, or on top of every layer (above the labels of a vector basemap too) */\n moveBefore(other: Layer | undefined): void {\n this.map.moveLayer(this, other);\n }\n}\n\n/** Raster tiles (basemaps, overlays) */\nexport class RasterLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: Required<Omit<RasterOptions, 'size' | 'loader' | 'grid' | 'attribution'>> & {\n size: number | undefined;\n loader: RasterOptions['loader'] | undefined;\n },\n ) {\n super(map);\n }\n\n /** Changes the opacity or saturation, the other kept */\n setStyle(style: Partial<RasterStyle>): void;\n /** @deprecated Positional form (saturation back to 1 when not given): `setStyle({ opacity, saturation })` */\n setStyle(opacity: number, saturation?: number): void;\n setStyle(style: Partial<RasterStyle> | number, saturation = 1): void {\n const changed = typeof style === 'number' ? { opacity: style, saturation } : style;\n this.options.opacity = changed.opacity ?? this.options.opacity;\n this.options.saturation = changed.saturation ?? this.options.saturation;\n this.map.engine.setRasterStyle(this.id, this.options.opacity, this.options.saturation);\n this.map.requestRender();\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { url, minZoom, maxZoom, opacity, saturation, size, loader } = this.options;\n return engine.addRaster(url, minZoom, maxZoom, opacity, saturation, size, loader);\n }\n}\n\n/** Line network colored by a value per node (travel time, water depth…) */\nexport class NetworkLayer extends Layer {\n private values: Float32Array | undefined;\n /** Node and line positions in Mercator, kept for a context loss: f32 offsets from an origin (exact to the centimetre\n * across a region, half the memory of f64) */\n private kept: { origin: [number, number]; nodes: Float32Array; lines: Float32Array | undefined } | undefined;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private geometry: { nodes: Float64Array; edges: Uint32Array; lines: NetworkOptions['lines'] | undefined },\n private costs: Float32Array | undefined,\n private style: NetworkStyle,\n private edgeWidths: Float32Array | undefined,\n ) {\n super(map);\n }\n\n /** One value per node, in node order; negative (or 1e30 and above) = unreached. Costs one texture upload, drawn\n * next frame. */\n setValues(values: Float32Array): void {\n this.values = values;\n this.map.engine.setNetworkValues(this.id, values);\n this.map.requestRender();\n }\n\n /** Costs of the edges, A → B then B → A (see `NetworkOptions.costs`), when the way the network is travelled\n * changes; undefined: values interpolated along the edges. The geometry stays on the graphics card. */\n setCosts(costs: Float32Array | undefined): void {\n this.costs = costs;\n this.map.engine.setNetworkCosts(this.id, costs);\n this.map.requestRender();\n }\n\n setStyle(style: Partial<NetworkStyle>): void {\n const ramp = this.style.ramp;\n this.style = { ...this.style, ...style };\n this.map.engine.setNetworkStyle(this.id, networkStyle(this.style));\n if (this.style.ramp !== ramp)\n this.map.engine.setNetworkRamp(this.id, this.style.ramp && rampTexels(this.style.ramp).rgba);\n this.map.requestRender();\n }\n\n /** Width factor of each edge (undefined: 1 for all) */\n setEdgeWidths(widths: Float32Array | undefined): void {\n this.edgeWidths = widths;\n this.map.engine.setNetworkScales(this.id, widths);\n this.map.requestRender();\n }\n\n /** Pieces in all and drawn in the last frame */\n stats(): NetworkStats | undefined {\n return this.map.engine.networkStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const { nodes, edges, lines } = this.geometry;\n let mercator: { nodes: Float64Array; lines: Float64Array | undefined };\n if (this.kept) {\n const { origin, nodes: n, lines: l } = this.kept;\n mercator = { nodes: unpack(n, origin), lines: l && unpack(l, origin) };\n } else {\n // Mercator here: Math.tan and Math.log run natively, several times faster than in WebAssembly\n mercator = { nodes: mercatorPoints(nodes), lines: lines && mercatorPoints(lines.points) };\n const origin: [number, number] = [mercator.nodes[0] ?? 0, mercator.nodes[1] ?? 0];\n this.kept = {\n origin,\n nodes: pack(mercator.nodes, origin),\n lines: mercator.lines && pack(mercator.lines, origin),\n };\n // The degrees are not needed again: millions of points for a region\n this.geometry = { nodes: EMPTY, edges, lines: lines && { start: lines.start, points: EMPTY } };\n }\n const id = engine.addNetwork(\n mercator.nodes,\n edges,\n lines?.start,\n mercator.lines,\n this.costs,\n networkStyle(this.style),\n );\n if (this.style.ramp) engine.setNetworkRamp(id, rampTexels(this.style.ramp).rgba);\n if (this.edgeWidths) engine.setNetworkScales(id, this.edgeWidths);\n if (this.values) engine.setNetworkValues(id, this.values);\n return id;\n }\n}\n\n/** The 25 numbers of a network style for the engine */\nfunction networkStyle(style: NetworkStyle): Float32Array {\n const { width, halo, max, contour, opacity, haloOpacity, unreachedColor, fade } = style;\n return Float32Array.from([\n ...stops(width),\n ...stops(halo),\n max,\n contour,\n opacity,\n haloOpacity,\n ...parseColor(unreachedColor),\n fade,\n ]);\n}\n\nconst EMPTY = new Float64Array(0);\n\n/** Interleaved points as f32 offsets from an origin, and back */\nfunction pack(points: Float64Array, [ox, oy]: [number, number]): Float32Array {\n const out = new Float32Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) - ox;\n out[i + 1] = (points[i + 1] ?? 0) - oy;\n }\n return out;\n}\n\nfunction unpack(points: Float32Array, [ox, oy]: [number, number]): Float64Array {\n const out = new Float64Array(points.length);\n for (let i = 0; i < points.length; i += 2) {\n out[i] = (points[i] ?? 0) + ox;\n out[i + 1] = (points[i + 1] ?? 0) + oy;\n }\n return out;\n}\n\n/** Longitudes and latitudes (degrees, interleaved) to Mercator [0, 1], y towards the south */\nfunction mercatorPoints(lonLat: Float64Array): Float64Array {\n const out = new Float64Array(lonLat.length);\n for (let i = 0; i < lonLat.length; i += 2) {\n out[i] = mercatorX(lonLat[i] ?? 0);\n out[i + 1] = mercatorY(lonLat[i + 1] ?? 0);\n }\n return out;\n}\n\n/** Textured meshes in 3D Tiles */\nexport class Tiles3dLayer extends Layer {\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly url: string,\n private style: Tiles3dStyle,\n ) {\n super(map);\n }\n\n setStyle(style: Partial<Tiles3dStyle>): void {\n this.style = { ...this.style, ...style };\n // Kept for its creation while the engine with 3D Tiles loads\n if (this.id < 0) return;\n this.map.engine.setTiles3dStyle(this.id, this.style.maxScreenSpaceError, this.style.opacity);\n this.map.requestRender();\n }\n\n /** Loading counters; undefined once the layer is removed, and while the engine with 3D Tiles loads (see\n * `GeoMapOptions.tiles3d`) */\n stats(): Tiles3dStats | undefined {\n return this.id < 0 ? undefined : this.map.engine.tiles3dStats(this.id);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addTiles3d(this.url, this.style.maxScreenSpaceError);\n engine.setTiles3dStyle(id, this.style.maxScreenSpaceError, this.style.opacity);\n return id;\n }\n}\n\n/** A texture of a ground layer (see `GroundLayer`) */\nexport interface GroundTexture {\n /** `r8`, `r8ui`, `r16ui`, `r16i`, `r32ui`, `r32f`, `rg16ui`, `rg32f`, `rgba8`, `rgba8ui`, `rgba16ui`, `rgba32f`:\n * integer formats are read with `usampler2D` / `isampler2D` and `texelFetch` */\n format: string;\n width: number;\n height: number;\n /** Layers of a 2D array (`sampler2DArray`, `usampler2DArray`…); 0 or undefined: a 2D texture */\n depth?: number;\n /** Linear filtering (non-integer formats); default nearest */\n linear?: boolean;\n /** Texels row after row (layer after layer), any typed array; undefined: left empty */\n data?: ArrayBufferView;\n}\n\nexport interface GroundOptions {\n /**\n * GLSL ES 3.0 defining `vec4 ground(vec2 offset)`: the color of the ground (premultiplied alpha, 0 for nothing) at\n * `offset`, the Mercator offset of the pixel from `anchor` (times `ISARD_CIRCUMFERENCE`: metres of EPSG:3857), exact to\n * the millimetre at any zoom. The code declares its own uniforms and samplers; also there: `u_zoom`,\n * `u_pixel_ratio`\n */\n code: string;\n /** Where the offsets are taken from */\n anchor: LonLat;\n /** Box it shows in, `[west, south, east, north]` (default the world): only the ground there is drawn again */\n bounds?: [west: number, south: number, east: number, north: number];\n textures?: Record<string, GroundTexture>;\n uniforms?: Record<string, number | readonly number[]>;\n}\n\nconst bytesOf = (data: ArrayBufferView) => new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n\n/** The application's fragment shader run over the ground, draped on the relief (water depth, heat maps…) */\nexport class GroundLayer extends Layer {\n private readonly textures = new Map<string, GroundTexture>();\n private readonly uniforms = new Map<string, number[]>();\n private visible = true;\n\n /** @internal */\n constructor(\n map: LayerHost,\n private readonly options: GroundOptions,\n ) {\n super(map);\n for (const [name, texture] of Object.entries(options.textures ?? {})) this.textures.set(name, texture);\n for (const [name, value] of Object.entries(options.uniforms ?? {})) this.uniforms.set(name, [value].flat());\n }\n\n /** Creates or replaces a texture of the code's sampler `name` */\n setTexture(name: string, texture: GroundTexture): void {\n this.textures.set(name, texture);\n this.sendTexture(this.map.engine, this.id, name, texture);\n this.map.requestRender();\n }\n\n /**\n * Replaces a region of a texture: `data` holds `width` × `height` texels for (`x`, `y`) of `layer` (2D arrays).\n * Keep the texture's own `data` up to date too if it must survive a WebGL context loss.\n */\n updateTexture(\n name: string,\n data: ArrayBufferView,\n region: { x?: number; y?: number; layer?: number; width: number; height: number },\n ): void {\n const { x = 0, y = 0, layer = 0, width, height } = region;\n this.map.engine.updateGroundTexture(this.id, name, x, y, layer, width, height, bytesOf(data));\n this.map.requestRender();\n }\n\n /** A uniform of the code: a number, or numbers for vectors, arrays and matrices (column major) */\n setUniform(name: string, value: number | readonly number[]): void {\n const values = [value].flat();\n this.uniforms.set(name, values);\n this.map.engine.setGroundUniform(this.id, name, Float64Array.from(values));\n this.map.requestRender();\n }\n\n setBounds(bounds: [west: number, south: number, east: number, north: number]): void {\n this.options.bounds = bounds;\n this.map.engine.setGroundBounds(this.id, ...mercatorBox(bounds));\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.visible = visible;\n this.map.engine.setGroundVisible(this.id, visible);\n this.map.requestRender();\n }\n\n private sendTexture(engine: Engine, id: number, name: string, t: GroundTexture): void {\n const data = t.data && bytesOf(t.data);\n engine.setGroundTexture(id, name, t.format, t.width, t.height, t.depth ?? 0, t.linear ?? false, data);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const [ax, ay] = toMercator(this.options.anchor);\n const id = engine.addGround(\n this.options.code,\n ax,\n ay,\n ...mercatorBox(this.options.bounds ?? [-180, -85.06, 180, 85.06]),\n );\n for (const [name, texture] of this.textures) this.sendTexture(engine, id, name, texture);\n for (const [name, values] of this.uniforms) engine.setGroundUniform(id, name, Float64Array.from(values));\n engine.setGroundVisible(id, this.visible);\n return id;\n }\n}\n\n/** A lon/lat box to Mercator min x, min y, max x, max y (y towards the south) */\nfunction mercatorBox([west, south, east, north]: [number, number, number, number]): [number, number, number, number] {\n const [x0, y1] = toMercator([west, south]);\n const [x1, y0] = toMercator([east, north]);\n return [x0, y0, x1, y1];\n}\n"]}
package/dist/lru.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A cache keeping its most recently used entries (the decoded tiles and images of the workers, the source tiles of a
3
+ * reprojection, the labels of the vector tiles): a `Map` in order of use, the least recent dropped past `capacity`.
4
+ */
5
+ export declare class Lru<K, V> {
6
+ capacity: number;
7
+ private readonly evict?;
8
+ private readonly entries;
9
+ /** `evict`: told of each entry dropped for room (not of those deleted) */
10
+ constructor(capacity: number, evict?: ((value: V, key: K) => void) | undefined);
11
+ get size(): number;
12
+ /** The value of a key, now the most recently used; undefined if absent */
13
+ get(key: K): V | undefined;
14
+ /** Whether a key is kept, without using it */
15
+ has(key: K): boolean;
16
+ /** Adds or replaces a value, the most recently used; drops the least recent ones past the capacity */
17
+ set(key: K, value: V): void;
18
+ delete(key: K): boolean;
19
+ /** The values, least recently used first */
20
+ values(): IterableIterator<V>;
21
+ clear(): void;
22
+ }
package/dist/lru.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A cache keeping its most recently used entries (the decoded tiles and images of the workers, the source tiles of a
3
+ * reprojection, the labels of the vector tiles): a `Map` in order of use, the least recent dropped past `capacity`.
4
+ */
5
+ export class Lru {
6
+ capacity;
7
+ evict;
8
+ entries = new Map();
9
+ /** `evict`: told of each entry dropped for room (not of those deleted) */
10
+ constructor(capacity, evict) {
11
+ this.capacity = capacity;
12
+ this.evict = evict;
13
+ }
14
+ get size() {
15
+ return this.entries.size;
16
+ }
17
+ /** The value of a key, now the most recently used; undefined if absent */
18
+ get(key) {
19
+ const value = this.entries.get(key);
20
+ if (value !== undefined) {
21
+ this.entries.delete(key);
22
+ this.entries.set(key, value);
23
+ }
24
+ return value;
25
+ }
26
+ /** Whether a key is kept, without using it */
27
+ has(key) {
28
+ return this.entries.has(key);
29
+ }
30
+ /** Adds or replaces a value, the most recently used; drops the least recent ones past the capacity */
31
+ set(key, value) {
32
+ this.entries.delete(key);
33
+ this.entries.set(key, value);
34
+ for (const [oldest, old] of this.entries) {
35
+ if (this.entries.size <= this.capacity)
36
+ break;
37
+ this.entries.delete(oldest);
38
+ this.evict?.(old, oldest);
39
+ }
40
+ }
41
+ delete(key) {
42
+ return this.entries.delete(key);
43
+ }
44
+ /** The values, least recently used first */
45
+ values() {
46
+ return this.entries.values();
47
+ }
48
+ clear() {
49
+ this.entries.clear();
50
+ }
51
+ }
52
+ //# sourceMappingURL=lru.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru.js","sourceRoot":"","sources":["../src/lru.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,GAAG;IAKL;IACU;IALF,OAAO,GAAG,IAAI,GAAG,EAAQ,CAAC;IAE3C,0EAA0E;IAC1E,YACS,QAAgB,EACN,KAAkC;QAD5C,aAAQ,GAAR,QAAQ,CAAQ;QACN,UAAK,GAAL,KAAK,CAA6B;IAClD,CAAC;IAEJ,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,0EAA0E;IAC1E,GAAG,CAAC,GAAM;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,8CAA8C;IAC9C,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,sGAAsG;IACtG,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC7B,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ;gBAAE,MAAM;YAC9C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,MAAM,CAAC,GAAM;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,4CAA4C;IAC5C,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF","sourcesContent":["/**\n * A cache keeping its most recently used entries (the decoded tiles and images of the workers, the source tiles of a\n * reprojection, the labels of the vector tiles): a `Map` in order of use, the least recent dropped past `capacity`.\n */\nexport class Lru<K, V> {\n private readonly entries = new Map<K, V>();\n\n /** `evict`: told of each entry dropped for room (not of those deleted) */\n constructor(\n public capacity: number,\n private readonly evict?: (value: V, key: K) => void,\n ) {}\n\n get size(): number {\n return this.entries.size;\n }\n\n /** The value of a key, now the most recently used; undefined if absent */\n get(key: K): V | undefined {\n const value = this.entries.get(key);\n if (value !== undefined) {\n this.entries.delete(key);\n this.entries.set(key, value);\n }\n return value;\n }\n\n /** Whether a key is kept, without using it */\n has(key: K): boolean {\n return this.entries.has(key);\n }\n\n /** Adds or replaces a value, the most recently used; drops the least recent ones past the capacity */\n set(key: K, value: V): void {\n this.entries.delete(key);\n this.entries.set(key, value);\n for (const [oldest, old] of this.entries) {\n if (this.entries.size <= this.capacity) break;\n this.entries.delete(oldest);\n this.evict?.(old, oldest);\n }\n }\n\n delete(key: K): boolean {\n return this.entries.delete(key);\n }\n\n /** The values, least recently used first */\n values(): IterableIterator<V> {\n return this.entries.values();\n }\n\n clear(): void {\n this.entries.clear();\n }\n}\n"]}
package/dist/map.d.ts CHANGED
@@ -6,8 +6,6 @@ import { SymbolLayer, type SymbolOptions } from './symbols.ts';
6
6
  import type { AnimationOptions, AtmosphereOptions, Basemap, FeatureHit, FlyToOptions, GeoMapOptions, LoadingMode, LonLat, MapEvents, NetworkOptions, Point, Projection, RasterOptions, TerrainModel, TerrainOptions, Tiles3dOptions } from './types.ts';
7
7
  import { VectorTiles, type VectorTilesOptions } from './vectortiles.ts';
8
8
  import type { Camera, PickHit, RasterLayerStats } from './wasm/isard.js';
9
- /** MapLibre's default easing: cubic Bézier (0.25, 0.1, 0.25, 1) */
10
- export declare function defaultEasing(t: number): number;
11
9
  /** A map (see `GeoMap.create`); layers take it as their host */
12
10
  export declare class GeoMap {
13
11
  #private;
@@ -18,6 +16,8 @@ export declare class GeoMap {
18
16
  private vector;
19
17
  private readonly glyphsUrl;
20
18
  private readonly basemapWorkerUrl;
19
+ /** Texture size of the vector basemap's tiles */
20
+ private readonly basemapTileSize;
21
21
  private readonly container;
22
22
  /** Markers and popups, over the canvas */
23
23
  private readonly overlay;
@@ -80,6 +80,9 @@ export declare class GeoMap {
80
80
  private unwatchRatio;
81
81
  /** Stops listening to the canvas's context loss and restoration */
82
82
  private readonly unwatchContext;
83
+ /** The loaders of the relief by encoding, URL and floor: the same loader for the same tiles (the engine keeps its
84
+ * tiles when only the exaggeration changes) */
85
+ private readonly terrainLoaders;
83
86
  /** Loads the engine (once per page) and creates a map filling `container` */
84
87
  static create(container: HTMLElement, options?: GeoMapOptions): Promise<GeoMap>;
85
88
  private constructor();
@@ -169,8 +172,8 @@ export declare class GeoMap {
169
172
  /** Replaces the basemap and the IGN hillshade, under the other layers (hillshade by default: 0, none). The former
170
173
  * names of the Géoplateforme basemaps (`LegacyBasemap`) are taken under their new ones */
171
174
  setBasemap(basemap: Basemap, hillshade?: number): void;
172
- /** Raster tiles ({z}, {x}, {y} URL; Web Mercator, or reprojected from an equirectangular `grid`), over the layers
173
- * already added */
175
+ /** Raster tiles ({z}, {x}, {y} URL; Web Mercator, or reprojected from another `grid`: longitudes and latitudes,
176
+ * Lambert-93, UTM…), over the layers already added */
174
177
  addRaster(options: RasterOptions & {
175
178
  before?: Layer;
176
179
  }): RasterLayer;
@@ -196,6 +199,15 @@ export declare class GeoMap {
196
199
  * basemap.
197
200
  */
198
201
  vectorTiles(options?: VectorTilesOptions): VectorTiles;
202
+ /**
203
+ * The workers decoding the relief and reprojecting rasters: the map's pool, unless the map has no workers
204
+ * (`workers: false` or 0, or none in this browser): that is done in the page then
205
+ */
206
+ private decodingPool;
207
+ private readonly remoteHeights;
208
+ private readonly remoteReprojection;
209
+ /** The loader of the relief tiles of `url` in a PNG encoding (one per URL, encoding and floor) */
210
+ private readonly terrainLoader;
199
211
  /** Adds a layer, under `before` if given */
200
212
  private place;
201
213
  /** Textured meshes in 3D Tiles (photogrammetry, buildings), drawn with depth over the basemap */