maplibre-gl 3.0.1 → 3.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.
Files changed (101) hide show
  1. package/README.md +7 -7
  2. package/build/generate-shaders.ts +39 -6
  3. package/build/readme.md +0 -5
  4. package/dist/maplibre-gl-csp-worker.js +1 -1
  5. package/dist/maplibre-gl-csp-worker.js.map +1 -1
  6. package/dist/maplibre-gl-csp.js +1 -1
  7. package/dist/maplibre-gl-csp.js.map +1 -1
  8. package/dist/maplibre-gl-dev.js +185 -142
  9. package/dist/maplibre-gl-dev.js.map +1 -1
  10. package/dist/maplibre-gl.d.ts +44 -40
  11. package/dist/maplibre-gl.js +4 -4
  12. package/dist/maplibre-gl.js.map +1 -1
  13. package/package.json +33 -32
  14. package/src/geo/lng_lat.ts +2 -2
  15. package/src/gl/context.ts +27 -10
  16. package/src/gl/types.ts +14 -14
  17. package/src/gl/value.ts +11 -3
  18. package/src/gl/vertex_buffer.ts +2 -2
  19. package/src/gl/webgl2.ts +12 -0
  20. package/src/render/draw_heatmap.ts +1 -0
  21. package/src/render/painter.ts +1 -1
  22. package/src/render/program.ts +1 -4
  23. package/src/render/texture.ts +4 -4
  24. package/src/render/uniform_binding.ts +1 -1
  25. package/src/shaders/README.md +2 -2
  26. package/src/shaders/_prelude.fragment.glsl.g.ts +1 -1
  27. package/src/shaders/_prelude.vertex.glsl.g.ts +1 -1
  28. package/src/shaders/background.fragment.glsl.g.ts +1 -1
  29. package/src/shaders/background.vertex.glsl.g.ts +1 -1
  30. package/src/shaders/background_pattern.fragment.glsl.g.ts +1 -1
  31. package/src/shaders/background_pattern.vertex.glsl.g.ts +1 -1
  32. package/src/shaders/circle.fragment.glsl.g.ts +1 -1
  33. package/src/shaders/circle.vertex.glsl.g.ts +1 -1
  34. package/src/shaders/clipping_mask.fragment.glsl.g.ts +1 -1
  35. package/src/shaders/clipping_mask.vertex.glsl.g.ts +1 -1
  36. package/src/shaders/collision_box.fragment.glsl.g.ts +1 -1
  37. package/src/shaders/collision_box.vertex.glsl.g.ts +1 -1
  38. package/src/shaders/collision_circle.fragment.glsl.g.ts +1 -1
  39. package/src/shaders/collision_circle.vertex.glsl.g.ts +1 -1
  40. package/src/shaders/debug.fragment.glsl.g.ts +1 -1
  41. package/src/shaders/debug.vertex.glsl.g.ts +1 -1
  42. package/src/shaders/fill.fragment.glsl.g.ts +1 -1
  43. package/src/shaders/fill.vertex.glsl.g.ts +1 -1
  44. package/src/shaders/fill_extrusion.fragment.glsl.g.ts +1 -1
  45. package/src/shaders/fill_extrusion.vertex.glsl.g.ts +1 -1
  46. package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +1 -1
  47. package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +1 -1
  48. package/src/shaders/fill_outline.fragment.glsl.g.ts +1 -1
  49. package/src/shaders/fill_outline.vertex.glsl.g.ts +1 -1
  50. package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +1 -1
  51. package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +1 -1
  52. package/src/shaders/fill_pattern.fragment.glsl.g.ts +1 -1
  53. package/src/shaders/fill_pattern.vertex.glsl.g.ts +1 -1
  54. package/src/shaders/heatmap.fragment.glsl.g.ts +1 -1
  55. package/src/shaders/heatmap.vertex.glsl.g.ts +1 -1
  56. package/src/shaders/heatmap_texture.fragment.glsl.g.ts +1 -1
  57. package/src/shaders/heatmap_texture.vertex.glsl.g.ts +1 -1
  58. package/src/shaders/hillshade.fragment.glsl.g.ts +1 -1
  59. package/src/shaders/hillshade.vertex.glsl.g.ts +1 -1
  60. package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +1 -1
  61. package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +1 -1
  62. package/src/shaders/line.fragment.glsl.g.ts +1 -1
  63. package/src/shaders/line.vertex.glsl.g.ts +1 -1
  64. package/src/shaders/line_gradient.fragment.glsl.g.ts +1 -1
  65. package/src/shaders/line_gradient.vertex.glsl.g.ts +1 -1
  66. package/src/shaders/line_pattern.fragment.glsl.g.ts +1 -1
  67. package/src/shaders/line_pattern.vertex.glsl.g.ts +1 -1
  68. package/src/shaders/line_sdf.fragment.glsl.g.ts +1 -1
  69. package/src/shaders/line_sdf.vertex.glsl.g.ts +1 -1
  70. package/src/shaders/raster.fragment.glsl.g.ts +1 -1
  71. package/src/shaders/raster.vertex.glsl.g.ts +1 -1
  72. package/src/shaders/shaders.ts +5 -5
  73. package/src/shaders/symbol_icon.fragment.glsl.g.ts +1 -1
  74. package/src/shaders/symbol_icon.vertex.glsl.g.ts +1 -1
  75. package/src/shaders/symbol_sdf.fragment.glsl.g.ts +1 -1
  76. package/src/shaders/symbol_sdf.vertex.glsl.g.ts +1 -1
  77. package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +1 -1
  78. package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +1 -1
  79. package/src/shaders/terrain.fragment.glsl.g.ts +1 -1
  80. package/src/shaders/terrain.vertex.glsl.g.ts +1 -1
  81. package/src/shaders/terrain_coords.fragment.glsl.g.ts +1 -1
  82. package/src/shaders/terrain_depth.fragment.glsl.g.ts +1 -1
  83. package/src/source/raster_dem_tile_source.ts +4 -3
  84. package/src/source/source_cache.ts +8 -3
  85. package/src/source/vector_tile_source.test.ts +11 -11
  86. package/src/source/vector_tile_worker_source.ts +1 -1
  87. package/src/style/style_layer/custom_style_layer.ts +6 -6
  88. package/src/ui/control/attribution_control.ts +1 -1
  89. package/src/ui/control/fullscreen_control.ts +1 -1
  90. package/src/ui/control/geolocate_control.ts +6 -6
  91. package/src/ui/control/navigation_control.ts +4 -4
  92. package/src/ui/control/scale_control.ts +1 -1
  93. package/src/ui/control/terrain_control.ts +4 -5
  94. package/src/ui/map.test.ts +11 -0
  95. package/src/ui/map.ts +19 -12
  96. package/src/ui/marker.ts +2 -2
  97. package/src/ui/popup.ts +2 -2
  98. package/src/util/browser.ts +2 -2
  99. package/src/util/config.ts +2 -0
  100. package/src/util/test/mock_webgl.ts +4 -1
  101. package/src/util/webp_supported.ts +3 -3
