@tangram.gl/basemap-layers 0.0.1 → 10.0.0-alpha.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/README.md +12 -7
- package/THIRD-PARTY-NOTICES.md +7 -5
- package/dist/geojson-task-worker.js +3166 -0
- package/dist/geojson-task-worker.js.map +6 -0
- package/dist/geojson-worker.js +1089 -7
- package/dist/geojson-worker.js.map +3 -3
- package/dist/index.cjs +9588 -2093
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +9599 -2090
- package/dist/index.js.map +3 -3
- package/dist/map-style.cjs +456 -20
- package/dist/map-style.cjs.map +3 -3
- package/dist/map-style.js +456 -19
- package/dist/map-style.js.map +2 -2
- package/dist/types/basemap-error.d.ts +52 -0
- package/dist/types/basemap-layer.d.ts +378 -25
- package/dist/types/basemap-protocol.d.ts +91 -0
- package/dist/types/basemap-request.d.ts +73 -0
- package/dist/types/circle-layer.d.ts +65 -8
- package/dist/types/color-relief-layer.d.ts +184 -0
- package/dist/types/dem-pixels.d.ts +40 -0
- package/dist/types/feature-state.d.ts +55 -0
- package/dist/types/fill-extrusion-lighting-extension.d.ts +1 -2
- package/dist/types/fill-outline-extension.d.ts +2 -3
- package/dist/types/fill-pattern.d.ts +35 -3
- package/dist/types/fill-style-extensions.d.ts +11 -59
- package/dist/types/geojson-resource.d.ts +18 -0
- package/dist/types/geojson-source.d.ts +13 -2
- package/dist/types/geojson-task-handler.d.ts +2 -0
- package/dist/types/geojson-task.d.ts +26 -0
- package/dist/types/geojson-tiler.d.ts +29 -2
- package/dist/types/geojson-worker.d.ts +5 -1
- package/dist/types/globe-horizon-extension.d.ts +2 -45
- package/dist/types/globe-layers.d.ts +141 -45
- package/dist/types/globe-line-angle-extension.d.ts +20 -17
- package/dist/types/glyph-store.d.ts +10 -1
- package/dist/types/heatmap-layer.d.ts +99 -0
- package/dist/types/hillshade-layer.d.ts +159 -27
- package/dist/types/icon-text-fit.d.ts +92 -0
- package/dist/types/image-source-layer.d.ts +142 -0
- package/dist/types/index.d.ts +25 -1
- package/dist/types/line-blur-extension.d.ts +3 -11
- package/dist/types/line-dash-extension.d.ts +53 -0
- package/dist/types/line-gradient-extension.d.ts +69 -0
- package/dist/types/line-metrics.d.ts +24 -0
- package/dist/types/line-pattern-extension.d.ts +50 -0
- package/dist/types/line-shape-extension.d.ts +76 -0
- package/dist/types/map-style-loader.d.ts +1 -1
- package/dist/types/map-style.d.ts +2 -2
- package/dist/types/mvt-label-layer.d.ts +111 -20
- package/dist/types/pmtiles-source.d.ts +38 -0
- package/dist/types/projected-background-layer.d.ts +63 -0
- package/dist/types/projected-bitmap-layer.d.ts +58 -0
- package/dist/types/projected-tile-data.d.ts +16 -0
- package/dist/types/projected-tile-selection.d.ts +72 -0
- package/dist/types/projected-tileset.d.ts +92 -0
- package/dist/types/projected-viewport.d.ts +76 -0
- package/dist/types/raster-color-extension.d.ts +4 -7
- package/dist/types/raster-fade.d.ts +155 -0
- package/dist/types/raster-tile-fingerprint.d.ts +11 -0
- package/dist/types/raster-tile-loader.d.ts +80 -0
- package/dist/types/shader-injection-plugin.d.ts +8 -0
- package/dist/types/source-features.d.ts +58 -0
- package/dist/types/source-tiles.d.ts +32 -0
- package/dist/types/sprite.d.ts +37 -3
- package/dist/types/stretch-icon-layer.d.ts +28 -0
- package/dist/types/style-accessor.d.ts +50 -12
- package/dist/types/style-expression.d.ts +22 -2
- package/dist/types/style-resolver.d.ts +47 -2
- package/dist/types/terrain-query.d.ts +39 -0
- package/dist/types/zoom-load-gate.d.ts +22 -0
- package/dist/types/zoom-paint-extension.d.ts +80 -11
- package/package.json +24 -21
- package/src/basemap-error.ts +82 -0
- package/src/basemap-layer.ts +1289 -101
- package/src/basemap-protocol.ts +353 -0
- package/src/basemap-request.ts +212 -0
- package/src/circle-layer.ts +430 -54
- package/src/color-relief-layer.ts +572 -0
- package/src/dem-pixels.ts +174 -0
- package/src/feature-state.ts +164 -0
- package/src/fill-extrusion-lighting-extension.ts +126 -9
- package/src/fill-outline-extension.ts +4 -4
- package/src/fill-pattern.ts +87 -9
- package/src/fill-style-extensions.ts +114 -44
- package/src/geojson-resource.ts +58 -0
- package/src/geojson-source.ts +106 -85
- package/src/geojson-task-handler.ts +11 -0
- package/src/geojson-task-worker.ts +8 -0
- package/src/geojson-task.ts +34 -0
- package/src/geojson-tiler.ts +270 -4
- package/src/geojson-worker.ts +36 -6
- package/src/globe-horizon-extension.ts +14 -4
- package/src/globe-layers.ts +1905 -406
- package/src/globe-line-angle-extension.ts +183 -23
- package/src/glyph-store.ts +28 -6
- package/src/heatmap-layer.ts +591 -0
- package/src/hillshade-layer.ts +309 -88
- package/src/icon-text-fit.ts +358 -0
- package/src/image-source-layer.ts +380 -0
- package/src/index.ts +58 -1
- package/src/line-blur-extension.ts +14 -12
- package/src/line-dash-extension.ts +303 -0
- package/src/line-gradient-extension.ts +191 -0
- package/src/line-metrics.ts +90 -0
- package/src/line-pattern-extension.ts +173 -0
- package/src/line-shape-extension.ts +272 -0
- package/src/map-style-loader.ts +5 -4
- package/src/map-style.ts +2 -1
- package/src/mvt-label-layer.ts +568 -144
- package/src/pmtiles-source.ts +276 -0
- package/src/projected-background-layer.ts +202 -0
- package/src/projected-bitmap-layer.ts +262 -0
- package/src/projected-tile-data.ts +132 -0
- package/src/projected-tile-selection.ts +605 -0
- package/src/projected-tileset.ts +183 -0
- package/src/projected-viewport.ts +254 -0
- package/src/raster-color-extension.ts +43 -18
- package/src/raster-fade.ts +319 -0
- package/src/raster-tile-fingerprint.ts +31 -0
- package/src/raster-tile-loader.ts +211 -0
- package/src/shader-injection-plugin.ts +25 -0
- package/src/source-features.ts +170 -0
- package/src/source-tiles.ts +102 -0
- package/src/sprite.ts +122 -15
- package/src/stretch-icon-layer.ts +87 -0
- package/src/style-accessor.ts +105 -17
- package/src/style-expression.ts +80 -3
- package/src/style-resolver.ts +200 -22
- package/src/terrain-query.ts +86 -0
- package/src/text-layout.ts +2 -3
- package/src/zoom-load-gate.ts +57 -0
- package/src/zoom-paint-extension.ts +245 -47
- package/dist/types/arabic-shaping.d.ts +0 -7
- package/dist/types/bidi.d.ts +0 -8
- package/dist/types/polylabel.d.ts +0 -17
- package/src/arabic-shaping.ts +0 -366
- package/src/bidi.ts +0 -199
- package/src/polylabel.ts +0 -312
package/src/mvt-label-layer.ts
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import {CompositeLayer} from '@deck.gl/core';
|
|
6
6
|
import {isGlobeViewport} from './is-globe-viewport';
|
|
7
|
+
import {
|
|
8
|
+
getProjectedPlaneAngle,
|
|
9
|
+
isGeographicViewport,
|
|
10
|
+
isPositionDrawn,
|
|
11
|
+
isProjectedViewport
|
|
12
|
+
} from './projected-viewport';
|
|
7
13
|
import type {DefaultProps, Layer, LayerContext, UpdateParameters, Viewport} from '@deck.gl/core';
|
|
8
14
|
import {
|
|
9
15
|
acquireSharedLabelPlacement,
|
|
@@ -29,10 +35,31 @@ import {
|
|
|
29
35
|
getStylePropertyDefault,
|
|
30
36
|
type CompiledStyleProperty
|
|
31
37
|
} from './style-expression';
|
|
32
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
getIconPartName,
|
|
40
|
+
getSpriteImageNames,
|
|
41
|
+
getStretchIconMapping,
|
|
42
|
+
isStretchableIcon,
|
|
43
|
+
resolveSpriteIcon,
|
|
44
|
+
warnMissingIcon
|
|
45
|
+
} from './sprite';
|
|
46
|
+
import {
|
|
47
|
+
fitIconToText,
|
|
48
|
+
getFittedIconCollisionBox,
|
|
49
|
+
getIconQuadBox,
|
|
50
|
+
getIconQuads
|
|
51
|
+
} from './icon-text-fit';
|
|
52
|
+
import type {FittedIcon, IconTextFit} from './icon-text-fit';
|
|
53
|
+
import {StretchIconLayer} from './stretch-icon-layer';
|
|
33
54
|
import type {ResolvedSpriteIcon, SpriteAtlas} from './sprite';
|
|
34
55
|
import {GlobeHorizonExtension} from './globe-horizon-extension';
|
|
35
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
FirstPersonLabelSizeExtension,
|
|
58
|
+
GlobeLineAngleExtension,
|
|
59
|
+
getFirstPersonLabelPerspective,
|
|
60
|
+
getFirstPersonLabelReferenceDepth
|
|
61
|
+
} from './globe-line-angle-extension';
|
|
62
|
+
import {isGeographicFirstPersonViewport} from './projected-background-layer';
|
|
36
63
|
import {DEFAULT_TEXT_FONT, getTextLayerFontWeight, resolveLabelFont} from './text-font';
|
|
37
64
|
import {getHaloBlurGamma, TextHaloBlurExtension} from './text-halo-blur-extension';
|
|
38
65
|
import {
|
|
@@ -63,7 +90,7 @@ import {
|
|
|
63
90
|
DEFAULT_POLE_SEARCH_SEGMENT_TESTS,
|
|
64
91
|
getPoleOfInaccessibility,
|
|
65
92
|
type PoleSearchBudget
|
|
66
|
-
} from '
|
|
93
|
+
} from '@math.gl/geometry/polygon';
|
|
67
94
|
import type {LabelFont, LabelFontFamily} from './text-font';
|
|
68
95
|
import {
|
|
69
96
|
DEFAULT_LINE_ANCHOR_STEPS,
|
|
@@ -93,6 +120,13 @@ type FeatureLike = {
|
|
|
93
120
|
properties?: Record<string, any>;
|
|
94
121
|
};
|
|
95
122
|
|
|
123
|
+
/**
|
|
124
|
+
* One quad of a label row's icon, fitted to its text (`part`), or the whole icon at its own size
|
|
125
|
+
* for a row without text (`part` null). It inherits the row's fields, such as `position` and
|
|
126
|
+
* `__source`, so accessors of rows read it as its row.
|
|
127
|
+
*/
|
|
128
|
+
type FittedIconPiece = LabelRow & {row: LabelRow; rowIndex: number; part: number | null};
|
|
129
|
+
|
|
96
130
|
type LabelRow = {
|
|
97
131
|
position: number[];
|
|
98
132
|
/** For labels along a line: the line's direction, in degrees counter-clockwise from east. */
|
|
@@ -183,16 +217,21 @@ export type MVTLabelLayerProps = {
|
|
|
183
217
|
* by one tile. Tile-local coordinates always use the tile's `[0, 1)` square.
|
|
184
218
|
*/
|
|
185
219
|
tileBoundingBox?: {west: number; south: number; east: number; north: number} | null;
|
|
186
|
-
/** The tile's zoom
|
|
220
|
+
/** The tile's index zoom. Defaults to the integer map zoom adjusted for the tile size. */
|
|
187
221
|
tileZoom?: number | null;
|
|
222
|
+
/**
|
|
223
|
+
* The source's deepest tile zoom (`maxzoom`), in tile-index zoom like `tileZoom`.
|
|
224
|
+
* Coarser tiles never overzoom.
|
|
225
|
+
*/
|
|
226
|
+
tileMaxZoom?: number | null;
|
|
188
227
|
/** The tile's size in pixels at its own zoom. Default: 512. */
|
|
189
228
|
tileSize?: number | null;
|
|
190
229
|
/**
|
|
191
230
|
* The label features of several tiles, labelled together in one layer instead of `data`: each
|
|
192
|
-
* tile's anchors are placed as for a layer of its own
|
|
193
|
-
* `
|
|
194
|
-
*
|
|
195
|
-
*
|
|
231
|
+
* tile's anchors are placed as for a layer of its own, using its `tileBoundingBox`, `tileZoom`,
|
|
232
|
+
* `tileMaxZoom` and `tileSize`, then drawn in longitude/latitude. Pass the same array while
|
|
233
|
+
* the tiles stay the same. A tile keeps its anchors while its features and placement inputs
|
|
234
|
+
* stay the same. See {@link LabelTile}.
|
|
196
235
|
*/
|
|
197
236
|
tiles?: LabelTile[] | null;
|
|
198
237
|
};
|
|
@@ -210,6 +249,11 @@ export type LabelTile = {
|
|
|
210
249
|
north: number;
|
|
211
250
|
} | null;
|
|
212
251
|
tileZoom?: number | null;
|
|
252
|
+
/**
|
|
253
|
+
* The source's deepest tile zoom (`maxzoom`), in tile-index zoom like `tileZoom`.
|
|
254
|
+
* Coarser tiles never overzoom.
|
|
255
|
+
*/
|
|
256
|
+
tileMaxZoom?: number | null;
|
|
213
257
|
tileSize?: number | null;
|
|
214
258
|
/** Returned as `info.tile` when a label of the tile is picked. */
|
|
215
259
|
tile?: unknown;
|
|
@@ -275,12 +319,32 @@ export function combineTileRows(tiles: LabelTile[], tileRows: LabelRow[][]): Lab
|
|
|
275
319
|
return combined;
|
|
276
320
|
}
|
|
277
321
|
|
|
322
|
+
/**
|
|
323
|
+
* The rows whose anchor lies on a tile of `tiles`. A tile of a low zoom holds labels of places far
|
|
324
|
+
* outside it, and a projected view draws only the tiles in the projection's area of use: an anchor
|
|
325
|
+
* on no drawn tile is off the drawn map. One on another drawn tile is kept, as a tile of a mixed
|
|
326
|
+
* selection may not hold the labels of its own area, which the buffer of a deeper tile does.
|
|
327
|
+
* Rows are in longitude/latitude.
|
|
328
|
+
*/
|
|
329
|
+
export function filterRowsOnDrawnTiles(tiles: LabelTile[], rows: LabelRow[]): LabelRow[] {
|
|
330
|
+
const keys = new Set(tiles.map(({index: {x, y, z}}) => getTileKey(x, y, z)));
|
|
331
|
+
const zooms = [...new Set(tiles.map(tile => tile.index.z))];
|
|
332
|
+
return rows.filter(row => {
|
|
333
|
+
const [wx, wy] = lngLatToWorld(row.position);
|
|
334
|
+
return zooms.some(z => {
|
|
335
|
+
const scale = 2 ** z;
|
|
336
|
+
const x = Math.floor(wx * scale);
|
|
337
|
+
return keys.has(getTileKey(((x % scale) + scale) % scale, Math.floor(wy * scale), z));
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
278
342
|
/**
|
|
279
343
|
* Draw parameters of the text, icon and anchor mark sublayers. Labels draw over the map without a depth test.
|
|
280
344
|
* Their screen-space quads wind clockwise, so `GlobeView`'s default `cullMode: 'back'` would cull
|
|
281
345
|
* every one of them; they are drawn with culling off, in every view.
|
|
282
346
|
*/
|
|
283
|
-
const LABEL_PARAMETERS = {
|
|
347
|
+
const LABEL_PARAMETERS = {depthCompare: 'always', cullMode: 'none'} as const;
|
|
284
348
|
|
|
285
349
|
/**
|
|
286
350
|
* Without a depth test, labels on the far side of a globe would draw through it. This extension
|
|
@@ -380,6 +444,15 @@ function getGlobeDrawnAngle(
|
|
|
380
444
|
return keepUpright && dx < 0 ? angle + Math.PI : angle;
|
|
381
445
|
}
|
|
382
446
|
|
|
447
|
+
/** Project a map-plane direction into the billboard's screen plane. */
|
|
448
|
+
function getMercatorDrawnAngle(toScreen: number[], angle: number, keepUpright: boolean): number {
|
|
449
|
+
const [ax, ay, bx, by] = toScreen;
|
|
450
|
+
const x = ax * Math.cos(angle) - bx * Math.sin(angle);
|
|
451
|
+
const y = ay * Math.cos(angle) - by * Math.sin(angle);
|
|
452
|
+
const projected = Math.atan2(-y, x);
|
|
453
|
+
return keepUpright && x < 0 ? projected + Math.PI : projected;
|
|
454
|
+
}
|
|
455
|
+
|
|
383
456
|
/** What placement needs of a label layer's rows that does not change with the view. */
|
|
384
457
|
type PlacementGeometry = {
|
|
385
458
|
key: unknown[];
|
|
@@ -416,6 +489,24 @@ const GLOBE_LINE_ANGLE_EXTENSIONS = {
|
|
|
416
489
|
uprightText: new GlobeLineAngleExtension({keepUpright: true, keepOffsetSide: true})
|
|
417
490
|
};
|
|
418
491
|
|
|
492
|
+
const MERCATOR_TEXT_ANGLE_EXTENSIONS = {
|
|
493
|
+
free: new GlobeLineAngleExtension({keepUpright: false, mercator: true}),
|
|
494
|
+
upright: new GlobeLineAngleExtension({keepUpright: true, keepOffsetSide: true, mercator: true})
|
|
495
|
+
};
|
|
496
|
+
const FIRST_PERSON_LABEL_SIZE_EXTENSION = new FirstPersonLabelSizeExtension();
|
|
497
|
+
|
|
498
|
+
/** One quad of an icon stretched by `icon-text-fit`, as a `StretchIconLayer` draws it. */
|
|
499
|
+
type FittedIconPart = {
|
|
500
|
+
/** The mapping entry of the quad's part of the image (see `getStretchIconMapping`). */
|
|
501
|
+
name: string;
|
|
502
|
+
/** Height in pixels. */
|
|
503
|
+
size: number;
|
|
504
|
+
/** `getIconStretch`: the width over the image part's aspect ratio at `size`. */
|
|
505
|
+
stretch: [number, number];
|
|
506
|
+
/** The quad's center in pixels from the anchor, before the icon turns. */
|
|
507
|
+
offset: [number, number];
|
|
508
|
+
};
|
|
509
|
+
|
|
419
510
|
/** `text-anchor` / `icon-anchor` as a horizontal and vertical fraction from the center. */
|
|
420
511
|
const ANCHOR_FRACTIONS: Record<string, [number, number]> = {
|
|
421
512
|
center: [0, 0],
|
|
@@ -508,6 +599,10 @@ type MVTLabelLayerState = {
|
|
|
508
599
|
/** See `getPlacementGeometry`. */
|
|
509
600
|
placementGeometry?: PlacementGeometry;
|
|
510
601
|
placementRowBoxes?: {key: unknown[]; boxes: WeakMap<LabelRow, Float64Array>};
|
|
602
|
+
/** Each row's icon parts with `icon-text-fit` (see `getFittedIconParts`). */
|
|
603
|
+
fittedIconParts?: {key: unknown[]; parts: (FittedIconPart[] | null)[]; revision: number};
|
|
604
|
+
/** The data of each fitted icon layer, by its id (see `getFittedIconPieces`). */
|
|
605
|
+
fittedIconPieces?: Map<string, {key: unknown[]; pieces: FittedIconPiece[]}>;
|
|
511
606
|
placementCommons?: {kind: string; positions: WeakMap<LabelRow, number[]>};
|
|
512
607
|
/** The slot accessor of `getRows` from `placementSlotBase` (see `getPlacementSlotAccessor`). */
|
|
513
608
|
placementSlots?: {rows: LabelRow[]; base: number; accessor: (row: LabelRow) => number};
|
|
@@ -521,6 +616,7 @@ type MVTLabelLayerState = {
|
|
|
521
616
|
glyphKey?: string;
|
|
522
617
|
/** The map bearing, in `BEARING_STEP` steps, that upright line labels were turned for. */
|
|
523
618
|
bearingStep?: number;
|
|
619
|
+
firstPersonText?: boolean;
|
|
524
620
|
/** 1 while the layer waits for glyphs of the labels' text to load (see `hasLabelGlyphs`). */
|
|
525
621
|
glyphLoads?: number;
|
|
526
622
|
/** The glyph store the layer waits on while `glyphLoads` is 1. */
|
|
@@ -1013,7 +1109,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1013
1109
|
private placingTile: LabelTile | null = null;
|
|
1014
1110
|
|
|
1015
1111
|
/** The tile props that anchors are placed with: the tile being placed, or this layer's. */
|
|
1016
|
-
getTileProps(): Pick<MVTLabelLayerProps, 'tileBoundingBox' | 'tileZoom' | 'tileSize'> {
|
|
1112
|
+
getTileProps(): Pick<MVTLabelLayerProps, 'tileBoundingBox' | 'tileZoom' | 'tileMaxZoom' | 'tileSize'> {
|
|
1017
1113
|
return this.placingTile ?? this.props;
|
|
1018
1114
|
}
|
|
1019
1115
|
|
|
@@ -1257,7 +1353,8 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1257
1353
|
/**
|
|
1258
1354
|
* One `IconLayer` per sprite that this layer's icons come from. Each holds every label row, so
|
|
1259
1355
|
* an icon has the same row index, and so the same placement slot, as its own label. Rows whose
|
|
1260
|
-
* icon is in another sprite, or in none, draw nothing.
|
|
1356
|
+
* icon is in another sprite, or in none, draw nothing. With `icon-text-fit`, a sprite's layer
|
|
1357
|
+
* holds the quads of its rows' icons instead, each in its row's placement slot.
|
|
1261
1358
|
*
|
|
1262
1359
|
* `icon-image` is evaluated once per row. Each sprite's layer evaluates the other style
|
|
1263
1360
|
* properties only for its own rows and gives every other row constants, so the style evaluation
|
|
@@ -1266,7 +1363,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1266
1363
|
* data cannot.
|
|
1267
1364
|
*/
|
|
1268
1365
|
renderIconLayers(icons: (ResolvedSpriteIcon | null)[] = this.getRowIcons()): any[] {
|
|
1269
|
-
const {iconLoadOptions, billboard, spriteAtlases} = this.props;
|
|
1366
|
+
const {iconLoadOptions, billboard, labelSizeUnits, spriteAtlases} = this.props;
|
|
1270
1367
|
const labelRows = this.getRows();
|
|
1271
1368
|
const atlases = new Set<SpriteAtlas>();
|
|
1272
1369
|
for (const icon of icons) {
|
|
@@ -1280,6 +1377,12 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1280
1377
|
}
|
|
1281
1378
|
const groups = this.getSymbolPartGroups('icon', () => this.getRowsWithText());
|
|
1282
1379
|
const {props: angleProps, getAngle, extensions: angleExtensions} = this.getIconAngleProps();
|
|
1380
|
+
const scaleBillboard =
|
|
1381
|
+
labelSizeUnits === 'pixels' &&
|
|
1382
|
+
(angleProps.billboard ?? billboard) &&
|
|
1383
|
+
isGeographicFirstPersonViewport(this.context?.viewport);
|
|
1384
|
+
const textFit = this.getStyleProperty('text-field') ? this.getIconTextFit() : 'none';
|
|
1385
|
+
const fitted = textFit === 'none' ? null : this.getFittedIconParts(icons, textFit);
|
|
1283
1386
|
// Sprite ids are arbitrary strings, so `${id}${idSuffix}` (and a copy's `-overlap`) can repeat
|
|
1284
1387
|
// another sprite's id; a repeated id gets a number.
|
|
1285
1388
|
const ids = new Set<string>();
|
|
@@ -1300,47 +1403,143 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1300
1403
|
return (row: LabelRow, info: {index: number}) =>
|
|
1301
1404
|
isOwnRow(info.index) ? getValue(row, info) : fallback;
|
|
1302
1405
|
};
|
|
1303
|
-
const
|
|
1304
|
-
...this.getSubLayerProps({id: getUniqueId(`icons-${atlas.id}${idSuffix}`)}),
|
|
1406
|
+
const props = {
|
|
1305
1407
|
data: labelRows,
|
|
1306
1408
|
iconAtlas: this.getIconAtlas(atlas) as any,
|
|
1307
|
-
iconMapping: atlas.mapping,
|
|
1308
1409
|
loadOptions: iconLoadOptions || undefined,
|
|
1309
1410
|
billboard,
|
|
1310
1411
|
...angleProps,
|
|
1311
1412
|
...(getAngle ? {getAngle} : {}),
|
|
1312
|
-
sizeUnits: 'pixels',
|
|
1413
|
+
sizeUnits: 'pixels' as const,
|
|
1313
1414
|
parameters: LABEL_PARAMETERS,
|
|
1314
1415
|
extensions: [
|
|
1315
1416
|
...(this.props.extensions || []),
|
|
1316
1417
|
LABEL_PLACEMENT_EXTENSION,
|
|
1317
1418
|
GLOBE_HORIZON_EXTENSION,
|
|
1318
|
-
...angleExtensions
|
|
1419
|
+
...angleExtensions,
|
|
1420
|
+
...(scaleBillboard ? [FIRST_PERSON_LABEL_SIZE_EXTENSION] : [])
|
|
1319
1421
|
],
|
|
1320
1422
|
...this.getPlacementProps(1),
|
|
1321
1423
|
getPosition: (d: LabelRow) => d.position,
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1424
|
+
getColor: forOwnRows(feature => this.getIconColor(feature), [0, 0, 0, 0]) as any
|
|
1425
|
+
};
|
|
1426
|
+
const iconTriggers = this.getIconUpdateTriggers();
|
|
1427
|
+
const updateTriggers = {
|
|
1428
|
+
...iconTriggers,
|
|
1429
|
+
getPlacementSlot: this.state.placementSlotBase,
|
|
1430
|
+
// The sprite list decides which rows `icon-image` resolves into this sprite, and which
|
|
1431
|
+
// rows have text decides the group's rows. The latter's change between split and
|
|
1432
|
+
// unsplit groups also refreshes the rows masked out before.
|
|
1433
|
+
all: [atlas, spriteAtlases, rows ? this.getLabelUpdateTriggers().getText : null]
|
|
1434
|
+
};
|
|
1435
|
+
const getIconSize = forOwnRows(feature => this.getIconSize(feature), 0);
|
|
1436
|
+
const getIconOffset = forOwnRows(
|
|
1437
|
+
feature => this.getIconPixelOffset(feature),
|
|
1438
|
+
[0, 0] as [number, number]
|
|
1439
|
+
);
|
|
1440
|
+
if (!fitted) {
|
|
1441
|
+
return [
|
|
1442
|
+
new IconLayer({
|
|
1443
|
+
...this.getSubLayerProps({id: getUniqueId(`icons-${atlas.id}${idSuffix}`)}),
|
|
1444
|
+
...props,
|
|
1445
|
+
iconMapping: atlas.mapping,
|
|
1446
|
+
getIcon: ((_: LabelRow, {index}: {index: number}) =>
|
|
1447
|
+
isOwnRow(index) ? icons[index]!.name : null) as any,
|
|
1448
|
+
getSize: getIconSize as any,
|
|
1449
|
+
getPixelOffset: withIconAngle(getIconOffset, getAngle) as any,
|
|
1450
|
+
updateTriggers
|
|
1451
|
+
})
|
|
1452
|
+
];
|
|
1453
|
+
}
|
|
1454
|
+
// One layer of the quads of the icons fitted to their text: each icon's quads one after the
|
|
1455
|
+
// other, in row order, so that an icon is drawn whole before the next one, as MapLibre GL JS
|
|
1456
|
+
// draws its icon quads. A row without a fitted icon draws its icon at its own size.
|
|
1457
|
+
const {parts, revision} = fitted;
|
|
1458
|
+
const id = getUniqueId(`icons-fit-${atlas.id}${idSuffix}`);
|
|
1459
|
+
const pieces = this.getFittedIconPieces(id, parts, icons, rows, atlas);
|
|
1460
|
+
const getPart = (piece: FittedIconPiece) =>
|
|
1461
|
+
piece.part === null ? null : parts[piece.rowIndex]![piece.part]!;
|
|
1462
|
+
// Row accessors, called with the piece's row and the row's index.
|
|
1463
|
+
const onRow =
|
|
1464
|
+
<T>(accessor: (row: LabelRow, info: {index: number}) => T) =>
|
|
1465
|
+
(piece: FittedIconPiece, info: {index: number}) =>
|
|
1466
|
+
accessor(piece.row, {...info, index: piece.rowIndex});
|
|
1467
|
+
const getPlacementSlot = this.getPlacementSlotAccessor();
|
|
1468
|
+
return [
|
|
1469
|
+
new StretchIconLayer({
|
|
1470
|
+
...this.getSubLayerProps({id}),
|
|
1471
|
+
...props,
|
|
1472
|
+
data: pieces,
|
|
1473
|
+
getColor: onRow(props.getColor) as any,
|
|
1474
|
+
getPlacementSlot:
|
|
1475
|
+
typeof getPlacementSlot === 'function'
|
|
1476
|
+
? (piece: FittedIconPiece) => getPlacementSlot(piece.row)
|
|
1477
|
+
: getPlacementSlot,
|
|
1478
|
+
iconMapping: getStretchIconMapping(atlas),
|
|
1479
|
+
getIcon: ((piece: FittedIconPiece) =>
|
|
1480
|
+
getPart(piece)?.name ?? icons[piece.rowIndex]!.name) as any,
|
|
1481
|
+
getSize: ((piece: FittedIconPiece, info: {index: number}) =>
|
|
1482
|
+
getPart(piece)?.size ?? onRow(getIconSize)(piece, info)) as any,
|
|
1483
|
+
getIconStretch: (piece: FittedIconPiece) => getPart(piece)?.stretch ?? [1, 1],
|
|
1484
|
+
getPixelOffset: withIconAngle(
|
|
1485
|
+
(piece, info) =>
|
|
1486
|
+
getPart(piece as FittedIconPiece)?.offset ??
|
|
1487
|
+
onRow(getIconOffset)(piece as FittedIconPiece, info),
|
|
1488
|
+
getAngle
|
|
1489
|
+
) as any,
|
|
1490
|
+
updateTriggers: {
|
|
1491
|
+
...updateTriggers,
|
|
1492
|
+
getIcon: `${iconTriggers.getIcon}|${revision}`,
|
|
1493
|
+
getSize: `${iconTriggers.getSize}|${revision}`,
|
|
1494
|
+
getIconStretch: revision,
|
|
1495
|
+
getPixelOffset: `${iconTriggers.getPixelOffset}|${revision}`
|
|
1496
|
+
}
|
|
1497
|
+
})
|
|
1498
|
+
];
|
|
1340
1499
|
})
|
|
1341
1500
|
);
|
|
1342
1501
|
}
|
|
1343
1502
|
|
|
1503
|
+
/**
|
|
1504
|
+
* The data of a fitted icon layer: the quads of each row whose icon is in `atlas`, and in the
|
|
1505
|
+
* group's `rows`, in row order (see `FittedIconPiece`). It is kept while its inputs stay the
|
|
1506
|
+
* same, so the layer's attributes are not made again at each render.
|
|
1507
|
+
*/
|
|
1508
|
+
getFittedIconPieces(
|
|
1509
|
+
id: string,
|
|
1510
|
+
parts: (FittedIconPart[] | null)[],
|
|
1511
|
+
icons: (ResolvedSpriteIcon | null)[],
|
|
1512
|
+
rows: boolean[] | null | undefined,
|
|
1513
|
+
atlas: SpriteAtlas
|
|
1514
|
+
): FittedIconPiece[] {
|
|
1515
|
+
const labelRows = this.getRows();
|
|
1516
|
+
// `parts` is made again whenever the rows' icons can change (see `getFittedIconParts`).
|
|
1517
|
+
const key = [labelRows, parts, rows, atlas];
|
|
1518
|
+
this.state.fittedIconPieces ||= new Map();
|
|
1519
|
+
const cached = this.state.fittedIconPieces.get(id);
|
|
1520
|
+
if (cached && cached.key.every((value, index) => value === key[index])) {
|
|
1521
|
+
return cached.pieces;
|
|
1522
|
+
}
|
|
1523
|
+
const pieces: FittedIconPiece[] = [];
|
|
1524
|
+
const addPiece = (row: LabelRow, rowIndex: number, part: number | null) =>
|
|
1525
|
+
pieces.push(Object.assign(Object.create(row), {row, rowIndex, part}));
|
|
1526
|
+
labelRows.forEach((row, rowIndex) => {
|
|
1527
|
+
if (icons[rowIndex]?.atlas !== atlas || (rows && !rows[rowIndex])) {
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
const rowParts = parts[rowIndex];
|
|
1531
|
+
if (!rowParts) {
|
|
1532
|
+
addPiece(row, rowIndex, null);
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
for (let part = 0; part < rowParts.length; part++) {
|
|
1536
|
+
addPiece(row, rowIndex, part);
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
this.state.fittedIconPieces.set(id, {key, pieces});
|
|
1540
|
+
return pieces;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1344
1543
|
/**
|
|
1345
1544
|
* The label rows in the order every text and icon sublayer holds them: `labelData` in reverse.
|
|
1346
1545
|
* A symbol's placement slot follows its index here, so an icon and its label share it; every
|
|
@@ -1901,9 +2100,15 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1901
2100
|
'text-padding',
|
|
1902
2101
|
'text-size',
|
|
1903
2102
|
'text-rotation-alignment',
|
|
2103
|
+
'text-rotate',
|
|
1904
2104
|
'symbol-placement'
|
|
1905
2105
|
),
|
|
1906
|
-
getAngle: `${this.state?.bearingStep}|${getTrigger(
|
|
2106
|
+
getAngle: `${this.state?.bearingStep}|${getTrigger(
|
|
2107
|
+
'text-keep-upright',
|
|
2108
|
+
'text-pitch-alignment',
|
|
2109
|
+
'text-rotate',
|
|
2110
|
+
'symbol-placement'
|
|
2111
|
+
)}`,
|
|
1907
2112
|
// Also lays out the lines of each label (see `LabelTextLayer`).
|
|
1908
2113
|
getTextAnchor: getTrigger(
|
|
1909
2114
|
'text-anchor',
|
|
@@ -1943,6 +2148,139 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1943
2148
|
);
|
|
1944
2149
|
}
|
|
1945
2150
|
|
|
2151
|
+
/**
|
|
2152
|
+
* The width and height in pixels of a feature's label at its `text-size`: its widest line, with
|
|
2153
|
+
* letter spacing between characters, by its lines at `text-line-height`.
|
|
2154
|
+
*/
|
|
2155
|
+
measureLabel(
|
|
2156
|
+
feature: FeatureLike,
|
|
2157
|
+
measure: (character: string) => number,
|
|
2158
|
+
lineHeight: number
|
|
2159
|
+
): [number, number] {
|
|
2160
|
+
const label = this.getLabel(feature) || '';
|
|
2161
|
+
const size = this.getLabelSize(feature);
|
|
2162
|
+
const spacing = this.getLetterSpacing(feature, label);
|
|
2163
|
+
const lines = label.split('\n');
|
|
2164
|
+
let textWidth = 0;
|
|
2165
|
+
for (const line of lines) {
|
|
2166
|
+
const characters = Array.from(line);
|
|
2167
|
+
let lineWidth = 0;
|
|
2168
|
+
for (const character of characters) {
|
|
2169
|
+
lineWidth += measure(character);
|
|
2170
|
+
}
|
|
2171
|
+
lineWidth += Math.max(0, characters.length - 1) * spacing;
|
|
2172
|
+
textWidth = Math.max(textWidth, lineWidth);
|
|
2173
|
+
}
|
|
2174
|
+
return [textWidth * size, lines.length * lineHeight * size];
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
/** `icon-text-fit` at the stepped zoom. */
|
|
2178
|
+
getIconTextFit(): IconTextFit {
|
|
2179
|
+
const value = this.getStyleProperty('icon-text-fit')?.evaluate(
|
|
2180
|
+
getZoomBucket(this.props.zoom || 0)
|
|
2181
|
+
);
|
|
2182
|
+
return value === 'width' || value === 'height' || value === 'both' ? value : 'none';
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
/**
|
|
2186
|
+
* A row's icon stretched to its text by `icon-text-fit` (see `fitIconToText`), at `icon-size` 1.
|
|
2187
|
+
* As in MapLibre, the text box is the one laid out for collision: at the collision text size, with
|
|
2188
|
+
* `text-anchor` and `text-offset`. `icon-anchor` is not read.
|
|
2189
|
+
*/
|
|
2190
|
+
getFittedIcon(
|
|
2191
|
+
row: LabelRow,
|
|
2192
|
+
icon: ResolvedSpriteIcon,
|
|
2193
|
+
textFit: IconTextFit,
|
|
2194
|
+
measure: (character: string) => number,
|
|
2195
|
+
lineHeight: number
|
|
2196
|
+
): FittedIcon {
|
|
2197
|
+
const feature = (row as any).__source?.object ?? row;
|
|
2198
|
+
const size = this.getLabelSize(feature);
|
|
2199
|
+
const [w, h] = this.measureLabel(feature, measure, lineHeight);
|
|
2200
|
+
const [ax, ay] = ANCHOR_FRACTIONS[this.getRowAnchor(row)] || ANCHOR_FRACTIONS.center;
|
|
2201
|
+
const [dx, dy] = this.getRowPixelOffset(row);
|
|
2202
|
+
const linePlacement = isLinePlacement(this.getSymbolPlacement());
|
|
2203
|
+
const scale = linePlacement || !(size > 0) ? 1 : this.getCollisionLabelSize(feature) / size;
|
|
2204
|
+
const left = (-(ax + 0.5) * w + dx) * scale;
|
|
2205
|
+
const top = (-(ay + 0.5) * h + dy) * scale;
|
|
2206
|
+
const padding = ((this.getStyleProperty('icon-text-fit-padding')?.evaluate(
|
|
2207
|
+
getZoomBucket(this.props.zoom || 0)
|
|
2208
|
+
) as number[] | undefined) ?? (getStylePropertyDefault('icon-text-fit-padding') as number[])).map(
|
|
2209
|
+
value => Number(value) || 0
|
|
2210
|
+
);
|
|
2211
|
+
const offset = (this.evaluateStyleProperty('icon-offset', feature) as number[] | undefined) || [
|
|
2212
|
+
0, 0
|
|
2213
|
+
];
|
|
2214
|
+
return fitIconToText(
|
|
2215
|
+
icon.entry,
|
|
2216
|
+
{left, top, right: left + w * scale, bottom: top + h * scale},
|
|
2217
|
+
textFit,
|
|
2218
|
+
padding,
|
|
2219
|
+
offset
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
/**
|
|
2224
|
+
* The parts each label row's icon is drawn in with `icon-text-fit`, in `getRows` order: for a row
|
|
2225
|
+
* with text, one per quad of its fitted icon (see `getIconQuads`); `null` for a row whose icon is
|
|
2226
|
+
* drawn at its own size (it has no text) or that has no icon. Kept while the rows, their text,
|
|
2227
|
+
* the sprites, the style's layout values, the font's measured widths and the zoom step are the
|
|
2228
|
+
* same; `revision` changes when they are made again.
|
|
2229
|
+
*/
|
|
2230
|
+
getFittedIconParts(
|
|
2231
|
+
icons: (ResolvedSpriteIcon | null)[],
|
|
2232
|
+
textFit: IconTextFit
|
|
2233
|
+
): {parts: (FittedIconPart[] | null)[]; revision: number} {
|
|
2234
|
+
const {spriteAtlases, styleLayer, fontFamily} = this.props;
|
|
2235
|
+
const rows = this.getRows();
|
|
2236
|
+
const zoom = getZoomBucket(this.props.zoom || 0);
|
|
2237
|
+
const key = [
|
|
2238
|
+
rows,
|
|
2239
|
+
this.state.labelText,
|
|
2240
|
+
spriteAtlases,
|
|
2241
|
+
styleLayer,
|
|
2242
|
+
fontFamily,
|
|
2243
|
+
this.getFontKey(),
|
|
2244
|
+
this.getLineGlyphWidthsRevision()(),
|
|
2245
|
+
zoom,
|
|
2246
|
+
...(styleLayer?.layout ? Object.entries(styleLayer.layout).flat() : [])
|
|
2247
|
+
];
|
|
2248
|
+
const cached = this.state.fittedIconParts;
|
|
2249
|
+
if (cached && isSameList(cached.key, key)) {
|
|
2250
|
+
return cached;
|
|
2251
|
+
}
|
|
2252
|
+
const rowsWithText = this.getRowsWithText();
|
|
2253
|
+
const measure = this.getCharacterMeasurer();
|
|
2254
|
+
const lineHeight = this.getLineHeight();
|
|
2255
|
+
const parts = rows.map((row, index) => {
|
|
2256
|
+
const icon = icons[index];
|
|
2257
|
+
if (!icon || !rowsWithText[index]) {
|
|
2258
|
+
return null;
|
|
2259
|
+
}
|
|
2260
|
+
const feature = (row as any).__source?.object ?? row;
|
|
2261
|
+
const iconSize = Number(this.evaluateStyleProperty('icon-size', feature) ?? 1);
|
|
2262
|
+
const fitted = this.getFittedIcon(row, icon, textFit, measure, lineHeight);
|
|
2263
|
+
const quads = getIconQuads(icon.entry, fitted);
|
|
2264
|
+
const stretchable = isStretchableIcon(icon.entry);
|
|
2265
|
+
return quads.map((quad, quadIndex): FittedIconPart => {
|
|
2266
|
+
const box = getIconQuadBox(quad, iconSize);
|
|
2267
|
+
const width = box.right - box.left;
|
|
2268
|
+
const height = box.bottom - box.top;
|
|
2269
|
+
// `IconLayer` sizes an icon by its height, keeping its image's aspect ratio unless stretched.
|
|
2270
|
+
const imageAspect = quad.image.width / quad.image.height;
|
|
2271
|
+
return {
|
|
2272
|
+
name: stretchable ? getIconPartName(icon.name, quadIndex) : icon.name,
|
|
2273
|
+
size: Math.max(0, height),
|
|
2274
|
+
stretch: [height > 0 ? Math.max(0, width) / height / imageAspect : 1, 1],
|
|
2275
|
+
offset: [(box.left + box.right) / 2, (box.top + box.bottom) / 2]
|
|
2276
|
+
};
|
|
2277
|
+
});
|
|
2278
|
+
});
|
|
2279
|
+
const result = {key, parts, revision: (cached?.revision ?? 0) + 1};
|
|
2280
|
+
this.state.fittedIconParts = result;
|
|
2281
|
+
return result;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
1946
2284
|
/**
|
|
1947
2285
|
* The tile's own extent in feature coordinates: the `[0, 1)` square for tile-local coordinates,
|
|
1948
2286
|
* the tile's longitude/latitude box for globe tiles, or null when it is not known.
|
|
@@ -1969,7 +2307,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
1969
2307
|
*/
|
|
1970
2308
|
getLabelAnchors(
|
|
1971
2309
|
feature: FeatureLike,
|
|
1972
|
-
geographic: boolean =
|
|
2310
|
+
geographic: boolean = isGeographicViewport(this.context?.viewport),
|
|
1973
2311
|
placement: string = this.getSymbolPlacement(),
|
|
1974
2312
|
budget: PoleSearchBudget = {segmentTests: TILE_POLE_SEARCH_SEGMENT_TESTS}
|
|
1975
2313
|
): number[][] {
|
|
@@ -2008,10 +2346,10 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2008
2346
|
}
|
|
2009
2347
|
|
|
2010
2348
|
/**
|
|
2011
|
-
*
|
|
2012
|
-
*
|
|
2013
|
-
*
|
|
2014
|
-
*
|
|
2349
|
+
* Returns the placement zoom for line labels and the tile's pixel size at that zoom.
|
|
2350
|
+
* The tile's own zoom accounts for its size. For a 256 px tile it is one less than its index zoom.
|
|
2351
|
+
* At the source's deepest tile level, or if the limit is unknown, placement can scale up to
|
|
2352
|
+
* the integer map zoom. Coarser tiles always use their own zoom.
|
|
2015
2353
|
*/
|
|
2016
2354
|
getLinePlacementScale(): {zoom: number; tileZoom: number; tileSize: number} {
|
|
2017
2355
|
const mapZoom = Math.floor(this.props.zoom || 0);
|
|
@@ -2019,7 +2357,10 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2019
2357
|
const size = tileProps.tileSize || 512;
|
|
2020
2358
|
const tileZoom = tileProps.tileZoom ?? mapZoom + Math.log2(512 / size);
|
|
2021
2359
|
const ownZoom = tileZoom - Math.log2(512 / size);
|
|
2022
|
-
const
|
|
2360
|
+
const {tileMaxZoom} = tileProps;
|
|
2361
|
+
const canOverzoom =
|
|
2362
|
+
tileMaxZoom == null || !Number.isFinite(tileMaxZoom) || tileZoom >= tileMaxZoom;
|
|
2363
|
+
const zoom = canOverzoom ? Math.max(ownZoom, mapZoom) : ownZoom;
|
|
2023
2364
|
return {zoom, tileZoom, tileSize: size * 2 ** (zoom - ownZoom)};
|
|
2024
2365
|
}
|
|
2025
2366
|
|
|
@@ -2234,7 +2575,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2234
2575
|
const lineBudget = {steps: TILE_LINE_ANCHOR_STEPS};
|
|
2235
2576
|
const lineContext = isLinePlacement(placement) ? this.getLinePlacementContext() : undefined;
|
|
2236
2577
|
const merged = placement === 'line' ? this.getMergedLines(features) : null;
|
|
2237
|
-
|
|
2578
|
+
const rows = features.flatMap((feature, index) =>
|
|
2238
2579
|
isLinePlacement(placement) && isLineGeometry(feature)
|
|
2239
2580
|
? merged?.[index] === null
|
|
2240
2581
|
? []
|
|
@@ -2261,20 +2602,29 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2261
2602
|
);
|
|
2262
2603
|
})
|
|
2263
2604
|
);
|
|
2605
|
+
// A projected view moves a position outside the area of use of its projection to the edge of
|
|
2606
|
+
// that area: a label there would show on the edge, far from its place. Checked once for each
|
|
2607
|
+
// row, when the rows of a tile are made.
|
|
2608
|
+
const viewport = this.context?.viewport;
|
|
2609
|
+
return isProjectedViewport(viewport)
|
|
2610
|
+
? rows.filter(row => isPositionDrawn(viewport, row.position))
|
|
2611
|
+
: rows;
|
|
2264
2612
|
}
|
|
2265
2613
|
|
|
2266
2614
|
/**
|
|
2267
2615
|
* The inputs besides the tile data that the anchors depend on: `symbol-placement`, the
|
|
2268
|
-
* coordinate mode, the tile's extent and, for
|
|
2269
|
-
* along lines also depend on the placement scale and on the style values that size
|
|
2270
|
-
* them.
|
|
2616
|
+
* coordinate mode, the tile's extent and, for geographic polygon anchors, the search precision's
|
|
2617
|
+
* zoom. Labels along lines also depend on the placement scale and on the style values that size
|
|
2618
|
+
* and space them.
|
|
2271
2619
|
*/
|
|
2272
2620
|
getAnchorKey(geographic: boolean): string {
|
|
2273
2621
|
const placement = this.getSymbolPlacement();
|
|
2274
2622
|
return JSON.stringify([
|
|
2275
2623
|
placement,
|
|
2276
2624
|
geographic,
|
|
2277
|
-
geographic ? Math.floor(this.props.zoom || 0) : null,
|
|
2625
|
+
geographic && placement === 'point' ? Math.floor(this.props.zoom || 0) : null,
|
|
2626
|
+
// The rows a projected view keeps depend on its projection (see `getLabelData`).
|
|
2627
|
+
isProjectedViewport(this.context?.viewport) ? this.context.viewport.crs?.signature : null,
|
|
2278
2628
|
this.getTileBounds(geographic),
|
|
2279
2629
|
// The number of rows of a point label (see `getLabelData`).
|
|
2280
2630
|
isLinePlacement(placement)
|
|
@@ -2326,8 +2676,8 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2326
2676
|
return (
|
|
2327
2677
|
super.shouldUpdateState(params) ||
|
|
2328
2678
|
(params.changeFlags.viewportChanged &&
|
|
2329
|
-
this.
|
|
2330
|
-
|
|
2679
|
+
(isGeographicFirstPersonViewport(params.context.viewport) !== Boolean(this.state.firstPersonText) ||
|
|
2680
|
+
(this.turnsWithLines() && this.getBearingStep(params.context.viewport) !== this.state.bearingStep)))
|
|
2331
2681
|
);
|
|
2332
2682
|
}
|
|
2333
2683
|
|
|
@@ -2352,11 +2702,19 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2352
2702
|
);
|
|
2353
2703
|
}
|
|
2354
2704
|
|
|
2705
|
+
/** First-person viewport pitch can be combined with map-relative rotation. */
|
|
2706
|
+
usesMercatorLineBillboard(viewport: unknown = this.context?.viewport): boolean {
|
|
2707
|
+
return this.props.billboard !== false &&
|
|
2708
|
+
isGeographicFirstPersonViewport(viewport) &&
|
|
2709
|
+
this.getStyleProperty('text-pitch-alignment')?.evaluate(getZoomBucket(this.props.zoom || 0)) === 'viewport';
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2355
2712
|
/**
|
|
2356
2713
|
* Text layer props for labels along lines: each label is turned to its line, upright when
|
|
2357
2714
|
* `text-keep-upright` is set (the default). On a flat map they are drawn in the map plane, as
|
|
2358
2715
|
* MapLibre does with the `auto` `text-rotation-alignment` and `text-pitch-alignment` of line
|
|
2359
|
-
* placement
|
|
2716
|
+
* placement. On a globe or in first-person with viewport pitch alignment, they follow the line
|
|
2717
|
+
* in screen space.
|
|
2360
2718
|
*/
|
|
2361
2719
|
getLineLabelProps(): Record<string, unknown> {
|
|
2362
2720
|
const placement = this.getSymbolPlacement();
|
|
@@ -2372,10 +2730,16 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2372
2730
|
const keepUpright =
|
|
2373
2731
|
(this.getStyleProperty('text-keep-upright')?.evaluate(getZoomBucket(this.props.zoom || 0)) ??
|
|
2374
2732
|
getStylePropertyDefault('text-keep-upright')) !== false;
|
|
2375
|
-
const
|
|
2733
|
+
const viewport = this.context?.viewport;
|
|
2734
|
+
const geographic = isGlobeViewport(viewport);
|
|
2735
|
+
// A line's angle is measured in Web Mercator space. A projected view draws the map plane in
|
|
2736
|
+
// another projection, where the line has another direction.
|
|
2737
|
+
const getLineAngle = isProjectedViewport(viewport)
|
|
2738
|
+
? (row: LabelRow) => getProjectedPlaneAngle(viewport, row.position, row.angle ?? 0)
|
|
2739
|
+
: (row: LabelRow) => row.angle ?? 0;
|
|
2376
2740
|
return {
|
|
2377
|
-
billboard: geographic ? this.props.billboard :
|
|
2378
|
-
getAngle: (row: LabelRow) => getUprightAngle(row
|
|
2741
|
+
billboard: geographic ? this.props.billboard : this.usesMercatorLineBillboard(viewport),
|
|
2742
|
+
getAngle: (row: LabelRow) => getUprightAngle(getLineAngle(row), bearingStep, keepUpright)
|
|
2379
2743
|
};
|
|
2380
2744
|
}
|
|
2381
2745
|
|
|
@@ -2386,7 +2750,9 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2386
2750
|
* globe, labels are billboards turned on screen, and stay straight.
|
|
2387
2751
|
*/
|
|
2388
2752
|
curvesLineText(viewport: any = this.context?.viewport): boolean {
|
|
2389
|
-
|
|
2753
|
+
// In a projected view, glyph offsets along a line, measured in Web Mercator space, have
|
|
2754
|
+
// another direction and length: labels stay straight there.
|
|
2755
|
+
if (!viewport || isGeographicViewport(viewport) || this.usesMercatorLineBillboard(viewport) || this.context?.device?.type === 'webgpu') {
|
|
2390
2756
|
return false;
|
|
2391
2757
|
}
|
|
2392
2758
|
if (this.props.labelSizeUnits !== 'pixels' || !this.getStyleProperty('text-field')) {
|
|
@@ -2597,10 +2963,9 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2597
2963
|
}
|
|
2598
2964
|
|
|
2599
2965
|
/**
|
|
2600
|
-
* The extensions that
|
|
2601
|
-
*
|
|
2602
|
-
*
|
|
2603
|
-
* alone does not tell which way they read. A flat map draws them in the map plane. The shader
|
|
2966
|
+
* The extensions that turn billboards to their lines in screen space. Globe labels and
|
|
2967
|
+
* viewport-pitched road text use the direction the view draws the line at every frame.
|
|
2968
|
+
* The shader
|
|
2604
2969
|
* keeps an angle upright only when it is the line's direction: icons turned by `icon-rotate` are
|
|
2605
2970
|
* kept upright from north up, by their angles. Text keeps its `text-offset` on its side of the
|
|
2606
2971
|
* line as it turns around.
|
|
@@ -2611,12 +2976,16 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2611
2976
|
isLineDirection = true
|
|
2612
2977
|
): GlobeLineAngleExtension[] {
|
|
2613
2978
|
const isGlobeBillboard = isGlobeViewport(this.context?.viewport) && this.props.billboard;
|
|
2614
|
-
|
|
2979
|
+
const isMercatorBillboard = keepUpright === 'text-keep-upright' && this.usesMercatorLineBillboard();
|
|
2980
|
+
if (!turnsWithLine || !(isGlobeBillboard || isMercatorBillboard)) {
|
|
2615
2981
|
return [];
|
|
2616
2982
|
}
|
|
2617
2983
|
const upright =
|
|
2618
2984
|
(this.getStyleProperty(keepUpright)?.evaluate(getZoomBucket(this.props.zoom || 0)) ??
|
|
2619
2985
|
getStylePropertyDefault(keepUpright)) === true;
|
|
2986
|
+
if (isMercatorBillboard) {
|
|
2987
|
+
return [upright ? MERCATOR_TEXT_ANGLE_EXTENSIONS.upright : MERCATOR_TEXT_ANGLE_EXTENSIONS.free];
|
|
2988
|
+
}
|
|
2620
2989
|
if (!upright || !isLineDirection) {
|
|
2621
2990
|
return [GLOBE_LINE_ANGLE_EXTENSIONS.free];
|
|
2622
2991
|
}
|
|
@@ -2660,8 +3029,12 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2660
3029
|
const keepUpright =
|
|
2661
3030
|
(this.getStyleProperty('icon-keep-upright')?.evaluate(zoom) ??
|
|
2662
3031
|
getStylePropertyDefault('icon-keep-upright')) === true;
|
|
3032
|
+
const viewport = this.context?.viewport;
|
|
3033
|
+
const getRowAngle = isProjectedViewport(viewport)
|
|
3034
|
+
? (row: LabelRow) => getProjectedPlaneAngle(viewport, row.position, row.angle ?? 0)
|
|
3035
|
+
: (row: LabelRow) => row.angle ?? 0;
|
|
2663
3036
|
const getLineAngle = (row: LabelRow) =>
|
|
2664
|
-
turnsWithLine ? getUprightAngle(row
|
|
3037
|
+
turnsWithLine ? getUprightAngle(getRowAngle(row), bearingStep, keepUpright) : 0;
|
|
2665
3038
|
const getRotate = (row: LabelRow) =>
|
|
2666
3039
|
iconRotate
|
|
2667
3040
|
? Number(
|
|
@@ -2672,6 +3045,24 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2672
3045
|
return {props, getAngle: (row: LabelRow) => getLineAngle(row) - getRotate(row), extensions};
|
|
2673
3046
|
}
|
|
2674
3047
|
|
|
3048
|
+
/**
|
|
3049
|
+
* The angle `text-rotate` turns each row's text by, counter-clockwise in degrees as deck.gl
|
|
3050
|
+
* takes it, or null when the layer does not set it. Only point labels are turned: MapLibre turns
|
|
3051
|
+
* each glyph along a line about its own center, which labels along lines do not do here.
|
|
3052
|
+
*/
|
|
3053
|
+
getTextRotateAngle(): ((row: LabelRow) => number) | null {
|
|
3054
|
+
if (!this.getStyleProperty('text-rotate') || isLinePlacement(this.getSymbolPlacement())) {
|
|
3055
|
+
return null;
|
|
3056
|
+
}
|
|
3057
|
+
// `text-rotate` is clockwise; deck.gl angles are counter-clockwise.
|
|
3058
|
+
return (row: LabelRow) =>
|
|
3059
|
+
-(
|
|
3060
|
+
Number(
|
|
3061
|
+
this.evaluateStyleProperty('text-rotate', (row as any).__source?.object ?? row) ?? 0
|
|
3062
|
+
) || 0
|
|
3063
|
+
);
|
|
3064
|
+
}
|
|
3065
|
+
|
|
2675
3066
|
/**
|
|
2676
3067
|
* Forgets a font load in flight, so that its completion does not update a finalized layer, and
|
|
2677
3068
|
* releases the shared sprite textures.
|
|
@@ -2703,7 +3094,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2703
3094
|
if (!data && !tiles) {
|
|
2704
3095
|
return;
|
|
2705
3096
|
}
|
|
2706
|
-
const geographic =
|
|
3097
|
+
const geographic = isGeographicViewport(this.context?.viewport);
|
|
2707
3098
|
const textTrigger = this.getLabelUpdateTriggers().getText;
|
|
2708
3099
|
if (textTrigger !== this.state.labelText?.key[0]) {
|
|
2709
3100
|
// Labels along lines are placed by their text's length, so they must not read text cached
|
|
@@ -2919,7 +3310,10 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
2919
3310
|
}
|
|
2920
3311
|
this.retainGlyphs(waiting, refusedAny);
|
|
2921
3312
|
if (changed) {
|
|
2922
|
-
|
|
3313
|
+
let combined = combineTileRows(tiles, tileRows);
|
|
3314
|
+
if (geographic && isProjectedViewport(this.context?.viewport)) {
|
|
3315
|
+
combined = filterRowsOnDrawnTiles(tiles, combined);
|
|
3316
|
+
}
|
|
2923
3317
|
// A tile shown or hidden without rows of this layer leaves the rows as they are: the same
|
|
2924
3318
|
// array keeps the sublayers' data, which deck.gl would otherwise update for every row.
|
|
2925
3319
|
const previousRows = this.state.labelData;
|
|
@@ -3169,11 +3563,14 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3169
3563
|
const measure = this.getCharacterMeasurer();
|
|
3170
3564
|
const lineHeight = this.getLineHeight();
|
|
3171
3565
|
const linePlacement = isLinePlacement(this.getSymbolPlacement());
|
|
3566
|
+
const textFit = hasIconData && hasTextData ? this.getIconTextFit() : 'none';
|
|
3172
3567
|
const textBoxes = new Float64Array(count * 4).fill(Number.NaN);
|
|
3173
3568
|
const textOffsets = new Float64Array(count * 2);
|
|
3174
3569
|
const iconBoxes = new Float64Array(count * 4).fill(Number.NaN);
|
|
3175
3570
|
const sortKey = this.getStyleProperty('symbol-sort-key');
|
|
3176
3571
|
const keys = sortKey ? new Float64Array(count) : null;
|
|
3572
|
+
const textPadding = this.getTextPadding();
|
|
3573
|
+
const getTextRotate = this.getTextRotateAngle();
|
|
3177
3574
|
for (let i = 0; i < count; i++) {
|
|
3178
3575
|
const row = labelData[i];
|
|
3179
3576
|
const rowIndex = count - 1 - i;
|
|
@@ -3189,22 +3586,8 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3189
3586
|
continue;
|
|
3190
3587
|
}
|
|
3191
3588
|
if (rowsWithText?.[rowIndex]) {
|
|
3192
|
-
const label = this.getLabel(feature) || '';
|
|
3193
3589
|
const size = this.getLabelSize(feature);
|
|
3194
|
-
const
|
|
3195
|
-
const lines = label.split('\n');
|
|
3196
|
-
let textWidth = 0;
|
|
3197
|
-
for (const line of lines) {
|
|
3198
|
-
const characters = Array.from(line);
|
|
3199
|
-
let lineWidth = 0;
|
|
3200
|
-
for (const character of characters) {
|
|
3201
|
-
lineWidth += measure(character);
|
|
3202
|
-
}
|
|
3203
|
-
lineWidth += Math.max(0, characters.length - 1) * spacing;
|
|
3204
|
-
textWidth = Math.max(textWidth, lineWidth);
|
|
3205
|
-
}
|
|
3206
|
-
const w = textWidth * size;
|
|
3207
|
-
const h = lines.length * lineHeight * size;
|
|
3590
|
+
const [w, h] = this.measureLabel(feature, measure, lineHeight);
|
|
3208
3591
|
const [ax, ay] = ANCHOR_FRACTIONS[this.getRowAnchor(row)] || ANCHOR_FRACTIONS.center;
|
|
3209
3592
|
const [dx, dy] = this.getRowPixelOffset(row);
|
|
3210
3593
|
// A point label's box, offset included, is laid out at its collision size; text along a
|
|
@@ -3212,32 +3595,50 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3212
3595
|
const scale = linePlacement || !(size > 0) ? 1 : this.getCollisionLabelSize(feature) / size;
|
|
3213
3596
|
// Variable anchors include a shift by the padded box. Padding stays in pixels when the
|
|
3214
3597
|
// text and its em offsets are scaled to the collision size.
|
|
3215
|
-
const padding = this.getRowTextAnchor(row) ? 2 *
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3598
|
+
const padding = this.getRowTextAnchor(row) ? 2 * textPadding : 0;
|
|
3599
|
+
const box = [
|
|
3600
|
+
(-(ax + 0.5) * w + dx + ax * padding) * scale - ax * padding,
|
|
3601
|
+
(-(ay + 0.5) * h + dy + ay * padding) * scale - ay * padding,
|
|
3602
|
+
w * scale,
|
|
3603
|
+
h * scale
|
|
3604
|
+
];
|
|
3605
|
+
const angle = getTextRotate ? getTextRotate(row) : 0;
|
|
3606
|
+
if (angle) {
|
|
3607
|
+
// As in MapLibre, turned text collides with the box around its turned, padded box.
|
|
3608
|
+
// `getTextBox` pads the box again.
|
|
3609
|
+
const p = textPadding;
|
|
3610
|
+
const [x1, y1, x2, y2] = getTurnedBounds(
|
|
3611
|
+
[box[0] - p, box[1] - p, box[0] + box[2] + p, box[1] + box[3] + p],
|
|
3612
|
+
angle
|
|
3613
|
+
);
|
|
3614
|
+
box.splice(0, 4, x1 + p, y1 + p, x2 - x1 - 2 * p, y2 - y1 - 2 * p);
|
|
3615
|
+
}
|
|
3616
|
+
textBoxes.set(box, i * 4);
|
|
3225
3617
|
textOffsets.set([dx, dy], i * 2);
|
|
3226
3618
|
}
|
|
3227
3619
|
const resolved = icons?.[rowIndex];
|
|
3228
3620
|
if (resolved) {
|
|
3229
3621
|
const scale = Number(this.evaluateStyleProperty('icon-size', feature) ?? 1);
|
|
3230
|
-
const
|
|
3231
|
-
const h = (resolved.entry.height / resolved.entry.pixelRatio) * scale;
|
|
3232
|
-
const [ox, oy] = this.getIconPixelOffset(feature);
|
|
3233
|
-
const [top, right, bottom, left] = (
|
|
3622
|
+
const padding = (
|
|
3234
3623
|
(this.evaluateStyleProperty('icon-padding', feature) as number[] | undefined) ??
|
|
3235
3624
|
(getStylePropertyDefault('icon-padding') as number[])
|
|
3236
3625
|
).map(value => Math.max(0, Number(value)) || 0);
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3626
|
+
const fitted =
|
|
3627
|
+
textFit !== 'none' && rowsWithText?.[rowIndex]
|
|
3628
|
+
? this.getFittedIcon(row, resolved, textFit, measure, lineHeight)
|
|
3629
|
+
: null;
|
|
3630
|
+
if (fitted) {
|
|
3631
|
+
iconBoxes.set(getFittedIconCollisionBox(resolved.entry, fitted, scale, padding), i * 4);
|
|
3632
|
+
} else {
|
|
3633
|
+
const w = (resolved.entry.width / resolved.entry.pixelRatio) * scale;
|
|
3634
|
+
const h = (resolved.entry.height / resolved.entry.pixelRatio) * scale;
|
|
3635
|
+
const [ox, oy] = this.getIconPixelOffset(feature);
|
|
3636
|
+
const [top, right, bottom, left] = padding;
|
|
3637
|
+
iconBoxes.set(
|
|
3638
|
+
[ox - w / 2 - left, oy - h / 2 - top, ox + w / 2 + right, oy + h / 2 + bottom],
|
|
3639
|
+
i * 4
|
|
3640
|
+
);
|
|
3641
|
+
}
|
|
3241
3642
|
}
|
|
3242
3643
|
const boxes = new Float64Array(10);
|
|
3243
3644
|
boxes.set(textBoxes.subarray(i * 4, i * 4 + 4), 0);
|
|
@@ -3264,7 +3665,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3264
3665
|
textBoxes,
|
|
3265
3666
|
textOffsets,
|
|
3266
3667
|
iconBoxes,
|
|
3267
|
-
textPadding
|
|
3668
|
+
textPadding
|
|
3268
3669
|
};
|
|
3269
3670
|
this.state.placementGeometry = geometry;
|
|
3270
3671
|
return geometry;
|
|
@@ -3293,21 +3694,25 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3293
3694
|
const padding = PLACEMENT_VIEWPORT_PADDING;
|
|
3294
3695
|
const {width, height} = viewport;
|
|
3295
3696
|
const isGlobe = isGlobeViewport(viewport);
|
|
3697
|
+
const firstPerson = isGeographicFirstPersonViewport(viewport);
|
|
3296
3698
|
// Text along lines and icons aligned to the map are drawn in the map plane on a flat map: their
|
|
3297
3699
|
// pixel offsets turn with the bearing and are foreshortened by the pitch.
|
|
3298
3700
|
const textInMapPlane = !isGlobe && Boolean(lineProps.getAngle) && lineProps.billboard === false;
|
|
3299
3701
|
const iconInMapPlane = !isGlobe && iconAngleProps?.props.billboard === false;
|
|
3702
|
+
const scaleBillboards = firstPerson && this.props.labelSizeUnits === 'pixels';
|
|
3703
|
+
const scaleText = scaleBillboards && (lineProps.billboard ?? this.props.billboard);
|
|
3704
|
+
const scaleIcon = scaleBillboards && iconAngleProps &&
|
|
3705
|
+
(iconAngleProps.props.billboard ?? this.props.billboard);
|
|
3706
|
+
const referenceDepth =
|
|
3707
|
+
(scaleText || scaleIcon) && firstPerson ? getFirstPersonLabelReferenceDepth(viewport) : 0;
|
|
3300
3708
|
const toScreen = [1, 0, 0, 1];
|
|
3301
3709
|
// Glyphs placed along lines, as drawn (see `getLineGlyphProps`).
|
|
3302
3710
|
const curves = textInMapPlane && this.curvesLineText(viewport);
|
|
3303
3711
|
const bearingStep = curves ? this.getBearingStep(viewport) : 0;
|
|
3304
3712
|
const styleKey = curves ? this.getLineGlyphStyleKey() : '';
|
|
3305
3713
|
const spritesLoading = rules.hasIconData && this.props.spriteAtlases === null;
|
|
3306
|
-
//
|
|
3307
|
-
|
|
3308
|
-
const textGlobeTurn = isGlobe
|
|
3309
|
-
? this.getLineAngleExtensions(Boolean(lineProps.getAngle), 'text-keep-upright')[0]
|
|
3310
|
-
: undefined;
|
|
3714
|
+
// Line billboards collide along the direction the shader draws them on screen.
|
|
3715
|
+
const textBillboardTurn = this.getLineAngleExtensions(Boolean(lineProps.getAngle), 'text-keep-upright')[0];
|
|
3311
3716
|
const iconGlobeTurn = isGlobe ? iconAngleProps?.extensions[0] : undefined;
|
|
3312
3717
|
|
|
3313
3718
|
// `tiles` rows are in longitude/latitude: their common-space positions, which do not change
|
|
@@ -3316,15 +3721,15 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3316
3721
|
const m = viewport.pixelProjectionMatrix as number[];
|
|
3317
3722
|
const horizon = isGlobe ? this.getHorizonTest(viewport) : null;
|
|
3318
3723
|
// The padded text box of row `j` at the grid point `x, y`.
|
|
3319
|
-
const getTextBox = (j: number, x: number, y: number): PlacementShape => {
|
|
3724
|
+
const getTextBox = (j: number, x: number, y: number, scale: number): PlacementShape => {
|
|
3320
3725
|
const x1 = textBoxes[j * 4];
|
|
3321
3726
|
const y1 = textBoxes[j * 4 + 1];
|
|
3322
3727
|
return {
|
|
3323
3728
|
box: [
|
|
3324
|
-
x + x1 - textPadding,
|
|
3325
|
-
y + y1 - textPadding,
|
|
3326
|
-
x + x1 + textBoxes[j * 4 + 2] + textPadding,
|
|
3327
|
-
y + y1 + textBoxes[j * 4 + 3] + textPadding
|
|
3729
|
+
x + x1 * scale - textPadding,
|
|
3730
|
+
y + y1 * scale - textPadding,
|
|
3731
|
+
x + (x1 + textBoxes[j * 4 + 2]) * scale + textPadding,
|
|
3732
|
+
y + (y1 + textBoxes[j * 4 + 3]) * scale + textPadding
|
|
3328
3733
|
]
|
|
3329
3734
|
};
|
|
3330
3735
|
};
|
|
@@ -3334,15 +3739,17 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3334
3739
|
let sy: number;
|
|
3335
3740
|
let occluded = false;
|
|
3336
3741
|
let common: number[] | null = null;
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3742
|
+
let anchorDepth = 0;
|
|
3743
|
+
if (commons || firstPerson) {
|
|
3744
|
+
common = commons
|
|
3745
|
+
? [commons[i * 3], commons[i * 3 + 1], commons[i * 3 + 2]]
|
|
3746
|
+
: this.projectPosition(row.position, {viewport, autoOffset: false});
|
|
3747
|
+
const [cx, cy, cz] = common;
|
|
3341
3748
|
const w = m[3] * cx + m[7] * cy + m[11] * cz + m[15];
|
|
3749
|
+
anchorDepth = w;
|
|
3342
3750
|
sx = (m[0] * cx + m[4] * cy + m[8] * cz + m[12]) / w;
|
|
3343
3751
|
sy = (m[1] * cx + m[5] * cy + m[9] * cz + m[13]) / w;
|
|
3344
|
-
occluded =
|
|
3345
|
-
common = [cx, cy, cz];
|
|
3752
|
+
occluded = (firstPerson && w <= 0) || Boolean(horizon?.(cx, cy, cz));
|
|
3346
3753
|
} else {
|
|
3347
3754
|
[sx, sy] = this.project(row.position as any) as number[];
|
|
3348
3755
|
occluded = isGlobe && this.isBeyondHorizon(viewport, row.position);
|
|
@@ -3363,12 +3770,14 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3363
3770
|
}
|
|
3364
3771
|
const t = i * 4;
|
|
3365
3772
|
const inMapPlane =
|
|
3366
|
-
(textInMapPlane && !Number.isNaN(textBoxes[t + 2])) ||
|
|
3773
|
+
((textInMapPlane || textBillboardTurn?.opts.mercator) && !Number.isNaN(textBoxes[t + 2])) ||
|
|
3367
3774
|
(iconInMapPlane && !Number.isNaN(iconBoxes[t]));
|
|
3368
3775
|
if (inMapPlane) {
|
|
3369
3776
|
common ||= viewport.projectPosition(viewport.unproject([sx, sy])) as number[];
|
|
3370
3777
|
getMapPlaneToScreen(viewport, common, sx, sy, toScreen);
|
|
3371
3778
|
}
|
|
3779
|
+
const perspective = getFirstPersonLabelPerspective(referenceDepth, anchorDepth);
|
|
3780
|
+
const textScale = scaleText ? perspective : 1;
|
|
3372
3781
|
let text: PlacementShape | null = null;
|
|
3373
3782
|
let textAnchors: PlacementSymbol['textAnchors'];
|
|
3374
3783
|
const w = textBoxes[t + 2];
|
|
@@ -3408,47 +3817,40 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3408
3817
|
// Circles along the turned label, as MapLibre's collision circles along a line, taken
|
|
3409
3818
|
// to the screen when the text is drawn in the map plane.
|
|
3410
3819
|
let angle = (lineProps.getAngle(row) * Math.PI) / 180;
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
row.position as number[],
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
);
|
|
3820
|
+
const toBillboardAngle = (radians: number, upright: boolean) =>
|
|
3821
|
+
textBillboardTurn?.opts.mercator
|
|
3822
|
+
? getMercatorDrawnAngle(toScreen, radians, upright)
|
|
3823
|
+
: getGlobeDrawnAngle(viewport, row.position as number[], radians, upright);
|
|
3824
|
+
if (textBillboardTurn) {
|
|
3825
|
+
angle = toBillboardAngle(angle, textBillboardTurn.opts.keepUpright);
|
|
3418
3826
|
}
|
|
3419
3827
|
const ux = Math.cos(angle);
|
|
3420
3828
|
const uy = -Math.sin(angle);
|
|
3421
|
-
const radius = h / 2 + textPadding;
|
|
3829
|
+
const radius = (h / 2) * textScale + textPadding;
|
|
3830
|
+
const textWidth = w * textScale;
|
|
3422
3831
|
// The text turns with its upright angle, and its offset with the line (see
|
|
3423
3832
|
// `withLineDirection`), as drawn.
|
|
3424
3833
|
const dx = textOffsets[i * 2];
|
|
3425
3834
|
const dy = textOffsets[i * 2 + 1];
|
|
3426
|
-
//
|
|
3835
|
+
// The offset follows the line's direction, even if the text is turned upright.
|
|
3427
3836
|
const [ex, ey] = rotatePixelOffset(
|
|
3428
|
-
[dx, dy],
|
|
3429
|
-
|
|
3430
|
-
? (
|
|
3431
|
-
viewport,
|
|
3432
|
-
row.position as number[],
|
|
3433
|
-
((row.angle ?? 0) * Math.PI) / 180,
|
|
3434
|
-
false
|
|
3435
|
-
) *
|
|
3436
|
-
180) /
|
|
3437
|
-
Math.PI
|
|
3837
|
+
[dx * textScale, dy * textScale],
|
|
3838
|
+
textBillboardTurn
|
|
3839
|
+
? (toBillboardAngle(((row.angle ?? 0) * Math.PI) / 180, false) * 180) / Math.PI
|
|
3438
3840
|
: (row.angle ?? 0)
|
|
3439
3841
|
);
|
|
3440
|
-
const cx = x1 + w / 2 - dx;
|
|
3441
|
-
const cy = y1 + h / 2 - dy;
|
|
3842
|
+
const cx = (x1 + w / 2 - dx) * textScale;
|
|
3843
|
+
const cy = (y1 + h / 2 - dy) * textScale;
|
|
3442
3844
|
// A label without height has a single circle.
|
|
3443
3845
|
const n =
|
|
3444
3846
|
radius > 0
|
|
3445
|
-
? Math.max(1, Math.ceil(Math.max(0,
|
|
3847
|
+
? Math.max(1, Math.ceil(Math.max(0, textWidth - 2 * radius) / (radius * 2.5)) + 1)
|
|
3446
3848
|
: 1;
|
|
3447
3849
|
const [ax, ay, bx, by] = textInMapPlane ? toScreen : [1, 0, 0, 1];
|
|
3448
3850
|
const screenRadius = radius * Math.sqrt(Math.abs(ax * by - ay * bx));
|
|
3449
3851
|
const circles: number[] = [];
|
|
3450
3852
|
for (let k = 0; k < n; k++) {
|
|
3451
|
-
const along = n === 1 ? 0 : -
|
|
3853
|
+
const along = n === 1 ? 0 : -textWidth / 2 + radius + ((textWidth - 2 * radius) * k) / (n - 1);
|
|
3452
3854
|
const ox = cx + along;
|
|
3453
3855
|
const mx = ox * ux - cy * uy + ex;
|
|
3454
3856
|
const my = ox * uy + cy * ux + ey;
|
|
@@ -3456,7 +3858,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3456
3858
|
}
|
|
3457
3859
|
text = {circles};
|
|
3458
3860
|
} else {
|
|
3459
|
-
text = getTextBox(i, x, y);
|
|
3861
|
+
text = getTextBox(i, x, y, textScale);
|
|
3460
3862
|
const textAnchorCount = row.textAnchorCount ?? 0;
|
|
3461
3863
|
if (textAnchorCount > 1) {
|
|
3462
3864
|
// The label's text at each of its anchors, from the rows that follow (see
|
|
@@ -3468,7 +3870,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3468
3870
|
if (labelData[j]?.textAnchorIndex !== k || Number.isNaN(textBoxes[j * 4 + 2])) {
|
|
3469
3871
|
break;
|
|
3470
3872
|
}
|
|
3471
|
-
shapes.push(getTextBox(j, x, y));
|
|
3873
|
+
shapes.push(getTextBox(j, x, y, textScale));
|
|
3472
3874
|
slots.push(slotBase + count - 1 - j);
|
|
3473
3875
|
}
|
|
3474
3876
|
// A tile's rows are kept while it is drawn, so the first row names the label across
|
|
@@ -3479,6 +3881,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3479
3881
|
}
|
|
3480
3882
|
let icon: PlacementShape | null = null;
|
|
3481
3883
|
if (!Number.isNaN(iconBoxes[t])) {
|
|
3884
|
+
const iconScale = scaleIcon ? perspective : 1;
|
|
3482
3885
|
let iconAngle = getIconAngle ? getIconAngle(row) : 0;
|
|
3483
3886
|
if (iconGlobeTurn) {
|
|
3484
3887
|
iconAngle =
|
|
@@ -3492,7 +3895,12 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3492
3895
|
Math.PI;
|
|
3493
3896
|
}
|
|
3494
3897
|
const [bx1, by1, bx2, by2] = getTurnedBounds(
|
|
3495
|
-
[
|
|
3898
|
+
[
|
|
3899
|
+
iconBoxes[t] * iconScale,
|
|
3900
|
+
iconBoxes[t + 1] * iconScale,
|
|
3901
|
+
iconBoxes[t + 2] * iconScale,
|
|
3902
|
+
iconBoxes[t + 3] * iconScale
|
|
3903
|
+
],
|
|
3496
3904
|
iconAngle,
|
|
3497
3905
|
iconInMapPlane ? toScreen : null
|
|
3498
3906
|
);
|
|
@@ -3520,7 +3928,11 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3520
3928
|
* viewport: a globe's or a map's, which do not change with the view. Kept per row.
|
|
3521
3929
|
*/
|
|
3522
3930
|
getPlacementCommons(viewport: any, geometry: PlacementGeometry): Float64Array {
|
|
3523
|
-
const kind = isGlobeViewport(viewport)
|
|
3931
|
+
const kind = isGlobeViewport(viewport)
|
|
3932
|
+
? 'globe'
|
|
3933
|
+
: isProjectedViewport(viewport)
|
|
3934
|
+
? `projected:${viewport.crs?.signature}`
|
|
3935
|
+
: 'map';
|
|
3524
3936
|
if (geometry.commons?.kind === kind) {
|
|
3525
3937
|
return geometry.commons.positions;
|
|
3526
3938
|
}
|
|
@@ -3582,6 +3994,8 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3582
3994
|
renderLayers(): any {
|
|
3583
3995
|
const {config, labelSizeUnits, billboard, renderGeometry} = this.props;
|
|
3584
3996
|
const layers: any[] = [];
|
|
3997
|
+
const firstPerson = isGeographicFirstPersonViewport(this.context?.viewport);
|
|
3998
|
+
this.state.firstPersonText = firstPerson;
|
|
3585
3999
|
|
|
3586
4000
|
if (renderGeometry) {
|
|
3587
4001
|
layers.push(
|
|
@@ -3624,6 +4038,7 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3624
4038
|
// group's rows decide which rows have text, so they are part of it.
|
|
3625
4039
|
const getTextTrigger = [updateTriggers.getText, ...(groupTrigger || [])];
|
|
3626
4040
|
const lineLabelProps = this.getLineLabelProps();
|
|
4041
|
+
const getTextRotate = this.getTextRotateAngle();
|
|
3627
4042
|
const lineGlyphs = this.getLineGlyphProps();
|
|
3628
4043
|
updateTriggers.getLineGlyphs = lineGlyphs.trigger;
|
|
3629
4044
|
const textProps = {
|
|
@@ -3633,12 +4048,16 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3633
4048
|
LABEL_PLACEMENT_EXTENSION,
|
|
3634
4049
|
GLOBE_HORIZON_EXTENSION,
|
|
3635
4050
|
TEXT_HALO_BLUR_EXTENSION,
|
|
3636
|
-
...this.getLineAngleExtensions('getAngle' in lineLabelProps, 'text-keep-upright')
|
|
4051
|
+
...this.getLineAngleExtensions('getAngle' in lineLabelProps, 'text-keep-upright'),
|
|
4052
|
+
...(firstPerson && labelSizeUnits === 'pixels' && (lineLabelProps.billboard ?? billboard)
|
|
4053
|
+
? [FIRST_PERSON_LABEL_SIZE_EXTENSION]
|
|
4054
|
+
: [])
|
|
3637
4055
|
],
|
|
3638
4056
|
...this.getPlacementProps(0),
|
|
3639
4057
|
parameters: LABEL_PARAMETERS,
|
|
3640
4058
|
billboard,
|
|
3641
4059
|
...lineLabelProps,
|
|
4060
|
+
...(getTextRotate ? {getAngle: getTextRotate} : {}),
|
|
3642
4061
|
characterSet: 'auto',
|
|
3643
4062
|
// Glyphs are signed distance fields, which `TextLayer` outlines for halos.
|
|
3644
4063
|
...this.getFontProps(font),
|
|
@@ -3653,9 +4072,14 @@ export class MVTLabelLayer extends CompositeLayer<MVTLabelLayerProps> {
|
|
|
3653
4072
|
(feature: FeatureLike) => this.getLabelColor(feature),
|
|
3654
4073
|
[0, 0, 0, 0]
|
|
3655
4074
|
),
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
4075
|
+
// `text-rotate` turns the text with its anchor and offset about the point, as an icon
|
|
4076
|
+
// turns (see `withIconAngle`).
|
|
4077
|
+
getPixelOffset: withIconAngle(
|
|
4078
|
+
withLineDirection(
|
|
4079
|
+
forRows(rows, (row: LabelRow) => this.getRowPixelOffset(row), [0, 0]) as any,
|
|
4080
|
+
Boolean(lineLabelProps.getAngle)
|
|
4081
|
+
),
|
|
4082
|
+
getTextRotate
|
|
3659
4083
|
),
|
|
3660
4084
|
getLineGlyphs: lineGlyphs.getLineGlyphs,
|
|
3661
4085
|
getLineGlyphKey: lineGlyphs.getLineGlyphKey,
|