Skip to content

Commit d0e98d3

Browse files
authored
Improve documentation / Prepare leaflet.markercluster support (#25)
* First MarkerCluster idea * Init some documentation for markercluster * Update configKey / Polish doc / Polish module API * Fix playground baseURL * Improve documentation * Add cover image * Add Nuxt UI to improve playground * Make markercluster client-side only * Make markercluster more usable * Update comment * Add custom marker icon example * Improve documentation * Improve documentation * Hide doc page temporarily for main merge
1 parent aad63f3 commit d0e98d3

File tree

19 files changed

+1975
-191
lines changed

19 files changed

+1975
-191
lines changed

.nuxtrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
imports.autoImport=false
1+
imports.autoImport=true
22
typescript.includeWorkspace=true

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![@nuxtjs/leaflet](./docs/public/cover.png)](https://leaflet.nuxtjs.org)
2+
13
# Nuxt Leaflet
24

35
[![npm version][npm-version-src]][npm-version-href]

docs/.vitepress/config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ export default defineConfig({
2626
text: 'Guide',
2727
items: [
2828
{ text: 'Using L', link: '/guide/using-l' },
29-
{ text: 'Accessing Map Instance', link: '/guide/accessing-map-instance' },
30-
{ text: 'Leaflet Draw (Experimental)', link: '/guide/leaflet-draw' }
29+
{ text: 'Accessing a map instance', link: '/guide/accessing-map-instance' }
30+
// { text: 'Leaflet.markercluster', link: '/guide/marker-cluster' }
3131
]
3232
},
3333
{
3434
text: 'Components',
35+
collapsed: true,
3536
items: [
3637
{ text: 'Introduction', link: '/components/introduction' },
3738
{ text: 'LCircle', link: '/components/l-circle' },
@@ -57,7 +58,13 @@ export default defineConfig({
5758
{ text: 'LTooltip', link: '/components/l-tooltip' },
5859
{ text: 'LWmsTileLayer', link: '/components/l-wms-tile-layer' },
5960
]
60-
}
61+
},
62+
{
63+
text: 'About',
64+
items: [
65+
{ text: 'Q&A', link: '/about/q&a' },
66+
]
67+
},
6168
],
6269

6370
socialLinks: [

docs/about/q&a.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Q&A
2+
3+
## Does the module support Nuxt 2 ?
4+
5+
No, the module at least requires Nuxt 3.
6+
7+
For Nuxt 2, you can use [this module](https://www.npmjs.com/package/nuxt-leaflet).
8+
9+
## How does Leaflet compare to Mapbox ?
10+
11+
[Mapbox](https://www.mapbox.com/) is a mapping platform that provides a suite of tools to create maps and location-based services. It includes similar features to Leaflet, but with paid plans for more advanced services.
12+
13+
Think of Leaflet as an open-source technology, while Mapbox is a complete collection of advanced tools and services.
14+
15+
Both are great choices, it depends on your needs and budget. To be fair, [the creator of Leaflet](https://github.com/mourner) also works at Mapbox.
16+
17+
If you want to use Mapbox with Nuxt, you can use the [Nuxt Mapbox](https://nuxt.com/modules/nuxt-mapbox) module.
18+
19+
## How does Leaflet compare to MapLibre ?
20+
21+
[MapLibre](https://maplibre.org/) is a fork of the original Mapbox GL JS library. It has very similar features to Leaflet, and is also free and open-source.
22+
23+
:::tip Quote from [MapLibre's Github repository](https://github.com/maplibre/maplibre-gl-js)
24+
MapLibre originated as an open-source fork of mapbox-gl-js, before their switch to a non-OSS license in December 2020.
25+
26+
The library's initial versions (1.x) were intended to be a drop-in replacement for the Mapbox’s OSS version (1.x) with additional functionality, but have evolved a lot since then.
27+
:::
28+
29+
If you want to use MapLibre with Nuxt, you can use the [Vue MapLibre](https://indoorequal.github.io/vue-maplibre-gl/) module which has some documentation for Nuxt.
30+
31+
We are also working on a dedicated Nuxt module for MapLibre.
32+
33+
## Will Leaflet.draw be supported in the future ?
34+
35+
[Leaflet.draw](https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html) was created to provide a simple way to draw shapes on a map made with Leaflet.
36+
37+
However, as the project is not maintained anymore (last update in 2018, see [Github repository](https://github.com/Leaflet/Leaflet.draw)), we choose not to include its support in the module.

docs/guide/accessing-map-instance.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Accessing a Map Instance
1+
# Accessing a map instance
22

33
The guide explains how to access a Leaflet map instance from a Vue component, as featured in the [original vue-leaflet library](https://github.com/vue-leaflet/vue-leaflet/blob/master/docs/faq/index.md#how-can-i-access-the-leaflet-map-object).
44

@@ -12,7 +12,7 @@ The guide explains how to access a Leaflet map instance from a Vue component, as
1212
:zoom="6"
1313
:max-zoom="18"
1414
:center="[47.21322, -1.559482]"
15-
@ready="mapInitialized"
15+
@ready="onMapReady"
1616
>
1717
<LTileLayer
1818
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
@@ -31,7 +31,7 @@ const map = ref(null)
3131
</script>
3232
```
3333

34-
- Create a `mapInitialized` method that will be called when the map is ready.
34+
- Create a `onMapReady` method that will be called when the map is ready.
3535

3636
You can now access the Leaflet map instance using `map.value.leafletObject`.
3737

@@ -43,7 +43,7 @@ You can now access the Leaflet map instance using `map.value.leafletObject`.
4343
:zoom="6"
4444
:max-zoom="18"
4545
:center="[47.21322, -1.559482]"
46-
@ready="mapInitialized"
46+
@ready="onMapReady"
4747
>
4848
<LTileLayer
4949
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
@@ -61,7 +61,7 @@ import { ref } from 'vue'
6161
const map = ref(null)
6262
6363
// When the map is ready
64-
const mapInitialized = () => {
64+
const onMapReady = () => {
6565
// Access the Leaflet map instance
6666
console.log(map.value.leafletObject)
6767
}

docs/guide/leaflet-draw.md

Lines changed: 0 additions & 118 deletions
This file was deleted.

docs/guide/marker-cluster.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Using Leaflet.markercluster
2+
3+
The guide explains how to use the [Leaflet.markercluster](https://github.com/Leaflet/Leaflet.markercluster) plugin.
4+
A dedicated composable is available to help you use this plugin.
5+
6+
Options for the markers are the same as the ones available in the [Leaflet documentation](https://leafletjs.com/reference.html#marker).
7+
8+
::: warning
9+
This is only possible in a client-side environment. You should either :
10+
- Use a [Client-Only Page](https://nuxt.com/docs/guide/directory-structure/pages#client-only-pages).
11+
- Wrap your component inside the [ClientOnly](https://nuxt.com/docs/api/components/client-only) component.
12+
- Set your [rendering strategy](https://nuxt.com/docs/guide/concepts/rendering#client-side-rendering) to `ssr: false` for the appropriate route.
13+
:::
14+
15+
## Installation
16+
17+
- First install markercluster
18+
19+
```bash
20+
npm install leaflet.markercluster
21+
```
22+
23+
- Update your Nuxt config to activate the plugin
24+
25+
```ts{3-5}
26+
export default defineNuxtConfig({
27+
modules: ['@nuxtjs/leaflet'],
28+
leaflet: {
29+
markerCluster: true
30+
}
31+
})
32+
```
33+
34+
- Use the `useMarkerCluster` composable in your component
35+
36+
:::warning
37+
It is very important to keep the manual import of Leaflet and the `:use-global-leaflet="true"` as leaflet.markercluster requires Leaflet to be loaded globally.
38+
:::
39+
40+
```vue{9,23,28-61,65-68}
41+
<template>
42+
<div style="height:100vh; width:100vw">
43+
<h1>Marker Cluster</h1>
44+
<LMap
45+
ref="map"
46+
:zoom="6"
47+
:max-zoom="18"
48+
:center="[47.21322, -1.559482]"
49+
:use-global-leaflet="true"
50+
@ready="onMapReady"
51+
>
52+
<LTileLayer
53+
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
54+
attribution="&amp;copy; <a href=&quot;https://www.openstreetmap.org/&quot;>OpenStreetMap</a> contributors"
55+
layer-type="base"
56+
name="OpenStreetMap"
57+
/>
58+
</LMap>
59+
</div>
60+
</template>
61+
62+
<script setup lang="ts">
63+
import L from 'leaflet'
64+
import { ref } from 'vue';
65+
66+
const map = ref(null) as any;
67+
68+
// Create locations data (20 locations around Nantes)
69+
const locations = [
70+
{ name: 'Nantes', lat: 47.218371, lng: -1.553621, options: {
71+
// Standard Leaflet Marker options
72+
draggable: true,
73+
icon: L.icon({
74+
iconUrl: '/my-icon.png',
75+
iconSize: [30, 30],
76+
})
77+
} },
78+
{
79+
// name is optional (no tooltip will be displayed if not provided)
80+
/* name: 'Saint-Nazaire', */
81+
lat: 47.273018, lng: -2.213733
82+
},
83+
{ name: 'La Baule', lat: 47.286835, lng: -2.393108 },
84+
{ name: 'Pornic', lat: 47.112, lng: -2.102 },
85+
{ name: 'Guérande', lat: 47.328, lng: -2.429 },
86+
{ name: 'Clisson', lat: 47.087, lng: -1.276 },
87+
{ name: 'Ancenis', lat: 47.366, lng: -1.176 },
88+
{ name: 'Châteaubriant', lat: 47.716, lng: -1.376 },
89+
{ name: 'Redon', lat: 47.652, lng: -2.084 },
90+
{ name: 'Pontchâteau', lat: 47.433, lng: -2.117 },
91+
{ name: 'Savenay', lat: 47.327, lng: -1.952 },
92+
{ name: 'Rezé', lat: 47.183, lng: -1.55 },
93+
{ name: 'Vertou', lat: 47.166, lng: -1.466 },
94+
{ name: 'Carquefou', lat: 47.283, lng: -1.5 },
95+
{ name: 'Orvault', lat: 47.283, lng: -1.633 },
96+
{ name: 'Saint-Herblain', lat: 47.216, lng: -1.65 },
97+
{ name: 'Sainte-Luce-sur-Loire', lat: 47.233, lng: -1.483 },
98+
{ name: 'Bouguenais', lat: 47.183, lng: -1.583 },
99+
{ name: 'Saint-Sébastien-sur-Loire', lat: 47.183, lng: -1.483 },
100+
{ name: 'Basse-Goulaine', lat: 47.2, lng: -1.483 }
101+
];
102+
103+
// When the map is ready
104+
const onMapReady = () => {
105+
useMarkerCluster({
106+
leafletObject: map.value.leafletObject,
107+
markers: locations
108+
});
109+
}
110+
</script>
111+
```

docs/guide/using-l.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
You might want to access the Leaflet global variable in your Vue component. This can be useful if you want to use a Leaflet plugin that is not available as a Vue component.
44

5-
You can still import the `L` global variable from the `leaflet` package and use it in your Vue component. Here is an example of how you can access the `L` global variable in a Vue component.
5+
You can still import the `L` global variable from the `leaflet` package and use it in your Vue component. Here is an example :
66

77
::: warning
8-
This is only possible in a client-side environment. You should use the `client-only` component to ensure that the code is only executed on the client side or set your map route to `ssr: false`.
8+
This is only possible in a client-side environment. You should either :
9+
- Use a [Client-Only Page](https://nuxt.com/docs/guide/directory-structure/pages#client-only-pages).
10+
- Wrap your component inside the [ClientOnly](https://nuxt.com/docs/api/components/client-only) component.
11+
- Set your [rendering strategy](https://nuxt.com/docs/guide/concepts/rendering#client-side-rendering) to `ssr: false` for the appropriate route.
912
:::
1013

1114
```vue{6,18,21-23}

docs/public/cover.png

1010 KB
Loading

0 commit comments

Comments
 (0)