[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;
This commit is contained in:
Eimantas Vaiciunas
2017-02-13 10:41:18 +02:00
committed by Minh Nguyễn
parent 685f237d02
commit d8bdc7307d
2 changed files with 27 additions and 6 deletions

View File

@@ -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

View File

@@ -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.