by leaflet-extras

leaflet-extras / RTree

R-Tree Library for Javascript, optimized for maps.

211 Stars 36 Forks Last release: Not found MIT License 158 Commits 8 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

rTree Build Status

A non-recursive R-Tree library in pure JavaScript with no dependencies. Fork of Jon-Carlos Rivera's fantastic library which sadly seems not to be maintained. MIT Licensed.

So far:

  • Bug fix when deleting points.
  • Common.js module.
  • Updated tests.
  • Factory function for constructor.
  • Method for dealing with GeoJSON.
  • All methods now accept callbacks.
  • Query by bbox instead of rectangle.
  • Submit to NPM.
  • Update examples.
  • add closure
  • add GruntFile
  • fix syntax (make it pass jslint)
  • more modular
  • that bug with deleting


  • RTree ( [ Number **maxnodewidth, Function **callback ] )


  • maxnodewidth : optional : The maximum width of a node before a split is performed1.


  • An empty rTree object.


  • Make a new rTree with a max node width of 10:
  • var myRTree = RTree(10);


  • rTree.insert ( Rectangle3 bounds, Object element)


  • bounds : required : A minimally bounding box for element.
  • element : required : An object to add to the R-Tree.


  • True.


  • Insert a 10x10 object that starts at position 10x10:
  • myRTree.insert({x:10, y:10, w:10, h:10}, myObject);


  • rTree.remove ( Rectangle3 area _[, Object element)


  • area : required : An area to search within.
  • element : optional : An object to remove from the R-Tree. If no object is specified, all elements that touch area are deleted.


  • An array of leafs deleted from the R-Tree.


  • Deletes all object that touch the 10x10 rectangle starting at position 10x10:
  • var myDelCount = myRTree.delete({x:10, y:10, w:10, h:10});
  • Delete only specific object if it touches the 10x10 rectangle starting at position 10x10:
  • var myDelCount = myRTree.delete({x:10, y:10, w:10, h:10}, specific_object);


  • rTree.geoJSON ( Object or Array geoJSON)


  • geoJSON : required : Either an Object representing a GeoJSON feature collection or an Array representing a list of GeoJSON features.




  • rTree.bbox ( Bounds area)


  • area : required : Area to search, this can either be represented by a single parameter bounds array
    , two parameters representing the southwest and northeast corners
    , or 4 parameters of


  • An array of matched features.


  • Search a 10x10 area that starts at position 10x10 (these are all equivalent):
  • var myObjects1 = myRTree.bbox([[10,10],[20,20]]);
  • var myObjects2 = myRTree.bbox([[10,10],[20,20]]);
  • var myObjects3 = myRTree.bbox([10,10],[20,20]);
  • var myObjects4 = myRTree.bbox([10,10],[20,20]);
  • var myObjects5 = myRTree.bbox(10,10,20,20);
  • var myObjects6 = myRTree.bbox(10,10,20,20);


  • RTree.search ( Rectangle3 area [, Boolean return node, Array return_array ])


  • area : required : An area to search within.
  • return node : optional : Whether to return the entire node, mainly internal option.
  • return array : optional : An existing array to add the results to, defaults to [], mainly internal option.


  • An array of objects that overlap or touch area.


  • Search a 10x10 area that starts at position 10x10:
  • var myObjects = myRTree.search({x:10, y:10, w:10, h:10});


1 Default max node width is currently 6.

3 A Rectangle is any object with public x, y, w, h properties. The object itself is not saved or used directly but copies are made of its x, y, w, h properties.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.