Skip to content
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
20 changes: 20 additions & 0 deletions plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ Vue({
* [`setOnMarkerDragEndListener(...)`](#setonmarkerdragendlistener)
* [`setOnMyLocationButtonClickListener(...)`](#setonmylocationbuttonclicklistener)
* [`setOnMyLocationClickListener(...)`](#setonmylocationclicklistener)
* [`show()`](#show)
* [`hide()`](#hide)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)
Expand Down Expand Up @@ -964,6 +966,24 @@ setOnMyLocationClickListener(callback?: MapListenerCallback<MapClickCallbackData
--------------------


### show()

```typescript
show() => Promise<void>
```

--------------------


### hide()

```typescript
hide() => Promise<void>
```

--------------------


### Interfaces


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ export interface CapacitorGoogleMapsPlugin extends Plugin {
fitBounds(args: FitBoundsArgs): Promise<void>;
mapBoundsContains(args: MapBoundsContainsArgs): Promise<{ contains: boolean }>;
mapBoundsExtend(args: MapBoundsExtendArgs): Promise<{ bounds: LatLngBounds }>;
show(args: { id: string }): Promise<void>;
hide(args: { id: string }): Promise<void>;
}

const CapacitorGoogleMaps = registerPlugin<CapacitorGoogleMapsPlugin>('CapacitorGoogleMaps', {
Expand Down
15 changes: 15 additions & 0 deletions plugin/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export interface GoogleMapInterface {
setOnMarkerDragEndListener(callback?: MapListenerCallback<MarkerClickCallbackData>): Promise<void>;
setOnMyLocationButtonClickListener(callback?: MapListenerCallback<MyLocationButtonClickCallbackData>): Promise<void>;
setOnMyLocationClickListener(callback?: MapListenerCallback<MapClickCallbackData>): Promise<void>;

show(): Promise<void>;
hide(): Promise<void>;
}

class MapCustomElement extends HTMLElement {
Expand Down Expand Up @@ -1106,4 +1109,16 @@ export class GoogleMap {
}
};
}

async show(): Promise<void> {
return CapacitorGoogleMaps.show({
id: this.id,
});
}

async hide(): Promise<void> {
return CapacitorGoogleMaps.hide({
id: this.id,
});
}
}
8 changes: 8 additions & 0 deletions plugin/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,12 @@ export class CapacitorGoogleMapsWeb extends WebPlugin implements CapacitorGoogle

return advancedMarker;
}

async show(): Promise<void> {
return;
}

async hide(): Promise<void> {
return;
}
}