Google Map - Dart
Google Map - Dart
part of google_maps_flutter;
/// A widget which displays a map with data obtained from the Google Maps servic
e.
class GoogleMap extends StatefulWidget {
/// Creates a widget displaying data from Google Maps services.
///
/// [AssertionError] will be thrown if [initialCameraPosition] is null;
const GoogleMap({
Key key,
@required this.initialCameraPosition,
this.onMapCreated,
this.gestureRecognizers,
this.compassEnabled = true,
this.mapToolbarEnabled = true,
this.cameraTargetBounds = CameraTargetBounds.unbounded,
this.mapType = MapType.normal,
this.minMaxZoomPreference = MinMaxZoomPreference.unbounded,
this.rotateGesturesEnabled = true,
this.scrollGesturesEnabled = true,
this.zoomControlsEnabled = true,
this.zoomGesturesEnabled = true,
this.liteModeEnabled = false,
this.tiltGesturesEnabled = true,
this.myLocationEnabled = false,
this.myLocationButtonEnabled = true,
/// True if the map should show a toolbar when you interact with the map. Andr
oid only.
final bool mapToolbarEnabled;
/// True if the map view should show zoom controls. This includes two buttons
/// to zoom in and zoom out. The default value is to show zoom controls.
///
/// This is only supported on Android. And this field is silently ignored on i
OS.
final bool zoomControlsEnabled;
/// True if the map view should be in lite mode. Android only.
///
/// See https://developers.google.com/maps/documentation/android-sdk/lite#over
view_of_lite_mode for more details.
final bool liteModeEnabled;
/// Called when camera movement has ended, there are no pending
/// animations and the user has stopped interacting with the map.
final VoidCallback onCameraIdle;
@override
Widget build(BuildContext context) {
final Map<String, dynamic> creationParams = <String, dynamic>{
'initialCameraPosition': widget.initialCameraPosition?.toMap(),
'options': _googleMapOptions.toMap(),
'markersToAdd': serializeMarkerSet(widget.markers),
'polygonsToAdd': serializePolygonSet(widget.polygons),
'polylinesToAdd': serializePolylineSet(widget.polylines),
'circlesToAdd': serializeCircleSet(widget.circles),
};
return _googleMapsFlutterPlatform.buildView(
creationParams,
widget.gestureRecognizers,
onPlatformViewCreated,
);
}
@override
void initState() {
super.initState();
_googleMapOptions = _GoogleMapOptions.fromWidget(widget);
_markers = keyByMarkerId(widget.markers);
_polygons = keyByPolygonId(widget.polygons);
_polylines = keyByPolylineId(widget.polylines);
_circles = keyByCircleId(widget.circles);
}
@override
void didUpdateWidget(GoogleMap oldWidget) {
super.didUpdateWidget(oldWidget);
_updateOptions();
_updateMarkers();
_updatePolygons();
_updatePolylines();
_updateCircles();
}
addIfNonNull('compassEnabled', compassEnabled);
addIfNonNull('mapToolbarEnabled', mapToolbarEnabled);
addIfNonNull('cameraTargetBounds', cameraTargetBounds?.toJson());
addIfNonNull('mapType', mapType?.index);
addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?.toJson());
addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled);
addIfNonNull('scrollGesturesEnabled', scrollGesturesEnabled);
addIfNonNull('tiltGesturesEnabled', tiltGesturesEnabled);
addIfNonNull('zoomControlsEnabled', zoomControlsEnabled);
addIfNonNull('zoomGesturesEnabled', zoomGesturesEnabled);
addIfNonNull('liteModeEnabled', liteModeEnabled);
addIfNonNull('trackCameraPosition', trackCameraPosition);
addIfNonNull('myLocationEnabled', myLocationEnabled);
addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled);
addIfNonNull('padding', <double>[
padding?.top,
padding?.left,
padding?.bottom,
padding?.right,
]);
addIfNonNull('indoorEnabled', indoorViewEnabled);
addIfNonNull('trafficEnabled', trafficEnabled);
addIfNonNull('buildingsEnabled', buildingsEnabled);
return optionsMap;
}
return newOptions.toMap()
..removeWhere(
(String key, dynamic value) => prevOptionsMap[key] == value);
}
}