Aggregate Map Tools

Aggregate Map Tools is a set of PHP and JavaScript code, used with Google Maps, that makes it easy to aggregate multiple spatially close data points into one marker on the map, preventing the map from being overrun with many markers close together.

This code is being released courtesy of my employer, The Bivings Group, which funded its development.

This code is being released in two parts. The first, GlobalMapTiles, is code that makes it easy to aggregate multiple nearby locations into one marker on the map.

The second part, which implements the more interesting search and retrieval and interfaces with Google Maps, is not finished, but will be released soon.

This code is licensed under the X11 license.

GlobalMapTiles

GlobalMapTiles, available as PHP and JavaScript code, provides support for converting between latitude and longitude coordinates and a “quadtree” representation that makes it easy to search a database for physically close points.

This code is based on globalmaptiles.py by Klokan Petr Přidal, with additions.

How to use:

The interface for the PHP and JavaScript versions are indentical.

To convert a latitude/longitude to quadtree representation, create a new instance of the GlobalMercator object, and call QuadTreeFromLatLon:

$mercator = new GlobalMercator();
$quadtree = $mercator->QuadTreeFromLatLon(38.9193540, -77.0705180, 19);

To convert the quadtree back into a region:

$mercator = new GlobalMercator();
$bounds = $mercator->QuadTreeToLatLon($quadtree);

$centerLat = ($bounds[0] + $bounds[2]) / 2;
$centerLon = ($bounds[1] + $bounds[3]) / 2;

To get a list of all of the quadtree ids within a given rectangle (say, that of a google map window):

var mercator = new GlobalMercator();
var bounds = map.getBounds();

var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
quadtreeList = mercator.GetQuadTreeList(zoom, [sw.lat(), sw.lng()], [ne.lat(), ne.lng()]);
for(var quadtree in quadtreeList)
	document.write(quadtree + ' ( ' + quadtreeList[quadtree] + ' )<br />');