Skip to content

Commit

Permalink
Revert "don't clear state on reload, just on setData (#7129)"
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Aug 16, 2018
1 parent aad9b54 commit 68353fd
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 113 deletions.
12 changes: 3 additions & 9 deletions src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class SourceCache extends Evented {
// for sources with mutable data, this event fires when the underlying data
// to a source is changed. (i.e. GeoJSONSource#setData and ImageSource#serCoordinates)
if (this._sourceLoaded && !this._paused && e.dataType === "source" && e.sourceDataType === 'content') {
if (this._source.type === "geojson") this.resetState();
this.reload();
if (this.transform) {
this.update(this.transform);
Expand Down Expand Up @@ -218,6 +217,9 @@ class SourceCache extends Evented {
}

this._cache.reset();
//Reset the SourceCache when the source has been reloaded. For GeoJSON sources,
// the `id` of features is not guaranteed to be identical when updated
this._state = new SourceFeatureState();

for (const i in this._tiles) {
if (this._tiles[i].state !== "errored") this._reloadTile(i, 'reloading');
Expand Down Expand Up @@ -831,14 +833,6 @@ class SourceCache extends Evented {
sourceLayer = sourceLayer || '_geojsonTileLayer';
return this._state.getState(sourceLayer, feature);
}

/**
* Reset the SourceFeatureState when the source has been reloaded. For GeoJSON sources,
* the `id` of features is not guaranteed to be identical when updated
*/
resetState() {
this._state = new SourceFeatureState();
}
}

SourceCache.maxOverzooming = 10;
Expand Down
1 change: 0 additions & 1 deletion src/style-spec/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,3 @@ export type LayerSpecification =
| RasterLayerSpecification
| HillshadeLayerSpecification
| BackgroundLayerSpecification;

Binary file not shown.

This file was deleted.

32 changes: 0 additions & 32 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,38 +1268,6 @@ test('Map', (t) => {
t.end();
});
});

t.test('resets state if source data is updated', (t) => {
const map = createMap(t, {
style: {
"version": 8,
"sources": {
"geojson": createStyleSource()
},
"layers": []
}
});
map.on('load', () => {
map.setFeatureState({ source: 'geojson', id: '12345'}, {'hover': true});
const fState = map.getFeatureState({ source: 'geojson', id: '12345'});
t.equal(fState.hover, true);

map.on('data', () => {
if (map.isSourceLoaded('geojson')) {
const cleanState = map.getFeatureState({ source: 'geojson', id: '12345'});
t.notOk(cleanState.hover);
t.end();
}
});

map.getSource('geojson')
.setData({
type: "FeatureCollection",
features: []
});
});
});

t.test('throw before loaded', (t) => {
const map = createMap(t, {
style: {
Expand Down

0 comments on commit 68353fd

Please sign in to comment.