Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android] Fix added to map checks #9602

Merged
merged 1 commit into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ List<Marker> addMarkers(@NonNull List<? extends BaseMarkerOptions> markerOptions
}

void updateMarker(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) {
if (!isAddedToMap(updatedMarker)) {
logNonAdded(updatedMarker);
return;
}
markers.update(updatedMarker, mapboxMap);
}

Expand Down Expand Up @@ -230,6 +234,10 @@ List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList, @Non
}

void updatePolygon(Polygon polygon) {
if (!isAddedToMap(polygon)) {
logNonAdded(polygon);
return;
}
polygons.update(polygon);
}

Expand All @@ -256,6 +264,10 @@ List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList,
}

void updatePolyline(Polyline polyline) {
if (!isAddedToMap(polyline)) {
logNonAdded(polyline);
return;
}
polylines.update(polyline);
}

Expand Down Expand Up @@ -365,6 +377,14 @@ void adjustTopOffsetPixels(MapboxMap mapboxMap) {
}
}

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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

/**
* Encapsulates {@link Marker}'s functionality.
*/
Expand Down Expand Up @@ -92,11 +90,6 @@ public List<Marker> addBy(@NonNull List<? extends BaseMarkerOptions> markerOptio

@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);
Expand Down Expand Up @@ -237,10 +230,6 @@ private Marker prepareMarker(BaseMarkerOptions markerOptions) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

/**
* Encapsulates {@link Polygon}'s functionality.
*/
Expand Down Expand Up @@ -76,11 +74,6 @@ public List<Polygon> addBy(@NonNull List<PolygonOptions> polygonOptionsList, @No

@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);
}
Expand All @@ -97,8 +90,4 @@ public List<Polygon> obtainAll() {
}
return polygons;
}

private boolean isAddedToMap(Annotation annotation) {
return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

/**
* Encapsulates {@link Polyline}'s functionality.
*/
Expand Down Expand Up @@ -78,11 +76,6 @@ public List<Polyline> addBy(@NonNull List<PolylineOptions> polylineOptionsList,

@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);
}
Expand All @@ -99,8 +92,4 @@ public List<Polyline> obtainAll() {
}
return polylines;
}

private boolean isAddedToMap(Annotation annotation) {
return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
}
}