Leaflet: .on ('popupopen') evento não disparado em marcadores

Criado em 22 set. 2014  ·  3Comentários  ·  Fonte: Leaflet/Leaflet

Olá,

CONTEXTO
Eu escrevi várias diretivas AngularJS para folheto. Um para o mapa, um para a camada, um para marcadores e um para pop-ups.

A diretiva angular para pop-up está ouvindo um marcador para ser associado.

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

ESPERADO
Todos os eventos devem ser disparados.

RESULTADO

popupevent não foi demitido? Os outros são despedidos.


Folheto: 0,7,2
SO: Windows 7
navegador: Google Chrome 37 e Firefox 32

Comentários muito úteis

Aqui está o problema, quando você faz isso

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

O método bindPopup() pode ter um objeto String ou Popup. Para este exemplo, passamos uma String e o método criará o pop-up correto. Se você passar um elemento pop-up personalizado, será necessário anexar o marcador ao pop-up antes. Caso contrário, o pop-up nunca terá seu elemento de origem.

A solução final.

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);
    });

Todos 3 comentários

Depois de alguns testes, o problema veio de nossa biblioteca personalizada pop-up.

comentar avez vous fait?

22/09/2014 11h39 GMT + 02h Pierre Baron [email protected] :

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

-
Responda a este e-mail diretamente ou visualize-o no GitHub
https://github.com/Leaflet/Leaflet/issues/2907#event -168346883.

Aqui está o problema, quando você faz isso

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

O método bindPopup() pode ter um objeto String ou Popup. Para este exemplo, passamos uma String e o método criará o pop-up correto. Se você passar um elemento pop-up personalizado, será necessário anexar o marcador ao pop-up antes. Caso contrário, o pop-up nunca terá seu elemento de origem.

A solução final.

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);
    });
Esta página foi útil?
0 / 5 - 0 avaliações

Questões relacionadas

ttback picture ttback  ·  4Comentários

onethread picture onethread  ·  3Comentários

arminghm picture arminghm  ·  3Comentários

edmsgists picture edmsgists  ·  3Comentários

CallMarl picture CallMarl  ·  3Comentários