maplibre-gl 3.1.0 → 3.2.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/build/generate-doc-images.ts +73 -0
- package/build/generate-docs.ts +100 -0
- package/build/generate-struct-arrays.ts +9 -12
- package/dist/maplibre-gl-csp-worker.js +1 -1
- package/dist/maplibre-gl-csp-worker.js.map +1 -1
- package/dist/maplibre-gl-csp.js +1 -1
- package/dist/maplibre-gl-csp.js.map +1 -1
- package/dist/maplibre-gl-dev.js +3303 -3398
- package/dist/maplibre-gl-dev.js.map +1 -1
- package/dist/maplibre-gl.d.ts +3899 -3531
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +28 -25
- package/src/data/array_types.g.ts +14 -48
- package/src/data/bucket/circle_bucket.ts +11 -14
- package/src/data/bucket/fill_bucket.test.ts +6 -6
- package/src/data/bucket/fill_bucket.ts +10 -12
- package/src/data/bucket/fill_extrusion_bucket.ts +11 -13
- package/src/data/bucket/heatmap_bucket.ts +3 -6
- package/src/data/bucket/line_attributes.ts +1 -2
- package/src/data/bucket/line_attributes_ext.ts +1 -2
- package/src/data/bucket/line_bucket.test.ts +5 -5
- package/src/data/bucket/line_bucket.ts +18 -21
- package/src/data/bucket/pattern_attributes.ts +1 -3
- package/src/data/bucket/pattern_bucket_features.ts +3 -3
- package/src/data/bucket/symbol_bucket.test.ts +5 -5
- package/src/data/bucket/symbol_bucket.ts +12 -15
- package/src/data/bucket.ts +7 -11
- package/src/data/dem_data.test.ts +1 -1
- package/src/data/dem_data.ts +1 -1
- package/src/data/evaluation_feature.ts +4 -5
- package/src/data/extent.ts +1 -4
- package/src/data/feature_index.ts +14 -13
- package/src/data/feature_position_map.test.ts +4 -4
- package/src/data/feature_position_map.ts +1 -1
- package/src/data/index_array_type.ts +0 -1
- package/src/data/load_geometry.test.ts +1 -1
- package/src/data/load_geometry.ts +3 -4
- package/src/data/program_configuration.ts +6 -11
- package/src/data/segment.ts +9 -6
- package/src/geo/edge_insets.test.ts +1 -1
- package/src/geo/edge_insets.ts +36 -26
- package/src/geo/lng_lat.test.ts +1 -1
- package/src/geo/lng_lat.ts +61 -44
- package/src/geo/lng_lat_bounds.test.ts +2 -2
- package/src/geo/lng_lat_bounds.ts +88 -68
- package/src/geo/mercator_coordinate.test.ts +2 -2
- package/src/geo/mercator_coordinate.ts +34 -27
- package/src/geo/transform.test.ts +3 -3
- package/src/geo/transform.ts +58 -79
- package/src/gl/color_mode.ts +1 -3
- package/src/gl/context.ts +12 -11
- package/src/gl/cull_face_mode.ts +1 -3
- package/src/gl/depth_mode.ts +1 -3
- package/src/gl/framebuffer.ts +5 -4
- package/src/gl/index_buffer.ts +5 -4
- package/src/gl/render_pool.test.ts +2 -2
- package/src/gl/render_pool.ts +5 -5
- package/src/gl/state.test.ts +1 -1
- package/src/gl/stencil_mode.ts +1 -3
- package/src/gl/value.ts +1 -1
- package/src/gl/vertex_buffer.test.ts +2 -2
- package/src/gl/vertex_buffer.ts +8 -14
- package/src/index.test.ts +2 -2
- package/src/index.ts +121 -113
- package/src/render/draw_background.ts +7 -9
- package/src/render/draw_circle.ts +13 -15
- package/src/render/draw_collision_debug.ts +11 -13
- package/src/render/draw_custom.ts +6 -8
- package/src/render/draw_debug.test.ts +4 -4
- package/src/render/draw_debug.ts +8 -10
- package/src/render/draw_fill.test.ts +13 -13
- package/src/render/draw_fill.ts +9 -11
- package/src/render/draw_fill_extrusion.ts +10 -12
- package/src/render/draw_heatmap.ts +12 -14
- package/src/render/draw_hillshade.ts +10 -12
- package/src/render/draw_line.ts +9 -9
- package/src/render/draw_raster.ts +9 -11
- package/src/render/draw_symbol.test.ts +16 -16
- package/src/render/draw_symbol.ts +15 -16
- package/src/render/draw_terrain.ts +11 -11
- package/src/render/glyph_atlas.ts +10 -1
- package/src/render/glyph_manager.test.ts +3 -3
- package/src/render/glyph_manager.ts +7 -7
- package/src/render/image_atlas.ts +6 -3
- package/src/render/image_manager.ts +3 -5
- package/src/render/line_atlas.test.ts +1 -1
- package/src/render/line_atlas.ts +19 -14
- package/src/render/painter.ts +85 -65
- package/src/render/program/background_program.ts +2 -2
- package/src/render/program/circle_program.ts +5 -5
- package/src/render/program/clipping_mask_program.ts +1 -1
- package/src/render/program/collision_program.ts +4 -4
- package/src/render/program/debug_program.ts +1 -1
- package/src/render/program/fill_extrusion_program.ts +3 -3
- package/src/render/program/fill_program.ts +3 -3
- package/src/render/program/heatmap_program.ts +5 -5
- package/src/render/program/hillshade_program.ts +7 -7
- package/src/render/program/line_program.ts +6 -6
- package/src/render/program/pattern.ts +3 -3
- package/src/render/program/raster_program.ts +2 -2
- package/src/render/program/symbol_program.ts +2 -2
- package/src/render/program/terrain_program.ts +1 -1
- package/src/render/program.ts +18 -16
- package/src/render/render_to_texture.test.ts +15 -15
- package/src/render/render_to_texture.ts +10 -10
- package/src/render/terrain.test.ts +38 -7
- package/src/render/terrain.ts +103 -67
- package/src/render/texture.ts +5 -4
- package/src/render/uniform_binding.test.ts +1 -1
- package/src/render/uniform_binding.ts +7 -1
- package/src/render/update_pattern_positions_in_program.ts +5 -5
- package/src/render/vertex_array_object.ts +9 -8
- package/src/shaders/encode_attribute.ts +0 -2
- package/src/shaders/shaders.ts +1 -3
- package/src/source/canvas_source.test.ts +6 -6
- package/src/source/canvas_source.ts +46 -60
- package/src/source/geojson_source.test.ts +5 -5
- package/src/source/geojson_source.ts +75 -59
- package/src/source/geojson_source_diff.ts +39 -2
- package/src/source/geojson_worker_source.test.ts +3 -3
- package/src/source/geojson_worker_source.ts +20 -26
- package/src/source/geojson_wrapper.test.ts +3 -3
- package/src/source/geojson_wrapper.ts +2 -4
- package/src/source/image_source.test.ts +9 -8
- package/src/source/image_source.ts +49 -35
- package/src/source/load_tilejson.ts +2 -2
- package/src/source/pixels_to_tile_units.ts +2 -3
- package/src/source/query_features.test.ts +3 -3
- package/src/source/query_features.ts +50 -19
- package/src/source/raster_dem_tile_source.test.ts +3 -3
- package/src/source/raster_dem_tile_source.ts +23 -10
- package/src/source/raster_dem_tile_worker_source.test.ts +2 -2
- package/src/source/raster_dem_tile_worker_source.ts +3 -5
- package/src/source/raster_tile_source.test.ts +3 -3
- package/src/source/raster_tile_source.ts +38 -11
- package/src/source/rtl_text_plugin.ts +4 -1
- package/src/source/source.ts +67 -59
- package/src/source/source_cache.test.ts +7 -7
- package/src/source/source_cache.ts +17 -38
- package/src/source/source_state.ts +2 -5
- package/src/source/terrain_source_cache.test.ts +8 -8
- package/src/source/terrain_source_cache.ts +42 -27
- package/src/source/tile.test.ts +3 -3
- package/src/source/tile.ts +32 -38
- package/src/source/tile_bounds.ts +2 -4
- package/src/source/tile_cache.test.ts +2 -2
- package/src/source/tile_cache.ts +20 -30
- package/src/source/tile_id.ts +11 -2
- package/src/source/vector_tile_source.test.ts +3 -3
- package/src/source/vector_tile_source.ts +34 -24
- package/src/source/vector_tile_worker_source.test.ts +4 -4
- package/src/source/vector_tile_worker_source.ts +11 -23
- package/src/source/video_source.test.ts +5 -5
- package/src/source/video_source.ts +21 -28
- package/src/source/worker.ts +6 -8
- package/src/source/worker_source.ts +6 -8
- package/src/source/worker_tile.test.ts +5 -5
- package/src/source/worker_tile.ts +13 -16
- package/src/style/create_style_layer.ts +31 -26
- package/src/style/evaluation_parameters.ts +5 -4
- package/src/style/format_section_override.test.ts +2 -2
- package/src/style/format_section_override.ts +1 -1
- package/src/style/light.test.ts +2 -2
- package/src/style/light.ts +3 -5
- package/src/style/load_glyph_range.test.ts +1 -1
- package/src/style/load_glyph_range.ts +3 -3
- package/src/style/load_sprite.test.ts +1 -1
- package/src/style/load_sprite.ts +3 -3
- package/src/style/parse_glyph_pbf.ts +1 -1
- package/src/style/pauseable_placement.ts +7 -9
- package/src/style/properties.ts +4 -53
- package/src/style/query_utils.ts +3 -3
- package/src/style/style.test.ts +22 -19
- package/src/style/style.ts +118 -84
- package/src/style/style_glyph.ts +6 -0
- package/src/style/style_image.ts +39 -33
- package/src/style/style_layer/background_style_layer.ts +2 -4
- package/src/style/style_layer/circle_style_layer.ts +7 -6
- package/src/style/style_layer/custom_style_layer.ts +23 -48
- package/src/style/style_layer/fill_extrusion_style_layer.ts +4 -6
- package/src/style/style_layer/fill_style_layer.ts +5 -7
- package/src/style/style_layer/heatmap_style_layer.ts +8 -7
- package/src/style/style_layer/hillshade_style_layer.ts +2 -4
- package/src/style/style_layer/line_style_layer.ts +6 -8
- package/src/style/style_layer/overlap_mode.test.ts +3 -3
- package/src/style/style_layer/overlap_mode.ts +3 -0
- package/src/style/style_layer/raster_style_layer.ts +2 -4
- package/src/style/style_layer/symbol_style_layer.ts +6 -8
- package/src/style/style_layer/typed_style_layer.ts +7 -7
- package/src/style/style_layer.test.ts +5 -5
- package/src/style/style_layer.ts +7 -6
- package/src/style/style_layer_index.test.ts +1 -1
- package/src/style/style_layer_index.ts +3 -5
- package/src/style/zoom_history.ts +1 -3
- package/src/symbol/anchor.test.ts +1 -1
- package/src/symbol/anchor.ts +1 -3
- package/src/symbol/check_max_angle.test.ts +8 -2
- package/src/symbol/check_max_angle.ts +10 -13
- package/src/symbol/clip_line.test.ts +1 -1
- package/src/symbol/clip_line.ts +6 -9
- package/src/symbol/collision_feature.test.ts +2 -2
- package/src/symbol/collision_feature.ts +7 -12
- package/src/symbol/collision_index.test.ts +2 -2
- package/src/symbol/collision_index.ts +5 -11
- package/src/symbol/cross_tile_symbol_index.test.ts +2 -2
- package/src/symbol/cross_tile_symbol_index.ts +5 -7
- package/src/symbol/get_anchors.ts +2 -2
- package/src/symbol/grid_index.test.ts +1 -1
- package/src/symbol/grid_index.ts +4 -5
- package/src/symbol/merge_lines.test.ts +1 -1
- package/src/symbol/merge_lines.ts +1 -1
- package/src/symbol/opacity_state.ts +1 -3
- package/src/symbol/path_interpolator.test.ts +1 -1
- package/src/symbol/path_interpolator.ts +1 -3
- package/src/symbol/placement.ts +9 -9
- package/src/symbol/projection.ts +61 -34
- package/src/symbol/quads.ts +7 -11
- package/src/symbol/shaping.ts +1 -1
- package/src/symbol/symbol_layout.ts +9 -12
- package/src/symbol/symbol_size.ts +1 -1
- package/src/symbol/symbol_style_layer.test.ts +4 -4
- package/src/symbol/transform_text.ts +2 -2
- package/src/types/callback.ts +14 -14
- package/src/types/cancelable.ts +3 -0
- package/src/types/transferable.ts +3 -0
- package/src/ui/anchor.ts +4 -0
- package/src/ui/camera.test.ts +6 -6
- package/src/ui/camera.ts +392 -361
- package/src/ui/control/attribution_control.test.ts +1 -1
- package/src/ui/control/attribution_control.ts +34 -30
- package/src/ui/control/control.ts +14 -20
- package/src/ui/control/fullscreen_control.test.ts +1 -1
- package/src/ui/control/fullscreen_control.ts +21 -26
- package/src/ui/control/geolocate_control.test.ts +5 -5
- package/src/ui/control/geolocate_control.ts +181 -194
- package/src/ui/control/logo_control.ts +20 -16
- package/src/ui/control/navigation_control.test.ts +1 -1
- package/src/ui/control/navigation_control.ts +46 -42
- package/src/ui/control/scale_control.test.ts +1 -1
- package/src/ui/control/scale_control.ts +30 -21
- package/src/ui/control/terrain_control.test.ts +1 -1
- package/src/ui/control/terrain_control.ts +14 -18
- package/src/ui/default_locale.ts +1 -3
- package/src/ui/events.ts +570 -1281
- package/src/ui/handler/box_zoom.test.ts +2 -2
- package/src/ui/handler/box_zoom.ts +16 -11
- package/src/ui/handler/click_zoom.ts +11 -3
- package/src/ui/handler/cooperative_gestures.test.ts +3 -3
- package/src/ui/handler/dblclick_zoom.test.ts +1 -1
- package/src/ui/handler/drag_handler.ts +30 -22
- package/src/ui/handler/drag_move_state_manager.ts +1 -1
- package/src/ui/handler/drag_pan.test.ts +2 -2
- package/src/ui/handler/drag_rotate.test.ts +3 -3
- package/src/ui/handler/keyboard.test.ts +2 -2
- package/src/ui/handler/keyboard.ts +22 -13
- package/src/ui/handler/map_event.test.ts +2 -2
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/mouse_rotate.test.ts +3 -3
- package/src/ui/handler/scroll_zoom.test.ts +3 -3
- package/src/ui/handler/scroll_zoom.ts +45 -52
- package/src/ui/handler/shim/dblclick_zoom.ts +12 -6
- package/src/ui/handler/shim/drag_pan.ts +34 -14
- package/src/ui/handler/shim/drag_rotate.ts +20 -12
- package/src/ui/handler/shim/two_fingers_touch.ts +24 -18
- package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
- package/src/ui/handler/tap_drag_zoom.ts +18 -10
- package/src/ui/handler/tap_recognizer.ts +1 -1
- package/src/ui/handler/tap_zoom.ts +4 -3
- package/src/ui/handler/touch_pan.ts +3 -2
- package/src/ui/handler/transform-provider.ts +4 -6
- package/src/ui/handler/two_fingers_touch.test.ts +3 -3
- package/src/ui/handler/two_fingers_touch.ts +64 -47
- package/src/ui/handler_inertia.ts +4 -4
- package/src/ui/handler_manager.ts +86 -52
- package/src/ui/hash.test.ts +1 -1
- package/src/ui/hash.ts +21 -28
- package/src/ui/map/isMoving.test.ts +3 -3
- package/src/ui/map/isRotating.test.ts +3 -3
- package/src/ui/map/isZooming.test.ts +3 -3
- package/src/ui/map.test.ts +97 -8
- package/src/ui/map.ts +856 -702
- package/src/ui/map_events.test.ts +1 -1
- package/src/ui/marker.test.ts +35 -15
- package/src/ui/marker.ts +220 -141
- package/src/ui/popup.test.ts +2 -2
- package/src/ui/popup.ts +179 -147
- package/src/util/actor.test.ts +7 -7
- package/src/util/actor.ts +25 -22
- package/src/util/ajax.ts +37 -17
- package/src/util/browser.test.ts +1 -1
- package/src/util/browser.ts +2 -6
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/classify_rings.ts +1 -1
- package/src/util/color_ramp.ts +0 -2
- package/src/util/config.ts +6 -3
- package/src/util/debug.ts +0 -2
- package/src/util/dictionary_coder.ts +1 -4
- package/src/util/dispatcher.test.ts +3 -3
- package/src/util/dispatcher.ts +4 -9
- package/src/util/dom.ts +1 -1
- package/src/util/evented.ts +23 -18
- package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +4 -5
- package/src/util/global_worker_pool.ts +2 -3
- package/src/util/image.ts +10 -4
- package/src/util/image_request.test.ts +3 -3
- package/src/util/image_request.ts +15 -14
- package/src/util/is_char_in_unicode_block.ts +1 -3
- package/src/util/offscreen_canvas_supported.ts +1 -1
- package/src/util/performance.ts +1 -2
- package/src/util/request_manager.ts +4 -0
- package/src/util/resolve_tokens.test.ts +1 -1
- package/src/util/resolve_tokens.ts +3 -6
- package/src/util/script_detection.ts +1 -4
- package/src/util/smart_wrap.ts +3 -5
- package/src/util/struct_array.ts +18 -14
- package/src/util/style.ts +2 -2
- package/src/util/task_queue.test.ts +1 -1
- package/src/util/task_queue.ts +1 -3
- package/src/util/test/mock_webgl.ts +6 -0
- package/src/util/test/util.ts +2 -2
- package/src/util/throttle.test.ts +1 -1
- package/src/util/throttle.ts +1 -2
- package/src/util/throttled_invoker.ts +1 -5
- package/src/util/transferable_grid_index.test.ts +1 -1
- package/src/util/transferable_grid_index.ts +1 -3
- package/src/util/util.test.ts +1 -14
- package/src/util/util.ts +44 -107
- package/src/util/vectortile_to_geojson.ts +13 -3
- package/src/util/verticalize_punctuation.ts +1 -1
- package/src/util/web_worker.ts +2 -2
- package/src/util/web_worker_transfer.ts +11 -8
- package/src/util/webp_supported.ts +2 -4
- package/src/util/worker_pool.test.ts +1 -1
- package/src/util/worker_pool.ts +4 -5
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
import {Event, Evented} from '../../util/evented';
|
|
2
|
-
import DOM from '../../util/dom';
|
|
3
|
-
import {extend,
|
|
2
|
+
import {DOM} from '../../util/dom';
|
|
3
|
+
import {extend, warnOnce} from '../../util/util';
|
|
4
4
|
import {checkGeolocationSupport} from '../../util/geolocation_support';
|
|
5
|
-
import LngLat from '../../geo/lng_lat';
|
|
6
|
-
import Marker from '../marker';
|
|
5
|
+
import {LngLat} from '../../geo/lng_lat';
|
|
6
|
+
import {Marker} from '../marker';
|
|
7
7
|
|
|
8
|
-
import type Map from '../map';
|
|
8
|
+
import type {Map} from '../map';
|
|
9
9
|
import type {FitBoundsOptions} from '../camera';
|
|
10
10
|
import type {IControl} from './control';
|
|
11
|
-
import LngLatBounds from '../../geo/lng_lat_bounds';
|
|
11
|
+
import {LngLatBounds} from '../../geo/lng_lat_bounds';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* The {@link GeolocateControl} options
|
|
15
|
+
*/
|
|
13
16
|
type GeolocateOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* A Geolocation API [PositionOptions](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions) object.
|
|
19
|
+
* @defaultValue `{enableHighAccuracy: false, timeout: 6000}`
|
|
20
|
+
*/
|
|
14
21
|
positionOptions?: PositionOptions;
|
|
22
|
+
/**
|
|
23
|
+
* A options object to use when the map is panned and zoomed to the user's location. The default is to use a `maxZoom` of 15 to limit how far the map will zoom in for very accurate locations.
|
|
24
|
+
*/
|
|
15
25
|
fitBoundsOptions?: FitBoundsOptions;
|
|
26
|
+
/**
|
|
27
|
+
* If `true` the Geolocate Control becomes a toggle button and when active the map will receive updates to the user's location as it changes.
|
|
28
|
+
* @defaultValue false
|
|
29
|
+
*/
|
|
16
30
|
trackUserLocation?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* By default, if showUserLocation is `true`, a transparent circle will be drawn around the user location indicating the accuracy (95% confidence level) of the user's location. Set to `false` to disable. Always disabled when showUserLocation is `false`.
|
|
33
|
+
* @defaultValue true
|
|
34
|
+
*/
|
|
17
35
|
showAccuracyCircle?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* By default a dot will be shown on the map at the user's location. Set to `false` to disable.
|
|
38
|
+
* @defaultValue true
|
|
39
|
+
*/
|
|
18
40
|
showUserLocation?: boolean;
|
|
19
41
|
};
|
|
20
42
|
|
|
@@ -53,25 +75,125 @@ let noTimeout = false;
|
|
|
53
75
|
* * disabled - occurs if Geolocation is not available, disabled or denied.
|
|
54
76
|
*
|
|
55
77
|
* These interaction states can't be controlled programmatically, rather they are set based on user interactions.
|
|
56
|
-
*
|
|
57
|
-
* @implements {IControl}
|
|
58
|
-
* @param {GeolocateOptions} [options]
|
|
59
|
-
* @param {PositionOptions} [options.positionOptions={enableHighAccuracy: false, timeout: 6000}] A Geolocation API [PositionOptions](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions) object.
|
|
60
|
-
* @param {FitBoundsOptions} [options.fitBoundsOptions={maxZoom: 15}] A {@link Map#fitBounds} options object to use when the map is panned and zoomed to the user's location. The default is to use a `maxZoom` of 15 to limit how far the map will zoom in for very accurate locations.
|
|
61
|
-
* @param {boolean} [options.trackUserLocation=false] If `true` the Geolocate Control becomes a toggle button and when active the map will receive updates to the user's location as it changes.
|
|
62
|
-
* @param {boolean} [options.showAccuracyCircle=true] By default, if showUserLocation is `true`, a transparent circle will be drawn around the user location indicating the accuracy (95% confidence level) of the user's location. Set to `false` to disable. Always disabled when showUserLocation is `false`.
|
|
63
|
-
* @param {boolean} [options.showUserLocation=true] By default a dot will be shown on the map at the user's location. Set to `false` to disable.
|
|
78
|
+
* @group Markers and Controls
|
|
64
79
|
*
|
|
65
80
|
* @example
|
|
81
|
+
* ```ts
|
|
66
82
|
* map.addControl(new maplibregl.GeolocateControl({
|
|
67
83
|
* positionOptions: {
|
|
68
84
|
* enableHighAccuracy: true
|
|
69
85
|
* },
|
|
70
86
|
* trackUserLocation: true
|
|
71
87
|
* }));
|
|
72
|
-
*
|
|
88
|
+
* ```
|
|
89
|
+
* @see [Locate the user](https://maplibre.org/maplibre-gl-js/docs/examples/locate-user/)
|
|
90
|
+
*
|
|
91
|
+
* ### Events
|
|
92
|
+
*
|
|
93
|
+
* @event `trackuserlocationend` - Fired when the Geolocate Control changes to the background state, which happens when a user changes the camera during an active position lock. This only applies when trackUserLocation is true. In the background state, the dot on the map will update with location updates but the camera will not.
|
|
94
|
+
*
|
|
95
|
+
* @event `trackuserlocationstart` - Fired when the Geolocate Control changes to the active lock state, which happens either upon first obtaining a successful Geolocation API position for the user (a geolocate event will follow), or the user clicks the geolocate button when in the background state which uses the last known position to recenter the map and enter active lock state (no geolocate event will follow unless the users's location changes).
|
|
96
|
+
*
|
|
97
|
+
* @event `geolocate` - Fired on each Geolocation API position update which returned as success.
|
|
98
|
+
* `data` - The returned [Position](https://developer.mozilla.org/en-US/docs/Web/API/Position) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
|
|
99
|
+
*
|
|
100
|
+
* @event `error` - Fired on each Geolocation API position update which returned as an error.
|
|
101
|
+
* `data` - The returned [PositionError](https://developer.mozilla.org/en-US/docs/Web/API/PositionError) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
|
|
102
|
+
*
|
|
103
|
+
* @event `outofmaxbounds` Fired on each Geolocation API position update which returned as success but user position is out of map maxBounds.
|
|
104
|
+
* `data` - The returned [Position](https://developer.mozilla.org/en-US/docs/Web/API/Position) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* // Initialize the geolocate control.
|
|
109
|
+
* let geolocate = new maplibregl.GeolocateControl({
|
|
110
|
+
* positionOptions: {
|
|
111
|
+
* enableHighAccuracy: true
|
|
112
|
+
* },
|
|
113
|
+
* trackUserLocation: true
|
|
114
|
+
* });
|
|
115
|
+
* // Add the control to the map.
|
|
116
|
+
* map.addControl(geolocate);
|
|
117
|
+
* // Set an event listener that fires
|
|
118
|
+
* // when a trackuserlocationend event occurs.
|
|
119
|
+
* geolocate.on('trackuserlocationend', function() {
|
|
120
|
+
* console.log('A trackuserlocationend event has occurred.')
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* // Initialize the geolocate control.
|
|
127
|
+
* let geolocate = new maplibregl.GeolocateControl({
|
|
128
|
+
* positionOptions: {
|
|
129
|
+
* enableHighAccuracy: true
|
|
130
|
+
* },
|
|
131
|
+
* trackUserLocation: true
|
|
132
|
+
* });
|
|
133
|
+
* // Add the control to the map.
|
|
134
|
+
* map.addControl(geolocate);
|
|
135
|
+
* // Set an event listener that fires
|
|
136
|
+
* // when a trackuserlocationstart event occurs.
|
|
137
|
+
* geolocate.on('trackuserlocationstart', function() {
|
|
138
|
+
* console.log('A trackuserlocationstart event has occurred.')
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* // Initialize the geolocate control.
|
|
145
|
+
* let geolocate = new maplibregl.GeolocateControl({
|
|
146
|
+
* positionOptions: {
|
|
147
|
+
* enableHighAccuracy: true
|
|
148
|
+
* },
|
|
149
|
+
* trackUserLocation: true
|
|
150
|
+
* });
|
|
151
|
+
* // Add the control to the map.
|
|
152
|
+
* map.addControl(geolocate);
|
|
153
|
+
* // Set an event listener that fires
|
|
154
|
+
* // when a geolocate event occurs.
|
|
155
|
+
* geolocate.on('geolocate', function() {
|
|
156
|
+
* console.log('A geolocate event has occurred.')
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* // Initialize the geolocate control.
|
|
163
|
+
* let geolocate = new maplibregl.GeolocateControl({
|
|
164
|
+
* positionOptions: {
|
|
165
|
+
* enableHighAccuracy: true
|
|
166
|
+
* },
|
|
167
|
+
* trackUserLocation: true
|
|
168
|
+
* });
|
|
169
|
+
* // Add the control to the map.
|
|
170
|
+
* map.addControl(geolocate);
|
|
171
|
+
* // Set an event listener that fires
|
|
172
|
+
* // when an error event occurs.
|
|
173
|
+
* geolocate.on('error', function() {
|
|
174
|
+
* console.log('An error event has occurred.')
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* // Initialize the geolocate control.
|
|
181
|
+
* let geolocate = new maplibregl.GeolocateControl({
|
|
182
|
+
* positionOptions: {
|
|
183
|
+
* enableHighAccuracy: true
|
|
184
|
+
* },
|
|
185
|
+
* trackUserLocation: true
|
|
186
|
+
* });
|
|
187
|
+
* // Add the control to the map.
|
|
188
|
+
* map.addControl(geolocate);
|
|
189
|
+
* // Set an event listener that fires
|
|
190
|
+
* // when an outofmaxbounds event occurs.
|
|
191
|
+
* geolocate.on('outofmaxbounds', function() {
|
|
192
|
+
* console.log('An outofmaxbounds event has occurred.')
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
73
195
|
*/
|
|
74
|
-
class GeolocateControl extends Evented implements IControl {
|
|
196
|
+
export class GeolocateControl extends Evented implements IControl {
|
|
75
197
|
_map: Map;
|
|
76
198
|
options: GeolocateOptions;
|
|
77
199
|
_container: HTMLElement;
|
|
@@ -80,6 +202,22 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
80
202
|
_geolocateButton: HTMLButtonElement;
|
|
81
203
|
_geolocationWatchID: number;
|
|
82
204
|
_timeoutId: ReturnType<typeof setTimeout>;
|
|
205
|
+
/* Geolocate Control Watch States
|
|
206
|
+
* This is the private state of the control.
|
|
207
|
+
*
|
|
208
|
+
* OFF
|
|
209
|
+
* off/inactive
|
|
210
|
+
* WAITING_ACTIVE
|
|
211
|
+
* Geolocate Control was clicked but still waiting for Geolocation API response with user location
|
|
212
|
+
* ACTIVE_LOCK
|
|
213
|
+
* Showing the user location as a dot AND tracking the camera to be fixed to their location. If their location changes the map moves to follow.
|
|
214
|
+
* ACTIVE_ERROR
|
|
215
|
+
* There was en error from the Geolocation API while trying to show and track the user location.
|
|
216
|
+
* BACKGROUND
|
|
217
|
+
* Showing the user location as a dot but the camera doesn't follow their location as it changes.
|
|
218
|
+
* BACKGROUND_ERROR
|
|
219
|
+
* There was an error from the Geolocation API while trying to show (but not track) the user location.
|
|
220
|
+
*/
|
|
83
221
|
_watchState: 'OFF' | 'ACTIVE_LOCK' | 'WAITING_ACTIVE' | 'ACTIVE_ERROR' | 'BACKGROUND' | 'BACKGROUND_ERROR';
|
|
84
222
|
_lastKnownPosition: any;
|
|
85
223
|
_userLocationDotMarker: Marker;
|
|
@@ -90,18 +228,9 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
90
228
|
constructor(options: GeolocateOptions) {
|
|
91
229
|
super();
|
|
92
230
|
this.options = extend({}, defaultOptions, options);
|
|
93
|
-
|
|
94
|
-
bindAll([
|
|
95
|
-
'_onSuccess',
|
|
96
|
-
'_onError',
|
|
97
|
-
'_onZoom',
|
|
98
|
-
'_finish',
|
|
99
|
-
'_setupUI',
|
|
100
|
-
'_updateCamera',
|
|
101
|
-
'_updateMarker'
|
|
102
|
-
], this);
|
|
103
231
|
}
|
|
104
232
|
|
|
233
|
+
/** {@inheritDoc IControl.onAdd} */
|
|
105
234
|
onAdd(map: Map) {
|
|
106
235
|
this._map = map;
|
|
107
236
|
this._container = DOM.create('div', 'maplibregl-ctrl maplibregl-ctrl-group');
|
|
@@ -109,6 +238,7 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
109
238
|
return this._container;
|
|
110
239
|
}
|
|
111
240
|
|
|
241
|
+
/** {@inheritDoc IControl.onRemove} */
|
|
112
242
|
onRemove() {
|
|
113
243
|
// clear the geolocation watch if exists
|
|
114
244
|
if (this._geolocationWatchID !== undefined) {
|
|
@@ -134,9 +264,8 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
134
264
|
/**
|
|
135
265
|
* Check if the Geolocation API Position is outside the map's maxbounds.
|
|
136
266
|
*
|
|
137
|
-
* @param
|
|
138
|
-
* @returns
|
|
139
|
-
* @private
|
|
267
|
+
* @param position - the Geolocation API Position
|
|
268
|
+
* @returns `true` if position is outside the map's maxbounds, otherwise returns `false`.
|
|
140
269
|
*/
|
|
141
270
|
_isOutOfMapMaxBounds(position: GeolocationPosition) {
|
|
142
271
|
const bounds = this._map.getMaxBounds();
|
|
@@ -181,10 +310,9 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
181
310
|
/**
|
|
182
311
|
* When the Geolocation API returns a new location, update the GeolocateControl.
|
|
183
312
|
*
|
|
184
|
-
* @param
|
|
185
|
-
* @private
|
|
313
|
+
* @param position - the Geolocation API Position
|
|
186
314
|
*/
|
|
187
|
-
_onSuccess(position: GeolocationPosition) {
|
|
315
|
+
_onSuccess = (position: GeolocationPosition) => {
|
|
188
316
|
if (!this._map) {
|
|
189
317
|
// control has since been removed
|
|
190
318
|
return;
|
|
@@ -244,15 +372,14 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
244
372
|
|
|
245
373
|
this.fire(new Event('geolocate', position));
|
|
246
374
|
this._finish();
|
|
247
|
-
}
|
|
375
|
+
};
|
|
248
376
|
|
|
249
377
|
/**
|
|
250
378
|
* Update the camera location to center on the current position
|
|
251
379
|
*
|
|
252
|
-
* @param
|
|
253
|
-
* @private
|
|
380
|
+
* @param position - the Geolocation API Position
|
|
254
381
|
*/
|
|
255
|
-
_updateCamera(position: GeolocationPosition) {
|
|
382
|
+
_updateCamera = (position: GeolocationPosition) => {
|
|
256
383
|
const center = new LngLat(position.coords.longitude, position.coords.latitude);
|
|
257
384
|
const radius = position.coords.accuracy;
|
|
258
385
|
const bearing = this._map.getBearing();
|
|
@@ -262,15 +389,14 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
262
389
|
this._map.fitBounds(newBounds, options, {
|
|
263
390
|
geolocateSource: true // tag this camera change so it won't cause the control to change to background state
|
|
264
391
|
});
|
|
265
|
-
}
|
|
392
|
+
};
|
|
266
393
|
|
|
267
394
|
/**
|
|
268
395
|
* Update the user location dot Marker to the current position
|
|
269
396
|
*
|
|
270
|
-
* @param
|
|
271
|
-
* @private
|
|
397
|
+
* @param position - the Geolocation API Position
|
|
272
398
|
*/
|
|
273
|
-
_updateMarker(position?: GeolocationPosition | null) {
|
|
399
|
+
_updateMarker = (position?: GeolocationPosition | null) => {
|
|
274
400
|
if (position) {
|
|
275
401
|
const center = new LngLat(position.coords.longitude, position.coords.latitude);
|
|
276
402
|
this._accuracyCircleMarker.setLngLat(center).addTo(this._map);
|
|
@@ -283,7 +409,7 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
283
409
|
this._userLocationDotMarker.remove();
|
|
284
410
|
this._accuracyCircleMarker.remove();
|
|
285
411
|
}
|
|
286
|
-
}
|
|
412
|
+
};
|
|
287
413
|
|
|
288
414
|
_updateCircleRadius() {
|
|
289
415
|
const bounds = this._map.getBounds();
|
|
@@ -296,13 +422,13 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
296
422
|
this._circleElement.style.height = `${circleDiameter}px`;
|
|
297
423
|
}
|
|
298
424
|
|
|
299
|
-
_onZoom() {
|
|
425
|
+
_onZoom = () => {
|
|
300
426
|
if (this.options.showUserLocation && this.options.showAccuracyCircle) {
|
|
301
427
|
this._updateCircleRadius();
|
|
302
428
|
}
|
|
303
|
-
}
|
|
429
|
+
};
|
|
304
430
|
|
|
305
|
-
_onError(error: GeolocationPositionError) {
|
|
431
|
+
_onError = (error: GeolocationPositionError) => {
|
|
306
432
|
if (!this._map) {
|
|
307
433
|
// control has since been removed
|
|
308
434
|
return;
|
|
@@ -343,14 +469,14 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
343
469
|
this.fire(new Event('error', error));
|
|
344
470
|
|
|
345
471
|
this._finish();
|
|
346
|
-
}
|
|
472
|
+
};
|
|
347
473
|
|
|
348
|
-
_finish() {
|
|
474
|
+
_finish = () => {
|
|
349
475
|
if (this._timeoutId) { clearTimeout(this._timeoutId); }
|
|
350
476
|
this._timeoutId = undefined;
|
|
351
|
-
}
|
|
477
|
+
};
|
|
352
478
|
|
|
353
|
-
_setupUI(supported: boolean) {
|
|
479
|
+
_setupUI = (supported: boolean) => {
|
|
354
480
|
// this method is called asynchronously during onAdd
|
|
355
481
|
// the control could have been removed before reaching here
|
|
356
482
|
if (!this._map) {
|
|
@@ -383,7 +509,7 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
383
509
|
if (this.options.showUserLocation) {
|
|
384
510
|
this._dotElement = DOM.create('div', 'maplibregl-user-location-dot');
|
|
385
511
|
|
|
386
|
-
this._userLocationDotMarker = new Marker(this._dotElement);
|
|
512
|
+
this._userLocationDotMarker = new Marker({element: this._dotElement});
|
|
387
513
|
|
|
388
514
|
this._circleElement = DOM.create('div', 'maplibregl-user-location-accuracy-circle');
|
|
389
515
|
this._accuracyCircleMarker = new Marker({element: this._circleElement, pitchAlignment: 'map'});
|
|
@@ -412,15 +538,16 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
412
538
|
}
|
|
413
539
|
});
|
|
414
540
|
}
|
|
415
|
-
}
|
|
541
|
+
};
|
|
416
542
|
|
|
417
543
|
/**
|
|
418
544
|
* Programmatically request and move the map to the user's location.
|
|
419
545
|
*
|
|
420
|
-
* @returns
|
|
546
|
+
* @returns `false` if called before control was added to a map, otherwise returns `true`.
|
|
421
547
|
* @example
|
|
548
|
+
* ```ts
|
|
422
549
|
* // Initialize the geolocate control.
|
|
423
|
-
*
|
|
550
|
+
* let geolocate = new maplibregl.GeolocateControl({
|
|
424
551
|
* positionOptions: {
|
|
425
552
|
* enableHighAccuracy: true
|
|
426
553
|
* },
|
|
@@ -431,8 +558,9 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
431
558
|
* map.on('load', function() {
|
|
432
559
|
* geolocate.trigger();
|
|
433
560
|
* });
|
|
561
|
+
* ```
|
|
434
562
|
*/
|
|
435
|
-
trigger() {
|
|
563
|
+
trigger(): boolean {
|
|
436
564
|
if (!this._setup) {
|
|
437
565
|
warnOnce('Geolocate control triggered before added to a map');
|
|
438
566
|
return false;
|
|
@@ -537,144 +665,3 @@ class GeolocateControl extends Evented implements IControl {
|
|
|
537
665
|
}
|
|
538
666
|
}
|
|
539
667
|
|
|
540
|
-
export default GeolocateControl;
|
|
541
|
-
|
|
542
|
-
/* Geolocate Control Watch States
|
|
543
|
-
* This is the private state of the control.
|
|
544
|
-
*
|
|
545
|
-
* OFF
|
|
546
|
-
* off/inactive
|
|
547
|
-
* WAITING_ACTIVE
|
|
548
|
-
* Geolocate Control was clicked but still waiting for Geolocation API response with user location
|
|
549
|
-
* ACTIVE_LOCK
|
|
550
|
-
* Showing the user location as a dot AND tracking the camera to be fixed to their location. If their location changes the map moves to follow.
|
|
551
|
-
* ACTIVE_ERROR
|
|
552
|
-
* There was en error from the Geolocation API while trying to show and track the user location.
|
|
553
|
-
* BACKGROUND
|
|
554
|
-
* Showing the user location as a dot but the camera doesn't follow their location as it changes.
|
|
555
|
-
* BACKGROUND_ERROR
|
|
556
|
-
* There was an error from the Geolocation API while trying to show (but not track) the user location.
|
|
557
|
-
*/
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Fired on each Geolocation API position update which returned as success.
|
|
561
|
-
*
|
|
562
|
-
* @event geolocate
|
|
563
|
-
* @memberof GeolocateControl
|
|
564
|
-
* @instance
|
|
565
|
-
* @property {Position} data The returned [Position](https://developer.mozilla.org/en-US/docs/Web/API/Position) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
|
|
566
|
-
* @example
|
|
567
|
-
* // Initialize the geolocate control.
|
|
568
|
-
* var geolocate = new maplibregl.GeolocateControl({
|
|
569
|
-
* positionOptions: {
|
|
570
|
-
* enableHighAccuracy: true
|
|
571
|
-
* },
|
|
572
|
-
* trackUserLocation: true
|
|
573
|
-
* });
|
|
574
|
-
* // Add the control to the map.
|
|
575
|
-
* map.addControl(geolocate);
|
|
576
|
-
* // Set an event listener that fires
|
|
577
|
-
* // when a geolocate event occurs.
|
|
578
|
-
* geolocate.on('geolocate', function() {
|
|
579
|
-
* console.log('A geolocate event has occurred.')
|
|
580
|
-
* });
|
|
581
|
-
*
|
|
582
|
-
*/
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Fired on each Geolocation API position update which returned as an error.
|
|
586
|
-
*
|
|
587
|
-
* @event error
|
|
588
|
-
* @memberof GeolocateControl
|
|
589
|
-
* @instance
|
|
590
|
-
* @property {PositionError} data The returned [PositionError](https://developer.mozilla.org/en-US/docs/Web/API/PositionError) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
|
|
591
|
-
* @example
|
|
592
|
-
* // Initialize the geolocate control.
|
|
593
|
-
* var geolocate = new maplibregl.GeolocateControl({
|
|
594
|
-
* positionOptions: {
|
|
595
|
-
* enableHighAccuracy: true
|
|
596
|
-
* },
|
|
597
|
-
* trackUserLocation: true
|
|
598
|
-
* });
|
|
599
|
-
* // Add the control to the map.
|
|
600
|
-
* map.addControl(geolocate);
|
|
601
|
-
* // Set an event listener that fires
|
|
602
|
-
* // when an error event occurs.
|
|
603
|
-
* geolocate.on('error', function() {
|
|
604
|
-
* console.log('An error event has occurred.')
|
|
605
|
-
* });
|
|
606
|
-
*
|
|
607
|
-
*/
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Fired on each Geolocation API position update which returned as success but user position is out of map maxBounds.
|
|
611
|
-
*
|
|
612
|
-
* @event outofmaxbounds
|
|
613
|
-
* @memberof GeolocateControl
|
|
614
|
-
* @instance
|
|
615
|
-
* @property {Position} data The returned [Position](https://developer.mozilla.org/en-US/docs/Web/API/Position) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
|
|
616
|
-
* @example
|
|
617
|
-
* // Initialize the geolocate control.
|
|
618
|
-
* var geolocate = new maplibregl.GeolocateControl({
|
|
619
|
-
* positionOptions: {
|
|
620
|
-
* enableHighAccuracy: true
|
|
621
|
-
* },
|
|
622
|
-
* trackUserLocation: true
|
|
623
|
-
* });
|
|
624
|
-
* // Add the control to the map.
|
|
625
|
-
* map.addControl(geolocate);
|
|
626
|
-
* // Set an event listener that fires
|
|
627
|
-
* // when an outofmaxbounds event occurs.
|
|
628
|
-
* geolocate.on('outofmaxbounds', function() {
|
|
629
|
-
* console.log('An outofmaxbounds event has occurred.')
|
|
630
|
-
* });
|
|
631
|
-
*
|
|
632
|
-
*/
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* Fired when the Geolocate Control changes to the active lock state, which happens either upon first obtaining a successful Geolocation API position for the user (a geolocate event will follow), or the user clicks the geolocate button when in the background state which uses the last known position to recenter the map and enter active lock state (no geolocate event will follow unless the users's location changes).
|
|
636
|
-
*
|
|
637
|
-
* @event trackuserlocationstart
|
|
638
|
-
* @memberof GeolocateControl
|
|
639
|
-
* @instance
|
|
640
|
-
* @example
|
|
641
|
-
* // Initialize the geolocate control.
|
|
642
|
-
* var geolocate = new maplibregl.GeolocateControl({
|
|
643
|
-
* positionOptions: {
|
|
644
|
-
* enableHighAccuracy: true
|
|
645
|
-
* },
|
|
646
|
-
* trackUserLocation: true
|
|
647
|
-
* });
|
|
648
|
-
* // Add the control to the map.
|
|
649
|
-
* map.addControl(geolocate);
|
|
650
|
-
* // Set an event listener that fires
|
|
651
|
-
* // when a trackuserlocationstart event occurs.
|
|
652
|
-
* geolocate.on('trackuserlocationstart', function() {
|
|
653
|
-
* console.log('A trackuserlocationstart event has occurred.')
|
|
654
|
-
* });
|
|
655
|
-
*
|
|
656
|
-
*/
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Fired when the Geolocate Control changes to the background state, which happens when a user changes the camera during an active position lock. This only applies when trackUserLocation is true. In the background state, the dot on the map will update with location updates but the camera will not.
|
|
660
|
-
*
|
|
661
|
-
* @event trackuserlocationend
|
|
662
|
-
* @memberof GeolocateControl
|
|
663
|
-
* @instance
|
|
664
|
-
* @example
|
|
665
|
-
* // Initialize the geolocate control.
|
|
666
|
-
* var geolocate = new maplibregl.GeolocateControl({
|
|
667
|
-
* positionOptions: {
|
|
668
|
-
* enableHighAccuracy: true
|
|
669
|
-
* },
|
|
670
|
-
* trackUserLocation: true
|
|
671
|
-
* });
|
|
672
|
-
* // Add the control to the map.
|
|
673
|
-
* map.addControl(geolocate);
|
|
674
|
-
* // Set an event listener that fires
|
|
675
|
-
* // when a trackuserlocationend event occurs.
|
|
676
|
-
* geolocate.on('trackuserlocationend', function() {
|
|
677
|
-
* console.log('A trackuserlocationend event has occurred.')
|
|
678
|
-
* });
|
|
679
|
-
*
|
|
680
|
-
*/
|
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
import DOM from '../../util/dom';
|
|
2
|
-
import {bindAll} from '../../util/util';
|
|
1
|
+
import {DOM} from '../../util/dom';
|
|
3
2
|
|
|
4
|
-
import type Map from '../map';
|
|
3
|
+
import type {Map} from '../map';
|
|
5
4
|
import type {ControlPosition, IControl} from './control';
|
|
6
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The {@link LogoControl} options object
|
|
8
|
+
*/
|
|
7
9
|
type LogoOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* If `true`, force a compact logo.
|
|
12
|
+
* If `false`, force the full logo. The default is a responsive logo that collapses when the map is less than 640 pixels wide.
|
|
13
|
+
*/
|
|
8
14
|
compact?: boolean;
|
|
9
15
|
};
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
18
|
* A `LogoControl` is a control that adds the watermark.
|
|
13
19
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
20
|
+
* @group Markers and Controls
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* map.addControl(new maplibregl.LogoControl({compact: false}));
|
|
25
|
+
* ```
|
|
17
26
|
**/
|
|
18
|
-
|
|
19
|
-
class LogoControl implements IControl {
|
|
27
|
+
export class LogoControl implements IControl {
|
|
20
28
|
options: LogoOptions;
|
|
21
29
|
_map: Map;
|
|
22
30
|
_compact: boolean;
|
|
@@ -24,16 +32,13 @@ class LogoControl implements IControl {
|
|
|
24
32
|
|
|
25
33
|
constructor(options: LogoOptions = {}) {
|
|
26
34
|
this.options = options;
|
|
27
|
-
|
|
28
|
-
bindAll([
|
|
29
|
-
'_updateCompact'
|
|
30
|
-
], this);
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
getDefaultPosition(): ControlPosition {
|
|
34
38
|
return 'bottom-left';
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
/** {@inheritDoc IControl.onAdd} */
|
|
37
42
|
onAdd(map: Map) {
|
|
38
43
|
this._map = map;
|
|
39
44
|
this._compact = this.options && this.options.compact;
|
|
@@ -53,6 +58,7 @@ class LogoControl implements IControl {
|
|
|
53
58
|
return this._container;
|
|
54
59
|
}
|
|
55
60
|
|
|
61
|
+
/** {@inheritDoc IControl.onRemove} */
|
|
56
62
|
onRemove() {
|
|
57
63
|
DOM.remove(this._container);
|
|
58
64
|
this._map.off('resize', this._updateCompact);
|
|
@@ -60,7 +66,7 @@ class LogoControl implements IControl {
|
|
|
60
66
|
this._compact = undefined;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
_updateCompact() {
|
|
69
|
+
_updateCompact = () => {
|
|
64
70
|
const containerChildren = this._container.children;
|
|
65
71
|
if (containerChildren.length) {
|
|
66
72
|
const anchor = containerChildren[0];
|
|
@@ -72,8 +78,6 @@ class LogoControl implements IControl {
|
|
|
72
78
|
anchor.classList.remove('maplibregl-compact');
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
|
-
}
|
|
81
|
+
};
|
|
76
82
|
|
|
77
83
|
}
|
|
78
|
-
|
|
79
|
-
export default LogoControl;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import simulate from '../../../test/unit/lib/simulate_interaction';
|
|
2
2
|
import {createMap as globalCreateMap, beforeMapTest} from '../../util/test/util';
|
|
3
|
-
import NavigationControl from './navigation_control';
|
|
3
|
+
import {NavigationControl} from './navigation_control';
|
|
4
4
|
|
|
5
5
|
function createMap() {
|
|
6
6
|
return globalCreateMap({});
|