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

Update annotation view touch handling (with offsets) #12234

Merged
merged 5 commits into from
Jul 9, 2018

Conversation

julianrex
Copy link
Contributor

@julianrex julianrex commented Jun 27, 2018

Addresses #11829

This PR adds the offset to the annotation rect checking in -[MGLMapView annotationTagAtPoint:persistingResults:] (and associated changes).

  • Test with other types of annotations (this has been tested with annotation views and images)
  • Create an annotation selection test (with offset)

@julianrex julianrex added iOS Mapbox Maps SDK for iOS annotations Annotations on iOS and macOS or markers on Android in progress labels Jun 27, 2018
@julianrex julianrex self-assigned this Jun 27, 2018
@@ -1658,23 +1658,6 @@ - (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap
}
}

// Handle the case of an offset annotation view by converting the tap point to be the geo location
// of the annotation itself that the view represents
for (MGLAnnotationView *view in self.annotationContainerView.annotationViews)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop has been removed and the offset logic moved deeper into the annotation query.

  • tapPoint is mutated within this loop, potentially leading to drifting away from the original tap
  • With an offset, the tap point can end up outside the annotation view (but still within the bounds of the source annotation) - this leads to annotations being selected when it looks like they shouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to understand what the point of this loop was, in case I'm missing something obvious 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That loop was added to fix a similar bug #5931

_largestAnnotationViewSize = CGSizeMake(MAX(_largestAnnotationViewSize.width, CGRectGetWidth(bounds)),
MAX(_largestAnnotationViewSize.height, CGRectGetHeight(bounds)));
// Take any offset into consideration
CGFloat adjustedAnnotationWidth = CGRectGetWidth(bounds) + fabs(annotationView.centerOffset.dx);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annotation's apparent size now includes any offset, so that the initial annotation query returns the correct results. This means that _unionedAnnotationRepresentationSize can now be larger. This could be a performance issue with lots of annotations if the offsets are large.


// We need to take any offset into consideration. Note that a large offset will result in a
// large value for `_unionedAnnotationRepresentationSize` - which will affect performance for lots
// of annotations. Keep the offset as small as possible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this note be worth adding to the API docs for centerOffset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Since the performance hasn't been measured and the extent of this (expected) effect is unknown perhaps we don't right now? In that case, maybe the above comment needs to be amended too?

@@ -0,0 +1,68 @@
//
// MGLAnnotationViewIntegrationTests.m
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops this header snuck into the test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is WIP - but good catch :) I need to turn that off

@julianrex julianrex force-pushed the jrex-11829-touch-handling-with-offset branch from 36ad3fa to ad8ca4c Compare June 29, 2018 21:39
@julianrex
Copy link
Contributor Author

Rebased.

@julianrex julianrex requested a review from friedbunny July 3, 2018 17:14
@friedbunny friedbunny added this to the ios-v4.2.0 milestone Jul 6, 2018
@friedbunny
Copy link
Contributor

@julianrex Thanks — this’ll also need a changelog entry.

@friedbunny friedbunny added the needs changelog Indicates PR needs a changelog entry prior to merging. label Jul 6, 2018
@julianrex julianrex force-pushed the jrex-11829-touch-handling-with-offset branch from 04e4db8 to 4f6138a Compare July 8, 2018 18:30
@julianrex
Copy link
Contributor Author

Rebased.

@julianrex julianrex removed the needs changelog Indicates PR needs a changelog entry prior to merging. label Jul 8, 2018
@julianrex julianrex merged commit 3710ef8 into master Jul 9, 2018
@julianrex julianrex deleted the jrex-11829-touch-handling-with-offset branch July 9, 2018 14:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants