I've run into a little problem regarding the awesome leaflet map. I want to display a map with a couple of markers on it. Below this map I want to place some content, including a link once in a while that, when clicked, will move and zoom to one of those markers. I found some code on Stack Overflow that supposedly should do the trick, but it doesn't work for me and I cannot figure out where I've taken a wrong turn.
This is the code I'm using for the map and zooming onclick:
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script>
var map = L.map('map').setView([48.45653, 8.90068], 8);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'examples.map-i86knfo3'
}).addTo(map);
var circle = L.circle([48.06591, 7.67221], 80, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.3
}).addTo(map)
.bindPopup("Popup").openPopup();
L.marker([48.06633, 7.67268]).addTo(map)
.bindPopup("<b>Popup</b><br />Text");
L.marker([48.8098, 9.44223]).addTo(map)
.bindPopup("<b>Popup</b><br />Text");
document.getElementById('map-navigation').onclick = function(abc) {
var pos = abc.target.getAttribute('data-position');
var zoom = abc.target.getAttribute('data-zoom');
if (pos && zoom) {
var locat = pos.split(',');
var zoo = parseInt(zoom);
map.setView(locat, zoo, {animation: true});
return false;
}
}
var popup = L.popup();
</script>
This is the html I'm using as a link:
<div id="map">
<div id="map-navigation" class="map-navigation">
<a href="#" data-zoom="12" data-position="48.06633,7.67268">
Link
</a>
</div>
</div>