maplibre-gl 3.1.0 → 3.2.0-pre.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/README.md +7 -7
- package/build/generate-doc-images.ts +73 -0
- package/build/generate-docs.ts +100 -0
- package/build/generate-struct-arrays.ts +9 -12
- package/dist/maplibre-gl-csp-worker.js +1 -1
- package/dist/maplibre-gl-csp-worker.js.map +1 -1
- package/dist/maplibre-gl-csp.js +1 -1
- package/dist/maplibre-gl-csp.js.map +1 -1
- package/dist/maplibre-gl-dev.js +3303 -3398
- package/dist/maplibre-gl-dev.js.map +1 -1
- package/dist/maplibre-gl.d.ts +3899 -3531
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +28 -25
- package/src/data/array_types.g.ts +14 -48
- package/src/data/bucket/circle_bucket.ts +11 -14
- package/src/data/bucket/fill_bucket.test.ts +6 -6
- package/src/data/bucket/fill_bucket.ts +10 -12
- package/src/data/bucket/fill_extrusion_bucket.ts +11 -13
- package/src/data/bucket/heatmap_bucket.ts +3 -6
- package/src/data/bucket/line_attributes.ts +1 -2
- package/src/data/bucket/line_attributes_ext.ts +1 -2
- package/src/data/bucket/line_bucket.test.ts +5 -5
- package/src/data/bucket/line_bucket.ts +18 -21
- package/src/data/bucket/pattern_attributes.ts +1 -3
- package/src/data/bucket/pattern_bucket_features.ts +3 -3
- package/src/data/bucket/symbol_bucket.test.ts +5 -5
- package/src/data/bucket/symbol_bucket.ts +12 -15
- package/src/data/bucket.ts +7 -11
- package/src/data/dem_data.test.ts +1 -1
- package/src/data/dem_data.ts +1 -1
- package/src/data/evaluation_feature.ts +4 -5
- package/src/data/extent.ts +1 -4
- package/src/data/feature_index.ts +14 -13
- package/src/data/feature_position_map.test.ts +4 -4
- package/src/data/feature_position_map.ts +1 -1
- package/src/data/index_array_type.ts +0 -1
- package/src/data/load_geometry.test.ts +1 -1
- package/src/data/load_geometry.ts +3 -4
- package/src/data/program_configuration.ts +6 -11
- package/src/data/segment.ts +9 -6
- package/src/geo/edge_insets.test.ts +1 -1
- package/src/geo/edge_insets.ts +36 -26
- package/src/geo/lng_lat.test.ts +1 -1
- package/src/geo/lng_lat.ts +61 -44
- package/src/geo/lng_lat_bounds.test.ts +2 -2
- package/src/geo/lng_lat_bounds.ts +88 -68
- package/src/geo/mercator_coordinate.test.ts +2 -2
- package/src/geo/mercator_coordinate.ts +34 -27
- package/src/geo/transform.test.ts +3 -3
- package/src/geo/transform.ts +58 -79
- package/src/gl/color_mode.ts +1 -3
- package/src/gl/context.ts +12 -11
- package/src/gl/cull_face_mode.ts +1 -3
- package/src/gl/depth_mode.ts +1 -3
- package/src/gl/framebuffer.ts +5 -4
- package/src/gl/index_buffer.ts +5 -4
- package/src/gl/render_pool.test.ts +2 -2
- package/src/gl/render_pool.ts +5 -5
- package/src/gl/state.test.ts +1 -1
- package/src/gl/stencil_mode.ts +1 -3
- package/src/gl/value.ts +1 -1
- package/src/gl/vertex_buffer.test.ts +2 -2
- package/src/gl/vertex_buffer.ts +8 -14
- package/src/index.test.ts +2 -2
- package/src/index.ts +121 -113
- package/src/render/draw_background.ts +7 -9
- package/src/render/draw_circle.ts +13 -15
- package/src/render/draw_collision_debug.ts +11 -13
- package/src/render/draw_custom.ts +6 -8
- package/src/render/draw_debug.test.ts +4 -4
- package/src/render/draw_debug.ts +8 -10
- package/src/render/draw_fill.test.ts +13 -13
- package/src/render/draw_fill.ts +9 -11
- package/src/render/draw_fill_extrusion.ts +10 -12
- package/src/render/draw_heatmap.ts +12 -14
- package/src/render/draw_hillshade.ts +10 -12
- package/src/render/draw_line.ts +9 -9
- package/src/render/draw_raster.ts +9 -11
- package/src/render/draw_symbol.test.ts +16 -16
- package/src/render/draw_symbol.ts +15 -16
- package/src/render/draw_terrain.ts +11 -11
- package/src/render/glyph_atlas.ts +10 -1
- package/src/render/glyph_manager.test.ts +3 -3
- package/src/render/glyph_manager.ts +7 -7
- package/src/render/image_atlas.ts +6 -3
- package/src/render/image_manager.ts +3 -5
- package/src/render/line_atlas.test.ts +1 -1
- package/src/render/line_atlas.ts +19 -14
- package/src/render/painter.ts +85 -65
- package/src/render/program/background_program.ts +2 -2
- package/src/render/program/circle_program.ts +5 -5
- package/src/render/program/clipping_mask_program.ts +1 -1
- package/src/render/program/collision_program.ts +4 -4
- package/src/render/program/debug_program.ts +1 -1
- package/src/render/program/fill_extrusion_program.ts +3 -3
- package/src/render/program/fill_program.ts +3 -3
- package/src/render/program/heatmap_program.ts +5 -5
- package/src/render/program/hillshade_program.ts +7 -7
- package/src/render/program/line_program.ts +6 -6
- package/src/render/program/pattern.ts +3 -3
- package/src/render/program/raster_program.ts +2 -2
- package/src/render/program/symbol_program.ts +2 -2
- package/src/render/program/terrain_program.ts +1 -1
- package/src/render/program.ts +18 -16
- package/src/render/render_to_texture.test.ts +15 -15
- package/src/render/render_to_texture.ts +10 -10
- package/src/render/terrain.test.ts +38 -7
- package/src/render/terrain.ts +103 -67
- package/src/render/texture.ts +5 -4
- package/src/render/uniform_binding.test.ts +1 -1
- package/src/render/uniform_binding.ts +7 -1
- package/src/render/update_pattern_positions_in_program.ts +5 -5
- package/src/render/vertex_array_object.ts +9 -8
- package/src/shaders/encode_attribute.ts +0 -2
- package/src/shaders/shaders.ts +1 -3
- package/src/source/canvas_source.test.ts +6 -6
- package/src/source/canvas_source.ts +46 -60
- package/src/source/geojson_source.test.ts +5 -5
- package/src/source/geojson_source.ts +75 -59
- package/src/source/geojson_source_diff.ts +39 -2
- package/src/source/geojson_worker_source.test.ts +3 -3
- package/src/source/geojson_worker_source.ts +20 -26
- package/src/source/geojson_wrapper.test.ts +3 -3
- package/src/source/geojson_wrapper.ts +2 -4
- package/src/source/image_source.test.ts +9 -8
- package/src/source/image_source.ts +49 -35
- package/src/source/load_tilejson.ts +2 -2
- package/src/source/pixels_to_tile_units.ts +2 -3
- package/src/source/query_features.test.ts +3 -3
- package/src/source/query_features.ts +50 -19
- package/src/source/raster_dem_tile_source.test.ts +3 -3
- package/src/source/raster_dem_tile_source.ts +23 -10
- package/src/source/raster_dem_tile_worker_source.test.ts +2 -2
- package/src/source/raster_dem_tile_worker_source.ts +3 -5
- package/src/source/raster_tile_source.test.ts +3 -3
- package/src/source/raster_tile_source.ts +38 -11
- package/src/source/rtl_text_plugin.ts +4 -1
- package/src/source/source.ts +67 -59
- package/src/source/source_cache.test.ts +7 -7
- package/src/source/source_cache.ts +17 -38
- package/src/source/source_state.ts +2 -5
- package/src/source/terrain_source_cache.test.ts +8 -8
- package/src/source/terrain_source_cache.ts +42 -27
- package/src/source/tile.test.ts +3 -3
- package/src/source/tile.ts +32 -38
- package/src/source/tile_bounds.ts +2 -4
- package/src/source/tile_cache.test.ts +2 -2
- package/src/source/tile_cache.ts +20 -30
- package/src/source/tile_id.ts +11 -2
- package/src/source/vector_tile_source.test.ts +3 -3
- package/src/source/vector_tile_source.ts +34 -24
- package/src/source/vector_tile_worker_source.test.ts +4 -4
- package/src/source/vector_tile_worker_source.ts +11 -23
- package/src/source/video_source.test.ts +5 -5
- package/src/source/video_source.ts +21 -28
- package/src/source/worker.ts +6 -8
- package/src/source/worker_source.ts +6 -8
- package/src/source/worker_tile.test.ts +5 -5
- package/src/source/worker_tile.ts +13 -16
- package/src/style/create_style_layer.ts +31 -26
- package/src/style/evaluation_parameters.ts +5 -4
- package/src/style/format_section_override.test.ts +2 -2
- package/src/style/format_section_override.ts +1 -1
- package/src/style/light.test.ts +2 -2
- package/src/style/light.ts +3 -5
- package/src/style/load_glyph_range.test.ts +1 -1
- package/src/style/load_glyph_range.ts +3 -3
- package/src/style/load_sprite.test.ts +1 -1
- package/src/style/load_sprite.ts +3 -3
- package/src/style/parse_glyph_pbf.ts +1 -1
- package/src/style/pauseable_placement.ts +7 -9
- package/src/style/properties.ts +4 -53
- package/src/style/query_utils.ts +3 -3
- package/src/style/style.test.ts +22 -19
- package/src/style/style.ts +118 -84
- package/src/style/style_glyph.ts +6 -0
- package/src/style/style_image.ts +39 -33
- package/src/style/style_layer/background_style_layer.ts +2 -4
- package/src/style/style_layer/circle_style_layer.ts +7 -6
- package/src/style/style_layer/custom_style_layer.ts +23 -48
- package/src/style/style_layer/fill_extrusion_style_layer.ts +4 -6
- package/src/style/style_layer/fill_style_layer.ts +5 -7
- package/src/style/style_layer/heatmap_style_layer.ts +8 -7
- package/src/style/style_layer/hillshade_style_layer.ts +2 -4
- package/src/style/style_layer/line_style_layer.ts +6 -8
- package/src/style/style_layer/overlap_mode.test.ts +3 -3
- package/src/style/style_layer/overlap_mode.ts +3 -0
- package/src/style/style_layer/raster_style_layer.ts +2 -4
- package/src/style/style_layer/symbol_style_layer.ts +6 -8
- package/src/style/style_layer/typed_style_layer.ts +7 -7
- package/src/style/style_layer.test.ts +5 -5
- package/src/style/style_layer.ts +7 -6
- package/src/style/style_layer_index.test.ts +1 -1
- package/src/style/style_layer_index.ts +3 -5
- package/src/style/zoom_history.ts +1 -3
- package/src/symbol/anchor.test.ts +1 -1
- package/src/symbol/anchor.ts +1 -3
- package/src/symbol/check_max_angle.test.ts +8 -2
- package/src/symbol/check_max_angle.ts +10 -13
- package/src/symbol/clip_line.test.ts +1 -1
- package/src/symbol/clip_line.ts +6 -9
- package/src/symbol/collision_feature.test.ts +2 -2
- package/src/symbol/collision_feature.ts +7 -12
- package/src/symbol/collision_index.test.ts +2 -2
- package/src/symbol/collision_index.ts +5 -11
- package/src/symbol/cross_tile_symbol_index.test.ts +2 -2
- package/src/symbol/cross_tile_symbol_index.ts +5 -7
- package/src/symbol/get_anchors.ts +2 -2
- package/src/symbol/grid_index.test.ts +1 -1
- package/src/symbol/grid_index.ts +4 -5
- package/src/symbol/merge_lines.test.ts +1 -1
- package/src/symbol/merge_lines.ts +1 -1
- package/src/symbol/opacity_state.ts +1 -3
- package/src/symbol/path_interpolator.test.ts +1 -1
- package/src/symbol/path_interpolator.ts +1 -3
- package/src/symbol/placement.ts +9 -9
- package/src/symbol/projection.ts +61 -34
- package/src/symbol/quads.ts +7 -11
- package/src/symbol/shaping.ts +1 -1
- package/src/symbol/symbol_layout.ts +9 -12
- package/src/symbol/symbol_size.ts +1 -1
- package/src/symbol/symbol_style_layer.test.ts +4 -4
- package/src/symbol/transform_text.ts +2 -2
- package/src/types/callback.ts +14 -14
- package/src/types/cancelable.ts +3 -0
- package/src/types/transferable.ts +3 -0
- package/src/ui/anchor.ts +4 -0
- package/src/ui/camera.test.ts +6 -6
- package/src/ui/camera.ts +392 -361
- package/src/ui/control/attribution_control.test.ts +1 -1
- package/src/ui/control/attribution_control.ts +34 -30
- package/src/ui/control/control.ts +14 -20
- package/src/ui/control/fullscreen_control.test.ts +1 -1
- package/src/ui/control/fullscreen_control.ts +21 -26
- package/src/ui/control/geolocate_control.test.ts +5 -5
- package/src/ui/control/geolocate_control.ts +181 -194
- package/src/ui/control/logo_control.ts +20 -16
- package/src/ui/control/navigation_control.test.ts +1 -1
- package/src/ui/control/navigation_control.ts +46 -42
- package/src/ui/control/scale_control.test.ts +1 -1
- package/src/ui/control/scale_control.ts +30 -21
- package/src/ui/control/terrain_control.test.ts +1 -1
- package/src/ui/control/terrain_control.ts +14 -18
- package/src/ui/default_locale.ts +1 -3
- package/src/ui/events.ts +570 -1281
- package/src/ui/handler/box_zoom.test.ts +2 -2
- package/src/ui/handler/box_zoom.ts +16 -11
- package/src/ui/handler/click_zoom.ts +11 -3
- package/src/ui/handler/cooperative_gestures.test.ts +3 -3
- package/src/ui/handler/dblclick_zoom.test.ts +1 -1
- package/src/ui/handler/drag_handler.ts +30 -22
- package/src/ui/handler/drag_move_state_manager.ts +1 -1
- package/src/ui/handler/drag_pan.test.ts +2 -2
- package/src/ui/handler/drag_rotate.test.ts +3 -3
- package/src/ui/handler/keyboard.test.ts +2 -2
- package/src/ui/handler/keyboard.ts +22 -13
- package/src/ui/handler/map_event.test.ts +2 -2
- 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 +3 -3
- package/src/ui/handler/scroll_zoom.test.ts +3 -3
- package/src/ui/handler/scroll_zoom.ts +45 -52
- package/src/ui/handler/shim/dblclick_zoom.ts +12 -6
- package/src/ui/handler/shim/drag_pan.ts +34 -14
- package/src/ui/handler/shim/drag_rotate.ts +20 -12
- package/src/ui/handler/shim/two_fingers_touch.ts +24 -18
- package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
- package/src/ui/handler/tap_drag_zoom.ts +18 -10
- package/src/ui/handler/tap_recognizer.ts +1 -1
- package/src/ui/handler/tap_zoom.ts +4 -3
- package/src/ui/handler/touch_pan.ts +3 -2
- package/src/ui/handler/transform-provider.ts +4 -6
- package/src/ui/handler/two_fingers_touch.test.ts +3 -3
- package/src/ui/handler/two_fingers_touch.ts +64 -47
- package/src/ui/handler_inertia.ts +4 -4
- package/src/ui/handler_manager.ts +86 -52
- package/src/ui/hash.test.ts +1 -1
- package/src/ui/hash.ts +21 -28
- package/src/ui/map/isMoving.test.ts +3 -3
- package/src/ui/map/isRotating.test.ts +3 -3
- package/src/ui/map/isZooming.test.ts +3 -3
- package/src/ui/map.test.ts +97 -8
- package/src/ui/map.ts +856 -702
- package/src/ui/map_events.test.ts +1 -1
- package/src/ui/marker.test.ts +35 -15
- package/src/ui/marker.ts +220 -141
- package/src/ui/popup.test.ts +2 -2
- package/src/ui/popup.ts +179 -147
- package/src/util/actor.test.ts +7 -7
- package/src/util/actor.ts +25 -22
- package/src/util/ajax.ts +37 -17
- package/src/util/browser.test.ts +1 -1
- package/src/util/browser.ts +2 -6
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/classify_rings.ts +1 -1
- package/src/util/color_ramp.ts +0 -2
- package/src/util/config.ts +6 -3
- package/src/util/debug.ts +0 -2
- package/src/util/dictionary_coder.ts +1 -4
- package/src/util/dispatcher.test.ts +3 -3
- package/src/util/dispatcher.ts +4 -9
- package/src/util/dom.ts +1 -1
- package/src/util/evented.ts +23 -18
- package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +4 -5
- package/src/util/global_worker_pool.ts +2 -3
- package/src/util/image.ts +10 -4
- package/src/util/image_request.test.ts +3 -3
- package/src/util/image_request.ts +15 -14
- package/src/util/is_char_in_unicode_block.ts +1 -3
- package/src/util/offscreen_canvas_supported.ts +1 -1
- package/src/util/performance.ts +1 -2
- package/src/util/request_manager.ts +4 -0
- package/src/util/resolve_tokens.test.ts +1 -1
- package/src/util/resolve_tokens.ts +3 -6
- package/src/util/script_detection.ts +1 -4
- package/src/util/smart_wrap.ts +3 -5
- package/src/util/struct_array.ts +18 -14
- package/src/util/style.ts +2 -2
- package/src/util/task_queue.test.ts +1 -1
- package/src/util/task_queue.ts +1 -3
- package/src/util/test/mock_webgl.ts +6 -0
- package/src/util/test/util.ts +2 -2
- package/src/util/throttle.test.ts +1 -1
- package/src/util/throttle.ts +1 -2
- package/src/util/throttled_invoker.ts +1 -5
- package/src/util/transferable_grid_index.test.ts +1 -1
- package/src/util/transferable_grid_index.ts +1 -3
- package/src/util/util.test.ts +1 -14
- package/src/util/util.ts +44 -107
- package/src/util/vectortile_to_geojson.ts +13 -3
- package/src/util/verticalize_punctuation.ts +1 -1
- package/src/util/web_worker.ts +2 -2
- package/src/util/web_worker_transfer.ts +11 -8
- package/src/util/webp_supported.ts +2 -4
- package/src/util/worker_pool.test.ts +1 -1
- package/src/util/worker_pool.ts +4 -5
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import Point from '@mapbox/point-geometry';
|
|
2
2
|
|
|
3
|
-
import DOM from '../../util/dom';
|
|
4
|
-
import {extend
|
|
3
|
+
import {DOM} from '../../util/dom';
|
|
4
|
+
import {extend} from '../../util/util';
|
|
5
5
|
import {generateMousePitchHandler, generateMouseRotationHandler, MousePitchHandler, MouseRotateHandler} from '../handler/mouse';
|
|
6
6
|
import {generateOneFingerTouchPitchHandler, generateOneFingerTouchRotationHandler, OneFingerTouchPitchHandler, OneFingerTouchRotateHandler} from '../handler/one_finger_touch_drag';
|
|
7
7
|
|
|
8
|
-
import type Map from '../map';
|
|
8
|
+
import type {Map} from '../map';
|
|
9
9
|
import type {IControl} from './control';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The {@link NavigationControl} options object
|
|
13
|
+
*/
|
|
11
14
|
type NavigationOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* If `true` the compass button is included.
|
|
17
|
+
*/
|
|
12
18
|
showCompass?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* If `true` the zoom-in and zoom-out buttons are included.
|
|
21
|
+
*/
|
|
13
22
|
showZoom?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* If `true` the pitch is visualized by rotating X-axis of compass.
|
|
25
|
+
*/
|
|
14
26
|
visualizePitch?: boolean;
|
|
15
27
|
};
|
|
16
28
|
|
|
@@ -23,18 +35,17 @@ const defaultOptions: NavigationOptions = {
|
|
|
23
35
|
/**
|
|
24
36
|
* A `NavigationControl` control contains zoom buttons and a compass.
|
|
25
37
|
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* @param {boolean} [options.showCompass=true] If `true` the compass button is included.
|
|
29
|
-
* @param {boolean} [options.showZoom=true] If `true` the zoom-in and zoom-out buttons are included.
|
|
30
|
-
* @param {boolean} [options.visualizePitch=false] If `true` the pitch is visualized by rotating X-axis of compass.
|
|
38
|
+
* @group Markers and Controls
|
|
39
|
+
*
|
|
31
40
|
* @example
|
|
32
|
-
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* let nav = new maplibregl.NavigationControl();
|
|
33
43
|
* map.addControl(nav, 'top-left');
|
|
34
|
-
*
|
|
35
|
-
* @see [
|
|
44
|
+
* ```
|
|
45
|
+
* @see [Display map navigation controls](https://maplibre.org/maplibre-gl-js/docs/examples/navigation/)
|
|
46
|
+
* @see [Add a third party vector tile source](https://maplibre.org/maplibre-gl-js/docs/examples/third-party/)
|
|
36
47
|
*/
|
|
37
|
-
class NavigationControl implements IControl {
|
|
48
|
+
export class NavigationControl implements IControl {
|
|
38
49
|
_map: Map;
|
|
39
50
|
options: NavigationOptions;
|
|
40
51
|
_container: HTMLElement;
|
|
@@ -44,6 +55,9 @@ class NavigationControl implements IControl {
|
|
|
44
55
|
_compassIcon: HTMLElement;
|
|
45
56
|
_handler: MouseRotateWrapper;
|
|
46
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @param options - the control's options
|
|
60
|
+
*/
|
|
47
61
|
constructor(options?: NavigationOptions) {
|
|
48
62
|
this.options = extend({}, defaultOptions, options);
|
|
49
63
|
|
|
@@ -51,19 +65,12 @@ class NavigationControl implements IControl {
|
|
|
51
65
|
this._container.addEventListener('contextmenu', (e) => e.preventDefault());
|
|
52
66
|
|
|
53
67
|
if (this.options.showZoom) {
|
|
54
|
-
bindAll([
|
|
55
|
-
'_setButtonTitle',
|
|
56
|
-
'_updateZoomButtons'
|
|
57
|
-
], this);
|
|
58
68
|
this._zoomInButton = this._createButton('maplibregl-ctrl-zoom-in', (e) => this._map.zoomIn({}, {originalEvent: e}));
|
|
59
69
|
DOM.create('span', 'maplibregl-ctrl-icon', this._zoomInButton).setAttribute('aria-hidden', 'true');
|
|
60
70
|
this._zoomOutButton = this._createButton('maplibregl-ctrl-zoom-out', (e) => this._map.zoomOut({}, {originalEvent: e}));
|
|
61
71
|
DOM.create('span', 'maplibregl-ctrl-icon', this._zoomOutButton).setAttribute('aria-hidden', 'true');
|
|
62
72
|
}
|
|
63
73
|
if (this.options.showCompass) {
|
|
64
|
-
bindAll([
|
|
65
|
-
'_rotateCompassArrow'
|
|
66
|
-
], this);
|
|
67
74
|
this._compass = this._createButton('maplibregl-ctrl-compass', (e) => {
|
|
68
75
|
if (this.options.visualizePitch) {
|
|
69
76
|
this._map.resetNorthPitch({}, {originalEvent: e});
|
|
@@ -76,7 +83,7 @@ class NavigationControl implements IControl {
|
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
85
|
|
|
79
|
-
_updateZoomButtons() {
|
|
86
|
+
_updateZoomButtons = () => {
|
|
80
87
|
const zoom = this._map.getZoom();
|
|
81
88
|
const isMax = zoom === this._map.getMaxZoom();
|
|
82
89
|
const isMin = zoom === this._map.getMinZoom();
|
|
@@ -84,15 +91,15 @@ class NavigationControl implements IControl {
|
|
|
84
91
|
this._zoomOutButton.disabled = isMin;
|
|
85
92
|
this._zoomInButton.setAttribute('aria-disabled', isMax.toString());
|
|
86
93
|
this._zoomOutButton.setAttribute('aria-disabled', isMin.toString());
|
|
87
|
-
}
|
|
94
|
+
};
|
|
88
95
|
|
|
89
|
-
_rotateCompassArrow() {
|
|
96
|
+
_rotateCompassArrow = () => {
|
|
90
97
|
const rotate = this.options.visualizePitch ?
|
|
91
98
|
`scale(${1 / Math.pow(Math.cos(this._map.transform.pitch * (Math.PI / 180)), 0.5)}) rotateX(${this._map.transform.pitch}deg) rotateZ(${this._map.transform.angle * (180 / Math.PI)}deg)` :
|
|
92
99
|
`rotate(${this._map.transform.angle * (180 / Math.PI)}deg)`;
|
|
93
100
|
|
|
94
101
|
this._compassIcon.style.transform = rotate;
|
|
95
|
-
}
|
|
102
|
+
};
|
|
96
103
|
|
|
97
104
|
onAdd(map: Map) {
|
|
98
105
|
this._map = map;
|
|
@@ -138,11 +145,11 @@ class NavigationControl implements IControl {
|
|
|
138
145
|
return a;
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
_setButtonTitle(button: HTMLButtonElement, title: string) {
|
|
148
|
+
_setButtonTitle = (button: HTMLButtonElement, title: string) => {
|
|
142
149
|
const str = this._map._getUIString(`NavigationControl.${title}`);
|
|
143
150
|
button.title = str;
|
|
144
151
|
button.setAttribute('aria-label', str);
|
|
145
|
-
}
|
|
152
|
+
};
|
|
146
153
|
}
|
|
147
154
|
|
|
148
155
|
class MouseRotateWrapper {
|
|
@@ -171,7 +178,6 @@ class MouseRotateWrapper {
|
|
|
171
178
|
this.touchPitch = generateOneFingerTouchPitchHandler({clickTolerance: mapPitchTolerance, enable: true});
|
|
172
179
|
}
|
|
173
180
|
|
|
174
|
-
bindAll(['mousedown', 'mousemove', 'mouseup', 'touchstart', 'touchmove', 'touchend', 'reset'], this);
|
|
175
181
|
DOM.addEventListener(element, 'mousedown', this.mousedown);
|
|
176
182
|
DOM.addEventListener(element, 'touchstart', this.touchstart, {passive: false});
|
|
177
183
|
DOM.addEventListener(element, 'touchcancel', this.reset);
|
|
@@ -227,23 +233,23 @@ class MouseRotateWrapper {
|
|
|
227
233
|
DOM.removeEventListener(window, 'touchend', this.touchend);
|
|
228
234
|
}
|
|
229
235
|
|
|
230
|
-
mousedown(e: MouseEvent) {
|
|
236
|
+
mousedown = (e: MouseEvent) => {
|
|
231
237
|
this.startMouse(extend({}, e, {ctrlKey: true, preventDefault: () => e.preventDefault()}), DOM.mousePos(this.element, e));
|
|
232
238
|
DOM.addEventListener(window, 'mousemove', this.mousemove);
|
|
233
239
|
DOM.addEventListener(window, 'mouseup', this.mouseup);
|
|
234
|
-
}
|
|
240
|
+
};
|
|
235
241
|
|
|
236
|
-
mousemove(e: MouseEvent) {
|
|
242
|
+
mousemove = (e: MouseEvent) => {
|
|
237
243
|
this.moveMouse(e, DOM.mousePos(this.element, e));
|
|
238
|
-
}
|
|
244
|
+
};
|
|
239
245
|
|
|
240
|
-
mouseup(e: MouseEvent) {
|
|
246
|
+
mouseup = (e: MouseEvent) => {
|
|
241
247
|
this.mouseRotate.dragEnd(e);
|
|
242
248
|
if (this.mousePitch) this.mousePitch.dragEnd(e);
|
|
243
249
|
this.offTemp();
|
|
244
|
-
}
|
|
250
|
+
};
|
|
245
251
|
|
|
246
|
-
touchstart(e: TouchEvent) {
|
|
252
|
+
touchstart = (e: TouchEvent) => {
|
|
247
253
|
if (e.targetTouches.length !== 1) {
|
|
248
254
|
this.reset();
|
|
249
255
|
} else {
|
|
@@ -252,18 +258,18 @@ class MouseRotateWrapper {
|
|
|
252
258
|
DOM.addEventListener(window, 'touchmove', this.touchmove, {passive: false});
|
|
253
259
|
DOM.addEventListener(window, 'touchend', this.touchend);
|
|
254
260
|
}
|
|
255
|
-
}
|
|
261
|
+
};
|
|
256
262
|
|
|
257
|
-
touchmove(e: TouchEvent) {
|
|
263
|
+
touchmove = (e: TouchEvent) => {
|
|
258
264
|
if (e.targetTouches.length !== 1) {
|
|
259
265
|
this.reset();
|
|
260
266
|
} else {
|
|
261
267
|
this._lastPos = DOM.touchPos(this.element, e.targetTouches)[0];
|
|
262
268
|
this.moveTouch(e, this._lastPos);
|
|
263
269
|
}
|
|
264
|
-
}
|
|
270
|
+
};
|
|
265
271
|
|
|
266
|
-
touchend(e: TouchEvent) {
|
|
272
|
+
touchend = (e: TouchEvent) => {
|
|
267
273
|
if (e.targetTouches.length === 0 &&
|
|
268
274
|
this._startPos &&
|
|
269
275
|
this._lastPos &&
|
|
@@ -273,9 +279,9 @@ class MouseRotateWrapper {
|
|
|
273
279
|
delete this._startPos;
|
|
274
280
|
delete this._lastPos;
|
|
275
281
|
this.offTemp();
|
|
276
|
-
}
|
|
282
|
+
};
|
|
277
283
|
|
|
278
|
-
reset() {
|
|
284
|
+
reset = () => {
|
|
279
285
|
this.mouseRotate.reset();
|
|
280
286
|
if (this.mousePitch) this.mousePitch.reset();
|
|
281
287
|
this.touchRotate.reset();
|
|
@@ -283,7 +289,5 @@ class MouseRotateWrapper {
|
|
|
283
289
|
delete this._startPos;
|
|
284
290
|
delete this._lastPos;
|
|
285
291
|
this.offTemp();
|
|
286
|
-
}
|
|
292
|
+
};
|
|
287
293
|
}
|
|
288
|
-
|
|
289
|
-
export default NavigationControl;
|
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
import DOM from '../../util/dom';
|
|
2
|
-
import {extend
|
|
1
|
+
import {DOM} from '../../util/dom';
|
|
2
|
+
import {extend} from '../../util/util';
|
|
3
3
|
|
|
4
|
-
import type Map from '../map';
|
|
4
|
+
import type {Map} from '../map';
|
|
5
5
|
import type {ControlPosition, IControl} from './control';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* The unit type for length to use for the {@link ScaleControl}
|
|
9
|
+
*/
|
|
7
10
|
export type Unit = 'imperial' | 'metric' | 'nautical';
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The {@link ScaleControl} options object
|
|
14
|
+
*/
|
|
9
15
|
type ScaleOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* The maximum length of the scale control in pixels.
|
|
18
|
+
* @defaultValue 100
|
|
19
|
+
*/
|
|
10
20
|
maxWidth?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Unit of the distance (`'imperial'`, `'metric'` or `'nautical'`).
|
|
23
|
+
* @defaultValue 'metric'
|
|
24
|
+
*/
|
|
11
25
|
unit?: Unit;
|
|
12
26
|
};
|
|
13
27
|
|
|
@@ -19,41 +33,37 @@ const defaultOptions: ScaleOptions = {
|
|
|
19
33
|
/**
|
|
20
34
|
* A `ScaleControl` control displays the ratio of a distance on the map to the corresponding distance on the ground.
|
|
21
35
|
*
|
|
22
|
-
* @
|
|
23
|
-
*
|
|
24
|
-
* @param {number} [options.maxWidth='100'] The maximum length of the scale control in pixels.
|
|
25
|
-
* @param {string} [options.unit='metric'] Unit of the distance (`'imperial'`, `'metric'` or `'nautical'`).
|
|
36
|
+
* @group Markers and Controls
|
|
37
|
+
*
|
|
26
38
|
* @example
|
|
27
|
-
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* let scale = new maplibregl.ScaleControl({
|
|
28
41
|
* maxWidth: 80,
|
|
29
42
|
* unit: 'imperial'
|
|
30
43
|
* });
|
|
31
44
|
* map.addControl(scale);
|
|
32
45
|
*
|
|
33
46
|
* scale.setUnit('metric');
|
|
47
|
+
* ```
|
|
34
48
|
*/
|
|
35
|
-
class ScaleControl implements IControl {
|
|
49
|
+
export class ScaleControl implements IControl {
|
|
36
50
|
_map: Map;
|
|
37
51
|
_container: HTMLElement;
|
|
38
52
|
options: ScaleOptions;
|
|
39
53
|
|
|
40
54
|
constructor(options: ScaleOptions) {
|
|
41
55
|
this.options = extend({}, defaultOptions, options);
|
|
42
|
-
|
|
43
|
-
bindAll([
|
|
44
|
-
'_onMove',
|
|
45
|
-
'setUnit'
|
|
46
|
-
], this);
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
getDefaultPosition(): ControlPosition {
|
|
50
59
|
return 'bottom-left';
|
|
51
60
|
}
|
|
52
61
|
|
|
53
|
-
_onMove() {
|
|
62
|
+
_onMove = () => {
|
|
54
63
|
updateScale(this._map, this._container, this.options);
|
|
55
|
-
}
|
|
64
|
+
};
|
|
56
65
|
|
|
66
|
+
/** {@inheritDoc IControl.onAdd} */
|
|
57
67
|
onAdd(map: Map) {
|
|
58
68
|
this._map = map;
|
|
59
69
|
this._container = DOM.create('div', 'maplibregl-ctrl maplibregl-ctrl-scale', map.getContainer());
|
|
@@ -64,6 +74,7 @@ class ScaleControl implements IControl {
|
|
|
64
74
|
return this._container;
|
|
65
75
|
}
|
|
66
76
|
|
|
77
|
+
/** {@inheritDoc IControl.onRemove} */
|
|
67
78
|
onRemove() {
|
|
68
79
|
DOM.remove(this._container);
|
|
69
80
|
this._map.off('move', this._onMove);
|
|
@@ -73,16 +84,14 @@ class ScaleControl implements IControl {
|
|
|
73
84
|
/**
|
|
74
85
|
* Set the scale's unit of the distance
|
|
75
86
|
*
|
|
76
|
-
* @param unit Unit of the distance (`'imperial'`, `'metric'` or `'nautical'`).
|
|
87
|
+
* @param unit - Unit of the distance (`'imperial'`, `'metric'` or `'nautical'`).
|
|
77
88
|
*/
|
|
78
|
-
setUnit(unit: Unit) {
|
|
89
|
+
setUnit = (unit: Unit) => {
|
|
79
90
|
this.options.unit = unit;
|
|
80
91
|
updateScale(this._map, this._container, this.options);
|
|
81
|
-
}
|
|
92
|
+
};
|
|
82
93
|
}
|
|
83
94
|
|
|
84
|
-
export default ScaleControl;
|
|
85
|
-
|
|
86
95
|
function updateScale(map, container, options) {
|
|
87
96
|
// A horizontal scale is imagined to be present at center of the map
|
|
88
97
|
// container with maximum length (Default) as 100px.
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import DOM from '../../util/dom';
|
|
2
|
-
import {bindAll} from '../../util/util';
|
|
1
|
+
import {DOM} from '../../util/dom';
|
|
3
2
|
|
|
4
|
-
import type Map from '../map';
|
|
3
|
+
import type {Map} from '../map';
|
|
5
4
|
import type {IControl} from './control';
|
|
6
5
|
import type {TerrainSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* A `TerrainControl` control contains a button for turning the terrain on and off.
|
|
10
9
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
* @param {string} [options.source] The ID of the raster-dem source to use.
|
|
14
|
-
* @param {number} [options.exaggeration]
|
|
10
|
+
* @group Markers and Controls
|
|
11
|
+
*
|
|
15
12
|
* @example
|
|
16
|
-
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* let map = new maplibregl.Map({TerrainControl: false})
|
|
17
15
|
* .addControl(new maplibregl.TerrainControl({
|
|
18
16
|
* source: "terrain"
|
|
19
17
|
* }));
|
|
18
|
+
* ```
|
|
20
19
|
*/
|
|
21
|
-
export
|
|
20
|
+
export class TerrainControl implements IControl {
|
|
22
21
|
options: TerrainSpecification;
|
|
23
22
|
_map: Map;
|
|
24
23
|
_container: HTMLElement;
|
|
@@ -26,13 +25,9 @@ export default class TerrainControl implements IControl {
|
|
|
26
25
|
|
|
27
26
|
constructor(options: TerrainSpecification) {
|
|
28
27
|
this.options = options;
|
|
29
|
-
|
|
30
|
-
bindAll([
|
|
31
|
-
'_toggleTerrain',
|
|
32
|
-
'_updateTerrainIcon',
|
|
33
|
-
], this);
|
|
34
28
|
}
|
|
35
29
|
|
|
30
|
+
/** {@inheritDoc IControl.onAdd} */
|
|
36
31
|
onAdd(map: Map) {
|
|
37
32
|
this._map = map;
|
|
38
33
|
this._container = DOM.create('div', 'maplibregl-ctrl maplibregl-ctrl-group');
|
|
@@ -46,22 +41,23 @@ export default class TerrainControl implements IControl {
|
|
|
46
41
|
return this._container;
|
|
47
42
|
}
|
|
48
43
|
|
|
44
|
+
/** {@inheritDoc IControl.onRemove} */
|
|
49
45
|
onRemove() {
|
|
50
46
|
DOM.remove(this._container);
|
|
51
47
|
this._map.off('terrain', this._updateTerrainIcon);
|
|
52
48
|
this._map = undefined;
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
_toggleTerrain() {
|
|
51
|
+
_toggleTerrain = () => {
|
|
56
52
|
if (this._map.getTerrain()) {
|
|
57
53
|
this._map.setTerrain(null);
|
|
58
54
|
} else {
|
|
59
55
|
this._map.setTerrain(this.options);
|
|
60
56
|
}
|
|
61
57
|
this._updateTerrainIcon();
|
|
62
|
-
}
|
|
58
|
+
};
|
|
63
59
|
|
|
64
|
-
_updateTerrainIcon() {
|
|
60
|
+
_updateTerrainIcon = () => {
|
|
65
61
|
this._terrainButton.classList.remove('maplibregl-ctrl-terrain');
|
|
66
62
|
this._terrainButton.classList.remove('maplibregl-ctrl-terrain-enabled');
|
|
67
63
|
if (this._map.terrain) {
|
|
@@ -71,5 +67,5 @@ export default class TerrainControl implements IControl {
|
|
|
71
67
|
this._terrainButton.classList.add('maplibregl-ctrl-terrain');
|
|
72
68
|
this._terrainButton.title = this._map._getUIString('TerrainControl.enableTerrain');
|
|
73
69
|
}
|
|
74
|
-
}
|
|
70
|
+
};
|
|
75
71
|
}
|
package/src/ui/default_locale.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const defaultLocale = {
|
|
1
|
+
export const defaultLocale = {
|
|
2
2
|
'AttributionControl.ToggleAttribution': 'Toggle attribution',
|
|
3
3
|
'AttributionControl.MapFeedback': 'Map feedback',
|
|
4
4
|
'FullscreenControl.Enter': 'Enter fullscreen',
|
|
@@ -17,5 +17,3 @@ const defaultLocale = {
|
|
|
17
17
|
'TerrainControl.enableTerrain': 'Enable terrain',
|
|
18
18
|
'TerrainControl.disableTerrain': 'Disable terrain'
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
export default defaultLocale;
|