Leaflet Virtual Grid
You can use new VirtualGrid
to generate simple, cacheable, grids of L.LatLngBounds
objects you can use to query APIs. This lets you query APIs for smaller units and space and never make a call data in the same area twice.
Usage with Events
var vg = ; // listen for when new cells come into the view for the first timevg; // listen for when cells reenter the viewvg; // listen for when cells leave the viewvg; // add the grid to the mapvg;
Usage as a Class
var MyGrid = { console; } { console; } { console; } var thingWithGrid = ;
Options
var vg = cellSize: 512 updateInterval: 150;
updateInterval
How often to update the grid. Defaults to 150
cellSize
How big each cell is in pixels. Defaults to 512
Example
Here is what the grid looks like under the hood...
Each rectangle would represent a call to an API or query to a data source. You would only make one request per cell so you not make repeat calls to areas like requesting all the data in a map view when a user performs a small pan.
Credit
Most of this code is based on L.Grid
from https://github.com/Leaflet/Leaflet/commit/670dbaac045c7670ff26198136e440be9c2bb3e5.