[android] #5663 - make shape annotations updateable

This commit is contained in:
Tobrun
2016-08-02 11:16:49 -04:00
parent 77c8f0a705
commit f26c89c0b6
12 changed files with 357 additions and 47 deletions

View File

@@ -34,19 +34,24 @@ public abstract class MultiPoint extends Annotation {
*
* @param points the points of the polyline
*/
void setPoints(List<LatLng> points) {
public void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
update();
}
void addPoint(LatLng point) {
public void addPoint(LatLng point) {
points.add(point);
update();
}
public float getAlpha() {
return alpha;
}
void setAlpha(float alpha) {
public void setAlpha(float alpha) {
this.alpha = alpha;
update();
}
abstract void update();
}

View File

@@ -2,10 +2,7 @@ package com.mapbox.mapboxsdk.annotations;
import android.graphics.Color;
import com.mapbox.mapboxsdk.geometry.LatLng;
import java.util.ArrayList;
import java.util.List;
import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Polygon is a geometry annotation that's a closed loop of coordinates.
@@ -19,19 +16,49 @@ public final class Polygon extends MultiPoint {
super();
}
/**
* Get the color of the fill region of the polygon.
*
* @return the color of the fill
*/
public int getFillColor() {
return fillColor;
}
/**
* Get the color fo the stroke of the polygon.
*
* @return the color of the stroke
*/
public int getStrokeColor() {
return strokeColor;
}
void setFillColor(int color) {
/**
* Sets the color of the fill region of the polygon.
*
* @param color - the color in ARGB format
*/
public void setFillColor(int color) {
fillColor = color;
update();
}
void setStrokeColor(int color) {
/**
* Sets the color of the stroke of the polygon.
*
* @param color - the color in ARGB format
*/
public void setStrokeColor(int color) {
strokeColor = color;
update();
}
@Override
void update() {
MapboxMap mapboxMap = getMapboxMap();
if (mapboxMap != null) {
mapboxMap.updatePolygon(this);
}
}
}

View File

@@ -2,6 +2,8 @@ package com.mapbox.mapboxsdk.annotations;
import android.graphics.Color;
import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Polyline is a geometry feature with an unclosed list of coordinates drawn as a line
*/
@@ -14,10 +16,20 @@ public final class Polyline extends MultiPoint {
super();
}
/**
* Returns the Polyline tint color.
*
* @return the tint color
*/
public int getColor() {
return color;
}
/**
* Returns the Polyline width.
*
* @return the width
*/
public float getWidth() {
return width;
}
@@ -27,8 +39,9 @@ public final class Polyline extends MultiPoint {
*
* @param color - the color in ARGB format
*/
void setColor(int color) {
public void setColor(int color) {
this.color = color;
update();
}
/**
@@ -36,7 +49,16 @@ public final class Polyline extends MultiPoint {
*
* @param width in pixels
*/
void setWidth(float width) {
public void setWidth(float width) {
this.width = width;
update();
}
@Override
void update() {
MapboxMap mapboxMap = getMapboxMap();
if (mapboxMap != null) {
mapboxMap.updatePolyline(this);
}
}
}

View File

@@ -1016,6 +1016,7 @@ public class MapView extends FrameLayout {
if (updatedMarker.getId() == -1) {
Log.w(MapboxConstants.TAG, "marker has an id of -1, possibly was not added yet, doing nothing");
return;
}
if (!(updatedMarker instanceof MarkerView)) {
@@ -1025,6 +1026,43 @@ public class MapView extends FrameLayout {
mNativeMapView.updateMarker(updatedMarker);
}
void updatePolygon(Polygon polygon) {
if (mDestroyed) {
return;
}
if (polygon == null) {
Log.w(MapboxConstants.TAG, "polygon was null, doing nothing");
return;
}
if (polygon.getId() == -1) {
Log.w(MapboxConstants.TAG, "polygon has an id of -1, indicating the polygon was not added to the map yet.");
return;
}
mNativeMapView.updatePolygon(polygon);
}
void updatePolyline(Polyline polyline) {
if (mDestroyed) {
return;
}
if (polyline == null) {
Log.w(MapboxConstants.TAG, "polygon was null, doing nothing");
return;
}
if (polyline.getId() == -1) {
Log.w(MapboxConstants.TAG, "polygon has an id of -1, indicating the polygon was not added to the map yet.");
return;
}
mNativeMapView.updatePolyline(polyline);
}
private void ensureIconLoaded(Marker marker) {
Icon icon = marker.getIcon();
if (icon == null) {

View File

@@ -826,6 +826,36 @@ public class MapboxMap {
}
}
/**
* Update a polygon on this map.
*
* @param polygon An updated polygon object.
*/
@UiThread
public void updatePolygon(Polygon polygon) {
mMapView.updatePolygon(polygon);
int index = mAnnotations.indexOfKey(polygon.getId());
if (index > -1) {
mAnnotations.setValueAt(index, polygon);
}
}
/**
* Update a polyline on this map.
*
* @param polyline An updated polyline object.
*/
@UiThread
public void updatePolyline(Polyline polyline) {
mMapView.updatePolyline(polyline);
int index = mAnnotations.indexOfKey(polyline.getId());
if (index > -1) {
mAnnotations.setValueAt(index, polyline);
}
}
/**
* Adds a polyline to this map.
*

View File

@@ -381,6 +381,18 @@ final class NativeMapView {
nativeUpdateMarker(mNativeMapViewPtr, marker.getId(), position.getLatitude(), position.getLongitude(), icon.getId());
}
public void updatePolygon(Polygon polygon) {
//TODO remove new id assignment, https://github.com/mapbox/mapbox-gl-native/issues/5844
long newId = nativeUpdatePolygon(mNativeMapViewPtr, polygon.getId(), polygon);
polygon.setId(newId);
}
public void updatePolyline(Polyline polyline) {
//TODO remove new id assignment, https://github.com/mapbox/mapbox-gl-native/issues/5844
long newId = nativeUpdatePolyline(mNativeMapViewPtr, polyline.getId(), polyline);
polyline.setId(newId);
}
public void removeAnnotation(long id) {
long[] ids = {id};
removeAnnotations(ids);
@@ -670,4 +682,8 @@ final class NativeMapView {
private native void nativeAddSource(long mNativeMapViewPtr, String id, Source source);
private native void nativeRemoveSource(long mNativeMapViewPtr, String sourceId);
private native long nativeUpdatePolygon(long nativeMapViewPtr, long polygonId, Polygon polygon);
private native long nativeUpdatePolyline(long nativeMapviewPtr, long polylineId, Polyline polyline);
}