简体   繁体   中英

Catch Leaflet Search event

I'm trying to add a search box to my leaflet map viewer:

var controlSearch = new L.Control.Search({
    layer: new L.LayerGroup()
}).on('search_expanded', function () {
    console.log('search_expanded!')
}).on('popupopen', function(e) {
    var marker = e.popup._source.feature.properties.markerid;
}).addTo(map);

I need to add custom code to execute the search function on events , on which I've put break points. However the code isn't reaching my events when I press the search button or type text.
I'm using the map to show area's of land. The search has to identify area's based on their custom properties and highlight them or something else to identify them to the user. So the search should not apply to location or anything like that, but custom properties of the items that are being shown. The page mostly works with jQuery, no Angular.

I haven't been able to find a list of events.
So how do I catch the event where the user types?

You can add event like this to search input box:

var controlSearch = new L.Control.Search({
   layer: new L.LayerGroup()
}).on('search:expanded', function () {
   this._input.onkeyup = function(){
     console.log(this.value)
   }

}).addTo(map);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM