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

[iOS] Clickable annotation image area to select annotation #3880

Closed
BFTE opened this issue Feb 10, 2016 · 4 comments
Closed

[iOS] Clickable annotation image area to select annotation #3880

BFTE opened this issue Feb 10, 2016 · 4 comments
Assignees
Labels
iOS Mapbox Maps SDK for iOS
Milestone

Comments

@BFTE
Copy link

BFTE commented Feb 10, 2016

Hi, at some point in v.3.1.0 there was a change:
"Tapping now selects annotations more reliably. Tapping near the top of a large annotation image now selects that annotation. An annotation image’s alignment insets influence how far away the user can tap and still select the annotation."

According to above I try to change annotation image alignment rect like this:

MGLAnnotationImage *annotationImage;
UIImage *image = [UIImage imageNamed:[self annotationImageName]];
image = [image imageWithAlignmentRectInsets:UIEdgeInsetsMake(0, 0, 60.0, 0)];
annotationImage = [MGLAnnotationImage annotationImageWithImage:image reuseIdentifier:self.identifier];

but I did not notice any changes in clickable area which is too big in my case, I have to reduce clickable area to half of the annotation image.
I can add that dequeue method:

[mapView dequeueReusableAnnotationImageWithIdentifier:identifier]

returns me annotations image with correct alignment rect: (0, 0, 60.0, 0)

Maybe I'm doing something wrong or misunderstand something... Can you show me an example how to set annotation image's alignment rect or what I'm doing wrong? Thanks!

("annotation image" I mean property "image" in MGLAnnotationImage)

@1ec5
Copy link
Contributor

1ec5 commented Feb 10, 2016

UIEdgeInsetsMake(0, 0, 60.0, 0)

This insets the bottom edge of the image by 60 pixels. If your image is 120 pixels tall, that would indeed exclude the bottom half of the image from the alignment rect.

However, what you’re observing sounds like the five-pixel slop area we place on all sides of the alignment rect, since taps can be quite imprecise. (In the OS X SDK, by contrast, we do exact hit-testing on the visible portion of the image, because mouse clicks are far more precise.) We’re definitely open to ideas about how to respect the alignment rect more literally while allowing for imprecise taps.

@1ec5 1ec5 added the iOS Mapbox Maps SDK for iOS label Feb 10, 2016
@BFTE
Copy link
Author

BFTE commented Feb 10, 2016

Thanks for quick response. What I am trying to achieve is to exclude bottom half of annotation image from being clickable. I have a lot annotations with image like the one below:
default_marker 2x
to be more accurate with position of our markers. As far as I know there is no API to set or change anchor point of annotation image yet.

Problem occurs with selectable annotations, when user taps below an image and transparent part of the image takes part in detection process if user click (or not) annotation.
And I thought that I can exclude transparent part by setting image alignment rect, but without success.

1ec5 added a commit that referenced this issue Feb 11, 2016
After filtering out elements of a vector using std::remove_if(), it’s apparently necessary to resize the vector. Otherwise, removing only has the effect of shifting the non-matching items to the end of the vector. This change reduces the annotation tap target back to almost what it was before #3261, except that these days the target is centered around the annotation image rather than the center point. There remains a much smaller slop area around the annotation, but nothing close to the effective padding before this change.

Fixes #3880.
@1ec5 1ec5 self-assigned this Feb 11, 2016
@1ec5
Copy link
Contributor

1ec5 commented Feb 11, 2016

As far as I know there is no API to set or change anchor point of annotation image yet.

That’s correct, although if #3885 turns out to be the right solution for the Android SDK, we could easily port it over to the iOS SDK.

And I thought that I can exclude transparent part by setting image alignment rect, but without success.

You’re right in expecting that to work. There is a bug in how we’re hit-testing annotations that you’re probably running into: #3898.

@1ec5 1ec5 added this to the ios-v3.1.1 milestone Feb 11, 2016
@1ec5
Copy link
Contributor

1ec5 commented Feb 11, 2016

Fixed in #3898, which will be in 3.1.1, to be released shortly.

@1ec5 1ec5 closed this as completed Feb 11, 2016
@1ec5 1ec5 removed the in progress label Feb 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

2 participants