comparison bandmap/static/js/bandmap.js @ 827:5103edd3acc4

Bandmap: initial version complete. Javascript queries server for band data. View created to handle query. Test created for view. Link added to map in sidebar. Template tweaks.
author Brian Neal <bgneal@gmail.com>
date Sat, 27 Sep 2014 19:41:41 -0500
parents 71db8076dc3d
children b9973588af28
comparison
equal deleted inserted replaced
826:d7e4c08b2e8b 827:5103edd3acc4
1 var bandmap = null; 1 var bandmap = null;
2 var geocoder = null; 2 var geocoder = null;
3 var surfbands = [];
4 var map_options = {
5 center: {lat: 15.0, lng: -30.0},
6 zoom: 2
7 };
8 var info_win = null;
3 9
4 function addBandOnSubmit(event) { 10 function addBandOnSubmit(event) {
5 var location = $('#id_location').val(); 11 var location = $('#id_location').val();
6 if (!location) { 12 if (!location) {
7 alert("Please enter a location"); 13 alert("Please enter a location");
24 } 30 }
25 }); 31 });
26 return false; 32 return false;
27 } 33 }
28 34
35
36 function refreshMap() {
37 bandmap.setOptions(map_options);
38 $.each(surfbands, function(i, band) {
39 band.marker.setMap(null);
40 });
41 surfbands.length = 0;
42 var band_sel = $('#map-bands');
43 band_sel[0].length = 0;
44 band_sel.append($('<option>', {value: -1}).html('(select)'));
45 var count_span = $('#map-band-count');
46 count_span.html('0');
47 var filter = $('#map-filter option:selected').val();
48
49 $.getJSON('/bandmap/query/', {show: filter},
50 function(data) {
51 $.each(data, function(i, band) {
52 band_sel.append($('<option>', {value: i, text: band.name}));
53 var marker = new google.maps.Marker({
54 position: {lat: band.lat, lng: band.lon},
55 title: band.name,
56 map: bandmap
57 });
58 google.maps.event.addListener(marker, 'click', function() {
59 info_win.setContent(band.note);
60 info_win.open(bandmap, marker);
61 });
62 surfbands[i] = band;
63 surfbands[i].marker = marker;
64 });
65 count_span.html(data.length);
66 });
67 }
68
29 $(document).ready(function() { 69 $(document).ready(function() {
30 var map_div = $('#map-canvas'); 70 var map_div = $('#map-canvas');
31 if (map_div.length) { 71 if (map_div.length) {
32 var map_options = {
33 center: {lat: 15.0, lng: -30.0},
34 zoom: 2
35 };
36 bandmap = new google.maps.Map(map_div[0], map_options); 72 bandmap = new google.maps.Map(map_div[0], map_options);
73 info_win = new google.maps.InfoWindow();
74 $('#map-filter-go').click(refreshMap);
75 $('#map-bands').change(function() {
76 var n = $('option:selected', this).val();
77 if (n != -1) {
78 info_win.setContent(surfbands[n].note);
79 info_win.open(bandmap, surfbands[n].marker);
80 }
81 });
82 refreshMap();
37 } 83 }
38 84
39 var add_form = $('#bandmap-add-form'); 85 var add_form = $('#bandmap-add-form');
40 if (add_form.length) { 86 if (add_form.length) {
41 geocoder = new google.maps.Geocoder(); 87 geocoder = new google.maps.Geocoder();