@mapwhit/tilerenderer 0.52.1 → 1.1.0
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 +7 -0
- package/build/min/package.json +2 -1
- package/build/min/src/shaders/_prelude.fragment.glsl.js +2 -2
- package/build/min/src/shaders/_prelude.vertex.glsl.js +2 -2
- package/build/min/src/shaders/background.fragment.glsl.js +2 -2
- package/build/min/src/shaders/background.vertex.glsl.js +1 -1
- package/build/min/src/shaders/background_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/circle.fragment.glsl.js +2 -2
- package/build/min/src/shaders/circle.vertex.glsl.js +2 -2
- 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 +2 -2
- package/build/min/src/shaders/fill.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/heatmap.fragment.glsl.js +2 -2
- package/build/min/src/shaders/heatmap.vertex.glsl.js +2 -2
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +2 -2
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade.fragment.glsl.js +2 -2
- package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +2 -2
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line.vertex.glsl.js +2 -2
- package/build/min/src/shaders/line_gradient.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line_gradient.vertex.glsl.js +2 -2
- package/build/min/src/shaders/line_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/line_sdf.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line_sdf.vertex.glsl.js +2 -2
- package/build/min/src/shaders/raster.fragment.glsl.js +2 -2
- package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
- package/build/min/src/shaders/symbol_icon.fragment.glsl.js +2 -2
- package/build/min/src/shaders/symbol_icon.vertex.glsl.js +2 -2
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +2 -2
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +2 -2
- package/package.json +5 -4
- package/src/data/array_types.js +55 -117
- package/src/data/bucket/circle_attributes.js +2 -4
- package/src/data/bucket/circle_bucket.js +19 -16
- package/src/data/bucket/fill_attributes.js +2 -4
- package/src/data/bucket/fill_bucket.js +38 -27
- package/src/data/bucket/fill_extrusion_attributes.js +2 -4
- package/src/data/bucket/fill_extrusion_bucket.js +56 -37
- package/src/data/bucket/heatmap_bucket.js +2 -11
- package/src/data/bucket/line_attributes.js +2 -4
- package/src/data/bucket/line_bucket.js +208 -163
- package/src/data/bucket/pattern_attributes.js +2 -4
- package/src/data/bucket/pattern_bucket_features.js +7 -9
- package/src/data/bucket/symbol_attributes.js +12 -26
- package/src/data/bucket/symbol_bucket.js +174 -323
- package/src/data/bucket/symbol_buffers.js +62 -0
- package/src/data/bucket/symbol_collision_buffers.js +33 -0
- package/src/data/bucket.js +26 -25
- package/src/data/dem_data.js +11 -10
- package/src/data/extent.js +1 -1
- package/src/data/feature_index.js +38 -28
- 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 +47 -38
- package/src/data/raster_bounds_attributes.js +2 -2
- package/src/data/segment.js +4 -7
- 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 +17 -12
- package/src/render/draw_circle.js +15 -12
- package/src/render/draw_collision_debug.js +11 -8
- package/src/render/draw_debug.js +16 -14
- package/src/render/draw_fill.js +27 -20
- package/src/render/draw_fill_extrusion.js +20 -17
- package/src/render/draw_heatmap.js +21 -16
- package/src/render/draw_hillshade.js +12 -9
- package/src/render/draw_line.js +36 -22
- package/src/render/draw_raster.js +22 -18
- package/src/render/draw_symbol.js +38 -33
- package/src/render/glyph_atlas.js +9 -8
- package/src/render/glyph_manager.js +2 -3
- package/src/render/image_atlas.js +4 -11
- package/src/render/image_manager.js +39 -28
- package/src/render/line_atlas.js +2 -2
- package/src/render/painter.js +78 -61
- package/src/render/program/background_program.js +6 -13
- package/src/render/program/circle_program.js +8 -10
- 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 +9 -15
- package/src/render/program/fill_program.js +10 -21
- package/src/render/program/heatmap_program.js +9 -15
- package/src/render/program/hillshade_program.js +16 -22
- package/src/render/program/line_program.js +14 -25
- package/src/render/program/pattern.js +5 -7
- package/src/render/program/program_uniforms.js +13 -20
- package/src/render/program/raster_program.js +9 -11
- 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 +25 -30
- package/src/source/geojson_worker_source.js +46 -74
- package/src/source/geojson_wrapper.js +13 -5
- package/src/source/image_source.js +17 -28
- package/src/source/load_tilejson.js +3 -3
- package/src/source/pixels_to_tile_units.js +3 -3
- package/src/source/query_features.js +17 -15
- package/src/source/raster_dem_tile_source.js +54 -71
- package/src/source/raster_tile_source.js +14 -15
- package/src/source/resources/glyphs.js +4 -5
- package/src/source/resources/index.js +4 -12
- package/src/source/rtl_text_plugin.js +62 -35
- package/src/source/source.js +14 -22
- package/src/source/source_cache.js +221 -179
- package/src/source/source_state.js +125 -13
- package/src/source/tile.js +67 -66
- package/src/source/tile_bounds.js +36 -29
- package/src/source/tile_cache.js +2 -2
- package/src/source/tile_id.js +30 -26
- package/src/source/vector_tile_source.js +23 -21
- package/src/source/vector_tile_worker_source.js +22 -26
- package/src/source/worker_tile.js +139 -134
- 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 +7 -9
- package/src/style/properties.js +21 -51
- package/src/style/query_utils.js +7 -13
- package/src/style/style.js +314 -221
- 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 +25 -20
- package/src/style/style_layer/circle_style_layer_properties.js +2 -2
- package/src/style/style_layer/fill_extrusion_style_layer.js +55 -37
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +2 -2
- package/src/style/style_layer/fill_style_layer.js +11 -12
- package/src/style/style_layer/fill_style_layer_properties.js +2 -2
- package/src/style/style_layer/heatmap_style_layer.js +6 -7
- package/src/style/style_layer/heatmap_style_layer_properties.js +2 -2
- package/src/style/style_layer/hillshade_style_layer.js +4 -5
- package/src/style/style_layer/hillshade_style_layer_properties.js +2 -2
- package/src/style/style_layer/line_style_layer.js +33 -30
- 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 +20 -21
- package/src/style/style_layer/symbol_style_layer_properties.js +2 -2
- package/src/style/style_layer.js +66 -47
- package/src/style/style_layer_index.js +17 -42
- 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 -6
- 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 +7 -10
- 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 -5
- package/src/symbol/placement.js +28 -23
- package/src/symbol/projection.js +29 -28
- package/src/symbol/quads.js +14 -16
- package/src/symbol/shaping.js +27 -19
- package/src/symbol/symbol_layout.js +24 -28
- package/src/symbol/symbol_size.js +13 -12
- package/src/symbol/transform_text.js +4 -4
- package/src/ui/camera.js +34 -18
- package/src/ui/map.js +102 -44
- 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 +41 -0
- package/src/util/image.js +3 -13
- 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 +25 -0
- package/src/util/loader/image.js +1 -1
- package/src/util/object.js +33 -76
- 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
- package/src/worker.js +1 -4
- package/src/source/resources/images.js +0 -68
- package/src/source/worker.js +0 -110
- package/src/source/worker_source.js +0 -14
- package/src/style-spec/deref.js +0 -51
- package/src/style-spec/group_by_layout.js +0 -46
- package/src/util/actor.js +0 -108
- package/src/util/dispatcher.js +0 -65
- package/src/util/global_worker_pool.js +0 -15
- package/src/util/transfer_registry.js +0 -168
- package/src/util/web_worker_transfer.js +0 -43
- package/src/util/worker_pool.js +0 -41
package/src/util/util.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const Coordinate = require('../geo/coordinate');
|
|
1
|
+
import UnitBezier from '@mapbox/unitbezier';
|
|
2
|
+
import Coordinate from '../geo/coordinate.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* @module util
|
|
@@ -14,9 +13,13 @@ const Coordinate = require('../geo/coordinate');
|
|
|
14
13
|
*
|
|
15
14
|
* @private
|
|
16
15
|
*/
|
|
17
|
-
function easeCubicInOut(t) {
|
|
18
|
-
if (t <= 0)
|
|
19
|
-
|
|
16
|
+
export function easeCubicInOut(t) {
|
|
17
|
+
if (t <= 0) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
if (t >= 1) {
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
20
23
|
const t2 = t * t;
|
|
21
24
|
const t3 = t2 * t;
|
|
22
25
|
return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
|
|
@@ -32,7 +35,7 @@ function easeCubicInOut(t) {
|
|
|
32
35
|
* @param p2y control point 2 y coordinate
|
|
33
36
|
* @private
|
|
34
37
|
*/
|
|
35
|
-
function bezier(p1x, p1y, p2x, p2y) {
|
|
38
|
+
export function bezier(p1x, p1y, p2x, p2y) {
|
|
36
39
|
const bezier = new UnitBezier(p1x, p1y, p2x, p2y);
|
|
37
40
|
return function (t) {
|
|
38
41
|
return bezier.solve(t);
|
|
@@ -45,7 +48,7 @@ function bezier(p1x, p1y, p2x, p2y) {
|
|
|
45
48
|
*
|
|
46
49
|
* @private
|
|
47
50
|
*/
|
|
48
|
-
const ease = bezier(0.25, 0.1, 0.25, 1);
|
|
51
|
+
export const ease = bezier(0.25, 0.1, 0.25, 1);
|
|
49
52
|
|
|
50
53
|
/**
|
|
51
54
|
* constrain n to the given range via min + max
|
|
@@ -56,7 +59,7 @@ const ease = bezier(0.25, 0.1, 0.25, 1);
|
|
|
56
59
|
* @returns the clamped value
|
|
57
60
|
* @private
|
|
58
61
|
*/
|
|
59
|
-
function clamp(n, min, max) {
|
|
62
|
+
export function clamp(n, min, max) {
|
|
60
63
|
return Math.min(max, Math.max(min, n));
|
|
61
64
|
}
|
|
62
65
|
|
|
@@ -69,7 +72,7 @@ function clamp(n, min, max) {
|
|
|
69
72
|
* @returns constrained number
|
|
70
73
|
* @private
|
|
71
74
|
*/
|
|
72
|
-
function wrap(n, min, max) {
|
|
75
|
+
export function wrap(n, min, max) {
|
|
73
76
|
const d = max - min;
|
|
74
77
|
const w = ((((n - min) % d) + d) % d) + min;
|
|
75
78
|
return w === min ? max : w;
|
|
@@ -81,7 +84,7 @@ function wrap(n, min, max) {
|
|
|
81
84
|
* @returns centerpoint
|
|
82
85
|
* @private
|
|
83
86
|
*/
|
|
84
|
-
function getCoordinatesCenter(coords) {
|
|
87
|
+
export function getCoordinatesCenter(coords) {
|
|
85
88
|
let minX = Number.POSITIVE_INFINITY;
|
|
86
89
|
let minY = Number.POSITIVE_INFINITY;
|
|
87
90
|
let maxX = Number.NEGATIVE_INFINITY;
|
|
@@ -108,7 +111,7 @@ function getCoordinatesCenter(coords) {
|
|
|
108
111
|
* @returns true for a counter clockwise set of points
|
|
109
112
|
*/
|
|
110
113
|
// http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
|
|
111
|
-
function isCounterClockwise(a, b, c) {
|
|
114
|
+
export function isCounterClockwise(a, b, c) {
|
|
112
115
|
return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
|
|
113
116
|
}
|
|
114
117
|
|
|
@@ -120,7 +123,7 @@ function isCounterClockwise(a, b, c) {
|
|
|
120
123
|
* @private
|
|
121
124
|
* @param ring Exterior or interior ring
|
|
122
125
|
*/
|
|
123
|
-
function calculateSignedArea(ring) {
|
|
126
|
+
export function calculateSignedArea(ring) {
|
|
124
127
|
let sum = 0;
|
|
125
128
|
const len = ring.length;
|
|
126
129
|
let p2 = ring[len - 1]; // last point
|
|
@@ -138,10 +141,12 @@ function calculateSignedArea(ring) {
|
|
|
138
141
|
* @param points array of points
|
|
139
142
|
* @return true if the points are a closed polygon
|
|
140
143
|
*/
|
|
141
|
-
function isClosedPolygon(points) {
|
|
144
|
+
export function isClosedPolygon(points) {
|
|
142
145
|
// If it is 2 points that are the same then it is a point
|
|
143
146
|
// If it is 3 points with start and end the same then it is a line
|
|
144
|
-
if (points.length < 4)
|
|
147
|
+
if (points.length < 4) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
145
150
|
|
|
146
151
|
const p1 = points[0];
|
|
147
152
|
const p2 = points[points.length - 1];
|
|
@@ -162,7 +167,7 @@ function isClosedPolygon(points) {
|
|
|
162
167
|
* @return cartesian coordinates in [x, y, z]
|
|
163
168
|
*/
|
|
164
169
|
|
|
165
|
-
function sphericalToCartesian([r, azimuthal, polar]) {
|
|
170
|
+
export function sphericalToCartesian([r, azimuthal, polar]) {
|
|
166
171
|
// We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2):
|
|
167
172
|
// correct for that here
|
|
168
173
|
azimuthal += 90;
|
|
@@ -177,16 +182,3 @@ function sphericalToCartesian([r, azimuthal, polar]) {
|
|
|
177
182
|
z: r * Math.cos(polar)
|
|
178
183
|
};
|
|
179
184
|
}
|
|
180
|
-
|
|
181
|
-
module.exports = {
|
|
182
|
-
easeCubicInOut,
|
|
183
|
-
bezier,
|
|
184
|
-
ease,
|
|
185
|
-
clamp,
|
|
186
|
-
wrap,
|
|
187
|
-
getCoordinatesCenter,
|
|
188
|
-
isCounterClockwise,
|
|
189
|
-
calculateSignedArea,
|
|
190
|
-
isClosedPolygon,
|
|
191
|
-
sphericalToCartesian
|
|
192
|
-
};
|
|
@@ -34,11 +34,13 @@ class Feature {
|
|
|
34
34
|
geometry: this.geometry
|
|
35
35
|
};
|
|
36
36
|
for (const i in this) {
|
|
37
|
-
if (i === '_geometry' || i === '_vectorTileFeature')
|
|
37
|
+
if (i === '_geometry' || i === '_vectorTileFeature') {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
38
40
|
json[i] = this[i];
|
|
39
41
|
}
|
|
40
42
|
return json;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
export default Feature;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { charHasRotatedVerticalOrientation } from './script_detection.js';
|
|
2
2
|
|
|
3
|
-
const verticalizedCharacterMap = {
|
|
3
|
+
export const verticalizedCharacterMap = {
|
|
4
4
|
'!': '︕',
|
|
5
5
|
'#': '#',
|
|
6
6
|
$: '$',
|
|
@@ -86,7 +86,7 @@ const verticalizedCharacterMap = {
|
|
|
86
86
|
'」': '﹂'
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
function verticalizePunctuation(input) {
|
|
89
|
+
export default function verticalizePunctuation(input) {
|
|
90
90
|
let output = '';
|
|
91
91
|
|
|
92
92
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -106,7 +106,3 @@ function verticalizePunctuation(input) {
|
|
|
106
106
|
|
|
107
107
|
return output;
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
verticalizePunctuation.verticalizedCharacterMap = verticalizedCharacterMap;
|
|
111
|
-
|
|
112
|
-
module.exports = verticalizePunctuation;
|
package/src/util/warn.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
const warnOnceHistory = {};
|
|
8
8
|
|
|
9
|
-
function
|
|
9
|
+
function warnOnce(message) {
|
|
10
10
|
if (!warnOnceHistory[message]) {
|
|
11
11
|
console.warn(message);
|
|
12
12
|
warnOnceHistory[message] = true;
|
|
@@ -15,7 +15,7 @@ function once(message) {
|
|
|
15
15
|
|
|
16
16
|
function noop() {}
|
|
17
17
|
|
|
18
|
+
const once = typeof console !== 'undefined' ? warnOnce : noop;
|
|
19
|
+
|
|
18
20
|
// console isn't defined in some WebWorkers, see #2558
|
|
19
|
-
|
|
20
|
-
once: typeof console !== 'undefined' ? once : noop
|
|
21
|
-
};
|
|
21
|
+
export default { once };
|
package/src/util/web_worker.js
CHANGED
package/src/worker.js
CHANGED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
module.exports = images;
|
|
2
|
-
|
|
3
|
-
function images({ actor, mapId }) {
|
|
4
|
-
const cache = new Map(); // id -> image
|
|
5
|
-
const inProgress = new Map(); // id -> promise
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
getImages
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
async function getImages({ icons }) {
|
|
12
|
-
const missing = new Set();
|
|
13
|
-
const result = {};
|
|
14
|
-
for (const id of icons) {
|
|
15
|
-
if (cache.has(id)) {
|
|
16
|
-
const image = cache.get(id);
|
|
17
|
-
if (image) {
|
|
18
|
-
result[id] = image;
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
missing.add(id);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (missing.size === 0) {
|
|
25
|
-
// All images are already in the cache
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
const active = new Set();
|
|
29
|
-
const needed = [...missing];
|
|
30
|
-
// Check if any of the missing images are already being fetched
|
|
31
|
-
for (const id of missing) {
|
|
32
|
-
if (inProgress.has(id)) {
|
|
33
|
-
active.add(inProgress.get(id));
|
|
34
|
-
missing.delete(id);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (missing.size > 0) {
|
|
38
|
-
// Fetch the remaining images
|
|
39
|
-
await fetchMissing([...missing]);
|
|
40
|
-
}
|
|
41
|
-
if (active.size > 0) {
|
|
42
|
-
await Promise.all(active);
|
|
43
|
-
}
|
|
44
|
-
for (const id of needed) {
|
|
45
|
-
const image = cache.get(id);
|
|
46
|
-
if (image) {
|
|
47
|
-
result[id] = image;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function fetchMissing(icons) {
|
|
54
|
-
const promise = actor.send('getImages', { icons }, mapId);
|
|
55
|
-
for (const id of icons) {
|
|
56
|
-
inProgress.set(id, promise);
|
|
57
|
-
}
|
|
58
|
-
const result = await promise;
|
|
59
|
-
// Add the fetched images to the cache
|
|
60
|
-
for (const id of icons) {
|
|
61
|
-
cache.set(id, result[id]);
|
|
62
|
-
}
|
|
63
|
-
// Remove the fetched images from the inProgress set
|
|
64
|
-
for (const id of icons) {
|
|
65
|
-
inProgress.delete(id);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/source/worker.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
require('../util/polyfill');
|
|
2
|
-
|
|
3
|
-
const Actor = require('../util/actor');
|
|
4
|
-
|
|
5
|
-
const StyleLayerIndex = require('../style/style_layer_index');
|
|
6
|
-
const VectorTileWorkerSource = require('./vector_tile_worker_source');
|
|
7
|
-
const GeoJSONWorkerSource = require('./geojson_worker_source');
|
|
8
|
-
const assert = require('assert');
|
|
9
|
-
const { plugin: globalRTLTextPlugin } = require('./rtl_text_plugin');
|
|
10
|
-
const DEMData = require('../data/dem_data');
|
|
11
|
-
const { resources } = require('./resources');
|
|
12
|
-
|
|
13
|
-
class Worker {
|
|
14
|
-
#resources = {};
|
|
15
|
-
|
|
16
|
-
constructor(self) {
|
|
17
|
-
this.self = self;
|
|
18
|
-
this.actor = new Actor(self, this);
|
|
19
|
-
|
|
20
|
-
this.actors = {};
|
|
21
|
-
this.layerIndexes = {};
|
|
22
|
-
|
|
23
|
-
this.workerSourceTypes = {
|
|
24
|
-
vector: VectorTileWorkerSource,
|
|
25
|
-
geojson: GeoJSONWorkerSource
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// [mapId][sourceType][sourceName] => worker source instance
|
|
29
|
-
this.workerSources = {};
|
|
30
|
-
|
|
31
|
-
this.self.registerWorkerSource = (name, WorkerSource) => {
|
|
32
|
-
if (this.workerSourceTypes[name]) {
|
|
33
|
-
throw new Error(`Worker source with name "${name}" already registered.`);
|
|
34
|
-
}
|
|
35
|
-
this.workerSourceTypes[name] = WorkerSource;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
this.self.registerRTLTextPlugin = rtlTextPlugin => {
|
|
39
|
-
if (globalRTLTextPlugin.isLoaded()) {
|
|
40
|
-
throw new Error('RTL text plugin already registered.');
|
|
41
|
-
}
|
|
42
|
-
globalRTLTextPlugin['applyArabicShaping'] = rtlTextPlugin.applyArabicShaping;
|
|
43
|
-
globalRTLTextPlugin['processBidirectionalText'] = rtlTextPlugin.processBidirectionalText;
|
|
44
|
-
globalRTLTextPlugin['processStyledBidirectionalText'] = rtlTextPlugin.processStyledBidirectionalText;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
setLayers(mapId, layers) {
|
|
49
|
-
this.getLayerIndex(mapId).replace(layers);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
updateLayers(mapId, params) {
|
|
53
|
-
this.getLayerIndex(mapId).update(params.layers, params.removedIds);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
loadTile(mapId, params) {
|
|
57
|
-
assert(params.type);
|
|
58
|
-
return this.getWorkerSource(mapId, params.type, params.source).loadTile(params);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
loadDEMTile(mapId, params) {
|
|
62
|
-
const { uid, rawImageData, encoding } = params;
|
|
63
|
-
return new DEMData(uid, rawImageData, encoding);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
removeSource(mapId, params) {
|
|
67
|
-
const { type, source } = params;
|
|
68
|
-
assert(type);
|
|
69
|
-
assert(source);
|
|
70
|
-
|
|
71
|
-
const worker = this.workerSources?.[mapId]?.[type]?.[source];
|
|
72
|
-
if (worker) {
|
|
73
|
-
delete this.workerSources[mapId][type][source];
|
|
74
|
-
worker.removeSource?.(params);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
loadRTLTextPlugin(map, pluginURL) {
|
|
79
|
-
if (!globalRTLTextPlugin.isLoaded()) {
|
|
80
|
-
this.self.importScripts(pluginURL);
|
|
81
|
-
if (!globalRTLTextPlugin.isLoaded()) {
|
|
82
|
-
throw new Error(`RTL Text Plugin failed to import scripts from ${pluginURL}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getLayerIndex(mapId) {
|
|
88
|
-
return (this.layerIndexes[mapId] ??= new StyleLayerIndex());
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
getResources(mapId) {
|
|
92
|
-
return (this.#resources[mapId] ??= resources(this.actor, mapId));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getWorkerSource(mapId, type, source) {
|
|
96
|
-
this.workerSources[mapId] ??= {};
|
|
97
|
-
this.workerSources[mapId][type] ??= {};
|
|
98
|
-
|
|
99
|
-
return (this.workerSources[mapId][type][source] ??= this.createWorkerSource(type, mapId));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
createWorkerSource(type, mapId) {
|
|
103
|
-
const WorkerSource = this.workerSourceTypes[type];
|
|
104
|
-
return new WorkerSource(this.getResources(mapId), this.getLayerIndex(mapId));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
module.exports = function createWorker(self) {
|
|
109
|
-
return new Worker(self);
|
|
110
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* May be implemented by custom source types to provide code that can be run on
|
|
3
|
-
* the WebWorkers. In addition to providing a custom
|
|
4
|
-
* {@link WorkerSource#loadTile}, any other methods attached to a `WorkerSource`
|
|
5
|
-
* implementation may also be targeted by the {@link Source} via
|
|
6
|
-
* `dispatcher.send('source-type.methodname', params, callback)`.
|
|
7
|
-
*
|
|
8
|
-
* @see {@link Map#addSourceType}
|
|
9
|
-
* @private
|
|
10
|
-
*
|
|
11
|
-
* @class WorkerSource
|
|
12
|
-
* @param actor
|
|
13
|
-
* @param layerIndex
|
|
14
|
-
*/
|
package/src/style-spec/deref.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const refProperties = require('./util/ref_properties');
|
|
2
|
-
|
|
3
|
-
function deref(layer, parent) {
|
|
4
|
-
const result = {};
|
|
5
|
-
|
|
6
|
-
for (const k in layer) {
|
|
7
|
-
if (k !== 'ref') {
|
|
8
|
-
result[k] = layer[k];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
refProperties.forEach(k => {
|
|
13
|
-
if (k in parent) {
|
|
14
|
-
result[k] = parent[k];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = derefLayers;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Given an array of layers, some of which may contain `ref` properties
|
|
25
|
-
* whose value is the `id` of another property, return a new array where
|
|
26
|
-
* such layers have been augmented with the 'type', 'source', etc. properties
|
|
27
|
-
* from the parent layer, and the `ref` property has been removed.
|
|
28
|
-
*
|
|
29
|
-
* The input is not modified. The output may contain references to portions
|
|
30
|
-
* of the input.
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
* @param {Array<Layer>} layers
|
|
34
|
-
* @returns {Array<Layer>}
|
|
35
|
-
*/
|
|
36
|
-
function derefLayers(layers) {
|
|
37
|
-
layers = layers.slice();
|
|
38
|
-
|
|
39
|
-
const map = Object.create(null);
|
|
40
|
-
for (let i = 0; i < layers.length; i++) {
|
|
41
|
-
map[layers[i].id] = layers[i];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (let i = 0; i < layers.length; i++) {
|
|
45
|
-
if ('ref' in layers[i]) {
|
|
46
|
-
layers[i] = deref(layers[i], map[layers[i].ref]);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return layers;
|
|
51
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const refProperties = require('./util/ref_properties');
|
|
2
|
-
|
|
3
|
-
function stringify(obj) {
|
|
4
|
-
if (obj == null) return 'null';
|
|
5
|
-
const type = typeof obj;
|
|
6
|
-
if (type === 'number' || type === 'boolean' || type === 'string') return obj;
|
|
7
|
-
|
|
8
|
-
if (Array.isArray(obj)) {
|
|
9
|
-
return '[' + obj.map(val => stringify(val)).join(',') + ']';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const keys = Object.keys(obj).sort();
|
|
13
|
-
return '{' + keys.map(key => `${key}:${stringify(obj[key])}`).join(',') + '}';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getKey(layer) {
|
|
17
|
-
return refProperties.map(k => stringify(layer[k])).join('/');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = groupByLayout;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Given an array of layers, return an array of arrays of layers where all
|
|
24
|
-
* layers in each group have identical layout-affecting properties. These
|
|
25
|
-
* are the properties that were formerly used by explicit `ref` mechanism
|
|
26
|
-
* for layers: 'type', 'source', 'source-layer', 'minzoom', 'maxzoom',
|
|
27
|
-
* 'filter', and 'layout'.
|
|
28
|
-
*
|
|
29
|
-
* The input is not modified. The output layers are references to the
|
|
30
|
-
* input layers.
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
* @param {Array<Layer>} layers
|
|
34
|
-
* @returns {Array<Array<Layer>>}
|
|
35
|
-
*/
|
|
36
|
-
function groupByLayout(layers) {
|
|
37
|
-
const groups = {};
|
|
38
|
-
|
|
39
|
-
for (const l of layers) {
|
|
40
|
-
const k = getKey(l);
|
|
41
|
-
const group = (groups[k] ??= []);
|
|
42
|
-
group.push(l);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return Object.values(groups);
|
|
46
|
-
}
|
package/src/util/actor.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const { serialize, deserialize } = require('./web_worker_transfer');
|
|
2
|
-
|
|
3
|
-
module.exports = actor;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* An implementation of the [Actor design pattern](http://en.wikipedia.org/wiki/Actor_model)
|
|
7
|
-
* that maintains the relationship between asynchronous tasks and the objects
|
|
8
|
-
* that spin them off - in this case, tasks like parsing parts of styles,
|
|
9
|
-
* owned by the styles
|
|
10
|
-
*
|
|
11
|
-
* @param {WebWorker} target
|
|
12
|
-
* @param {WebWorker} parent
|
|
13
|
-
* @param {string|number} mapId A unique identifier for the Map instance using this Actor.
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
function actor(target, parent, mapId, name) {
|
|
18
|
-
const promises = new Map();
|
|
19
|
-
let callbackID = Number.MIN_SAFE_INTEGER;
|
|
20
|
-
target.addEventListener('message', receive, false);
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
send,
|
|
24
|
-
receive,
|
|
25
|
-
remove,
|
|
26
|
-
name
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Sends a message from a main-thread map to a Worker or from a Worker back to
|
|
31
|
-
* a main-thread map instance.
|
|
32
|
-
*
|
|
33
|
-
* @param type The name of the target method to invoke or '[source-type].[source-name].name' for a method on a WorkerSource.
|
|
34
|
-
* @param targetMapId A particular mapId to which to send this message.
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
function send(type, data, targetMapId) {
|
|
38
|
-
const id = `${mapId}:${callbackID++}`;
|
|
39
|
-
const p = Promise.withResolvers();
|
|
40
|
-
promises.set(id, p);
|
|
41
|
-
postMessage(targetMapId, id, type, data);
|
|
42
|
-
return p.promise;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function receive(message) {
|
|
46
|
-
const { data } = message;
|
|
47
|
-
const { id, type, targetMapId } = data;
|
|
48
|
-
|
|
49
|
-
if (targetMapId && mapId !== targetMapId) return;
|
|
50
|
-
|
|
51
|
-
if (type === '<response>') {
|
|
52
|
-
const p = promises.get(id);
|
|
53
|
-
if (p) {
|
|
54
|
-
promises.delete(id);
|
|
55
|
-
if (data.error) {
|
|
56
|
-
p.reject(deserialize(data.error));
|
|
57
|
-
} else {
|
|
58
|
-
p.resolve(deserialize(data.data));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (typeof id !== 'undefined') {
|
|
65
|
-
let perform;
|
|
66
|
-
if (parent[type]) {
|
|
67
|
-
// data.type == 'loadTile' etc.
|
|
68
|
-
perform = () => parent[type](data.sourceMapId, deserialize(data.data));
|
|
69
|
-
} else if (parent.getWorkerSource) {
|
|
70
|
-
// data.type == sourcetype.method
|
|
71
|
-
const [sourcetype, method] = type.split('.');
|
|
72
|
-
const params = deserialize(data.data);
|
|
73
|
-
const workerSource = parent.getWorkerSource(data.sourceMapId, sourcetype, params.source);
|
|
74
|
-
perform = () => workerSource[method](params);
|
|
75
|
-
} else {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const result = await perform();
|
|
80
|
-
postMessage(data.sourceMapId, id, '<response>', result);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
postMessage(data.sourceMapId, id, '<response>', undefined, err);
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
parent[type](deserialize(data.data));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function remove() {
|
|
91
|
-
target.removeEventListener('message', receive, false);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function postMessage(targetMapId, id, type, data, err) {
|
|
95
|
-
const buffers = [];
|
|
96
|
-
const payload = {
|
|
97
|
-
targetMapId,
|
|
98
|
-
sourceMapId: mapId,
|
|
99
|
-
type,
|
|
100
|
-
id,
|
|
101
|
-
data: serialize(data, buffers)
|
|
102
|
-
};
|
|
103
|
-
if (err) {
|
|
104
|
-
payload.error = serialize(err);
|
|
105
|
-
}
|
|
106
|
-
target.postMessage(payload, buffers);
|
|
107
|
-
}
|
|
108
|
-
}
|
package/src/util/dispatcher.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const uniqueId = require('./unique_id');
|
|
2
|
-
const actor = require('./actor');
|
|
3
|
-
|
|
4
|
-
module.exports = dispatcher;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Responsible for sending messages from a {@link Source} to an associated
|
|
8
|
-
* {@link WorkerSource}.
|
|
9
|
-
*
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
function dispatcher(workerPool, parent, makeActor = actor) {
|
|
13
|
-
// exposed to allow stubbing in unit tests
|
|
14
|
-
|
|
15
|
-
let currentActor = -1;
|
|
16
|
-
const id = uniqueId();
|
|
17
|
-
const workers = workerPool.acquire(id);
|
|
18
|
-
const actors = workers.map((worker, i) => makeActor(worker, parent, id, `Worker ${i}`));
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Broadcast a message to all Workers.
|
|
22
|
-
*/
|
|
23
|
-
function broadcast(type, data) {
|
|
24
|
-
const tasks = actors.map(actor => actor.send(type, data));
|
|
25
|
-
return Promise.all(tasks);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Use round robin to send requests to web workers.
|
|
29
|
-
function nextActorId() {
|
|
30
|
-
currentActor += 1;
|
|
31
|
-
if (currentActor === actors.length) {
|
|
32
|
-
currentActor = 0;
|
|
33
|
-
}
|
|
34
|
-
return currentActor;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Send a message to a Worker.
|
|
39
|
-
* @param targetID The ID of the Worker to which to send this message. Omit to allow the dispatcher to choose.
|
|
40
|
-
* @returns The ID of the worker to which the message was sent.
|
|
41
|
-
*/
|
|
42
|
-
function send(type, data, targetID = nextActorId()) {
|
|
43
|
-
return actors[targetID]?.send(type, data) ?? Promise.resolve();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function remove() {
|
|
47
|
-
actors.forEach(actor => actor.remove());
|
|
48
|
-
actors.length = 0;
|
|
49
|
-
workerPool.release(id);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function nextWorkerId(workerId = nextActorId()) {
|
|
53
|
-
return workerId;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
get id() {
|
|
58
|
-
return id;
|
|
59
|
-
},
|
|
60
|
-
broadcast,
|
|
61
|
-
send,
|
|
62
|
-
nextWorkerId,
|
|
63
|
-
remove
|
|
64
|
-
};
|
|
65
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const workerPool = require('./worker_pool');
|
|
2
|
-
|
|
3
|
-
let globalWorkerPool;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates (if necessary) and returns the single, global WorkerPool instance
|
|
7
|
-
* to be shared across each Map
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
module.exports = function getGlobalWorkerPool() {
|
|
11
|
-
if (!globalWorkerPool) {
|
|
12
|
-
globalWorkerPool = workerPool();
|
|
13
|
-
}
|
|
14
|
-
return globalWorkerPool;
|
|
15
|
-
};
|