Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter] Add TileOverlay support #2077

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
073fca5
Merge pull request #1 from flutter/master
otopba Jul 26, 2019
bb12418
Merge pull request #2 from flutter/master
otopba Aug 6, 2019
a03ee88
Merge pull request #3 from flutter/master
otopba Aug 31, 2019
e2613e0
Merge pull request #4 from flutter/master
otopba Sep 11, 2019
1c98d10
Merge pull request #5 from flutter/master
otopba Sep 16, 2019
b50c88e
Merge pull request #6 from flutter/master
otopba Sep 20, 2019
25f8b29
Add TileOverlay support for Android.
otopba Sep 21, 2019
99d6c94
Merge branch 'master' into tile_overlays
otopba Sep 21, 2019
684c2b4
Avoid unnecessary redraws
otopba Sep 21, 2019
bd8143a
fix format
otopba Sep 21, 2019
ce695b1
Merge pull request #7 from flutter/master
otopba Sep 25, 2019
afa565d
Merge branch 'master' into tile_overlays
otopba Sep 25, 2019
58192f4
Merge pull request #8 from flutter/master
otopba Oct 6, 2019
900264c
Merge branch 'master' into tile_overlays
otopba Oct 6, 2019
485a419
Merge pull request #9 from flutter/master
otopba Nov 2, 2019
f0df60a
Merge branch 'master' into tile_overlays
otopba Nov 2, 2019
dde8df7
Merge pull request #10 from flutter/master
otopba Nov 12, 2019
33ed689
Merge pull request #11 from flutter/master
otopba Nov 29, 2019
7ec3707
Merge remote-tracking branch 'upstream/master'
otopba Dec 8, 2019
f056c49
Merge remote-tracking branch 'upstream/master'
otopba Dec 11, 2019
ab1d5bc
Merge remote-tracking branch 'upstream/master'
otopba Dec 19, 2019
e4a6011
Merge remote-tracking branch 'upstream/master'
otopba Jan 7, 2020
62bf14c
Merge branch 'master' into tile_overlays
otopba Jan 14, 2020
fb15656
Merge remote-tracking branch 'upstream/master'
otopba Jan 19, 2020
596184c
Merge remote-tracking branch 'upstream/master'
otopba Jan 21, 2020
e038a3e
Add dummy map initialization
otopba Jan 21, 2020
4345ed5
Revert "Add dummy map initialization"
otopba Jan 21, 2020
ee302c1
Merge remote-tracking branch 'upstream/master'
otopba Jan 23, 2020
4bd7ee4
Merge branch 'master' into tile_overlays
otopba Jan 24, 2020
c9ee500
Merge remote-tracking branch 'origin/tile_overlays' into tile_overlays
otopba Jan 24, 2020
5850b81
fix changelog
otopba Jan 24, 2020
aa9a533
Add iOS implementation of TileOverlays
neokree Jan 27, 2020
5a5482c
Fix typo
neokree Jan 29, 2020
3b8b6b5
Add tileSize option in flutter TileOverlay class
neokree Jan 29, 2020
246636a
Unify zIndex property type to other overlays
neokree Jan 29, 2020
97598ab
Merge remote-tracking branch 'upstream/master'
otopba Jan 29, 2020
4bbcecf
Merge branch 'master' into tile_overlays
otopba Jan 29, 2020
4c8d45a
Merge remote-tracking branch 'upstream/master'
otopba Feb 1, 2020
976281f
Merge branch 'master' into tile_overlays
otopba Feb 1, 2020
a92d75d
merge
otopba Feb 1, 2020
cfbcb2c
fix analyze
otopba Feb 1, 2020
4ec2520
fix analyze
otopba Feb 1, 2020
f22aebd
fix analyze
otopba Feb 1, 2020
e9c4ea4
Merge branch 'master' into tile_overlays
neokree Feb 9, 2020
c267dca
Merge remote-tracking branch 'upstream/master'
otopba Feb 24, 2020
49dae7e
Merge branch 'master' into tile_overlays
otopba Feb 24, 2020
29de40b
move file
otopba Feb 24, 2020
b173a9c
move files
otopba Feb 24, 2020
fba1dd4
move files
otopba Feb 24, 2020
1936b10
fix path
otopba Feb 24, 2020
4816227
Merge remote-tracking branch 'upstream/master'
otopba Mar 19, 2020
bb4e5be
Merge remote-tracking branch 'upstream/master'
otopba Mar 22, 2020
cb85a8a
Merge branch 'master' into tile_overlays
otopba Mar 22, 2020
f46e1ba
merge
otopba Mar 22, 2020
7245d7f
Do not check for `tileOverlayId` nullability in native code
neokree Apr 13, 2020
0a86ebc
Merge remote-tracking branch 'upstream/master'
otopba Apr 30, 2020
6cd64da
Merge remote-tracking branch 'upstream/master'
otopba May 15, 2020
9c0090e
Merge remote-tracking branch 'upstream/master'
otopba Aug 20, 2020
b79938a
Merge remote-tracking branch 'upstream/master'
otopba Sep 14, 2020
46c9bc9
Merge remote-tracking branch 'plugins/master'
neokree Oct 12, 2020
f621d70
Merge pull request #13 from flutter/master
otopba Oct 26, 2020
8e0d4a6
Merge remote-tracking branch 'upstream/master'
otopba Nov 1, 2020
c4ab426
Merge remote-tracking branch 'origin/master'
otopba Nov 1, 2020
a17b8c0
Merge remote-tracking branch 'origin/tile_overlays' into tile_overlays
otopba Nov 1, 2020
eec0d88
Merge branch 'master' into tile_overlays
otopba Nov 1, 2020
0a90447
update versions
otopba Nov 1, 2020
80dd323
Merge branch 'master' into tile_overlays
neokree Nov 25, 2020
e1b39bd
Move types into google_maps_flutter_platform_interface package
neokree Nov 25, 2020
f40930b
Restore `updateTileOverlays` and `clearTileCache` methods
neokree Nov 25, 2020
510e7b5
Fix example app compilation error
neokree Nov 28, 2020
d6347d0
Fix getTile method
neokree Nov 28, 2020
4825de1
Use new pub google_maps_flutter_platform_interface package
neokree Nov 28, 2020
b8fb61e
Revert "Use new pub google_maps_flutter_platform_interface package"
neokree Nov 28, 2020
139bf05
Fix tile overlays not showed up before `onMapCreated` is called on iOS
neokree Nov 28, 2020
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
4 changes: 4 additions & 0 deletions packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.6

