Skip to content

Commit 7084c39

Browse files
committed
feat(google-maps): Refactored options and added feature to update the map options
1 parent ec53404 commit 7084c39

File tree

6 files changed

+192
-64
lines changed

6 files changed

+192
-64
lines changed

plugin/ios/Sources/CapacitorGoogleMapsPlugin/GoogleMapConfig.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,19 @@ public struct GoogleMapConfig: Codable {
4646
self.center = LatLng(lat: lat, lng: lng)
4747

4848
self.mapId = fromJSObject["iOSMapId"] as? String
49+
50+
var maxZoom = fromJSObject["maxZoom"] as? Double
51+
var minZoom = fromJSObject["minZoom"] as? Double
52+
if let unwrappedMinZoom = minZoom, let unwrappedMaxZoom = maxZoom, unwrappedMinZoom > unwrappedMaxZoom {
53+
swap(&minZoom, &maxZoom)
54+
}
55+
56+
if let maxZoom, zoom > maxZoom {
57+
self.zoom = maxZoom
58+
} else if let minZoom, zoom < minZoom {
59+
self.zoom = minZoom
60+
} else {
61+
self.zoom = zoom
62+
}
4963
}
5064
}

plugin/ios/Sources/CapacitorGoogleMapsPlugin/Map.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public class Map {
206206
}
207207

208208
if (configObj as [String: Any]).keys.contains("heading"), let heading = configObj["heading"] as? Float {
209-
self.mapViewController.GMapView.animate(toBearing: heading)
209+
self.mapViewController.GMapView.animate(toBearing: CLLocationDirection(heading))
210210
}
211211

212212
if (configObj as [String: Any]).keys.contains("isAccessibilityElementsEnabled"), let isAccessibilityElementsEnabled = configObj["isAccessibilityElementsEnabled"] as? Bool {

plugin/rollup.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ export default {
1818
inlineDynamicImports: true,
1919
},
2020
],
21-
external: ['@capacitor/core', '@googlemaps/js-api-loader', '@googlemaps/markerclusterer'],
21+
external: [
22+
'@capacitor/core',
23+
'@googlemaps/js-api-loader',
24+
'@googlemaps/markerclusterer',
25+
],
2226
};

plugin/src/implementation.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,20 @@ export interface CapacitorGoogleMapsPlugin extends Plugin {
187187
dispatchMapEvent(args: { id: string; focus: boolean }): Promise<void>;
188188
getMapBounds(args: { id: string }): Promise<LatLngBounds>;
189189
fitBounds(args: FitBoundsArgs): Promise<void>;
190-
mapBoundsContains(args: MapBoundsContainsArgs): Promise<{ contains: boolean }>;
190+
mapBoundsContains(
191+
args: MapBoundsContainsArgs,
192+
): Promise<{ contains: boolean }>;
191193
mapBoundsExtend(args: MapBoundsExtendArgs): Promise<{ bounds: LatLngBounds }>;
192194
}
193195

194-
const CapacitorGoogleMaps = registerPlugin<CapacitorGoogleMapsPlugin>('CapacitorGoogleMaps', {
195-
web: () => import('./web').then((m) => new m.CapacitorGoogleMapsWeb()),
196-
});
196+
const CapacitorGoogleMaps = registerPlugin<CapacitorGoogleMapsPlugin>(
197+
'CapacitorGoogleMaps',
198+
{
199+
web: () => import('./web').then(m => new m.CapacitorGoogleMapsWeb()),
200+
},
201+
);
197202

198-
CapacitorGoogleMaps.addListener('isMapInFocus', (data) => {
203+
CapacitorGoogleMaps.addListener('isMapInFocus', data => {
199204
const x = data.x;
200205
const y = data.y;
201206

plugin/src/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
/* eslint-disable @typescript-eslint/no-namespace */
2-
import { LatLngBounds, MapType, Marker, Polygon, Circle, Polyline, StyleSpan } from './definitions';
2+
import {
3+
LatLngBounds,
4+
MapType,
5+
Marker,
6+
Polygon,
7+
Circle,
8+
Polyline,
9+
StyleSpan,
10+
} from './definitions';
311
import { GoogleMap } from './map';
412

5-
export { GoogleMap, LatLngBounds, MapType, Marker, Polygon, Circle, Polyline, StyleSpan };
13+
export {
14+
GoogleMap,
15+
LatLngBounds,
16+
MapType,
17+
Marker,
18+
Polygon,
19+
Circle,
20+
Polyline,
21+
StyleSpan,
22+
};
623

724
declare global {
825
export namespace JSX {

0 commit comments

Comments
 (0)