-
-
Notifications
You must be signed in to change notification settings - Fork 866
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
[FEATURE] Fallback tile URLs in-case of HTTP error #1203
Comments
I haven't tested the errorTileCallback code....but maybe it depends how it failed ? For example, if there just isn't a response from a server, would it know ? |
Hi there @juanlabrador, |
Hi guys, thanks for answer, well, the simple example its put a bad url, the tile when faile its return 403 error, I mean, the tile does't show map, so, in that cases, the idea is use another tile url like support, but I don't know where catch this 403 error |
At the moment, fallback URLs aren't supported - if that's what you mean. But it sounds like an interesting and useful idea! |
Note that for the time being, feature requests have an indefinite wait time, as we have quite a backlog of issues and bugs to get to. Many thanks for your suggestion! |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Hi @JaffaKetchup, I think I've been able to add a fallbackUrl to the Code SampleTileLayer(
urlTemplate: 'https://fake-tile-provider.org/{z}/{x}/{y}.png',
fallbackUrl: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: const ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
tileProvider: NetworkTileProvider(),
), Implementationclass FMNetworkImageProvider extends ImageProvider<FMNetworkImageProvider> {
// ...
/// The fallback URL from which the image will be fetched.
final String? fallbackUrl;
// ...
FMNetworkImageProvider(
this.url, {
required this.fallbackUrl,
RetryClient? retryClient,
this.headers = const {},
}) : retryClient = retryClient ?? RetryClient(Client());
// ...
Future<ImageInfo> _loadWithRetry(
FMNetworkImageProvider key,
DecoderCallback decode, [
bool useFallback = false,
]) async {
assert(key == this);
assert(useFallback == false || fallbackUrl != null);
try {
final uri = Uri.parse(useFallback ? fallbackUrl! : url);
final response = await retryClient.get(uri, headers: headers);
if (response.statusCode != 200) {
throw NetworkImageLoadException(
statusCode: response.statusCode, uri: uri);
}
final codec = await decode(response.bodyBytes);
final image = (await codec.getNextFrame()).image;
return ImageInfo(image: image);
} catch (e) {
if (!useFallback && fallbackUrl != null) {
return _loadWithRetry(key, decode, true);
}
rethrow;
}
}
} Would you be interested in a PR ? (I've already created a full sample added to the example app) |
Hi @TesteurManiak, |
Thanks for the quick response, I think I can make it work for all providers, it was just easier for |
Describe The Problem
I'm try to catch an error callback when the tile failed, so, the idea is when the first tile url map failed, called another, but this method errorTileCallback doesn't call, so, don't find in examples an example, maybe someone know somehow? Thanks
Additional Information
TileLayerOptions getMapBoxStyle(Function refresh, {Key key}) =>
TileLayerOptions(
key: key,
urlTemplate: globalTileMap,
errorTileCallback: (tile, error) {
globalTileMap =
'https://tiles.picap.app/styles/osm-bright/{z}/{x}/{y}.png';
refresh.call();
},
backgroundColor: PiColors.backgroundTileMap);
The text was updated successfully, but these errors were encountered: