@tangram.gl/basemap-layers 0.0.0-stage → 0.0.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.
Files changed (105) hide show
  1. package/README.md +34 -2
  2. package/THIRD-PARTY-NOTICES.md +205 -0
  3. package/dist/geojson-worker.js +2160 -0
  4. package/dist/geojson-worker.js.map +6 -0
  5. package/dist/index.cjs +11388 -0
  6. package/dist/index.cjs.map +6 -0
  7. package/dist/index.js +11369 -0
  8. package/dist/index.js.map +6 -0
  9. package/dist/map-style.cjs +445 -0
  10. package/dist/map-style.cjs.map +6 -0
  11. package/dist/map-style.js +431 -0
  12. package/dist/map-style.js.map +6 -0
  13. package/dist/types/arabic-shaping.d.ts +7 -0
  14. package/dist/types/atmosphere-layer.d.ts +10 -0
  15. package/dist/types/basemap-layer.d.ts +150 -0
  16. package/dist/types/bidi.d.ts +8 -0
  17. package/dist/types/circle-layer.d.ts +49 -0
  18. package/dist/types/fill-extrusion-lighting-extension.d.ts +49 -0
  19. package/dist/types/fill-outline-extension.d.ts +22 -0
  20. package/dist/types/fill-pattern.d.ts +99 -0
  21. package/dist/types/fill-style-extensions.d.ts +100 -0
  22. package/dist/types/geojson-source.d.ts +29 -0
  23. package/dist/types/geojson-tiler.d.ts +48 -0
  24. package/dist/types/geojson-worker.d.ts +40 -0
  25. package/dist/types/globe-horizon-extension.d.ts +61 -0
  26. package/dist/types/globe-layers.d.ts +239 -0
  27. package/dist/types/globe-line-angle-extension.d.ts +37 -0
  28. package/dist/types/glyph-font-renderer.d.ts +37 -0
  29. package/dist/types/glyph-pbf.d.ts +37 -0
  30. package/dist/types/glyph-store.d.ts +103 -0
  31. package/dist/types/grid-index.d.ts +47 -0
  32. package/dist/types/hillshade-layer.d.ts +154 -0
  33. package/dist/types/index.d.ts +9 -0
  34. package/dist/types/is-globe-viewport.d.ts +2 -0
  35. package/dist/types/label-font-renderer.d.ts +18 -0
  36. package/dist/types/label-placement.d.ts +247 -0
  37. package/dist/types/label-text-layer.d.ts +231 -0
  38. package/dist/types/line-blur-extension.d.ts +73 -0
  39. package/dist/types/line-glyphs.d.ts +60 -0
  40. package/dist/types/line-placement.d.ts +93 -0
  41. package/dist/types/map-style-loader.d.ts +48 -0
  42. package/dist/types/map-style-schema.d.ts +72 -0
  43. package/dist/types/map-style.d.ts +6 -0
  44. package/dist/types/mapbox-style.d.ts +40 -0
  45. package/dist/types/mvt-label-layer.d.ts +923 -0
  46. package/dist/types/polylabel.d.ts +17 -0
  47. package/dist/types/raster-color-extension.d.ts +146 -0
  48. package/dist/types/shared-texture.d.ts +34 -0
  49. package/dist/types/sort-key.d.ts +10 -0
  50. package/dist/types/sprite.d.ts +82 -0
  51. package/dist/types/style-accessor.d.ts +45 -0
  52. package/dist/types/style-expression.d.ts +83 -0
  53. package/dist/types/style-resolver.d.ts +94 -0
  54. package/dist/types/text-font.d.ts +36 -0
  55. package/dist/types/text-halo-blur-extension.d.ts +55 -0
  56. package/dist/types/text-layout.d.ts +71 -0
  57. package/dist/types/util.d.ts +22 -0
  58. package/dist/types/zoom-paint-extension.d.ts +72 -0
  59. package/package.json +80 -3
  60. package/src/arabic-shaping.ts +366 -0
  61. package/src/atmosphere-layer.ts +19 -0
  62. package/src/basemap-layer.ts +533 -0
  63. package/src/bidi.ts +199 -0
  64. package/src/circle-layer.ts +191 -0
  65. package/src/fill-extrusion-lighting-extension.ts +206 -0
  66. package/src/fill-outline-extension.ts +70 -0
  67. package/src/fill-pattern.ts +400 -0
  68. package/src/fill-style-extensions.ts +177 -0
  69. package/src/geojson-source.ts +318 -0
  70. package/src/geojson-tiler.ts +185 -0
  71. package/src/geojson-worker.ts +98 -0
  72. package/src/globe-horizon-extension.ts +64 -0
  73. package/src/globe-layers.ts +3487 -0
  74. package/src/globe-line-angle-extension.ts +131 -0
  75. package/src/glyph-font-renderer.ts +173 -0
  76. package/src/glyph-pbf.ts +164 -0
  77. package/src/glyph-store.ts +326 -0
  78. package/src/grid-index.ts +177 -0
  79. package/src/hillshade-layer.ts +775 -0
  80. package/src/index.ts +18 -0
  81. package/src/is-globe-viewport.ts +24 -0
  82. package/src/label-font-renderer.ts +159 -0
  83. package/src/label-placement.ts +727 -0
  84. package/src/label-text-layer.ts +913 -0
  85. package/src/line-blur-extension.ts +237 -0
  86. package/src/line-glyphs.ts +364 -0
  87. package/src/line-placement.ts +446 -0
  88. package/src/map-style-loader.ts +56 -0
  89. package/src/map-style-schema.ts +83 -0
  90. package/src/map-style.ts +23 -0
  91. package/src/mapbox-style.ts +168 -0
  92. package/src/mvt-label-layer.ts +3744 -0
  93. package/src/polylabel.ts +312 -0
  94. package/src/raster-color-extension.ts +245 -0
  95. package/src/shared-texture.ts +153 -0
  96. package/src/sort-key.ts +63 -0
  97. package/src/sprite.ts +244 -0
  98. package/src/style-accessor.ts +95 -0
  99. package/src/style-expression.ts +327 -0
  100. package/src/style-resolver.ts +301 -0
  101. package/src/text-font.ts +150 -0
  102. package/src/text-halo-blur-extension.ts +115 -0
  103. package/src/text-layout.ts +441 -0
  104. package/src/util.ts +47 -0
  105. package/src/zoom-paint-extension.ts +207 -0
