@ml2drender/wasm 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  **A 2D map renderer for MapLibre styles, written in Rust. It needs no GPU.** It compiles to WebAssembly and runs in browsers, Cloudflare Workers, Deno and Node.js. Node-API and Python bindings are also included.
4
4
 
5
- [Live demo](https://kanahiro.github.io/ml2drender/) · [API reference](https://kanahiro.github.io/ml2drender/api/) · [Quick start](#quick-start) · [Projected CRSs](#projected-coordinate-reference-systems) · [Node.js addon](https://github.com/Kanahiro/ml2drender/tree/main/packages/ml2drender-node#readme) · [Python](https://github.com/Kanahiro/ml2drender/tree/main/crates/python#readme)
5
+ [Live demo](https://kanahiro.github.io/ml2drender/) · [API reference](https://kanahiro.github.io/ml2drender/api/) · [Quick start](#quick-start) · [Projected CRSs](#projected-coordinate-reference-systems) · [Node.js addon](https://github.com/Kanahiro/ml2drender/tree/main/packages/ml2drender-node#readme) · [Python](https://github.com/Kanahiro/ml2drender/tree/main/crates/python#readme) ([Colab notebook](https://colab.research.google.com/github/Kanahiro/ml2drender/blob/main/examples/python/quickstart.ipynb))
6
6
 
7
7
  - **No GPU, no native dependencies.** It is a software rasterizer in pure Rust. It runs on `wasm32-unknown-unknown` and links no C libraries.
8
- - **Faithful to MapLibre.** Bucket building, shader math and quantization are ported from MapLibre GL JS. It passes 98.0% of the applicable upstream render tests at GL JS's own tolerances ([conformance](#conformance)).
9
- - **Any projected CRS.** It draws maps directly in a CRS given as PROJJSON: UTM, national grids, LAEA, polar stereographic, Equal Earth, geostationary views and more.
8
+ - **Faithful to MapLibre.** Bucket building, shader math and quantization are ported from MapLibre GL JS. It passes 98.3% of the applicable upstream render tests at GL JS's own tolerances ([conformance](#conformance)).
9
+ - **Any projected CRS.** It draws maps directly in a CRS given as PROJJSON: UTM, national grids (including US State Plane in feet), Albers, LAEA, polar and oblique stereographic, world maps (Equal Earth, Robinson, Mollweide, Winkel Tripel…), orthographic and geostationary views and more.
10
10
  - **MapLibre GL JS in any CRS.** Every source of a style (vector tiles, GeoJSON, raster, DEM) can be reprojected and served on a CRS's tile grid. MapLibre GL JS can then draw the original style in that CRS, with interaction and feature queries.
11
11
  - **Made for serverless.** The core does no network or file I/O; the host fetches everything.
12
12
 
@@ -155,11 +155,15 @@ A `RenderedImage` has:
155
155
  Returns a `ProjectedRenderer` that draws in `crs`. The original renderer is unchanged. `crs` has the same shape as a CRS registered with MapLibre GL JS's `addProjection`:
156
156
 
157
157
  - `projjson`: the CRS as PROJJSON. `render` of a box needs nothing else.
158
- - `tileMatrixSet`: `{ origin: [minX, maxY], extentAtZoom0 }`, required by `renderTile`, `getTile` and `renderView`. A CRS has no tile grid of its own, so tiles and zoom levels mean nothing without one. Tile 0/0/0 is a square of side `extentAtZoom0` whose top-left corner is `origin`. Each zoom level splits every tile into four. x grows to the east and y to the south.
158
+ - `tileMatrixSet`: required by `renderTile`, `getTile` and `renderView`. A CRS has no tile grid of its own, so tiles and zoom levels mean nothing without one. Either form works:
159
+ - `{ origin: [minX, maxY], extentAtZoom0 }`, MapLibre GL JS's grid (`addProjection`). Tile 0/0/0 is a square of side `extentAtZoom0` whose top-left corner is `origin`. Each zoom level splits every tile into four. x grows to the east and y to the south.
160
+ - An [OGC 2D TileMatrixSet](https://docs.ogc.org/is/17-083r4/17-083r4.html) (2.0, JSON), such as `WorldCRS84Quad` or a national grid with its own scales. `z` is an index of its `tileMatrices`, and `x`/`y` range over each level's `matrixWidth`/`matrixHeight`. `pointOfOrigin` is in the CRS's axis order (from `orderedAxes` when it says Lat/Lon or N/E, else from the PROJJSON), and `cornerOfOrigin: "bottomLeft"` counts rows up. Tiles that are not square render `tileSize` wide. `variableMatrixWidths` are not supported. GL JS's `addProjection` takes only the first form, so tiles from `getTile` that GL JS reads with `toStyle`'s style must be cut on that grid (`getTile` itself works with either form).
161
+
162
+ Which to use: the first when the tiles are shown by MapLibre GL JS (pass the `tileMatrixSet` given to `addProjection`), with no limit on zoom levels. An OGC set for a published grid (a TileMatrixSet registry, an OGC API - Tiles server, a national grid), or for one the first cannot describe: scales not halved at each level, tiles not square or not 2^z × 2^z, a fixed list of levels. A GL JS grid is also the OGC set whose level z has 512 × 512 px tiles, `cellSize` = `extentAtZoom0 / 512 / 2^z` and 2^z × 2^z tiles from `origin`.
159
163
 
160
164
  - `name`: the CRS's name in GL JS, required by `toStyle` only.
161
165
 
162
- Projected renders pick a zoom level from CRS units per CSS px, read on EPSG:3857's scale at the equator (the idea behind OGC scale denominators; for longlat, 360° is one trip around the world). That zoom drives style evaluation and source tile selection. It does not depend on position, so tiles of one grid zoom line up at their edges. At high latitudes the zoom is higher than a Mercator map of the same ground resolution would use. It is not the grid zoom given to `renderView`: the two agree only when `extentAtZoom0` is the width of EPSG:3857's world (about 40,075 km, or 360° for longlat).
166
+ Projected renders pick a zoom level from CRS units per CSS px, read on EPSG:3857's scale at the equator (the idea behind OGC scale denominators; for longlat, 360° is one trip around the world). That zoom drives style evaluation and source tile selection. It does not depend on position, so tiles of one grid zoom line up at their edges. At high latitudes the zoom is higher than a Mercator map of the same ground resolution would use. It is not the grid zoom given to `renderView`: the two agree only when `extentAtZoom0` (or the width of a tile of an OGC set's first level) is the width of EPSG:3857's world (about 40,075 km, or 360° for longlat).
163
167
 
164
168
  Besides `renderView`, `render` and `renderTile`, it has two methods for MapLibre GL JS:
165
169
 
@@ -192,9 +196,18 @@ GL JS evaluates the style at its own zoom on the projected grid, and hillshade s
192
196
 
193
197
  ## Projected coordinate reference systems
194
198
 
195
- CRSs are given as PROJJSON (`GeographicCRS` or `ProjectedCRS`). PROJ strings and WKT are not accepted. You can get PROJJSON from `projinfo -o PROJJSON -q EPSG:32654`, for example.
196
-
197
- - **Supported methods:** longlat, Transverse Mercator (UTM, national grids), Mercator (including Web Mercator), Lambert Conformal Conic, Polar Stereographic, Lambert Azimuthal Equal Area, Equal Earth and Geostationary Satellite (geos). Any ellipsoid works. Units must be meters and the prime meridian Greenwich.
199
+ CRSs are given as PROJJSON (`GeographicCRS` or `ProjectedCRS`, or a `BoundCRS` or `CompoundCRS` of one, whose datum shift and vertical part are ignored). PROJ strings and WKT are not accepted. You can get PROJJSON from `projinfo -o PROJJSON -q EPSG:32654`, for example.
200
+
201
+ - **Supported methods:** longlat, Transverse Mercator (UTM, national grids), Mercator (including Web Mercator), Lambert Conformal Conic, Albers Equal Area, Equidistant Conic, Polar and Oblique Stereographic, Hotine Oblique Mercator (variants A and B), Krovak (North Orientated), Lambert Azimuthal Equal Area, Azimuthal Equidistant, Lambert Cylindrical Equal Area, Equidistant Cylindrical, Cassini-Soldner, American Polyconic, Orthographic, Equal Earth, Mollweide, Robinson, Sinusoidal, Natural Earth, Winkel Tripel, Miller Cylindrical and Geostationary Satellite (geos), including EPSG's spherical variants. Any ellipsoid, linear unit (e.g. US survey feet) and prime meridian works. A geographic CRS must use degrees from Greenwich. Results match PROJ 9.8 within a micrometre, except Cassini-Soldner, which follows EPSG's series (within 0.2 mm 1° from the central meridian).
202
+ - **TODO, not supported yet:**
203
+ - Gnomonic and Modified Azimuthal Equidistant (EPSG 9832).
204
+ - South- and west-orientated axes: Transverse Mercator (South Orientated) (EPSG 9808), Lambert Conic Conformal (West Orientated) (EPSG 9826) and Krovak (EPSG 9819, southing/westing). Krovak (North Orientated) works.
205
+ - Other EPSG variants: Mercator (variant C) (EPSG 1044), Polar Stereographic (variant C) (EPSG 9830), Lambert Conic Conformal (2SP Belgium) (EPSG 9803), (2SP Michigan) (EPSG 1051) and Near-Conformal (EPSG 9817), Krovak Modified (EPSG 1042, 1043), Hyperbolic Cassini-Soldner (EPSG 9833), Transverse Mercator Zoned Grid System (EPSG 9824).
206
+ - National and local methods: New Zealand Map Grid (EPSG 9811), Laborde Oblique Mercator (EPSG 9813), Guam Projection (EPSG 9831) and Vertical Perspective (EPSG 9838).
207
+ - Interrupted projections such as Interrupted Goode Homolosine.
208
+ - Other PROJ methods not listed above, such as Bonne, Van der Grinten, Eckert, Hammer and Aitoff.
209
+ - Geographic CRSs with a prime meridian other than Greenwich or angles in units other than degrees.
210
+ - Exact Cassini-Soldner (as PROJ 9) in place of EPSG's series.
198
211
  - **No datum transformations.** Style coordinates (WGS84) are projected as if they were lng/lat on the CRS's ellipsoid.
199
212
  - **Axis order:** always easting first, then northing (longitude, latitude), whatever the CRS's declared axis order.
200
213
  - **How layers are drawn:** background, fill, line, circle, heatmap and symbol layers are drawn from projected vertices directly into the output. Pixel lengths such as line widths, circle radii and text sizes stay constant on screen. raster, hillshade and color-relief layers are drawn in Web Mercator and warped onto a mesh. Areas outside the projection's domain are transparent.
@@ -213,7 +226,7 @@ The [MapLibre GL JS render tests](https://github.com/maplibre/maplibre-gl-js/tre
213
226
 
214
227
  | Suite | Result |
215
228
  |---|---|
216
- | Render tests (1008 applicable) | 988 pass / 20 fail (98.0%) |
229
+ | Render tests (1008 applicable) | 991 pass / 17 fail (98.3%) |
217
230
  | Expression tests (Style Spec, 583) | 581 pass / 2 fail (99.7%) |
218
231
 
219
232
  The 727 tests out of scope cover 3D, pitch, non-Mercator GL projections and runtime style changes. Main known gaps:
@@ -221,6 +234,7 @@ The 727 tests out of scope cover 3D, pitch, non-Mercator GL projections and runt
221
234
  - Bidirectional text and Arabic shaping. Glyphs drawn with browser fonts (TinySDF) are not available either.
222
235
  - History-dependent placement (`prevAnchor`, CrossTileSymbolIndex). Single still images cannot reproduce it.
223
236
  - Locale-sensitive collation, and `number-format` in locales other than en-US.
237
+ - Sub-pixel rounding of the GPU the reference images were drawn with (SwiftShader snaps vertices to 1/16 px). It moves a pixel row or texel in a few tests.
224
238
 
225
239
  ## Architecture
226
240
 
package/dist/index.d.ts CHANGED
@@ -55,9 +55,12 @@ export interface Crs {
55
55
  */
56
56
  name?: string;
57
57
  /**
58
- * PROJJSON of a geographic or projected CRS. Supported methods: Transverse Mercator, Mercator, Pseudo Mercator,
59
- * Lambert Conic Conformal, Polar Stereographic, Lambert Azimuthal Equal Area, Equal Earth and PROJ's
60
- * Geostationary Satellite, without datum shifts.
58
+ * PROJJSON of a geographic or projected CRS (or of a bound or compound CRS of one). Supported methods: Transverse
59
+ * Mercator, Mercator, Pseudo Mercator, Lambert Conic Conformal, Albers Equal Area, Equidistant Conic, Polar and
60
+ * Oblique Stereographic, Hotine Oblique Mercator, Krovak (North Orientated), Cassini-Soldner, American Polyconic,
61
+ * Lambert Azimuthal Equal Area, Azimuthal Equidistant, Lambert Cylindrical Equal Area, Equidistant Cylindrical,
62
+ * Orthographic, Equal Earth, Mollweide, Robinson, Sinusoidal, Natural Earth, Winkel Tripel, Miller Cylindrical and
63
+ * PROJ's Geostationary Satellite, without datum shifts.
61
64
  */
62
65
  projjson: object;
63
66
  /**
@@ -84,25 +87,71 @@ export interface ProjectedBox {
84
87
  /** Non-negative integer CSS pixels of extra coverage, cropped from the output. Default: 0. */
85
88
  margin?: number;
86
89
  }
90
+ /**
91
+ * The tile grid of a CRS, which a CRS does not have by itself: MapLibre GL JS's (`addProjection`), or an OGC 2D
92
+ * TileMatrixSet.
93
+ *
94
+ * Which to use:
95
+ * - {@link QuadTileMatrixSet} when the tiles are shown by MapLibre GL JS: pass the `tileMatrixSet` given to its
96
+ * `addProjection` (GL JS takes only this form, so it is the one for `getTile` tiles GL JS reads). Its zoom levels
97
+ * have no limit.
98
+ * - {@link OgcTileMatrixSet} for a published grid (a TileMatrixSet registry, an OGC API - Tiles server, a national
99
+ * grid) and for grids GL JS's form cannot describe: levels whose scales are not halved each time, tiles that are
100
+ * not square or not 2^z × 2^z, a fixed list of levels.
101
+ *
102
+ * Any GL JS grid is also the OGC set whose level z has 512 × 512 px tiles, `cellSize` = `extentAtZoom0 / 512 / 2^z`
103
+ * and 2^z × 2^z tiles from `origin`; the two render the same tiles.
104
+ */
105
+ export type TileMatrixSet = QuadTileMatrixSet | OgcTileMatrixSet;
87
106
  /**
88
107
  * MapLibre GL JS's `TileMatrixSet` (`addProjection`): tile 0/0/0 is the square of side `extentAtZoom0` whose
89
108
  * top-left corner is `origin`, and each zoom splits every tile in four; x grows east, y south.
90
109
  */
91
- export interface TileMatrixSet {
110
+ export interface QuadTileMatrixSet {
92
111
  /** CRS coordinates of the top-left corner of tile 0/0/0: [min x, max y]. */
93
112
  origin: [number, number];
94
113
  /** Width (= height) of tile 0/0/0 in CRS units. */
95
114
  extentAtZoom0: number;
96
115
  }
116
+ /**
117
+ * An OGC 2D TileMatrixSet (2.0, JSON): a matrix of tiles for each zoom level, `z` its index in `tileMatrices`. Its
118
+ * other members (`id`, `crs`, `scaleDenominator`…) may be there and are not read.
119
+ */
120
+ export interface OgcTileMatrixSet {
121
+ /**
122
+ * The CRS's axes in order. When the first is Lat, Lon, N or E (or their long names), it gives the order of each
123
+ * `pointOfOrigin`; otherwise the PROJJSON's axes do.
124
+ */
125
+ orderedAxes?: string[];
126
+ /** The zoom levels, from the coarsest. */
127
+ tileMatrices: TileMatrix[];
128
+ }
129
+ /** A zoom level of an {@link OgcTileMatrixSet}. `variableMatrixWidths` are not supported. */
130
+ export interface TileMatrix {
131
+ /** CRS units per pixel. */
132
+ cellSize: number;
133
+ /** The corner rows and columns count from, in the CRS's axis order. */
134
+ pointOfOrigin: [number, number];
135
+ /** Rows count down from the top-left corner (default) or up from the bottom-left one. */
136
+ cornerOfOrigin?: 'topLeft' | 'bottomLeft';
137
+ /** Pixels across a tile. */
138
+ tileWidth: number;
139
+ /** Pixels down a tile. */
140
+ tileHeight: number;
141
+ /** Tiles across the matrix. */
142
+ matrixWidth: number;
143
+ /** Tiles down the matrix. */
144
+ matrixHeight: number;
145
+ }
97
146
  /** A source of the style in a tile of a CRS's grid (see `ProjectedRenderer.getTile`). */
98
147
  export interface SourceTile {
99
148
  /** A vector, GeoJSON, raster, raster-dem or image source of the style. */
100
149
  source: string;
101
- /** Zoom level of the CRS's grid: an integer in 0..=30. */
150
+ /** Zoom level of the CRS's grid: an integer in 0..=30 of GL JS's grid, an index of an OGC set's `tileMatrices`. */
102
151
  z: number;
103
- /** Column, from the grid's west edge: an integer in 0..2^z. */
152
+ /** Column, from the grid's west edge: an integer below 2^z (GL JS's grid) or the level's `matrixWidth`. */
104
153
  x: number;
105
- /** Row, from the grid's north edge: an integer in 0..2^z. */
154
+ /** Row, from the grid's north edge (south for `cornerOfOrigin: "bottomLeft"`): below 2^z or `matrixHeight`. */
106
155
  y: number;
107
156
  }
108
157
  /** A `MapRenderer` drawing in a CRS (see `MapRenderer.projected`). */
@@ -111,11 +160,15 @@ export interface ProjectedRenderer {
111
160
  readonly crs: Crs;
112
161
  /** Fetch required resources and return a new RGBA image of `box.bbox` (CRS units). */
113
162
  render(box: ProjectedBox): Promise<RenderedImage>;
114
- /** `render` of tile `z/x/y` of the CRS's grid, `tileSize` CSS pixels (default 256) on a side. */
163
+ /**
164
+ * `render` of tile `z/x/y` of the CRS's grid, `tileSize` CSS pixels (default 256) wide and as high as the grid's
165
+ * tiles are (square in GL JS's grid). Zoom levels and ranges of `z`, `x` and `y` are the grid's.
166
+ */
115
167
  renderTile(tile: Tile): Promise<RenderedImage>;
116
168
  /**
117
- * `render` of MapLibre GL JS's camera in the CRS (registered with `addProjection`): `center` in degrees, tile
118
- * 0/0/0 of the grid in 512 CSS pixels at zoom 0, turned around `center` by `bearing`.
169
+ * `render` of MapLibre GL JS's camera in the CRS (registered with `addProjection`): `center` in degrees, a tile
170
+ * of the grid's first level (tile 0/0/0 of GL JS's) 512 CSS pixels wide at zoom 0, turned around `center` by
171
+ * `bearing`.
119
172
  */
120
173
  renderView(view: View): Promise<RenderedImage>;
121
174
  /**
@@ -214,6 +267,12 @@ export declare class MapRenderer {
214
267
  render(box: LngLatBox): Promise<RenderedImage>;
215
268
  /** This renderer drawing in `crs`, on its tile grid. Resources fetched for one CRS serve the others too. */
216
269
  projected(crs: Crs): ProjectedRenderer;
270
+ /**
271
+ * Tile z/x/y of the grid `grid` (encoded JSON) of the CRS `projjson` (encoded): its box, its height over its width,
272
+ * and the grid's CRS units per CSS pixel of a camera at zoom 0. Throws for a grid the core does not read or a tile
273
+ * not of it.
274
+ */
275
+ private tileMatrix;
217
276
  /** `[lng, lat]` in the CRS `projjson` (encoded); NaN where the CRS has no point. */
218
277
  private forward;
219
278
  private assertUsable;
package/dist/index.js CHANGED
@@ -220,27 +220,15 @@ export class MapRenderer {
220
220
  projected(crs) {
221
221
  if (!crs.projjson || typeof crs.projjson !== 'object')
222
222
  throw new TypeError('crs.projjson must be a PROJJSON object');
223
- const grid = () => {
224
- if (!crs.tileMatrixSet)
225
- throw new TypeError('crs.tileMatrixSet is required for tiles and cameras');
226
- const { origin, extentAtZoom0 } = crs.tileMatrixSet;
227
- if (!origin.every(Number.isFinite) || !(extentAtZoom0 > 0 && Number.isFinite(extentAtZoom0))) {
228
- throw new RangeError('crs.tileMatrixSet must have a finite origin and a finite, positive extentAtZoom0');
229
- }
230
- return crs.tileMatrixSet;
231
- };
232
223
  const projjson = encoder.encode(JSON.stringify(crs.projjson));
233
- // The box of tile z/x/y of the grid.
234
- const box = ({ z, x, y }) => {
235
- const { origin, extentAtZoom0 } = grid();
236
- const n = 2 ** z;
237
- if (!Number.isInteger(z) || z < 0 || z > 30)
238
- throw new RangeError('z must be an integer in 0..=30');
239
- if (!Number.isInteger(x) || !Number.isInteger(y) || x < 0 || y < 0 || x >= n || y >= n)
240
- throw new RangeError('x and y must be integers in 0..2^z');
241
- const s = extentAtZoom0 / n;
242
- const [minX, maxY] = [origin[0] + x * s, origin[1] - y * s];
243
- return [minX, maxY - s, minX + s, maxY];
224
+ const grid = crs.tileMatrixSet && encoder.encode(JSON.stringify(crs.tileMatrixSet));
225
+ // Tile z/x/y of the grid (0/0/0 for the grid's scale only).
226
+ const tile = ({ z, x, y }) => {
227
+ if (!grid)
228
+ throw new TypeError('crs.tileMatrixSet is required for tiles and cameras');
229
+ if (![z, x, y].every((v) => Number.isInteger(v) && v >= 0 && v < 2 ** 32))
230
+ throw new RangeError('z, x and y must be non-negative integers');
231
+ return this.tileMatrix(projjson, grid, z, x, y);
244
232
  };
245
233
  const render = async (view) => this.draw(view, ...this.projectedArgs(projjson, view));
246
234
  return {
@@ -250,10 +238,11 @@ export class MapRenderer {
250
238
  const [width, height] = fitSize(maxX - minX, maxY - minY, size);
251
239
  return render({ bbox, width, height, pixelRatio, margin });
252
240
  },
253
- renderTile: async ({ tileSize = 256, pixelRatio, margin, ...tile }) => {
241
+ renderTile: async ({ tileSize = 256, pixelRatio, margin, ...zxy }) => {
254
242
  if (!Number.isInteger(tileSize) || tileSize < 1)
255
243
  throw new RangeError('tileSize must be a positive integer');
256
- return render({ bbox: box(tile), width: tileSize, height: tileSize, pixelRatio, margin });
244
+ const { bbox, aspect } = tile(zxy);
245
+ return render({ bbox, width: tileSize, height: Math.max(1, Math.round(tileSize * aspect)), pixelRatio, margin });
257
246
  },
258
247
  renderView: async ({ center: [lng, lat], zoom, bearing = 0, width, height, pixelRatio, margin }) => {
259
248
  if (![lng, lat, zoom, bearing].every(Number.isFinite))
@@ -262,16 +251,16 @@ export class MapRenderer {
262
251
  if (!Number.isFinite(x) || !Number.isFinite(y))
263
252
  throw new RangeError('center is outside the CRS');
264
253
  // CRS units per CSS pixel.
265
- const unit = grid().extentAtZoom0 / (512 * 2 ** zoom);
254
+ const unit = tile({ z: 0, x: 0, y: 0 }).unit / 2 ** zoom;
266
255
  const [w, h] = [(width / 2) * unit, (height / 2) * unit];
267
256
  // The box at bearing 0, which the core turns around its center.
268
257
  return render({ bbox: [x - w, y - h, x + w, y + h], bearing, width, height, pixelRatio, margin });
269
258
  },
270
- getTile: async (tile) => {
271
- if (typeof tile.source !== 'string' || !tile.source)
259
+ getTile: async (sourceTile) => {
260
+ if (typeof sourceTile.source !== 'string' || !sourceTile.source)
272
261
  throw new TypeError('source must be a source id');
273
- const view = { bbox: box(tile), width: 512, height: 512 };
274
- return this.run(...this.projectedArgs(projjson, view), encoder.encode(tile.source), this.wasm.renderer_export_tile);
262
+ const view = { bbox: tile(sourceTile).bbox, width: 512, height: 512 };
263
+ return this.run(...this.projectedArgs(projjson, view), encoder.encode(sourceTile.source), this.wasm.renderer_export_tile);
275
264
  },
276
265
  toStyle: ({ tiles }) => {
277
266
  if (typeof crs.name !== 'string' || !crs.name)
@@ -298,6 +287,20 @@ export class MapRenderer {
298
287
  },
299
288
  };
300
289
  }
290
+ /**
291
+ * Tile z/x/y of the grid `grid` (encoded JSON) of the CRS `projjson` (encoded): its box, its height over its width,
292
+ * and the grid's CRS units per CSS pixel of a camera at zoom 0. Throws for a grid the core does not read or a tile
293
+ * not of it.
294
+ */
295
+ tileMatrix(projjson, grid, z, x, y) {
296
+ this.assertUsable();
297
+ const w = this.wasm;
298
+ const ok = this.withBytes(projjson, (pp, pl) => this.withBytes(grid, (gp, gl) => w.tile_matrix(pp, pl, gp, gl, z, x, y)));
299
+ if (!ok)
300
+ throw new RangeError(decoder.decode(this.output()));
301
+ const [minX, minY, maxX, maxY, aspect, unit] = new Float64Array(w.memory.buffer, w.xy_ptr(), 6);
302
+ return { bbox: [minX, minY, maxX, maxY], aspect, unit };
303
+ }
301
304
  /** `[lng, lat]` in the CRS `projjson` (encoded); NaN where the CRS has no point. */
302
305
  forward(projjson, lng, lat) {
303
306
  this.assertUsable();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ml2drender/wasm",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "MapLibre style 2D renderer in pure Rust / WebAssembly, no GPU",
5
5
  "license": "BSD-3-Clause",
6
6
  "repository": {
Binary file