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

[android] - warning log when attempting to update a non-added annotation #8832

Merged
merged 1 commit into from
Apr 28, 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 @@ -22,6 +22,8 @@
import java.util.Collections;
import java.util.List;

import timber.log.Timber;

/**
* Responsible for managing and tracking state of Annotations linked to Map. All events related to
* annotations that occur on {@link MapboxMap} are forwarded to this class.
Expand Down Expand Up @@ -260,24 +262,24 @@ private MarkerView prepareViewMarker(BaseMarkerViewOptions markerViewOptions) {
return marker;
}

void updateMarker(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) {
if (updatedMarker == null) {
void updateMarker(@NonNull Marker updatedMarker) {
if (!isAddedToMap(updatedMarker)) {
Timber.w("Attempting to update non-added Marker with value %s", updatedMarker);
return;
}

if (updatedMarker.getId() == -1) {
return;
}

if (!(updatedMarker instanceof MarkerView)) {
iconManager.ensureIconLoaded(updatedMarker, mapboxMap);
}

ensureIconLoaded(updatedMarker);
nativeMapView.updateMarker(updatedMarker);
annotations.setValueAt(annotations.indexOfKey(updatedMarker.getId()), updatedMarker);
}

int index = annotations.indexOfKey(updatedMarker.getId());
if (index > -1) {
annotations.setValueAt(index, updatedMarker);
private boolean isAddedToMap(Annotation annotation) {
return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
}

private void ensureIconLoaded(Marker marker) {
if (!(marker instanceof MarkerView)) {
iconManager.ensureIconLoaded(marker, mapboxMap);
}
}

Expand Down Expand Up @@ -465,21 +467,14 @@ List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList, @Non
return polygons;
}

void updatePolygon(Polygon polygon) {
if (polygon == null) {
return;
}

if (polygon.getId() == -1) {
void updatePolygon(@NonNull Polygon polygon) {
if (!isAddedToMap(polygon)) {
Timber.w("Attempting to update non-added Polygon with value %s", polygon);
return;
}

nativeMapView.updatePolygon(polygon);

int index = annotations.indexOfKey(polygon.getId());
if (index > -1) {
annotations.setValueAt(index, polygon);
}
annotations.setValueAt(annotations.indexOfKey(polygon.getId()), polygon);
}

List<Polygon> getPolygons() {
Expand Down Expand Up @@ -546,21 +541,13 @@ List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList,
return polylines;
}

void updatePolyline(Polyline polyline) {
if (polyline == null) {
return;
}

if (polyline.getId() == -1) {
return;
void updatePolyline(@NonNull Polyline polyline) {
if (!isAddedToMap(polyline)) {
Timber.w("Attempting to update non-added Polyline with value %s", polyline);
}

nativeMapView.updatePolyline(polyline);

int index = annotations.indexOfKey(polyline.getId());
if (index > -1) {
annotations.setValueAt(index, polyline);
}
annotations.setValueAt(annotations.indexOfKey(polyline.getId()), polyline);
}

List<Polyline> getPolylines() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ public List<Marker> addMarkers(@NonNull List<? extends
*/
@UiThread
public void updateMarker(@NonNull Marker updatedMarker) {
annotationManager.updateMarker(updatedMarker, this);
annotationManager.updateMarker(updatedMarker);
}

/**
Expand Down