Add multiple polygons at once to increase performance

This commit is contained in:
Niklas Ulvinge
2015-07-19 00:27:45 +02:00
parent 0f56c2b0d5
commit 45311e98de
4 changed files with 118 additions and 28 deletions

View File

@@ -243,6 +243,23 @@ public class MapView extends SurfaceView {
return polygon;
}
public List<Polygon> addPolygons(List<PolygonOptions> polygonOptions) {
List<Polygon> polygons = new ArrayList<>();
for(PolygonOptions popts : polygonOptions) {
polygons.add(popts.getPolygon());
}
long[] ids = mNativeMapView.addPolygons(polygons);
for(int i=0; i<polygons.size(); i++) {
polygons.get(i).setId(ids[i]);
polygons.get(i).setMapView(this);
annotations.add(polygons.get(i));
}
return polygons;
}
public void removeAnnotation(Annotation annotation) {
long id = annotation.getId();
mNativeMapView.removeAnnotation(id);

View File

@@ -230,6 +230,11 @@ class NativeMapView {
return nativeAddPolygon(mNativeMapViewPtr, polygon);
}
public long[] addPolygons(List<Polygon> polygon) {
// NH TODO Throw exception if returns -1
return nativeAddPolygons(mNativeMapViewPtr, polygon);
}
public void removeAnnotation(long id) {
nativeRemoveAnnotation(mNativeMapViewPtr, id);
}
@@ -472,6 +477,8 @@ class NativeMapView {
private native long nativeAddPolygon(long mNativeMapViewPtr, Polygon polygon);
private native long[] nativeAddPolygons(long mNativeMapViewPtr, List<Polygon> polygon);
private native void nativeRemoveAnnotation(long nativeMapViewPtr, long id);
private native LatLng nativeGetLatLng(long nativeMapViewPtr);