@@ -0,0 +1,239 @@
1
+ import type { GlyphStore } from "./glyph-store.js";
2
+ import { SharedMVTLayer, SharedTileset2D } from '@deck.gl-community/geo-layers';
3
+ import { type DemTile } from "./hillshade-layer.js";
4
+ import type { LabelPlacement } from "./label-placement.js";
5
+ import { type StyleAccessor } from "./style-accessor.js";
6
+ import { ZoomPaint, type ZoomPaintValues } from "./zoom-paint-extension.js";
7
+ import type { BasemapGlobeConfig, BasemapLayerProps } from "./basemap-layer.js";
8
+ import type { SpriteAtlas } from "./sprite.js";
9
+ import type { LabelFontFamily } from "./text-font.js";
10
+ import type { BasemapLoadOptions, BasemapSource, ResolvedBasemapStyleLayer as BasemapStyleLayer, ResolvedBasemapStyle } from "./style-resolver.js";
11
+ type BasemapMode = NonNullable<BasemapLayerProps['mode']>;
12
+ type BasemapLayerConfig = {
13
+ atmosphere: boolean;
14
+ basemap: boolean;
15
+ labels: boolean;
16
+ };
17
+ type BasemapLayerGroup = {
18
+ idPrefix?: string;
19
+ mode?: BasemapMode;
20
+ globe?: {
21
+ config?: BasemapGlobeConfig;
22
+ };
23
+ styleDefinition: ResolvedBasemapStyle;
24
+ zoom?: number;
25
+ loadOptions?: BasemapLoadOptions;
26
+ /**
27
+ * Sprites loaded for the style; symbol layers draw `icon-image` from them. `null` means the
28
+ * sprites are still loading: no icons are drawn, and labels are placed as if each symbol had its
29
+ * icon. Omit it, or pass `[]`, for a style without sprites.
30
+ */
31
+ spriteAtlases?: SpriteAtlas[] | null;
32
+ /** Overrides the label font that `text-font` maps to (see `BasemapLayerProps.fontFamily`). */
33
+ fontFamily?: LabelFontFamily | null;
34
+ /** The style's glyphs, which labels are drawn with (see `MVTLabelLayerProps.glyphs`). */
35
+ glyphs?: GlyphStore | null;
36
+ /** The label placement shared by the map's label layers (see `LabelPlacement`). */
37
+ labelPlacement?: LabelPlacement | null;
38
+ /** Externally owned source caches; BasemapLayer supplies and finalizes these. */
39
+ tilesets?: Map<BasemapSource, SharedTileset2D>;
40
+ };
41
+ /**
42
+ * Style layers that draw together, in style order: a background, raster or hillshade layer on its
43
+ * own, or consecutive style layers of one vector source, which share one tile layer.
44
+ */
45
+ export type StyleLayerRun = {
46
+ type: 'background' | 'raster' | 'hillshade' | 'vector';
47
+ /** The deck.gl layer id, without the basemap's id prefix. */
48
+ id: string;
49
+ sourceId?: string;
50
+ source?: BasemapSource;
51
+ styleLayers: BasemapStyleLayer[];
52
+ };
53
+ /** The `minzoom`/`maxzoom` limits that `isStyleLayerVisibleAtZoom` compares against. */
54
+ export declare function getStyleZoomLimits(styleLayers: BasemapStyleLayer[]): (number | undefined)[];
55
+ /**
56
+ * Evaluates the paint of style layers drawn by one sublayer for `ZoomPaintExtension`: a style
57
+ * layer's width, or 1 where it is per feature, and its colors in 0-1, or an alpha of -1 where they
58
+ * are per feature.
59
+ */
60
+ export declare function getZoomPaintValues(styleLayers: BasemapStyleLayer[], mode: BasemapMode, zoom: number): ZoomPaintValues;
61
+ /**
62
+ * The paint of one tile layer's fill and line sublayers for `ZoomPaintExtension`: the zoom its
63
+ * sublayers were generated at, and a `ZoomPaint` per sequence of style layers drawn by one
64
+ * sublayer, shared by all tiles. Kept in the tile layer's state.
65
+ */
66
+ export declare class ZoomPaintContext {
67
+ /** The stepped zoom (see `getZoomBucket`) at which paint is evaluated. */
68
+ zoom: number;
69
+ private zoomPaints;
70
+ /** The style the zoom paints were made for (see `setStyle`). */
71
+ private style;
72
+ /** The zoom paints no sublayer has asked for since the last style change. */
73
+ private unused;
74
+ /**
75
+ * Destroys the zoom paints of sequences of style layers that no sublayer drew with since the
76
+ * previous style change. A new style keeps the zoom paints of the style layers it keeps, and its
77
+ * tile sublayers, regenerated, ask for the others again, so at most one style's are left over.
78
+ */
79
+ setStyle(style: unknown): void;
80
+ /**
81
+ * The `ZoomPaint` of style layers drawn by one sublayer. Its values are evaluated once per zoom
82
+ * step, and again when a paint property is replaced.
83
+ */
84
+ get(styleLayers: BasemapStyleLayer[], mode: BasemapMode): ZoomPaint;
85
+ /** Releases the textures of every `ZoomPaint`. */
86
+ destroy(): void;
87
+ }
88
+ /**
89
+ * The `zoomOffset` of vector sources' tiles. MapLibre GL JS draws a vector source with the tiles
90
+ * at the floor of the zoom (and a raster source with those at the rounded zoom, as deck.gl's
91
+ * `TileLayer` does): its styles and labels are laid out for that. Half a zoom down before
92
+ * rounding selects the same tiles.
93
+ */
94
+ export declare const VECTOR_TILE_ZOOM_OFFSET = -0.5;
95
+ /**
96
+ * The tile pyramid range of a source. `TileLayer` draws nothing at a view zoom below its `minZoom`,
97
+ * unless it has an `extent`. On a globe, the view zoom goes below 0 near the poles: `GlobeView`
98
+ * lowers the zoom with the latitude, so that the globe keeps its size on screen (zoom 0 at the
99
+ * equator is zoom -2 at latitude 76). A source whose pyramid starts at zoom 0 draws its zoom 0
100
+ * tiles at any lower zoom, as in MapLibre; the extent, the whole pyramid, selects them.
101
+ */
102
+ export declare function getTilePyramidProps(source: BasemapSource): {
103
+ minZoom: number;
104
+ maxZoom: number;
105
+ extent: number[] | null;
106
+ };
107
+ /**
108
+ * Creates the tileset of a `raster-dem` source: each tile is fetched and decoded once, and shared by
109
+ * every `hillshade` layer drawn from it. `BasemapLayer` creates and finalizes these itself. Direct
110
+ * `getBasemapLayers` callers that call it on every render pass them in `tilesets`, keyed by source,
111
+ * to keep the tiles across calls, and finalize them when done.
112
+ */
113
+ export declare function createDemTileset(source: BasemapSource, loadOptions?: BasemapLoadOptions): SharedTileset2D<DemTile | null>;
114
+ /**
115
+ * Orders the sublayers of all tiles of a tile layer by style layer, as MapLibre draws each style
116
+ * layer across all tiles before the next: a tile's fills cannot paint over the labels of the tile
117
+ * drawn before it. Within a style layer, tiles keep their order, and so do the sublayers of a tile.
118
+ */
119
+ export declare function sortTileSubLayers<LayerT extends {
120
+ props: Record<string, any>;
121
+ }>(tileSubLayers: (LayerT[] | null | undefined)[]): LayerT[];
122
+ /**
123
+ * Whether two sets of layer props are the same to deck.gl. Per-feature accessors (`get*`) that
124
+ * are both functions count as the same, unless `accessors` is false: with the same data, deck.gl
125
+ * reads them again only when their update trigger, compared with the other props, changes.
126
+ */
127
+ export declare function isSameProps(a: Record<string, any>, b: Record<string, any>, depth?: number, accessors?: boolean): boolean;
128
+ /** All style-layer `minzoom`/`maxzoom` limits in a style. */
129
+ export declare function getStyleDefinitionZoomLimits(styleDefinition: BasemapLayerGroup['styleDefinition']): (number | undefined)[];
130
+ export declare function getBasemapLayers({ idPrefix, mode, globe, styleDefinition, zoom, loadOptions, spriteAtlases, fontFamily, glyphs, labelPlacement, tilesets }: BasemapLayerGroup): any[];
131
+ export declare function getGlobeBaseLayers({ globe, styleDefinition, idPrefix, zoom, loadOptions, spriteAtlases, fontFamily, glyphs, labelPlacement }: Omit<BasemapLayerGroup, 'mode'>): any[];
132
+ export declare function getGlobeTopLayers({ globe }: {
133
+ globe: {
134
+ config: BasemapGlobeConfig;
135
+ };
136
+ }): null[];
137
+ /**
138
+ * Converts a style `line-dasharray` into deck.gl's `[dash, gap]`. MapLibre measures dashes in line
139
+ * widths; deck.gl's `widths` unit is half the line width, so lengths double. deck.gl draws one dash
140
+ * and one gap per period, so a longer pattern keeps its period and total dash length, but merges
141
+ * its dashes. In an odd-length pattern the last dash runs into the first, as in MapLibre. An empty
142
+ * pattern, or one without gaps, draws a solid line.
143
+ */
144
+ export declare function getDashArray(dasharray: unknown): [number, number];
145
+ /** The least distance, in pixels, of a gap's line from the gap's center: see getLineOffset. */
146
+ export declare const MIN_GAP_LINE_CENTER = 0.01;
147
+ /**
148
+ * Converts `line-offset` and `line-gap-width` into deck.gl's `getOffset`, which is in line widths.
149
+ * A gap draws two lines of `width` with their centers `gapWidth / 2 + width / 2` either side of
150
+ * the offset line: `side` is 1 or -1 for them. Without a gap, `side` is ignored. Positive is to
151
+ * the right of the line's direction in both. Dividing by `width` assumes deck.gl draws the line
152
+ * `width` pixels wide, that is, no `lineWidthMinPixels`/`lineWidthMaxPixels` clamp applies.
153
+ *
154
+ * deck.gl offsets by widening the stroke and masking it across the line, not by offsetting the
155
+ * path, so the outside of a sharp corner breaks open and the two lines of a gap end in separate
156
+ * stubs rather than one cap. Offsetting the path belongs in deck.gl's `PathStyleExtension`.
157
+ */
158
+ export declare function getLineOffset(offset: number, gapWidth: number, width: number, side: number, blur?: number): number;
159
+ /**
160
+ * Scales a blurred gap's `getDashArray` by `width / drawnWidth` (see `getBlurredLineWidth`), so
161
+ * that its dashes keep the pixel lengths MapLibre gives them in `line-width`s. `shape` is the
162
+ * `[offset, gap, width, blur]` accessor of `getLineOffset`.
163
+ */
164
+ export declare function getBlurredDashArray(dashArray: StyleAccessor<[number, number]>, shape: StyleAccessor<[number, number, number, number]>): {
165
+ value: [number, number] | ((feature: any) => [number, number]);
166
+ updateTrigger?: unknown[];
167
+ };
168
+ /** deck.gl path props for a line's `line-cap`, `line-join` and `line-miter-limit`. */
169
+ export type LineShape = {
170
+ lineCapRounded: boolean;
171
+ lineJointRounded: boolean;
172
+ lineMiterLimit: number;
173
+ };
174
+ /**
175
+ * Converts `line-cap`, `line-join` and `line-miter-limit` into deck.gl path props.
176
+ *
177
+ * - `round` caps and joins are drawn round. `butt` caps end at the endpoint. deck.gl has no square
178
+ * cap, so `square` is drawn as `butt`: the line ends half its width short of MapLibre's.
179
+ * - deck.gl cuts a joint flat at `miterLimit + 1` half widths from the vertex. MapLibre draws a
180
+ * `miter` join in full while its tip is within `line-miter-limit` half widths of the vertex, so
181
+ * passing `line-miter-limit - 1` draws the same joins in full. A sharper corner, which MapLibre
182
+ * bevels, is cut flat at that distance instead.
183
+ * - deck.gl has no bevel join. A `bevel` join is cut flat half the line width from the vertex,
184
+ * which matches a bevel at shallow corners; at sharp corners a true bevel cuts closer.
185
+ */
186
+ export declare function getLineShape([cap, join, miterLimit]: unknown[]): LineShape;
187
+ /**
188
+ * One accessor for the features of several style layers: a constant when every style layer's
189
+ * value is the same constant, otherwise a function that applies each feature's own style layer's
190
+ * accessor. Its update trigger changes when any style layer's value or trigger changes.
191
+ */
192
+ export declare function mergeStyleAccessors<T>(accessors: StyleAccessor<T>[], partIndices: ArrayLike<number>): {
193
+ value: T | ((feature: any, info: {
194
+ index: number;
195
+ }) => T);
196
+ updateTrigger?: unknown;
197
+ };
198
+ /**
199
+ * Whether a source's layers draw from vector tiles: a vector source with tile templates, or a
200
+ * GeoJSON source with data, which is cut into tiles on the client (see `getGeoJsonTileFeatures`).
201
+ */
202
+ export declare function isVectorTileSource(source: BasemapSource | undefined): boolean;
203
+ /**
204
+ * The `getTileData` of a vector tile source's tileset: `loader` fetches and decodes a vector
205
+ * source's tiles, and a GeoJSON source's tiles are cut from its data, in the same tile-local
206
+ * coordinates.
207
+ */
208
+ export declare function getVectorTileLoader(source: BasemapSource, loader: SharedMVTLayer): (tile: Parameters<SharedMVTLayer['getTileData']>[0]) => Promise<any>;
209
+ /**
210
+ * The source layers drawn from each vector source, over all of its runs, sorted; `null` for a
211
+ * source with a style layer that names none. Tiles decode only these: OpenMapTiles tiles, for
212
+ * one, carry house numbers and peaks that few styles draw, and points of interest, most of a
213
+ * street-level tile, that a style without them, or with labels off, does not draw.
214
+ */
215
+ export declare function getRunSourceLayers(runs: StyleLayerRun[]): Map<BasemapSource, string[] | null>;
216
+ /**
217
+ * The source layers each vector source of a style decodes (see `getRunSourceLayers`). With the
218
+ * basemap off they are those it would draw, so that turning it off and on keeps the tiles.
219
+ */
220
+ export declare function getStyleSourceLayers(styleDefinition: ResolvedBasemapStyle, globe?: {
221
+ config?: BasemapGlobeConfig;
222
+ }): Map<BasemapSource, string[] | null>;
223
+ /**
224
+ * `loadOptions` for a vector source's tiles, decoding only `sourceLayers` when given. Source
225
+ * layers set in `loadOptions.mvt.layers` are left as they are.
226
+ */
227
+ export declare function getSourceLoadOptions(loadOptions: BasemapLoadOptions | undefined, sourceLayers: string[] | null | undefined): BasemapLoadOptions | undefined;
228
+ /**
229
+ * Splits the style into runs that draw in style order, as in MapLibre: each background, raster
230
+ * and hillshade layer on its own, and consecutive layers of one vector source together, so that a
231
+ * raster layer between two vector layers draws between them. Layers that cannot draw (a source
232
+ * without tiles, labels turned off) do not split a run. Runs do not depend on zoom, so the tile
233
+ * layers keep their ids and tiles when a layer leaves its zoom range. Background, raster and
234
+ * hillshade runs have their style layer's id. The first run of a source has the source id as its
235
+ * id, unless a background, raster or hillshade run already has that id; later runs, and a first run whose source id is
236
+ * taken, add the quoted id of their first style layer.
237
+ */
238
+ export declare function getStyleLayerRuns(styleLayers: BasemapStyleLayer[], styleDefinition: ResolvedBasemapStyle, config?: BasemapLayerConfig): StyleLayerRun[];
239
+ export {};
@@ -0,0 +1,37 @@
1
+ import { LayerExtension } from '@deck.gl/core';
2
+ import type { Layer } from '@deck.gl/core';
3
+ /**
4
+ * Keeps billboards drawn along lines (labels and icons whose rotation is aligned to the map) on
5
+ * their lines in a `GlobeView`, which draws them in screen space: their angles are taken from
6
+ * north up, and the shader turns them as the view draws the line, upright with `keepUpright`. In
7
+ * other views it does nothing. Add it only to billboards (the shader would also turn the offset of
8
+ * a layer drawn in the map plane) whose angle is a direction on the map. WebGL only: on WebGPU the
9
+ * extension adds no shader code, and they stay as they are drawn from north up.
10
+ *
11
+ * Added to a composite layer such as `TextLayer`, it reaches the character and background
12
+ * sublayers. With `keepOffsetSide`, text kept upright is turned around without its pixel offset,
13
+ * which must then be a direction along and across the line, as `text-offset` is.
14
+ */
15
+ export declare class GlobeLineAngleExtension extends LayerExtension<{
16
+ keepUpright: boolean;
17
+ keepOffsetSide?: boolean;
18
+ }> {
19
+ static extensionName: string;
20
+ constructor(opts: {
21
+ keepUpright: boolean;
22
+ keepOffsetSide?: boolean;
23
+ });
24
+ getShaders(this: Layer, extension: GlobeLineAngleExtension): {
25
+ modules?: undefined;
26
+ } | {
27
+ modules: {
28
+ name: string;
29
+ dependencies: import("@luma.gl/shadertools").ShaderModule[];
30
+ inject: {
31
+ 'vs:#decl': string;
32
+ 'vs:#main-start': string;
33
+ 'vs:DECKGL_FILTER_SIZE': string;
34
+ };
35
+ }[];
36
+ };
37
+ }
@@ -0,0 +1,37 @@
1
+ import type { TextLayerProps } from '@deck.gl/layers';
2
+ import type { Glyph } from "./glyph-pbf.js";
3
+ import type { GlyphStore } from "./glyph-store.js";
4
+ type GetFontRenderer = NonNullable<TextLayerProps['_getFontRenderer']>;
5
+ type FontRenderer = ReturnType<GetFontRenderer>;
6
+ /**
7
+ * `TextLayer`'s font settings for glyphs from a style's `glyphs` URL: distance fields one em of
8
+ * {@link GLYPH_EM} pixels high, reaching 8 pixels, with the edge at 0.75, as MapLibre GL JS draws
9
+ * them. Cells are packed `buffer` pixels apart, the border of the glyph bitmaps.
10
+ */
11
+ export declare const GLYPH_FONT_SETTINGS: {
12
+ sdf: boolean;
13
+ fontSize: number;
14
+ buffer: number;
15
+ radius: number;
16
+ cutoff: number;
17
+ smoothing: number;
18
+ };
19
+ /**
20
+ * The glyph a character of `fontStack` is drawn with: from the store's ranges, or with the browser's
21
+ * fonts for the characters MapLibre GL JS draws so. Null while its range loads, and when the range
22
+ * has none: the character is then not drawn, as in MapLibre.
23
+ */
24
+ export declare function getStyleGlyph(store: GlyphStore, fontStack: string, character: string): Glyph | null;
25
+ /**
26
+ * A function giving a character's advance in ems: the glyph's advance, as MapLibre GL JS lays text
27
+ * out. A character without a glyph advances nothing.
28
+ */
29
+ export declare function getGlyphCharacterMeasurer(store: GlyphStore, fontStack: string): (character: string) => number;
30
+ /**
31
+ * `TextLayer`'s font renderer for the glyphs of a font stack. With
32
+ * {@link GLYPH_FONT_SETTINGS}, `TextLayer` lays each character's glyph out as MapLibre GL JS does:
33
+ * the line's baseline offset puts it {@link LINE_GLYPH_OFFSET} pixels below the line's top, and the
34
+ * glyph's bitmap is drawn `top` pixels below that and `left` pixels right of the pen.
35
+ */
36
+ export declare function getGlyphFontRenderer(store: GlyphStore, fontStack: string): FontRenderer;
37
+ export {};
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The pixels of distance field around each glyph of a glyph range, on every side, beyond its
3
+ * `width` and `height`: a bitmap is `width + 6` by `height + 6`.
4
+ */
5
+ export declare const GLYPH_BORDER = 3;
6
+ /** The size, in pixels, at which glyph ranges are drawn: one em. */
7
+ export declare const GLYPH_EM = 24;
8
+ /** Code points per glyph range: a range file holds `256 * n` to `256 * n + 255`. */
9
+ export declare const GLYPH_RANGE_SIZE = 256;
10
+ /**
11
+ * A glyph of a glyph range, as MapLibre GL JS reads it: a signed distance field and its metrics,
12
+ * in pixels at {@link GLYPH_EM}.
13
+ */
14
+ export type Glyph = {
15
+ /** Unicode code point. */
16
+ id: number;
17
+ /**
18
+ * One byte per pixel, `width + 2 * GLYPH_BORDER` by `height + 2 * GLYPH_BORDER`; empty for a
19
+ * glyph without ink, such as a space.
20
+ */
21
+ bitmap: Uint8Array | Uint8ClampedArray;
22
+ /** Width of the ink. */
23
+ width: number;
24
+ /** Height of the ink. */
25
+ height: number;
26
+ /** From the pen position to the left of the ink. */
27
+ left: number;
28
+ /** Vertical bearing of the top of the ink, as MapLibre GL JS reads it. */
29
+ top: number;
30
+ /** From the pen position to the next. */
31
+ advance: number;
32
+ };
33
+ /**
34
+ * Reads a glyph range, the `{fontstack}/{range}.pbf` file a style's `glyphs` URL points to: the
35
+ * glyphs of every font stack it holds. Glyphs whose bitmap does not match their size are skipped.
36
+ */
37
+ export declare function parseGlyphRange(data: ArrayBuffer | Uint8Array): Glyph[];
@@ -0,0 +1,103 @@
1
+ import type { Glyph } from "./glyph-pbf.js";
2
+ /** Options for a {@link GlyphStore}. */
3
+ export type GlyphStoreOptions = {
4
+ /** The style's `glyphs` URL, with `{fontstack}` and `{range}`. */
5
+ url: string;
6
+ /** Base URL that a relative `glyphs` URL resolves against, normally the style URL. */
7
+ baseUrl?: string;
8
+ fetch?: typeof fetch;
9
+ fetchOptions?: RequestInit;
10
+ };
11
+ /**
12
+ * Bound on the font stacks a store keeps glyphs for: stacks come from untrusted style and tile
13
+ * data. When full, the stack used least recently is dropped, and loaded again if asked for,
14
+ * unless a consumer retains it (see {@link GlyphStore.retain}).
15
+ */
16
+ export declare const MAX_GLYPH_STACKS = 64;
17
+ /** Bound on the font stacks one consumer, such as a label layer, can retain. */
18
+ export declare const MAX_RETAINED_GLYPH_STACKS: number;
19
+ /**
20
+ * Bound on the font stacks all the consumers of a store can retain together: the store never
21
+ * holds more than these, or {@link MAX_GLYPH_STACKS} when more.
22
+ */
23
+ export declare const MAX_STORE_RETAINED_GLYPH_STACKS: number;
24
+ /**
25
+ * Whether MapLibre GL JS draws a character with the browser's fonts rather than the style's
26
+ * glyphs: CJK ideographs, hangul, hiragana and katakana, by default (`localIdeographFontFamily`).
27
+ */
28
+ export declare function isLocalGlyph(codePoint: number): boolean;
29
+ export declare class GlyphStore {
30
+ /**
31
+ * Names this store among others, as of a style loaded again: a new store for the same URL holds
32
+ * none of the glyphs this one loaded.
33
+ */
34
+ readonly id: number;
35
+ readonly url: string;
36
+ private readonly fetch;
37
+ private readonly fetchOptions?;
38
+ private readonly stacks;
39
+ /** The font stacks each consumer retains (see `retain`). */
40
+ private readonly retained;
41
+ /** The number of consumers that retain each font stack retained. */
42
+ private readonly retainCounts;
43
+ /** Called once when a consumer next gives back a font stack (see `onRetainedFreed`). */
44
+ private readonly freedListeners;
45
+ constructor({ url, baseUrl, fetch: fetchFn, fetchOptions }: GlyphStoreOptions);
46
+ /**
47
+ * The glyph of a code point: `undefined` while its range is not loaded, `null` when the range
48
+ * has no glyph for it.
49
+ */
50
+ getGlyph(fontStack: string, codePoint: number): Glyph | null | undefined;
51
+ /** Whether the ranges of every code point of `text` are loaded, except local glyphs. */
52
+ hasGlyphs(fontStack: string, text: string): boolean;
53
+ /**
54
+ * Loads the ranges of the code points of `texts` that are not loaded yet. Resolves when they
55
+ * are, or have failed; returns null when there is nothing to load.
56
+ */
57
+ load(fontStack: string, texts: Iterable<string>): Promise<void> | null;
58
+ /**
59
+ * Keeps the glyphs of `fontStack` for `owner` until it gives the stack back (see `retainOnly`
60
+ * and `release`). A label layer retains the font stack of each label it draws or waits for
61
+ * before it loads any, so that loading some of them does not drop the others: a batch of
62
+ * labels in more than {@link MAX_GLYPH_STACKS} font stacks could otherwise never load.
63
+ *
64
+ * Returns false when the stack cannot be retained: `owner` retains
65
+ * {@link MAX_RETAINED_GLYPH_STACKS} stacks already, or the store's consumers
66
+ * {@link MAX_STORE_RETAINED_GLYPH_STACKS}. Font stacks come from untrusted tile data, so
67
+ * those bounds hold whatever a tile names; a label layer leaves the labels of a font stack it
68
+ * cannot retain undrawn, as those of a glyph range that fails to load.
69
+ */
70
+ retain(owner: object, fontStack: string): boolean;
71
+ /** Gives back the font stacks `owner` retains other than `fontStacks` (see `retain`). */
72
+ retainOnly(owner: object, fontStacks: ReadonlySet<string>): void;
73
+ /** Gives back the font stacks `owner` retains (see `retain`). */
74
+ release(owner: object): void;
75
+ /**
76
+ * Counts the times a consumer gave back font stacks: a `retain` refused before may succeed
77
+ * once it has changed.
78
+ */
79
+ generation: number;
80
+ /**
81
+ * Calls `listener` once, the next time a consumer gives back font stacks, in place of the
82
+ * listener `owner` set before; null removes it. A label layer whose font stacks were refused
83
+ * updates again then, to retain and load them.
84
+ */
85
+ onRetainedFreed(owner: object, listener: (() => void) | null): void;
86
+ /**
87
+ * The URL of a range: the font names of the stack, each URL-encoded, joined by commas. Font
88
+ * stacks can come from tile data (a data-driven `text-font`), so a name cannot add path
89
+ * segments, a query or a fragment to the URL.
90
+ */
91
+ getRangeUrl(fontStack: string, range: number): string;
92
+ private loadRange;
93
+ private getStack;
94
+ /**
95
+ * Drops the font stacks used least recently, beyond the bound, except those retained and
96
+ * `keep`, which is being loaded.
97
+ */
98
+ private evict;
99
+ private isRetained;
100
+ private unretain;
101
+ }
102
+ /** The index of the range that holds a code point. */
103
+ export declare function getGlyphRange(codePoint: number): number;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * How a placed part lets others overlap it, as MapLibre GL JS's `text-overlap` / `icon-overlap`:
3
+ * `never` overlaps nothing and is overlapped by nothing; `always` overlaps anything; `cooperative`
4
+ * overlaps `always` and `cooperative` parts, but not `never` ones.
5
+ */
6
+ export type OverlapMode = 'never' | 'always' | 'cooperative';
7
+ /** Whether a part placed with `mode` may overlap one placed with `placedMode`. */
8
+ export declare function allowsOverlap(mode: OverlapMode, placedMode: OverlapMode): boolean;
9
+ /**
10
+ * A grid of screen-space boxes and circles for label placement, as MapLibre GL JS's `GridIndex`:
11
+ * the plane is cut into square cells, each holding the shapes that reach into it, so that a test
12
+ * compares a shape only with the shapes of the cells it covers. Coordinates are pixels; a shape
13
+ * that reaches outside the grid is clamped to its edge cells.
14
+ */
15
+ export declare class GridIndex {
16
+ readonly width: number;
17
+ readonly height: number;
18
+ private readonly cellSize;
19
+ private readonly columns;
20
+ private readonly rows;
21
+ /** Per cell, the indices of the shapes in it. */
22
+ private readonly cells;
23
+ /** Per shape: `x1, y1, x2, y2` for a box, `x, y, radius, NaN` for a circle. */
24
+ private readonly shapes;
25
+ private readonly modes;
26
+ /** The query count at which each shape was last compared, so a query compares it once. */
27
+ private readonly seen;
28
+ private query;
29
+ constructor(width: number, height: number, cellSize: number);
30
+ /** The number of shapes inserted. */
31
+ get size(): number;
32
+ /** Adds a box from `x1, y1` to `x2, y2`. */
33
+ insert(x1: number, y1: number, x2: number, y2: number, mode?: OverlapMode): void;
34
+ /** Adds a circle. */
35
+ insertCircle(x: number, y: number, radius: number, mode?: OverlapMode): void;
36
+ /** Whether a box placed with `mode` would overlap a shape that it may not overlap. */
37
+ hitTest(x1: number, y1: number, x2: number, y2: number, mode?: OverlapMode): boolean;
38
+ /** Whether a circle placed with `mode` would overlap a shape that it may not overlap. */
39
+ hitTestCircle(x: number, y: number, radius: number, mode?: OverlapMode): boolean;
40
+ /** Whether a box lies at least partly within the grid. */
41
+ isInside(x1: number, y1: number, x2: number, y2: number): boolean;
42
+ private add;
43
+ private test;
44
+ /** Calls `visit` for each cell the box reaches, until it returns `true`. */
45
+ private forEachCell;
46
+ private toCell;
47
+ }
@@ -0,0 +1,154 @@
1
+ import type { Layer, LayersList, UpdateParameters } from '@deck.gl/core';
2
+ import { SharedTile2DLayer, SharedTileset2D } from '@deck.gl-community/geo-layers';
3
+ import type { SharedTile2DLayerProps, SharedTileset2DProps } from '@deck.gl-community/geo-layers';
4
+ import type { BasemapLoadOptions, BasemapSource } from "./style-resolver.js";
5
+ /**
6
+ * `hillshade` style layers over `raster-dem` sources, drawn as MapLibre GL JS draws them.
7
+ *
8
+ * MapLibre draws a hillshade in two passes. The first ("prepare") decodes each DEM tile into
9
+ * elevations and stores the slope of every pixel, scaled for the tile's zoom, in an 8-bit
10
+ * texture one pixel larger than the tile on every side. The second shades that texture with the
11
+ * layer's paint. Here the first pass runs on the CPU, with the same arithmetic and the same 8-bit
12
+ * rounding, and the second in the fragment shader of a `BitmapLayer`, ported from MapLibre's.
13
+ */
14
+ /** The encodings of a `raster-dem` source. */
15
+ export type DemEncoding = 'mapbox' | 'terrarium' | 'custom';
16
+ /** `[redFactor, greenFactor, blueFactor, baseShift]`: elevation = r·R + g·G + b·B − shift. */
17
+ export type DemUnpackVector = [number, number, number, number];
18
+ /** The elevations of a DEM tile, in meters, row by row from the north-west corner. */
19
+ export type DemTile = {
20
+ /** Width and height in pixels. */
21
+ dim: number;
22
+ elevations: Float32Array;
23
+ };
24
+ /** The unpack vector of a `raster-dem` source, as MapLibre GL JS's `DEMData` chooses it. */
25
+ export declare function getDemUnpackVector(source: BasemapSource): DemUnpackVector;
26
+ /** Decodes the RGBA pixels of a square DEM tile into elevations. */
27
+ export declare function decodeDemTile(pixels: ArrayLike<number>, width: number, height: number, [redFactor, greenFactor, blueFactor, baseShift]: DemUnpackVector): DemTile;
28
+ /**
29
+ * The DEM tile next to a tile, `dx` and `dy` (each -1, 0 or 1, not both 0) tiles away, or `null`
30
+ * where it is not loaded.
31
+ */
32
+ export type DemNeighbors = (dx: number, dy: number) => DemTile | null;
33
+ /**
34
+ * The slope texture of MapLibre GL JS's hillshade "prepare" pass, `dim + 2` pixels square: the
35
+ * tile and a one-pixel border, RGBA, with the scaled east-west and north-south slopes in red and
36
+ * green (128 is flat). Pixels past the tile's edges come from its loaded neighbors, and where a
37
+ * neighbor is missing, from the tile's nearest edge pixel, as MapLibre fills them.
38
+ *
39
+ * `zoom` is the tile's zoom, also where it is scaled up past its source's `maxzoom`. MapLibre
40
+ * scales the slopes by it, and exaggerates them below zoom 15.
41
+ */
42
+ export declare function prepareHillshadeTexture(dem: DemTile, zoom: number, getNeighbor?: DemNeighbors): Uint8ClampedArray<ArrayBuffer>;
43
+ /** The most light sources the shader takes. MapLibre takes any number. */
44
+ export declare const MAX_HILLSHADE_LIGHTS = 4;
45
+ /** A hillshade layer's paint, evaluated and ready for the shader (but for the map's bearing). */
46
+ export type HillshadeParameters = {
47
+ /** `hillshade-method`. */
48
+ method: number;
49
+ /** `hillshade-exaggeration`. */
50
+ exaggeration: number;
51
+ /** `hillshade-accent-color`, premultiplied RGBA in 0-1. */
52
+ accent: number[];
53
+ /** Whether the light turns with the map (`hillshade-illumination-anchor: viewport`). */
54
+ viewportAnchored: boolean;
55
+ /** One per light source, at most `MAX_HILLSHADE_LIGHTS`. Directions clockwise from north. */
56
+ directions: number[];
57
+ altitudes: number[];
58
+ /** Premultiplied RGBA in 0-1. */
59
+ shadows: number[][];
60
+ highlights: number[][];
61
+ };
62
+ /**
63
+ * The shader parameters of a hillshade layer's evaluated paint (see `getPaint`), with the
64
+ * specification's defaults for unset properties. As in MapLibre GL JS, the number of light sources
65
+ * is the number of `hillshade-highlight-color`s, and the other lists are lengthened to match by
66
+ * repeating their last value; only `multidirectional` uses more than the first.
67
+ */
68
+ export declare function getHillshadeParameters(paint: Record<string, unknown>): HillshadeParameters;
69
+ /** The `hillshade` shader module's uniforms. */
70
+ export type HillshadeUniforms = {
71
+ accent: number[];
72
+ altitudes: number[];
73
+ azimuths: number[];
74
+ shadows: number[];
75
+ highlights: number[];
76
+ latRange: [number, number];
77
+ exaggeration: number;
78
+ method: number;
79
+ lightCount: number;
80
+ };
81
+ /**
82
+ * The shader uniforms of a tile: its parameters, at the map's `bearing` (degrees) for a light
83
+ * anchored to the viewport, and the tile's latitude range `[north, south]`.
84
+ */
85
+ export declare function getHillshadeUniforms(parameters: HillshadeParameters, bearing: number, latRange: [number, number]): HillshadeUniforms;
86
+ /**
87
+ * Fetches and decodes a DEM tile. Colors are read as stored, without color space conversion or
88
+ * premultiplication, which would change the elevations. An empty response is a tile without data.
89
+ */
90
+ export declare function loadDemTile(url: string, unpack: DemUnpackVector, { signal, loadOptions }?: {
91
+ signal?: AbortSignal;
92
+ loadOptions?: BasemapLoadOptions;
93
+ }): Promise<DemTile | null>;
94
+ /**
95
+ * Creates the tileset of a `raster-dem` source: each tile is fetched and decoded once, and shared
96
+ * by every `HillshadeTileLayer` drawn from it, as the tiles of a vector source are shared by its
97
+ * style runs. `tilesetProps` are the source's tile pyramid (see `getTilePyramidProps`).
98
+ */
99
+ export declare function createSharedDemTileset(source: BasemapSource, loadOptions: BasemapLoadOptions | undefined, tilesetProps?: Partial<SharedTileset2DProps<DemTile | null>>): SharedTileset2D<DemTile | null>;
100
+ /**
101
+ * A tileset shared by the `HillshadeTileLayer`s of one `raster-dem` source, finalized when the
102
+ * last of them is. `BasemapLayer` owns its sources' tilesets itself; this is for the layers that
103
+ * `getBasemapLayers` creates without it.
104
+ */
105
+ export type DemTilesetOwner = {
106
+ tileset: SharedTileset2D;
107
+ consumers: Set<object>;
108
+ };
109
+ /** Props of a `HillshadeTileLayer`. */
110
+ export type HillshadeTileLayerProps = SharedTile2DLayerProps<DemTile | null> & {
111
+ hillshadeParameters: HillshadeParameters;
112
+ /** Extra props of every tile's bitmap layer, such as `parameters`. */
113
+ hillshadeSubLayerProps?: Record<string, unknown>;
114
+ /** The owner of a shared `data` tileset that the layer releases when finalized. */
115
+ demTilesetOwner?: DemTilesetOwner | null;
116
+ };
117
+ /**
118
+ * The tiles of a `raster-dem` source, shaded by one `hillshade` style layer. The decoded tiles
119
+ * come from the source's tileset, shared with the source's other hillshade layers (see
120
+ * `createSharedDemTileset`); the slopes and the shading are the layer's own. Each tile's slopes are
121
+ * prepared from its elevations and those of its loaded neighbors, so that tiles join without
122
+ * seams. Draws nothing on WebGPU: the shader is GLSL.
123
+ */
124
+ export declare class HillshadeTileLayer extends SharedTile2DLayer<DemTile | null, HillshadeTileLayerProps> {
125
+ static layerName: string;
126
+ static defaultProps: {
127
+ hillshadeParameters: {
128
+ type: string;
129
+ value: null;
130
+ compare: boolean;
131
+ };
132
+ hillshadeSubLayerProps: {
133
+ type: string;
134
+ value: null;
135
+ compare: boolean;
136
+ };
137
+ demTilesetOwner: {
138
+ type: string;
139
+ value: null;
140
+ compare: boolean;
141
+ };
142
+ };
143
+ state: SharedTile2DLayer<DemTile | null>['state'] & {
144
+ demTilesetOwner?: DemTilesetOwner;
145
+ /** Stands for this layer among an owner's consumers. */
146
+ demTilesetConsumer?: object;
147
+ };
148
+ updateState(params: UpdateParameters<this>): void;
149
+ finalizeState(): void;
150
+ private releaseDemTileset;
151
+ _onTileLoad(tile: any): void;
152
+ renderLayers(): Layer | null | LayersList;
153
+ renderSubLayers(props: any): Layer | null | LayersList;
154
+ }