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

feat(google-maps): Add map instance getter - getRawGoogleMapInstance #1757

Open
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions google-maps/README.md
Expand Up @@ -301,6 +301,7 @@ export default MyMap;
* [`setCamera(...)`](#setcamera)
* [`getMapType()`](#getmaptype)
* [`setMapType(...)`](#setmaptype)
* [`getRawGoogleMapInstance()`](#getrawgooglemapinstance)
* [`enableIndoorMaps(...)`](#enableindoormaps)
* [`enableTrafficLayer(...)`](#enabletrafficlayer)
* [`enableAccessibilityElements(...)`](#enableaccessibilityelements)
Expand Down Expand Up @@ -576,6 +577,19 @@ setMapType(mapType: MapType) => Promise<void>
--------------------


### getRawGoogleMapInstance(...)

```typescript
getRawGoogleMapInstance(id: string) => Promise<google.maps.Map>
```

| Param | Type |
| ------------- | ------------------------------------------- |
| **`id`** | <code>string</code> |

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


### enableIndoorMaps(...)

```typescript
Expand Down
Expand Up @@ -611,6 +611,10 @@ class CapacitorGoogleMap(
}
}

fun getRawGoogleMapInstance(callback: (type: String, error: GoogleMapsError?) -> Unit) {
throw GoogleMapsError('Not implemented on Android platform.');
}

fun enableIndoorMaps(enabled: Boolean, callback: (error: GoogleMapsError?) -> Unit) {
try {
googleMap ?: throw GoogleMapNotAvailable()
Expand Down
4 changes: 4 additions & 0 deletions google-maps/ios/Plugin/CapacitorGoogleMapsPlugin.swift
Expand Up @@ -579,6 +579,10 @@ public class CapacitorGoogleMapsPlugin: CAPPlugin, GMSMapViewDelegate {
}
}

@objc func getRawGoogleMapInstance(_ call: CAPPluginCall) {
throw GoogleMapErrors.unhandledError("Not implemented on iOS platform");
}

@objc func enableIndoorMaps(_ call: CAPPluginCall) {
do {
guard let id = call.getString("id") else {
Expand Down
5 changes: 5 additions & 0 deletions google-maps/src/implementation.ts
Expand Up @@ -112,6 +112,10 @@ export interface MapTypeArgs {
mapType: MapType;
}

export interface RawGoogleMapInstanceArgs {
id: string
}

export interface IndoorMapArgs {
id: string;
enabled: boolean;
Expand Down Expand Up @@ -189,6 +193,7 @@ export interface CapacitorGoogleMapsPlugin extends Plugin {
setCamera(args: CameraArgs): Promise<void>;
getMapType(args: { id: string }): Promise<{ type: string }>;
setMapType(args: MapTypeArgs): Promise<void>;
getRawGoogleMapInstance(args: RawGoogleMapInstanceArgs): google.maps.Map;
enableIndoorMaps(args: IndoorMapArgs): Promise<void>;
enableTrafficLayer(args: TrafficLayerArgs): Promise<void>;
enableAccessibilityElements(args: AccElementsArgs): Promise<void>;
Expand Down
5 changes: 5 additions & 0 deletions google-maps/src/map.ts
Expand Up @@ -55,6 +55,7 @@ export interface GoogleMapInterface {
*/
getMapType(): Promise<MapType>;
setMapType(mapType: MapType): Promise<void>;
getRawGoogleMapInstance(): Promise<google.maps.Map>;
enableIndoorMaps(enabled: boolean): Promise<void>;
enableTrafficLayer(enabled: boolean): Promise<void>;
enableAccessibilityElements(enabled: boolean): Promise<void>;
Expand Down Expand Up @@ -525,6 +526,10 @@ export class GoogleMap {
});
}

public async getRawGoogleMapInstance(): Promise<google.maps.Map> {
return await CapacitorGoogleMaps.getRawGoogleMapInstance(this.id);
}

/**
* Sets whether indoor maps are shown, where available.
*
Expand Down
5 changes: 5 additions & 0 deletions google-maps/src/web.ts
Expand Up @@ -33,6 +33,7 @@ import type {
RemoveCirclesArgs,
AddPolylinesArgs,
RemovePolylinesArgs,
RawGoogleMapInstanceArgs,
} from './implementation';

export class CapacitorGoogleMapsWeb
Expand Down Expand Up @@ -173,6 +174,10 @@ export class CapacitorGoogleMapsWeb
this.maps[_args.id].map.setMapTypeId(mapType);
}

public getRawGoogleMapInstance(_args: RawGoogleMapInstanceArgs): google.maps.Map {
return this.maps[_args.id].map;
}

async enableIndoorMaps(): Promise<void> {
throw new Error('Method not supported on web.');
}
Expand Down