-
-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* working for NetworkTileProvider * working for NetworkNoRetryTileProvider * done AssetTileProvider * formatted comments * fixed wording & removed openstreetmap subdomain * removed AssetTileProvider from tile_provider_web.dart
- Loading branch information
1 parent
44d570d
commit a56b2b3
Showing
14 changed files
with
287 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:flutter_map_example/widgets/drawer.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
|
||
class FallbackUrlPage extends StatelessWidget { | ||
final String route; | ||
final TileLayer tileLayer; | ||
final String title; | ||
final String description; | ||
final double zoom; | ||
final double? maxZoom; | ||
final double? minZoom; | ||
final LatLng center; | ||
|
||
const FallbackUrlPage({ | ||
Key? key, | ||
required this.route, | ||
required this.tileLayer, | ||
required this.title, | ||
required this.description, | ||
required this.center, | ||
this.zoom = 13, | ||
this.maxZoom, | ||
this.minZoom, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: Text(title)), | ||
drawer: buildDrawer(context, route), | ||
body: Padding( | ||
padding: const EdgeInsets.all(8), | ||
child: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.only(top: 8, bottom: 8), | ||
child: Text(description), | ||
), | ||
Flexible( | ||
child: FlutterMap( | ||
options: MapOptions( | ||
center: center, | ||
zoom: zoom, | ||
maxZoom: maxZoom, | ||
minZoom: minZoom, | ||
), | ||
children: [tileLayer], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:flutter_map_example/pages/fallback_url/fallback_url.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
|
||
class FallbackUrlNetworkPage extends StatelessWidget { | ||
static const String route = '/fallback_url_network'; | ||
|
||
const FallbackUrlNetworkPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FallbackUrlPage( | ||
route: route, | ||
tileLayer: TileLayer( | ||
urlTemplate: 'https://fake-tile-provider.org/{z}/{x}/{y}.png', | ||
fallbackUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', | ||
subdomains: const ['a', 'b', 'c'], | ||
userAgentPackageName: 'dev.fleaflet.flutter_map.example', | ||
), | ||
title: 'Fallback URL NetworkTileProvider', | ||
description: | ||
'Map with a fake url should use the fallback, showing (51.5, -0.9).', | ||
zoom: 5, | ||
center: LatLng(51.5, -0.09), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:flutter_map_example/pages/fallback_url/fallback_url.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
|
||
class FallbackUrlOfflinePage extends StatelessWidget { | ||
static const String route = '/fallback_url_offline'; | ||
|
||
const FallbackUrlOfflinePage({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FallbackUrlPage( | ||
route: route, | ||
tileLayer: TileLayer( | ||
tileProvider: AssetTileProvider(), | ||
maxZoom: 14, | ||
urlTemplate: 'assets/fake/tiles/{z}/{x}/{y}.png', | ||
fallbackUrl: 'assets/map/anholt_osmbright/{z}/{x}/{y}.png', | ||
), | ||
title: 'Fallback URL AssetTileProvider', | ||
description: | ||
'Map with a fake asset path, should be using the fallback to show Anholt Island, Denmark.', | ||
maxZoom: 14, | ||
minZoom: 12, | ||
center: LatLng(56.704173, 11.543808), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
lib/src/layer/tile_layer/tile_provider/asset_tile_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/coords.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/tile_layer.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/tile_provider/base_tile_provider.dart'; | ||
|
||
class AssetTileProvider extends TileProvider { | ||
@override | ||
AssetImage getImage(Coords<num> coords, TileLayer options) { | ||
return AssetImage( | ||
getTileUrl(coords, options), | ||
bundle: _FlutterMapAssetBundle( | ||
fallbackKey: getTileFallbackUrl(coords, options), | ||
), | ||
); | ||
} | ||
} | ||
|
||
/// Used to load a fallback asset when the main asset is not found. | ||
class _FlutterMapAssetBundle extends CachingAssetBundle { | ||
final String? fallbackKey; | ||
|
||
_FlutterMapAssetBundle({required this.fallbackKey}); | ||
|
||
Future<ByteData?> _loadAsset(String key) async { | ||
final Uint8List encoded = | ||
utf8.encoder.convert(Uri(path: Uri.encodeFull(key)).path); | ||
final ByteData? asset = await ServicesBinding | ||
.instance.defaultBinaryMessenger | ||
.send('flutter/assets', encoded.buffer.asByteData()); | ||
return asset; | ||
} | ||
|
||
@override | ||
Future<ByteData> load(String key) async { | ||
final asset = await _loadAsset(key); | ||
if (asset != null && asset.lengthInBytes > 0) return asset; | ||
|
||
if (fallbackKey != null) { | ||
final fallbackAsset = await _loadAsset(fallbackKey!); | ||
if (fallbackAsset != null) return fallbackAsset; | ||
} | ||
|
||
throw FlutterError('_FlutterMapAssetBundle - Unable to load asset: $key'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.