@@ -41,7 +41,7 @@ describe('VectorTileSource', () => {
41
41
  const source = createSource({
42
42
  minzoom: 1,
43
43
  maxzoom: 10,
44
- attribution: 'Maplibre',
44
+ attribution: 'MapLibre',
45
45
  tiles: ['http://example.com/{z}/{x}/{y}.png']
46
46
  });
47
47
 
@@ -50,7 +50,7 @@ describe('VectorTileSource', () => {
50
50
  expect(source.tiles).toEqual(['http://example.com/{z}/{x}/{y}.png']);
51
51
  expect(source.minzoom).toBe(1);
52
52
  expect(source.maxzoom).toBe(10);
53
- expect((source as Source).attribution).toBe('Maplibre');
53
+ expect((source as Source).attribution).toBe('MapLibre');
54
54
  done();
55
55
  }
56
56
  });
@@ -66,7 +66,7 @@ describe('VectorTileSource', () => {
66
66
  expect(source.tiles).toEqual(['http://example.com/{z}/{x}/{y}.png']);
67
67
  expect(source.minzoom).toBe(1);
68
68
  expect(source.maxzoom).toBe(10);
69
- expect((source as Source).attribution).toBe('Maplibre');
69
+ expect((source as Source).attribution).toBe('MapLibre');
70
70
  done();
71
71
  }
72
72
  });
@@ -125,14 +125,14 @@ describe('VectorTileSource', () => {
125
125
  const source = createSource({
126
126
  minzoom: 1,
127
127
  maxzoom: 10,
128
- attribution: 'Maplibre',
128
+ attribution: 'MapLibre',
129
129
  tiles: ['http://example.com/{z}/{x}/{y}.png']
130
130
  });
131
131
  expect(source.serialize()).toEqual({
132
132
  type: 'vector',
133
133
  minzoom: 1,
134
134
  maxzoom: 10,
135
- attribution: 'Maplibre',
135
+ attribution: 'MapLibre',
136
136
  tiles: ['http://example.com/{z}/{x}/{y}.png']
137
137
  });
138
138
  });
