summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEimantas Vaiciunas <eimantas@walkingsmarts.com>2017-02-13 10:41:18 +0200
committerMinh Nguyễn <mxn@1ec5.org>2017-02-15 22:51:30 -0800
commitd8bdc7307d77b73651ec1a81b33c4fb4ace60e7c (patch)
tree65f568a2ebc468353f305bb631940a76b68d337e
parent685f237d0286ef13aac52cbbab93fed82a0b31b8 (diff)
downloadqtlocation-mapboxgl-d8bdc7307d77b73651ec1a81b33c4fb4ace60e7c.tar.gz
[macos] Make + and - keys zoom the map
Override `insertText:` - send all `keyDown:` events to `interpretKeyEvents:` method; - in `insertText:` method check for the text to be sent and adjust zoom level if needed;
-rw-r--r--platform/macos/CHANGELOG.md1
-rw-r--r--platform/macos/src/MGLMapView.mm32
2 files changed, 27 insertions, 6 deletions
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index b53b720bf9..647d68f6ab 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -41,6 +41,7 @@
* Added a method to MGLMapViewDelegate, `-mapView:shouldChangeFromCamera:toCamera:`, that you can implement to restrict which parts the user can navigate to using gestures. ([#5584](https://github.com/mapbox/mapbox-gl-native/pull/5584))
* Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888))
* Zooming by double-tap, two-finger tap, zoom buttons, shortcut keys, or demo app menu items or shortcut keys now zooms to the nearest integer zoom level. ([#8027](https://github.com/mapbox/mapbox-gl-native/pull/8027))
+* Make "+" and "-" keys zoom in and out ([8033](https://github.com/mapbox/mapbox-gl-native/pull/8033))
## 0.3.1
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 654ca84fd0..98f4a0569d 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -1633,13 +1633,16 @@ public:
#pragma mark Keyboard events
- (void)keyDown:(NSEvent *)event {
- if (event.modifierFlags & NSNumericPadKeyMask) {
- // This is the recommended way to handle arrow key presses, causing
- // methods like -moveUp: and -moveToBeginningOfParagraph: to be called
- // for various standard keybindings.
- [self interpretKeyEvents:@[event]];
+ [self interpretKeyEvents:@[event]];
+}
+
+- (void)insertText:(NSString *)text {
+ BOOL textIsZoomCharacter = [@[@"-", @"=", @"+"] containsObject:text];
+
+ if (textIsZoomCharacter) {
+ [self adjustZoomLevelForKey:text];
} else {
- [super keyDown:event];
+ [super insertText:text];
}
}
@@ -1695,6 +1698,23 @@ public:
_compass.hidden = !rotateEnabled;
}
+- (void)adjustZoomLevelForKey:(NSString *)key {
+ double newZoomLevel = self.zoomLevel;
+ unichar keyUnichar = [key characterAtIndex:0];
+ switch(keyUnichar) {
+ case '-': {
+ newZoomLevel -= 1;
+ break;
+ }
+ case '=':
+ case '+': {
+ newZoomLevel += 1;
+ }
+ }
+
+ [self setZoomLevel:newZoomLevel animated:YES];
+}
+
#pragma mark Ornaments
/// Updates the zoom controls’ enabled state based on the current zoom level.