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