From 71611ec61247593aa6e9b568595114647363532d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 10 Feb 2016 09:34:19 -0800 Subject: [ios, osx] Fixed crash reselecting annotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handle the case where the currently selected annotation isn’t one of the nearby annotations. This hasn’t come up before on OS X because clicking an annotation while another annotation is selected only dismisses the callout popover. Fixes #3284. --- platform/osx/src/MGLMapView.mm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'platform/osx/src/MGLMapView.mm') diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 3a92c1901d..065a3a00c2 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -1757,17 +1757,23 @@ public: // set of annotations as we do now. Cycle through them. if (_lastSelectedAnnotationTag == MGLAnnotationTagNotFound || _lastSelectedAnnotationTag == _annotationsNearbyLastClick.back()) { - // Either an annotation from this set hasn’t been selected - // before or the last annotation in the set was selected. Wrap - // around to the first annotation in the set. + // Either no annotation is selected or the last annotation in + // the set was selected. Wrap around to the first annotation in + // the set. hitAnnotationTag = _annotationsNearbyLastClick.front(); } else { - // Step to the next annotation in the set. auto result = std::find(_annotationsNearbyLastClick.begin(), _annotationsNearbyLastClick.end(), _lastSelectedAnnotationTag); - auto distance = std::distance(_annotationsNearbyLastClick.begin(), result); - hitAnnotationTag = _annotationsNearbyLastClick[distance + 1]; + if (result == _annotationsNearbyLastClick.end()) { + // An annotation from this set hasn’t been selected before. + // Select the first (nearest) one. + hitAnnotationTag = _annotationsNearbyLastClick.front(); + } else { + // Step to the next annotation in the set. + auto distance = std::distance(_annotationsNearbyLastClick.begin(), result); + hitAnnotationTag = _annotationsNearbyLastClick[distance + 1]; + } } } else { // Remember the nearby annotations for the next time this method is -- cgit v1.2.1 From bd59ab9a5285bf56ecc7a02e180a21f269ad68c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 10 Feb 2016 15:15:29 -0800 Subject: [core, ios, osx] Only constrain after adding to a window Introduced a setter/getter for constrain mode. On iOS and OS X, the zoom level inspectable causes the zoom level to be set independently from the longitude and latitude. Thus, the latitude inspectable had no effect because the latitude was constrained to 0 at z0. Temporarily removing the heightwise constraint allows the map to center on the intended location before zooming, which is the usual case for storyboards and XIBs. On iOS, the only guarantee we have timing-wise is that all the inspectables are applied after initialization but before the view is added to a window. So we reimpose the heightwise constraint as soon as the view is added to a window, that is, before the user has a chance to pan the map out of bounds. Fixes #3868. --- platform/osx/src/MGLMapView.mm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'platform/osx/src/MGLMapView.mm') diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 065a3a00c2..73cbb7fe80 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -249,7 +249,7 @@ public: NSString *cachePath = cacheURL ? cacheURL.path : @""; _mbglFileSource = new mbgl::DefaultFileSource(cachePath.UTF8String, [[[[NSBundle mainBundle] resourceURL] path] UTF8String]); - _mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous); + _mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None); // Install the OpenGL layer. Interface Builder’s synchronous drawing means // we can’t display a map, so don’t even bother to have a map layer. @@ -559,19 +559,24 @@ public: } - (void)viewDidMoveToWindow { - if (self.dormant && self.window) { + NSWindow *window = self.window; + if (self.dormant && window) { _mbglMap->resume(); self.dormant = NO; } - [self.window addObserver:self - forKeyPath:@"contentLayoutRect" - options:NSKeyValueObservingOptionInitial - context:NULL]; - [self.window addObserver:self - forKeyPath:@"titlebarAppearsTransparent" - options:NSKeyValueObservingOptionInitial - context:NULL]; + if (window && _mbglMap->getConstrainMode() == mbgl::ConstrainMode::None) { + _mbglMap->setConstrainMode(mbgl::ConstrainMode::HeightOnly); + } + + [window addObserver:self + forKeyPath:@"contentLayoutRect" + options:NSKeyValueObservingOptionInitial + context:NULL]; + [window addObserver:self + forKeyPath:@"titlebarAppearsTransparent" + options:NSKeyValueObservingOptionInitial + context:NULL]; } - (BOOL)wantsLayer { -- cgit v1.2.1 From 51d7d204dbed99ffec67002c6e27cce7f33d4077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Wed, 10 Feb 2016 22:02:40 -0800 Subject: [ios, osx] Exclude misses from nearby annotations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- platform/osx/src/MGLMapView.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'platform/osx/src/MGLMapView.mm') diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 73cbb7fe80..ca282facdb 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -1717,7 +1717,7 @@ public: // Filter out any annotation whose image is unselectable or for which // hit testing fails. - std::remove_if(nearbyAnnotations.begin(), nearbyAnnotations.end(), [&](const MGLAnnotationTag annotationTag) { + auto end = std::remove_if(nearbyAnnotations.begin(), nearbyAnnotations.end(), [&](const MGLAnnotationTag annotationTag) { NSAssert(_annotationContextsByAnnotationTag.count(annotationTag) != 0, @"Unknown annotation found nearby click"); id annotation = [self annotationWithTag:annotationTag]; if (!annotation) { @@ -1736,6 +1736,7 @@ public: return !!![annotationImage.image hitTestRect:hitRect withImageDestinationRect:annotationRect context:nil hints:nil flipped:NO]; }); + nearbyAnnotations.resize(std::distance(nearbyAnnotations.begin(), end)); } MGLAnnotationTag hitAnnotationTag = MGLAnnotationTagNotFound; -- cgit v1.2.1