@mapwhit/tilerenderer 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/min/package.json +2 -1
- package/build/min/src/shaders/_prelude.fragment.glsl.js +1 -1
- package/build/min/src/shaders/_prelude.vertex.glsl.js +1 -1
- package/build/min/src/shaders/background.fragment.glsl.js +1 -1
- package/build/min/src/shaders/background.vertex.glsl.js +1 -1
- package/build/min/src/shaders/background_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/circle.fragment.glsl.js +1 -1
- package/build/min/src/shaders/circle.vertex.glsl.js +1 -1
- package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -1
- package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -1
- package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -1
- package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -1
- package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -1
- package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -1
- package/build/min/src/shaders/debug.fragment.glsl.js +1 -1
- package/build/min/src/shaders/debug.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/heatmap.fragment.glsl.js +1 -1
- package/build/min/src/shaders/heatmap.vertex.glsl.js +1 -1
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +1 -1
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade.fragment.glsl.js +1 -1
- package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +1 -1
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line_gradient.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line_gradient.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line_sdf.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line_sdf.vertex.glsl.js +1 -1
- package/build/min/src/shaders/raster.fragment.glsl.js +1 -1
- package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
- package/build/min/src/shaders/symbol_icon.fragment.glsl.js +1 -1
- package/build/min/src/shaders/symbol_icon.vertex.glsl.js +1 -1
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +1 -1
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +1 -1
- package/package.json +3 -2
- package/src/data/array_types.js +54 -81
- package/src/data/bucket/circle_attributes.js +2 -4
- package/src/data/bucket/circle_bucket.js +19 -13
- package/src/data/bucket/fill_attributes.js +2 -4
- package/src/data/bucket/fill_bucket.js +38 -24
- package/src/data/bucket/fill_extrusion_attributes.js +2 -4
- package/src/data/bucket/fill_extrusion_bucket.js +56 -34
- package/src/data/bucket/heatmap_bucket.js +2 -7
- package/src/data/bucket/line_attributes.js +2 -4
- package/src/data/bucket/line_bucket.js +207 -159
- package/src/data/bucket/pattern_attributes.js +2 -4
- package/src/data/bucket/pattern_bucket_features.js +5 -7
- package/src/data/bucket/symbol_attributes.js +12 -26
- package/src/data/bucket/symbol_bucket.js +111 -221
- package/src/data/bucket/symbol_buffers.js +62 -0
- package/src/data/bucket/symbol_collision_buffers.js +33 -0
- package/src/data/bucket.js +2 -6
- package/src/data/dem_data.js +11 -7
- package/src/data/extent.js +1 -1
- package/src/data/feature_index.js +35 -20
- package/src/data/index_array_type.js +1 -6
- package/src/data/load_geometry.js +6 -9
- package/src/data/pos_attributes.js +2 -3
- package/src/data/program_configuration.js +44 -26
- package/src/data/raster_bounds_attributes.js +2 -2
- package/src/data/segment.js +4 -3
- package/src/geo/coordinate.js +1 -1
- package/src/geo/lng_lat.js +3 -3
- package/src/geo/lng_lat_bounds.js +8 -4
- package/src/geo/transform.js +69 -30
- package/src/gl/color_mode.js +2 -2
- package/src/gl/context.js +28 -29
- package/src/gl/cull_face_mode.js +1 -1
- package/src/gl/depth_mode.js +1 -1
- package/src/gl/framebuffer.js +8 -4
- package/src/gl/index_buffer.js +2 -2
- package/src/gl/stencil_mode.js +1 -1
- package/src/gl/value.js +33 -68
- package/src/gl/vertex_buffer.js +2 -2
- package/src/index.js +49 -25
- package/src/render/draw_background.js +14 -9
- package/src/render/draw_circle.js +11 -8
- package/src/render/draw_collision_debug.js +11 -8
- package/src/render/draw_debug.js +16 -14
- package/src/render/draw_fill.js +19 -12
- package/src/render/draw_fill_extrusion.js +12 -9
- package/src/render/draw_heatmap.js +17 -12
- package/src/render/draw_hillshade.js +12 -9
- package/src/render/draw_line.js +30 -16
- package/src/render/draw_raster.js +17 -13
- package/src/render/draw_symbol.js +22 -17
- package/src/render/glyph_atlas.js +9 -5
- package/src/render/glyph_manager.js +1 -1
- package/src/render/image_atlas.js +4 -7
- package/src/render/image_manager.js +6 -9
- package/src/render/line_atlas.js +2 -2
- package/src/render/painter.js +65 -47
- package/src/render/program/background_program.js +6 -13
- package/src/render/program/circle_program.js +4 -6
- package/src/render/program/clipping_mask_program.js +3 -5
- package/src/render/program/collision_program.js +4 -6
- package/src/render/program/debug_program.js +3 -5
- package/src/render/program/fill_extrusion_program.js +8 -14
- package/src/render/program/fill_program.js +10 -21
- package/src/render/program/heatmap_program.js +8 -14
- package/src/render/program/hillshade_program.js +10 -16
- package/src/render/program/line_program.js +11 -22
- package/src/render/program/pattern.js +5 -7
- package/src/render/program/program_uniforms.js +13 -20
- package/src/render/program/raster_program.js +3 -5
- package/src/render/program/symbol_program.js +5 -7
- package/src/render/program.js +5 -6
- package/src/render/texture.js +1 -1
- package/src/render/tile_mask.js +6 -4
- package/src/render/uniform_binding.js +9 -20
- package/src/render/vertex_array_object.js +5 -3
- package/src/shaders/encode_attribute.js +2 -6
- package/src/shaders/index.js +103 -51
- package/src/source/geojson_source.js +11 -7
- package/src/source/geojson_worker_source.js +7 -7
- package/src/source/geojson_wrapper.js +4 -4
- package/src/source/image_source.js +11 -12
- package/src/source/load_tilejson.js +3 -3
- package/src/source/pixels_to_tile_units.js +3 -3
- package/src/source/query_features.js +13 -10
- package/src/source/raster_dem_tile_source.js +12 -10
- package/src/source/raster_tile_source.js +13 -9
- package/src/source/resources/glyphs.js +2 -3
- package/src/source/resources/index.js +2 -4
- package/src/source/rtl_text_plugin.js +8 -8
- package/src/source/source.js +9 -15
- package/src/source/source_cache.js +114 -49
- package/src/source/source_state.js +37 -14
- package/src/source/tile.js +38 -23
- package/src/source/tile_bounds.js +15 -8
- package/src/source/tile_cache.js +2 -2
- package/src/source/tile_id.js +30 -23
- package/src/source/vector_tile_source.js +10 -8
- package/src/source/vector_tile_worker_source.js +4 -4
- package/src/source/worker_tile.js +24 -22
- package/src/style/create_style_layer.js +11 -11
- package/src/style/evaluation_parameters.js +4 -6
- package/src/style/light.js +5 -5
- package/src/style/load_sprite.js +6 -6
- package/src/style/parse_glyph_pbf.js +21 -17
- package/src/style/pauseable_placement.js +3 -4
- package/src/style/properties.js +21 -44
- package/src/style/query_utils.js +4 -10
- package/src/style/style.js +64 -34
- package/src/style/style_layer/background_style_layer.js +3 -4
- package/src/style/style_layer/background_style_layer_properties.js +2 -2
- package/src/style/style_layer/circle_style_layer.js +12 -9
- package/src/style/style_layer/circle_style_layer_properties.js +2 -2
- package/src/style/style_layer/fill_extrusion_style_layer.js +16 -13
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +2 -2
- package/src/style/style_layer/fill_style_layer.js +6 -7
- package/src/style/style_layer/fill_style_layer_properties.js +2 -2
- package/src/style/style_layer/heatmap_style_layer.js +5 -6
- package/src/style/style_layer/heatmap_style_layer_properties.js +2 -2
- package/src/style/style_layer/hillshade_style_layer.js +3 -4
- package/src/style/style_layer/hillshade_style_layer_properties.js +2 -2
- package/src/style/style_layer/line_style_layer.js +10 -11
- package/src/style/style_layer/line_style_layer_properties.js +5 -5
- package/src/style/style_layer/raster_style_layer.js +3 -4
- package/src/style/style_layer/raster_style_layer_properties.js +2 -2
- package/src/style/style_layer/symbol_style_layer.js +7 -8
- package/src/style/style_layer/symbol_style_layer_properties.js +2 -2
- package/src/style/style_layer.js +21 -20
- package/src/style/style_layer_index.js +2 -2
- package/src/style/zoom_history.js +1 -1
- package/src/style-spec/error/parsing_error.js +1 -1
- package/src/style-spec/error/validation_error.js +5 -3
- package/src/style-spec/feature_filter/convert.js +17 -9
- package/src/style-spec/feature_filter/index.js +13 -9
- package/src/style-spec/util/eval_support.js +2 -2
- package/src/style-spec/util/ref_properties.js +1 -1
- package/src/symbol/anchor.js +2 -2
- package/src/symbol/check_max_angle.js +13 -5
- package/src/symbol/clip_line.js +2 -3
- package/src/symbol/collision_feature.js +8 -4
- package/src/symbol/collision_index.js +5 -7
- package/src/symbol/cross_tile_symbol_index.js +5 -5
- package/src/symbol/get_anchors.js +15 -8
- package/src/symbol/grid_index.js +5 -3
- package/src/symbol/mergelines.js +2 -2
- package/src/symbol/opacity_state.js +1 -1
- package/src/symbol/placement.js +25 -20
- package/src/symbol/projection.js +29 -28
- package/src/symbol/quads.js +10 -12
- package/src/symbol/shaping.js +27 -19
- package/src/symbol/symbol_layout.js +17 -21
- package/src/symbol/symbol_size.js +13 -12
- package/src/symbol/transform_text.js +3 -3
- package/src/ui/camera.js +34 -18
- package/src/ui/map.js +54 -34
- package/src/util/async.js +11 -5
- package/src/util/browser.js +1 -1
- package/src/util/callback.js +3 -9
- package/src/util/classify_rings.js +13 -8
- package/src/util/color_ramp.js +3 -3
- package/src/util/config.js +4 -4
- package/src/util/dictionary_coder.js +2 -3
- package/src/util/dom.js +7 -3
- package/src/util/find_pole_of_inaccessibility.js +29 -14
- package/src/util/group_layers.js +1 -1
- package/src/util/image.js +3 -8
- package/src/util/interpolate.js +1 -1
- package/src/util/intersection_tests.js +80 -42
- package/src/util/is_char_in_unicode_block.js +1 -1
- package/src/util/key.js +7 -3
- package/src/util/loader/image.js +1 -1
- package/src/util/object.js +25 -23
- package/src/util/script_detection.js +212 -91
- package/src/util/struct_array.js +8 -40
- package/src/util/task_queue.js +11 -7
- package/src/util/throttle.js +2 -2
- package/src/util/tile_cover.js +8 -5
- package/src/util/token.js +1 -1
- package/src/util/unique_id.js +2 -2
- package/src/util/util.js +21 -29
- package/src/util/vectortile_to_geojson.js +4 -2
- package/src/util/verticalize_punctuation.js +3 -7
- package/src/util/warn.js +4 -4
- package/src/util/web_worker.js +3 -3
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
1
|
+
import { VectorTileFeature } from '@mapwhit/vector-tile';
|
|
2
|
+
import EvaluationParameters from '../../style/evaluation_parameters.js';
|
|
3
|
+
import { LineLayoutArray } from '../array_types.js';
|
|
4
|
+
import EXTENT from '../extent.js';
|
|
5
|
+
import { TriangleIndexArray } from '../index_array_type.js';
|
|
6
|
+
import loadGeometry from '../load_geometry.js';
|
|
7
|
+
import { ProgramConfigurationSet } from '../program_configuration.js';
|
|
8
|
+
import SegmentVector from '../segment.js';
|
|
9
|
+
import layout from './line_attributes.js';
|
|
10
|
+
import { addPatternDependencies, hasPattern } from './pattern_bucket_features.js';
|
|
11
|
+
|
|
12
|
+
const layoutAttributes = layout.members;
|
|
13
|
+
const vectorTileFeatureTypes = VectorTileFeature.types;
|
|
13
14
|
|
|
14
15
|
// NOTE ON EXTRUDE SCALE:
|
|
15
16
|
// scale the extrusion vector so that the normal length is this value.
|
|
@@ -74,7 +75,6 @@ class LineBucket {
|
|
|
74
75
|
this.globalState = options.globalState;
|
|
75
76
|
this.overscaling = options.overscaling;
|
|
76
77
|
this.layers = options.layers;
|
|
77
|
-
this.layerIds = this.layers.map(layer => layer.id);
|
|
78
78
|
this.index = options.index;
|
|
79
79
|
this.features = [];
|
|
80
80
|
this.hasPattern = false;
|
|
@@ -92,8 +92,9 @@ class LineBucket {
|
|
|
92
92
|
for (const { feature, index, sourceLayerIndex } of features) {
|
|
93
93
|
if (
|
|
94
94
|
!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
|
|
95
|
-
)
|
|
95
|
+
) {
|
|
96
96
|
continue;
|
|
97
|
+
}
|
|
97
98
|
|
|
98
99
|
const geometry = loadGeometry(feature);
|
|
99
100
|
|
|
@@ -111,7 +112,15 @@ class LineBucket {
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
if (this.hasPattern) {
|
|
114
|
-
this.features.push(
|
|
115
|
+
this.features.push(
|
|
116
|
+
addPatternDependencies(
|
|
117
|
+
'line',
|
|
118
|
+
this.layers,
|
|
119
|
+
patternFeature,
|
|
120
|
+
{ zoom: this.zoom, globalState: this.globalState },
|
|
121
|
+
options
|
|
122
|
+
)
|
|
123
|
+
);
|
|
115
124
|
} else {
|
|
116
125
|
this.addFeature(patternFeature, geometry, index, {});
|
|
117
126
|
}
|
|
@@ -121,7 +130,9 @@ class LineBucket {
|
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
update(states, vtLayer, imagePositions) {
|
|
124
|
-
if (!this.stateDependentLayers.length)
|
|
133
|
+
if (!this.stateDependentLayers.length) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
125
136
|
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
|
|
126
137
|
imagePositions,
|
|
127
138
|
globalState: this.globalState
|
|
@@ -153,7 +164,9 @@ class LineBucket {
|
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
destroy() {
|
|
156
|
-
if (!this.layoutVertexBuffer)
|
|
167
|
+
if (!this.layoutVertexBuffer) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
157
170
|
this.layoutVertexBuffer.destroy();
|
|
158
171
|
this.indexBuffer.destroy();
|
|
159
172
|
this.programConfigurations.destroy();
|
|
@@ -189,28 +202,32 @@ class LineBucket {
|
|
|
189
202
|
const isPolygon = vectorTileFeatureTypes[feature.type] === 'Polygon';
|
|
190
203
|
|
|
191
204
|
// If the line has duplicate vertices at the ends, adjust start/length to remove them.
|
|
205
|
+
const firstVertex = vertices[0];
|
|
206
|
+
const lastVertex = vertices[vertices.length - 1];
|
|
192
207
|
let len = vertices.length;
|
|
193
|
-
while (len >= 2 &&
|
|
208
|
+
while (len >= 2 && lastVertex.equals(vertices[len - 2])) {
|
|
194
209
|
len--;
|
|
195
210
|
}
|
|
196
211
|
let first = 0;
|
|
197
|
-
while (first < len - 1 &&
|
|
212
|
+
while (first < len - 1 && firstVertex.equals(vertices[first + 1])) {
|
|
198
213
|
first++;
|
|
199
214
|
}
|
|
200
215
|
|
|
201
216
|
// Ignore invalid geometry.
|
|
202
|
-
if (len < (isPolygon ? 3 : 2))
|
|
217
|
+
if (len < (isPolygon ? 3 : 2)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
203
220
|
|
|
204
221
|
if (lineDistances) {
|
|
205
222
|
lineDistances.tileTotal = calculateFullDistance(vertices, first, len);
|
|
206
223
|
}
|
|
207
224
|
|
|
208
|
-
if (join === 'bevel')
|
|
225
|
+
if (join === 'bevel') {
|
|
226
|
+
miterLimit = 1.05;
|
|
227
|
+
}
|
|
209
228
|
|
|
210
229
|
const sharpCornerOffset = SHARP_CORNER_OFFSET * (EXTENT / (512 * this.overscaling));
|
|
211
230
|
|
|
212
|
-
const firstVertex = vertices[first];
|
|
213
|
-
|
|
214
231
|
// we could be more precise, but it would only save a negligible amount of space
|
|
215
232
|
const segment = this.segments.prepareSegment(len * 10, this.layoutVertexArray, this.indexArray);
|
|
216
233
|
|
|
@@ -221,11 +238,8 @@ class LineBucket {
|
|
|
221
238
|
let startOfLine = true;
|
|
222
239
|
let currentVertex;
|
|
223
240
|
let prevVertex;
|
|
224
|
-
let nextVertex;
|
|
225
241
|
let prevNormal;
|
|
226
242
|
let nextNormal;
|
|
227
|
-
let offsetA;
|
|
228
|
-
let offsetB;
|
|
229
243
|
|
|
230
244
|
// the last three vertices added
|
|
231
245
|
this.e1 = this.e2 = this.e3 = -1;
|
|
@@ -236,17 +250,23 @@ class LineBucket {
|
|
|
236
250
|
}
|
|
237
251
|
|
|
238
252
|
for (let i = first; i < len; i++) {
|
|
239
|
-
nextVertex =
|
|
253
|
+
const nextVertex =
|
|
240
254
|
isPolygon && i === len - 1
|
|
241
255
|
? vertices[first + 1]
|
|
242
256
|
: // if the line is closed, we treat the last vertex like the first
|
|
243
257
|
vertices[i + 1]; // just the next vertex
|
|
244
258
|
|
|
245
259
|
// if two consecutive vertices exist, skip the current one
|
|
246
|
-
if (nextVertex && vertices[i].equals(nextVertex))
|
|
260
|
+
if (nextVertex && vertices[i].equals(nextVertex)) {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
247
263
|
|
|
248
|
-
if (nextNormal)
|
|
249
|
-
|
|
264
|
+
if (nextNormal) {
|
|
265
|
+
prevNormal = nextNormal;
|
|
266
|
+
}
|
|
267
|
+
if (currentVertex) {
|
|
268
|
+
prevVertex = currentVertex;
|
|
269
|
+
}
|
|
250
270
|
|
|
251
271
|
currentVertex = vertices[i];
|
|
252
272
|
|
|
@@ -321,156 +341,179 @@ class LineBucket {
|
|
|
321
341
|
if (currentJoin === 'bevel') {
|
|
322
342
|
// The maximum extrude length is 128 / 63 = 2 times the width of the line
|
|
323
343
|
// so if miterLength >= 2 we need to draw a different type of bevel here.
|
|
324
|
-
if (miterLength > 2)
|
|
344
|
+
if (miterLength > 2) {
|
|
345
|
+
currentJoin = 'flipbevel';
|
|
346
|
+
}
|
|
325
347
|
|
|
326
348
|
// If the miterLength is really small and the line bevel wouldn't be visible,
|
|
327
349
|
// just draw a miter join to save a triangle.
|
|
328
|
-
if (miterLength < miterLimit)
|
|
350
|
+
if (miterLength < miterLimit) {
|
|
351
|
+
currentJoin = 'miter';
|
|
352
|
+
}
|
|
329
353
|
}
|
|
330
354
|
|
|
331
355
|
// Calculate how far along the line the currentVertex is
|
|
332
|
-
if (prevVertex)
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
joinNormal._mult(miterLength);
|
|
336
|
-
this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
|
|
337
|
-
} else if (currentJoin === 'flipbevel') {
|
|
338
|
-
// miter is too big, flip the direction to make a beveled join
|
|
339
|
-
|
|
340
|
-
if (miterLength > 100) {
|
|
341
|
-
// Almost parallel lines
|
|
342
|
-
joinNormal = nextNormal.clone().mult(-1);
|
|
343
|
-
} else {
|
|
344
|
-
const direction = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0 ? -1 : 1;
|
|
345
|
-
const bevelLength = (miterLength * prevNormal.add(nextNormal).mag()) / prevNormal.sub(nextNormal).mag();
|
|
346
|
-
joinNormal._perp()._mult(bevelLength * direction);
|
|
347
|
-
}
|
|
348
|
-
this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
|
|
349
|
-
this.addCurrentVertex(currentVertex, this.distance, joinNormal.mult(-1), 0, 0, false, segment, lineDistances);
|
|
350
|
-
} else if (currentJoin === 'bevel' || currentJoin === 'fakeround') {
|
|
351
|
-
const lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
|
|
352
|
-
const offset = -Math.sqrt(miterLength * miterLength - 1);
|
|
353
|
-
if (lineTurnsLeft) {
|
|
354
|
-
offsetB = 0;
|
|
355
|
-
offsetA = offset;
|
|
356
|
-
} else {
|
|
357
|
-
offsetA = 0;
|
|
358
|
-
offsetB = offset;
|
|
359
|
-
}
|
|
356
|
+
if (prevVertex) {
|
|
357
|
+
this.distance += currentVertex.dist(prevVertex);
|
|
358
|
+
}
|
|
360
359
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
360
|
+
switch (currentJoin) {
|
|
361
|
+
case 'miter':
|
|
362
|
+
joinNormal._mult(miterLength);
|
|
363
|
+
this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
|
|
364
|
+
break;
|
|
365
|
+
|
|
366
|
+
case 'flipbevel':
|
|
367
|
+
// miter is too big, flip the direction to make a beveled join
|
|
368
|
+
|
|
369
|
+
if (miterLength > 100) {
|
|
370
|
+
// Almost parallel lines
|
|
371
|
+
joinNormal = nextNormal.clone().mult(-1);
|
|
372
|
+
} else {
|
|
373
|
+
const direction = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0 ? -1 : 1;
|
|
374
|
+
const bevelLength = (miterLength * prevNormal.add(nextNormal).mag()) / prevNormal.sub(nextNormal).mag();
|
|
375
|
+
joinNormal._perp()._mult(bevelLength * direction);
|
|
376
|
+
}
|
|
377
|
+
this.addCurrentVertex(currentVertex, this.distance, joinNormal, 0, 0, false, segment, lineDistances);
|
|
378
|
+
this.addCurrentVertex(currentVertex, this.distance, joinNormal.mult(-1), 0, 0, false, segment, lineDistances);
|
|
379
|
+
break;
|
|
380
|
+
|
|
381
|
+
case 'bevel':
|
|
382
|
+
case 'fakeround': {
|
|
383
|
+
const lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
|
|
384
|
+
const offset = -Math.sqrt(miterLength * miterLength - 1);
|
|
385
|
+
let offsetA;
|
|
386
|
+
let offsetB;
|
|
387
|
+
|
|
388
|
+
if (lineTurnsLeft) {
|
|
389
|
+
offsetB = 0;
|
|
390
|
+
offsetA = offset;
|
|
391
|
+
} else {
|
|
392
|
+
offsetA = 0;
|
|
393
|
+
offsetB = offset;
|
|
394
|
+
}
|
|
374
395
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
// Create a round join by adding multiple pie slices. The join isn't actually round, but
|
|
379
|
-
// it looks like it is at the sizes we render lines at.
|
|
380
|
-
|
|
381
|
-
// Add more triangles for sharper angles.
|
|
382
|
-
// This math is just a good enough approximation. It isn't "correct".
|
|
383
|
-
const n = Math.floor((0.5 - (cosHalfAngle - 0.5)) * 8);
|
|
384
|
-
let approxFractionalJoinNormal;
|
|
385
|
-
|
|
386
|
-
for (let m = 0; m < n; m++) {
|
|
387
|
-
approxFractionalJoinNormal = nextNormal
|
|
388
|
-
.mult((m + 1) / (n + 1))
|
|
389
|
-
._add(prevNormal)
|
|
390
|
-
._unit();
|
|
391
|
-
this.addPieSliceVertex(
|
|
396
|
+
// Close previous segment with a bevel
|
|
397
|
+
if (!startOfLine) {
|
|
398
|
+
this.addCurrentVertex(
|
|
392
399
|
currentVertex,
|
|
393
400
|
this.distance,
|
|
394
|
-
|
|
395
|
-
|
|
401
|
+
prevNormal,
|
|
402
|
+
offsetA,
|
|
403
|
+
offsetB,
|
|
404
|
+
false,
|
|
396
405
|
segment,
|
|
397
406
|
lineDistances
|
|
398
407
|
);
|
|
399
408
|
}
|
|
400
409
|
|
|
401
|
-
|
|
410
|
+
if (currentJoin === 'fakeround') {
|
|
411
|
+
// The join angle is sharp enough that a round join would be visible.
|
|
412
|
+
// Bevel joins fill the gap between segments with a single pie slice triangle.
|
|
413
|
+
// Create a round join by adding multiple pie slices. The join isn't actually round, but
|
|
414
|
+
// it looks like it is at the sizes we render lines at.
|
|
415
|
+
|
|
416
|
+
// Add more triangles for sharper angles.
|
|
417
|
+
// This math is just a good enough approximation. It isn't "correct".
|
|
418
|
+
const n = Math.floor((0.5 - (cosHalfAngle - 0.5)) * 8);
|
|
419
|
+
let approxFractionalJoinNormal;
|
|
420
|
+
|
|
421
|
+
for (let m = 0; m < n; m++) {
|
|
422
|
+
approxFractionalJoinNormal = nextNormal
|
|
423
|
+
.mult((m + 1) / (n + 1))
|
|
424
|
+
._add(prevNormal)
|
|
425
|
+
._unit();
|
|
426
|
+
this.addPieSliceVertex(
|
|
427
|
+
currentVertex,
|
|
428
|
+
this.distance,
|
|
429
|
+
approxFractionalJoinNormal,
|
|
430
|
+
lineTurnsLeft,
|
|
431
|
+
segment,
|
|
432
|
+
lineDistances
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
this.addPieSliceVertex(currentVertex, this.distance, joinNormal, lineTurnsLeft, segment, lineDistances);
|
|
437
|
+
|
|
438
|
+
for (let k = n - 1; k >= 0; k--) {
|
|
439
|
+
approxFractionalJoinNormal = prevNormal
|
|
440
|
+
.mult((k + 1) / (n + 1))
|
|
441
|
+
._add(nextNormal)
|
|
442
|
+
._unit();
|
|
443
|
+
this.addPieSliceVertex(
|
|
444
|
+
currentVertex,
|
|
445
|
+
this.distance,
|
|
446
|
+
approxFractionalJoinNormal,
|
|
447
|
+
lineTurnsLeft,
|
|
448
|
+
segment,
|
|
449
|
+
lineDistances
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
402
453
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
._add(nextNormal)
|
|
407
|
-
._unit();
|
|
408
|
-
this.addPieSliceVertex(
|
|
454
|
+
// Start next segment
|
|
455
|
+
if (nextVertex) {
|
|
456
|
+
this.addCurrentVertex(
|
|
409
457
|
currentVertex,
|
|
410
458
|
this.distance,
|
|
411
|
-
|
|
412
|
-
|
|
459
|
+
nextNormal,
|
|
460
|
+
-offsetA,
|
|
461
|
+
-offsetB,
|
|
462
|
+
false,
|
|
413
463
|
segment,
|
|
414
464
|
lineDistances
|
|
415
465
|
);
|
|
416
466
|
}
|
|
467
|
+
break;
|
|
417
468
|
}
|
|
418
469
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
currentVertex,
|
|
423
|
-
|
|
424
|
-
nextNormal,
|
|
425
|
-
-offsetA,
|
|
426
|
-
-offsetB,
|
|
427
|
-
false,
|
|
428
|
-
segment,
|
|
429
|
-
lineDistances
|
|
430
|
-
);
|
|
431
|
-
}
|
|
432
|
-
} else if (currentJoin === 'butt') {
|
|
433
|
-
if (!startOfLine) {
|
|
434
|
-
// Close previous segment with a butt
|
|
435
|
-
this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
|
|
436
|
-
}
|
|
470
|
+
case 'butt':
|
|
471
|
+
if (!startOfLine) {
|
|
472
|
+
// Close previous segment with a butt
|
|
473
|
+
this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
|
|
474
|
+
}
|
|
437
475
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (!startOfLine) {
|
|
444
|
-
// Close previous segment with a square cap
|
|
445
|
-
this.addCurrentVertex(currentVertex, this.distance, prevNormal, 1, 1, false, segment, lineDistances);
|
|
476
|
+
// Start next segment with a butt
|
|
477
|
+
if (nextVertex) {
|
|
478
|
+
this.addCurrentVertex(currentVertex, this.distance, nextNormal, 0, 0, false, segment, lineDistances);
|
|
479
|
+
}
|
|
480
|
+
break;
|
|
446
481
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
482
|
+
case 'square':
|
|
483
|
+
if (!startOfLine) {
|
|
484
|
+
// Close previous segment with a square cap
|
|
485
|
+
this.addCurrentVertex(currentVertex, this.distance, prevNormal, 1, 1, false, segment, lineDistances);
|
|
450
486
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
} else if (currentJoin === 'round') {
|
|
456
|
-
if (!startOfLine) {
|
|
457
|
-
// Close previous segment with butt
|
|
458
|
-
this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
|
|
487
|
+
// The segment is done. Unset vertices to disconnect segments.
|
|
488
|
+
this.e1 = this.e2 = -1;
|
|
489
|
+
}
|
|
459
490
|
|
|
460
|
-
//
|
|
461
|
-
|
|
491
|
+
// Start next segment
|
|
492
|
+
if (nextVertex) {
|
|
493
|
+
this.addCurrentVertex(currentVertex, this.distance, nextNormal, -1, -1, false, segment, lineDistances);
|
|
494
|
+
}
|
|
495
|
+
break;
|
|
462
496
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
497
|
+
case 'round':
|
|
498
|
+
if (!startOfLine) {
|
|
499
|
+
// Close previous segment with butt
|
|
500
|
+
this.addCurrentVertex(currentVertex, this.distance, prevNormal, 0, 0, false, segment, lineDistances);
|
|
466
501
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
// Add round cap before first segment
|
|
470
|
-
this.addCurrentVertex(currentVertex, this.distance, nextNormal, -1, -1, true, segment, lineDistances);
|
|
502
|
+
// Add round cap or linejoin at end of segment
|
|
503
|
+
this.addCurrentVertex(currentVertex, this.distance, prevNormal, 1, 1, true, segment, lineDistances);
|
|
471
504
|
|
|
472
|
-
|
|
473
|
-
|
|
505
|
+
// The segment is done. Unset vertices to disconnect segments.
|
|
506
|
+
this.e1 = this.e2 = -1;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// Start next segment with a butt
|
|
510
|
+
if (nextVertex) {
|
|
511
|
+
// Add round cap before first segment
|
|
512
|
+
this.addCurrentVertex(currentVertex, this.distance, nextNormal, -1, -1, true, segment, lineDistances);
|
|
513
|
+
|
|
514
|
+
this.addCurrentVertex(currentVertex, this.distance, nextNormal, 0, 0, false, segment, lineDistances);
|
|
515
|
+
}
|
|
516
|
+
break;
|
|
474
517
|
}
|
|
475
518
|
|
|
476
519
|
if (isSharpCorner && i < len - 1) {
|
|
@@ -527,7 +570,9 @@ class LineBucket {
|
|
|
527
570
|
}
|
|
528
571
|
|
|
529
572
|
extrude = normal.clone();
|
|
530
|
-
if (endLeft)
|
|
573
|
+
if (endLeft) {
|
|
574
|
+
extrude._sub(normal.perp()._mult(endLeft));
|
|
575
|
+
}
|
|
531
576
|
addLineVertex(layoutVertexArray, currentVertex, extrude, round, false, endLeft, distance);
|
|
532
577
|
this.e3 = segment.vertexLength++;
|
|
533
578
|
if (this.e1 >= 0 && this.e2 >= 0) {
|
|
@@ -538,7 +583,9 @@ class LineBucket {
|
|
|
538
583
|
this.e2 = this.e3;
|
|
539
584
|
|
|
540
585
|
extrude = normal.mult(-1);
|
|
541
|
-
if (endRight)
|
|
586
|
+
if (endRight) {
|
|
587
|
+
extrude._sub(normal.perp()._mult(endRight));
|
|
588
|
+
}
|
|
542
589
|
addLineVertex(layoutVertexArray, currentVertex, extrude, round, true, -endRight, distance);
|
|
543
590
|
this.e3 = segment.vertexLength++;
|
|
544
591
|
if (this.e1 >= 0 && this.e2 >= 0) {
|
|
@@ -573,7 +620,9 @@ class LineBucket {
|
|
|
573
620
|
const layoutVertexArray = this.layoutVertexArray;
|
|
574
621
|
const indexArray = this.indexArray;
|
|
575
622
|
|
|
576
|
-
if (distancesForScaling)
|
|
623
|
+
if (distancesForScaling) {
|
|
624
|
+
distance = scaleDistance(distance, distancesForScaling);
|
|
625
|
+
}
|
|
577
626
|
|
|
578
627
|
addLineVertex(layoutVertexArray, currentVertex, extrude, false, lineTurnsLeft, 0, distance);
|
|
579
628
|
this.e3 = segment.vertexLength++;
|
|
@@ -618,15 +667,14 @@ function scaleDistance(tileDistance, stats) {
|
|
|
618
667
|
* @private
|
|
619
668
|
*/
|
|
620
669
|
function calculateFullDistance(vertices, first, len) {
|
|
621
|
-
let currentVertex;
|
|
622
|
-
let nextVertex;
|
|
623
670
|
let total = 0;
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
total +=
|
|
671
|
+
let prev = vertices[first];
|
|
672
|
+
for (let i = first + 1; i < len; i++) {
|
|
673
|
+
const next = vertices[i];
|
|
674
|
+
total += prev.dist(next);
|
|
675
|
+
prev = next;
|
|
628
676
|
}
|
|
629
677
|
return total;
|
|
630
678
|
}
|
|
631
679
|
|
|
632
|
-
|
|
680
|
+
export default LineBucket;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { createLayout } from '../../util/struct_array.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default createLayout([
|
|
4
4
|
// [tl.x, tl.y, br.x, br.y]
|
|
5
5
|
{ name: 'a_pattern_from', components: 4, type: 'Uint16' },
|
|
6
6
|
{ name: 'a_pattern_to', components: 4, type: 'Uint16' }
|
|
7
7
|
]);
|
|
8
|
-
|
|
9
|
-
module.exports = layout;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function hasPattern(type, layers, options) {
|
|
1
|
+
export function hasPattern(type, layers, options) {
|
|
2
2
|
const patterns = options.patternDependencies;
|
|
3
3
|
let hasPattern = false;
|
|
4
4
|
|
|
@@ -19,16 +19,16 @@ function hasPattern(type, layers, options) {
|
|
|
19
19
|
return hasPattern;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
function addPatternDependencies(type, layers, patternFeature, zoom, options) {
|
|
22
|
+
export function addPatternDependencies(type, layers, patternFeature, { zoom, globalState }, options) {
|
|
23
23
|
const patterns = options.patternDependencies;
|
|
24
24
|
for (const layer of layers) {
|
|
25
25
|
const patternProperty = layer._paint.get(`${type}-pattern`);
|
|
26
26
|
|
|
27
27
|
const patternPropertyValue = patternProperty.value;
|
|
28
28
|
if (patternPropertyValue.kind !== 'constant') {
|
|
29
|
-
const min = patternPropertyValue.evaluate({ zoom: zoom - 1 }, patternFeature, {});
|
|
30
|
-
const mid = patternPropertyValue.evaluate({ zoom: zoom }, patternFeature, {});
|
|
31
|
-
const max = patternPropertyValue.evaluate({ zoom: zoom + 1 }, patternFeature, {});
|
|
29
|
+
const min = patternPropertyValue.evaluate({ zoom: zoom - 1, globalState }, patternFeature, {});
|
|
30
|
+
const mid = patternPropertyValue.evaluate({ zoom: zoom, globalState }, patternFeature, {});
|
|
31
|
+
const max = patternPropertyValue.evaluate({ zoom: zoom + 1, globalState }, patternFeature, {});
|
|
32
32
|
// add to patternDependencies
|
|
33
33
|
patterns[min] = true;
|
|
34
34
|
patterns[mid] = true;
|
|
@@ -40,5 +40,3 @@ function addPatternDependencies(type, layers, patternFeature, zoom, options) {
|
|
|
40
40
|
}
|
|
41
41
|
return patternFeature;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
module.exports = { hasPattern, addPatternDependencies };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { createLayout } from '../../util/struct_array.js';
|
|
2
2
|
|
|
3
|
-
const symbolLayoutAttributes = createLayout([
|
|
3
|
+
export const symbolLayoutAttributes = createLayout([
|
|
4
4
|
{ name: 'a_pos_offset', components: 4, type: 'Int16' },
|
|
5
5
|
{ name: 'a_data', components: 4, type: 'Uint16' }
|
|
6
6
|
]);
|
|
7
7
|
|
|
8
|
-
const dynamicLayoutAttributes = createLayout([{ name: 'a_projected_pos', components: 3, type: 'Float32' }], 4);
|
|
8
|
+
export const dynamicLayoutAttributes = createLayout([{ name: 'a_projected_pos', components: 3, type: 'Float32' }], 4);
|
|
9
9
|
|
|
10
|
-
const placementOpacityAttributes = createLayout([{ name: 'a_fade_opacity', components: 1, type: 'Uint32' }], 4);
|
|
10
|
+
export const placementOpacityAttributes = createLayout([{ name: 'a_fade_opacity', components: 1, type: 'Uint32' }], 4);
|
|
11
11
|
|
|
12
|
-
const collisionVertexAttributes = createLayout([{ name: 'a_placed', components: 2, type: 'Uint8' }], 4);
|
|
12
|
+
export const collisionVertexAttributes = createLayout([{ name: 'a_placed', components: 2, type: 'Uint8' }], 4);
|
|
13
13
|
|
|
14
|
-
const collisionBox = createLayout([
|
|
14
|
+
export const collisionBox = createLayout([
|
|
15
15
|
// the box is centered around the anchor point
|
|
16
16
|
{ type: 'Int16', name: 'anchorPointX' },
|
|
17
17
|
{ type: 'Int16', name: 'anchorPointY' },
|
|
@@ -36,7 +36,7 @@ const collisionBox = createLayout([
|
|
|
36
36
|
{ type: 'Int16', name: 'signedDistanceFromAnchor' }
|
|
37
37
|
]);
|
|
38
38
|
|
|
39
|
-
const collisionBoxLayout = createLayout(
|
|
39
|
+
export const collisionBoxLayout = createLayout(
|
|
40
40
|
[
|
|
41
41
|
// used to render collision boxes for debugging purposes
|
|
42
42
|
{ name: 'a_pos', components: 2, type: 'Int16' },
|
|
@@ -46,7 +46,7 @@ const collisionBoxLayout = createLayout(
|
|
|
46
46
|
4
|
|
47
47
|
);
|
|
48
48
|
|
|
49
|
-
const collisionCircleLayout = createLayout(
|
|
49
|
+
export const collisionCircleLayout = createLayout(
|
|
50
50
|
[
|
|
51
51
|
// used to render collision circles for debugging purposes
|
|
52
52
|
{ name: 'a_pos', components: 2, type: 'Int16' },
|
|
@@ -56,7 +56,7 @@ const collisionCircleLayout = createLayout(
|
|
|
56
56
|
4
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
const placement = createLayout([
|
|
59
|
+
export const placement = createLayout([
|
|
60
60
|
{ type: 'Int16', name: 'anchorX' },
|
|
61
61
|
{ type: 'Int16', name: 'anchorY' },
|
|
62
62
|
{ type: 'Uint16', name: 'glyphStartIndex' },
|
|
@@ -73,7 +73,7 @@ const placement = createLayout([
|
|
|
73
73
|
{ type: 'Uint8', name: 'hidden' }
|
|
74
74
|
]);
|
|
75
75
|
|
|
76
|
-
const symbolInstance = createLayout([
|
|
76
|
+
export const symbolInstance = createLayout([
|
|
77
77
|
{ type: 'Int16', name: 'anchorX' },
|
|
78
78
|
{ type: 'Int16', name: 'anchorY' },
|
|
79
79
|
{ type: 'Int16', name: 'horizontalPlacedTextSymbolIndex' },
|
|
@@ -90,24 +90,10 @@ const symbolInstance = createLayout([
|
|
|
90
90
|
{ type: 'Uint32', name: 'crossTileID' }
|
|
91
91
|
]);
|
|
92
92
|
|
|
93
|
-
const glyphOffset = createLayout([{ type: 'Float32', name: 'offsetX' }]);
|
|
93
|
+
export const glyphOffset = createLayout([{ type: 'Float32', name: 'offsetX' }]);
|
|
94
94
|
|
|
95
|
-
const lineVertex = createLayout([
|
|
95
|
+
export const lineVertex = createLayout([
|
|
96
96
|
{ type: 'Int16', name: 'x' },
|
|
97
97
|
{ type: 'Int16', name: 'y' },
|
|
98
98
|
{ type: 'Int16', name: 'tileUnitDistanceFromAnchor' }
|
|
99
99
|
]);
|
|
100
|
-
|
|
101
|
-
module.exports = {
|
|
102
|
-
symbolLayoutAttributes,
|
|
103
|
-
dynamicLayoutAttributes,
|
|
104
|
-
placementOpacityAttributes,
|
|
105
|
-
collisionVertexAttributes,
|
|
106
|
-
collisionBox,
|
|
107
|
-
collisionBoxLayout,
|
|
108
|
-
collisionCircleLayout,
|
|
109
|
-
placement,
|
|
110
|
-
symbolInstance,
|
|
111
|
-
glyphOffset,
|
|
112
|
-
lineVertex
|
|
113
|
-
};
|