Skip to content

Commit

Permalink
toggle removes all annotations. ready for polygon JNI mapbox#1716
Browse files Browse the repository at this point in the history
  • Loading branch information
hallahan committed Jul 16, 2015
1 parent 9e3f607 commit 0df1d64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.mapbox.mapboxgl.annotations.Annotation;
import com.mapbox.mapboxgl.annotations.Marker;
import com.mapbox.mapboxgl.annotations.MarkerOptions;
import com.mapbox.mapboxgl.annotations.Polygon;
import com.mapbox.mapboxgl.annotations.PolygonOptions;
import com.mapbox.mapboxgl.annotations.Polyline;
import com.mapbox.mapboxgl.annotations.PolylineOptions;
import com.mapbox.mapboxgl.geometry.LatLng;
Expand Down Expand Up @@ -232,11 +234,29 @@ public Polyline addPolyline(PolylineOptions polylineOptions) {
return polyline;
}

public Polygon addPolygon(PolygonOptions polygonOptions) {
Polygon polygon = polygonOptions.getPolygon();
Long id = mNativeMapView.addPolygon(polygon);
polygon.setId(id);
polygon.setMapView(this);
annotations.add(polygon);
return polygon;
}

public void removeAnnotation(Annotation annotation) {
long id = annotation.getId();
mNativeMapView.removeAnnotation(id);
}

public void removeAnnotation(long annotationId) {
mNativeMapView.removeAnnotation(annotationId);
}

public void removeAnnotations() {
for (Annotation annotation : annotations) {
annotation.remove();
}
}

//
// Property methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.Surface;

import com.mapbox.mapboxgl.annotations.Marker;
import com.mapbox.mapboxgl.annotations.Polygon;
import com.mapbox.mapboxgl.annotations.Polyline;
import com.mapbox.mapboxgl.geometry.LatLng;
import com.mapbox.mapboxgl.geometry.LatLngZoom;
Expand Down Expand Up @@ -225,6 +226,11 @@ public long addPolyline(Polyline polyline) {
return nativeAddPolyline(mNativeMapViewPtr, polyline);
}

public long addPolygon(Polygon polygon) {
// NH TODO Throw exception if returns -1
return nativeAddPolygon(mNativeMapViewPtr, polygon);
}

public void removeAnnotation(long id) {
nativeRemoveAnnotation(mNativeMapViewPtr, id);
}
Expand Down Expand Up @@ -465,6 +471,8 @@ private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng,

private native long nativeAddPolyline(long nativeMapViewPtr, Polyline polyline);

private native long nativeAddPolygon(long mNativeMapViewPtr, Polygon polygon);

private native void nativeRemoveAnnotation(long nativeMapViewPtr, long id);

private native LatLng nativeGetLatLng(long nativeMapViewPtr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private void toggleMarkers(boolean enableMarkers) {
} else {
if (mIsMarkersOn) {
mIsMarkersOn = false;
removeMarkers();
removeAnnotations();
}
}
}
Expand Down Expand Up @@ -311,8 +311,8 @@ private void addPolyline() {
}
}

private void removeMarkers() {
marker.remove();
private void removeAnnotations() {
mMapFragment.getMap().removeAnnotations();
}

// This class forwards location updates to updateLocation()
Expand Down

0 comments on commit 0df1d64

Please sign in to comment.