Skip to content

Commit d309845

Browse files
madociHarelM
andauthored
Set transform request types to include null (#6180)
* Add null as a valid type to give to Map.setTransformRequest * Add a test for setting transformRequest to null * Update test to use a spy --------- Co-authored-by: Harel M <[email protected]>
1 parent f65ea48 commit d309845

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fix white artifacts when using non-zero elevation ([#6032](https://github.com/maplibre/maplibre-gl-js/pull/6032))
88
- Fix geolocate control lock loss on window resize ([#3504](https://github.com/maplibre/maplibre-gl-js/issues/3504))
99
- Fix a memory leak in `GeoJSONSource` when rapidly updating data ([#6163](https://github.com/maplibre/maplibre-gl-js/pull/6163))
10+
- Fix `Map.setTransformRequest` parameter type to include `null` ([#6179](https://github.com/maplibre/maplibre-gl-js/issues/6179))
1011

1112
- _...Add new stuff here..._
1213

src/ui/map.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ export class Map extends Camera {
18751875
* map.setTransformRequest((url: string, resourceType: string) => {});
18761876
* ```
18771877
*/
1878-
setTransformRequest(transformRequest: RequestTransformFunction): this {
1878+
setTransformRequest(transformRequest: RequestTransformFunction | null): this {
18791879
this._requestManager.setTransformRequest(transformRequest);
18801880
return this;
18811881
}
@@ -2205,12 +2205,12 @@ export class Map extends Camera {
22052205
}
22062206

22072207
/**
2208-
* Change the tile Level of Detail behavior of the specified source. These parameters have no effect when
2208+
* Change the tile Level of Detail behavior of the specified source. These parameters have no effect when
22092209
* pitch == 0, and the largest effect when the horizon is visible on screen.
22102210
*
22112211
* @param maxZoomLevelsOnScreen - The maximum number of distinct zoom levels allowed on screen at a time.
22122212
* There will generally be fewer zoom levels on the screen, the maximum can only be reached when the horizon
2213-
* is at the top of the screen. Increasing the maximum number of zoom levels causes the zoom level to decay
2213+
* is at the top of the screen. Increasing the maximum number of zoom levels causes the zoom level to decay
22142214
* faster toward the horizon.
22152215
* @param tileCountMaxMinRatio - The ratio of the maximum number of tiles loaded (at high pitch) to the minimum
22162216
* number of tiles loaded. Increasing this ratio allows more tiles to be loaded at high pitch angles. If the ratio

src/ui/map_tests/map_basic.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {createMap, beforeMapTest, createStyle, createStyleSource} from '../../ut
44
import {Tile} from '../../source/tile';
55
import {OverscaledTileID} from '../../source/tile_id';
66
import {fixedLngLat} from '../../../test/unit/lib/fixed';
7-
import {type RequestTransformFunction} from '../../util/request_manager';
7+
import {type RequestTransformFunction, ResourceType} from '../../util/request_manager';
88
import {type MapSourceDataEvent} from '../events';
99
import {MessageType} from '../../util/actor_messages';
1010

@@ -69,6 +69,16 @@ describe('Map', () => {
6969
map.setTransformRequest(transformRequest);
7070
map.setTransformRequest(transformRequest);
7171
});
72+
73+
test('removes function when called with null', () => {
74+
const map = createMap();
75+
76+
const transformRequest = vi.fn();
77+
map.setTransformRequest(transformRequest);
78+
map.setTransformRequest(null);
79+
map._requestManager.transformRequest('', ResourceType.Unknown);
80+
expect(transformRequest).not.toHaveBeenCalled();
81+
});
7282
});
7383

7484
describe('is_Loaded', () => {
@@ -117,7 +127,7 @@ describe('Map', () => {
117127

118128
expect(map.isStyleLoaded()).toBe(false);
119129
await map.once('load');
120-
expect(map.isStyleLoaded()).toBe(true);
130+
expect(map.isStyleLoaded()).toBe(true);
121131
});
122132

123133
test('Map.areTilesLoaded', async () => {
@@ -130,7 +140,7 @@ describe('Map', () => {
130140
map.style.sourceCaches.geojson._tiles[fakeTileId.key] = new Tile(fakeTileId, undefined);
131141
expect(map.areTilesLoaded()).toBe(false);
132142
map.style.sourceCaches.geojson._tiles[fakeTileId.key].state = 'loaded';
133-
expect(map.areTilesLoaded()).toBe(true);
143+
expect(map.areTilesLoaded()).toBe(true);
134144
});
135145
});
136146

src/util/request_manager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export const enum ResourceType {
2121
export type RequestTransformFunction = (url: string, resourceType?: ResourceType) => RequestParameters | undefined;
2222

2323
export class RequestManager {
24-
_transformRequestFn: RequestTransformFunction;
24+
_transformRequestFn: RequestTransformFunction | null;
2525

26-
constructor(transformRequestFn?: RequestTransformFunction) {
27-
this._transformRequestFn = transformRequestFn;
26+
constructor(transformRequestFn?: RequestTransformFunction | null) {
27+
this._transformRequestFn = transformRequestFn ?? null;
2828
}
2929

3030
transformRequest(url: string, type: ResourceType) {
@@ -35,7 +35,7 @@ export class RequestManager {
3535
return {url};
3636
}
3737

38-
setTransformRequest(transformRequest: RequestTransformFunction) {
38+
setTransformRequest(transformRequest: RequestTransformFunction | null) {
3939
this._transformRequestFn = transformRequest;
4040
}
4141
}

0 commit comments

Comments
 (0)