Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tarang19's avatar

User can add multiple markers in leaflet.js using Vue js

I am using leaflet js to get user current location and he can add his family member location but i am not able o understand how to do this using vue js

0 likes
1 reply
double-a's avatar

i have done similar thing but i have used Mapbox, but i assume the approach can be applied here too. what i did was creating a vue component with a prop for the div id that the map should render in ( u can pass whatever u need to initialize your map ) then initialize your map in mounted function as u usually do.

it should looks like this

<template>
	<div :id="id"></div>
</template>

<script>
	export default {
		props:{
			id:{ default:'map'}
		},
		data(){
			return {
				//your variables
			}
		},
		mounted(){
			//init your map
			map.init()

			//add click listener
			map.on('click',()=>{ 
				// add marker 
				// you can use functions from component methods but 
				// don't forget to use arrow function

				this.addMarker()
			}
		},
		methods:{
			f1(){
			},
			addMarker(){
			}
		}
	}
</script>

Please or to participate in this conversation.