[android] #3276 - remove Marker View implementation

This commit is contained in:
Tobrun
2016-05-09 11:17:52 +02:00
parent d5c63e6c82
commit b32c44ce73
6 changed files with 115 additions and 22 deletions

View File

@@ -456,14 +456,7 @@ public class MapView extends FrameLayout {
}
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE) {
if (mMapboxMap.getMarkerViewAdapter() != null) {
long currentTime = SystemClock.elapsedRealtime();
if (mViewMarkersUpdateRunning || currentTime < mViewMarkerBoundsUpdateTime) {
return;
}
mViewMarkerBoundsUpdateTime = currentTime + 300;
new MarkerInBoundsTask().execute();
invalidateViewMarkers();
}
}
}
@@ -478,8 +471,18 @@ public class MapView extends FrameLayout {
}
}
void invalidateViewMarkers(){
long currentTime = SystemClock.elapsedRealtime();
public class MarkerInBoundsTask extends AsyncTask<Void, Void, MarkerInBoundsTask.Result> {
if (mViewMarkersUpdateRunning || currentTime < mViewMarkerBoundsUpdateTime) {
return;
}
mViewMarkerBoundsUpdateTime = currentTime + 300;
new ViewMarkerInBoundsTask().execute();
}
public class ViewMarkerInBoundsTask extends AsyncTask<Void, Void, ViewMarkerInBoundsTask.Result> {
@Override
protected void onPreExecute() {
@@ -1454,12 +1457,14 @@ public class MapView extends FrameLayout {
mViewHolder = viewMarkers.valueAt(i);
if (mViewHolder != null) {
Marker marker = (Marker) mMapboxMap.getAnnotation(viewMarkers.keyAt(i));
PointF point = mMapboxMap.getProjection().toScreenLocation(marker.getPosition());
mViewHolder.setX(point.x - (mViewHolder.getMeasuredWidth() / 2));
mViewHolder.setY(point.y - (mViewHolder.getMeasuredHeight() / 2));
if(marker!=null) {
PointF point = mMapboxMap.getProjection().toScreenLocation(marker.getPosition());
mViewHolder.setX(point.x - (mViewHolder.getMeasuredWidth() / 2));
mViewHolder.setY(point.y - (mViewHolder.getMeasuredHeight() / 2));
if (mViewHolder.getVisibility() == View.GONE) {
mViewHolder.setVisibility(View.VISIBLE);
if (mViewHolder.getVisibility() == View.GONE) {
mViewHolder.setVisibility(View.VISIBLE);
}
}
}
}

View File

@@ -636,9 +636,11 @@ public class MapboxMap {
// Annotations
//
void setViewMarkersBoundsTaskResult(MapView.MarkerInBoundsTask.Result result) {
void setViewMarkersBoundsTaskResult(MapView.ViewMarkerInBoundsTask.Result result) {
Map<Marker, View> outBoundsMarker = result.getOutBounds();
View convertView;
// out of bounds markers
for (Map.Entry<Marker, View> outBoundsEntry : outBoundsMarker.entrySet()) {
convertView = outBoundsEntry.getValue();
if (convertView != null) {
@@ -648,6 +650,7 @@ public class MapboxMap {
}
}
// in bounds markers
List<Marker> inBoundsMarkers = result.getInBounds();
for (final Marker marker : inBoundsMarkers) {
convertView = viewSimplePool.acquire();
@@ -953,13 +956,24 @@ public class MapboxMap {
@UiThread
public void removeAnnotation(@NonNull Annotation annotation) {
if (annotation instanceof Marker) {
((Marker) annotation).hideInfoWindow();
Marker marker = (Marker) annotation;
marker.hideInfoWindow();
removeMarkerView(annotation.getId());
}
long id = annotation.getId();
mMapView.removeAnnotation(id);
mAnnotations.remove(id);
}
private void removeMarkerView(long id){
View viewHolder = mMarkerViews.get(id);
if(viewHolder!=null) {
viewHolder.setVisibility(View.GONE);
viewSimplePool.release(viewHolder);
}
mMarkerViews.remove(id);
}
/**
* Removes an annotation from the map
*
@@ -984,6 +998,7 @@ public class MapboxMap {
Annotation annotation = annotationList.get(i);
if (annotation instanceof Marker) {
((Marker) annotation).hideInfoWindow();
removeMarkerView(annotation.getId());
}
ids[i] = annotationList.get(i).getId();
}
@@ -1198,6 +1213,9 @@ public class MapboxMap {
public void setMarkerViewAdapter(@Nullable MarkerViewAdapter markerViewAdapter) {
mMarkerViewAdapter = markerViewAdapter;
if(markerViewAdapter!=null){
mMapView.invalidateViewMarkers();
}
}
public MarkerViewAdapter getMarkerViewAdapter() {