@@ -142,7 +142,7 @@ describe('VectorTileSource', () => {
142
142
  const source = createSource({
143
143
  minzoom: 1,
144
144
  maxzoom: 10,
145
- attribution: 'Maplibre',
145
+ attribution: 'MapLibre',
146
146
  tiles: ['http://example.com/{z}/{x}/{y}.png'],
147
147
  scheme
148
148
  });
@@ -229,7 +229,7 @@ describe('VectorTileSource', () => {
229
229
  const source = createSource({
230
230
  minzoom: 0,
231
231
  maxzoom: 22,
232
- attribution: 'Maplibre',
232
+ attribution: 'MapLibre',
233
233
  tiles: ['http://example.com/{z}/{x}/{y}.png'],
234
234
  bounds: [-47, -7, -45, -5]
235
235
  });
@@ -246,7 +246,7 @@ describe('VectorTileSource', () => {
246
246
  const source = createSource({
247
247
  minzoom: 0,
248
248
  maxzoom: 22,
249
- attribution: 'Maplibre',
249
+ attribution: 'MapLibre',
250
250
  tiles: ['http://example.com/{z}/{x}/{y}.png'],
251
251
  bounds: [-47, -7, -45, 91]
252
252
  });
@@ -263,7 +263,7 @@ describe('VectorTileSource', () => {
263
263
  server.respondWith('/source.json', JSON.stringify({
264
264
  minzoom: 0,
265
265
  maxzoom: 22,
266
- attribution: 'Maplibre',
266
+ attribution: 'MapLibre',
267
267
  tiles: ['http://example.com/{z}/{x}/{y}.png'],
268
268
  bounds: [-47, -7, -45, -5]
269
269
  }));
@@ -331,7 +331,7 @@ describe('VectorTileSource', () => {
331
331
  const source = createSource({
332
332
  minzoom: 1,
333
333
  maxzoom: 10,
334
- attribution: 'Maplibre',
334
+ attribution: 'MapLibre',
335
335
  tiles: ['http://example.com/{z}/{x}/{y}.png']
336
336
  });
337
337
  source.setTiles(['http://example2.com/{z}/{x}/{y}.png']);
@@ -339,7 +339,7 @@ describe('VectorTileSource', () => {
339
339
  type: 'vector',
340
340
  minzoom: 1,
341
341
  maxzoom: 10,
342
- attribution: 'Maplibre',
342
+ attribution: 'MapLibre',
343
343
  tiles: ['http://example2.com/{z}/{x}/{y}.png']
344
344
  });
345
345
  });
@@ -116,7 +116,7 @@ class VectorTileWorkerSource implements WorkerSource {
116
116
  }
117
117
 
118
118
  const rawTileData = response.rawData;
119
- const cacheControl = {} as {expires: any; cacheControl: any};
119
+ const cacheControl = {} as ExpiryData;
120
120
  if (response.expires) cacheControl.expires = response.expires;
121
121
  if (response.cacheControl) cacheControl.cacheControl = response.cacheControl;
122
122
 
@@ -3,7 +3,7 @@ import type Map from '../../ui/map';
3
3
  import {mat4} from 'gl-matrix';
4
4
  import {LayerSpecification} from '@maplibre/maplibre-gl-style-spec';
5
5
 
6
- type CustomRenderMethod = (gl: WebGL2RenderingContext, matrix: mat4) => void;
6
+ type CustomRenderMethod = (gl: WebGLRenderingContext|WebGL2RenderingContext, matrix: mat4) => void;
7
7
 
8
8
  /**
9
9
  * Interface for custom style layers. This is a specification for
@@ -103,7 +103,7 @@ export interface CustomLayerInterface {
103
103
  * @memberof CustomLayerInterface
104
104
  * @instance
105
105
  * @name render
106
- * @param {WebGL2RenderingContext} gl The map's gl context.
106
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The map's gl context.
107
107
  * @param {Array<number>} matrix The map's camera matrix. It projects spherical mercator
108
108
  * coordinates to gl coordinates. The spherical mercator coordinate `[0, 0]` represents the
109
109
  * top left corner of the mercator world and `[1, 1]` represents the bottom right corner. When
@@ -139,9 +139,9 @@ export interface CustomLayerInterface {
139
139
  * @instance
140
140
  * @name onAdd
141
141
  * @param {Map} map The Map this custom layer was just added to.
142
- * @param {WebGL2RenderingContext} gl The gl context for the map.
142
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The gl context for the map.
143
143
  */
144
- onAdd?(map: Map, gl: WebGL2RenderingContext): void;
144
+ onAdd?(map: Map, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
145
145
  /**
146
146
  * Optional method called when the layer has been removed from the Map with {@link Map#removeLayer}. This
147
147
  * gives the layer a chance to clean up gl resources and event listeners.
@@ -151,9 +151,9 @@ export interface CustomLayerInterface {
151
151
  * @instance
152
152
  * @name onRemove
153
153
  * @param {Map} map The Map this custom layer was just added to.
154
- * @param {WebGL2RenderingContext} gl The gl context for the map.
154
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The gl context for the map.
155
155
  */
156
- onRemove?(map: Map, gl: WebGL2RenderingContext): void;
156
+ onRemove?(map: Map, gl: WebGLRenderingContext | WebGL2RenderingContext): void;
157
157
  }
158
158
 
159
159
  export function validateCustomStyleLayer(layerObject: CustomLayerInterface) {
@@ -13,7 +13,7 @@ type AttributionOptions = {
13
13
  * An `AttributionControl` control presents the map's attribution information. By default, the attribution control is expanded (regardless of map width).
14
14
  *
15
15
  * @implements {IControl}
16
- * @param {Object} [options]
16
+ * @param {AttributionOptions} [options]
17
17
  * @param {boolean} [options.compact] If `true`, the attribution control will always collapse when moving the map. If `false`, force the expanded attribution control. The default is a responsive attribution that collapses when the user moves the map on maps less than 640 pixels wide. **Attribution should not be collapsed if it can comfortably fit on the map. `compact` should only be used to modify default attribution when map size makes it impossible to fit default attribution and when the automatic compact resizing for default settings are not sufficient.**
18
18
  * @param {string | Array<string>} [options.customAttribution] String or strings to show in addition to any other attributions.
19
19
  * @example
@@ -17,7 +17,7 @@ type FullscreenOptions = {
17
17
  * is in fullscreen mode, and is restored when the map exist fullscreen mode.
18
18
  *
19
19
  * @implements {IControl}
20
- * @param {Object} [options]
20
+ * @param {FullscreenOptions} [options]
21
21
  * @param {HTMLElement} [options.container] `container` is the [compatible DOM element](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#Compatible_elements) which should be made full screen. By default, the map container element will be made full screen.
22
22
  *
23
23
  * @example
@@ -55,12 +55,12 @@ let noTimeout = false;
55
55
  * These interaction states can't be controlled programmatically, rather they are set based on user interactions.
56
56
  *
57
57
  * @implements {IControl}
58
- * @param {Object} [options]
59
- * @param {Object} [options.positionOptions={enableHighAccuracy: false, timeout: 6000}] A Geolocation API [PositionOptions](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions) object.
60
- * @param {Object} [options.fitBoundsOptions={maxZoom: 15}] A {@link Map#fitBounds} options object to use when the map is panned and zoomed to the user's location. The default is to use a `maxZoom` of 15 to limit how far the map will zoom in for very accurate locations.
61
- * @param {Object} [options.trackUserLocation=false] If `true` the Geolocate Control becomes a toggle button and when active the map will receive updates to the user's location as it changes.
62
- * @param {Object} [options.showAccuracyCircle=true] By default, if showUserLocation is `true`, a transparent circle will be drawn around the user location indicating the accuracy (95% confidence level) of the user's location. Set to `false` to disable. Always disabled when showUserLocation is `false`.
63
- * @param {Object} [options.showUserLocation=true] By default a dot will be shown on the map at the user's location. Set to `false` to disable.
58
+ * @param {GeolocateOptions} [options]
59
+ * @param {PositionOptions} [options.positionOptions={enableHighAccuracy: false, timeout: 6000}] A Geolocation API [PositionOptions](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions) object.
60
+ * @param {FitBoundsOptions} [options.fitBoundsOptions={maxZoom: 15}] A {@link Map#fitBounds} options object to use when the map is panned and zoomed to the user's location. The default is to use a `maxZoom` of 15 to limit how far the map will zoom in for very accurate locations.
61
+ * @param {boolean} [options.trackUserLocation=false] If `true` the Geolocate Control becomes a toggle button and when active the map will receive updates to the user's location as it changes.
62
+ * @param {boolean} [options.showAccuracyCircle=true] By default, if showUserLocation is `true`, a transparent circle will be drawn around the user location indicating the accuracy (95% confidence level) of the user's location. Set to `false` to disable. Always disabled when showUserLocation is `false`.
63
+ * @param {boolean} [options.showUserLocation=true] By default a dot will be shown on the map at the user's location. Set to `false` to disable.
64
64
  *
65
65
  * @example
66
66
  * map.addControl(new maplibregl.GeolocateControl({
@@ -24,10 +24,10 @@ const defaultOptions: NavigationOptions = {
24
24
  * A `NavigationControl` control contains zoom buttons and a compass.
25
25
  *
26
26
  * @implements {IControl}
27
- * @param {Object} [options]
28
- * @param {Boolean} [options.showCompass=true] If `true` the compass button is included.
29
- * @param {Boolean} [options.showZoom=true] If `true` the zoom-in and zoom-out buttons are included.
30
- * @param {Boolean} [options.visualizePitch=false] If `true` the pitch is visualized by rotating X-axis of compass.
27
+ * @param {NavigationOptions} [options]
28
+ * @param {boolean} [options.showCompass=true] If `true` the compass button is included.
29
+ * @param {boolean} [options.showZoom=true] If `true` the zoom-in and zoom-out buttons are included.
30
+ * @param {boolean} [options.visualizePitch=false] If `true` the pitch is visualized by rotating X-axis of compass.
31
31
  * @example
32
32
  * var nav = new maplibregl.NavigationControl();
33
33
  * map.addControl(nav, 'top-left');
@@ -20,7 +20,7 @@ const defaultOptions: ScaleOptions = {
20
20
  * A `ScaleControl` control displays the ratio of a distance on the map to the corresponding distance on the ground.
21
21
  *
22
22
  * @implements {IControl}
23
- * @param {Object} [options]
23
+ * @param {ScaleOptions} [options]
24
24
  * @param {number} [options.maxWidth='100'] The maximum length of the scale control in pixels.
25
25
  * @param {string} [options.unit='metric'] Unit of the distance (`'imperial'`, `'metric'` or `'nautical'`).
26
26
  * @example
@@ -6,13 +6,12 @@ import type {IControl} from './control';
6
6
  import type {TerrainSpecification} from '@maplibre/maplibre-gl-style-spec';
7
7
 
8
8
  /**
9
- * An `TerrainControl` control adds a button to turn terrain on and off.
9
+ * A `TerrainControl` control contains a button for turning the terrain on and off.
10
10
  *
11
11
  * @implements {IControl}
12
- * @param {Object} [options]
13
- * @param {string} [options.id] The ID of the raster-dem source to use.
14
- * @param {Object} [options.options]
15
- * @param {number} [options.options.exaggeration]
12
+ * @param {TerrainSpecification} [options]
13
+ * @param {string} [options.source] The ID of the raster-dem source to use.
14
+ * @param {number} [options.exaggeration]
16
15
  * @example
17
16
  * var map = new maplibregl.Map({TerrainControl: false})
18
17
  * .addControl(new maplibregl.TerrainControl({
@@ -20,6 +20,7 @@ import Transform from '../geo/transform';
20
20
  import {StyleImageInterface} from '../style/style_image';
21
21
  import Style from '../style/style';
22
22
  import {MapSourceDataEvent} from './events';
23
+ import config from '../util/config';
23
24
 
24
25
  function createStyleSource() {
25
26
  return {
@@ -164,6 +165,16 @@ describe('Map', () => {
164
165
  });
165
166
 
166
167
  describe('#mapOptions', () => {
168
+ test('maxTileCacheZoomLevels: Default value is set', () => {
169
+ const map = createMap();
170
+ expect(map._maxTileCacheZoomLevels).toBe(config.MAX_TILE_CACHE_ZOOM_LEVELS);
171
+ });
172
+
173
+ test('maxTileCacheZoomLevels: Value can be set via map options', () => {
174
+ const map = createMap({maxTileCacheZoomLevels: 1});
175
+ expect(map._maxTileCacheZoomLevels).toBe(1);
176
+ });
177
+
167
178
  test('Style validation is enabled by default', () => {
168
179
  let validationOption = false;
169
180
  jest.spyOn(Style.prototype, 'loadJSON').mockImplementationOnce((styleJson, options) => {
package/src/ui/map.ts CHANGED
@@ -64,6 +64,7 @@ import type {ControlPosition, IControl} from './control/control';
64
64
  import type {MapGeoJSONFeature} from '../util/vectortile_to_geojson';
65
65
  import Terrain from '../render/terrain';
66
66
  import RenderToTexture from '../render/render_to_texture';
67
+ import config from '../util/config';
67
68
 
68
69
  const version = packageJSON.version;
69
70
  /* eslint-enable no-use-before-define */
@@ -101,6 +102,7 @@ export type MapOptions = {
101
102
  pitch?: number;
102
103
  renderWorldCopies?: boolean;
103
104
  maxTileCacheSize?: number;
105
+ maxTileCacheZoomLevels?: number;
104
106
  transformRequest?: RequestTransformFunction;
105
107
  transformCameraUpdate?: CameraUpdateTransformFunction;
106
108
  locale?: any;
@@ -194,6 +196,7 @@ const defaultOptions = {
194
196
  renderWorldCopies: true,
195
197
  refreshExpiredTiles: true,
196
198
  maxTileCacheSize: null,
199
+ maxTileCacheZoomLevels: config.MAX_TILE_CACHE_ZOOM_LEVELS,
197
200
  localIdeographFontFamily: 'sans-serif',
198
201
  transformRequest: null,
199
202
  transformCameraUpdate: null,
@@ -254,7 +257,7 @@ const defaultOptions = {
254
257
  * @param {boolean|Object} [options.touchPitch=true] If `true`, the "drag to pitch" interaction is enabled. An `Object` value is passed as options to {@link TwoFingersTouchPitchHandler#enable}.
255
258
  * @param {boolean|GestureOptions} [options.cooperativeGestures=undefined] If `true` or set to an options object, map is only accessible on desktop while holding Command/Ctrl and only accessible on mobile with two fingers. Interacting with the map using normal gestures will trigger an informational screen. With this option enabled, "drag to pitch" requires a three-finger gesture. Cooperative gestures are disabled when a map enters fullscreen using {@link #FullscreenControl}.
256
259
  * @param {boolean} [options.trackResize=true] If `true`, the map will automatically resize when the browser window resizes.
257
- * @param {LngLatLike} [options.center=[0, 0]] The initial geographical centerpoint of the map. If `center` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: MapLibre GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
260
+ * @param {LngLatLike} [options.center=[0, 0]] The initial geographical centerpoint of the map. If `center` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: MapLibre GL JS uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
258
261
  * @param {number} [options.zoom=0] The initial zoom level of the map. If `zoom` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
259
262
  * @param {number} [options.bearing=0] The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
260
263
  * @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-85). If `pitch` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`. 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.
@@ -265,8 +268,9 @@ const defaultOptions = {
265
268
  * container, there will be blank space beyond 180 and -180 degrees longitude.
266
269
  * - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
267
270
  * map and the other on the left edge of the map) at every zoom level.
268
- * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
269
- * @param {string} [options.validateStyle=true] If false, style validation will be skipped. Useful in production environment.
271
+ * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport which can be set using `maxTileCacheZoomLevels` constructor options.
272
+ * @param {number} [options.maxTileCacheZoomLevels=5] The maximum number of zoom levels for which to store tiles for a given source. Tile cache dynamic size is calculated by multiplying `maxTileCacheZoomLevels` with approx number of tiles in the viewport for a given source.
273
+ * @param {boolean} [options.validateStyle=true] If false, style validation will be skipped. Useful in production environment.
270
274
  * @param {string} [options.localIdeographFontFamily='sans-serif'] Defines a CSS
271
275
  * font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs', 'Hiragana', 'Katakana' and 'Hangul Syllables' ranges.
272
276
  * In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
@@ -321,6 +325,7 @@ class Map extends Camera {
321
325
  _vertices: boolean;
322
326
  _canvas: HTMLCanvasElement;
323
327
  _maxTileCacheSize: number;
328
+ _maxTileCacheZoomLevels: number;
324
329
  _frame: Cancelable;
325
330
  _styleDirty: boolean;
326
331
  _sourcesDirty: boolean;
@@ -434,6 +439,7 @@ class Map extends Camera {
434
439
  this._cooperativeGestures = options.cooperativeGestures;
435
440
  this._metaKey = navigator.platform.indexOf('Mac') === 0 ? 'metaKey' : 'ctrlKey';
436
441
  this._maxTileCacheSize = options.maxTileCacheSize;
442
+ this._maxTileCacheZoomLevels = options.maxTileCacheZoomLevels;
437
443
  this._failIfMajorPerformanceCaveat = options.failIfMajorPerformanceCaveat;
438
444
  this._preserveDrawingBuffer = options.preserveDrawingBuffer;
439
445
  this._antialias = options.antialias;
@@ -1328,7 +1334,7 @@ class Map extends Camera {
1328
1334
  * @param {FilterSpecification} [options.filter] (optional) A [filter](https://maplibre.org/maplibre-style-spec/layers/#filter)
1329
1335
  * to limit query results.
1330
1336
  * @param {Array<string>} [options.availableImages] (optional) An array of string representing the available images
1331
- * @param {boolean} [options.validate=true] (optional) Whether to check if the [options.filter] conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
1337
+ * @param {boolean} [options.validate=true] (optional) Whether to check if the [options.filter] conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
1332
1338
  *
1333
1339
  * @returns {Array<MapGeoJSONFeature>} An array of MapGeoJSONFeature objects.
1334
1340
  *
@@ -1419,7 +1425,7 @@ class Map extends Camera {
1419
1425
  * to query. *For vector tile sources, this parameter is required.* For GeoJSON sources, it is ignored.
1420
1426
  * @param {Array} [parameters.filter] A [filter](https://maplibre.org/maplibre-style-spec/layers/#filter)
1421
1427
  * to limit query results.
1422
- * @param {boolean} [parameters.validate=true] Whether to check if the [parameters.filter] conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
1428
+ * @param {boolean} [parameters.validate=true] Whether to check if the [parameters.filter] conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
1423
1429
  *
1424
1430
  * @returns {Array<MapGeoJSONFeature>} An array of MapGeoJSONFeature objects.
1425
1431
  *
@@ -2272,7 +2278,7 @@ class Map extends Camera {
2272
2278
  * @param {Array | null | undefined} filter The filter, conforming to the MapLibre Style Specification's
2273
2279
  * [filter definition](https://maplibre.org/maplibre-style-spec/layers/#filter). If `null` or `undefined` is provided, the function removes any existing filter from the layer.
2274
2280
  * @param {Object} [options] Options object.
2275
- * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2281
+ * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2276
2282
  * @returns {Map} `this`
2277
2283
  *
2278
2284
  * @example
@@ -2310,7 +2316,7 @@ class Map extends Camera {
2310
2316
  * @param {*} value The value of the paint property to set.
2311
2317
  * Must be of a type appropriate for the property, as defined in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/).
2312
2318
  * @param {Object} [options] Options object.
2313
- * @param {boolean} [options.validate=true] Whether to check if `value` conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2319
+ * @param {boolean} [options.validate=true] Whether to check if `value` conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2314
2320
  * @returns {Map} `this`
2315
2321
  * @example
2316
2322
  * map.setPaintProperty('my-layer', 'fill-color', '#faafee');
@@ -2340,7 +2346,7 @@ class Map extends Camera {
2340
2346
  * @param {string} name The name of the layout property to set.
2341
2347
  * @param {*} value The value of the layout property. Must be of a type appropriate for the property, as defined in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/).
2342
2348
  * @param {Object} [options] Options object.
2343
- * @param {boolean} [options.validate=true] Whether to check if `value` conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2349
+ * @param {boolean} [options.validate=true] Whether to check if `value` conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2344
2350
  * @returns {Map} `this`
2345
2351
  * @example
2346
2352
  * map.setLayoutProperty('my-layer', 'visibility', 'none');
@@ -2366,7 +2372,7 @@ class Map extends Camera {
2366
2372
  *
2367
2373
  * @param glyphsUrl Glyph URL to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/glyphs/).
2368
2374
  * @param {StyleSetterOptions} [options] Options object.
2369
- * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2375
+ * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2370
2376
  * @returns {Map} `this`
2371
2377
  * @example
2372
2378
  * map.setGlyphs('https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf');
@@ -2438,7 +2444,7 @@ class Map extends Camera {
2438
2444
  *
2439
2445
  * @param spriteUrl Sprite URL to set.
2440
2446
  * @param {StyleSetterOptions} [options] Options object.
2441
- * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2447
+ * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2442
2448
  * @returns {Map} `this`
2443
2449
  * @example
2444
2450
  * map.setSprite('YOUR_SPRITE_URL');
@@ -2458,7 +2464,7 @@ class Map extends Camera {
2458
2464
  *
2459
2465
  * @param light Light properties to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/#light).
2460
2466
  * @param {Object} [options] Options object.
2461
- * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre GL Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2467
+ * @param {boolean} [options.validate=true] Whether to check if the filter conforms to the MapLibre Style Specification. Disabling validation is a performance optimization that should only be used if you have previously validated the values you will be passing to this function.
2462
2468
  * @returns {Map} `this`
2463
2469
  * @example
2464
2470
  * var layerVisibility = map.getLayoutProperty('my-layer', 'visibility');
@@ -2743,7 +2749,8 @@ class Map extends Camera {
2743
2749
  }, {once: true});
2744
2750
 
2745
2751
  const gl =
2746
- this._canvas.getContext('webgl2', attributes) as WebGL2RenderingContext;
2752
+ this._canvas.getContext('webgl2', attributes) as WebGL2RenderingContext ||
2753
+ this._canvas.getContext('webgl', attributes) as WebGLRenderingContext;
2747
2754
 
2748
2755
  if (!gl) {
2749
2756
  const msg = 'Failed to initialize WebGL';
package/src/ui/marker.ts CHANGED
@@ -27,9 +27,9 @@ type MarkerOptions = {
27
27
 
28
28
  /**
29
29
  * Creates a marker component
30
- * @param {Object} [options]
30
+ * @param {MarkerOptions} [options]
31
31
  * @param {HTMLElement} [options.element] DOM element to use as a marker. The default is a light blue, droplet-shaped SVG marker.
32
- * @param {string} [options.anchor='center'] A string indicating the part of the Marker that should be positioned closest to the coordinate set via {@link Marker#setLngLat}.
32
+ * @param {PositionAnchor} [options.anchor='center'] A string indicating the part of the Marker that should be positioned closest to the coordinate set via {@link Marker#setLngLat}.
33
33
  * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`.
34
34
  * @param {PointLike} [options.offset] The offset in pixels as a {@link PointLike} object to apply relative to the element's center. Negatives indicate left and up.
35
35
  * @param {string} [options.color='#3FB1CE'] The color to use for the default marker if options.element is not provided. The default is light blue.
package/src/ui/popup.ts CHANGED
@@ -48,7 +48,7 @@ const focusQuerySelector = [
48
48
  /**
49
49
  * A popup component.
50
50
  *
51
- * @param {Object} [options]
51
+ * @param {PopupOptions} [options]
52
52
  * @param {boolean} [options.closeButton=true] If `true`, a close button will appear in the
53
53
  * top right corner of the popup.
54
54
  * @param {boolean} [options.closeOnClick=true] If `true`, the popup will closed when the
@@ -57,7 +57,7 @@ const focusQuerySelector = [
57
57
  * map moves.
58
58
  * @param {boolean} [options.focusAfterOpen=true] If `true`, the popup will try to focus the
59
59
  * first focusable element inside the popup.
60
- * @param {string} [options.anchor] - A string indicating the part of the Popup that should
60
+ * @param {PositionAnchor} [options.anchor] - A string indicating the part of the Popup that should
61
61
  * be positioned closest to the coordinate set via {@link Popup#setLngLat}.
62
62
  * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
63
63
  * `'top-right'`, `'bottom-left'`, and `'bottom-right'`. If unset the anchor will be
@@ -23,12 +23,12 @@ const exported = {
23
23
  return {cancel: () => cancelAnimationFrame(frame)};
24
24
  },
25
25
 
26
- getImageData(img: CanvasImageSource, padding: number = 0): ImageData {
26
+ getImageData(img: HTMLImageElement | ImageBitmap, padding: number = 0): ImageData {
27
27
  const context = this.getImageCanvasContext(img);
28
28
  return context.getImageData(-padding, -padding, img.width as number + 2 * padding, img.height as number + 2 * padding);
29
29
  },
30
30
 
31
- getImageCanvasContext(img: CanvasImageSource): CanvasRenderingContext2D {
31
+ getImageCanvasContext(img: HTMLImageElement | ImageBitmap): CanvasRenderingContext2D {
32
32
  const canvas = window.document.createElement('canvas') as HTMLCanvasElement;
33
33
  const context = canvas.getContext('2d', {willReadFrequently: true});
34
34
  if (!context) {
@@ -4,6 +4,7 @@ import type {RequestParameters, ResponseCallback} from './ajax';
4
4
  type Config = {
5
5
  MAX_PARALLEL_IMAGE_REQUESTS: number;
6
6
  MAX_PARALLEL_IMAGE_REQUESTS_PER_FRAME: number;
7
+ MAX_TILE_CACHE_ZOOM_LEVELS: number;
7
8
  REGISTERED_PROTOCOLS: {[x: string]: (requestParameters: RequestParameters, callback: ResponseCallback<any>) => Cancelable};
8
9
  WORKER_URL: string;
9
10
  };
@@ -11,6 +12,7 @@ type Config = {
11
12
  const config: Config = {
12
13
  MAX_PARALLEL_IMAGE_REQUESTS: 16,
13
14
  MAX_PARALLEL_IMAGE_REQUESTS_PER_FRAME: 8,
15
+ MAX_TILE_CACHE_ZOOM_LEVELS: 5,
14
16
  REGISTERED_PROTOCOLS: {},
15
17
  WORKER_URL: ''
16
18
  };
@@ -73,7 +73,10 @@ export function setWebGlContext() {
73
73
  const originalGetContext = global.HTMLCanvasElement.prototype.getContext;
74
74
 
75
75
  function imitateWebGlGetContext(type, attributes) {
76
- if (type === 'webgl2' || type === 'webgl') {
76
+ if (type === 'webgl2') {
77
+ return null;
78
+ }
79
+ if (type === 'webgl') {
77
80
  if (!this._webGLContext) {
78
81
  this._webGLContext = gl(this.width, this.height, attributes);
79
82
  if (!this._webGLContext) {
@@ -5,7 +5,7 @@ const exported = {
5
5
 
6
6
  export default exported;
7
7
 
8
- let glForTesting: WebGL2RenderingContext;
8
+ let glForTesting: WebGLRenderingContext|WebGL2RenderingContext;
9
9
  let webpCheckComplete = false;
10
10
  let webpImgTest;
11
11
  let webpImgTestOnloadComplete = false;
@@ -24,7 +24,7 @@ if (typeof document !== 'undefined') {
24
24
  webpImgTest.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=';
25
25
  }
26
26
 
27
- function testSupport(gl: WebGL2RenderingContext) {
27
+ function testSupport(gl: WebGLRenderingContext | WebGL2RenderingContext) {
28
28
  if (webpCheckComplete || !webpImgTest) return;
29
29
 
30
30
  // HTMLImageElement.complete is set when an image is done loading it's source
@@ -41,7 +41,7 @@ function testSupport(gl: WebGL2RenderingContext) {
41
41
  }
42
42
  }
43
43
 
44
- function testWebpTextureUpload(gl: WebGL2RenderingContext) {
44
+ function testWebpTextureUpload(gl: WebGLRenderingContext|WebGL2RenderingContext) {
45
45
  // Edge 18 supports WebP but not uploading a WebP image to a gl texture
46
46
  // Test support for this before allowing WebP images.
47
47
  // https://github.com/mapbox/mapbox-gl-js/issues/7671