-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbikecount.js
123 lines (95 loc) · 4.99 KB
/
bikecount.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
function view_current_assignments() {
$.ajax({
type: "GET",
url: "?action=get_assignments&email=" + encodeURIComponent($('#email_address').val())
}).done(function( html ) {
$('#current_assignments').html(html);
$('#current_assignments_popup').html(html);
$('#assignments').css('display', 'block');
});
}
function draw_map() {
var mobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
var map = new OpenLayers.Map("map");
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
// var toProjection = map.getProjectionObject(); // new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection ... that works for positioning hte map but breaks positioning the markers
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var osm = new OpenLayers.Layer.OSM("OSM Layer", [
"http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
"http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
"http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"
]);
map.addLayer(osm); // addLayer on a scalar, addLayers on an array
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
for( var i=0; i < pois.length; i++ ) {
var lonLat = new OpenLayers.LonLat( pois[i].lon, pois[i].lat ).transform( fromProjection, toProjection );
var new_marker = new OpenLayers.Marker(lonLat);
(function() {
var desc = pois[i].desc;
var marker_selected = function (ob) {
if( ! document.getElementById('email_address').value ) {
// no email addresss; show an error message
document.getElementById('enter_your_email').style.display = 'block';
} else {
// populate the form with the location_id of the selected intersection, and display the name of it to the human
document.getElementById('location_id').value = desc;
document.getElementById('intersection_name').innerHTML = desc;
$('#map_alternative').val( desc ); // select the same thing on the back-up select list below
// fetch the part of the form that lists what days the user wouldn't have conflicts for counting that intersection
$.ajax({
type: "GET",
url: "?action=get_times_for_intersection&location_id=" + desc + "&email=" + encodeURIComponent(document.getElementById('email_address').value)
}).done(function( html ) {
document.getElementById('intersection_options').innerHTML = html;
document.getElementById('assignment_details').style.display = 'block';
// scroll to the form
var viewportHeight = $(window).height(),
targ = $('#assignment_details'),
elHeight = targ.height(),
elOffset = targ.offset();
// $(window).scrollTop( elOffset.top + ( elHeight/2) - (viewportHeight/2));
$(window).scrollTop( elOffset.top );
});
}
};
// http://stackoverflow.com/questions/16772597/openlayers-how-to-add-click-and-touch-event-on-markers
if(mobile) {
new_marker.events.register( 'touchstart', new_marker, marker_selected );
} else {
new_marker.events.register( 'mousedown', new_marker, marker_selected );
}
})();
markers.addMarker(new_marker);
}
// from http://opencyclemap.org/?zoom=12&lat=33.39199&lon=-111.93891&layers=B00
var position = new OpenLayers.LonLat(-111.93891, 33.39199).transform( fromProjection, toProjection);
var zoom = 12;
map.setCenter( position, zoom );
}
$( document ).ready(function() {
(function() {
var divs = document.getElementById('ss-form').
getElementsByTagName('div');
var numDivs = divs.length;
for (var j = 0; j < numDivs; j++) {
if (divs[j].className == 'errorbox-bad') {
divs[j].lastChild.firstChild.lastChild.focus();
return;
}
}
})();
$('#map_alternative').change(function() {
var desc = $('#map_alternative').val();
document.getElementById('location_id').value = desc;
document.getElementById('intersection_name').innerHTML = desc;
$.ajax({
type: "GET",
url: "?action=get_times_for_intersection&location_id=" + encodeURIComponent(desc) + "&email=" + encodeURIComponent(document.getElementById('email_address'))
}).done(function( html ) {
document.getElementById('assignment_details').style.display = 'block';
document.getElementById('intersection_options').innerHTML = html;
});
});
draw_map();
});