Leaflet: .on('popupopen') event not fired on markers

Created on 22 Sep 2014  ·  3Comments  ·  Source: Leaflet/Leaflet

Hello,

CONTEXT
I wrote several AngularJS directives for leaflet. One for the map, one for the layer, one for markers and one for popups.

The angular directive for popup, is listening for a marker to be associated to.

    .bindPopup(popup)
    .on('dragstart', function () {
        console.log(dragstart");
    })
    .on('dragend', function () {
        console.log("dragend!");
    })
    .on('popupopen', function (popup) {
        console.log("popup opened !", popup);
    });

EXPECTED
All events should be fired.

RESULT

popupevent is not fired? The others are fired.


Leaflet : 0,7,2
OS : Windows 7
browser : Google Chrome 37 & Firefox 32

Most helpful comment

Here is the problem, when you do this

var coordinates = {};
var markerOptions = {};
var marker = L.marker(coordinates), markerOptions );
marker.bindPopup("my content");

The bindPopup() method can have either a String or a Popup object. For this example, we pass a String and the method will create the right popup. If you pass a custom popup element, you have to append the marker into the popup before. Otherwise, the popup will never have its source element.

The final solution.

var coordinates = {};
var markerOptions = {};
var marker = L.marker(coordinates), markerOptions );

var popupOptions = {};
// you have to append the marker on the creation of the popup
// so that the popup element will have the marker source.
var popup = L.popup(popupOptions, marker );

// and this will work !
marker
    .bindPopup(popup)
    .on('dragstart', function () {
        console.log(dragstart");
    })
    .on('dragend', function () {
        console.log("dragend!");
    })
    .on('popupopen', function (popup) {
        console.log("popup opened !", popup);
    });

All 3 comments

After some tests, the problem came from our popup custom library.

comment avez vous fait?

2014-09-22 11:39 GMT+02:00 Pierre Baron [email protected]:

Closed #2907 https://github.com/Leaflet/Leaflet/issues/2907.


Reply to this email directly or view it on GitHub
https://github.com/Leaflet/Leaflet/issues/2907#event-168346883.

Here is the problem, when you do this

var coordinates = {};
var markerOptions = {};
var marker = L.marker(coordinates), markerOptions );
marker.bindPopup("my content");

The bindPopup() method can have either a String or a Popup object. For this example, we pass a String and the method will create the right popup. If you pass a custom popup element, you have to append the marker into the popup before. Otherwise, the popup will never have its source element.

The final solution.

var coordinates = {};
var markerOptions = {};
var marker = L.marker(coordinates), markerOptions );

var popupOptions = {};
// you have to append the marker on the creation of the popup
// so that the popup element will have the marker source.
var popup = L.popup(popupOptions, marker );

// and this will work !
marker
    .bindPopup(popup)
    .on('dragstart', function () {
        console.log(dragstart");
    })
    .on('dragend', function () {
        console.log("dragend!");
    })
    .on('popupopen', function (popup) {
        console.log("popup opened !", popup);
    });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ttback picture ttback  ·  4Comments

broofa picture broofa  ·  4Comments

arminghm picture arminghm  ·  3Comments

onethread picture onethread  ·  3Comments

CallMarl picture CallMarl  ·  3Comments