maplibre-gl 2.0.2 → 2.1.0
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-struct-arrays.ts +1 -1
- package/build/post-ts-build.js +0 -9
- package/build/release-notes.js +7 -32
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +57 -219
- package/dist/maplibre-gl.js +4 -4
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +37 -53
- package/src/css/maplibre-gl.css +21 -21
- package/src/data/array_types.ts +1 -1
- package/src/data/bucket/circle_bucket.ts +1 -1
- package/src/data/bucket/fill_bucket.test.ts +1 -1
- package/src/data/bucket/fill_bucket.ts +1 -1
- package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
- package/src/data/bucket/line_bucket.test.ts +1 -1
- package/src/data/bucket/line_bucket.ts +1 -1
- package/src/data/bucket/symbol_bucket.test.ts +1 -1
- package/src/data/bucket/symbol_bucket.ts +4 -4
- package/src/data/bucket.ts +1 -1
- package/src/data/evaluation_feature.ts +1 -1
- package/src/data/feature_index.ts +1 -1
- package/src/data/load_geometry.ts +1 -1
- package/src/data/program_configuration.ts +1 -1
- package/src/geo/edge_insets.ts +1 -1
- package/src/geo/transform.test.ts +1 -1
- package/src/geo/transform.ts +1 -1
- package/src/index.ts +1 -1
- package/src/render/draw_debug.ts +1 -1
- package/src/render/draw_symbol.ts +1 -1
- package/src/render/glyph_manager.ts +1 -1
- package/src/render/painter.ts +5 -3
- package/src/render/program/circle_program.ts +1 -1
- package/src/render/program/line_program.ts +3 -3
- package/src/render/program/symbol_program.ts +1 -1
- package/src/source/geojson_source.test.ts +29 -1
- package/src/source/geojson_source.ts +2 -4
- package/src/source/geojson_wrapper.ts +1 -1
- package/src/source/image_source.test.ts +153 -0
- package/src/source/query_features.test.ts +1 -1
- package/src/source/query_features.ts +1 -1
- package/src/source/raster_dem_tile_source.test.ts +2 -1
- package/src/source/raster_dem_tile_source.ts +1 -1
- package/src/source/raster_tile_source.test.ts +2 -1
- package/src/source/raster_tile_source.ts +1 -1
- package/src/source/source_cache.test.ts +2 -2
- package/src/source/source_cache.ts +1 -1
- package/src/source/tile.test.ts +1 -1
- package/src/source/tile.ts +1 -1
- package/src/source/tile_id.test.ts +10 -12
- package/src/source/tile_id.ts +3 -3
- package/src/source/vector_tile_source.test.ts +2 -1
- package/src/source/vector_tile_source.ts +2 -2
- package/src/source/vector_tile_worker_source.test.ts +306 -0
- package/src/style/load_sprite.ts +2 -1
- package/src/style/properties.ts +1 -1
- package/src/style/query_utils.ts +1 -1
- package/src/style/style.test.ts +4 -0
- package/src/style/style.ts +1 -1
- package/src/style/style_layer/circle_style_layer.ts +1 -1
- package/src/style/style_layer/custom_style_layer.ts +2 -2
- package/src/style/style_layer/fill_extrusion_style_layer.ts +2 -2
- package/src/style/style_layer/fill_style_layer.ts +1 -1
- package/src/style/style_layer/line_style_layer.ts +1 -1
- package/src/style/style_layer/symbol_style_layer.ts +19 -0
- package/src/style/style_layer/symbol_style_layer_properties.ts +6 -0
- package/src/style/style_layer.ts +1 -1
- package/src/style-spec/CHANGELOG.md +6 -0
- package/src/style-spec/expression/index.ts +1 -1
- package/src/style-spec/feature_filter/feature_filter.test.ts +1 -1
- package/src/style-spec/migrate.test.ts +112 -0
- package/src/style-spec/package.json +1 -1
- package/src/style-spec/reference/v8.json +68 -2
- package/src/style-spec/style-spec.ts +0 -3
- package/src/style-spec/types.ts +2 -0
- package/src/style-spec/validate_spec.test.ts +29 -0
- package/src/symbol/anchor.ts +1 -1
- package/src/symbol/check_max_angle.test.ts +1 -1
- package/src/symbol/check_max_angle.ts +1 -1
- package/src/symbol/clip_line.test.ts +1 -1
- package/src/symbol/clip_line.ts +1 -1
- package/src/symbol/collision_feature.test.ts +1 -1
- package/src/symbol/collision_feature.ts +1 -1
- package/src/symbol/collision_index.ts +20 -20
- package/src/symbol/get_anchors.test.ts +1 -1
- package/src/symbol/get_anchors.ts +1 -1
- package/src/symbol/grid_index.test.ts +42 -19
- package/src/symbol/grid_index.ts +62 -33
- package/src/symbol/mergelines.test.ts +1 -1
- package/src/symbol/path_interpolator.test.ts +1 -1
- package/src/symbol/path_interpolator.ts +1 -1
- package/src/symbol/placement.ts +83 -54
- package/src/symbol/projection.ts +1 -1
- package/src/symbol/quads.ts +1 -1
- package/src/symbol/symbol_layout.ts +1 -1
- package/src/symbol/symbol_style_layer.test.ts +48 -1
- package/src/ui/camera.test.ts +0 -8
- package/src/ui/camera.ts +13 -3
- package/src/ui/control/navigation_control.ts +1 -1
- package/src/ui/events.ts +1 -1
- package/src/ui/handler/box_zoom.ts +1 -1
- package/src/ui/handler/click_zoom.ts +1 -1
- package/src/ui/handler/handler_util.ts +1 -1
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/scroll_zoom.ts +1 -1
- package/src/ui/handler/tap_drag_zoom.ts +1 -1
- package/src/ui/handler/tap_recognizer.ts +1 -1
- package/src/ui/handler/tap_zoom.ts +1 -1
- package/src/ui/handler/touch_pan.ts +1 -1
- package/src/ui/handler/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler_inertia.ts +1 -1
- package/src/ui/handler_manager.ts +1 -1
- package/src/ui/map.test.ts +61 -0
- package/src/ui/map.ts +35 -10
- package/src/ui/marker.test.ts +1 -1
- package/src/ui/marker.ts +2 -1
- package/src/ui/popup.test.ts +1 -1
- package/src/ui/popup.ts +2 -2
- package/src/util/ajax.test.ts +206 -0
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/classify_rings.ts +1 -1
- package/src/util/dom.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +1 -1
- package/src/util/intersection_tests.ts +1 -1
- package/src/util/smart_wrap.ts +1 -1
- package/src/util/test/util.ts +14 -0
- package/src/util/util.test.ts +1 -1
- package/src/util/util.ts +1 -1
- package/CHANGELOG.md +0 -2585
- package/src/types/packages-types/vector-tile/index.d.ts +0 -27
- package/src/util/point.ts +0 -349
package/src/ui/map.ts
CHANGED
|
@@ -12,7 +12,7 @@ import HandlerManager from './handler_manager';
|
|
|
12
12
|
import Camera from './camera';
|
|
13
13
|
import LngLat from '../geo/lng_lat';
|
|
14
14
|
import LngLatBounds from '../geo/lng_lat_bounds';
|
|
15
|
-
import Point
|
|
15
|
+
import Point from '@mapbox/point-geometry';
|
|
16
16
|
import AttributionControl from './control/attribution_control';
|
|
17
17
|
import LogoControl from './control/logo_control';
|
|
18
18
|
import {supported} from '@mapbox/mapbox-gl-supported';
|
|
@@ -33,7 +33,7 @@ import type {StyleOptions, StyleSetterOptions} from '../style/style';
|
|
|
33
33
|
import type {MapEvent, MapDataEvent} from './events';
|
|
34
34
|
import type {CustomLayerInterface} from '../style/style_layer/custom_style_layer';
|
|
35
35
|
import type {StyleImageInterface, StyleImageMetadata} from '../style/style_image';
|
|
36
|
-
|
|
36
|
+
import type {PointLike} from './camera';
|
|
37
37
|
import type ScrollZoomHandler from './handler/scroll_zoom';
|
|
38
38
|
import type BoxZoomHandler from './handler/box_zoom';
|
|
39
39
|
import type {TouchPitchHandler} from './handler/touch_zoom_rotate';
|
|
@@ -101,6 +101,7 @@ export type MapOptions = {
|
|
|
101
101
|
localIdeographFontFamily?: string;
|
|
102
102
|
style: StyleSpecification | string;
|
|
103
103
|
pitchWithRotate?: boolean;
|
|
104
|
+
pixelRatio?: number;
|
|
104
105
|
};
|
|
105
106
|
|
|
106
107
|
// See article here: https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585
|
|
@@ -235,6 +236,7 @@ const defaultOptions = {
|
|
|
235
236
|
* @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
|
|
236
237
|
* @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
|
|
237
238
|
* @param {Object} [options.locale=null] A patch to apply to the default localization table for UI strings, e.g. control tooltips. The `locale` object maps namespaced UI string IDs to translated strings in the target language; see `src/ui/default_locale.js` for an example with all supported string IDs. The object may specify all UI strings (thereby adding support for a new translation) or only a subset of strings (thereby patching the default translation table).
|
|
239
|
+
* @param {number} [options.pixelRatio] The pixel ratio. The canvas' `width` attribute will be `container.clientWidth * pixelRatio` and its `height` attribute will be `container.clientHeight * pixelRatio`. Defaults to `devicePixelRatio` if not specified.
|
|
238
240
|
* @example
|
|
239
241
|
* var map = new maplibregl.Map({
|
|
240
242
|
* container: 'map',
|
|
@@ -298,6 +300,7 @@ class Map extends Camera {
|
|
|
298
300
|
_locale: any;
|
|
299
301
|
_removed: boolean;
|
|
300
302
|
_clickTolerance: number;
|
|
303
|
+
_pixelRatio: number;
|
|
301
304
|
|
|
302
305
|
/**
|
|
303
306
|
* The map's {@link ScrollZoomHandler}, which implements zooming in and out with a scroll wheel or trackpad.
|
|
@@ -389,6 +392,7 @@ class Map extends Camera {
|
|
|
389
392
|
this._mapId = uniqueId();
|
|
390
393
|
this._locale = extend({}, defaultLocale, options.locale);
|
|
391
394
|
this._clickTolerance = options.clickTolerance;
|
|
395
|
+
this._pixelRatio = options.pixelRatio ?? devicePixelRatio;
|
|
392
396
|
|
|
393
397
|
this._requestManager = new RequestManager(options.transformRequest);
|
|
394
398
|
|
|
@@ -584,9 +588,9 @@ class Map extends Camera {
|
|
|
584
588
|
const width = dimensions[0];
|
|
585
589
|
const height = dimensions[1];
|
|
586
590
|
|
|
587
|
-
this._resizeCanvas(width, height);
|
|
591
|
+
this._resizeCanvas(width, height, this.getPixelRatio());
|
|
588
592
|
this.transform.resize(width, height);
|
|
589
|
-
this.painter.resize(width, height);
|
|
593
|
+
this.painter.resize(width, height, this.getPixelRatio());
|
|
590
594
|
|
|
591
595
|
const fireMoving = !this._moving;
|
|
592
596
|
if (fireMoving) {
|
|
@@ -602,6 +606,29 @@ class Map extends Camera {
|
|
|
602
606
|
return this;
|
|
603
607
|
}
|
|
604
608
|
|
|
609
|
+
/**
|
|
610
|
+
* Returns the map's pixel ratio.
|
|
611
|
+
* @returns {number} The pixel ratio.
|
|
612
|
+
*/
|
|
613
|
+
getPixelRatio() {
|
|
614
|
+
return this._pixelRatio;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Sets the map's pixel ratio. This allows to override `devicePixelRatio`.
|
|
619
|
+
* After this call, the canvas' `width` attribute will be `container.clientWidth * pixelRatio`
|
|
620
|
+
* and its height attribute will be `container.clientHeight * pixelRatio`.
|
|
621
|
+
* @param pixelRatio {number} The pixel ratio.
|
|
622
|
+
*/
|
|
623
|
+
setPixelRatio(pixelRatio: number) {
|
|
624
|
+
const [width, height] = this._containerDimensions();
|
|
625
|
+
|
|
626
|
+
this._pixelRatio = pixelRatio;
|
|
627
|
+
|
|
628
|
+
this._resizeCanvas(width, height, pixelRatio);
|
|
629
|
+
this.painter.resize(width, height, pixelRatio);
|
|
630
|
+
}
|
|
631
|
+
|
|
605
632
|
/**
|
|
606
633
|
* Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
|
|
607
634
|
* an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
|
|
@@ -828,11 +855,11 @@ class Map extends Camera {
|
|
|
828
855
|
}
|
|
829
856
|
|
|
830
857
|
/**
|
|
831
|
-
* Returns a
|
|
858
|
+
* Returns a [Point](https://github.com/mapbox/point-geometry) representing pixel coordinates, relative to the map's `container`,
|
|
832
859
|
* that correspond to the specified geographical location.
|
|
833
860
|
*
|
|
834
861
|
* @param {LngLatLike} lnglat The geographical location to project.
|
|
835
|
-
* @returns {Point} The
|
|
862
|
+
* @returns {Point} The [Point](https://github.com/mapbox/point-geometry) corresponding to `lnglat`, relative to the map's `container`.
|
|
836
863
|
* @example
|
|
837
864
|
* var coordinate = [-122.420679, 37.772537];
|
|
838
865
|
* var point = map.project(coordinate);
|
|
@@ -2349,7 +2376,7 @@ class Map extends Camera {
|
|
|
2349
2376
|
this._canvas.setAttribute('role', 'region');
|
|
2350
2377
|
|
|
2351
2378
|
const dimensions = this._containerDimensions();
|
|
2352
|
-
this._resizeCanvas(dimensions[0], dimensions[1]);
|
|
2379
|
+
this._resizeCanvas(dimensions[0], dimensions[1], this.getPixelRatio());
|
|
2353
2380
|
|
|
2354
2381
|
const controlContainer = this._controlContainer = DOM.create('div', 'maplibregl-control-container mapboxgl-control-container', container);
|
|
2355
2382
|
const positions = this._controlPositions = {};
|
|
@@ -2360,9 +2387,7 @@ class Map extends Camera {
|
|
|
2360
2387
|
this._container.addEventListener('scroll', this._onMapScroll, false);
|
|
2361
2388
|
}
|
|
2362
2389
|
|
|
2363
|
-
_resizeCanvas(width: number, height: number) {
|
|
2364
|
-
const pixelRatio = devicePixelRatio || 1;
|
|
2365
|
-
|
|
2390
|
+
_resizeCanvas(width: number, height: number, pixelRatio: number) {
|
|
2366
2391
|
// Request the required canvas size taking the pixelratio into account.
|
|
2367
2392
|
this._canvas.width = pixelRatio * width;
|
|
2368
2393
|
this._canvas.height = pixelRatio * height;
|
package/src/ui/marker.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {createMap as globalCreateMap, setPerformance, setWebGlContext} from '../
|
|
|
2
2
|
import Marker from './marker';
|
|
3
3
|
import Popup from './popup';
|
|
4
4
|
import LngLat from '../geo/lng_lat';
|
|
5
|
-
import Point from '
|
|
5
|
+
import Point from '@mapbox/point-geometry';
|
|
6
6
|
import simulate from '../../test/util/simulate_interaction';
|
|
7
7
|
|
|
8
8
|
function createMap(options = {}) {
|
package/src/ui/marker.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DOM from '../util/dom';
|
|
2
2
|
import LngLat from '../geo/lng_lat';
|
|
3
|
-
import Point
|
|
3
|
+
import Point from '@mapbox/point-geometry';
|
|
4
4
|
import smartWrap from '../util/smart_wrap';
|
|
5
5
|
import {bindAll, extend} from '../util/util';
|
|
6
6
|
import {anchorTranslate, applyAnchorClass} from './anchor';
|
|
@@ -10,6 +10,7 @@ import type Map from './map';
|
|
|
10
10
|
import Popup, {Offset} from './popup';
|
|
11
11
|
import type {LngLatLike} from '../geo/lng_lat';
|
|
12
12
|
import type {MapMouseEvent, MapTouchEvent} from './events';
|
|
13
|
+
import type {PointLike} from './camera';
|
|
13
14
|
|
|
14
15
|
type MarkerOptions = {
|
|
15
16
|
element?: HTMLElement;
|
package/src/ui/popup.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {createMap as globalCreateMap, setPerformance, setWebGlContext} from '../util/test/util';
|
|
2
2
|
import Popup, {Offset} from './popup';
|
|
3
3
|
import LngLat from '../geo/lng_lat';
|
|
4
|
-
import Point from '
|
|
4
|
+
import Point from '@mapbox/point-geometry';
|
|
5
5
|
import simulate from '../../test/util/simulate_interaction';
|
|
6
6
|
import {PositionAnchor} from './anchor';
|
|
7
7
|
|
package/src/ui/popup.ts
CHANGED
|
@@ -3,14 +3,14 @@ import {Event, Evented} from '../util/evented';
|
|
|
3
3
|
import {MapMouseEvent} from '../ui/events';
|
|
4
4
|
import DOM from '../util/dom';
|
|
5
5
|
import LngLat from '../geo/lng_lat';
|
|
6
|
-
import Point
|
|
6
|
+
import Point from '@mapbox/point-geometry';
|
|
7
7
|
import smartWrap from '../util/smart_wrap';
|
|
8
8
|
import {anchorTranslate, applyAnchorClass} from './anchor';
|
|
9
9
|
|
|
10
10
|
import type {PositionAnchor} from './anchor';
|
|
11
|
-
|
|
12
11
|
import type Map from './map';
|
|
13
12
|
import type {LngLatLike} from '../geo/lng_lat';
|
|
13
|
+
import type {PointLike} from './camera';
|
|
14
14
|
|
|
15
15
|
const defaultOptions = {
|
|
16
16
|
closeButton: true,
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getArrayBuffer,
|
|
3
|
+
getJSON,
|
|
4
|
+
postData,
|
|
5
|
+
getImage,
|
|
6
|
+
resetImageRequestQueue
|
|
7
|
+
} from './ajax';
|
|
8
|
+
import config from './config';
|
|
9
|
+
import webpSupported from './webp_supported';
|
|
10
|
+
import {fakeServer, SinonFakeServer} from 'sinon';
|
|
11
|
+
import {stubAjaxGetImage} from './test/util';
|
|
12
|
+
|
|
13
|
+
describe('ajax', () => {
|
|
14
|
+
let server: SinonFakeServer;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
global.fetch = null;
|
|
17
|
+
server = fakeServer.create();
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
server.restore();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('getArrayBuffer, 404', done => {
|
|
24
|
+
server.respondWith(request => {
|
|
25
|
+
request.respond(404, undefined, undefined);
|
|
26
|
+
});
|
|
27
|
+
getArrayBuffer({url:''}, (error) => {
|
|
28
|
+
expect((error as any).status).toBe(404);
|
|
29
|
+
done();
|
|
30
|
+
});
|
|
31
|
+
server.respond();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('getJSON', done => {
|
|
35
|
+
server.respondWith(request => {
|
|
36
|
+
request.respond(200, {'Content-Type': 'application/json'}, '{"foo": "bar"}');
|
|
37
|
+
});
|
|
38
|
+
getJSON({url:''}, (error, body) => {
|
|
39
|
+
expect(error).toBeFalsy();
|
|
40
|
+
expect(body).toEqual({foo: 'bar'});
|
|
41
|
+
done();
|
|
42
|
+
});
|
|
43
|
+
server.respond();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('getJSON, invalid syntax', done => {
|
|
47
|
+
server.respondWith(request => {
|
|
48
|
+
request.respond(200, {'Content-Type': 'application/json'}, 'how do i even');
|
|
49
|
+
});
|
|
50
|
+
getJSON({url:''}, (error) => {
|
|
51
|
+
expect(error).toBeTruthy();
|
|
52
|
+
done();
|
|
53
|
+
});
|
|
54
|
+
server.respond();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('getJSON, 404', done => {
|
|
58
|
+
server.respondWith(request => {
|
|
59
|
+
request.respond(404, undefined, undefined);
|
|
60
|
+
});
|
|
61
|
+
getJSON({url:''}, (error) => {
|
|
62
|
+
expect((error as any).status).toBe(404);
|
|
63
|
+
done();
|
|
64
|
+
});
|
|
65
|
+
server.respond();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('getJSON, 401: non-Mapbox domain', done => {
|
|
69
|
+
server.respondWith(request => {
|
|
70
|
+
request.respond(401, undefined, undefined);
|
|
71
|
+
});
|
|
72
|
+
getJSON({url:''}, (error) => {
|
|
73
|
+
expect((error as any).status).toBe(401);
|
|
74
|
+
expect(error.message).toBe('Unauthorized');
|
|
75
|
+
done();
|
|
76
|
+
});
|
|
77
|
+
server.respond();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('postData, 204(no content): no error', done => {
|
|
81
|
+
server.respondWith(request => {
|
|
82
|
+
request.respond(204, undefined, undefined);
|
|
83
|
+
});
|
|
84
|
+
postData({url:'api.mapbox.com'}, (error) => {
|
|
85
|
+
expect(error).toBeNull();
|
|
86
|
+
done();
|
|
87
|
+
});
|
|
88
|
+
server.respond();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('getImage respects maxParallelImageRequests', done => {
|
|
92
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
93
|
+
|
|
94
|
+
const maxRequests = config.MAX_PARALLEL_IMAGE_REQUESTS;
|
|
95
|
+
|
|
96
|
+
function callback(err) {
|
|
97
|
+
if (err) return;
|
|
98
|
+
// last request is only added after we got a response from one of the previous ones
|
|
99
|
+
expect(server.requests).toHaveLength(maxRequests + 1);
|
|
100
|
+
done();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (let i = 0; i < maxRequests + 1; i++) {
|
|
104
|
+
getImage({url: ''}, callback);
|
|
105
|
+
}
|
|
106
|
+
expect(server.requests).toHaveLength(maxRequests);
|
|
107
|
+
|
|
108
|
+
server.requests[0].respond(undefined, undefined, undefined);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('getImage cancelling frees up request for maxParallelImageRequests', done => {
|
|
112
|
+
resetImageRequestQueue();
|
|
113
|
+
|
|
114
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
115
|
+
|
|
116
|
+
const maxRequests = config.MAX_PARALLEL_IMAGE_REQUESTS;
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < maxRequests + 1; i++) {
|
|
119
|
+
getImage({url: ''}, () => done('test failed: getImage callback was called')).cancel();
|
|
120
|
+
}
|
|
121
|
+
expect(server.requests).toHaveLength(maxRequests + 1);
|
|
122
|
+
done();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('getImage requests that were once queued are still abortable', done => {
|
|
126
|
+
resetImageRequestQueue();
|
|
127
|
+
|
|
128
|
+
const maxRequests = config.MAX_PARALLEL_IMAGE_REQUESTS;
|
|
129
|
+
|
|
130
|
+
const requests = [];
|
|
131
|
+
for (let i = 0; i < maxRequests; i++) {
|
|
132
|
+
requests.push(getImage({url: ''}, () => {}));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// the limit of allowed requests is reached
|
|
136
|
+
expect(server.requests).toHaveLength(maxRequests);
|
|
137
|
+
|
|
138
|
+
const queuedURL = 'this-is-the-queued-request';
|
|
139
|
+
const queued = getImage({url: queuedURL}, () => done('test failed: getImage callback was called'));
|
|
140
|
+
|
|
141
|
+
// the new requests is queued because the limit is reached
|
|
142
|
+
expect(server.requests).toHaveLength(maxRequests);
|
|
143
|
+
|
|
144
|
+
// cancel the first request to let the queued request start
|
|
145
|
+
requests[0].cancel();
|
|
146
|
+
expect(server.requests).toHaveLength(maxRequests + 1);
|
|
147
|
+
|
|
148
|
+
// abort the previously queued request and confirm that it is aborted
|
|
149
|
+
const queuedRequest = server.requests[server.requests.length - 1];
|
|
150
|
+
expect(queuedRequest.url).toBe(queuedURL);
|
|
151
|
+
expect((queuedRequest as any).aborted).toBeUndefined();
|
|
152
|
+
queued.cancel();
|
|
153
|
+
expect((queuedRequest as any).aborted).toBe(true);
|
|
154
|
+
|
|
155
|
+
done();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('getImage sends accept/webp when supported', done => {
|
|
159
|
+
resetImageRequestQueue();
|
|
160
|
+
|
|
161
|
+
server.respondWith((request) => {
|
|
162
|
+
expect(request.requestHeaders.accept.includes('image/webp')).toBeTruthy();
|
|
163
|
+
request.respond(200, {'Content-Type': 'image/webp'}, '');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// mock webp support
|
|
167
|
+
webpSupported.supported = true;
|
|
168
|
+
|
|
169
|
+
getImage({url: ''}, () => { done(); });
|
|
170
|
+
|
|
171
|
+
server.respond();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('getImage uses ImageBitmap when supported', done => {
|
|
175
|
+
resetImageRequestQueue();
|
|
176
|
+
|
|
177
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
178
|
+
|
|
179
|
+
stubAjaxGetImage(() => Promise.resolve(new ImageBitmap()));
|
|
180
|
+
|
|
181
|
+
getImage({url: ''}, (err, img) => {
|
|
182
|
+
if (err) done(err);
|
|
183
|
+
expect(img).toBeInstanceOf(ImageBitmap);
|
|
184
|
+
done();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
server.respond();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('getImage uses HTMLImageElement when ImageBitmap is not supported', done => {
|
|
191
|
+
resetImageRequestQueue();
|
|
192
|
+
|
|
193
|
+
server.respondWith(request => request.respond(200, {'Content-Type': 'image/png'}, ''));
|
|
194
|
+
|
|
195
|
+
stubAjaxGetImage(undefined);
|
|
196
|
+
|
|
197
|
+
getImage({url: ''}, (err, img) => {
|
|
198
|
+
if (err) done(`get image failed with error ${err.message}`);
|
|
199
|
+
expect(img).toBeInstanceOf(HTMLImageElement);
|
|
200
|
+
done();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
server.respond();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
});
|
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import Protobuf from 'pbf';
|
|
4
4
|
import {VectorTile} from '@mapbox/vector-tile';
|
|
5
5
|
import classifyRings from './classify_rings';
|
|
6
|
-
import Point from '
|
|
6
|
+
import Point from '@mapbox/point-geometry';
|
|
7
7
|
|
|
8
8
|
// Load a fill feature from fixture tile.
|
|
9
9
|
const vt = new VectorTile(new Protobuf(fs.readFileSync(path.resolve(__dirname, '../../test/fixtures/mbsv5-6-18-23.vector.pbf'))));
|
|
@@ -2,7 +2,7 @@ import quickselect from 'quickselect';
|
|
|
2
2
|
|
|
3
3
|
import {calculateSignedArea} from './util';
|
|
4
4
|
|
|
5
|
-
import type Point from '
|
|
5
|
+
import type Point from '@mapbox/point-geometry';
|
|
6
6
|
|
|
7
7
|
// classifies an array of rings into polygons with outer rings and holes
|
|
8
8
|
export default function classifyRings(rings: Array<Array<Point>>, maxRings: number) {
|
package/src/util/dom.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {isCounterClockwise} from './util';
|
|
2
2
|
|
|
3
|
-
import Point from '
|
|
3
|
+
import Point from '@mapbox/point-geometry';
|
|
4
4
|
|
|
5
5
|
export {polygonIntersectsBufferedPoint, polygonIntersectsMultiPolygon, polygonIntersectsBufferedMultiLine, polygonIntersectsPolygon, distToSegmentSquared, polygonIntersectsBox};
|
|
6
6
|
|
package/src/util/smart_wrap.ts
CHANGED
package/src/util/test/util.ts
CHANGED
|
@@ -99,3 +99,17 @@ export function getMockDispatcher() {
|
|
|
99
99
|
|
|
100
100
|
return mockDispatcher;
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
export function stubAjaxGetImage(createImageBitmap) {
|
|
104
|
+
global.createImageBitmap = createImageBitmap;
|
|
105
|
+
|
|
106
|
+
global.URL.revokeObjectURL = () => {};
|
|
107
|
+
global.URL.createObjectURL = (_) => { return null; };
|
|
108
|
+
|
|
109
|
+
// eslint-disable-next-line accessor-pairs
|
|
110
|
+
Object.defineProperty(global.Image.prototype, 'src', {
|
|
111
|
+
set(_) {
|
|
112
|
+
this.onload();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
package/src/util/util.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {easeCubicInOut, keysDifference, extend, pick, uniqueId, bindAll, asyncAll, clamp, wrap, bezier, mapObject, filterObject, deepEqual, clone, arraysIntersect, isCounterClockwise, isClosedPolygon, parseCacheControl, nextPowerOfTwo, isPowerOfTwo} from './util';
|
|
2
|
-
import Point from '
|
|
2
|
+
import Point from '@mapbox/point-geometry';
|
|
3
3
|
|
|
4
4
|
describe('util', () => {
|
|
5
5
|
expect(easeCubicInOut(0)).toBe(0);
|