-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathimplementation.ts
More file actions
223 lines (193 loc) · 5.49 KB
/
Copy pathimplementation.ts
File metadata and controls
223 lines (193 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import type { Plugin } from '@capacitor/core';
import { registerPlugin } from '@capacitor/core';
import type {
CameraConfig,
Circle,
GoogleMapConfig,
LatLng,
LatLngBounds,
MapPadding,
MapType,
Marker,
Polygon,
Polyline,
} from './definitions';
/**
* An interface containing the options used when creating a map.
*/
export interface CreateMapArgs {
/**
* A unique identifier for the map instance.
*/
id: string;
/**
* The Google Maps SDK API Key.
*/
apiKey: string;
/**
* The initial configuration settings for the map.
*/
config: GoogleMapConfig;
/**
* The DOM element that the Google Map View will be mounted on which determines size and positioning.
*/
element: HTMLElement;
/**
* Destroy and re-create the map instance if a map with the supplied id already exists
* @default false
*/
forceCreate?: boolean;
/**
* The region parameter alters your application to serve different map tiles or bias the application (such as biasing geocoding results towards the region).
*
* Only available for web.
*/
region?: string;
/**
* The language parameter affects the names of controls, copyright notices, driving directions, and control labels, as well as the responses to service requests.
*
* Only available for web.
*/
language?: string;
}
export interface DestroyMapArgs {
id: string;
}
export interface RemoveMarkerArgs {
id: string;
markerId: string;
}
export interface RemoveMarkersArgs {
id: string;
markerIds: string[];
}
export interface AddMarkerArgs {
id: string;
marker: Marker;
}
export interface AddPolygonsArgs {
id: string;
polygons: Polygon[];
}
export interface RemovePolygonsArgs {
id: string;
polygonIds: string[];
}
export interface AddCirclesArgs {
id: string;
circles: Circle[];
}
export interface RemoveCirclesArgs {
id: string;
circleIds: string[];
}
export interface AddPolylinesArgs {
id: string;
polylines: Polyline[];
}
export interface RemovePolylinesArgs {
id: string;
polylineIds: string[];
}
export interface CameraArgs {
id: string;
config: CameraConfig;
}
export interface MapTypeArgs {
id: string;
mapType: MapType;
}
export interface IndoorMapArgs {
id: string;
enabled: boolean;
}
export interface TrafficLayerArgs {
id: string;
enabled: boolean;
}
export interface AccElementsArgs {
id: string;
enabled: boolean;
}
export interface PaddingArgs {
id: string;
padding: MapPadding;
}
export interface CurrentLocArgs {
id: string;
enabled: boolean;
enableButton: boolean;
}
export interface AddMarkersArgs {
id: string;
markers: Marker[];
}
export interface MapBoundsArgs {
id: string;
mapBounds: {
x: number;
y: number;
width: number;
height: number;
};
}
export interface MapBoundsContainsArgs {
bounds: LatLngBounds;
point: LatLng;
}
export type MapBoundsExtendArgs = MapBoundsContainsArgs;
export interface EnableClusteringArgs {
id: string;
minClusterSize?: number;
}
export interface FitBoundsArgs {
id: string;
bounds: LatLngBounds;
padding?: number;
}
export interface CapacitorGoogleMapsPlugin extends Plugin {
create(options: CreateMapArgs): Promise<void>;
enableTouch(args: { id: string }): Promise<void>;
disableTouch(args: { id: string }): Promise<void>;
addMarker(args: AddMarkerArgs): Promise<{ id: string }>;
addMarkers(args: AddMarkersArgs): Promise<{ ids: string[] }>;
removeMarker(args: RemoveMarkerArgs): Promise<void>;
removeMarkers(args: RemoveMarkersArgs): Promise<void>;
addPolygons(args: AddPolygonsArgs): Promise<{ ids: string[] }>;
removePolygons(args: RemovePolygonsArgs): Promise<void>;
addCircles(args: AddCirclesArgs): Promise<{ ids: string[] }>;
removeCircles(args: RemoveCirclesArgs): Promise<void>;
addPolylines(args: AddPolylinesArgs): Promise<{ ids: string[] }>;
removePolylines(args: RemovePolylinesArgs): Promise<void>;
enableClustering(args: EnableClusteringArgs): Promise<void>;
disableClustering(args: { id: string }): Promise<void>;
destroy(args: DestroyMapArgs): Promise<void>;
setCamera(args: CameraArgs): Promise<void>;
getMapType(args: { id: string }): Promise<{ type: string }>;
setMapType(args: MapTypeArgs): Promise<void>;
enableIndoorMaps(args: IndoorMapArgs): Promise<void>;
enableTrafficLayer(args: TrafficLayerArgs): Promise<void>;
enableAccessibilityElements(args: AccElementsArgs): Promise<void>;
enableCurrentLocation(args: CurrentLocArgs): Promise<void>;
setPadding(args: PaddingArgs): Promise<void>;
onScroll(args: MapBoundsArgs): Promise<void>;
onResize(args: MapBoundsArgs): Promise<void>;
onDisplay(args: MapBoundsArgs): Promise<void>;
dispatchMapEvent(args: { id: string; focus: boolean }): Promise<void>;
getMapBounds(args: { id: string }): Promise<LatLngBounds>;
fitBounds(args: FitBoundsArgs): Promise<void>;
mapBoundsContains(args: MapBoundsContainsArgs): Promise<{ contains: boolean }>;
mapBoundsExtend(args: MapBoundsExtendArgs): Promise<{ bounds: LatLngBounds }>;
}
const CapacitorGoogleMaps = registerPlugin<CapacitorGoogleMapsPlugin>('CapacitorGoogleMaps', {
web: () => import('./web').then((m) => new m.CapacitorGoogleMapsWeb()),
});
CapacitorGoogleMaps.addListener('isMapInFocus', (data) => {
const x = data.x;
const y = data.y;
const elem = document.elementFromPoint(x, y) as HTMLElement | null;
const internalId = elem?.dataset?.internalId;
const mapInFocus = internalId === data.mapId;
CapacitorGoogleMaps.dispatchMapEvent({ id: data.mapId, focus: mapInFocus });
});
export { CapacitorGoogleMaps };