maplibre-gl 2.0.1 → 2.0.5
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 +4 -4
- package/build/post-ts-build.js +1 -0
- package/build/release-notes.js +7 -32
- package/dist/maplibre-gl.d.ts +76 -192
- package/dist/maplibre-gl.js +4 -4
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +22 -27
- package/src/data/array_types.ts +21 -21
- package/src/data/bucket/circle_bucket.ts +1 -1
- package/src/data/bucket/fill_bucket.test.ts +2 -2
- 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 +2 -2
- package/src/data/bucket/line_bucket.ts +1 -1
- package/src/data/bucket/symbol_bucket.ts +1 -1
- package/src/data/bucket.ts +1 -1
- package/src/data/evaluation_feature.ts +1 -1
- package/src/data/feature_index.ts +3 -3
- package/src/data/load_geometry.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 -2
- package/src/render/draw_symbol.ts +1 -1
- package/src/source/geojson_source.test.ts +27 -0
- package/src/source/geojson_source.ts +1 -3
- 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/source.ts +2 -2
- package/src/source/source_cache.test.ts +3 -3
- package/src/source/source_cache.ts +1 -1
- package/src/source/tile.ts +1 -1
- package/src/source/tile_id.ts +1 -1
- package/src/source/vector_tile_worker_source.test.ts +306 -0
- package/src/source/worker_tile.test.ts +2 -1
- package/src/style/query_utils.ts +1 -1
- package/src/style/style.ts +1 -1
- package/src/style/style_layer/circle_style_layer.ts +1 -1
- package/src/style/style_layer/fill_extrusion_style_layer.ts +1 -1
- 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.ts +13 -16
- 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/style-spec.ts +0 -3
- 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 +1 -1
- package/src/symbol/get_anchors.test.ts +1 -1
- package/src/symbol/get_anchors.ts +1 -1
- 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 +1 -1
- package/src/symbol/projection.ts +1 -1
- package/src/symbol/quads.ts +1 -1
- package/src/symbol/symbol_layout.ts +1 -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.ts +4 -4
- 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/transferable_grid_index.test.ts +56 -0
- package/src/util/transferable_grid_index.ts +216 -0
- package/src/util/util.test.ts +1 -1
- package/src/util/util.ts +1 -1
- package/src/util/web_worker_transfer.ts +1 -17
- package/CHANGELOG.md +0 -2578
- package/src/types/non-typed-modules.d.ts +0 -47
- package/src/util/point.ts +0 -349
package/src/symbol/clip_line.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {number as interpolate} from '../style-spec/util/interpolate';
|
|
|
3
3
|
import Anchor from '../symbol/anchor';
|
|
4
4
|
import checkMaxAngle from './check_max_angle';
|
|
5
5
|
|
|
6
|
-
import type Point from '
|
|
6
|
+
import type Point from '@mapbox/point-geometry';
|
|
7
7
|
import type {Shaping, PositionedIcon} from './shaping';
|
|
8
8
|
|
|
9
9
|
export {getAnchors, getCenterAnchor};
|
package/src/symbol/placement.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {getAnchorAlignment, WritingMode} from './shaping';
|
|
|
7
7
|
import {mat4} from 'gl-matrix';
|
|
8
8
|
import assert from 'assert';
|
|
9
9
|
import pixelsToTileUnits from '../source/pixels_to_tile_units';
|
|
10
|
-
import Point from '
|
|
10
|
+
import Point from '@mapbox/point-geometry';
|
|
11
11
|
import type Transform from '../geo/transform';
|
|
12
12
|
import type StyleLayer from '../style/style_layer';
|
|
13
13
|
import {PossiblyEvaluated} from '../style/properties';
|
package/src/symbol/projection.ts
CHANGED
package/src/symbol/quads.ts
CHANGED
|
@@ -28,7 +28,7 @@ import type {ImagePosition} from '../render/image_atlas';
|
|
|
28
28
|
import type {GlyphPosition} from '../render/glyph_atlas';
|
|
29
29
|
import type {PossiblyEvaluatedPropertyValue} from '../style/properties';
|
|
30
30
|
|
|
31
|
-
import Point from '
|
|
31
|
+
import Point from '@mapbox/point-geometry';
|
|
32
32
|
import murmur3 from 'murmurhash-js';
|
|
33
33
|
|
|
34
34
|
// The symbol layout process needs `text-size` evaluated at up to five different zoom levels, and
|
package/src/ui/camera.test.ts
CHANGED
|
@@ -1777,14 +1777,6 @@ describe('#cameraForBounds', () => {
|
|
|
1777
1777
|
expect(fixedLngLat(transform.center, 4)).toEqual({lng: -100.5, lat: 44.4717});
|
|
1778
1778
|
});
|
|
1779
1779
|
|
|
1780
|
-
test('offset as object', () => {
|
|
1781
|
-
const camera = createCamera();
|
|
1782
|
-
const bb = [[-133, 16], [-68, 50]];
|
|
1783
|
-
const transform = camera.cameraForBounds(bb, {offset: {x: 0, y: 100}});
|
|
1784
|
-
|
|
1785
|
-
expect(fixedLngLat(transform.center, 4)).toEqual({lng: -100.5, lat: 44.4717});
|
|
1786
|
-
});
|
|
1787
|
-
|
|
1788
1780
|
test('offset and padding', () => {
|
|
1789
1781
|
const camera = createCamera();
|
|
1790
1782
|
const bb = [[-133, 16], [-68, 50]];
|
package/src/ui/camera.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {number as interpolate} from '../style-spec/util/interpolate';
|
|
|
3
3
|
import browser from '../util/browser';
|
|
4
4
|
import LngLat from '../geo/lng_lat';
|
|
5
5
|
import LngLatBounds from '../geo/lng_lat_bounds';
|
|
6
|
-
import Point
|
|
6
|
+
import Point from '@mapbox/point-geometry';
|
|
7
7
|
import {Event, Evented} from '../util/evented';
|
|
8
8
|
import assert from 'assert';
|
|
9
9
|
import {Debug} from '../util/debug';
|
|
@@ -14,6 +14,16 @@ import type {LngLatBoundsLike} from '../geo/lng_lat_bounds';
|
|
|
14
14
|
import type {TaskID} from '../util/task_queue';
|
|
15
15
|
import type {PaddingOptions} from '../geo/edge_insets';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* A [Point](https://github.com/mapbox/point-geometry) or an array of two numbers representing `x` and `y` screen coordinates in pixels.
|
|
19
|
+
*
|
|
20
|
+
* @typedef {(Point | [number, number])} PointLike
|
|
21
|
+
* @example
|
|
22
|
+
* var p1 = new Point(-77, 38); // a PointLike which is a Point
|
|
23
|
+
* var p2 = [-77, 38]; // a PointLike which is an array of two numbers
|
|
24
|
+
*/
|
|
25
|
+
export type PointLike = Point | [number, number];
|
|
26
|
+
|
|
17
27
|
export type RequireAtLeastOne<T> = { [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>; }[keyof T];
|
|
18
28
|
|
|
19
29
|
/**
|
|
@@ -599,7 +609,7 @@ abstract class Camera extends Evented {
|
|
|
599
609
|
* @memberof Map#
|
|
600
610
|
* @param bounds Center these bounds in the viewport and use the highest
|
|
601
611
|
* zoom level up to and including `Map#getMaxZoom()` that fits them in the viewport.
|
|
602
|
-
* @param {
|
|
612
|
+
* @param {FitBoundsOptions} [options] Options supports all properties from {@link AnimationOptions} and {@link CameraOptions} in addition to the fields below.
|
|
603
613
|
* @param {number | PaddingOptions} [options.padding] The amount of padding in pixels to add to the given bounds.
|
|
604
614
|
* @param {boolean} [options.linear=false] If `true`, the map transitions using
|
|
605
615
|
* {@link Map#easeTo}. If `false`, the map transitions using {@link Map#flyTo}. See
|
|
@@ -955,7 +965,7 @@ abstract class Camera extends Evented {
|
|
|
955
965
|
* unless 'options' includes `essential: true`.
|
|
956
966
|
*
|
|
957
967
|
* @memberof Map#
|
|
958
|
-
* @param {
|
|
968
|
+
* @param {FlyToOptions} options Options describing the destination and animation of the transition.
|
|
959
969
|
* Accepts {@link CameraOptions}, {@link AnimationOptions},
|
|
960
970
|
* and the following additional options.
|
|
961
971
|
* @param {number} [options.curve=1.42] The zooming "curve" that will occur along the
|
package/src/ui/events.ts
CHANGED
|
@@ -3,7 +3,7 @@ import DOM from '../../util/dom';
|
|
|
3
3
|
import {Event} from '../../util/evented';
|
|
4
4
|
|
|
5
5
|
import type Map from '../map';
|
|
6
|
-
import type Point from '
|
|
6
|
+
import type Point from '@mapbox/point-geometry';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The `BoxZoomHandler` allows the user to zoom the map to fit within a bounding box.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {MapMouseEvent, MapTouchEvent, MapWheelEvent} from '../events';
|
|
2
2
|
import {Handler} from '../handler_manager';
|
|
3
3
|
import type Map from '../map';
|
|
4
|
-
import type Point from '
|
|
4
|
+
import type Point from '@mapbox/point-geometry';
|
|
5
5
|
|
|
6
6
|
export class MapEventHandler implements Handler {
|
|
7
7
|
|
package/src/ui/handler/mouse.ts
CHANGED
|
@@ -8,7 +8,7 @@ import LngLat from '../../geo/lng_lat';
|
|
|
8
8
|
|
|
9
9
|
import type Map from '../map';
|
|
10
10
|
import type HandlerManager from '../handler_manager';
|
|
11
|
-
import type Point from '
|
|
11
|
+
import type Point from '@mapbox/point-geometry';
|
|
12
12
|
|
|
13
13
|
// deltaY value for mouse scroll wheel identification
|
|
14
14
|
const wheelZoomDelta = 4.000244140625;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import browser from '../util/browser';
|
|
2
2
|
import type Map from './map';
|
|
3
3
|
import {bezier, clamp, extend} from '../util/util';
|
|
4
|
-
import Point from '
|
|
4
|
+
import Point from '@mapbox/point-geometry';
|
|
5
5
|
import type {DragPanOptions} from './handler/shim/drag_pan';
|
|
6
6
|
|
|
7
7
|
const defaultInertiaOptions = {
|
|
@@ -17,7 +17,7 @@ import DragPanHandler from './handler/shim/drag_pan';
|
|
|
17
17
|
import DragRotateHandler from './handler/shim/drag_rotate';
|
|
18
18
|
import TouchZoomRotateHandler from './handler/shim/touch_zoom_rotate';
|
|
19
19
|
import {bindAll, extend} from '../util/util';
|
|
20
|
-
import Point from '
|
|
20
|
+
import Point from '@mapbox/point-geometry';
|
|
21
21
|
import assert from 'assert';
|
|
22
22
|
|
|
23
23
|
export type InputEvent = MouseEvent | TouchEvent | KeyboardEvent | WheelEvent;
|
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';
|
|
@@ -828,11 +828,11 @@ class Map extends Camera {
|
|
|
828
828
|
}
|
|
829
829
|
|
|
830
830
|
/**
|
|
831
|
-
* Returns a
|
|
831
|
+
* Returns a [Point](https://github.com/mapbox/point-geometry) representing pixel coordinates, relative to the map's `container`,
|
|
832
832
|
* that correspond to the specified geographical location.
|
|
833
833
|
*
|
|
834
834
|
* @param {LngLatLike} lnglat The geographical location to project.
|
|
835
|
-
* @returns {Point} The
|
|
835
|
+
* @returns {Point} The [Point](https://github.com/mapbox/point-geometry) corresponding to `lnglat`, relative to the map's `container`.
|
|
836
836
|
* @example
|
|
837
837
|
* var coordinate = [-122.420679, 37.772537];
|
|
838
838
|
* var point = map.project(coordinate);
|
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