Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
cache tileOverlays
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Yang committed Jan 21, 2021
1 parent fd0b1e3 commit 38d4d5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
return _channels[mapId];
}

// Keep a collection of id -> GetTileCallback
// Every method call passes the int mapId
final Map<int, MapGetTileCallback> _getTileCallbacks = {};
// Keep a collection of id -> TileOverlay.
final Map<int, TileOverlay> _tileOverlays = {};

/// Initializes the platform interface with [id].
///
Expand Down Expand Up @@ -189,10 +188,9 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
));
break;
case 'tileOverlay#getTile':
final MapGetTileCallback getTileCallback = _getTileCallbacks[mapId];
assert(getTileCallback != null);
final Tile tile = await getTileCallback(
call.arguments['tileOverlayId'],
final TileOverlay tileOverlay = _tileOverlays[mapId];
assert(tileOverlay.tileProvider != null);
final Tile tile = await tileOverlay.tileProvider.getTile(
call.arguments['x'],
call.arguments['y'],
call.arguments['zoom'],
Expand Down Expand Up @@ -505,10 +503,10 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
///
/// `mapId` and `callback` must not be null.
@override
void setGetTileCallback(
{@required int mapId, @required MapGetTileCallback callback}) {
assert(mapId != null && callback != null);
_getTileCallbacks[mapId] = callback;
void setTileOverlay(
{@required int mapId, @required TileOverlay tileOverlay}) {
assert(mapId != null && tileOverlay != null);
_tileOverlays[mapId] = tileOverlay;
}

/// This method builds the appropriate platform view where the map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
throw UnimplementedError('takeSnapshot() has not been implemented.');
}

/// Set the [MapGetTileCallback] for the map, which will be called
/// when a [Tile] is requested for an added [TileProvider].
void setGetTileCallback({@required int mapId, MapGetTileCallback callback}) {
/// Set the [TileOverlay] for the map.
///
/// The [TileProvider] is called when a [Tile] is requested.
void setTileOverlay(
{@required int mapId, @required TileOverlay tileOverlay}) {
throw UnimplementedError('onGetTile() has not been implemented.');
}

Expand Down

0 comments on commit 38d4d5a

Please sign in to comment.