diff --git a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt index bc29ae0..55e674c 100644 --- a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt +++ b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt @@ -13,6 +13,8 @@ class GoogleMapConfig(fromJSONObject: JSONObject) { var center: LatLng = LatLng(0.0, 0.0) var googleMapOptions: GoogleMapOptions? = null var zoom: Int = 0 + var minZoom: Float? = null + var maxZoom: Float? = null var liteMode: Boolean = false var devicePixelRatio: Float = 1.00f var styles: String? = null @@ -77,6 +79,13 @@ class GoogleMapConfig(fromJSONObject: JSONObject) { y = fromJSONObject.getInt("y") zoom = fromJSONObject.getInt("zoom") + if (fromJSONObject.has("minZoom")) { + minZoom = fromJSONObject.getDouble("minZoom").toFloat() + } + if (fromJSONObject.has("maxZoom")) { + maxZoom = fromJSONObject.getDouble("maxZoom").toFloat() + } + val lat = centerJSONObject.getDouble("lat") val lng = centerJSONObject.getDouble("lng") center = LatLng(lat, lng) @@ -91,5 +100,13 @@ class GoogleMapConfig(fromJSONObject: JSONObject) { if (mapId != null) { googleMapOptions?.mapId(mapId!!) } + + if (minZoom != null) { + googleMapOptions?.minZoomPreference(fromJSONObject.getDouble("minZoom").toFloat()) + } + + if (maxZoom != null) { + googleMapOptions?.maxZoomPreference(fromJSONObject.getDouble("maxZoom").toFloat()) + } } } diff --git a/plugin/ios/Plugin/GoogleMapConfig.swift b/plugin/ios/Plugin/GoogleMapConfig.swift index ef97fe7..60ed02b 100644 --- a/plugin/ios/Plugin/GoogleMapConfig.swift +++ b/plugin/ios/Plugin/GoogleMapConfig.swift @@ -8,6 +8,8 @@ public struct GoogleMapConfig: Codable { let y: Double let center: LatLng let zoom: Double + let minZoom: Float? + let maxZoom: Float? let styles: String? var mapId: String? @@ -45,6 +47,8 @@ public struct GoogleMapConfig: Codable { self.x = x self.y = y self.zoom = zoom + self.minZoom = fromJSObject["minZoom"] as? Float + self.maxZoom = fromJSObject["maxZoom"] as? Float self.center = LatLng(lat: lat, lng: lng) if let stylesArray = fromJSObject["styles"] as? JSArray, let jsonData = try? JSONSerialization.data(withJSONObject: stylesArray, options: []) { self.styles = String(data: jsonData, encoding: .utf8) diff --git a/plugin/ios/Plugin/Map.swift b/plugin/ios/Plugin/Map.swift index 71e4a7d..6f6ef76 100644 --- a/plugin/ios/Plugin/Map.swift +++ b/plugin/ios/Plugin/Map.swift @@ -122,6 +122,10 @@ public class Map { self.mapViewController.GMapView.delegate = self.delegate } + let minZoom = self.config.minZoom ?? self.mapViewController.GMapView.minZoom + let maxZoom = self.config.maxZoom ?? self.mapViewController.GMapView.maxZoom + self.mapViewController.GMapView.setMinZoom(minZoom, maxZoom: maxZoom) + if let styles = self.config.styles { do { self.mapViewController.GMapView.mapStyle = try GMSMapStyle(jsonString: styles)