Skip to content

Commit dcd8586

Browse files
authored
[google_maps_flutter] Custom marker size improvements - platform impls (#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
1 parent 1eb04b3 commit dcd8586

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2664
-240
lines changed

packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.9.0
2+
3+
* Adds support for BitmapDescriptor classes `AssetMapBitmap` and `BytesMapBitmap`.
4+
15
## 2.8.1
26

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

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

Lines changed: 299 additions & 21 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.annotation.SuppressLint;
99
import android.content.Context;
1010
import android.content.pm.PackageManager;
11+
import android.content.res.AssetManager;
1112
import android.graphics.Bitmap;
1213
import android.graphics.Point;
1314
import android.graphics.SurfaceTexture;
@@ -115,11 +116,13 @@ class GoogleMapController
115116
methodChannel =
116117
new MethodChannel(binaryMessenger, "plugins.flutter.dev/google_maps_android_" + id);
117118
methodChannel.setMethodCallHandler(this);
119+
AssetManager assetManager = context.getAssets();
118120
this.lifecycleProvider = lifecycleProvider;
119121
this.clusterManagersController = new ClusterManagersController(methodChannel, context);
120-
this.markersController = new MarkersController(methodChannel, clusterManagersController);
122+
this.markersController =
123+
new MarkersController(methodChannel, clusterManagersController, assetManager, density);
121124
this.polygonsController = new PolygonsController(methodChannel, density);
122-
this.polylinesController = new PolylinesController(methodChannel, density);
125+
this.polylinesController = new PolylinesController(methodChannel, assetManager, density);
123126
this.circlesController = new CirclesController(methodChannel, density);
124127
this.tileOverlaysController = new TileOverlaysController(methodChannel);
125128
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package io.flutter.plugins.googlemaps;
66

7+
import android.content.res.AssetManager;
78
import com.google.android.gms.maps.model.LatLng;
89
import com.google.android.gms.maps.model.Marker;
910
import com.google.android.gms.maps.model.MarkerOptions;
@@ -21,14 +22,21 @@ class MarkersController {
2122
private final MethodChannel methodChannel;
2223
private MarkerManager.Collection markerCollection;
2324
private final ClusterManagersController clusterManagersController;
25+
private final AssetManager assetManager;
26+
private final float density;
2427

2528
MarkersController(
26-
MethodChannel methodChannel, ClusterManagersController clusterManagersController) {
29+
MethodChannel methodChannel,
30+
ClusterManagersController clusterManagersController,
31+
AssetManager assetManager,
32+
float density) {
2733
this.markerIdToMarkerBuilder = new HashMap<>();
2834
this.markerIdToController = new HashMap<>();
2935
this.googleMapsMarkerIdToDartMarkerId = new HashMap<>();
3036
this.methodChannel = methodChannel;
3137
this.clusterManagersController = clusterManagersController;
38+
this.assetManager = assetManager;
39+
this.density = density;
3240
}
3341

3442
void setCollection(MarkerManager.Collection markerCollection) {
@@ -192,7 +200,7 @@ private void addMarker(Object marker) {
192200
}
193201
String clusterManagerId = getClusterManagerId(marker);
194202
MarkerBuilder markerBuilder = new MarkerBuilder(markerId, clusterManagerId);
195-
Convert.interpretMarkerOptions(marker, markerBuilder);
203+
Convert.interpretMarkerOptions(marker, markerBuilder, assetManager, density);
196204
addMarker(markerBuilder);
197205
}
198206

@@ -251,12 +259,12 @@ private void changeMarker(Object marker) {
251259
}
252260

253261
// Update marker builder.
254-
Convert.interpretMarkerOptions(marker, markerBuilder);
262+
Convert.interpretMarkerOptions(marker, markerBuilder, assetManager, density);
255263

256264
// Update existing marker on map.
257265
MarkerController markerController = markerIdToController.get(markerId);
258266
if (markerController != null) {
259-
Convert.interpretMarkerOptions(marker, markerController);
267+
Convert.interpretMarkerOptions(marker, markerController, assetManager, density);
260268
}
261269
}
262270

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package io.flutter.plugins.googlemaps;
66

7+
import android.content.res.AssetManager;
78
import com.google.android.gms.maps.GoogleMap;
89
import com.google.android.gms.maps.model.Polyline;
910
import com.google.android.gms.maps.model.PolylineOptions;
@@ -19,8 +20,10 @@ class PolylinesController {
1920
private final MethodChannel methodChannel;
2021
private GoogleMap googleMap;
2122
private final float density;
23+
private final AssetManager assetManager;
2224

23-
PolylinesController(MethodChannel methodChannel, float density) {
25+
PolylinesController(MethodChannel methodChannel, AssetManager assetManager, float density) {
26+
this.assetManager = assetManager;
2427
this.polylineIdToController = new HashMap<>();
2528
this.googleMapsPolylineIdToDartPolylineId = new HashMap<>();
2629
this.methodChannel = methodChannel;
@@ -82,7 +85,8 @@ private void addPolyline(Object polyline) {
8285
return;
8386
}
8487
PolylineBuilder polylineBuilder = new PolylineBuilder(density);
85-
String polylineId = Convert.interpretPolylineOptions(polyline, polylineBuilder);
88+
String polylineId =
89+
Convert.interpretPolylineOptions(polyline, polylineBuilder, assetManager, density);
8690
PolylineOptions options = polylineBuilder.build();
8791
addPolyline(polylineId, options, polylineBuilder.consumeTapEvents());
8892
}
@@ -102,7 +106,7 @@ private void changePolyline(Object polyline) {
102106
String polylineId = getPolylineId(polyline);
103107
PolylineController polylineController = polylineIdToController.get(polylineId);
104108
if (polylineController != null) {
105-
Convert.interpretPolylineOptions(polyline, polylineController);
109+
Convert.interpretPolylineOptions(polyline, polylineController, assetManager, density);
106110
}
107111
}
108112

packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/ClusterManagersControllerTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.mockito.Mockito.when;
1515

1616
import android.content.Context;
17+
import android.content.res.AssetManager;
1718
import android.os.Build;
1819
import androidx.test.core.app.ApplicationProvider;
1920
import com.google.android.gms.maps.GoogleMap;
@@ -34,6 +35,7 @@
3435
import org.junit.runner.RunWith;
3536
import org.mockito.ArgumentCaptor;
3637
import org.mockito.Mockito;
38+
import org.mockito.MockitoAnnotations;
3739
import org.robolectric.RobolectricTestRunner;
3840
import org.robolectric.annotation.Config;
3941

@@ -46,10 +48,14 @@ public class ClusterManagersControllerTest {
4648
private GoogleMap googleMap;
4749
private MarkerManager markerManager;
4850
private MarkerManager.Collection markerCollection;
51+
private AssetManager assetManager;
52+
private final float density = 1;
4953

5054
@Before
5155
public void setUp() {
56+
MockitoAnnotations.openMocks(this);
5257
context = ApplicationProvider.getApplicationContext();
58+
assetManager = context.getAssets();
5359
methodChannel =
5460
spy(new MethodChannel(mock(BinaryMessenger.class), "no-name", mock(MethodCodec.class)));
5561
controller = spy(new ClusterManagersController(methodChannel, context));
@@ -93,8 +99,8 @@ public void AddClusterManagersAndMarkers() throws InterruptedException {
9399
final Map<String, Object> markerData2 =
94100
createMarkerData(markerId2, location2, clusterManagerId);
95101

96-
Convert.interpretMarkerOptions(markerData1, markerBuilder1);
97-
Convert.interpretMarkerOptions(markerData2, markerBuilder2);
102+
Convert.interpretMarkerOptions(markerData1, markerBuilder1, assetManager, density);
103+
Convert.interpretMarkerOptions(markerData2, markerBuilder2, assetManager, density);
98104

99105
controller.addItem(markerBuilder1);
100106
controller.addItem(markerBuilder2);

0 commit comments

Comments
 (0)