Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose pitchEnabled property #407

Merged
merged 3 commits into from
Aug 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MapView } from 'react-native-mapbox-gl';
| `rotateEnabled` | `boolean` | Optional | Whether the map can rotate. | `true` |
| `scrollEnabled` | `boolean` | Optional | Whether the map can be scrolled. | `true` |
| `zoomEnabled` | `boolean` | Optional | Whether the map zoom level can be changed. | `true` |
| `pitchEnabled` | `boolean` | Optional | Whether the map pitch (tilt) level can be changed via a two-finger drag (iOS) or three-finger drag (Android). | `true` |
| `showsUserLocation` | `boolean` | Optional | Whether the user's location is shown on the map. Note: The map will not zoom to their location. | `false` |
| `userTrackingMode` | `enum` | Optional | Wether the map is zoomed to and follows the user's location. One of `Mapbox.userTrackingMode.none`, `Mapbox.userTrackingMode.follow`, `Mapbox.userTrackingMode.followWithCourse`, `Mapbox.userTrackingMode.followWithHeading` | `Mapbox.userTrackingMode.none` |
| `userLocationVerticalAlignment` | `enum` | Optional | Change the alignment of where the user location shows on the screen. One of `Mapbox.userLocationVerticalAlignment.top`, `Mapbox.userLocationVerticalAlignment.center`, `Mapbox.userLocationVerticalAlignment.bottom` | `Mapbox.userLocationVerticalAlignment.center` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public void setZoomEnabled(ReactNativeMapboxGLView view, boolean value) {
view.setZoomEnabled(value);
}

@ReactProp(name = "pitchEnabled")
public void setPitchEnabled(ReactNativeMapboxGLView view, boolean value) {
view.setPitchEnabled(value);
}

@ReactProp(name = "showsUserLocation")
public void setShowsUserLocation(ReactNativeMapboxGLView view, boolean value) {
view.setShowsUserLocation(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
private boolean _trackingModeUpdateScheduled = false;
private boolean _showsUserLocation;
private boolean _zoomEnabled = true;
private boolean _pitchEnabled = true;
private boolean _scrollEnabled = true;
private boolean _rotateEnabled = true;
private boolean _enableOnRegionWillChange = false;
Expand Down Expand Up @@ -148,6 +149,7 @@ public void onMapReady(MapboxMap mapboxMap) {
uiSettings.setZoomGesturesEnabled(_zoomEnabled);
uiSettings.setScrollGesturesEnabled(_scrollEnabled);
uiSettings.setRotateGesturesEnabled(_rotateEnabled);
uiSettings.setTiltGesturesEnabled(_pitchEnabled);

// If these settings changed between setupMapView() and onMapReady(), coerce them to their right values
// This doesn't happen in the current implementation of MapView, but let's be future proof
Expand Down Expand Up @@ -252,6 +254,14 @@ public void setZoomEnabled(boolean value) {
}
}

public void setPitchEnabled(boolean value) {
if (_pitchEnabled == value) { return; }
_pitchEnabled = value;
if (_map != null) {
_map.getUiSettings().setTiltGesturesEnabled(value);
}
}

public void setStyleURL(String styleURL) {
if (styleURL.equals(_mapOptions.getStyle())) { return; }
_mapOptions.styleUrl(styleURL);
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class MapView extends Component {
rotateEnabled: PropTypes.bool,
scrollEnabled: PropTypes.bool,
zoomEnabled: PropTypes.bool,
pitchEnabled: PropTypes.bool,
showsUserLocation: PropTypes.bool,
styleURL: PropTypes.string.isRequired,
userTrackingMode: PropTypes.number,
Expand Down Expand Up @@ -318,6 +319,7 @@ class MapView extends Component {
debugActive: false,
rotateEnabled: true,
scrollEnabled: true,
pitchEnabled: true,
showsUserLocation: false,
styleURL: mapStyles.streets,
userTrackingMode: userTrackingMode.none,
Expand Down
13 changes: 11 additions & 2 deletions ios/RCTMapboxGL/RCTMapboxGL.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @implementation RCTMapboxGL {
BOOL _finishedLoading;
BOOL _rotateEnabled;
BOOL _scrollEnabled;
BOOL _pitchEnabled;
BOOL _showsUserLocation;
NSURL *_styleURL;
int _userTrackingMode;
Expand Down Expand Up @@ -91,6 +92,7 @@ - (void)createMapIfNeeded
_map.rotateEnabled = _rotateEnabled;
_map.scrollEnabled = _scrollEnabled;
_map.zoomEnabled = _zoomEnabled;
_map.pitchEnabled = _pitchEnabled;
_map.showsUserLocation = _showsUserLocation;
_map.styleURL = _styleURL;
_map.zoomLevel = _initialZoomLevel;
Expand Down Expand Up @@ -282,14 +284,21 @@ - (void)setScrollEnabled:(BOOL)scrollEnabled
{
if (_scrollEnabled == scrollEnabled) { return; }
_scrollEnabled = scrollEnabled;
if (_map) { _map.scrollEnabled; }
if (_map) { _map.scrollEnabled = scrollEnabled; }
}

- (void)setZoomEnabled:(BOOL)zoomEnabled
{
if (_zoomEnabled == zoomEnabled) { return; }
_zoomEnabled = zoomEnabled;
if (_map) { _map.zoomEnabled; }
if (_map) { _map.zoomEnabled = zoomEnabled; }
}

- (void)setPitchEnabled:(BOOL)pitchEnabled
{
if (_pitchEnabled == pitchEnabled) { return; }
_pitchEnabled = pitchEnabled;
if (_map) { _map.pitchEnabled = pitchEnabled; }
}

- (void)setShowsUserLocation:(BOOL)showsUserLocation
Expand Down
1 change: 1 addition & 0 deletions ios/RCTMapboxGL/RCTMapboxGLManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ - (dispatch_queue_t)methodQueue
RCT_EXPORT_VIEW_PROPERTY(rotateEnabled, BOOL);
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL);
RCT_EXPORT_VIEW_PROPERTY(zoomEnabled, BOOL);
RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL);
RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL);
RCT_EXPORT_VIEW_PROPERTY(styleURL, NSURL);
RCT_EXPORT_VIEW_PROPERTY(userTrackingMode, int);
Expand Down