@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
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const EvaluationParameters = require('../style/evaluation_parameters');
|
|
6
|
-
|
|
7
|
-
module.exports = { getSizeData, evaluateSizeForFeature, evaluateSizeForZoom };
|
|
1
|
+
import { normalizePropertyExpression } from '@mapwhit/style-expressions';
|
|
2
|
+
import EvaluationParameters from '../style/evaluation_parameters.js';
|
|
3
|
+
import interpolate from '../util/interpolate.js';
|
|
4
|
+
import { clamp } from '../util/util.js';
|
|
8
5
|
|
|
9
6
|
// For {text,icon}-size, get the bucket-level data that will be needed by
|
|
10
7
|
// the painter to set symbol-size-related uniforms
|
|
11
|
-
function getSizeData(tileZoom, value) {
|
|
8
|
+
export function getSizeData(tileZoom, value) {
|
|
12
9
|
const { expression } = value;
|
|
13
10
|
if (expression.kind === 'constant') {
|
|
14
11
|
return {
|
|
@@ -25,10 +22,14 @@ function getSizeData(tileZoom, value) {
|
|
|
25
22
|
const levels = expression.zoomStops;
|
|
26
23
|
|
|
27
24
|
let lower = 0;
|
|
28
|
-
while (lower < levels.length && levels[lower] <= tileZoom)
|
|
25
|
+
while (lower < levels.length && levels[lower] <= tileZoom) {
|
|
26
|
+
lower++;
|
|
27
|
+
}
|
|
29
28
|
lower = Math.max(0, lower - 1);
|
|
30
29
|
let upper = lower;
|
|
31
|
-
while (upper < levels.length && levels[upper] < tileZoom + 1)
|
|
30
|
+
while (upper < levels.length && levels[upper] < tileZoom + 1) {
|
|
31
|
+
upper++;
|
|
32
|
+
}
|
|
32
33
|
upper = Math.min(levels.length - 1, upper);
|
|
33
34
|
|
|
34
35
|
const zoomRange = {
|
|
@@ -60,7 +61,7 @@ function getSizeData(tileZoom, value) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
function evaluateSizeForFeature(sizeData, partiallyEvaluatedSize, symbol) {
|
|
64
|
+
export function evaluateSizeForFeature(sizeData, partiallyEvaluatedSize, symbol) {
|
|
64
65
|
const part = partiallyEvaluatedSize;
|
|
65
66
|
if (sizeData.functionType === 'source') {
|
|
66
67
|
return symbol.lowerSize / 10;
|
|
@@ -71,7 +72,7 @@ function evaluateSizeForFeature(sizeData, partiallyEvaluatedSize, symbol) {
|
|
|
71
72
|
return part.uSize;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
function evaluateSizeForZoom(sizeData, currentZoom, property) {
|
|
75
|
+
export function evaluateSizeForZoom(sizeData, currentZoom, property) {
|
|
75
76
|
if (sizeData.functionType === 'constant') {
|
|
76
77
|
return {
|
|
77
78
|
uSizeT: 0,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { plugin as rtlTextPlugin } from '../source/rtl_text_plugin.js';
|
|
2
2
|
|
|
3
3
|
function transformText(text, layer, feature) {
|
|
4
|
-
const transform = layer.
|
|
4
|
+
const transform = layer._layout.get('text-transform').evaluate(feature, {});
|
|
5
5
|
if (transform === 'uppercase') {
|
|
6
6
|
text = text.toLocaleUpperCase();
|
|
7
7
|
} else if (transform === 'lowercase') {
|
|
@@ -15,9 +15,9 @@ function transformText(text, layer, feature) {
|
|
|
15
15
|
return text;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
export default function (text, layer, feature) {
|
|
19
19
|
text.sections.forEach(section => {
|
|
20
20
|
section.text = transformText(section.text, layer, feature);
|
|
21
21
|
});
|
|
22
22
|
return text;
|
|
23
|
-
}
|
|
23
|
+
}
|
package/src/ui/camera.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
import { Event, Evented } from '@mapwhit/events';
|
|
3
|
+
import LngLat from '../geo/lng_lat.js';
|
|
4
|
+
import LngLatBounds from '../geo/lng_lat_bounds.js';
|
|
5
|
+
import browser from '../util/browser.js';
|
|
6
|
+
import interpolate from '../util/interpolate.js';
|
|
7
|
+
import { deepEqual } from '../util/object.js';
|
|
8
|
+
import { clamp, ease as defaultEasing, wrap } from '../util/util.js';
|
|
9
|
+
import warn from '../util/warn.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Options common to {@link Map#jumpTo}, {@link Map#easeTo}, and {@link Map#flyTo}, controlling the desired location,
|
|
@@ -354,8 +354,12 @@ class Camera extends Evented {
|
|
|
354
354
|
if (
|
|
355
355
|
!deepEqual(
|
|
356
356
|
Object.keys(options.padding).sort((a, b) => {
|
|
357
|
-
if (a < b)
|
|
358
|
-
|
|
357
|
+
if (a < b) {
|
|
358
|
+
return -1;
|
|
359
|
+
}
|
|
360
|
+
if (a > b) {
|
|
361
|
+
return 1;
|
|
362
|
+
}
|
|
359
363
|
return 0;
|
|
360
364
|
}),
|
|
361
365
|
['bottom', 'left', 'right', 'top']
|
|
@@ -429,7 +433,9 @@ class Camera extends Evented {
|
|
|
429
433
|
const calculatedOptions = this.cameraForBounds(bounds, options);
|
|
430
434
|
|
|
431
435
|
// cameraForBounds warns + returns undefined if unable to fit:
|
|
432
|
-
if (!calculatedOptions)
|
|
436
|
+
if (!calculatedOptions) {
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
433
439
|
|
|
434
440
|
options = Object.assign(calculatedOptions, options);
|
|
435
441
|
|
|
@@ -542,7 +548,9 @@ class Camera extends Evented {
|
|
|
542
548
|
...options
|
|
543
549
|
};
|
|
544
550
|
|
|
545
|
-
if (options.animate === false)
|
|
551
|
+
if (options.animate === false) {
|
|
552
|
+
options.duration = 0;
|
|
553
|
+
}
|
|
546
554
|
|
|
547
555
|
const tr = this.transform;
|
|
548
556
|
const startZoom = this.getZoom();
|
|
@@ -820,7 +828,9 @@ class Camera extends Evented {
|
|
|
820
828
|
// When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
|
|
821
829
|
if (Math.abs(u1) < 0.000001 || !Number.isFinite(S)) {
|
|
822
830
|
// Perform a more or less instantaneous transition if the path is too short.
|
|
823
|
-
if (Math.abs(w0 - w1) < 0.000001)
|
|
831
|
+
if (Math.abs(w0 - w1) < 0.000001) {
|
|
832
|
+
return this.easeTo(options, eventData);
|
|
833
|
+
}
|
|
824
834
|
|
|
825
835
|
const k = w1 < w0 ? -1 : 1;
|
|
826
836
|
S = Math.abs(Math.log(w1 / w0)) / rho;
|
|
@@ -932,8 +942,12 @@ class Camera extends Evented {
|
|
|
932
942
|
_normalizeBearing(bearing, currentBearing) {
|
|
933
943
|
bearing = wrap(bearing, -180, 180);
|
|
934
944
|
const diff = Math.abs(bearing - currentBearing);
|
|
935
|
-
if (Math.abs(bearing - 360 - currentBearing) < diff)
|
|
936
|
-
|
|
945
|
+
if (Math.abs(bearing - 360 - currentBearing) < diff) {
|
|
946
|
+
bearing -= 360;
|
|
947
|
+
}
|
|
948
|
+
if (Math.abs(bearing + 360 - currentBearing) < diff) {
|
|
949
|
+
bearing += 360;
|
|
950
|
+
}
|
|
937
951
|
return bearing;
|
|
938
952
|
}
|
|
939
953
|
|
|
@@ -941,11 +955,13 @@ class Camera extends Evented {
|
|
|
941
955
|
// interpolating between the two endpoints will cross it.
|
|
942
956
|
_normalizeCenter(center) {
|
|
943
957
|
const tr = this.transform;
|
|
944
|
-
if (!tr.renderWorldCopies || tr.lngRange)
|
|
958
|
+
if (!tr.renderWorldCopies || tr.lngRange) {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
945
961
|
|
|
946
962
|
const delta = center.lng - tr.center.lng;
|
|
947
963
|
center.lng += delta > 180 ? -360 : delta < -180 ? 360 : 0;
|
|
948
964
|
}
|
|
949
965
|
}
|
|
950
966
|
|
|
951
|
-
|
|
967
|
+
export default Camera;
|
package/src/ui/map.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const { Event, ErrorEvent } = require('@mapwhit/events');
|
|
18
|
-
const taskQueue = require('../util/task_queue');
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
import { ErrorEvent, Event } from '@mapwhit/events';
|
|
3
|
+
import LngLat from '../geo/lng_lat.js';
|
|
4
|
+
import LngLatBounds from '../geo/lng_lat_bounds.js';
|
|
5
|
+
import Transform from '../geo/transform.js';
|
|
6
|
+
import Painter from '../render/painter.js';
|
|
7
|
+
import EvaluationParameters from '../style/evaluation_parameters.js';
|
|
8
|
+
import Style from '../style/style.js';
|
|
9
|
+
import browser from '../util/browser.js';
|
|
10
|
+
import DOM from '../util/dom.js';
|
|
11
|
+
import { RGBAImage } from '../util/image.js';
|
|
12
|
+
import loadImage from '../util/loader/image.js';
|
|
13
|
+
import { bindAll } from '../util/object.js';
|
|
14
|
+
import taskQueue from '../util/task_queue.js';
|
|
15
|
+
import warn from '../util/warn.js';
|
|
16
|
+
import Camera from './camera.js';
|
|
19
17
|
|
|
20
18
|
const defaultMinZoom = 0;
|
|
21
19
|
const defaultMaxZoom = 22;
|
|
@@ -41,10 +39,6 @@ const defaultOptions = {
|
|
|
41
39
|
|
|
42
40
|
renderWorldCopies: true,
|
|
43
41
|
|
|
44
|
-
refreshExpiredTiles: true,
|
|
45
|
-
|
|
46
|
-
maxTileCacheSize: null,
|
|
47
|
-
|
|
48
42
|
transformRequest: null,
|
|
49
43
|
fadeDuration: 300,
|
|
50
44
|
crossSourceCollisions: true
|
|
@@ -98,7 +92,6 @@ const defaultOptions = {
|
|
|
98
92
|
* @param {number} [options.bearing=0] The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
|
|
99
93
|
* @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-60). If `pitch` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
|
|
100
94
|
* @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered, when zoomed out.
|
|
101
|
-
* @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
|
|
102
95
|
* @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
|
|
103
96
|
* @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
|
|
104
97
|
* @example
|
|
@@ -125,7 +118,6 @@ class Map extends Camera {
|
|
|
125
118
|
this.loadImage = loadImage;
|
|
126
119
|
|
|
127
120
|
this._interactive = options.interactive;
|
|
128
|
-
this._maxTileCacheSize = options.maxTileCacheSize;
|
|
129
121
|
this._failIfMajorPerformanceCaveat = options.failIfMajorPerformanceCaveat;
|
|
130
122
|
this._preserveDrawingBuffer = options.preserveDrawingBuffer;
|
|
131
123
|
this._trackResize = options.trackResize;
|
|
@@ -189,7 +181,9 @@ class Map extends Camera {
|
|
|
189
181
|
|
|
190
182
|
this.resize();
|
|
191
183
|
|
|
192
|
-
if (options.style)
|
|
184
|
+
if (options.style) {
|
|
185
|
+
this.setStyle(options.style);
|
|
186
|
+
}
|
|
193
187
|
|
|
194
188
|
this.on('style.load', function () {
|
|
195
189
|
if (this.transform.unmodified) {
|
|
@@ -365,7 +359,9 @@ class Map extends Camera {
|
|
|
365
359
|
this.transform.minZoom = minZoom;
|
|
366
360
|
this._update();
|
|
367
361
|
|
|
368
|
-
if (this.getZoom() < minZoom)
|
|
362
|
+
if (this.getZoom() < minZoom) {
|
|
363
|
+
this.setZoom(minZoom);
|
|
364
|
+
}
|
|
369
365
|
|
|
370
366
|
return this;
|
|
371
367
|
}
|
|
@@ -397,7 +393,9 @@ class Map extends Camera {
|
|
|
397
393
|
this.transform.maxZoom = maxZoom;
|
|
398
394
|
this._update();
|
|
399
395
|
|
|
400
|
-
if (this.getZoom() > maxZoom)
|
|
396
|
+
if (this.getZoom() > maxZoom) {
|
|
397
|
+
this.setZoom(maxZoom);
|
|
398
|
+
}
|
|
401
399
|
|
|
402
400
|
return this;
|
|
403
401
|
}
|
|
@@ -560,8 +558,6 @@ class Map extends Camera {
|
|
|
560
558
|
// queryRenderedFeatures(geometry: PointLike | [PointLike, PointLike], options?: Object)
|
|
561
559
|
// queryRenderedFeatures(options?: Object)
|
|
562
560
|
//
|
|
563
|
-
// There no way to express that in a way that's compatible with both flow and documentation.js.
|
|
564
|
-
// Related: https://github.com/facebook/flow/issues/1556
|
|
565
561
|
if (arguments.length === 2) {
|
|
566
562
|
geometry = arguments[0];
|
|
567
563
|
options = arguments[1];
|
|
@@ -687,7 +683,7 @@ class Map extends Camera {
|
|
|
687
683
|
*/
|
|
688
684
|
getStyle() {
|
|
689
685
|
if (this.style) {
|
|
690
|
-
return this.style.serialize();
|
|
686
|
+
return this.style.serialize?.() ?? this.style;
|
|
691
687
|
}
|
|
692
688
|
}
|
|
693
689
|
|
|
@@ -697,7 +693,9 @@ class Map extends Camera {
|
|
|
697
693
|
* @returns {boolean} A Boolean indicating whether the style is fully loaded.
|
|
698
694
|
*/
|
|
699
695
|
isStyleLoaded() {
|
|
700
|
-
if (!this.style)
|
|
696
|
+
if (!this.style) {
|
|
697
|
+
return warn.once('There is no style added to the map.');
|
|
698
|
+
}
|
|
701
699
|
return this.style.loaded();
|
|
702
700
|
}
|
|
703
701
|
|
|
@@ -727,7 +725,7 @@ class Map extends Camera {
|
|
|
727
725
|
* @returns {boolean} A Boolean indicating whether the source is loaded.
|
|
728
726
|
*/
|
|
729
727
|
isSourceLoaded(id) {
|
|
730
|
-
const source = this.style?.
|
|
728
|
+
const source = this.style?._sources[id];
|
|
731
729
|
if (source === undefined) {
|
|
732
730
|
this.fire(new ErrorEvent(new Error(`There is no source with ID '${id}'`)));
|
|
733
731
|
return;
|
|
@@ -743,13 +741,14 @@ class Map extends Camera {
|
|
|
743
741
|
*/
|
|
744
742
|
|
|
745
743
|
areTilesLoaded() {
|
|
746
|
-
const sources = this.style?.
|
|
744
|
+
const sources = this.style?._sources;
|
|
747
745
|
for (const id in sources) {
|
|
748
746
|
const source = sources[id];
|
|
749
747
|
const tiles = source._tiles;
|
|
750
|
-
for (const
|
|
751
|
-
|
|
752
|
-
|
|
748
|
+
for (const tile of tiles.values()) {
|
|
749
|
+
if (!(tile.state === 'loaded' || tile.state === 'errored')) {
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
753
752
|
}
|
|
754
753
|
}
|
|
755
754
|
return true;
|
|
@@ -798,6 +797,16 @@ class Map extends Camera {
|
|
|
798
797
|
*/
|
|
799
798
|
addImage(id, image, { pixelRatio = 1, sdf = false } = {}) {
|
|
800
799
|
if (image instanceof HTMLImageElement) {
|
|
800
|
+
if (!image.complete) {
|
|
801
|
+
const promise = new Promise(resolve => {
|
|
802
|
+
image.decode().then(() => {
|
|
803
|
+
const { width, height, data } = browser.getImageData(image);
|
|
804
|
+
resolve({ data: new RGBAImage({ width, height }, data), pixelRatio, sdf });
|
|
805
|
+
});
|
|
806
|
+
});
|
|
807
|
+
this.style.addImage(id, { promise });
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
801
810
|
const { width, height, data } = browser.getImageData(image);
|
|
802
811
|
this.style.addImage(id, { data: new RGBAImage({ width, height }, data), pixelRatio, sdf });
|
|
803
812
|
} else if (image.width === undefined || image.height === undefined) {
|
|
@@ -819,6 +828,23 @@ class Map extends Camera {
|
|
|
819
828
|
}
|
|
820
829
|
}
|
|
821
830
|
|
|
831
|
+
/**
|
|
832
|
+
* Returns an image, specified by ID, currently available in the map.
|
|
833
|
+
* This includes both images from the style's original sprite
|
|
834
|
+
* and any images that have been added at runtime using {@link Map.addImage}.
|
|
835
|
+
*
|
|
836
|
+
* @param id - The ID of the image.
|
|
837
|
+
* @returns An image in the map with the specified ID.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```js
|
|
841
|
+
* let coffeeShopIcon = map.getImage("coffee_cup");
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
getImage(id) {
|
|
845
|
+
return this.style.getImage(id);
|
|
846
|
+
}
|
|
847
|
+
|
|
822
848
|
/**
|
|
823
849
|
* Define wether the image has been added or not
|
|
824
850
|
*
|
|
@@ -1054,6 +1080,24 @@ class Map extends Camera {
|
|
|
1054
1080
|
this._update();
|
|
1055
1081
|
}
|
|
1056
1082
|
|
|
1083
|
+
/**
|
|
1084
|
+
* Removes feature state, setting it back to the default behavior. If only
|
|
1085
|
+
* source is specified, removes all states of that source. If
|
|
1086
|
+
* target.id is also specified, removes all keys for that feature's state.
|
|
1087
|
+
* If key is also specified, removes that key from that feature's state.
|
|
1088
|
+
*
|
|
1089
|
+
* @param {Object} target Identifier of where to set state: can be a source, a feature, or a specific key of feature.
|
|
1090
|
+
* Feature objects returned from {@link Map#queryRenderedFeatures} or event handlers can be used as feature identifiers.
|
|
1091
|
+
* @param {string | number} target.id (optional) Unique id of the feature. Optional if key is not specified.
|
|
1092
|
+
* @param {string} target.source The Id of the vector source or GeoJSON source for the feature.
|
|
1093
|
+
* @param {string} [target.sourceLayer] (optional) *For vector tile sources, the sourceLayer is
|
|
1094
|
+
* required.*
|
|
1095
|
+
* @param {string} key (optional) The key in the feature state to reset.
|
|
1096
|
+
*/
|
|
1097
|
+
removeFeatureState(target, key) {
|
|
1098
|
+
this.style.removeFeatureState(target, key);
|
|
1099
|
+
return this._update();
|
|
1100
|
+
}
|
|
1057
1101
|
/**
|
|
1058
1102
|
* Gets the state of a feature.
|
|
1059
1103
|
*
|
|
@@ -1204,8 +1248,12 @@ class Map extends Camera {
|
|
|
1204
1248
|
* @returns {boolean} A Boolean indicating whether the map is fully loaded.
|
|
1205
1249
|
*/
|
|
1206
1250
|
loaded() {
|
|
1207
|
-
if (this._styleDirty || this._sourcesDirty)
|
|
1208
|
-
|
|
1251
|
+
if (this._styleDirty || this._sourcesDirty) {
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
if (!this.style || !this.style.loaded()) {
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1209
1257
|
return true;
|
|
1210
1258
|
}
|
|
1211
1259
|
|
|
@@ -1218,7 +1266,9 @@ class Map extends Camera {
|
|
|
1218
1266
|
* @private
|
|
1219
1267
|
*/
|
|
1220
1268
|
_update(updateStyle) {
|
|
1221
|
-
if (!this.style)
|
|
1269
|
+
if (!this.style) {
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1222
1272
|
|
|
1223
1273
|
this._styleDirty = this._styleDirty || updateStyle;
|
|
1224
1274
|
this._sourcesDirty = true;
|
|
@@ -1357,7 +1407,9 @@ class Map extends Camera {
|
|
|
1357
1407
|
window.removeEventListener('online', this._onWindowOnline, false);
|
|
1358
1408
|
}
|
|
1359
1409
|
const extension = this.painter.context.gl.getExtension('WEBGL_lose_context');
|
|
1360
|
-
if (extension)
|
|
1410
|
+
if (extension) {
|
|
1411
|
+
extension.loseContext();
|
|
1412
|
+
}
|
|
1361
1413
|
removeNode(this._canvasContainer);
|
|
1362
1414
|
removeNode(this._controlContainer);
|
|
1363
1415
|
this._container.classList.remove('mapboxgl-map');
|
|
@@ -1396,7 +1448,9 @@ class Map extends Camera {
|
|
|
1396
1448
|
return !!this._showTileBoundaries;
|
|
1397
1449
|
}
|
|
1398
1450
|
set showTileBoundaries(value) {
|
|
1399
|
-
if (this._showTileBoundaries === value)
|
|
1451
|
+
if (this._showTileBoundaries === value) {
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1400
1454
|
this._showTileBoundaries = value;
|
|
1401
1455
|
this._update();
|
|
1402
1456
|
}
|
|
@@ -1416,7 +1470,9 @@ class Map extends Camera {
|
|
|
1416
1470
|
return !!this._showCollisionBoxes;
|
|
1417
1471
|
}
|
|
1418
1472
|
set showCollisionBoxes(value) {
|
|
1419
|
-
if (this._showCollisionBoxes === value)
|
|
1473
|
+
if (this._showCollisionBoxes === value) {
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1420
1476
|
this._showCollisionBoxes = value;
|
|
1421
1477
|
if (value) {
|
|
1422
1478
|
// When we turn collision boxes on we have to generate them for existing tiles
|
|
@@ -1444,7 +1500,9 @@ class Map extends Camera {
|
|
|
1444
1500
|
return !!this._showOverdrawInspector;
|
|
1445
1501
|
}
|
|
1446
1502
|
set showOverdrawInspector(value) {
|
|
1447
|
-
if (this._showOverdrawInspector === value)
|
|
1503
|
+
if (this._showOverdrawInspector === value) {
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1448
1506
|
this._showOverdrawInspector = value;
|
|
1449
1507
|
this._update();
|
|
1450
1508
|
}
|
|
@@ -1485,7 +1543,7 @@ class Map extends Camera {
|
|
|
1485
1543
|
}
|
|
1486
1544
|
}
|
|
1487
1545
|
|
|
1488
|
-
|
|
1546
|
+
export default Map;
|
|
1489
1547
|
|
|
1490
1548
|
function removeNode(node) {
|
|
1491
1549
|
if (node.parentNode) {
|
package/src/util/async.js
CHANGED
|
@@ -8,16 +8,22 @@
|
|
|
8
8
|
* called with an array, containing the results of each async call.
|
|
9
9
|
* @private
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
if (!array.length)
|
|
11
|
+
export function all(array, fn, callback) {
|
|
12
|
+
if (!array.length) {
|
|
13
|
+
return callback(null, []);
|
|
14
|
+
}
|
|
13
15
|
let remaining = array.length;
|
|
14
16
|
const results = new Array(array.length);
|
|
15
17
|
let error = null;
|
|
16
18
|
array.forEach((item, i) => {
|
|
17
19
|
fn(item, (err, result) => {
|
|
18
|
-
if (err)
|
|
20
|
+
if (err) {
|
|
21
|
+
error = err;
|
|
22
|
+
}
|
|
19
23
|
results[i] = result;
|
|
20
|
-
if (--remaining === 0)
|
|
24
|
+
if (--remaining === 0) {
|
|
25
|
+
callback(error, results);
|
|
26
|
+
}
|
|
21
27
|
});
|
|
22
28
|
});
|
|
23
|
-
}
|
|
29
|
+
}
|
package/src/util/browser.js
CHANGED
package/src/util/callback.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
callback,
|
|
3
|
-
callbackWithSpread,
|
|
4
|
-
callbackWithNoResult
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
function callback(fn, promise) {
|
|
1
|
+
export function callback(fn, promise) {
|
|
8
2
|
if (fn) {
|
|
9
3
|
promise.then(result => fn(null, result), fn);
|
|
10
4
|
}
|
|
11
5
|
return promise;
|
|
12
6
|
}
|
|
13
7
|
|
|
14
|
-
function callbackWithSpread(fn, promise) {
|
|
8
|
+
export function callbackWithSpread(fn, promise) {
|
|
15
9
|
if (fn) {
|
|
16
10
|
promise.then(result => fn(null, ...result), fn);
|
|
17
11
|
}
|
|
18
12
|
return promise;
|
|
19
13
|
}
|
|
20
14
|
|
|
21
|
-
function callbackWithNoResult(fn, promise) {
|
|
15
|
+
export function callbackWithNoResult(fn, promise) {
|
|
22
16
|
if (fn) {
|
|
23
17
|
promise.then(() => fn(null), fn);
|
|
24
18
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { calculateSignedArea } = require('./util');
|
|
1
|
+
import quickselect from 'quickselect';
|
|
2
|
+
import { calculateSignedArea } from './util.js';
|
|
4
3
|
|
|
5
4
|
// classifies an array of rings into polygons with outer rings and holes
|
|
6
|
-
|
|
7
|
-
if (rings.length <= 1)
|
|
5
|
+
export default function classifyRings(rings, maxRings) {
|
|
6
|
+
if (rings.length <= 1) {
|
|
7
|
+
return [rings];
|
|
8
|
+
}
|
|
8
9
|
|
|
9
10
|
const polygons = [];
|
|
10
11
|
let polygon;
|
|
@@ -12,11 +13,15 @@ module.exports = function classifyRings(rings, maxRings) {
|
|
|
12
13
|
|
|
13
14
|
for (const ring of rings) {
|
|
14
15
|
const area = calculateSignedArea(ring);
|
|
15
|
-
if (area === 0)
|
|
16
|
+
if (area === 0) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
16
19
|
|
|
17
20
|
ring.area = Math.abs(area);
|
|
18
21
|
|
|
19
|
-
if (ccw === undefined)
|
|
22
|
+
if (ccw === undefined) {
|
|
23
|
+
ccw = area < 0;
|
|
24
|
+
}
|
|
20
25
|
|
|
21
26
|
if (ccw === area < 0) {
|
|
22
27
|
append(polygon);
|
|
@@ -40,4 +45,4 @@ module.exports = function classifyRings(rings, maxRings) {
|
|
|
40
45
|
}
|
|
41
46
|
polygons.push(polygon);
|
|
42
47
|
}
|
|
43
|
-
}
|
|
48
|
+
}
|
package/src/util/color_ramp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { RGBAImage } from './image.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Given an expression that should evaluate to a color ramp, return
|
|
@@ -6,7 +6,7 @@ const { RGBAImage } = require('./image');
|
|
|
6
6
|
*
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
export default function renderColorRamp(expression, colorRampEvaluationParameter) {
|
|
10
10
|
const colorRampData = new Uint8Array(256 * 4);
|
|
11
11
|
const evaluationGlobals = {};
|
|
12
12
|
for (let i = 0, j = 0; i < 256; i++, j += 4) {
|
|
@@ -21,4 +21,4 @@ module.exports = function renderColorRamp(expression, colorRampEvaluationParamet
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
return new RGBAImage({ width: 256, height: 1 }, colorRampData);
|
|
24
|
-
}
|
|
24
|
+
}
|
package/src/util/config.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { Evented } from '@mapwhit/events';
|
|
2
|
+
import browser from './browser.js';
|
|
2
3
|
|
|
3
4
|
function getDefaultWorkerCount() {
|
|
4
|
-
const browser = require('./browser');
|
|
5
5
|
return Math.max(Math.floor(browser.hardwareConcurrency / 2), 1);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
const config = new Evented();
|
|
9
9
|
|
|
10
|
+
export default config;
|
|
11
|
+
|
|
10
12
|
config.set = function set(c) {
|
|
11
13
|
Object.assign(config, c);
|
|
12
14
|
config.notify();
|
|
@@ -20,5 +22,3 @@ config.set({
|
|
|
20
22
|
WORKER_COUNT: getDefaultWorkerCount(),
|
|
21
23
|
WORKER_URL: ''
|
|
22
24
|
});
|
|
23
|
-
|
|
24
|
-
module.exports = config;
|
package/src/util/dom.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
const DOM = {};
|
|
2
|
-
|
|
2
|
+
export default DOM;
|
|
3
3
|
|
|
4
4
|
DOM.create = function (tagName, className, container) {
|
|
5
5
|
const el = window.document.createElement(tagName);
|
|
6
|
-
if (className)
|
|
7
|
-
|
|
6
|
+
if (className) {
|
|
7
|
+
el.className = className;
|
|
8
|
+
}
|
|
9
|
+
if (container) {
|
|
10
|
+
container.appendChild(el);
|
|
11
|
+
}
|
|
8
12
|
return el;
|
|
9
13
|
};
|
|
10
14
|
|