Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix min/max zoom on Android/iOS #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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())
}
}
}
4 changes: 4 additions & 0 deletions plugin/ios/Plugin/GoogleMapConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions plugin/ios/Plugin/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down