Permalink
Browse files

add geocodify; next, look up shapes and data based on result

  • Loading branch information...
1 parent 18ac3af commit 6bc3b042dc39619df6ae48b3176571e7b4a38663 @JoeGermuska JoeGermuska committed Sep 2, 2011
Showing with 26 additions and 2 deletions.
  1. +4 −1 censusweb/api/templates/map.html
  2. +22 −1 censusweb/media/js/map.js
@@ -5,8 +5,11 @@
{% block content %}
<link rel="stylesheet" href="{{ MEDIA_URL }}leaflet/leaflet.css" type="text/css" charset="utf-8">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
+<script type="text/javascript" src="https://raw.github.com/datadesk/jquery-geocodify/master/jquery.geocodify.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}leaflet/leaflet.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/map.js"></script>
-<h1>A map goes here!</h1>
+<div id="legend">
+<form id="geocoder"></form>
+</div>
<div id="map" style="height: 500px"></div>
{% endblock %}
View
@@ -1,5 +1,6 @@
$(function(){
-
+var geocoder = new google.maps.Geocoder();
+window.boundary_layers = {}
function coords_to_paths(coords) {
// Construct new polygons
var paths = [];
@@ -42,6 +43,20 @@ window.parseGeoids = function() {
return geoids;
}
+function move_map_based_on_geocode(map,result) {
+ var viewport = result.geometry.viewport;
+ var top_left = new L.LatLng(viewport.getNorthEast().lat(), viewport.getSouthWest().lng());
+ var bottom_right = new L.LatLng(viewport.getSouthWest().lat(),viewport.getNorthEast().lng())
+ bounds = new L.LatLngBounds(top_left, bottom_right);
+ map.fitBounds(bounds);
+}
+function handle_geocode(result) {
+ window.geostash = result;
+ lat = result.geometry.location.lat();
+ lng = result.geometry.location.lng();
+ window.map.panTo(new L.LatLng(lat,lng));
+ move_map_based_on_geocode(window.map,result);
+}
window.map = null;
function init_map(lat, lng) {
if (window.map == null) {
@@ -66,7 +81,12 @@ function init_map(lat, lng) {
for (var i = 0; i < geoids.length; i++) {
add_boundary(geoids[i]);
}
+
}
+
+ $("#geocoder").geocodify({
+ onSelect: handle_geocode
+ });
}
window.add_boundary = function(geoid) {
@@ -83,6 +103,7 @@ window.add_boundary = function(geoid) {
});
map.addLayer(displayed_polygon);
+ window.boundary_layers[geojson.external_id] = displayed_polygon;
map.fitBounds(x.bounds);
});
}

0 comments on commit 6bc3b04

Please sign in to comment.