I am following the leafletjs guide from here :
https://vue2-leaflet.netlify.app/components/LIcon.html#demo
and just adding stuffs into the component like this:
<l-map ref="myMapstats" :zoom="zoom" :center="center">
<l-tile-layer
url="https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png"
attribution='© <a target="_blank"
href="http://osm.org/copyright">OpenStreetMap</a>'
></l-tile-layer>
<l-marker
:lat-lng="[47.413220, -1.209482]"
:icon="icon" >
</l-marker>
<l-icon
:icon-anchor="iconAnchor"
:icon-size="iconSize"
:popup-
: anchor="popupAnchor">
icon-url="static/images/baseball-marker.png" >
</l-icon>
<l-popup>
LOL
</l-popup>
</l-marker>
</l-map>
And importing like this: import {LMap, LTileLayer, LMarker, LIcon} from ‘vue2-leaflet’;
So I am able to use LMAP and other components from ‘vue2-leaflet’;
But, I can see many people are using the same leafletmap in different way,
and the L.Marker in this way and then adding to the map, see below:
var map = L.map('map').setView([51.495, -0.09], 15);
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmLayer = new L.TileLayer(osmUrl, {
maxZoom: 19,
attribution: 'Map data © OpenStreetMap contributors'
});
map.addLayer(osmLayer);
var marker1 = L.marker([51.497, -0.09], {
title: "marker_1"
}).addTo(map).bindPopup("Marker 1").on('click', clickZoom);
So for example I want to create a function ‘clickHandler(index)’, in my map ( the first Example ), and then calling the function from marker and in function I am using the LMap.setView()…., and when I run I am getting error, LMAP not define.
Just want to know id there any differennce between :
'<l-map> </l-map>' and 'var map = L.map('map')'
Thanks in advance!
<l-marker
v-for="(marker, index) in markers"
:key="index"
@click="clickHandler(index)"
>
....... more code here ....
methods: {
clickHandler(index) {
LMap.setView(markers[index].location, 13);
//this.$refs.myMapstats;
markers[index].openPopUp();
},
}