[android] #4487 - ArraysInOfBoundsException fix for addMarkers

This commit is contained in:
Tobrun
2016-03-29 09:16:02 +02:00
committed by Brad Leege
parent 9a556bf24a
commit f8b6e1f7da
2 changed files with 46 additions and 22 deletions

View File

@@ -610,29 +610,36 @@ public class MapboxMap {
public List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) {
int count = markerOptionsList.size();
List<Marker> markers = new ArrayList<>(count);
MarkerOptions markerOptions;
Marker marker;
for (int i = 0; i < count; i++) {
markerOptions = markerOptionsList.get(i);
marker = prepareMarker(markerOptions);
markers.add(marker);
}
long[] ids = mMapView.addMarkers(markers);
long id = 0;
Marker m;
for (int i = 0; i < markers.size(); i++) {
m = markers.get(i);
m.setMapboxMap(this);
if (ids != null) {
id = ids[i];
} else {
//unit test
id++;
if (count > 0) {
MarkerOptions markerOptions;
Marker marker;
for (int i = 0; i < count; i++) {
markerOptions = markerOptionsList.get(i);
marker = prepareMarker(markerOptions);
markers.add(marker);
}
if (markers.size() > 0) {
long[] ids = mMapView.addMarkers(markers);
// if unittests or markers are correctly added to map
if (ids == null || ids.length == markers.size()) {
long id = 0;
Marker m;
for (int i = 0; i < markers.size(); i++) {
m = markers.get(i);
m.setMapboxMap(this);
if (ids != null) {
id = ids[i];
} else {
//unit test
id++;
}
m.setId(id);
mAnnotations.put(id, m);
}
}
}
m.setId(id);
mAnnotations.put(id, m);
}
return markers;
}