diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-08-02 11:16:49 -0400 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2016-08-03 14:50:41 -0400 |
commit | f26c89c0b6f17039794e67756a610e7f2028100c (patch) | |
tree | 8c941ea2b4fc6929384e4a66cb595e08b04bcaf5 | |
parent | 77c8f0a7058dff25268f69a74554007fc84601fe (diff) | |
download | qtlocation-mapboxgl-f26c89c0b6f17039794e67756a610e7f2028100c.tar.gz |
[android] #5663 - make shape annotations updateable
12 files changed, 357 insertions, 47 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); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java index 68a5b642c4..9f3940bd3f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java @@ -5,9 +5,11 @@ import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.view.Menu; import android.view.MenuItem; import android.view.ViewGroup; +import com.mapbox.mapboxsdk.annotations.Polygon; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.constants.Style; @@ -17,14 +19,45 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.MapboxMapOptions; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant; import java.util.ArrayList; import java.util.List; public class PolygonActivity extends AppCompatActivity { + private static final int BLUE_COLOR = Color.parseColor("#3bb2d0"); + private static final int RED_COLOR = Color.parseColor("#AF0000"); + + private static final float FULL_ALPHA = 1.0f; + private static final float PARTIAL_ALPHA = 0.5f; + private static final float NO_ALPHA = 0.0f; + + private static final List<LatLng> POINTS = new ArrayList<LatLng>() {{ + add(new LatLng(45.522585, -122.685699)); + add(new LatLng(45.534611, -122.708873)); + add(new LatLng(45.530883, -122.678833)); + add(new LatLng(45.547115, -122.667503)); + add(new LatLng(45.530643, -122.660121)); + add(new LatLng(45.533529, -122.636260)); + add(new LatLng(45.521743, -122.659091)); + add(new LatLng(45.510677, -122.648792)); + add(new LatLng(45.515008, -122.664070)); + add(new LatLng(45.502496, -122.669048)); + }}; + + private List<LatLng> ADDITIONAL_POINTS = new ArrayList<LatLng>() {{ + add(new LatLng(45.515369, -122.678489)); + add(new LatLng(45.506346, -122.702007)); + add(new LatLng(45.522585, -122.685699)); + }}; + private MapView mapView; + private Polygon polygon; + + private boolean fullAlpha = true; + private boolean visible = true; + private boolean allPoints = true; + private boolean color = true; @Override protected void onCreate(Bundle savedInstanceState) { @@ -42,8 +75,7 @@ public class PolygonActivity extends AppCompatActivity { // configure inital map state MapboxMapOptions options = new MapboxMapOptions() - .attributionTintColor(Color.RED) - .accessToken(getString(R.string.mapbox_access_token)) + .attributionTintColor(RED_COLOR) .styleUrl(Style.MAPBOX_STREETS) .camera(new CameraPosition.Builder() .target(new LatLng(45.520486, -122.673541)) @@ -57,23 +89,10 @@ public class PolygonActivity extends AppCompatActivity { mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(MapboxMap mapboxMap) { - List<LatLng> polygon = new ArrayList<>(); - polygon.add(new LatLng(45.522585, -122.685699)); - polygon.add(new LatLng(45.534611, -122.708873)); - polygon.add(new LatLng(45.530883, -122.678833)); - polygon.add(new LatLng(45.547115, -122.667503)); - polygon.add(new LatLng(45.530643, -122.660121)); - polygon.add(new LatLng(45.533529, -122.636260)); - polygon.add(new LatLng(45.521743, -122.659091)); - polygon.add(new LatLng(45.510677, -122.648792)); - polygon.add(new LatLng(45.515008, -122.664070)); - polygon.add(new LatLng(45.502496, -122.669048)); - polygon.add(new LatLng(45.515369, -122.678489)); - polygon.add(new LatLng(45.506346, -122.702007)); - polygon.add(new LatLng(45.522585, -122.685699)); - mapboxMap.addPolygon(new PolygonOptions() - .addAll(polygon) - .fillColor(Color.parseColor("#3bb2d0"))); + POINTS.addAll(ADDITIONAL_POINTS); + polygon = mapboxMap.addPolygon(new PolygonOptions() + .addAll(POINTS) + .fillColor(BLUE_COLOR)); } }); @@ -117,8 +136,39 @@ public class PolygonActivity extends AppCompatActivity { case android.R.id.home: onBackPressed(); return true; + + case R.id.action_id_alpha: + fullAlpha = !fullAlpha; + polygon.setAlpha(fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA); + return true; + + case R.id.action_id_visible: + visible = !visible; + polygon.setAlpha(visible ? (fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA) : NO_ALPHA); + return true; + + case R.id.action_id_points: + allPoints = !allPoints; + if (allPoints) { + POINTS.addAll(ADDITIONAL_POINTS); + } else { + POINTS.removeAll(ADDITIONAL_POINTS); + } + polygon.setPoints(POINTS); + return true; + + case R.id.action_id_color: + color = !color; + polygon.setFillColor(color ? BLUE_COLOR : RED_COLOR); + default: return super.onOptionsItemSelected(item); } } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_polygon, menu); + return true; + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java index 9eb4bc1741..5b45223da0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java @@ -25,6 +25,7 @@ import java.util.List; public class PolylineActivity extends AppCompatActivity { private static final String STATE_POLYLINE_OPTIONS = "polylineOptions"; + private static final LatLng ANDORRA = new LatLng(42.505777, 1.52529); private static final LatLng LUXEMBOURG = new LatLng(49.815273, 6.129583); private static final LatLng MONACO = new LatLng(43.738418, 7.424616); @@ -32,11 +33,20 @@ public class PolylineActivity extends AppCompatActivity { private static final LatLng SAN_MARINO = new LatLng(43.942360, 12.457777); private static final LatLng LIECHTENSTEIN = new LatLng(47.166000, 9.555373); + private static final float FULL_ALPHA = 1.0f; + private static final float PARTIAL_ALPHA = 0.5f; + private static final float NO_ALPHA = 0.0f; + private List<Polyline> mPolylines; private ArrayList<PolylineOptions> mPolylineOptions = new ArrayList<>(); private MapView mMapView; private MapboxMap mMapboxMap; + private boolean fullAlpha = true; + private boolean visible = true; + private boolean width = true; + private boolean color = true; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -67,25 +77,29 @@ public class PolylineActivity extends AppCompatActivity { } }); - findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (mMapboxMap != null) { - if (mPolylines != null && mPolylines.size() > 0) { - if (mPolylines.size() == 1) { - // test for removing annotation - mMapboxMap.removeAnnotation(mPolylines.get(0)); - } else { - // test for removing annotations - mMapboxMap.removeAnnotations(mPolylines); + View fab = findViewById(R.id.fab); + if (fab != null) { + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mMapboxMap != null) { + if (mPolylines != null && mPolylines.size() > 0) { + if (mPolylines.size() == 1) { + // test for removing annotation + mMapboxMap.removeAnnotation(mPolylines.get(0)); + } else { + // test for removing annotations + mMapboxMap.removeAnnotations(mPolylines); + } } + mPolylineOptions.clear(); + mPolylineOptions.addAll(getRandomLine()); + mPolylines = mMapboxMap.addPolylines(mPolylineOptions); + } - mPolylineOptions.clear(); - mPolylineOptions.addAll(getRandomLine()); - mPolylines = mMapboxMap.addPolylines(mPolylineOptions); } - } - }); + }); + } } private List<PolylineOptions> getAllPolylines() { @@ -161,6 +175,34 @@ public class PolylineActivity extends AppCompatActivity { mMapboxMap.clear(); return true; + case R.id.action_id_alpha: + fullAlpha = !fullAlpha; + for (Polyline p : mPolylines) { + p.setAlpha(fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA); + } + return true; + + case R.id.action_id_color: + color = !color; + for (Polyline p : mPolylines) { + p.setColor(color ? Color.RED : Color.BLUE); + } + return true; + + case R.id.action_id_width: + width = !width; + for (Polyline p : mPolylines) { + p.setWidth(width ? 3.0f : 5.0f); + } + return true; + + case R.id.action_id_visible: + visible = !visible; + for (Polyline p : mPolylines) { + p.setAlpha(visible ? (fullAlpha ? FULL_ALPHA : PARTIAL_ALPHA) : NO_ALPHA); + } + return true; + case android.R.id.home: onBackPressed(); return true; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_polygon.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_polygon.xml new file mode 100644 index 0000000000..62d4c83594 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_polygon.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:mapbox="http://schemas.android.com/apk/res-auto"> + <item + android:id="@+id/action_id_alpha" + android:title="@string/action_alpha_polygon" + mapbox:showAsAction="never" /> + <item + android:id="@+id/action_id_visible" + android:title="@string/action_visibility_polygon" + mapbox:showAsAction="never" /> + <item + android:id="@+id/action_id_points" + android:title="@string/action_points_polygon" + mapbox:showAsAction="never" /> + <item + android:id="@+id/action_id_color" + android:title="@string/action_color_polygon" + mapbox:showAsAction="never" /> +</menu>
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_polyline.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_polyline.xml index 3590d0c68b..7c324fc9dc 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_polyline.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_polyline.xml @@ -6,4 +6,20 @@ android:icon="@drawable/ic_delete_24dp" android:title="@string/action_remove_polylines" mapbox:showAsAction="ifRoom" /> + <item + android:id="@+id/action_id_width" + android:title="@string/action_width_polyline" + mapbox:showAsAction="never" /> + <item + android:id="@+id/action_id_alpha" + android:title="@string/action_alpha_polygon" + mapbox:showAsAction="never" /> + <item + android:id="@+id/action_id_color" + android:title="@string/action_color_polygon" + mapbox:showAsAction="never" /> + <item + android:id="@+id/action_id_visible" + android:title="@string/action_visibility_polygon" + mapbox:showAsAction="never" /> </menu>
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 5562ee20f8..c6738869a3 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -121,6 +121,12 @@ <string name="action_visible_bounds_explanation">Center map around 2 markers</string> <string name="action_remove_polylines">Remove polylines</string> + <string name="action_visibility_polygon">Change visibility</string> + <string name="action_alpha_polygon">Change alpha</string> + <string name="action_points_polygon">Change points</string> + <string name="action_color_polygon">Change color</string> + <string name="action_width_polyline">Change width</string> + <string name="button_camera_move">Move</string> <string name="button_camera_ease">Ease</string> <string name="button_camera_animate">Animate</string> diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 3a7963f11e..5fc29f4c29 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -788,6 +788,42 @@ jni::jarray<jlong>* nativeAddPolygons(JNIEnv *env, jni::jobject* obj, jlong nati return std_vector_uint_to_jobject(env, ids); } +jlong nativeUpdatePolygon(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlong polygonId, jni::jobject* polygon) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdatePolygon"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + if (polygonId == -1) { + return polygonId; + } + jni::jobject* points = jni::GetField<jni::jobject*>(*env, polygon, *polygonPointsId); + + mbgl::FillAnnotation annotation { mbgl::Polygon<double> { toGeometry<mbgl::LinearRing<double>>(env, points) } }; + annotation.opacity = { jni::GetField<jfloat>(*env, polygon, *polygonAlphaId) }; + annotation.outlineColor = { toColor(jni::GetField<jint>(*env, polygon, *polygonStrokeColorId)) }; + annotation.color = { toColor(jni::GetField<jint>(*env, polygon, *polygonFillColorId)) }; + //TODO replace remove add with updateAnnotation, https://github.com/mapbox/mapbox-gl-native/issues/5844 + nativeMapView->getMap().removeAnnotation(polygonId); + return nativeMapView->getMap().addAnnotation(annotation); +} + +jlong nativeUpdatePolyline(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlong polylineId, jni::jobject* polyline) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdatePolyline"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + if (polylineId == -1) { + return polylineId; + } + jni::jobject* points = jni::GetField<jni::jobject*>(*env, polyline, *polylinePointsId); + + mbgl::LineAnnotation annotation { toGeometry<mbgl::LineString<double>>(env, points) }; + annotation.opacity = { jni::GetField<jfloat>(*env, polyline, *polylineAlphaId) }; + annotation.color = { toColor(jni::GetField<jint>(*env, polyline, *polylineColorId)) }; + annotation.width = { jni::GetField<jfloat>(*env, polyline, *polylineWidthId) }; + //TODO replace remove add with updateAnnotation, https://github.com/mapbox/mapbox-gl-native/issues/5844 + nativeMapView->getMap().removeAnnotation(polylineId); + return nativeMapView->getMap().addAnnotation(annotation); +} + void nativeRemoveAnnotations(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jarray<jlong>* jarray) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotations"); assert(nativeMapViewPtr != 0); @@ -1724,6 +1760,8 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { MAKE_NATIVE_METHOD(nativeAddPolylines, "(J[Lcom/mapbox/mapboxsdk/annotations/Polyline;)[J"), MAKE_NATIVE_METHOD(nativeAddPolygons, "(J[Lcom/mapbox/mapboxsdk/annotations/Polygon;)[J"), MAKE_NATIVE_METHOD(nativeUpdateMarker, "(JJDDLjava/lang/String;)V"), + MAKE_NATIVE_METHOD(nativeUpdatePolygon, "(JJLcom/mapbox/mapboxsdk/annotations/Polygon;)J"), + MAKE_NATIVE_METHOD(nativeUpdatePolyline, "(JJLcom/mapbox/mapboxsdk/annotations/Polyline;)J"), MAKE_NATIVE_METHOD(nativeRemoveAnnotations, "(J[J)V"), MAKE_NATIVE_METHOD(nativeGetAnnotationsInBounds, "(JLcom/mapbox/mapboxsdk/geometry/LatLngBounds;)[J"), MAKE_NATIVE_METHOD(nativeAddAnnotationIcon, "(JLjava/lang/String;IIF[B)V"), |