I have an application that displays recent tasks on the map, like points using Leafletjs.
With Leafletjs, when you want to zoom in to a location discovered by the user, you call something like:
map.locate({'setView' : true, 'timeout' : 10000, maxZoom: 10});
However, for some locations, zoom level 10 does not contain any tasks, so I would like to dynamically set the scale so that at least the task is visible to users.
I know that I can listen for the success of the localization function and then check something like:
map.on('locationfound', function() { //for marker in markers{ //is point within currently visible bounds //break on first positive //else, //zoom up a level, repeat previous checks } }
but itβs quite inefficient, especially if I have a large number of points.
Does Leaflet have built-in functions / methods for providing layer information in the current map view?
source share