diff --git a/google-maps/README.md b/google-maps/README.md index e63385591..bfbcdba5f 100644 --- a/google-maps/README.md +++ b/google-maps/README.md @@ -900,6 +900,9 @@ For iOS and Android only the config options declared on Logger.debug("Capacitor Google Maps", "Latest Google Maps renderer enabled") + MapsInitializer.Renderer.LEGACY -> Logger.debug("Capacitor Google Maps", "Legacy Google Maps renderer enabled - Cloud based map styling and advanced drawing not available") + } + } + override fun handleOnStart() { super.handleOnStart() maps.forEach { it.value.onStart() } diff --git a/google-maps/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt b/google-maps/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt index 6f27d10ab..bc29ae08f 100644 --- a/google-maps/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt +++ b/google-maps/android/src/main/java/com/capacitorjs/plugins/googlemaps/GoogleMapConfig.kt @@ -16,6 +16,7 @@ class GoogleMapConfig(fromJSONObject: JSONObject) { var liteMode: Boolean = false var devicePixelRatio: Float = 1.00f var styles: String? = null + var mapId: String? = null init { if (!fromJSONObject.has("width")) { @@ -81,8 +82,14 @@ class GoogleMapConfig(fromJSONObject: JSONObject) { center = LatLng(lat, lng) val cameraPosition = CameraPosition(center, zoom.toFloat(), 0.0F, 0.0F) - googleMapOptions = GoogleMapOptions().camera(cameraPosition).liteMode(liteMode) styles = fromJSONObject.getString("styles") + + mapId = fromJSONObject.getString("androidMapId") + + googleMapOptions = GoogleMapOptions().camera(cameraPosition).liteMode(liteMode) + if (mapId != null) { + googleMapOptions?.mapId(mapId!!) + } } } diff --git a/google-maps/ios/Plugin/GoogleMapConfig.swift b/google-maps/ios/Plugin/GoogleMapConfig.swift index 4905b18e3..ef97fe77b 100644 --- a/google-maps/ios/Plugin/GoogleMapConfig.swift +++ b/google-maps/ios/Plugin/GoogleMapConfig.swift @@ -9,6 +9,7 @@ public struct GoogleMapConfig: Codable { let center: LatLng let zoom: Double let styles: String? + var mapId: String? init(fromJSObject: JSObject) throws { guard let width = fromJSObject["width"] as? Double else { @@ -50,5 +51,7 @@ public struct GoogleMapConfig: Codable { } else { self.styles = nil } + + self.mapId = fromJSObject["iOSMapId"] as? String } } diff --git a/google-maps/ios/Plugin/Map.swift b/google-maps/ios/Plugin/Map.swift index d7315f0e9..71e4a7de9 100644 --- a/google-maps/ios/Plugin/Map.swift +++ b/google-maps/ios/Plugin/Map.swift @@ -13,6 +13,7 @@ class GMViewController: UIViewController { var GMapView: GMSMapView! var cameraPosition: [String: Double]! var minimumClusterSize: Int? + var mapId: String? private var clusterManager: GMUClusterManager? @@ -25,7 +26,13 @@ class GMViewController: UIViewController { let camera = GMSCameraPosition.camera(withLatitude: cameraPosition["latitude"] ?? 0, longitude: cameraPosition["longitude"] ?? 0, zoom: Float(cameraPosition["zoom"] ?? 12)) let frame = CGRect(x: mapViewBounds["x"] ?? 0, y: mapViewBounds["y"] ?? 0, width: mapViewBounds["width"] ?? 0, height: mapViewBounds["height"] ?? 0) - self.GMapView = GMSMapView.map(withFrame: frame, camera: camera) + if let id = mapId { + let gmsId = GMSMapID(identifier: id) + self.GMapView = GMSMapView(frame: frame, mapID: gmsId, camera: camera) + } else { + self.GMapView = GMSMapView(frame: frame, camera: camera) + } + self.view = GMapView } @@ -85,6 +92,7 @@ public class Map { self.config = config self.delegate = delegate self.mapViewController = GMViewController() + self.mapViewController.mapId = config.mapId self.render() } diff --git a/google-maps/src/definitions.ts b/google-maps/src/definitions.ts index 0c2c92328..57f331c83 100644 --- a/google-maps/src/definitions.ts +++ b/google-maps/src/definitions.ts @@ -191,6 +191,36 @@ export interface GoogleMapConfig extends google.maps.MapOptions { * @since 4.3.0 */ styles?: google.maps.MapTypeStyle[] | null; + /** + * A map id associated with a specific map style or feature. + * + * [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id) + * + * Only for Web. + * + * @since 6.0.0 + */ + mapId?: string; + /** + * A map id associated with a specific map style or feature. + * + * [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id) + * + * Only for Android. + * + * @since 6.0.0 + */ + androidMapId?: string; + /** + * A map id associated with a specific map style or feature. + * + * [Use Map IDs](https://developers.google.com/maps/documentation/get-map-id) + * + * Only for iOS. + * + * @since 6.0.0 + */ + iOSMapId?: string; } /** diff --git a/google-maps/src/web.ts b/google-maps/src/web.ts index b8c6467b8..5b82addec 100644 --- a/google-maps/src/web.ts +++ b/google-maps/src/web.ts @@ -436,6 +436,7 @@ export class CapacitorGoogleMapsWeb async create(_args: CreateMapArgs): Promise { console.log(`Create map: ${_args.id}`); await this.importGoogleLib(_args.apiKey, _args.region, _args.language); + this.maps[_args.id] = { map: new window.google.maps.Map(_args.element, { ..._args.config }), element: _args.element,