[android] fix added to map checks because LongSparseArray#indexOfKey could return a negative number when the specified key is not mapped (#9602)
This commit is contained in:
@@ -181,6 +181,10 @@ class AnnotationManager {
|
||||
}
|
||||
|
||||
void updateMarker(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) {
|
||||
if (!isAddedToMap(updatedMarker)) {
|
||||
logNonAdded(updatedMarker);
|
||||
return;
|
||||
}
|
||||
markers.update(updatedMarker, mapboxMap);
|
||||
}
|
||||
|
||||
@@ -230,6 +234,10 @@ class AnnotationManager {
|
||||
}
|
||||
|
||||
void updatePolygon(Polygon polygon) {
|
||||
if (!isAddedToMap(polygon)) {
|
||||
logNonAdded(polygon);
|
||||
return;
|
||||
}
|
||||
polygons.update(polygon);
|
||||
}
|
||||
|
||||
@@ -256,6 +264,10 @@ class AnnotationManager {
|
||||
}
|
||||
|
||||
void updatePolyline(Polyline polyline) {
|
||||
if (!isAddedToMap(polyline)) {
|
||||
logNonAdded(polyline);
|
||||
return;
|
||||
}
|
||||
polylines.update(polyline);
|
||||
}
|
||||
|
||||
@@ -365,6 +377,14 @@ class AnnotationManager {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAddedToMap(Annotation annotation) {
|
||||
return annotation != null && annotation.getId() != -1 && annotationsArray.indexOfKey(annotation.getId()) > -1;
|
||||
}
|
||||
|
||||
private void logNonAdded(Annotation annotation) {
|
||||
Timber.w("Attempting to update non-added %s with value %s", annotation.getClass().getCanonicalName(), annotation);
|
||||
}
|
||||
|
||||
//
|
||||
// Click event
|
||||
//
|
||||
|
||||
@@ -18,8 +18,6 @@ import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Encapsulates {@link Marker}'s functionality.
|
||||
*/
|
||||
@@ -92,11 +90,6 @@ class MarkerContainer implements Markers {
|
||||
|
||||
@Override
|
||||
public void update(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) {
|
||||
if (!isAddedToMap(updatedMarker)) {
|
||||
Timber.w("Attempting to update non-added Marker with value %s", updatedMarker);
|
||||
return;
|
||||
}
|
||||
|
||||
ensureIconLoaded(updatedMarker, mapboxMap);
|
||||
nativeMapView.updateMarker(updatedMarker);
|
||||
annotations.setValueAt(annotations.indexOfKey(updatedMarker.getId()), updatedMarker);
|
||||
@@ -237,10 +230,6 @@ class MarkerContainer implements Markers {
|
||||
return marker;
|
||||
}
|
||||
|
||||
private boolean isAddedToMap(Annotation annotation) {
|
||||
return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
|
||||
}
|
||||
|
||||
private void ensureIconLoaded(Marker marker, MapboxMap mapboxMap) {
|
||||
if (!(marker instanceof MarkerView)) {
|
||||
iconManager.ensureIconLoaded(marker, mapboxMap);
|
||||
|
||||
@@ -11,8 +11,6 @@ import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Encapsulates {@link Polygon}'s functionality.
|
||||
*/
|
||||
@@ -76,11 +74,6 @@ class PolygonContainer implements Polygons {
|
||||
|
||||
@Override
|
||||
public void update(Polygon polygon) {
|
||||
if (!isAddedToMap(polygon)) {
|
||||
Timber.w("Attempting to update non-added Polygon with value %s", polygon);
|
||||
return;
|
||||
}
|
||||
|
||||
nativeMapView.updatePolygon(polygon);
|
||||
annotations.setValueAt(annotations.indexOfKey(polygon.getId()), polygon);
|
||||
}
|
||||
@@ -97,8 +90,4 @@ class PolygonContainer implements Polygons {
|
||||
}
|
||||
return polygons;
|
||||
}
|
||||
|
||||
private boolean isAddedToMap(Annotation annotation) {
|
||||
return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ import com.mapbox.mapboxsdk.annotations.PolylineOptions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Encapsulates {@link Polyline}'s functionality.
|
||||
*/
|
||||
@@ -78,11 +76,6 @@ class PolylineContainer implements Polylines {
|
||||
|
||||
@Override
|
||||
public void update(Polyline polyline) {
|
||||
if (!isAddedToMap(polyline)) {
|
||||
Timber.w("Attempting to update non-added Polyline with value %s", polyline);
|
||||
return;
|
||||
}
|
||||
|
||||
nativeMapView.updatePolyline(polyline);
|
||||
annotations.setValueAt(annotations.indexOfKey(polyline.getId()), polyline);
|
||||
}
|
||||
@@ -99,8 +92,4 @@ class PolylineContainer implements Polylines {
|
||||
}
|
||||
return polylines;
|
||||
}
|
||||
|
||||
private boolean isAddedToMap(Annotation annotation) {
|
||||
return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user