30
30
import com .google .android .gms .maps .GoogleMapOptions ;
31
31
import com .google .android .gms .maps .MapView ;
32
32
import com .google .android .gms .maps .OnMapReadyCallback ;
33
- import com .google .android .gms .maps .model .CameraPosition ;
34
33
import com .google .android .gms .maps .model .Circle ;
35
34
import com .google .android .gms .maps .model .LatLng ;
36
35
import com .google .android .gms .maps .model .LatLngBounds ;
44
43
import com .google .maps .android .collections .MarkerManager ;
45
44
import io .flutter .embedding .engine .plugins .activity .ActivityPluginBinding ;
46
45
import io .flutter .plugin .common .BinaryMessenger ;
47
- import io .flutter .plugin .common .MethodChannel ;
48
46
import io .flutter .plugin .platform .PlatformView ;
49
47
import io .flutter .plugins .googlemaps .Messages .FlutterError ;
50
48
import io .flutter .plugins .googlemaps .Messages .MapsApi ;
49
+ import io .flutter .plugins .googlemaps .Messages .MapsCallbackApi ;
51
50
import io .flutter .plugins .googlemaps .Messages .MapsInspectorApi ;
52
51
import java .io .ByteArrayOutputStream ;
53
52
import java .util .ArrayList ;
54
- import java .util .Collections ;
55
- import java .util .HashMap ;
56
53
import java .util .List ;
57
54
import java .util .Map ;
58
55
import java .util .Objects ;
@@ -73,7 +70,7 @@ class GoogleMapController
73
70
74
71
private static final String TAG = "GoogleMapController" ;
75
72
private final int id ;
76
- private final MethodChannel methodChannel ;
73
+ private final MapsCallbackApi flutterApi ;
77
74
private final BinaryMessenger binaryMessenger ;
78
75
private final GoogleMapOptions options ;
79
76
@ Nullable private MapView mapView ;
@@ -121,19 +118,18 @@ class GoogleMapController
121
118
this .mapView = new MapView (context , options );
122
119
this .density = context .getResources ().getDisplayMetrics ().density ;
123
120
this .binaryMessenger = binaryMessenger ;
124
- methodChannel =
125
- new MethodChannel (binaryMessenger , "plugins.flutter.dev/google_maps_android_" + id );
121
+ flutterApi = new MapsCallbackApi (binaryMessenger , Integer .toString (id ));
126
122
MapsApi .setUp (binaryMessenger , Integer .toString (id ), this );
127
123
MapsInspectorApi .setUp (binaryMessenger , Integer .toString (id ), this );
128
124
AssetManager assetManager = context .getAssets ();
129
125
this .lifecycleProvider = lifecycleProvider ;
130
- this .clusterManagersController = new ClusterManagersController (methodChannel , context );
126
+ this .clusterManagersController = new ClusterManagersController (flutterApi , context );
131
127
this .markersController =
132
- new MarkersController (methodChannel , clusterManagersController , assetManager , density );
133
- this .polygonsController = new PolygonsController (methodChannel , density );
134
- this .polylinesController = new PolylinesController (methodChannel , assetManager , density );
135
- this .circlesController = new CirclesController (methodChannel , density );
136
- this .tileOverlaysController = new TileOverlaysController (methodChannel );
128
+ new MarkersController (flutterApi , clusterManagersController , assetManager , density );
129
+ this .polygonsController = new PolygonsController (flutterApi , density );
130
+ this .polylinesController = new PolylinesController (flutterApi , assetManager , density );
131
+ this .circlesController = new CirclesController (flutterApi , density );
132
+ this .tileOverlaysController = new TileOverlaysController (flutterApi );
137
133
}
138
134
139
135
// Constructor for testing purposes only
@@ -142,7 +138,7 @@ class GoogleMapController
142
138
int id ,
143
139
Context context ,
144
140
BinaryMessenger binaryMessenger ,
145
- MethodChannel methodChannel ,
141
+ MapsCallbackApi flutterApi ,
146
142
LifecycleProvider lifecycleProvider ,
147
143
GoogleMapOptions options ,
148
144
ClusterManagersController clusterManagersController ,
@@ -154,7 +150,7 @@ class GoogleMapController
154
150
this .id = id ;
155
151
this .context = context ;
156
152
this .binaryMessenger = binaryMessenger ;
157
- this .methodChannel = methodChannel ;
153
+ this .flutterApi = flutterApi ;
158
154
this .options = options ;
159
155
this .mapView = new MapView (context , options );
160
156
this .density = context .getResources ().getDisplayMetrics ().density ;
@@ -182,10 +178,6 @@ void init() {
182
178
mapView .getMapAsync (this );
183
179
}
184
180
185
- private CameraPosition getCameraPosition () {
186
- return trackCameraPosition ? googleMap .getCameraPosition () : null ;
187
- }
188
-
189
181
@ Override
190
182
public void onMapReady (@ NonNull GoogleMap googleMap ) {
191
183
this .googleMap = googleMap ;
@@ -298,24 +290,17 @@ public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
298
290
299
291
@ Override
300
292
public void onMapClick (@ NonNull LatLng latLng ) {
301
- final Map <String , Object > arguments = new HashMap <>(2 );
302
- arguments .put ("position" , Convert .latLngToJson (latLng ));
303
- methodChannel .invokeMethod ("map#onTap" , arguments );
293
+ flutterApi .onTap (Convert .latLngToPigeon (latLng ), new NoOpVoidResult ());
304
294
}
305
295
306
296
@ Override
307
297
public void onMapLongClick (@ NonNull LatLng latLng ) {
308
- final Map <String , Object > arguments = new HashMap <>(2 );
309
- arguments .put ("position" , Convert .latLngToJson (latLng ));
310
- methodChannel .invokeMethod ("map#onLongPress" , arguments );
298
+ flutterApi .onLongPress (Convert .latLngToPigeon (latLng ), new NoOpVoidResult ());
311
299
}
312
300
313
301
@ Override
314
302
public void onCameraMoveStarted (int reason ) {
315
- final Map <String , Object > arguments = new HashMap <>(2 );
316
- boolean isGesture = reason == GoogleMap .OnCameraMoveStartedListener .REASON_GESTURE ;
317
- arguments .put ("isGesture" , isGesture );
318
- methodChannel .invokeMethod ("camera#onMoveStarted" , arguments );
303
+ flutterApi .onCameraMoveStarted (new NoOpVoidResult ());
319
304
}
320
305
321
306
@ Override
@@ -328,15 +313,14 @@ public void onCameraMove() {
328
313
if (!trackCameraPosition ) {
329
314
return ;
330
315
}
331
- final Map <String , Object > arguments = new HashMap <>(2 );
332
- arguments .put ("position" , Convert .cameraPositionToJson (googleMap .getCameraPosition ()));
333
- methodChannel .invokeMethod ("camera#onMove" , arguments );
316
+ flutterApi .onCameraMove (
317
+ Convert .cameraPositionToPigeon (googleMap .getCameraPosition ()), new NoOpVoidResult ());
334
318
}
335
319
336
320
@ Override
337
321
public void onCameraIdle () {
338
322
clusterManagersController .onCameraIdle ();
339
- methodChannel . invokeMethod ( "camera#onIdle" , Collections . singletonMap ( "map" , id ));
323
+ flutterApi . onCameraIdle ( new NoOpVoidResult ( ));
340
324
}
341
325
342
326
@ Override
0 commit comments