Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #3115 - optimised + cleanup before PR
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Nov 25, 2015
1 parent 4c9751c commit e7c4ee4
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class InfoWindow {
private WeakReference<MapView> mMapView;
private float mMarkerHeightOffset;
private float mViewWidthOffset;
private PointF mCoordinates;
private boolean mIsVisible;
protected View mView;

Expand Down Expand Up @@ -84,15 +85,17 @@ public boolean onTouch(View v, MotionEvent e) {
*/
InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) {
setBoundMarker(boundMarker);
mMarkerHeightOffset = offsetY;

MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT);
mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

// Calculate y-offset for update method
mMarkerHeightOffset = -mView.getMeasuredHeight() + offsetY;

// Calculate default Android x,y coordinate
PointF coords = mMapView.get().toScreenLocation(position);
float x = coords.x - (mView.getMeasuredWidth() / 2) + offsetX;
float y = coords.y - mView.getMeasuredHeight() + mMarkerHeightOffset;
mCoordinates = mMapView.get().toScreenLocation(position);
float x = mCoordinates.x - (mView.getMeasuredWidth() / 2) + offsetX;
float y = mCoordinates.y - mView.getMeasuredHeight() + offsetY;

if (mView instanceof InfoWindowView) {
// only apply repositioning/margin for InfoWindowView
Expand Down Expand Up @@ -133,15 +136,13 @@ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) {
if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) {
x -= marginHorizontal - (mapRight - rightSideInfowWindow);
tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset;

leftSideInfoWindow = x;
}

// Add margin left
if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) {
x += marginHorizontal - (leftSideInfoWindow - mapLeft);
tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset;

}

// Adjust tipView
Expand All @@ -153,7 +154,8 @@ InfoWindow open(Marker boundMarker, LatLng position, int offsetX, int offsetY) {
mView.setX(x);
mView.setY(y);

mViewWidthOffset = x - (coords.x - (mView.getMeasuredWidth() / 2) + offsetX);
// Calculate x-offset for update method
mViewWidthOffset = x - mCoordinates.x - offsetX;

close(); //if it was already opened
mMapView.get().addView(mView, lp);
Expand Down Expand Up @@ -237,9 +239,9 @@ public void update() {
MapView mapView = mMapView.get();
Marker marker = mBoundMarker.get();
if (mapView != null && marker != null) {
PointF pointF = mapView.toScreenLocation(marker.getPosition());
mView.setX((pointF.x - (mView.getWidth() / 2)) + mViewWidthOffset);
mView.setY(pointF.y - mView.getHeight() + mMarkerHeightOffset);
mCoordinates = mapView.toScreenLocation(marker.getPosition());
mView.setX(mCoordinates.x + mViewWidthOffset);
mView.setY(mCoordinates.y + mMarkerHeightOffset);
}
}

Expand Down

0 comments on commit e7c4ee4

Please sign in to comment.