comparison bandmap/static/js/bandmap.js @ 821:71db8076dc3d

Bandmap WIP: geocoding integrated with add form. Add form works. Before submitting the form, client side JS makes a geocode request to Google and populates hidden lat/lon fields with the result. Successfully created a model instance on the server side. Still need to update admin dashboard, admin approval, and give out badges for adding bands to the map. Once that is done, then work on displaying the map with filtering.
author Brian Neal <bgneal@gmail.com>
date Tue, 23 Sep 2014 20:40:31 -0500
parents 9a0df7bd2409
children 5103edd3acc4
comparison
equal deleted inserted replaced
820:9a0df7bd2409 821:71db8076dc3d
1 var bandmap = null;
2 var geocoder = null;
3
4 function addBandOnSubmit(event) {
5 var location = $('#id_location').val();
6 if (!location) {
7 alert("Please enter a location");
8 return false;
9 }
10 var button = $(this);
11 button.attr('disabled', 'disabled');
12 var form = $('#bandmap-add-form');
13 geocoder.geocode({'address': location}, function(results, status) {
14 button.removeAttr('disabled');
15 if (status == google.maps.GeocoderStatus.OK) {
16 $('#id_lat').val(results[0].geometry.location.lat().toString());
17 $('#id_lon').val(results[0].geometry.location.lng().toString());
18 $(form).submit();
19 }
20 else {
21 var msg = "Geocode unsuccessful: " + status + "\n" +
22 "Enter a new location";
23 alert(msg);
24 }
25 });
26 return false;
27 }
28
1 $(document).ready(function() { 29 $(document).ready(function() {
2 var map_div = $('#map-canvas'); 30 var map_div = $('#map-canvas');
3 if (map_div.length) { 31 if (map_div.length) {
4 var map_options = { 32 var map_options = {
5 center: {lat: 15.0, lng: -30.0}, 33 center: {lat: 15.0, lng: -30.0},
6 zoom: 2 34 zoom: 2
7 }; 35 };
8 var map = new google.maps.Map(map_div[0], map_options); 36 bandmap = new google.maps.Map(map_div[0], map_options);
9 } 37 }
10 38
11 var add_form = $('#bandmap-add-form'); 39 var add_form = $('#bandmap-add-form');
12 if (add_form.length) { 40 if (add_form.length) {
41 geocoder = new google.maps.Geocoder();
42 $('#bandmap-add-submit').click(addBandOnSubmit);
13 } 43 }
14 }); 44 });