ts-maps 0.3.1 → 0.3.3
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/dist/core-map/control/FullscreenControl.d.ts +39 -0
- package/dist/core-map/control/GeocoderControl.d.ts +61 -0
- package/dist/core-map/control/LocateControl.d.ts +56 -0
- package/dist/core-map/control/NavigationControl.d.ts +39 -0
- package/dist/core-map/control/index.d.ts +8 -0
- package/dist/core-map/game/TerritoryLog.d.ts +66 -0
- package/dist/core-map/game/TerritoryStore.d.ts +59 -0
- package/dist/core-map/game/index.d.ts +11 -0
- package/dist/core-map/game/loop.d.ts +61 -0
- package/dist/core-map/geo/area.d.ts +52 -0
- package/dist/core-map/geo/index.d.ts +30 -0
- package/dist/core-map/geo/index.js +856 -31
- package/dist/core-map/geo/polygonClip.d.ts +75 -0
- package/dist/core-map/geo/validate.d.ts +54 -0
- package/dist/core-map/geometry/index.js +28 -28
- package/dist/core-map/index.d.ts +8 -2
- package/dist/core-map/layer/GeoJSONTileSource.d.ts +50 -0
- package/dist/core-map/layer/RunTrailLayer.d.ts +35 -0
- package/dist/core-map/layer/TerritoryLayer.d.ts +62 -0
- package/dist/core-map/layer/index.d.ts +6 -0
- package/dist/core-map/layer/tile/RasterDEMLayer.d.ts +4 -0
- package/dist/core-map/layer/tile/VectorTileMapLayer.d.ts +59 -11
- package/dist/core-map/layer/tile/urlTemplate.d.ts +1 -2
- package/dist/core-map/map/Map.d.ts +32 -1
- package/dist/core-map/mvt/DecodedTile.d.ts +20 -0
- package/dist/core-map/mvt/FlatTile.d.ts +25 -0
- package/dist/core-map/mvt/VectorTileFeature.d.ts +8 -0
- package/dist/core-map/services/index.js +48 -48
- package/dist/core-map/storage/index.js +5 -5
- package/dist/core-map/style-spec/expressions/formatted.d.ts +36 -0
- package/dist/core-map/style-spec/expressions/operators/binding.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/geometry.d.ts +19 -0
- package/dist/core-map/style-spec/expressions/types.d.ts +3 -0
- package/dist/core-map/style-spec/index.js +460 -60
- package/dist/core-map/style-spec/schema.d.ts +43 -3
- package/dist/core-map/style-spec/types.d.ts +47 -7
- package/dist/core-map/styles/basemap.d.ts +41 -0
- package/dist/core-map/styles/index.d.ts +5 -0
- package/dist/core-map/styles/palette.d.ts +31 -0
- package/dist/core-map/symbols/CollisionIndex.d.ts +22 -5
- package/dist/core-map/symbols/GlyphAtlas.d.ts +6 -1
- package/dist/core-map/symbols/GlyphProvider.d.ts +21 -0
- package/dist/core-map/symbols/GlyphRenderer.d.ts +48 -0
- package/dist/core-map/symbols/IconAtlas.d.ts +10 -1
- package/dist/core-map/symbols/SymbolOverlay.d.ts +47 -0
- package/dist/core-map/symbols/index.d.ts +4 -0
- package/dist/core-map/symbols/index.js +1072 -68
- package/dist/core-map/symbols/loadGlyphs.d.ts +53 -0
- package/dist/core-map/symbols/loadSprite.d.ts +57 -0
- package/dist/core-map/symbols/placement.d.ts +67 -0
- package/dist/core-map/symbols/sdf.d.ts +37 -0
- package/dist/core-map/symbols/sections.d.ts +32 -0
- package/dist/core-map/workers/WorkerPool.d.ts +40 -0
- package/dist/core-map/workers/decodeMvtFlat.d.ts +52 -0
- package/dist/index.js +11783 -6100
- package/package.json +2 -2
- package/src/core-map/ts-maps.css +576 -79
|
@@ -209,6 +209,47 @@ declare const symbolPaint: Record<string, PropertySchema>;
|
|
|
209
209
|
* ```
|
|
210
210
|
*/
|
|
211
211
|
declare const rasterPaint: Record<string, PropertySchema>;
|
|
212
|
+
/**
|
|
213
|
+
* @defaultValue
|
|
214
|
+
* ```ts
|
|
215
|
+
* {
|
|
216
|
+
* 'hillshade-illumination-direction': { type: 'number', default: 335, minimum: 0, maximum: 359, sdk: 'gl' },
|
|
217
|
+
* 'hillshade-illumination-anchor': { type: 'enum', values: ['map', 'viewport'], default: 'viewport', sdk: 'gl' },
|
|
218
|
+
* 'hillshade-exaggeration': {
|
|
219
|
+
* type: 'number',
|
|
220
|
+
* default: 0.5,
|
|
221
|
+
* minimum: 0,
|
|
222
|
+
* maximum: 1,
|
|
223
|
+
* transition: true,
|
|
224
|
+
* sdk: 'gl'
|
|
225
|
+
* },
|
|
226
|
+
* 'hillshade-shadow-color': { type: 'color', default: '#000000', transition: true, sdk: 'gl' },
|
|
227
|
+
* 'hillshade-highlight-color': { type: 'color', default: '#FFFFFF', transition: true, sdk: 'gl' },
|
|
228
|
+
* 'hillshade-accent-color': { type: 'color', default: '#000000', transition: true, sdk: 'gl' }
|
|
229
|
+
* }
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
declare const hillshadePaint: Record<string, PropertySchema>;
|
|
233
|
+
/**
|
|
234
|
+
* @defaultValue
|
|
235
|
+
* ```ts
|
|
236
|
+
* {
|
|
237
|
+
* 'heatmap-radius': { type: 'number', default: 30, minimum: 1, transition: true, sdk: 'gl' },
|
|
238
|
+
* 'heatmap-weight': { type: 'number', default: 1, minimum: 0, sdk: 'gl' },
|
|
239
|
+
* 'heatmap-intensity': { type: 'number', default: 1, minimum: 0, transition: true, sdk: 'gl' },
|
|
240
|
+
* 'heatmap-color': { type: 'color', sdk: 'gl' },
|
|
241
|
+
* 'heatmap-opacity': {
|
|
242
|
+
* type: 'number',
|
|
243
|
+
* default: 1,
|
|
244
|
+
* minimum: 0,
|
|
245
|
+
* maximum: 1,
|
|
246
|
+
* transition: true,
|
|
247
|
+
* sdk: 'gl'
|
|
248
|
+
* }
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare const heatmapPaint: Record<string, PropertySchema>;
|
|
212
253
|
export declare const paintPropertySchemas: Record<LayerType, Record<string, PropertySchema>>;
|
|
213
254
|
// ---------- layout ----------
|
|
214
255
|
declare const visibility: PropertySchema;
|
|
@@ -350,12 +391,11 @@ declare const circleLayout: Record<string, PropertySchema>;
|
|
|
350
391
|
*/
|
|
351
392
|
declare const symbolLayout: Record<string, PropertySchema>;
|
|
352
393
|
declare const rasterLayout: Record<string, PropertySchema>;
|
|
394
|
+
declare const hillshadeLayout: Record<string, PropertySchema>;
|
|
395
|
+
declare const heatmapLayout: Record<string, PropertySchema>;
|
|
353
396
|
export declare const layoutPropertySchemas: Record<LayerType, Record<string, PropertySchema>>;
|
|
354
397
|
// The set of known layer types — exported separately so the validator can
|
|
355
398
|
// decide whether an unknown layer `type` is user error vs. an SDK mismatch.
|
|
356
|
-
// `hillshade` and `heatmap` are intentionally excluded — their renderers
|
|
357
|
-
// ship as standalone classes (`HillshadeLayer`, `HeatmapLayer`) rather
|
|
358
|
-
// than through the style-spec path.
|
|
359
399
|
export declare const layerTypes: readonly LayerType[];
|
|
360
400
|
// Source types we currently recognise in the validator.
|
|
361
401
|
export declare const sourceTypes: readonly string[];
|
|
@@ -26,6 +26,7 @@ export declare interface VectorSourceSpecification {
|
|
|
26
26
|
attribution?: string
|
|
27
27
|
promoteId?: PromoteIdSpecification
|
|
28
28
|
volatile?: boolean
|
|
29
|
+
offlineCache?: boolean
|
|
29
30
|
}
|
|
30
31
|
export declare interface RasterSourceSpecification {
|
|
31
32
|
type: 'raster'
|
|
@@ -38,6 +39,7 @@ export declare interface RasterSourceSpecification {
|
|
|
38
39
|
scheme?: 'xyz' | 'tms'
|
|
39
40
|
attribution?: string
|
|
40
41
|
volatile?: boolean
|
|
42
|
+
offlineCache?: boolean
|
|
41
43
|
}
|
|
42
44
|
export declare interface RasterDEMSourceSpecification {
|
|
43
45
|
type: 'raster-dem'
|
|
@@ -308,6 +310,45 @@ export declare interface RasterLayerSpecification {
|
|
|
308
310
|
layout?: RasterLayoutSpecification
|
|
309
311
|
paint?: RasterPaintSpecification
|
|
310
312
|
}
|
|
313
|
+
// ---------- hillshade ----------
|
|
314
|
+
export declare interface HillshadePaintSpecification {
|
|
315
|
+
'hillshade-illumination-direction'?: PropertyValueSpecification<number>
|
|
316
|
+
'hillshade-illumination-anchor'?: 'map' | 'viewport'
|
|
317
|
+
'hillshade-exaggeration'?: PropertyValueSpecification<number>
|
|
318
|
+
'hillshade-shadow-color'?: PropertyValueSpecification<string>
|
|
319
|
+
'hillshade-highlight-color'?: PropertyValueSpecification<string>
|
|
320
|
+
'hillshade-accent-color'?: PropertyValueSpecification<string>
|
|
321
|
+
}
|
|
322
|
+
export declare interface HillshadeLayerSpecification {
|
|
323
|
+
id: string
|
|
324
|
+
type: 'hillshade'
|
|
325
|
+
metadata?: Record<string, unknown>
|
|
326
|
+
source: string
|
|
327
|
+
minzoom?: number
|
|
328
|
+
maxzoom?: number
|
|
329
|
+
layout?: { visibility?: 'visible' | 'none' }
|
|
330
|
+
paint?: HillshadePaintSpecification
|
|
331
|
+
}
|
|
332
|
+
// ---------- heatmap ----------
|
|
333
|
+
export declare interface HeatmapPaintSpecification {
|
|
334
|
+
'heatmap-radius'?: PropertyValueSpecification<number>
|
|
335
|
+
'heatmap-weight'?: PropertyValueSpecification<number>
|
|
336
|
+
'heatmap-intensity'?: PropertyValueSpecification<number>
|
|
337
|
+
'heatmap-color'?: unknown
|
|
338
|
+
'heatmap-opacity'?: PropertyValueSpecification<number>
|
|
339
|
+
}
|
|
340
|
+
export declare interface HeatmapLayerSpecification {
|
|
341
|
+
id: string
|
|
342
|
+
type: 'heatmap'
|
|
343
|
+
metadata?: Record<string, unknown>
|
|
344
|
+
source: string
|
|
345
|
+
'source-layer'?: string
|
|
346
|
+
minzoom?: number
|
|
347
|
+
maxzoom?: number
|
|
348
|
+
filter?: unknown
|
|
349
|
+
layout?: { visibility?: 'visible' | 'none' }
|
|
350
|
+
paint?: HeatmapPaintSpecification
|
|
351
|
+
}
|
|
311
352
|
// ---------- root style ----------
|
|
312
353
|
export declare interface Style {
|
|
313
354
|
version: 8
|
|
@@ -359,17 +400,16 @@ export type LayerType = | 'background'
|
|
|
359
400
|
| 'line'
|
|
360
401
|
| 'circle'
|
|
361
402
|
| 'symbol'
|
|
362
|
-
| 'raster'
|
|
403
|
+
| 'raster'
|
|
404
|
+
| 'hillshade'
|
|
405
|
+
| 'heatmap';
|
|
363
406
|
// ---------- layer union ----------
|
|
364
|
-
//
|
|
365
|
-
// Note: `hillshade` and `heatmap` Mapbox layer types are NOT part of the
|
|
366
|
-
// style-spec union because the runtime doesn't render them through the
|
|
367
|
-
// style-spec path. Use `HillshadeLayer` (`RasterDEMLayer`) and
|
|
368
|
-
// `HeatmapLayer` as ordinary layer instances via `layer.addTo(map)`.
|
|
369
407
|
export type LayerSpecification = | BackgroundLayerSpecification
|
|
370
408
|
| FillLayerSpecification
|
|
371
409
|
| FillExtrusionLayerSpecification
|
|
372
410
|
| LineLayerSpecification
|
|
373
411
|
| CircleLayerSpecification
|
|
374
412
|
| SymbolLayerSpecification
|
|
375
|
-
| RasterLayerSpecification
|
|
413
|
+
| RasterLayerSpecification
|
|
414
|
+
| HillshadeLayerSpecification
|
|
415
|
+
| HeatmapLayerSpecification;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Palette } from './palette';
|
|
2
|
+
import type { Style as StyleSpec } from '../style-spec/types';
|
|
3
|
+
/** The dark basemap. Pair it with `theme: 'dark'` so the chrome matches. */
|
|
4
|
+
export declare function dark(options: BasemapStyleOptions): StyleSpec;
|
|
5
|
+
/** The light basemap. The default `theme: 'light'` chrome already matches. */
|
|
6
|
+
export declare function light(options: BasemapStyleOptions): StyleSpec;
|
|
7
|
+
/**
|
|
8
|
+
* Built-in basemap styles.
|
|
9
|
+
*
|
|
10
|
+
* These are functions rather than constants because ts-maps ships no tile
|
|
11
|
+
* service: a style is only meaningful once it is pointed at a source. Call
|
|
12
|
+
* `styles.dark({ tiles })` with a vector tile URL and you get a complete
|
|
13
|
+
* StyleSpec; the palette, layer order and zoom ramps are the parts worth not
|
|
14
|
+
* hand-writing.
|
|
15
|
+
*
|
|
16
|
+
* Layer names default to the OpenMapTiles schema, which is what the keyless
|
|
17
|
+
* public services publish (OpenFreeMap, MapTiler, a self-hosted Tileserver
|
|
18
|
+
* GL). A source using different names — Mapbox Streets, say — is accommodated
|
|
19
|
+
* by `sourceLayers` rather than by forking the style.
|
|
20
|
+
*/
|
|
21
|
+
export declare interface BasemapStyleOptions {
|
|
22
|
+
tiles: string | string[]
|
|
23
|
+
mode?: 'vector' | 'raster'
|
|
24
|
+
attribution?: string
|
|
25
|
+
minzoom?: number
|
|
26
|
+
maxzoom?: number
|
|
27
|
+
tileSize?: number
|
|
28
|
+
sourceLayers?: Partial<Record<SourceLayerKey, string>>
|
|
29
|
+
palette?: Partial<Palette>
|
|
30
|
+
name?: string
|
|
31
|
+
glyphs?: string
|
|
32
|
+
sprite?: string
|
|
33
|
+
}
|
|
34
|
+
export type SourceLayerKey = | 'water'
|
|
35
|
+
| 'landcover'
|
|
36
|
+
| 'landuse'
|
|
37
|
+
| 'building'
|
|
38
|
+
| 'transportation'
|
|
39
|
+
| 'transportationName'
|
|
40
|
+
| 'boundary'
|
|
41
|
+
| 'place';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { BasemapStyleOptions, SourceLayerKey } from './basemap';
|
|
2
|
+
export type { Palette } from './palette';
|
|
3
|
+
// Built-in basemap styles. See `basemap.ts` for why these are functions.
|
|
4
|
+
export { dark, light } from './basemap';
|
|
5
|
+
export { DARK, LIGHT } from './palette';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dark palette, tuned for data on top.
|
|
3
|
+
*
|
|
4
|
+
* Roads sit close to the background rather than reading as bright lines: on a
|
|
5
|
+
* dark incident or fleet map the overlay is the subject, and a road network at
|
|
6
|
+
* high contrast competes with it. Water is desaturated navy rather than blue
|
|
7
|
+
* for the same reason — it should read as "not land" without pulling the eye.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DARK: Palette;
|
|
10
|
+
/** Light palette: a clean neutral street style, same skeleton. */
|
|
11
|
+
export declare const LIGHT: Palette;
|
|
12
|
+
// The two palettes the built-in styles are cut from.
|
|
13
|
+
//
|
|
14
|
+
// Light and dark share one layer skeleton (see `basemap.ts`) and differ only
|
|
15
|
+
// in this table, so a colour added to one is a compile error until it exists
|
|
16
|
+
// in the other. That is the whole point: the usual way a pair of themes drifts
|
|
17
|
+
// is one of them quietly gaining a layer the other never got.
|
|
18
|
+
export declare interface Palette {
|
|
19
|
+
background: string
|
|
20
|
+
land: string
|
|
21
|
+
green: string
|
|
22
|
+
water: string
|
|
23
|
+
roadMajor: string
|
|
24
|
+
roadMinor: string
|
|
25
|
+
roadCasing: string
|
|
26
|
+
buildings: string
|
|
27
|
+
boundary: string
|
|
28
|
+
label: string
|
|
29
|
+
labelHalo: string
|
|
30
|
+
labelMuted: string
|
|
31
|
+
}
|
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
// CollisionIndex —
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// CollisionIndex — sparse spatial hash for symbol placement.
|
|
2
|
+
//
|
|
3
|
+
// Boxes are bucketed into every cell they overlap; `tryInsert` rejects when a
|
|
4
|
+
// colliding neighbour has priority >= the new box's.
|
|
5
|
+
//
|
|
6
|
+
// The grid is sparse and unbounded rather than a fixed cols×rows array, which
|
|
7
|
+
// is what lets one index span the whole viewport instead of a single tile.
|
|
8
|
+
// A per-tile index cannot see across a tile seam, so two halves of the same
|
|
9
|
+
// street name, or two towns either side of an edge, would each place happily
|
|
10
|
+
// and then overlap on screen. Callers now insert in world-pixel coordinates
|
|
11
|
+
// and share one index across every tile at a zoom level.
|
|
12
|
+
//
|
|
13
|
+
// Because tiles are drawn, discarded on pan, and drawn again, every box may
|
|
14
|
+
// carry an `owner` — the tile that placed it. `removeOwner` drops that tile's
|
|
15
|
+
// boxes before it redraws, so a tile never collides with the ghosts of its own
|
|
16
|
+
// previous placement.
|
|
4
17
|
export declare interface CollisionBox {
|
|
5
18
|
minX: number
|
|
6
19
|
minY: number
|
|
7
20
|
maxX: number
|
|
8
21
|
maxY: number
|
|
9
22
|
priority?: number
|
|
23
|
+
owner?: string
|
|
10
24
|
}
|
|
11
25
|
export declare interface CollisionIndexOptions {
|
|
12
|
-
width: number
|
|
13
|
-
height: number
|
|
14
26
|
cellSize?: number
|
|
27
|
+
width?: number
|
|
28
|
+
height?: number
|
|
15
29
|
}
|
|
16
30
|
export declare class CollisionIndex {
|
|
17
31
|
constructor(opts?: CollisionIndexOptions);
|
|
32
|
+
hits(box: CollisionBox): boolean;
|
|
18
33
|
tryInsert(box: CollisionBox): boolean;
|
|
19
34
|
insert(box: CollisionBox): void;
|
|
35
|
+
removeOwner(owner: string): void;
|
|
20
36
|
clear(): void;
|
|
37
|
+
get size(): number;
|
|
21
38
|
}
|
|
@@ -25,7 +25,11 @@ export declare class GlyphAtlas {
|
|
|
25
25
|
canvas: HTMLCanvasElement;
|
|
26
26
|
constructor(opts?: GlyphAtlasOptions);
|
|
27
27
|
getOrAddGlyph(codePoint: number, style?: { italic?: boolean, bold?: boolean }): GlyphMetrics;
|
|
28
|
-
measure(text: string, style?: { italic?: boolean, bold?: boolean }): { width: number, height: number };
|
|
28
|
+
measure(text: string, style?: { italic?: boolean, bold?: boolean, family?: string }): { width: number, height: number };
|
|
29
|
+
advances(text: string, size: number, style?: { italic?: boolean, bold?: boolean, family?: string }): Array<{ char: string, advance: number }>;
|
|
30
|
+
measureText(text: string, size: number, style?: { italic?: boolean, bold?: boolean, family?: string }): { width: number, height: number, ascent: number, descent: number };
|
|
31
|
+
fontString(size: number, style?: { italic?: boolean, bold?: boolean, family?: string }): string;
|
|
32
|
+
resolveFont(textFont: string | string[] | undefined): { family: string, bold: boolean, italic: boolean };
|
|
29
33
|
drawText(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, options: {
|
|
30
34
|
color: string
|
|
31
35
|
haloColor?: string
|
|
@@ -33,6 +37,7 @@ export declare class GlyphAtlas {
|
|
|
33
37
|
size: number
|
|
34
38
|
italic?: boolean
|
|
35
39
|
bold?: boolean
|
|
40
|
+
family?: string
|
|
36
41
|
}): void;
|
|
37
42
|
_buildSDF(imageData: ImageData): ImageData;
|
|
38
43
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GlyphBitmapCache } from './GlyphRenderer';
|
|
2
|
+
import type { Glyph, GlyphSource } from './loadGlyphs';
|
|
3
|
+
/**
|
|
4
|
+
* A font stack as the server names it.
|
|
5
|
+
*
|
|
6
|
+
* Glyph URLs take a comma-separated stack — `"Noto Sans Regular,Arial Unicode
|
|
7
|
+
* MS Regular"` — which is also a serviceable cache key.
|
|
8
|
+
*/
|
|
9
|
+
export declare function stackKey(fontStack: string | string[] | undefined): string;
|
|
10
|
+
export declare interface GlyphProviderOptions {
|
|
11
|
+
source: GlyphSource
|
|
12
|
+
isFontAvailable: (fontStack: string | string[] | undefined) => boolean
|
|
13
|
+
onLoad: () => void
|
|
14
|
+
}
|
|
15
|
+
export declare class GlyphProvider {
|
|
16
|
+
cache: GlyphBitmapCache;
|
|
17
|
+
constructor(options: GlyphProviderOptions);
|
|
18
|
+
needsServer(fontStack: string | string[] | undefined): boolean;
|
|
19
|
+
glyphs(fontStack: string | string[] | undefined, text: string): Glyph[] | null;
|
|
20
|
+
invalidate(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Glyph, GlyphRange } from './loadGlyphs';
|
|
2
|
+
/**
|
|
3
|
+
* Look glyphs up for a run of text.
|
|
4
|
+
*
|
|
5
|
+
* Returns `null` if any character's range has not been loaded, because a label
|
|
6
|
+
* drawn with holes in it is worse than a label that appears a moment later.
|
|
7
|
+
* The caller's job on `null` is to request the ranges and redraw.
|
|
8
|
+
*/
|
|
9
|
+
export declare function glyphsFor(range: (codePoint: number) => Glyph | undefined, text: string): Glyph[] | null;
|
|
10
|
+
/** Measure a run laid out from server glyphs. */
|
|
11
|
+
export declare function measureGlyphs(glyphs: Glyph[], size: number): GlyphTextMetrics;
|
|
12
|
+
/**
|
|
13
|
+
* Draw a run of server glyphs with `x` at its left edge and `y` on its
|
|
14
|
+
* baseline — the same contract as the canvas text path, so a caller does not
|
|
15
|
+
* have to know which one it got.
|
|
16
|
+
*/
|
|
17
|
+
export declare function drawGlyphs(ctx: CanvasRenderingContext2D, glyphs: Glyph[], x: number, y: number, options: GlyphDrawOptions, cache?: GlyphBitmapCache): void;
|
|
18
|
+
/** Colour one glyph's field into a bitmap ready to blit. */
|
|
19
|
+
export declare function renderGlyphBitmap(glyph: Glyph, options: GlyphDrawOptions): HTMLCanvasElement | null;
|
|
20
|
+
/** A `GlyphRange` as the lookup `glyphsFor` wants. */
|
|
21
|
+
export declare function rangeLookup(ranges: GlyphRange[]): (codePoint: number) => Glyph | undefined;
|
|
22
|
+
/** The em size Mapbox's glyph generator rasterises at. */
|
|
23
|
+
export declare const GLYPH_EM: 24;
|
|
24
|
+
export declare interface GlyphDrawOptions {
|
|
25
|
+
size: number
|
|
26
|
+
color: string
|
|
27
|
+
haloColor?: string
|
|
28
|
+
haloWidth?: number
|
|
29
|
+
}
|
|
30
|
+
export declare interface GlyphTextMetrics {
|
|
31
|
+
width: number
|
|
32
|
+
height: number
|
|
33
|
+
ascent: number
|
|
34
|
+
descent: number
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Coloured glyph bitmaps, keyed by glyph and appearance.
|
|
38
|
+
*
|
|
39
|
+
* A label is redrawn on every pan and zoom, and the same few hundred glyphs
|
|
40
|
+
* recur across every tile on screen; colouring each field per frame would be
|
|
41
|
+
* the most expensive thing the renderer does.
|
|
42
|
+
*/
|
|
43
|
+
export declare class GlyphBitmapCache {
|
|
44
|
+
constructor(limit?: number);
|
|
45
|
+
get(glyph: Glyph, options: GlyphDrawOptions): HTMLCanvasElement | null;
|
|
46
|
+
clear(): void;
|
|
47
|
+
get size(): number;
|
|
48
|
+
}
|
|
@@ -8,11 +8,20 @@ export declare interface SpriteEntry {
|
|
|
8
8
|
width: number
|
|
9
9
|
height: number
|
|
10
10
|
pixelRatio?: number
|
|
11
|
+
sdf?: boolean
|
|
12
|
+
}
|
|
13
|
+
export declare interface DrawIconOptions {
|
|
14
|
+
size?: number
|
|
15
|
+
rotation?: number
|
|
16
|
+
color?: string
|
|
17
|
+
opacity?: number
|
|
18
|
+
haloColor?: string
|
|
19
|
+
haloWidth?: number
|
|
11
20
|
}
|
|
12
21
|
export declare class IconAtlas {
|
|
13
22
|
canvas: HTMLCanvasElement;
|
|
14
23
|
constructor();
|
|
15
24
|
addSprite(entry: SpriteEntry, source: HTMLImageElement | HTMLCanvasElement | ImageData): void;
|
|
16
25
|
get(id: string): SpriteEntry | undefined;
|
|
17
|
-
drawIcon(ctx: CanvasRenderingContext2D, id: string, dx: number, dy: number, opts?:
|
|
26
|
+
drawIcon(ctx: CanvasRenderingContext2D, id: string, dx: number, dy: number, opts?: DrawIconOptions): void;
|
|
18
27
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CollisionIndex } from './CollisionIndex';
|
|
2
|
+
/**
|
|
3
|
+
* The canvas labels are drawn on, above the tiles rather than inside them.
|
|
4
|
+
*
|
|
5
|
+
* Symbols used to be painted into each tile's own canvas, which had three
|
|
6
|
+
* consequences worth undoing:
|
|
7
|
+
*
|
|
8
|
+
* - **WebGL tiles had no labels at all.** A canvas bound to a WebGL context
|
|
9
|
+
* cannot also hand out a 2D context, so the symbol pass was skipped
|
|
10
|
+
* entirely — you opted into the faster renderer and silently lost every
|
|
11
|
+
* piece of text on the map.
|
|
12
|
+
* - **Rotation was baked in.** Placement happened once, when the tile was
|
|
13
|
+
* drawn, so turning the map carried the labels round with it: text upside
|
|
14
|
+
* down at a bearing of 180, and collision boxes still computed for north.
|
|
15
|
+
* - **Labels stopped at tile edges**, because a tile can only draw inside
|
|
16
|
+
* itself however wide the collision index's view is.
|
|
17
|
+
*
|
|
18
|
+
* One viewport-sized canvas fixes all three. It lives in the map's own
|
|
19
|
+
* `symbolPane`, which sits above the tiles and below markers and popups — a
|
|
20
|
+
* marker should never end up behind a street name — and which the map
|
|
21
|
+
* counter-rotates, so placement is done in screen space and glyphs stay
|
|
22
|
+
* upright however the map is turned.
|
|
23
|
+
*
|
|
24
|
+
* Redrawing happens at settled moments: the end of a pan, a zoom, a rotation,
|
|
25
|
+
* or when tiles arrive. In between the pane carries the canvas along with the
|
|
26
|
+
* map, so labels stay stuck to the ground without re-placing hundreds of them
|
|
27
|
+
* every frame.
|
|
28
|
+
*/
|
|
29
|
+
export declare interface SymbolOverlayHost {
|
|
30
|
+
drawSymbols: (ctx: CanvasRenderingContext2D, collision: CollisionIndex) => void
|
|
31
|
+
createCollisionIndex: () => CollisionIndex
|
|
32
|
+
}
|
|
33
|
+
export declare class SymbolOverlay {
|
|
34
|
+
canvas: HTMLCanvasElement | null;
|
|
35
|
+
_map: any;
|
|
36
|
+
_host: SymbolOverlayHost;
|
|
37
|
+
_ratio: number;
|
|
38
|
+
_frame: number | null;
|
|
39
|
+
constructor(map: any, host: SymbolOverlayHost);
|
|
40
|
+
_attach(): void;
|
|
41
|
+
_pixelRatio(): number;
|
|
42
|
+
_resize(): void;
|
|
43
|
+
_position(): void;
|
|
44
|
+
schedule(): void;
|
|
45
|
+
redraw(): void;
|
|
46
|
+
remove(): void;
|
|
47
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export type { CollisionBox, CollisionIndexOptions } from './CollisionIndex';
|
|
2
2
|
export type { GlyphAtlasOptions, GlyphMetrics } from './GlyphAtlas';
|
|
3
3
|
export type { SpriteEntry } from './IconAtlas';
|
|
4
|
+
export type { Glyph, GlyphRange, LoadGlyphsOptions } from './loadGlyphs';
|
|
5
|
+
export type { LoadedSprite, LoadSpriteOptions, SpriteIndex, SpriteIndexEntry } from './loadSprite';
|
|
4
6
|
export { CollisionIndex } from './CollisionIndex';
|
|
5
7
|
export { GlyphAtlas } from './GlyphAtlas';
|
|
6
8
|
export { IconAtlas } from './IconAtlas';
|
|
9
|
+
export { decodeGlyphPbf, GLYPH_BORDER, GlyphSource, glyphUrl, rangeStartFor } from './loadGlyphs';
|
|
10
|
+
export { addSpriteToAtlas, loadSprite, spriteUrl } from './loadSprite';
|