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

Add minimal touch target to marker click detection #12482

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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