0
votes

I am using leaflet to draw a map and then insert a lot of markers on it afterwards. The markers come out nicely, I have a custom icon for them, but I can't get any of the popups to work with .bindPopup(). I get no errors either.

Here is my code:

var map = L.map('map').setView([60.20, 24.92], 11);

L.tileLayer('https://ssl_tiles.cloudmade.com/<APIKEY>/997/256/{z}/{x}/{y}.png', {
    attribution: '',
    maxZoom: 18
}).addTo(map);

function setLeafletMarker() {
        var markerLocation = new L.LatLng(60.2, 24.8);
        var marker = new L.Marker(markerLocation);
        map.addLayer(marker);
        marker.bindPopup("<b>Hello world!</b><br />I am a popup.")
}

$(document).ready(function () {
    setLeafletMarker()
}
2

2 Answers

1
votes

Your code works for me. Just add missing parentheses and semicolons and you're done. You can even simplify your code as you can see in Leaflet Quick Start tutorial:

function setLeafletMarker() {
    L.marker([60.2, 24.8])
        .addTo(map)
        .bindPopup("<b>Hello world!</b><br />I am a popup.");
};
-2
votes
bindPopup( <String> html | <HTMLElement> el | <Popup> popup, <Popup options> options? ) 

Binds a popup with a particular HTML content to a click on this marker. You can also open the bound popup with the Marker openPopup method.

Ref : The official leaflet doc