Skip to content

Commit

Permalink
Fix incorrect style serialization when using raster DEM tile sources (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji authored Mar 2, 2021
1 parent 7325e2d commit e1942b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/source/raster_dem_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ class RasterDEMTileSource extends RasterTileSource implements Source {
this.encoding = options.encoding || "mapbox";
}

serialize() {
return {
type: 'raster-dem',
url: this.url,
tileSize: this.tileSize,
tiles: this.tiles,
bounds: this.bounds,
encoding: this.encoding
};
}

loadTile(tile: Tile, callback: Callback<void>) {
const url = this.map._requestManager.normalizeTileURL(tile.tileID.canonical.url(this.tiles, this.scheme), false, this.tileSize);
tile.request = getImage(this.map._requestManager.transformRequest(url, ResourceType.Tile), imageLoaded.bind(this));
Expand Down
23 changes: 23 additions & 0 deletions test/unit/source/raster_dem_tile_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import RasterDEMTileSource from '../../../src/source/raster_dem_tile_source.js';
import window from '../../../src/util/window.js';
import {OverscaledTileID} from '../../../src/source/tile_id.js';
import {RequestManager} from '../../../src/util/mapbox.js';
import {extend} from '../../../src/util/util.js';

function createSource(options, transformCallback) {
const source = new RasterDEMTileSource('id', options, {send() {}}, options.eventedParent);
Expand Down Expand Up @@ -30,6 +31,28 @@ test('RasterTileSource', (t) => {
callback();
});

t.test('create and serialize source', (t) => {
window.server.respondWith('/source.json', JSON.stringify({}));
const transformSpy = t.spy((url) => {
return {url};
});
const options = {
url: "/source.json",
minzoom: 0,
maxzoom: 22,
attribution: "Mapbox",
tiles: ["http://example.com/{z}/{x}/{y}.png"],
bounds: [-47, -7, -45, -5],
encoding: "terrarium",
tileSize: 512,
volatile: false
};
const source = createSource(options, transformSpy);
source.load();
t.deepEqual(source.serialize(), extend({type: "raster-dem"}, options));
t.end();
});

t.test('transforms request for TileJSON URL', (t) => {
window.server.respondWith('/source.json', JSON.stringify({
minzoom: 0,
Expand Down

0 comments on commit e1942b3

Please sign in to comment.