Skip to content

Commit 101c315

Browse files
fix(android): make config options optional (#97)
1 parent e26260d commit 101c315

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,23 @@ class GoogleMapConfig(fromJSONObject: JSONObject) {
8282
x = fromJSONObject.getInt("x")
8383
y = fromJSONObject.getInt("y")
8484

85-
val _zoom = fromJSONObject.getInt("zoom")
86-
var _minZoom = fromJSONObject.getInt("minZoom")
87-
var _maxZoom = fromJSONObject.getInt("maxZoom")
88-
if (_minZoom != null && maxZoom != null && _minZoom > _maxZoom) {
89-
_minZoom = _maxZoom.also { _maxZoom = _minZoom }
90-
}
91-
minZoom = _minZoom
92-
maxZoom = _maxZoom
93-
if (_maxZoom != null && _zoom > _maxZoom) {
94-
zoom = _maxZoom
95-
} else if (_minZoom != null && _zoom < _minZoom) {
96-
zoom = _minZoom
97-
} else {
98-
zoom = _zoom
85+
val tempZoom = fromJSONObject.getInt("zoom")
86+
var tempMinZoom = fromJSONObject.optInt("minZoom").takeIf { fromJSONObject.has("minZoom") }
87+
var tempMaxZoom = fromJSONObject.optInt("maxZoom").takeIf { fromJSONObject.has("maxZoom") }
88+
89+
if (tempMinZoom != null && tempMaxZoom != null && tempMinZoom > tempMaxZoom) {
90+
tempMinZoom = tempMaxZoom.also { tempMaxZoom = tempMinZoom }
9991
}
10092

101-
mapTypeId = fromJSONObject.getString("mapTypeId")
93+
minZoom = tempMinZoom
94+
maxZoom = tempMaxZoom
95+
96+
zoom = tempZoom.coerceIn(
97+
tempMinZoom ?: Int.MIN_VALUE,
98+
tempMaxZoom ?: Int.MAX_VALUE
99+
)
100+
101+
mapTypeId = fromJSONObject.optString("mapTypeId").takeIf { fromJSONObject.has("mapTypeId") }
102102

103103
val lat = centerJSONObject.getDouble("lat")
104104
val lng = centerJSONObject.getDouble("lng")
@@ -110,11 +110,9 @@ class GoogleMapConfig(fromJSONObject: JSONObject) {
110110

111111
mapId = fromJSONObject.getString("androidMapId")
112112

113-
if (fromJSONObject.has("restriction")) {
114-
restriction = GoogleMapConfigRestriction(fromJSONObject.getJSONObject("restriction"))
115-
}
113+
restriction = fromJSONObject.optJSONObject("restriction")?.let { GoogleMapConfigRestriction(it) }
116114

117-
heading = fromJSONObject.getDouble("heading")
115+
heading = fromJSONObject.optDouble("heading").takeIf { fromJSONObject.has("heading") }
118116

119117
googleMapOptions = GoogleMapOptions().camera(cameraPosition).liteMode(liteMode)
120118
if (mapId != null) {

0 commit comments

Comments
 (0)