Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@mayardb

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 RectF around the tapPoint. 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;
}

Activity

  1. tobrun commented on Mar 8, 2016

    @tobrun
    Member

    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!

  2. added
    Android
    on Mar 8, 2016
  3. removed
    Android
    on Mar 8, 2016
  4. added a commit that references this issue on Mar 8, 2016
  5. added a commit that references this issue on Mar 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions