Skip to content

Provide a fallback provider for missing tile layer #5810

Closed

Description

Leaflet version : 1.2.0

More an improvement than a bug, but currently the fallback "errorTileUrl" for TileLayers only allows for an image to replace the missing tiles, but you can't request another provider for the tiles.
For instance, if I want to get tileLayers from my own server, but in case it's down, load google maps instead.

Here is what I wanted to achieve : https://jsfiddle.net/cLvcfw34/
As you can see, the parameters aren't replaced and therefore the fallback is failing.

I have slightly change the code to allow for another provider as a fallback (inspired by https://github.com/ghybs/Leaflet.TileLayer.Fallback) as follow :

I added in createTile function
tile._originalCoords = coords

And in replaced _tileOnError by:
`
_tileOnError: function (done, tile, e) {

	var errorUrl = this.options.errorTileUrl;
	if (errorUrl && tile.getAttribute('src') !== errorUrl) {
		//tile.src = errorUrl;
		this.setUrl(errorUrl)
		this.getTileUrl(tile._originalCoords)
	}
	done(e, tile);
}

`

As errorTileUrl is already used for image loading, would it might be useful to provide another option such as "fallbackUrl" for instance (and prevent for infinite looping if the fallback fail as well it should be replaced by errorUrl).

I hoped I did not miss something already in place. If you find this feature useful I can try to make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions