google-maps-react-markers 2.0.14 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,296 +1,216 @@
1
- import * as React from 'react';
2
- import React__default from 'react';
3
-
4
- declare global {
5
- interface Window {
6
- google?: any;
7
- googleMapsCallback?: () => void;
8
- }
9
- }
10
- type MapMouseEvent = google.maps.MapMouseEvent;
11
- type Map = google.maps.Map;
12
- type MapsLibrary = typeof google.maps;
13
- type MapPanes = google.maps.MapPanes;
14
- type MapOptions = google.maps.MapOptions;
15
- type LatLng = google.maps.LatLng;
1
+ /// <reference types="google.maps" />
2
+ import { CSSProperties, ReactNode, Ref } from "react";
16
3
  type LatLngLiteral = google.maps.LatLngLiteral;
17
- type LatLngBounds = google.maps.LatLngBounds;
18
- type LatLngBoundsLiteral = google.maps.LatLngBoundsLiteral;
4
+ /** Map bounds as `[westLng, southLat, eastLng, northLat]`, ready for supercluster's `getClusters()`. */
5
+ type BBox = [west: number, south: number, east: number, north: number];
6
+ /** Loading status of the Google Maps JavaScript API. */
7
+ type GoogleMapsStatus = 'loading' | 'ready' | 'error';
19
8
  /**
20
- * The drag configuration of the overlay.
9
+ * How markers are drawn.
10
+ * - `advanced`: `google.maps.marker.AdvancedMarkerElement`. Needs a `mapId`.
11
+ * - `overlay`: a custom `google.maps.OverlayView`. Works without `mapId`, so JSON `styles` keep working.
12
+ * - `auto`: `advanced` when the map has a `mapId`, `overlay` otherwise.
21
13
  */
