Skip to content

Commit 503593e

Browse files
committed
Replaced TileLayer options property with String networkUrl in image provider
Fixed equality in image provider to ensure changes to tile layer URL template make tiles update (breaks tile image cache keys when URL changes)
1 parent 07b2bfd commit 503593e

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

lib/src/providers/image_provider/image_provider.dart

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,28 @@ class _FMTCImageProvider extends ImageProvider<_FMTCImageProvider> {
1010
/// Create a specialised [ImageProvider] that uses FMTC internals to enable
1111
/// browse caching
1212
const _FMTCImageProvider({
13-
required this.provider,
14-
required this.options,
13+
required this.networkUrl,
1514
required this.coords,
15+
required this.provider,
1616
required this.startedLoading,
1717
required this.finishedLoadingBytes,
1818
});
1919

20-
/// An instance of the [FMTCTileProvider] in use
21-
final FMTCTileProvider provider;
22-
23-
/// An instance of the [TileLayer] in use
24-
final TileLayer options;
20+
/// The network URL of the tile at [coords], determined by
21+
/// [FMTCTileProvider.getTileUrl]
22+
final String networkUrl;
2523

2624
/// The coordinates of the tile to be fetched
25+
///
26+
/// Must be set when using the image provider - acts as a key for
27+
/// [FMTCTileProvider.tileLoadingInterceptor], and is used for some debug
28+
/// info. Optional when [provideTile] is used directly, if
29+
/// `tileLoadingInterceptor` functionality is not used.
2730
final TileCoordinates coords;
2831

32+
/// An instance of the [FMTCTileProvider] in use
33+
final FMTCTileProvider provider;
34+
2935
/// Function invoked when the image starts loading (not from cache)
3036
///
3137
/// Used with [finishedLoadingBytes] to safely dispose of the `httpClient`
@@ -46,7 +52,7 @@ class _FMTCImageProvider extends ImageProvider<_FMTCImageProvider> {
4652
MultiFrameImageStreamCompleter(
4753
codec: provideTile(
4854
coords: coords,
49-
networkUrl: provider.getTileUrl(coords, options),
55+
networkUrl: networkUrl,
5056
provider: provider,
5157
key: key,
5258
finishedLoadingBytes: finishedLoadingBytes,
@@ -55,19 +61,15 @@ class _FMTCImageProvider extends ImageProvider<_FMTCImageProvider> {
5561
).then(ImmutableBuffer.fromUint8List).then((v) => decode(v)),
5662
scale: 1,
5763
debugLabel: coords.toString(),
58-
informationCollector: () {
59-
final tileUrl = provider.getTileUrl(coords, options);
60-
61-
return [
62-
DiagnosticsProperty('Stores', provider.stores),
63-
DiagnosticsProperty('Tile coordinates', coords),
64-
DiagnosticsProperty('Tile URL', tileUrl),
65-
DiagnosticsProperty(
66-
'Tile storage-suitable UID',
67-
provider.urlTransformer?.call(tileUrl) ?? tileUrl,
68-
),
69-
];
70-
},
64+
informationCollector: () => [
65+
DiagnosticsProperty('Stores', provider.stores),
66+
DiagnosticsProperty('Tile coordinates', coords),
67+
DiagnosticsProperty('Tile URL', networkUrl),
68+
DiagnosticsProperty(
69+
'Tile storage-suitable UID',
70+
provider.urlTransformer?.call(networkUrl) ?? networkUrl,
71+
),
72+
],
7173
);
7274

7375
/// {@macro fmtc.tileProvider.provideTile}
@@ -149,6 +151,7 @@ class _FMTCImageProvider extends ImageProvider<_FMTCImageProvider> {
149151
bool operator ==(Object other) =>
150152
identical(this, other) ||
151153
(other is _FMTCImageProvider &&
154+
other.networkUrl == networkUrl &&
152155
other.coords == coords &&
153156
other.provider == provider);
154157

lib/src/providers/tile_provider/tile_provider.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ class FMTCTileProvider extends TileProvider {
278278
@override
279279
ImageProvider getImage(TileCoordinates coordinates, TileLayer options) =>
280280
_FMTCImageProvider(
281-
provider: this,
282-
options: options,
281+
networkUrl: getTileUrl(coordinates, options),
283282
coords: coordinates,
283+
provider: this,
284284
startedLoading: () => _tilesInProgress[coordinates] = Completer(),
285285
finishedLoadingBytes: () {
286286
_tilesInProgress[coordinates]?.complete();
@@ -352,8 +352,8 @@ class FMTCTileProvider extends TileProvider {
352352
bool requireValidImage = false,
353353
}) =>
354354
_FMTCImageProvider.provideTile(
355-
coords: coords,
356355
networkUrl: networkUrl,
356+
coords: coords,
357357
provider: this,
358358
key: key,
359359
startedLoading: startedLoading,

0 commit comments

Comments
 (0)