@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,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { distToSegmentSquared } = require('./intersection_tests');
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
import Queue from 'tinyqueue';
|
|
3
|
+
import { distToSegmentSquared } from './intersection_tests.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Finds an approximation of a polygon's Pole Of Inaccessibiliy https://en.wikipedia.org/wiki/Pole_of_inaccessibility
|
|
@@ -13,7 +12,7 @@ const { distToSegmentSquared } = require('./intersection_tests');
|
|
|
13
12
|
* @returns Pole of Inaccessibiliy.
|
|
14
13
|
* @private
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
export default function (polygonRings, precision = 1, debug = false) {
|
|
17
16
|
// find the bounding box of the outer ring
|
|
18
17
|
let minX = Number.POSITIVE_INFINITY;
|
|
19
18
|
let minY = Number.POSITIVE_INFINITY;
|
|
@@ -22,10 +21,18 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
|
|
|
22
21
|
const outerRing = polygonRings[0];
|
|
23
22
|
for (let i = 0; i < outerRing.length; i++) {
|
|
24
23
|
const p = outerRing[i];
|
|
25
|
-
if (!i || p.x < minX)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (!i || p.y
|
|
24
|
+
if (!i || p.x < minX) {
|
|
25
|
+
minX = p.x;
|
|
26
|
+
}
|
|
27
|
+
if (!i || p.y < minY) {
|
|
28
|
+
minY = p.y;
|
|
29
|
+
}
|
|
30
|
+
if (!i || p.x > maxX) {
|
|
31
|
+
maxX = p.x;
|
|
32
|
+
}
|
|
33
|
+
if (!i || p.y > maxY) {
|
|
34
|
+
maxY = p.y;
|
|
35
|
+
}
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
const width = maxX - minX;
|
|
@@ -36,7 +43,9 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
|
|
|
36
43
|
// a priority queue of cells in order of their "potential" (max distance to polygon)
|
|
37
44
|
const cellQueue = new Queue(undefined, compareMax);
|
|
38
45
|
|
|
39
|
-
if (cellSize === 0)
|
|
46
|
+
if (cellSize === 0) {
|
|
47
|
+
return new Point(minX, minY);
|
|
48
|
+
}
|
|
40
49
|
|
|
41
50
|
// cover polygon with initial cells
|
|
42
51
|
for (let x = minX; x < maxX; x += cellSize) {
|
|
@@ -56,11 +65,15 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
|
|
|
56
65
|
// update the best cell if we found a better one
|
|
57
66
|
if (cell.d > bestCell.d || !bestCell.d) {
|
|
58
67
|
bestCell = cell;
|
|
59
|
-
if (debug)
|
|
68
|
+
if (debug) {
|
|
69
|
+
console.log('found best %d after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
|
|
70
|
+
}
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
// do not drill down further if there's no chance of a better solution
|
|
63
|
-
if (cell.max - bestCell.d <= precision)
|
|
74
|
+
if (cell.max - bestCell.d <= precision) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
64
77
|
|
|
65
78
|
// split the cell into four cells
|
|
66
79
|
h = cell.h / 2;
|
|
@@ -77,7 +90,7 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
|
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
return bestCell.p;
|
|
80
|
-
}
|
|
93
|
+
}
|
|
81
94
|
|
|
82
95
|
function compareMax(a, b) {
|
|
83
96
|
return b.max - a.max;
|
|
@@ -102,7 +115,9 @@ function pointToPolygonDist(p, polygon) {
|
|
|
102
115
|
const a = ring[i];
|
|
103
116
|
const b = ring[j];
|
|
104
117
|
|
|
105
|
-
if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x)
|
|
118
|
+
if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x) {
|
|
119
|
+
inside = !inside;
|
|
120
|
+
}
|
|
106
121
|
|
|
107
122
|
minDistSq = Math.min(minDistSq, distToSegmentSquared(p, a, b));
|
|
108
123
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export default groupBySource;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Given an collection of layers, divide them by property 'source', then by 'source-layer',
|
|
5
|
+
* and then by layout-affecting properties: 'type', , 'minzoom', 'maxzoom', 'filter', and 'layout'.
|
|
6
|
+
*
|
|
7
|
+
* The input is not modified. The output layers are references to the
|
|
8
|
+
* input layers.
|
|
9
|
+
*
|
|
10
|
+
* @param layers iterable collection of layers
|
|
11
|
+
* @returns Map source to {Map source-layer to {Map layout key to Array of layers}}
|
|
12
|
+
*/
|
|
13
|
+
function groupBySource(layers) {
|
|
14
|
+
const groups = new Map();
|
|
15
|
+
|
|
16
|
+
// Iterate through each layer and group them by source, source-layer, and layout properties
|
|
17
|
+
for (const layer of layers) {
|
|
18
|
+
if (layer.visibility === 'none') {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { source = '', sourceLayer = '_geojsonTileLayer' } = layer;
|
|
23
|
+
let sourceGroup = groups.get(source);
|
|
24
|
+
if (!sourceGroup) {
|
|
25
|
+
sourceGroup = new Map();
|
|
26
|
+
groups.set(source, sourceGroup);
|
|
27
|
+
}
|
|
28
|
+
let sourceLayerGroup = sourceGroup.get(sourceLayer);
|
|
29
|
+
if (!sourceLayerGroup) {
|
|
30
|
+
sourceLayerGroup = new Map();
|
|
31
|
+
sourceGroup.set(sourceLayer, sourceLayerGroup);
|
|
32
|
+
}
|
|
33
|
+
let layoutGroup = sourceLayerGroup.get(layer.key);
|
|
34
|
+
if (!layoutGroup) {
|
|
35
|
+
layoutGroup = [];
|
|
36
|
+
sourceLayerGroup.set(layer.key, layoutGroup);
|
|
37
|
+
}
|
|
38
|
+
layoutGroup.push(layer);
|
|
39
|
+
}
|
|
40
|
+
return groups;
|
|
41
|
+
}
|
package/src/util/image.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { register } = require('./transfer_registry');
|
|
1
|
+
import assert from 'assert';
|
|
4
2
|
|
|
5
3
|
function createImage(image, { width, height }, channels, data) {
|
|
6
4
|
if (!data) {
|
|
@@ -77,7 +75,7 @@ function copyImage(srcImg, dstImg, srcPt, dstPt, size, channels) {
|
|
|
77
75
|
return dstImg;
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
class AlphaImage {
|
|
78
|
+
export class AlphaImage {
|
|
81
79
|
constructor(size, data) {
|
|
82
80
|
createImage(this, size, 1, data);
|
|
83
81
|
}
|
|
@@ -97,7 +95,7 @@ class AlphaImage {
|
|
|
97
95
|
|
|
98
96
|
// Not premultiplied, because ImageData is not premultiplied.
|
|
99
97
|
// UNPACK_PREMULTIPLY_ALPHA_WEBGL must be used when uploading to a texture.
|
|
100
|
-
class RGBAImage {
|
|
98
|
+
export class RGBAImage {
|
|
101
99
|
constructor(size, data) {
|
|
102
100
|
createImage(this, size, 4, data);
|
|
103
101
|
}
|
|
@@ -114,11 +112,3 @@ class RGBAImage {
|
|
|
114
112
|
copyImage(srcImg, dstImg, srcPt, dstPt, size, 4);
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
|
-
|
|
118
|
-
register('AlphaImage', AlphaImage);
|
|
119
|
-
register('RGBAImage', RGBAImage);
|
|
120
|
-
|
|
121
|
-
module.exports = {
|
|
122
|
-
AlphaImage,
|
|
123
|
-
RGBAImage
|
|
124
|
-
};
|
package/src/util/interpolate.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
polygonIntersectsBufferedPoint,
|
|
6
|
-
polygonIntersectsMultiPolygon,
|
|
7
|
-
polygonIntersectsBufferedMultiLine,
|
|
8
|
-
polygonIntersectsPolygon,
|
|
9
|
-
distToSegmentSquared,
|
|
10
|
-
polygonIntersectsBox
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function polygonIntersectsPolygon(polygonA, polygonB) {
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
import { isCounterClockwise } from './util.js';
|
|
3
|
+
|
|
4
|
+
export function polygonIntersectsPolygon(polygonA, polygonB) {
|
|
14
5
|
for (let i = 0; i < polygonA.length; i++) {
|
|
15
|
-
if (polygonContainsPoint(polygonB, polygonA[i]))
|
|
6
|
+
if (polygonContainsPoint(polygonB, polygonA[i])) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
16
9
|
}
|
|
17
10
|
|
|
18
11
|
for (let i = 0; i < polygonB.length; i++) {
|
|
19
|
-
if (polygonContainsPoint(polygonA, polygonB[i]))
|
|
12
|
+
if (polygonContainsPoint(polygonA, polygonB[i])) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
20
15
|
}
|
|
21
16
|
|
|
22
|
-
if (lineIntersectsLine(polygonA, polygonB))
|
|
17
|
+
if (lineIntersectsLine(polygonA, polygonB)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
23
20
|
|
|
24
21
|
return false;
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
function polygonIntersectsBufferedPoint(polygon, point, radius) {
|
|
28
|
-
if (polygonContainsPoint(polygon, point))
|
|
29
|
-
|
|
24
|
+
export function polygonIntersectsBufferedPoint(polygon, point, radius) {
|
|
25
|
+
if (polygonContainsPoint(polygon, point)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (pointIntersectsBufferedLine(point, polygon, radius)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
30
31
|
return false;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
|
|
34
|
+
export function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
|
|
34
35
|
if (polygon.length === 1) {
|
|
35
36
|
return multiPolygonContainsPoint(multiPolygon, polygon[0]);
|
|
36
37
|
}
|
|
@@ -38,62 +39,82 @@ function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
|
|
|
38
39
|
for (let m = 0; m < multiPolygon.length; m++) {
|
|
39
40
|
const ring = multiPolygon[m];
|
|
40
41
|
for (let n = 0; n < ring.length; n++) {
|
|
41
|
-
if (polygonContainsPoint(polygon, ring[n]))
|
|
42
|
+
if (polygonContainsPoint(polygon, ring[n])) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
for (let i = 0; i < polygon.length; i++) {
|
|
46
|
-
if (multiPolygonContainsPoint(multiPolygon, polygon[i]))
|
|
49
|
+
if (multiPolygonContainsPoint(multiPolygon, polygon[i])) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
for (let k = 0; k < multiPolygon.length; k++) {
|
|
50
|
-
if (lineIntersectsLine(polygon, multiPolygon[k]))
|
|
55
|
+
if (lineIntersectsLine(polygon, multiPolygon[k])) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
return false;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
function polygonIntersectsBufferedMultiLine(polygon, multiLine, radius) {
|
|
63
|
+
export function polygonIntersectsBufferedMultiLine(polygon, multiLine, radius) {
|
|
57
64
|
for (let i = 0; i < multiLine.length; i++) {
|
|
58
65
|
const line = multiLine[i];
|
|
59
66
|
|
|
60
67
|
if (polygon.length >= 3) {
|
|
61
68
|
for (let k = 0; k < line.length; k++) {
|
|
62
|
-
if (polygonContainsPoint(polygon, line[k]))
|
|
69
|
+
if (polygonContainsPoint(polygon, line[k])) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
|
|
66
|
-
if (lineIntersectsBufferedLine(polygon, line, radius))
|
|
75
|
+
if (lineIntersectsBufferedLine(polygon, line, radius)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
return false;
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
function lineIntersectsBufferedLine(lineA, lineB, radius) {
|
|
72
83
|
if (lineA.length > 1) {
|
|
73
|
-
if (lineIntersectsLine(lineA, lineB))
|
|
84
|
+
if (lineIntersectsLine(lineA, lineB)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
74
87
|
|
|
75
88
|
// Check whether any point in either line is within radius of the other line
|
|
76
89
|
for (let j = 0; j < lineB.length; j++) {
|
|
77
|
-
if (pointIntersectsBufferedLine(lineB[j], lineA, radius))
|
|
90
|
+
if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
for (let k = 0; k < lineA.length; k++) {
|
|
82
|
-
if (pointIntersectsBufferedLine(lineA[k], lineB, radius))
|
|
97
|
+
if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
return false;
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
function lineIntersectsLine(lineA, lineB) {
|
|
89
|
-
if (lineA.length === 0 || lineB.length === 0)
|
|
106
|
+
if (lineA.length === 0 || lineB.length === 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
90
109
|
for (let i = 0; i < lineA.length - 1; i++) {
|
|
91
110
|
const a0 = lineA[i];
|
|
92
111
|
const a1 = lineA[i + 1];
|
|
93
112
|
for (let j = 0; j < lineB.length - 1; j++) {
|
|
94
113
|
const b0 = lineB[j];
|
|
95
114
|
const b1 = lineB[j + 1];
|
|
96
|
-
if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1))
|
|
115
|
+
if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
97
118
|
}
|
|
98
119
|
}
|
|
99
120
|
return false;
|
|
@@ -109,25 +130,35 @@ function lineSegmentIntersectsLineSegment(a0, a1, b0, b1) {
|
|
|
109
130
|
function pointIntersectsBufferedLine(p, line, radius) {
|
|
110
131
|
const radiusSquared = radius * radius;
|
|
111
132
|
|
|
112
|
-
if (line.length === 1)
|
|
133
|
+
if (line.length === 1) {
|
|
134
|
+
return p.distSqr(line[0]) < radiusSquared;
|
|
135
|
+
}
|
|
113
136
|
|
|
114
137
|
for (let i = 1; i < line.length; i++) {
|
|
115
138
|
// Find line segments that have a distance <= radius^2 to p
|
|
116
139
|
// In that case, we treat the line as "containing point p".
|
|
117
140
|
const v = line[i - 1];
|
|
118
141
|
const w = line[i];
|
|
119
|
-
if (distToSegmentSquared(p, v, w) < radiusSquared)
|
|
142
|
+
if (distToSegmentSquared(p, v, w) < radiusSquared) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
120
145
|
}
|
|
121
146
|
return false;
|
|
122
147
|
}
|
|
123
148
|
|
|
124
149
|
// Code from http://stackoverflow.com/a/1501725/331379.
|
|
125
|
-
function distToSegmentSquared(p, v, w) {
|
|
150
|
+
export function distToSegmentSquared(p, v, w) {
|
|
126
151
|
const l2 = v.distSqr(w);
|
|
127
|
-
if (l2 === 0)
|
|
152
|
+
if (l2 === 0) {
|
|
153
|
+
return p.distSqr(v);
|
|
154
|
+
}
|
|
128
155
|
const t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
|
|
129
|
-
if (t < 0)
|
|
130
|
-
|
|
156
|
+
if (t < 0) {
|
|
157
|
+
return p.distSqr(v);
|
|
158
|
+
}
|
|
159
|
+
if (t > 1) {
|
|
160
|
+
return p.distSqr(w);
|
|
161
|
+
}
|
|
131
162
|
return p.distSqr(w.sub(v)._mult(t)._add(v));
|
|
132
163
|
}
|
|
133
164
|
|
|
@@ -163,23 +194,29 @@ function polygonContainsPoint(ring, p) {
|
|
|
163
194
|
return c;
|
|
164
195
|
}
|
|
165
196
|
|
|
166
|
-
function polygonIntersectsBox(ring, boxX1, boxY1, boxX2, boxY2) {
|
|
197
|
+
export function polygonIntersectsBox(ring, boxX1, boxY1, boxX2, boxY2) {
|
|
167
198
|
for (const p of ring) {
|
|
168
|
-
if (boxX1 <= p.x && boxY1 <= p.y && boxX2 >= p.x && boxY2 >= p.y)
|
|
199
|
+
if (boxX1 <= p.x && boxY1 <= p.y && boxX2 >= p.x && boxY2 >= p.y) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
169
202
|
}
|
|
170
203
|
|
|
171
204
|
const corners = [new Point(boxX1, boxY1), new Point(boxX1, boxY2), new Point(boxX2, boxY2), new Point(boxX2, boxY1)];
|
|
172
205
|
|
|
173
206
|
if (ring.length > 2) {
|
|
174
207
|
for (const corner of corners) {
|
|
175
|
-
if (polygonContainsPoint(ring, corner))
|
|
208
|
+
if (polygonContainsPoint(ring, corner)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
176
211
|
}
|
|
177
212
|
}
|
|
178
213
|
|
|
179
214
|
for (let i = 0; i < ring.length - 1; i++) {
|
|
180
215
|
const p1 = ring[i];
|
|
181
216
|
const p2 = ring[i + 1];
|
|
182
|
-
if (edgeIntersectsBox(p1, p2, corners))
|
|
217
|
+
if (edgeIntersectsBox(p1, p2, corners)) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
183
220
|
}
|
|
184
221
|
|
|
185
222
|
return false;
|
|
@@ -194,8 +231,9 @@ function edgeIntersectsBox(e1, e2, corners) {
|
|
|
194
231
|
(e1.x > br.x && e2.x > br.x) ||
|
|
195
232
|
(e1.y < tl.y && e2.y < tl.y) ||
|
|
196
233
|
(e1.y > br.y && e2.y > br.y)
|
|
197
|
-
)
|
|
234
|
+
) {
|
|
198
235
|
return false;
|
|
236
|
+
}
|
|
199
237
|
|
|
200
238
|
// check if all corners of the box are on the same side of the edge
|
|
201
239
|
const dir = isCounterClockwise(e1, e2, corners[0]);
|
package/src/util/key.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default createKey;
|
|
2
|
+
|
|
3
|
+
function stringify(obj) {
|
|
4
|
+
if (obj == null) {
|
|
5
|
+
return 'null';
|
|
6
|
+
}
|
|
7
|
+
const type = typeof obj;
|
|
8
|
+
if (type === 'number' || type === 'boolean' || type === 'string') {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (Array.isArray(obj)) {
|
|
13
|
+
return '[' + obj.map(val => stringify(val)).join(',') + ']';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const keys = Object.keys(obj).sort();
|
|
17
|
+
return '{' + keys.map(key => `${key}:${stringify(obj[key])}`).join(',') + '}';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a unique key for an based on its properties.
|
|
22
|
+
*/
|
|
23
|
+
function createKey(properties, object) {
|
|
24
|
+
return properties.map(k => stringify(object[k])).join('/');
|
|
25
|
+
}
|
package/src/util/loader/image.js
CHANGED
package/src/util/object.js
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Polyfill for Object.values. Not fully spec compliant, but we don't
|
|
3
|
-
* need it to be.
|
|
4
|
-
*
|
|
5
|
-
* @private
|
|
6
|
-
*/
|
|
7
|
-
function values(obj) {
|
|
8
|
-
const result = [];
|
|
9
|
-
for (const k in obj) {
|
|
10
|
-
result.push(obj[k]);
|
|
11
|
-
}
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/*
|
|
16
|
-
* Compute the difference between the keys in one object and the keys
|
|
17
|
-
* in another object.
|
|
18
|
-
*
|
|
19
|
-
* @returns keys difference
|
|
20
|
-
* @private
|
|
21
|
-
*/
|
|
22
|
-
function keysDifference(obj, other) {
|
|
23
|
-
const difference = [];
|
|
24
|
-
for (const i in obj) {
|
|
25
|
-
if (!(i in other)) {
|
|
26
|
-
difference.push(i);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return difference;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
1
|
/**
|
|
33
2
|
* Given an object and a number of properties as strings, return version
|
|
34
3
|
* of that object with only those properties.
|
|
@@ -43,15 +12,9 @@ function keysDifference(obj, other) {
|
|
|
43
12
|
* // justName = { name: 'Charlie' }
|
|
44
13
|
* @private
|
|
45
14
|
*/
|
|
46
|
-
function pick(src, properties) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const k = properties[i];
|
|
50
|
-
if (k in src) {
|
|
51
|
-
result[k] = src[k];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
15
|
+
export function pick(src, properties) {
|
|
16
|
+
const entries = properties.filter(p => p in src).map(p => [p, src[p]]);
|
|
17
|
+
return Object.fromEntries(entries);
|
|
55
18
|
}
|
|
56
19
|
|
|
57
20
|
/**
|
|
@@ -75,7 +38,7 @@ function pick(src, properties) {
|
|
|
75
38
|
* setTimeout(myClass.ontimer, 100);
|
|
76
39
|
* @private
|
|
77
40
|
*/
|
|
78
|
-
function bindAll(fns, context) {
|
|
41
|
+
export function bindAll(fns, context) {
|
|
79
42
|
fns.forEach(fn => {
|
|
80
43
|
if (!context[fn]) {
|
|
81
44
|
return;
|
|
@@ -90,12 +53,10 @@ function bindAll(fns, context) {
|
|
|
90
53
|
*
|
|
91
54
|
* @private
|
|
92
55
|
*/
|
|
93
|
-
function mapObject(input, iterator, context) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
return output;
|
|
56
|
+
export function mapObject(input, iterator, context) {
|
|
57
|
+
context ??= this;
|
|
58
|
+
const entries = Object.entries(input).map(([k, v]) => [k, iterator.call(context, v, k, input)]);
|
|
59
|
+
return Object.fromEntries(entries);
|
|
99
60
|
}
|
|
100
61
|
|
|
101
62
|
/**
|
|
@@ -103,14 +64,10 @@ function mapObject(input, iterator, context) {
|
|
|
103
64
|
*
|
|
104
65
|
* @private
|
|
105
66
|
*/
|
|
106
|
-
function filterObject(input, iterator, context) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
output[key] = input[key];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return output;
|
|
67
|
+
export function filterObject(input, iterator, context) {
|
|
68
|
+
context ??= this;
|
|
69
|
+
const entries = Object.entries(input).filter(([k, v]) => iterator.call(context, v, k, input));
|
|
70
|
+
return Object.fromEntries(entries);
|
|
114
71
|
}
|
|
115
72
|
|
|
116
73
|
/**
|
|
@@ -118,20 +75,30 @@ function filterObject(input, iterator, context) {
|
|
|
118
75
|
*
|
|
119
76
|
* @private
|
|
120
77
|
*/
|
|
121
|
-
function deepEqual(a, b) {
|
|
78
|
+
export function deepEqual(a, b) {
|
|
122
79
|
if (Array.isArray(a)) {
|
|
123
|
-
if (!Array.isArray(b) || a.length !== b.length)
|
|
80
|
+
if (!Array.isArray(b) || a.length !== b.length) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
124
83
|
for (let i = 0; i < a.length; i++) {
|
|
125
|
-
if (!deepEqual(a[i], b[i]))
|
|
84
|
+
if (!deepEqual(a[i], b[i])) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
126
87
|
}
|
|
127
88
|
return true;
|
|
128
89
|
}
|
|
129
90
|
if (typeof a === 'object' && a !== null && b !== null) {
|
|
130
|
-
if (!(typeof b === 'object'))
|
|
91
|
+
if (!(typeof b === 'object')) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
131
94
|
const keys = Object.keys(a);
|
|
132
|
-
if (keys.length !== Object.keys(b).length)
|
|
95
|
+
if (keys.length !== Object.keys(b).length) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
133
98
|
for (const key in a) {
|
|
134
|
-
if (!deepEqual(a[key], b[key]))
|
|
99
|
+
if (!deepEqual(a[key], b[key])) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
135
102
|
}
|
|
136
103
|
return true;
|
|
137
104
|
}
|
|
@@ -143,7 +110,7 @@ function deepEqual(a, b) {
|
|
|
143
110
|
*
|
|
144
111
|
* @private
|
|
145
112
|
*/
|
|
146
|
-
function clone(input) {
|
|
113
|
+
export function clone(input) {
|
|
147
114
|
if (Array.isArray(input)) {
|
|
148
115
|
return input.map(clone);
|
|
149
116
|
}
|
|
@@ -158,21 +125,11 @@ function clone(input) {
|
|
|
158
125
|
*
|
|
159
126
|
* @private
|
|
160
127
|
*/
|
|
161
|
-
function arraysIntersect(a, b) {
|
|
128
|
+
export function arraysIntersect(a, b) {
|
|
162
129
|
for (let l = 0; l < a.length; l++) {
|
|
163
|
-
if (b.indexOf(a[l]) >= 0)
|
|
130
|
+
if (b.indexOf(a[l]) >= 0) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
164
133
|
}
|
|
165
134
|
return false;
|
|
166
135
|
}
|
|
167
|
-
|
|
168
|
-
module.exports = {
|
|
169
|
-
values,
|
|
170
|
-
keysDifference,
|
|
171
|
-
pick,
|
|
172
|
-
bindAll,
|
|
173
|
-
mapObject,
|
|
174
|
-
filterObject,
|
|
175
|
-
deepEqual,
|
|
176
|
-
clone,
|
|
177
|
-
arraysIntersect
|
|
178
|
-
};
|