-
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
Refactor CustomSource
#12063
Refactor CustomSource
#12063
Conversation
Documenting conversation from elsewhere: Erroring the tile will cause the parent tile to be shown, if it is available. If we need this in some cases but not in other we'll need to support both a way to error the tile and a way to make it empty. |
loadTile
returns no data in CustomSource
After some feedback, it looks like we should support both ways — to render nothing and to show an overscaled parent tile in the tile’s space. I see two possible solutions: we can either add a boolean flag to the // If the implementation returned `undefined` as tile data,
// mark the tile as `errored` to indicate that we have no data for it.
// A map will render an overscaled parent tile in the tile’s space.
if (data === undefined) {
tile.state = 'errored';
return callback(null);
}
// If the implementation returned `null` as tile data,
// mark the tile as `loaded` and use an an empty image as tile data.
// A map will render nothing in the tile’s space.
if (data === null) {
const emptyImage = {width: this.tileSize, height: this.tileSize, data: null};
this.loadTileData(tile, (emptyImage: any));
tile.state = 'loaded';
return callback(null);
} |
Another option would be to catch rejected promises and treat those as errors. Error/rejection == missing tile. Undefined/null === blank tile. |
@ansis yes, that's possible too. It's probably a matter of taste, but since the use-case implies that the user might want to return a missing tile explicitly, I'd prefer not to use |
ddc4a21
to
a88f0cd
Compare
loadTile
returns no data in CustomSourceCustomSource
by the undefined
vs null
value returned by loadTile
6d4726f
to
3f409c6
Compare
…" tile behavior in CustomSource
e926328
to
e7a4d44
Compare
CustomSource
by the undefined
vs null
value returned by loadTile
CustomSource
using the undefined
vs null
return value
CustomSource
using the undefined
vs null
return valueCustomSource
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.
Love how this simplifies the code significantly!
I'm not sure if it's related to this PR or not, but this is an odd behavior I observe on the custom-source debug page, in which high-zoom tiles continue to be displayed as you zoom out and until you zoom in elsewhere. I wonder if this is related to needing to manually implement your own unload function or something? I do not observe this behavior for regular tiles on the debug/debug.html page with tile debug turned on. unloading.mov |
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.
I really like the changes!! 👏 I think it's definitely headed in the right direction, but I observed what appears to be a bug in the debug page, a possible bug in tile unloading, and had a question about a possible alternative API design.
A little comment about
but raster is checked as
Thank you for the |
Good catch, @SergeiMelman! I've updated the JSDoc for |
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.
This looks good to me, thanks for the changes! My strategy now is to use an LRU cache to store canvases by z/x/y and separately use a Set
to track whether particular tiles need to be redraw. This happens since there are two cases:
- the tile's canvas is cached and can be re-used as-is
- the tile's canvas is cached but needs to be repainted
I think this is reasonable and matches expectations, and I'm able to use it to accomplish the rendering I was after!
(Also, "raster-fade-duration": 1
solved my other problem regarding the retained tiles, thanks for tracking down the source of that issue!)
This PR makes 3 changes:
prepareTile
as it was complicating more than helpingclearTiles
method that allows an implementation to remove all existing tiles inSourceCache
sCustomSource
by theundefined
vsnull
value returned by theloadTile
. More context is below.Before the fix, we draw nothing (an empty tile) if
loadTile
throws or returns no data (blank space on the first screenshot). After the fix, ifloadTile
returnsundefined
, such tiles are marked aserrored,
and a map draws an overscaled parent tile if there is any (red tile on the second screenshot).IfprepareTile
returnsnull
, such tiles are marked asloading,
and a map draws nothing. (blank space on the first screenshot). IfprepareTile
returnsundefined
, a map draws an overscaled parent tile if there is any (red tile on the second screenshot).loadTile
returnsnull
loadTile
returnsundefined
Related to #11608
Closes #11687 #12159
Launch Checklist