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.

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.