@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,173 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {LayerExtension} from '@deck.gl/core';
|
|
6
|
+
import type {CompositeLayer, Layer} from '@deck.gl/core';
|
|
7
|
+
import {createSegmentAttributeUpdate} from './line-metrics';
|
|
8
|
+
import {createShaderInjectionPlugin} from './shader-injection-plugin';
|
|
9
|
+
|
|
10
|
+
const SHADER_MODULE_NAME = 'linePattern';
|
|
11
|
+
|
|
12
|
+
const UNIFORMS = `\
|
|
13
|
+
layout(std140) uniform linePatternUniforms {
|
|
14
|
+
vec2 textureSize;
|
|
15
|
+
float pixelsPerUnit;
|
|
16
|
+
} linePattern;
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const VS = `\
|
|
20
|
+
${UNIFORMS}
|
|
21
|
+
in vec4 instanceLinePatternFrames;
|
|
22
|
+
in vec3 instanceLinePatternDistances;
|
|
23
|
+
flat out vec4 linePattern_frame;
|
|
24
|
+
flat out float linePattern_repeat;
|
|
25
|
+
out float linePattern_distance;
|
|
26
|
+
out float linePattern_across;
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
const FS = `\
|
|
30
|
+
${UNIFORMS}
|
|
31
|
+
uniform sampler2D linePattern_texture;
|
|
32
|
+
flat in vec4 linePattern_frame;
|
|
33
|
+
flat in float linePattern_repeat;
|
|
34
|
+
in float linePattern_distance;
|
|
35
|
+
in float linePattern_across;
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
type LinePatternModuleProps = {
|
|
39
|
+
linePattern_texture: unknown;
|
|
40
|
+
textureSize: [number, number];
|
|
41
|
+
pixelsPerUnit: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** An image's rectangle in the pattern atlas, in pixels. */
|
|
45
|
+
type PatternFrame = {x: number; y: number; width: number; height: number};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Adds `line-pattern` to the `PathLayer`s of a layer, as MapLibre GL JS draws it: the image is
|
|
49
|
+
* stretched across the line's width and repeated along it, at its own aspect ratio. Its height is
|
|
50
|
+
* the line's `line-width` at the integer zoom (`getLinePatternWidth`), and its length is measured
|
|
51
|
+
* from the start of each line in the tile, in pixels at the integer zoom: between integer zooms
|
|
52
|
+
* the pattern scales with the map. Each fragment takes the image's color times the stroke's own
|
|
53
|
+
* color, which should be white with the line's opacity.
|
|
54
|
+
*
|
|
55
|
+
* `linePatternAtlas` holds the images, each with a 1 pixel border copied from its opposite edge
|
|
56
|
+
* (see `getPatternAtlas`), at `linePatternMapping`'s rectangles; `getLinePattern` names a path's
|
|
57
|
+
* image. `linePatternPixelsPerUnit` is 2 to the integer zoom: pixels per common unit at that
|
|
58
|
+
* zoom. WebGL only: on WebGPU the paths draw nothing.
|
|
59
|
+
*/
|
|
60
|
+
export class LinePatternExtension extends LayerExtension {
|
|
61
|
+
static extensionName = 'LinePatternExtension';
|
|
62
|
+
static defaultProps = {
|
|
63
|
+
linePatternAtlas: {type: 'image', value: null, async: true},
|
|
64
|
+
linePatternMapping: {type: 'object', value: {}, async: true},
|
|
65
|
+
linePatternPixelsPerUnit: 1,
|
|
66
|
+
getLinePattern: {type: 'accessor', value: ''},
|
|
67
|
+
getLinePatternWidth: {type: 'accessor', value: 1}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
isEnabled(layer: Layer): boolean {
|
|
71
|
+
return layer.context.device.type !== 'webgpu' && 'pathTesselator' in (layer.state || {});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
initializeState(this: Layer<any>, context: unknown, extension: this) {
|
|
75
|
+
if (!extension.isEnabled(this)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.getAttributeManager()?.addInstanced({
|
|
79
|
+
instanceLinePatternFrames: {
|
|
80
|
+
size: 4,
|
|
81
|
+
accessor: 'getLinePattern',
|
|
82
|
+
transform: (name: string) => {
|
|
83
|
+
const frame = (this.props.linePatternMapping as Record<string, PatternFrame>)?.[name];
|
|
84
|
+
return frame ? [frame.x, frame.y, frame.width, frame.height] : [0, 0, 0, 0];
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
// Each segment's distances from its path's start, and the path's width at the integer zoom.
|
|
88
|
+
instanceLinePatternDistances: {
|
|
89
|
+
size: 3,
|
|
90
|
+
accessor: ['getPath', 'getLinePatternWidth'],
|
|
91
|
+
update: createSegmentAttributeUpdate(({start, end}, object, objectInfo) => {
|
|
92
|
+
const width = (this.props as any).getLinePatternWidth;
|
|
93
|
+
return [start, end, typeof width === 'function' ? width(object, objectInfo) : width];
|
|
94
|
+
}),
|
|
95
|
+
noAlloc: false
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** On WebGPU, where the pattern shader does not run, the paths draw nothing. */
|
|
101
|
+
getSubLayerProps(this: CompositeLayer, extension: this): any {
|
|
102
|
+
const props = LayerExtension.prototype.getSubLayerProps.call(this, extension);
|
|
103
|
+
return this.context.device.type === 'webgpu' ? {...props, getColor: [0, 0, 0, 0]} : props;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
updateState(this: Layer<any>, {props, oldProps}: any, extension: this) {
|
|
107
|
+
if (extension.isEnabled(this) && props.linePatternMapping !== oldProps.linePatternMapping) {
|
|
108
|
+
this.getAttributeManager()?.invalidate('getLinePattern');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
draw(this: Layer<any>, params: unknown, extension: this) {
|
|
113
|
+
const texture = this.props.linePatternAtlas;
|
|
114
|
+
if (!extension.isEnabled(this) || !texture) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const linePattern: LinePatternModuleProps = {
|
|
118
|
+
linePattern_texture: texture,
|
|
119
|
+
textureSize: [texture.width, texture.height],
|
|
120
|
+
pixelsPerUnit: Number(this.props.linePatternPixelsPerUnit) || 1
|
|
121
|
+
};
|
|
122
|
+
this.setShaderModuleProps({[SHADER_MODULE_NAME]: linePattern});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getShaders(this: Layer, extension: this) {
|
|
126
|
+
if (!extension.isEnabled(this)) {
|
|
127
|
+
return {};
|
|
128
|
+
}
|
|
129
|
+
const plugin = createShaderInjectionPlugin({
|
|
130
|
+
name: SHADER_MODULE_NAME,
|
|
131
|
+
vs: VS,
|
|
132
|
+
fs: FS,
|
|
133
|
+
inject: {
|
|
134
|
+
// The distance at this vertex, from its segment's start by PathLayer's `vPathPosition.y`,
|
|
135
|
+
// in the segment's widths. One repeat of the image is its width over its height, in line
|
|
136
|
+
// widths at the integer zoom.
|
|
137
|
+
'vs:#main-end': `
|
|
138
|
+
float linePattern_along = vPathLength > 0.0 ? vPathPosition.y / vPathLength : 0.0;
|
|
139
|
+
linePattern_distance = mix(
|
|
140
|
+
instanceLinePatternDistances.x, instanceLinePatternDistances.y, linePattern_along
|
|
141
|
+
) * linePattern.pixelsPerUnit;
|
|
142
|
+
linePattern_frame = instanceLinePatternFrames;
|
|
143
|
+
linePattern_repeat = instanceLinePatternFrames.w > 0.0
|
|
144
|
+
? instanceLinePatternFrames.z / instanceLinePatternFrames.w * instanceLinePatternDistances.z
|
|
145
|
+
: 0.0;
|
|
146
|
+
linePattern_across = vPathPosition.x;
|
|
147
|
+
`,
|
|
148
|
+
// As MapLibre samples it: across the image from one edge of the line to the other, and
|
|
149
|
+
// along it from the border pixel before the image to the one after.
|
|
150
|
+
'fs:DECKGL_FILTER_COLOR': `
|
|
151
|
+
if (!bool(picking.isActive)) {
|
|
152
|
+
if (linePattern_repeat <= 0.0) {
|
|
153
|
+
discard;
|
|
154
|
+
}
|
|
155
|
+
vec2 linePattern_position = vec2(
|
|
156
|
+
fract(linePattern_distance / linePattern_repeat),
|
|
157
|
+
clamp(0.5 * linePattern_across + 0.5, 0.0, 1.0)
|
|
158
|
+
);
|
|
159
|
+
vec2 linePattern_texel = 1.0 / linePattern.textureSize;
|
|
160
|
+
vec2 linePattern_uv = mix(
|
|
161
|
+
linePattern_frame.xy * linePattern_texel - linePattern_texel,
|
|
162
|
+
(linePattern_frame.xy + linePattern_frame.zw) * linePattern_texel + linePattern_texel,
|
|
163
|
+
linePattern_position
|
|
164
|
+
);
|
|
165
|
+
color *= texture(linePattern_texture, linePattern_uv);
|
|
166
|
+
}
|
|
167
|
+
`
|
|
168
|
+
},
|
|
169
|
+
uniformTypes: {textureSize: 'vec2<f32>', pixelsPerUnit: 'f32'}
|
|
170
|
+
});
|
|
171
|
+
return {plugins: [plugin]};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {LayerExtension} from '@deck.gl/core';
|
|
6
|
+
import type {Accessor, CompositeLayer, Layer, LayerContext, UpdateParameters} from '@deck.gl/core';
|
|
7
|
+
import {PathStyleExtension} from '@deck.gl/extensions';
|
|
8
|
+
import type {PathStyleExtensionProps} from '@deck.gl/extensions';
|
|
9
|
+
import type {ShaderPlugin} from '@luma.gl/shaders';
|
|
10
|
+
import {createShaderInjectionPlugin} from './shader-injection-plugin';
|
|
11
|
+
|
|
12
|
+
type LineShapeProps = {lineCapSquare?: boolean};
|
|
13
|
+
|
|
14
|
+
const MIN_JOINT_SIN_HALF_ANGLE = 0.001;
|
|
15
|
+
/** The largest miter ratio that the line shape shader can measure. */
|
|
16
|
+
export const MAX_LINE_SHAPE_MITER_RATIO = 1 / MIN_JOINT_SIN_HALF_ANGLE;
|
|
17
|
+
|
|
18
|
+
const UNIFORMS = /* glsl */ `
|
|
19
|
+
layout(std140) uniform lineShapeUniforms {
|
|
20
|
+
float squareCap;
|
|
21
|
+
} lineShape;
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How far the line is cut beyond a joint, in half widths along the joint's outward miter
|
|
26
|
+
* direction, as MapLibre GL JS draws it. A miter within the limit is not cut. Beyond the limit,
|
|
27
|
+
* a miter becomes a bevel: the chord between the two outer corners, `sinHalfAngle` from the
|
|
28
|
+
* vertex. Past a miter of two half widths MapLibre draws its "flip bevel", whose edge passes
|
|
29
|
+
* through the vertex.
|
|
30
|
+
*/
|
|
31
|
+
const GET_JOINT_CUT = /* glsl */ `
|
|
32
|
+
vec3 lineShape_getJoint(vec2 deltaA, vec2 deltaB, bool isCap, bool isRound, float miterLimit) {
|
|
33
|
+
float lenA = length(deltaA);
|
|
34
|
+
float lenB = length(deltaB);
|
|
35
|
+
if (isCap || isRound || lenA == 0.0 || lenB == 0.0) {
|
|
36
|
+
return vec3(0.0, 0.0, 1e6);
|
|
37
|
+
}
|
|
38
|
+
vec2 dirA = deltaA / lenA;
|
|
39
|
+
vec2 dirB = deltaB / lenB;
|
|
40
|
+
float sinHalfAngle = sqrt(max(0.5 + 0.5 * dot(dirA, dirB), 0.0));
|
|
41
|
+
float miterSize = 1.0 / max(sinHalfAngle, ${MIN_JOINT_SIN_HALF_ANGLE});
|
|
42
|
+
vec2 outward = dirA - dirB;
|
|
43
|
+
if (miterSize <= miterLimit || length(outward) == 0.0) {
|
|
44
|
+
return vec3(0.0, 0.0, 1e6);
|
|
45
|
+
}
|
|
46
|
+
return vec3(normalize(outward), miterSize > 2.0 ? 0.0 : sinHalfAngle);
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const LINE_SHAPE_PLUGIN = createShaderInjectionPlugin({
|
|
51
|
+
name: 'lineShape',
|
|
52
|
+
vs: /* glsl */ `
|
|
53
|
+
${UNIFORMS}
|
|
54
|
+
${GET_JOINT_CUT}
|
|
55
|
+
// Per joint: how far this vertex is beyond the joint, and where the joint is cut.
|
|
56
|
+
out vec2 lineShape_beyond;
|
|
57
|
+
out vec2 lineShape_cut;
|
|
58
|
+
`,
|
|
59
|
+
fs: /* glsl */ `
|
|
60
|
+
in vec2 lineShape_beyond;
|
|
61
|
+
in vec2 lineShape_cut;
|
|
62
|
+
`,
|
|
63
|
+
uniformTypes: {squareCap: 'f32'},
|
|
64
|
+
inject: {
|
|
65
|
+
'vs:#main-end': {
|
|
66
|
+
order: 1,
|
|
67
|
+
injection: /* glsl */ `
|
|
68
|
+
lineShape_beyond = vec2(0.0);
|
|
69
|
+
lineShape_cut = vec2(1e6);
|
|
70
|
+
if (!path.billboard) {
|
|
71
|
+
bool endVertex = positions.x > 0.0;
|
|
72
|
+
// PathLayer has the previous, current and next points of this vertex. The segment's other
|
|
73
|
+
// joint takes the point beyond the segment's other end.
|
|
74
|
+
vec3 otherPosition = endVertex
|
|
75
|
+
? project_position(instanceLeftPositions, instanceLeftPositions64Low)
|
|
76
|
+
: project_position(instanceRightPositions, instanceRightPositions64Low);
|
|
77
|
+
vec3 left = endVertex ? otherPosition : prevPosition;
|
|
78
|
+
vec3 start = endVertex ? prevPosition : currPosition;
|
|
79
|
+
vec3 end = endVertex ? currPosition : nextPosition;
|
|
80
|
+
vec3 right = endVertex ? nextPosition : otherPosition;
|
|
81
|
+
mat3 rotationMatrix;
|
|
82
|
+
bool needsRotation = project_needs_rotation(currPosition, rotationMatrix);
|
|
83
|
+
mat3 rotation = needsRotation ? rotationMatrix : mat3(1.0);
|
|
84
|
+
vec2 segment = ((end - start) * rotation).xy;
|
|
85
|
+
vec2 beforeStart = ((start - left) * rotation).xy;
|
|
86
|
+
vec2 afterEnd = ((right - end) * rotation).xy;
|
|
87
|
+
bool isPathStart = instanceTypes == 1.0 || instanceTypes == 3.0;
|
|
88
|
+
bool isPathEnd = instanceTypes == 2.0 || instanceTypes == 3.0;
|
|
89
|
+
|
|
90
|
+
if (lineShape.squareCap > 0.5 && length(segment) > 0.0) {
|
|
91
|
+
// MapLibre extends the cap's vertices beyond the endpoint and keeps the endpoint's line
|
|
92
|
+
// distance on them, so the dashes of the first and last segments stretch over the caps.
|
|
93
|
+
float capDirection = 0.0;
|
|
94
|
+
if (!endVertex && isPathStart) {
|
|
95
|
+
capDirection = -1.0;
|
|
96
|
+
} else if (endVertex && isPathEnd) {
|
|
97
|
+
capDirection = 1.0;
|
|
98
|
+
}
|
|
99
|
+
float capLength = width.x;
|
|
100
|
+
#ifdef PATH_STYLE_OFFSET
|
|
101
|
+
capLength /= abs(instanceOffsets * 2.0) + 1.0;
|
|
102
|
+
#ifdef LINE_SHAPE_GAP_CAP
|
|
103
|
+
if (instanceOffsetAndCap.y > 0.0) {
|
|
104
|
+
capLength = project_pixel_size(instanceOffsetAndCap.y);
|
|
105
|
+
}
|
|
106
|
+
#endif
|
|
107
|
+
#endif
|
|
108
|
+
vec3 shift = vec3(normalize(segment) * capDirection * capLength, 0.0);
|
|
109
|
+
if (needsRotation) {
|
|
110
|
+
shift = rotationMatrix * shift;
|
|
111
|
+
}
|
|
112
|
+
geometry.position.xyz += shift;
|
|
113
|
+
gl_Position += project.viewProjectionMatrix * vec4(shift, 0.0);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#ifndef PATH_STYLE_OFFSET
|
|
117
|
+
// Offset lines turn their corners away from the path: their joints keep PathLayer's cut.
|
|
118
|
+
if (width.x > 0.0) {
|
|
119
|
+
vec3 startJoint = lineShape_getJoint(
|
|
120
|
+
beforeStart, segment, isPathStart, path.jointType > 0.5, path.miterLimit + 1.0
|
|
121
|
+
);
|
|
122
|
+
vec3 endJoint = lineShape_getJoint(
|
|
123
|
+
segment, afterEnd, isPathEnd, path.jointType > 0.5, path.miterLimit + 1.0
|
|
124
|
+
);
|
|
125
|
+
vec2 fromStart = ((geometry.position.xyz - start) * rotation).xy / width.x;
|
|
126
|
+
vec2 fromEnd = ((geometry.position.xyz - end) * rotation).xy / width.x;
|
|
127
|
+
lineShape_beyond = vec2(dot(fromStart, startJoint.xy), dot(fromEnd, endJoint.xy));
|
|
128
|
+
lineShape_cut = vec2(startJoint.z, endJoint.z);
|
|
129
|
+
}
|
|
130
|
+
#endif
|
|
131
|
+
}
|
|
132
|
+
`
|
|
133
|
+
},
|
|
134
|
+
'fs:#main-end': {
|
|
135
|
+
order: 1,
|
|
136
|
+
injection: /* glsl */ `
|
|
137
|
+
// Both are affine in the fragment's position, so they interpolate exactly.
|
|
138
|
+
#ifndef PATH_STYLE_OFFSET
|
|
139
|
+
if (lineShape_beyond.x > lineShape_cut.x || lineShape_beyond.y > lineShape_cut.y) {
|
|
140
|
+
discard;
|
|
141
|
+
}
|
|
142
|
+
#endif
|
|
143
|
+
`
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
function isPathLayer(layer: Layer): boolean {
|
|
149
|
+
return layer.context.device.type === 'webgl' && 'pathTesselator' in (layer.state || {});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Draws a `PathLayer`'s caps and joins as MapLibre GL JS draws `line-cap` and `line-join`, which
|
|
154
|
+
* deck.gl does not: with `lineCapSquare`, each end of a path extends past its endpoint by half
|
|
155
|
+
* the line's width, or by half the gap plus the line width for a gap. A join whose miter exceeds
|
|
156
|
+
* `miterLimit + 1` half widths is bevelled (see `GET_JOINT_CUT`). Set `capRounded: false` for
|
|
157
|
+
* a square cap. Adds no vertex attribute. WebGL
|
|
158
|
+
* only, and not on billboard paths; joins of paths with `PathStyleExtension`'s offsets keep
|
|
159
|
+
* deck.gl's flat cut.
|
|
160
|
+
*/
|
|
161
|
+
export class LineShapeExtension extends LayerExtension {
|
|
162
|
+
static extensionName = 'LineShapeExtension';
|
|
163
|
+
static defaultProps = {lineCapSquare: false};
|
|
164
|
+
|
|
165
|
+
/** Forward the cap choice to the shader. */
|
|
166
|
+
updateState(this: Layer<LineShapeProps>, {props}: UpdateParameters<Layer<LineShapeProps>>) {
|
|
167
|
+
if (isPathLayer(this)) {
|
|
168
|
+
this.setShaderModuleProps({lineShape: {squareCap: props.lineCapSquare ? 1 : 0}});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Install the shape shader on supported PathLayers. */
|
|
173
|
+
getShaders(this: Layer) {
|
|
174
|
+
return isPathLayer(this) ? {plugins: [LINE_SHAPE_PLUGIN]} : {};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Carries the distance to a square gap cap alongside the lateral offset. WebGL2 only guarantees
|
|
180
|
+
* 16 vertex attributes, all of which a dashed and offset path already uses.
|
|
181
|
+
*/
|
|
182
|
+
export class GapCapOffsetExtension extends PathStyleExtension {
|
|
183
|
+
static extensionName = 'GapCapOffsetExtension';
|
|
184
|
+
static defaultProps = {
|
|
185
|
+
...PathStyleExtension.defaultProps,
|
|
186
|
+
getSquareGapCap: {type: 'accessor', value: 0}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** Pack the lateral offset and the per-feature square cap length into one accessor on WebGL. */
|
|
190
|
+
getSubLayerProps(this: CompositeLayer, extension: this) {
|
|
191
|
+
const props: {
|
|
192
|
+
getOffset: Accessor<unknown, number>;
|
|
193
|
+
getSquareGapCap: Accessor<unknown, number>;
|
|
194
|
+
updateTriggers: Record<string, unknown>;
|
|
195
|
+
} = LayerExtension.prototype.getSubLayerProps.call(this, extension);
|
|
196
|
+
if (this.context.device.type !== 'webgl') {
|
|
197
|
+
return props;
|
|
198
|
+
}
|
|
199
|
+
const {getOffset, getSquareGapCap, updateTriggers} = props;
|
|
200
|
+
const packed: Accessor<unknown, [number, number]> = (feature, info) => [
|
|
201
|
+
typeof getOffset === 'function' ? getOffset(feature, info) : getOffset,
|
|
202
|
+
typeof getSquareGapCap === 'function' ? getSquareGapCap(feature, info) : getSquareGapCap
|
|
203
|
+
];
|
|
204
|
+
return {
|
|
205
|
+
...props,
|
|
206
|
+
getOffset: packed,
|
|
207
|
+
updateTriggers: {
|
|
208
|
+
...updateTriggers,
|
|
209
|
+
getOffset: [updateTriggers.getOffset, updateTriggers.getSquareGapCap]
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Use the packed buffer from the first model build. */
|
|
215
|
+
initializeState(this: Layer<PathStyleExtensionProps>, context: LayerContext, extension: this) {
|
|
216
|
+
addGapCapOffsetAttribute(this);
|
|
217
|
+
super.initializeState.call(this, context, extension);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Refresh the layout if an existing path starts drawing with an offset. */
|
|
221
|
+
updateState(
|
|
222
|
+
this: Layer<PathStyleExtensionProps>,
|
|
223
|
+
params: UpdateParameters<Layer<PathStyleExtensionProps>>,
|
|
224
|
+
extension: this
|
|
225
|
+
) {
|
|
226
|
+
if (params.changeFlags.extensionsChanged) {
|
|
227
|
+
addGapCapOffsetAttribute(this);
|
|
228
|
+
}
|
|
229
|
+
super.updateState.call(this, params, extension);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Adapt the existing PathStyle shader to read the first component for lateral offsets. */
|
|
233
|
+
getShaders(this: Layer<PathStyleExtensionProps>, extension: this) {
|
|
234
|
+
const shaders = super.getShaders.call(this, extension);
|
|
235
|
+
if (!isPathLayer(this)) {
|
|
236
|
+
return shaders;
|
|
237
|
+
}
|
|
238
|
+
const plugins = (shaders.plugins as ShaderPlugin[]).map(plugin => {
|
|
239
|
+
const vertexInputs = {...plugin.vertexInputs};
|
|
240
|
+
delete vertexInputs.instanceOffsets;
|
|
241
|
+
vertexInputs.instanceOffsetAndCap = 'vec2<f32>';
|
|
242
|
+
return {
|
|
243
|
+
...plugin,
|
|
244
|
+
vertexInputs,
|
|
245
|
+
module: {
|
|
246
|
+
...plugin.module,
|
|
247
|
+
name: plugin.name,
|
|
248
|
+
vs: `${plugin.module?.vs ?? ''}\n#define instanceOffsets instanceOffsetAndCap.x\n`
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
return {...shaders, plugins, defines: {...shaders.defines, LINE_SHAPE_GAP_CAP: true}};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function addGapCapOffsetAttribute(layer: Layer): void {
|
|
257
|
+
if (!isPathLayer(layer)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const attributes = layer.getAttributeManager();
|
|
261
|
+
if (attributes && attributes.getAttributes().instanceOffsets?.size !== 2) {
|
|
262
|
+
attributes.remove(['instanceOffsets']);
|
|
263
|
+
attributes.addInstanced({
|
|
264
|
+
instanceOffsets: {
|
|
265
|
+
size: 2,
|
|
266
|
+
accessor: 'getOffset',
|
|
267
|
+
shaderAttributes: {instanceOffsetAndCap: {}}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
attributes.getAttributes().instanceOffsets.setLayoutChanged();
|
|
271
|
+
}
|
|
272
|
+
}
|
package/src/map-style-loader.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {LoaderContext, LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
5
|
+
import type {LoaderContext, LoaderOptions, LoaderWithParser} from '@loaders.gl/core/loader-utils';
|
|
6
6
|
import {ResolvedBasemapStyleSchema} from './map-style-schema';
|
|
7
|
-
import {resolveBasemapStyle} from './style-resolver';
|
|
7
|
+
import {markResolvedBasemapStyle, resolveBasemapStyle} from './style-resolver';
|
|
8
8
|
import type {BasemapLoadOptions, BasemapStyle, ResolvedBasemapStyle} from './style-resolver';
|
|
9
9
|
|
|
10
10
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
@@ -50,7 +50,8 @@ export const MapStyleLoader = {
|
|
|
50
50
|
) => {
|
|
51
51
|
const text = typeof data === 'string' ? data : new TextDecoder().decode(data);
|
|
52
52
|
const style = JSON.parse(text) as BasemapStyle;
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
const loadOptions = getMapStyleLoadOptions(options, context);
|
|
54
|
+
const resolved = await resolveBasemapStyle(style, loadOptions);
|
|
55
|
+
return markResolvedBasemapStyle(ResolvedBasemapStyleSchema.parse(resolved), loadOptions.baseUrl);
|
|
55
56
|
}
|
|
56
57
|
} as const satisfies LoaderWithParser<ResolvedBasemapStyle, never, MapStyleLoaderOptions>;
|
package/src/map-style.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
/** Map-style helpers exported from `@
|
|
5
|
+
/** Map-style helpers exported from `@tangram.gl/basemap-layers/map-style`. */
|
|
6
6
|
export {filterFeatures, findFeaturesStyledByLayer, parseProperties} from './mapbox-style';
|
|
7
7
|
export {
|
|
8
8
|
BasemapSourceSchema,
|
|
@@ -13,6 +13,7 @@ export {
|
|
|
13
13
|
export {MapStyleLoader} from './map-style-loader';
|
|
14
14
|
export type {MapStyleLoaderOptions} from './map-style-loader';
|
|
15
15
|
export {
|
|
16
|
+
isResolvedBasemapStyle,
|
|
16
17
|
resolveBasemapStyle,
|
|
17
18
|
type BasemapLoadOptions,
|
|
18
19
|
type BasemapSource,
|