1

First time I used the leaflet. I want to create a popup on marker. On mouse-over of marker I want to get a popup message . my code is :

for (var i = 0; i <= result.length - 1; i++) {
    var px = result[i]['p1_x'];
    var py=result[i]['p1_y'];
    var map = this.state.maps[0];


   // create custom icon
    var firefoxIcon = L.icon({
         iconUrl:  LOCAL_BASE_URL + '/assets/heatmap/' +'/HARBOURFRONT/' + "/" + BASEMAPS + "/" +  'icon_sensor.png',
         iconSize: [15, 15], // size of the icon
   });

   console.log(" drawAllBaseMaps1 add icon inside map");
   // create marker object, pass custom icon as option, ad/d to map         
   var marker = L.marker([px, py], {icon: firefoxIcon}).addTo(map);

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

It is not working.

John Powell
  • 13,649
  • 5
  • 46
  • 62
saranya
  • 11
  • 1
  • where do you get an error and what is the message? – LaughU Sep 25 '17 at 12:01
  • please edit your code to be more specific on your problem (ex : don't need to know "// create custom icon section" – Hugo Roussaffa Sep 25 '17 at 12:58
  • I believe you need the mouseover from the marker onEachFeature function. Might want to look at: https://gis.stackexchange.com/questions/31951/how-to-show-a-popup-on-mouse-over-not-on-click https://gis.stackexchange.com/questions/131944/leaflet-marker-mouseover-popup – Bill Chappell Sep 25 '17 at 14:26

0 Answers0