Skip to content

Demo how to use leaflet in vue 3 web application (with leaflet directly and use use vue-leaflet library)

Notifications You must be signed in to change notification settings

jhkluiver/Vue3Leaflet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Note: leaflet is a great project, but I run into problem when dynamic updating layers.Now using openlayers for vue 3, I would recomment to use this project.

Leaflet in vue 3

This demo project shows how to use leaflet map in an vue 3 web application. In this example the quasar framework was used, but this can be anything (vuetify, no framework).

Two approaches where used (demonstrated in one webpage):

  • Leaflet directly (left side of screenshot)

    Use the leaflet package directly (install with npm i leaflet). The leaflet creation is all done in the script part. This gives a lot of control (any leaflet function can be used)

  • With library vue-leaflet (right side of screenshot)

    Use the leaflet package through the vue-leaflet library (install with npm i vue-leaflet). The advantage is that the leaflet can be defined in the vue template. Reactive the elements can be bound. A disadvantage is that you have less control over the leaflet. Should be possible with map reference, but I didn't find out how.

Used chrome as web browser to test (didn't check other browsers)

Build

Install the Node Package Manager (NPM).

npm install
npm run dev
# Open webbrowser on port 9000

Intellisense

The leaflet library is in plain JavaScript. This demo uses typescript for validation and intellisense (Visual Code Editor). In the project @types/leaflet the typescript definitions for leaflet can be found. After installing with npm i @types/leaflet the definitions are placed in node_modules\@types\leaflet. Visual Code will automatically combine this type information with the leaflet library (leaflet is still JavaScript).

Intellisense

File locations

File Description
\src\components\RawLeafletMap.vue Approach one with plain leaflet
\src\components\VueLeafletMap Approach two with vue-leaflet lib

Dependencies:

About

Demo how to use leaflet in vue 3 web application (with leaflet directly and use use vue-leaflet library)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published