vue3-google-map 0.9.0 → 0.12.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
@@ -4,9 +4,32 @@
4
4
 
5
5
  `vue3-google-map` offers a set of composable components for easy use of Google Maps in your Vue 3 projects.
6
6
 
7
- ## Installation
7
+ Note: Please refer to the [documentation site](https://vue3-google-map.netlify.app/) for rendered examples.
8
8
 
9
- ### NPM
9
+ ## Table of Contents
10
+
11
+ - [Getting Started](#getting-started)
12
+ - [Installation](#installation)
13
+ - [Your First Map](#your-first-map)
14
+ - [Components](#components)
15
+ - [Marker](#marker)
16
+ - [Polyline](#polyline)
17
+ - [Polygon](#polygon)
18
+ - [Rectangle](#rectangle)
19
+ - [Circle](#circle)
20
+ - [Info Window](#info-window)
21
+ - [Custom Marker](#custom-marker)
22
+ - [Custom Control](#custom-control)
23
+ - [Marker Cluster](#marker-cluster)
24
+ - [Advanced Usage](#advanced-usage)
25
+ - [Contribution](#contribution)
26
+ - [License](#license)
27
+
28
+ ## Getting Started
29
+
30
+ ### Installation
31
+
32
+ #### NPM
10
33
 
11
34
  ```bash
12
35
  npm install vue3-google-map
@@ -14,7 +37,7 @@ npm install vue3-google-map
14
37
  yarn add vue3-google-map
15
38
  ```
16
39
 
17
- ### CDN
40
+ #### CDN
18
41
 
19
42
  Include the following script tag in your `index.html` (make sure to include it after Vue 3).
20
43
 
@@ -22,28 +45,700 @@ Include the following script tag in your `index.html` (make sure to include it a
22
45
  <script src="https://unpkg.com/vue3-google-map"></script>
23
46
  ```
24
47
 
48
+ ### Your First Map
49
+
50
+ 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#L30-L209) for all the supported `MapOptions`).
51
+ 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.
52
+
53
+ ```vue
54
+ <template>
55
+ <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="15">
56
+ <Marker :options="{ position: center }" />
57
+ </GoogleMap>
58
+ </template>
59
+
60
+ <script>
61
+ import { defineComponent } from "vue";
62
+ import { GoogleMap, Marker } from "vue3-google-map";
63
+
64
+ export default defineComponent({
65
+ components: { GoogleMap, Marker },
66
+ setup() {
67
+ const center = { lat: 40.689247, lng: -74.044502 };
68
+
69
+ return { center };
70
+ },
71
+ });
72
+ </script>
73
+ ```
74
+
75
+ ## Components
76
+
77
+ 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.
78
+
79
+ The main mapping component is `GoogleMap`, however the following components are available at your disposal:
80
+
81
+ - [Marker](#marker)
82
+ - [Polyline](#polyline)
83
+ - [Polygon](#polygon)
84
+ - [Rectangle](#rectangle)
85
+ - [Circle](#circle)
86
+ - [InfoWindow](#info-window)
87
+ - [CustomMarker](#custom-marker)
88
+ - [CustomControl](#custom-control)
89
+ - [MarkerCluster](#marker-cluster)
90
+
91
+ ### Marker
92
+
93
+ Use the `Marker` component to draw markers, drop pins or any custom icons on a map.
94
+
95
+ #### Options
96
+
97
+ You can pass a [MarkerOptions](https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerOptions) object to the `options` prop to configure your marker.
98
+
99
+ ```vue
100
+ <template>
101
+ <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="15">
102
+ <Marker :options="markerOptions" />
103
+ </GoogleMap>
104
+ </template>
105
+
106
+ <script>
107
+ import { defineComponent } from "vue";
108
+ import { GoogleMap, Marker } from "vue3-google-map";
109
+
110
+ export default defineComponent({
111
+ components: { GoogleMap, Marker },
112
+ setup() {
113
+ const center = { lat: 40.689247, lng: -74.044502 };
114
+ const markerOptions = { position: center, label: "L", title: "LADY LIBERTY" };
115
+
116
+ return { center, markerOptions };
117
+ },
118
+ });
119
+ </script>
120
+ ```
121
+
122
+ #### Events
123
+
124
+ You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/marker#Marker-Events) on the `Marker` component.
125
+
126
+ ### Polyline
127
+
128
+ Use the `Polyline` component to draw paths and arbitrary shapes on a map.
129
+
130
+ #### Options
131
+
132
+ You can pass a [PolylineOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#PolylineOptions) object to the `options` prop to configure your polyline.
133
+
134
+ ```vue
135
+ <template>
136
+ <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="3">
137
+ <Polyline :options="flightPath" />
138
+ </GoogleMap>
139
+ </template>
140
+
141
+ <script>
142
+ import { defineComponent } from "vue";
143
+ import { GoogleMap, Polyline } from "vue3-google-map";
144
+
145
+ export default defineComponent({
146
+ components: { GoogleMap, Polyline },
147
+ setup() {
148
+ const center = { lat: 0, lng: -180 };
149
+ const flightPlanCoordinates = [
150
+ { lat: 37.772, lng: -122.214 },
151
+ { lat: 21.291, lng: -157.821 },
152
+ { lat: -18.142, lng: 178.431 },
153
+ { lat: -27.467, lng: 153.027 },
154
+ ];
155
+ const flightPath = {
156
+ path: flightPlanCoordinates,
157
+ geodesic: true,
158
+ strokeColor: "#FF0000",
159
+ strokeOpacity: 1.0,
160
+ strokeWeight: 2,
161
+ };
162
+
163
+ return { center, flightPath };
164
+ },
165
+ });
166
+ </script>
167
+ ```
168
+
169
+ #### Events
170
+
171
+ You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polyline-Events) on the `Polyline` component.
172
+
173
+ ### Polygon
174
+
175
+ Use the `Polygon` component to draw polgons (arbitrary number of sides) on a map.
176
+
177
+ #### Options
178
+
179
+ You can pass a [PolylgonOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#PolygonOptions) object to the `options` prop to configure your polyline.
180
+
181
+ ```vue
182
+ <template>
183
+ <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="5">
184
+ <Polygon :options="bermudaTriangle" />
185
+ </GoogleMap>
186
+ </template>
187
+
188
+ <script>
189
+ import { defineComponent } from "vue";
190
+ import { GoogleMap, Polygon } from "vue3-google-map";
191
+
192
+ export default defineComponent({
193
+ components: { GoogleMap, Polygon },
194
+ setup() {
195
+ const center = { lat: 24.886, lng: -70.268 };
196
+ const triangleCoords = [
197
+ { lat: 25.774, lng: -80.19 },
198
+ { lat: 18.466, lng: -66.118 },
199
+ { lat: 32.321, lng: -64.757 },
200
+ { lat: 25.774, lng: -80.19 },
201
+ ];
202
+ const bermudaTriangle = {
203
+ paths: triangleCoords,
204
+ strokeColor: "#FF0000",
205
+ strokeOpacity: 0.8,
206
+ strokeWeight: 2,
207
+ fillColor: "#FF0000",
208
+ fillOpacity: 0.35,
209
+ };
210
+
211
+ return { center, bermudaTriangle };
212
+ },
213
+ });
214
+ </script>
215
+ ```
216
+
217
+ #### Events
218
+
219
+ You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polygon-Events) on the `Polygon` component.
220
+
221
+ ### Rectangle
222
+
223
+ Use the `Rectangle` component to draw simple rectangles on a map.
224
+
225
+ #### Options
226
+
227
+ You can pass a [RectangleOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#RectangleOptions) object to the `options` prop to configure your rectangle.
228
+
229
+ ```vue
230
+ <template>
231
+ <GoogleMap
232
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
233
+ style="width: 100%; height: 500px"
234
+ mapTypeId="terrain"
235
+ :center="center"
236
+ :zoom="11"
237
+ >
238
+ <Rectangle :options="rectangle" />
239
+ </GoogleMap>
240
+ </template>
241
+
242
+ <script>
243
+ import { defineComponent } from "vue";
244
+ import { GoogleMap, Marker } from "vue3-google-map";
245
+
246
+ export default defineComponent({
247
+ components: { GoogleMap, Marker },
248
+ setup() {
249
+ const center = { lat: 33.678, lng: -116.243 };
250
+ const rectangle = {
251
+ strokeColor: "#FF0000",
252
+ strokeOpacity: 0.8,
253
+ strokeWeight: 2,
254
+ fillColor: "#FF0000",
255
+ fillOpacity: 0.35,
256
+ bounds: {
257
+ north: 33.685,
258
+ south: 33.671,
259
+ east: -116.234,
260
+ west: -116.251,
261
+ },
262
+ };
263
+
264
+ return { center, rectangle };
265
+ },
266
+ });
267
+ </script>
268
+ ```
269
+
270
+ #### Events
271
+
272
+ You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/polygon#Rectangle-Events) on the `Rectangle` component.
273
+
274
+ ### Circle
275
+
276
+ Use the `Circle` component to draw circles on a map.
277
+
278
+ #### Options
279
+
280
+ You can pass a [CircleOptions](https://developers.google.com/maps/documentation/javascript/reference/polygon#CircleOptions) object to the `options` prop to configure your circle.
281
+
282
+ ```vue
283
+ <template>
284
+ <GoogleMap
285
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
286
+ style="width: 100%; height: 500px"
287
+ mapTypeId="terrain"
288
+ :center="center"
289
+ :zoom="4"
290
+ >
291
+ <Circle v-for="circle in circles" :options="circle" />
292
+ </GoogleMap>
293
+ </template>
294
+
295
+ <script>
296
+ import { defineComponent } from "vue";
297
+ import { GoogleMap, Circle } from "vue3-google-map";
298
+
299
+ export default defineComponent({
300
+ components: { GoogleMap, Circle },
301
+ setup() {
302
+ const center = { lat: 37.09, lng: -95.712 };
303
+ const cities = {
304
+ chicago: {
305
+ center: { lat: 41.878, lng: -87.629 },
306
+ population: 2714856,
307
+ },
308
+ newyork: {
309
+ center: { lat: 40.714, lng: -74.005 },
310
+ population: 8405837,
311
+ },
312
+ losangeles: {
313
+ center: { lat: 34.052, lng: -118.243 },
314
+ population: 3857799,
315
+ },
316
+ vancouver: {
317
+ center: { lat: 49.25, lng: -123.1 },
318
+ population: 603502,
319
+ },
320
+ };
321
+
322
+ const circles = {};
323
+
324
+ for (const key in cities) {
325
+ circles[key] = {
326
+ center: cities[key].center,
327
+ radius: Math.sqrt(cities[key].population) * 100,
328
+ strokeColor: "#FF0000",
329
+ strokeOpacity: 0.8,
330
+ strokeWeight: 2,
331
+ fillColor: "#FF0000",
332
+ fillOpacity: 0.35,
333
+ };
334
+ }
335
+
336
+ return { center, circles };
337
+ },
338
+ });
339
+ </script>
340
+ ```
341
+
342
+ #### Events
343
+
344
+ You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/polygon#Circle-Events) on the `Circle` component.
345
+
346
+ ### Info Window
347
+
348
+ Use the `InfoWindow` component to display content in a popup window above the map, at a given location.
349
+
350
+ #### Options
351
+
352
+ 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.
353
+
354
+ ```vue
355
+ <template>
356
+ <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="10">
357
+ <InfoWindow :options="{ position: center, content: 'Hello World!' }" />
358
+ <InfoWindow :options="{ position: { lat: center.lat, lng: 150.8 } }"> Content passed through slot </InfoWindow>
359
+ </GoogleMap>
360
+ </template>
361
+
362
+ <script>
363
+ import { defineComponent } from "vue";
364
+ import { GoogleMap, InfoWindow } from "vue3-google-map";
365
+
366
+ export default defineComponent({
367
+ components: { GoogleMap, InfoWindow },
368
+ setup() {
369
+ const center = { lat: -33.9, lng: 151.1 };
370
+
371
+ return { center };
372
+ },
373
+ });
374
+ </script>
375
+ ```
376
+
377
+ #### Use with Marker
378
+
379
+ You can nest the `InfoWindow` component inside the `Marker` component to display an info window when the marker is clicked.
380
+
381
+ ```vue
382
+ <template>
383
+ <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="4">
384
+ <Marker :options="{ position: center }">
385
+ <InfoWindow>
386
+ <div id="contet">
387
+ <div id="siteNotice"></div>
388
+ <h1 id="firstHeading" class="firstHeading">Uluru</h1>
389
+ <div id="bodyContent">
390
+ <p>
391
+ <b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large sandstone rock formation in the southern
392
+ part of the Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) south west of the
393
+ nearest large town, Alice Springs; 450&#160;km (280&#160;mi) by road. Kata Tjuta and Uluru are the two
394
+ major features of the Uluru - Kata Tjuta National Park. Uluru is sacred to the Pitjantjatjara and
395
+ Yankunytjatjara, the Aboriginal people of the area. It has many springs, waterholes, rock caves and
396
+ ancient paintings. Uluru is listed as a World Heritage Site.
397
+ </p>
398
+ <p>
399
+ Attribution: Uluru,
400
+ <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">
401
+ https://en.wikipedia.org/w/index.php?title=Uluru</a
402
+ >
403
+ (last visited June 22, 2009).
404
+ </p>
405
+ </div>
406
+ </div>
407
+ </InfoWindow>
408
+ </Marker>
409
+ </GoogleMap>
410
+ </template>
411
+
412
+ <script>
413
+ import { defineComponent } from "vue";
414
+ import { GoogleMap, Marker, InfoWindow } from "vue3-google-map";
415
+
416
+ export default defineComponent({
417
+ components: { GoogleMap, Marker, InfoWindow },
418
+ setup() {
419
+ const center = { lat: -25.363, lng: 131.044 };
420
+
421
+ return { center };
422
+ },
423
+ });
424
+ </script>
425
+ ```
426
+
427
+ #### Events
428
+
429
+ You can listen for [the following events](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow-Events) on the `InfoWindow` component.
430
+
431
+ ### Custom Marker
432
+
433
+ Regular markers can be customized a great deal but if you need to you can use the `CustomMarker` component and provide your own custom markup through it's `default` slot.
434
+
435
+ #### Options
436
+
437
+ | Parameter | Type | Description |
438
+ | :-------- | :------- | :------------------------- |
439
+ | `position` | `{ lat: number, lng: number}` | Sets the marker position. |
440
+ | `anchorPoint` | `'CENTER' \| 'TOP_CENTER' \|'BOTTOM_CENTER' \| 'LEFT_CENTER' \| 'RIGHT_CENTER' \| 'TOP_LEFT' \| 'TOP_RIGHT' \| 'BOTTOM_LEFT' \| 'BOTTOM_RIGHT'` | Sets how the marker is anchored relative to it's `position` point. Default is `CENTER`. |
441
+ | `offsetX` | `number` | Horizontal offset from the `position` point. |
442
+ | `offsetY` | `number` | Vertical offset from the `position` point. |
443
+ | `zIndex` | `number` | `z-index` value of the marker. |
444
+
445
+
446
+ ```vue
447
+ <template>
448
+ <GoogleMap
449
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
450
+ style="width: 100%; height: 500px"
451
+ :center="center"
452
+ :zoom="15"
453
+ >
454
+ <CustomMarker :options="{ position: center, anchorPoint: 'BOTTOM_CENTER' }">
455
+ <div style="text-align: center">
456
+ <div style="font-size: 1.125rem">Vuejs Amsterdam</div>
457
+ <img src="https://vuejs.org/images/logo.png" width="50" height="50" style="margin-top: 8px" />
458
+ </div>
459
+ </CustomMarker>
460
+ </GoogleMap>
461
+ </template>
462
+
463
+ <script>
464
+ import { defineComponent } from 'vue'
465
+ import { GoogleMap, CustomMarker } from 'vue3-google-map'
466
+
467
+ export default defineComponent({
468
+ components: { GoogleMap, CustomMarker },
469
+ setup() {
470
+ const center = { lat: 52.36834, lng: 4.88635 }
471
+
472
+ return { center }
473
+ },
474
+ })
475
+ </script>
476
+ ```
477
+
478
+ ### Custom Control
479
+
480
+ Use the `CustomControl` component to add custom buttons/controls to your map.
481
+
482
+ #### Usage
483
+
484
+ You can define the markup of your custom control in the `default` slot of the `CustomControl` component. The component itself takes two props:
485
+
486
+ - `position`: Defines the position of your custom control on the map. Its value must be one of the [ControlPosition](https://developers.google.com/maps/documentation/javascript/reference/control#ControlPosition) constants.
487
+ - `index` (optional): Controls the order of placement for custom controls that occupy the same position.
488
+
489
+ Refer to the [Google Maps documentation](https://developers.google.com/maps/documentation/javascript/controls#CustomControls) on custom controls positioning.
490
+
491
+ ```vue
492
+ <template>
493
+ <GoogleMap api-key="YOUR_GOOGLE_MAPS_API_KEY" style="width: 100%; height: 500px" :center="center" :zoom="13">
494
+ <CustomControl position="BOTTOM_CENTER">
495
+ <button class="custom-btn" @click="sayHi">👋</button>
496
+ </CustomControl>
497
+ </GoogleMap>
498
+ </template>
499
+
500
+ <script>
501
+ import { defineComponent } from "vue";
502
+ import { GoogleMap, CustomControl } from "vue3-google-map";
503
+
504
+ export default defineComponent({
505
+ components: { GoogleMap, CustomControl },
506
+ setup() {
507
+ const center = { lat: 35, lng: -95 };
508
+ const sayHi = () => alert("Hi!");
509
+
510
+ return { center, sayHi };
511
+ },
512
+ });
513
+ </script>
514
+
515
+ <style scoped>
516
+ .custom-btn {
517
+ box-sizing: border-box;
518
+ background: white;
519
+ height: 40px;
520
+ width: 40px;
521
+ border-radius: 2px;
522
+ border: 0px;
523
+ margin: 10px;
524
+ padding: 0px;
525
+ font-size: 1.25rem;
526
+ text-transform: none;
527
+ appearance: none;
528
+ cursor: pointer;
529
+ user-select: none;
530
+ box-shadow: rgba(0, 0, 0, 0.3) 0px 1px 4px -1px;
531
+ overflow: hidden;
532
+ }
533
+ </style>
534
+ ```
535
+
536
+ ### Marker Cluster
537
+
538
+ Use the `MarkerCluster` component to display a large number of markers on a map. It will combine markers of close proximity into clusters, and simplify the display of markers on the map. Can be used with the `Marker` or `CustomMarker` components.
539
+
25
540
  ## Usage
26
541
 
27
- Please refer to the [documentation](https://vue3-google-map.netlify.app/)
542
+ Simply pass your `Marker`/`CustomMarker`(s) in the `default` slot of the `MarkerCluster` component.
543
+
544
+ ```vue
545
+ <template>
546
+ <GoogleMap
547
+ api-key="YOUR_GOOGLE_MAPS_API_KEY"
548
+ style="width: 100%; height: 500px"
549
+ :center="center"
550
+ :zoom="3"
551
+ >
552
+ <MarkerCluster>
553
+ <Marker v-for="(location, i) in locations" :options="{ position: location }" :key="i" />
554
+ </MarkerCluster>
555
+ </GoogleMap>
556
+ </template>
557
+
558
+ <script>
559
+ import { defineComponent } from 'vue'
560
+ import { GoogleMap, Marker, MarkerCluster } from 'vue3-google-map'
561
+
562
+ export default defineComponent({
563
+ components: { GoogleMap, Marker, MarkerCluster },
564
+ setup() {
565
+ const center = { lat: -28.024, lng: 140.887 }
566
+
567
+ const locations = [
568
+ { lat: -31.56391, lng: 147.154312 },
569
+ { lat: -33.718234, lng: 150.363181 },
570
+ { lat: -33.727111, lng: 150.371124 },
571
+ { lat: -33.848588, lng: 151.209834 },
572
+ { lat: -33.851702, lng: 151.216968 },
573
+ { lat: -34.671264, lng: 150.863657 },
574
+ { lat: -35.304724, lng: 148.662905 },
575
+ { lat: -36.817685, lng: 175.699196 },
576
+ { lat: -36.828611, lng: 175.790222 },
577
+ { lat: -37.75, lng: 145.116667 },
578
+ { lat: -37.759859, lng: 145.128708 },
579
+ { lat: -37.765015, lng: 145.133858 },
580
+ { lat: -37.770104, lng: 145.143299 },
581
+ { lat: -37.7737, lng: 145.145187 },
582
+ { lat: -37.774785, lng: 145.137978 },
583
+ { lat: -37.819616, lng: 144.968119 },
584
+ { lat: -38.330766, lng: 144.695692 },
585
+ { lat: -39.927193, lng: 175.053218 },
586
+ { lat: -41.330162, lng: 174.865694 },
587
+ { lat: -42.734358, lng: 147.439506 },
588
+ { lat: -42.734358, lng: 147.501315 },
589
+ { lat: -42.735258, lng: 147.438 },
590
+ { lat: -43.999792, lng: 170.463352 },
591
+ ]
592
+
593
+ return { center, locations }
594
+ },
595
+ })
596
+ </script>
597
+ ```
598
+
599
+ #### Options
600
+
601
+ `MarkerCluster` accepts an `options` prop (an object) where you can configure `algorithm`, `onClusterClick`, and `renderer` from the [MarkerClustererOptions](https://googlemaps.github.io/js-markerclusterer/interfaces/MarkerClustererOptions.html) interface. Note that all these options are completely optional but non-reactive.
602
+
603
+ #### Events
604
+
605
+ You can listen for [the following events](https://googlemaps.github.io/js-markerclusterer/enums/MarkerClustererEvents.html) on the `MarkerCluster` component.
606
+
607
+
608
+ ## Advanced Usage
28
609
 
29
- ## Development Setup
610
+ 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:
30
611
 
31
- Clone the repo and checkout the `develop` branch.
612
+ - `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.
613
+ - `map`: The [Map](https://developers.google.com/maps/documentation/javascript/reference/map#Map) class instance.
614
+ - `api`: The [Google Maps API](https://developers.google.com/maps/documentation/javascript/reference).
615
+ - `mapTilesLoaded`: A boolean indicating when the map tiles have been fully loaded.
32
616
 
33
- ```sh
34
- # install deps
35
- yarn install
617
+ Some useage patterns:
36
618
 
37
- # build dist files
38
- yarn build
619
+ ```vue
620
+ <template>
621
+ <GoogleMap ref="mapRef">
622
+ <template #default="{ ready, api, map, mapTilesLoaded }">
623
+ <!-- First pattern: Here you have access to the API and map instance.
624
+ "ready" is a boolean that indicates when the Google Maps script
625
+ has been loaded and the api and map instance are ready to be used -->
626
+ </template>
627
+ </GoogleMap>
628
+ </template>
39
629
 
40
- # run develpment server and serve basic example
41
- yarn dev
630
+ <script>
631
+ import { defineComponent, ref, computed, watch } from 'vue'
632
+ import { GoogleMap } from 'vue3-google-map'
42
633
 
43
- # serve docs
44
- yarn docs
634
+ export default defineComponent({
635
+ components: { GoogleMap },
636
+ setup() {
637
+ const mapRef = ref(null)
638
+
639
+ // Second pattern: compute some value using the API or map instance when "ready"
640
+ markerIcon = computed(() => mapRef.value.ready
641
+ ? {
642
+ url: /* icon image url */,
643
+ scaledSize: new mapRef.value.api.Size(20, 20)
644
+ }
645
+ : null)
646
+
647
+ // Third pattern: watch for "ready" then do something with the API or map instance
648
+ watch(() => mapRef.value.ready, (ready) => {
649
+ if (!ready) return
650
+
651
+ // do something with the api using `mapRef.value.api`
652
+ // or with the map instance using `mapRef.value.map`
653
+ })
654
+
655
+ return { mapRef }
656
+ },
657
+ })
658
+ </script>
45
659
  ```
46
660
 
661
+ Example:
662
+
663
+ ```vue
664
+ <template>
665
+ <GoogleMap ref="mapRef" api-key="YOUR_GOOGLE_MAPS_API_KEY" class="map" :center="center" :zoom="2" />
666
+ <label for="lng">Longitude</label>
667
+ <input v-model.number="lng" id="lng" type="number" min="-180" max="180" step="10" />
668
+ </template>
669
+
670
+ <script>
671
+ import { defineComponent, ref, computed, watch } from "vue";
672
+ import { GoogleMap } from "vue3-google-map";
673
+
674
+ export default defineComponent({
675
+ components: { GoogleMap },
676
+ setup() {
677
+ const mapRef = ref(null);
678
+ const center = { lat: 0, lng: 0 };
679
+
680
+ const _lng = ref(0);
681
+ const lng = computed({
682
+ get: () => _lng.value,
683
+ set: (v) => {
684
+ if (!Number.isFinite(v)) {
685
+ _lng.value = 0;
686
+ } else if (v > 180) {
687
+ _lng.value = 180;
688
+ } else if (v < -180) {
689
+ _lng.value = -180;
690
+ } else {
691
+ _lng.value = v;
692
+ }
693
+ },
694
+ });
695
+
696
+ watch(lng, () => {
697
+ if (mapRef.value?.ready) {
698
+ mapRef.value.map.panTo({ lat: 0, lng: lng.value });
699
+ }
700
+ });
701
+
702
+ return { mapRef, center, lng };
703
+ },
704
+ });
705
+ </script>
706
+
707
+ <style scoped>
708
+ .map {
709
+ position: relative;
710
+ width: 100%;
711
+ height: 500px;
712
+ }
713
+
714
+ .map::after {
715
+ position: absolute;
716
+ content: "";
717
+ width: 1px;
718
+ height: 100%;
719
+ top: 0;
720
+ left: 50%;
721
+ background: red;
722
+ }
723
+
724
+ input[type="number"] {
725
+ width: 200px;
726
+ margin-top: 20px;
727
+ margin-left: 10px;
728
+ }
729
+ </style>
730
+ ```
731
+
732
+ In addition, most of the subcomponents expose their instance should you need it:
733
+
734
+ - `Marker` exposes `marker` (a [Marker](https://developers.google.com/maps/documentation/javascript/reference/marker#Marker) class instance).
735
+ - `Polyline` exposes `polyline` (a [Polyline](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polyline) class instance).
736
+ - `Polygon` exposes `polygon` (a [Polygon](https://developers.google.com/maps/documentation/javascript/reference/polygon#Polygon) class instance).
737
+ - `Rectangle` exposes `rectangle` (a [Rectangle](https://developers.google.com/maps/documentation/javascript/reference/polygon#Rectangle) class instance).
738
+ - `Circle` exposes `circle` (a [Circle](https://developers.google.com/maps/documentation/javascript/reference/polygon#Circle) class instance).
739
+ - `InfoWindow` exposes `infoWindow` (an [InfoWindow](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow) class instance).
740
+ - `MarkerCluster` exposes `markerCluster` (a [MarkerClusterer](https://googlemaps.github.io/js-markerclusterer/classes/MarkerClusterer.html) class instance).
741
+
47
742
  ## Contribution
48
743
 
49
744
  All contributions are welcome. Before submitting a PR though it would be nice if you created an issue explaining what you want to acheive and why.