diff --git a/library/src/main/assets/google_map.html b/library/src/main/assets/google_map.html index c3c10f3..106fa91 100644 --- a/library/src/main/assets/google_map.html +++ b/library/src/main/assets/google_map.html @@ -60,6 +60,9 @@ function stopTrackingUserLocation() { GeoMarker.setMap(null); } +function setTouchEnabled(enabled) { + map.setOptions({draggable: enabled, zoomControl: enabled, scrollwheel: enabled, disableDoubleClickZoom: !enabled}); +} function clearMarkers() { for (var key in markers) { diff --git a/library/src/main/java/com/airbnb/android/airmapview/AirGoogleMapOptions.java b/library/src/main/java/com/airbnb/android/airmapview/AirGoogleMapOptions.java index dccde8c..48c49e5 100644 --- a/library/src/main/java/com/airbnb/android/airmapview/AirGoogleMapOptions.java +++ b/library/src/main/java/com/airbnb/android/airmapview/AirGoogleMapOptions.java @@ -76,6 +76,14 @@ public AirGoogleMapOptions mapToolbarEnabled(boolean enabled) { return this; } + public AirGoogleMapOptions setTouchEnabled(boolean enabled) { + tiltGesturesEnabled(enabled); + rotateGesturesEnabled(enabled); + zoomGesturesEnabled(enabled); + scrollGesturesEnabled(enabled); + return this; + } + public Boolean getZOrderOnTop() { return options.getZOrderOnTop(); } diff --git a/library/src/main/java/com/airbnb/android/airmapview/AirMapInterface.java b/library/src/main/java/com/airbnb/android/airmapview/AirMapInterface.java index 02f6a63..f1545da 100644 --- a/library/src/main/java/com/airbnb/android/airmapview/AirMapInterface.java +++ b/library/src/main/java/com/airbnb/android/airmapview/AirMapInterface.java @@ -248,4 +248,9 @@ public interface AirMapInterface { * Remove GeoJson layer from map, if any. */ void clearGeoJsonLayer(); + /** + * Set to whether to enable touch. If it's disabled then the user won't be allowed to drag, zoom or pan. + * @param enabled + */ + void setTouchEnabled(boolean enabled); } diff --git a/library/src/main/java/com/airbnb/android/airmapview/AirMapView.java b/library/src/main/java/com/airbnb/android/airmapview/AirMapView.java index faca82c..3e48c4c 100644 --- a/library/src/main/java/com/airbnb/android/airmapview/AirMapView.java +++ b/library/src/main/java/com/airbnb/android/airmapview/AirMapView.java @@ -349,6 +349,10 @@ public void setMyLocationEnabled(boolean trackUserLocation) { mapInterface.setMyLocationEnabled(trackUserLocation); } + public void setTouchEnabled(boolean enabled) { + mapInterface.setTouchEnabled(enabled); + } + @Override public void onCameraChanged(LatLng latLng, int zoom) { if (onCameraChangeListener != null) { onCameraChangeListener.onCameraChanged(latLng, zoom); diff --git a/library/src/main/java/com/airbnb/android/airmapview/NativeGoogleMapFragment.java b/library/src/main/java/com/airbnb/android/airmapview/NativeGoogleMapFragment.java index 4911c4c..b94ae1f 100644 --- a/library/src/main/java/com/airbnb/android/airmapview/NativeGoogleMapFragment.java +++ b/library/src/main/java/com/airbnb/android/airmapview/NativeGoogleMapFragment.java @@ -80,6 +80,7 @@ public void onMapReady(GoogleMap googleMap) { if (onMapLoadedListener != null) { onMapLoadedListener.onMapLoaded(); } + } } }); @@ -126,6 +127,10 @@ public void onInfoWindowClick(Marker marker) { }); } + @Override public void setTouchEnabled(boolean enabled) { + googleMap.getUiSettings().setAllGesturesEnabled(enabled); + } + @Override public void setInfoWindowCreator(GoogleMap.InfoWindowAdapter adapter, InfoWindowCreator creator) { googleMap.setInfoWindowAdapter(adapter); diff --git a/library/src/main/java/com/airbnb/android/airmapview/WebViewMapFragment.java b/library/src/main/java/com/airbnb/android/airmapview/WebViewMapFragment.java index ddede5f..4d9dd78 100644 --- a/library/src/main/java/com/airbnb/android/airmapview/WebViewMapFragment.java +++ b/library/src/main/java/com/airbnb/android/airmapview/WebViewMapFragment.java @@ -243,6 +243,11 @@ public void setOnMarkerClickListener(OnMapMarkerClickListener listener) { // no-op } + @Override + public void setTouchEnabled(boolean enabled) { + webView.loadUrl("javascript:setTouchEnabled(" + enabled + ");"); + } + @Override public void addPolyline(AirMapPolyline polyline) { try { JSONArray array = new JSONArray(); diff --git a/sample/src/main/java/com/airbnb/airmapview/sample/MainActivity.java b/sample/src/main/java/com/airbnb/airmapview/sample/MainActivity.java index 6404b11..eb3e895 100644 --- a/sample/src/main/java/com/airbnb/airmapview/sample/MainActivity.java +++ b/sample/src/main/java/com/airbnb/airmapview/sample/MainActivity.java @@ -32,7 +32,6 @@ import com.airbnb.android.airmapview.listeners.OnMapInitializedListener; import com.airbnb.android.airmapview.listeners.OnMapMarkerClickListener; import com.google.android.gms.maps.model.LatLng; -import com.google.android.gms.maps.model.Marker; import org.json.JSONException; diff --git a/sample/src/main/res/menu/menu_main.xml b/sample/src/main/res/menu/menu_main.xml index ac624d9..aeda59f 100644 --- a/sample/src/main/res/menu/menu_main.xml +++ b/sample/src/main/res/menu/menu_main.xml @@ -4,9 +4,9 @@ tools:context=".MainActivity"> + android:title="Use Native Map" + android:orderInCategory="100" + app:showAsAction="never"/>