$(document).ready(function(){
    var latLng = L.latLng(43.36025847, -1.80390358);
    var zoom = 18;
    var mapa = L.map('mapa_ostatuak', {
        center: latLng,
        zoom: zoom,
        layers: [ new L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
            attribution: '© OpenStreetMap contributors',
            maxZoom: 18
        })]
    });
        L.marker([43.36025847, -1.80390358], {draggable: false, autoPan: false, icon: L.icon({iconUrl: 'https://kartadigitalak.eus/images/icons/marker.png', iconAnchor:   [0, 0]})}).bindPopup('Laia jatetxea
Hondarribia').addTo(mapa);
    
    mapa.on('popupopen', function(e) {
        var px = mapa.project(e.target._popup._latlng); // find the pixel location on the map where the popup anchor is
        px.y -= e.target._popup._container.clientHeight/2; // find the height of the popup container, divide by 2, subtract from the Y axis of marker location
        mapa.panTo(mapa.unproject(px),{animate: true}); // pan to new center
    });
});