bgneal@821
|
1 var bandmap = null;
|
bgneal@821
|
2 var geocoder = null;
|
bgneal@827
|
3 var surfbands = [];
|
bgneal@827
|
4 var map_options = {
|
bgneal@827
|
5 center: {lat: 15.0, lng: -30.0},
|
bgneal@827
|
6 zoom: 2
|
bgneal@827
|
7 };
|
bgneal@827
|
8 var info_win = null;
|
bgneal@821
|
9
|
bgneal@821
|
10 function addBandOnSubmit(event) {
|
bgneal@821
|
11 var location = $('#id_location').val();
|
bgneal@821
|
12 if (!location) {
|
bgneal@821
|
13 alert("Please enter a location");
|
bgneal@821
|
14 return false;
|
bgneal@821
|
15 }
|
bgneal@821
|
16 var button = $(this);
|
bgneal@821
|
17 button.attr('disabled', 'disabled');
|
bgneal@821
|
18 var form = $('#bandmap-add-form');
|
bgneal@821
|
19 geocoder.geocode({'address': location}, function(results, status) {
|
bgneal@821
|
20 button.removeAttr('disabled');
|
bgneal@821
|
21 if (status == google.maps.GeocoderStatus.OK) {
|
bgneal@821
|
22 $('#id_lat').val(results[0].geometry.location.lat().toString());
|
bgneal@821
|
23 $('#id_lon').val(results[0].geometry.location.lng().toString());
|
bgneal@821
|
24 $(form).submit();
|
bgneal@821
|
25 }
|
bgneal@821
|
26 else {
|
bgneal@821
|
27 var msg = "Geocode unsuccessful: " + status + "\n" +
|
bgneal@821
|
28 "Enter a new location";
|
bgneal@821
|
29 alert(msg);
|
bgneal@821
|
30 }
|
bgneal@821
|
31 });
|
bgneal@821
|
32 return false;
|
bgneal@821
|
33 }
|
bgneal@821
|
34
|
bgneal@827
|
35
|
bgneal@827
|
36 function refreshMap() {
|
bgneal@827
|
37 bandmap.setOptions(map_options);
|
bgneal@827
|
38 $.each(surfbands, function(i, band) {
|
bgneal@827
|
39 band.marker.setMap(null);
|
bgneal@827
|
40 });
|
bgneal@827
|
41 surfbands.length = 0;
|
bgneal@827
|
42 var band_sel = $('#map-bands');
|
bgneal@827
|
43 band_sel[0].length = 0;
|
bgneal@827
|
44 band_sel.append($('<option>', {value: -1}).html('(select)'));
|
bgneal@827
|
45 var count_span = $('#map-band-count');
|
bgneal@827
|
46 count_span.html('0');
|
bgneal@827
|
47 var filter = $('#map-filter option:selected').val();
|
bgneal@827
|
48
|
bgneal@827
|
49 $.getJSON('/bandmap/query/', {show: filter},
|
bgneal@827
|
50 function(data) {
|
bgneal@827
|
51 $.each(data, function(i, band) {
|
bgneal@827
|
52 band_sel.append($('<option>', {value: i, text: band.name}));
|
bgneal@827
|
53 var marker = new google.maps.Marker({
|
bgneal@827
|
54 position: {lat: band.lat, lng: band.lon},
|
bgneal@827
|
55 title: band.name,
|
bgneal@993
|
56 icon: band.is_active ? "https://maps.google.com/mapfiles/ms/icons/green-dot.png"
|
bgneal@993
|
57 : "https://maps.google.com/mapfiles/ms/icons/red-dot.png",
|
bgneal@827
|
58 map: bandmap
|
bgneal@827
|
59 });
|
bgneal@827
|
60 google.maps.event.addListener(marker, 'click', function() {
|
bgneal@827
|
61 info_win.setContent(band.note);
|
bgneal@827
|
62 info_win.open(bandmap, marker);
|
bgneal@827
|
63 });
|
bgneal@827
|
64 surfbands[i] = band;
|
bgneal@827
|
65 surfbands[i].marker = marker;
|
bgneal@827
|
66 });
|
bgneal@827
|
67 count_span.html(data.length);
|
bgneal@827
|
68 });
|
bgneal@827
|
69 }
|
bgneal@827
|
70
|
bgneal@820
|
71 $(document).ready(function() {
|
bgneal@820
|
72 var map_div = $('#map-canvas');
|
bgneal@820
|
73 if (map_div.length) {
|
bgneal@821
|
74 bandmap = new google.maps.Map(map_div[0], map_options);
|
bgneal@832
|
75 info_win = new google.maps.InfoWindow({maxWidth: 300});
|
bgneal@827
|
76 $('#map-filter-go').click(refreshMap);
|
bgneal@827
|
77 $('#map-bands').change(function() {
|
bgneal@827
|
78 var n = $('option:selected', this).val();
|
bgneal@827
|
79 if (n != -1) {
|
bgneal@827
|
80 info_win.setContent(surfbands[n].note);
|
bgneal@827
|
81 info_win.open(bandmap, surfbands[n].marker);
|
bgneal@827
|
82 }
|
bgneal@827
|
83 });
|
bgneal@827
|
84 refreshMap();
|
bgneal@820
|
85 }
|
bgneal@820
|
86
|
bgneal@820
|
87 var add_form = $('#bandmap-add-form');
|
bgneal@820
|
88 if (add_form.length) {
|
bgneal@821
|
89 geocoder = new google.maps.Geocoder();
|
bgneal@821
|
90 $('#bandmap-add-submit').click(addBandOnSubmit);
|
bgneal@820
|
91 }
|
bgneal@820
|
92 });
|