Skip to content

Commit

Permalink
add NonCachingNetworkTileProvider to demonstrate web support
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpryan committed Oct 9, 2019
1 parent 5158e54 commit e8e687b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
22 changes: 17 additions & 5 deletions example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class HomePage extends StatelessWidget {
height: 80.0,
point: LatLng(51.5, -0.09),
builder: (ctx) => Container(
child: FlutterLogo(),
child: FlutterLogo(
colors: Colors.blue,
key: ObjectKey(Colors.blue),
),
),
),
Marker(
Expand All @@ -25,6 +28,7 @@ class HomePage extends StatelessWidget {
builder: (ctx) => Container(
child: FlutterLogo(
colors: Colors.green,
key: ObjectKey(Colors.green),
),
),
),
Expand All @@ -33,7 +37,10 @@ class HomePage extends StatelessWidget {
height: 80.0,
point: LatLng(48.8566, 2.3522),
builder: (ctx) => Container(
child: FlutterLogo(colors: Colors.purple),
child: FlutterLogo(
colors: Colors.purple,
key: ObjectKey(Colors.purple),
),
),
),
];
Expand All @@ -57,9 +64,14 @@ class HomePage extends StatelessWidget {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
// For example purposes. It is recommended to use
// TileProvider with a caching and retry strategy, like
// NetworkTileProvider or CachedNetworkTileProvider
tileProvider: NonCachingNetworkTileProvider(),
),
MarkerLayerOptions(markers: markers)
],
),
Expand Down
7 changes: 7 additions & 0 deletions lib/src/layer/tile_provider/tile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class NetworkTileProvider extends TileProvider {
}
}

class NonCachingNetworkTileProvider extends TileProvider {
@override
ImageProvider getImage(Coords<num> coords, TileLayerOptions options) {
return NetworkImage(getTileUrl(coords, options));

This comment has been minimized.

Copy link
@JeanChristopheMobizel

JeanChristopheMobizel Nov 26, 2019

in the image_provider.dart, NetworkImage class comment's mention (line 473) that

/// The image will be cached regardless of cache headers from the server.

In order to skip the image caching we used an AdvancedNetworkImage provider from https://pub.dev/packages/flutter_advanced_networkimage with disableMemoryCache to true

}
}

class AssetTileProvider extends TileProvider {
@override
ImageProvider getImage(Coords<num> coords, TileLayerOptions options) {
Expand Down

0 comments on commit e8e687b

Please sign in to comment.