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
package/src/ui/map.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import {extend,
|
|
2
|
-
import browser from '../util/browser';
|
|
3
|
-
import DOM from '../util/dom';
|
|
1
|
+
import {extend, warnOnce, uniqueId, isImageBitmap} from '../util/util';
|
|
2
|
+
import {browser} from '../util/browser';
|
|
3
|
+
import {DOM} from '../util/dom';
|
|
4
4
|
import packageJSON from '../../package.json' assert {type: 'json'};
|
|
5
5
|
|
|
6
6
|
import {getJSON} from '../util/ajax';
|
|
7
|
-
import ImageRequest from '../util/image_request';
|
|
7
|
+
import {ImageRequest} from '../util/image_request';
|
|
8
8
|
import type {GetImageCallback} from '../util/image_request';
|
|
9
9
|
|
|
10
10
|
import {RequestManager, ResourceType} from '../util/request_manager';
|
|
11
|
-
import Style,
|
|
12
|
-
import EvaluationParameters from '../style/evaluation_parameters';
|
|
13
|
-
import Painter from '../render/painter';
|
|
14
|
-
import Transform from '../geo/transform';
|
|
15
|
-
import Hash from './hash';
|
|
16
|
-
import HandlerManager from './handler_manager';
|
|
17
|
-
import Camera,
|
|
18
|
-
import LngLat from '../geo/lng_lat';
|
|
19
|
-
import LngLatBounds from '../geo/lng_lat_bounds';
|
|
11
|
+
import {Style, StyleSwapOptions} from '../style/style';
|
|
12
|
+
import {EvaluationParameters} from '../style/evaluation_parameters';
|
|
13
|
+
import {Painter} from '../render/painter';
|
|
14
|
+
import {Transform} from '../geo/transform';
|
|
15
|
+
import {Hash} from './hash';
|
|
16
|
+
import {HandlerManager} from './handler_manager';
|
|
17
|
+
import {Camera, CameraOptions, CameraUpdateTransformFunction, FitBoundsOptions} from './camera';
|
|
18
|
+
import {LngLat} from '../geo/lng_lat';
|
|
19
|
+
import {LngLatBounds} from '../geo/lng_lat_bounds';
|
|
20
20
|
import Point from '@mapbox/point-geometry';
|
|
21
|
-
import AttributionControl from './control/attribution_control';
|
|
22
|
-
import LogoControl from './control/logo_control';
|
|
21
|
+
import {AttributionControl} from './control/attribution_control';
|
|
22
|
+
import {LogoControl} from './control/logo_control';
|
|
23
23
|
|
|
24
24
|
import {RGBAImage} from '../util/image';
|
|
25
25
|
import {Event, ErrorEvent, Listener} from '../util/evented';
|
|
26
26
|
import {MapEventType, MapLayerEventType, MapMouseEvent, MapSourceDataEvent, MapStyleDataEvent} from './events';
|
|
27
|
-
import TaskQueue from '../util/task_queue';
|
|
28
|
-
import webpSupported from '../util/webp_supported';
|
|
27
|
+
import {TaskQueue} from '../util/task_queue';
|
|
28
|
+
import {webpSupported} from '../util/webp_supported';
|
|
29
29
|
import {PerformanceMarkers, PerformanceUtils} from '../util/performance';
|
|
30
|
-
import {Source} from '../source/source';
|
|
31
|
-
import StyleLayer from '../style/style_layer';
|
|
30
|
+
import {Source, SourceClass} from '../source/source';
|
|
31
|
+
import {StyleLayer} from '../style/style_layer';
|
|
32
32
|
|
|
33
33
|
import type {RequestTransformFunction} from '../util/request_manager';
|
|
34
34
|
import type {LngLatLike} from '../geo/lng_lat';
|
|
35
35
|
import type {LngLatBoundsLike} from '../geo/lng_lat_bounds';
|
|
36
36
|
import type {FeatureIdentifier, StyleOptions, StyleSetterOptions} from '../style/style';
|
|
37
|
-
import type {
|
|
37
|
+
import type {MapDataEvent} from './events';
|
|
38
38
|
import type {CustomLayerInterface} from '../style/style_layer/custom_style_layer';
|
|
39
39
|
import type {StyleImage, StyleImageInterface, StyleImageMetadata} from '../style/style_image';
|
|
40
40
|
import type {PointLike} from './camera';
|
|
41
|
-
import type ScrollZoomHandler from './handler/scroll_zoom';
|
|
42
|
-
import type BoxZoomHandler from './handler/box_zoom';
|
|
43
|
-
import type {TwoFingersTouchPitchHandler} from './handler/two_fingers_touch';
|
|
44
|
-
import type DragRotateHandler from './handler/shim/drag_rotate';
|
|
45
|
-
import DragPanHandler,
|
|
46
|
-
|
|
47
|
-
import type KeyboardHandler from './handler/keyboard';
|
|
48
|
-
import type DoubleClickZoomHandler from './handler/shim/dblclick_zoom';
|
|
49
|
-
import type TwoFingersTouchZoomRotateHandler from './handler/shim/two_fingers_touch';
|
|
50
|
-
import defaultLocale from './default_locale';
|
|
41
|
+
import type {ScrollZoomHandler} from './handler/scroll_zoom';
|
|
42
|
+
import type {BoxZoomHandler} from './handler/box_zoom';
|
|
43
|
+
import type {AroundCenterOptions, TwoFingersTouchPitchHandler} from './handler/two_fingers_touch';
|
|
44
|
+
import type {DragRotateHandler} from './handler/shim/drag_rotate';
|
|
45
|
+
import {DragPanHandler, DragPanOptions} from './handler/shim/drag_pan';
|
|
46
|
+
|
|
47
|
+
import type {KeyboardHandler} from './handler/keyboard';
|
|
48
|
+
import type {DoubleClickZoomHandler} from './handler/shim/dblclick_zoom';
|
|
49
|
+
import type {TwoFingersTouchZoomRotateHandler} from './handler/shim/two_fingers_touch';
|
|
50
|
+
import {defaultLocale} from './default_locale';
|
|
51
51
|
import type {TaskID} from '../util/task_queue';
|
|
52
52
|
import type {Cancelable} from '../types/cancelable';
|
|
53
53
|
import type {
|
|
@@ -62,71 +62,283 @@ import type {
|
|
|
62
62
|
import {Callback} from '../types/callback';
|
|
63
63
|
import type {ControlPosition, IControl} from './control/control';
|
|
64
64
|
import type {MapGeoJSONFeature} from '../util/vectortile_to_geojson';
|
|
65
|
-
import Terrain from '../render/terrain';
|
|
66
|
-
import RenderToTexture from '../render/render_to_texture';
|
|
67
|
-
import config from '../util/config';
|
|
65
|
+
import {Terrain} from '../render/terrain';
|
|
66
|
+
import {RenderToTexture} from '../render/render_to_texture';
|
|
67
|
+
import {config} from '../util/config';
|
|
68
|
+
import type {QueryRenderedFeaturesOptions, QuerySourceFeatureOptions} from '../source/query_features';
|
|
68
69
|
|
|
69
70
|
const version = packageJSON.version;
|
|
70
|
-
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The {@link Map} options object.
|
|
74
|
+
*/
|
|
71
75
|
export type MapOptions = {
|
|
76
|
+
/**
|
|
77
|
+
* If `true`, the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL.
|
|
78
|
+
* For example, `http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60`.
|
|
79
|
+
* An additional string may optionally be provided to indicate a parameter-styled hash,
|
|
80
|
+
* e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo
|
|
81
|
+
* is a custom parameter and bar is an arbitrary hash distinct from the map hash.
|
|
82
|
+
* @defaultValue false
|
|
83
|
+
*/
|
|
72
84
|
hash?: boolean | string;
|
|
85
|
+
/**
|
|
86
|
+
* If `false`, no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to interaction.
|
|
87
|
+
* @defaultValue true
|
|
88
|
+
*/
|
|
73
89
|
interactive?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The HTML element in which MapLibre GL JS will render the map, or the element's string `id`. The specified element must have no children.
|
|
92
|
+
*/
|
|
74
93
|
container: HTMLElement | string;
|
|
94
|
+
/**
|
|
95
|
+
* The threshold, measured in degrees, that determines when the map's
|
|
96
|
+
* bearing will snap to north. For example, with a `bearingSnap` of 7, if the user rotates
|
|
97
|
+
* the map within 7 degrees of north, the map will automatically snap to exact north.
|
|
98
|
+
* @defaultValue 7
|
|
99
|
+
*/
|
|
75
100
|
bearingSnap?: number;
|
|
101
|
+
/**
|
|
102
|
+
* If `true`, an {@link AttributionControl} will be added to the map.
|
|
103
|
+
* @defaultValue true
|
|
104
|
+
*/
|
|
76
105
|
attributionControl?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Attribuition text to show in an {@link AttributionControl}. Only applicable if `options.attributionControl` is `true`.
|
|
108
|
+
*/
|
|
77
109
|
customAttribution?: string | Array<string>;
|
|
110
|
+
/**
|
|
111
|
+
* If `true`, the MapLibre logo will be shown.
|
|
112
|
+
* @defaultValue false
|
|
113
|
+
*/
|
|
78
114
|
maplibreLogo?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* A string representing the position of the MapLibre wordmark on the map. Valid options are `top-left`,`top-right`, `bottom-left`, or `bottom-right`.
|
|
117
|
+
* @defaultValue 'bottom-left'
|
|
118
|
+
*/
|
|
79
119
|
logoPosition?: ControlPosition;
|
|
120
|
+
/**
|
|
121
|
+
* If `true`, map creation will fail if the performance of MapLibre GL JS would be dramatically worse than expected
|
|
122
|
+
* (i.e. a software renderer would be used).
|
|
123
|
+
* @defaultValue false
|
|
124
|
+
*/
|
|
80
125
|
failIfMajorPerformanceCaveat?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* If `true`, the map's canvas can be exported to a PNG using `map.getCanvas().toDataURL()`. This is `false` by default as a performance optimization.
|
|
128
|
+
* @defaultValue false
|
|
129
|
+
*/
|
|
81
130
|
preserveDrawingBuffer?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* If `true`, the gl context will be created with MSAA antialiasing, which can be useful for antialiasing custom layers. This is `false` by default as a performance optimization.
|
|
133
|
+
*/
|
|
82
134
|
antialias?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* If `false`, the map won't attempt to re-request tiles once they expire per their HTTP `cacheControl`/`expires` headers.
|
|
137
|
+
* @defaultValue true
|
|
138
|
+
*/
|
|
83
139
|
refreshExpiredTiles?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* If set, the map will be constrained to the given bounds.
|
|
142
|
+
*/
|
|
84
143
|
maxBounds?: LngLatBoundsLike;
|
|
85
|
-
|
|
144
|
+
/**
|
|
145
|
+
* If `true`, the "scroll to zoom" interaction is enabled. {@link AroundCenterOptions} are passed as options to {@link ScrollZoomHandler#enable}.
|
|
146
|
+
* @defaultValue true
|
|
147
|
+
*/
|
|
148
|
+
scrollZoom?: boolean | AroundCenterOptions;
|
|
149
|
+
/**
|
|
150
|
+
* The minimum zoom level of the map (0-24).
|
|
151
|
+
* @defaultValue 0
|
|
152
|
+
*/
|
|
86
153
|
minZoom?: number | null;
|
|
154
|
+
/**
|
|
155
|
+
* The maximum zoom level of the map (0-24).
|
|
156
|
+
* @defaultValue 22
|
|
157
|
+
*/
|
|
87
158
|
maxZoom?: number | null;
|
|
159
|
+
/**
|
|
160
|
+
* The minimum pitch of the map (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
161
|
+
* @defaultValue 0
|
|
162
|
+
*/
|
|
88
163
|
minPitch?: number | null;
|
|
164
|
+
/**
|
|
165
|
+
* The maximum pitch of the map (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
166
|
+
* @defaultValue 60
|
|
167
|
+
*/
|
|
89
168
|
maxPitch?: number | null;
|
|
169
|
+
/**
|
|
170
|
+
* If `true`, the "box zoom" interaction is enabled (see {@link BoxZoomHandler}).
|
|
171
|
+
* @defaultValue true
|
|
172
|
+
*/
|
|
90
173
|
boxZoom?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* If `true`, the "drag to rotate" interaction is enabled (see {@link DragRotateHandler}).
|
|
176
|
+
* @defaultValue true
|
|
177
|
+
*/
|
|
91
178
|
dragRotate?: boolean;
|
|
92
|
-
|
|
179
|
+
/**
|
|
180
|
+
* If `true`, the "drag to pan" interaction is enabled. An `Object` value is passed as options to {@link DragPanHandler#enable}.
|
|
181
|
+
* @defaultValue true
|
|
182
|
+
*/
|
|
183
|
+
dragPan?: boolean | DragPanOptions;
|
|
184
|
+
/**
|
|
185
|
+
* If `true`, keyboard shortcuts are enabled (see {@link KeyboardHandler}).
|
|
186
|
+
* @defaultValue true
|
|
187
|
+
*/
|
|
93
188
|
keyboard?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* If `true`, the "double click to zoom" interaction is enabled (see {@link DoubleClickZoomHandler}).
|
|
191
|
+
* @defaultValue true
|
|
192
|
+
*/
|
|
94
193
|
doubleClickZoom?: boolean;
|
|
95
|
-
|
|
96
|
-
|
|
194
|
+
/**
|
|
195
|
+
* If `true`, the "pinch to rotate and zoom" interaction is enabled. An `Object` value is passed as options to {@link TwoFingersTouchZoomRotateHandler#enable}.
|
|
196
|
+
* @defaultValue true
|
|
197
|
+
*/
|
|
198
|
+
touchZoomRotate?: boolean | AroundCenterOptions;
|
|
199
|
+
/**
|
|
200
|
+
* If `true`, the "drag to pitch" interaction is enabled. An `Object` value is passed as options to {@link TwoFingersTouchPitchHandler#enable}.
|
|
201
|
+
* @defaultValue true
|
|
202
|
+
*/
|
|
203
|
+
touchPitch?: boolean | AroundCenterOptions;
|
|
204
|
+
/**
|
|
205
|
+
* If `true` or set to an options object, the map is only accessible on desktop while holding Command/Ctrl and only accessible on mobile with two fingers. Interacting with the map using normal gestures will trigger an informational screen. With this option enabled, "drag to pitch" requires a three-finger gesture. Cooperative gestures are disabled when a map enters fullscreen using {@link FullscreenControl}.
|
|
206
|
+
* @defaultValue undefined
|
|
207
|
+
*/
|
|
97
208
|
cooperativeGestures?: boolean | GestureOptions;
|
|
209
|
+
/**
|
|
210
|
+
* If `true`, the map will automatically resize when the browser window resizes.
|
|
211
|
+
* @defaultValue true
|
|
212
|
+
*/
|
|
98
213
|
trackResize?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* The initial geographical centerpoint of the map. If `center` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: MapLibre GL JS uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
|
|
216
|
+
* @defaultValue [0, 0]
|
|
217
|
+
*/
|
|
99
218
|
center?: LngLatLike;
|
|
219
|
+
/**
|
|
220
|
+
* The initial zoom level of the map. If `zoom` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
|
|
221
|
+
* @defaultValue 0
|
|
222
|
+
*/
|
|
100
223
|
zoom?: number;
|
|
224
|
+
/**
|
|
225
|
+
* The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
|
|
226
|
+
* @defaultValue 0
|
|
227
|
+
*/
|
|
101
228
|
bearing?: number;
|
|
229
|
+
/**
|
|
230
|
+
* The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-85). If `pitch` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`. Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
231
|
+
* @defaultValue 0
|
|
232
|
+
*/
|
|
102
233
|
pitch?: number;
|
|
234
|
+
/**
|
|
235
|
+
* If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
|
|
236
|
+
* - When the map is zoomed out far enough that a single representation of the world does not fill the map's entire
|
|
237
|
+
* container, there will be blank space beyond 180 and -180 degrees longitude.
|
|
238
|
+
* - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
|
|
239
|
+
* map and the other on the left edge of the map) at every zoom level.
|
|
240
|
+
* @defaultValue true
|
|
241
|
+
*/
|
|
103
242
|
renderWorldCopies?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport which can be set using `maxTileCacheZoomLevels` constructor options.
|
|
245
|
+
* @defaultValue null
|
|
246
|
+
*/
|
|
104
247
|
maxTileCacheSize?: number;
|
|
248
|
+
/**
|
|
249
|
+
* The maximum number of zoom levels for which to store tiles for a given source. Tile cache dynamic size is calculated by multiplying `maxTileCacheZoomLevels` with the approximate number of tiles in the viewport for a given source.
|
|
250
|
+
* @defaultValue 5
|
|
251
|
+
*/
|
|
105
252
|
maxTileCacheZoomLevels?: number;
|
|
253
|
+
/**
|
|
254
|
+
* A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
|
|
255
|
+
* Expected to return an object with a `url` property and optionally `headers` and `credentials` properties.
|
|
256
|
+
*/
|
|
106
257
|
transformRequest?: RequestTransformFunction;
|
|
258
|
+
/**
|
|
259
|
+
* A callback run before the map's camera is moved due to user input or animation. The callback can be used to modify the new center, zoom, pitch and bearing.
|
|
260
|
+
* Expected to return an object containing center, zoom, pitch or bearing values to overwrite.
|
|
261
|
+
*/
|
|
107
262
|
transformCameraUpdate?: CameraUpdateTransformFunction;
|
|
263
|
+
/**
|
|
264
|
+
* A patch to apply to the default localization table for UI strings, e.g. control tooltips. The `locale` object maps namespaced UI string IDs to translated strings in the target language; see `src/ui/default_locale.js` for an example with all supported string IDs. The object may specify all UI strings (thereby adding support for a new translation) or only a subset of strings (thereby patching the default translation table).
|
|
265
|
+
* @defaultValue null
|
|
266
|
+
*/
|
|
108
267
|
locale?: any;
|
|
268
|
+
/**
|
|
269
|
+
* Controls the duration of the fade-in/fade-out animation for label collisions after initial map load, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
|
|
270
|
+
* @defaultValue 300
|
|
271
|
+
*/
|
|
109
272
|
fadeDuration?: number;
|
|
273
|
+
/**
|
|
274
|
+
* If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
|
|
275
|
+
* @defaultValue true
|
|
276
|
+
*/
|
|
110
277
|
crossSourceCollisions?: boolean;
|
|
278
|
+
/**
|
|
279
|
+
* If `true`, Resource Timing API information will be collected for requests made by GeoJSON and Vector Tile web workers (this information is normally inaccessible from the main Javascript thread). Information will be returned in a `resourceTiming` property of relevant `data` events.
|
|
280
|
+
* @defaultValue false
|
|
281
|
+
*/
|
|
111
282
|
collectResourceTiming?: boolean;
|
|
283
|
+
/**
|
|
284
|
+
* The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag).
|
|
285
|
+
* @defaultValue true
|
|
286
|
+
*/
|
|
112
287
|
clickTolerance?: number;
|
|
288
|
+
/**
|
|
289
|
+
* The initial bounds of the map. If `bounds` is specified, it overrides `center` and `zoom` constructor options.
|
|
290
|
+
*/
|
|
113
291
|
bounds?: LngLatBoundsLike;
|
|
114
|
-
|
|
292
|
+
/**
|
|
293
|
+
* A {@link FitBoundsOptions} options object to use _only_ when fitting the initial `bounds` provided above.
|
|
294
|
+
*/
|
|
295
|
+
fitBoundsOptions?: FitBoundsOptions;
|
|
296
|
+
/**
|
|
297
|
+
* Defines a CSS
|
|
298
|
+
* font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs', 'Hiragana', 'Katakana' and 'Hangul Syllables' ranges.
|
|
299
|
+
* In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
|
|
300
|
+
* Set to `false`, to enable font settings from the map's style for these glyph ranges.
|
|
301
|
+
* The purpose of this option is to avoid bandwidth-intensive glyph server requests. (See [Use locally generated ideographs](https://maplibre.org/maplibre-gl-js/docs/examples/local-ideographs).)
|
|
302
|
+
* @defaultValue 'sans-serif'
|
|
303
|
+
*/
|
|
115
304
|
localIdeographFontFamily?: string;
|
|
305
|
+
/**
|
|
306
|
+
* The map's MapLibre style. This must be a JSON object conforming to
|
|
307
|
+
* the schema described in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/),
|
|
308
|
+
* or a URL to such JSON.
|
|
309
|
+
*/
|
|
116
310
|
style: StyleSpecification | string;
|
|
311
|
+
/**
|
|
312
|
+
* If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
|
|
313
|
+
* @defaultValue true
|
|
314
|
+
*/
|
|
117
315
|
pitchWithRotate?: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* The pixel ratio. The canvas' `width` attribute will be `container.clientWidth * pixelRatio` and its `height` attribute will be `container.clientHeight * pixelRatio`. Defaults to `devicePixelRatio` if not specified.
|
|
318
|
+
*/
|
|
118
319
|
pixelRatio?: number;
|
|
320
|
+
/**
|
|
321
|
+
* If false, style validation will be skipped. Useful in production environment.
|
|
322
|
+
* @defaultValue true
|
|
323
|
+
*/
|
|
119
324
|
validateStyle?: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* The canvas' `width` and `height` max size. The values are passed as an array where the first element is max width and the second element is max height.
|
|
327
|
+
* You shouldn't set this above WebGl `MAX_TEXTURE_SIZE`. Defaults to [4096, 4096].
|
|
328
|
+
*/
|
|
329
|
+
maxCanvasSize?: [number, number];
|
|
120
330
|
};
|
|
121
331
|
|
|
122
332
|
/**
|
|
123
333
|
* An options object for the gesture settings
|
|
124
334
|
* @example
|
|
335
|
+
* ```ts
|
|
125
336
|
* let options = {
|
|
126
337
|
* windowsHelpText: "Use Ctrl + scroll to zoom the map",
|
|
127
338
|
* macHelpText: "Use ⌘ + scroll to zoom the map",
|
|
128
339
|
* mobileHelpText: "Use two fingers to move the map",
|
|
129
340
|
* }
|
|
341
|
+
* ```
|
|
130
342
|
*/
|
|
131
343
|
export type GestureOptions = {
|
|
132
344
|
windowsHelpText?: string;
|
|
@@ -134,6 +346,10 @@ export type GestureOptions = {
|
|
|
134
346
|
mobileHelpText?: string;
|
|
135
347
|
};
|
|
136
348
|
|
|
349
|
+
export type AddImageOptions = {
|
|
350
|
+
|
|
351
|
+
}
|
|
352
|
+
|
|
137
353
|
// See article here: https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585
|
|
138
354
|
type Complete<T> = {
|
|
139
355
|
[P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? T[P] : (T[P] | undefined);
|
|
@@ -142,13 +358,6 @@ type Complete<T> = {
|
|
|
142
358
|
// This type is used inside map since all properties are assigned a default value.
|
|
143
359
|
export type CompleteMapOptions = Complete<MapOptions>;
|
|
144
360
|
|
|
145
|
-
type QueryRenderedFeaturesOptions = {
|
|
146
|
-
layers?: Array<string>;
|
|
147
|
-
filter?: FilterSpecification;
|
|
148
|
-
availableImages?: Array<string>;
|
|
149
|
-
validate?: boolean;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
361
|
const defaultMinZoom = -2;
|
|
153
362
|
const defaultMaxZoom = 22;
|
|
154
363
|
|
|
@@ -202,7 +411,9 @@ const defaultOptions = {
|
|
|
202
411
|
transformCameraUpdate: null,
|
|
203
412
|
fadeDuration: 300,
|
|
204
413
|
crossSourceCollisions: true,
|
|
205
|
-
validateStyle: true
|
|
414
|
+
validateStyle: true,
|
|
415
|
+
/** Because GL MAX_TEXTURE_SIZE is usually at least 4096px. */
|
|
416
|
+
maxCanvasSize: [4096, 4096]
|
|
206
417
|
} as CompleteMapOptions;
|
|
207
418
|
|
|
208
419
|
/**
|
|
@@ -210,83 +421,14 @@ const defaultOptions = {
|
|
|
210
421
|
* and properties that enable you to programmatically change the map,
|
|
211
422
|
* and fires events as users interact with it.
|
|
212
423
|
*
|
|
213
|
-
* You create a `Map` by specifying a `container` and other options.
|
|
214
|
-
* Then MapLibre GL JS initializes the map on the page and returns your `Map`
|
|
215
|
-
* object.
|
|
424
|
+
* You create a `Map` by specifying a `container` and other options, see {@link MapOptions} for the full list.
|
|
425
|
+
* Then MapLibre GL JS initializes the map on the page and returns your `Map` object.
|
|
216
426
|
*
|
|
217
|
-
* @
|
|
218
|
-
* @param {Object} options
|
|
219
|
-
* @param {HTMLElement|string} options.container The HTML element in which MapLibre GL JS will render the map, or the element's string `id`. The specified element must have no children.
|
|
220
|
-
* @param {number} [options.minZoom=0] The minimum zoom level of the map (0-24).
|
|
221
|
-
* @param {number} [options.maxZoom=22] The maximum zoom level of the map (0-24).
|
|
222
|
-
* @param {number} [options.minPitch=0] The minimum pitch of the map (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
223
|
-
* @param {number} [options.maxPitch=60] The maximum pitch of the map (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
224
|
-
* @param {Object|string} [options.style] The map's MapLibre style. This must be an a JSON object conforming to
|
|
225
|
-
* the schema described in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/), or a URL to
|
|
226
|
-
* such JSON.
|
|
427
|
+
* @group Main
|
|
227
428
|
*
|
|
228
|
-
*
|
|
229
|
-
* @param {(boolean|string)} [options.hash=false] If `true`, the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL.
|
|
230
|
-
* For example, `http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60`.
|
|
231
|
-
* An additional string may optionally be provided to indicate a parameter-styled hash,
|
|
232
|
-
* e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo
|
|
233
|
-
* is a custom parameter and bar is an arbitrary hash distinct from the map hash.
|
|
234
|
-
* @param {boolean} [options.interactive=true] If `false`, no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to interaction.
|
|
235
|
-
* @param {number} [options.bearingSnap=7] The threshold, measured in degrees, that determines when the map's
|
|
236
|
-
* bearing will snap to north. For example, with a `bearingSnap` of 7, if the user rotates
|
|
237
|
-
* the map within 7 degrees of north, the map will automatically snap to exact north.
|
|
238
|
-
* @param {boolean} [options.pitchWithRotate=true] If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
|
|
239
|
-
* @param {number} [options.clickTolerance=3] The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag).
|
|
240
|
-
* @param {boolean} [options.attributionControl=true] If `true`, an {@link AttributionControl} will be added to the map.
|
|
241
|
-
* @param {string | Array<string>} [options.customAttribution] String or strings to show in an {@link AttributionControl}. Only applicable if `options.attributionControl` is `true`.
|
|
242
|
-
* @param {boolean} [options.maplibreLogo=false] If `true`, the MapLibre logo will be shown.
|
|
243
|
-
* @param {string} [options.logoPosition='bottom-left'] A string representing the position of the MapLibre wordmark on the map. Valid options are `top-left`,`top-right`, `bottom-left`, `bottom-right`.
|
|
244
|
-
* @param {boolean} [options.failIfMajorPerformanceCaveat=false] If `true`, map creation will fail if the performance of MapLibre
|
|
245
|
-
* GL JS would be dramatically worse than expected (i.e. a software renderer would be used).
|
|
246
|
-
* @param {boolean} [options.preserveDrawingBuffer=false] If `true`, the map's canvas can be exported to a PNG using `map.getCanvas().toDataURL()`. This is `false` by default as a performance optimization.
|
|
247
|
-
* @param {boolean} [options.antialias] If `true`, the gl context will be created with MSAA antialiasing, which can be useful for antialiasing custom layers. this is `false` by default as a performance optimization.
|
|
248
|
-
* @param {boolean} [options.refreshExpiredTiles=true] If `false`, the map won't attempt to re-request tiles once they expire per their HTTP `cacheControl`/`expires` headers.
|
|
249
|
-
* @param {LngLatBoundsLike} [options.maxBounds] If set, the map will be constrained to the given bounds.
|
|
250
|
-
* @param {boolean|Object} [options.scrollZoom=true] If `true`, the "scroll to zoom" interaction is enabled. An `Object` value is passed as options to {@link ScrollZoomHandler#enable}.
|
|
251
|
-
* @param {boolean} [options.boxZoom=true] If `true`, the "box zoom" interaction is enabled (see {@link BoxZoomHandler}).
|
|
252
|
-
* @param {boolean} [options.dragRotate=true] If `true`, the "drag to rotate" interaction is enabled (see {@link DragRotateHandler}).
|
|
253
|
-
* @param {boolean|Object} [options.dragPan=true] If `true`, the "drag to pan" interaction is enabled. An `Object` value is passed as options to {@link DragPanHandler#enable}.
|
|
254
|
-
* @param {boolean} [options.keyboard=true] If `true`, keyboard shortcuts are enabled (see {@link KeyboardHandler}).
|
|
255
|
-
* @param {boolean} [options.doubleClickZoom=true] If `true`, the "double click to zoom" interaction is enabled (see {@link DoubleClickZoomHandler}).
|
|
256
|
-
* @param {boolean|Object} [options.touchZoomRotate=true] If `true`, the "pinch to rotate and zoom" interaction is enabled. An `Object` value is passed as options to {@link TwoFingersTouchZoomRotateHandler#enable}.
|
|
257
|
-
* @param {boolean|Object} [options.touchPitch=true] If `true`, the "drag to pitch" interaction is enabled. An `Object` value is passed as options to {@link TwoFingersTouchPitchHandler#enable}.
|
|
258
|
-
* @param {boolean|GestureOptions} [options.cooperativeGestures=undefined] If `true` or set to an options object, map is only accessible on desktop while holding Command/Ctrl and only accessible on mobile with two fingers. Interacting with the map using normal gestures will trigger an informational screen. With this option enabled, "drag to pitch" requires a three-finger gesture. Cooperative gestures are disabled when a map enters fullscreen using {@link #FullscreenControl}.
|
|
259
|
-
* @param {boolean} [options.trackResize=true] If `true`, the map will automatically resize when the browser window resizes.
|
|
260
|
-
* @param {LngLatLike} [options.center=[0, 0]] The initial geographical centerpoint of the map. If `center` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: MapLibre GL JS uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
|
|
261
|
-
* @param {number} [options.zoom=0] The initial zoom level of the map. If `zoom` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
|
|
262
|
-
* @param {number} [options.bearing=0] The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
|
|
263
|
-
* @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-85). If `pitch` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`. Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
264
|
-
* @param {LngLatBoundsLike} [options.bounds] The initial bounds of the map. If `bounds` is specified, it overrides `center` and `zoom` constructor options.
|
|
265
|
-
* @param {Object} [options.fitBoundsOptions] A {@link Map#fitBounds} options object to use _only_ when fitting the initial `bounds` provided above.
|
|
266
|
-
* @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
|
|
267
|
-
* - When the map is zoomed out far enough that a single representation of the world does not fill the map's entire
|
|
268
|
-
* container, there will be blank space beyond 180 and -180 degrees longitude.
|
|
269
|
-
* - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
|
|
270
|
-
* map and the other on the left edge of the map) at every zoom level.
|
|
271
|
-
* @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport which can be set using `maxTileCacheZoomLevels` constructor options.
|
|
272
|
-
* @param {number} [options.maxTileCacheZoomLevels=5] The maximum number of zoom levels for which to store tiles for a given source. Tile cache dynamic size is calculated by multiplying `maxTileCacheZoomLevels` with approx number of tiles in the viewport for a given source.
|
|
273
|
-
* @param {boolean} [options.validateStyle=true] If false, style validation will be skipped. Useful in production environment.
|
|
274
|
-
* @param {string} [options.localIdeographFontFamily='sans-serif'] Defines a CSS
|
|
275
|
-
* font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs', 'Hiragana', 'Katakana' and 'Hangul Syllables' ranges.
|
|
276
|
-
* In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
|
|
277
|
-
* Set to `false`, to enable font settings from the map's style for these glyph ranges.
|
|
278
|
-
* The purpose of this option is to avoid bandwidth-intensive glyph server requests. (See [Use locally generated ideographs](https://maplibre.org/maplibre-gl-js-docs/example/local-ideographs).)
|
|
279
|
-
* @param {RequestTransformFunction} [options.transformRequest=null] A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
|
|
280
|
-
* Expected to return an object with a `url` property and optionally `headers` and `credentials` properties.
|
|
281
|
-
* @param {CameraUpdateTransformFunction} [options.transformCameraUpdate=null] A callback run before the Map's camera is moved due to user input or animation. The callback can be used to modify the new center, zoom, pitch and bearing.
|
|
282
|
-
* Expected to return an object containing center, zoom, pitch or bearing values to overwrite.
|
|
283
|
-
* @param {boolean} [options.collectResourceTiming=false] If `true`, Resource Timing API information will be collected for requests made by GeoJSON and Vector Tile web workers (this information is normally inaccessible from the main Javascript thread). Information will be returned in a `resourceTiming` property of relevant `data` events.
|
|
284
|
-
* @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions after initial map load, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
|
|
285
|
-
* @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
|
|
286
|
-
* @param {Object} [options.locale=null] A patch to apply to the default localization table for UI strings, e.g. control tooltips. The `locale` object maps namespaced UI string IDs to translated strings in the target language; see `src/ui/default_locale.js` for an example with all supported string IDs. The object may specify all UI strings (thereby adding support for a new translation) or only a subset of strings (thereby patching the default translation table).
|
|
287
|
-
* @param {number} [options.pixelRatio] The pixel ratio. The canvas' `width` attribute will be `container.clientWidth * pixelRatio` and its `height` attribute will be `container.clientHeight * pixelRatio`. Defaults to `devicePixelRatio` if not specified.
|
|
288
429
|
* @example
|
|
289
|
-
*
|
|
430
|
+
* ```ts
|
|
431
|
+
* let map = new maplibregl.Map({
|
|
290
432
|
* container: 'map',
|
|
291
433
|
* center: [-122.420679, 37.772537],
|
|
292
434
|
* zoom: 13,
|
|
@@ -302,9 +444,10 @@ const defaultOptions = {
|
|
|
302
444
|
* }
|
|
303
445
|
* }
|
|
304
446
|
* });
|
|
305
|
-
*
|
|
447
|
+
* ```
|
|
448
|
+
* @see [Display a map](https://maplibre.org/maplibre-gl-js/docs/examples/simple-map/)
|
|
306
449
|
*/
|
|
307
|
-
class Map extends Camera {
|
|
450
|
+
export class Map extends Camera {
|
|
308
451
|
style: Style;
|
|
309
452
|
painter: Painter;
|
|
310
453
|
handlers: HandlerManager;
|
|
@@ -356,7 +499,8 @@ class Map extends Camera {
|
|
|
356
499
|
_locale: any;
|
|
357
500
|
_removed: boolean;
|
|
358
501
|
_clickTolerance: number;
|
|
359
|
-
|
|
502
|
+
_overridePixelRatio: number | null;
|
|
503
|
+
_maxCanvasSize: [number, number];
|
|
360
504
|
_terrainDataCallback: (e: MapStyleDataEvent | MapSourceDataEvent) => void;
|
|
361
505
|
|
|
362
506
|
/** image queue throttling handle. To be used later when clean up */
|
|
@@ -455,7 +599,8 @@ class Map extends Camera {
|
|
|
455
599
|
this._mapId = uniqueId();
|
|
456
600
|
this._locale = extend({}, defaultLocale, options.locale);
|
|
457
601
|
this._clickTolerance = options.clickTolerance;
|
|
458
|
-
this.
|
|
602
|
+
this._overridePixelRatio = options.pixelRatio;
|
|
603
|
+
this._maxCanvasSize = options.maxCanvasSize;
|
|
459
604
|
this.transformCameraUpdate = options.transformCameraUpdate;
|
|
460
605
|
|
|
461
606
|
this._imageQueueHandle = ImageRequest.addThrottleControl(() => this.isMoving());
|
|
@@ -477,14 +622,6 @@ class Map extends Camera {
|
|
|
477
622
|
this.setMaxBounds(options.maxBounds);
|
|
478
623
|
}
|
|
479
624
|
|
|
480
|
-
bindAll([
|
|
481
|
-
'_onWindowOnline',
|
|
482
|
-
'_onMapScroll',
|
|
483
|
-
'_cooperativeGesturesOnWheel',
|
|
484
|
-
'_contextLost',
|
|
485
|
-
'_contextRestored'
|
|
486
|
-
], this);
|
|
487
|
-
|
|
488
625
|
this._setupContainer();
|
|
489
626
|
this._setupPainter();
|
|
490
627
|
|
|
@@ -566,12 +703,11 @@ class Map extends Camera {
|
|
|
566
703
|
});
|
|
567
704
|
}
|
|
568
705
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
*/
|
|
706
|
+
/**
|
|
707
|
+
* Returns a unique number for this map instance which is used for the MapLoadEvent
|
|
708
|
+
* to make sure we only fire one event per instantiated map object.
|
|
709
|
+
* @returns the uniq map ID
|
|
710
|
+
*/
|
|
575
711
|
_getMapId() {
|
|
576
712
|
return this._mapId;
|
|
577
713
|
}
|
|
@@ -579,16 +715,18 @@ class Map extends Camera {
|
|
|
579
715
|
/**
|
|
580
716
|
* Adds an {@link IControl} to the map, calling `control.onAdd(this)`.
|
|
581
717
|
*
|
|
582
|
-
* @param
|
|
583
|
-
* @param
|
|
718
|
+
* @param control - The {@link IControl} to add.
|
|
719
|
+
* @param position - position on the map to which the control will be added.
|
|
584
720
|
* Valid values are `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`. Defaults to `'top-right'`.
|
|
585
|
-
* @returns
|
|
721
|
+
* @returns `this`
|
|
586
722
|
* @example
|
|
587
|
-
*
|
|
723
|
+
* Add zoom and rotation controls to the map.
|
|
724
|
+
* ```ts
|
|
588
725
|
* map.addControl(new maplibregl.NavigationControl());
|
|
589
|
-
*
|
|
726
|
+
* ```
|
|
727
|
+
* @see [Display map navigation controls](https://maplibre.org/maplibre-gl-js/docs/examples/navigation/)
|
|
590
728
|
*/
|
|
591
|
-
addControl(control: IControl, position?: ControlPosition) {
|
|
729
|
+
addControl(control: IControl, position?: ControlPosition): Map {
|
|
592
730
|
if (position === undefined) {
|
|
593
731
|
if (control.getDefaultPosition) {
|
|
594
732
|
position = control.getDefaultPosition();
|
|
@@ -615,17 +753,19 @@ class Map extends Camera {
|
|
|
615
753
|
/**
|
|
616
754
|
* Removes the control from the map.
|
|
617
755
|
*
|
|
618
|
-
* @param
|
|
619
|
-
* @returns
|
|
756
|
+
* @param control - The {@link IControl} to remove.
|
|
757
|
+
* @returns `this`
|
|
620
758
|
* @example
|
|
759
|
+
* ```ts
|
|
621
760
|
* // Define a new navigation control.
|
|
622
|
-
*
|
|
761
|
+
* let navigation = new maplibregl.NavigationControl();
|
|
623
762
|
* // Add zoom and rotation controls to the map.
|
|
624
763
|
* map.addControl(navigation);
|
|
625
764
|
* // Remove zoom and rotation controls from the map.
|
|
626
765
|
* map.removeControl(navigation);
|
|
766
|
+
* ```
|
|
627
767
|
*/
|
|
628
|
-
removeControl(control: IControl) {
|
|
768
|
+
removeControl(control: IControl): Map {
|
|
629
769
|
if (!control || !control.onRemove) {
|
|
630
770
|
return this.fire(new ErrorEvent(new Error(
|
|
631
771
|
'Invalid argument to map.removeControl(). Argument must be a control with onAdd and onRemove methods.')));
|
|
@@ -639,15 +779,17 @@ class Map extends Camera {
|
|
|
639
779
|
/**
|
|
640
780
|
* Checks if a control exists on the map.
|
|
641
781
|
*
|
|
642
|
-
* @param
|
|
643
|
-
* @returns
|
|
782
|
+
* @param control - The {@link IControl} to check.
|
|
783
|
+
* @returns true if map contains control.
|
|
644
784
|
* @example
|
|
785
|
+
* ```ts
|
|
645
786
|
* // Define a new navigation control.
|
|
646
|
-
*
|
|
787
|
+
* let navigation = new maplibregl.NavigationControl();
|
|
647
788
|
* // Add zoom and rotation controls to the map.
|
|
648
789
|
* map.addControl(navigation);
|
|
649
790
|
* // Check that the navigation control exists on the map.
|
|
650
791
|
* map.hasControl(navigation);
|
|
792
|
+
* ```
|
|
651
793
|
*/
|
|
652
794
|
hasControl(control: IControl) {
|
|
653
795
|
return this._controls.indexOf(control) > -1;
|
|
@@ -668,25 +810,38 @@ class Map extends Camera {
|
|
|
668
810
|
* This method must be called after the map's `container` is resized programmatically
|
|
669
811
|
* or when the map is shown after being initially hidden with CSS.
|
|
670
812
|
*
|
|
671
|
-
* @param eventData Additional properties to be passed to `movestart`, `move`, `resize`, and `moveend`
|
|
813
|
+
* @param eventData - Additional properties to be passed to `movestart`, `move`, `resize`, and `moveend`
|
|
672
814
|
* events that get triggered as a result of resize. This can be useful for differentiating the
|
|
673
815
|
* source of an event (for example, user-initiated or programmatically-triggered events).
|
|
674
|
-
* @returns
|
|
816
|
+
* @returns `this`
|
|
675
817
|
* @example
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
818
|
+
* Resize the map when the map container is shown after being initially hidden with CSS.
|
|
819
|
+
* ```ts
|
|
820
|
+
* let mapDiv = document.getElementById('map');
|
|
679
821
|
* if (mapDiv.style.visibility === true) map.resize();
|
|
822
|
+
* ```
|
|
680
823
|
*/
|
|
681
|
-
resize(eventData?: any) {
|
|
824
|
+
resize(eventData?: any): Map {
|
|
682
825
|
const dimensions = this._containerDimensions();
|
|
683
826
|
const width = dimensions[0];
|
|
684
827
|
const height = dimensions[1];
|
|
685
828
|
|
|
686
|
-
this.
|
|
829
|
+
const clampedPixelRatio = this._getClampedPixelRatio(width, height);
|
|
830
|
+
this._resizeCanvas(width, height, clampedPixelRatio);
|
|
831
|
+
this.painter.resize(width, height, clampedPixelRatio);
|
|
832
|
+
|
|
833
|
+
// check if we've reached GL limits, in that case further clamps pixelRatio
|
|
834
|
+
if (this.painter.overLimit()) {
|
|
835
|
+
const gl = this.painter.context.gl;
|
|
836
|
+
// store updated _maxCanvasSize value
|
|
837
|
+
this._maxCanvasSize = [gl.drawingBufferWidth, gl.drawingBufferHeight];
|
|
838
|
+
const clampedPixelRatio = this._getClampedPixelRatio(width, height);
|
|
839
|
+
this._resizeCanvas(width, height, clampedPixelRatio);
|
|
840
|
+
this.painter.resize(width, height, clampedPixelRatio);
|
|
841
|
+
}
|
|
842
|
+
|
|
687
843
|
this.transform.resize(width, height);
|
|
688
844
|
this._requestedCameraState?.resize(width, height);
|
|
689
|
-
this.painter.resize(width, height, this.getPixelRatio());
|
|
690
845
|
|
|
691
846
|
const fireMoving = !this._moving;
|
|
692
847
|
if (fireMoving) {
|
|
@@ -702,35 +857,53 @@ class Map extends Camera {
|
|
|
702
857
|
return this;
|
|
703
858
|
}
|
|
704
859
|
|
|
860
|
+
/*
|
|
861
|
+
* Return the map's pixel ratio eventually scaled down to respect maxCanvasSize.
|
|
862
|
+
* Internally you should use this and not getPixelRatio().
|
|
863
|
+
*/
|
|
864
|
+
_getClampedPixelRatio(width: number, height: number): number {
|
|
865
|
+
const {0: maxCanvasWidth, 1: maxCanvasHeight} = this._maxCanvasSize;
|
|
866
|
+
const pixelRatio = this.getPixelRatio();
|
|
867
|
+
|
|
868
|
+
const canvasWidth = width * pixelRatio;
|
|
869
|
+
const canvasHeight = height * pixelRatio;
|
|
870
|
+
|
|
871
|
+
const widthScaleFactor = canvasWidth > maxCanvasWidth ? (maxCanvasWidth / canvasWidth) : 1;
|
|
872
|
+
const heightScaleFactor = canvasHeight > maxCanvasHeight ? (maxCanvasHeight / canvasHeight) : 1;
|
|
873
|
+
|
|
874
|
+
return Math.min(widthScaleFactor, heightScaleFactor) * pixelRatio;
|
|
875
|
+
}
|
|
876
|
+
|
|
705
877
|
/**
|
|
706
878
|
* Returns the map's pixel ratio.
|
|
707
|
-
*
|
|
879
|
+
* Note that the pixel ratio actually applied may be lower to respect maxCanvasSize.
|
|
880
|
+
* @returns The pixel ratio.
|
|
708
881
|
*/
|
|
709
|
-
getPixelRatio() {
|
|
710
|
-
return this.
|
|
882
|
+
getPixelRatio(): number {
|
|
883
|
+
return this._overridePixelRatio ?? devicePixelRatio;
|
|
711
884
|
}
|
|
712
885
|
|
|
713
886
|
/**
|
|
714
887
|
* Sets the map's pixel ratio. This allows to override `devicePixelRatio`.
|
|
715
888
|
* After this call, the canvas' `width` attribute will be `container.clientWidth * pixelRatio`
|
|
716
889
|
* and its height attribute will be `container.clientHeight * pixelRatio`.
|
|
717
|
-
*
|
|
890
|
+
* Set this to null to disable `devicePixelRatio` override.
|
|
891
|
+
* Note that the pixel ratio actually applied may be lower to respect maxCanvasSize.
|
|
892
|
+
* @param pixelRatio - The pixel ratio.
|
|
718
893
|
*/
|
|
719
894
|
setPixelRatio(pixelRatio: number) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
this._pixelRatio = pixelRatio;
|
|
723
|
-
|
|
724
|
-
this._resizeCanvas(width, height, pixelRatio);
|
|
725
|
-
this.painter.resize(width, height, pixelRatio);
|
|
895
|
+
this._overridePixelRatio = pixelRatio;
|
|
896
|
+
this.resize();
|
|
726
897
|
}
|
|
727
898
|
|
|
728
899
|
/**
|
|
729
900
|
* Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
|
|
730
901
|
* an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
|
|
731
|
-
* @returns
|
|
902
|
+
* @returns The geographical bounds of the map as {@link LngLatBounds}.
|
|
732
903
|
* @example
|
|
733
|
-
*
|
|
904
|
+
* ```ts
|
|
905
|
+
* let bounds = map.getBounds();
|
|
906
|
+
* ```
|
|
734
907
|
*/
|
|
735
908
|
getBounds(): LngLatBounds {
|
|
736
909
|
return this.transform.getBounds();
|
|
@@ -740,7 +913,9 @@ class Map extends Camera {
|
|
|
740
913
|
* Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
|
|
741
914
|
* @returns The map object.
|
|
742
915
|
* @example
|
|
743
|
-
*
|
|
916
|
+
* ```ts
|
|
917
|
+
* let maxBounds = map.getMaxBounds();
|
|
918
|
+
* ```
|
|
744
919
|
*/
|
|
745
920
|
getMaxBounds(): LngLatBounds | null {
|
|
746
921
|
return this.transform.getMaxBounds();
|
|
@@ -756,18 +931,19 @@ class Map extends Camera {
|
|
|
756
931
|
* as close as possible to the operation's request while still
|
|
757
932
|
* remaining within the bounds.
|
|
758
933
|
*
|
|
759
|
-
* @param
|
|
760
|
-
* @returns
|
|
934
|
+
* @param bounds - The maximum bounds to set. If `null` or `undefined` is provided, the function removes the map's maximum bounds.
|
|
935
|
+
* @returns `this`
|
|
761
936
|
* @example
|
|
762
|
-
*
|
|
763
|
-
*
|
|
937
|
+
* Define bounds that conform to the `LngLatBoundsLike` object as set the max bounds.
|
|
938
|
+
* ```ts
|
|
939
|
+
* let bounds = [
|
|
764
940
|
* [-74.04728, 40.68392], // [west, south]
|
|
765
941
|
* [-73.91058, 40.87764] // [east, north]
|
|
766
942
|
* ];
|
|
767
|
-
* // Set the map's max bounds.
|
|
768
943
|
* map.setMaxBounds(bounds);
|
|
944
|
+
* ```
|
|
769
945
|
*/
|
|
770
|
-
setMaxBounds(bounds?: LngLatBoundsLike | null) {
|
|
946
|
+
setMaxBounds(bounds?: LngLatBoundsLike | null): Map {
|
|
771
947
|
this.transform.setMaxBounds(LngLatBounds.convert(bounds));
|
|
772
948
|
return this._update();
|
|
773
949
|
}
|
|
@@ -782,13 +958,15 @@ class Map extends Camera {
|
|
|
782
958
|
* if the map is 512px tall it will not be possible to zoom below zoom 0
|
|
783
959
|
* no matter what the `minZoom` is set to.
|
|
784
960
|
*
|
|
785
|
-
* @param
|
|
961
|
+
* @param minZoom - The minimum zoom level to set (-2 - 24).
|
|
786
962
|
* If `null` or `undefined` is provided, the function removes the current minimum zoom (i.e. sets it to -2).
|
|
787
|
-
* @returns
|
|
963
|
+
* @returns `this`
|
|
788
964
|
* @example
|
|
965
|
+
* ```ts
|
|
789
966
|
* map.setMinZoom(12.25);
|
|
967
|
+
* ```
|
|
790
968
|
*/
|
|
791
|
-
setMinZoom(minZoom?: number | null) {
|
|
969
|
+
setMinZoom(minZoom?: number | null): Map {
|
|
792
970
|
|
|
793
971
|
minZoom = minZoom === null || minZoom === undefined ? defaultMinZoom : minZoom;
|
|
794
972
|
|
|
@@ -806,24 +984,28 @@ class Map extends Camera {
|
|
|
806
984
|
/**
|
|
807
985
|
* Returns the map's minimum allowable zoom level.
|
|
808
986
|
*
|
|
809
|
-
* @returns
|
|
987
|
+
* @returns minZoom
|
|
810
988
|
* @example
|
|
811
|
-
*
|
|
989
|
+
* ```ts
|
|
990
|
+
* let minZoom = map.getMinZoom();
|
|
991
|
+
* ```
|
|
812
992
|
*/
|
|
813
|
-
getMinZoom() { return this.transform.minZoom; }
|
|
993
|
+
getMinZoom(): number { return this.transform.minZoom; }
|
|
814
994
|
|
|
815
995
|
/**
|
|
816
996
|
* Sets or clears the map's maximum zoom level.
|
|
817
997
|
* If the map's current zoom level is higher than the new maximum,
|
|
818
998
|
* the map will zoom to the new maximum.
|
|
819
999
|
*
|
|
820
|
-
* @param
|
|
1000
|
+
* @param maxZoom - The maximum zoom level to set.
|
|
821
1001
|
* If `null` or `undefined` is provided, the function removes the current maximum zoom (sets it to 22).
|
|
822
|
-
* @returns
|
|
1002
|
+
* @returns `this`
|
|
823
1003
|
* @example
|
|
1004
|
+
* ```ts
|
|
824
1005
|
* map.setMaxZoom(18.75);
|
|
1006
|
+
* ```
|
|
825
1007
|
*/
|
|
826
|
-
setMaxZoom(maxZoom?: number | null) {
|
|
1008
|
+
setMaxZoom(maxZoom?: number | null): Map {
|
|
827
1009
|
|
|
828
1010
|
maxZoom = maxZoom === null || maxZoom === undefined ? defaultMaxZoom : maxZoom;
|
|
829
1011
|
|
|
@@ -841,22 +1023,24 @@ class Map extends Camera {
|
|
|
841
1023
|
/**
|
|
842
1024
|
* Returns the map's maximum allowable zoom level.
|
|
843
1025
|
*
|
|
844
|
-
* @returns
|
|
1026
|
+
* @returns The maxZoom
|
|
845
1027
|
* @example
|
|
846
|
-
*
|
|
1028
|
+
* ```ts
|
|
1029
|
+
* let maxZoom = map.getMaxZoom();
|
|
1030
|
+
* ```
|
|
847
1031
|
*/
|
|
848
|
-
getMaxZoom() { return this.transform.maxZoom; }
|
|
1032
|
+
getMaxZoom(): number { return this.transform.maxZoom; }
|
|
849
1033
|
|
|
850
1034
|
/**
|
|
851
1035
|
* Sets or clears the map's minimum pitch.
|
|
852
1036
|
* If the map's current pitch is lower than the new minimum,
|
|
853
1037
|
* the map will pitch to the new minimum.
|
|
854
1038
|
*
|
|
855
|
-
* @param
|
|
1039
|
+
* @param minPitch - The minimum pitch to set (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
856
1040
|
* If `null` or `undefined` is provided, the function removes the current minimum pitch (i.e. sets it to 0).
|
|
857
|
-
* @returns
|
|
1041
|
+
* @returns `this`
|
|
858
1042
|
*/
|
|
859
|
-
setMinPitch(minPitch?: number | null) {
|
|
1043
|
+
setMinPitch(minPitch?: number | null): Map {
|
|
860
1044
|
|
|
861
1045
|
minPitch = minPitch === null || minPitch === undefined ? defaultMinPitch : minPitch;
|
|
862
1046
|
|
|
@@ -878,20 +1062,20 @@ class Map extends Camera {
|
|
|
878
1062
|
/**
|
|
879
1063
|
* Returns the map's minimum allowable pitch.
|
|
880
1064
|
*
|
|
881
|
-
* @returns
|
|
1065
|
+
* @returns The minPitch
|
|
882
1066
|
*/
|
|
883
|
-
getMinPitch() { return this.transform.minPitch; }
|
|
1067
|
+
getMinPitch(): number { return this.transform.minPitch; }
|
|
884
1068
|
|
|
885
1069
|
/**
|
|
886
1070
|
* Sets or clears the map's maximum pitch.
|
|
887
1071
|
* If the map's current pitch is higher than the new maximum,
|
|
888
1072
|
* the map will pitch to the new maximum.
|
|
889
1073
|
*
|
|
890
|
-
* @param
|
|
1074
|
+
* @param maxPitch - The maximum pitch to set (0-85). Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
|
|
891
1075
|
* If `null` or `undefined` is provided, the function removes the current maximum pitch (sets it to 60).
|
|
892
|
-
* @returns
|
|
1076
|
+
* @returns `this`
|
|
893
1077
|
*/
|
|
894
|
-
setMaxPitch(maxPitch?: number | null) {
|
|
1078
|
+
setMaxPitch(maxPitch?: number | null): Map {
|
|
895
1079
|
|
|
896
1080
|
maxPitch = maxPitch === null || maxPitch === undefined ? defaultMaxPitch : maxPitch;
|
|
897
1081
|
|
|
@@ -913,9 +1097,9 @@ class Map extends Camera {
|
|
|
913
1097
|
/**
|
|
914
1098
|
* Returns the map's maximum allowable pitch.
|
|
915
1099
|
*
|
|
916
|
-
* @returns
|
|
1100
|
+
* @returns The maxPitch
|
|
917
1101
|
*/
|
|
918
|
-
getMaxPitch() { return this.transform.maxPitch; }
|
|
1102
|
+
getMaxPitch(): number { return this.transform.maxPitch; }
|
|
919
1103
|
|
|
920
1104
|
/**
|
|
921
1105
|
* Returns the state of `renderWorldCopies`. If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
|
|
@@ -923,29 +1107,33 @@ class Map extends Camera {
|
|
|
923
1107
|
* container, there will be blank space beyond 180 and -180 degrees longitude.
|
|
924
1108
|
* - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
|
|
925
1109
|
* map and the other on the left edge of the map) at every zoom level.
|
|
926
|
-
* @returns
|
|
1110
|
+
* @returns The renderWorldCopies
|
|
927
1111
|
* @example
|
|
928
|
-
*
|
|
929
|
-
*
|
|
1112
|
+
* ```ts
|
|
1113
|
+
* let worldCopiesRendered = map.getRenderWorldCopies();
|
|
1114
|
+
* ```
|
|
1115
|
+
* @see [Render world copies](https://maplibre.org/maplibre-gl-js/docs/examples/render-world-copies/)
|
|
930
1116
|
*/
|
|
931
|
-
getRenderWorldCopies() { return this.transform.renderWorldCopies; }
|
|
1117
|
+
getRenderWorldCopies(): boolean { return this.transform.renderWorldCopies; }
|
|
932
1118
|
|
|
933
1119
|
/**
|
|
934
1120
|
* Sets the state of `renderWorldCopies`.
|
|
935
1121
|
*
|
|
936
|
-
* @param
|
|
1122
|
+
* @param renderWorldCopies - If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
|
|
937
1123
|
* - When the map is zoomed out far enough that a single representation of the world does not fill the map's entire
|
|
938
1124
|
* container, there will be blank space beyond 180 and -180 degrees longitude.
|
|
939
1125
|
* - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
|
|
940
1126
|
* map and the other on the left edge of the map) at every zoom level.
|
|
941
1127
|
*
|
|
942
1128
|
* `undefined` is treated as `true`, `null` is treated as `false`.
|
|
943
|
-
* @returns
|
|
1129
|
+
* @returns `this`
|
|
944
1130
|
* @example
|
|
1131
|
+
* ```ts
|
|
945
1132
|
* map.setRenderWorldCopies(true);
|
|
946
|
-
*
|
|
1133
|
+
* ```
|
|
1134
|
+
* @see [Render world copies](https://maplibre.org/maplibre-gl-js/docs/examples/render-world-copies/)
|
|
947
1135
|
*/
|
|
948
|
-
setRenderWorldCopies(renderWorldCopies?: boolean | null) {
|
|
1136
|
+
setRenderWorldCopies(renderWorldCopies?: boolean | null): Map {
|
|
949
1137
|
this.transform.renderWorldCopies = renderWorldCopies;
|
|
950
1138
|
return this._update();
|
|
951
1139
|
}
|
|
@@ -953,19 +1141,19 @@ class Map extends Camera {
|
|
|
953
1141
|
/**
|
|
954
1142
|
* Gets the map's cooperativeGestures option
|
|
955
1143
|
*
|
|
956
|
-
* @returns
|
|
1144
|
+
* @returns The gestureOptions
|
|
957
1145
|
*/
|
|
958
|
-
getCooperativeGestures() {
|
|
1146
|
+
getCooperativeGestures(): boolean | GestureOptions {
|
|
959
1147
|
return this._cooperativeGestures;
|
|
960
1148
|
}
|
|
961
1149
|
|
|
962
1150
|
/**
|
|
963
1151
|
* Sets or clears the map's cooperativeGestures option
|
|
964
1152
|
*
|
|
965
|
-
* @param
|
|
966
|
-
* @returns
|
|
1153
|
+
* @param gestureOptions - If `true` or set to an options object, map is only accessible on desktop while holding Command/Ctrl and only accessible on mobile with two fingers. Interacting with the map using normal gestures will trigger an informational screen. With this option enabled, "drag to pitch" requires a three-finger gesture.
|
|
1154
|
+
* @returns `this`
|
|
967
1155
|
*/
|
|
968
|
-
setCooperativeGestures(gestureOptions?: GestureOptions | boolean | null) {
|
|
1156
|
+
setCooperativeGestures(gestureOptions?: GestureOptions | boolean | null): Map {
|
|
969
1157
|
this._cooperativeGestures = gestureOptions;
|
|
970
1158
|
if (this._cooperativeGestures) {
|
|
971
1159
|
this._setupCooperativeGestures();
|
|
@@ -980,13 +1168,15 @@ class Map extends Camera {
|
|
|
980
1168
|
* Returns a [Point](https://github.com/mapbox/point-geometry) representing pixel coordinates, relative to the map's `container`,
|
|
981
1169
|
* that correspond to the specified geographical location.
|
|
982
1170
|
*
|
|
983
|
-
* @param
|
|
984
|
-
* @returns
|
|
1171
|
+
* @param lnglat - The geographical location to project.
|
|
1172
|
+
* @returns The [Point](https://github.com/mapbox/point-geometry) corresponding to `lnglat`, relative to the map's `container`.
|
|
985
1173
|
* @example
|
|
986
|
-
*
|
|
987
|
-
*
|
|
1174
|
+
* ```ts
|
|
1175
|
+
* let coordinate = [-122.420679, 37.772537];
|
|
1176
|
+
* let point = map.project(coordinate);
|
|
1177
|
+
* ```
|
|
988
1178
|
*/
|
|
989
|
-
project(lnglat: LngLatLike) {
|
|
1179
|
+
project(lnglat: LngLatLike): Point {
|
|
990
1180
|
return this.transform.locationPoint(LngLat.convert(lnglat), this.style && this.terrain);
|
|
991
1181
|
}
|
|
992
1182
|
|
|
@@ -994,23 +1184,27 @@ class Map extends Camera {
|
|
|
994
1184
|
* Returns a {@link LngLat} representing geographical coordinates that correspond
|
|
995
1185
|
* to the specified pixel coordinates.
|
|
996
1186
|
*
|
|
997
|
-
* @param
|
|
998
|
-
* @returns
|
|
1187
|
+
* @param point - The pixel coordinates to unproject.
|
|
1188
|
+
* @returns The {@link LngLat} corresponding to `point`.
|
|
999
1189
|
* @example
|
|
1190
|
+
* ```ts
|
|
1000
1191
|
* map.on('click', function(e) {
|
|
1001
1192
|
* // When the map is clicked, get the geographic coordinate.
|
|
1002
|
-
*
|
|
1193
|
+
* let coordinate = map.unproject(e.point);
|
|
1003
1194
|
* });
|
|
1195
|
+
* ```
|
|
1004
1196
|
*/
|
|
1005
|
-
unproject(point: PointLike) {
|
|
1197
|
+
unproject(point: PointLike): LngLat {
|
|
1006
1198
|
return this.transform.pointLocation(Point.convert(point), this.terrain);
|
|
1007
1199
|
}
|
|
1008
1200
|
|
|
1009
1201
|
/**
|
|
1010
1202
|
* Returns true if the map is panning, zooming, rotating, or pitching due to a camera animation or user gesture.
|
|
1011
|
-
* @returns
|
|
1203
|
+
* @returns true if the map is moving.
|
|
1012
1204
|
* @example
|
|
1013
|
-
*
|
|
1205
|
+
* ```ts
|
|
1206
|
+
* let isMoving = map.isMoving();
|
|
1207
|
+
* ```
|
|
1014
1208
|
*/
|
|
1015
1209
|
isMoving(): boolean {
|
|
1016
1210
|
return this._moving || this.handlers?.isMoving();
|
|
@@ -1018,9 +1212,11 @@ class Map extends Camera {
|
|
|
1018
1212
|
|
|
1019
1213
|
/**
|
|
1020
1214
|
* Returns true if the map is zooming due to a camera animation or user gesture.
|
|
1021
|
-
* @returns
|
|
1215
|
+
* @returns true if the map is zooming.
|
|
1022
1216
|
* @example
|
|
1023
|
-
*
|
|
1217
|
+
* ```ts
|
|
1218
|
+
* let isZooming = map.isZooming();
|
|
1219
|
+
* ```
|
|
1024
1220
|
*/
|
|
1025
1221
|
isZooming(): boolean {
|
|
1026
1222
|
return this._zooming || this.handlers?.isZooming();
|
|
@@ -1028,15 +1224,17 @@ class Map extends Camera {
|
|
|
1028
1224
|
|
|
1029
1225
|
/**
|
|
1030
1226
|
* Returns true if the map is rotating due to a camera animation or user gesture.
|
|
1031
|
-
* @returns
|
|
1227
|
+
* @returns true if the map is rotating.
|
|
1032
1228
|
* @example
|
|
1229
|
+
* ```ts
|
|
1033
1230
|
* map.isRotating();
|
|
1231
|
+
* ```
|
|
1034
1232
|
*/
|
|
1035
1233
|
isRotating(): boolean {
|
|
1036
1234
|
return this._rotating || this.handlers?.isRotating();
|
|
1037
1235
|
}
|
|
1038
1236
|
|
|
1039
|
-
_createDelegatedListener(type:
|
|
1237
|
+
_createDelegatedListener(type: keyof MapEventType | string, layerId: string, listener: Listener): {
|
|
1040
1238
|
layer: string;
|
|
1041
1239
|
listener: Listener;
|
|
1042
1240
|
delegates: {[type in keyof MapEventType]?: (e: any) => void};
|
|
@@ -1090,70 +1288,71 @@ class Map extends Camera {
|
|
|
1090
1288
|
|
|
1091
1289
|
/**
|
|
1092
1290
|
* Adds a listener for events of a specified type, optionally limited to features in a specified style layer.
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1291
|
+
* See {@link MapEventType} and {@link MapLayerEventType} for a full list of events and their description.
|
|
1292
|
+
*
|
|
1293
|
+
* | Event | Compatible with `layerId` |
|
|
1294
|
+
* |------------------------|---------------------------|
|
|
1295
|
+
* | `mousedown` | yes |
|
|
1296
|
+
* | `mouseup` | yes |
|
|
1297
|
+
* | `mouseover` | yes |
|
|
1298
|
+
* | `mouseout` | yes |
|
|
1299
|
+
* | `mousemove` | yes |
|
|
1300
|
+
* | `mouseenter` | yes (required) |
|
|
1301
|
+
* | `mouseleave` | yes (required) |
|
|
1302
|
+
* | `click` | yes |
|
|
1303
|
+
* | `dblclick` | yes |
|
|
1304
|
+
* | `contextmenu` | yes |
|
|
1305
|
+
* | `touchstart` | yes |
|
|
1306
|
+
* | `touchend` | yes |
|
|
1307
|
+
* | `touchcancel` | yes |
|
|
1308
|
+
* | `wheel` | |
|
|
1309
|
+
* | `resize` | |
|
|
1310
|
+
* | `remove` | |
|
|
1311
|
+
* | `touchmove` | |
|
|
1312
|
+
* | `movestart` | |
|
|
1313
|
+
* | `move` | |
|
|
1314
|
+
* | `moveend` | |
|
|
1315
|
+
* | `dragstart` | |
|
|
1316
|
+
* | `drag` | |
|
|
1317
|
+
* | `dragend` | |
|
|
1318
|
+
* | `zoomstart` | |
|
|
1319
|
+
* | `zoom` | |
|
|
1320
|
+
* | `zoomend` | |
|
|
1321
|
+
* | `rotatestart` | |
|
|
1322
|
+
* | `rotate` | |
|
|
1323
|
+
* | `rotateend` | |
|
|
1324
|
+
* | `pitchstart` | |
|
|
1325
|
+
* | `pitch` | |
|
|
1326
|
+
* | `pitchend` | |
|
|
1327
|
+
* | `boxzoomstart` | |
|
|
1328
|
+
* | `boxzoomend` | |
|
|
1329
|
+
* | `boxzoomcancel` | |
|
|
1330
|
+
* | `webglcontextlost` | |
|
|
1331
|
+
* | `webglcontextrestored` | |
|
|
1332
|
+
* | `load` | |
|
|
1333
|
+
* | `render` | |
|
|
1334
|
+
* | `idle` | |
|
|
1335
|
+
* | `error` | |
|
|
1336
|
+
* | `data` | |
|
|
1337
|
+
* | `styledata` | |
|
|
1338
|
+
* | `sourcedata` | |
|
|
1339
|
+
* | `dataloading` | |
|
|
1340
|
+
* | `styledataloading` | |
|
|
1341
|
+
* | `sourcedataloading` | |
|
|
1342
|
+
* | `styleimagemissing` | |
|
|
1343
|
+
* | `dataabort` | |
|
|
1344
|
+
* | `sourcedataabort` | |
|
|
1345
|
+
*
|
|
1346
|
+
* @param type - The event type to listen for. Events compatible with the optional `layerId` parameter are triggered
|
|
1095
1347
|
* when the cursor enters a visible portion of the specified layer from outside that layer or outside the map canvas.
|
|
1096
|
-
*
|
|
1097
|
-
* | Event | Compatible with `layerId` |
|
|
1098
|
-
* |-----------------------------------------------------------|---------------------------|
|
|
1099
|
-
* | [`mousedown`](#map.event:mousedown) | yes |
|
|
1100
|
-
* | [`mouseup`](#map.event:mouseup) | yes |
|
|
1101
|
-
* | [`mouseover`](#map.event:mouseover) | yes |
|
|
1102
|
-
* | [`mouseout`](#map.event:mouseout) | yes |
|
|
1103
|
-
* | [`mousemove`](#map.event:mousemove) | yes |
|
|
1104
|
-
* | [`mouseenter`](#map.event:mouseenter) | yes (required) |
|
|
1105
|
-
* | [`mouseleave`](#map.event:mouseleave) | yes (required) |
|
|
1106
|
-
* | [`click`](#map.event:click) | yes |
|
|
1107
|
-
* | [`dblclick`](#map.event:dblclick) | yes |
|
|
1108
|
-
* | [`contextmenu`](#map.event:contextmenu) | yes |
|
|
1109
|
-
* | [`touchstart`](#map.event:touchstart) | yes |
|
|
1110
|
-
* | [`touchend`](#map.event:touchend) | yes |
|
|
1111
|
-
* | [`touchcancel`](#map.event:touchcancel) | yes |
|
|
1112
|
-
* | [`wheel`](#map.event:wheel) | |
|
|
1113
|
-
* | [`resize`](#map.event:resize) | |
|
|
1114
|
-
* | [`remove`](#map.event:remove) | |
|
|
1115
|
-
* | [`touchmove`](#map.event:touchmove) | |
|
|
1116
|
-
* | [`movestart`](#map.event:movestart) | |
|
|
1117
|
-
* | [`move`](#map.event:move) | |
|
|
1118
|
-
* | [`moveend`](#map.event:moveend) | |
|
|
1119
|
-
* | [`dragstart`](#map.event:dragstart) | |
|
|
1120
|
-
* | [`drag`](#map.event:drag) | |
|
|
1121
|
-
* | [`dragend`](#map.event:dragend) | |
|
|
1122
|
-
* | [`zoomstart`](#map.event:zoomstart) | |
|
|
1123
|
-
* | [`zoom`](#map.event:zoom) | |
|
|
1124
|
-
* | [`zoomend`](#map.event:zoomend) | |
|
|
1125
|
-
* | [`rotatestart`](#map.event:rotatestart) | |
|
|
1126
|
-
* | [`rotate`](#map.event:rotate) | |
|
|
1127
|
-
* | [`rotateend`](#map.event:rotateend) | |
|
|
1128
|
-
* | [`pitchstart`](#map.event:pitchstart) | |
|
|
1129
|
-
* | [`pitch`](#map.event:pitch) | |
|
|
1130
|
-
* | [`pitchend`](#map.event:pitchend) | |
|
|
1131
|
-
* | [`boxzoomstart`](#map.event:boxzoomstart) | |
|
|
1132
|
-
* | [`boxzoomend`](#map.event:boxzoomend) | |
|
|
1133
|
-
* | [`boxzoomcancel`](#map.event:boxzoomcancel) | |
|
|
1134
|
-
* | [`webglcontextlost`](#map.event:webglcontextlost) | |
|
|
1135
|
-
* | [`webglcontextrestored`](#map.event:webglcontextrestored) | |
|
|
1136
|
-
* | [`load`](#map.event:load) | |
|
|
1137
|
-
* | [`render`](#map.event:render) | |
|
|
1138
|
-
* | [`idle`](#map.event:idle) | |
|
|
1139
|
-
* | [`error`](#map.event:error) | |
|
|
1140
|
-
* | [`data`](#map.event:data) | |
|
|
1141
|
-
* | [`styledata`](#map.event:styledata) | |
|
|
1142
|
-
* | [`sourcedata`](#map.event:sourcedata) | |
|
|
1143
|
-
* | [`dataloading`](#map.event:dataloading) | |
|
|
1144
|
-
* | [`styledataloading`](#map.event:styledataloading) | |
|
|
1145
|
-
* | [`sourcedataloading`](#map.event:sourcedataloading) | |
|
|
1146
|
-
* | [`styleimagemissing`](#map.event:styleimagemissing) | |
|
|
1147
|
-
* | [`dataabort`](#map.event:dataabort) | |
|
|
1148
|
-
* | [`sourcedataabort`](#map.event:sourcedataabort) | |
|
|
1149
|
-
*
|
|
1150
|
-
* @param {string | Listener} layer The ID of a style layer or a listener if no ID is provided. Event will only be triggered if its location
|
|
1348
|
+
* @param layer - The ID of a style layer or a listener if no ID is provided. Event will only be triggered if its location
|
|
1151
1349
|
* is within a visible feature in this layer. The event will have a `features` property containing
|
|
1152
1350
|
* an array of the matching features. If `layerIdOrListener` is not supplied, the event will not have a `features` property.
|
|
1153
1351
|
* Please note that many event types are not compatible with the optional `layerIdOrListener` parameter.
|
|
1154
|
-
* @param
|
|
1155
|
-
* @returns
|
|
1352
|
+
* @param listener - The function to be called when the event is fired.
|
|
1353
|
+
* @returns `this`
|
|
1156
1354
|
* @example
|
|
1355
|
+
* ```ts
|
|
1157
1356
|
* // Set an event listener that will fire
|
|
1158
1357
|
* // when the map has finished loading
|
|
1159
1358
|
* map.on('load', function() {
|
|
@@ -1175,28 +1374,38 @@ class Map extends Camera {
|
|
|
1175
1374
|
* }
|
|
1176
1375
|
* });
|
|
1177
1376
|
* });
|
|
1377
|
+
* ```
|
|
1178
1378
|
* @example
|
|
1379
|
+
* ```ts
|
|
1179
1380
|
* // Set an event listener that will fire
|
|
1180
1381
|
* // when a feature on the countries layer of the map is clicked
|
|
1181
|
-
* map.on('click', 'countries',
|
|
1382
|
+
* map.on('click', 'countries', (e) => {
|
|
1182
1383
|
* new maplibregl.Popup()
|
|
1183
1384
|
* .setLngLat(e.lngLat)
|
|
1184
1385
|
* .setHTML(`Country name: ${e.features[0].properties.name}`)
|
|
1185
1386
|
* .addTo(map);
|
|
1186
1387
|
* });
|
|
1187
|
-
*
|
|
1188
|
-
* @see [
|
|
1189
|
-
* @see [
|
|
1190
|
-
* @see [Create a
|
|
1388
|
+
* ```
|
|
1389
|
+
* @see [Display popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
|
|
1390
|
+
* @see [Center the map on a clicked symbol](https://maplibre.org/maplibre-gl-js/docs/examples/center-on-symbol/)
|
|
1391
|
+
* @see [Create a hover effect](https://maplibre.org/maplibre-gl-js/docs/examples/hover-styles/)
|
|
1392
|
+
* @see [Create a draggable marker](https://maplibre.org/maplibre-gl-js/docs/examples/drag-a-point/)
|
|
1191
1393
|
*/
|
|
1394
|
+
on(type: keyof MapEventType | string, listener: Listener): this;
|
|
1192
1395
|
on<T extends keyof MapLayerEventType>(
|
|
1193
1396
|
type: T,
|
|
1194
1397
|
layer: string,
|
|
1195
1398
|
listener: (ev: MapLayerEventType[T] & Object) => void,
|
|
1196
|
-
):
|
|
1399
|
+
): Map;
|
|
1197
1400
|
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
1198
|
-
|
|
1199
|
-
|
|
1401
|
+
/**
|
|
1402
|
+
* This is an overload of the `on` method that allows to listen to events based on the `layerId`
|
|
1403
|
+
* @param type - The type of the event.
|
|
1404
|
+
* @param layerIdOrListener - The ID of the layer.
|
|
1405
|
+
* @param listener - The listener callback.
|
|
1406
|
+
* @returns `this`
|
|
1407
|
+
*/
|
|
1408
|
+
on(type: keyof MapEventType | string, layerIdOrListener: string | Listener, listener?: Listener): this {
|
|
1200
1409
|
if (listener === undefined) {
|
|
1201
1410
|
return super.on(type, layerIdOrListener as Listener);
|
|
1202
1411
|
}
|
|
@@ -1208,49 +1417,35 @@ class Map extends Camera {
|
|
|
1208
1417
|
this._delegatedListeners[type].push(delegatedListener);
|
|
1209
1418
|
|
|
1210
1419
|
for (const event in delegatedListener.delegates) {
|
|
1211
|
-
this.on(event
|
|
1420
|
+
this.on(event, delegatedListener.delegates[event]);
|
|
1212
1421
|
}
|
|
1213
1422
|
|
|
1214
1423
|
return this;
|
|
1215
1424
|
}
|
|
1216
1425
|
|
|
1217
|
-
/**
|
|
1218
|
-
* Adds a listener that will be called only once to a specified event type.
|
|
1219
|
-
*
|
|
1220
|
-
* @method
|
|
1221
|
-
* @name once
|
|
1222
|
-
* @memberof Map
|
|
1223
|
-
* @instance
|
|
1224
|
-
* @param {string} type The event type to add a listener for.
|
|
1225
|
-
* @param {Function} listener The function to be called when the event is fired.
|
|
1226
|
-
* The listener function is called with the data object passed to `fire`,
|
|
1227
|
-
* extended with `target` and `type` properties.
|
|
1228
|
-
* @returns {Map} `this`
|
|
1229
|
-
*/
|
|
1230
|
-
|
|
1231
1426
|
/**
|
|
1232
1427
|
* Adds a listener that will be called only once to a specified event type occurring on features in a specified style layer.
|
|
1233
1428
|
*
|
|
1234
|
-
* @param
|
|
1429
|
+
* @param type - The event type to listen for; one of `'mousedown'`, `'mouseup'`, `'click'`, `'dblclick'`,
|
|
1235
1430
|
* `'mousemove'`, `'mouseenter'`, `'mouseleave'`, `'mouseover'`, `'mouseout'`, `'contextmenu'`, `'touchstart'`,
|
|
1236
1431
|
* `'touchend'`, or `'touchcancel'`. `mouseenter` and `mouseover` events are triggered when the cursor enters
|
|
1237
1432
|
* a visible portion of the specified layer from outside that layer or outside the map canvas. `mouseleave`
|
|
1238
1433
|
* and `mouseout` events are triggered when the cursor leaves a visible portion of the specified layer, or leaves
|
|
1239
1434
|
* the map canvas.
|
|
1240
|
-
* @param
|
|
1435
|
+
* @param layer - The ID of a style layer or a listener if no ID is provided. Only events whose location is within a visible
|
|
1241
1436
|
* feature in this layer will trigger the listener. The event will have a `features` property containing
|
|
1242
1437
|
* an array of the matching features.
|
|
1243
|
-
* @param
|
|
1244
|
-
* @returns
|
|
1438
|
+
* @param listener - The function to be called when the event is fired.
|
|
1439
|
+
* @returns `this` if listener is provided, promise otherwise to allow easier usage of async/await
|
|
1245
1440
|
*/
|
|
1441
|
+
once(type: keyof MapEventType | string, listener?: Listener): this | Promise<any>;
|
|
1246
1442
|
once<T extends keyof MapLayerEventType>(
|
|
1247
1443
|
type: T,
|
|
1248
1444
|
layer: string,
|
|
1249
1445
|
listener?: (ev: MapLayerEventType[T] & Object) => void,
|
|
1250
1446
|
): this | Promise<MapLayerEventType[T] & Object>;
|
|
1251
1447
|
once<T extends keyof MapEventType>(type: T, listener?: (ev: MapEventType[T] & Object) => void): this | Promise<any>;
|
|
1252
|
-
once(type:
|
|
1253
|
-
once(type: MapEvent | string, layerIdOrListener: string | Listener, listener?: Listener): this | Promise<any> {
|
|
1448
|
+
once(type: keyof MapEventType | string, layerIdOrListener: string | Listener, listener?: Listener): this | Promise<any> {
|
|
1254
1449
|
|
|
1255
1450
|
if (listener === undefined) {
|
|
1256
1451
|
return super.once(type, layerIdOrListener as Listener);
|
|
@@ -1259,40 +1454,28 @@ class Map extends Camera {
|
|
|
1259
1454
|
const delegatedListener = this._createDelegatedListener(type, layerIdOrListener as string, listener);
|
|
1260
1455
|
|
|
1261
1456
|
for (const event in delegatedListener.delegates) {
|
|
1262
|
-
this.once(event
|
|
1457
|
+
this.once(event, delegatedListener.delegates[event]);
|
|
1263
1458
|
}
|
|
1264
1459
|
|
|
1265
1460
|
return this;
|
|
1266
1461
|
}
|
|
1267
1462
|
|
|
1268
|
-
/**
|
|
1269
|
-
* Removes an event listener previously added with `Map#on`.
|
|
1270
|
-
*
|
|
1271
|
-
* @method
|
|
1272
|
-
* @name off
|
|
1273
|
-
* @memberof Map
|
|
1274
|
-
* @instance
|
|
1275
|
-
* @param {string} type The event type previously used to install the listener.
|
|
1276
|
-
* @param {Function} listener The function previously installed as a listener.
|
|
1277
|
-
* @returns {Map} `this`
|
|
1278
|
-
*/
|
|
1279
|
-
|
|
1280
1463
|
/**
|
|
1281
1464
|
* Removes an event listener for layer-specific events previously added with `Map#on`.
|
|
1282
1465
|
*
|
|
1283
|
-
* @param
|
|
1284
|
-
* @param
|
|
1285
|
-
* @param
|
|
1286
|
-
* @returns
|
|
1466
|
+
* @param type - The event type previously used to install the listener.
|
|
1467
|
+
* @param layerIdOrListener - The layer ID or listener previously used to install the listener.
|
|
1468
|
+
* @param listener - (optional) The function previously installed as a listener.
|
|
1469
|
+
* @returns `this`
|
|
1287
1470
|
*/
|
|
1471
|
+
off(type: keyof MapEventType | string, listener: Listener): this;
|
|
1288
1472
|
off<T extends keyof MapLayerEventType>(
|
|
1289
1473
|
type: T,
|
|
1290
1474
|
layer: string,
|
|
1291
1475
|
listener: (ev: MapLayerEventType[T] & Object) => void,
|
|
1292
1476
|
): this;
|
|
1293
1477
|
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
1294
|
-
off(type:
|
|
1295
|
-
off(type: MapEvent | string, layerIdOrListener: string | Listener, listener?: Listener): this {
|
|
1478
|
+
off(type: keyof MapEventType | string, layerIdOrListener: string | Listener, listener?: Listener): this {
|
|
1296
1479
|
if (listener === undefined) {
|
|
1297
1480
|
return super.off(type, layerIdOrListener as Listener);
|
|
1298
1481
|
}
|
|
@@ -1322,21 +1505,15 @@ class Map extends Camera {
|
|
|
1322
1505
|
* Returns an array of MapGeoJSONFeature objects
|
|
1323
1506
|
* representing visible features that satisfy the query parameters.
|
|
1324
1507
|
*
|
|
1325
|
-
* @param
|
|
1508
|
+
* @param geometryOrOptions - (optional) The geometry of the query region:
|
|
1326
1509
|
* either a single point or southwest and northeast points describing a bounding box.
|
|
1327
1510
|
* Omitting this parameter (i.e. calling {@link Map#queryRenderedFeatures} with zero arguments,
|
|
1328
1511
|
* or with only a `options` argument) is equivalent to passing a bounding box encompassing the entire
|
|
1329
1512
|
* map viewport.
|
|
1330
|
-
* The geometryOrOptions can receive a QueryRenderedFeaturesOptions only to support a situation where the function receives only one parameter which is the options parameter.
|
|
1331
|
-
* @param
|
|
1332
|
-
* @param {Array<string>} [options.layers] (optional) An array of [style layer IDs](https://maplibre.org/maplibre-style-spec/#layer-id) for the query to inspect.
|
|
1333
|
-
* Only features within these layers will be returned. If this parameter is undefined, all layers will be checked.
|
|
1334
|
-
* @param {FilterSpecification} [options.filter] (optional) A [filter](https://maplibre.org/maplibre-style-spec/layers/#filter)
|
|
1335
|
-
* to limit query results.
|
|
1336
|
-
* @param {Array<string>} [options.availableImages] (optional) An array of string representing the available images
|
|
1337
|
-
* @param {boolean} [options.validate=true] (optional) Whether to check if the [options.filter] conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
|
|
1513
|
+
* The geometryOrOptions can receive a {@link QueryRenderedFeaturesOptions} only to support a situation where the function receives only one parameter which is the options parameter.
|
|
1514
|
+
* @param options - (optional) Options object.
|
|
1338
1515
|
*
|
|
1339
|
-
* @returns
|
|
1516
|
+
* @returns An array of MapGeoJSONFeature objects.
|
|
1340
1517
|
*
|
|
1341
1518
|
* The `properties` value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only
|
|
1342
1519
|
* string and numeric property values are supported (i.e. `null`, `Array`, and `Object` values are not supported).
|
|
@@ -1368,32 +1545,40 @@ class Map extends Camera {
|
|
|
1368
1545
|
* tiles due to tile buffering.
|
|
1369
1546
|
*
|
|
1370
1547
|
* @example
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1548
|
+
* Find all features at a point
|
|
1549
|
+
* ```ts
|
|
1550
|
+
* let features = map.queryRenderedFeatures(
|
|
1373
1551
|
* [20, 35],
|
|
1374
1552
|
* { layers: ['my-layer-name'] }
|
|
1375
1553
|
* );
|
|
1554
|
+
* ```
|
|
1376
1555
|
*
|
|
1377
1556
|
* @example
|
|
1378
|
-
*
|
|
1379
|
-
*
|
|
1557
|
+
* Find all features within a static bounding box
|
|
1558
|
+
* ```ts
|
|
1559
|
+
* let features = map.queryRenderedFeatures(
|
|
1380
1560
|
* [[10, 20], [30, 50]],
|
|
1381
1561
|
* { layers: ['my-layer-name'] }
|
|
1382
1562
|
* );
|
|
1563
|
+
* ```
|
|
1383
1564
|
*
|
|
1384
1565
|
* @example
|
|
1385
|
-
*
|
|
1386
|
-
*
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1566
|
+
* Find all features within a bounding box around a point
|
|
1567
|
+
* ```ts
|
|
1568
|
+
* let width = 10;
|
|
1569
|
+
* let height = 20;
|
|
1570
|
+
* let features = map.queryRenderedFeatures([
|
|
1389
1571
|
* [point.x - width / 2, point.y - height / 2],
|
|
1390
1572
|
* [point.x + width / 2, point.y + height / 2]
|
|
1391
1573
|
* ], { layers: ['my-layer-name'] });
|
|
1574
|
+
* ```
|
|
1392
1575
|
*
|
|
1393
1576
|
* @example
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1396
|
-
*
|
|
1577
|
+
* Query all rendered features from a single layer
|
|
1578
|
+
* ```ts
|
|
1579
|
+
* let features = map.queryRenderedFeatures({ layers: ['my-layer-name'] });
|
|
1580
|
+
* ```
|
|
1581
|
+
* @see [Get features under the mouse pointer](https://maplibre.org/maplibre-gl-js/docs/examples/queryrenderedfeatures/)
|
|
1397
1582
|
*/
|
|
1398
1583
|
queryRenderedFeatures(geometryOrOptions?: PointLike | [PointLike, PointLike] | QueryRenderedFeaturesOptions, options?: QueryRenderedFeaturesOptions): MapGeoJSONFeature[] {
|
|
1399
1584
|
if (!this.style) {
|
|
@@ -1419,15 +1604,9 @@ class Map extends Camera {
|
|
|
1419
1604
|
* Returns an array of MapGeoJSONFeature objects
|
|
1420
1605
|
* representing features within the specified vector tile or GeoJSON source that satisfy the query parameters.
|
|
1421
1606
|
*
|
|
1422
|
-
* @param
|
|
1423
|
-
* @param
|
|
1424
|
-
* @
|
|
1425
|
-
* to query. *For vector tile sources, this parameter is required.* For GeoJSON sources, it is ignored.
|
|
1426
|
-
* @param {Array} [parameters.filter] A [filter](https://maplibre.org/maplibre-style-spec/layers/#filter)
|
|
1427
|
-
* to limit query results.
|
|
1428
|
-
* @param {boolean} [parameters.validate=true] Whether to check if the [parameters.filter] conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
|
|
1429
|
-
*
|
|
1430
|
-
* @returns {Array<MapGeoJSONFeature>} An array of MapGeoJSONFeature objects.
|
|
1607
|
+
* @param sourceId - The ID of the vector tile or GeoJSON source to query.
|
|
1608
|
+
* @param parameters - The options object.
|
|
1609
|
+
* @returns An array of MapGeoJSONFeature objects.
|
|
1431
1610
|
*
|
|
1432
1611
|
* In contrast to {@link Map#queryRenderedFeatures}, this function returns all features matching the query parameters,
|
|
1433
1612
|
* whether or not they are rendered by the current style (i.e. visible). The domain of the query includes all currently-loaded
|
|
@@ -1443,17 +1622,15 @@ class Map extends Camera {
|
|
|
1443
1622
|
* tiles due to tile buffering.
|
|
1444
1623
|
*
|
|
1445
1624
|
* @example
|
|
1446
|
-
*
|
|
1447
|
-
*
|
|
1625
|
+
* Find all features in one source layer in a vector source
|
|
1626
|
+
* ```ts
|
|
1627
|
+
* let features = map.querySourceFeatures('your-source-id', {
|
|
1448
1628
|
* sourceLayer: 'your-source-layer'
|
|
1449
1629
|
* });
|
|
1630
|
+
* ```
|
|
1450
1631
|
*
|
|
1451
1632
|
*/
|
|
1452
|
-
querySourceFeatures(sourceId: string, parameters?: {
|
|
1453
|
-
sourceLayer?: string;
|
|
1454
|
-
filter?: FilterSpecification;
|
|
1455
|
-
validate?: boolean;
|
|
1456
|
-
} | null): MapGeoJSONFeature[] {
|
|
1633
|
+
querySourceFeatures(sourceId: string, parameters?: QuerySourceFeatureOptions | null): MapGeoJSONFeature[] {
|
|
1457
1634
|
return this.style.querySourceFeatures(sourceId, parameters);
|
|
1458
1635
|
}
|
|
1459
1636
|
|
|
@@ -1467,22 +1644,13 @@ class Map extends Camera {
|
|
|
1467
1644
|
* the given one from scratch.
|
|
1468
1645
|
*
|
|
1469
1646
|
*
|
|
1470
|
-
* @param style A JSON object conforming to the schema described in the
|
|
1647
|
+
* @param style - A JSON object conforming to the schema described in the
|
|
1471
1648
|
* [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/), or a URL to such JSON.
|
|
1472
|
-
* @param
|
|
1473
|
-
* @
|
|
1474
|
-
* and building the given one instead of attempting a diff-based update.
|
|
1475
|
-
* @param {boolean} [options.validate=true] If false, style validation will be skipped. Useful in production environment.
|
|
1476
|
-
* @param {string} [options.localIdeographFontFamily='sans-serif'] Defines a CSS
|
|
1477
|
-
* font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs', 'Hiragana', 'Katakana' and 'Hangul Syllables' ranges.
|
|
1478
|
-
* In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
|
|
1479
|
-
* Set to `false`, to enable font settings from the map's style for these glyph ranges.
|
|
1480
|
-
* Forces a full update.
|
|
1481
|
-
* @param {TransformStyleFunction} [options.transformStyle=undefined] transformStyle is a convenience function
|
|
1482
|
-
* that allows to modify a style after it is fetched but before it is committed to the map state. Refer to {@link TransformStyleFunction}.
|
|
1483
|
-
* @returns {Map} `this`
|
|
1649
|
+
* @param options - The options object.
|
|
1650
|
+
* @returns `this`
|
|
1484
1651
|
*
|
|
1485
1652
|
* @example
|
|
1653
|
+
* ```ts
|
|
1486
1654
|
* map.setStyle("https://demotiles.maplibre.org/style.json");
|
|
1487
1655
|
*
|
|
1488
1656
|
* map.setStyle('https://demotiles.maplibre.org/style.json', {
|
|
@@ -1512,8 +1680,9 @@ class Map extends Camera {
|
|
|
1512
1680
|
* ]
|
|
1513
1681
|
* })
|
|
1514
1682
|
* });
|
|
1683
|
+
* ```
|
|
1515
1684
|
*/
|
|
1516
|
-
setStyle(style: StyleSpecification | string | null, options?: StyleSwapOptions & StyleOptions) {
|
|
1685
|
+
setStyle(style: StyleSpecification | string | null, options?: StyleSwapOptions & StyleOptions): this {
|
|
1517
1686
|
options = extend({},
|
|
1518
1687
|
{
|
|
1519
1688
|
localIdeographFontFamily: this._localIdeographFontFamily,
|
|
@@ -1532,15 +1701,17 @@ class Map extends Camera {
|
|
|
1532
1701
|
/**
|
|
1533
1702
|
* Updates the requestManager's transform request with a new function
|
|
1534
1703
|
*
|
|
1535
|
-
* @param transformRequest A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
|
|
1704
|
+
* @param transformRequest - A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
|
|
1536
1705
|
* Expected to return an object with a `url` property and optionally `headers` and `credentials` properties
|
|
1537
1706
|
*
|
|
1538
|
-
* @returns
|
|
1707
|
+
* @returns `this`
|
|
1539
1708
|
*
|
|
1540
|
-
*
|
|
1541
|
-
*
|
|
1709
|
+
* @example
|
|
1710
|
+
* ```ts
|
|
1711
|
+
* map.setTransformRequest((url: string, resourceType: string) => {});
|
|
1712
|
+
* ```
|
|
1542
1713
|
*/
|
|
1543
|
-
setTransformRequest(transformRequest: RequestTransformFunction) {
|
|
1714
|
+
setTransformRequest(transformRequest: RequestTransformFunction): this {
|
|
1544
1715
|
this._requestManager.setTransformRequest(transformRequest);
|
|
1545
1716
|
return this;
|
|
1546
1717
|
}
|
|
@@ -1627,10 +1798,12 @@ class Map extends Camera {
|
|
|
1627
1798
|
/**
|
|
1628
1799
|
* Returns the map's MapLibre style object, a JSON object which can be used to recreate the map's style.
|
|
1629
1800
|
*
|
|
1630
|
-
* @returns
|
|
1801
|
+
* @returns The map's style JSON object.
|
|
1631
1802
|
*
|
|
1632
1803
|
* @example
|
|
1633
|
-
*
|
|
1804
|
+
* ```ts
|
|
1805
|
+
* let styleJson = map.getStyle();
|
|
1806
|
+
* ```
|
|
1634
1807
|
*
|
|
1635
1808
|
*/
|
|
1636
1809
|
getStyle(): StyleSpecification {
|
|
@@ -1642,12 +1815,14 @@ class Map extends Camera {
|
|
|
1642
1815
|
/**
|
|
1643
1816
|
* Returns a Boolean indicating whether the map's style is fully loaded.
|
|
1644
1817
|
*
|
|
1645
|
-
* @returns
|
|
1818
|
+
* @returns A Boolean indicating whether the style is fully loaded.
|
|
1646
1819
|
*
|
|
1647
1820
|
* @example
|
|
1648
|
-
*
|
|
1821
|
+
* ```ts
|
|
1822
|
+
* let styleLoadStatus = map.isStyleLoaded();
|
|
1823
|
+
* ```
|
|
1649
1824
|
*/
|
|
1650
|
-
isStyleLoaded() {
|
|
1825
|
+
isStyleLoaded(): boolean | void {
|
|
1651
1826
|
if (!this.style) return warnOnce('There is no style added to the map.');
|
|
1652
1827
|
return this.style.loaded();
|
|
1653
1828
|
}
|
|
@@ -1655,18 +1830,21 @@ class Map extends Camera {
|
|
|
1655
1830
|
/**
|
|
1656
1831
|
* Adds a source to the map's style.
|
|
1657
1832
|
*
|
|
1658
|
-
* @param
|
|
1659
|
-
* @param
|
|
1833
|
+
* @param id - The ID of the source to add. Must not conflict with existing sources.
|
|
1834
|
+
* @param source - The source object, conforming to the
|
|
1660
1835
|
* MapLibre Style Specification's [source definition](https://maplibre.org/maplibre-style-spec/#sources) or
|
|
1661
|
-
* {@link
|
|
1662
|
-
* @
|
|
1663
|
-
* @returns
|
|
1836
|
+
* {@link CanvasSourceSpecification}.
|
|
1837
|
+
* @event `source.add`
|
|
1838
|
+
* @returns `this`
|
|
1664
1839
|
* @example
|
|
1840
|
+
* ```ts
|
|
1665
1841
|
* map.addSource('my-data', {
|
|
1666
1842
|
* type: 'vector',
|
|
1667
1843
|
* url: 'https://demotiles.maplibre.org/tiles/tiles.json'
|
|
1668
1844
|
* });
|
|
1845
|
+
* ```
|
|
1669
1846
|
* @example
|
|
1847
|
+
* ```ts
|
|
1670
1848
|
* map.addSource('my-data', {
|
|
1671
1849
|
* "type": "geojson",
|
|
1672
1850
|
* "data": {
|
|
@@ -1681,9 +1859,10 @@ class Map extends Camera {
|
|
|
1681
1859
|
* }
|
|
1682
1860
|
* }
|
|
1683
1861
|
* });
|
|
1684
|
-
*
|
|
1862
|
+
* ```
|
|
1863
|
+
* @see GeoJSON source: [Add live realtime data](https://maplibre.org/maplibre-gl-js/docs/examples/live-geojson/)
|
|
1685
1864
|
*/
|
|
1686
|
-
addSource(id: string, source: SourceSpecification) {
|
|
1865
|
+
addSource(id: string, source: SourceSpecification): this {
|
|
1687
1866
|
this._lazyInitEmptyStyle();
|
|
1688
1867
|
this.style.addSource(id, source);
|
|
1689
1868
|
return this._update(true);
|
|
@@ -1693,12 +1872,14 @@ class Map extends Camera {
|
|
|
1693
1872
|
* Returns a Boolean indicating whether the source is loaded. Returns `true` if the source with
|
|
1694
1873
|
* the given ID in the map's style has no outstanding network requests, otherwise `false`.
|
|
1695
1874
|
*
|
|
1696
|
-
* @param
|
|
1697
|
-
* @returns
|
|
1875
|
+
* @param id - The ID of the source to be checked.
|
|
1876
|
+
* @returns A Boolean indicating whether the source is loaded.
|
|
1698
1877
|
* @example
|
|
1699
|
-
*
|
|
1878
|
+
* ```ts
|
|
1879
|
+
* let sourceLoaded = map.isSourceLoaded('bathymetry-data');
|
|
1880
|
+
* ```
|
|
1700
1881
|
*/
|
|
1701
|
-
isSourceLoaded(id: string) {
|
|
1882
|
+
isSourceLoaded(id: string): boolean {
|
|
1702
1883
|
const source = this.style && this.style.sourceCaches[id];
|
|
1703
1884
|
if (source === undefined) {
|
|
1704
1885
|
this.fire(new ErrorEvent(new Error(`There is no source with ID '${id}'`)));
|
|
@@ -1709,12 +1890,14 @@ class Map extends Camera {
|
|
|
1709
1890
|
|
|
1710
1891
|
/**
|
|
1711
1892
|
* Loads a 3D terrain mesh, based on a "raster-dem" source.
|
|
1712
|
-
* @param
|
|
1713
|
-
* @returns
|
|
1893
|
+
* @param options - Options object.
|
|
1894
|
+
* @returns `this`
|
|
1714
1895
|
* @example
|
|
1896
|
+
* ```ts
|
|
1715
1897
|
* map.setTerrain({ source: 'terrain' });
|
|
1898
|
+
* ```
|
|
1716
1899
|
*/
|
|
1717
|
-
setTerrain(options: TerrainSpecification):
|
|
1900
|
+
setTerrain(options: TerrainSpecification): this {
|
|
1718
1901
|
this.style._checkLoaded();
|
|
1719
1902
|
|
|
1720
1903
|
// clear event handlers
|
|
@@ -1758,9 +1941,11 @@ class Map extends Camera {
|
|
|
1758
1941
|
|
|
1759
1942
|
/**
|
|
1760
1943
|
* Get the terrain-options if terrain is loaded
|
|
1761
|
-
* @returns
|
|
1944
|
+
* @returns the TerrainSpecification passed to setTerrain
|
|
1762
1945
|
* @example
|
|
1946
|
+
* ```ts
|
|
1763
1947
|
* map.getTerrain(); // { source: 'terrain' };
|
|
1948
|
+
* ```
|
|
1764
1949
|
*/
|
|
1765
1950
|
getTerrain(): TerrainSpecification {
|
|
1766
1951
|
return this.terrain && this.terrain.options;
|
|
@@ -1770,9 +1955,11 @@ class Map extends Camera {
|
|
|
1770
1955
|
* Returns a Boolean indicating whether all tiles in the viewport from all sources on
|
|
1771
1956
|
* the style are loaded.
|
|
1772
1957
|
*
|
|
1773
|
-
* @returns
|
|
1958
|
+
* @returns A Boolean indicating whether all tiles are loaded.
|
|
1774
1959
|
* @example
|
|
1775
|
-
*
|
|
1960
|
+
* ```ts
|
|
1961
|
+
* let tilesLoaded = map.areTilesLoaded();
|
|
1962
|
+
* ```
|
|
1776
1963
|
*/
|
|
1777
1964
|
areTilesLoaded(): boolean {
|
|
1778
1965
|
const sources = this.style && this.style.sourceCaches;
|
|
@@ -1790,12 +1977,11 @@ class Map extends Camera {
|
|
|
1790
1977
|
/**
|
|
1791
1978
|
* Adds a [custom source type](#Custom Sources), making it available for use with
|
|
1792
1979
|
* {@link Map#addSource}.
|
|
1793
|
-
* @
|
|
1794
|
-
* @param
|
|
1795
|
-
* @param
|
|
1796
|
-
* @param {Callback<void>} callback Called when the source type is ready or with an error argument if there is an error.
|
|
1980
|
+
* @param name - The name of the source type; source definition objects use this name in the `{type: ...}` field.
|
|
1981
|
+
* @param SourceType - A {@link Source} constructor.
|
|
1982
|
+
* @param callback - Called when the source type is ready or with an error argument if there is an error.
|
|
1797
1983
|
*/
|
|
1798
|
-
addSourceType(name: string, SourceType:
|
|
1984
|
+
addSourceType(name: string, SourceType: SourceClass, callback: Callback<void>) {
|
|
1799
1985
|
this._lazyInitEmptyStyle();
|
|
1800
1986
|
return this.style.addSourceType(name, SourceType, callback);
|
|
1801
1987
|
}
|
|
@@ -1803,10 +1989,12 @@ class Map extends Camera {
|
|
|
1803
1989
|
/**
|
|
1804
1990
|
* Removes a source from the map's style.
|
|
1805
1991
|
*
|
|
1806
|
-
* @param
|
|
1807
|
-
* @returns
|
|
1992
|
+
* @param id - The ID of the source to remove.
|
|
1993
|
+
* @returns `this`
|
|
1808
1994
|
* @example
|
|
1995
|
+
* ```ts
|
|
1809
1996
|
* map.removeSource('bathymetry-data');
|
|
1997
|
+
* ```
|
|
1810
1998
|
*/
|
|
1811
1999
|
removeSource(id: string): Map {
|
|
1812
2000
|
this.style.removeSource(id);
|
|
@@ -1821,23 +2009,24 @@ class Map extends Camera {
|
|
|
1821
2009
|
* For example, setting the `data` for a GeoJSON source or updating the `url` and `coordinates`
|
|
1822
2010
|
* of an image source.
|
|
1823
2011
|
*
|
|
1824
|
-
* @param
|
|
1825
|
-
* @returns
|
|
2012
|
+
* @param id - The ID of the source to get.
|
|
2013
|
+
* @returns The style source with the specified ID or `undefined` if the ID
|
|
1826
2014
|
* corresponds to no existing sources.
|
|
1827
2015
|
* The shape of the object varies by source type.
|
|
1828
2016
|
* A list of options for each source type is available on the MapLibre Style Specification's
|
|
1829
2017
|
* [Sources](https://maplibre.org/maplibre-style-spec/sources/) page.
|
|
1830
2018
|
* @example
|
|
1831
|
-
*
|
|
1832
|
-
*
|
|
1833
|
-
*
|
|
1834
|
-
* @see [
|
|
2019
|
+
* ```ts
|
|
2020
|
+
* let sourceObject = map.getSource('points');
|
|
2021
|
+
* ```
|
|
2022
|
+
* @see [Create a draggable point](https://maplibre.org/maplibre-gl-js/docs/examples/drag-a-point/)
|
|
2023
|
+
* @see [Animate a point](https://maplibre.org/maplibre-gl-js/docs/examples/animate-point-along-line/)
|
|
2024
|
+
* @see [Add live realtime data](https://maplibre.org/maplibre-gl-js/docs/examples/live-geojson/)
|
|
1835
2025
|
*/
|
|
1836
2026
|
getSource(id: string): Source | undefined {
|
|
1837
2027
|
return this.style.getSource(id);
|
|
1838
2028
|
}
|
|
1839
2029
|
|
|
1840
|
-
// eslint-disable-next-line jsdoc/require-returns
|
|
1841
2030
|
/**
|
|
1842
2031
|
* Add an image to the style. This image can be displayed on the map like any other icon in the style's
|
|
1843
2032
|
* sprite using the image's ID with
|
|
@@ -1845,19 +2034,15 @@ class Map extends Camera {
|
|
|
1845
2034
|
* [`background-pattern`](https://maplibre.org/maplibre-style-spec/#paint-background-background-pattern),
|
|
1846
2035
|
* [`fill-pattern`](https://maplibre.org/maplibre-style-spec/#paint-fill-fill-pattern),
|
|
1847
2036
|
* or [`line-pattern`](https://maplibre.org/maplibre-style-spec/#paint-line-line-pattern).
|
|
1848
|
-
* A {@link
|
|
2037
|
+
* A {@link ErrorEvent} event will be fired if there is not enough space in the sprite to add this image.
|
|
1849
2038
|
*
|
|
1850
|
-
* @param id The ID of the image.
|
|
1851
|
-
* @param image The image as an `HTMLImageElement`, `ImageData`, `ImageBitmap` or object with `width`, `height`, and `data`
|
|
2039
|
+
* @param id - The ID of the image.
|
|
2040
|
+
* @param image - The image as an `HTMLImageElement`, `ImageData`, `ImageBitmap` or object with `width`, `height`, and `data`
|
|
1852
2041
|
* properties with the same format as `ImageData`.
|
|
1853
|
-
* @param options Options object.
|
|
1854
|
-
* @
|
|
1855
|
-
* @param options.sdf Whether the image should be interpreted as an SDF image
|
|
1856
|
-
* @param options.content `[x1, y1, x2, y2]` If `icon-text-fit` is used in a layer with this image, this option defines the part of the image that can be covered by the content in `text-field`.
|
|
1857
|
-
* @param options.stretchX `[[x1, x2], ...]` If `icon-text-fit` is used in a layer with this image, this option defines the part(s) of the image that can be stretched horizontally.
|
|
1858
|
-
* @param options.stretchY `[[y1, y2], ...]` If `icon-text-fit` is used in a layer with this image, this option defines the part(s) of the image that can be stretched vertically.
|
|
1859
|
-
*
|
|
2042
|
+
* @param options - Options object.
|
|
2043
|
+
* @returns `this`
|
|
1860
2044
|
* @example
|
|
2045
|
+
* ```ts
|
|
1861
2046
|
* // If the style's sprite does not already contain an image with ID 'cat',
|
|
1862
2047
|
* // add the image 'cat-icon.png' to the style's sprite with the ID 'cat'.
|
|
1863
2048
|
* map.loadImage('https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Cat_silhouette.svg/400px-Cat_silhouette.svg.png', function(error, image) {
|
|
@@ -1865,7 +2050,6 @@ class Map extends Camera {
|
|
|
1865
2050
|
* if (!map.hasImage('cat')) map.addImage('cat', image);
|
|
1866
2051
|
* });
|
|
1867
2052
|
*
|
|
1868
|
-
*
|
|
1869
2053
|
* // Add a stretchable image that can be used with `icon-text-fit`
|
|
1870
2054
|
* // In this example, the image is 600px wide by 400px high.
|
|
1871
2055
|
* map.loadImage('https://upload.wikimedia.org/wikipedia/commons/8/89/Black_and_White_Boxed_%28bordered%29.png', function(error, image) {
|
|
@@ -1878,10 +2062,9 @@ class Map extends Camera {
|
|
|
1878
2062
|
* });
|
|
1879
2063
|
* }
|
|
1880
2064
|
* });
|
|
1881
|
-
*
|
|
1882
|
-
*
|
|
1883
|
-
* @see Use `
|
|
1884
|
-
* @see Use `ImageData`: [Add a generated icon to the map](https://maplibre.org/maplibre-gl-js-docs/example/add-image-generated/)
|
|
2065
|
+
* ```
|
|
2066
|
+
* @see Use `HTMLImageElement`: [Add an icon to the map](https://maplibre.org/maplibre-gl-js/docs/examples/add-image/)
|
|
2067
|
+
* @see Use `ImageData`: [Add a generated icon to the map](https://maplibre.org/maplibre-gl-js/docs/examples/add-image-generated/)
|
|
1885
2068
|
*/
|
|
1886
2069
|
addImage(id: string,
|
|
1887
2070
|
image: HTMLImageElement | ImageBitmap | ImageData | {
|
|
@@ -1889,13 +2072,14 @@ class Map extends Camera {
|
|
|
1889
2072
|
height: number;
|
|
1890
2073
|
data: Uint8Array | Uint8ClampedArray;
|
|
1891
2074
|
} | StyleImageInterface,
|
|
1892
|
-
{
|
|
2075
|
+
options: Partial<StyleImageMetadata> = {}): this {
|
|
2076
|
+
const {
|
|
1893
2077
|
pixelRatio = 1,
|
|
1894
2078
|
sdf = false,
|
|
1895
2079
|
stretchX,
|
|
1896
2080
|
stretchY,
|
|
1897
2081
|
content
|
|
1898
|
-
}
|
|
2082
|
+
} = options;
|
|
1899
2083
|
this._lazyInitEmptyStyle();
|
|
1900
2084
|
const version = 0;
|
|
1901
2085
|
|
|
@@ -1924,10 +2108,10 @@ class Map extends Camera {
|
|
|
1924
2108
|
if (userImage.onAdd) {
|
|
1925
2109
|
userImage.onAdd(this, id);
|
|
1926
2110
|
}
|
|
2111
|
+
return this;
|
|
1927
2112
|
}
|
|
1928
2113
|
}
|
|
1929
2114
|
|
|
1930
|
-
// eslint-disable-next-line jsdoc/require-returns
|
|
1931
2115
|
/**
|
|
1932
2116
|
* Update an existing image in a style. This image can be displayed on the map like any other icon in the style's
|
|
1933
2117
|
* sprite using the image's ID with
|
|
@@ -1936,21 +2120,23 @@ class Map extends Camera {
|
|
|
1936
2120
|
* [`fill-pattern`](https://maplibre.org/maplibre-style-spec/#paint-fill-fill-pattern),
|
|
1937
2121
|
* or [`line-pattern`](https://maplibre.org/maplibre-style-spec/#paint-line-line-pattern).
|
|
1938
2122
|
*
|
|
1939
|
-
* @param id The ID of the image.
|
|
1940
|
-
* @param image The image as an `HTMLImageElement`, `ImageData`, `ImageBitmap` or object with `width`, `height`, and `data`
|
|
2123
|
+
* @param id - The ID of the image.
|
|
2124
|
+
* @param image - The image as an `HTMLImageElement`, `ImageData`, `ImageBitmap` or object with `width`, `height`, and `data`
|
|
1941
2125
|
* properties with the same format as `ImageData`.
|
|
1942
|
-
*
|
|
2126
|
+
* @returns `this`
|
|
1943
2127
|
* @example
|
|
2128
|
+
* ```ts
|
|
1944
2129
|
* // If an image with the ID 'cat' already exists in the style's sprite,
|
|
1945
2130
|
* // replace that image with a new image, 'other-cat-icon.png'.
|
|
1946
2131
|
* if (map.hasImage('cat')) map.updateImage('cat', './other-cat-icon.png');
|
|
2132
|
+
* ```
|
|
1947
2133
|
*/
|
|
1948
2134
|
updateImage(id: string,
|
|
1949
2135
|
image: HTMLImageElement | ImageBitmap | ImageData | {
|
|
1950
2136
|
width: number;
|
|
1951
2137
|
height: number;
|
|
1952
2138
|
data: Uint8Array | Uint8ClampedArray;
|
|
1953
|
-
} | StyleImageInterface) {
|
|
2139
|
+
} | StyleImageInterface): this {
|
|
1954
2140
|
|
|
1955
2141
|
const existingImage = this.style.getImage(id);
|
|
1956
2142
|
if (!existingImage) {
|
|
@@ -1977,6 +2163,7 @@ class Map extends Camera {
|
|
|
1977
2163
|
existingImage.data.replace(data, copy);
|
|
1978
2164
|
|
|
1979
2165
|
this.style.updateImage(id, existingImage);
|
|
2166
|
+
return this;
|
|
1980
2167
|
}
|
|
1981
2168
|
|
|
1982
2169
|
/**
|
|
@@ -1984,12 +2171,13 @@ class Map extends Camera {
|
|
|
1984
2171
|
* This includes both images from the style's original sprite
|
|
1985
2172
|
* and any images that have been added at runtime using {@link Map#addImage}.
|
|
1986
2173
|
*
|
|
1987
|
-
* @param id The ID of the image.
|
|
1988
|
-
* @returns
|
|
2174
|
+
* @param id - The ID of the image.
|
|
2175
|
+
* @returns An image in the map with the specified ID.
|
|
1989
2176
|
*
|
|
1990
2177
|
* @example
|
|
1991
|
-
*
|
|
1992
|
-
*
|
|
2178
|
+
* ```ts
|
|
2179
|
+
* let coffeeShopIcon = map.getImage("coffee_cup");
|
|
2180
|
+
* ```
|
|
1993
2181
|
*/
|
|
1994
2182
|
getImage(id: string): StyleImage {
|
|
1995
2183
|
return this.style.getImage(id);
|
|
@@ -2000,13 +2188,14 @@ class Map extends Camera {
|
|
|
2000
2188
|
* in the style's original sprite and any images
|
|
2001
2189
|
* that have been added at runtime using {@link Map#addImage}.
|
|
2002
2190
|
*
|
|
2003
|
-
* @param id The ID of the image.
|
|
2191
|
+
* @param id - The ID of the image.
|
|
2004
2192
|
*
|
|
2005
|
-
* @returns
|
|
2193
|
+
* @returns A Boolean indicating whether the image exists.
|
|
2006
2194
|
* @example
|
|
2007
|
-
*
|
|
2008
|
-
*
|
|
2009
|
-
*
|
|
2195
|
+
* Check if an image with the ID 'cat' exists in the style's sprite.
|
|
2196
|
+
* ```ts
|
|
2197
|
+
* let catIconExists = map.hasImage('cat');
|
|
2198
|
+
* ```
|
|
2010
2199
|
*/
|
|
2011
2200
|
hasImage(id: string): boolean {
|
|
2012
2201
|
if (!id) {
|
|
@@ -2022,12 +2211,14 @@ class Map extends Camera {
|
|
|
2022
2211
|
* sprite or any images
|
|
2023
2212
|
* that have been added at runtime using {@link Map#addImage}.
|
|
2024
2213
|
*
|
|
2025
|
-
* @param id The ID of the image.
|
|
2214
|
+
* @param id - The ID of the image.
|
|
2026
2215
|
*
|
|
2027
2216
|
* @example
|
|
2217
|
+
* ```ts
|
|
2028
2218
|
* // If an image with the ID 'cat' exists in
|
|
2029
2219
|
* // the style's sprite, remove it.
|
|
2030
2220
|
* if (map.hasImage('cat')) map.removeImage('cat');
|
|
2221
|
+
* ```
|
|
2031
2222
|
*/
|
|
2032
2223
|
removeImage(id: string) {
|
|
2033
2224
|
this.style.removeImage(id);
|
|
@@ -2037,18 +2228,19 @@ class Map extends Camera {
|
|
|
2037
2228
|
* Load an image from an external URL to be used with {@link Map#addImage}. External
|
|
2038
2229
|
* domains must support [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS).
|
|
2039
2230
|
*
|
|
2040
|
-
* @param
|
|
2041
|
-
* @param
|
|
2231
|
+
* @param url - The URL of the image file. Image file must be in png, webp, or jpg format.
|
|
2232
|
+
* @param callback - Expecting `callback(error, data)`. Called when the image has loaded or with an error argument if there is an error.
|
|
2042
2233
|
*
|
|
2043
2234
|
* @example
|
|
2044
|
-
*
|
|
2235
|
+
* Load an image from an external URL.
|
|
2236
|
+
* ```ts
|
|
2045
2237
|
* map.loadImage('http://placekitten.com/50/50', function(error, image) {
|
|
2046
2238
|
* if (error) throw error;
|
|
2047
2239
|
* // Add the loaded image to the style's sprite with the ID 'kitten'.
|
|
2048
2240
|
* map.addImage('kitten', image);
|
|
2049
2241
|
* });
|
|
2050
|
-
*
|
|
2051
|
-
* @see [Add an icon to the map](https://maplibre.org/maplibre-gl-js
|
|
2242
|
+
* ```
|
|
2243
|
+
* @see [Add an icon to the map](https://maplibre.org/maplibre-gl-js/docs/examples/add-image/)
|
|
2052
2244
|
*/
|
|
2053
2245
|
loadImage(url: string, callback: GetImageCallback) {
|
|
2054
2246
|
ImageRequest.getImage(this._requestManager.transformRequest(url, ResourceType.Image), callback);
|
|
@@ -2059,13 +2251,14 @@ class Map extends Camera {
|
|
|
2059
2251
|
* This includes both images from the style's original sprite
|
|
2060
2252
|
* and any images that have been added at runtime using {@link Map#addImage}.
|
|
2061
2253
|
*
|
|
2062
|
-
* @returns
|
|
2254
|
+
* @returns An Array of strings containing the names of all sprites/images currently available in the map.
|
|
2063
2255
|
*
|
|
2064
2256
|
* @example
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2257
|
+
* ```ts
|
|
2258
|
+
* let allImages = map.listImages();
|
|
2259
|
+
* ```
|
|
2067
2260
|
*/
|
|
2068
|
-
listImages() {
|
|
2261
|
+
listImages(): Array<string> {
|
|
2069
2262
|
return this.style.listImages();
|
|
2070
2263
|
}
|
|
2071
2264
|
|
|
@@ -2076,56 +2269,21 @@ class Map extends Camera {
|
|
|
2076
2269
|
* A layer defines how data from a specified source will be styled. Read more about layer types
|
|
2077
2270
|
* and available paint and layout properties in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/#layers).
|
|
2078
2271
|
*
|
|
2079
|
-
*
|
|
2080
|
-
* @param {Object} layer
|
|
2272
|
+
* @param layer - The layer to add,
|
|
2081
2273
|
* conforming to either the MapLibre Style Specification's [layer definition](https://maplibre.org/maplibre-style-spec/#layers) or,
|
|
2082
2274
|
* less commonly, the {@link CustomLayerInterface} specification.
|
|
2083
2275
|
* The MapLibre Style Specification's layer definition is appropriate for most layers.
|
|
2084
2276
|
*
|
|
2085
|
-
* @param
|
|
2086
|
-
* @param {string} layer.type The type of layer (for example `fill` or `symbol`).
|
|
2087
|
-
* A list of layer types is available in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#type).
|
|
2088
|
-
*
|
|
2089
|
-
* (This can also be `custom`. For more information, see {@link CustomLayerInterface}.)
|
|
2090
|
-
* @param {string | SourceSpecification} [layer.source] The data source for the layer.
|
|
2091
|
-
* Reference a source that has _already been defined_ using the source's unique id.
|
|
2092
|
-
* Reference a _new source_ using a source object (as defined in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/sources/)) directly.
|
|
2093
|
-
* This is **required** for all `layer.type` options _except_ for `custom` and `background`.
|
|
2094
|
-
* @param {string} [layer.sourceLayer] (optional) The name of the source layer within the specified `layer.source` to use for this style layer.
|
|
2095
|
-
* This is only applicable for vector tile sources and is **required** when `layer.source` is of the type `vector`.
|
|
2096
|
-
* @param {array} [layer.filter] (optional) An expression specifying conditions on source features.
|
|
2097
|
-
* Only features that match the filter are displayed.
|
|
2098
|
-
* The MapLibre Style Specification includes more information on the limitations of the [`filter`](https://maplibre.org/maplibre-style-spec/layers/#filter) parameter
|
|
2099
|
-
* and a complete list of available [expressions](https://maplibre.org/maplibre-style-spec/expressions/).
|
|
2100
|
-
* If no filter is provided, all features in the source (or source layer for vector tilesets) will be displayed.
|
|
2101
|
-
* @param {Object} [layer.paint] (optional) Paint properties for the layer.
|
|
2102
|
-
* Available paint properties vary by `layer.type`.
|
|
2103
|
-
* A full list of paint properties for each layer type is available in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/).
|
|
2104
|
-
* If no paint properties are specified, default values will be used.
|
|
2105
|
-
* @param {Object} [layer.layout] (optional) Layout properties for the layer.
|
|
2106
|
-
* Available layout properties vary by `layer.type`.
|
|
2107
|
-
* A full list of layout properties for each layer type is available in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/).
|
|
2108
|
-
* If no layout properties are specified, default values will be used.
|
|
2109
|
-
* @param {number} [layer.maxzoom] (optional) The maximum zoom level for the layer.
|
|
2110
|
-
* At zoom levels equal to or greater than the maxzoom, the layer will be hidden.
|
|
2111
|
-
* The value can be any number between `0` and `24` (inclusive).
|
|
2112
|
-
* If no maxzoom is provided, the layer will be visible at all zoom levels for which there are tiles available.
|
|
2113
|
-
* @param {number} [layer.minzoom] (optional) The minimum zoom level for the layer.
|
|
2114
|
-
* At zoom levels less than the minzoom, the layer will be hidden.
|
|
2115
|
-
* The value can be any number between `0` and `24` (inclusive).
|
|
2116
|
-
* If no minzoom is provided, the layer will be visible at all zoom levels for which there are tiles available.
|
|
2117
|
-
* @param {Object} [layer.metadata] (optional) Arbitrary properties useful to track with the layer, but do not influence rendering.
|
|
2118
|
-
* @param {string} [layer.renderingMode] This is only applicable for layers with the type `custom`.
|
|
2119
|
-
* See {@link CustomLayerInterface} for more information.
|
|
2120
|
-
* @param {string} [beforeId] The ID of an existing layer to insert the new layer before,
|
|
2277
|
+
* @param beforeId - The ID of an existing layer to insert the new layer before,
|
|
2121
2278
|
* resulting in the new layer appearing visually beneath the existing layer.
|
|
2122
2279
|
* If this argument is not specified, the layer will be appended to the end of the layers array
|
|
2123
2280
|
* and appear visually above all other layers.
|
|
2124
2281
|
*
|
|
2125
|
-
* @returns
|
|
2282
|
+
* @returns `this`
|
|
2126
2283
|
*
|
|
2127
2284
|
* @example
|
|
2128
|
-
*
|
|
2285
|
+
* Add a circle layer with a vector source
|
|
2286
|
+
* ```ts
|
|
2129
2287
|
* map.addLayer({
|
|
2130
2288
|
* id: 'points-of-interest',
|
|
2131
2289
|
* source: {
|
|
@@ -2141,9 +2299,11 @@ class Map extends Camera {
|
|
|
2141
2299
|
* // MapLibre Style Specification layout properties
|
|
2142
2300
|
* }
|
|
2143
2301
|
* });
|
|
2302
|
+
* ```
|
|
2144
2303
|
*
|
|
2145
2304
|
* @example
|
|
2146
|
-
*
|
|
2305
|
+
* Define a source before using it to create a new layer
|
|
2306
|
+
* ```ts
|
|
2147
2307
|
* map.addSource('state-data', {
|
|
2148
2308
|
* type: 'geojson',
|
|
2149
2309
|
* data: 'path/to/data.geojson'
|
|
@@ -2161,9 +2321,11 @@ class Map extends Camera {
|
|
|
2161
2321
|
* text-field: ['get', 'name']
|
|
2162
2322
|
* }
|
|
2163
2323
|
* });
|
|
2324
|
+
* ```
|
|
2164
2325
|
*
|
|
2165
2326
|
* @example
|
|
2166
|
-
*
|
|
2327
|
+
* Add a new symbol layer before an existing layer
|
|
2328
|
+
* ```ts
|
|
2167
2329
|
* map.addLayer({
|
|
2168
2330
|
* id: 'states',
|
|
2169
2331
|
* // References a source that's already been defined
|
|
@@ -2176,10 +2338,10 @@ class Map extends Camera {
|
|
|
2176
2338
|
* }
|
|
2177
2339
|
* // Add the layer before the existing `cities` layer
|
|
2178
2340
|
* }, 'cities');
|
|
2179
|
-
*
|
|
2180
|
-
* @see [Create and style clusters](https://maplibre.org/maplibre-gl-js
|
|
2181
|
-
* @see [Add a vector tile source](https://maplibre.org/maplibre-gl-js
|
|
2182
|
-
* @see [Add a WMS source](https://maplibre.org/maplibre-gl-js
|
|
2341
|
+
* ```
|
|
2342
|
+
* @see [Create and style clusters](https://maplibre.org/maplibre-gl-js/docs/examples/cluster/)
|
|
2343
|
+
* @see [Add a vector tile source](https://maplibre.org/maplibre-gl-js/docs/examples/vector-source/)
|
|
2344
|
+
* @see [Add a WMS source](https://maplibre.org/maplibre-gl-js/docs/examples/wms/)
|
|
2183
2345
|
*/
|
|
2184
2346
|
addLayer(layer: (LayerSpecification & {source?: string | SourceSpecification}) | CustomLayerInterface, beforeId?: string) {
|
|
2185
2347
|
this._lazyInitEmptyStyle();
|
|
@@ -2190,33 +2352,37 @@ class Map extends Camera {
|
|
|
2190
2352
|
/**
|
|
2191
2353
|
* Moves a layer to a different z-position.
|
|
2192
2354
|
*
|
|
2193
|
-
* @param
|
|
2194
|
-
* @param
|
|
2195
|
-
* @returns
|
|
2355
|
+
* @param id - The ID of the layer to move.
|
|
2356
|
+
* @param beforeId - The ID of an existing layer to insert the new layer before. When viewing the map, the `id` layer will appear beneath the `beforeId` layer. If `beforeId` is omitted, the layer will be appended to the end of the layers array and appear above all other layers on the map.
|
|
2357
|
+
* @returns `this`
|
|
2196
2358
|
*
|
|
2197
2359
|
* @example
|
|
2198
|
-
*
|
|
2360
|
+
* Move a layer with ID 'polygon' before the layer with ID 'country-label'. The `polygon` layer will appear beneath the `country-label` layer on the map.
|
|
2361
|
+
* ```ts
|
|
2199
2362
|
* map.moveLayer('polygon', 'country-label');
|
|
2363
|
+
* ```
|
|
2200
2364
|
*/
|
|
2201
|
-
moveLayer(id: string, beforeId?: string) {
|
|
2365
|
+
moveLayer(id: string, beforeId?: string): this {
|
|
2202
2366
|
this.style.moveLayer(id, beforeId);
|
|
2203
2367
|
return this._update(true);
|
|
2204
2368
|
}
|
|
2205
2369
|
|
|
2206
|
-
// eslint-disable-next-line jsdoc/require-returns
|
|
2207
2370
|
/**
|
|
2208
2371
|
* Removes the layer with the given ID from the map's style.
|
|
2209
2372
|
*
|
|
2210
2373
|
* If no such layer exists, an `error` event is fired.
|
|
2211
2374
|
*
|
|
2212
|
-
* @param
|
|
2213
|
-
* @
|
|
2375
|
+
* @param id - The ID of the layer to remove
|
|
2376
|
+
* @event `error`
|
|
2377
|
+
* @returns `this`
|
|
2214
2378
|
*
|
|
2215
2379
|
* @example
|
|
2216
|
-
*
|
|
2380
|
+
* If a layer with ID 'state-data' exists, remove it.
|
|
2381
|
+
* ```ts
|
|
2217
2382
|
* if (map.getLayer('state-data')) map.removeLayer('state-data');
|
|
2383
|
+
* ```
|
|
2218
2384
|
*/
|
|
2219
|
-
removeLayer(id: string) {
|
|
2385
|
+
removeLayer(id: string): this {
|
|
2220
2386
|
this.style.removeLayer(id);
|
|
2221
2387
|
return this._update(true);
|
|
2222
2388
|
}
|
|
@@ -2224,15 +2390,16 @@ class Map extends Camera {
|
|
|
2224
2390
|
/**
|
|
2225
2391
|
* Returns the layer with the specified ID in the map's style.
|
|
2226
2392
|
*
|
|
2227
|
-
* @param
|
|
2228
|
-
* @returns
|
|
2393
|
+
* @param id - The ID of the layer to get.
|
|
2394
|
+
* @returns The layer with the specified ID, or `undefined`
|
|
2229
2395
|
* if the ID corresponds to no existing layers.
|
|
2230
2396
|
*
|
|
2231
2397
|
* @example
|
|
2232
|
-
*
|
|
2233
|
-
*
|
|
2234
|
-
*
|
|
2235
|
-
* @see [Filter symbols by
|
|
2398
|
+
* ```ts
|
|
2399
|
+
* let stateDataLayer = map.getLayer('state-data');
|
|
2400
|
+
* ```
|
|
2401
|
+
* @see [Filter symbols by toggling a list](https://maplibre.org/maplibre-gl-js/docs/examples/filter-markers/)
|
|
2402
|
+
* @see [Filter symbols by text input](https://maplibre.org/maplibre-gl-js/docs/examples/filter-markers-by-input/)
|
|
2236
2403
|
*/
|
|
2237
2404
|
getLayer(id: string): StyleLayer {
|
|
2238
2405
|
return this.style.getLayer(id);
|
|
@@ -2249,16 +2416,17 @@ class Map extends Camera {
|
|
|
2249
2416
|
* zoom level of the source layer is higher than the minimum zoom level defined in the style layer, the style
|
|
2250
2417
|
* layer will not be rendered at all zoom levels in the zoom range.
|
|
2251
2418
|
*
|
|
2252
|
-
* @param
|
|
2253
|
-
* @param
|
|
2254
|
-
* @param
|
|
2255
|
-
* @returns
|
|
2419
|
+
* @param layerId - The ID of the layer to which the zoom extent will be applied.
|
|
2420
|
+
* @param minzoom - The minimum zoom to set (0-24).
|
|
2421
|
+
* @param maxzoom - The maximum zoom to set (0-24).
|
|
2422
|
+
* @returns `this`
|
|
2256
2423
|
*
|
|
2257
2424
|
* @example
|
|
2425
|
+
* ```ts
|
|
2258
2426
|
* map.setLayerZoomRange('my-layer', 2, 5);
|
|
2259
|
-
*
|
|
2427
|
+
* ```
|
|
2260
2428
|
*/
|
|
2261
|
-
setLayerZoomRange(layerId: string, minzoom: number, maxzoom: number) {
|
|
2429
|
+
setLayerZoomRange(layerId: string, minzoom: number, maxzoom: number): this {
|
|
2262
2430
|
this.style.setLayerZoomRange(layerId, minzoom, maxzoom);
|
|
2263
2431
|
return this._update(true);
|
|
2264
2432
|
}
|
|
@@ -2274,24 +2442,28 @@ class Map extends Camera {
|
|
|
2274
2442
|
*
|
|
2275
2443
|
* To clear the filter, pass `null` or `undefined` as the second parameter.
|
|
2276
2444
|
*
|
|
2277
|
-
* @param
|
|
2278
|
-
* @param
|
|
2445
|
+
* @param layerId - The ID of the layer to which the filter will be applied.
|
|
2446
|
+
* @param filter - The filter, conforming to the MapLibre Style Specification's
|
|
2279
2447
|
* [filter definition](https://maplibre.org/maplibre-style-spec/layers/#filter). If `null` or `undefined` is provided, the function removes any existing filter from the layer.
|
|
2280
|
-
* @param
|
|
2281
|
-
* @
|
|
2282
|
-
* @returns {Map} `this`
|
|
2448
|
+
* @param options - Options object.
|
|
2449
|
+
* @returns `this`
|
|
2283
2450
|
*
|
|
2284
2451
|
* @example
|
|
2285
|
-
*
|
|
2452
|
+
* Display only features with the 'name' property 'USA'
|
|
2453
|
+
* ```ts
|
|
2286
2454
|
* map.setFilter('my-layer', ['==', ['get', 'name'], 'USA']);
|
|
2455
|
+
* ```
|
|
2287
2456
|
* @example
|
|
2288
|
-
*
|
|
2457
|
+
* Display only features with five or more 'available-spots'
|
|
2458
|
+
* ```ts
|
|
2289
2459
|
* map.setFilter('bike-docks', ['>=', ['get', 'available-spots'], 5]);
|
|
2460
|
+
* ```
|
|
2290
2461
|
* @example
|
|
2291
|
-
*
|
|
2462
|
+
* Remove the filter for the 'bike-docks' style layer
|
|
2463
|
+
* ```ts
|
|
2292
2464
|
* map.setFilter('bike-docks', null);
|
|
2293
|
-
*
|
|
2294
|
-
* @see [Create a timeline animation](https://maplibre.org/maplibre-gl-js
|
|
2465
|
+
* ```
|
|
2466
|
+
* @see [Create a timeline animation](https://maplibre.org/maplibre-gl-js/docs/examples/timeline-animation/)
|
|
2295
2467
|
*/
|
|
2296
2468
|
setFilter(layerId: string, filter?: FilterSpecification | null, options: StyleSetterOptions = {}) {
|
|
2297
2469
|
this.style.setFilter(layerId, filter, options);
|
|
@@ -2301,29 +2473,30 @@ class Map extends Camera {
|
|
|
2301
2473
|
/**
|
|
2302
2474
|
* Returns the filter applied to the specified style layer.
|
|
2303
2475
|
*
|
|
2304
|
-
* @param
|
|
2305
|
-
* @returns
|
|
2476
|
+
* @param layerId - The ID of the style layer whose filter to get.
|
|
2477
|
+
* @returns The layer's filter.
|
|
2306
2478
|
*/
|
|
2307
|
-
getFilter(layerId: string) {
|
|
2479
|
+
getFilter(layerId: string): FilterSpecification | void {
|
|
2308
2480
|
return this.style.getFilter(layerId);
|
|
2309
2481
|
}
|
|
2310
2482
|
|
|
2311
2483
|
/**
|
|
2312
2484
|
* Sets the value of a paint property in the specified style layer.
|
|
2313
2485
|
*
|
|
2314
|
-
* @param
|
|
2315
|
-
* @param
|
|
2316
|
-
* @param
|
|
2486
|
+
* @param layerId - The ID of the layer to set the paint property in.
|
|
2487
|
+
* @param name - The name of the paint property to set.
|
|
2488
|
+
* @param value - The value of the paint property to set.
|
|
2317
2489
|
* Must be of a type appropriate for the property, as defined in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/).
|
|
2318
|
-
* @param
|
|
2319
|
-
* @
|
|
2320
|
-
* @returns {Map} `this`
|
|
2490
|
+
* @param options - Options object.
|
|
2491
|
+
* @returns `this`
|
|
2321
2492
|
* @example
|
|
2493
|
+
* ```ts
|
|
2322
2494
|
* map.setPaintProperty('my-layer', 'fill-color', '#faafee');
|
|
2323
|
-
*
|
|
2324
|
-
* @see [
|
|
2495
|
+
* ```
|
|
2496
|
+
* @see [Change a layer's color with buttons](https://maplibre.org/maplibre-gl-js/docs/examples/color-switcher/)
|
|
2497
|
+
* @see [Create a draggable point](https://maplibre.org/maplibre-gl-js/docs/examples/drag-a-point/)
|
|
2325
2498
|
*/
|
|
2326
|
-
setPaintProperty(layerId: string, name: string, value: any, options: StyleSetterOptions = {}) {
|
|
2499
|
+
setPaintProperty(layerId: string, name: string, value: any, options: StyleSetterOptions = {}): this {
|
|
2327
2500
|
this.style.setPaintProperty(layerId, name, value, options);
|
|
2328
2501
|
return this._update(true);
|
|
2329
2502
|
}
|
|
@@ -2331,9 +2504,9 @@ class Map extends Camera {
|
|
|
2331
2504
|
/**
|
|
2332
2505
|
* Returns the value of a paint property in the specified style layer.
|
|
2333
2506
|
*
|
|
2334
|
-
* @param
|
|
2335
|
-
* @param
|
|
2336
|
-
* @returns
|
|
2507
|
+
* @param layerId - The ID of the layer to get the paint property from.
|
|
2508
|
+
* @param name - The name of a paint property to get.
|
|
2509
|
+
* @returns The value of the specified paint property.
|
|
2337
2510
|
*/
|
|
2338
2511
|
getPaintProperty(layerId: string, name: string) {
|
|
2339
2512
|
return this.style.getPaintProperty(layerId, name);
|
|
@@ -2342,16 +2515,17 @@ class Map extends Camera {
|
|
|
2342
2515
|
/**
|
|
2343
2516
|
* Sets the value of a layout property in the specified style layer.
|
|
2344
2517
|
*
|
|
2345
|
-
* @param
|
|
2346
|
-
* @param
|
|
2347
|
-
* @param
|
|
2348
|
-
* @param
|
|
2349
|
-
* @
|
|
2350
|
-
* @returns {Map} `this`
|
|
2518
|
+
* @param layerId - The ID of the layer to set the layout property in.
|
|
2519
|
+
* @param name - The name of the layout property to set.
|
|
2520
|
+
* @param value - The value of the layout property. Must be of a type appropriate for the property, as defined in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/).
|
|
2521
|
+
* @param options - The options object.
|
|
2522
|
+
* @returns `this`
|
|
2351
2523
|
* @example
|
|
2524
|
+
* ```ts
|
|
2352
2525
|
* map.setLayoutProperty('my-layer', 'visibility', 'none');
|
|
2526
|
+
* ```
|
|
2353
2527
|
*/
|
|
2354
|
-
setLayoutProperty(layerId: string, name: string, value: any, options: StyleSetterOptions = {}) {
|
|
2528
|
+
setLayoutProperty(layerId: string, name: string, value: any, options: StyleSetterOptions = {}): this {
|
|
2355
2529
|
this.style.setLayoutProperty(layerId, name, value, options);
|
|
2356
2530
|
return this._update(true);
|
|
2357
2531
|
}
|
|
@@ -2359,9 +2533,9 @@ class Map extends Camera {
|
|
|
2359
2533
|
/**
|
|
2360
2534
|
* Returns the value of a layout property in the specified style layer.
|
|
2361
2535
|
*
|
|
2362
|
-
* @param
|
|
2363
|
-
* @param
|
|
2364
|
-
* @returns
|
|
2536
|
+
* @param layerId - The ID of the layer to get the layout property from.
|
|
2537
|
+
* @param name - The name of the layout property to get.
|
|
2538
|
+
* @returns The value of the specified layout property.
|
|
2365
2539
|
*/
|
|
2366
2540
|
getLayoutProperty(layerId: string, name: string) {
|
|
2367
2541
|
return this.style.getLayoutProperty(layerId, name);
|
|
@@ -2370,14 +2544,15 @@ class Map extends Camera {
|
|
|
2370
2544
|
/**
|
|
2371
2545
|
* Sets the value of the style's glyphs property.
|
|
2372
2546
|
*
|
|
2373
|
-
* @param glyphsUrl Glyph URL to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/glyphs/).
|
|
2374
|
-
* @param
|
|
2375
|
-
* @
|
|
2376
|
-
* @returns {Map} `this`
|
|
2547
|
+
* @param glyphsUrl - Glyph URL to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/glyphs/).
|
|
2548
|
+
* @param options - Options object.
|
|
2549
|
+
* @returns `this`
|
|
2377
2550
|
* @example
|
|
2551
|
+
* ```ts
|
|
2378
2552
|
* map.setGlyphs('https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf');
|
|
2553
|
+
* ```
|
|
2379
2554
|
*/
|
|
2380
|
-
setGlyphs(glyphsUrl: string | null, options: StyleSetterOptions = {}) {
|
|
2555
|
+
setGlyphs(glyphsUrl: string | null, options: StyleSetterOptions = {}): this {
|
|
2381
2556
|
this._lazyInitEmptyStyle();
|
|
2382
2557
|
this.style.setGlyphs(glyphsUrl, options);
|
|
2383
2558
|
return this._update(true);
|
|
@@ -2386,24 +2561,26 @@ class Map extends Camera {
|
|
|
2386
2561
|
/**
|
|
2387
2562
|
* Returns the value of the style's glyphs URL
|
|
2388
2563
|
*
|
|
2389
|
-
* @returns
|
|
2564
|
+
* @returns glyphs Style's glyphs url
|
|
2390
2565
|
*/
|
|
2391
|
-
getGlyphs() {
|
|
2566
|
+
getGlyphs(): string | null {
|
|
2392
2567
|
return this.style.getGlyphsUrl();
|
|
2393
2568
|
}
|
|
2394
2569
|
|
|
2395
2570
|
/**
|
|
2396
2571
|
* Adds a sprite to the map's style.
|
|
2397
2572
|
*
|
|
2398
|
-
* @param
|
|
2399
|
-
* @param
|
|
2400
|
-
* @param
|
|
2401
|
-
* @
|
|
2402
|
-
* @returns
|
|
2573
|
+
* @param id - The ID of the sprite to add. Must not conflict with existing sprites.
|
|
2574
|
+
* @param url - The URL to load the sprite from
|
|
2575
|
+
* @param options - Options object.
|
|
2576
|
+
* @event `style`
|
|
2577
|
+
* @returns `this`
|
|
2403
2578
|
* @example
|
|
2579
|
+
* ```ts
|
|
2404
2580
|
* map.addSprite('sprite-two', 'http://example.com/sprite-two');
|
|
2581
|
+
* ```
|
|
2405
2582
|
*/
|
|
2406
|
-
addSprite(id: string, url: string, options: StyleSetterOptions = {}) {
|
|
2583
|
+
addSprite(id: string, url: string, options: StyleSetterOptions = {}): this {
|
|
2407
2584
|
this._lazyInitEmptyStyle();
|
|
2408
2585
|
this.style.addSprite(id, url, options, (err) => {
|
|
2409
2586
|
if (!err) {
|
|
@@ -2416,13 +2593,14 @@ class Map extends Camera {
|
|
|
2416
2593
|
/**
|
|
2417
2594
|
* Removes the sprite from the map's style.
|
|
2418
2595
|
*
|
|
2419
|
-
* @param
|
|
2420
|
-
* @
|
|
2421
|
-
* @returns
|
|
2596
|
+
* @param id - The ID of the sprite to remove. If the sprite is declared as a single URL, the ID must be "default".
|
|
2597
|
+
* @event `style`
|
|
2598
|
+
* @returns `this`
|
|
2422
2599
|
* @example
|
|
2600
|
+
* ```ts
|
|
2423
2601
|
* map.removeSprite('sprite-two');
|
|
2424
|
-
* @example
|
|
2425
2602
|
* map.removeSprite('default');
|
|
2603
|
+
* ```
|
|
2426
2604
|
*/
|
|
2427
2605
|
removeSprite(id: string) {
|
|
2428
2606
|
this._lazyInitEmptyStyle();
|
|
@@ -2433,21 +2611,22 @@ class Map extends Camera {
|
|
|
2433
2611
|
/**
|
|
2434
2612
|
* Returns the as-is value of the style's sprite.
|
|
2435
2613
|
*
|
|
2436
|
-
* @returns
|
|
2614
|
+
* @returns style's sprite list of id-url pairs
|
|
2437
2615
|
*/
|
|
2438
|
-
getSprite() {
|
|
2616
|
+
getSprite(): {id: string; url: string}[] {
|
|
2439
2617
|
return this.style.getSprite();
|
|
2440
2618
|
}
|
|
2441
2619
|
|
|
2442
2620
|
/**
|
|
2443
2621
|
* Sets the value of the style's sprite property.
|
|
2444
2622
|
*
|
|
2445
|
-
* @param spriteUrl Sprite URL to set.
|
|
2446
|
-
* @param
|
|
2447
|
-
* @
|
|
2448
|
-
* @returns {Map} `this`
|
|
2623
|
+
* @param spriteUrl - Sprite URL to set.
|
|
2624
|
+
* @param options - Options object.
|
|
2625
|
+
* @returns `this`
|
|
2449
2626
|
* @example
|
|
2627
|
+
* ```ts
|
|
2450
2628
|
* map.setSprite('YOUR_SPRITE_URL');
|
|
2629
|
+
* ```
|
|
2451
2630
|
*/
|
|
2452
2631
|
setSprite(spriteUrl: string | null, options: StyleSetterOptions = {}) {
|
|
2453
2632
|
this._lazyInitEmptyStyle();
|
|
@@ -2462,12 +2641,14 @@ class Map extends Camera {
|
|
|
2462
2641
|
/**
|
|
2463
2642
|
* Sets the any combination of light values.
|
|
2464
2643
|
*
|
|
2465
|
-
* @param light Light properties to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/#light).
|
|
2466
|
-
* @param
|
|
2467
|
-
* @
|
|
2468
|
-
*
|
|
2644
|
+
* @param light - Light properties to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/#light).
|
|
2645
|
+
* @param options - Options object.
|
|
2646
|
+
* @returns `this`
|
|
2647
|
+
*
|
|
2469
2648
|
* @example
|
|
2470
|
-
*
|
|
2649
|
+
* ```ts
|
|
2650
|
+
* let layerVisibility = map.getLayoutProperty('my-layer', 'visibility');
|
|
2651
|
+
* ```
|
|
2471
2652
|
*/
|
|
2472
2653
|
setLight(light: LightSpecification, options: StyleSetterOptions = {}) {
|
|
2473
2654
|
this._lazyInitEmptyStyle();
|
|
@@ -2478,13 +2659,12 @@ class Map extends Camera {
|
|
|
2478
2659
|
/**
|
|
2479
2660
|
* Returns the value of the light object.
|
|
2480
2661
|
*
|
|
2481
|
-
* @returns
|
|
2662
|
+
* @returns light Light properties of the style.
|
|
2482
2663
|
*/
|
|
2483
|
-
getLight() {
|
|
2664
|
+
getLight(): LightSpecification {
|
|
2484
2665
|
return this.style.getLight();
|
|
2485
2666
|
}
|
|
2486
2667
|
|
|
2487
|
-
// eslint-disable-next-line jsdoc/require-returns
|
|
2488
2668
|
/**
|
|
2489
2669
|
* Sets the `state` of a feature.
|
|
2490
2670
|
* A feature's `state` is a set of user-defined key-value pairs that are assigned to a feature at runtime.
|
|
@@ -2498,14 +2678,13 @@ class Map extends Camera {
|
|
|
2498
2678
|
*
|
|
2499
2679
|
* _Note: You can use the [`feature-state` expression](https://maplibre.org/maplibre-style-spec/expressions/#feature-state) to access the values in a feature's state object for the purposes of styling._
|
|
2500
2680
|
*
|
|
2501
|
-
* @param
|
|
2681
|
+
* @param feature - Feature identifier. Feature objects returned from
|
|
2502
2682
|
* {@link Map#queryRenderedFeatures} or event handlers can be used as feature identifiers.
|
|
2503
|
-
* @param
|
|
2504
|
-
* @
|
|
2505
|
-
* @param {string} [feature.sourceLayer] (optional) *For vector tile sources, `sourceLayer` is required.*
|
|
2506
|
-
* @param {Object} state A set of key-value pairs. The values should be valid JSON types.
|
|
2683
|
+
* @param state - A set of key-value pairs. The values should be valid JSON types.
|
|
2684
|
+
* @returns `this`
|
|
2507
2685
|
*
|
|
2508
2686
|
* @example
|
|
2687
|
+
* ```ts
|
|
2509
2688
|
* // When the mouse moves over the `my-layer` layer, update
|
|
2510
2689
|
* // the feature state for the feature under the mouse
|
|
2511
2690
|
* map.on('mousemove', 'my-layer', function(e) {
|
|
@@ -2519,15 +2698,14 @@ class Map extends Camera {
|
|
|
2519
2698
|
* });
|
|
2520
2699
|
* }
|
|
2521
2700
|
* });
|
|
2522
|
-
*
|
|
2523
|
-
* @see [Create a hover effect](https://maplibre.org/maplibre-gl-js
|
|
2701
|
+
* ```
|
|
2702
|
+
* @see [Create a hover effect](https://maplibre.org/maplibre-gl-js/docs/examples/hover-styles/)
|
|
2524
2703
|
*/
|
|
2525
|
-
setFeatureState(feature: FeatureIdentifier, state: any) {
|
|
2704
|
+
setFeatureState(feature: FeatureIdentifier, state: any): this {
|
|
2526
2705
|
this.style.setFeatureState(feature, state);
|
|
2527
2706
|
return this._update();
|
|
2528
2707
|
}
|
|
2529
2708
|
|
|
2530
|
-
// eslint-disable-next-line jsdoc/require-returns
|
|
2531
2709
|
/**
|
|
2532
2710
|
* Removes the `state` of a feature, setting it back to the default behavior.
|
|
2533
2711
|
* If only a `target.source` is specified, it will remove the state for all features from that source.
|
|
@@ -2535,24 +2713,23 @@ class Map extends Camera {
|
|
|
2535
2713
|
* If `key` is also specified, it removes only that key from that feature's state.
|
|
2536
2714
|
* Features are identified by their `feature.id` attribute, which can be any number or string.
|
|
2537
2715
|
*
|
|
2538
|
-
* @param
|
|
2716
|
+
* @param target - Identifier of where to remove state. It can be a source, a feature, or a specific key of feature.
|
|
2539
2717
|
* Feature objects returned from {@link Map#queryRenderedFeatures} or event handlers can be used as feature identifiers.
|
|
2540
|
-
* @param
|
|
2541
|
-
* @
|
|
2542
|
-
* @param {string} [target.sourceLayer] (optional) *For vector tile sources, `sourceLayer` is required.*
|
|
2543
|
-
* @param {string} key (optional) The key in the feature state to reset.
|
|
2544
|
-
*
|
|
2718
|
+
* @param key - (optional) The key in the feature state to reset.
|
|
2719
|
+
* @returns `this`
|
|
2545
2720
|
* @example
|
|
2546
|
-
*
|
|
2547
|
-
*
|
|
2721
|
+
* Reset the entire state object for all features in the `my-source` source
|
|
2722
|
+
* ```ts
|
|
2548
2723
|
* map.removeFeatureState({
|
|
2549
2724
|
* source: 'my-source'
|
|
2550
2725
|
* });
|
|
2726
|
+
* ```
|
|
2551
2727
|
*
|
|
2552
2728
|
* @example
|
|
2553
|
-
*
|
|
2554
|
-
*
|
|
2555
|
-
*
|
|
2729
|
+
* When the mouse leaves the `my-layer` layer,
|
|
2730
|
+
* reset the entire state object for the
|
|
2731
|
+
* feature under the mouse
|
|
2732
|
+
* ```ts
|
|
2556
2733
|
* map.on('mouseleave', 'my-layer', function(e) {
|
|
2557
2734
|
* map.removeFeatureState({
|
|
2558
2735
|
* source: 'my-source',
|
|
@@ -2560,11 +2737,13 @@ class Map extends Camera {
|
|
|
2560
2737
|
* id: e.features[0].id
|
|
2561
2738
|
* });
|
|
2562
2739
|
* });
|
|
2740
|
+
* ```
|
|
2563
2741
|
*
|
|
2564
2742
|
* @example
|
|
2565
|
-
*
|
|
2566
|
-
*
|
|
2567
|
-
*
|
|
2743
|
+
* When the mouse leaves the `my-layer` layer,
|
|
2744
|
+
* reset only the `hover` key-value pair in the
|
|
2745
|
+
* state for the feature under the mouse
|
|
2746
|
+
* ```ts
|
|
2568
2747
|
* map.on('mouseleave', 'my-layer', function(e) {
|
|
2569
2748
|
* map.removeFeatureState({
|
|
2570
2749
|
* source: 'my-source',
|
|
@@ -2572,9 +2751,9 @@ class Map extends Camera {
|
|
|
2572
2751
|
* id: e.features[0].id
|
|
2573
2752
|
* }, 'hover');
|
|
2574
2753
|
* });
|
|
2575
|
-
*
|
|
2754
|
+
* ```
|
|
2576
2755
|
*/
|
|
2577
|
-
removeFeatureState(target: FeatureIdentifier, key?: string) {
|
|
2756
|
+
removeFeatureState(target: FeatureIdentifier, key?: string): this {
|
|
2578
2757
|
this.style.removeFeatureState(target, key);
|
|
2579
2758
|
return this._update();
|
|
2580
2759
|
}
|
|
@@ -2586,17 +2765,14 @@ class Map extends Camera {
|
|
|
2586
2765
|
*
|
|
2587
2766
|
* _Note: To access the values in a feature's state object for the purposes of styling the feature, use the [`feature-state` expression](https://maplibre.org/maplibre-style-spec/expressions/#feature-state)._
|
|
2588
2767
|
*
|
|
2589
|
-
* @param
|
|
2768
|
+
* @param feature - Feature identifier. Feature objects returned from
|
|
2590
2769
|
* {@link Map#queryRenderedFeatures} or event handlers can be used as feature identifiers.
|
|
2591
|
-
* @
|
|
2592
|
-
* @param {string} feature.source The id of the vector or GeoJSON source for the feature.
|
|
2593
|
-
* @param {string} [feature.sourceLayer] (optional) *For vector tile sources, `sourceLayer` is required.*
|
|
2594
|
-
*
|
|
2595
|
-
* @returns {Object} The state of the feature: a set of key-value pairs that was assigned to the feature at runtime.
|
|
2770
|
+
* @returns The state of the feature: a set of key-value pairs that was assigned to the feature at runtime.
|
|
2596
2771
|
*
|
|
2597
2772
|
* @example
|
|
2598
|
-
*
|
|
2599
|
-
*
|
|
2773
|
+
* When the mouse moves over the `my-layer` layer,
|
|
2774
|
+
* get the feature state for the feature under the mouse
|
|
2775
|
+
* ```ts
|
|
2600
2776
|
* map.on('mousemove', 'my-layer', function(e) {
|
|
2601
2777
|
* if (e.features.length > 0) {
|
|
2602
2778
|
* map.getFeatureState({
|
|
@@ -2606,7 +2782,7 @@ class Map extends Camera {
|
|
|
2606
2782
|
* });
|
|
2607
2783
|
* }
|
|
2608
2784
|
* });
|
|
2609
|
-
*
|
|
2785
|
+
* ```
|
|
2610
2786
|
*/
|
|
2611
2787
|
getFeatureState(feature: FeatureIdentifier): any {
|
|
2612
2788
|
return this.style.getFeatureState(feature);
|
|
@@ -2615,9 +2791,9 @@ class Map extends Camera {
|
|
|
2615
2791
|
/**
|
|
2616
2792
|
* Returns the map's containing HTML element.
|
|
2617
2793
|
*
|
|
2618
|
-
* @returns
|
|
2794
|
+
* @returns The map's container.
|
|
2619
2795
|
*/
|
|
2620
|
-
getContainer() {
|
|
2796
|
+
getContainer(): HTMLElement {
|
|
2621
2797
|
return this._container;
|
|
2622
2798
|
}
|
|
2623
2799
|
|
|
@@ -2630,22 +2806,22 @@ class Map extends Camera {
|
|
|
2630
2806
|
* attached. It will receive bubbled events from child elements such as the `<canvas>`, but not from
|
|
2631
2807
|
* map controls.
|
|
2632
2808
|
*
|
|
2633
|
-
* @returns
|
|
2634
|
-
* @see [Create a draggable point](https://maplibre.org/maplibre-gl-js
|
|
2809
|
+
* @returns The container of the map's `<canvas>`.
|
|
2810
|
+
* @see [Create a draggable point](https://maplibre.org/maplibre-gl-js/docs/examples/drag-a-point/)
|
|
2635
2811
|
*/
|
|
2636
|
-
getCanvasContainer() {
|
|
2812
|
+
getCanvasContainer(): HTMLElement {
|
|
2637
2813
|
return this._canvasContainer;
|
|
2638
2814
|
}
|
|
2639
2815
|
|
|
2640
2816
|
/**
|
|
2641
2817
|
* Returns the map's `<canvas>` element.
|
|
2642
2818
|
*
|
|
2643
|
-
* @returns
|
|
2644
|
-
* @see [Measure distances](https://maplibre.org/maplibre-gl-js
|
|
2645
|
-
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js
|
|
2646
|
-
* @see [Center the map on a clicked symbol](https://maplibre.org/maplibre-gl-js
|
|
2819
|
+
* @returns The map's `<canvas>` element.
|
|
2820
|
+
* @see [Measure distances](https://maplibre.org/maplibre-gl-js/docs/examples/measure/)
|
|
2821
|
+
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
|
|
2822
|
+
* @see [Center the map on a clicked symbol](https://maplibre.org/maplibre-gl-js/docs/examples/center-on-symbol/)
|
|
2647
2823
|
*/
|
|
2648
|
-
getCanvas() {
|
|
2824
|
+
getCanvas(): HTMLCanvasElement {
|
|
2649
2825
|
return this._canvas;
|
|
2650
2826
|
}
|
|
2651
2827
|
|
|
@@ -2678,7 +2854,8 @@ class Map extends Camera {
|
|
|
2678
2854
|
this._canvas.setAttribute('role', 'region');
|
|
2679
2855
|
|
|
2680
2856
|
const dimensions = this._containerDimensions();
|
|
2681
|
-
this.
|
|
2857
|
+
const clampedPixelRatio = this._getClampedPixelRatio(dimensions[0], dimensions[1]);
|
|
2858
|
+
this._resizeCanvas(dimensions[0], dimensions[1], clampedPixelRatio);
|
|
2682
2859
|
|
|
2683
2860
|
const controlContainer = this._controlContainer = DOM.create('div', 'maplibregl-control-container', container);
|
|
2684
2861
|
const positions = this._controlPositions = {};
|
|
@@ -2689,9 +2866,9 @@ class Map extends Camera {
|
|
|
2689
2866
|
this._container.addEventListener('scroll', this._onMapScroll, false);
|
|
2690
2867
|
}
|
|
2691
2868
|
|
|
2692
|
-
_cooperativeGesturesOnWheel(event: WheelEvent) {
|
|
2869
|
+
_cooperativeGesturesOnWheel = (event: WheelEvent) => {
|
|
2693
2870
|
this._onCooperativeGesture(event, event[this._metaKey], 1);
|
|
2694
|
-
}
|
|
2871
|
+
};
|
|
2695
2872
|
|
|
2696
2873
|
_setupCooperativeGestures() {
|
|
2697
2874
|
const container = this._container;
|
|
@@ -2720,8 +2897,8 @@ class Map extends Camera {
|
|
|
2720
2897
|
|
|
2721
2898
|
_resizeCanvas(width: number, height: number, pixelRatio: number) {
|
|
2722
2899
|
// Request the required canvas size taking the pixelratio into account.
|
|
2723
|
-
this._canvas.width = pixelRatio * width;
|
|
2724
|
-
this._canvas.height = pixelRatio * height;
|
|
2900
|
+
this._canvas.width = Math.floor(pixelRatio * width);
|
|
2901
|
+
this._canvas.height = Math.floor(pixelRatio * height);
|
|
2725
2902
|
|
|
2726
2903
|
// Maintain the same canvas size, potentially downscaling it for HiDPI displays
|
|
2727
2904
|
this._canvas.style.width = `${width}px`;
|
|
@@ -2767,30 +2944,30 @@ class Map extends Camera {
|
|
|
2767
2944
|
webpSupported.testSupport(gl);
|
|
2768
2945
|
}
|
|
2769
2946
|
|
|
2770
|
-
_contextLost(event: any) {
|
|
2947
|
+
_contextLost = (event: any) => {
|
|
2771
2948
|
event.preventDefault();
|
|
2772
2949
|
if (this._frame) {
|
|
2773
2950
|
this._frame.cancel();
|
|
2774
2951
|
this._frame = null;
|
|
2775
2952
|
}
|
|
2776
2953
|
this.fire(new Event('webglcontextlost', {originalEvent: event}));
|
|
2777
|
-
}
|
|
2954
|
+
};
|
|
2778
2955
|
|
|
2779
|
-
_contextRestored(event: any) {
|
|
2956
|
+
_contextRestored = (event: any) => {
|
|
2780
2957
|
this._setupPainter();
|
|
2781
2958
|
this.resize();
|
|
2782
2959
|
this._update();
|
|
2783
2960
|
this.fire(new Event('webglcontextrestored', {originalEvent: event}));
|
|
2784
|
-
}
|
|
2961
|
+
};
|
|
2785
2962
|
|
|
2786
|
-
_onMapScroll(event: any) {
|
|
2963
|
+
_onMapScroll = (event: any) => {
|
|
2787
2964
|
if (event.target !== this._container) return;
|
|
2788
2965
|
|
|
2789
2966
|
// Revert any scroll which would move the canvas outside of the view
|
|
2790
2967
|
this._container.scrollTop = 0;
|
|
2791
2968
|
this._container.scrollLeft = 0;
|
|
2792
2969
|
return false;
|
|
2793
|
-
}
|
|
2970
|
+
};
|
|
2794
2971
|
|
|
2795
2972
|
_onCooperativeGesture(event: any, metaPress, touches) {
|
|
2796
2973
|
if (!metaPress && touches < 2) {
|
|
@@ -2810,19 +2987,18 @@ class Map extends Camera {
|
|
|
2810
2987
|
* or if there has been a change to the sources or style that
|
|
2811
2988
|
* has not yet fully loaded.
|
|
2812
2989
|
*
|
|
2813
|
-
* @returns
|
|
2990
|
+
* @returns A Boolean indicating whether the map is fully loaded.
|
|
2814
2991
|
*/
|
|
2815
|
-
loaded() {
|
|
2992
|
+
loaded(): boolean {
|
|
2816
2993
|
return !this._styleDirty && !this._sourcesDirty && !!this.style && this.style.loaded();
|
|
2817
2994
|
}
|
|
2818
2995
|
|
|
2819
2996
|
/**
|
|
2820
2997
|
* Update this map's style and sources, and re-render the map.
|
|
2821
2998
|
*
|
|
2822
|
-
* @param
|
|
2999
|
+
* @param updateStyle - mark the map's style for reprocessing as
|
|
2823
3000
|
* well as its sources
|
|
2824
|
-
* @returns
|
|
2825
|
-
* @private
|
|
3001
|
+
* @returns `this`
|
|
2826
3002
|
*/
|
|
2827
3003
|
_update(updateStyle?: boolean) {
|
|
2828
3004
|
if (!this.style || !this.style._loaded) return this;
|
|
@@ -2838,7 +3014,6 @@ class Map extends Camera {
|
|
|
2838
3014
|
* Request that the given callback be executed during the next render
|
|
2839
3015
|
* frame. Schedule a render frame if one is not already scheduled.
|
|
2840
3016
|
* @returns An id that can be used to cancel the callback
|
|
2841
|
-
* @private
|
|
2842
3017
|
*/
|
|
2843
3018
|
_requestRenderFrame(callback: () => void): TaskID {
|
|
2844
3019
|
this._update();
|
|
@@ -2856,10 +3031,9 @@ class Map extends Camera {
|
|
|
2856
3031
|
* - The map has is moving (or just finished moving)
|
|
2857
3032
|
* - A transition is in progress
|
|
2858
3033
|
*
|
|
2859
|
-
* @param
|
|
3034
|
+
* @param paintStartTimeStamp - The time when the animation frame began executing.
|
|
2860
3035
|
*
|
|
2861
|
-
* @returns
|
|
2862
|
-
* @private
|
|
3036
|
+
* @returns `this`
|
|
2863
3037
|
*/
|
|
2864
3038
|
_render(paintStartTimeStamp: number) {
|
|
2865
3039
|
const fadeDuration = this._idleTriggered ? this._fadeDuration : 0;
|
|
@@ -2966,11 +3140,13 @@ class Map extends Camera {
|
|
|
2966
3140
|
|
|
2967
3141
|
/**
|
|
2968
3142
|
* Force a synchronous redraw of the map.
|
|
3143
|
+
* @returns `this`
|
|
2969
3144
|
* @example
|
|
3145
|
+
* ```ts
|
|
2970
3146
|
* map.redraw();
|
|
2971
|
-
*
|
|
3147
|
+
* ```
|
|
2972
3148
|
*/
|
|
2973
|
-
redraw():
|
|
3149
|
+
redraw(): this {
|
|
2974
3150
|
if (this.style) {
|
|
2975
3151
|
// cancel the scheduled update
|
|
2976
3152
|
if (this._frame) {
|
|
@@ -3035,9 +3211,11 @@ class Map extends Camera {
|
|
|
3035
3211
|
* repaint the map when the layer changes. Calling this multiple times before the
|
|
3036
3212
|
* next frame is rendered will still result in only a single frame being rendered.
|
|
3037
3213
|
* @example
|
|
3214
|
+
* ```ts
|
|
3038
3215
|
* map.triggerRepaint();
|
|
3039
|
-
*
|
|
3040
|
-
* @see [Add
|
|
3216
|
+
* ```
|
|
3217
|
+
* @see [Add a 3D model](https://maplibre.org/maplibre-gl-js/docs/examples/add-3d-model/)
|
|
3218
|
+
* @see [Add an animated icon to the map](https://maplibre.org/maplibre-gl-js/docs/examples/add-image-animated/)
|
|
3041
3219
|
*/
|
|
3042
3220
|
triggerRepaint() {
|
|
3043
3221
|
if (this.style && !this._frame) {
|
|
@@ -3049,9 +3227,9 @@ class Map extends Camera {
|
|
|
3049
3227
|
}
|
|
3050
3228
|
}
|
|
3051
3229
|
|
|
3052
|
-
_onWindowOnline() {
|
|
3230
|
+
_onWindowOnline = () => {
|
|
3053
3231
|
this._update();
|
|
3054
|
-
}
|
|
3232
|
+
};
|
|
3055
3233
|
|
|
3056
3234
|
/**
|
|
3057
3235
|
* Gets and sets a Boolean indicating whether the map will render an outline
|
|
@@ -3061,12 +3239,10 @@ class Map extends Camera {
|
|
|
3061
3239
|
* The uncompressed file size of the first vector source is drawn in the top left
|
|
3062
3240
|
* corner of each tile, next to the tile ID.
|
|
3063
3241
|
*
|
|
3064
|
-
* @name showTileBoundaries
|
|
3065
|
-
* @type {boolean}
|
|
3066
|
-
* @instance
|
|
3067
|
-
* @memberof Map
|
|
3068
3242
|
* @example
|
|
3243
|
+
* ```ts
|
|
3069
3244
|
* map.showTileBoundaries = true;
|
|
3245
|
+
* ```
|
|
3070
3246
|
*/
|
|
3071
3247
|
get showTileBoundaries(): boolean { return !!this._showTileBoundaries; }
|
|
3072
3248
|
set showTileBoundaries(value: boolean) {
|
|
@@ -3078,11 +3254,6 @@ class Map extends Camera {
|
|
|
3078
3254
|
/**
|
|
3079
3255
|
* Gets and sets a Boolean indicating whether the map will visualize
|
|
3080
3256
|
* the padding offsets.
|
|
3081
|
-
*
|
|
3082
|
-
* @name showPadding
|
|
3083
|
-
* @type {boolean}
|
|
3084
|
-
* @instance
|
|
3085
|
-
* @memberof Map
|
|
3086
3257
|
*/
|
|
3087
3258
|
get showPadding(): boolean { return !!this._showPadding; }
|
|
3088
3259
|
set showPadding(value: boolean) {
|
|
@@ -3096,11 +3267,6 @@ class Map extends Camera {
|
|
|
3096
3267
|
* around all symbols in the data source, revealing which symbols
|
|
3097
3268
|
* were rendered or which were hidden due to collisions.
|
|
3098
3269
|
* This information is useful for debugging.
|
|
3099
|
-
*
|
|
3100
|
-
* @name showCollisionBoxes
|
|
3101
|
-
* @type {boolean}
|
|
3102
|
-
* @instance
|
|
3103
|
-
* @memberof Map
|
|
3104
3270
|
*/
|
|
3105
3271
|
get showCollisionBoxes(): boolean { return !!this._showCollisionBoxes; }
|
|
3106
3272
|
set showCollisionBoxes(value: boolean) {
|
|
@@ -3116,17 +3282,12 @@ class Map extends Camera {
|
|
|
3116
3282
|
}
|
|
3117
3283
|
}
|
|
3118
3284
|
|
|
3119
|
-
|
|
3285
|
+
/**
|
|
3120
3286
|
* Gets and sets a Boolean indicating whether the map should color-code
|
|
3121
3287
|
* each fragment to show how many times it has been shaded.
|
|
3122
3288
|
* White fragments have been shaded 8 or more times.
|
|
3123
3289
|
* Black fragments have been shaded 0 times.
|
|
3124
3290
|
* This information is useful for debugging.
|
|
3125
|
-
*
|
|
3126
|
-
* @name showOverdraw
|
|
3127
|
-
* @type {boolean}
|
|
3128
|
-
* @instance
|
|
3129
|
-
* @memberof Map
|
|
3130
3291
|
*/
|
|
3131
3292
|
get showOverdrawInspector(): boolean { return !!this._showOverdrawInspector; }
|
|
3132
3293
|
set showOverdrawInspector(value: boolean) {
|
|
@@ -3138,11 +3299,6 @@ class Map extends Camera {
|
|
|
3138
3299
|
/**
|
|
3139
3300
|
* Gets and sets a Boolean indicating whether the map will
|
|
3140
3301
|
* continuously repaint. This information is useful for analyzing performance.
|
|
3141
|
-
*
|
|
3142
|
-
* @name repaint
|
|
3143
|
-
* @type {boolean}
|
|
3144
|
-
* @instance
|
|
3145
|
-
* @memberof Map
|
|
3146
3302
|
*/
|
|
3147
3303
|
get repaint(): boolean { return !!this._repaint; }
|
|
3148
3304
|
set repaint(value: boolean) {
|
|
@@ -3157,7 +3313,7 @@ class Map extends Camera {
|
|
|
3157
3313
|
|
|
3158
3314
|
/**
|
|
3159
3315
|
* Returns the package version of the library
|
|
3160
|
-
* @returns
|
|
3316
|
+
* @returns Package version of the library
|
|
3161
3317
|
*/
|
|
3162
3318
|
get version(): string {
|
|
3163
3319
|
return version;
|
|
@@ -3167,11 +3323,9 @@ class Map extends Camera {
|
|
|
3167
3323
|
* Returns the elevation for the point where the camera is looking.
|
|
3168
3324
|
* This value corresponds to:
|
|
3169
3325
|
* "meters above sea level" * "exaggeration"
|
|
3170
|
-
* @returns
|
|
3326
|
+
* @returns The elevation.
|
|
3171
3327
|
*/
|
|
3172
3328
|
getCameraTargetElevation(): number {
|
|
3173
3329
|
return this.transform.elevation;
|
|
3174
3330
|
}
|
|
3175
3331
|
}
|
|
3176
|
-
|
|
3177
|
-
export default Map;
|