Link to location

by nouse4contact

HTML

<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css">
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<div id="map">
</div>

<div id="map-navigation" class="map-navigation">
    <a href="#" data-zoom="12" data-position="48.06633,7.67268">
     Link
     </a>
</div>

CSS

#map { height: 180px; }

JavaScript

var map = L.map('map').setView([48.45653, 8.90068], 8);

    L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        maxZoom: 18,
        attribution: 'Map data &copy; <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();