Search code examples
angularjsleafletangular-leaflet-directive

Angular Leaflet Search control event


I have an AngularJS application and I'm currently trying to access the "search_expanded" event of Leaflet Search control but having no luck.

Here's my code:

angular.module('myApp', [ 'leaflet-directive' ])
       .controller('ShowMapCtrl', ["$scope", "leafletData", function ($scope, leafletData) {
       // some code
            leafletData.getMap().then(function(map) {
                       map.on('search_expanded', function(e){
                            alert("search control expannded"); 
                       });
                   });

Solution

  • The search_expanded event, and all the other events supported by L.Control.Search are fired on the actual control instance not on the map instance as you can see in the following example:

    var controlSearch = new L.Control.Search({
        layer: new L.LayerGroup()
    }).on('search_expanded', function () {
        console.log('search_expanded!')
    }).addTo(map);
    

    http://plnkr.co/edit/njeXYb4PfbaG3hppcgmO?p=preview