Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Possible Duplicate:
How to show a popup on mouse-over, not on click?

I'm working with Leaflet library. I defined L.layerGroup and add some markers to the group. Can somebody help me with mouseover function on markers. I need to get function which will open popup when user mouseover on marker. How to write code for that function considering this coding I wrote? I'm new with Javascript so please consider that.

Thanks!

var cities = new L.layerGroup();

var city1 = new L.marker([35.896667,14.4625], {icon: myIcon} ).addTo(cities);
var city2 = new L.marker([35.882222,14.522222], {icon: myIcon} ).addTo(cities);
var city3 = new L.marker([35.840854,14.484347], {icon: myIcon} ).addTo(cities);
share|improve this question

marked as duplicate by whuber Sep 4 '12 at 11:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer 1

up vote 3 down vote accepted

You need to set a listener for the mouseover event. The markers page lists a "mouseover" event, and the events page shows how to configure a listener. So the code will be something like:

city1.on('mouseover', function(e) {
  //open popup;
  var popup = L.popup()
    .setLatLng(e.latlng) //(assuming e.latlng returns the coordinates of the event)
    .setContent('<p>Hello world!<br />This is a nice popup.</p>')
    .openOn(map);
});

(Note that I haven't actually tested that, so view it as pseudo-code)

Steve

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.