-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[google_maps_flutter] Add support for styling google maps #1697
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| [ | ||
| { | ||
| "elementType": "geometry", | ||
| "stylers": [ | ||
| { | ||
| "color": "#242f3e" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#746855" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "elementType": "labels.text.stroke", | ||
| "stylers": [ | ||
| { | ||
| "color": "#242f3e" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "administrative.locality", | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#d59563" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "poi", | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#d59563" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "poi.park", | ||
| "elementType": "geometry", | ||
| "stylers": [ | ||
| { | ||
| "color": "#263c3f" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "poi.park", | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#6b9a76" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "road", | ||
| "elementType": "geometry", | ||
| "stylers": [ | ||
| { | ||
| "color": "#38414e" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "road", | ||
| "elementType": "geometry.stroke", | ||
| "stylers": [ | ||
| { | ||
| "color": "#212a37" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "road", | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#9ca5b3" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "road.highway", | ||
| "elementType": "geometry", | ||
| "stylers": [ | ||
| { | ||
| "color": "#746855" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "road.highway", | ||
| "elementType": "geometry.stroke", | ||
| "stylers": [ | ||
| { | ||
| "color": "#1f2835" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "road.highway", | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#f3d19c" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "transit", | ||
| "elementType": "geometry", | ||
| "stylers": [ | ||
| { | ||
| "color": "#2f3948" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "transit.station", | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#d59563" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "water", | ||
| "elementType": "geometry", | ||
| "stylers": [ | ||
| { | ||
| "color": "#17263c" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "water", | ||
| "elementType": "labels.text.fill", | ||
| "stylers": [ | ||
| { | ||
| "color": "#515c6d" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "featureType": "water", | ||
| "elementType": "labels.text.stroke", | ||
| "stylers": [ | ||
| { | ||
| "color": "#17263c" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,6 +226,14 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { | |
| } else if ([call.method isEqualToString:@"map#isMyLocationButtonEnabled"]) { | ||
| NSNumber* isMyLocationButtonEnabled = @(_mapView.settings.myLocationButton); | ||
| result(isMyLocationButtonEnabled); | ||
| } else if ([call.method isEqualToString:@"map#setStyle"]) { | ||
| NSString* mapStyle = [call arguments]; | ||
| NSString* error = [self setMapStyle:mapStyle]; | ||
| if (error == nil) { | ||
| result(@[ @(YES) ]); | ||
| } else { | ||
| result(@[ @(NO), error ]); | ||
| } | ||
| } else { | ||
| result(FlutterMethodNotImplemented); | ||
| } | ||
|
|
@@ -308,6 +316,21 @@ - (void)setMyLocationButtonEnabled:(BOOL)enabled { | |
| _mapView.settings.myLocationButton = enabled; | ||
| } | ||
|
|
||
| - (NSString*)setMapStyle:(NSString*)mapStyle { | ||
| if (mapStyle == (id)[NSNull null] || mapStyle.length == 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we don't seem to cast to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get an IDE warning about comparison between incompatible pointer types, we could either cast it to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally reasonable was just wondering why this is different from the other similar checks in this file. Taking another look I guess it's because the other instances here are access |
||
| _mapView.mapStyle = nil; | ||
| return nil; | ||
| } | ||
| NSError* error; | ||
| GMSMapStyle* style = [GMSMapStyle styleWithJSONString:mapStyle error:&error]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any useful information in error we should send back to Dart?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error has some more details about what the issue with the JSON is. Though it is useful to know what the error is for fixing the style, I don't think we can take any action based on the specifics of the error on the dart side in this case. Typical action on error would be to keep the existing style (which is the default) or change to an empty/alternate style, which the user can currently do by checking the return value.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should pass back whatever information we have to the Dart side. e.g it's possible that I'm building an app for editing and previewing map styles, in which case I would even want to show the error to the user. |
||
| if (!style) { | ||
| return [error localizedDescription]; | ||
| } else { | ||
| _mapView.mapStyle = style; | ||
| return nil; | ||
| } | ||
| } | ||
|
|
||
| #pragma mark - GMSMapViewDelegate methods | ||
|
|
||
| - (void)mapView:(GMSMapView*)mapView willMove:(BOOL)gesture { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can
_controllerbe null here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is only called from
_nightModeTogglerwhere we first check for_isMapCreatedwhich is set alongside with_controller.