Skip to content

Commit

Permalink
mapbox#894 - Getting InfoWindow view to measure itself before being a…
Browse files Browse the repository at this point in the history
…dded so that placement can be calculated
  • Loading branch information
bleege authored and incanus committed Sep 7, 2015
1 parent 32088a5 commit 5aaf32d
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ public boolean onTouch(View v, MotionEvent e) {
public InfoWindow open(Marker object, LatLng position, int offsetX, int offsetY) {
onOpen(object);
MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT);
PointF coords = mMapView.toScreenLocation(position);
mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

double y = mMapView.getTopOffsetPixelsForAnnotationSymbol(object.sprite);
PointF coords = mMapView.toScreenLocation(position);
// double y = mMapView.getTopOffsetPixelsForAnnotationSymbol(object.sprite);

// Flip y coordinate as Android view origin is upper left corner
coords.y = mMapView.getHeight() - coords.y;
lp.leftMargin = (int) coords.x - 1;
lp.topMargin = (int) coords.y + (int) y;
lp.leftMargin = (int) coords.x - (mView.getMeasuredWidth() / 2);
lp.topMargin = (int) coords.y - (mView.getMeasuredHeight());

close(); //if it was already opened
mMapView.addView(mView, lp);
Expand Down

0 comments on commit 5aaf32d

Please sign in to comment.