MarkerView more robust when updates are asynchronous (#6717)
* [android] - remove ViewMarkers crash, show correct view cache size in test activity * use MapboxMap to indicate a MarkerView is no longer added on a map, no future updates will be passed on to core. * resolve memory leak
This commit is contained in:
@@ -345,19 +345,23 @@ public class MarkerView extends Marker {
|
||||
* <p>
|
||||
* This method is used to instantiate the MarkerView and provide an instance of {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter}
|
||||
* </p>
|
||||
* <p>
|
||||
* This method is used to notify that a MarkerView is no longer active by setting a null value.
|
||||
* </p>
|
||||
*
|
||||
* @param mapboxMap the MapboxMap instances
|
||||
*/
|
||||
@Override
|
||||
public void setMapboxMap(MapboxMap mapboxMap) {
|
||||
super.setMapboxMap(mapboxMap);
|
||||
if(mapboxMap!=null) {
|
||||
if (isFlat()) {
|
||||
// initial tilt value if MapboxMap is started with a tilt attribute
|
||||
tiltValue = (float) mapboxMap.getCameraPosition().tilt;
|
||||
}
|
||||
|
||||
if (isFlat()) {
|
||||
// initial tilt value if MapboxMap is started with a tilt attribute
|
||||
tiltValue = (float) mapboxMap.getCameraPosition().tilt;
|
||||
markerViewManager = mapboxMap.getMarkerViewManager();
|
||||
}
|
||||
|
||||
markerViewManager = mapboxMap.getMarkerViewManager();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -317,6 +317,7 @@ public class MarkerViewManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
marker.setMapboxMap(null);
|
||||
markerViewMap.remove(marker);
|
||||
}
|
||||
|
||||
@@ -390,14 +391,15 @@ public class MarkerViewManager {
|
||||
// remove old markers
|
||||
Iterator<MarkerView> iterator = markerViewMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
MarkerView m = iterator.next();
|
||||
if (!markers.contains(m)) {
|
||||
MarkerView marker = iterator.next();
|
||||
if (!markers.contains(marker)) {
|
||||
// remove marker
|
||||
convertView = markerViewMap.get(m);
|
||||
convertView = markerViewMap.get(marker);
|
||||
for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) {
|
||||
if (adapter.getMarkerClass().equals(m.getClass())) {
|
||||
adapter.prepareViewForReuse(m, convertView);
|
||||
if (adapter.getMarkerClass().equals(marker.getClass())) {
|
||||
adapter.prepareViewForReuse(marker, convertView);
|
||||
adapter.releaseView(convertView);
|
||||
marker.setMapboxMap(null);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
@@ -409,20 +411,14 @@ public class MarkerViewManager {
|
||||
if (!markerViewMap.containsKey(marker)) {
|
||||
for (final MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) {
|
||||
if (adapter.getMarkerClass().equals(marker.getClass())) {
|
||||
|
||||
// Inflate View
|
||||
convertView = (View) adapter.getViewReusePool().acquire();
|
||||
final View adaptedView = adapter.getView(marker, convertView, mapView);
|
||||
if (adaptedView != null) {
|
||||
|
||||
// tilt
|
||||
adaptedView.setRotationX(marker.getTilt());
|
||||
|
||||
// rotation
|
||||
adaptedView.setRotation(marker.getRotation());
|
||||
|
||||
// alpha
|
||||
adaptedView.setAlpha(marker.getAlpha());
|
||||
|
||||
// visible
|
||||
adaptedView.setVisibility(View.GONE);
|
||||
|
||||
if (mapboxMap.getSelectedMarkers().contains(marker)) {
|
||||
@@ -448,6 +444,7 @@ public class MarkerViewManager {
|
||||
}
|
||||
});
|
||||
|
||||
marker.setMapboxMap(mapboxMap);
|
||||
markerViewMap.put(marker, adaptedView);
|
||||
if (convertView == null) {
|
||||
adaptedView.setVisibility(View.GONE);
|
||||
|
||||
Reference in New Issue
Block a user