Get a list of markers/layers within current map bounds in Leaflet

前端 未结 4 1329
面向向阳花
面向向阳花 2020-12-31 03:46

This is somewhat similar to the question asked here --

I\'m writing a search box for a map application, which retrieves a whole set of search results (people\'s name

4条回答
  •  情话喂你
    2020-12-31 03:58

    You have to check the bounds of each layer versus the map's bounds. Because eachLayer() returns all layers regardless of whether they are in the visible extent.

    if(map.getBounds().contains(layer.getLatLng())) { ... }
    

    In Stefano's code, this is shown around this line:

    https://github.com/stefanocudini/leaflet-list-markers/blob/master/src/leaflet-list-markers.js#L95

提交回复
热议问题