-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps_trips.php
More file actions
248 lines (198 loc) · 7.45 KB
/
maps_trips.php
File metadata and controls
248 lines (198 loc) · 7.45 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html >
<head>
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Pilotsnpaws.org trip request map</title>
<script src="https://maps.googleapis.com/maps/api/js?key=UPDATE_KEY_HERE_TODO&v=3&libraries=geometry"></script>
<script type="text/javascript">
//<![CDATA[
var map;
var flightPaths = [];
var lastPostAge;
function initialize() {
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(38.000000,-98.000000),
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('gMap'),mapOptions);
updateTrips();
// add options box
map.controls[google.maps.ControlPosition.TOP_LEFT].push(document.getElementById('optionsBox'));
// add legend table
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('legend'));
}
function updateTrips() {
removeFlightPaths();
lastPostAge = document.getElementById("lastPostAge").value;
// alert(lastPostAge);
var searchURL = "maps_create_trips_xml.php?lastPostAge=" + lastPostAge;
downloadUrl(searchURL, function(data) {
var xml = data.responseXML;
var pathInfoWindow = new google.maps.InfoWindow();
// radians to degrees
function toDeg(rad) {
return rad * 180 / Math.PI;
}
// degrees to radians
function toRad(deg) {
return deg * Math.PI / 180;
}
// calulate the flight direction
function getBearing(lat1, lon1, lat2, lon2) {
var d = toRad((lon2 - lon1));
var y = Math.sin(d) * Math.cos(toRad(lat2));
var x = Math.cos(toRad(lat1)) * Math.sin(toRad(lat2)) - Math.sin(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.cos(d);
var brng = toDeg(Math.atan2(y, x));
return (360 + brng) % 360;
}
var trips = xml.documentElement.getElementsByTagName("trip");
for (var i = 0; i < trips.length; i++) {
var topic = trips[i].getAttribute("topicTitle");
var topicID = trips[i].getAttribute("topicID");
var lastPost = trips[i].getAttribute("lastPost");
var lastPostHuman = trips[i].getAttribute("lastPostHuman");
var sendLat = trips[i].getAttribute("sendLat");
var sendLon = trips[i].getAttribute("sendLon");
var recLat = trips[i].getAttribute("recLat");
var recLon = trips[i].getAttribute("recLon");
var sendZip = trips[i].getAttribute("sendZip");
var recZip = trips[i].getAttribute("recZip");
var sendCity = trips[i].getAttribute("sendCity");
var recCity = trips[i].getAttribute("recCity");
var flightPlanCoordinates = [
new google.maps.LatLng(sendLat, sendLon),
new google.maps.LatLng(recLat, recLon),
];
// determine color for flight direction
var bearing = getBearing(sendLat, sendLon, recLat, recLon);
if (bearing >= 0 && bearing < 180)
// 0-179 deg (Eastbound)
{ var directionColor = '#00AD6E'; // greenish
}
else
// 180-359 deg (Westbound)
{ var directionColor = '#8D00DE'; // purple
}
// show direction of flight
var lineType = { path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW };
// do length calcs, make a dummy path to get length.. if not, cant calc length in the html string below
var lengthFlightPath = new google.maps.Polyline({
path: flightPlanCoordinates
});
var lengthMeters = google.maps.geometry.spherical.computeLength(lengthFlightPath.getPath()) ;
var lengthMiles = Math.round(lengthMeters / 1609.344);
var lengthNM = Math.round(lengthMeters / 1852);
var strHTML = '<a href=/forum/viewtopic.php?t=' + topicID +
' target="_blank" >' + topic + '</a><br>' +
'From ' + sendCity + ' to ' + recCity + '<br>' +
'Distance: ' + lengthMiles + ' miles / ' + lengthNM + ' nm' + '<br>' +
'Topic last updated: ' + lastPostHuman
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: directionColor,
icons: [{ icon: lineType, offset: '100%' }],
strokeOpacity: 1.0,
strokeWeight: 2,
html: strHTML,
geodesic : true,
});
flightPaths.push(flightPath);
google.maps.event.addListener(flightPath, 'click', function(event) {
// get the click's latlng and use that as anchor for infoWindow
// found here: http://stackoverflow.com/questions/9998003/calling-infowindow-w-google-map-v3-api
var marker = new google.maps.Marker({
position: event.latLng,
map: map
});
// set the info popup content as the html from polyline above
pathInfoWindow.setContent(this.html);
pathInfoWindow.open(map, marker);
google.maps.event.addListener(map, 'click', function(event) {
pathInfoWindow.close(map, marker);
} );
});
flightPath.setMap(map);
}
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
}
request.open('GET', url, true);
request.send(null);
}
// got this from http://stackoverflow.com/questions/9058911/cant-remove-mvcarray-polylines-using-google-maps-api-v3
function removeFlightPaths() {
for (var i=0; i < flightPaths.length; i++) {
flightPaths[i].setMap(null);
}
// you probably then want to empty out your array as well
flightPaths = [];
// not sure you'll require this at this point, but if you want to also clear out your array of coordinates...
//routePoints.clear();
}
function doNothing() {}
google.maps.event.addDomListener(window, 'load', initialize);
//]]>
</script>
<!-- Google analytics added 2015-05-06 -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-62646402-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google analytics added 2015-05-06 -->
</head>
<body >
<style>
html, body {
margin:0;
padding:0;
height:100%; /* needed for container min-height */
}
#legend {
background: white;
padding: 10px;
width: 100px;;
}
#optionsBox {
background: white;
padding: 10px;
}
</style>
<div id="optionsBox">
Filter by recent activity:
<select id="lastPostAge">
<option value="0">Today only</option>
<option value="3">In the last 3 days</option>
<option value="5">In the last 5 days</option>
<option value="7">In the last 7 days</option>
<option value="14" selected="selected">In the last 14 days</option>
<option value="30">In the last 30 days</option>
<option value="365">Last 12 months</option>
</select>
<input type="button" onclick="updateTrips()" value="Search"/>
</div>
<div id="legend">
<div style="margin-bottom:5px;font-weight:500;">Legend:</div>
<div style="float:left;width:30px;height:1em;background-color:#8D00DE;border: 1px solid black;;"></div>
<div style="float:left;padding-left:5px;"> Westbound</div>
<div style="float:left;width:30px;height:1em;background-color:#00AD6E;border: 1px solid black;"></div>
<div style="float:left;padding-left:5px;"> Eastbound</div>
</div>
<div id="gMap" style="width: 100%; height: 100%;"></div>
</body>
</html>