-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_maps_flutter] Add TileOverlay support #2077
Changes from 66 commits
073fca5
bb12418
a03ee88
e2613e0
1c98d10
b50c88e
25f8b29
99d6c94
684c2b4
bd8143a
ce695b1
afa565d
58192f4
900264c
485a419
f0df60a
dde8df7
33ed689
7ec3707
f056c49
ab1d5bc
e4a6011
62bf14c
fb15656
596184c
e038a3e
4345ed5
ee302c1
4bd7ee4
c9ee500
5850b81
aa9a533
5a5482c
3b8b6b5
246636a
97598ab
4bbcecf
4c8d45a
976281f
a92d75d
cfbcb2c
4ec2520
f22aebd
e9c4ea4
c267dca
49dae7e
29de40b
b173a9c
fba1dd4
1936b10
4816227
bb4e5be
cb85a8a
f46e1ba
7245d7f
0a86ebc
6cd64da
9c0090e
b79938a
46c9bc9
f621d70
8e0d4a6
c4ab426
a17b8c0
eec0d88
0a90447
80dd323
e1b39bd
f40930b
510e7b5
d6347d0
4825de1
b8fb61e
139bf05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -197,6 +205,18 @@ static Object circleIdToJson(String circleId) { | |
return data; | ||
} | ||
|
||
static Object tileOverlayArgumentsToJson(String tileOverlayId, int x, int y, int zoom) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return type can be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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); | ||
} | ||
|
@@ -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 |
---|---|---|
@@ -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); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.