sposnjak
sposnjak

Reputation: 1499

How to fire event on leaflet marker with angularjs

I use angular-leaflet-directive to display a map populated with multiple markers and I have a table from where the user can choose one of the markers. I know how to center (to show on map) the one marker which was clicked in the table, but I would like to open the popup message of the marker. I know that I need to fire an click event on the map but I do not understand how to do it in a "angular way". Any advice would be deeply appreciated.

Upvotes: 1

Views: 2923

Answers (1)

Justin Poehnelt
Justin Poehnelt

Reputation: 3469

Capture marker click with this:

$scope.$on('leafletDirectiveMarker.click', function(e, args) {
    // Args will contain the marker name and other relevant information
    console.log("Leaflet Click");
});

I don't know why you would need to do this though as angular-leaflet-directive is already doing so. See this example. Make sure you have the markers setup correctly:

markers: {
      m1: {
        lat: 51.505,
        lng: -0.09,
        focus: true, // popup message visible
        draggable: false,
        message: "Hi there!" // popup message
      }
}

Upvotes: 5

Related Questions