maplibre-gl 2.0.4 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{banner.js → banner.ts} +1 -1
- package/build/generate-query-test-fixtures.ts +123 -0
- package/build/generate-shaders.ts +35 -0
- package/build/generate-struct-arrays.ts +7 -7
- package/build/generate-style-code.ts +8 -8
- package/build/generate-style-spec.ts +5 -4
- package/build/generate-typings.ts +16 -0
- package/build/readme.md +8 -18
- package/build/release-notes.js +9 -13
- package/build/{rollup_plugin_minify_style_spec.js → rollup_plugin_minify_style_spec.ts} +4 -3
- package/build/{rollup_plugins.js → rollup_plugins.ts} +12 -26
- package/dist/maplibre-gl-dev.js +54885 -0
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +1583 -1023
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +99 -141
- package/src/css/maplibre-gl.css +36 -36
- package/src/data/{array_types.ts → array_types.g.ts} +0 -0
- package/src/data/bucket/circle_bucket.ts +1 -1
- package/src/data/bucket/fill_bucket.test.ts +1 -1
- package/src/data/bucket/fill_bucket.ts +4 -4
- package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
- package/src/data/bucket/line_bucket.test.ts +1 -1
- package/src/data/bucket/line_bucket.ts +6 -6
- package/src/data/bucket/symbol_bucket.test.ts +16 -16
- package/src/data/bucket/symbol_bucket.ts +56 -56
- package/src/data/bucket.ts +43 -43
- package/src/data/dem_data.ts +12 -12
- package/src/data/evaluation_feature.ts +10 -10
- package/src/data/feature_index.ts +37 -37
- package/src/data/feature_position_map.ts +5 -5
- package/src/data/index_array_type.ts +1 -1
- package/src/data/load_geometry.test.ts +1 -1
- package/src/data/program_configuration.ts +47 -47
- package/src/data/segment.ts +14 -14
- package/src/geo/edge_insets.ts +2 -2
- package/src/geo/lng_lat.ts +4 -4
- package/src/geo/lng_lat_bounds.ts +35 -35
- package/src/geo/mercator_coordinate.ts +5 -5
- package/src/geo/transform.test.ts +1 -1
- package/src/geo/transform.ts +14 -14
- package/src/gl/context.ts +3 -3
- package/src/gl/types.ts +19 -19
- package/src/gl/value.ts +6 -6
- package/src/gl/vertex_buffer.test.ts +1 -1
- package/src/index.ts +24 -9
- package/src/render/draw_circle.ts +8 -8
- package/src/render/draw_collision_debug.ts +5 -5
- package/src/render/draw_debug.ts +1 -1
- package/src/render/draw_line.ts +4 -4
- package/src/render/draw_symbol.ts +21 -21
- package/src/render/glyph_atlas.ts +12 -12
- package/src/render/glyph_manager.test.ts +10 -21
- package/src/render/glyph_manager.ts +34 -33
- package/src/render/image_manager.ts +4 -4
- package/src/render/painter.ts +16 -14
- package/src/render/program/background_program.ts +29 -29
- package/src/render/program/circle_program.ts +11 -11
- package/src/render/program/clipping_mask_program.ts +1 -1
- package/src/render/program/collision_program.ts +9 -9
- package/src/render/program/debug_program.ts +4 -4
- package/src/render/program/fill_extrusion_program.ts +31 -31
- package/src/render/program/fill_program.ts +29 -29
- package/src/render/program/heatmap_program.ts +12 -12
- package/src/render/program/hillshade_program.ts +12 -12
- package/src/render/program/line_program.ts +41 -41
- package/src/render/program/pattern.ts +28 -28
- package/src/render/program/raster_program.ts +21 -21
- package/src/render/program/symbol_program.ts +97 -97
- package/src/render/program.ts +25 -25
- package/src/render/texture.ts +9 -9
- package/src/render/uniform_binding.ts +1 -1
- package/src/render/vertex_array_object.ts +13 -13
- package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
- package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
- package/src/shaders/background.fragment.glsl.g.ts +2 -0
- package/src/shaders/background.vertex.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/debug.fragment.glsl.g.ts +2 -0
- package/src/shaders/debug.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
- package/src/shaders/line.fragment.glsl.g.ts +2 -0
- package/src/shaders/line.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/raster.fragment.glsl.g.ts +2 -0
- package/src/shaders/raster.vertex.glsl.g.ts +2 -0
- package/src/shaders/shaders.ts +52 -55
- package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
- package/src/source/canvas_source.test.ts +11 -12
- package/src/source/canvas_source.ts +4 -4
- package/src/source/geojson_source.test.ts +2 -1
- package/src/source/geojson_source.ts +1 -1
- package/src/source/geojson_worker_source.ts +23 -23
- package/src/source/geojson_wrapper.ts +8 -8
- package/src/source/image_source.test.ts +153 -0
- package/src/source/image_source.ts +6 -6
- package/src/source/pixels_to_tile_units.ts +6 -6
- package/src/source/query_features.ts +20 -20
- package/src/source/raster_dem_tile_source.test.ts +4 -3
- package/src/source/raster_dem_tile_source.ts +1 -1
- package/src/source/raster_tile_source.test.ts +4 -3
- package/src/source/raster_tile_source.ts +1 -1
- package/src/source/rtl_text_plugin.ts +10 -10
- package/src/source/source.ts +29 -29
- package/src/source/source_cache.test.ts +33 -1
- package/src/source/source_cache.ts +7 -5
- package/src/source/source_state.ts +1 -1
- package/src/source/tile.test.ts +3 -3
- package/src/source/tile.ts +15 -15
- package/src/source/tile_cache.test.ts +6 -4
- package/src/source/tile_cache.ts +6 -6
- package/src/source/tile_id.test.ts +10 -13
- package/src/source/tile_id.ts +2 -2
- package/src/source/vector_tile_source.test.ts +17 -5
- package/src/source/vector_tile_source.ts +4 -5
- package/src/source/vector_tile_worker_source.test.ts +4 -4
- package/src/source/vector_tile_worker_source.ts +5 -5
- package/src/source/worker.test.ts +1 -1
- package/src/source/worker.ts +22 -22
- package/src/source/worker_source.ts +56 -56
- package/src/source/worker_tile.ts +4 -4
- package/src/style/evaluation_parameters.ts +3 -3
- package/src/style/format_section_override.test.ts +1 -1
- package/src/style/light.ts +10 -10
- package/src/style/load_glyph_range.test.ts +3 -5
- package/src/style/load_glyph_range.ts +6 -6
- package/src/style/load_sprite.ts +5 -4
- package/src/style/pauseable_placement.ts +1 -1
- package/src/style/properties.ts +70 -70
- package/src/style/query_utils.ts +7 -7
- package/src/style/style.test.ts +26 -15
- package/src/style/style.ts +30 -30
- package/src/style/style_glyph.ts +8 -8
- package/src/style/style_image.ts +58 -58
- package/src/style/style_layer/background_style_layer.ts +2 -2
- package/src/style/style_layer/{background_style_layer_properties.ts → background_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/circle_style_layer.ts +10 -10
- package/src/style/style_layer/{circle_style_layer_properties.ts → circle_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/custom_style_layer.ts +19 -19
- package/src/style/style_layer/fill_extrusion_style_layer.ts +11 -11
- package/src/style/style_layer/{fill_extrusion_style_layer_properties.ts → fill_extrusion_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/fill_style_layer.ts +9 -9
- package/src/style/style_layer/{fill_style_layer_properties.ts → fill_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/heatmap_style_layer.ts +2 -2
- package/src/style/style_layer/{heatmap_style_layer_properties.ts → heatmap_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/hillshade_style_layer.ts +2 -2
- package/src/style/style_layer/{hillshade_style_layer_properties.ts → hillshade_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/line_style_layer.ts +9 -9
- package/src/style/style_layer/{line_style_layer_properties.ts → line_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/raster_style_layer.ts +2 -2
- package/src/style/style_layer/{raster_style_layer_properties.ts → raster_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/symbol_style_layer.ts +26 -7
- package/src/style/style_layer/{symbol_style_layer_properties.ts → symbol_style_layer_properties.g.ts} +6 -0
- package/src/style/style_layer.ts +10 -10
- package/src/style/style_layer_index.ts +3 -3
- package/src/style/validate_style.ts +15 -15
- package/src/style-spec/CHANGELOG.md +6 -0
- package/src/style-spec/error/validation_error.ts +1 -1
- package/src/style-spec/expression/compound_expression.ts +3 -3
- package/src/style-spec/expression/definitions/format.ts +11 -11
- package/src/style-spec/expression/definitions/interpolate.ts +5 -5
- package/src/style-spec/expression/definitions/match.ts +2 -2
- package/src/style-spec/expression/definitions/number_format.ts +11 -11
- package/src/style-spec/expression/expression.ts +8 -8
- package/src/style-spec/expression/index.ts +97 -97
- package/src/style-spec/expression/parsing_context.ts +11 -11
- package/src/style-spec/expression/types/collator.ts +9 -9
- package/src/style-spec/expression/types/resolved_image.ts +2 -2
- package/src/style-spec/expression/types.ts +14 -14
- package/src/style-spec/expression/values.ts +1 -1
- package/src/style-spec/feature_filter/index.ts +66 -66
- package/src/style-spec/function/convert.ts +3 -3
- package/src/style-spec/package.json +1 -1
- package/src/style-spec/reference/v8.json +68 -2
- package/src/style-spec/style-spec.ts +44 -44
- package/src/style-spec/types.ts +2 -0
- package/src/style-spec/util/color_spaces.ts +8 -8
- package/src/style-spec/util/result.ts +4 -4
- package/src/style-spec/validate/validate_filter.ts +58 -58
- package/src/style-spec/validate/validate_source.ts +63 -63
- package/src/style-spec/visit.ts +11 -11
- package/src/symbol/collision_feature.test.ts +1 -1
- package/src/symbol/collision_feature.ts +10 -10
- package/src/symbol/collision_index.ts +43 -43
- package/src/symbol/cross_tile_symbol_index.ts +17 -17
- package/src/symbol/get_anchors.ts +16 -16
- package/src/symbol/grid_index.test.ts +42 -19
- package/src/symbol/grid_index.ts +69 -40
- package/src/symbol/placement.ts +124 -95
- package/src/symbol/projection.ts +30 -30
- package/src/symbol/quads.ts +30 -30
- package/src/symbol/shaping.ts +160 -160
- package/src/symbol/symbol_layout.ts +119 -119
- package/src/symbol/symbol_size.ts +29 -29
- package/src/symbol/symbol_style_layer.test.ts +49 -2
- package/src/types/cancelable.ts +1 -1
- package/src/types/tilejson.ts +13 -13
- package/src/ui/anchor.ts +1 -1
- package/src/ui/camera.test.ts +9 -9
- package/src/ui/camera.ts +26 -18
- package/src/ui/control/attribution_control.test.ts +51 -16
- package/src/ui/control/attribution_control.ts +35 -16
- package/src/ui/control/control.ts +40 -40
- package/src/ui/control/fullscreen_control.ts +1 -1
- package/src/ui/control/geolocate_control.test.ts +1 -1
- package/src/ui/control/geolocate_control.ts +102 -102
- package/src/ui/control/logo_control.test.ts +5 -4
- package/src/ui/control/navigation_control.ts +3 -3
- package/src/ui/control/scale_control.test.ts +2 -2
- package/src/ui/control/scale_control.ts +5 -5
- package/src/ui/events.ts +289 -200
- package/src/ui/handler/box_zoom.test.ts +1 -1
- package/src/ui/handler/box_zoom.ts +1 -1
- package/src/ui/handler/dblclick_zoom.test.ts +1 -1
- package/src/ui/handler/drag_pan.test.ts +1 -1
- package/src/ui/handler/drag_rotate.test.ts +1 -1
- package/src/ui/handler/keyboard.test.ts +1 -1
- package/src/ui/handler/keyboard.ts +51 -51
- package/src/ui/handler/map_event.test.ts +1 -1
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/mouse_rotate.test.ts +1 -1
- package/src/ui/handler/scroll_zoom.test.ts +3 -2
- package/src/ui/handler/scroll_zoom.ts +9 -9
- package/src/ui/handler/shim/drag_pan.ts +4 -4
- package/src/ui/handler/shim/drag_rotate.ts +1 -1
- package/src/ui/handler/shim/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler/tap_recognizer.ts +4 -4
- package/src/ui/handler/touch_pan.ts +2 -2
- package/src/ui/handler/touch_zoom_rotate.test.ts +1 -1
- package/src/ui/handler/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler_inertia.ts +6 -6
- package/src/ui/handler_manager.ts +44 -44
- package/src/ui/map/isMoving.test.ts +1 -1
- package/src/ui/map/isRotating.test.ts +1 -1
- package/src/ui/map/isZooming.test.ts +1 -1
- package/src/ui/map.test.ts +87 -14
- package/src/ui/map.ts +138 -108
- package/src/ui/map_events.test.ts +1 -1
- package/src/ui/marker.test.ts +12 -12
- package/src/ui/marker.ts +37 -37
- package/src/ui/popup.test.ts +7 -7
- package/src/ui/popup.ts +9 -9
- package/src/util/actor.test.ts +41 -10
- package/src/util/actor.ts +8 -8
- package/src/util/ajax.test.ts +214 -0
- package/src/util/ajax.ts +51 -30
- package/src/util/browser.ts +1 -1
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/color_ramp.ts +5 -5
- package/src/util/config.ts +2 -2
- package/src/util/dispatcher.ts +1 -1
- package/src/util/dom.ts +2 -2
- package/src/util/evented.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +3 -3
- package/src/util/image.ts +5 -5
- package/src/util/performance.ts +7 -7
- package/src/util/request_manager.ts +4 -4
- package/src/util/resolve_tokens.ts +4 -4
- package/src/util/struct_array.test.ts +1 -1
- package/src/util/struct_array.ts +15 -15
- package/src/util/task_queue.ts +3 -3
- package/src/util/test/util.ts +14 -0
- package/src/util/tile_request_cache.ts +3 -3
- package/src/util/transferable_grid_index.ts +4 -4
- package/src/util/util.ts +8 -8
- package/src/util/web_worker.ts +4 -68
- package/src/util/web_worker_transfer.test.ts +3 -0
- package/src/util/web_worker_transfer.ts +21 -17
- package/src/util/worker_pool.ts +1 -1
- package/build/.eslintrc +0 -21
- package/build/glsl_to_js.js +0 -12
- package/build/post-ts-build.js +0 -43
- package/build/release-notes.md.ejs +0 -8
- package/build/test/build-tape.js +0 -17
- package/build/web_worker_replacement.js +0 -5
- package/dist/package.json +0 -1
- package/src/style-spec/validate_spec.test.ts +0 -29
- package/src/symbol/shaping.test.ts +0 -392
- package/src/types/glsl.d.ts +0 -4
package/src/ui/marker.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Marker from './marker';
|
|
|
3
3
|
import Popup from './popup';
|
|
4
4
|
import LngLat from '../geo/lng_lat';
|
|
5
5
|
import Point from '@mapbox/point-geometry';
|
|
6
|
-
import simulate from '../../test/
|
|
6
|
+
import simulate from '../../test/unit/lib/simulate_interaction';
|
|
7
7
|
|
|
8
8
|
function createMap(options = {}) {
|
|
9
9
|
const container = window.document.createElement('div');
|
|
@@ -46,16 +46,16 @@ describe('marker', () => {
|
|
|
46
46
|
|
|
47
47
|
// initial dimensions of svg element
|
|
48
48
|
expect(
|
|
49
|
-
|
|
49
|
+
defaultMarker.getElement().children[0].getAttribute('height').includes('41')
|
|
50
50
|
).toBeTruthy();
|
|
51
51
|
expect(defaultMarker.getElement().children[0].getAttribute('width').includes('27')).toBeTruthy();
|
|
52
52
|
|
|
53
53
|
// (41 * 0.8) = 32.8, (27 * 0.8) = 21.6
|
|
54
54
|
expect(
|
|
55
|
-
|
|
55
|
+
smallerMarker.getElement().children[0].getAttribute('height').includes('32.8')
|
|
56
56
|
).toBeTruthy();
|
|
57
57
|
expect(
|
|
58
|
-
|
|
58
|
+
smallerMarker.getElement().children[0].getAttribute('width').includes('21.6')
|
|
59
59
|
).toBeTruthy();
|
|
60
60
|
|
|
61
61
|
// (41 * 2) = 82, (27 * 2) = 54
|
|
@@ -287,49 +287,49 @@ describe('marker', () => {
|
|
|
287
287
|
|
|
288
288
|
// marker should default to above since it has enough space
|
|
289
289
|
expect(
|
|
290
|
-
|
|
290
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-bottom')
|
|
291
291
|
).toBeTruthy();
|
|
292
292
|
|
|
293
293
|
// move marker to the top forcing the popup to below
|
|
294
294
|
marker.setLngLat(map.unproject([mapHeight / 2, markerTop]));
|
|
295
295
|
expect(
|
|
296
|
-
|
|
296
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-top')
|
|
297
297
|
).toBeTruthy();
|
|
298
298
|
|
|
299
299
|
// move marker to the right forcing the popup to the left
|
|
300
300
|
marker.setLngLat(map.unproject([mapHeight - markerRight, mapHeight / 2]));
|
|
301
301
|
expect(
|
|
302
|
-
|
|
302
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-right')
|
|
303
303
|
).toBeTruthy();
|
|
304
304
|
|
|
305
305
|
// move marker to the left forcing the popup to the right
|
|
306
306
|
marker.setLngLat(map.unproject([markerRight, mapHeight / 2]));
|
|
307
307
|
expect(
|
|
308
|
-
|
|
308
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-left')
|
|
309
309
|
).toBeTruthy();
|
|
310
310
|
|
|
311
311
|
// move marker to the top left forcing the popup to the bottom right
|
|
312
312
|
marker.setLngLat(map.unproject([markerRight, markerTop]));
|
|
313
313
|
expect(
|
|
314
|
-
|
|
314
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-top-left')
|
|
315
315
|
).toBeTruthy();
|
|
316
316
|
|
|
317
317
|
// move marker to the top right forcing the popup to the bottom left
|
|
318
318
|
marker.setLngLat(map.unproject([mapHeight - markerRight, markerTop]));
|
|
319
319
|
expect(
|
|
320
|
-
|
|
320
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-top-right')
|
|
321
321
|
).toBeTruthy();
|
|
322
322
|
|
|
323
323
|
// move marker to the bottom left forcing the popup to the top right
|
|
324
324
|
marker.setLngLat(map.unproject([markerRight, mapHeight]));
|
|
325
325
|
expect(
|
|
326
|
-
|
|
326
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-bottom-left')
|
|
327
327
|
).toBeTruthy();
|
|
328
328
|
|
|
329
329
|
// move marker to the bottom right forcing the popup to the top left
|
|
330
330
|
marker.setLngLat(map.unproject([mapHeight - markerRight, mapHeight]));
|
|
331
331
|
expect(
|
|
332
|
-
|
|
332
|
+
marker.getPopup()._container.classList.contains('maplibregl-popup-anchor-bottom-right')
|
|
333
333
|
).toBeTruthy();
|
|
334
334
|
|
|
335
335
|
});
|
package/src/ui/marker.ts
CHANGED
|
@@ -13,16 +13,16 @@ import type {MapMouseEvent, MapTouchEvent} from './events';
|
|
|
13
13
|
import type {PointLike} from './camera';
|
|
14
14
|
|
|
15
15
|
type MarkerOptions = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
element?: HTMLElement;
|
|
17
|
+
offset?: PointLike;
|
|
18
|
+
anchor?: PositionAnchor;
|
|
19
|
+
color?: string;
|
|
20
|
+
scale?: number;
|
|
21
|
+
draggable?: boolean;
|
|
22
|
+
clickTolerance?: number;
|
|
23
|
+
rotation?: number;
|
|
24
|
+
rotationAlignment?: string;
|
|
25
|
+
pitchAlignment?: string;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -289,29 +289,29 @@ export default class Marker extends Evented {
|
|
|
289
289
|
* the marker on screen.
|
|
290
290
|
*
|
|
291
291
|
* @returns {LngLat} A {@link LngLat} describing the marker's location.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
292
|
+
* @example
|
|
293
|
+
* // Store the marker's longitude and latitude coordinates in a variable
|
|
294
|
+
* var lngLat = marker.getLngLat();
|
|
295
|
+
* // Print the marker's longitude and latitude values in the console
|
|
296
|
+
* console.log('Longitude: ' + lngLat.lng + ', Latitude: ' + lngLat.lat )
|
|
297
|
+
* @see [Create a draggable Marker](https://maplibre.org/maplibre-gl-js-docs/example/drag-a-marker/)
|
|
298
|
+
*/
|
|
299
299
|
getLngLat() {
|
|
300
300
|
return this._lngLat;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
304
|
+
* Set the marker's geographical position and move it.
|
|
305
|
+
* @param {LngLat} lnglat A {@link LngLat} describing where the marker should be located.
|
|
306
|
+
* @returns {Marker} `this`
|
|
307
|
+
* @example
|
|
308
|
+
* // Create a new marker, set the longitude and latitude, and add it to the map
|
|
309
|
+
* new maplibregl.Marker()
|
|
310
|
+
* .setLngLat([-65.017, -16.457])
|
|
311
|
+
* .addTo(map);
|
|
312
|
+
* @see [Add custom icons with Markers](https://maplibre.org/maplibre-gl-js-docs/example/custom-marker-icons/)
|
|
313
|
+
* @see [Create a draggable Marker](https://maplibre.org/maplibre-gl-js-docs/example/drag-a-marker/)
|
|
314
|
+
*/
|
|
315
315
|
setLngLat(lnglat: LngLatLike) {
|
|
316
316
|
this._lngLat = LngLat.convert(lnglat);
|
|
317
317
|
this._pos = null;
|
|
@@ -437,7 +437,7 @@ export default class Marker extends Evented {
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
_update(e?: {
|
|
440
|
-
|
|
440
|
+
type: 'move' | 'moveend';
|
|
441
441
|
}) {
|
|
442
442
|
if (!this._map) return;
|
|
443
443
|
|
|
@@ -545,14 +545,14 @@ export default class Marker extends Evented {
|
|
|
545
545
|
// only fire dragend if it was preceded by at least one drag event
|
|
546
546
|
if (this._state === 'active') {
|
|
547
547
|
/**
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
548
|
+
* Fired when the marker is finished being dragged
|
|
549
|
+
*
|
|
550
|
+
* @event dragend
|
|
551
|
+
* @memberof Marker
|
|
552
|
+
* @instance
|
|
553
|
+
* @type {Object}
|
|
554
|
+
* @property {Marker} marker object that was dragged
|
|
555
|
+
*/
|
|
556
556
|
this.fire(new Event('dragend'));
|
|
557
557
|
}
|
|
558
558
|
|
package/src/ui/popup.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {createMap as globalCreateMap, setPerformance, setWebGlContext} from '../
|
|
|
2
2
|
import Popup, {Offset} from './popup';
|
|
3
3
|
import LngLat from '../geo/lng_lat';
|
|
4
4
|
import Point from '@mapbox/point-geometry';
|
|
5
|
-
import simulate from '../../test/
|
|
5
|
+
import simulate from '../../test/unit/lib/simulate_interaction';
|
|
6
6
|
import {PositionAnchor} from './anchor';
|
|
7
7
|
|
|
8
8
|
const containerWidth = 512;
|
|
@@ -91,7 +91,7 @@ describe('popup', () => {
|
|
|
91
91
|
.addTo(map);
|
|
92
92
|
|
|
93
93
|
expect(
|
|
94
|
-
|
|
94
|
+
popup.getElement().querySelectorAll('.maplibregl-popup-close-button')
|
|
95
95
|
).toHaveLength(0);
|
|
96
96
|
});
|
|
97
97
|
|
|
@@ -561,7 +561,7 @@ describe('popup', () => {
|
|
|
561
561
|
.addTo(map);
|
|
562
562
|
|
|
563
563
|
expect(
|
|
564
|
-
|
|
564
|
+
popup._container.classList.value
|
|
565
565
|
).toContain('maplibregl-popup-track-pointer');
|
|
566
566
|
});
|
|
567
567
|
|
|
@@ -574,7 +574,7 @@ describe('popup', () => {
|
|
|
574
574
|
popup.setText('Test');
|
|
575
575
|
|
|
576
576
|
expect(
|
|
577
|
-
|
|
577
|
+
popup._container.classList.value
|
|
578
578
|
).toContain('maplibregl-popup-track-pointer');
|
|
579
579
|
});
|
|
580
580
|
|
|
@@ -587,7 +587,7 @@ describe('popup', () => {
|
|
|
587
587
|
popup.trackPointer();
|
|
588
588
|
|
|
589
589
|
expect(
|
|
590
|
-
|
|
590
|
+
popup._container.classList.value
|
|
591
591
|
).toContain('maplibregl-popup-track-pointer');
|
|
592
592
|
});
|
|
593
593
|
|
|
@@ -601,7 +601,7 @@ describe('popup', () => {
|
|
|
601
601
|
|
|
602
602
|
expect(popup._pos).toEqual(map.project([0, 0]));
|
|
603
603
|
expect(
|
|
604
|
-
|
|
604
|
+
popup._container.classList.value
|
|
605
605
|
).not.toContain('maplibregl-popup-track-pointer');
|
|
606
606
|
});
|
|
607
607
|
|
|
@@ -613,7 +613,7 @@ describe('popup', () => {
|
|
|
613
613
|
.addTo(map);
|
|
614
614
|
|
|
615
615
|
expect(
|
|
616
|
-
|
|
616
|
+
popup._container.classList.value
|
|
617
617
|
).not.toContain('maplibregl-popup-track-pointer');
|
|
618
618
|
});
|
|
619
619
|
|
package/src/ui/popup.ts
CHANGED
|
@@ -21,18 +21,18 @@ const defaultOptions = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export type Offset = number | PointLike | {
|
|
24
|
-
|
|
24
|
+
[_ in PositionAnchor]: PointLike;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export type PopupOptions = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
closeButton?: boolean;
|
|
29
|
+
closeOnClick?: boolean;
|
|
30
|
+
closeOnMove?: boolean;
|
|
31
|
+
focusAfterOpen?: boolean;
|
|
32
|
+
anchor?: PositionAnchor;
|
|
33
|
+
offset?: Offset;
|
|
34
|
+
className?: string;
|
|
35
|
+
maxWidth?: string;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
const focusQuerySelector = [
|
package/src/util/actor.test.ts
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
import Actor from './actor';
|
|
2
2
|
import workerFactory from './web_worker';
|
|
3
|
+
import {MessageBus} from '../../test/unit/lib/web_worker_mock';
|
|
4
|
+
|
|
5
|
+
const originalWorker = global.Worker;
|
|
6
|
+
|
|
7
|
+
function setTestWorker(MockWorker: { new(...args: any): any}) {
|
|
8
|
+
(global as any).Worker = function Worker(_: string) {
|
|
9
|
+
const parentListeners = [];
|
|
10
|
+
const workerListeners = [];
|
|
11
|
+
const parentBus = new MessageBus(workerListeners, parentListeners);
|
|
12
|
+
const workerBus = new MessageBus(parentListeners, workerListeners);
|
|
13
|
+
|
|
14
|
+
parentBus.target = workerBus;
|
|
15
|
+
workerBus.target = parentBus;
|
|
16
|
+
|
|
17
|
+
new MockWorker(workerBus);
|
|
18
|
+
|
|
19
|
+
return parentBus;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
3
22
|
|
|
4
23
|
describe('Actor', () => {
|
|
24
|
+
afterAll(() => {
|
|
25
|
+
global.Worker = originalWorker;
|
|
26
|
+
});
|
|
27
|
+
|
|
5
28
|
test('forwards responses to correct callback', done => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
29
|
+
setTestWorker(class MockWorker {
|
|
30
|
+
self: any;
|
|
31
|
+
actor: Actor;
|
|
32
|
+
constructor(self) {
|
|
33
|
+
this.self = self;
|
|
34
|
+
this.actor = new Actor(self, this);
|
|
35
|
+
}
|
|
36
|
+
test(mapId, params, callback) {
|
|
10
37
|
setTimeout(callback, 0, null, params);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
13
40
|
|
|
14
41
|
const worker = workerFactory();
|
|
15
42
|
|
|
@@ -38,10 +65,14 @@ describe('Actor', () => {
|
|
|
38
65
|
test('targets worker-initiated messages to correct map instance', done => {
|
|
39
66
|
let workerActor;
|
|
40
67
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
setTestWorker(class MockWorker {
|
|
69
|
+
self: any;
|
|
70
|
+
actor: Actor;
|
|
71
|
+
constructor(self) {
|
|
72
|
+
this.self = self;
|
|
73
|
+
this.actor = workerActor = new Actor(self, this);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
45
76
|
|
|
46
77
|
const worker = workerFactory();
|
|
47
78
|
|
package/src/util/actor.ts
CHANGED
|
@@ -21,15 +21,15 @@ class Actor {
|
|
|
21
21
|
parent: any;
|
|
22
22
|
mapId: number;
|
|
23
23
|
callbacks: {
|
|
24
|
-
|
|
24
|
+
number: any;
|
|
25
25
|
};
|
|
26
26
|
name: string;
|
|
27
27
|
tasks: {
|
|
28
|
-
|
|
28
|
+
number: any;
|
|
29
29
|
};
|
|
30
30
|
taskQueue: Array<number>;
|
|
31
31
|
cancelCallbacks: {
|
|
32
|
-
|
|
32
|
+
number: Cancelable;
|
|
33
33
|
};
|
|
34
34
|
invoker: ThrottledInvoker;
|
|
35
35
|
globalScope: any;
|
|
@@ -57,11 +57,11 @@ class Actor {
|
|
|
57
57
|
* @private
|
|
58
58
|
*/
|
|
59
59
|
send(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
type: string,
|
|
61
|
+
data: unknown,
|
|
62
|
+
callback?: Function | null,
|
|
63
|
+
targetMapId?: string | null,
|
|
64
|
+
mustQueue: boolean = false
|
|
65
65
|
): Cancelable {
|
|
66
66
|
// We're using a string ID instead of numbers because they are being used as object keys
|
|
67
67
|
// anyway, and thus stringified implicitly. We use random IDs because an actor may receive
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getArrayBuffer,
|
|
3
|
+
getJSON,
|
|
4
|
+
postData,
|
|
5
|
+
getImage,
|
|
6
|
+
resetImageRequestQueue,
|
|
7
|
+
AJAXError
|
|
8
|
+
} from './ajax';
|
|
9
|
+
import config from './config';
|
|
10
|
+
import webpSupported from './webp_supported';
|
|
11
|
+
import {fakeServer, FakeServer} from 'nise';
|
|
12
|
+
import {stubAjaxGetImage} from './test/util';
|
|
13
|
+
|
|
14
|
+
function readAsText(blob) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const fileReader = new FileReader();
|
|
17
|
+
fileReader.onload = () => resolve(fileReader.result);
|
|
18
|
+
fileReader.onerror = () => reject(fileReader.error);
|
|
19
|
+
fileReader.readAsText(blob);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('ajax', () => {
|
|
24
|
+
let server: FakeServer;
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
global.fetch = null;
|
|
27
|
+
server = fakeServer.create();
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
server.restore();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('getArrayBuffer, 404', done => {
|
|
34
|
+
server.respondWith(request => {
|
|
35
|
+
request.respond(404, undefined, '404 Not Found');
|
|
36
|
+
});
|
|
37
|
+
getArrayBuffer({url:'http://example.com/test.bin'}, async (error) => {
|
|
38
|
+
const ajaxError = error as AJAXError;
|
|
39
|
+
const body = await readAsText(ajaxError.body);
|
|
40
|
+
expect(ajaxError.status).toBe(404);
|
|
41
|
+
expect(ajaxError.statusText).toBe('Not Found');
|
|
42
|
+
expect(ajaxError.url).toBe('http://example.com/test.bin');
|
|
43
|
+
expect(body).toBe('404 Not Found');
|
|
44
|
+
done();
|
|
45
|
+
});
|
|
46
|
+
server.respond();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('getJSON', done => {
|
|
50
|
+
server.respondWith(request => {
|
|
51
|
+
request.respond(200, {'Content-Type': 'application/json'}, '{"foo": "bar"}');
|
|
52
|
+
});
|
|
53
|
+
getJSON({url:''}, (error, body) => {
|
|
54
|
+
expect(error).toBeFalsy();
|
|
55
|
+
expect(body).toEqual({foo: 'bar'});
|
|
56
|
+
done();
|
|
57
|
+
});
|
|
58
|
+
server.respond();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('getJSON, invalid syntax', done => {
|
|
62
|
+
server.respondWith(request => {
|
|
63
|
+
request.respond(200, {'Content-Type': 'application/json'}, 'how do i even');
|
|
64
|
+
});
|
|
65
|
+
getJSON({url:''}, (error) => {
|
|
66
|
+
expect(error).toBeTruthy();
|
|
67
|
+
done();
|
|
68
|
+
});
|
|
69
|
+
server.respond();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('getJSON, 404', done => {
|
|
73
|
+
server.respondWith(request => {
|
|
74
|
+
request.respond(404, undefined, '404 Not Found');
|
|
75
|
+
});
|
|
76
|
+
getJSON({url:'http://example.com/test.json'}, async (error) => {
|
|
77
|
+
const ajaxError = error as AJAXError;
|
|
78
|
+
const body = await readAsText(ajaxError.body);
|
|
79
|
+
expect(ajaxError.status).toBe(404);
|
|
80
|
+
expect(ajaxError.statusText).toBe('Not Found');
|
|
81
|
+
expect(ajaxError.url).toBe('http://example.com/test.json');
|
|
82
|
+
expect(body).toBe('404 Not Found');
|
|
83
|
+
done();
|
|
84
|
+
});
|
|
85
|
+
server.respond();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('postData, 204(no content): no error', done => {
|
|
89
|
+
server.respondWith(request => {
|
|
90
|
+
request.respond(204, undefined, undefined);
|
|
91
|
+
});
|
|
92
|
+
postData({url:'api.mapbox.com'}, (error) => {
|
|
93
|
+
expect(error).toBeNull();
|
|
94
|
+
done();
|
|
95
|
+
});
|
|
96
|
+
server.respond();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('getImage respects maxParallelImageRequests', done => {
|
|
100
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
101
|
+
|
|
102
|
+
const maxRequests = config.MAX_PARALLEL_IMAGE_REQUESTS;
|
|
103
|
+
|
|
104
|
+
function callback(err) {
|
|
105
|
+
if (err) return;
|
|
106
|
+
// last request is only added after we got a response from one of the previous ones
|
|
107
|
+
expect(server.requests).toHaveLength(maxRequests + 1);
|
|
108
|
+
done();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
for (let i = 0; i < maxRequests + 1; i++) {
|
|
112
|
+
getImage({url: ''}, callback);
|
|
113
|
+
}
|
|
114
|
+
expect(server.requests).toHaveLength(maxRequests);
|
|
115
|
+
|
|
116
|
+
server.requests[0].respond(undefined, undefined, undefined);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('getImage cancelling frees up request for maxParallelImageRequests', done => {
|
|
120
|
+
resetImageRequestQueue();
|
|
121
|
+
|
|
122
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
123
|
+
|
|
124
|
+
const maxRequests = config.MAX_PARALLEL_IMAGE_REQUESTS;
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < maxRequests + 1; i++) {
|
|
127
|
+
getImage({url: ''}, () => done('test failed: getImage callback was called')).cancel();
|
|
128
|
+
}
|
|
129
|
+
expect(server.requests).toHaveLength(maxRequests + 1);
|
|
130
|
+
done();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('getImage requests that were once queued are still abortable', done => {
|
|
134
|
+
resetImageRequestQueue();
|
|
135
|
+
|
|
136
|
+
const maxRequests = config.MAX_PARALLEL_IMAGE_REQUESTS;
|
|
137
|
+
|
|
138
|
+
const requests = [];
|
|
139
|
+
for (let i = 0; i < maxRequests; i++) {
|
|
140
|
+
requests.push(getImage({url: ''}, () => {}));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// the limit of allowed requests is reached
|
|
144
|
+
expect(server.requests).toHaveLength(maxRequests);
|
|
145
|
+
|
|
146
|
+
const queuedURL = 'this-is-the-queued-request';
|
|
147
|
+
const queued = getImage({url: queuedURL}, () => done('test failed: getImage callback was called'));
|
|
148
|
+
|
|
149
|
+
// the new requests is queued because the limit is reached
|
|
150
|
+
expect(server.requests).toHaveLength(maxRequests);
|
|
151
|
+
|
|
152
|
+
// cancel the first request to let the queued request start
|
|
153
|
+
requests[0].cancel();
|
|
154
|
+
expect(server.requests).toHaveLength(maxRequests + 1);
|
|
155
|
+
|
|
156
|
+
// abort the previously queued request and confirm that it is aborted
|
|
157
|
+
const queuedRequest = server.requests[server.requests.length - 1];
|
|
158
|
+
expect(queuedRequest.url).toBe(queuedURL);
|
|
159
|
+
expect((queuedRequest as any).aborted).toBeUndefined();
|
|
160
|
+
queued.cancel();
|
|
161
|
+
expect((queuedRequest as any).aborted).toBe(true);
|
|
162
|
+
|
|
163
|
+
done();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('getImage sends accept/webp when supported', done => {
|
|
167
|
+
resetImageRequestQueue();
|
|
168
|
+
|
|
169
|
+
server.respondWith((request) => {
|
|
170
|
+
expect(request.requestHeaders.accept.includes('image/webp')).toBeTruthy();
|
|
171
|
+
request.respond(200, {'Content-Type': 'image/webp'}, '');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// mock webp support
|
|
175
|
+
webpSupported.supported = true;
|
|
176
|
+
|
|
177
|
+
getImage({url: ''}, () => { done(); });
|
|
178
|
+
|
|
179
|
+
server.respond();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('getImage uses ImageBitmap when supported', done => {
|
|
183
|
+
resetImageRequestQueue();
|
|
184
|
+
|
|
185
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
186
|
+
|
|
187
|
+
stubAjaxGetImage(() => Promise.resolve(new ImageBitmap()));
|
|
188
|
+
|
|
189
|
+
getImage({url: ''}, (err, img) => {
|
|
190
|
+
if (err) done(err);
|
|
191
|
+
expect(img).toBeInstanceOf(ImageBitmap);
|
|
192
|
+
done();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
server.respond();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('getImage uses HTMLImageElement when ImageBitmap is not supported', done => {
|
|
199
|
+
resetImageRequestQueue();
|
|
200
|
+
|
|
201
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
202
|
+
|
|
203
|
+
stubAjaxGetImage(undefined);
|
|
204
|
+
|
|
205
|
+
getImage({url: ''}, (err, img) => {
|
|
206
|
+
if (err) done(`get image failed with error ${err.message}`);
|
|
207
|
+
expect(img).toBeInstanceOf(HTMLImageElement);
|
|
208
|
+
done();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
server.respond();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
});
|