Add TileOverlay support.

## 1.0.5

Overhaul lifecycle management in GoogleMapsPlugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ rootProject.allprojects {

apply plugin: 'com.android.library'

sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8

android {
compileSdkVersion 29

Expand All @@ -31,6 +34,10 @@ android {
lintOptions {
disable 'InvalidPackage'
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

dependencies {
implementation "androidx.annotation:annotation:1.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.android.gms.maps.model.PatternItem;
import com.google.android.gms.maps.model.RoundCap;
import com.google.android.gms.maps.model.SquareCap;
import com.google.android.gms.maps.model.Tile;
import io.flutter.view.FlutterMain;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -142,6 +143,13 @@ private static int toInt(Object o) {
return ((Number) o).intValue();
}

private static byte[] toByteArray(Object o) {
if (o == null) {
return null;
}
return (byte[]) o;
}

static Object cameraPositionToJson(CameraPosition position) {
if (position == null) {
return null;
Expand Down Expand Up @@ -197,6 +205,18 @@ static Object circleIdToJson(String circleId) {
return data;
}

static Object tileOverlayArgumentsToJson(String tileOverlayId, int x, int y, int zoom) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Return type can be Map<String, Object>

Copy link
Contributor Author

@otopba otopba Mar 22, 2020

Choose a reason for hiding this comment

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

Yes, the type may be like that. In this class, the other methods all return an Object. Do you think not to pay attention to other methods and return the Map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same is in your other comments. I did in the same style as the existing code

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why it was like that in other places in the code. Probably some historical reasons.
I would follow the best practice (to indicate the actual return type instead of always use a generic Object) in the new code.

Do you mind doing it? It would help me reviewing the PR much easier :)

if (tileOverlayId == null) {
return null;
}
final Map<String, Object> data = new HashMap<>(4);
data.put("tileOverlayId", tileOverlayId);
data.put("x", x);
data.put("y", y);
data.put("zoom", zoom);
return data;
}

static Object latLngToJson(LatLng latLng) {
return Arrays.asList(latLng.latitude, latLng.longitude);
}
Expand Down Expand Up @@ -615,4 +635,38 @@ private static Cap toCap(Object o) {
throw new IllegalArgumentException("Cannot interpret " + o + " as Cap");
}
}

static String interpretTileOverlayOptions(Object o, TileOverlaySink sink) {
final Map<?, ?> data = toMap(o);
final Object fadeIn = data.get("fadeIn");
if (fadeIn != null) {
sink.setFadeIn(toBoolean(fadeIn));
}
final Object transparency = data.get("transparency");
if (transparency != null) {
sink.setTransparency(toFloat(transparency));
}
final Object zIndex = data.get("zIndex");
if (zIndex != null) {
sink.setZIndex(toFloat(zIndex));
}
final Object visible = data.get("visible");
if (visible != null) {
sink.setVisible(toBoolean(visible));
}
final String tileOverlayId = (String) data.get("tileOverlayId");
if (tileOverlayId == null) {
throw new IllegalArgumentException("tileOverlayId was null");
} else {
return tileOverlayId;
}
}

static Tile interpretTile(Object o) {
final Map<?, ?> data = toMap(o);
int width = toInt(data.get("width"));
int height = toInt(data.get("height"));
byte[] dataArray = toByteArray(data.get("data"));
return new Tile(width, height, dataArray);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GoogleMapBuilder implements GoogleMapOptionsSink {
private Object initialPolygons;
private Object initialPolylines;
private Object initialCircles;
private Object initialTileOverlays;
private Rect padding = new Rect(0, 0, 0, 0);

GoogleMapController build(
Expand All @@ -43,6 +44,7 @@ GoogleMapController build(
controller.setInitialPolygons(initialPolygons);
controller.setInitialPolylines(initialPolylines);
controller.setInitialCircles(initialCircles);
controller.setInitialTileOverlays(initialTileOverlays);
controller.setPadding(padding.top, padding.left, padding.bottom, padding.right);
return controller;
}
Expand Down Expand Up @@ -165,4 +167,9 @@ public void setInitialPolylines(Object initialPolylines) {
public void setInitialCircles(Object initialCircles) {
this.initialCircles = initialCircles;
}

@Override
public void setInitialTileOverlays(Object initialTileOverlays) {
this.initialTileOverlays = initialTileOverlays;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ final class GoogleMapController
private final PolygonsController polygonsController;
private final PolylinesController polylinesController;
private final CirclesController circlesController;
private final TileOverlaysController tileOverlayController;
private List<Object> initialMarkers;
private List<Object> initialPolygons;
private List<Object> initialPolylines;
private List<Object> initialCircles;
private List<Object> initialTileOverlays;

GoogleMapController(
int id,
Expand All @@ -99,6 +101,7 @@ final class GoogleMapController
this.polygonsController = new PolygonsController(methodChannel, density);
this.polylinesController = new PolylinesController(methodChannel, density);
this.circlesController = new CirclesController(methodChannel, density);
this.tileOverlayController = new TileOverlaysController(methodChannel);
}

@Override
Expand Down Expand Up @@ -140,10 +143,12 @@ public void onMapReady(GoogleMap googleMap) {
polygonsController.setGoogleMap(googleMap);
polylinesController.setGoogleMap(googleMap);
circlesController.setGoogleMap(googleMap);
tileOverlayController.setGoogleMap(googleMap);
updateInitialMarkers();
updateInitialPolygons();
updateInitialPolylines();
updateInitialCircles();
updateInitialTileOverlays();
}

@Override
Expand Down Expand Up @@ -385,6 +390,24 @@ public void onSnapshotReady(Bitmap bitmap) {
result.success(mapStyleResult);
break;
}
case "tileOverlays#update":
{
Object tileOverlaysToAdd = call.argument("tileOverlaysToAdd");
tileOverlayController.addTileOverlays((List<Object>) tileOverlaysToAdd);
Object tileOverlaysToChange = call.argument("tileOverlaysToChange");
tileOverlayController.changeTileOverlays((List<Object>) tileOverlaysToChange);
Object tileOverlaysToRemove = call.argument("tileOverlayIdsToRemove");
tileOverlayController.removeTileOverlays((List<Object>) tileOverlaysToRemove);
result.success(null);
break;
}
case "tileOverlays#clearTileCache":
{
Object rawTileOverlayId = call.argument("tileOverlayId");
tileOverlayController.clearTileCache(rawTileOverlayId);
result.success(null);
break;
}
default:
result.notImplemented();
}
Expand Down Expand Up @@ -728,6 +751,18 @@ private void updateInitialCircles() {
circlesController.addCircles(initialCircles);
}

@Override
public void setInitialTileOverlays(Object initialTileOverlays) {
this.initialTileOverlays = (List<Object>) initialTileOverlays;
if (googleMap != null) {
updateInitialTileOverlays();
}
}

private void updateInitialTileOverlays() {
tileOverlayController.addTileOverlays(initialTileOverlays);
}

@SuppressLint("MissingPermission")
private void updateMyLocationSettings() {
if (hasLocationPermission()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public PlatformView create(Context context, int id, Object args) {
if (params.containsKey("circlesToAdd")) {
builder.setInitialCircles(params.get("circlesToAdd"));
}
if (params.containsKey("tileOverlaysToAdd")) {
builder.setInitialTileOverlays(params.get("tileOverlaysToAdd"));
}
return builder.build(id, context, binaryMessenger, lifecycleProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ interface GoogleMapOptionsSink {
void setInitialPolylines(Object initialPolylines);

void setInitialCircles(Object initialCircles);

void setInitialTileOverlays(Object initialTileOverlays);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.flutter.plugins.googlemaps;

import com.google.android.gms.maps.model.TileOverlayOptions;
import com.google.android.gms.maps.model.TileProvider;

public class TileOverlayBuilder implements TileOverlaySink {
private final TileOverlayOptions tileOverlayOptions;

TileOverlayBuilder() {
this.tileOverlayOptions = new TileOverlayOptions();
}

TileOverlayOptions build() {
return tileOverlayOptions;
}

@Override
public void setFadeIn(boolean fadeIn) {
tileOverlayOptions.fadeIn(fadeIn);
}

@Override
public void setTransparency(float transparency) {
tileOverlayOptions.transparency(transparency);
}

@Override
public void setZIndex(float zIndex) {
tileOverlayOptions.zIndex(zIndex);
}

@Override
public void setVisible(boolean visible) {
tileOverlayOptions.visible(visible);
}

@Override
public void setTileProvider(TileProvider tileProvider) {
tileOverlayOptions.tileProvider(tileProvider);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.flutter.plugins.googlemaps;

import com.google.android.gms.maps.model.TileOverlay;
import com.google.android.gms.maps.model.TileProvider;

public class TileOverlayController implements TileOverlaySink {

private final TileOverlay tileOverlay;

public TileOverlayController(TileOverlay tileOverlay) {
this.tileOverlay = tileOverlay;
}

void remove() {
tileOverlay.remove();
}

void clearTileCache() {
tileOverlay.clearTileCache();
}

@Override
public void setFadeIn(boolean fadeIn) {
tileOverlay.setFadeIn(fadeIn);
}

@Override
public void setTransparency(float transparency) {
tileOverlay.setTransparency(transparency);
}

@Override
public void setZIndex(float zIndex) {
tileOverlay.setZIndex(zIndex);
}

@Override
public void setVisible(boolean visible) {
tileOverlay.setVisible(visible);
}

@Override
public void setTileProvider(TileProvider tileProvider) {
// You can not change tile provider after creation
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.flutter.plugins.googlemaps;

import com.google.android.gms.maps.model.TileProvider;

/** Receiver of TileOverlayOptions configuration. */
public interface TileOverlaySink {
void setFadeIn(boolean fadeIn);

void setTransparency(float transparency);

void setZIndex(float zIndex);

void setVisible(boolean visible);

void setTileProvider(TileProvider tileProvider);
}
Loading