Skip to content

Commit

Permalink
docs(docs): improve and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoazh committed Apr 1, 2024
1 parent b3e7541 commit 79c4b79
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: examples
sidebar_position: 5
sidebar_label: Examples
---

# Examples

Here you can play with a CodeSandbox project to test all the examples provided in this documentation.
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,52 @@ id: dynamic-load
sidebar_position: 1
sidebar_label: Dynamic load
---

# Dynamic load

If you need to initialize the Google Maps API in a dynamic way you can use the `dynamicLoad` option of the plugin
configuration, this option start the plugin but **it doesn't load the Google Maps API**, **you need to load it manually** using
the `googleMapsApiInitializer` function from the `utilities` object exposed by the plugin as we show below

```ts title="main.ts" showLineNumbers
//...

createApp(App)
.use(router)
.use(createGmapVuePlugin({ dynamicLoad: true }))
.mount("#app");

//...
```

In setup script

```ts title="[your-component].vue" showLineNumbers {5,6,9}
import { onMounted } from 'vue'
import { utilities } from '@gmap-vue/v3';
import { usePluginOptions } from '@gmap-vue/v3/composables';
```ts title="[your-component].vue - Composition API" showLineNumbers {5,6,9}
import { onMounted } from "vue";
import { utilities } from "@gmap-vue/v3";
import { usePluginOptions } from "@gmap-vue/v3/composables";

const { googleMapsApiInitializer } = utilities;
const options = usePluginOptions();

onMounted(() => {
googleMapsApiInitializer(options);
})
});
```

or in options API

```ts title="[your-component].vue" showLineNumbers {4,8}
import { onMounted } from 'vue'
import { utilities } from '@gmap-vue/v3';
```ts title="[your-component].vue - Options API" showLineNumbers {4,8}
import { onMounted } from "vue";
import { utilities } from "@gmap-vue/v3";

const { googleMapsApiInitializer } = utilities;

export default {
mounted() {
googleMapsApiInitializer(this.$gmapOptions);
}
}
},
};
```

:::info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ If you need to gain access to the `Map` instance (e.g. to call `panToBounds`, `p
</template>
<script setup lang="ts">
import { useMapPromise } from '@gmap-vue/v3/composables';
import { onMounted, ref } from 'vue';
import { MapLayer } from '@gmap-vue/v3/components';
import { useMapPromise } from "@gmap-vue/v3/composables";
import { onMounted, ref } from "vue";
import { MapLayer } from "@gmap-vue/v3/components";
const mapRef = ref<typeof MapLayer | null>(null);
const mapPromise = useMapPromise();
Expand Down Expand Up @@ -91,14 +91,14 @@ If you need to gain access to the `Map` instance (e.g. to call `panToBounds`, `p
To safety type a ref of one of the plugin components is to add the following to your `main.ts` file
```ts title="main.ts" showLineNumbers {11}
import { ComponentInstance } from 'vue';
import { MapLayer } from '@gmap-vue/v3/components';
import { type IMapLayerVueComponentExpose } from '@gmap-vue/v3/interfaces';
import { ComponentInstance } from "vue";
import { MapLayer } from "@gmap-vue/v3/components";
import { type IMapLayerVueComponentExpose } from "@gmap-vue/v3/interfaces";
/**
* Vue augmentations
*/
declare module 'vue' {
declare module "vue" {
interface ComponentCustomProperties {
$refs: {
mapRef: ComponentInstance<typeof MapLayer & IMapLayerVueComponentExpose>;
Expand All @@ -116,8 +116,8 @@ declare module 'vue' {
In this example you can not use the `inject` method to get the mapPromise as we show below
```ts title="Composition API" showLineNumbers
import { inject } from 'vue';
import { $mapPromise } from '@gmap-vue/v3/keys';
import { inject } from "vue";
import { $mapPromise } from "@gmap-vue/v3/keys";
const mapPromise = inject($mapPromise);
```
Expand Down
6 changes: 3 additions & 3 deletions packages/documentation/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ const config: Config = {
items: [
{
label: 'Stack Overflow',
href: 'https://stackoverflow.com/questions/tagged/docusaurus',
href: 'https://stackoverflow.com',
},
{
label: 'Discord',
href: 'https://discordapp.com/invite/docusaurus',
href: 'https://discordapp.com/',
},
{
label: 'Twitter',
href: 'https://twitter.com/docusaurus',
href: 'https://twitter.com/',
},
],
},
Expand Down

0 comments on commit 79c4b79

Please sign in to comment.