$(document).ready(function(){ var latLng = L.latLng(43.29312496, -1.86638759); 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.29312496, -1.86638759], {draggable: false, autoPan: false, icon: L.icon({iconUrl: 'https://kartadigitalak.eus/images/icons/marker.png', iconAnchor: [0, 0]})}).bindPopup('Zuberoa jatetxea
Araneder Bidea, Barrio Iturriotz 20180 OIARTZUN, Gipuzkoa
Oiartzun').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 }); });