get latlng and put then inside LatLng(.....)

27 views
Skip to first unread message

Pouemes

unread,
Apr 3, 2018, 11:20:04 AM4/3/18
to Leaflet
hello,

i need you help in my script all my markers are loaded with a popup which give a link to a page: like this (all works fine)

var markers = [{pos: [44.653024, -69.19922], popup: '<a '+am+'page1.htm"><b>page1</b></a>'},
{pos: [39.504041, -105.322267], popup: '<a '+am+'page2.htm"><b>page2</b></a>'},
{pos: [-23.335534, -67.177734], popup: '<a '+am+'page3.htm"><b>page3</b></a>'},
etc...'}];
markers.forEach(function (obj) {var m = L.marker(obj.pos).addTo(map), p = new L.Popup({autoClose:false, closeOnClick:false}).setContent(obj.popup).setLatLng(obj.pos); m.bindPopup(p).openPopup();});

on my site each page correspond to a marker, i would that when a page is loaded the marker which correspondt to the page come on center
i imagine to include in the script something to get the name of the page by example "page1.htm" then an other part which can get 44.653024, -69.19922 then put them at the end of the script inside  map.setView(new L.LatLng(lat, lng), 5);

i am not a professional in javascript and i dont know how to do perhaps someone could help me
thanks




k_man_au

unread,
May 7, 2018, 11:31:11 PM5/7/18
to Leaflet


<a '+am+'page1.htm" onClick='centerMe(44.653024, -69.19922); return false;'><b>page1</b></a>




function centerMe(x, y) {
    map.setView(new L.LatLng(x, y), map.getZoom());

}
Reply all
Reply to author
Forward
0 new messages