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.

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

Closed

Description

@BFTE

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)

Activity

  1. 1ec5 commented on Feb 10, 2016

    @1ec5
    Contributor

    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.

  2. added
    iOS
    on Feb 10, 2016
  3. BFTE commented on Feb 10, 2016

    @BFTE
    Author

    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.

  4. added a commit that references this issue on Feb 11, 2016
    51d7d20
  5. self-assigned this
    on Feb 11, 2016
  6. 1ec5 commented on Feb 11, 2016

    @1ec5
    Contributor

    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.

  7. added this to the ios-v3.1.1 milestone on Feb 11, 2016
  8. 1ec5 commented on Feb 11, 2016

    @1ec5
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

iOS

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions