diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com')
6 files changed, 149 insertions, 11 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java index d2aaea1d17..a76238fdcb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java @@ -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(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java index 4a07b16827..78e3a99e96 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java @@ -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); + } } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java index cfaf0d21d9..4bf3242d57 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java @@ -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); + } } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index c4cf0b3efc..4003c7abde 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -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) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 275cc2aeab..26f13ed353 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -827,6 +827,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. * * @param polylineOptions A polyline options object that defines how to render the polyline. diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 973fa8b5e1..0adc551d8d 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -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); } |