[android] - MarkerView is responsible for managing height and width of a Marker (opposed to the recycled view). (#6809)
This commit is contained in:
@@ -21,11 +21,14 @@ public class MarkerView extends Marker {
|
||||
|
||||
private MarkerViewManager markerViewManager;
|
||||
|
||||
private float width;
|
||||
private float height;
|
||||
|
||||
private float anchorU;
|
||||
private float anchorV;
|
||||
|
||||
private float offsetX = -1;
|
||||
private float offsetY = -1;
|
||||
private float offsetX = MapboxConstants.UNMEASURED;
|
||||
private float offsetY = MapboxConstants.UNMEASURED;
|
||||
|
||||
private float infoWindowAnchorU;
|
||||
private float infoWindowAnchorV;
|
||||
@@ -41,6 +44,7 @@ public class MarkerView extends Marker {
|
||||
|
||||
private boolean selected;
|
||||
|
||||
|
||||
/**
|
||||
* Publicly hidden default constructor
|
||||
*/
|
||||
@@ -64,6 +68,22 @@ public class MarkerView extends Marker {
|
||||
this.selected = baseMarkerViewOptions.selected;
|
||||
}
|
||||
|
||||
float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
float getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
void setHeight(float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the anchor being set on a particular point point of the MarkerView.
|
||||
* <p>
|
||||
|
||||
@@ -130,14 +130,18 @@ public class MarkerViewManager {
|
||||
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
|
||||
if (marker.getOffsetX() == MapboxConstants.UNMEASURED) {
|
||||
// ensure view is measured first
|
||||
if (convertView.getWidth() == 0) {
|
||||
if (marker.getWidth() == 0) {
|
||||
convertView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
||||
if (convertView.getMeasuredWidth() != 0) {
|
||||
marker.setWidth(convertView.getMeasuredWidth());
|
||||
marker.setHeight(convertView.getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
if (convertView.getMeasuredWidth() != 0) {
|
||||
int x = (int) (marker.getAnchorU() * convertView.getMeasuredWidth());
|
||||
int y = (int) (marker.getAnchorV() * convertView.getMeasuredHeight());
|
||||
marker.setOffset(x, y);
|
||||
}
|
||||
}
|
||||
if (marker.getWidth() != 0) {
|
||||
int x = (int) (marker.getAnchorU() * marker.getWidth());
|
||||
int y = (int) (marker.getAnchorV() * marker.getHeight());
|
||||
marker.setOffset(x, y);
|
||||
}
|
||||
|
||||
convertView.setX(point.x - marker.getOffsetX());
|
||||
@@ -322,7 +326,7 @@ public class MarkerViewManager {
|
||||
if (adapter.getMarkerClass().equals(marker.getClass())) {
|
||||
if (adapter.prepareViewForReuse(marker, viewHolder)) {
|
||||
// reset offset for reuse
|
||||
marker.setOffset(-1, -1);
|
||||
marker.setOffset(MapboxConstants.UNMEASURED, MapboxConstants.UNMEASURED);
|
||||
adapter.releaseView(viewHolder);
|
||||
}
|
||||
}
|
||||
@@ -492,15 +496,19 @@ public class MarkerViewManager {
|
||||
}
|
||||
|
||||
if (view != null) {
|
||||
//Ensure the marker's view is measured first
|
||||
if (view.getMeasuredWidth() == 0) {
|
||||
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
||||
if (marker.getWidth() == 0) {
|
||||
if(view.getMeasuredWidth()==0) {
|
||||
//Ensure the marker's view is measured first
|
||||
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
||||
}
|
||||
marker.setWidth(view.getMeasuredWidth());
|
||||
marker.setHeight(view.getMeasuredHeight());
|
||||
}
|
||||
|
||||
// update position on map
|
||||
if (marker.getOffsetX() == -1) {
|
||||
int x = (int) (marker.getAnchorU() * view.getMeasuredWidth());
|
||||
int y = (int) (marker.getAnchorV() * view.getMeasuredHeight());
|
||||
if (marker.getOffsetX() == MapboxConstants.UNMEASURED) {
|
||||
int x = (int) (marker.getAnchorU() * marker.getWidth());
|
||||
int y = (int) (marker.getAnchorV() * marker.getHeight());
|
||||
marker.setOffset(x, y);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user