@@ -11,8 +11,6 @@ final _nullLatLngBounds = LatLngBounds(
1111);
1212
1313// Defaults taken from the Google Maps Platform SDK documentation.
14- final _defaultStrokeColor = Colors .black.value;
15- final _defaultFillColor = Colors .transparent.value;
1614final _defaultCssColor = '#000000' ;
1715final _defaultCssOpacity = 0.0 ;
1816
@@ -59,41 +57,39 @@ double _getCssOpacity(Color color) {
5957// buildingsEnabled seems to not have an equivalent in web
6058// padding seems to behave differently in web than mobile. You can't move UI elements in web.
6159gmaps.MapOptions _rawOptionsToGmapsOptions (Map <String , dynamic > rawOptions) {
62- Map <String , dynamic > optionsUpdate = rawOptions['options' ] ?? {};
63-
6460 gmaps.MapOptions options = gmaps.MapOptions ();
6561
66- if (_mapTypeToMapTypeId.containsKey (optionsUpdate ['mapType' ])) {
67- options.mapTypeId = _mapTypeToMapTypeId[optionsUpdate ['mapType' ]];
62+ if (_mapTypeToMapTypeId.containsKey (rawOptions ['mapType' ])) {
63+ options.mapTypeId = _mapTypeToMapTypeId[rawOptions ['mapType' ]];
6864 }
6965
70- if (optionsUpdate ['minMaxZoomPreference' ] != null ) {
66+ if (rawOptions ['minMaxZoomPreference' ] != null ) {
7167 options
72- ..minZoom = optionsUpdate ['minMaxZoomPreference' ][0 ]
73- ..maxZoom = optionsUpdate ['minMaxZoomPreference' ][1 ];
68+ ..minZoom = rawOptions ['minMaxZoomPreference' ][0 ]
69+ ..maxZoom = rawOptions ['minMaxZoomPreference' ][1 ];
7470 }
7571
76- if (optionsUpdate ['cameraTargetBounds' ] != null ) {
72+ if (rawOptions ['cameraTargetBounds' ] != null ) {
7773 // Needs gmaps.MapOptions.restriction and gmaps.MapRestriction
7874 // see: https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions.restriction
7975 }
8076
81- if (optionsUpdate ['zoomControlsEnabled' ] != null ) {
82- options.zoomControl = optionsUpdate ['zoomControlsEnabled' ];
77+ if (rawOptions ['zoomControlsEnabled' ] != null ) {
78+ options.zoomControl = rawOptions ['zoomControlsEnabled' ];
8379 }
8480
85- if (optionsUpdate ['styles' ] != null ) {
86- options.styles = optionsUpdate ['styles' ];
81+ if (rawOptions ['styles' ] != null ) {
82+ options.styles = rawOptions ['styles' ];
8783 }
8884
89- if (optionsUpdate ['scrollGesturesEnabled' ] == false ||
90- optionsUpdate ['zoomGesturesEnabled' ] == false ) {
85+ if (rawOptions ['scrollGesturesEnabled' ] == false ||
86+ rawOptions ['zoomGesturesEnabled' ] == false ) {
9187 options.gestureHandling = 'none' ;
9288 } else {
9389 options.gestureHandling = 'auto' ;
9490 }
9591
96- // These don't have any optionUpdate entry, but they seem to be off in the native maps.
92+ // These don't have any rawOptions entry, but they seem to be off in the native maps.
9793 options.mapTypeControl = false ;
9894 options.fullscreenControl = false ;
9995 options.streetViewControl = false ;
@@ -102,26 +98,21 @@ gmaps.MapOptions _rawOptionsToGmapsOptions(Map<String, dynamic> rawOptions) {
10298}
10399
104100gmaps.MapOptions _applyInitialPosition (
105- Map < String , dynamic > rawOptions ,
101+ CameraPosition initialPosition ,
106102 gmaps.MapOptions options,
107103) {
108104 // Adjust the initial position, if passed...
109- Map <String , dynamic > initialPosition = rawOptions['initialCameraPosition' ];
110105 if (initialPosition != null ) {
111- final position = CameraPosition .fromMap (initialPosition);
112- options.zoom = position.zoom;
113- options.center =
114- gmaps.LatLng (position.target.latitude, position.target.longitude);
106+ options.zoom = initialPosition.zoom;
107+ options.center = gmaps.LatLng (
108+ initialPosition.target.latitude, initialPosition.target.longitude);
115109 }
116110 return options;
117111}
118112
119113// Extracts the status of the traffic layer from the rawOptions map.
120114bool _isTrafficLayerEnabled (Map <String , dynamic > rawOptions) {
121- if (rawOptions['options' ] == null ) {
122- return false ;
123- }
124- return rawOptions['options' ]['trafficEnabled' ] ?? false ;
115+ return rawOptions['trafficEnabled' ] ?? false ;
125116}
126117
127118// Coverts the incoming JSON object into a List of MapTypeStyler objects.
@@ -257,126 +248,6 @@ CameraPosition _gmViewportToCameraPosition(gmaps.GMap map) {
257248 );
258249}
259250
260- Set <Marker > _rawOptionsToInitialMarkers (Map <String , dynamic > rawOptions) {
261- final List <Map <String , dynamic >> list = rawOptions['markersToAdd' ];
262- Set <Marker > markers = {};
263- markers.addAll (list? .map ((rawMarker) {
264- Offset offset;
265- LatLng position;
266- InfoWindow infoWindow;
267- BitmapDescriptor icon;
268- if (rawMarker['anchor' ] != null ) {
269- offset = Offset ((rawMarker['anchor' ][0 ]), (rawMarker['anchor' ][1 ]));
270- }
271- if (rawMarker['position' ] != null ) {
272- position = LatLng .fromJson (rawMarker['position' ]);
273- }
274- if (rawMarker['infoWindow' ] != null ) {
275- final String title = rawMarker['infoWindow' ]['title' ];
276- final String snippet = rawMarker['infoWindow' ]['snippet' ];
277- if (title != null || snippet != null ) {
278- infoWindow = InfoWindow (
279- title: title ?? '' ,
280- snippet: snippet ?? '' ,
281- );
282- }
283- }
284- if (rawMarker['icon' ] != null ) {
285- icon = BitmapDescriptor .fromJson (rawMarker['icon' ]);
286- }
287- return Marker (
288- markerId: MarkerId (rawMarker['markerId' ]),
289- alpha: rawMarker['alpha' ],
290- anchor: offset,
291- consumeTapEvents: rawMarker['consumeTapEvents' ],
292- draggable: rawMarker['draggable' ],
293- flat: rawMarker['flat' ],
294- icon: icon,
295- infoWindow: infoWindow,
296- position: position ?? _nullLatLng,
297- rotation: rawMarker['rotation' ],
298- visible: rawMarker['visible' ],
299- zIndex: rawMarker['zIndex' ],
300- );
301- }) ??
302- []);
303- return markers;
304- }
305-
306- Set <Circle > _rawOptionsToInitialCircles (Map <String , dynamic > rawOptions) {
307- final List <Map <String , dynamic >> list = rawOptions['circlesToAdd' ];
308- Set <Circle > circles = {};
309- circles.addAll (list? .map ((rawCircle) {
310- LatLng center;
311- if (rawCircle['center' ] != null ) {
312- center = LatLng .fromJson (rawCircle['center' ]);
313- }
314- return Circle (
315- circleId: CircleId (rawCircle['circleId' ]),
316- consumeTapEvents: rawCircle['consumeTapEvents' ],
317- fillColor: Color (rawCircle['fillColor' ] ?? _defaultFillColor),
318- center: center ?? _nullLatLng,
319- radius: rawCircle['radius' ],
320- strokeColor: Color (rawCircle['strokeColor' ] ?? _defaultStrokeColor),
321- strokeWidth: rawCircle['strokeWidth' ],
322- visible: rawCircle['visible' ],
323- zIndex: rawCircle['zIndex' ],
324- );
325- }) ??
326- []);
327- return circles;
328- }
329-
330- // Unsupported on the web: endCap, jointType, patterns and startCap.
331- Set <Polyline > _rawOptionsToInitialPolylines (Map <String , dynamic > rawOptions) {
332- final List <Map <String , dynamic >> list = rawOptions['polylinesToAdd' ];
333- Set <Polyline > polylines = {};
334- polylines.addAll (list? .map ((rawPolyline) {
335- return Polyline (
336- polylineId: PolylineId (rawPolyline['polylineId' ]),
337- consumeTapEvents: rawPolyline['consumeTapEvents' ],
338- color: Color (rawPolyline['color' ] ?? _defaultStrokeColor),
339- geodesic: rawPolyline['geodesic' ],
340- visible: rawPolyline['visible' ],
341- zIndex: rawPolyline['zIndex' ],
342- width: rawPolyline['width' ],
343- points: rawPolyline['points' ]
344- ? .map <LatLng >((rawPoint) => LatLng .fromJson (rawPoint))
345- ? .toList (),
346- );
347- }) ??
348- []);
349- return polylines;
350- }
351-
352- Set <Polygon > _rawOptionsToInitialPolygons (Map <String , dynamic > rawOptions) {
353- final List <Map <String , dynamic >> list = rawOptions['polygonsToAdd' ];
354- Set <Polygon > polygons = {};
355-
356- polygons.addAll (list? .map ((rawPolygon) {
357- return Polygon (
358- polygonId: PolygonId (rawPolygon['polygonId' ]),
359- consumeTapEvents: rawPolygon['consumeTapEvents' ],
360- fillColor: Color (rawPolygon['fillColor' ] ?? _defaultFillColor),
361- geodesic: rawPolygon['geodesic' ],
362- strokeColor: Color (rawPolygon['strokeColor' ] ?? _defaultStrokeColor),
363- strokeWidth: rawPolygon['strokeWidth' ],
364- visible: rawPolygon['visible' ],
365- zIndex: rawPolygon['zIndex' ],
366- points: rawPolygon['points' ]
367- ? .map <LatLng >((rawPoint) => LatLng .fromJson (rawPoint))
368- ? .toList (),
369- holes: rawPolygon['holes' ]
370- ? .map <List <LatLng >>((List hole) => hole
371- ? .map <LatLng >((rawPoint) => LatLng .fromJson (rawPoint))
372- ? .toList ())
373- ? .toList (),
374- );
375- }) ??
376- []);
377- return polygons;
378- }
379-
380251// Convert plugin objects to gmaps.Options objects
381252// TODO: Move to their appropriate objects, maybe make these copy constructors:
382253// Marker.fromMarker(anotherMarker, moreOptions);
@@ -550,7 +421,7 @@ gmaps.PolylineOptions _polylineOptionsFromPolyline(
550421
551422// Translates a [CameraUpdate] into operations on a [gmaps.GMap].
552423void _applyCameraUpdate (gmaps.GMap map, CameraUpdate update) {
553- final json = update.toJson ();
424+ final json = update.toJson () as List < dynamic > ;
554425 switch (json[0 ]) {
555426 case 'newCameraPosition' :
556427 map.heading = json[1 ]['bearing' ];
0 commit comments