I'm trying to give a popup for the mouse hover event instead of click on markers and do some some other stuff (e.g. a func) when it's get clicked.
My half successful code which I don't believe will help you think in that direction:
(I'm simply adding a hover on click event)
marker[i].on('mouseover', marker[i].bindPopup('hi').openPopup.bind(marker[i]));
[i] simply stands for a loop
Leaflet's API: http://leaflet.cloudmade.com/reference.html#map-openpopup
The following code shows a popup when the marker is moused over and does something else when the marker is clicked:
marker[i].on('mouseover', function(evt) {
//evt.target is the marker that is being moused over
//bindPopup() does not need to be called here if it was already called
//somewhere else for this marker.
evt.target.bindPopup('hi').openPopup();
});
marker[i].on('click', function(evt) {
//again, evt.target will contain the marker that was clicked
console.log('you clicked a marker');
});
You are not providing a callback for the mouseover event.
marker[i].on('mouseover', function () {
marker[i].bindPopup('hi').openPopup.bind(marker[i])
});
Pass in an anonymous function as your callback, when it is invoked it will do what you want.
I am not very familiar with leaflet api (just started using it a few months back) so there may also be an issue with marker[i].bindPopup('hi').openPopup.bind(marker[i])
as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With