diff --git a/src/source/raster_tile_source.js b/src/source/raster_tile_source.js index 870f62709d4..15e91fde043 100644 --- a/src/source/raster_tile_source.js +++ b/src/source/raster_tile_source.js @@ -22,13 +22,13 @@ class RasterTileSource extends Evented { this.scheme = 'xyz'; this.tileSize = 512; this._loaded = false; - this.options = options; + this._options = util.extend({}, options); util.extend(this, util.pick(options, ['url', 'scheme', 'tileSize'])); } load() { this.fire('dataloading', {dataType: 'source'}); - loadTileJSON(this.options, (err, tileJSON) => { + loadTileJSON(this._options, (err, tileJSON) => { if (err) { return this.fire('error', err); } @@ -58,13 +58,7 @@ class RasterTileSource extends Evented { } serialize() { - return { - type: 'raster', - url: this.url, - tileSize: this.tileSize, - tiles: this.tiles, - bounds: this.bounds, - }; + return util.extend({}, this._options); } hasTile(coord) { diff --git a/test/unit/style/style.test.js b/test/unit/style/style.test.js index ed2efdd84ab..bcaf4249665 100644 --- a/test/unit/style/style.test.js +++ b/test/unit/style/style.test.js @@ -347,6 +347,27 @@ test('Style#setState', (t) => { }); }); + t.test('Issue #3893: compare new source options against originally provided options rather than normalized properties', (t) => { + window.useFakeXMLHttpRequest(); + window.server.respondWith('/tilejson.json', JSON.stringify({ + tiles: ['http://tiles.server'] + })); + const initial = createStyleJSON(); + initial.sources.mySource = { + type: 'raster', + url: '/tilejson.json' + }; + const style = new Style(initial); + style.on('style.load', () => { + t.stub(style, 'removeSource').callsFake(() => t.fail('removeSource called')); + t.stub(style, 'addSource').callsFake(() => t.fail('addSource called')); + style.setState(initial); + window.restore(); + t.end(); + }); + window.server.respond(); + }); + t.test('return true if there is a change', (t) => { const initialState = createStyleJSON(); const nextState = createStyleJSON({