Skip to content

Commit e89bada

Browse files
committed
Minor improvements to logic and documentation
1 parent f482577 commit e89bada

File tree

7 files changed

+80
-19
lines changed

7 files changed

+80
-19
lines changed

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,8 @@ static Tile tileFromPigeon(Messages.PlatformTile tile) {
861861
* asset files stored in the application's assets directory.
862862
* @param density the density of the display, used to calculate pixel dimensions.
863863
* @param wrapper the BitmapDescriptorFactoryWrapper to create BitmapDescriptor.
864-
* @return the identifier of the ground overlay.
864+
* @return the identifier of the ground overlay. The identifier is valid as long as the ground
865+
* overlay exists.
865866
* @throws IllegalArgumentException if required fields are missing or invalid.
866867
*/
867868
static @NonNull String interpretGroundOverlayOptions(
@@ -911,8 +912,12 @@ static Tile tileFromPigeon(Messages.PlatformTile tile) {
911912
@NonNull String groundOverlayId,
912913
boolean isCreatedWithBounds) {
913914

914-
// Dummy image is used as image is a required field of PlatformGroundOverlay and converting
915-
// BitmapDescriptor used by Google Maps back to PlatformImageDescriptor is not currently supported.
915+
// Image is mandatory field on PlatformGroundOverlay (and it should be kept
916+
// non-nullable), therefore image must be set for the object. The image is
917+
// description either contains set of bytes, or path to asset. This info is
918+
// converted to format google maps uses (BitmapDescription), and the original
919+
// data is not stored on native code. Therefore placeholder image is used for
920+
// the image field.
916921
Messages.PlatformBitmap dummyImage =
917922
new Messages.PlatformBitmap.Builder()
918923
.setBitmap(

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/GroundOverlaySink.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,71 @@
1212

1313
/** Receiver of GroundOverlayOptions configuration. */
1414
interface GroundOverlaySink {
15+
/**
16+
* Sets the transparency of the ground overlay.
17+
*
18+
* @param transparency the transparency value, where 0 is fully opaque and 1 is fully transparent.
19+
*/
1520
void setTransparency(float transparency);
1621

22+
/**
23+
* Sets the zIndex of the ground overlay.
24+
*
25+
* @param zIndex the zIndex value.
26+
*/
1727
void setZIndex(float zIndex);
1828

29+
/**
30+
* Sets the visibility of the ground overlay.
31+
*
32+
* @param visible true to make the ground overlay visible, false to make it invisible.
33+
*/
1934
void setVisible(boolean visible);
2035

36+
/**
37+
* Sets the anchor point of the ground overlay.
38+
*
39+
* @param u the u-coordinate of the anchor, as a ratio of the image width (in the range [0, 1]).
40+
* @param v the v-coordinate of the anchor, as a ratio of the image height (in the range [0, 1]).
41+
*/
2142
void setAnchor(float u, float v);
2243

44+
/**
45+
* Sets the bearing of the ground overlay.
46+
*
47+
* @param bearing the bearing in degrees clockwise from north.
48+
*/
2349
void setBearing(float bearing);
2450

51+
/**
52+
* Sets the clickability of the ground overlay.
53+
*
54+
* @param clickable true to make the ground overlay clickable, false otherwise. When clickable,
55+
* the ground overlay triggers click events.
56+
*/
2557
void setClickable(boolean clickable);
2658

59+
/**
60+
* Sets the image for the ground overlay.
61+
*
62+
* @param imageDescriptor the BitmapDescriptor representing the image.
63+
*/
2764
void setImage(@NonNull BitmapDescriptor imageDescriptor);
2865

66+
/**
67+
* Sets the position of the ground overlay using a location and dimensions.
68+
*
69+
* @param location the LatLng location of the anchor point.
70+
* @param width the width of the ground overlay.
71+
* @param height the height of the ground overlay, or null to calculate proportions of the image
72+
* automatically.
73+
*/
2974
void setPosition(@NonNull LatLng location, @NonNull Float width, @Nullable Float height);
3075

76+
/**
77+
* Sets the position of the ground overlay using bounds.
78+
*
79+
* @param bounds the LatLngBounds to fit the ground overlay within.
80+
*/
3181
void setPositionFromBounds(@NonNull LatLngBounds bounds);
3282
}

packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/google_maps_tests.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7-
import 'dart:io';
87
import 'dart:typed_data';
98
import 'dart:ui' as ui;
109

@@ -1001,7 +1000,7 @@ void googleMapsTests() {
10011000
},
10021001
// TODO(cyanglaz): un-skip the test when we can test this on CI with API key enabled.
10031002
// https://github.com/flutter/flutter/issues/57057
1004-
skip: Platform.isAndroid);
1003+
skip: true);
10051004

10061005
testWidgets(
10071006
'set tileOverlay correctly',

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ GMSMapViewType FGMGetMapViewTypeForPigeonMapType(FGMPlatformMapType type) {
116116
FGMPlatformGroundOverlay *FGMGetPigeonGroundOverlay(GMSGroundOverlay *groundOverlay,
117117
NSString *overlayId, BOOL isCreatedWithBounds,
118118
NSNumber *zoomLevel) {
119-
/// Dummy image is used as image is required field of FGMPlatformGroundOverlay and converting
120-
/// image back to bitmap image is not currently supported.
119+
// Image is mandatory field on FGMPlatformGroundOverlay (and it should be kept
120+
// non-nullable), therefore image must be set for the object. The image is
121+
// description either contains set of bytes, or path to asset. This info is
122+
// converted to format google maps uses (BitmapDescription), and the original
123+
// data is not stored on native code. Therefore placeholder image is used for
124+
// the image field.
121125
FGMPlatformBitmap *placeholderImage =
122126
[FGMPlatformBitmap makeWithBitmap:[FGMPlatformBitmapDefaultMarker makeWithHue:0]];
123127
if (isCreatedWithBounds) {

packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_inspector_web.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class GoogleMapsInspectorWeb extends GoogleMapsInspectorPlatform {
9797
return null;
9898
}
9999

100+
final JSAny? clickable = groundOverlay.get('clickable');
101+
100102
return GroundOverlay.fromBounds(
101103
groundOverlayId: groundOverlayId,
102104
image: BytesMapBitmap(
@@ -106,8 +108,7 @@ class GoogleMapsInspectorWeb extends GoogleMapsInspectorPlatform {
106108
bounds: gmLatLngBoundsTolatLngBounds(groundOverlay.bounds),
107109
transparency: 1.0 - groundOverlay.opacity,
108110
visible: groundOverlay.map != null,
109-
clickable: groundOverlay.get('clickable') is JSAny &&
110-
(groundOverlay.get('clickable')! as JSBoolean).toDart);
111+
clickable: clickable != null && (clickable as JSBoolean).toDart);
111112
}
112113

113114
@override

packages/google_maps_flutter/google_maps_flutter_web/lib/src/ground_overlay.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ class GroundOverlayController {
1111
GroundOverlayController({
1212
required gmaps.GroundOverlay groundOverlay,
1313
required VoidCallback onTap,
14-
}) {
15-
_groundOverlay = groundOverlay;
16-
_groundOverlay.onClick.listen((gmaps.MapMouseEvent event) {
14+
}) : _groundOverlay = groundOverlay {
15+
groundOverlay.onClick.listen((gmaps.MapMouseEvent event) {
1716
onTap.call();
1817
});
1918
}
2019

2120
/// The [GroundOverlay] providing data for this controller.
22-
gmaps.GroundOverlay get groundOverlay => _groundOverlay;
23-
late gmaps.GroundOverlay _groundOverlay;
21+
gmaps.GroundOverlay? get groundOverlay => _groundOverlay;
22+
gmaps.GroundOverlay? _groundOverlay;
2423

2524
/// Removes the [GroundOverlay] from the map.
2625
void remove() {
27-
_groundOverlay.map = null;
26+
if (_groundOverlay != null) {
27+
_groundOverlay!.map = null;
28+
_groundOverlay = null;
29+
}
2830
}
2931
}

packages/google_maps_flutter/google_maps_flutter_web/lib/src/ground_overlays.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ class GroundOverlaysController extends GeometryController {
6464
final GroundOverlayController? controller =
6565
_groundOverlayIdToController[groundOverlay.groundOverlayId];
6666

67-
if (controller == null) {
67+
if (controller == null || controller.groundOverlay == null) {
6868
return;
6969
}
7070

7171
assert(groundOverlay.bounds != null,
7272
'On Web platform, bounds must be provided for GroundOverlay');
7373

74-
controller.groundOverlay.set('clickable', groundOverlay.clickable.toJS);
75-
controller.groundOverlay.map = groundOverlay.visible ? googleMap : null;
76-
controller.groundOverlay.opacity = 1.0 - groundOverlay.transparency;
74+
controller.groundOverlay!.set('clickable', groundOverlay.clickable.toJS);
75+
controller.groundOverlay!.map = groundOverlay.visible ? googleMap : null;
76+
controller.groundOverlay!.opacity = 1.0 - groundOverlay.transparency;
7777
}
7878

7979
/// Removes the ground overlays associated with the given [GroundOverlayId]s.

0 commit comments

Comments
 (0)