ianh / district-tiler

Look up congressional districts client-side using only JavaScript and static files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need to turn long/lat points into US congressional districts?
Copy the 'tiles' directory into your web site and use the following code:

<script src="tiles/lookup.js"></script>
<script>
lookupDistrict(longitude, latitude, function (found, state, district) {
    if (found === "found") {
        // ...
    }
});
</script>

Calling lookupDistrict() finds the proper tile in the 'tiles' directory, then
tests each polygonal district in the tile until it finds one containing the
query point.  No requests are made to any service -- the tile data are hosted as
as static files.

To re-generate the 'tiles' directory, compile and run main.go.  It takes as
input a shapefile of congressional districts (available from the US Census
Bureau at http://www.census.gov/geo/maps-data/data/tiger-line.html) and slices
it up into tiles.  These tiles are adaptively sized and indexed using a
k-d tree -- see the code for details.

About

Look up congressional districts client-side using only JavaScript and static files.

License:Other


Languages

Language:Go 59.3%Language:JavaScript 40.7%