Skip to content

Commit 964d6af

Browse files
authored
Adds RasterTileSource#setUrl method (#3700)
* Add RasterTileSource#setUrl method * Improve formatting * Update changelog
1 parent f42f901 commit 964d6af

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
## main
22

33
### ✨ Features and improvements
4-
- _...Add new stuff here..._
4+
5+
- Add `setUrl` method to RasterTileSource to dynamically update existing TileJSON resource. ([3700](https://github.com/maplibre/maplibre-gl-js/pull/3700))
56

67
### 🐞 Bug fixes
8+
79
- Fix Marker losing opacity after window resize ([#3656](https://github.com/maplibre/maplibre-gl-js/pull/3656))
810
- Fix vector tiles not loading when html is opened via "file://" ([#3681](https://github.com/maplibre/maplibre-gl-js/pull/3681))
911

@@ -12,14 +14,16 @@
1214
### ✨ Features and improvements
1315

1416
- ⚠️ Remove all global getters and setters from `maplibregl`, this means the the following methods have changed:
17+
1518
- `maplibregl.version` => `getVersion()`
1619
- `maplibregl.workerCount` => `getWorkerCount()`, `setWorkerCount(...)`
1720
- `maplibregl.maxParallelImageRequests` => `getMaxParallelImageRequests()`, `setMaxParallelImageRequests(...)`
1821
- `maplibregl.workerUrl` => `getWorkerUrl()`, `setWorkerUrl(...)`
1922

2023
This is to avoid the need to use a global object and allow named exports/imports ([#3601](https://github.com/maplibre/maplibre-gl-js/issues/3601))
24+
2125
- ⚠️ Change attribution to be on by default, change `MapOptions.attributionControl` to be the type that the control handles, removed `MapOptions.customAttribution` ([#3618](https://github.com/maplibre/maplibre-gl-js/issues/3618))
22-
Note: showing the logo of MapLibre is not required for using MapLibre.
26+
Note: showing the logo of MapLibre is not required for using MapLibre.
2327
- ⚠️ Changed cooperative gesture config and removed the strings from it in favor of the locale variable ([#3621](https://github.com/maplibre/maplibre-gl-js/issues/3621))
2428
- ⚠️ Changed the terrain enable disable locale key to match the other keys' styles, updated the typings to allow using locale with more ease ([#3621](https://github.com/maplibre/maplibre-gl-js/issues/3621))
2529
- ⚠️ Add the ability to import a script in the worker thread and call `addProtocol` and `removeProtocol` there ([#3459](https://github.com/maplibre/maplibre-gl-js/pull/3459)) - this also changed how `addSourceType` works since now you'll need to load the script with `maplibregl.importScriptInWorkers`.
@@ -43,7 +47,7 @@ Note: showing the logo of MapLibre is not required for using MapLibre.
4347
### 🐞 Bug fixes
4448

4549
- Fix wheel zoom to be into the same direction above or under the horizon ([#3398](https://github.com/maplibre/maplibre-gl-js/issues/3398))
46-
- Fix _cameraForBoxAndBearing not fitting bounds properly when using asymettrical camera viewport and bearing.([#3591](https://github.com/maplibre/maplibre-gl-js/pull/3591))
50+
- Fix \_cameraForBoxAndBearing not fitting bounds properly when using asymettrical camera viewport and bearing.([#3591](https://github.com/maplibre/maplibre-gl-js/pull/3591))
4751
- Fix missing export `Map` type in the `d.ts` file ([#3564](https://github.com/maplibre/maplibre-gl-js/pull/3564))
4852
- Fix the shifted mouse events after a css transform scale on the map container ([#3437](https://github.com/maplibre/maplibre-gl-js/pull/3437))
4953
- Fix markers remaining transparent when disabling terrain ([#3431](https://github.com/maplibre/maplibre-gl-js/pull/3431))
@@ -59,7 +63,7 @@ Note: showing the logo of MapLibre is not required for using MapLibre.
5963
### ✨ Features and improvements
6064

6165
- ⚠️ Change attribution to be on by default, change `MapOptions.attributionControl` to be the type that the control handles, removed `MapOptions.customAttribution` ([#3618](https://github.com/maplibre/maplibre-gl-js/issues/3618))
62-
Note: showing the logo of MapLibre is not required for using MapLibre.
66+
Note: showing the logo of MapLibre is not required for using MapLibre.
6367
- ⚠️ Changed cooperative gesture config and removed the strings from it in favor of the locale variable ([#3621](https://github.com/maplibre/maplibre-gl-js/issues/3621))
6468
- ⚠️ Changed the terrain enable disable locale key to match the other keys' styles, updated the typings to allow using locale with more ease ([#3621](https://github.com/maplibre/maplibre-gl-js/issues/3621))
6569
- Add "opacity" option and "setOpacity" method to Marker ([#3620](https://github.com/maplibre/maplibre-gl-js/pull/3620))
@@ -78,7 +82,7 @@ Note: showing the logo of MapLibre is not required for using MapLibre.
7882
### 🐞 Bug fixes
7983

8084
- Fix wheel zoom to be into the same direction above or under the horizon ([#3398](https://github.com/maplibre/maplibre-gl-js/issues/3398))
81-
- Fix _cameraForBoxAndBearing not fitting bounds properly when using asymettrical camera viewport and bearing ([#3591](https://github.com/maplibre/maplibre-gl-js/pull/3591))
85+
- Fix \_cameraForBoxAndBearing not fitting bounds properly when using asymettrical camera viewport and bearing ([#3591](https://github.com/maplibre/maplibre-gl-js/pull/3591))
8286

8387
## 4.0.0-pre.4
8488

src/source/raster_tile_source.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ describe('RasterTileSource', () => {
179179
expect((server.lastRequest as any).aborted).toBe(true);
180180
});
181181

182+
test('supports url property updates', () => {
183+
const source = createSource({
184+
url: 'http://localhost:2900/source.json'
185+
});
186+
source.setUrl('http://localhost:2900/source2.json');
187+
expect(source.serialize()).toEqual({
188+
type: 'raster',
189+
url: 'http://localhost:2900/source2.json'
190+
});
191+
});
192+
182193
it('serializes options', () => {
183194
const source = createSource({
184195
tiles: ['http://localhost:2900/raster/{z}/{x}/{y}.png'],

src/source/raster_tile_source.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ export class RasterTileSource extends Evented implements Source {
150150
return this;
151151
}
152152

153+
/**
154+
* Sets the source `url` property and re-renders the map.
155+
*
156+
* @param url - A URL to a TileJSON resource. Supported protocols are `http:` and `https:`.
157+
* @returns `this`
158+
*/
159+
setUrl(url: string): this {
160+
this.setSourceProperty(() => {
161+
this.url = url;
162+
this._options.url = url;
163+
});
164+
165+
return this;
166+
}
167+
153168
serialize() {
154169
return extend({}, this._options);
155170
}

0 commit comments

Comments
 (0)