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/popup.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {extend
|
|
1
|
+
import {extend} from '../util/util';
|
|
2
2
|
import {Event, Evented} from '../util/evented';
|
|
3
3
|
import {MapMouseEvent} from '../ui/events';
|
|
4
|
-
import DOM from '../util/dom';
|
|
5
|
-
import LngLat from '../geo/lng_lat';
|
|
4
|
+
import {DOM} from '../util/dom';
|
|
5
|
+
import {LngLat} from '../geo/lng_lat';
|
|
6
6
|
import Point from '@mapbox/point-geometry';
|
|
7
|
-
import smartWrap from '../util/smart_wrap';
|
|
7
|
+
import {smartWrap} from '../util/smart_wrap';
|
|
8
8
|
import {anchorTranslate, applyAnchorClass} from './anchor';
|
|
9
9
|
|
|
10
10
|
import type {PositionAnchor} from './anchor';
|
|
11
|
-
import type Map from './map';
|
|
11
|
+
import type {Map} from './map';
|
|
12
12
|
import type {LngLatLike} from '../geo/lng_lat';
|
|
13
13
|
import type {PointLike} from './camera';
|
|
14
14
|
|
|
@@ -20,18 +20,61 @@ const defaultOptions = {
|
|
|
20
20
|
maxWidth: '240px'
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* A pixel offset specified as:
|
|
25
|
+
* - a single number specifying a distance from the location
|
|
26
|
+
* - a {@link PointLike} specifying a constant offset
|
|
27
|
+
* - an object of {@link Point}s specifying an offset for each anchor position
|
|
28
|
+
* Negative offsets indicate left and up.
|
|
29
|
+
*/
|
|
23
30
|
export type Offset = number | PointLike | {
|
|
24
31
|
[_ in PositionAnchor]: PointLike;
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
export type PopupOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* If `true`, a close button will appear in the top right corner of the popup.
|
|
37
|
+
* @defaultValue true
|
|
38
|
+
*/
|
|
28
39
|
closeButton?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* If `true`, the popup will closed when the map is clicked.
|
|
42
|
+
* @defaultValue true
|
|
43
|
+
*/
|
|
29
44
|
closeOnClick?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* If `true`, the popup will closed when the map moves.
|
|
47
|
+
* @defaultValue false
|
|
48
|
+
*/
|
|
30
49
|
closeOnMove?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* If `true`, the popup will try to focus the first focusable element inside the popup.
|
|
52
|
+
* @defaultValue true
|
|
53
|
+
*/
|
|
31
54
|
focusAfterOpen?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* A string indicating the part of the Popup that should
|
|
57
|
+
* be positioned closest to the coordinate set via {@link Popup#setLngLat}.
|
|
58
|
+
* Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
|
|
59
|
+
* `'top-right'`, `'bottom-left'`, and `'bottom-right'`. If unset the anchor will be
|
|
60
|
+
* dynamically set to ensure the popup falls within the map container with a preference
|
|
61
|
+
* for `'bottom'`.
|
|
62
|
+
*/
|
|
32
63
|
anchor?: PositionAnchor;
|
|
64
|
+
/**
|
|
65
|
+
* A pixel offset applied to the popup's location
|
|
66
|
+
*/
|
|
33
67
|
offset?: Offset;
|
|
68
|
+
/**
|
|
69
|
+
* Space-separated CSS class names to add to popup container
|
|
70
|
+
*/
|
|
34
71
|
className?: string;
|
|
72
|
+
/**
|
|
73
|
+
* A string that sets the CSS property of the popup's maximum width, eg `'300px'`.
|
|
74
|
+
* To ensure the popup resizes to fit its content, set this property to `'none'`.
|
|
75
|
+
* Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
|
|
76
|
+
* @defaultValue '240px'
|
|
77
|
+
*/
|
|
35
78
|
maxWidth?: string;
|
|
36
79
|
};
|
|
37
80
|
|
|
@@ -48,35 +91,35 @@ const focusQuerySelector = [
|
|
|
48
91
|
/**
|
|
49
92
|
* A popup component.
|
|
50
93
|
*
|
|
51
|
-
* @
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* for `'bottom'`.
|
|
66
|
-
* @param {number|PointLike|Object} [options.offset] -
|
|
67
|
-
* A pixel offset applied to the popup's location specified as:
|
|
68
|
-
* - a single number specifying a distance from the popup's location
|
|
69
|
-
* - a {@link PointLike} specifying a constant offset
|
|
70
|
-
* - an object of {@link Point}s specifying an offset for each anchor position
|
|
71
|
-
* Negative offsets indicate left and up.
|
|
72
|
-
* @param {string} [options.className] Space-separated CSS class names to add to popup container
|
|
73
|
-
* @param {string} [options.maxWidth='240px'] -
|
|
74
|
-
* A string that sets the CSS property of the popup's maximum width, eg `'300px'`.
|
|
75
|
-
* To ensure the popup resizes to fit its content, set this property to `'none'`.
|
|
76
|
-
* Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
|
|
94
|
+
* @group Markers and Controls
|
|
95
|
+
*
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* Create a popup
|
|
99
|
+
* ```ts
|
|
100
|
+
* let popup = new maplibregl.Popup();
|
|
101
|
+
* // Set an event listener that will fire
|
|
102
|
+
* // any time the popup is opened
|
|
103
|
+
* popup.on('open', function(){
|
|
104
|
+
* console.log('popup was opened');
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
77
108
|
* @example
|
|
78
|
-
*
|
|
79
|
-
*
|
|
109
|
+
* Create a popup
|
|
110
|
+
* ```ts
|
|
111
|
+
* let popup = new maplibregl.Popup();
|
|
112
|
+
* // Set an event listener that will fire
|
|
113
|
+
* // any time the popup is closed
|
|
114
|
+
* popup.on('close', function(){
|
|
115
|
+
* console.log('popup was closed');
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* let markerHeight = 50, markerRadius = 10, linearOffset = 25;
|
|
122
|
+
* let popupOffsets = {
|
|
80
123
|
* 'top': [0, 0],
|
|
81
124
|
* 'top-left': [0,0],
|
|
82
125
|
* 'top-right': [0,0],
|
|
@@ -86,17 +129,24 @@ const focusQuerySelector = [
|
|
|
86
129
|
* 'left': [markerRadius, (markerHeight - markerRadius) * -1],
|
|
87
130
|
* 'right': [-markerRadius, (markerHeight - markerRadius) * -1]
|
|
88
131
|
* };
|
|
89
|
-
*
|
|
132
|
+
* let popup = new maplibregl.Popup({offset: popupOffsets, className: 'my-class'})
|
|
90
133
|
* .setLngLat(e.lngLat)
|
|
91
134
|
* .setHTML("<h1>Hello World!</h1>")
|
|
92
135
|
* .setMaxWidth("300px")
|
|
93
136
|
* .addTo(map);
|
|
94
|
-
*
|
|
95
|
-
* @see [Display a popup
|
|
96
|
-
* @see [Display a popup on
|
|
97
|
-
* @see [
|
|
137
|
+
* ```
|
|
138
|
+
* @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
|
|
139
|
+
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
|
|
140
|
+
* @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
|
|
141
|
+
* @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js/docs/examples/set-popup/)
|
|
142
|
+
*
|
|
143
|
+
* ### Events
|
|
144
|
+
*
|
|
145
|
+
* @event `open` Fired when the popup is opened manually or programmatically. `popup` object that was opened
|
|
146
|
+
*
|
|
147
|
+
* @event `close` Fired when the popup is closed manually or programmatically. `popup` object that was closed
|
|
98
148
|
*/
|
|
99
|
-
export
|
|
149
|
+
export class Popup extends Evented {
|
|
100
150
|
_map: Map;
|
|
101
151
|
options: PopupOptions;
|
|
102
152
|
_content: HTMLElement;
|
|
@@ -110,25 +160,26 @@ export default class Popup extends Evented {
|
|
|
110
160
|
constructor(options?: PopupOptions) {
|
|
111
161
|
super();
|
|
112
162
|
this.options = extend(Object.create(defaultOptions), options);
|
|
113
|
-
bindAll(['_update', '_onClose', 'remove', '_onMouseMove', '_onMouseUp', '_onDrag'], this);
|
|
114
163
|
}
|
|
115
164
|
|
|
116
165
|
/**
|
|
117
166
|
* Adds the popup to a map.
|
|
118
167
|
*
|
|
119
|
-
* @param
|
|
120
|
-
* @returns
|
|
168
|
+
* @param map - The MapLibre GL JS map to add the popup to.
|
|
169
|
+
* @returns `this`
|
|
121
170
|
* @example
|
|
171
|
+
* ```ts
|
|
122
172
|
* new maplibregl.Popup()
|
|
123
173
|
* .setLngLat([0, 0])
|
|
124
174
|
* .setHTML("<h1>Null Island</h1>")
|
|
125
175
|
* .addTo(map);
|
|
126
|
-
*
|
|
127
|
-
* @see [Display a popup
|
|
128
|
-
* @see [Display a popup on
|
|
129
|
-
* @see [
|
|
176
|
+
* ```
|
|
177
|
+
* @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
|
|
178
|
+
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
|
|
179
|
+
* @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
|
|
180
|
+
* @see [Show polygon information on click](https://maplibre.org/maplibre-gl-js/docs/examples/polygon-popup-on-click/)
|
|
130
181
|
*/
|
|
131
|
-
addTo(map: Map) {
|
|
182
|
+
addTo(map: Map): this {
|
|
132
183
|
if (this._map) this.remove();
|
|
133
184
|
|
|
134
185
|
this._map = map;
|
|
@@ -155,32 +206,13 @@ export default class Popup extends Evented {
|
|
|
155
206
|
this._map.on('move', this._update);
|
|
156
207
|
}
|
|
157
208
|
|
|
158
|
-
/**
|
|
159
|
-
* Fired when the popup is opened manually or programmatically.
|
|
160
|
-
*
|
|
161
|
-
* @event open
|
|
162
|
-
* @memberof Popup
|
|
163
|
-
* @instance
|
|
164
|
-
* @type {Object}
|
|
165
|
-
* @property {Popup} popup object that was opened
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* // Create a popup
|
|
169
|
-
* var popup = new maplibregl.Popup();
|
|
170
|
-
* // Set an event listener that will fire
|
|
171
|
-
* // any time the popup is opened
|
|
172
|
-
* popup.on('open', function(){
|
|
173
|
-
* console.log('popup was opened');
|
|
174
|
-
* });
|
|
175
|
-
*
|
|
176
|
-
*/
|
|
177
209
|
this.fire(new Event('open'));
|
|
178
210
|
|
|
179
211
|
return this;
|
|
180
212
|
}
|
|
181
213
|
|
|
182
214
|
/**
|
|
183
|
-
* @returns
|
|
215
|
+
* @returns `true` if the popup is open, `false` if it is closed.
|
|
184
216
|
*/
|
|
185
217
|
isOpen() {
|
|
186
218
|
return !!this._map;
|
|
@@ -190,11 +222,13 @@ export default class Popup extends Evented {
|
|
|
190
222
|
* Removes the popup from the map it has been added to.
|
|
191
223
|
*
|
|
192
224
|
* @example
|
|
193
|
-
*
|
|
225
|
+
* ```ts
|
|
226
|
+
* let popup = new maplibregl.Popup().addTo(map);
|
|
194
227
|
* popup.remove();
|
|
195
|
-
*
|
|
228
|
+
* ```
|
|
229
|
+
* @returns `this`
|
|
196
230
|
*/
|
|
197
|
-
remove() {
|
|
231
|
+
remove = (): this => {
|
|
198
232
|
if (this._content) {
|
|
199
233
|
DOM.remove(this._content);
|
|
200
234
|
}
|
|
@@ -215,29 +249,10 @@ export default class Popup extends Evented {
|
|
|
215
249
|
delete this._map;
|
|
216
250
|
}
|
|
217
251
|
|
|
218
|
-
/**
|
|
219
|
-
* Fired when the popup is closed manually or programmatically.
|
|
220
|
-
*
|
|
221
|
-
* @event close
|
|
222
|
-
* @memberof Popup
|
|
223
|
-
* @instance
|
|
224
|
-
* @type {Object}
|
|
225
|
-
* @property {Popup} popup object that was closed
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* // Create a popup
|
|
229
|
-
* var popup = new maplibregl.Popup();
|
|
230
|
-
* // Set an event listener that will fire
|
|
231
|
-
* // any time the popup is closed
|
|
232
|
-
* popup.on('close', function(){
|
|
233
|
-
* console.log('popup was closed');
|
|
234
|
-
* });
|
|
235
|
-
*
|
|
236
|
-
*/
|
|
237
252
|
this.fire(new Event('close'));
|
|
238
253
|
|
|
239
254
|
return this;
|
|
240
|
-
}
|
|
255
|
+
};
|
|
241
256
|
|
|
242
257
|
/**
|
|
243
258
|
* Returns the geographical location of the popup's anchor.
|
|
@@ -246,19 +261,19 @@ export default class Popup extends Evented {
|
|
|
246
261
|
* set by `setLngLat` because `Popup` wraps the anchor longitude across copies of the world to keep
|
|
247
262
|
* the popup on screen.
|
|
248
263
|
*
|
|
249
|
-
* @returns
|
|
264
|
+
* @returns The geographical location of the popup's anchor.
|
|
250
265
|
*/
|
|
251
|
-
getLngLat() {
|
|
266
|
+
getLngLat(): LngLat {
|
|
252
267
|
return this._lngLat;
|
|
253
268
|
}
|
|
254
269
|
|
|
255
270
|
/**
|
|
256
271
|
* Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior.
|
|
257
272
|
*
|
|
258
|
-
* @param lnglat The geographical location to set as the popup's anchor.
|
|
259
|
-
* @returns
|
|
273
|
+
* @param lnglat - The geographical location to set as the popup's anchor.
|
|
274
|
+
* @returns `this`
|
|
260
275
|
*/
|
|
261
|
-
setLngLat(lnglat: LngLatLike) {
|
|
276
|
+
setLngLat(lnglat: LngLatLike): this {
|
|
262
277
|
this._lngLat = LngLat.convert(lnglat);
|
|
263
278
|
this._pos = null;
|
|
264
279
|
|
|
@@ -282,13 +297,15 @@ export default class Popup extends Evented {
|
|
|
282
297
|
* Tracks the popup anchor to the cursor position on screens with a pointer device (it will be hidden on touchscreens). Replaces the `setLngLat` behavior.
|
|
283
298
|
* For most use cases, set `closeOnClick` and `closeButton` to `false`.
|
|
284
299
|
* @example
|
|
285
|
-
*
|
|
300
|
+
* ```ts
|
|
301
|
+
* let popup = new maplibregl.Popup({ closeOnClick: false, closeButton: false })
|
|
286
302
|
* .setHTML("<h1>Hello World!</h1>")
|
|
287
303
|
* .trackPointer()
|
|
288
304
|
* .addTo(map);
|
|
289
|
-
*
|
|
305
|
+
* ```
|
|
306
|
+
* @returns `this`
|
|
290
307
|
*/
|
|
291
|
-
trackPointer() {
|
|
308
|
+
trackPointer(): this {
|
|
292
309
|
this._trackPointer = true;
|
|
293
310
|
this._pos = null;
|
|
294
311
|
this._update();
|
|
@@ -309,16 +326,18 @@ export default class Popup extends Evented {
|
|
|
309
326
|
/**
|
|
310
327
|
* Returns the `Popup`'s HTML element.
|
|
311
328
|
* @example
|
|
312
|
-
*
|
|
313
|
-
*
|
|
329
|
+
* Change the `Popup` element's font size
|
|
330
|
+
* ```ts
|
|
331
|
+
* let popup = new maplibregl.Popup()
|
|
314
332
|
* .setLngLat([-96, 37.8])
|
|
315
333
|
* .setHTML("<p>Hello World!</p>")
|
|
316
334
|
* .addTo(map);
|
|
317
|
-
*
|
|
335
|
+
* let popupElem = popup.getElement();
|
|
318
336
|
* popupElem.style.fontSize = "25px";
|
|
319
|
-
*
|
|
337
|
+
* ```
|
|
338
|
+
* @returns element
|
|
320
339
|
*/
|
|
321
|
-
getElement() {
|
|
340
|
+
getElement(): HTMLElement {
|
|
322
341
|
return this._container;
|
|
323
342
|
}
|
|
324
343
|
|
|
@@ -329,15 +348,17 @@ export default class Popup extends Evented {
|
|
|
329
348
|
* so it cannot insert raw HTML. Use this method for security against XSS
|
|
330
349
|
* if the popup content is user-provided.
|
|
331
350
|
*
|
|
332
|
-
* @param text Textual content for the popup.
|
|
333
|
-
* @returns
|
|
351
|
+
* @param text - Textual content for the popup.
|
|
352
|
+
* @returns `this`
|
|
334
353
|
* @example
|
|
335
|
-
*
|
|
354
|
+
* ```ts
|
|
355
|
+
* let popup = new maplibregl.Popup()
|
|
336
356
|
* .setLngLat(e.lngLat)
|
|
337
357
|
* .setText('Hello, world!')
|
|
338
358
|
* .addTo(map);
|
|
359
|
+
* ```
|
|
339
360
|
*/
|
|
340
|
-
setText(text: string) {
|
|
361
|
+
setText(text: string): this {
|
|
341
362
|
return this.setDOMContent(document.createTextNode(text));
|
|
342
363
|
}
|
|
343
364
|
|
|
@@ -348,19 +369,21 @@ export default class Popup extends Evented {
|
|
|
348
369
|
* used only with trusted content. Consider {@link Popup#setText} if
|
|
349
370
|
* the content is an untrusted text string.
|
|
350
371
|
*
|
|
351
|
-
* @param html A string representing HTML content for the popup.
|
|
352
|
-
* @returns
|
|
372
|
+
* @param html - A string representing HTML content for the popup.
|
|
373
|
+
* @returns `this`
|
|
353
374
|
* @example
|
|
354
|
-
*
|
|
375
|
+
* ```ts
|
|
376
|
+
* let popup = new maplibregl.Popup()
|
|
355
377
|
* .setLngLat(e.lngLat)
|
|
356
378
|
* .setHTML("<h1>Hello World!</h1>")
|
|
357
379
|
* .addTo(map);
|
|
358
|
-
*
|
|
359
|
-
* @see [Display a popup
|
|
360
|
-
* @see [Display a popup on
|
|
361
|
-
* @see [
|
|
380
|
+
* ```
|
|
381
|
+
* @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
|
|
382
|
+
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
|
|
383
|
+
* @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
|
|
384
|
+
* @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js/docs/examples/set-popup/)
|
|
362
385
|
*/
|
|
363
|
-
setHTML(html: string) {
|
|
386
|
+
setHTML(html: string): this {
|
|
364
387
|
const frag = document.createDocumentFragment();
|
|
365
388
|
const temp = document.createElement('body');
|
|
366
389
|
let child;
|
|
@@ -377,20 +400,20 @@ export default class Popup extends Evented {
|
|
|
377
400
|
/**
|
|
378
401
|
* Returns the popup's maximum width.
|
|
379
402
|
*
|
|
380
|
-
* @returns
|
|
403
|
+
* @returns The maximum width of the popup.
|
|
381
404
|
*/
|
|
382
|
-
getMaxWidth() {
|
|
383
|
-
return this._container
|
|
405
|
+
getMaxWidth(): string {
|
|
406
|
+
return this._container?.style.maxWidth;
|
|
384
407
|
}
|
|
385
408
|
|
|
386
409
|
/**
|
|
387
410
|
* Sets the popup's maximum width. This is setting the CSS property `max-width`.
|
|
388
411
|
* Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
|
|
389
412
|
*
|
|
390
|
-
* @param maxWidth A string representing the value for the maximum width.
|
|
391
|
-
* @returns
|
|
413
|
+
* @param maxWidth - A string representing the value for the maximum width.
|
|
414
|
+
* @returns `this`
|
|
392
415
|
*/
|
|
393
|
-
setMaxWidth(maxWidth: string) {
|
|
416
|
+
setMaxWidth(maxWidth: string): this {
|
|
394
417
|
this.options.maxWidth = maxWidth;
|
|
395
418
|
this._update();
|
|
396
419
|
return this;
|
|
@@ -399,18 +422,20 @@ export default class Popup extends Evented {
|
|
|
399
422
|
/**
|
|
400
423
|
* Sets the popup's content to the element provided as a DOM node.
|
|
401
424
|
*
|
|
402
|
-
* @param htmlNode A DOM node to be used as content for the popup.
|
|
403
|
-
* @returns
|
|
425
|
+
* @param htmlNode - A DOM node to be used as content for the popup.
|
|
426
|
+
* @returns `this`
|
|
404
427
|
* @example
|
|
405
|
-
*
|
|
406
|
-
*
|
|
428
|
+
* Create an element with the popup content
|
|
429
|
+
* ```ts
|
|
430
|
+
* let div = document.createElement('div');
|
|
407
431
|
* div.innerHTML = 'Hello, world!';
|
|
408
|
-
*
|
|
432
|
+
* let popup = new maplibregl.Popup()
|
|
409
433
|
* .setLngLat(e.lngLat)
|
|
410
434
|
* .setDOMContent(div)
|
|
411
435
|
* .addTo(map);
|
|
436
|
+
* ```
|
|
412
437
|
*/
|
|
413
|
-
setDOMContent(htmlNode: Node) {
|
|
438
|
+
setDOMContent(htmlNode: Node): this {
|
|
414
439
|
if (this._content) {
|
|
415
440
|
// Clear out children first.
|
|
416
441
|
while (this._content.hasChildNodes()) {
|
|
@@ -433,11 +458,13 @@ export default class Popup extends Evented {
|
|
|
433
458
|
/**
|
|
434
459
|
* Adds a CSS class to the popup container element.
|
|
435
460
|
*
|
|
436
|
-
* @param
|
|
461
|
+
* @param className - Non-empty string with CSS class name to add to popup container
|
|
437
462
|
*
|
|
438
463
|
* @example
|
|
464
|
+
* ```ts
|
|
439
465
|
* let popup = new maplibregl.Popup()
|
|
440
466
|
* popup.addClassName('some-class')
|
|
467
|
+
* ```
|
|
441
468
|
*/
|
|
442
469
|
addClassName(className: string) {
|
|
443
470
|
if (this._container) {
|
|
@@ -448,11 +475,13 @@ export default class Popup extends Evented {
|
|
|
448
475
|
/**
|
|
449
476
|
* Removes a CSS class from the popup container element.
|
|
450
477
|
*
|
|
451
|
-
* @param
|
|
478
|
+
* @param className - Non-empty string with CSS class name to remove from popup container
|
|
452
479
|
*
|
|
453
480
|
* @example
|
|
481
|
+
* ```ts
|
|
454
482
|
* let popup = new maplibregl.Popup()
|
|
455
483
|
* popup.removeClassName('some-class')
|
|
484
|
+
* ```
|
|
456
485
|
*/
|
|
457
486
|
removeClassName(className: string) {
|
|
458
487
|
if (this._container) {
|
|
@@ -463,10 +492,10 @@ export default class Popup extends Evented {
|
|
|
463
492
|
/**
|
|
464
493
|
* Sets the popup's offset.
|
|
465
494
|
*
|
|
466
|
-
* @param offset Sets the popup's offset.
|
|
467
|
-
* @returns
|
|
495
|
+
* @param offset - Sets the popup's offset.
|
|
496
|
+
* @returns `this`
|
|
468
497
|
*/
|
|
469
|
-
setOffset (offset?: Offset) {
|
|
498
|
+
setOffset (offset?: Offset): this {
|
|
470
499
|
this.options.offset = offset;
|
|
471
500
|
this._update();
|
|
472
501
|
return this;
|
|
@@ -475,15 +504,17 @@ export default class Popup extends Evented {
|
|
|
475
504
|
/**
|
|
476
505
|
* Add or remove the given CSS class on the popup container, depending on whether the container currently has that class.
|
|
477
506
|
*
|
|
478
|
-
* @param
|
|
507
|
+
* @param className - Non-empty string with CSS class name to add/remove
|
|
479
508
|
*
|
|
480
|
-
* @returns
|
|
509
|
+
* @returns if the class was removed return false, if class was added, then return true, undefined if there is no container
|
|
481
510
|
*
|
|
482
511
|
* @example
|
|
512
|
+
* ```ts
|
|
483
513
|
* let popup = new maplibregl.Popup()
|
|
484
514
|
* popup.toggleClassName('toggleClass')
|
|
515
|
+
* ```
|
|
485
516
|
*/
|
|
486
|
-
toggleClassName(className: string) {
|
|
517
|
+
toggleClassName(className: string): boolean | undefined {
|
|
487
518
|
if (this._container) {
|
|
488
519
|
return this._container.classList.toggle(className);
|
|
489
520
|
}
|
|
@@ -499,19 +530,19 @@ export default class Popup extends Evented {
|
|
|
499
530
|
}
|
|
500
531
|
}
|
|
501
532
|
|
|
502
|
-
_onMouseUp(event: MapMouseEvent) {
|
|
533
|
+
_onMouseUp = (event: MapMouseEvent) => {
|
|
503
534
|
this._update(event.point);
|
|
504
|
-
}
|
|
535
|
+
};
|
|
505
536
|
|
|
506
|
-
_onMouseMove(event: MapMouseEvent) {
|
|
537
|
+
_onMouseMove = (event: MapMouseEvent) => {
|
|
507
538
|
this._update(event.point);
|
|
508
|
-
}
|
|
539
|
+
};
|
|
509
540
|
|
|
510
|
-
_onDrag(event: MapMouseEvent) {
|
|
541
|
+
_onDrag = (event: MapMouseEvent) => {
|
|
511
542
|
this._update(event.point);
|
|
512
|
-
}
|
|
543
|
+
};
|
|
513
544
|
|
|
514
|
-
_update(cursor?: Point) {
|
|
545
|
+
_update = (cursor?: Point) => {
|
|
515
546
|
const hasPosition = this._lngLat || this._trackPointer;
|
|
516
547
|
|
|
517
548
|
if (!this._map || !hasPosition || !this._content) { return; }
|
|
@@ -521,8 +552,9 @@ export default class Popup extends Evented {
|
|
|
521
552
|
this._tip = DOM.create('div', 'maplibregl-popup-tip', this._container);
|
|
522
553
|
this._container.appendChild(this._content);
|
|
523
554
|
if (this.options.className) {
|
|
524
|
-
this.options.className.split(' ')
|
|
525
|
-
this._container.classList.add(name)
|
|
555
|
+
for (const name of this.options.className.split(' ')) {
|
|
556
|
+
this._container.classList.add(name);
|
|
557
|
+
}
|
|
526
558
|
}
|
|
527
559
|
|
|
528
560
|
if (this._trackPointer) {
|
|
@@ -574,7 +606,7 @@ export default class Popup extends Evented {
|
|
|
574
606
|
const offsetedPos = pos.add(offset[anchor]).round();
|
|
575
607
|
DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`);
|
|
576
608
|
applyAnchorClass(this._container, anchor, 'popup');
|
|
577
|
-
}
|
|
609
|
+
};
|
|
578
610
|
|
|
579
611
|
_focusFirstElement() {
|
|
580
612
|
if (!this.options.focusAfterOpen || !this._container) return;
|
|
@@ -584,9 +616,9 @@ export default class Popup extends Evented {
|
|
|
584
616
|
if (firstFocusable) firstFocusable.focus();
|
|
585
617
|
}
|
|
586
618
|
|
|
587
|
-
_onClose() {
|
|
619
|
+
_onClose = () => {
|
|
588
620
|
this.remove();
|
|
589
|
-
}
|
|
621
|
+
};
|
|
590
622
|
}
|
|
591
623
|
|
|
592
624
|
function normalizeOffset(offset?: Offset | null) {
|
package/src/util/actor.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Actor from './actor';
|
|
2
|
-
import workerFactory from './web_worker';
|
|
1
|
+
import {Actor} from './actor';
|
|
2
|
+
import {workerFactory} from './web_worker';
|
|
3
3
|
import {MessageBus} from '../../test/unit/lib/web_worker_mock';
|
|
4
4
|
|
|
5
5
|
const originalWorker = global.Worker;
|
|
@@ -40,8 +40,8 @@ describe('Actor', () => {
|
|
|
40
40
|
|
|
41
41
|
const worker = workerFactory();
|
|
42
42
|
|
|
43
|
-
const m1 = new Actor(worker, {}, 1);
|
|
44
|
-
const m2 = new Actor(worker, {}, 2);
|
|
43
|
+
const m1 = new Actor(worker, {}, '1');
|
|
44
|
+
const m2 = new Actor(worker, {}, '2');
|
|
45
45
|
|
|
46
46
|
let callbackCount = 0;
|
|
47
47
|
m1.send('test', {value: 1729}, (err, response) => {
|
|
@@ -78,14 +78,14 @@ describe('Actor', () => {
|
|
|
78
78
|
|
|
79
79
|
new Actor(worker, {
|
|
80
80
|
test () { done(); }
|
|
81
|
-
}, 1);
|
|
81
|
+
}, '1');
|
|
82
82
|
new Actor(worker, {
|
|
83
83
|
test () {
|
|
84
84
|
done('test failed');
|
|
85
85
|
}
|
|
86
|
-
}, 2);
|
|
86
|
+
}, '2');
|
|
87
87
|
|
|
88
|
-
workerActor.send('test', {}, () => {}, 1);
|
|
88
|
+
workerActor.send('test', {}, () => {}, '1');
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
test('#remove unbinds event listener', done => {
|