This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
[android] single taping on a Marker does not work #4243
Copy link
Copy link
Closed
Description
Hello Mapbox team!
By taping on the top of a Marker, I do not have any IndoWindow prompting.
Reading the code (from MapView and copied below), I notice some things:
- We are using a hard coded tolerance
RectFaround thetapPoint. Where do these dimension come from ? (30 * 25 dip, with only 5 dip below the tapPoint) - We are looking for Markers in this
RectF. This means that we are looking for Marker position that are currently in it. However if the Marker is high, when taping on the top of the marker we miss the tap using this algorithm.
For Example : try to tap on the top of the default_marker.
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// Open / Close InfoWindow
PointF tapPoint = new PointF(e.getX(), e.getY());
List<Marker> selectedMarkers = mMapboxMap.getSelectedMarkers();
final float toleranceSides = 15 * mScreenDensity;
final float toleranceTop = 20 * mScreenDensity;
final float toleranceBottom = 5 * mScreenDensity;
RectF tapRect = new RectF(tapPoint.x - toleranceSides, tapPoint.y + toleranceTop,
tapPoint.x + toleranceSides, tapPoint.y - toleranceBottom);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(fromScreenLocation(new PointF(tapRect.left, tapRect.bottom)));
builder.include(fromScreenLocation(new PointF(tapRect.left, tapRect.top)));
builder.include(fromScreenLocation(new PointF(tapRect.right, tapRect.top)));
builder.include(fromScreenLocation(new PointF(tapRect.right, tapRect.bottom)));
List<Marker> nearbyMarkers = getMarkersInBounds(builder.build());
long newSelectedMarkerId = -1;
if (nearbyMarkers != null && nearbyMarkers.size() > 0) {
Collections.sort(nearbyMarkers);
for (Marker nearbyMarker : nearbyMarkers) {
boolean found = false;
for (Marker selectedMarker : selectedMarkers) {
if (selectedMarker.equals(nearbyMarker)) {
found = true;
}
}
if (!found) {
newSelectedMarkerId = nearbyMarker.getId();
break;
}
}
}
if (newSelectedMarkerId >= 0) {
List<Annotation> annotations = mMapboxMap.getAnnotations();
int count = annotations.size();
for (int i = 0; i < count; i++) {
Annotation annotation = annotations.get(i);
if (annotation instanceof Marker) {
if (annotation.getId() == newSelectedMarkerId) {
if (selectedMarkers.isEmpty() || !selectedMarkers.contains(annotation)) {
mMapboxMap.selectMarker((Marker) annotation);
}
break;
}
}
}
} else {
// deselect any selected marker
mMapboxMap.deselectMarkers();
// notify app of map click
MapboxMap.OnMapClickListener listener = mMapboxMap.getOnMapClickListener();
if (listener != null) {
LatLng point = fromScreenLocation(tapPoint);
listener.onMapClick(point);
}
}
trackGestureEvent(MapboxEvent.GESTURE_SINGLETAP, e.getX(), e.getY());
return true;
}
Metadata
Metadata
Assignees
Labels
No labels
Activity
tobrun commentedon Mar 8, 2016
This is a known issue, I have been trying to tackle this in #3643. This also mentions your issue in #4218. I consider this been a duplicate of the ticket mentioned. Going to close this one. Nevertheless thank you for reaching out and for reporting this issue!
[android] mapbox#4243 mapbox#3643 - refactoring the onSingleTapConfir…
[android] mapbox#4243 mapbox#3643 - refactoring the onSingleTapConfir…