[android] Recalculate offset with new anchor

Fixes #5421
This commit is contained in:
Tobrun Van Nuland
2016-06-23 14:46:04 +02:00
committed by Antonio Zugaldia
parent fa54b7dd06
commit 6b1a753fd4
2 changed files with 8 additions and 18 deletions

View File

@@ -86,6 +86,7 @@ public class MarkerView extends Marker {
public void setAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) {
this.anchorU = u;
this.anchorV = v;
setOffset(-1, -1);
}
/**
@@ -107,26 +108,16 @@ public class MarkerView extends Marker {
}
/**
* Internal method to set the horizontal calculated offset.
* Internal method to set the calculated offset.
* <p>
* These are calculated based on the View bounds and the provided anchor.
* </p>
*
* @param x the x-value of the offset
*/
void setOffsetX(float x) {
offsetX = x;
}
/**
* Internal method to set the vertical calculated offset.
* <p>
* These are calculated based on the View bounds and the provided anchor.
* </p>
*
* @param y the y-value of the offset
*/
void setOffsetY(float y) {
void setOffset(float x, float y) {
offsetX = x;
offsetY = y;
}

View File

@@ -118,8 +118,7 @@ public class MarkerViewManager {
if (marker.getOffsetX() == -1) {
int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
marker.setOffsetX(x);
marker.setOffsetY(y);
marker.setOffset(x, y);
}
convertView.setX(point.x - marker.getOffsetX());
@@ -247,6 +246,8 @@ public class MarkerViewManager {
for (final MapboxMap.MarkerViewAdapter<?> adapter : markerViewAdapters) {
if (adapter.getMarkerClass().equals(marker.getClass())) {
if (adapter.prepareViewForReuse(marker, viewHolder)) {
// reset offset for reuse
marker.setOffset(-1, -1);
adapter.releaseView(viewHolder);
}
}
@@ -417,11 +418,9 @@ public class MarkerViewManager {
// update position on map
if (marker.getOffsetX() == -1) {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
int x = (int) (marker.getAnchorU() * view.getMeasuredWidth());
int y = (int) (marker.getAnchorV() * view.getMeasuredHeight());
marker.setOffsetX(x);
marker.setOffsetY(y);
marker.setOffset(x, y);
}
// InfoWindow offset