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

Commit

Permalink
[android] - add minimal touch target to marker click detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 26, 2018
1 parent b8b0134 commit 5fcd6e3
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,12 @@ private static class MarkerHitResolver {

private final MarkerViewManager markerViewManager;
private final Projection projection;
private final int minimalTouchSize;

private View view;
private Bitmap bitmap;
private int bitmapWidth;
private int bitmapHeight;
private PointF markerLocation;

private Rect hitRectView = new Rect();
Expand All @@ -486,6 +489,7 @@ private static class MarkerHitResolver {
MarkerHitResolver(@NonNull MapboxMap mapboxMap) {
this.markerViewManager = mapboxMap.getMarkerViewManager();
this.projection = mapboxMap.getProjection();
this.minimalTouchSize = (int) (32 * Mapbox.getApplicationContext().getResources().getDisplayMetrics().density);
}

public long execute(MarkerHit markerHit) {
Expand Down Expand Up @@ -515,10 +519,21 @@ private void resolveForMarkerView(MarkerHit markerHit, MarkerView markerView) {
private void resolveForMarker(MarkerHit markerHit, Marker marker) {
markerLocation = projection.toScreenLocation(marker.getPosition());
bitmap = marker.getIcon().getBitmap();
hitRectMarker.set(0, 0, bitmap.getWidth(), bitmap.getHeight());

bitmapHeight = bitmap.getHeight();
if (bitmapHeight < minimalTouchSize) {
bitmapHeight = minimalTouchSize;
}

bitmapWidth = bitmap.getWidth();
if (bitmapWidth < minimalTouchSize) {
bitmapWidth = minimalTouchSize;
}

hitRectMarker.set(0, 0, bitmapWidth, bitmapHeight);
hitRectMarker.offsetTo(
markerLocation.x - bitmap.getWidth() / 2,
markerLocation.y - bitmap.getHeight() / 2
markerLocation.x - bitmapWidth / 2,
markerLocation.y - bitmapHeight / 2
);
hitTestMarker(markerHit, marker, hitRectMarker);
}
Expand Down

0 comments on commit 5fcd6e3

Please sign in to comment.