Click link inside Leaflet Popup and do Javascript

前端 未结 7 1822
遇见更好的自我
遇见更好的自我 2020-12-05 06:42

I have a leaflet map up and running. It overlays a series of polygons (via GeoJSON) on the map and attaches popups to each polygon. Each of the popups display information a

7条回答
  •  一生所求
    2020-12-05 07:22

    That's what I find on the mapbox offical website: Create a click event in a marker popup with Mapbox.js and jQuery. The comment explains why we say $('#map') instead of $('#mybutton').

    var marker = L.marker([43.6475, -79.3838], {
      icon: L.mapbox.marker.icon({
        'marker-color': '#9c89cc'
      })
    })
    .bindPopup('')
    .addTo(map);
    //The HTML we put in bindPopup doesn't exist yet, so we can't just say
    //$('#mybutton'). Instead, we listen for click events on the map element which will bubble up from the tooltip, once it's created and someone clicks on it.
    
    $('#map').on('click', '.trigger', function() {
    alert('Hello from Toronto!');});
    

提交回复
热议问题