[android] - avoid IndexOutOfBounds when destroying map object

This commit is contained in:
Tobrun Van Nuland
2017-08-17 10:32:49 +02:00
committed by Tobrun
parent 830bf151be
commit 83336e2224
3 changed files with 19 additions and 57 deletions

View File

@@ -53,7 +53,7 @@ class MarkerContainer implements Markers {
mapboxMap) {
int count = markerOptionsList.size();
List<Marker> markers = new ArrayList<>(count);
if (count > 0) {
if (nativeMapView != null && count > 0) {
BaseMarkerOptions markerOptions;
Marker marker;
for (int i = 0; i < count; i++) {
@@ -63,26 +63,13 @@ class MarkerContainer implements Markers {
}
if (markers.size() > 0) {
long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addMarkers(markers);
long[] ids = nativeMapView.addMarkers(markers);
for (int i = 0; i < ids.length; i++) {
Marker createdMarker = markers.get(i);
createdMarker.setMapboxMap(mapboxMap);
createdMarker.setId(ids[i]);
annotations.put(ids[i], createdMarker);
}
long id = 0;
Marker m;
for (int i = 0; i < markers.size(); i++) {
m = markers.get(i);
m.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
m.setId(id);
annotations.put(id, m);
}
}
}
return markers;

View File

@@ -42,7 +42,7 @@ class PolygonContainer implements Polygons {
Polygon polygon;
List<Polygon> polygons = new ArrayList<>(count);
if (count > 0) {
if (nativeMapView != null && count > 0) {
for (PolygonOptions polygonOptions : polygonOptionsList) {
polygon = polygonOptions.getPolygon();
if (!polygon.getPoints().isEmpty()) {
@@ -50,23 +50,12 @@ class PolygonContainer implements Polygons {
}
}
long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addPolygons(polygons);
}
long id = 0;
for (int i = 0; i < polygons.size(); i++) {
long[] ids = nativeMapView.addPolygons(polygons);
for (int i = 0; i < ids.length; i++) {
polygon = polygons.get(i);
polygon.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
polygon.setId(id);
annotations.put(id, polygon);
polygon.setId(ids[i]);
annotations.put(ids[i], polygon);
}
}
return polygons;

View File

@@ -41,8 +41,7 @@ class PolylineContainer implements Polylines {
int count = polylineOptionsList.size();
Polyline polyline;
List<Polyline> polylines = new ArrayList<>(count);
if (count > 0) {
if (nativeMapView != null && count > 0) {
for (PolylineOptions options : polylineOptionsList) {
polyline = options.getPolyline();
if (!polyline.getPoints().isEmpty()) {
@@ -50,25 +49,12 @@ class PolylineContainer implements Polylines {
}
}
long[] ids = null;
if (nativeMapView != null) {
ids = nativeMapView.addPolylines(polylines);
}
long id = 0;
Polyline p;
for (int i = 0; i < polylines.size(); i++) {
p = polylines.get(i);
p.setMapboxMap(mapboxMap);
if (ids != null) {
id = ids[i];
} else {
// unit test
id++;
}
p.setId(id);
annotations.put(id, p);
long[] ids = nativeMapView.addPolylines(polylines);
for (int i = 0; i < ids.length; i++) {
Polyline polylineCreated = polylines.get(i);
polylineCreated.setMapboxMap(mapboxMap);
polylineCreated.setId(ids[i]);
annotations.put(ids[i], polylineCreated);
}
}
return polylines;