Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.14

* Adds support for disabling or moving the camera control button on web.

## 0.5.13

* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,57 @@ void main() {
expect(capturedOptions!.gestureHandling, 'greedy');
});

testWidgets('translates webCameraControlEnabled option', (
WidgetTester tester,
) async {
gmaps.MapOptions? capturedOptions;
controller = createController(
mapConfiguration: const MapConfiguration(
zoomGesturesEnabled: false,
webCameraControlEnabled: true,
),
);
controller.debugSetOverrides(
createMap: (_, gmaps.MapOptions options) {
capturedOptions = options;
return map;
},
);

controller.init();

expect(capturedOptions, isNotNull);
expect(capturedOptions!.cameraControl, isTrue);
});

testWidgets('translates webCameraControlPosition option', (
WidgetTester tester,
) async {
gmaps.MapOptions? capturedOptions;
controller = createController(
mapConfiguration: const MapConfiguration(
zoomGesturesEnabled: false,
webCameraControlEnabled: true,
webCameraControlPosition: WebCameraControlPosition.bottomLeft,
),
);
controller.debugSetOverrides(
createMap: (_, gmaps.MapOptions options) {
capturedOptions = options;
return map;
},
);

controller.init();

expect(capturedOptions, isNotNull);
expect(capturedOptions!.cameraControl, isTrue);
expect(
capturedOptions!.cameraControlOptions?.position,
gmaps.ControlPosition.BOTTOM_LEFT,
);
});

testWidgets('translates cameraTargetBounds option', (
WidgetTester tester,
) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
dependencies:
flutter:
sdk: flutter
google_maps_flutter_platform_interface: ^2.12.1
google_maps_flutter_platform_interface: ^2.14.0
google_maps_flutter_web:
path: ../
web: ^1.0.0
Expand All @@ -17,7 +17,7 @@ dev_dependencies:
build_runner: ^2.1.1
flutter_test:
sdk: flutter
google_maps: ^8.0.0
google_maps: ^8.1.0
google_maps_flutter: ^2.2.0 # Needed for projection_test.dart
http: ^1.2.2
integration_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions(
options.gestureHandling = WebGestureHandling.auto.name;
}

if (configuration.webCameraControlEnabled != null) {
options.cameraControl = configuration.webCameraControlEnabled;
}

if (configuration.webCameraControlPosition != null) {
final gmaps.ControlPosition? controlPosition = _toControlPosition(
configuration.webCameraControlPosition!,
);

if (controlPosition != null) {
options.cameraControlOptions = gmaps.CameraControlOptions(
position: controlPosition,
);
}
}

if (configuration.fortyFiveDegreeImageryEnabled != null) {
options.rotateControl = configuration.fortyFiveDegreeImageryEnabled;
}
Expand Down Expand Up @@ -787,3 +803,59 @@ gmaps.LatLng _pixelToLatLng(gmaps.Map map, int x, int y) {

return projection.fromPointToLatLng(point)!;
}

/// Converts a [WebCameraControlPosition] to [gmaps.ControlPosition].
gmaps.ControlPosition? _toControlPosition(
WebCameraControlPosition webCameraControlPosition,
) {
switch (webCameraControlPosition) {
case WebCameraControlPosition.blockEndInlineCenter:
return gmaps.ControlPosition.BLOCK_END_INLINE_CENTER;
case WebCameraControlPosition.blockEndInlineEnd:
return gmaps.ControlPosition.BLOCK_END_INLINE_END;
case WebCameraControlPosition.blockEndInlineStart:
return gmaps.ControlPosition.BLOCK_END_INLINE_START;
case WebCameraControlPosition.blockStartInlineCenter:
return gmaps.ControlPosition.BLOCK_START_INLINE_CENTER;
case WebCameraControlPosition.blockStartInlineEnd:
return gmaps.ControlPosition.BLOCK_START_INLINE_END;
case WebCameraControlPosition.blockStartInlineStart:
return gmaps.ControlPosition.BLOCK_START_INLINE_START;
case WebCameraControlPosition.bottomCenter:
return gmaps.ControlPosition.BOTTOM_CENTER;
case WebCameraControlPosition.bottomLeft:
return gmaps.ControlPosition.BOTTOM_LEFT;
case WebCameraControlPosition.bottomRight:
return gmaps.ControlPosition.BOTTOM_RIGHT;
case WebCameraControlPosition.inlineEndBlockCenter:
return gmaps.ControlPosition.INLINE_END_BLOCK_CENTER;
case WebCameraControlPosition.inlineEndBlockEnd:
return gmaps.ControlPosition.INLINE_END_BLOCK_END;
case WebCameraControlPosition.inlineEndBlockStart:
return gmaps.ControlPosition.INLINE_END_BLOCK_START;
case WebCameraControlPosition.inlineStartBlockCenter:
return gmaps.ControlPosition.INLINE_START_BLOCK_CENTER;
case WebCameraControlPosition.inlineStartBlockEnd:
return gmaps.ControlPosition.INLINE_START_BLOCK_END;
case WebCameraControlPosition.inlineStartBlockStart:
return gmaps.ControlPosition.INLINE_START_BLOCK_START;
case WebCameraControlPosition.leftBottom:
return gmaps.ControlPosition.LEFT_BOTTOM;
case WebCameraControlPosition.leftCenter:
return gmaps.ControlPosition.LEFT_CENTER;
case WebCameraControlPosition.leftTop:
return gmaps.ControlPosition.LEFT_TOP;
case WebCameraControlPosition.rightBottom:
return gmaps.ControlPosition.RIGHT_BOTTOM;
case WebCameraControlPosition.rightCenter:
return gmaps.ControlPosition.RIGHT_CENTER;
case WebCameraControlPosition.rightTop:
return gmaps.ControlPosition.RIGHT_TOP;
case WebCameraControlPosition.topCenter:
return gmaps.ControlPosition.TOP_CENTER;
case WebCameraControlPosition.topLeft:
return gmaps.ControlPosition.TOP_LEFT;
case WebCameraControlPosition.topRight:
return gmaps.ControlPosition.TOP_RIGHT;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a return outside of this, to handle the case of an enum value being added, since it comes from a different package. See

// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return gmaps.MapTypeId.ROADMAP;
for an example.

In this case I would suggest making the function return a nullable value so the fallback can be null, and then at the call site checking that this returns a non-null value before setting the value in the options class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Done.

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_web
description: Web platform implementation of google_maps_flutter
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 0.5.13
version: 0.5.14

environment:
sdk: ^3.7.0
Expand All @@ -22,8 +22,8 @@ dependencies:
sdk: flutter
flutter_web_plugins:
sdk: flutter
google_maps: ^8.0.0
google_maps_flutter_platform_interface: ^2.12.1
google_maps: ^8.1.0
google_maps_flutter_platform_interface: ^2.14.0
sanitize_html: ^2.0.0
stream_transform: ^2.0.0
web: ">=0.5.1 <2.0.0"
Expand Down