-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fire sourcedata when source metadata and tiles are loaded #4347
Changes from 4 commits
e58fecf
1973eb5
17cda5c
799779c
89ae98b
3ccc7e0
c19a117
94c35d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,23 +27,26 @@ class SourceCache extends Evented { | |
this.id = id; | ||
this.dispatcher = dispatcher; | ||
|
||
this.on('source.load', function() { | ||
this._sourceLoaded = true; | ||
}); | ||
|
||
this.on('error', function() { | ||
this._sourceErrored = true; | ||
}); | ||
|
||
this.on('data', function(event) { | ||
if (this._sourceLoaded && event.dataType === 'source') { | ||
this.on('data', function(e) { | ||
// this._sourceLoaded signifies that the TileJSON is loaded if applicable | ||
// if the source type does not come with a TileJSON, the flag signifies the | ||
// source data has loaded (i.e geojson has been tiled on the worker and is ready) | ||
if (e.dataType === 'source' && e.metadata) this._sourceLoaded = true; | ||
|
||
// 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 && e.dataType==="source" && e.update) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great ❤️ Notes/questions:
|
||
this.reload(); | ||
if (this.transform) { | ||
this.update(this.transform); | ||
} | ||
} | ||
}); | ||
|
||
this.on('error', function() { | ||
this._sourceErrored = true; | ||
}); | ||
|
||
this._source = Source.create(id, options, dispatcher, this); | ||
|
||
this._tiles = {}; | ||
|
@@ -169,7 +172,7 @@ class SourceCache extends Evented { | |
tile.timeAdded = new Date().getTime(); | ||
if (previousState === 'expired') tile.refreshedUponExpiration = true; | ||
this._setTileReloadTimer(id, tile); | ||
this._source.fire('data', {tile: tile, coord: tile.coord, dataType: 'tile'}); | ||
this._source.fire('data', {dataType: 'source', tile: tile, coord: tile.coord}); | ||
|
||
// HACK this is necessary to fix https://github.com/mapbox/mapbox-gl-js/issues/2986 | ||
if (this.map) this.map.painter.tileExtentVAO.vao = null; | ||
|
@@ -296,6 +299,7 @@ class SourceCache extends Evented { | |
* @private | ||
*/ | ||
update(transform) { | ||
this.transform = transform; | ||
if (!this._sourceLoaded) { return; } | ||
let i; | ||
let coord; | ||
|
@@ -394,8 +398,6 @@ class SourceCache extends Evented { | |
for (i = 0; i < remove.length; i++) { | ||
this.removeTile(+remove[i]); | ||
} | ||
|
||
this.transform = transform; | ||
} | ||
|
||
/** | ||
|
@@ -423,8 +425,8 @@ class SourceCache extends Evented { | |
} | ||
} | ||
} | ||
|
||
if (!tile) { | ||
const cached = Boolean(tile); | ||
if (!cached) { | ||
const zoom = coord.z; | ||
const overscaling = zoom > this._source.maxzoom ? Math.pow(2, zoom - this._source.maxzoom) : 1; | ||
tile = new Tile(wrapped, this._source.tileSize * overscaling, this._source.maxzoom); | ||
|
@@ -433,7 +435,7 @@ class SourceCache extends Evented { | |
|
||
tile.uses++; | ||
this._tiles[coord.id] = tile; | ||
this._source.fire('dataloading', {tile: tile, coord: tile.coord, dataType: 'tile'}); | ||
if (!cached) this._source.fire('dataloading', {tile: tile, coord: tile.coord, dataType: 'source'}); | ||
|
||
return tile; | ||
} | ||
|
@@ -475,6 +477,7 @@ class SourceCache extends Evented { | |
clearTimeout(this._timers[id]); | ||
this._timers[id] = undefined; | ||
} | ||
// TODO should we keep this?? | ||
this._source.fire('data', { tile: tile, coord: tile.coord, dataType: 'tile' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lucaswoj @anandthakker do you think we need to fire an event when a tile is removed now that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this event isn't useful -- if we're not using it anywhere internally, then I'm all for removing it. What might be useful someday in the future would be a way for users to listen for changes to the list of currently renderable/rendered tile coordinates -- but this doesn't really provide that, and anyway that's a super non-urgent nice-to-have. |
||
|
||
if (tile.uses > 0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lbud would love to know what this line is for. for some reason it's behaving in unexpected ways with the new eventing system and making the canvas source tests fail 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lbud might be able to say more, but my recollection from a while back is that this had to do with 'tricking' the source cache into always requesting the 'right' tile from the ImageSource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think @anandthakker is right — because of #3186 (👺) we have to trick the source cache into thinking there's only one appropriate tile to ever request for image + image-inheriting sources. 👀 …