@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
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
// MapLibre GL JS
|
|
6
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
7
|
+
// Copyright (c) 2023, MapLibre contributors
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @license
|
|
11
|
+
* Portions of this file are adapted from MapLibre GL JS v6.13.0, src/source/image_source.ts and
|
|
12
|
+
* src/shaders/glsl/raster.vertex.glsl, under this license (see also THIRD-PARTY-NOTICES.md):
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2023, MapLibre contributors
|
|
15
|
+
*
|
|
16
|
+
* All rights reserved.
|
|
17
|
+
*
|
|
18
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
|
19
|
+
* are permitted provided that the following conditions are met:
|
|
20
|
+
*
|
|
21
|
+
* * Redistributions of source code must retain the above copyright notice,
|
|
22
|
+
* this list of conditions and the following disclaimer.
|
|
23
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
24
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
25
|
+
* and/or other materials provided with the distribution.
|
|
26
|
+
* * Neither the name of MapLibre GL JS nor the names of its contributors
|
|
27
|
+
* may be used to endorse or promote products derived from this software
|
|
28
|
+
* without specific prior written permission.
|
|
29
|
+
*
|
|
30
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
31
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
32
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
33
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
34
|
+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
35
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
36
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
37
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
38
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
39
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
40
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import {CompositeLayer} from '@deck.gl/core';
|
|
44
|
+
import type {CompositeLayerProps, DefaultProps} from '@deck.gl/core';
|
|
45
|
+
import type {BitmapBoundingBox} from '@deck.gl/layers';
|
|
46
|
+
import {BitmapLayer} from '@deck.gl/layers';
|
|
47
|
+
import {
|
|
48
|
+
MAX_MERCATOR_LATITUDE,
|
|
49
|
+
lngLatToMercatorWorld,
|
|
50
|
+
mercatorWorldToLngLat
|
|
51
|
+
} from './projected-viewport';
|
|
52
|
+
import type {BasemapLoadOptions, BasemapSource} from './style-resolver';
|
|
53
|
+
|
|
54
|
+
/** A longitude and a latitude, in degrees. */
|
|
55
|
+
export type ImageSourceCorner = [number, number];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The corners of an `image` source, as the style specification lists them: top left, top right,
|
|
59
|
+
* bottom right and bottom left.
|
|
60
|
+
*/
|
|
61
|
+
export type ImageSourceCorners = [
|
|
62
|
+
ImageSourceCorner,
|
|
63
|
+
ImageSourceCorner,
|
|
64
|
+
ImageSourceCorner,
|
|
65
|
+
ImageSourceCorner
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The largest longitude of a corner, in degrees: an image may reach into the world copies on
|
|
70
|
+
* either side, as in MapLibre, but no further.
|
|
71
|
+
*/
|
|
72
|
+
const MAX_CORNER_LONGITUDE = 540;
|
|
73
|
+
|
|
74
|
+
function isCorner(value: unknown): value is ImageSourceCorner {
|
|
75
|
+
return (
|
|
76
|
+
Array.isArray(value) &&
|
|
77
|
+
value.length === 2 &&
|
|
78
|
+
value.every(Number.isFinite) &&
|
|
79
|
+
Math.abs(value[0]) <= MAX_CORNER_LONGITUDE &&
|
|
80
|
+
Math.abs(value[1]) <= MAX_MERCATOR_LATITUDE
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The `coordinates` of an `image` source, or null unless they are four `[longitude, latitude]`
|
|
86
|
+
* corners of finite numbers, with latitudes within the Web Mercator world (±85.051129°) and
|
|
87
|
+
* longitudes within ±540°.
|
|
88
|
+
*/
|
|
89
|
+
export function getImageSourceCorners(source: BasemapSource): ImageSourceCorners | null {
|
|
90
|
+
const {coordinates} = source;
|
|
91
|
+
return Array.isArray(coordinates) && coordinates.length === 4 && coordinates.every(isCorner)
|
|
92
|
+
? (coordinates.map(([longitude, latitude]) => [longitude, latitude]) as ImageSourceCorners)
|
|
93
|
+
: null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Whether a source is an `image` source that can draw: one with a `url` and valid corners. */
|
|
97
|
+
export function isDrawableImageSource(source: BasemapSource | undefined): boolean {
|
|
98
|
+
return (
|
|
99
|
+
source?.type === 'image' &&
|
|
100
|
+
typeof source.url === 'string' &&
|
|
101
|
+
source.url.length > 0 &&
|
|
102
|
+
getImageSourceCorners(source) !== null
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The `bounds` of a `BitmapLayer` over the corners of an image: bottom left, top left, top right
|
|
108
|
+
* and bottom right. `ImageQuadLayer` draws its own mesh, but a change of bounds rebuilds it.
|
|
109
|
+
*/
|
|
110
|
+
export function getImageSourceBounds([
|
|
111
|
+
topLeft,
|
|
112
|
+
topRight,
|
|
113
|
+
bottomRight,
|
|
114
|
+
bottomLeft
|
|
115
|
+
]: ImageSourceCorners): BitmapBoundingBox {
|
|
116
|
+
return [bottomLeft, topLeft, topRight, bottomRight];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* How much a warp may foreshorten the image, as the ratio between the largest and the smallest
|
|
121
|
+
* homogeneous denominator over the quad, while staying purely projective (MapLibre's value).
|
|
122
|
+
*/
|
|
123
|
+
const PROJECTIVE_FORESHORTENING = 4;
|
|
124
|
+
|
|
125
|
+
/** The foreshortening at which a warp is taken to be purely bilinear (MapLibre's value). */
|
|
126
|
+
const BILINEAR_FORESHORTENING = 512;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The grid cells along each side of the mesh of a quad that is not a parallelogram. Within a cell
|
|
130
|
+
* the image is mapped linearly, so the drawn image departs from the warp by a small fraction of a
|
|
131
|
+
* cell: MapLibre GL JS draws a projective warp exactly, and a blended one on 16 cells.
|
|
132
|
+
*/
|
|
133
|
+
const WARP_GRID_CELLS = 32;
|
|
134
|
+
|
|
135
|
+
/** The most grid cells along each side of the mesh of an image, however large it is. */
|
|
136
|
+
export const MAX_IMAGE_GRID_CELLS = 256;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* How an image is warped onto its corners, as MapLibre GL JS warps it (`ImageSource` with its
|
|
140
|
+
* default `auto` warp): `[perspectiveX, perspectiveY, blend]`. The first two are the perspective
|
|
141
|
+
* terms of the projective mapping of the unit square onto the corners, and `blend` mixes that
|
|
142
|
+
* mapping towards the bilinear one: 0 is purely projective, 1 purely bilinear. A parallelogram,
|
|
143
|
+
* and a quad with no perspective view (concave, self-crossing or collinear), is warped bilinearly.
|
|
144
|
+
*/
|
|
145
|
+
export type ImageWarp = [number, number, number];
|
|
146
|
+
|
|
147
|
+
const BILINEAR_WARP: ImageWarp = [0, 0, 1];
|
|
148
|
+
|
|
149
|
+
/** The corners in Web Mercator world units, y up. */
|
|
150
|
+
function getWorldCorners(corners: ImageSourceCorners): [number, number][] {
|
|
151
|
+
return corners.map(corner => lngLatToMercatorWorld(corner));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Whether the corners form a parallelogram, which every warp maps affinely. Compared relative to
|
|
156
|
+
* the size of the quad: MapLibre compares corners rounded to its tile grid.
|
|
157
|
+
*/
|
|
158
|
+
function isParallelogram([topLeft, topRight, bottomRight, bottomLeft]: [number, number][]): boolean {
|
|
159
|
+
const size = Math.hypot(bottomRight[0] - topLeft[0], bottomRight[1] - topLeft[1]);
|
|
160
|
+
const epsilon = size * 1e-9;
|
|
161
|
+
return (
|
|
162
|
+
Math.abs(topLeft[0] + bottomRight[0] - topRight[0] - bottomLeft[0]) <= epsilon &&
|
|
163
|
+
Math.abs(topLeft[1] + bottomRight[1] - topRight[1] - bottomLeft[1]) <= epsilon
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* How far a warp of the given foreshortening is blended towards the bilinear one: purely
|
|
169
|
+
* projective up to `PROJECTIVE_FORESHORTENING`, purely bilinear at `BILINEAR_FORESHORTENING`.
|
|
170
|
+
*/
|
|
171
|
+
function getBilinearBlend(foreshortening: number): number {
|
|
172
|
+
const ramp =
|
|
173
|
+
(1 - PROJECTIVE_FORESHORTENING / foreshortening) /
|
|
174
|
+
(1 - PROJECTIVE_FORESHORTENING / BILINEAR_FORESHORTENING);
|
|
175
|
+
return Math.max(0, ramp);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The warp of an image onto its corners, with MapLibre GL JS's `calculateImageWarp`, in Web
|
|
180
|
+
* Mercator space. A warp is the same in any frame that differs by an affine map, so y up gives
|
|
181
|
+
* the warp of MapLibre's y-down tile space.
|
|
182
|
+
*/
|
|
183
|
+
export function getImageWarp(corners: ImageSourceCorners): ImageWarp {
|
|
184
|
+
const world = getWorldCorners(corners);
|
|
185
|
+
if (isParallelogram(world)) {
|
|
186
|
+
return BILINEAR_WARP;
|
|
187
|
+
}
|
|
188
|
+
const [topLeft, topRight, bottomRight, bottomLeft] = world;
|
|
189
|
+
const sumX = topLeft[0] - topRight[0] + bottomRight[0] - bottomLeft[0];
|
|
190
|
+
const sumY = topLeft[1] - topRight[1] + bottomRight[1] - bottomLeft[1];
|
|
191
|
+
const rightX = topRight[0] - bottomRight[0];
|
|
192
|
+
const rightY = topRight[1] - bottomRight[1];
|
|
193
|
+
const downX = bottomLeft[0] - bottomRight[0];
|
|
194
|
+
const downY = bottomLeft[1] - bottomRight[1];
|
|
195
|
+
const determinant = rightX * downY - downX * rightY;
|
|
196
|
+
const perspectiveX = (sumX * downY - downX * sumY) / determinant;
|
|
197
|
+
const perspectiveY = (rightX * sumY - sumX * rightY) / determinant;
|
|
198
|
+
|
|
199
|
+
// The homogeneous denominator at the corners of the unit square, one at the top left. It stays
|
|
200
|
+
// finite and positive over the quad exactly while the quad is a perspective view of the image.
|
|
201
|
+
const denominators = [1, 1 + perspectiveX, 1 + perspectiveX + perspectiveY, 1 + perspectiveY];
|
|
202
|
+
const foreshortening = Math.max(...denominators) / Math.min(...denominators);
|
|
203
|
+
const blend = getBilinearBlend(foreshortening);
|
|
204
|
+
if (!(foreshortening >= 1 && foreshortening <= BILINEAR_FORESHORTENING) || blend >= 1) {
|
|
205
|
+
return BILINEAR_WARP;
|
|
206
|
+
}
|
|
207
|
+
return [perspectiveX, perspectiveY, blend];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The place of a point of the image, `u` right and `v` down from its top left corner in 0 to 1, in
|
|
212
|
+
* the same units as the corners: MapLibre's raster vertex shader.
|
|
213
|
+
*/
|
|
214
|
+
export function warpImagePoint(
|
|
215
|
+
[topLeft, topRight, bottomRight, bottomLeft]: [number, number][],
|
|
216
|
+
[perspectiveX, perspectiveY, blend]: ImageWarp,
|
|
217
|
+
u: number,
|
|
218
|
+
v: number
|
|
219
|
+
): [number, number] {
|
|
220
|
+
const point: [number, number] = [0, 0];
|
|
221
|
+
const denominator = perspectiveX * u + perspectiveY * v + 1;
|
|
222
|
+
for (let axis = 0; axis < 2; axis++) {
|
|
223
|
+
const top = topLeft[axis] + (topRight[axis] - topLeft[axis]) * u;
|
|
224
|
+
const bottom = bottomLeft[axis] + (bottomRight[axis] - bottomLeft[axis]) * u;
|
|
225
|
+
const bilinear = top + (bottom - top) * v;
|
|
226
|
+
const acrossTop = topRight[axis] - topLeft[axis] + perspectiveX * topRight[axis];
|
|
227
|
+
const downLeft = bottomLeft[axis] - topLeft[axis] + perspectiveY * bottomLeft[axis];
|
|
228
|
+
const projective = (acrossTop * u + downLeft * v + topLeft[axis]) / denominator;
|
|
229
|
+
point[axis] = projective + (bilinear - projective) * blend;
|
|
230
|
+
}
|
|
231
|
+
return point;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The grid cells along each side of the mesh of an image (see `createImageMesh`): one for a
|
|
236
|
+
* parallelogram, `WARP_GRID_CELLS` for another quad, more where `subdivisionStep` asks for them,
|
|
237
|
+
* and never more than `MAX_IMAGE_GRID_CELLS`.
|
|
238
|
+
*/
|
|
239
|
+
export function getImageGridCells(corners: ImageSourceCorners, subdivisionStep = 0): number {
|
|
240
|
+
let cells = isParallelogram(getWorldCorners(corners)) ? 1 : WARP_GRID_CELLS;
|
|
241
|
+
if (subdivisionStep > 0) {
|
|
242
|
+
const longitudes = corners.map(corner => corner[0]);
|
|
243
|
+
const latitudes = corners.map(corner => corner[1]);
|
|
244
|
+
const span = Math.max(
|
|
245
|
+
Math.max(...longitudes) - Math.min(...longitudes),
|
|
246
|
+
Math.max(...latitudes) - Math.min(...latitudes)
|
|
247
|
+
);
|
|
248
|
+
cells = Math.max(cells, Math.ceil(span / subdivisionStep));
|
|
249
|
+
}
|
|
250
|
+
return Math.min(cells, MAX_IMAGE_GRID_CELLS);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** A mesh of an image, as `BitmapLayer` draws it. */
|
|
254
|
+
export type ImageMesh = {
|
|
255
|
+
/** The count of indices. */
|
|
256
|
+
vertexCount: number;
|
|
257
|
+
/** Longitude, latitude and 0 of each vertex. */
|
|
258
|
+
positions: Float64Array;
|
|
259
|
+
indices: Uint32Array;
|
|
260
|
+
/** The image coordinates of each vertex, with v down. */
|
|
261
|
+
texCoords: Float32Array;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The mesh of an image warped onto its corners (see `getImageWarp`). A parallelogram is one cell,
|
|
266
|
+
* split from its bottom left to its top right corner as MapLibre splits it; another quad is a grid
|
|
267
|
+
* of `WARP_GRID_CELLS`, or of more cells where `subdivisionStep` (degrees, on a globe) asks for
|
|
268
|
+
* them, up to `MAX_IMAGE_GRID_CELLS`. The vertices are placed in Web Mercator space, so the image is uniform there, as in MapLibre.
|
|
269
|
+
*/
|
|
270
|
+
export function createImageMesh(corners: ImageSourceCorners, subdivisionStep = 0): ImageMesh {
|
|
271
|
+
const world = getWorldCorners(corners);
|
|
272
|
+
const warp = getImageWarp(corners);
|
|
273
|
+
const cells = getImageGridCells(corners, subdivisionStep);
|
|
274
|
+
const side = cells + 1;
|
|
275
|
+
const positions = new Float64Array(side * side * 3);
|
|
276
|
+
const texCoords = new Float32Array(side * side * 2);
|
|
277
|
+
const indices = new Uint32Array(cells * cells * 6);
|
|
278
|
+
let index = 0;
|
|
279
|
+
for (let row = 0; row < side; row++) {
|
|
280
|
+
for (let column = 0; column < side; column++) {
|
|
281
|
+
const vertex = row * side + column;
|
|
282
|
+
const u = column / cells;
|
|
283
|
+
const v = row / cells;
|
|
284
|
+
positions.set(mercatorWorldToLngLat(warpImagePoint(world, warp, u, v)), vertex * 3);
|
|
285
|
+
texCoords[vertex * 2] = u;
|
|
286
|
+
texCoords[vertex * 2 + 1] = v;
|
|
287
|
+
if (row > 0 && column > 0) {
|
|
288
|
+
const bottomRight = vertex;
|
|
289
|
+
const bottomLeft = vertex - 1;
|
|
290
|
+
const topRight = vertex - side;
|
|
291
|
+
const topLeft = vertex - side - 1;
|
|
292
|
+
indices.set([topRight, topLeft, bottomLeft, topRight, bottomLeft, bottomRight], index);
|
|
293
|
+
index += 6;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return {vertexCount: indices.length, positions, indices, texCoords};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Whether the corners are listed counterclockwise on the map, which mirrors the image. Its
|
|
302
|
+
* triangles then face away, and a globe, which culls back faces, must cull front faces instead, as
|
|
303
|
+
* MapLibre GL JS does. Measured in Web Mercator space, as MapLibre measures it.
|
|
304
|
+
*/
|
|
305
|
+
export function hasFlippedWinding([topLeft, topRight, bottomRight]: ImageSourceCorners): boolean {
|
|
306
|
+
const [x0, y0] = lngLatToMercatorWorld(topLeft);
|
|
307
|
+
const [x1, y1] = lngLatToMercatorWorld(topRight);
|
|
308
|
+
const [x2, y2] = lngLatToMercatorWorld(bottomRight);
|
|
309
|
+
// Mercator world y is up: clockwise corners turn with a negative cross product.
|
|
310
|
+
return (x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0) > 0;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** A `BitmapLayer` that draws an image warped onto four corners (see `createImageMesh`). */
|
|
314
|
+
class ImageQuadLayer extends BitmapLayer<{corners: ImageSourceCorners}> {
|
|
315
|
+
static layerName = 'ImageQuadLayer';
|
|
316
|
+
|
|
317
|
+
protected _createMesh() {
|
|
318
|
+
return createImageMesh(this.props.corners, this.getSubdivisionStep()) as ReturnType<
|
|
319
|
+
BitmapLayer['_createMesh']
|
|
320
|
+
>;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Props of {@link ImageSourceLayer}. */
|
|
325
|
+
export type ImageSourceLayerProps = CompositeLayerProps & {
|
|
326
|
+
/** The URL of the image, loaded with the layer's `fetch` and `loadOptions`. */
|
|
327
|
+
image: string;
|
|
328
|
+
/** The corners the image is drawn at (see {@link getImageSourceCorners}). */
|
|
329
|
+
corners: ImageSourceCorners;
|
|
330
|
+
/** The texture parameters of the image, or null for the defaults of `BitmapLayer`. */
|
|
331
|
+
textureParameters?: Record<string, unknown> | null;
|
|
332
|
+
/** The load options of the basemap, for the image. */
|
|
333
|
+
loadOptions?: BasemapLoadOptions | null;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const defaultProps: DefaultProps<ImageSourceLayerProps> = {
|
|
337
|
+
image: '',
|
|
338
|
+
corners: {
|
|
339
|
+
type: 'array',
|
|
340
|
+
value: [
|
|
341
|
+
[0, 0],
|
|
342
|
+
[0, 0],
|
|
343
|
+
[0, 0],
|
|
344
|
+
[0, 0]
|
|
345
|
+
],
|
|
346
|
+
compare: true
|
|
347
|
+
},
|
|
348
|
+
textureParameters: {type: 'object', value: null, compare: true},
|
|
349
|
+
loadOptions: {type: 'object', value: null, compare: true}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Draws a `raster` style layer over an `image` source: one image warped onto four corners, as
|
|
354
|
+
* MapLibre GL JS draws it. The layer's extensions (`RasterColorExtension`) pass to the image, as
|
|
355
|
+
* they pass to each tile of a raster tile layer.
|
|
356
|
+
*/
|
|
357
|
+
export class ImageSourceLayer extends CompositeLayer<ImageSourceLayerProps> {
|
|
358
|
+
static layerName = 'ImageSourceLayer';
|
|
359
|
+
static defaultProps = defaultProps;
|
|
360
|
+
|
|
361
|
+
renderLayers() {
|
|
362
|
+
const {image, corners, textureParameters, loadOptions} = this.props;
|
|
363
|
+
const subLayerProps = this.getSubLayerProps({id: 'image'});
|
|
364
|
+
// Set by `RasterColorExtension` where its shader runs, which outputs premultiplied colors.
|
|
365
|
+
const blendParameters = subLayerProps.rasterColorBlendParameters as object | null | undefined;
|
|
366
|
+
return new ImageQuadLayer({
|
|
367
|
+
...subLayerProps,
|
|
368
|
+
// A texture keeps the filter it was created with, so a filter change needs a new layer.
|
|
369
|
+
id: textureParameters ? `${subLayerProps.id}-filtered` : subLayerProps.id,
|
|
370
|
+
...(loadOptions ? {loadOptions} : {}),
|
|
371
|
+
image,
|
|
372
|
+
corners,
|
|
373
|
+
bounds: getImageSourceBounds(corners),
|
|
374
|
+
textureParameters,
|
|
375
|
+
parameters: blendParameters
|
|
376
|
+
? {...subLayerProps.parameters, ...blendParameters}
|
|
377
|
+
: subLayerProps.parameters
|
|
378
|
+
} as any);
|
|
379
|
+
}
|
|
380
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,17 +2,74 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
/** Runtime exports for `@
|
|
5
|
+
/** Runtime exports for `@tangram.gl/basemap-layers`. */
|
|
6
6
|
export {BasemapLayer} from './basemap-layer';
|
|
7
|
+
export type {BasemapTile} from './basemap-layer';
|
|
8
|
+
export type {BasemapSourceData} from './basemap-layer';
|
|
9
|
+
export type {BasemapInsertion} from './basemap-layer';
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
BasemapGlobeConfig,
|
|
13
|
+
BasemapLayerLoadOptions,
|
|
14
|
+
BasemapLayerProps
|
|
15
|
+
} from './basemap-layer';
|
|
16
|
+
export type {
|
|
17
|
+
BasemapLoadOptions,
|
|
18
|
+
BasemapSource,
|
|
19
|
+
BasemapStyle,
|
|
20
|
+
BasemapStyleLayer,
|
|
21
|
+
ResolvedBasemapStyle,
|
|
22
|
+
ResolvedBasemapStyleLayer
|
|
23
|
+
} from './style-resolver';
|
|
24
|
+
|
|
25
|
+
export {BasemapLoadError} from './basemap-error';
|
|
26
|
+
export type {BasemapLoadErrorDetails, BasemapLoadErrorKind} from './basemap-error';
|
|
27
|
+
export {DemPixelReadError} from './dem-pixels';
|
|
28
|
+
export type {BasemapSourceFeature, QuerySourceFeaturesOptions} from './source-features';
|
|
29
|
+
export {pickTerrainSurface} from './terrain-query';
|
|
30
|
+
export type {TerrainSurface, TerrainSurfaceHit} from './terrain-query';
|
|
31
|
+
export type {
|
|
32
|
+
BasemapFeatureState,
|
|
33
|
+
BasemapPickedFeature,
|
|
34
|
+
FeatureState,
|
|
35
|
+
FeatureStates
|
|
36
|
+
} from './feature-state';
|
|
7
37
|
export {
|
|
8
38
|
createDemTileset,
|
|
9
39
|
getBasemapLayers,
|
|
10
40
|
getGlobeBaseLayers,
|
|
11
41
|
getGlobeTopLayers
|
|
12
42
|
} from './globe-layers';
|
|
43
|
+
export type {StyleLayerSubLayerProps} from './globe-layers';
|
|
13
44
|
export {getSpriteIconMapping, getSpriteSources, loadSpriteAtlases} from './sprite';
|
|
14
45
|
export type {SpriteAtlas, SpriteIconMappingEntry, SpriteSource} from './sprite';
|
|
15
46
|
export {getLabelFont} from './text-font';
|
|
16
47
|
export type {LabelFont, LabelFontFamily} from './text-font';
|
|
48
|
+
export {
|
|
49
|
+
createRasterTileFingerprintFilter,
|
|
50
|
+
getRasterTileFingerprint
|
|
51
|
+
} from './raster-tile-fingerprint';
|
|
52
|
+
export type {RasterTileIndex, RasterTileResponse, RejectRasterTile} from './raster-tile-loader';
|
|
53
|
+
export type {
|
|
54
|
+
BasemapResourceType,
|
|
55
|
+
BasemapTransformedRequest,
|
|
56
|
+
BasemapTransformRequest
|
|
57
|
+
} from './basemap-request';
|
|
17
58
|
export {GlyphStore} from './glyph-store';
|
|
18
59
|
export type {GlyphStoreOptions} from './glyph-store';
|
|
60
|
+
export {ProjectedBitmapLayer} from './projected-bitmap-layer';
|
|
61
|
+
export {DEFAULT_MAX_STRETCH, getProjectedTileIndices} from './projected-tile-selection';
|
|
62
|
+
export type {
|
|
63
|
+
ProjectedTileIndex,
|
|
64
|
+
ProjectedTileSelectionOptions
|
|
65
|
+
} from './projected-tile-selection';
|
|
66
|
+
export {ProjectedTileLayer, ProjectedTileset2D} from './projected-tileset';
|
|
67
|
+
export {getMercatorZoom} from './projected-viewport';
|
|
68
|
+
export type {ProjectedViewportLike} from './projected-viewport';
|
|
69
|
+
export {registerBasemapProtocol, unregisterBasemapProtocol} from './basemap-protocol';
|
|
70
|
+
export type {
|
|
71
|
+
BasemapProtocolHandler,
|
|
72
|
+
BasemapRequestParameters,
|
|
73
|
+
BasemapRequestType,
|
|
74
|
+
BasemapResourceResponse
|
|
75
|
+
} from './basemap-protocol';
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import {LayerExtension} from '@deck.gl/core';
|
|
10
10
|
import type {Layer, UpdateParameters} from '@deck.gl/core';
|
|
11
|
-
import
|
|
11
|
+
import {createShaderInjectionPlugin} from './shader-injection-plugin';
|
|
12
12
|
|
|
13
13
|
export type LineBlurExtensionOptions = {
|
|
14
14
|
/**
|
|
@@ -104,7 +104,7 @@ export class LineBlurExtension extends LayerExtension<LineBlurExtensionOptions>
|
|
|
104
104
|
// `vPathPosition.x` rather than its absolute value, whose gradient falls to 0 across the
|
|
105
105
|
// middle of the stroke, where a blur wider than the line keeps it translucent in MapLibre.
|
|
106
106
|
// Gradients are taken before any fragment of the quad is discarded.
|
|
107
|
-
const lineBlur
|
|
107
|
+
const lineBlur = createShaderInjectionPlugin({
|
|
108
108
|
name: 'lineBlur',
|
|
109
109
|
inject: {
|
|
110
110
|
'vs:#decl': `${UNIFORMS}
|
|
@@ -140,13 +140,13 @@ float lineBlur_widthRatio = 1.0;
|
|
|
140
140
|
#if defined(DASH_ENABLED) && !defined(PATH_STYLE_OFFSET)
|
|
141
141
|
// PathStyleExtension measured the dashes in the drawn stroke's widths, MapLibre in the line's.
|
|
142
142
|
// Offset lines are not widened, and keep the dash phase that the offset shader corrects.
|
|
143
|
-
|
|
144
|
-
#ifdef
|
|
145
|
-
float lineBlur_dashUnit =
|
|
143
|
+
pathStyle_dashArray *= lineBlur_widthRatio;
|
|
144
|
+
#ifdef DASH_MODE_PATH
|
|
145
|
+
float lineBlur_dashUnit = pathStyle_dashArray.x + pathStyle_dashArray.y;
|
|
146
146
|
float lineBlur_dashPeriod = pathStyle.dashAlignMode == 0.0
|
|
147
147
|
? lineBlur_dashUnit
|
|
148
|
-
:
|
|
149
|
-
|
|
148
|
+
: pathStyle_dashPathLength / max(round(pathStyle_dashPathLength / max(lineBlur_dashUnit, 0.0001)), 1.0);
|
|
149
|
+
pathStyle_dashOffset = lineBlur_dashPeriod > 0.0 ? mod(dashOffsetAndLength.x, lineBlur_dashPeriod) : 0.0;
|
|
150
150
|
#endif
|
|
151
151
|
#endif
|
|
152
152
|
#ifdef LINE_BLUR_PER_FEATURE
|
|
@@ -204,19 +204,21 @@ in float lineBlur_padPixels;
|
|
|
204
204
|
}
|
|
205
205
|
lineBlur_edgePixels -= lineBlur_padPixels;
|
|
206
206
|
// Picking colors keep the coverage PathLayer gave them.
|
|
207
|
+
float lineBlur_fade = lineBlur_coverage;
|
|
207
208
|
if (lineBlur_coverage > 0.0 && !bool(picking.isActive)) {
|
|
208
|
-
|
|
209
|
+
lineBlur_fade = clamp(
|
|
209
210
|
(lineBlur_edgePixels + 0.5) / (lineBlur_blur + 1.0), 0.0, 1.0
|
|
210
|
-
)
|
|
211
|
+
);
|
|
212
|
+
fragColor.a *= lineBlur_fade / lineBlur_coverage;
|
|
211
213
|
}
|
|
212
214
|
#endif
|
|
213
215
|
`
|
|
214
216
|
},
|
|
215
217
|
uniformTypes: {blur: 'f32', gapOffset: 'f32', gapSide: 'f32'}
|
|
216
|
-
};
|
|
218
|
+
});
|
|
217
219
|
return {
|
|
218
|
-
|
|
219
|
-
defines:
|
|
220
|
+
plugins: [lineBlur],
|
|
221
|
+
defines: {LINE_BLUR_ENABLED: true, LINE_BLUR_PER_FEATURE: extension.opts.perFeature}
|
|
220
222
|
};
|
|
221
223
|
}
|
|
222
224
|
}
|