Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Adds support for BuildingsEnabled property in Google Maps
Browse files Browse the repository at this point in the history
Added e2e
  • Loading branch information
Scott McArthur committed Dec 4, 2019
1 parent 8c19f6f commit cb67abb
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/google_maps_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.21+14

* Adds support for toggling 3D buildings.

## 0.5.21+13

* Add documentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) {
if (trafficEnabled != null) {
sink.setTrafficEnabled(toBoolean(trafficEnabled));
}
final Object buildingsEnabled = data.get("buildingsEnabled");
if (buildingsEnabled != null) {
sink.setBuildingsEnabled(toBoolean(buildingsEnabled));
}
}

/** Returns the dartMarkerId of the interpreted marker. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GoogleMapBuilder implements GoogleMapOptionsSink {
private boolean myLocationButtonEnabled = false;
private boolean indoorEnabled = true;
private boolean trafficEnabled = false;
private boolean buildingsEnabled = true;
private Object initialMarkers;
private Object initialPolygons;
private Object initialPolylines;
Expand All @@ -34,6 +35,7 @@ GoogleMapController build(
controller.setMyLocationButtonEnabled(myLocationButtonEnabled);
controller.setIndoorEnabled(indoorEnabled);
controller.setTrafficEnabled(trafficEnabled);
controller.setBuildingsEnabled(buildingsEnabled);
controller.setTrackCameraPosition(trackCameraPosition);
controller.setInitialMarkers(initialMarkers);
controller.setInitialPolygons(initialPolygons);
Expand Down Expand Up @@ -117,6 +119,11 @@ public void setTrafficEnabled(boolean trafficEnabled) {
this.trafficEnabled = trafficEnabled;
}

@Override
public void setBuildingsEnabled(boolean buildingsEnabled) {
this.buildingsEnabled = buildingsEnabled;
}

@Override
public void setMyLocationEnabled(boolean myLocationEnabled) {
this.myLocationEnabled = myLocationEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class GoogleMapController
private boolean myLocationButtonEnabled = false;
private boolean indoorEnabled = true;
private boolean trafficEnabled = false;
private boolean buildingsEnabled = true;
private boolean disposed = false;
private final float density;
private MethodChannel.Result mapReadyResult;
Expand Down Expand Up @@ -172,6 +173,7 @@ public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
this.googleMap.setIndoorEnabled(this.indoorEnabled);
this.googleMap.setTrafficEnabled(this.trafficEnabled);
this.googleMap.setBuildingsEnabled(this.buildingsEnabled);
googleMap.setOnInfoWindowClickListener(this);
if (mapReadyResult != null) {
mapReadyResult.success(null);
Expand Down Expand Up @@ -361,6 +363,11 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
result.success(googleMap.isTrafficEnabled());
break;
}
case "map#isBuildingsEnabled":
{
result.success(googleMap.isBuildingsEnabled());
break;
}
case "map#setStyle":
{
String mapStyle = (String) call.arguments;
Expand Down Expand Up @@ -716,4 +723,8 @@ public void setIndoorEnabled(boolean indoorEnabled) {
public void setTrafficEnabled(boolean trafficEnabled) {
this.trafficEnabled = trafficEnabled;
}

public void setBuildingsEnabled(boolean buildingsEnabled) {
this.buildingsEnabled = buildingsEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ interface GoogleMapOptionsSink {

void setTrafficEnabled(boolean trafficEnabled);

void setBuildingsEnabled(boolean buildingsEnabled);

void setInitialMarkers(Object initialMarkers);

void setInitialPolygons(Object initialPolygons);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ class GoogleMapInspector {
Future<bool> isTrafficEnabled() async {
return await _channel.invokeMethod<bool>('map#isTrafficEnabled');
}

Future<bool> isBuildingsEnabled() async {
return await _channel.invokeMethod<bool>('map#isBuildingsEnabled');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,31 @@ void main() {
expect(isTrafficEnabled, true);
});

testWidgets('testBuildings', (WidgetTester tester) async {
final Key key = GlobalKey();
final Completer<GoogleMapInspector> inspectorCompleter =
Completer<GoogleMapInspector>();

await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: GoogleMap(
key: key,
initialCameraPosition: _kInitialCameraPosition,
buildingsEnabled: true,
onMapCreated: (GoogleMapController controller) {
final GoogleMapInspector inspector =
// ignore: invalid_use_of_visible_for_testing_member
GoogleMapInspector(controller.channel);
inspectorCompleter.complete(inspector);
},
),
));

final GoogleMapInspector inspector = await inspectorCompleter.future;
final bool isBuildingsEnabled = await inspector.isBuildingsEnabled();
expect(isBuildingsEnabled, true);
});

testWidgets('testMyLocationButtonToggle', (WidgetTester tester) async {
final Key key = GlobalKey();
final Completer<GoogleMapInspector> inspectorCompleter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setCompassEnabled:(BOOL)enabled;
- (void)setIndoorEnabled:(BOOL)enabled;
- (void)setTrafficEnabled:(BOOL)enabled;
- (void)setBuildingsEnabled:(BOOL)enabled;
- (void)setMapType:(GMSMapViewType)type;
- (void)setMinZoom:(float)minZoom maxZoom:(float)maxZoom;
- (void)setPaddingTop:(float)top left:(float)left bottom:(float)bottom right:(float)right;
Expand Down
11 changes: 11 additions & 0 deletions packages/google_maps_flutter/ios/Classes/GoogleMapController.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
} else if ([call.method isEqualToString:@"map#isTrafficEnabled"]) {
NSNumber* isTrafficEnabled = @(_mapView.trafficEnabled);
result(isTrafficEnabled);
} else if ([call.method isEqualToString:@"map#isBuildingsEnabled"]) {
NSNumber* isBuildingsEnabled = @(_mapView.buildingsEnabled);
result(isBuildingsEnabled);
} else if ([call.method isEqualToString:@"map#setStyle"]) {
NSString* mapStyle = [call arguments];
NSString* error = [self setMapStyle:mapStyle];
Expand Down Expand Up @@ -315,6 +318,10 @@ - (void)setTrafficEnabled:(BOOL)enabled {
_mapView.trafficEnabled = enabled;
}

- (void)setBuildingsEnabled:(BOOL)enabled {
_mapView.buildingsEnabled = enabled;
}

- (void)setMapType:(GMSMapViewType)mapType {
_mapView.mapType = mapType;
}
Expand Down Expand Up @@ -554,6 +561,10 @@ static void InterpretMapOptions(NSDictionary* data, id<FLTGoogleMapOptionsSink>
if (trafficEnabled) {
[sink setTrafficEnabled:ToBool(trafficEnabled)];
}
id buildingsEnabled = data[@"buildingsEnabled"];
if (buildingsEnabled) {
[sink setBuildingsEnabled:ToBool(buildingsEnabled)];
}
id mapType = data[@"mapType"];
if (mapType) {
[sink setMapType:ToMapViewType(mapType)];
Expand Down
9 changes: 9 additions & 0 deletions packages/google_maps_flutter/lib/src/google_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GoogleMap extends StatefulWidget {
this.padding = const EdgeInsets.all(0),
this.indoorViewEnabled = false,
this.trafficEnabled = false,
this.buildingsEnabled = true,
this.markers,
this.polygons,
this.polylines,
Expand Down Expand Up @@ -179,6 +180,9 @@ class GoogleMap extends StatefulWidget {
/// Enables or disables the traffic layer of the map
final bool trafficEnabled;

/// Enables or disables showing 3D buildings where available
final bool buildingsEnabled;

/// Which gestures should be consumed by the map.
///
/// It is possible for other gesture recognizers to be competing with the map on pointer
Expand Down Expand Up @@ -394,6 +398,7 @@ class _GoogleMapOptions {
this.padding,
this.indoorViewEnabled,
this.trafficEnabled,
this.buildingsEnabled,
});

static _GoogleMapOptions fromWidget(GoogleMap map) {
Expand All @@ -413,6 +418,7 @@ class _GoogleMapOptions {
padding: map.padding,
indoorViewEnabled: map.indoorViewEnabled,
trafficEnabled: map.trafficEnabled,
buildingsEnabled: map.buildingsEnabled,
);
}

Expand Down Expand Up @@ -446,6 +452,8 @@ class _GoogleMapOptions {

final bool trafficEnabled;

final bool buildingsEnabled;

Map<String, dynamic> toMap() {
final Map<String, dynamic> optionsMap = <String, dynamic>{};

Expand Down Expand Up @@ -475,6 +483,7 @@ class _GoogleMapOptions {
]);
addIfNonNull('indoorEnabled', indoorViewEnabled);
addIfNonNull('trafficEnabled', trafficEnabled);
addIfNonNull('buildingsEnabled', buildingsEnabled);
return optionsMap;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/google_maps_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter
version: 0.5.21+13
version: 0.5.21+14

dependencies:
flutter:
Expand Down
5 changes: 5 additions & 0 deletions packages/google_maps_flutter/test/fake_maps_controllers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class FakePlatformGoogleMap {

bool trafficEnabled;

bool buildingsEnabled;

bool myLocationButtonEnabled;

List<dynamic> padding;
Expand Down Expand Up @@ -358,6 +360,9 @@ class FakePlatformGoogleMap {
if (options.containsKey('trafficEnabled')) {
trafficEnabled = options['trafficEnabled'];
}
if (options.containsKey('buildingsEnabled')) {
buildingsEnabled = options['buildingsEnabled'];
}
if (options.containsKey('padding')) {
padding = options['padding'];
}
Expand Down
29 changes: 29 additions & 0 deletions packages/google_maps_flutter/test/google_map_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,33 @@ void main() {

expect(platformGoogleMap.trafficEnabled, true);
});

testWidgets('Can update buildings', (WidgetTester tester) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: GoogleMap(
initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)),
buildingsEnabled: false,
),
),
);

final FakePlatformGoogleMap platformGoogleMap =
fakePlatformViewsController.lastCreatedView;

expect(platformGoogleMap.buildingsEnabled, false);

await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: GoogleMap(
initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)),
buildingsEnabled: true,
),
),
);

expect(platformGoogleMap.buildingsEnabled, true);
});
}

0 comments on commit cb67abb

Please sign in to comment.