Skip to content

Commit a5d7187

Browse files
committed
Added the setTouchEnabled method so we can disable any touch inputs
1 parent 1ec03cc commit a5d7187

File tree

8 files changed

+33
-4
lines changed

8 files changed

+33
-4
lines changed

library/src/main/assets/google_map.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
function stopTrackingUserLocation() {
6161
GeoMarker.setMap(null);
6262
}
63+
function setTouchEnabled(enabled) {
64+
map.setOptions({draggable: enabled, zoomControl: enabled, scrollwheel: enabled, disableDoubleClickZoom: !enabled});
65+
}
6366

6467
function clearMarkers() {
6568
for (var key in markers) {

library/src/main/java/com/airbnb/android/airmapview/AirGoogleMapOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public AirGoogleMapOptions mapToolbarEnabled(boolean enabled) {
7676
return this;
7777
}
7878

79+
public AirGoogleMapOptions setTouchEnabled(boolean enabled) {
80+
tiltGesturesEnabled(enabled);
81+
rotateGesturesEnabled(enabled);
82+
zoomGesturesEnabled(enabled);
83+
scrollGesturesEnabled(enabled);
84+
return this;
85+
}
86+
7987
public Boolean getZOrderOnTop() {
8088
return options.getZOrderOnTop();
8189
}

library/src/main/java/com/airbnb/android/airmapview/AirMapInterface.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,9 @@ public interface AirMapInterface {
248248
* Remove GeoJson layer from map, if any.
249249
*/
250250
void clearGeoJsonLayer();
251+
/**
252+
* Set to whether to enable touch. If it's disabled then the user won't be allowed to drag, zoom or pan.
253+
* @param enabled
254+
*/
255+
void setTouchEnabled(boolean enabled);
251256
}

library/src/main/java/com/airbnb/android/airmapview/AirMapView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ public void setMyLocationEnabled(boolean trackUserLocation) {
349349
mapInterface.setMyLocationEnabled(trackUserLocation);
350350
}
351351

352+
public void setTouchEnabled(boolean enabled) {
353+
mapInterface.setTouchEnabled(enabled);
354+
}
355+
352356
@Override public void onCameraChanged(LatLng latLng, int zoom) {
353357
if (onCameraChangeListener != null) {
354358
onCameraChangeListener.onCameraChanged(latLng, zoom);

library/src/main/java/com/airbnb/android/airmapview/NativeGoogleMapFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void onMapReady(GoogleMap googleMap) {
8080
if (onMapLoadedListener != null) {
8181
onMapLoadedListener.onMapLoaded();
8282
}
83+
8384
}
8485
}
8586
});
@@ -126,6 +127,10 @@ public void onInfoWindowClick(Marker marker) {
126127
});
127128
}
128129

130+
@Override public void setTouchEnabled(boolean enabled) {
131+
googleMap.getUiSettings().setAllGesturesEnabled(enabled);
132+
}
133+
129134
@Override public void setInfoWindowCreator(GoogleMap.InfoWindowAdapter adapter,
130135
InfoWindowCreator creator) {
131136
googleMap.setInfoWindowAdapter(adapter);

library/src/main/java/com/airbnb/android/airmapview/WebViewMapFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ public void setOnMarkerClickListener(OnMapMarkerClickListener listener) {
243243
// no-op
244244
}
245245

246+
@Override
247+
public void setTouchEnabled(boolean enabled) {
248+
webView.loadUrl("javascript:setTouchEnabled(" + enabled + ");");
249+
}
250+
246251
@Override public <T> void addPolyline(AirMapPolyline<T> polyline) {
247252
try {
248253
JSONArray array = new JSONArray();

sample/src/main/java/com/airbnb/airmapview/sample/MainActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.airbnb.android.airmapview.listeners.OnMapInitializedListener;
3333
import com.airbnb.android.airmapview.listeners.OnMapMarkerClickListener;
3434
import com.google.android.gms.maps.model.LatLng;
35-
import com.google.android.gms.maps.model.Marker;
3635

3736
import org.json.JSONException;
3837

sample/src/main/res/menu/menu_main.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
tools:context=".MainActivity">
55

66
<item android:id="@+id/action_native_map"
7-
android:title="Use Native Map"
8-
android:orderInCategory="100"
9-
app:showAsAction="never"/>
7+
android:title="Use Native Map"
8+
android:orderInCategory="100"
9+
app:showAsAction="never"/>
1010

1111
<item android:id="@+id/action_google_web_map"
1212
android:title="Use Google Web Map"

0 commit comments

Comments
 (0)