Skip to content

Commit

Permalink
[google_maps_flutter] Custom marker size improvements - platform impls (
Browse files Browse the repository at this point in the history
#6826)

Platform implementations portion of : #4055

Adds platform handling for new BitmapDescriptor classes `AssetMapBitmap` and `BytesMapBitmap` introduced in #6687

Containing only changes to packages
 * `google_maps_flutter_android`
 * `google_maps_flutter_ios`
 * `google_maps_flutter_web`

Follow up PR will hold the app-facing plugin implementations.

Linked issue: flutter/flutter#34657
  • Loading branch information
jokerttu authored Jun 4, 2024
1 parent 1eb04b3 commit dcd8586
Show file tree
Hide file tree
Showing 45 changed files with 2,664 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.9.0

* Adds support for BitmapDescriptor classes `AssetMapBitmap` and `BytesMapBitmap`.

## 2.8.1

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.SurfaceTexture;
Expand Down Expand Up @@ -115,11 +116,13 @@ class GoogleMapController
methodChannel =
new MethodChannel(binaryMessenger, "plugins.flutter.dev/google_maps_android_" + id);
methodChannel.setMethodCallHandler(this);
AssetManager assetManager = context.getAssets();
this.lifecycleProvider = lifecycleProvider;
this.clusterManagersController = new ClusterManagersController(methodChannel, context);
this.markersController = new MarkersController(methodChannel, clusterManagersController);
this.markersController =
new MarkersController(methodChannel, clusterManagersController, assetManager, density);
this.polygonsController = new PolygonsController(methodChannel, density);
this.polylinesController = new PolylinesController(methodChannel, density);
this.polylinesController = new PolylinesController(methodChannel, assetManager, density);
this.circlesController = new CirclesController(methodChannel, density);
this.tileOverlaysController = new TileOverlaysController(methodChannel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.flutter.plugins.googlemaps;

import android.content.res.AssetManager;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
Expand All @@ -21,14 +22,21 @@ class MarkersController {
private final MethodChannel methodChannel;
private MarkerManager.Collection markerCollection;
private final ClusterManagersController clusterManagersController;
private final AssetManager assetManager;
private final float density;

MarkersController(
MethodChannel methodChannel, ClusterManagersController clusterManagersController) {
MethodChannel methodChannel,
ClusterManagersController clusterManagersController,
AssetManager assetManager,
float density) {
this.markerIdToMarkerBuilder = new HashMap<>();
this.markerIdToController = new HashMap<>();
this.googleMapsMarkerIdToDartMarkerId = new HashMap<>();
this.methodChannel = methodChannel;
this.clusterManagersController = clusterManagersController;
this.assetManager = assetManager;
this.density = density;
}

void setCollection(MarkerManager.Collection markerCollection) {
Expand Down Expand Up @@ -192,7 +200,7 @@ private void addMarker(Object marker) {
}
String clusterManagerId = getClusterManagerId(marker);
MarkerBuilder markerBuilder = new MarkerBuilder(markerId, clusterManagerId);
Convert.interpretMarkerOptions(marker, markerBuilder);
Convert.interpretMarkerOptions(marker, markerBuilder, assetManager, density);
addMarker(markerBuilder);
}

Expand Down Expand Up @@ -251,12 +259,12 @@ private void changeMarker(Object marker) {
}

// Update marker builder.
Convert.interpretMarkerOptions(marker, markerBuilder);
Convert.interpretMarkerOptions(marker, markerBuilder, assetManager, density);

// Update existing marker on map.
MarkerController markerController = markerIdToController.get(markerId);
if (markerController != null) {
Convert.interpretMarkerOptions(marker, markerController);
Convert.interpretMarkerOptions(marker, markerController, assetManager, density);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.flutter.plugins.googlemaps;

import android.content.res.AssetManager;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
Expand All @@ -19,8 +20,10 @@ class PolylinesController {
private final MethodChannel methodChannel;
private GoogleMap googleMap;
private final float density;
private final AssetManager assetManager;

PolylinesController(MethodChannel methodChannel, float density) {
PolylinesController(MethodChannel methodChannel, AssetManager assetManager, float density) {
this.assetManager = assetManager;
this.polylineIdToController = new HashMap<>();
this.googleMapsPolylineIdToDartPolylineId = new HashMap<>();
this.methodChannel = methodChannel;
Expand Down Expand Up @@ -82,7 +85,8 @@ private void addPolyline(Object polyline) {
return;
}
PolylineBuilder polylineBuilder = new PolylineBuilder(density);
String polylineId = Convert.interpretPolylineOptions(polyline, polylineBuilder);
String polylineId =
Convert.interpretPolylineOptions(polyline, polylineBuilder, assetManager, density);
PolylineOptions options = polylineBuilder.build();
addPolyline(polylineId, options, polylineBuilder.consumeTapEvents());
}
Expand All @@ -102,7 +106,7 @@ private void changePolyline(Object polyline) {
String polylineId = getPolylineId(polyline);
PolylineController polylineController = polylineIdToController.get(polylineId);
if (polylineController != null) {
Convert.interpretPolylineOptions(polyline, polylineController);
Convert.interpretPolylineOptions(polyline, polylineController, assetManager, density);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.AssetManager;
import android.os.Build;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.gms.maps.GoogleMap;
Expand All @@ -34,6 +35,7 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

Expand All @@ -46,10 +48,14 @@ public class ClusterManagersControllerTest {
private GoogleMap googleMap;
private MarkerManager markerManager;
private MarkerManager.Collection markerCollection;
private AssetManager assetManager;
private final float density = 1;

@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
context = ApplicationProvider.getApplicationContext();
assetManager = context.getAssets();
methodChannel =
spy(new MethodChannel(mock(BinaryMessenger.class), "no-name", mock(MethodCodec.class)));
controller = spy(new ClusterManagersController(methodChannel, context));
Expand Down Expand Up @@ -93,8 +99,8 @@ public void AddClusterManagersAndMarkers() throws InterruptedException {
final Map<String, Object> markerData2 =
createMarkerData(markerId2, location2, clusterManagerId);

Convert.interpretMarkerOptions(markerData1, markerBuilder1);
Convert.interpretMarkerOptions(markerData2, markerBuilder2);
Convert.interpretMarkerOptions(markerData1, markerBuilder1, assetManager, density);
Convert.interpretMarkerOptions(markerData2, markerBuilder2, assetManager, density);

controller.addItem(markerBuilder1);
controller.addItem(markerBuilder2);
Expand Down
Loading

0 comments on commit dcd8586

Please sign in to comment.