vue3-google-map 0.19.0 → 0.21.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/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # vue3-google-map
2
+
2
3
  ![Build Status](https://github.com/inocan-group/vue3-google-map/actions/workflows/build.yml/badge.svg)
3
4
  [![License](https://img.shields.io/github/license/inocan-group/vue3-google-map)](https://github.com/inocan-group/vue3-google-map/blob/develop/LICENSE)
4
5
 
@@ -6,7 +7,7 @@
6
7
 
7
8
  `vue3-google-map` offers a set of composable components for easy use of Google Maps in your Vue 3 projects.
8
9
 
9
- Note: Please refer to the [documentation site](https://vue3-google-map.netlify.app/) for rendered examples.
10
+ Note: Please refer to the [documentation site](https://vue3-google-map.com/) for rendered examples.
10
11
 
11
12
  ## Table of Contents
12
13
 
@@ -14,6 +15,7 @@ Note: Please refer to the [documentation site](https://vue3-google-map.netlify.a
14
15
  - [Installation](#installation)
15
16
  - [Your First Map](#your-first-map)
16
17
  - [Components](#components)
18
+ - [Advanced Marker](#advanced-marker)
17
19
  - [Marker](#marker)
18
20
  - [Polyline](#polyline)
19
21
  - [Polygon](#polygon)
@@ -54,37 +56,35 @@ All the map components are available on the `Vue3GoogleMap` global variable.
54
56
 
55
57
  ### Your First Map
56
58
 
57
- To construct a map using `vue3-google-map` you'll need to use the base `GoogleMap` component which receives your [Google Maps API key](https://developers.google.com/maps/documentation/javascript/get-api-key), styles (e.g. setting width and height), and any [MapOptions](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions) to configure your map ([see this](https://github.com/inocan-group/vue3-google-map/blob/develop/src/components/GoogleMap.vue#L57-L218) for all the supported `MapOptions`).
59
+ To construct a map using `vue3-google-map` you'll need to use the base `GoogleMap` component which receives your [Google Maps API key](https://developers.google.com/maps/documentation/javascript/get-api-key), styles (e.g. setting width and height), and any [MapOptions](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions) to configure your map ([see this](https://github.com/inocan-group/vue3-google-map/blob/develop/src/components/GoogleMap.vue#L36-L230) for all the supported `MapOptions`).
58
60
  Other map features can be added to your map by passing map subcomponents ([Marker](#marker), [Polyline](#polyline), [Polygon](#polygon), [Rectangle](#rectangle), [Circle](#circle), [InfoWindow](#info-window), [CustomMarker](#custom-marker), [CustomControl](#custom-control), or [MarkerCluster](#marker-cluster)) to the default slot of the `GoogleMap` component.
59
61
 
60
62
  ```vue
63
+ <script setup>
64
+ import { GoogleMap, Marker } from 'vue3-google-map'
65
+
66
+ const center = { lat: 40.689247, lng: -74.044502 }
67
+ </script>
68
+
61
69
  <template>
62
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="15">
70
+ <GoogleMap
71
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
72
+ style="width: 100%; height: 500px"
73
+ :center="center"
74
+ :zoom="15"
75
+ >
63
76
  <Marker :options="{ position: center }" />
64
77
  </GoogleMap>
65
78
  </template>
66
-
67
- <script>
68
- import { defineComponent } from "vue";
69
- import { GoogleMap, Marker } from "vue3-google-map";
70
-
71
- export default defineComponent({
72
- components: { GoogleMap, Marker },
73
- setup() {
74
- const center = { lat: 40.689247, lng: -74.044502 };
75
-
76
- return { center };
77
- },
78
- });
79
- </script>
80
79
  ```
81
80
 
82
81
  ## Components
83
82
 
84
- This library is intended to be used in a _composable_ fashion and therefore you will find yourself using nested components to build your map rather than just a complicated _inline_ format.
83
+ This library is intended to be used in a composable fashion. Therefore you will find yourself using nested components to build your map rather than just a complicated inline format.
85
84
 
86
85
  The main mapping component is `GoogleMap`, however the following components are available at your disposal:
87
86
 
87
+ - [AdvancedMarker](#advanced-marker)
88
88
  - [Marker](#marker)
89
89
  - [Polyline](#polyline)
90
90
  - [Polygon](#polygon)
@@ -95,35 +95,70 @@ The main mapping component is `GoogleMap`, however the following components are
95
95
  - [CustomControl](#custom-control)
96
96
  - [MarkerCluster](#marker-cluster)
97
97
 
98
- ### Marker
98
+ ### Advanced Marker
99
99
 
100
- Use the `Marker` component to draw markers, drop pins or any custom icons on a map.
100
+ Use the `AdvancedMarker` component to draw markers, drop pins or any custom icons on a map. `AdvancedMarker` is the new version offered by google when deprecated the `Marker` component ([read more here](https://developers.google.com/maps/deprecations#googlemapsmarker_in_the_deprecated_as_of_february_2024)).
101
+
102
+ In order to use the `AdvancedMarker` component is necessary to specify a MapId on declaring the `GoogleMap` component ([see more here](https://developers.google.com/maps/documentation/javascript/advanced-markers/start#create_a_map_id)).
101
103
 
102
104
  #### Options
103
105
 
104
- You can pass a [MarkerOptions](https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerOptions) object to the `options` prop to configure your marker.
106
+ You can pass a [AdvancedMarkerElementOptions](https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElementOptions) object to the `options` prop to configure your marker.
107
+
108
+ You can also pass a [PinElementOptions interface](https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#PinElementOptions) object to custumize pin used by the marker.
105
109
 
106
110
  ```vue
111
+ <script setup>
112
+ import { GoogleMap, AdvancedMarker } from 'vue3-google-map'
113
+
114
+ const center = { lat: 40.689247, lng: -74.044502 }
115
+ const markerOptions = { position: center, label: 'L', title: 'LADY LIBERTY' }
116
+ const pinOptions = { background: '#FBBC04' }
117
+ </script>
118
+
107
119
  <template>
108
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="15">
109
- <Marker :options="markerOptions" />
120
+ <GoogleMap
121
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
122
+ mapId="DEMO_MAP_ID"
123
+ style="width: 100%; height: 500px"
124
+ :center="center"
125
+ :zoom="15"
126
+ >
127
+ <AdvancedMarker :options="markerOptions" :pin-options="pinOptions"/>
110
128
  </GoogleMap>
111
129
  </template>
130
+ ```
131
+
132
+ #### Events
112
133
 
113
- <script>
114
- import { defineComponent } from "vue";
115
- import { GoogleMap, Marker } from "vue3-google-map";
134
+ You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElement-Events) on the `AdvancedMarker` component.
116
135
 
117
- export default defineComponent({
118
- components: { GoogleMap, Marker },
119
- setup() {
120
- const center = { lat: 40.689247, lng: -74.044502 };
121
- const markerOptions = { position: center, label: "L", title: "LADY LIBERTY" };
136
+ ### Marker
122
137
 
123
- return { center, markerOptions };
124
- },
125
- });
138
+ Use the `Marker` component to draw markers, drop pins or any custom icons on a map.
139
+
140
+ #### Options
141
+
142
+ You can pass a [MarkerOptions](https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerOptions) object to the `options` prop to configure your marker.
143
+
144
+ ```vue
145
+ <script setup>
146
+ import { GoogleMap, Marker } from 'vue3-google-map'
147
+
148
+ const center = { lat: 40.689247, lng: -74.044502 }
149
+ const markerOptions = { position: center, label: 'L', title: 'LADY LIBERTY' }
126
150
  </script>
151
+
152
+ <template>
153
+ <GoogleMap
154
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
155
+ style="width: 100%; height: 500px"
156
+ :center="center"
157
+ :zoom="15"
158
+ >
159
+ <Marker :options="markerOptions" />
160
+ </GoogleMap>
161
+ </template>
127
162
  ```
128
163
 
129
164
  #### Events
@@ -139,38 +174,35 @@ Use the `Polyline` component to draw paths and arbitrary shapes on a map.
139
174
  You can pass a [PolylineOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#PolylineOptions) object to the `options` prop to configure your polyline.
140
175
 
141
176
  ```vue
177
+ <script setup>
178
+ import { GoogleMap, Polyline } from 'vue3-google-map'
179
+
180
+ const center = { lat: 0, lng: -180 }
181
+ const flightPlanCoordinates = [
182
+ { lat: 37.772, lng: -122.214 },
183
+ { lat: 21.291, lng: -157.821 },
184
+ { lat: -18.142, lng: 178.431 },
185
+ { lat: -27.467, lng: 153.027 },
186
+ ]
187
+ const flightPath = {
188
+ path: flightPlanCoordinates,
189
+ geodesic: true,
190
+ strokeColor: '#FF0000',
191
+ strokeOpacity: 1.0,
192
+ strokeWeight: 2,
193
+ }
194
+ </script>
195
+
142
196
  <template>
143
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="3">
197
+ <GoogleMap
198
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
199
+ style="width: 100%; height: 500px"
200
+ :center="center"
201
+ :zoom="3"
202
+ >
144
203
  <Polyline :options="flightPath" />
145
204
  </GoogleMap>
146
205
  </template>
147
-
148
- <script>
149
- import { defineComponent } from "vue";
150
- import { GoogleMap, Polyline } from "vue3-google-map";
151
-
152
- export default defineComponent({
153
- components: { GoogleMap, Polyline },
154
- setup() {
155
- const center = { lat: 0, lng: -180 };
156
- const flightPlanCoordinates = [
157
- { lat: 37.772, lng: -122.214 },
158
- { lat: 21.291, lng: -157.821 },
159
- { lat: -18.142, lng: 178.431 },
160
- { lat: -27.467, lng: 153.027 },
161
- ];
162
- const flightPath = {
163
- path: flightPlanCoordinates,
164
- geodesic: true,
165
- strokeColor: "#FF0000",
166
- strokeOpacity: 1.0,
167
- strokeWeight: 2,
168
- };
169
-
170
- return { center, flightPath };
171
- },
172
- });
173
- </script>
174
206
  ```
175
207
 
176
208
  #### Events
@@ -186,39 +218,36 @@ Use the `Polygon` component to draw polgons (arbitrary number of sides) on a map
186
218
  You can pass a [PolylgonOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#PolygonOptions) object to the `options` prop to configure your polyline.
187
219
 
188
220
  ```vue
221
+ <script setup>
222
+ import { GoogleMap, Polygon } from 'vue3-google-map'
223
+
224
+ const center = { lat: 24.886, lng: -70.268 }
225
+ const triangleCoords = [
226
+ { lat: 25.774, lng: -80.19 },
227
+ { lat: 18.466, lng: -66.118 },
228
+ { lat: 32.321, lng: -64.757 },
229
+ { lat: 25.774, lng: -80.19 },
230
+ ]
231
+ const bermudaTriangle = {
232
+ paths: triangleCoords,
233
+ strokeColor: '#FF0000',
234
+ strokeOpacity: 0.8,
235
+ strokeWeight: 2,
236
+ fillColor: '#FF0000',
237
+ fillOpacity: 0.35,
238
+ }
239
+ </script>
240
+
189
241
  <template>
190
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="5">
242
+ <GoogleMap
243
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
244
+ style="width: 100%; height: 500px"
245
+ :center="center"
246
+ :zoom="5"
247
+ >
191
248
  <Polygon :options="bermudaTriangle" />
192
249
  </GoogleMap>
193
250
  </template>
194
-
195
- <script>
196
- import { defineComponent } from "vue";
197
- import { GoogleMap, Polygon } from "vue3-google-map";
198
-
199
- export default defineComponent({
200
- components: { GoogleMap, Polygon },
201
- setup() {
202
- const center = { lat: 24.886, lng: -70.268 };
203
- const triangleCoords = [
204
- { lat: 25.774, lng: -80.19 },
205
- { lat: 18.466, lng: -66.118 },
206
- { lat: 32.321, lng: -64.757 },
207
- { lat: 25.774, lng: -80.19 },
208
- ];
209
- const bermudaTriangle = {
210
- paths: triangleCoords,
211
- strokeColor: "#FF0000",
212
- strokeOpacity: 0.8,
213
- strokeWeight: 2,
214
- fillColor: "#FF0000",
215
- fillOpacity: 0.35,
216
- };
217
-
218
- return { center, bermudaTriangle };
219
- },
220
- });
221
- </script>
222
251
  ```
223
252
 
224
253
  #### Events
@@ -234,6 +263,25 @@ Use the `Rectangle` component to draw simple rectangles on a map.
234
263
  You can pass a [RectangleOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#RectangleOptions) object to the `options` prop to configure your rectangle.
235
264
 
236
265
  ```vue
266
+ <script setup>
267
+ import { GoogleMap, Rectangle } from 'vue3-google-map'
268
+
269
+ const center = { lat: 33.678, lng: -116.243 }
270
+ const rectangle = {
271
+ strokeColor: '#FF0000',
272
+ strokeOpacity: 0.8,
273
+ strokeWeight: 2,
274
+ fillColor: '#FF0000',
275
+ fillOpacity: 0.35,
276
+ bounds: {
277
+ north: 33.685,
278
+ south: 33.671,
279
+ east: -116.234,
280
+ west: -116.251,
281
+ },
282
+ }
283
+ </script>
284
+
237
285
  <template>
238
286
  <GoogleMap
239
287
  api-key="YOUR_GOOGLE_MAPS_API_KEY"
@@ -245,33 +293,6 @@ You can pass a [RectangleOptions](https://developers.google.com/maps/documentati
245
293
  <Rectangle :options="rectangle" />
246
294
  </GoogleMap>
247
295
  </template>
248
-
249
- <script>
250
- import { defineComponent } from "vue";
251
- import { GoogleMap, Marker } from "vue3-google-map";
252
-
253
- export default defineComponent({
254
- components: { GoogleMap, Marker },
255
- setup() {
256
- const center = { lat: 33.678, lng: -116.243 };
257
- const rectangle = {
258
- strokeColor: "#FF0000",
259
- strokeOpacity: 0.8,
260
- strokeWeight: 2,
261
- fillColor: "#FF0000",
262
- fillOpacity: 0.35,
263
- bounds: {
264
- north: 33.685,
265
- south: 33.671,
266
- east: -116.234,
267
- west: -116.251,
268
- },
269
- };
270
-
271
- return { center, rectangle };
272
- },
273
- });
274
- </script>
275
296
  ```
276
297
 
277
298
  #### Events
@@ -287,6 +308,44 @@ Use the `Circle` component to draw circles on a map.
287
308
  You can pass a [CircleOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#CircleOptions) object to the `options` prop to configure your circle.
288
309
 
289
310
  ```vue
311
+ <script setup>
312
+ import { GoogleMap, Circle } from 'vue3-google-map'
313
+
314
+ const center = { lat: 37.09, lng: -95.712 }
315
+ const cities = {
316
+ chicago: {
317
+ center: { lat: 41.878, lng: -87.629 },
318
+ population: 2714856,
319
+ },
320
+ newyork: {
321
+ center: { lat: 40.714, lng: -74.005 },
322
+ population: 8405837,
323
+ },
324
+ losangeles: {
325
+ center: { lat: 34.052, lng: -118.243 },
326
+ population: 3857799,
327
+ },
328
+ vancouver: {
329
+ center: { lat: 49.25, lng: -123.1 },
330
+ population: 603502,
331
+ },
332
+ }
333
+
334
+ const circles = {}
335
+
336
+ for (const key in cities) {
337
+ circles[key] = {
338
+ center: cities[key].center,
339
+ radius: Math.sqrt(cities[key].population) * 100,
340
+ strokeColor: '#FF0000',
341
+ strokeOpacity: 0.8,
342
+ strokeWeight: 2,
343
+ fillColor: '#FF0000',
344
+ fillOpacity: 0.35,
345
+ }
346
+ }
347
+ </script>
348
+
290
349
  <template>
291
350
  <GoogleMap
292
351
  api-key="YOUR_GOOGLE_MAPS_API_KEY"
@@ -298,52 +357,6 @@ You can pass a [CircleOptions](https://developers.google.com/maps/documentation/
298
357
  <Circle v-for="circle in circles" :options="circle" />
299
358
  </GoogleMap>
300
359
  </template>
301
-
302
- <script>
303
- import { defineComponent } from "vue";
304
- import { GoogleMap, Circle } from "vue3-google-map";
305
-
306
- export default defineComponent({
307
- components: { GoogleMap, Circle },
308
- setup() {
309
- const center = { lat: 37.09, lng: -95.712 };
310
- const cities = {
311
- chicago: {
312
- center: { lat: 41.878, lng: -87.629 },
313
- population: 2714856,
314
- },
315
- newyork: {
316
- center: { lat: 40.714, lng: -74.005 },
317
- population: 8405837,
318
- },
319
- losangeles: {
320
- center: { lat: 34.052, lng: -118.243 },
321
- population: 3857799,
322
- },
323
- vancouver: {
324
- center: { lat: 49.25, lng: -123.1 },
325
- population: 603502,
326
- },
327
- };
328
-
329
- const circles = {};
330
-
331
- for (const key in cities) {
332
- circles[key] = {
333
- center: cities[key].center,
334
- radius: Math.sqrt(cities[key].population) * 100,
335
- strokeColor: "#FF0000",
336
- strokeOpacity: 0.8,
337
- strokeWeight: 2,
338
- fillColor: "#FF0000",
339
- fillOpacity: 0.35,
340
- };
341
- }
342
-
343
- return { center, circles };
344
- },
345
- });
346
- </script>
347
360
  ```
348
361
 
349
362
  #### Events
@@ -359,26 +372,25 @@ Use the `InfoWindow` component to display content in a popup window above the ma
359
372
  You can pass an [InfoWindowOptions](https://developers.google.com/maps/documentation/javascript/reference#InfoWindowOptions) object to the `options` prop to configure your info window. Note that you can optionally pass your content to the default slot of the `InfoWindow` component.
360
373
 
361
374
  ```vue
375
+ <script setup>
376
+ import { GoogleMap, InfoWindow } from 'vue3-google-map'
377
+
378
+ const center = { lat: -33.9, lng: 151.1 }
379
+ </script>
380
+
362
381
  <template>
363
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="10">
382
+ <GoogleMap
383
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
384
+ style="width: 100%; height: 500px"
385
+ :center="center"
386
+ :zoom="10"
387
+ >
364
388
  <InfoWindow :options="{ position: center, content: 'Hello World!' }" />
365
- <InfoWindow :options="{ position: { lat: center.lat, lng: 150.8 } }"> Content passed through slot </InfoWindow>
389
+ <InfoWindow :options="{ position: { lat: center.lat, lng: 150.8 } }">
390
+ Content passed through slot
391
+ </InfoWindow>
366
392
  </GoogleMap>
367
393
  </template>
368
-
369
- <script>
370
- import { defineComponent } from "vue";
371
- import { GoogleMap, InfoWindow } from "vue3-google-map";
372
-
373
- export default defineComponent({
374
- components: { GoogleMap, InfoWindow },
375
- setup() {
376
- const center = { lat: -33.9, lng: 151.1 };
377
-
378
- return { center };
379
- },
380
- });
381
- </script>
382
394
  ```
383
395
 
384
396
  #### Use with Marker
@@ -386,49 +398,44 @@ export default defineComponent({
386
398
  You can nest the `InfoWindow` component inside the `Marker` component to display an info window when the marker is clicked.
387
399
 
388
400
  ```vue
401
+ <script setup>
402
+ import { GoogleMap, Marker, InfoWindow } from 'vue3-google-map'
403
+
404
+ const center = { lat: -25.363, lng: 131.044 }
405
+ </script>
406
+
389
407
  <template>
390
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="4">
408
+ <GoogleMap
409
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
410
+ style="width: 100%; height: 500px"
411
+ :center="center"
412
+ :zoom="4"
413
+ >
391
414
  <Marker :options="{ position: center }">
392
415
  <InfoWindow>
393
416
  <div id="content">
394
417
  <div id="siteNotice"></div>
395
418
  <h1 id="firstHeading" class="firstHeading">Uluru</h1>
396
419
  <div id="bodyContent">
397
- <p>
398
- <b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large sandstone rock formation in the southern
399
- part of the Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) south west of the
400
- nearest large town, Alice Springs; 450&#160;km (280&#160;mi) by road. Kata Tjuta and Uluru are the two
401
- major features of the Uluru - Kata Tjuta National Park. Uluru is sacred to the Pitjantjatjara and
402
- Yankunytjatjara, the Aboriginal people of the area. It has many springs, waterholes, rock caves and
403
- ancient paintings. Uluru is listed as a World Heritage Site.
404
- </p>
405
- <p>
406
- Attribution: Uluru,
407
- <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">
408
- https://en.wikipedia.org/w/index.php?title=Uluru</a
409
- >
410
- (last visited June 22, 2009).
411
- </p>
420
+ <p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large
421
+ sandstone rock formation in the southern part of the
422
+ Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi)
423
+ south west of the nearest large town, Alice Springs; 450&#160;km
424
+ (280&#160;mi) by road. Kata Tjuta and Uluru are the two major
425
+ features of the Uluru - Kata Tjuta National Park. Uluru is
426
+ sacred to the Pitjantjatjara and Yankunytjatjara, the
427
+ Aboriginal people of the area. It has many springs, waterholes,
428
+ rock caves and ancient paintings. Uluru is listed as a World
429
+ Heritage Site.</p>
430
+ <p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">
431
+ https://en.wikipedia.org/w/index.php?title=Uluru</a>
432
+ (last visited June 22, 2009).</p>
412
433
  </div>
413
434
  </div>
414
435
  </InfoWindow>
415
436
  </Marker>
416
437
  </GoogleMap>
417
438
  </template>
418
-
419
- <script>
420
- import { defineComponent } from "vue";
421
- import { GoogleMap, Marker, InfoWindow } from "vue3-google-map";
422
-
423
- export default defineComponent({
424
- components: { GoogleMap, Marker, InfoWindow },
425
- setup() {
426
- const center = { lat: -25.363, lng: 131.044 };
427
-
428
- return { center };
429
- },
430
- });
431
- </script>
432
439
  ```
433
440
 
434
441
  #### Open and close the Info Window
@@ -436,37 +443,32 @@ export default defineComponent({
436
443
  You can use `v-model` to manage the state of the info window programmatically or to know whether it's open or closed
437
444
 
438
445
  ```vue
446
+ <script setup>
447
+ import { ref, watch } from 'vue';
448
+ import { GoogleMap, Marker, InfoWindow } from 'vue3-google-map';
449
+
450
+ const center = { lat: -25.363, lng: 131.044 };
451
+ const infowindow = ref(true); // Will be open when mounted
452
+
453
+ watch(infowindow, (v) => {
454
+ alert('infowindow has been ' + (v ? 'opened' : 'closed'));
455
+ });
456
+ </script>
457
+
439
458
  <template>
440
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="4">
459
+ <GoogleMap
460
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
461
+ style="width: 100%; height: 500px"
462
+ :center="center"
463
+ :zoom="4"
464
+ >
441
465
  <Marker :options="{ position: center }">
442
466
  <InfoWindow v-model="infowindow">
443
- <div id="content">
444
- This is the infowindow content
445
- </div>
467
+ <div id="content">This is the infowindow content</div>
446
468
  </InfoWindow>
447
469
  </Marker>
448
470
  </GoogleMap>
449
471
  </template>
450
-
451
- <script>
452
- import { defineComponent } from "vue";
453
- import { GoogleMap, Marker, InfoWindow } from "vue3-google-map";
454
-
455
- export default defineComponent({
456
- components: { GoogleMap, Marker, InfoWindow },
457
- setup() {
458
- const center = { lat: -25.363, lng: 131.044 };
459
- const infowindow = ref(true); // Will be opened when mounted
460
-
461
- return { center, infowindow };
462
- },
463
- watch: {
464
- infowindow(v) {
465
- alert('infowindow has been ' + (v ? 'opened' : 'closed'))
466
- }
467
- }
468
- });
469
- </script>
470
472
  ```
471
473
 
472
474
  #### Events
@@ -487,8 +489,13 @@ Regular markers can be customized a great deal but if you need to you can use th
487
489
  | `offsetY` | `number` | Vertical offset from the `position` point. |
488
490
  | `zIndex` | `number` | `z-index` value of the marker. |
489
491
 
490
-
491
492
  ```vue
493
+ <script setup>
494
+ import { GoogleMap, CustomMarker } from 'vue3-google-map'
495
+
496
+ const center = { lat: 52.36834, lng: 4.88635 }
497
+ </script>
498
+
492
499
  <template>
493
500
  <GoogleMap
494
501
  api-key="YOUR_GOOGLE_MAPS_API_KEY"
@@ -504,20 +511,6 @@ Regular markers can be customized a great deal but if you need to you can use th
504
511
  </CustomMarker>
505
512
  </GoogleMap>
506
513
  </template>
507
-
508
- <script>
509
- import { defineComponent } from 'vue'
510
- import { GoogleMap, CustomMarker } from 'vue3-google-map'
511
-
512
- export default defineComponent({
513
- components: { GoogleMap, CustomMarker },
514
- setup() {
515
- const center = { lat: 52.36834, lng: 4.88635 }
516
-
517
- return { center }
518
- },
519
- })
520
- </script>
521
514
  ```
522
515
 
523
516
  ### Custom Control
@@ -534,29 +527,26 @@ You can define the markup of your custom control in the `default` slot of the `C
534
527
  Refer to the [Google Maps documentation](https://developers.google.com/maps/documentation/javascript/controls#CustomControls) on custom controls positioning.
535
528
 
536
529
  ```vue
530
+ <script setup>
531
+ import { GoogleMap, CustomControl } from 'vue3-google-map'
532
+
533
+ const center = { lat: 35, lng: -95 }
534
+ const sayHi = () => alert('Hi!')
535
+ </script>
536
+
537
537
  <template>
538
- <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="13">
538
+ <GoogleMap
539
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
540
+ style="width: 100%; height: 500px"
541
+ :center="center"
542
+ :zoom="13"
543
+ >
539
544
  <CustomControl position="BOTTOM_CENTER">
540
545
  <button class="custom-btn" @click="sayHi">👋</button>
541
546
  </CustomControl>
542
547
  </GoogleMap>
543
548
  </template>
544
549
 
545
- <script>
546
- import { defineComponent } from "vue";
547
- import { GoogleMap, CustomControl } from "vue3-google-map";
548
-
549
- export default defineComponent({
550
- components: { GoogleMap, CustomControl },
551
- setup() {
552
- const center = { lat: 35, lng: -95 };
553
- const sayHi = () => alert("Hi!");
554
-
555
- return { center, sayHi };
556
- },
557
- });
558
- </script>
559
-
560
550
  <style scoped>
561
551
  .custom-btn {
562
552
  box-sizing: border-box;
@@ -587,6 +577,38 @@ Use the `MarkerCluster` component to display a large number of markers on a map.
587
577
  Simply pass your `Marker`/`CustomMarker`(s) in the `default` slot of the `MarkerCluster` component.
588
578
 
589
579
  ```vue
580
+ <script setup>
581
+ import { GoogleMap, Marker, MarkerCluster } from 'vue3-google-map'
582
+
583
+ const center = { lat: -28.024, lng: 140.887 }
584
+
585
+ const locations = [
586
+ { lat: -31.56391, lng: 147.154312 },
587
+ { lat: -33.718234, lng: 150.363181 },
588
+ { lat: -33.727111, lng: 150.371124 },
589
+ { lat: -33.848588, lng: 151.209834 },
590
+ { lat: -33.851702, lng: 151.216968 },
591
+ { lat: -34.671264, lng: 150.863657 },
592
+ { lat: -35.304724, lng: 148.662905 },
593
+ { lat: -36.817685, lng: 175.699196 },
594
+ { lat: -36.828611, lng: 175.790222 },
595
+ { lat: -37.75, lng: 145.116667 },
596
+ { lat: -37.759859, lng: 145.128708 },
597
+ { lat: -37.765015, lng: 145.133858 },
598
+ { lat: -37.770104, lng: 145.143299 },
599
+ { lat: -37.7737, lng: 145.145187 },
600
+ { lat: -37.774785, lng: 145.137978 },
601
+ { lat: -37.819616, lng: 144.968119 },
602
+ { lat: -38.330766, lng: 144.695692 },
603
+ { lat: -39.927193, lng: 175.053218 },
604
+ { lat: -41.330162, lng: 174.865694 },
605
+ { lat: -42.734358, lng: 147.439506 },
606
+ { lat: -42.734358, lng: 147.501315 },
607
+ { lat: -42.735258, lng: 147.438 },
608
+ { lat: -43.999792, lng: 170.463352 },
609
+ ]
610
+ </script>
611
+
590
612
  <template>
591
613
  <GoogleMap
592
614
  api-key="YOUR_GOOGLE_MAPS_API_KEY"
@@ -595,50 +617,14 @@ Simply pass your `Marker`/`CustomMarker`(s) in the `default` slot of the `Marker
595
617
  :zoom="3"
596
618
  >
597
619
  <MarkerCluster>
598
- <Marker v-for="(location, i) in locations" :options="{ position: location }" :key="i" />
620
+ <Marker
621
+ v-for="(location, i) in locations"
622
+ :key="i"
623
+ :options="{ position: location }"
624
+ />
599
625
  </MarkerCluster>
600
626
  </GoogleMap>
601
627
  </template>
602
-
603
- <script>
604
- import { defineComponent } from 'vue'
605
- import { GoogleMap, Marker, MarkerCluster } from 'vue3-google-map'
606
-
607
- export default defineComponent({
608
- components: { GoogleMap, Marker, MarkerCluster },
609
- setup() {
610
- const center = { lat: -28.024, lng: 140.887 }
611
-
612
- const locations = [
613
- { lat: -31.56391, lng: 147.154312 },
614
- { lat: -33.718234, lng: 150.363181 },
615
- { lat: -33.727111, lng: 150.371124 },
616
- { lat: -33.848588, lng: 151.209834 },
617
- { lat: -33.851702, lng: 151.216968 },
618
- { lat: -34.671264, lng: 150.863657 },
619
- { lat: -35.304724, lng: 148.662905 },
620
- { lat: -36.817685, lng: 175.699196 },
621
- { lat: -36.828611, lng: 175.790222 },
622
- { lat: -37.75, lng: 145.116667 },
623
- { lat: -37.759859, lng: 145.128708 },
624
- { lat: -37.765015, lng: 145.133858 },
625
- { lat: -37.770104, lng: 145.143299 },
626
- { lat: -37.7737, lng: 145.145187 },
627
- { lat: -37.774785, lng: 145.137978 },
628
- { lat: -37.819616, lng: 144.968119 },
629
- { lat: -38.330766, lng: 144.695692 },
630
- { lat: -39.927193, lng: 175.053218 },
631
- { lat: -41.330162, lng: 174.865694 },
632
- { lat: -42.734358, lng: 147.439506 },
633
- { lat: -42.734358, lng: 147.501315 },
634
- { lat: -42.735258, lng: 147.438 },
635
- { lat: -43.999792, lng: 170.463352 },
636
- ]
637
-
638
- return { center, locations }
639
- },
640
- })
641
- </script>
642
628
  ```
643
629
 
644
630
  #### Options
@@ -658,6 +644,30 @@ Use the `HeatmapLayer` component to depict the intensity of data at geographical
658
644
  You can pass a [HeatmapLayerOptions](https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayerOptions) object to the `options` prop to configure your heatmap layer. Note that for convenience you can use [LatLngLiteral](https://developers.google.com/maps/documentation/javascript/reference/coordinates#LatLngLiteral)s if you wish for the locations.
659
645
 
660
646
  ```vue
647
+ <script setup>
648
+ import { GoogleMap, HeatmapLayer } from 'vue3-google-map'
649
+
650
+ const sanFrancisco = { lat: 37.774546, lng: -122.433523 }
651
+
652
+ const heatmapData = [
653
+ { location: { lat: 37.782, lng: -122.447 }, weight: 0.5 },
654
+ { lat: 37.782, lng: -122.445 },
655
+ { location: { lat: 37.782, lng: -122.443 }, weight: 2 },
656
+ { location: { lat: 37.782, lng: -122.441 }, weight: 3 },
657
+ { location: { lat: 37.782, lng: -122.439 }, weight: 2 },
658
+ { lat: 37.782, lng: -122.437 },
659
+ { location: { lat: 37.782, lng: -122.435 }, weight: 0.5 },
660
+
661
+ { location: { lat: 37.785, lng: -122.447 }, weight: 3 },
662
+ { location: { lat: 37.785, lng: -122.445 }, weight: 2 },
663
+ { lat: 37.785, lng: -122.443 },
664
+ { location: { lat: 37.785, lng: -122.441 }, weight: 0.5 },
665
+ { lat: 37.785, lng: -122.439 },
666
+ { location: { lat: 37.785, lng: -122.437 }, weight: 2 },
667
+ { location: { lat: 37.785, lng: -122.435 }, weight: 3 },
668
+ ]
669
+ </script>
670
+
661
671
  <template>
662
672
  <GoogleMap
663
673
  api-key="YOUR_GOOGLE_MAPS_API_KEY"
@@ -669,142 +679,111 @@ You can pass a [HeatmapLayerOptions](https://developers.google.com/maps/document
669
679
  <HeatmapLayer :options="{ data: heatmapData }" />
670
680
  </GoogleMap>
671
681
  </template>
672
-
673
- <script>
674
- import { defineComponent } from "vue";
675
- import { GoogleMap, HeatmapLayer } from "vue3-google-map";
676
-
677
- export default defineComponent({
678
- components: { GoogleMap, HeatmapLayer },
679
- setup() {
680
- const sanFrancisco = { lat: 37.774546, lng: -122.433523 }
681
-
682
- const heatmapData = [
683
- { location: { lat: 37.782, lng: -122.447 }, weight: 0.5 },
684
- { lat: 37.782, lng: -122.445 },
685
- { location: { lat: 37.782, lng: -122.443 }, weight: 2 },
686
- { location: { lat: 37.782, lng: -122.441 }, weight: 3 },
687
- { location: { lat: 37.782, lng: -122.439 }, weight: 2 },
688
- { lat: 37.782, lng: -122.437 },
689
- { location: { lat: 37.782, lng: -122.435 }, weight: 0.5 },
690
-
691
- { location: { lat: 37.785, lng: -122.447 }, weight: 3 },
692
- { location: { lat: 37.785, lng: -122.445 }, weight: 2 },
693
- { lat: 37.785, lng: -122.443 },
694
- { location: { lat: 37.785, lng: -122.441 }, weight: 0.5 },
695
- { lat: 37.785, lng: -122.439 },
696
- { location: { lat: 37.785, lng: -122.437 }, weight: 2 },
697
- { location: { lat: 37.785, lng: -122.435 }, weight: 3 },
698
- ];
699
-
700
- return {
701
- sanFrancisco,
702
- heatmapData,
703
- }
704
- },
705
- });
706
- </script>
707
682
  ```
708
683
 
709
684
  ## Advanced Usage
710
685
 
711
- The basic components that `vue3-google-map` provides are fully reactive and will get you pretty far. Should you need to access the Google Maps API, however, the `GoogleMaps` component exposes the following:
686
+ The basic components that `vue3-google-map` provides are fully reactive and will get you pretty far. Should you need to access the Google Maps API, however, the `GoogleMap` component exposes the following:
712
687
 
713
688
  - `ready`: A boolean indicating when the Google Maps script has been loaded. By this point the map instance has been created, the API is ready for use and event listeners have been set up on the map.
714
689
  - `map`: The [Map](https://developers.google.com/maps/documentation/javascript/reference/map#Map) class instance.
715
690
  - `api`: The [Google Maps API](https://developers.google.com/maps/documentation/javascript/reference).
716
691
  - `mapTilesLoaded`: A boolean indicating when the map tiles have been fully loaded.
717
692
 
718
- Some usage patterns:
693
+ In addition, most of the subcomponents expose their instance should you need it:
694
+
695
+ - `Marker` exposes `marker` (a [Marker](https://developers.google.com/maps/documentation/javascript/reference/marker#Marker) class instance).
696
+ - `Polyline` exposes `polyline` (a [Polyline](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polyline) class instance).
697
+ - `Polygon` exposes `polygon` (a [Polygon](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polygon) class instance).
698
+ - `Rectangle` exposes `rectangle` (a [Rectangle](https://developers.google.com/maps/documentation/javascript/reference/polygon#Rectangle) class instance).
699
+ - `Circle` exposes `circle` (a [Circle](https://developers.google.com/maps/documentation/javascript/reference/polygon#Circle) class instance).
700
+ - `InfoWindow` exposes `infoWindow` (an [InfoWindow](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow) class instance).
701
+ - `MarkerCluster` exposes `markerCluster` (a [MarkerClusterer](https://googlemaps.github.io/js-markerclusterer/classes/MarkerClusterer.html) class instance).
702
+ - `HeatmapLayer` exposes `heatmapLayer` (a [HeatmapLayer](https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayer) class instance).
703
+
704
+ ### Usage Patterns
719
705
 
720
706
  ```vue
707
+ <script setup>
708
+ import { ref, computed, watch } from 'vue'
709
+ import { GoogleMap } from 'vue3-google-map'
710
+
711
+ const mapRef = ref(null)
712
+
713
+ // First pattern: compute some value using the API or map instance when "ready"
714
+ const markerIcon = computed(() => mapRef.value?.ready
715
+ ? {
716
+ url: /* icon image url */,
717
+ scaledSize: new mapRef.value.api.Size(20, 20)
718
+ }
719
+ : null)
720
+
721
+ // Second pattern: watch for "ready" then do something with the API or map instance
722
+ watch(() => mapRef.value?.ready, (ready) => {
723
+ if (!ready) return
724
+
725
+ // do something with the api using `mapRef.value.api`
726
+ // or with the map instance using `mapRef.value.map`
727
+ })
728
+ </script>
729
+
721
730
  <template>
722
731
  <GoogleMap ref="mapRef">
723
732
  <template #default="{ ready, api, map, mapTilesLoaded }">
724
- <!-- First pattern: Here you have access to the API and map instance.
733
+ <!-- Third pattern: Here you have access to the API and map instance.
725
734
  "ready" is a boolean that indicates when the Google Maps script
726
735
  has been loaded and the api and map instance are ready to be used -->
727
736
  </template>
728
737
  </GoogleMap>
729
738
  </template>
739
+ ```
730
740
 
731
- <script>
732
- import { defineComponent, ref, computed, watch } from 'vue'
733
- import { GoogleMap } from 'vue3-google-map'
734
-
735
- export default defineComponent({
736
- components: { GoogleMap },
737
- setup() {
738
- const mapRef = ref(null)
741
+ Example:
739
742
 
740
- // Second pattern: compute some value using the API or map instance when "ready"
741
- const markerIcon = computed(() => mapRef.value?.ready
742
- ? {
743
- url: /* icon image url */,
744
- scaledSize: new mapRef.value.api.Size(20, 20)
745
- }
746
- : null)
743
+ ```vue
744
+ <script setup>
745
+ import { ref, computed, watch } from 'vue'
746
+ import { GoogleMap } from 'vue3-google-map'
747
747
 
748
- // Third pattern: watch for "ready" then do something with the API or map instance
749
- watch(() => mapRef.value?.ready, (ready) => {
750
- if (!ready) return
748
+ const mapRef = ref(null)
749
+ const center = { lat: 0, lng: 0 }
750
+
751
+ const _lng = ref(0)
752
+ const lng = computed({
753
+ get: () => _lng.value,
754
+ set: v => {
755
+ if (!Number.isFinite(v)) {
756
+ _lng.value = 0
757
+ } else if (v > 180) {
758
+ _lng.value = 180
759
+ } else if (v < -180) {
760
+ _lng.value = -180
761
+ } else {
762
+ _lng.value = v
763
+ }
764
+ },
765
+ })
751
766
 
752
- // do something with the api using `mapRef.value.api`
753
- // or with the map instance using `mapRef.value.map`
754
- })
767
+ watch([() => mapRef.value?.ready, lng], ([ready, lng]) => {
768
+ if (!ready)
769
+ return
755
770
 
756
- return { mapRef }
757
- },
771
+ mapRef.value.map.panTo({ lat: 0, lng })
758
772
  })
759
773
  </script>
760
- ```
761
-
762
- Example:
763
774
 
764
- ```vue
765
775
  <template>
766
- <GoogleMap ref="mapRef" api-key="YOUR_GOOGLE_MAPS_API_KEY" class="map" :center="center" :zoom="2" />
776
+ <GoogleMap
777
+ ref="mapRef"
778
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
779
+ class="map"
780
+ :center="center"
781
+ :zoom="2"
782
+ />
767
783
  <label for="lng">Longitude</label>
768
784
  <input v-model.number="lng" id="lng" type="number" min="-180" max="180" step="10" />
769
785
  </template>
770
786
 
771
- <script>
772
- import { defineComponent, ref, computed, watch } from "vue";
773
- import { GoogleMap } from "vue3-google-map";
774
-
775
- export default defineComponent({
776
- components: { GoogleMap },
777
- setup() {
778
- const mapRef = ref(null);
779
- const center = { lat: 0, lng: 0 };
780
-
781
- const _lng = ref(0);
782
- const lng = computed({
783
- get: () => _lng.value,
784
- set: (v) => {
785
- if (!Number.isFinite(v)) {
786
- _lng.value = 0;
787
- } else if (v > 180) {
788
- _lng.value = 180;
789
- } else if (v < -180) {
790
- _lng.value = -180;
791
- } else {
792
- _lng.value = v;
793
- }
794
- },
795
- });
796
-
797
- watch(lng, () => {
798
- if (mapRef.value?.ready) {
799
- mapRef.value.map.panTo({ lat: 0, lng: lng.value });
800
- }
801
- });
802
-
803
- return { mapRef, center, lng };
804
- },
805
- });
806
- </script>
807
-
808
787
  <style scoped>
809
788
  .map {
810
789
  position: relative;
@@ -814,7 +793,7 @@ export default defineComponent({
814
793
 
815
794
  .map::after {
816
795
  position: absolute;
817
- content: "";
796
+ content: '';
818
797
  width: 1px;
819
798
  height: 100%;
820
799
  top: 0;
@@ -822,23 +801,50 @@ export default defineComponent({
822
801
  background: red;
823
802
  }
824
803
 
825
- input[type="number"] {
826
- width: 200px;
804
+ label {
805
+ font-weight: 500;
806
+ }
807
+
808
+ input[type='number'] {
827
809
  margin-top: 20px;
828
810
  margin-left: 10px;
811
+ outline: 1px solid #ccc;
812
+ border-radius: 4px;
829
813
  }
830
814
  </style>
831
815
  ```
832
816
 
833
- In addition, most of the subcomponents expose their instance should you need it:
817
+ ### Loading the Google Maps API script externally
834
818
 
835
- - `Marker` exposes `marker` (a [Marker](https://developers.google.com/maps/documentation/javascript/reference/marker#Marker) class instance).
836
- - `Polyline` exposes `polyline` (a [Polyline](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polyline) class instance).
837
- - `Polygon` exposes `polygon` (a [Polygon](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polygon) class instance).
838
- - `Rectangle` exposes `rectangle` (a [Rectangle](https://developers.google.com/maps/documentation/javascript/reference/polygon#Rectangle) class instance).
839
- - `Circle` exposes `circle` (a [Circle](https://developers.google.com/maps/documentation/javascript/reference/polygon#Circle) class instance).
840
- - `InfoWindow` exposes `infoWindow` (an [InfoWindow](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow) class instance).
841
- - `MarkerCluster` exposes `markerCluster` (a [MarkerClusterer](https://googlemaps.github.io/js-markerclusterer/classes/MarkerClusterer.html) class instance).
819
+ By default you would pass your API key as a prop to the `GoogleMap` component and it handles the loading of the Google Maps API script for you. There are cases, however, where you might want to load the script yourself. For example, you might be using other Google Maps components or your Vue app might be a part of a larger app that uses the Google Maps API elsewhere. In these cases you can use the `apiPromise` prop to pass a promise that resolves to the Google Maps API global `google` object.
820
+
821
+ ```vue
822
+ <script setup>
823
+ import { GoogleMap, Marker } from 'vue3-google-map';
824
+ import { Loader } from '@googlemaps/js-api-loader';
825
+
826
+ const loader = new Loader({
827
+ apiKey: '',
828
+ version: 'weekly',
829
+ libraries: ['places'],
830
+ });
831
+
832
+ const apiPromise = loader.load();
833
+
834
+ const center = { lat: 40.689247, lng: -74.044502 };
835
+ </script>
836
+
837
+ <template>
838
+ <GoogleMap
839
+ :api-promise="apiPromise"
840
+ style="width: 100%; height: 500px"
841
+ :center="center"
842
+ :zoom="15"
843
+ >
844
+ <Marker :options="{ position: center }" />
845
+ </GoogleMap>
846
+ </template>
847
+ ```
842
848
 
843
849
  ## Contribution
844
850