From 38d4d5a6db5e5cc61fd03ee2e6c8d462c6c628b0 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Thu, 21 Jan 2021 13:13:57 -0800 Subject: [PATCH] cache tileOverlays --- .../method_channel_google_maps_flutter.dart | 20 +++++++++---------- .../google_maps_flutter_platform.dart | 8 +++++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart index 2a891ca6bcea..df7b6d07fdc4 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart @@ -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 _getTileCallbacks = {}; + // Keep a collection of id -> TileOverlay. + final Map _tileOverlays = {}; /// Initializes the platform interface with [id]. /// @@ -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'], @@ -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 diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart index 5c6052b34751..93cda7c4749f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart +++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart @@ -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.'); }