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

Marker clickable area #6761

Closed
mpuchala opened this issue Oct 19, 2016 · 12 comments
Closed

Marker clickable area #6761

mpuchala opened this issue Oct 19, 2016 · 12 comments
Labels
Android Mapbox Maps SDK for Android

Comments

@mpuchala
Copy link

mpuchala commented Oct 19, 2016

Platform: Android
Mapbox SDK version: 4.2.0 SNAPSHOT

Steps to trigger behavior

  1. Create Map
  2. Click Markers

Actual behavior

I'm using resources without transparency. Clickable region seems to be much more bigger than image and this is important issue when we have a lot of markers. Also, on 4.1.0 it works fine and area contains only marker.

Example:
https://www.dropbox.com/s/6zin9c8guvrcy6y/clickable_area.mp4?dl=0

Regards!

@mpuchala mpuchala changed the title [Android] Markers problem [Android] Marker problems - too big clickable area Oct 19, 2016
@mpuchala mpuchala changed the title [Android] Marker problems - too big clickable area [Android] Too big marker's clickable area Oct 19, 2016
@tobrun tobrun added the Android Mapbox Maps SDK for Android label Oct 20, 2016
@tobrun
Copy link
Member

tobrun commented Oct 25, 2016

@mpuchala thank you for reaching out. To give you a some background on marker click handling. Currently we take Android motionEvent and calculate a rectangle from it. The rectangle size is based on the average icon width/height and some additional tolerance:

float left = (tapPoint.x - averageIconWidth / 2 - toleranceSides);
float top = (tapPoint.y - averageIconHeight / 2 - toleranceTopBottom);
float right = (tapPoint.x + averageIconWidth / 2 + toleranceSides);
float bottom = (tapPoint.y + averageIconHeight / 2 + toleranceTopBottom);

RectF tapRect = new RectF(left / screenDensity, top / screenDensity, right / screenDensity, bottom / screenDensity);

This rectangle is passed into cpp code and we will be returned all the markers in that rectangle. Using averages here is a very basic way of solving this issue and we could definitely use a more complex approach here.

this is important issue when we have a lot of markers

If possible I would advice you to look into using markers of a similar size. This will improve the clickable area issue but imo also improve consistency in your map design.

@tobrun tobrun changed the title [Android] Too big marker's clickable area Marker clickable area Oct 25, 2016
@tobrun tobrun added this to the android-future milestone Oct 25, 2016
@mpuchala
Copy link
Author

@tobrun thanks for clarification.

Despite the fact I have usually same size icons sometimes it works unstable. When I was analyzing your code I found potential bug. Please take a look on MapView class. In loadIconForMarker(Marker marker) method we have:

        if (icon == null) {
            icon = IconFactory.getInstance(getContext()).defaultMarker();
            Bitmap bitmap = icon.getBitmap();
            averageIconHeight = averageIconHeight + (bitmap.getHeight() / 2 - averageIconHeight) / iconSize;
            averageIconWidth = averageIconHeight + (bitmap.getWidth() - averageIconHeight) / iconSize;
            marker.setIcon(icon);
        } else {
            Bitmap bitmap = icon.getBitmap();
            averageIconHeight = averageIconHeight + (bitmap.getHeight() - averageIconHeight) / iconSize;
            averageIconWidth = averageIconHeight + (bitmap.getWidth() - averageIconHeight) / iconSize;
        }

averageIconWidth is mixed with averageIconHeight when you're setting it. I don't think it's kind of workaround more like oversight, isn't it?

@tobrun
Copy link
Member

tobrun commented Oct 25, 2016

I noticed the same thing today, I have a fix for that in #5639

@tobrun
Copy link
Member

tobrun commented Dec 7, 2016

Adding here that improving this system should also take in account anchoring as noted in #7307.

@pnull
Copy link

pnull commented Jan 31, 2017

Any chance that this will be fixed soon? We have serious problems with this offset bug..

@MikeKasperlik
Copy link

Yep we see this too in our App

@zugaldia zugaldia removed this from the android-v5.0.0 milestone Mar 6, 2017
@galacticappster04
Copy link

when tobrun explained how the code works I was really scratching my head. I just don't really know how everything works under the hood. I was thinking that the pin has width and height and position forming a rect, i tapped the map, I clicked on a pin (touch/mouse position x and y) and then check if that (x,y) is within the bounds of that pin.

I just realized, this works fine on a very very small environment just like on video games. But we are talking about a very very large map and we can't just check all pins on the map if the touch location is within a rect. So at least how it originally works made sense to me.

@mariusboepple
Copy link

This thing is a severe bug... Anyone who is using clickable markers, which are anchored at the bottom (that's a really common case) must accept the bad user experience (#7307).

This should be of higher priority...

@tobrun
Copy link
Member

tobrun commented Mar 17, 2017

Small update on this issue:

@galacticappster04
Copy link

Has this been implemented on the v5.0.2? Please confirm. If so close this issue.

@tobrun
Copy link
Member

tobrun commented Apr 7, 2017

Apologies @neonwarge04, I still had to update this issue to the latest state. With 5.0.2 we reverted the changes made for onTouch in the migration of 4.x -> 5.x (#8585). This issue is still applicable for both Markers as MarkerViews.

@tobrun
Copy link
Member

tobrun commented Apr 19, 2017

Tracking latest state in #8159

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

No branches or pull requests

7 participants