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

Commit

Permalink
[android] #2588 - Make getTopOffsetPixelsForAnnotationSymbol private.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leith Bade committed Oct 13, 2015
1 parent 96a9e07 commit 67f0108
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
3 changes: 3 additions & 0 deletions android/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ MapboxGLAndroidSDKTestApp/src/main/res/raw/token.txt

# Twitter Fabric / Crashlytics
fabric.properties

# Capture files
captures/
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ 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.getSprite());
y = y * mMapView.getScreenDensity();

lp.leftMargin = (int) coords.x - (mView.getMeasuredWidth() / 2);
lp.leftMargin = (int) coords.x - (mView.getMeasuredWidth() / 2) + offsetX;
// Add y because it's a negative value
lp.topMargin = (int) coords.y - mView.getMeasuredHeight() + (int) y;
lp.topMargin = (int) coords.y - mView.getMeasuredHeight() + offsetY;

close(); //if it was already opened
mMapView.addView(mView, lp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ public class Marker extends Annotation {
private boolean flat;
private float infoWindowAnchorU;
private float infoWindowAnchorV;
LatLng position;
private LatLng position;
private float rotation;
private String snippet;
String sprite = "default_marker";
private String sprite = "default_marker";
private String title;
private InfoWindow infoWindow = null;

private boolean infoWindowShown = false;
private int topOffsetPixels;

/**
* Constructor
Expand Down Expand Up @@ -124,7 +125,7 @@ public void setInfoWindowAnchor(float u, float v) {
infoWindowAnchorV = v;
}

public void setPosition(LatLng latlng) {
public void setPosition(LatLng position) {
this.position = position;
}

Expand Down Expand Up @@ -161,26 +162,26 @@ public void setTitle(String title) {
}

public void showInfoWindow() {

if (!isVisible() || mapView == null) {
return;
}

getInfoWindow().adaptDefaultMarker(this);
getInfoWindow().open(this, getPosition(), (int) anchorU, (int) anchorV);
getInfoWindow().setBoundMarker(this);
infoWindowShown = true;
showInfoWindow(getInfoWindow());
}

public void showInfoWindow(View view){

if (!isVisible() || mapView == null) {
return;
}

infoWindow = new InfoWindow(view, mapView);
infoWindow.open(this, getPosition(), (int) anchorU, (int) anchorV);
infoWindow.setBoundMarker(this);
showInfoWindow(infoWindow);
}

private void showInfoWindow(InfoWindow iw) {
iw.open(this, getPosition(), (int) anchorU, (int) anchorV + topOffsetPixels);
iw.setBoundMarker(this);
infoWindowShown = true;
}

Expand Down Expand Up @@ -222,4 +223,8 @@ public void setVisible(boolean visible) {
// void setIcon(BitmapDescriptor icon) {
//
// }

void setTopOffsetPixels(int topOffsetPixels) {
this.topOffsetPixels = topOffsetPixels;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public float getInfoWindowAnchorV() {
return ((Marker)annotation).getInfoWindowAnchorV();
}

public Marker getMarker() {
public Marker getMarker(int topOffsetPixels) {
((Marker)annotation).setTopOffsetPixels(topOffsetPixels);
return (Marker)annotation;
}

Expand All @@ -66,6 +67,10 @@ public String getTitle() {
return ((Marker)annotation).getTitle();
}

public String getSprite() {
return ((Marker)annotation).getSprite();
}

public MarkerOptions infoWindowAnchor(float u, float v) {
((Marker)annotation).setInfoWindowAnchor(u, v);
return this;
Expand All @@ -84,7 +89,7 @@ public boolean isVisible() {
}

public MarkerOptions position(LatLng position) {
((Marker)annotation).position = position;
((Marker)annotation).setPosition(position);
return this;
}

Expand All @@ -100,7 +105,7 @@ public MarkerOptions snippet(String snippet) {

public MarkerOptions sprite(@Nullable String sprite) {
if (!TextUtils.isEmpty(sprite)) {
((Marker)annotation).sprite = sprite;
((Marker)annotation).setSprite(sprite);
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ public Marker addMarker(@NonNull MarkerOptions markerOptions) {
throw new NullPointerException("markerOptions is null");
}

Marker marker = markerOptions.getMarker();
Marker marker = markerOptions.getMarker(getTopOffsetPixelsForAnnotationSymbol(markerOptions.getSprite()));

// Load the default marker sprite
if (marker.getSprite() == null) {
Expand Down Expand Up @@ -1634,7 +1634,7 @@ public List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) {

List<Marker> markers = new ArrayList<>(markerOptionsList.size());
for (MarkerOptions markerOptions : markerOptionsList) {
Marker marker = markerOptions.getMarker();
Marker marker = markerOptions.getMarker(getTopOffsetPixelsForAnnotationSymbol(markerOptions.getSprite()));

// Load the default marker sprite
if (marker.getSprite() == null) {
Expand All @@ -1646,7 +1646,7 @@ public List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) {
marker.setSprite("default_marker");
//marker.setSprite(DEFAULT_SPRITE);
}
markers.add(markerOptions.getMarker());
markers.add(marker);
}

long[] ids = mNativeMapView.addMarkers(markers);
Expand Down Expand Up @@ -1857,8 +1857,8 @@ private List<Marker> getMarkersInBounds(@NonNull BoundingBox bbox) {
* @param symbolName Annotation Symbol
* @return Top Offset in pixels
*/
public double getTopOffsetPixelsForAnnotationSymbol(@NonNull String symbolName) {
return mNativeMapView.getTopOffsetPixelsForAnnotationSymbol(symbolName);
private int getTopOffsetPixelsForAnnotationSymbol(String symbolName) {
return (int) (mNativeMapView.getTopOffsetPixelsForAnnotationSymbol(symbolName) * mScreenDensity);
}

/**
Expand All @@ -1875,14 +1875,6 @@ public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) dou
return mNativeMapView.getMetersPerPixelAtLatitude(latitude, getZoomLevel());
}

/**
* Get ScreenDensity of device
* @return Screen Density ratio
*/
public float getScreenDensity() {
return mScreenDensity;
}

private void selectMarker(Marker marker) {
if (marker == null) {
return;
Expand Down

0 comments on commit 67f0108

Please sign in to comment.