summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-02-10 15:15:29 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-02-10 15:15:29 -0800
commitbd59ab9a5285bf56ecc7a02e180a21f269ad68c0 (patch)
treeb1c6be1c99cd940ed08955aefcb8994ae03c1c52 /platform/osx
parent71611ec61247593aa6e9b568595114647363532d (diff)
downloadqtlocation-mapboxgl-bd59ab9a5285bf56ecc7a02e180a21f269ad68c0.tar.gz
[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.
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/src/MGLMapView.mm25
1 files changed, 15 insertions, 10 deletions
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 {