Skip to content

Commit

Permalink
mapbox#894 - Placing InfoWindow directly on top of Marker sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege authored and incanus committed Sep 7, 2015
1 parent 5aaf32d commit c98bedc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ public InfoWindow open(Marker object, LatLng position, int offsetX, int offsetY)
mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

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

// Flip y coordinate as Android view origin is upper left corner
coords.y = mMapView.getHeight() - coords.y;
lp.leftMargin = (int) coords.x - (mView.getMeasuredWidth() / 2);
lp.topMargin = (int) coords.y - (mView.getMeasuredHeight());
// Add y because it's a negative value
lp.topMargin = (int) coords.y - mView.getMeasuredHeight() + (int) y;

close(); //if it was already opened
mMapView.addView(mView, lp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,15 @@ public double getTopOffsetPixelsForAnnotationSymbol(@NonNull String symbolName)
return mNativeMapView.getTopOffsetPixelsForAnnotationSymbol(symbolName);
}

//
/**
* Common Screen Density
* @return Screen Density
*/
public float getScreenDensity() {
return mScreenDensity;
}

//
// Lifecycle events
//

Expand Down

0 comments on commit c98bedc

Please sign in to comment.