maplibre-gl 3.3.0 → 3.3.1
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/LICENSE.txt +1 -1
- package/README.md +2 -1
- package/build/generate-dist-package.js +7 -2
- package/build/generate-typings.ts +1 -1
- package/dist/LICENSE.txt +116 -0
- 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 +57 -36
- package/dist/maplibre-gl-dev.js.map +1 -1
- package/dist/maplibre-gl.d.ts +14 -9
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +22 -21
- package/src/render/program.ts +15 -0
- package/src/source/vector_tile_source.ts +0 -1
- package/src/source/video_source.ts +4 -0
- package/src/style/style.ts +14 -8
- package/src/style/style_layer/variable_text_anchor.ts +1 -1
- package/src/ui/control/navigation_control.ts +0 -1
- package/src/ui/map.test.ts +37 -8
- package/src/ui/map.ts +14 -13
- package/src/ui/marker.ts +1 -1
- package/src/ui/popup.ts +1 -1
- package/src/util/throttle.ts +7 -3
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"
|
|
1
|
+
{"name":"maplibre-gl","type":"commonjs","deprecated":"Please install maplibre-gl from parent directory instead"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maplibre-gl",
|
|
3
3
|
"description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.1",
|
|
5
5
|
"main": "dist/maplibre-gl.js",
|
|
6
6
|
"style": "dist/maplibre-gl.css",
|
|
7
7
|
"license": "BSD-3-Clause",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@mapbox/mapbox-gl-rtl-text": "^0.2.3",
|
|
44
44
|
"@mapbox/mvt-fixtures": "^3.10.0",
|
|
45
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
45
|
+
"@rollup/plugin-commonjs": "^25.0.4",
|
|
46
46
|
"@rollup/plugin-json": "^6.0.0",
|
|
47
|
-
"@rollup/plugin-node-resolve": "^15.1
|
|
47
|
+
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
48
48
|
"@rollup/plugin-replace": "^5.0.2",
|
|
49
49
|
"@rollup/plugin-strip": "^3.0.2",
|
|
50
50
|
"@rollup/plugin-terser": "^0.4.3",
|
|
51
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
51
|
+
"@rollup/plugin-typescript": "^11.1.3",
|
|
52
52
|
"@types/benchmark": "^2.1.2",
|
|
53
53
|
"@types/cssnano": "^5.0.0",
|
|
54
54
|
"@types/d3": "^7.4.0",
|
|
@@ -58,38 +58,38 @@
|
|
|
58
58
|
"@types/gl": "^6.0.2",
|
|
59
59
|
"@types/glob": "^8.1.0",
|
|
60
60
|
"@types/jest": "^29.5.3",
|
|
61
|
-
"@types/jsdom": "^21.1.
|
|
61
|
+
"@types/jsdom": "^21.1.2",
|
|
62
62
|
"@types/minimist": "^1.2.2",
|
|
63
63
|
"@types/murmurhash-js": "^1.0.4",
|
|
64
64
|
"@types/nise": "^1.4.1",
|
|
65
|
-
"@types/node": "^20.
|
|
65
|
+
"@types/node": "^20.5.7",
|
|
66
66
|
"@types/offscreencanvas": "^2019.7.0",
|
|
67
67
|
"@types/pixelmatch": "^5.2.4",
|
|
68
68
|
"@types/pngjs": "^6.0.1",
|
|
69
|
-
"@types/react": "^18.2.
|
|
69
|
+
"@types/react": "^18.2.21",
|
|
70
70
|
"@types/react-dom": "^18.2.7",
|
|
71
71
|
"@types/request": "^2.48.8",
|
|
72
72
|
"@types/shuffle-seed": "^1.1.0",
|
|
73
73
|
"@types/window-or-global": "^1.0.4",
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
75
|
-
"@typescript-eslint/parser": "^6.
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
|
75
|
+
"@typescript-eslint/parser": "^6.4.1",
|
|
76
76
|
"address": "^1.2.2",
|
|
77
77
|
"benchmark": "^2.1.4",
|
|
78
78
|
"canvas": "^2.11.2",
|
|
79
79
|
"cssnano": "^6.0.1",
|
|
80
80
|
"d3": "^7.8.5",
|
|
81
81
|
"d3-queue": "^3.0.7",
|
|
82
|
-
"devtools-protocol": "^0.0.
|
|
82
|
+
"devtools-protocol": "^0.0.1188743",
|
|
83
83
|
"diff": "^5.1.0",
|
|
84
84
|
"dts-bundle-generator": "^8.0.1",
|
|
85
|
-
"eslint": "^8.
|
|
85
|
+
"eslint": "^8.48.0",
|
|
86
86
|
"eslint-config-mourner": "^3.0.0",
|
|
87
87
|
"eslint-plugin-html": "^7.1.0",
|
|
88
|
-
"eslint-plugin-import": "^2.28.
|
|
88
|
+
"eslint-plugin-import": "^2.28.1",
|
|
89
89
|
"eslint-plugin-jest": "^27.2.3",
|
|
90
|
-
"eslint-plugin-react": "^7.33.
|
|
90
|
+
"eslint-plugin-react": "^7.33.2",
|
|
91
91
|
"eslint-plugin-tsdoc": "0.2.17",
|
|
92
|
-
"expect": "^29.6.
|
|
92
|
+
"expect": "^29.6.4",
|
|
93
93
|
"gl": "^6.0.2",
|
|
94
94
|
"glob": "^10.3.3",
|
|
95
95
|
"is-builtin-module": "^3.2.1",
|
|
@@ -107,28 +107,28 @@
|
|
|
107
107
|
"pdf-merger-js": "^4.3.0",
|
|
108
108
|
"pixelmatch": "^5.3.0",
|
|
109
109
|
"pngjs": "^7.0.0",
|
|
110
|
-
"postcss": "^8.4.
|
|
110
|
+
"postcss": "^8.4.28",
|
|
111
111
|
"postcss-cli": "^10.1.0",
|
|
112
112
|
"postcss-inline-svg": "^6.0.0",
|
|
113
113
|
"pretty-bytes": "^6.1.1",
|
|
114
|
-
"puppeteer": "^21.0
|
|
114
|
+
"puppeteer": "^21.1.0",
|
|
115
115
|
"react": "^18.2.0",
|
|
116
116
|
"react-dom": "^18.2.0",
|
|
117
|
-
"rollup": "^3.
|
|
117
|
+
"rollup": "^3.28.1",
|
|
118
118
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
119
119
|
"rw": "^1.3.3",
|
|
120
120
|
"semver": "^7.5.4",
|
|
121
121
|
"shuffle-seed": "^1.1.6",
|
|
122
122
|
"source-map-explorer": "^2.5.3",
|
|
123
123
|
"st": "^3.0.0",
|
|
124
|
-
"stylelint": "^15.10.
|
|
124
|
+
"stylelint": "^15.10.3",
|
|
125
125
|
"stylelint-config-standard": "^34.0.0",
|
|
126
126
|
"ts-jest": "^29.1.1",
|
|
127
127
|
"ts-node": "^10.9.1",
|
|
128
|
-
"tslib": "^2.6.
|
|
128
|
+
"tslib": "^2.6.2",
|
|
129
129
|
"typedoc": "^0.24.8",
|
|
130
|
-
"typedoc-plugin-markdown": "^3.
|
|
131
|
-
"typedoc-plugin-missing-exports": "^2.0
|
|
130
|
+
"typedoc-plugin-markdown": "^3.16.0",
|
|
131
|
+
"typedoc-plugin-missing-exports": "^2.1.0",
|
|
132
132
|
"typescript": "^5.1.6"
|
|
133
133
|
},
|
|
134
134
|
"overrides": {
|
|
@@ -159,6 +159,7 @@
|
|
|
159
159
|
"build-benchmarks": "npm run build-dev && rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts",
|
|
160
160
|
"watch-benchmarks": "rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts --watch",
|
|
161
161
|
"start-server": "st --no-cache -H 0.0.0.0 --port 9966 .",
|
|
162
|
+
"start-docs": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material",
|
|
162
163
|
"start": "run-p watch-css watch-dev start-server",
|
|
163
164
|
"start-bench": "run-p watch-css watch-benchmarks start-server",
|
|
164
165
|
"lint": "eslint --cache --ext .ts,.tsx,.js,.html --ignore-path .gitignore .",
|
package/src/render/program.ts
CHANGED
|
@@ -89,6 +89,11 @@ export class Program<Us extends UniformBindings> {
|
|
|
89
89
|
}
|
|
90
90
|
gl.shaderSource(fragmentShader, fragmentSource);
|
|
91
91
|
gl.compileShader(fragmentShader);
|
|
92
|
+
|
|
93
|
+
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
94
|
+
throw new Error(`Could not compile fragment shader: ${gl.getShaderInfoLog(fragmentShader)}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
92
97
|
gl.attachShader(this.program, fragmentShader);
|
|
93
98
|
|
|
94
99
|
const vertexShader = gl.createShader(gl.VERTEX_SHADER);
|
|
@@ -98,6 +103,11 @@ export class Program<Us extends UniformBindings> {
|
|
|
98
103
|
}
|
|
99
104
|
gl.shaderSource(vertexShader, vertexSource);
|
|
100
105
|
gl.compileShader(vertexShader);
|
|
106
|
+
|
|
107
|
+
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
108
|
+
throw new Error(`Could not compile vertex shader: ${gl.getShaderInfoLog(vertexShader)}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
gl.attachShader(this.program, vertexShader);
|
|
102
112
|
|
|
103
113
|
this.attributes = {};
|
|
@@ -113,6 +123,11 @@ export class Program<Us extends UniformBindings> {
|
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
gl.linkProgram(this.program);
|
|
126
|
+
|
|
127
|
+
if (!gl.getProgramParameter(this.program, gl.LINK_STATUS)) {
|
|
128
|
+
throw new Error(`Program failed to link: ${gl.getProgramInfoLog(this.program)}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
116
131
|
gl.deleteShader(vertexShader);
|
|
117
132
|
gl.deleteShader(fragmentShader);
|
|
118
133
|
|
|
@@ -52,7 +52,6 @@ export type VectorTileSourceOptions = VectorSourceSpecification & {
|
|
|
52
52
|
* map.getSource('some id').setTiles(['https://d25uarhxywzl1j.cloudfront.net/v0.1/{z}/{x}/{y}.mvt']);
|
|
53
53
|
* ```
|
|
54
54
|
* @see [Add a vector tile source](https://maplibre.org/maplibre-gl-js/docs/examples/vector-source/)
|
|
55
|
-
* @see [Add a third party vector tile source](https://maplibre.org/maplibre-gl-js/docs/examples/third-party/)
|
|
56
55
|
*/
|
|
57
56
|
export class VectorTileSource extends Evented implements Source {
|
|
58
57
|
type: 'vector';
|
|
@@ -48,6 +48,10 @@ import type {VideoSourceSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
|
48
48
|
* map.removeSource('some id'); // remove
|
|
49
49
|
* ```
|
|
50
50
|
* @see [Add a video](https://maplibre.org/maplibre-gl-js/docs/examples/video-on-a-map/)
|
|
51
|
+
*
|
|
52
|
+
* Note that when rendered as a raster layer, the layer's `raster-fade-duration` property will cause the video to fade in.
|
|
53
|
+
* This happens when playback is started, paused and resumed, or when the video's coordinates are updated. To avoid this behavior,
|
|
54
|
+
* set the layer's `raster-fade-duration` property to `0`.
|
|
51
55
|
*/
|
|
52
56
|
export class VideoSource extends ImageSource {
|
|
53
57
|
options: VideoSourceSpecification;
|
package/src/style/style.ts
CHANGED
|
@@ -191,6 +191,12 @@ export type StyleSwapOptions = {
|
|
|
191
191
|
transformStyle?: TransformStyleFunction;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Specifies a layer to be added to a {@link Style}. In addition to a standard {@link LayerSpecification}
|
|
196
|
+
* or a {@link CustomLayerInterface}, a {@link LayerSpecification} with an embedded {@link SourceSpecification} can also be provided.
|
|
197
|
+
*/
|
|
198
|
+
export type AddLayerObject = LayerSpecification | (Omit<LayerSpecification, 'source'> & {source: SourceSpecification}) | CustomLayerInterface;
|
|
199
|
+
|
|
194
200
|
/**
|
|
195
201
|
* The Style base class
|
|
196
202
|
*/
|
|
@@ -362,7 +368,7 @@ export class Style extends Evented {
|
|
|
362
368
|
|
|
363
369
|
this.light = new Light(this.stylesheet.light);
|
|
364
370
|
|
|
365
|
-
this.map.setTerrain(this.stylesheet.terrain);
|
|
371
|
+
this.map.setTerrain(this.stylesheet.terrain ?? null);
|
|
366
372
|
|
|
367
373
|
this.fire(new Event('data', {dataType: 'style'}));
|
|
368
374
|
this.fire(new Event('style.load'));
|
|
@@ -848,7 +854,7 @@ export class Style extends Evented {
|
|
|
848
854
|
* @param options - Style setter options.
|
|
849
855
|
* @returns `this`.
|
|
850
856
|
*/
|
|
851
|
-
addLayer(layerObject:
|
|
857
|
+
addLayer(layerObject: AddLayerObject, before?: string, options: StyleSetterOptions = {}): this {
|
|
852
858
|
this._checkLoaded();
|
|
853
859
|
|
|
854
860
|
const id = layerObject.id;
|
|
@@ -858,7 +864,7 @@ export class Style extends Evented {
|
|
|
858
864
|
return;
|
|
859
865
|
}
|
|
860
866
|
|
|
861
|
-
let layer
|
|
867
|
+
let layer: ReturnType<typeof createStyleLayer>;
|
|
862
868
|
if (layerObject.type === 'custom') {
|
|
863
869
|
|
|
864
870
|
if (emitValidationErrors(this, validateCustomStyleLayer(layerObject))) return;
|
|
@@ -866,17 +872,17 @@ export class Style extends Evented {
|
|
|
866
872
|
layer = createStyleLayer(layerObject);
|
|
867
873
|
|
|
868
874
|
} else {
|
|
869
|
-
if (
|
|
870
|
-
this.addSource(id,
|
|
875
|
+
if ('source' in layerObject && typeof layerObject.source === 'object') {
|
|
876
|
+
this.addSource(id, layerObject.source);
|
|
871
877
|
layerObject = clone(layerObject);
|
|
872
|
-
layerObject =
|
|
878
|
+
layerObject = extend(layerObject, {source: id});
|
|
873
879
|
}
|
|
874
880
|
|
|
875
881
|
// this layer is not in the style.layers array, so we pass an impossible array index
|
|
876
882
|
if (this._validate(validateStyle.layer,
|
|
877
883
|
`layers.${id}`, layerObject, {arrayIndex: -1}, options)) return;
|
|
878
884
|
|
|
879
|
-
layer = createStyleLayer(layerObject);
|
|
885
|
+
layer = createStyleLayer(layerObject as LayerSpecification | CustomLayerInterface);
|
|
880
886
|
this._validateLayer(layer);
|
|
881
887
|
|
|
882
888
|
layer.setEventedParent(this, {layer: {id}});
|
|
@@ -994,7 +1000,7 @@ export class Style extends Evented {
|
|
|
994
1000
|
* @param id - id of the desired layer
|
|
995
1001
|
* @returns a layer, if one with the given `id` exists
|
|
996
1002
|
*/
|
|
997
|
-
getLayer(id: string): StyleLayer {
|
|
1003
|
+
getLayer(id: string): StyleLayer | undefined {
|
|
998
1004
|
return this._layers[id];
|
|
999
1005
|
}
|
|
1000
1006
|
|
|
@@ -32,7 +32,7 @@ export function evaluateVariableOffset(anchor: TextAnchor, offset: [number, numb
|
|
|
32
32
|
let x = 0, y = 0;
|
|
33
33
|
if (radialOffset < 0) radialOffset = 0; // Ignore negative offset.
|
|
34
34
|
// solve for r where r^2 + r^2 = radialOffset^2
|
|
35
|
-
const hypotenuse = radialOffset / Math.
|
|
35
|
+
const hypotenuse = radialOffset / Math.SQRT2;
|
|
36
36
|
switch (anchor) {
|
|
37
37
|
case 'top-right':
|
|
38
38
|
case 'top-left':
|
|
@@ -43,7 +43,6 @@ const defaultOptions: NavigationOptions = {
|
|
|
43
43
|
* map.addControl(nav, 'top-left');
|
|
44
44
|
* ```
|
|
45
45
|
* @see [Display map navigation controls](https://maplibre.org/maplibre-gl-js/docs/examples/navigation/)
|
|
46
|
-
* @see [Add a third party vector tile source](https://maplibre.org/maplibre-gl-js/docs/examples/third-party/)
|
|
47
46
|
*/
|
|
48
47
|
export class NavigationControl implements IControl {
|
|
49
48
|
_map: Map;
|
package/src/ui/map.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {OverscaledTileID} from '../source/tile_id';
|
|
|
6
6
|
import {Event, ErrorEvent} from '../util/evented';
|
|
7
7
|
import simulate from '../../test/unit/lib/simulate_interaction';
|
|
8
8
|
import {fixedLngLat, fixedNum} from '../../test/unit/lib/fixed';
|
|
9
|
-
import {LayerSpecification, SourceSpecification, StyleSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
9
|
+
import {GeoJSONSourceSpecification, LayerSpecification, SourceSpecification, StyleSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
10
10
|
import {RequestTransformFunction} from '../util/request_manager';
|
|
11
11
|
import {extend} from '../util/util';
|
|
12
12
|
import {LngLatBoundsLike} from '../geo/lng_lat_bounds';
|
|
@@ -675,6 +675,19 @@ describe('Map', () => {
|
|
|
675
675
|
map.addSource('fill', source);
|
|
676
676
|
});
|
|
677
677
|
|
|
678
|
+
test('a layer can be added with an embedded source specification', () => {
|
|
679
|
+
const map = createMap({deleteStyle: true});
|
|
680
|
+
const source: GeoJSONSourceSpecification = {
|
|
681
|
+
type: 'geojson',
|
|
682
|
+
data: {type: 'Point', coordinates: [0, 0]}
|
|
683
|
+
};
|
|
684
|
+
map.addLayer({
|
|
685
|
+
id: 'foo',
|
|
686
|
+
type: 'symbol',
|
|
687
|
+
source
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
|
|
678
691
|
test('returns the style with added source and layer', done => {
|
|
679
692
|
const style = createStyle();
|
|
680
693
|
const map = createMap({style});
|
|
@@ -848,21 +861,30 @@ describe('Map', () => {
|
|
|
848
861
|
|
|
849
862
|
const map = createMap();
|
|
850
863
|
|
|
851
|
-
const
|
|
852
|
-
const
|
|
864
|
+
const updateSpy = jest.spyOn(map, '_update');
|
|
865
|
+
const resizeSpy = jest.spyOn(map, 'resize');
|
|
853
866
|
|
|
854
867
|
// The initial "observe" event fired by ResizeObserver should be captured/muted
|
|
855
868
|
// in the map constructor
|
|
856
869
|
|
|
857
870
|
observerCallback();
|
|
858
|
-
expect(
|
|
859
|
-
expect(
|
|
871
|
+
expect(updateSpy).not.toHaveBeenCalled();
|
|
872
|
+
expect(resizeSpy).not.toHaveBeenCalled();
|
|
873
|
+
|
|
874
|
+
// The next "observe" event should fire a resize / _update
|
|
860
875
|
|
|
861
|
-
|
|
876
|
+
observerCallback();
|
|
877
|
+
expect(updateSpy).toHaveBeenCalled();
|
|
878
|
+
expect(resizeSpy).toHaveBeenCalledTimes(1);
|
|
862
879
|
|
|
880
|
+
// Additional "observe" events should be throttled
|
|
881
|
+
observerCallback();
|
|
882
|
+
observerCallback();
|
|
863
883
|
observerCallback();
|
|
864
|
-
|
|
865
|
-
expect(
|
|
884
|
+
observerCallback();
|
|
885
|
+
expect(resizeSpy).toHaveBeenCalledTimes(1);
|
|
886
|
+
await new Promise((resolve) => { setTimeout(resolve, 100); });
|
|
887
|
+
expect(resizeSpy).toHaveBeenCalledTimes(2);
|
|
866
888
|
});
|
|
867
889
|
|
|
868
890
|
test('width and height correctly rounded', () => {
|
|
@@ -2569,6 +2591,13 @@ describe('Map', () => {
|
|
|
2569
2591
|
});
|
|
2570
2592
|
});
|
|
2571
2593
|
|
|
2594
|
+
describe('#getTerrain', () => {
|
|
2595
|
+
test('returns null when not set', () => {
|
|
2596
|
+
const map = createMap();
|
|
2597
|
+
expect(map.getTerrain()).toBeNull();
|
|
2598
|
+
});
|
|
2599
|
+
});
|
|
2600
|
+
|
|
2572
2601
|
describe('#setCooperativeGestures', () => {
|
|
2573
2602
|
test('returns self', () => {
|
|
2574
2603
|
const map = createMap();
|
package/src/ui/map.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {RGBAImage} from '../util/image';
|
|
|
25
25
|
import {Event, ErrorEvent, Listener} from '../util/evented';
|
|
26
26
|
import {MapEventType, MapLayerEventType, MapMouseEvent, MapSourceDataEvent, MapStyleDataEvent} from './events';
|
|
27
27
|
import {TaskQueue} from '../util/task_queue';
|
|
28
|
+
import {throttle} from '../util/throttle';
|
|
28
29
|
import {webpSupported} from '../util/webp_supported';
|
|
29
30
|
import {PerformanceMarkers, PerformanceUtils} from '../util/performance';
|
|
30
31
|
import {Source, SourceClass} from '../source/source';
|
|
@@ -33,9 +34,8 @@ import {StyleLayer} from '../style/style_layer';
|
|
|
33
34
|
import type {RequestTransformFunction} from '../util/request_manager';
|
|
34
35
|
import type {LngLatLike} from '../geo/lng_lat';
|
|
35
36
|
import type {LngLatBoundsLike} from '../geo/lng_lat_bounds';
|
|
36
|
-
import type {FeatureIdentifier, StyleOptions, StyleSetterOptions} from '../style/style';
|
|
37
|
+
import type {AddLayerObject, FeatureIdentifier, StyleOptions, StyleSetterOptions} from '../style/style';
|
|
37
38
|
import type {MapDataEvent} from './events';
|
|
38
|
-
import type {CustomLayerInterface} from '../style/style_layer/custom_style_layer';
|
|
39
39
|
import type {StyleImage, StyleImageInterface, StyleImageMetadata} from '../style/style_image';
|
|
40
40
|
import type {PointLike} from './camera';
|
|
41
41
|
import type {ScrollZoomHandler} from './handler/scroll_zoom';
|
|
@@ -51,7 +51,6 @@ import {defaultLocale} from './default_locale';
|
|
|
51
51
|
import type {TaskID} from '../util/task_queue';
|
|
52
52
|
import type {Cancelable} from '../types/cancelable';
|
|
53
53
|
import type {
|
|
54
|
-
LayerSpecification,
|
|
55
54
|
FilterSpecification,
|
|
56
55
|
StyleSpecification,
|
|
57
56
|
LightSpecification,
|
|
@@ -640,15 +639,17 @@ export class Map extends Camera {
|
|
|
640
639
|
if (typeof window !== 'undefined') {
|
|
641
640
|
addEventListener('online', this._onWindowOnline, false);
|
|
642
641
|
let initialResizeEventCaptured = false;
|
|
642
|
+
const throttledResizeCallback = throttle((entries: ResizeObserverEntry[]) => {
|
|
643
|
+
if (this._trackResize && !this._removed) {
|
|
644
|
+
this.resize(entries)._update();
|
|
645
|
+
}
|
|
646
|
+
}, 50);
|
|
643
647
|
this._resizeObserver = new ResizeObserver((entries) => {
|
|
644
648
|
if (!initialResizeEventCaptured) {
|
|
645
649
|
initialResizeEventCaptured = true;
|
|
646
650
|
return;
|
|
647
651
|
}
|
|
648
|
-
|
|
649
|
-
if (this._trackResize) {
|
|
650
|
-
this.resize(entries)._update();
|
|
651
|
-
}
|
|
652
|
+
throttledResizeCallback(entries);
|
|
652
653
|
});
|
|
653
654
|
this._resizeObserver.observe(this._container);
|
|
654
655
|
}
|
|
@@ -1962,7 +1963,7 @@ export class Map extends Camera {
|
|
|
1962
1963
|
* map.setTerrain({ source: 'terrain' });
|
|
1963
1964
|
* ```
|
|
1964
1965
|
*/
|
|
1965
|
-
setTerrain(options: TerrainSpecification): this {
|
|
1966
|
+
setTerrain(options: TerrainSpecification | null): this {
|
|
1966
1967
|
this.style._checkLoaded();
|
|
1967
1968
|
|
|
1968
1969
|
// clear event handlers
|
|
@@ -2017,8 +2018,8 @@ export class Map extends Camera {
|
|
|
2017
2018
|
* map.getTerrain(); // { source: 'terrain' };
|
|
2018
2019
|
* ```
|
|
2019
2020
|
*/
|
|
2020
|
-
getTerrain(): TerrainSpecification {
|
|
2021
|
-
return this.terrain
|
|
2021
|
+
getTerrain(): TerrainSpecification | null {
|
|
2022
|
+
return this.terrain?.options ?? null;
|
|
2022
2023
|
}
|
|
2023
2024
|
|
|
2024
2025
|
/**
|
|
@@ -2346,7 +2347,7 @@ export class Map extends Camera {
|
|
|
2346
2347
|
*
|
|
2347
2348
|
* @param layer - The layer to add,
|
|
2348
2349
|
* conforming to either the MapLibre Style Specification's [layer definition](https://maplibre.org/maplibre-style-spec/layers) or,
|
|
2349
|
-
* less commonly, the {@link CustomLayerInterface} specification.
|
|
2350
|
+
* less commonly, the {@link CustomLayerInterface} specification. Can also be a layer definition with an embedded source definition.
|
|
2350
2351
|
* The MapLibre Style Specification's layer definition is appropriate for most layers.
|
|
2351
2352
|
*
|
|
2352
2353
|
* @param beforeId - The ID of an existing layer to insert the new layer before,
|
|
@@ -2418,7 +2419,7 @@ export class Map extends Camera {
|
|
|
2418
2419
|
* @see [Add a vector tile source](https://maplibre.org/maplibre-gl-js/docs/examples/vector-source/)
|
|
2419
2420
|
* @see [Add a WMS source](https://maplibre.org/maplibre-gl-js/docs/examples/wms/)
|
|
2420
2421
|
*/
|
|
2421
|
-
addLayer(layer:
|
|
2422
|
+
addLayer(layer: AddLayerObject, beforeId?: string) {
|
|
2422
2423
|
this._lazyInitEmptyStyle();
|
|
2423
2424
|
this.style.addLayer(layer, beforeId);
|
|
2424
2425
|
return this._update(true);
|
|
@@ -2475,7 +2476,7 @@ export class Map extends Camera {
|
|
|
2475
2476
|
* @see [Filter symbols by toggling a list](https://maplibre.org/maplibre-gl-js/docs/examples/filter-markers/)
|
|
2476
2477
|
* @see [Filter symbols by text input](https://maplibre.org/maplibre-gl-js/docs/examples/filter-markers-by-input/)
|
|
2477
2478
|
*/
|
|
2478
|
-
getLayer(id: string): StyleLayer {
|
|
2479
|
+
getLayer(id: string): StyleLayer | undefined {
|
|
2479
2480
|
return this.style.getLayer(id);
|
|
2480
2481
|
}
|
|
2481
2482
|
|
package/src/ui/marker.ts
CHANGED
|
@@ -419,7 +419,7 @@ export class Marker extends Evented {
|
|
|
419
419
|
if (!('offset' in popup.options)) {
|
|
420
420
|
const markerHeight = 41 - (5.8 / 2);
|
|
421
421
|
const markerRadius = 13.5;
|
|
422
|
-
const linearOffset = Math.
|
|
422
|
+
const linearOffset = Math.abs(markerRadius) / Math.SQRT2;
|
|
423
423
|
popup.options.offset = this._defaultMarker ? {
|
|
424
424
|
'top': [0, 0],
|
|
425
425
|
'top-left': [0, 0],
|
package/src/ui/popup.ts
CHANGED
|
@@ -627,7 +627,7 @@ function normalizeOffset(offset?: Offset | null) {
|
|
|
627
627
|
|
|
628
628
|
} else if (typeof offset === 'number') {
|
|
629
629
|
// input specifies a radius from which to calculate offsets at all positions
|
|
630
|
-
const cornerOffset = Math.round(Math.
|
|
630
|
+
const cornerOffset = Math.round(Math.abs(offset) / Math.SQRT2);
|
|
631
631
|
return {
|
|
632
632
|
'center': new Point(0, 0),
|
|
633
633
|
'top': new Point(0, offset),
|
package/src/util/throttle.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Throttle the given function to run at most every `period` milliseconds.
|
|
3
3
|
*/
|
|
4
|
-
export function throttle(
|
|
4
|
+
export function throttle<T extends (...args: any) => void>(fn: T, time: number): (...args: Parameters<T>) => ReturnType<typeof setTimeout> {
|
|
5
5
|
let pending = false;
|
|
6
6
|
let timerId: ReturnType<typeof setTimeout> = null;
|
|
7
|
+
let lastCallContext = null;
|
|
8
|
+
let lastCallArgs: Parameters<T>;
|
|
7
9
|
|
|
8
10
|
const later = () => {
|
|
9
11
|
timerId = null;
|
|
10
12
|
if (pending) {
|
|
11
|
-
fn();
|
|
13
|
+
fn.apply(lastCallContext, lastCallArgs);
|
|
12
14
|
timerId = setTimeout(later, time);
|
|
13
15
|
pending = false;
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
17
|
-
return () => {
|
|
19
|
+
return (...args: Parameters<T>) => {
|
|
18
20
|
pending = true;
|
|
21
|
+
lastCallContext = this;
|
|
22
|
+
lastCallArgs = args;
|
|
19
23
|
if (!timerId) {
|
|
20
24
|
later();
|
|
21
25
|
}
|