maplibre-gl 3.2.0 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/generate-docs.ts +1 -1
- package/build/generate-struct-arrays.ts +3 -2
- 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 +351 -281
- package/dist/maplibre-gl-dev.js.map +1 -1
- package/dist/maplibre-gl.d.ts +254 -181
- package/dist/maplibre-gl.js +4 -4
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +30 -30
- package/src/data/array_types.g.ts +32 -10
- package/src/data/bucket/circle_bucket.ts +1 -0
- package/src/data/bucket/line_bucket.ts +1 -0
- package/src/data/bucket/symbol_bucket.ts +1 -0
- package/src/data/feature_index.ts +1 -0
- package/src/data/program_configuration.ts +1 -0
- package/src/data/segment.ts +2 -0
- package/src/geo/transform.test.ts +9 -16
- package/src/geo/transform.ts +11 -32
- package/src/gl/context.ts +1 -0
- package/src/gl/framebuffer.ts +1 -0
- package/src/gl/index_buffer.ts +1 -0
- package/src/gl/render_pool.ts +2 -1
- package/src/gl/vertex_buffer.ts +1 -0
- package/src/render/draw_fill.test.ts +1 -1
- package/src/render/draw_symbol.test.ts +3 -3
- package/src/render/image_atlas.ts +1 -0
- package/src/render/line_atlas.ts +1 -0
- package/src/render/painter.ts +1 -1
- package/src/render/program.ts +1 -1
- package/src/render/render_to_texture.ts +31 -14
- package/src/render/terrain.test.ts +17 -0
- package/src/render/terrain.ts +34 -2
- package/src/render/texture.ts +1 -0
- package/src/render/uniform_binding.ts +2 -0
- package/src/render/vertex_array_object.ts +1 -0
- package/src/shaders/symbol_sdf.fragment.glsl +9 -3
- package/src/shaders/symbol_sdf.fragment.glsl.g.ts +1 -1
- package/src/source/canvas_source.ts +1 -3
- package/src/source/geojson_source.ts +1 -3
- package/src/source/image_source.ts +2 -4
- package/src/source/raster_dem_tile_source.test.ts +14 -0
- package/src/source/raster_dem_tile_source.ts +0 -11
- package/src/source/raster_tile_source.test.ts +13 -0
- package/src/source/source_cache.ts +1 -0
- package/src/source/source_state.ts +1 -0
- package/src/source/terrain_source_cache.ts +1 -0
- package/src/source/tile.ts +1 -0
- package/src/source/tile_cache.ts +1 -1
- package/src/source/tile_id.ts +1 -0
- package/src/source/vector_tile_worker_source.test.ts +116 -67
- package/src/source/vector_tile_worker_source.ts +30 -16
- package/src/source/worker_source.ts +1 -0
- package/src/source/worker_tile.test.ts +143 -0
- package/src/source/worker_tile.ts +26 -7
- package/src/style/evaluation_parameters.ts +1 -0
- package/src/style/properties.ts +14 -0
- package/src/style/style.ts +1 -0
- package/src/style/style_glyph.ts +1 -0
- package/src/symbol/collision_index.ts +1 -0
- package/src/symbol/grid_index.ts +1 -0
- package/src/ui/camera.test.ts +12 -9
- package/src/ui/camera.ts +77 -95
- package/src/ui/handler/box_zoom.ts +1 -3
- package/src/ui/handler/click_zoom.ts +1 -3
- package/src/ui/handler/keyboard.ts +1 -3
- package/src/ui/handler/scroll_zoom.ts +1 -3
- package/src/ui/handler/shim/dblclick_zoom.ts +1 -3
- package/src/ui/handler/shim/drag_pan.ts +1 -3
- package/src/ui/handler/shim/drag_rotate.ts +1 -3
- package/src/ui/handler/shim/two_fingers_touch.ts +1 -3
- package/src/ui/handler/transform-provider.ts +1 -0
- package/src/ui/handler/two_fingers_touch.ts +1 -3
- package/src/ui/handler_manager.ts +2 -2
- package/src/ui/hash.ts +1 -2
- package/src/ui/map.test.ts +17 -12
- package/src/ui/map.ts +132 -44
- package/src/ui/map_events.test.ts +76 -0
- package/src/ui/marker.test.ts +1 -1
- package/src/util/ajax.test.ts +33 -0
- package/src/util/ajax.ts +5 -0
- package/src/util/image.ts +1 -0
- package/src/util/image_request.ts +2 -2
- package/src/util/performance.ts +1 -2
- package/src/util/struct_array.ts +5 -1
- package/src/util/test/mock_fetch.ts +51 -0
package/src/ui/map.test.ts
CHANGED
|
@@ -2625,15 +2625,20 @@ describe('Map', () => {
|
|
|
2625
2625
|
});
|
|
2626
2626
|
});
|
|
2627
2627
|
|
|
2628
|
+
describe('cooperativeGestures option', () => {
|
|
2629
|
+
test('cooperativeGesture container element is hidden from a11y tree', () => {
|
|
2630
|
+
const map = createMap({cooperativeGestures: true});
|
|
2631
|
+
|
|
2632
|
+
expect(map.getContainer().querySelector('.maplibregl-cooperative-gesture-screen').getAttribute('aria-hidden')).toBeTruthy();
|
|
2633
|
+
});
|
|
2634
|
+
});
|
|
2635
|
+
|
|
2628
2636
|
describe('getCameraTargetElevation', () => {
|
|
2629
2637
|
test('Elevation is zero without terrain, and matches any given terrain', () => {
|
|
2630
2638
|
const map = createMap();
|
|
2631
2639
|
expect(map.getCameraTargetElevation()).toBe(0);
|
|
2632
2640
|
|
|
2633
|
-
const mockedGetElevation = jest.fn((_tileID: OverscaledTileID, _x: number, _y: number, _extent?: number) => 2000);
|
|
2634
|
-
|
|
2635
2641
|
const terrainStub = {} as Terrain;
|
|
2636
|
-
terrainStub.getElevation = mockedGetElevation;
|
|
2637
2642
|
map.terrain = terrainStub;
|
|
2638
2643
|
|
|
2639
2644
|
const transform = new Transform(0, 22, 0, 60, true);
|
|
@@ -2641,7 +2646,7 @@ describe('Map', () => {
|
|
|
2641
2646
|
transform.center = new LngLat(10.0, 50.0);
|
|
2642
2647
|
transform.zoom = 14;
|
|
2643
2648
|
transform.resize(512, 512);
|
|
2644
|
-
transform.
|
|
2649
|
+
transform.elevation = 2000;
|
|
2645
2650
|
map.transform = transform;
|
|
2646
2651
|
|
|
2647
2652
|
expect(map.getCameraTargetElevation()).toBe(2000);
|
|
@@ -2653,10 +2658,10 @@ describe('Map', () => {
|
|
|
2653
2658
|
test('pitch 90 with terrain', () => {
|
|
2654
2659
|
const map = createMap();
|
|
2655
2660
|
|
|
2656
|
-
const mockedGetElevation = jest.fn((
|
|
2661
|
+
const mockedGetElevation = jest.fn((_lngLat: LngLat, _zoom: number) => 111200);
|
|
2657
2662
|
|
|
2658
2663
|
const terrainStub = {} as Terrain;
|
|
2659
|
-
terrainStub.
|
|
2664
|
+
terrainStub.getElevationForLngLatZoom = mockedGetElevation;
|
|
2660
2665
|
map.terrain = terrainStub;
|
|
2661
2666
|
|
|
2662
2667
|
// distance between lng x and lng x+1 is 111.2km at same lat
|
|
@@ -2670,10 +2675,10 @@ describe('Map', () => {
|
|
|
2670
2675
|
test('pitch 153.435 with terrain', () => {
|
|
2671
2676
|
const map = createMap();
|
|
2672
2677
|
|
|
2673
|
-
const mockedGetElevation = jest.fn((
|
|
2678
|
+
const mockedGetElevation = jest.fn((_lngLat: LngLat, _zoom: number) => 111200 * 3);
|
|
2674
2679
|
|
|
2675
2680
|
const terrainStub = {} as Terrain;
|
|
2676
|
-
terrainStub.
|
|
2681
|
+
terrainStub.getElevationForLngLatZoom = mockedGetElevation;
|
|
2677
2682
|
map.terrain = terrainStub;
|
|
2678
2683
|
// distance between lng x and lng x+1 is 111.2km at same lat
|
|
2679
2684
|
// (elevation difference of cam and center) / 2 = grounddistance =>
|
|
@@ -2687,10 +2692,10 @@ describe('Map', () => {
|
|
|
2687
2692
|
test('pitch 63 with terrain', () => {
|
|
2688
2693
|
const map = createMap();
|
|
2689
2694
|
|
|
2690
|
-
const mockedGetElevation = jest.fn((
|
|
2695
|
+
const mockedGetElevation = jest.fn((_lngLat: LngLat, _zoom: number) => 111200 / 2);
|
|
2691
2696
|
|
|
2692
2697
|
const terrainStub = {} as Terrain;
|
|
2693
|
-
terrainStub.
|
|
2698
|
+
terrainStub.getElevationForLngLatZoom = mockedGetElevation;
|
|
2694
2699
|
map.terrain = terrainStub;
|
|
2695
2700
|
|
|
2696
2701
|
// distance between lng x and lng x+1 is 111.2km at same lat
|
|
@@ -2705,10 +2710,10 @@ describe('Map', () => {
|
|
|
2705
2710
|
test('zoom distance 1000', () => {
|
|
2706
2711
|
const map = createMap();
|
|
2707
2712
|
|
|
2708
|
-
const mockedGetElevation = jest.fn((
|
|
2713
|
+
const mockedGetElevation = jest.fn((_lngLat: LngLat, _zoom: number) => 1000);
|
|
2709
2714
|
|
|
2710
2715
|
const terrainStub = {} as Terrain;
|
|
2711
|
-
terrainStub.
|
|
2716
|
+
terrainStub.getElevationForLngLatZoom = mockedGetElevation;
|
|
2712
2717
|
map.terrain = terrainStub;
|
|
2713
2718
|
|
|
2714
2719
|
const expectedZoom = Math.log2(map.transform.cameraToCenterDistance / mercatorZfromAltitude(1000, 0) / map.transform.tileSize);
|
package/src/ui/map.ts
CHANGED
|
@@ -412,7 +412,7 @@ const defaultOptions = {
|
|
|
412
412
|
fadeDuration: 300,
|
|
413
413
|
crossSourceCollisions: true,
|
|
414
414
|
validateStyle: true,
|
|
415
|
-
/**
|
|
415
|
+
/**Because GL MAX_TEXTURE_SIZE is usually at least 4096px. */
|
|
416
416
|
maxCanvasSize: [4096, 4096]
|
|
417
417
|
} as CompleteMapOptions;
|
|
418
418
|
|
|
@@ -503,7 +503,10 @@ export class Map extends Camera {
|
|
|
503
503
|
_maxCanvasSize: [number, number];
|
|
504
504
|
_terrainDataCallback: (e: MapStyleDataEvent | MapSourceDataEvent) => void;
|
|
505
505
|
|
|
506
|
-
/**
|
|
506
|
+
/**
|
|
507
|
+
* @internal
|
|
508
|
+
* image queue throttling handle. To be used later when clean up
|
|
509
|
+
*/
|
|
507
510
|
_imageQueueHandle: number;
|
|
508
511
|
|
|
509
512
|
/**
|
|
@@ -704,6 +707,7 @@ export class Map extends Camera {
|
|
|
704
707
|
}
|
|
705
708
|
|
|
706
709
|
/**
|
|
710
|
+
* @internal
|
|
707
711
|
* Returns a unique number for this map instance which is used for the MapLoadEvent
|
|
708
712
|
* to make sure we only fire one event per instantiated map object.
|
|
709
713
|
* @returns the uniq map ID
|
|
@@ -715,6 +719,8 @@ export class Map extends Camera {
|
|
|
715
719
|
/**
|
|
716
720
|
* Adds an {@link IControl} to the map, calling `control.onAdd(this)`.
|
|
717
721
|
*
|
|
722
|
+
* An {@link ErrorEvent} will be fired if the image parameter is invald.
|
|
723
|
+
*
|
|
718
724
|
* @param control - The {@link IControl} to add.
|
|
719
725
|
* @param position - position on the map to which the control will be added.
|
|
720
726
|
* Valid values are `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`. Defaults to `'top-right'`.
|
|
@@ -753,6 +759,8 @@ export class Map extends Camera {
|
|
|
753
759
|
/**
|
|
754
760
|
* Removes the control from the map.
|
|
755
761
|
*
|
|
762
|
+
* An {@link ErrorEvent} will be fired if the image parameter is invald.
|
|
763
|
+
*
|
|
756
764
|
* @param control - The {@link IControl} to remove.
|
|
757
765
|
* @returns `this`
|
|
758
766
|
* @example
|
|
@@ -791,13 +799,13 @@ export class Map extends Camera {
|
|
|
791
799
|
* map.hasControl(navigation);
|
|
792
800
|
* ```
|
|
793
801
|
*/
|
|
794
|
-
hasControl(control: IControl) {
|
|
802
|
+
hasControl(control: IControl): boolean {
|
|
795
803
|
return this._controls.indexOf(control) > -1;
|
|
796
804
|
}
|
|
797
805
|
|
|
798
806
|
calculateCameraOptionsFromTo(from: LngLat, altitudeFrom: number, to: LngLat, altitudeTo?: number): CameraOptions {
|
|
799
807
|
if (altitudeTo == null && this.terrain) {
|
|
800
|
-
altitudeTo = this.
|
|
808
|
+
altitudeTo = this.terrain.getElevationForLngLatZoom(to, this.transform.tileZoom);
|
|
801
809
|
}
|
|
802
810
|
return super.calculateCameraOptionsFromTo(from, altitudeFrom, to, altitudeTo);
|
|
803
811
|
}
|
|
@@ -810,6 +818,8 @@ export class Map extends Camera {
|
|
|
810
818
|
* This method must be called after the map's `container` is resized programmatically
|
|
811
819
|
* or when the map is shown after being initially hidden with CSS.
|
|
812
820
|
*
|
|
821
|
+
* Triggers the following events: `movestart`, `move`, `moveend`, and `resize`.
|
|
822
|
+
*
|
|
813
823
|
* @param eventData - Additional properties to be passed to `movestart`, `move`, `resize`, and `moveend`
|
|
814
824
|
* events that get triggered as a result of resize. This can be useful for differentiating the
|
|
815
825
|
* source of an event (for example, user-initiated or programmatically-triggered events).
|
|
@@ -857,7 +867,8 @@ export class Map extends Camera {
|
|
|
857
867
|
return this;
|
|
858
868
|
}
|
|
859
869
|
|
|
860
|
-
|
|
870
|
+
/**
|
|
871
|
+
* @internal
|
|
861
872
|
* Return the map's pixel ratio eventually scaled down to respect maxCanvasSize.
|
|
862
873
|
* Internally you should use this and not getPixelRatio().
|
|
863
874
|
*/
|
|
@@ -958,6 +969,8 @@ export class Map extends Camera {
|
|
|
958
969
|
* if the map is 512px tall it will not be possible to zoom below zoom 0
|
|
959
970
|
* no matter what the `minZoom` is set to.
|
|
960
971
|
*
|
|
972
|
+
* A {@link ErrorEvent} event will be fired if minZoom is out of bounds.
|
|
973
|
+
*
|
|
961
974
|
* @param minZoom - The minimum zoom level to set (-2 - 24).
|
|
962
975
|
* If `null` or `undefined` is provided, the function removes the current minimum zoom (i.e. sets it to -2).
|
|
963
976
|
* @returns `this`
|
|
@@ -997,6 +1010,8 @@ export class Map extends Camera {
|
|
|
997
1010
|
* If the map's current zoom level is higher than the new maximum,
|
|
998
1011
|
* the map will zoom to the new maximum.
|
|
999
1012
|
*
|
|
1013
|
+
* A {@link ErrorEvent} event will be fired if minZoom is out of bounds.
|
|
1014
|
+
*
|
|
1000
1015
|
* @param maxZoom - The maximum zoom level to set.
|
|
1001
1016
|
* If `null` or `undefined` is provided, the function removes the current maximum zoom (sets it to 22).
|
|
1002
1017
|
* @returns `this`
|
|
@@ -1036,6 +1051,8 @@ export class Map extends Camera {
|
|
|
1036
1051
|
* If the map's current pitch is lower than the new minimum,
|
|
1037
1052
|
* the map will pitch to the new minimum.
|
|
1038
1053
|
*
|
|
1054
|
+
* A {@link ErrorEvent} event will be fired if minPitch is out of bounds.
|
|
1055
|
+
*
|
|
1039
1056
|
* @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.
|
|
1040
1057
|
* If `null` or `undefined` is provided, the function removes the current minimum pitch (i.e. sets it to 0).
|
|
1041
1058
|
* @returns `this`
|
|
@@ -1071,6 +1088,8 @@ export class Map extends Camera {
|
|
|
1071
1088
|
* If the map's current pitch is higher than the new maximum,
|
|
1072
1089
|
* the map will pitch to the new maximum.
|
|
1073
1090
|
*
|
|
1091
|
+
* A {@link ErrorEvent} event will be fired if maxPitch is out of bounds.
|
|
1092
|
+
*
|
|
1074
1093
|
* @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.
|
|
1075
1094
|
* If `null` or `undefined` is provided, the function removes the current maximum pitch (sets it to 60).
|
|
1076
1095
|
* @returns `this`
|
|
@@ -1287,6 +1306,7 @@ export class Map extends Camera {
|
|
|
1287
1306
|
}
|
|
1288
1307
|
|
|
1289
1308
|
/**
|
|
1309
|
+
* @event
|
|
1290
1310
|
* Adds a listener for events of a specified type, optionally limited to features in a specified style layer.
|
|
1291
1311
|
* See {@link MapEventType} and {@link MapLayerEventType} for a full list of events and their description.
|
|
1292
1312
|
*
|
|
@@ -1347,8 +1367,8 @@ export class Map extends Camera {
|
|
|
1347
1367
|
* when the cursor enters a visible portion of the specified layer from outside that layer or outside the map canvas.
|
|
1348
1368
|
* @param layer - The ID of a style layer or a listener if no ID is provided. Event will only be triggered if its location
|
|
1349
1369
|
* is within a visible feature in this layer. The event will have a `features` property containing
|
|
1350
|
-
* an array of the matching features. If `
|
|
1351
|
-
* Please note that many event types are not compatible with the optional `
|
|
1370
|
+
* an array of the matching features. If `layer` is not supplied, the event will not have a `features` property.
|
|
1371
|
+
* Please note that many event types are not compatible with the optional `layer` parameter.
|
|
1352
1372
|
* @param listener - The function to be called when the event is fired.
|
|
1353
1373
|
* @returns `this`
|
|
1354
1374
|
* @example
|
|
@@ -1391,20 +1411,27 @@ export class Map extends Camera {
|
|
|
1391
1411
|
* @see [Create a hover effect](https://maplibre.org/maplibre-gl-js/docs/examples/hover-styles/)
|
|
1392
1412
|
* @see [Create a draggable marker](https://maplibre.org/maplibre-gl-js/docs/examples/drag-a-point/)
|
|
1393
1413
|
*/
|
|
1394
|
-
on(type: keyof MapEventType | string, listener: Listener): this;
|
|
1395
1414
|
on<T extends keyof MapLayerEventType>(
|
|
1396
1415
|
type: T,
|
|
1397
1416
|
layer: string,
|
|
1398
1417
|
listener: (ev: MapLayerEventType[T] & Object) => void,
|
|
1399
1418
|
): Map;
|
|
1419
|
+
/**
|
|
1420
|
+
* Overload of the `on` method that allows to listen to events without specifying a layer.
|
|
1421
|
+
* @event
|
|
1422
|
+
* @param type - The type of the event.
|
|
1423
|
+
* @param listener - The listener callback.
|
|
1424
|
+
* @returns `this`
|
|
1425
|
+
*/
|
|
1400
1426
|
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
1401
1427
|
/**
|
|
1402
|
-
*
|
|
1428
|
+
* Overload of the `on` method that allows to listen to events without specifying a layer.
|
|
1429
|
+
* @event
|
|
1403
1430
|
* @param type - The type of the event.
|
|
1404
|
-
* @param layerIdOrListener - The ID of the layer.
|
|
1405
1431
|
* @param listener - The listener callback.
|
|
1406
1432
|
* @returns `this`
|
|
1407
1433
|
*/
|
|
1434
|
+
on(type: keyof MapEventType | string, listener: Listener): this;
|
|
1408
1435
|
on(type: keyof MapEventType | string, layerIdOrListener: string | Listener, listener?: Listener): this {
|
|
1409
1436
|
if (listener === undefined) {
|
|
1410
1437
|
return super.on(type, layerIdOrListener as Listener);
|
|
@@ -1424,8 +1451,9 @@ export class Map extends Camera {
|
|
|
1424
1451
|
}
|
|
1425
1452
|
|
|
1426
1453
|
/**
|
|
1427
|
-
* Adds a listener that will be called only once to a specified event type
|
|
1454
|
+
* Adds a listener that will be called only once to a specified event type, optionally limited to features in a specified style layer.
|
|
1428
1455
|
*
|
|
1456
|
+
* @event
|
|
1429
1457
|
* @param type - The event type to listen for; one of `'mousedown'`, `'mouseup'`, `'click'`, `'dblclick'`,
|
|
1430
1458
|
* `'mousemove'`, `'mouseenter'`, `'mouseleave'`, `'mouseover'`, `'mouseout'`, `'contextmenu'`, `'touchstart'`,
|
|
1431
1459
|
* `'touchend'`, or `'touchcancel'`. `mouseenter` and `mouseover` events are triggered when the cursor enters
|
|
@@ -1438,13 +1466,27 @@ export class Map extends Camera {
|
|
|
1438
1466
|
* @param listener - The function to be called when the event is fired.
|
|
1439
1467
|
* @returns `this` if listener is provided, promise otherwise to allow easier usage of async/await
|
|
1440
1468
|
*/
|
|
1441
|
-
once(type: keyof MapEventType | string, listener?: Listener): this | Promise<any>;
|
|
1442
1469
|
once<T extends keyof MapLayerEventType>(
|
|
1443
1470
|
type: T,
|
|
1444
1471
|
layer: string,
|
|
1445
1472
|
listener?: (ev: MapLayerEventType[T] & Object) => void,
|
|
1446
1473
|
): this | Promise<MapLayerEventType[T] & Object>;
|
|
1474
|
+
/**
|
|
1475
|
+
* Overload of the `once` method that allows to listen to events without specifying a layer.
|
|
1476
|
+
* @event
|
|
1477
|
+
* @param type - The type of the event.
|
|
1478
|
+
* @param listener - The listener callback.
|
|
1479
|
+
* @returns `this`
|
|
1480
|
+
*/
|
|
1447
1481
|
once<T extends keyof MapEventType>(type: T, listener?: (ev: MapEventType[T] & Object) => void): this | Promise<any>;
|
|
1482
|
+
/**
|
|
1483
|
+
* Overload of the `once` method that allows to listen to events without specifying a layer.
|
|
1484
|
+
* @event
|
|
1485
|
+
* @param type - The type of the event.
|
|
1486
|
+
* @param listener - The listener callback.
|
|
1487
|
+
* @returns `this`
|
|
1488
|
+
*/
|
|
1489
|
+
once(type: keyof MapEventType | string, listener?: Listener): this | Promise<any>;
|
|
1448
1490
|
once(type: keyof MapEventType | string, layerIdOrListener: string | Listener, listener?: Listener): this | Promise<any> {
|
|
1449
1491
|
|
|
1450
1492
|
if (listener === undefined) {
|
|
@@ -1461,20 +1503,35 @@ export class Map extends Camera {
|
|
|
1461
1503
|
}
|
|
1462
1504
|
|
|
1463
1505
|
/**
|
|
1464
|
-
* Removes an event listener for
|
|
1506
|
+
* Removes an event listener for events previously added with `Map#on`.
|
|
1465
1507
|
*
|
|
1508
|
+
* @event
|
|
1466
1509
|
* @param type - The event type previously used to install the listener.
|
|
1467
|
-
* @param
|
|
1468
|
-
* @param listener -
|
|
1510
|
+
* @param layer - The layer ID or listener previously used to install the listener.
|
|
1511
|
+
* @param listener - The function previously installed as a listener.
|
|
1469
1512
|
* @returns `this`
|
|
1470
1513
|
*/
|
|
1471
|
-
off(type: keyof MapEventType | string, listener: Listener): this;
|
|
1472
1514
|
off<T extends keyof MapLayerEventType>(
|
|
1473
1515
|
type: T,
|
|
1474
1516
|
layer: string,
|
|
1475
1517
|
listener: (ev: MapLayerEventType[T] & Object) => void,
|
|
1476
1518
|
): this;
|
|
1519
|
+
/**
|
|
1520
|
+
* Overload of the `off` method that allows to listen to events without specifying a layer.
|
|
1521
|
+
* @event
|
|
1522
|
+
* @param type - The type of the event.
|
|
1523
|
+
* @param listener - The function previously installed as a listener.
|
|
1524
|
+
* @returns `this`
|
|
1525
|
+
*/
|
|
1477
1526
|
off<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
|
|
1527
|
+
/**
|
|
1528
|
+
* Overload of the `off` method that allows to listen to events without specifying a layer.
|
|
1529
|
+
* @event
|
|
1530
|
+
* @param type - The type of the event.
|
|
1531
|
+
* @param listener - The function previously installed as a listener.
|
|
1532
|
+
* @returns `this`
|
|
1533
|
+
*/
|
|
1534
|
+
off(type: keyof MapEventType | string, listener: Listener): this;
|
|
1478
1535
|
off(type: keyof MapEventType | string, layerIdOrListener: string | Listener, listener?: Listener): this {
|
|
1479
1536
|
if (listener === undefined) {
|
|
1480
1537
|
return super.off(type, layerIdOrListener as Listener);
|
|
@@ -1830,11 +1887,14 @@ export class Map extends Camera {
|
|
|
1830
1887
|
/**
|
|
1831
1888
|
* Adds a source to the map's style.
|
|
1832
1889
|
*
|
|
1890
|
+
* Events triggered:
|
|
1891
|
+
*
|
|
1892
|
+
* Triggers the `source.add` event.
|
|
1893
|
+
*
|
|
1833
1894
|
* @param id - The ID of the source to add. Must not conflict with existing sources.
|
|
1834
1895
|
* @param source - The source object, conforming to the
|
|
1835
|
-
* MapLibre Style Specification's [source definition](https://maplibre.org/maplibre-style-spec
|
|
1896
|
+
* MapLibre Style Specification's [source definition](https://maplibre.org/maplibre-style-spec/sources) or
|
|
1836
1897
|
* {@link CanvasSourceSpecification}.
|
|
1837
|
-
* @event `source.add`
|
|
1838
1898
|
* @returns `this`
|
|
1839
1899
|
* @example
|
|
1840
1900
|
* ```ts
|
|
@@ -1872,6 +1932,8 @@ export class Map extends Camera {
|
|
|
1872
1932
|
* Returns a Boolean indicating whether the source is loaded. Returns `true` if the source with
|
|
1873
1933
|
* the given ID in the map's style has no outstanding network requests, otherwise `false`.
|
|
1874
1934
|
*
|
|
1935
|
+
* A {@link ErrorEvent} event will be fired if there is no source wit the specified ID.
|
|
1936
|
+
*
|
|
1875
1937
|
* @param id - The ID of the source to be checked.
|
|
1876
1938
|
* @returns A Boolean indicating whether the source is loaded.
|
|
1877
1939
|
* @example
|
|
@@ -1890,6 +1952,9 @@ export class Map extends Camera {
|
|
|
1890
1952
|
|
|
1891
1953
|
/**
|
|
1892
1954
|
* Loads a 3D terrain mesh, based on a "raster-dem" source.
|
|
1955
|
+
*
|
|
1956
|
+
* Triggers the `terrain` event.
|
|
1957
|
+
*
|
|
1893
1958
|
* @param options - Options object.
|
|
1894
1959
|
* @returns `this`
|
|
1895
1960
|
* @example
|
|
@@ -1909,7 +1974,8 @@ export class Map extends Camera {
|
|
|
1909
1974
|
this.terrain = null;
|
|
1910
1975
|
if (this.painter.renderToTexture) this.painter.renderToTexture.destruct();
|
|
1911
1976
|
this.painter.renderToTexture = null;
|
|
1912
|
-
this.transform.
|
|
1977
|
+
this.transform._minEleveationForCurrentTile = 0;
|
|
1978
|
+
this.transform.elevation = 0;
|
|
1913
1979
|
} else {
|
|
1914
1980
|
// add terrain
|
|
1915
1981
|
const sourceCache = this.style.sourceCaches[options.source];
|
|
@@ -1923,12 +1989,16 @@ export class Map extends Camera {
|
|
|
1923
1989
|
}
|
|
1924
1990
|
this.terrain = new Terrain(this.painter, sourceCache, options);
|
|
1925
1991
|
this.painter.renderToTexture = new RenderToTexture(this.painter, this.terrain);
|
|
1926
|
-
this.transform.
|
|
1992
|
+
this.transform._minEleveationForCurrentTile = this.terrain.getMinTileElevationForLngLatZoom(this.transform.center, this.transform.tileZoom);
|
|
1993
|
+
this.transform.elevation = this.terrain.getElevationForLngLatZoom(this.transform.center, this.transform.tileZoom);
|
|
1927
1994
|
this._terrainDataCallback = e => {
|
|
1928
1995
|
if (e.dataType === 'style') {
|
|
1929
1996
|
this.terrain.sourceCache.freeRtt();
|
|
1930
1997
|
} else if (e.dataType === 'source' && e.tile) {
|
|
1931
|
-
if (e.sourceId === options.source
|
|
1998
|
+
if (e.sourceId === options.source && !this._elevationFreeze) {
|
|
1999
|
+
this.transform._minEleveationForCurrentTile = this.terrain.getMinTileElevationForLngLatZoom(this.transform.center, this.transform.tileZoom);
|
|
2000
|
+
this.transform.elevation = this.terrain.getElevationForLngLatZoom(this.transform.center, this.transform.tileZoom);
|
|
2001
|
+
}
|
|
1932
2002
|
this.terrain.sourceCache.freeRtt(e.tile.tileID);
|
|
1933
2003
|
}
|
|
1934
2004
|
};
|
|
@@ -2030,11 +2100,12 @@ export class Map extends Camera {
|
|
|
2030
2100
|
/**
|
|
2031
2101
|
* Add an image to the style. This image can be displayed on the map like any other icon in the style's
|
|
2032
2102
|
* sprite using the image's ID with
|
|
2033
|
-
* [`icon-image`](https://maplibre.org/maplibre-style-spec/#layout-symbol-icon-image),
|
|
2034
|
-
* [`background-pattern`](https://maplibre.org/maplibre-style-spec/#paint-background-background-pattern),
|
|
2035
|
-
* [`fill-pattern`](https://maplibre.org/maplibre-style-spec/#paint-fill-fill-pattern),
|
|
2036
|
-
* or [`line-pattern`](https://maplibre.org/maplibre-style-spec/#paint-line-line-pattern).
|
|
2037
|
-
*
|
|
2103
|
+
* [`icon-image`](https://maplibre.org/maplibre-style-spec/layers/#layout-symbol-icon-image),
|
|
2104
|
+
* [`background-pattern`](https://maplibre.org/maplibre-style-spec/layers/#paint-background-background-pattern),
|
|
2105
|
+
* [`fill-pattern`](https://maplibre.org/maplibre-style-spec/layers/#paint-fill-fill-pattern),
|
|
2106
|
+
* or [`line-pattern`](https://maplibre.org/maplibre-style-spec/layers/#paint-line-line-pattern).
|
|
2107
|
+
*
|
|
2108
|
+
* A {@link ErrorEvent} event will be fired if the image parameter is invalid or there is not enough space in the sprite to add this image.
|
|
2038
2109
|
*
|
|
2039
2110
|
* @param id - The ID of the image.
|
|
2040
2111
|
* @param image - The image as an `HTMLImageElement`, `ImageData`, `ImageBitmap` or object with `width`, `height`, and `data`
|
|
@@ -2115,10 +2186,12 @@ export class Map extends Camera {
|
|
|
2115
2186
|
/**
|
|
2116
2187
|
* Update an existing image in a style. This image can be displayed on the map like any other icon in the style's
|
|
2117
2188
|
* sprite using the image's ID with
|
|
2118
|
-
* [`icon-image`](https://maplibre.org/maplibre-style-spec/#layout-symbol-icon-image),
|
|
2119
|
-
* [`background-pattern`](https://maplibre.org/maplibre-style-spec/#paint-background-background-pattern),
|
|
2120
|
-
* [`fill-pattern`](https://maplibre.org/maplibre-style-spec/#paint-fill-fill-pattern),
|
|
2121
|
-
* or [`line-pattern`](https://maplibre.org/maplibre-style-spec/#paint-line-line-pattern).
|
|
2189
|
+
* [`icon-image`](https://maplibre.org/maplibre-style-spec/layers/#layout-symbol-icon-image),
|
|
2190
|
+
* [`background-pattern`](https://maplibre.org/maplibre-style-spec/layers/#paint-background-background-pattern),
|
|
2191
|
+
* [`fill-pattern`](https://maplibre.org/maplibre-style-spec/layers/#paint-fill-fill-pattern),
|
|
2192
|
+
* or [`line-pattern`](https://maplibre.org/maplibre-style-spec/layers/#paint-line-line-pattern).
|
|
2193
|
+
*
|
|
2194
|
+
* An {@link ErrorEvent} will be fired if the image parameter is invald.
|
|
2122
2195
|
*
|
|
2123
2196
|
* @param id - The ID of the image.
|
|
2124
2197
|
* @param image - The image as an `HTMLImageElement`, `ImageData`, `ImageBitmap` or object with `width`, `height`, and `data`
|
|
@@ -2188,6 +2261,8 @@ export class Map extends Camera {
|
|
|
2188
2261
|
* in the style's original sprite and any images
|
|
2189
2262
|
* that have been added at runtime using {@link Map#addImage}.
|
|
2190
2263
|
*
|
|
2264
|
+
* An {@link ErrorEvent} will be fired if the image parameter is invald.
|
|
2265
|
+
*
|
|
2191
2266
|
* @param id - The ID of the image.
|
|
2192
2267
|
*
|
|
2193
2268
|
* @returns A Boolean indicating whether the image exists.
|
|
@@ -2263,14 +2338,14 @@ export class Map extends Camera {
|
|
|
2263
2338
|
}
|
|
2264
2339
|
|
|
2265
2340
|
/**
|
|
2266
|
-
* Adds a [MapLibre style layer](https://maplibre.org/maplibre-style-spec
|
|
2341
|
+
* Adds a [MapLibre style layer](https://maplibre.org/maplibre-style-spec/layers)
|
|
2267
2342
|
* to the map's style.
|
|
2268
2343
|
*
|
|
2269
2344
|
* A layer defines how data from a specified source will be styled. Read more about layer types
|
|
2270
|
-
* and available paint and layout properties in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec
|
|
2345
|
+
* and available paint and layout properties in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/layers).
|
|
2271
2346
|
*
|
|
2272
2347
|
* @param layer - The layer to add,
|
|
2273
|
-
* conforming to either the MapLibre Style Specification's [layer definition](https://maplibre.org/maplibre-style-spec
|
|
2348
|
+
* conforming to either the MapLibre Style Specification's [layer definition](https://maplibre.org/maplibre-style-spec/layers) or,
|
|
2274
2349
|
* less commonly, the {@link CustomLayerInterface} specification.
|
|
2275
2350
|
* The MapLibre Style Specification's layer definition is appropriate for most layers.
|
|
2276
2351
|
*
|
|
@@ -2370,10 +2445,9 @@ export class Map extends Camera {
|
|
|
2370
2445
|
/**
|
|
2371
2446
|
* Removes the layer with the given ID from the map's style.
|
|
2372
2447
|
*
|
|
2373
|
-
*
|
|
2448
|
+
* An {@link ErrorEvent} will be fired if the image parameter is invald.
|
|
2374
2449
|
*
|
|
2375
2450
|
* @param id - The ID of the layer to remove
|
|
2376
|
-
* @event `error`
|
|
2377
2451
|
* @returns `this`
|
|
2378
2452
|
*
|
|
2379
2453
|
* @example
|
|
@@ -2407,8 +2481,8 @@ export class Map extends Camera {
|
|
|
2407
2481
|
|
|
2408
2482
|
/**
|
|
2409
2483
|
* Sets the zoom extent for the specified style layer. The zoom extent includes the
|
|
2410
|
-
* [minimum zoom level](https://maplibre.org/maplibre-style-spec/#
|
|
2411
|
-
* and [maximum zoom level](https://maplibre.org/maplibre-style-spec/#
|
|
2484
|
+
* [minimum zoom level](https://maplibre.org/maplibre-style-spec/layers/#minzoom)
|
|
2485
|
+
* and [maximum zoom level](https://maplibre.org/maplibre-style-spec/layers/#maxzoom))
|
|
2412
2486
|
* at which the layer will be rendered.
|
|
2413
2487
|
*
|
|
2414
2488
|
* Note: For style layers using vector sources, style layers cannot be rendered at zoom levels lower than the
|
|
@@ -2568,12 +2642,11 @@ export class Map extends Camera {
|
|
|
2568
2642
|
}
|
|
2569
2643
|
|
|
2570
2644
|
/**
|
|
2571
|
-
* Adds a sprite to the map's style.
|
|
2645
|
+
* Adds a sprite to the map's style. Fires the `style` event.
|
|
2572
2646
|
*
|
|
2573
2647
|
* @param id - The ID of the sprite to add. Must not conflict with existing sprites.
|
|
2574
2648
|
* @param url - The URL to load the sprite from
|
|
2575
2649
|
* @param options - Options object.
|
|
2576
|
-
* @event `style`
|
|
2577
2650
|
* @returns `this`
|
|
2578
2651
|
* @example
|
|
2579
2652
|
* ```ts
|
|
@@ -2591,10 +2664,9 @@ export class Map extends Camera {
|
|
|
2591
2664
|
}
|
|
2592
2665
|
|
|
2593
2666
|
/**
|
|
2594
|
-
* Removes the sprite from the map's style.
|
|
2667
|
+
* Removes the sprite from the map's style. Fires the `style` event.
|
|
2595
2668
|
*
|
|
2596
2669
|
* @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
2670
|
* @returns `this`
|
|
2599
2671
|
* @example
|
|
2600
2672
|
* ```ts
|
|
@@ -2641,7 +2713,7 @@ export class Map extends Camera {
|
|
|
2641
2713
|
/**
|
|
2642
2714
|
* Sets the any combination of light values.
|
|
2643
2715
|
*
|
|
2644
|
-
* @param light - Light properties to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec
|
|
2716
|
+
* @param light - Light properties to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/light).
|
|
2645
2717
|
* @param options - Options object.
|
|
2646
2718
|
* @returns `this`
|
|
2647
2719
|
*
|
|
@@ -2882,6 +2954,10 @@ export class Map extends Camera {
|
|
|
2882
2954
|
<div class="maplibregl-desktop-message">${desktopMessage}</div>
|
|
2883
2955
|
<div class="maplibregl-mobile-message">${mobileMessage}</div>
|
|
2884
2956
|
`;
|
|
2957
|
+
|
|
2958
|
+
// Remove cooperative gesture screen from the accessibility tree since screenreaders cannot interact with the map using gestures
|
|
2959
|
+
this._cooperativeGesturesScreen.setAttribute('aria-hidden', 'true');
|
|
2960
|
+
|
|
2885
2961
|
// Add event to canvas container since gesture container is pointer-events: none
|
|
2886
2962
|
this._canvasContainer.addEventListener('wheel', this._cooperativeGesturesOnWheel, false);
|
|
2887
2963
|
|
|
@@ -2994,6 +3070,7 @@ export class Map extends Camera {
|
|
|
2994
3070
|
}
|
|
2995
3071
|
|
|
2996
3072
|
/**
|
|
3073
|
+
* @internal
|
|
2997
3074
|
* Update this map's style and sources, and re-render the map.
|
|
2998
3075
|
*
|
|
2999
3076
|
* @param updateStyle - mark the map's style for reprocessing as
|
|
@@ -3011,8 +3088,10 @@ export class Map extends Camera {
|
|
|
3011
3088
|
}
|
|
3012
3089
|
|
|
3013
3090
|
/**
|
|
3091
|
+
* @internal
|
|
3014
3092
|
* Request that the given callback be executed during the next render
|
|
3015
3093
|
* frame. Schedule a render frame if one is not already scheduled.
|
|
3094
|
+
*
|
|
3016
3095
|
* @returns An id that can be used to cancel the callback
|
|
3017
3096
|
*/
|
|
3018
3097
|
_requestRenderFrame(callback: () => void): TaskID {
|
|
@@ -3025,6 +3104,7 @@ export class Map extends Camera {
|
|
|
3025
3104
|
}
|
|
3026
3105
|
|
|
3027
3106
|
/**
|
|
3107
|
+
* @internal
|
|
3028
3108
|
* Call when a (re-)render of the map is required:
|
|
3029
3109
|
* - The style has changed (`setPaintProperty()`, etc.)
|
|
3030
3110
|
* - Source data has changed (e.g. tiles have finished loading)
|
|
@@ -3083,8 +3163,16 @@ export class Map extends Camera {
|
|
|
3083
3163
|
}
|
|
3084
3164
|
|
|
3085
3165
|
// update terrain stuff
|
|
3086
|
-
if (this.terrain)
|
|
3087
|
-
|
|
3166
|
+
if (this.terrain) {
|
|
3167
|
+
this.terrain.sourceCache.update(this.transform, this.terrain);
|
|
3168
|
+
this.transform._minEleveationForCurrentTile = this.terrain.getMinTileElevationForLngLatZoom(this.transform.center, this.transform.tileZoom);
|
|
3169
|
+
if (!this._elevationFreeze) {
|
|
3170
|
+
this.transform.elevation = this.terrain.getElevationForLngLatZoom(this.transform.center, this.transform.tileZoom);
|
|
3171
|
+
}
|
|
3172
|
+
} else {
|
|
3173
|
+
this.transform._minEleveationForCurrentTile = 0;
|
|
3174
|
+
this.transform.elevation = 0;
|
|
3175
|
+
}
|
|
3088
3176
|
|
|
3089
3177
|
this._placementDirty = this.style && this.style._updatePlacement(this.painter.transform, this.showCollisionBoxes, fadeDuration, this._crossSourceCollisions);
|
|
3090
3178
|
|
|
@@ -4,6 +4,10 @@ import {createMap, beforeMapTest} from '../util/test/util';
|
|
|
4
4
|
import {MapGeoJSONFeature} from '../util/vectortile_to_geojson';
|
|
5
5
|
import {MapLayerEventType, MapLibreEvent} from './events';
|
|
6
6
|
|
|
7
|
+
type IsAny<T> = 0 extends T & 1 ? T : never;
|
|
8
|
+
type NotAny<T> = T extends IsAny<T> ? never : T;
|
|
9
|
+
function assertNotAny<T>(_x: NotAny<T>) { }
|
|
10
|
+
|
|
7
11
|
beforeEach(() => {
|
|
8
12
|
beforeMapTest();
|
|
9
13
|
});
|
|
@@ -170,6 +174,20 @@ describe('map events', () => {
|
|
|
170
174
|
expect(handler.onMove).toHaveBeenCalledTimes(1);
|
|
171
175
|
});
|
|
172
176
|
|
|
177
|
+
test('Map#on allows a listener to infer the event type ', () => {
|
|
178
|
+
const map = createMap();
|
|
179
|
+
|
|
180
|
+
const spy = jest.fn();
|
|
181
|
+
map.on('mousemove', (event) => {
|
|
182
|
+
assertNotAny(event);
|
|
183
|
+
const {lng, lat} = event.lngLat;
|
|
184
|
+
spy({lng, lat});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
simulate.mousemove(map.getCanvas());
|
|
188
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
189
|
+
});
|
|
190
|
+
|
|
173
191
|
test('Map#off removes a delegated event listener', () => {
|
|
174
192
|
const map = createMap();
|
|
175
193
|
|
|
@@ -244,6 +262,64 @@ describe('map events', () => {
|
|
|
244
262
|
expect(spyB).not.toHaveBeenCalled();
|
|
245
263
|
});
|
|
246
264
|
|
|
265
|
+
test('Map#off calls an event listener with no type arguments, defaulting to \'unknown\' originalEvent type', () => {
|
|
266
|
+
const map = createMap();
|
|
267
|
+
|
|
268
|
+
const handler = {
|
|
269
|
+
onMove: function onMove(_event: MapLibreEvent) {}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
jest.spyOn(handler, 'onMove');
|
|
273
|
+
|
|
274
|
+
map.off('move', (event) => handler.onMove(event));
|
|
275
|
+
map.jumpTo({center: {lng: 10, lat: 10}});
|
|
276
|
+
|
|
277
|
+
expect(handler.onMove).toHaveBeenCalledTimes(0);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('Map#off allows a listener to infer the event type ', () => {
|
|
281
|
+
const map = createMap();
|
|
282
|
+
|
|
283
|
+
const spy = jest.fn();
|
|
284
|
+
map.off('mousemove', (event) => {
|
|
285
|
+
assertNotAny(event);
|
|
286
|
+
const {lng, lat} = event.lngLat;
|
|
287
|
+
spy({lng, lat});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
simulate.mousemove(map.getCanvas());
|
|
291
|
+
expect(spy).toHaveBeenCalledTimes(0);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('Map#once calls an event listener with no type arguments, defaulting to \'unknown\' originalEvent type', () => {
|
|
295
|
+
const map = createMap();
|
|
296
|
+
|
|
297
|
+
const handler = {
|
|
298
|
+
onMoveOnce: function onMoveOnce(_event: MapLibreEvent) {}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
jest.spyOn(handler, 'onMoveOnce');
|
|
302
|
+
|
|
303
|
+
map.once('move', (event) => handler.onMoveOnce(event));
|
|
304
|
+
map.jumpTo({center: {lng: 10, lat: 10}});
|
|
305
|
+
|
|
306
|
+
expect(handler.onMoveOnce).toHaveBeenCalledTimes(1);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('Map#once allows a listener to infer the event type ', () => {
|
|
310
|
+
const map = createMap();
|
|
311
|
+
|
|
312
|
+
const spy = jest.fn();
|
|
313
|
+
map.once('mousemove', (event) => {
|
|
314
|
+
assertNotAny(event);
|
|
315
|
+
const {lng, lat} = event.lngLat;
|
|
316
|
+
spy({lng, lat});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
simulate.mousemove(map.getCanvas());
|
|
320
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
321
|
+
});
|
|
322
|
+
|
|
247
323
|
(['mouseenter', 'mouseover'] as (keyof MapLayerEventType)[]).forEach((event) => {
|
|
248
324
|
test(`Map#on ${event} does not fire if the specified layer does not exist`, () => {
|
|
249
325
|
const map = createMap();
|