Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-virtual-grid

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-virtual-grid

A lightweight DOM-less tile layer for Leaflet that can be used to query APIs with bounding boxes or center/radius as opposed to loading tiles.

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by49.51%
Maintainers
2
Weekly downloads
 
Created
Source

Leaflet Virtual Grid

npm version build status

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 = new VirtualGrid();

// listen for when new cells come into the view for the first time
vg.on("cellcreate", function(e){
  console.log(e.type, e);
});

// listen for when cells reenter the view
vg.on("cellenter", function(e){
  console.log(e.type, e);
});

// listen for when cells leave the view
vg.on("cellleave", function(e){
  console.log(e.type, e);
});

// add the grid to the map
vg.addTo(map);

Usage as a Class

var MyGrid = new VirtualGrid.extend({
  createCell: function(bounds, coords){
    console.log('create cell', bounds, coords);
  },

  cellEnter: function(bounds, coords){
    console.log('cell enter', bounds, coords);
  },

  cellLeave: function(bounds, coords){
    console.log('cell leave', bounds, coords);
  }
})

var thingWithGrid = new MyGrid().addTo(map);

Options

var vg = new VirtualGrid({
  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...

Example

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.

Keywords

FAQs

Package last updated on 04 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc