diff --git a/plugin/README.md b/plugin/README.md index 6ac6da4..c86d13e 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -381,6 +381,8 @@ Vue({ * [`setOnMarkerDragEndListener(...)`](#setonmarkerdragendlistener) * [`setOnMyLocationButtonClickListener(...)`](#setonmylocationbuttonclicklistener) * [`setOnMyLocationClickListener(...)`](#setonmylocationclicklistener) +* [`show()`](#show) +* [`hide()`](#hide) * [Interfaces](#interfaces) * [Type Aliases](#type-aliases) * [Enums](#enums) @@ -964,6 +966,24 @@ setOnMyLocationClickListener(callback?: MapListenerCallback Promise +``` + +-------------------- + + +### hide() + +```typescript +hide() => Promise +``` + +-------------------- + + ### Interfaces diff --git a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt index c0bc416..c7729e3 100644 --- a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt +++ b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt @@ -769,6 +769,20 @@ class CapacitorGoogleMap( googleMap?.animateCamera(cameraUpdate) } + fun show() { + CoroutineScope(Dispatchers.Main).launch { + mapView.onResume() + mapView.visibility = View.VISIBLE + } + } + + fun hide() { + CoroutineScope(Dispatchers.Main).launch { + mapView.onPause() + mapView.visibility = View.GONE + } + } + private fun getScaledPixels(bridge: Bridge, pixels: Int): Int { // Get the screen's density scale val scale = bridge.activity.resources.displayMetrics.density diff --git a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt index 06ecab2..f7090c6 100644 --- a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt +++ b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt @@ -1042,6 +1042,44 @@ class CapacitorGoogleMapsPlugin : Plugin(), OnMapsSdkInitializedCallback { } } + @PluginMethod + fun show(call: PluginCall) { + try { + val id = call.getString("id") + id ?: throw InvalidMapIdError() + + val map = maps[id] + map ?: throw MapNotFoundError() + + map.show() + + call.resolve() + } catch (e: GoogleMapsError) { + handleError(call, e) + } catch (e: Exception) { + handleError(call, e) + } + } + + @PluginMethod + fun hide(call: PluginCall) { + try { + val id = call.getString("id") + id ?: throw InvalidMapIdError() + + val map = maps[id] + map ?: throw MapNotFoundError() + + map.hide() + + call.resolve() + } catch (e: GoogleMapsError) { + handleError(call, e) + } catch (e: Exception) { + handleError(call, e) + } + } + private fun createLatLng(point: JSObject): LatLng { return LatLng( point.getDouble("lat"), diff --git a/plugin/ios/Sources/CapacitorGoogleMapsPlugin/CapacitorGoogleMapsPlugin.swift b/plugin/ios/Sources/CapacitorGoogleMapsPlugin/CapacitorGoogleMapsPlugin.swift index 55a830e..7a0a497 100644 --- a/plugin/ios/Sources/CapacitorGoogleMapsPlugin/CapacitorGoogleMapsPlugin.swift +++ b/plugin/ios/Sources/CapacitorGoogleMapsPlugin/CapacitorGoogleMapsPlugin.swift @@ -100,7 +100,9 @@ public class CapacitorGoogleMapsPlugin: CAPPlugin, GMSMapViewDelegate, CAPBridge CAPPluginMethod(name: "getMapBounds", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "fitBounds", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "mapBoundsContains", returnType: CAPPluginReturnPromise), - CAPPluginMethod(name: "mapBoundsExtend", returnType: CAPPluginReturnPromise) + CAPPluginMethod(name: "mapBoundsExtend", returnType: CAPPluginReturnPromise), + CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise), + CAPPluginMethod(name: "hide", returnType: CAPPluginReturnPromise) ] private var maps = [String: Map]() private var isInitialized = false @@ -970,6 +972,14 @@ public class CapacitorGoogleMapsPlugin: CAPPlugin, GMSMapViewDelegate, CAPBridge } } + @objc func show(_ call: CAPPluginCall) { + call.resolve() + } + + @objc func hide(_ call: CAPPluginCall) { + call.resolve() + } + private func getGMSCoordinateBounds(_ bounds: JSObject) throws -> GMSCoordinateBounds { guard let southwest = bounds["southwest"] as? JSObject else { throw GoogleMapErrors.unhandledError("Bounds southwest property not formatted properly.") diff --git a/plugin/src/implementation.ts b/plugin/src/implementation.ts index 357f0d1..91b7a49 100644 --- a/plugin/src/implementation.ts +++ b/plugin/src/implementation.ts @@ -215,6 +215,8 @@ export interface CapacitorGoogleMapsPlugin extends Plugin { fitBounds(args: FitBoundsArgs): Promise; mapBoundsContains(args: MapBoundsContainsArgs): Promise<{ contains: boolean }>; mapBoundsExtend(args: MapBoundsExtendArgs): Promise<{ bounds: LatLngBounds }>; + show(args: { id: string }): Promise; + hide(args: { id: string }): Promise; } const CapacitorGoogleMaps = registerPlugin('CapacitorGoogleMaps', { diff --git a/plugin/src/map.ts b/plugin/src/map.ts index 851d166..1453fea 100644 --- a/plugin/src/map.ts +++ b/plugin/src/map.ts @@ -88,6 +88,9 @@ export interface GoogleMapInterface { setOnMarkerDragEndListener(callback?: MapListenerCallback): Promise; setOnMyLocationButtonClickListener(callback?: MapListenerCallback): Promise; setOnMyLocationClickListener(callback?: MapListenerCallback): Promise; + + show(): Promise; + hide(): Promise; } class MapCustomElement extends HTMLElement { @@ -1106,4 +1109,16 @@ export class GoogleMap { } }; } + + async show(): Promise { + return CapacitorGoogleMaps.show({ + id: this.id, + }); + } + + async hide(): Promise { + return CapacitorGoogleMaps.hide({ + id: this.id, + }); + } } diff --git a/plugin/src/web.ts b/plugin/src/web.ts index aae4773..4d1be17 100644 --- a/plugin/src/web.ts +++ b/plugin/src/web.ts @@ -720,4 +720,12 @@ export class CapacitorGoogleMapsWeb extends WebPlugin implements CapacitorGoogle return advancedMarker; } + + async show(): Promise { + return; + } + + async hide(): Promise { + return; + } }