Reputation: 165
I have a MapBox map placed on a scrollview, and the scrollview means I can not pan/zoom around the map.
I'm not sure if this is a bug with MapBox or whether I'm missing something, potentially obvious?
I found this issue raised in Github (https://github.com/mapbox/react-native-mapbox-gl/issues/208), but as I say, I'm not sure this actually a bug and is actually just a problem with my implementation.
Upvotes: 3
Views: 1725
Reputation: 3168
This snippet of code might resolve the issue for you:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
// Setup the MapView
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
// ....
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
sv.requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
sv.requestDisallowInterceptTouchEvent(false);
break;
}
return mapView.onTouchEvent(event);
}
});
Lastly, heres my XML
ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cameron.mapboxplayground.MainActivity"
android:id="@+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Set the starting camera position and map style using xml-->
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="500dp"
mapbox:access_token="@string/accessToken"
mapbox:style_url="@string/style_light"
mapbox:center_latitude="40.7359"
mapbox:center_longitude="-74.0151"
mapbox:zoom="10"/>
</LinearLayout>
</ScrollView>
Hope this helps you out!
Upvotes: 8