Skip to content
Open
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 @@
## 2.19.13

* Avoids recreating ground overlay images when only other overlay properties change.

## 2.19.12

* Bumps the androidx group across 10 directories with 1 update.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ static Tile tileFromPigeon(PlatformTile tile) {
* asset files stored in the application's assets directory.
* @param density the density of the display, used to calculate pixel dimensions.
* @param wrapper the BitmapDescriptorFactoryWrapper to create BitmapDescriptor.
* @param updateImage whether to convert and set the ground overlay image.
* @return the identifier of the ground overlay. The identifier is valid as long as the ground
* overlay exists.
* @throws IllegalArgumentException if required fields are missing or invalid.
Expand All @@ -830,7 +831,8 @@ static Tile tileFromPigeon(PlatformTile tile) {
@NonNull GroundOverlaySink sink,
@NonNull AssetManager assetManager,
float density,
@NonNull BitmapDescriptorFactoryWrapper wrapper) {
@NonNull BitmapDescriptorFactoryWrapper wrapper,
boolean updateImage) {
sink.setTransparency((float) groundOverlay.getTransparency());
sink.setZIndex((float) groundOverlay.getZIndex());
sink.setVisible(groundOverlay.getVisible());
Expand All @@ -840,7 +842,9 @@ static Tile tileFromPigeon(PlatformTile tile) {
}
sink.setBearing((float) groundOverlay.getBearing());
sink.setClickable(groundOverlay.getClickable());
sink.setImage(toBitmapDescriptor(groundOverlay.getImage(), assetManager, density, wrapper));
if (updateImage) {
sink.setImage(toBitmapDescriptor(groundOverlay.getImage(), assetManager, density, wrapper));
}
if (groundOverlay.getPosition() != null) {
if (groundOverlay.getWidth() == null) {
throw new FlutterError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ class GroundOverlayController implements GroundOverlaySink {
private final GroundOverlay groundOverlay;
private final String googleMapsGroundOverlayId;
private final boolean isCreatedWithBounds;
private @NonNull PlatformBitmap platformBitmap;

GroundOverlayController(@NonNull GroundOverlay groundOverlay, boolean isCreatedWithBounds) {
GroundOverlayController(
@NonNull GroundOverlay groundOverlay,
boolean isCreatedWithBounds,
@NonNull PlatformBitmap platformBitmap) {
this.groundOverlay = groundOverlay;
this.googleMapsGroundOverlayId = groundOverlay.getId();
this.isCreatedWithBounds = isCreatedWithBounds;
this.platformBitmap = platformBitmap;
}

void remove() {
Expand Down Expand Up @@ -85,4 +90,12 @@ String getGoogleMapsGroundOverlayId() {
public boolean isCreatedWithBounds() {
return isCreatedWithBounds;
}

boolean hasImage(@NonNull PlatformBitmap platformBitmap) {
return this.platformBitmap.equals(platformBitmap);
}

void setPlatformBitmap(@NonNull PlatformBitmap platformBitmap) {
this.platformBitmap = platformBitmap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ private void addGroundOverlay(@NonNull PlatformGroundOverlay platformGroundOverl
groundOverlayOptionsBuilder,
assetManager,
density,
bitmapDescriptorFactoryWrapper);
bitmapDescriptorFactoryWrapper,
true);
GroundOverlayOptions options = groundOverlayOptionsBuilder.build();
final GroundOverlay groundOverlay = googleMap.addGroundOverlay(options);
if (groundOverlay != null) {
GroundOverlayController groundOverlayController =
new GroundOverlayController(groundOverlay, platformGroundOverlay.getBounds() != null);
new GroundOverlayController(
groundOverlay,
platformGroundOverlay.getBounds() != null,
platformGroundOverlay.getImage());
groundOverlayIdToController.put(groundOverlayId, groundOverlayController);
googleMapsGroundOverlayIdToDartGroundOverlayId.put(groundOverlay.getId(), groundOverlayId);
}
Expand All @@ -101,12 +105,18 @@ private void changeGroundOverlay(@NonNull PlatformGroundOverlay platformGroundOv
GroundOverlayController groundOverlayController =
groundOverlayIdToController.get(groundOverlayId);
if (groundOverlayController != null) {
final PlatformBitmap image = platformGroundOverlay.getImage();
final boolean imageChanged = !groundOverlayController.hasImage(image);
Convert.interpretGroundOverlayOptions(
platformGroundOverlay,
groundOverlayController,
assetManager,
density,
bitmapDescriptorFactoryWrapper);
bitmapDescriptorFactoryWrapper,
imageChanged);
if (imageChanged) {
groundOverlayController.setPlatformBitmap(image);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.content.Context;
Expand Down Expand Up @@ -46,6 +48,12 @@ public class GroundOverlaysControllerTest {

@NonNull
private PlatformGroundOverlay createGroundOverlay(String overlayId, double transparency) {
return createGroundOverlay(overlayId, transparency, 100.0);
}

@NonNull
private PlatformGroundOverlay createGroundOverlay(
String overlayId, double transparency, double imageWidth) {
byte[] bmpData = Base64.decode(base64Image, Base64.DEFAULT);

return new PlatformGroundOverlay(
Expand All @@ -55,7 +63,7 @@ private PlatformGroundOverlay createGroundOverlay(String overlayId, double trans
bmpData,
PlatformMapBitmapScaling.AUTO,
/* imagePixelRatio */ 2.0,
/* width */ 100.0, /* height */
/* width */ imageWidth, /* height */
null)),
/* position */ null,
/* bounds */ null,
Expand Down Expand Up @@ -107,9 +115,28 @@ public void controller_AddChangeAndRemoveGroundOverlay() {
controller.changeGroundOverlays(
Collections.singletonList(createGroundOverlay(googleGroundOverlayId, newTransparency)));
Mockito.verify(groundOverlay, times(1)).setTransparency(newTransparency);
verify(bitmapDescriptorFactoryWrapper, times(1)).fromBitmap(any());
verifyNoMoreInteractions(bitmapDescriptorFactoryWrapper);

controller.removeGroundOverlays(Collections.singletonList(googleGroundOverlayId));

Mockito.verify(groundOverlay, times(1)).remove();
}

@Test
public void controller_ChangeGroundOverlayUpdatesChangedImage() {
final GroundOverlay groundOverlay = mock(GroundOverlay.class);
final String groundOverlayId = "ground-overlay";

when(groundOverlay.getId()).thenReturn("google-ground-overlay");
when(googleMap.addGroundOverlay(any(GroundOverlayOptions.class))).thenReturn(groundOverlay);

controller.addGroundOverlays(
Collections.singletonList(createGroundOverlay(groundOverlayId, 0.1, 100.0)));
controller.changeGroundOverlays(
Collections.singletonList(createGroundOverlay(groundOverlayId, 0.1, 101.0)));

verify(bitmapDescriptorFactoryWrapper, times(2)).fromBitmap(any());
verify(groundOverlay).setImage(mockBitmapDescriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_android
description: Android implementation of the google_maps_flutter plugin.
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.19.12
version: 2.19.13

environment:
sdk: ^3.12.0
Expand Down