Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

put a marker down

  • Loading branch information...
commit 46d0d8684dd9717c03615fbd43bbdab47f13fc2d 1 parent 5f8476e
@JoeGermuska JoeGermuska authored
Showing with 23 additions and 8 deletions.
  1. +3 −2 censusweb/api/views.py
  2. +20 −6 censusweb/media/js/map.js
View
5 censusweb/api/views.py
@@ -259,7 +259,7 @@ def map_contains(request):
point = request.REQUEST.get('point',None)
try:
lat,lng = point.split(',',1)
- point = Point(float(lat),float(lng))
+ point = Point(float(lng),float(lat))
except:
raise TypeError("A point must be provided as a comma-separated string, 'lat,lng'")
@@ -273,5 +273,6 @@ def map_contains(request):
boundaries = Boundary.objects.filter(shape__contains=point,set__slug__in=types)
geoids = sorted(x[0] for x in boundaries.values_list('external_id'))
geoids = ','.join(geoids)
- return HttpResponseRedirect(reverse('map',kwargs={'geoids': geoids}))
+ url = reverse('map',kwargs={'geoids': geoids}) + "#%.6f,%.6f" % (point.y,point.x)
+ return HttpResponseRedirect(url)
View
26 censusweb/media/js/map.js
@@ -57,17 +57,26 @@ function leaflet_point_from_google_point(location) {
}
function handle_geocode(result) {
- window.geostash = result;
- window.map.panTo(leaflet_point_from_google_point(result.geometry.location));
- window.map.fitBounds(leaflet_bounds_from_google_viewport(result.geometry.viewport));
+ // window.map.panTo(leaflet_point_from_google_point(result.geometry.location));
+ // window.map.fitBounds(leaflet_bounds_from_google_viewport(result.geometry.viewport));
+ window.location = "/map/contains?point=" + result.geometry.location.lat() + "," + result.geometry.location.lng();
}
-function init_map(lat, lng) {
+function init_map() {
if (window.map == null) {
- if (lat == null || lng == null) {
+ var marker_at_center = false;
+
+ if (window.location.hash) {
+ var locstr = window.location.hash.substr(1);
+ parts = locstr.split(',');
+ lat = parseFloat(parts[0]);
+ lng = parseFloat(parts[1]);
+ marker_at_center = true;
+ } else {
lat = 41.882087;
lng = -87.627799;
- }
+ }
+
var ll = new L.LatLng(lat, lng);
window.map = new L.Map('map', {
@@ -75,6 +84,11 @@ function init_map(lat, lng) {
center: ll,
});
+ if (marker_at_center) {
+ user_marker = new L.Marker(ll, { draggable: false });
+ window.map.addLayer(user_marker);
+ }
+
tiles = new L.TileLayer("http://mt1.google.com/vt/lyrs=m@155000000&hl=en&x={x}&y={y}&z={z}&s={s}", {
maxZoom: 17,
attribution: "Map data is Copyright Google, 2011"

0 comments on commit 46d0d86

Please sign in to comment.
Something went wrong with that request. Please try again.