Skip to content

Commit dd847dd

Browse files
committed
Android: handle updateContentInsets method call
This is the android implementation of PR #215. On Android the content insets are modeled as camera padding. Includes a few whitespace fixes.
1 parent f61f625 commit dd847dd

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

android/src/main/java/com/mapbox/mapboxgl/Convert.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ static CameraUpdate toCameraUpdate(Object o, MapboxMap mapboxMap, float density)
119119
}
120120
}
121121

122+
static CameraUpdate toContentPaddingCameraUpdate(Object o) {
123+
final Map<?, ?> data = toMap(o);
124+
return CameraUpdateFactory.paddingTo(
125+
toDouble(data.get("left")),
126+
toDouble(data.get("top")),
127+
toDouble(data.get("right")),
128+
toDouble(data.get("bottom"))
129+
);
130+
}
131+
122132
private static double toDouble(Object o) {
123133
return ((Number) o).doubleValue();
124134
}
@@ -546,4 +556,4 @@ static void interpretFillOptions(Object o, FillOptionsSink sink) {
546556
sink.setDraggable(toBoolean(draggable));
547557
}
548558
}
549-
}
559+
}

android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public void onStyleLoaded(@NonNull Style style) {
321321
throw new IllegalArgumentException("Unknown annotation type: " + annotationType + ", must be either 'fill', 'line', 'circle' or 'symbol'");
322322
}
323323
}
324-
324+
325325
if (myLocationEnabled) {
326326
enableLocationComponent(style);
327327
}
@@ -609,6 +609,15 @@ public void onError(@NonNull String message) {
609609
});
610610
break;
611611
}
612+
case "map#updateContentInsets": {
613+
CameraUpdate cameraUpdate = Convert.toContentPaddingCameraUpdate(call.argument("bounds"));
614+
if ((Boolean) call.argument("animated")) {
615+
mapboxMap.animateCamera(cameraUpdate);
616+
} else {
617+
mapboxMap.moveCamera(cameraUpdate);
618+
}
619+
break;
620+
}
612621
case "symbols#addAll": {
613622
List<String> newSymbolIds = new ArrayList<String>();
614623
final List<Object> options = call.argument("options");
@@ -706,7 +715,7 @@ public void onError(@NonNull String message) {
706715
result.success(null);
707716
break;
708717
}
709-
case "line#addAll": {
718+
case "line#addAll": {
710719
List<String> newIds = new ArrayList<String>();
711720
final List<Object> options = call.argument("options");
712721
List<LineOptions> optionList = new ArrayList<LineOptions>();
@@ -778,7 +787,7 @@ public void onError(@NonNull String message) {
778787
result.success(circleId);
779788
break;
780789
}
781-
case "circle#addAll": {
790+
case "circle#addAll": {
782791
List<String> newIds = new ArrayList<String>();
783792
final List<Object> options = call.argument("options");
784793
List<CircleOptions> optionList = new ArrayList<CircleOptions>();
@@ -854,7 +863,7 @@ public void onError(@NonNull String message) {
854863
break;
855864
}
856865

857-
case "fill#addAll": {
866+
case "fill#addAll": {
858867
List<String> newIds = new ArrayList<String>();
859868
final List<Object> options = call.argument("options");
860869
List<FillOptions> optionList = new ArrayList<FillOptions>();

0 commit comments

Comments
 (0)