I want open a popup on bottom of my marker icon in Leaflet.
my code:
var mymap = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', {
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: 'mapbox.streets'
}).addTo(mymap);
var lati = 51.51;
var longi = -0.09;
var popupLocation1 = new L.LatLng(lati, longi);
var popupContent1 = 'This is a nice popup';
popup1 = new L.Popup();
popup1.setLatLng(popupLocation1);
popup1.setContent(popupContent1);
var m1 = L.marker([ lati, longi ]).addTo(mymap);
m1.bindPopup(popup1);
m1.openPopup();
So I get a popup on top of my marker.
I want get a popup on bottom like:
Best Answer
You can specify the offsets by using the
popupAnchor
options, but not where you would expect it. First, you need to specify an icon like this:You can then use this icon in your marker options:
Now your popup opens up 30 px above your marker. This is not exactly what you asked for as you also need to place the little arrowish triangle on the top of your popup, but I think it's still worth mentioning.