22
- type Drag = {
23
- /**
24
- * Whether the overlay is draggable.
25
- * @default false
26
- */
27
- draggable: boolean;
28
- /**
29
- * Callback fired repeatedly when the overlay is dragged.
30
- * @param e The event.
31
- * @param props The props.
32
- */
33
- onDrag: (e: MouseEvent, props: {}) => void;
34
- /**
35
- * Callback fired when the drag has ended.
36
- * @param e The event.
37
- * @param props The props.
38
- */
39
- onDragEnd: (e: MouseEvent, props: {}) => void;
40
- /**
41
- * Callback fired when the drag has started.
42
- * @param e The event.
43
- * @param props The props.
44
- */
45
- onDragStart: (e: MouseEvent, props: {}) => void;
46
- };
47
- type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
48
- type Pane = 'floatPane' | 'mapPane' | 'markerLayer' | 'overlayLayer' | 'overlayMouseTarget';
49
- interface IUseGoogleMaps {
50
- /**
51
- * The Google Maps API key.
52
- */
53
- apiKey?: string;
54
- /**
55
- * The Google Maps API callback.
56
- */
57
- callback?: () => void;
58
- /**
59
- * The Google Maps API params to be appended to the script URL.
60
- * @example
61
- * {
62
- * language: 'en',
63
- * region: 'GB',
64
- * }
65
- */
66
- externalApiParams?: {
67
- [key: string]: any;
68
- };
69
- /**
70
- * The Google Maps API libraries to be loaded.
71
- * @default ['places', 'geometry']
72
- */
73
- libraries?: string[];
74
- /**
75
- * Whether to manage the script loading externally.
76
- * @default false
77
- */
78
- loadScriptExternally?: boolean;
79
- /**
80
- * The status of the script loading.
81
- * To be used only if `loadScriptExternally` is `true`.
82
- */
83
- status?: UseScriptStatus;
84
- }
85
- interface ScriptProps {
86
- /**
87
- * The attributes to be passed to the script element.
88
- */
89
- attributes?: {
90
- [key: string]: string;
91
- };
92
- /**
93
- * The callback to be called when the script has loaded
94
- * successfully or has failed to load.
95
- */
96
- callbacks?: {
97
- onErrorCallback?: () => void;
98
- onLoadCallback?: () => void;
99
- };
100
- /**
101
- * The ID of the HTML element where the script will be appended.
102
- * If not provided, the script will be appended to the `body` element.
103
- */
104
- elementIdToAppend?: string;
105
- /**
106
- * The URL of the script to be loaded.
107
- */
108
- src: string;
109
- }
110
- interface UseScriptOptions {
111
- /**
112
- * Whether to remove the script when the component unmounts.
113
- */
114
- removeOnUnmount?: boolean;
115
- /**
116
- * Whether to prevent the script from loading.
117
- * @default false
118
- */
119
- shouldPreventLoad?: boolean;
120
- }
121
- interface MapContextProps {
122
- /**
123
- * The Google Maps instance.
124
- */
125
- map: Map;
126
- /**
127
- * The Google Maps API object.
128
- */
129
- maps: MapsLibrary;
14
+ type MarkerRenderer = 'auto' | 'advanced' | 'overlay';
15
+ /** Options for loading the Google Maps JavaScript API. Only the first mounted map applies them. */
16
+ interface GoogleMapsLoaderOptions {
17
+ /** Your Google Maps Platform API key. */
18
+ apiKey?: string;
19
+ /**
20
+ * Optional `auth_referrer_policy` parameter.
21
+ * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api#optional_parameters
22
+ */
23
+ authReferrerPolicy?: string;
24
+ /** Optional `channel` parameter, used for usage reports. */
25
+ channel?: string;
26
+ /** Language of map labels and controls, for example `'it'`. */
27
+ language?: string;
28
+ /**
29
+ * Extra libraries to load together with the map, for example `['places', 'geometry']`.
30
+ * You can also load them later with `useMapsLibrary()`.
31
+ */
32
+ libraries?: (keyof google.maps.ImportLibraryMap)[];
33
+ /** Map IDs to preload. */
34
+ mapIds?: string[];
35
+ /** Region bias, for example `'IT'`. */
36
+ region?: string;
37
+ /**
38
+ * API version: `'weekly'`, `'quarterly'`, `'beta'` or a specific version.
39
+ * @default 'weekly'
40
+ */
41
+ version?: string;
130
42
  }
131
- interface OverlayViewProps extends MapContextProps {
132
- /**
133
- * The children to be rendered within the overlay.
134
- */
135
- children?: React__default.ReactElement;
136
- /**
137
- * The drag configuration of the overlay.
138
- * @default { draggable: false }
139
- */
140
- drag?: Drag;
141
- /**
142
- * The map pane in which to render the overlay.
143
- * @default 'floatPane'
144
- */
145
- pane?: Pane | undefined;
146
- /**
147
- * The geographical coordinates of the overlay.
148
- */
149
- position: LatLng;
150
- /**
151
- * The z-index of the overlay.
152
- * @default 0
153
- */
154
- zIndex?: number | 0;
43
+ /** Values passed to `onChange` every time the map settles after a pan or a zoom. */
44
+ interface MapChangeEvent {
45
+ /** Bounds as `[westLng, southLat, eastLng, northLat]`. */
46
+ bbox: BBox;
47
+ bounds: google.maps.LatLngBounds;
48
+ center: LatLngLiteral;
49
+ map: google.maps.Map;
50
+ zoom: number;
155
51
  }
156
- interface createOverlayProps {
157
- /**
158
- * The HTML container element in which to render the overlay.
159
- */
160
- container: HTMLDivElement;
161
- /**
162
- * The drag configuration of the overlay.
163
- * @default { draggable: false }
164
- */
165
- drag?: Drag;
166
- /**
167
- * The Google Maps API object.
168
- */
169
- maps: MapContextProps['maps'];
170
- /**
171
- * The map pane in which to render the overlay.
172
- * @default 'floatPane'
173
- */
174
- pane: Pane;
175
- /**
176
- * The geographical coordinates of the overlay.
177
- */
178
- position: LatLng;
52
+ interface MapLoadEvent {
53
+ map: google.maps.Map;
54
+ /** The `google.maps` namespace. */
55
+ maps: typeof google.maps;
179
56
  }
180
- interface EventProps {
181
- /**
182
- * The event handler.
183
- * @param e The event.
184
- */
185
- handler: (e: any) => void;
186
- /**
187
- * The HTML Event attribute name.
188
- * @reference https://www.w3schools.com/tags/ref_eventattributes.asp
189
- * @example
190
- * 'onClick'
191
- */
192
- name: string;
57
+ type MapMouseHandler = (event: google.maps.MapMouseEvent, map: google.maps.Map) => void;
58
+ type MapHandler = (map: google.maps.Map) => void;
59
+ /** Google Maps events, exposed as props. Handlers always see your latest props. */
60
+ interface MapEventProps {
61
+ onBoundsChanged?: MapHandler;
62
+ onCenterChanged?: MapHandler;
63
+ onClick?: MapMouseHandler;
64
+ onContextMenu?: MapMouseHandler;
65
+ onDoubleClick?: MapMouseHandler;
66
+ onDrag?: MapHandler;
67
+ onDragEnd?: MapHandler;
68
+ onDragStart?: MapHandler;
69
+ onHeadingChanged?: MapHandler;
70
+ onIdle?: MapHandler;
71
+ onMapTypeIdChanged?: MapHandler;
72
+ onMouseMove?: MapMouseHandler;
73
+ onMouseOut?: MapMouseHandler;
74
+ onMouseOver?: MapMouseHandler;
75
+ onTilesLoaded?: MapHandler;
76
+ onTiltChanged?: MapHandler;
77
+ onZoomChanged?: MapHandler;
193
78
  }
194
- interface onGoogleApiLoadedProps extends MapContextProps {
195
- /**
196
- * The ref of the Map.
197
- */
198
- ref: HTMLDivElement | null;
79
+ interface GoogleMapProps extends GoogleMapsLoaderOptions, MapEventProps {
80
+ /**
81
+ * Controlled center. When it changes, the map moves there. Users can still pan:
82
+ * keep your state in sync with `onChange`.
83
+ */
84
+ center?: LatLngLiteral;
85
+ /** Markers, controls and any component that uses `useMap()`. */
86
+ children?: ReactNode;
87
+ /** Class name of the outer container. Give it a height, or the map has none. */
88
+ className?: string;
89
+ /** Initial center, when `center` is not set. */
90
+ defaultCenter?: LatLngLiteral;
91
+ /** Initial zoom, when `zoom` is not set. */
92
+ defaultZoom?: number;
93
+ /**
94
+ * Rendered when the API fails to load or the API key is rejected.
95
+ * @default null
96
+ */
97
+ errorContent?: ReactNode;
98
+ /** `id` of the outer container. */
99
+ id?: string;
100
+ /**
101
+ * Rendered while the API is loading, and on the server.
102
+ * @default null
103
+ */
104
+ loadingContent?: ReactNode;
105
+ /**
106
+ * Cloud map ID. Enables `AdvancedMarkerElement` markers and cloud-based styling.
107
+ * Changing it creates a new map.
108
+ */
109
+ mapId?: string;
110
+ /**
111
+ * How `<Marker>` children are drawn.
112
+ * @default 'auto'
113
+ */
114
+ markerRenderer?: MarkerRenderer;
115
+ /** Fired every time the map settles (`idle`) with a new center, zoom or bounds. */
116
+ onChange?: (event: MapChangeEvent) => void;
117
+ /** Fired once, when the map has been created. */
118
+ onLoad?: (event: MapLoadEvent) => void;
119
+ /**
120
+ * Any `google.maps.MapOptions`. Changes are applied with `map.setOptions()`.
121
+ * @see https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
122
+ */
123
+ options?: Omit<google.maps.MapOptions, 'center' | 'zoom' | 'mapId'>;
124
+ /** Ref to the outer container `div`. */
125
+ ref?: Ref<HTMLDivElement>;
126
+ /** Style of the outer container, merged over `{ position: 'relative', width: '100%', height: '100%' }`. */
127
+ style?: CSSProperties;
128
+ /** Controlled zoom. Pair it with `onChange`. */
129
+ zoom?: number;
199
130
  }
200
- interface MapMarkersProps extends MapContextProps {
201
- /**
202
- * The Markers to be rendered on the map.
203
- */
204
- children: React__default.ReactNode;
205
- }
206
- interface MapProps {
207
- /**
208
- * The Markers to be rendered on the map
209
- */
210
- children?: React__default.ReactNode;
211
- /**
212
- * The default center of the map.
213
- */
214
- defaultCenter: LatLngLiteral;
215
- /**
216
- * The default zoom of the map.
217
- */
218
- defaultZoom: number;
219
- /**
220
- * The events to pass to the Google Maps instance (`div`).
221
- * @type {Array}
222
- * @example
223
- * [
224
- * {
225
- * name: 'onClick',
226
- * handler: (event) => { ... }
227
- * }
228
- * ]
229
- */
230
- events?: EventProps[];
231
- /**
232
- * The callback fired when the map changes (center, zoom, bounds).
233
- */
234
- onChange?: (options: {
235
- bounds: LatLngBounds;
236
- center: (number | undefined)[];
237
- zoom: number;
238
- }) => void;
239
- /**
240
- * The callback fired when the map is loaded.
241
- */
242
- onGoogleApiLoaded?: (props: onGoogleApiLoadedProps) => void;
243
- /**
244
- * The options to pass to the Google Maps instance.
245
- * @reference https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
246
- */
247
- options?: MapOptions;
248
- /**
249
- * The style of the map container.
250
- * @default
251
- * {
252
- * width: '100%',
253
- * height: '100%',
254
- * left: 0,
255
- * top: 0,
256
- * margin: 0,
257
- * padding: 0,
258
- * position: 'absolute'
259
- * }
260
- */
261
- style?: React__default.CSSProperties;
131
+ type MarkerAnchorPreset = 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
132
+ /**
133
+ * Which point of the marker sits on its coordinates.
134
+ * A preset, or `{ x, y }` as fractions of the marker size (`{ x: 0.5, y: 1 }` is bottom center).
135
+ */
136
+ type MarkerAnchor = MarkerAnchorPreset | {
137
+ x: number;
138
+ y: number;
139
+ };
140
+ type MarkerDragHandler = (event: Event, data: {
141
+ latLng: LatLngLiteral;
142
+ }) => void;
143
+ interface MarkerProps {
144
+ /**
145
+ * Which point of the marker sits on `lat`/`lng`.
146
+ * @default 'center'
147
+ */
148
+ anchor?: MarkerAnchor;
149
+ /** Any React content: this is your marker. */
150
+ children?: ReactNode;
151
+ /** Class name of the marker container. */
152
+ className?: string;
153
+ /**
154
+ * Collision behavior, `advanced` renderer only.
155
+ * @see https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElementOptions.collisionBehavior
156
+ */
157
+ collisionBehavior?: google.maps.CollisionBehaviorString;
158
+ /**
159
+ * Whether users can drag the marker: with mouse or touch, or from the keyboard
160
+ * (Alt + Enter, arrow keys, Enter to drop, Escape to cancel) on both renderers.
161
+ * @default false
162
+ */
163
+ draggable?: boolean;
164
+ lat: number;
165
+ lng: number;
166
+ /**
167
+ * Fired on click, and on Enter or Space when the marker has keyboard focus.
168
+ * A clickable marker becomes a focusable button named by `title`. With the `overlay` renderer,
169
+ * content that already has its own button or link keeps the focus instead.
170
+ */
171
+ onClick?: (event: Event) => void;
172
+ /** Fired repeatedly while dragging. */
173
+ onDrag?: MarkerDragHandler;
174
+ /** Fired when dragging ends. Update your `lat`/`lng` state here. */
175
+ onDragEnd?: MarkerDragHandler;
176
+ /** Fired when dragging starts. */
177
+ onDragStart?: MarkerDragHandler;
178
+ /**
179
+ * Accessible name of the marker, read by screen readers and shown as a tooltip.
180
+ * Give one to every clickable or draggable marker.
181
+ */
182
+ title?: string;
183
+ /** Stacking order. Higher values are drawn on top. */
184
+ zIndex?: number;
262
185
  }
263
- interface GoogleMapProps extends MapProps, IUseGoogleMaps {
264
- /**
265
- * The props to pass to the `div` container element.
266
- */
267
- containerProps?: React__default.HTMLAttributes<HTMLDivElement>;
268
- /**
269
- * The content to be rendered when the script fails to load.
270
- * @default 'Google Maps is on error'
271
- */
272
- errorContent?: React__default.ReactNode;
273
- /**
274
- * The content to be rendered when the script is on idle.
275
- * @default 'Google Maps is on idle'
276
- */
277
- idleContent?: React__default.ReactNode;
278
- /**
279
- * The content to be rendered while the script is loading.
280
- * @default 'Google Maps is loading'
281
- */
282
- loadingContent?: React__default.ReactNode;
283
- /**
284
- * The minimum height of the map container.
285
- * @default 'unset'
286
- */
287
- mapMinHeight?: string;
288
- /**
289
- * The Google Maps API script callback
290
- */
291
- scriptCallback?: () => void;
186
+ interface MapControlProps {
187
+ children?: ReactNode;
188
+ /** Where to place the control, for example `'TOP_RIGHT'`. */
189
+ position: keyof typeof google.maps.ControlPosition | google.maps.ControlPosition;
292
190
  }
293
-
294
- declare const GoogleMap: React.ForwardRefExoticComponent<GoogleMapProps & React.RefAttributes<HTMLDivElement>>;
295
-
296
- export { type Drag, type EventProps, type GoogleMapProps, type IUseGoogleMaps, type LatLng, type LatLngBounds, type LatLngBoundsLiteral, type LatLngLiteral, type Map, type MapContextProps, type MapMarkersProps, type MapMouseEvent, type MapOptions, type MapPanes, type MapProps, type MapsLibrary, type OverlayViewProps, type Pane, type ScriptProps, type UseScriptOptions, type UseScriptStatus, type createOverlayProps, GoogleMap as default, type onGoogleApiLoadedProps };
191
+ /**
192
+ * A Google Map. Renders `loadingContent` on the server and while the API loads, then the map.
193
+ * Put `<Marker>`, `<MapControl>` and components that use `useMap()` inside it.
194
+ */
195
+ export declare const GoogleMap: (props: GoogleMapProps) => import("react").JSX.Element;
196
+ /**
197
+ * The `google.maps.Map` instance of the closest `<GoogleMap>`, or `null` while it is loading
198
+ * (and on the server). Throws when used outside `<GoogleMap>`: use its `onLoad` prop there.
199
+ */
200
+ export declare const useMap: () => google.maps.Map | null;
201
+ /** Loading status of the Google Maps JavaScript API. Always `'loading'` on the server. */
202
+ export declare const useGoogleMapsStatus: () => GoogleMapsStatus;
203
+ /**
204
+ * Loads a Maps JavaScript API library, for example `useMapsLibrary('places')`.
205
+ * Returns `null` until it is loaded (and on the server). Works anywhere in the page,
206
+ * as soon as a `<GoogleMap>` has configured the loader.
207
+ */
208
+ export declare const useMapsLibrary: <T extends keyof google.maps.ImportLibraryMap>(name: T) => google.maps.ImportLibraryMap[T] | null;
209
+ /** Renders React content as a native map control, for example `<MapControl position="TOP_RIGHT">`. */
210
+ export declare const MapControl: ({ position, children }: MapControlProps) => import("react").ReactPortal | null;
211
+ /**
212
+ * Renders any React content at `lat`/`lng`. Must be inside `<GoogleMap>`.
213
+ * Renders nothing on the server and until the map is ready.
214
+ */
215
+ export declare const Marker: (props: MarkerProps) => import("react").ReactPortal | null;
216
+ export type { BBox, GoogleMapProps, GoogleMapsLoaderOptions, GoogleMapsStatus, LatLngLiteral, MapChangeEvent, MapControlProps, MapEventProps, MapLoadEvent, MarkerAnchor, MarkerAnchorPreset, MarkerDragHandler, MarkerProps, MarkerRenderer };