@@ -294,30 +294,34 @@ class _GoogleMapState extends State<GoogleMap> {
294
294
Map <PolygonId , Polygon > _polygons = < PolygonId , Polygon > {};
295
295
Map <PolylineId , Polyline > _polylines = < PolylineId , Polyline > {};
296
296
Map <CircleId , Circle > _circles = < CircleId , Circle > {};
297
- late _GoogleMapOptions _googleMapOptions ;
297
+ late MapConfiguration _mapConfiguration ;
298
298
299
299
@override
300
300
Widget build (BuildContext context) {
301
- return GoogleMapsFlutterPlatform .instance.buildViewWithTextDirection (
301
+ return GoogleMapsFlutterPlatform .instance.buildViewWithConfiguration (
302
302
_mapId,
303
303
onPlatformViewCreated,
304
- textDirection: widget.layoutDirection ??
305
- Directionality .maybeOf (context) ??
306
- TextDirection .ltr,
307
- initialCameraPosition: widget.initialCameraPosition,
308
- markers: widget.markers,
309
- polygons: widget.polygons,
310
- polylines: widget.polylines,
311
- circles: widget.circles,
312
- gestureRecognizers: widget.gestureRecognizers,
313
- mapOptions: _googleMapOptions.toMap (),
304
+ widgetConfiguration: MapWidgetConfiguration (
305
+ textDirection: widget.layoutDirection ??
306
+ Directionality .maybeOf (context) ??
307
+ TextDirection .ltr,
308
+ initialCameraPosition: widget.initialCameraPosition,
309
+ gestureRecognizers: widget.gestureRecognizers,
310
+ ),
311
+ mapObjects: MapObjects (
312
+ markers: widget.markers,
313
+ polygons: widget.polygons,
314
+ polylines: widget.polylines,
315
+ circles: widget.circles,
316
+ ),
317
+ mapConfiguration: _mapConfiguration,
314
318
);
315
319
}
316
320
317
321
@override
318
322
void initState () {
319
323
super .initState ();
320
- _googleMapOptions = _GoogleMapOptions . fromWidget (widget);
324
+ _mapConfiguration = _configurationFromMapWidget (widget);
321
325
_markers = keyByMarkerId (widget.markers);
322
326
_polygons = keyByPolygonId (widget.polygons);
323
327
_polylines = keyByPolylineId (widget.polylines);
@@ -347,16 +351,15 @@ class _GoogleMapState extends State<GoogleMap> {
347
351
}
348
352
349
353
Future <void > _updateOptions () async {
350
- final _GoogleMapOptions newOptions = _GoogleMapOptions .fromWidget (widget);
351
- final Map <String , dynamic > updates =
352
- _googleMapOptions.updatesMap (newOptions);
354
+ final MapConfiguration newConfig = _configurationFromMapWidget (widget);
355
+ final MapConfiguration updates = newConfig.diffFrom (_mapConfiguration);
353
356
if (updates.isEmpty) {
354
357
return ;
355
358
}
356
359
final GoogleMapController controller = await _controller.future;
357
360
// ignore: unawaited_futures
358
- controller._updateMapOptions (updates);
359
- _googleMapOptions = newOptions ;
361
+ controller._updateMapConfiguration (updates);
362
+ _mapConfiguration = newConfig ;
360
363
}
361
364
362
365
Future <void > _updateMarkers () async {
@@ -524,98 +527,27 @@ class _GoogleMapState extends State<GoogleMap> {
524
527
}
525
528
}
526
529
527
- /// Configuration options for the GoogleMaps user interface.
528
- class _GoogleMapOptions {
529
- _GoogleMapOptions .fromWidget (GoogleMap map)
530
- : compassEnabled = map.compassEnabled,
531
- mapToolbarEnabled = map.mapToolbarEnabled,
532
- cameraTargetBounds = map.cameraTargetBounds,
533
- mapType = map.mapType,
534
- minMaxZoomPreference = map.minMaxZoomPreference,
535
- rotateGesturesEnabled = map.rotateGesturesEnabled,
536
- scrollGesturesEnabled = map.scrollGesturesEnabled,
537
- tiltGesturesEnabled = map.tiltGesturesEnabled,
538
- trackCameraPosition = map.onCameraMove != null ,
539
- zoomControlsEnabled = map.zoomControlsEnabled,
540
- zoomGesturesEnabled = map.zoomGesturesEnabled,
541
- liteModeEnabled = map.liteModeEnabled,
542
- myLocationEnabled = map.myLocationEnabled,
543
- myLocationButtonEnabled = map.myLocationButtonEnabled,
544
- padding = map.padding,
545
- indoorViewEnabled = map.indoorViewEnabled,
546
- trafficEnabled = map.trafficEnabled,
547
- buildingsEnabled = map.buildingsEnabled,
548
- assert (! map.liteModeEnabled || Platform .isAndroid);
549
-
550
- final bool compassEnabled;
551
-
552
- final bool mapToolbarEnabled;
553
-
554
- final CameraTargetBounds cameraTargetBounds;
555
-
556
- final MapType mapType;
557
-
558
- final MinMaxZoomPreference minMaxZoomPreference;
559
-
560
- final bool rotateGesturesEnabled;
561
-
562
- final bool scrollGesturesEnabled;
563
-
564
- final bool tiltGesturesEnabled;
565
-
566
- final bool trackCameraPosition;
567
-
568
- final bool zoomControlsEnabled;
569
-
570
- final bool zoomGesturesEnabled;
571
-
572
- final bool liteModeEnabled;
573
-
574
- final bool myLocationEnabled;
575
-
576
- final bool myLocationButtonEnabled;
577
-
578
- final EdgeInsets padding;
579
-
580
- final bool indoorViewEnabled;
581
-
582
- final bool trafficEnabled;
583
-
584
- final bool buildingsEnabled;
585
-
586
- Map <String , dynamic > toMap () {
587
- return < String , dynamic > {
588
- 'compassEnabled' : compassEnabled,
589
- 'mapToolbarEnabled' : mapToolbarEnabled,
590
- 'cameraTargetBounds' : cameraTargetBounds.toJson (),
591
- 'mapType' : mapType.index,
592
- 'minMaxZoomPreference' : minMaxZoomPreference.toJson (),
593
- 'rotateGesturesEnabled' : rotateGesturesEnabled,
594
- 'scrollGesturesEnabled' : scrollGesturesEnabled,
595
- 'tiltGesturesEnabled' : tiltGesturesEnabled,
596
- 'zoomControlsEnabled' : zoomControlsEnabled,
597
- 'zoomGesturesEnabled' : zoomGesturesEnabled,
598
- 'liteModeEnabled' : liteModeEnabled,
599
- 'trackCameraPosition' : trackCameraPosition,
600
- 'myLocationEnabled' : myLocationEnabled,
601
- 'myLocationButtonEnabled' : myLocationButtonEnabled,
602
- 'padding' : < double > [
603
- padding.top,
604
- padding.left,
605
- padding.bottom,
606
- padding.right,
607
- ],
608
- 'indoorEnabled' : indoorViewEnabled,
609
- 'trafficEnabled' : trafficEnabled,
610
- 'buildingsEnabled' : buildingsEnabled,
611
- };
612
- }
613
-
614
- Map <String , dynamic > updatesMap (_GoogleMapOptions newOptions) {
615
- final Map <String , dynamic > prevOptionsMap = toMap ();
616
-
617
- return newOptions.toMap ()
618
- ..removeWhere (
619
- (String key, dynamic value) => prevOptionsMap[key] == value);
620
- }
530
+ /// Builds a [MapConfiguration] from the given [map] .
531
+ MapConfiguration _configurationFromMapWidget (GoogleMap map) {
532
+ assert (! map.liteModeEnabled || Platform .isAndroid);
533
+ return MapConfiguration (
534
+ compassEnabled: map.compassEnabled,
535
+ mapToolbarEnabled: map.mapToolbarEnabled,
536
+ cameraTargetBounds: map.cameraTargetBounds,
537
+ mapType: map.mapType,
538
+ minMaxZoomPreference: map.minMaxZoomPreference,
539
+ rotateGesturesEnabled: map.rotateGesturesEnabled,
540
+ scrollGesturesEnabled: map.scrollGesturesEnabled,
541
+ tiltGesturesEnabled: map.tiltGesturesEnabled,
542
+ trackCameraPosition: map.onCameraMove != null ,
543
+ zoomControlsEnabled: map.zoomControlsEnabled,
544
+ zoomGesturesEnabled: map.zoomGesturesEnabled,
545
+ liteModeEnabled: map.liteModeEnabled,
546
+ myLocationEnabled: map.myLocationEnabled,
547
+ myLocationButtonEnabled: map.myLocationButtonEnabled,
548
+ padding: map.padding,
549
+ indoorViewEnabled: map.indoorViewEnabled,
550
+ trafficEnabled: map.trafficEnabled,
551
+ buildingsEnabled: map.buildingsEnabled,
552
+ );
621
553
}
0 commit comments