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

-[MGLMapView selectAnnotation:animated:] pans map to fit callout view - #11442

Merged
julianrex merged 6 commits into
release-bobafrom
jrex-3249-fit-annotation
Mar 21, 2018
Merged

julianrex merged 6 commits into
release-bobafrom
jrex-3249-fit-annotation

Conversation

@julianrex

Copy link
Copy Markdown
Contributor

See #3249.

If -[MGLMapView selectAnnotation:animated:] is called with animated: YES, an offscreen annotation (and its callout) are moved to be just on screen. On-screen annotations are not moved.

If animated is NO then the annotation is not moved on screen.

This requires #9790 (selecting offscreen annotations)

@julianrex julianrex added iOS Mapbox Maps SDK for iOS ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold annotations Annotations on iOS and macOS or markers on Android labels Mar 13, 2018
@julianrex
julianrex requested review from 1ec5 and friedbunny March 13, 2018 13:42
@julianrex

julianrex commented Mar 13, 2018 •

Copy link
Copy Markdown
Contributor Author

This is a WIP PR (branched off https://github.com/mapbox/mapbox-gl-native/tree/jrex-9790-offscreen-annotation) - looking for feedback, and discussion about the animated parameters. Equivalent macOS changes are yet to be done.

Some points for discussion:

  • This requires PR [ios] Removes check for on-screen in setSelectedAnnotations (#9790) #11257 (which addresses Selecting an off-screen annotation doesn't work #9790) to land.

  • The meaning of the animated parameter to -[MGLMapView selectAnnotation:animated:] has changed to mean "animate the annotation and the callout" on-screen. If it is not set, then the annotation is selected but not moved.

    However, the animated parameter is also used here, when marking as annotation view as selected:

     [annotationView setSelected:YES animated:animated];
    

    and

    [calloutView presentCalloutFromRect:calloutPositioningRect
                                 inView:self.glView
                      constrainedToRect:constrainedRect
                               animated:YES]; // WIP: Always animate.
    

    MKMapView always animates the callout view, so this would be in line, but annotation view's selection is a different matter. Perhaps we always annotate that too?

    My preferred option though is to add a third parameter for these view animations, and provide a suitable default for the existing selectAnnotation method.

  • This code currently does not distinguish between annotation types (testing with a simple polyline, showed that it picked one of the vertices, not the centroid, so some work would be needed there if we want to MGLSMCalloutView all annotations). Perhaps we restrict to just point-type annotations (e.g. views/images)?

  • I needed to modify MGLSMCalloutView and the MGLCalloutView protocol, to provide a callout dimension hint. Given that MGLSMCalloutView is based on third party code, perhaps some of these changes would be better handled by a category.

/cc @lilykaiser

@lilykaiser lilykaiser added this to the ios-v3.7.7 milestone Mar 13, 2018
@julianrex
julianrex requested a review from fabian-guerra March 13, 2018 15:36
@julianrex julianrex added the macOS Mapbox Maps SDK for macOS label Mar 14, 2018
@friedbunny friedbunny modified the milestones: ios-v3.7.7, ios-v4.0.0 Mar 16, 2018
@julianrex

Copy link
Copy Markdown
Contributor Author

Closed related PR #11257 (this PR is a superset)

@julianrex
julianrex force-pushed the jrex-3249-fit-annotation branch from 26f7bc4 to 8b6ffed Compare March 16, 2018 22:01
@julianrex julianrex removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Mar 19, 2018
Comment thread platform/ios/app/MBXViewController.m Outdated
}

- (id<MGLAnnotation>)randomOffscreenAnnotation {
NSArray *annotations = self.mapView.annotations;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method also needs to remove unselectable offscreen annotations (i.e., shapes) from consideration, otherwise it can fail silently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed - and I'll update the method to indicate that it just selects, er, selectable annotations.

Comment thread platform/ios/src/MGLCalloutView.h Outdated

These are used to determine positioning. Currently only the top and bottom properties of the return
value are used. For example, `{ .top = -50.0, .left = 0.0, .bottom = 0.0, .right = 0.0 }` indicates
a 50 point margin above the presentation origin rect, in which the callout is assumed to be displayed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let’s also indicate what the default insets are.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Comment thread platform/ios/src/MGLCalloutView.h Outdated

@param rect rect that the callout is presented from. This should be the same as the one passed in
`-presentCalloutFromRect:inView:constrainedToRect:animated:`
@return margins. Since this is a UIEdgeInsets, values should be negative.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Jazzy doesn’t understand the formatting of this line:

screen shot 2018-03-19 at 2 19 17 pm

Comment thread platform/ios/src/MGLMapView.h Outdated
method has no effect.

@param annotation The annotation object to select.
@param animated If `YES`, the callout view is animated into position.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be updated to say that the viewport moves to show the annotation.

@friedbunny friedbunny Mar 19, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also seems like a good place to talk about the animated parameter generally.

As implemented, the animated param controls whether or not the viewport is moved to show the annotation, not whether or not the viewport is moved with an animation. This seems potentially confusing.

I think the animated param should control how the viewport moves to show the annotation, not whether or not the viewport moves at all. For most cases, this would be what the developer expects: selecting an annotation indicates that it should probably be visible.

I’m less certain about how to or if we should handle the case where a newly selected annotation shouldn’t move the viewport.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is confusing 😢 As currently written it should match Mapkit, which is also confusing. I don't like the use if the word animated in this context.

I'm tempted to leave the functionality as is, but really try to make it clear through documentation.

Perhaps changing animated to something more appropriate in the new (not yet public) method, would help here, and pave the way for clarifying (or removing) the existing method.

@julianrex
julianrex force-pushed the jrex-3249-fit-annotation branch from 8b6ffed to c6b1052 Compare March 20, 2018 15:55
@julianrex
julianrex removed the request for review from 1ec5 March 20, 2018 18:27
Comment thread platform/ios/src/MGLMapView.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This note here is good. Let’s also make explicit whether or not setting selectedAnnotations will move the viewport (and point them in the direction of selectAnnotation:animated: if they need more control over that).

Comment thread platform/ios/CHANGELOG.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Being that the macOS SDK isn’t productized and most readers of this changelog may not know about it, let’s omit that bit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The last sentence?

@julianrex
julianrex force-pushed the jrex-3249-fit-annotation branch from c6b1052 to 4787d7e Compare March 20, 2018 20:07

@fabian-guerra fabian-guerra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, @julianrex.
I reviewed:

  • Class/methods documentation is clear.
  • Method names without prepositions and clear purpose.
  • Code readability.
  • Test cases test each scenario.
  • There is no code side effects.

Besides the nits and adding the blurb to macOS changelog this PR LGTM.

Comment thread platform/ios/app/MBXViewController.m Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: The return statement should be at the end of this line or between curly brackets.
if (annotations.count == 0) return nil;

Comment thread platform/ios/app/MBXViewController.m Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: The return statement should be at the end of this line or between curly brackets.

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 macOS Mapbox Maps SDK for macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants