From 24b4b1b5144f064e7b00a0fcba1b1897182af5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 12 Apr 2016 09:27:28 -0700 Subject: [PATCH] [osx] Scroll to zoom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a hidden preference to MGLMapView that enables “unnatural zooming”, in which the scroll wheel zooms in and out, as in a Web browser, instead of scrolling the map, as is the platform convention on iOS and OS X. Added a checkbox to osxapp’ preferences window that toggles this hidden preference via a binding. You can either use this checkbox or set the MGLScrollWheelZoomsMapView user default to YES. Fixes #4670. --- platform/osx/app/MainMenu.xib | 25 +++++++++++++++++++------ platform/osx/src/MGLMapView.mm | 14 +++++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/platform/osx/app/MainMenu.xib b/platform/osx/app/MainMenu.xib index 646c4ae40..4f3633343 100644 --- a/platform/osx/app/MainMenu.xib +++ b/platform/osx/app/MainMenu.xib @@ -565,14 +565,14 @@ - + - + - + @@ -583,7 +583,7 @@ - + @@ -594,7 +594,7 @@ + @@ -613,15 +623,18 @@ + + + - + diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index f8bbb61d0..6f20e957a 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -56,6 +56,9 @@ const CGFloat MGLKeyPanningIncrement = 150; /// Degrees that a single press of the rotation keyboard shortcut rotates the map by. const CLLocationDegrees MGLKeyRotationIncrement = 25; +/// Key for the user default that, when true, causes the map view to zoom in and out on scroll wheel events. +NSString * const MGLScrollWheelZoomsMapViewDefaultKey = @"MGLScrollWheelZoomsMapView"; + /// Reuse identifier and file name of the default point annotation image. static NSString * const MGLDefaultStyleMarkerSymbolName = @"default_marker"; @@ -193,6 +196,14 @@ public: #pragma mark Lifecycle ++ (void)initialize { + if (self == [MGLMapView class]) { + [[NSUserDefaults standardUserDefaults] registerDefaults:@{ + MGLScrollWheelZoomsMapViewDefaultKey: @NO, + }]; + } +} + - (instancetype)initWithFrame:(NSRect)frameRect { if (self = [super initWithFrame:frameRect]) { [self commonInit]; @@ -1332,7 +1343,8 @@ public: - (void)scrollWheel:(NSEvent *)event { // https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/#10_7Dragging - if (event.phase == NSEventPhaseNone && event.momentumPhase == NSEventPhaseNone && !event.hasPreciseScrollingDeltas) { + BOOL isScrollWheel = event.phase == NSEventPhaseNone && event.momentumPhase == NSEventPhaseNone && !event.hasPreciseScrollingDeltas; + if (isScrollWheel || [[NSUserDefaults standardUserDefaults] boolForKey:MGLScrollWheelZoomsMapViewDefaultKey]) { // A traditional, vertical scroll wheel zooms instead of panning. if (self.zoomEnabled && std::abs(event.scrollingDeltaX) < std::abs(event.scrollingDeltaY)) { _mbglMap->cancelTransitions();