Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/web/www/routino/router.js
Parent Directory
|
Revision Log
Revision 629 -
(hide annotations)
(download)
(as text)
Fri Feb 11 10:12:14 2011 UTC (14 years, 1 month ago) by amb
File MIME type: application/javascript
File size: 43302 byte(s)
Fri Feb 11 10:12:14 2011 UTC (14 years, 1 month ago) by amb
File MIME type: application/javascript
File size: 43302 byte(s)
Print a message if routed OK, allow web users to see router output (now logged to file).
1 | amb | 569 | // |
2 | // Routino router web page Javascript | ||
3 | // | ||
4 | // Part of the Routino routing software. | ||
5 | // | ||
6 | amb | 622 | // This file Copyright 2008-2011 Andrew M. Bishop |
7 | amb | 569 | // |
8 | // This program is free software: you can redistribute it and/or modify | ||
9 | // it under the terms of the GNU Affero General Public License as published by | ||
10 | // the Free Software Foundation, either version 3 of the License, or | ||
11 | // (at your option) any later version. | ||
12 | // | ||
13 | // This program is distributed in the hope that it will be useful, | ||
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | // GNU Affero General Public License for more details. | ||
17 | // | ||
18 | // You should have received a copy of the GNU Affero General Public License | ||
19 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | // | ||
21 | |||
22 | amb | 574 | //////////////////////////////////////////////////////////////////////////////// |
23 | amb | 577 | /////////////////////////// Routino default profile //////////////////////////// |
24 | //////////////////////////////////////////////////////////////////////////////// | ||
25 | amb | 574 | |
26 | amb | 585 | var routino={ // contains all default Routino options (generated using "--help-profile-json"). |
27 | amb | 569 | |
28 | amb | 577 | // Default transport type |
29 | transport: 'motorcar', | ||
30 | amb | 569 | |
31 | amb | 577 | // Transport types |
32 | amb | 585 | transports: { foot: 1, horse: 2, wheelchair: 3, bicycle: 4, moped: 5, motorbike: 6, motorcar: 7, goods: 8, hgv: 9, psv: 10 }, |
33 | amb | 574 | |
34 | amb | 577 | // Highway types |
35 | amb | 585 | highways: { motorway: 1, trunk: 2, primary: 3, secondary: 4, tertiary: 5, unclassified: 6, residential: 7, service: 8, track: 9, cycleway: 10, path: 11, steps: 12, ferry: 13 }, |
36 | amb | 569 | |
37 | amb | 577 | // Property types |
38 | amb | 585 | properties: { paved: 1, multilane: 2, bridge: 3, tunnel: 4, footroute: 5, bicycleroute: 6 }, |
39 | amb | 569 | |
40 | amb | 577 | // Restriction types |
41 | amb | 622 | restrictions: { oneway: 1, turns: 2, weight: 3, height: 4, width: 5, length: 6 }, |
42 | amb | 569 | |
43 | amb | 577 | // Allowed highways |
44 | profile_highway: { | ||
45 | amb | 585 | motorway: { foot: 0, horse: 0, wheelchair: 0, bicycle: 0, moped: 0, motorbike: 100, motorcar: 100, goods: 100, hgv: 100, psv: 100 }, |
46 | trunk: { foot: 40, horse: 25, wheelchair: 40, bicycle: 30, moped: 90, motorbike: 100, motorcar: 100, goods: 100, hgv: 100, psv: 100 }, | ||
47 | primary: { foot: 50, horse: 50, wheelchair: 50, bicycle: 70, moped: 100, motorbike: 90, motorcar: 90, goods: 90, hgv: 90, psv: 90 }, | ||
48 | secondary: { foot: 60, horse: 50, wheelchair: 60, bicycle: 80, moped: 90, motorbike: 80, motorcar: 80, goods: 80, hgv: 80, psv: 80 }, | ||
49 | tertiary: { foot: 70, horse: 75, wheelchair: 70, bicycle: 90, moped: 80, motorbike: 70, motorcar: 70, goods: 70, hgv: 70, psv: 70 }, | ||
50 | unclassified: { foot: 80, horse: 75, wheelchair: 80, bicycle: 90, moped: 70, motorbike: 60, motorcar: 60, goods: 60, hgv: 60, psv: 60 }, | ||
51 | residential: { foot: 90, horse: 75, wheelchair: 90, bicycle: 90, moped: 60, motorbike: 50, motorcar: 50, goods: 50, hgv: 50, psv: 50 }, | ||
52 | service: { foot: 90, horse: 75, wheelchair: 90, bicycle: 90, moped: 80, motorbike: 80, motorcar: 80, goods: 80, hgv: 80, psv: 80 }, | ||
53 | track: { foot: 95, horse: 100, wheelchair: 95, bicycle: 90, moped: 0, motorbike: 0, motorcar: 0, goods: 0, hgv: 0, psv: 0 }, | ||
54 | cycleway: { foot: 95, horse: 90, wheelchair: 95, bicycle: 100, moped: 0, motorbike: 0, motorcar: 0, goods: 0, hgv: 0, psv: 0 }, | ||
55 | path: { foot: 100, horse: 100, wheelchair: 100, bicycle: 90, moped: 0, motorbike: 0, motorcar: 0, goods: 0, hgv: 0, psv: 0 }, | ||
56 | steps: { foot: 80, horse: 0, wheelchair: 0, bicycle: 0, moped: 0, motorbike: 0, motorcar: 0, goods: 0, hgv: 0, psv: 0 }, | ||
57 | ferry: { foot: 20, horse: 20, wheelchair: 20, bicycle: 20, moped: 20, motorbike: 20, motorcar: 20, goods: 20, hgv: 20, psv: 20 } | ||
58 | amb | 577 | }, |
59 | amb | 574 | |
60 | amb | 577 | // Speed limits |
61 | profile_speed: { | ||
62 | amb | 585 | motorway: { foot: 0, horse: 0, wheelchair: 0, bicycle: 0, moped: 48, motorbike: 112, motorcar: 112, goods: 96, hgv: 89, psv: 89 }, |
63 | trunk: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 48, motorbike: 96, motorcar: 96, goods: 96, hgv: 80, psv: 80 }, | ||
64 | primary: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 48, motorbike: 96, motorcar: 96, goods: 96, hgv: 80, psv: 80 }, | ||
65 | secondary: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 48, motorbike: 88, motorcar: 88, goods: 88, hgv: 80, psv: 80 }, | ||
66 | tertiary: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 48, motorbike: 80, motorcar: 80, goods: 80, hgv: 80, psv: 80 }, | ||
67 | unclassified: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 48, motorbike: 64, motorcar: 64, goods: 64, hgv: 64, psv: 64 }, | ||
68 | residential: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 48, motorbike: 48, motorcar: 48, goods: 48, hgv: 48, psv: 48 }, | ||
69 | service: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 32, motorbike: 32, motorcar: 32, goods: 32, hgv: 32, psv: 32 }, | ||
70 | track: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 16, motorbike: 16, motorcar: 16, goods: 16, hgv: 16, psv: 16 }, | ||
71 | cycleway: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 0, motorbike: 0, motorcar: 0, goods: 0, hgv: 0, psv: 0 }, | ||
72 | path: { foot: 4, horse: 8, wheelchair: 4, bicycle: 20, moped: 0, motorbike: 0, motorcar: 0, goods: 0, hgv: 0, psv: 0 }, | ||
73 | steps: { foot: 4, horse: 0, wheelchair: 4, bicycle: 0, moped: 0, motorbike: 0, motorcar: 0, goods: 0, hgv: 0, psv: 0 }, | ||
74 | ferry: { foot: 10, horse: 10, wheelchair: 10, bicycle: 10, moped: 10, motorbike: 10, motorcar: 10, goods: 10, hgv: 10, psv: 10 } | ||
75 | amb | 577 | }, |
76 | amb | 569 | |
77 | amb | 577 | // Highway properties |
78 | profile_property: { | ||
79 | amb | 585 | paved: { foot: 50, horse: 20, wheelchair: 90, bicycle: 50, moped: 100, motorbike: 100, motorcar: 100, goods: 100, hgv: 100, psv: 100 }, |
80 | multilane: { foot: 25, horse: 25, wheelchair: 25, bicycle: 25, moped: 35, motorbike: 60, motorcar: 60, goods: 60, hgv: 60, psv: 60 }, | ||
81 | bridge: { foot: 50, horse: 50, wheelchair: 50, bicycle: 50, moped: 50, motorbike: 50, motorcar: 50, goods: 50, hgv: 50, psv: 50 }, | ||
82 | tunnel: { foot: 50, horse: 50, wheelchair: 50, bicycle: 50, moped: 50, motorbike: 50, motorcar: 50, goods: 50, hgv: 50, psv: 50 }, | ||
83 | footroute: { foot: 55, horse: 50, wheelchair: 55, bicycle: 50, moped: 50, motorbike: 50, motorcar: 45, goods: 45, hgv: 45, psv: 45 }, | ||
84 | bicycleroute: { foot: 55, horse: 50, wheelchair: 55, bicycle: 60, moped: 50, motorbike: 50, motorcar: 45, goods: 45, hgv: 45, psv: 45 } | ||
85 | amb | 577 | }, |
86 | amb | 574 | |
87 | amb | 577 | // Restrictions |
88 | profile_restrictions: { | ||
89 | amb | 585 | oneway: { foot: 0, horse: 1, wheelchair: 0, bicycle: 1, moped: 1, motorbike: 1, motorcar: 1, goods: 1, hgv: 1, psv: 1 }, |
90 | amb | 622 | turns: { foot: 0, horse: 1, wheelchair: 1, bicycle: 1, moped: 1, motorbike: 1, motorcar: 1, goods: 1, hgv: 1, psv: 1 }, |
91 | amb | 585 | weight: { foot: 0.0, horse: 0.0, wheelchair: 0.0, bicycle: 0.0, moped: 0.0, motorbike: 0.0, motorcar: 0.0, goods: 5.0, hgv: 10.0, psv: 15.0 }, |
92 | height: { foot: 0.0, horse: 0.0, wheelchair: 0.0, bicycle: 0.0, moped: 0.0, motorbike: 0.0, motorcar: 0.0, goods: 2.5, hgv: 3.0, psv: 3.0 }, | ||
93 | width: { foot: 0.0, horse: 0.0, wheelchair: 0.0, bicycle: 0.0, moped: 0.0, motorbike: 0.0, motorcar: 0.0, goods: 2.0, hgv: 2.5, psv: 2.5 }, | ||
94 | length: { foot: 0.0, horse: 0.0, wheelchair: 0.0, bicycle: 0.0, moped: 0.0, motorbike: 0.0, motorcar: 0.0, goods: 5.0, hgv: 6.0, psv: 6.0 } | ||
95 | amb | 577 | } |
96 | amb | 569 | |
97 | amb | 577 | }; // end of routino variable |
98 | amb | 569 | |
99 | amb | 577 | // Make a deep copy of the routino profile. |
100 | amb | 569 | |
101 | amb | 577 | var routino_default={}; |
102 | for(var l1 in routino) | ||
103 | if(typeof(routino[l1])!='object') | ||
104 | routino_default[l1]=routino[l1]; | ||
105 | else | ||
106 | { | ||
107 | routino_default[l1]={}; | ||
108 | for(var l2 in routino[l1]) | ||
109 | if(typeof(routino[l1][l2])!='object') | ||
110 | routino_default[l1][l2]=Number(routino[l1][l2]); | ||
111 | else | ||
112 | { | ||
113 | routino_default[l1][l2]={}; | ||
114 | for(var l3 in routino[l1][l2]) | ||
115 | routino_default[l1][l2][l3]=Number(routino[l1][l2][l3]); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | |||
120 | //////////////////////////////////////////////////////////////////////////////// | ||
121 | //////////////////////////////// Form handling ///////////////////////////////// | ||
122 | //////////////////////////////////////////////////////////////////////////////// | ||
123 | |||
124 | amb | 569 | // |
125 | // Form initialisation - fill in the uninitialised parts | ||
126 | // | ||
127 | |||
128 | function form_init() | ||
129 | { | ||
130 | amb | 577 | // Update the routino variable with the URL settings (from the HTML). |
131 | amb | 569 | |
132 | amb | 577 | for(var lang=0;lang< document.forms["form"].elements["language"].length;lang++) |
133 | if(document.forms["form"].elements["language"][lang].checked) | ||
134 | formSetLanguage(document.forms["form"].elements["language"][lang].value); | ||
135 | amb | 569 | |
136 | amb | 577 | var transport=null; |
137 | |||
138 | for(var key in routino.transports) | ||
139 | if(document.forms["form"].elements["transport"][routino.transports[key]-1].checked) | ||
140 | transport=key; | ||
141 | |||
142 | if(transport==null) | ||
143 | formSetTransport(routino.transport); | ||
144 | amb | 569 | else |
145 | { | ||
146 | amb | 577 | routino.transport=transport; |
147 | |||
148 | for(var key in routino.profile_highway) | ||
149 | amb | 569 | { |
150 | if(document.forms["form"].elements["highway-" + key].value=="") | ||
151 | amb | 577 | document.forms["form"].elements["highway-" + key].value=routino.profile_highway[key][routino.transport]; |
152 | amb | 569 | else |
153 | formSetHighway(key); | ||
154 | } | ||
155 | |||
156 | amb | 577 | for(var key in routino.profile_speed) |
157 | amb | 569 | { |
158 | if(document.forms["form"].elements["speed-" + key].value=="") | ||
159 | amb | 577 | document.forms["form"].elements["speed-" + key].value=routino.profile_speed[key][routino.transport]; |
160 | amb | 569 | else |
161 | formSetSpeed(key); | ||
162 | } | ||
163 | |||
164 | amb | 577 | for(var key in routino.profile_property) |
165 | amb | 574 | { |
166 | if(document.forms["form"].elements["property-" + key].value=="") | ||
167 | amb | 577 | document.forms["form"].elements["property-" + key].value=routino.profile_property[key][routino.transport]; |
168 | amb | 574 | else |
169 | formSetProperty(key); | ||
170 | } | ||
171 | |||
172 | amb | 577 | for(var key in routino.restrictions) |
173 | amb | 569 | { |
174 | amb | 622 | if(key=="oneway" || key=="turns") |
175 | amb | 569 | formSetRestriction(key); |
176 | else | ||
177 | { | ||
178 | amb | 574 | if(document.forms["form"].elements["restrict-" + key].value=="") |
179 | amb | 577 | document.forms["form"].elements["restrict-" + key].value=routino.profile_restrictions[key][routino.transport]; |
180 | amb | 569 | else |
181 | formSetRestriction(key); | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | |||
186 | amb | 577 | // Delete the extra empty waypoints |
187 | |||
188 | var filled=0; | ||
189 | |||
190 | amb | 574 | for(var marker=nmarkers;marker>=1;marker--) |
191 | { | ||
192 | var lon=document.forms["form"].elements["lon" + marker].value; | ||
193 | var lat=document.forms["form"].elements["lat" + marker].value; | ||
194 | amb | 569 | |
195 | amb | 574 | if(lon != "" && lat != "") |
196 | amb | 577 | { |
197 | filled++; | ||
198 | amb | 574 | markerAddMap(marker); |
199 | amb | 577 | } |
200 | else if(filled==0) | ||
201 | amb | 574 | markerRemove(marker); |
202 | } | ||
203 | amb | 569 | |
204 | amb | 577 | // Get the home location cookie and compare to each waypoint |
205 | |||
206 | var cookies=document.cookie.split('; '); | ||
207 | |||
208 | for(var cookie=0;cookie<cookies.length;cookie++) | ||
209 | if(cookies[cookie].substr(0,"Routino-home".length)=="Routino-home") | ||
210 | { | ||
211 | var data=cookies[cookie].split(/[=:;]/); | ||
212 | |||
213 | if(data[1]=="lon") homelon=Number(data[2]); | ||
214 | if(data[3]=="lat") homelat=Number(data[4]); | ||
215 | } | ||
216 | |||
217 | if(homelon!=null && homelat!=null) | ||
218 | { | ||
219 | for(var marker=nmarkers;marker>=1;marker--) | ||
220 | { | ||
221 | var lon=document.forms["form"].elements["lon" + marker].value; | ||
222 | var lat=document.forms["form"].elements["lat" + marker].value; | ||
223 | |||
224 | if(lon==homelon && lat==homelat) | ||
225 | updateIcon(marker); | ||
226 | } | ||
227 | |||
228 | // If the first location is empty and the cookie is set then fill it. | ||
229 | |||
230 | if(document.forms["form"].elements["lon1"].value=="" && document.forms["form"].elements["lat1"].value=="") | ||
231 | { | ||
232 | document.forms["form"].elements["lon1"].value=homelon; | ||
233 | document.forms["form"].elements["lat1"].value=homelat; | ||
234 | |||
235 | markerAddMap(1); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | amb | 569 | updateCustomURL(); |
240 | } | ||
241 | |||
242 | |||
243 | // | ||
244 | amb | 577 | // Change of language in the form |
245 | // | ||
246 | |||
247 | function formSetLanguage(type) | ||
248 | { | ||
249 | routino.language=type; | ||
250 | |||
251 | updateCustomURL(); | ||
252 | } | ||
253 | |||
254 | |||
255 | // | ||
256 | amb | 569 | // Change of transport in the form |
257 | // | ||
258 | |||
259 | function formSetTransport(type) | ||
260 | { | ||
261 | amb | 577 | routino.transport=type; |
262 | amb | 569 | |
263 | amb | 577 | for(var key in routino.transports) |
264 | document.forms["form"].elements["transport"][routino.transports[key]-1].checked=(key==routino.transport); | ||
265 | amb | 569 | |
266 | amb | 577 | for(var key in routino.profile_highway) |
267 | document.forms["form"].elements["highway-" + key].value=routino.profile_highway[key][routino.transport]; | ||
268 | amb | 569 | |
269 | amb | 577 | for(var key in routino.profile_speed) |
270 | document.forms["form"].elements["speed-" + key].value=routino.profile_speed[key][routino.transport]; | ||
271 | amb | 569 | |
272 | amb | 577 | for(var key in routino.profile_property) |
273 | document.forms["form"].elements["property-" + key].value=routino.profile_property[key][routino.transport]; | ||
274 | amb | 569 | |
275 | amb | 577 | for(var key in routino.restrictions) |
276 | amb | 569 | { |
277 | amb | 622 | if(key=="oneway" || key=="turns") |
278 | amb | 577 | document.forms["form"].elements["restrict-" + key].checked=routino.profile_restrictions[key][routino.transport]; |
279 | amb | 569 | else |
280 | amb | 577 | document.forms["form"].elements["restrict-" + key].value=routino.profile_restrictions[key][routino.transport]; |
281 | amb | 569 | } |
282 | |||
283 | paramschanged=true; | ||
284 | |||
285 | updateCustomURL(); | ||
286 | } | ||
287 | |||
288 | |||
289 | // | ||
290 | // Change of highway in the form | ||
291 | // | ||
292 | |||
293 | function formSetHighway(type) | ||
294 | { | ||
295 | amb | 577 | routino.profile_highway[type][routino.transport]=document.forms["form"].elements["highway-" + type].value; |
296 | amb | 569 | |
297 | paramschanged=true; | ||
298 | |||
299 | updateCustomURL(); | ||
300 | } | ||
301 | |||
302 | |||
303 | // | ||
304 | // Change of Speed in the form | ||
305 | // | ||
306 | |||
307 | function formSetSpeed(type) | ||
308 | { | ||
309 | amb | 577 | routino.profile_speed[type][routino.transport]=document.forms["form"].elements["speed-" + type].value; |
310 | amb | 569 | |
311 | paramschanged=true; | ||
312 | |||
313 | updateCustomURL(); | ||
314 | } | ||
315 | |||
316 | |||
317 | // | ||
318 | amb | 574 | // Change of Property in the form |
319 | // | ||
320 | |||
321 | function formSetProperty(type) | ||
322 | { | ||
323 | amb | 577 | routino.profile_property[type][routino.transport]=document.forms["form"].elements["property-" + type].value; |
324 | amb | 574 | |
325 | paramschanged=true; | ||
326 | |||
327 | updateCustomURL(); | ||
328 | } | ||
329 | |||
330 | |||
331 | // | ||
332 | amb | 622 | // Change of Restriction rule in the form |
333 | amb | 569 | // |
334 | |||
335 | function formSetRestriction(type) | ||
336 | { | ||
337 | amb | 622 | if(type=="oneway" || type=="turns") |
338 | amb | 577 | routino.profile_restrictions[type][routino.transport]=document.forms["form"].elements["restrict-" + type].checked; |
339 | amb | 569 | else |
340 | amb | 577 | routino.profile_restrictions[type][routino.transport]=document.forms["form"].elements["restrict-" + type].value; |
341 | amb | 569 | |
342 | paramschanged=true; | ||
343 | |||
344 | updateCustomURL(); | ||
345 | } | ||
346 | |||
347 | |||
348 | // | ||
349 | amb | 577 | // Set the feature coordinates from the form when the form changes. |
350 | // | ||
351 | |||
352 | function formSetCoords(marker) | ||
353 | { | ||
354 | var lonlat=map.getCenter().clone(); | ||
355 | |||
356 | lonlat.transform(map.getProjectionObject(),epsg4326); | ||
357 | |||
358 | var lon=document.forms["form"].elements["lon" + marker].value; | ||
359 | var lat=document.forms["form"].elements["lat" + marker].value; | ||
360 | |||
361 | if(lon!="") | ||
362 | { | ||
363 | if(lon<-180) lon=-180; | ||
364 | if(lon>+180) lon=+180; | ||
365 | lonlat.lon=lon; | ||
366 | } | ||
367 | |||
368 | if(lat!="") | ||
369 | { | ||
370 | if(lat<-90 ) lat=-90 ; | ||
371 | if(lat>+90 ) lat=+90 ; | ||
372 | lonlat.lat=lat; | ||
373 | } | ||
374 | |||
375 | var point = lonlat.clone(); | ||
376 | |||
377 | point.transform(epsg4326,map.getProjectionObject()); | ||
378 | |||
379 | markers[marker].move(point); | ||
380 | |||
381 | markersmoved=true; | ||
382 | |||
383 | coordsSetForm(marker); | ||
384 | } | ||
385 | |||
386 | |||
387 | // | ||
388 | // Set the feature coordinates in the form. | ||
389 | // | ||
390 | |||
391 | function coordsSetForm(marker) | ||
392 | { | ||
393 | var lonlat = new OpenLayers.LonLat(markers[marker].geometry.x, markers[marker].geometry.y); | ||
394 | lonlat.transform(map.getProjectionObject(),epsg4326); | ||
395 | |||
396 | var lon=format5f(lonlat.lon); | ||
397 | var lat=format5f(lonlat.lat); | ||
398 | |||
399 | document.forms["form"].elements["lon" + marker].value=lon; | ||
400 | document.forms["form"].elements["lat" + marker].value=lat; | ||
401 | |||
402 | updateIcon(marker); | ||
403 | |||
404 | updateCustomURL(); | ||
405 | } | ||
406 | |||
407 | |||
408 | // | ||
409 | // Format a number in printf("%.5f") format. | ||
410 | // | ||
411 | |||
412 | function format5f(number) | ||
413 | { | ||
414 | var newnumber=Math.floor(number*100000+0.5); | ||
415 | var delta=0; | ||
416 | |||
417 | if(newnumber>=0 && newnumber<100000) delta= 100000; | ||
418 | if(newnumber<0 && newnumber>-100000) delta=-100000; | ||
419 | |||
420 | var string=String(newnumber+delta); | ||
421 | |||
422 | var intpart =string.substring(0,string.length-5); | ||
423 | var fracpart=string.substring(string.length-5,string.length); | ||
424 | |||
425 | if(delta>0) intpart="0"; | ||
426 | if(delta<0) intpart="-0"; | ||
427 | |||
428 | return(intpart + "." + fracpart); | ||
429 | } | ||
430 | |||
431 | |||
432 | // | ||
433 | // Build a set of URL arguments | ||
434 | // | ||
435 | |||
436 | function buildURLArguments(all) | ||
437 | { | ||
438 | var url="?"; | ||
439 | |||
440 | url=url + "transport=" + routino.transport; | ||
441 | |||
442 | for(var marker=1;marker<=vismarkers;marker++) | ||
443 | if(markers[marker].style.display == "" || all) | ||
444 | { | ||
445 | url=url + ";lon" + marker + "=" + document.forms["form"].elements["lon" + marker].value; | ||
446 | url=url + ";lat" + marker + "=" + document.forms["form"].elements["lat" + marker].value; | ||
447 | } | ||
448 | |||
449 | for(var key in routino.profile_highway) | ||
450 | if(routino.profile_highway[key][routino.transport]!=routino_default.profile_highway[key][routino.transport]) | ||
451 | url=url + ";highway-" + key + "=" + routino.profile_highway[key][routino.transport]; | ||
452 | |||
453 | for(var key in routino.profile_speed) | ||
454 | if(routino.profile_speed[key][routino.transport]!=routino_default.profile_speed[key][routino.transport]) | ||
455 | url=url + ";speed-" + key + "=" + routino.profile_speed[key][routino.transport]; | ||
456 | |||
457 | for(var key in routino.profile_property) | ||
458 | if(routino.profile_property[key][routino.transport]!=routino_default.profile_property[key][routino.transport]) | ||
459 | url=url + ";property-" + key + "=" + routino.profile_property[key][routino.transport]; | ||
460 | |||
461 | for(var key in routino.restrictions) | ||
462 | if(routino.profile_restrictions[key][routino.transport]!=routino_default.profile_restrictions[key][routino.transport]) | ||
463 | url=url + ";" + key + "=" + routino.profile_restrictions[key][routino.transport]; | ||
464 | |||
465 | if(routino.language) | ||
466 | url=url + ";language=" + routino.language; | ||
467 | |||
468 | return(url); | ||
469 | } | ||
470 | |||
471 | |||
472 | // | ||
473 | amb | 569 | // Update custom URL |
474 | // | ||
475 | |||
476 | function updateCustomURL() | ||
477 | { | ||
478 | amb | 574 | var visualiser_url=document.getElementById("visualiser_url"); |
479 | amb | 577 | var link_url =document.getElementById("link_url"); |
480 | var edit_url =document.getElementById("edit_url"); | ||
481 | amb | 569 | |
482 | amb | 574 | visualiser_url.href="customvisualiser.cgi?" + map_args; |
483 | amb | 577 | link_url.href="customrouter.cgi" + buildURLArguments(1) + ";" + map_args; |
484 | edit_url.href="http://www.openstreetmap.org/edit?" + map_args; | ||
485 | amb | 569 | } |
486 | |||
487 | |||
488 | // | ||
489 | // Block the use of the return key to submit the form | ||
490 | // | ||
491 | |||
492 | function block_return_key() | ||
493 | { | ||
494 | var form=document.getElementById("form"); | ||
495 | |||
496 | if(form.addEventListener) | ||
497 | form.addEventListener('keyup', discardReturnKey, false); | ||
498 | else if(form.attachEvent) | ||
499 | form.attachEvent('keyup', discardReturnKey); // Internet Explorer | ||
500 | } | ||
501 | |||
502 | // | ||
503 | // Function to discard the return key if pressed | ||
504 | // | ||
505 | |||
506 | function discardReturnKey(ev) | ||
507 | { | ||
508 | if(ev.keyCode==13) | ||
509 | return(false); | ||
510 | |||
511 | return(true); | ||
512 | } | ||
513 | |||
514 | |||
515 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
516 | ///////////////////////////////// Map handling ///////////////////////////////// | ||
517 | //////////////////////////////////////////////////////////////////////////////// | ||
518 | amb | 569 | |
519 | var map; | ||
520 | amb | 572 | var layerMapOSM, layerVectors, layerGPX; |
521 | amb | 569 | var epsg4326, epsg900913; |
522 | amb | 574 | var map_args; |
523 | amb | 569 | |
524 | // | ||
525 | // Initialise the 'map' object | ||
526 | // | ||
527 | |||
528 | function map_init(lat,lon,zoom) | ||
529 | { | ||
530 | amb | 577 | // Default configuration: |
531 | // UK coordinate range | ||
532 | // West -11.0, South 49.5, East 2.0, North 61.0 | ||
533 | // Zoom level 4 to 15 | ||
534 | |||
535 | // EDIT THIS below to change the visible map limits | ||
536 | |||
537 | var westedge = -11.0; // Minimum longitude (degrees) | ||
538 | var eastedge = 2.0; // Maximum longitude (degrees) | ||
539 | var southedge = 49.5; // Minimum latitude (degrees) | ||
540 | var northedge = 61.0; // Maximum latitude (degrees) | ||
541 | var zoomout = 4; // Minimum zoom | ||
542 | var zoomin = 15; // Maximum zoom | ||
543 | |||
544 | // EDIT THIS above to change the visible map limits | ||
545 | |||
546 | amb | 569 | // |
547 | // Create the map | ||
548 | // | ||
549 | |||
550 | epsg4326=new OpenLayers.Projection("EPSG:4326"); | ||
551 | epsg900913=new OpenLayers.Projection("EPSG:900913"); | ||
552 | |||
553 | map = new OpenLayers.Map ("map", | ||
554 | { | ||
555 | controls:[ | ||
556 | new OpenLayers.Control.Navigation(), | ||
557 | new OpenLayers.Control.PanZoomBar(), | ||
558 | new OpenLayers.Control.ScaleLine(), | ||
559 | new OpenLayers.Control.LayerSwitcher() | ||
560 | ], | ||
561 | |||
562 | projection: epsg900913, | ||
563 | displayProjection: epsg4326, | ||
564 | |||
565 | amb | 577 | minZoomLevel: zoomout, |
566 | numZoomLevels: zoomin-zoomout+1, | ||
567 | maxResolution: 156543.0339 / Math.pow(2,zoomout), | ||
568 | amb | 569 | |
569 | amb | 577 | maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34), |
570 | restrictedExtent: new OpenLayers.Bounds(westedge,southedge,eastedge,northedge).transform(epsg4326,epsg900913), | ||
571 | amb | 569 | |
572 | units: "m" | ||
573 | }); | ||
574 | |||
575 | map.events.register("moveend", map, mapMoved); | ||
576 | |||
577 | amb | 572 | // Add a map tile layer (OpenStreetMap tiles, direct access) |
578 | amb | 569 | |
579 | amb | 572 | layerMapOSM = new OpenLayers.Layer.TMS("Original OSM map", |
580 | amb | 569 | "http://tile.openstreetmap.org/", |
581 | { | ||
582 | emptyUrl: "http://openstreetmap.org/openlayers/img/404.png", | ||
583 | type: 'png', | ||
584 | getURL: limitedUrl, | ||
585 | displayOutsideMaxExtent: true, | ||
586 | buffer: 1 | ||
587 | }); | ||
588 | amb | 572 | map.addLayer(layerMapOSM); |
589 | amb | 569 | |
590 | amb | 577 | // Get a URL for the tile; limited to map restricted extent. |
591 | amb | 569 | |
592 | function limitedUrl(bounds) | ||
593 | { | ||
594 | var z = map.getZoom() + map.minZoomLevel; | ||
595 | |||
596 | amb | 577 | if (z>=7 && (bounds.right < map.restrictedExtent.left || |
597 | bounds.left > map.restrictedExtent.right || | ||
598 | bounds.top < map.restrictedExtent.bottom || | ||
599 | bounds.bottom > map.restrictedExtent.top)) | ||
600 | amb | 569 | return this.emptyUrl; |
601 | |||
602 | var res = map.getResolution(); | ||
603 | var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); | ||
604 | var limit = Math.pow(2, z); | ||
605 | |||
606 | if (y < 0 || y >= limit) | ||
607 | return this.emptyUrl; | ||
608 | |||
609 | var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w)); | ||
610 | |||
611 | x = ((x % limit) + limit) % limit; | ||
612 | return this.url + z + "/" + x + "/" + y + "." + this.type; | ||
613 | } | ||
614 | |||
615 | // Define a GPX layer but don't add it yet | ||
616 | |||
617 | layerGPX={shortest: null, quickest: null}; | ||
618 | |||
619 | gpx_style={shortest: new OpenLayers.Style({},{strokeWidth: 3, strokeColor: "#00FF00"}), | ||
620 | quickest: new OpenLayers.Style({},{strokeWidth: 3, strokeColor: "#0000FF"})}; | ||
621 | |||
622 | // Add a vectors layer | ||
623 | |||
624 | layerVectors = new OpenLayers.Layer.Vector("Markers"); | ||
625 | map.addLayer(layerVectors); | ||
626 | |||
627 | // A set of markers | ||
628 | |||
629 | amb | 574 | nmarkers=99; |
630 | vismarkers=0; | ||
631 | markers={}; | ||
632 | amb | 569 | markersmoved=false; |
633 | paramschanged=false; | ||
634 | |||
635 | amb | 574 | for(var marker=1;marker<=nmarkers;marker++) |
636 | amb | 569 | { |
637 | amb | 572 | if(document.forms["form"].elements["lon" + marker] != undefined) |
638 | { | ||
639 | markers[marker] = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0),{}, | ||
640 | new OpenLayers.Style({},{externalGraphic: 'icons/marker-' + marker + '-red.png', | ||
641 | amb | 574 | fillColor: "white", |
642 | amb | 572 | graphicYOffset: -25, |
643 | graphicWidth: 21, | ||
644 | graphicHeight: 25, | ||
645 | display: "none"})); | ||
646 | amb | 569 | |
647 | amb | 572 | layerVectors.addFeatures([markers[marker]]); |
648 | } | ||
649 | amb | 574 | else |
650 | { | ||
651 | nmarkers=marker-1; | ||
652 | vismarkers=marker-1; | ||
653 | break; | ||
654 | } | ||
655 | amb | 569 | } |
656 | |||
657 | // A function to drag the markers | ||
658 | |||
659 | var drag = new OpenLayers.Control.DragFeature(layerVectors, | ||
660 | {onDrag: dragMove, | ||
661 | onComplete: dragComplete }); | ||
662 | map.addControl(drag); | ||
663 | drag.activate(); | ||
664 | |||
665 | // Markers to highlight a selected point | ||
666 | |||
667 | amb | 577 | for(var highlight in highlights) |
668 | amb | 569 | { |
669 | highlights[highlight] = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0),{}, | ||
670 | amb | 577 | new OpenLayers.Style({},{strokeColor: route_dark_colours[highlight], |
671 | amb | 574 | fillColor: "white", |
672 | amb | 569 | pointRadius: 10, |
673 | strokeWidth: 4, | ||
674 | fillOpacity: 0, | ||
675 | display: "none"})); | ||
676 | |||
677 | layerVectors.addFeatures([highlights[highlight]]); | ||
678 | } | ||
679 | |||
680 | amb | 574 | // A popup for routing results |
681 | |||
682 | amb | 577 | for(var popup in popups) |
683 | popups[popup] = createPopup(popup); | ||
684 | amb | 574 | |
685 | amb | 572 | // Set the map centre to the limited range specified |
686 | |||
687 | amb | 577 | map.setCenter(map.restrictedExtent.getCenterLonLat(), map.getZoomForExtent(map.restrictedExtent,true)); |
688 | amb | 572 | map.maxResolution = map.getResolution(); |
689 | |||
690 | amb | 569 | // Move the map |
691 | |||
692 | if(lon != 'lon' && lat != 'lat' && zoom != 'zoom') | ||
693 | { | ||
694 | var lonlat = new OpenLayers.LonLat(lon,lat).transform(epsg4326,map.getProjectionObject()); | ||
695 | |||
696 | map.moveTo(lonlat,zoom-map.minZoomLevel); | ||
697 | } | ||
698 | } | ||
699 | |||
700 | |||
701 | // | ||
702 | // Map has moved | ||
703 | // | ||
704 | |||
705 | function mapMoved() | ||
706 | { | ||
707 | var centre = map.getCenter().clone(); | ||
708 | |||
709 | var lonlat = centre.transform(map.getProjectionObject(),epsg4326); | ||
710 | |||
711 | var zoom = this.getZoom() + map.minZoomLevel; | ||
712 | |||
713 | amb | 574 | map_args="lat=" + lonlat.lat + ";lon=" + lonlat.lon + ";zoom=" + zoom; |
714 | amb | 569 | |
715 | amb | 574 | updateCustomURL(); |
716 | amb | 569 | } |
717 | |||
718 | |||
719 | // | ||
720 | // OpenLayers.Control.DragFeature callback for a drag occuring. | ||
721 | // | ||
722 | |||
723 | function dragMove(feature,pixel) | ||
724 | { | ||
725 | amb | 574 | for(var marker in markers) |
726 | amb | 569 | if(feature==markers[marker]) |
727 | { | ||
728 | markersmoved=true; | ||
729 | |||
730 | coordsSetForm(marker); | ||
731 | } | ||
732 | } | ||
733 | |||
734 | |||
735 | // | ||
736 | // OpenLayers.Control.DragFeature callback for completing a drag. | ||
737 | // | ||
738 | |||
739 | function dragComplete(feature,pixel) | ||
740 | { | ||
741 | amb | 574 | for(var marker in markers) |
742 | amb | 569 | if(feature==markers[marker]) |
743 | { | ||
744 | markersmoved=true; | ||
745 | |||
746 | coordsSetForm(marker); | ||
747 | } | ||
748 | } | ||
749 | |||
750 | |||
751 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
752 | /////////////////////////////// Marker handling //////////////////////////////// | ||
753 | //////////////////////////////////////////////////////////////////////////////// | ||
754 | |||
755 | var nmarkers, vismarkers, markers, markersmoved, paramschanged; | ||
756 | var homelat=null, homelon=null; | ||
757 | |||
758 | |||
759 | amb | 569 | // |
760 | amb | 574 | // Toggle a marker on the map. |
761 | amb | 569 | // |
762 | |||
763 | amb | 574 | function markerToggleMap(marker) |
764 | amb | 569 | { |
765 | amb | 577 | if(markers[marker].style.display == "") |
766 | amb | 574 | markerRemoveMap(marker); |
767 | else | ||
768 | markerAddMap(marker); | ||
769 | } | ||
770 | |||
771 | |||
772 | // | ||
773 | // Show a marker on the map. | ||
774 | // | ||
775 | |||
776 | function markerAddMap(marker) | ||
777 | { | ||
778 | amb | 577 | markers[marker].style.display = ""; |
779 | amb | 574 | |
780 | formSetCoords(marker); | ||
781 | |||
782 | amb | 577 | updateIcon(marker); |
783 | amb | 574 | |
784 | markersmoved=true; | ||
785 | } | ||
786 | |||
787 | |||
788 | // | ||
789 | // Remove a marker from the map. | ||
790 | // | ||
791 | |||
792 | function markerRemoveMap(marker) | ||
793 | { | ||
794 | amb | 577 | markers[marker].style.display = "none"; |
795 | amb | 574 | |
796 | amb | 577 | updateIcon(marker); |
797 | amb | 574 | |
798 | amb | 577 | markersmoved=true; |
799 | } | ||
800 | amb | 574 | |
801 | amb | 577 | |
802 | // | ||
803 | // Centre the marker on the map | ||
804 | // | ||
805 | |||
806 | function markerCentre(marker) | ||
807 | { | ||
808 | document.forms["form"].elements["lon" + marker].value=""; | ||
809 | document.forms["form"].elements["lat" + marker].value=""; | ||
810 | |||
811 | formSetCoords(marker); | ||
812 | |||
813 | amb | 574 | markersmoved=true; |
814 | } | ||
815 | |||
816 | |||
817 | // | ||
818 | // Clear the current marker. | ||
819 | // | ||
820 | |||
821 | function markerRemove(marker) | ||
822 | { | ||
823 | for(var marker2=marker;marker2<vismarkers;marker2++) | ||
824 | amb | 569 | { |
825 | amb | 574 | document.forms["form"].elements["lon" + marker2].value=document.forms["form"].elements["lon" + (marker2+1)].value; |
826 | document.forms["form"].elements["lat" + marker2].value=document.forms["form"].elements["lat" + (marker2+1)].value; | ||
827 | |||
828 | if(markers[marker2+1].style.display=="") | ||
829 | markerAddMap(marker2); | ||
830 | else | ||
831 | markerRemoveMap(marker2); | ||
832 | amb | 569 | } |
833 | amb | 574 | |
834 | markerRemoveMap(vismarkers); | ||
835 | |||
836 | var marker_tr=document.getElementById("point" + vismarkers); | ||
837 | |||
838 | marker_tr.style.display="none"; | ||
839 | |||
840 | vismarkers--; | ||
841 | |||
842 | if(vismarkers==1) | ||
843 | markerAddAfter(1); | ||
844 | |||
845 | updateCustomURL(); | ||
846 | } | ||
847 | |||
848 | |||
849 | // | ||
850 | // Add a marker before the current one. | ||
851 | // | ||
852 | |||
853 | function markerAddBefore(marker) | ||
854 | { | ||
855 | if(vismarkers==nmarkers || marker==1) | ||
856 | return false; | ||
857 | |||
858 | vismarkers++; | ||
859 | |||
860 | var marker_tr=document.getElementById("point" + vismarkers); | ||
861 | |||
862 | marker_tr.style.display=""; | ||
863 | |||
864 | for(var marker2=vismarkers;marker2>marker;marker2--) | ||
865 | amb | 569 | { |
866 | amb | 574 | document.forms["form"].elements["lon" + marker2].value=document.forms["form"].elements["lon" + (marker2-1)].value; |
867 | document.forms["form"].elements["lat" + marker2].value=document.forms["form"].elements["lat" + (marker2-1)].value; | ||
868 | amb | 569 | |
869 | amb | 574 | if(markers[marker2-1].style.display=="") |
870 | markerAddMap(marker2); | ||
871 | else | ||
872 | markerRemoveMap(marker2); | ||
873 | } | ||
874 | amb | 569 | |
875 | amb | 574 | document.forms["form"].elements["lon" + marker].value=""; |
876 | document.forms["form"].elements["lat" + marker].value=""; | ||
877 | markers[marker].style.display="none"; | ||
878 | amb | 569 | |
879 | amb | 574 | markerRemoveMap(marker); |
880 | |||
881 | updateCustomURL(); | ||
882 | } | ||
883 | |||
884 | |||
885 | // | ||
886 | // Add a marker after the current one. | ||
887 | // | ||
888 | |||
889 | function markerAddAfter(marker) | ||
890 | { | ||
891 | if(vismarkers==nmarkers) | ||
892 | return false; | ||
893 | |||
894 | vismarkers++; | ||
895 | |||
896 | var marker_tr=document.getElementById("point" + vismarkers); | ||
897 | |||
898 | marker_tr.style.display=""; | ||
899 | |||
900 | for(var marker2=vismarkers;marker2>(marker+1);marker2--) | ||
901 | { | ||
902 | document.forms["form"].elements["lon" + marker2].value=document.forms["form"].elements["lon" + (marker2-1)].value; | ||
903 | document.forms["form"].elements["lat" + marker2].value=document.forms["form"].elements["lat" + (marker2-1)].value; | ||
904 | |||
905 | if(markers[marker2-1].style.display=="") | ||
906 | markerAddMap(marker2); | ||
907 | else | ||
908 | markerRemoveMap(marker2); | ||
909 | amb | 569 | } |
910 | |||
911 | amb | 574 | document.forms["form"].elements["lon" + (marker+1)].value=""; |
912 | document.forms["form"].elements["lat" + (marker+1)].value=""; | ||
913 | markers[marker+1].style.display="none"; | ||
914 | amb | 569 | |
915 | amb | 574 | markerRemoveMap(marker+1); |
916 | |||
917 | updateCustomURL(); | ||
918 | amb | 569 | } |
919 | |||
920 | |||
921 | // | ||
922 | amb | 577 | // Set this marker as the home location. |
923 | // | ||
924 | |||
925 | function markerHome(marker) | ||
926 | { | ||
927 | if(markerHomeCookie(marker)) | ||
928 | for(marker=1;marker<=nmarkers;marker++) | ||
929 | updateIcon(marker); | ||
930 | } | ||
931 | |||
932 | |||
933 | // | ||
934 | // Update an icon to set colours and home or normal marker. | ||
935 | // | ||
936 | |||
937 | function updateIcon(marker) | ||
938 | { | ||
939 | var lon=document.forms["form"].elements["lon" + marker].value; | ||
940 | var lat=document.forms["form"].elements["lat" + marker].value; | ||
941 | |||
942 | if(lon==homelon && lat==homelat) | ||
943 | { | ||
944 | if(markers[marker].style.display=="") | ||
945 | document.images["waypoint" + marker].src="icons/marker-home-red.png"; | ||
946 | else | ||
947 | document.images["waypoint" + marker].src="icons/marker-home-grey.png"; | ||
948 | |||
949 | markers[marker].style.externalGraphic="icons/marker-home-red.png"; | ||
950 | } | ||
951 | else | ||
952 | { | ||
953 | if(markers[marker].style.display=="") | ||
954 | document.images["waypoint" + marker].src="icons/marker-" + marker + "-red.png"; | ||
955 | else | ||
956 | document.images["waypoint" + marker].src="icons/marker-" + marker + "-grey.png"; | ||
957 | |||
958 | markers[marker].style.externalGraphic="icons/marker-" + marker + "-red.png"; | ||
959 | } | ||
960 | |||
961 | layerVectors.drawFeature(markers[marker]); | ||
962 | } | ||
963 | |||
964 | |||
965 | // | ||
966 | // Set or clear the home marker icon | ||
967 | // | ||
968 | |||
969 | function markerHomeCookie(marker) | ||
970 | { | ||
971 | var lon=document.forms["form"].elements["lon" + marker].value; | ||
972 | var lat=document.forms["form"].elements["lat" + marker].value; | ||
973 | |||
974 | if(lon=="" || lat=="") | ||
975 | return(false); | ||
976 | |||
977 | var cookie; | ||
978 | var date = new Date(); | ||
979 | |||
980 | if((homelat==null && homelon==null) || | ||
981 | (homelat!=lat && homelon!=lon)) | ||
982 | { | ||
983 | cookie="Routino-home=lon:" + lon + ":lat:" + lat; | ||
984 | |||
985 | date.setUTCFullYear(date.getUTCFullYear()+5); | ||
986 | |||
987 | homelat=lat; | ||
988 | homelon=lon; | ||
989 | } | ||
990 | else | ||
991 | { | ||
992 | cookie="Routino-home=unset"; | ||
993 | |||
994 | date.setUTCFullYear(date.getUTCFullYear()-1); | ||
995 | |||
996 | homelat=null; | ||
997 | homelon=null; | ||
998 | } | ||
999 | |||
1000 | document.cookie=cookie + ";expires=" + date.toGMTString(); | ||
1001 | |||
1002 | return(true); | ||
1003 | } | ||
1004 | |||
1005 | |||
1006 | // | ||
1007 | amb | 574 | // Move this marker up. |
1008 | // | ||
1009 | |||
1010 | function markerMoveUp(marker) | ||
1011 | { | ||
1012 | if(marker==1) | ||
1013 | return false; | ||
1014 | |||
1015 | markerSwap(marker,marker-1); | ||
1016 | } | ||
1017 | |||
1018 | |||
1019 | // | ||
1020 | // Move this marker down. | ||
1021 | // | ||
1022 | |||
1023 | function markerMoveDown(marker) | ||
1024 | { | ||
1025 | if(marker==vismarkers) | ||
1026 | return false; | ||
1027 | |||
1028 | markerSwap(marker,marker+1); | ||
1029 | } | ||
1030 | |||
1031 | |||
1032 | // | ||
1033 | // Swap a pair of markers. | ||
1034 | // | ||
1035 | |||
1036 | function markerSwap(marker1,marker2) | ||
1037 | { | ||
1038 | var lon=document.forms["form"].elements["lon" + marker1].value; | ||
1039 | var lat=document.forms["form"].elements["lat" + marker1].value; | ||
1040 | var display=markers[marker1].style.display; | ||
1041 | |||
1042 | document.forms["form"].elements["lon" + marker1].value=document.forms["form"].elements["lon" + marker2].value; | ||
1043 | document.forms["form"].elements["lat" + marker1].value=document.forms["form"].elements["lat" + marker2].value; | ||
1044 | if(markers[marker2].style.display=="") | ||
1045 | markerAddMap(marker1); | ||
1046 | else | ||
1047 | markerRemoveMap(marker1); | ||
1048 | |||
1049 | document.forms["form"].elements["lon" + marker2].value=lon; | ||
1050 | document.forms["form"].elements["lat" + marker2].value=lat; | ||
1051 | if(display=="") | ||
1052 | markerAddMap(marker2); | ||
1053 | else | ||
1054 | markerRemoveMap(marker2); | ||
1055 | |||
1056 | updateCustomURL(); | ||
1057 | } | ||
1058 | |||
1059 | |||
1060 | // | ||
1061 | // Reverse the markers. | ||
1062 | // | ||
1063 | |||
1064 | function markersReverse() | ||
1065 | { | ||
1066 | for(var marker=1;marker<=vismarkers/2;marker++) | ||
1067 | markerSwap(marker,vismarkers+1-marker); | ||
1068 | |||
1069 | updateCustomURL(); | ||
1070 | } | ||
1071 | |||
1072 | |||
1073 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
1074 | //////////////////////////// Route results handling //////////////////////////// | ||
1075 | //////////////////////////////////////////////////////////////////////////////// | ||
1076 | |||
1077 | var route_light_colours={shortest: "#60C060", quickest: "#6060C0"}; | ||
1078 | var route_dark_colours ={shortest: "#408040", quickest: "#404080"}; | ||
1079 | |||
1080 | var highlights={shortest: null, quickest: null}; | ||
1081 | var popups={shortest: null, quickest: null}; | ||
1082 | var routepoints={shortest: {}, quickest: {}}; | ||
1083 | var gpx_style={shortest: null, quickest: null}; | ||
1084 | |||
1085 | amb | 574 | // |
1086 | amb | 577 | // Zoom to a specific item in the route |
1087 | amb | 569 | // |
1088 | |||
1089 | amb | 577 | function zoomTo(type,line) |
1090 | amb | 569 | { |
1091 | amb | 577 | var lonlat = new OpenLayers.LonLat(routepoints[type][line].lon,routepoints[type][line].lat).transform(epsg4326,map.getProjectionObject()); |
1092 | amb | 569 | |
1093 | amb | 577 | map.moveTo(lonlat,map.numZoomLevels-2); |
1094 | amb | 569 | } |
1095 | |||
1096 | |||
1097 | // | ||
1098 | amb | 577 | // Highlight a specific item in the route |
1099 | amb | 569 | // |
1100 | |||
1101 | amb | 577 | function highlight(type,line) |
1102 | amb | 569 | { |
1103 | amb | 577 | if(line==-1) |
1104 | { | ||
1105 | highlights[type].style.display = "none"; | ||
1106 | amb | 569 | |
1107 | amb | 577 | drawPopup(popups[type],null); |
1108 | amb | 569 | } |
1109 | amb | 577 | else |
1110 | amb | 569 | { |
1111 | amb | 577 | // Marker |
1112 | amb | 569 | |
1113 | amb | 577 | var lonlat = new OpenLayers.LonLat(routepoints[type][line].lon,routepoints[type][line].lat).transform(epsg4326,map.getProjectionObject()); |
1114 | amb | 569 | |
1115 | amb | 577 | highlights[type].move(lonlat); |
1116 | amb | 569 | |
1117 | amb | 577 | if(highlights[type].style.display = "none") |
1118 | highlights[type].style.display = ""; | ||
1119 | amb | 569 | |
1120 | amb | 577 | // Popup |
1121 | amb | 569 | |
1122 | amb | 577 | drawPopup(popups[type],"<table>" + routepoints[type][line].html + "</table>"); |
1123 | } | ||
1124 | |||
1125 | layerVectors.drawFeature(highlights[type]); | ||
1126 | amb | 569 | } |
1127 | |||
1128 | |||
1129 | // | ||
1130 | amb | 577 | // Create a popup - not using OpenLayers because want it fixed on screen not fixed on map. |
1131 | amb | 569 | // |
1132 | |||
1133 | amb | 577 | function createPopup(type) |
1134 | amb | 569 | { |
1135 | amb | 577 | var popup=document.createElement('div'); |
1136 | amb | 569 | |
1137 | amb | 577 | popup.className = "popup"; |
1138 | amb | 569 | |
1139 | amb | 577 | popup.innerHTML = "<span></span>"; |
1140 | amb | 569 | |
1141 | amb | 577 | popup.style.display = "none"; |
1142 | amb | 569 | |
1143 | amb | 577 | popup.style.position = "fixed"; |
1144 | popup.style.top = "-4000px"; | ||
1145 | popup.style.left = "-4000px"; | ||
1146 | popup.style.zIndex = "100"; | ||
1147 | amb | 569 | |
1148 | amb | 577 | popup.style.padding = "5px"; |
1149 | amb | 569 | |
1150 | amb | 577 | popup.style.opacity=0.85; |
1151 | popup.style.backgroundColor=route_light_colours[type]; | ||
1152 | popup.style.border="4px solid " + route_dark_colours[type]; | ||
1153 | amb | 569 | |
1154 | amb | 577 | document.body.appendChild(popup); |
1155 | amb | 569 | |
1156 | amb | 577 | return(popup); |
1157 | amb | 569 | } |
1158 | |||
1159 | |||
1160 | // | ||
1161 | amb | 577 | // Draw a popup - not using OpenLayers because want it fixed on screen not fixed on map. |
1162 | amb | 569 | // |
1163 | |||
1164 | amb | 577 | function drawPopup(popup,html) |
1165 | amb | 569 | { |
1166 | amb | 577 | if(html==null) |
1167 | amb | 569 | { |
1168 | amb | 577 | popup.style.display="none"; |
1169 | return; | ||
1170 | } | ||
1171 | amb | 574 | |
1172 | amb | 577 | if(popup.style.display=="none") |
1173 | amb | 569 | { |
1174 | amb | 577 | var map_div=document.getElementById("map"); |
1175 | amb | 569 | |
1176 | amb | 577 | popup.style.left =map_div.offsetParent.offsetLeft+map_div.offsetLeft+60 + "px"; |
1177 | popup.style.top = map_div.offsetTop +30 + "px"; | ||
1178 | popup.style.width =map_div.clientWidth-100 + "px"; | ||
1179 | amb | 574 | |
1180 | amb | 577 | popup.style.display=""; |
1181 | amb | 569 | } |
1182 | |||
1183 | amb | 577 | popup.innerHTML=html; |
1184 | amb | 569 | } |
1185 | |||
1186 | |||
1187 | // | ||
1188 | amb | 577 | // Remove a GPX trace |
1189 | amb | 569 | // |
1190 | |||
1191 | amb | 577 | function removeGPXTrace(type) |
1192 | amb | 569 | { |
1193 | amb | 577 | map.removeLayer(layerGPX[type]); |
1194 | layerGPX[type].destroy(); | ||
1195 | layerGPX[type]=null; | ||
1196 | amb | 569 | |
1197 | amb | 577 | displayStatus(type,"no_info"); |
1198 | amb | 569 | |
1199 | amb | 577 | var div_links=document.getElementById(type + "_links"); |
1200 | div_links.style.display = "none"; | ||
1201 | amb | 569 | |
1202 | amb | 577 | var div_route=document.getElementById(type + "_route"); |
1203 | div_route.innerHTML = ""; | ||
1204 | amb | 569 | |
1205 | amb | 577 | hideshow_hide(type); |
1206 | } | ||
1207 | amb | 569 | |
1208 | amb | 574 | |
1209 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
1210 | /////////////////////////////// Server handling //////////////////////////////// | ||
1211 | //////////////////////////////////////////////////////////////////////////////// | ||
1212 | amb | 569 | |
1213 | // | ||
1214 | // Display data statistics | ||
1215 | // | ||
1216 | |||
1217 | function displayStatistics() | ||
1218 | { | ||
1219 | // Use AJAX to get the statistics | ||
1220 | |||
1221 | OpenLayers.loadURL("statistics.cgi",null,null,runStatisticsSuccess); | ||
1222 | } | ||
1223 | |||
1224 | |||
1225 | // | ||
1226 | amb | 577 | // Success in running data statistics generation. |
1227 | amb | 569 | // |
1228 | |||
1229 | function runStatisticsSuccess(response) | ||
1230 | { | ||
1231 | var statistics_data=document.getElementById("statistics_data"); | ||
1232 | var statistics_link=document.getElementById("statistics_link"); | ||
1233 | |||
1234 | statistics_data.innerHTML="<pre>" + response.responseText + "</pre>"; | ||
1235 | |||
1236 | statistics_link.style.display="none"; | ||
1237 | } | ||
1238 | |||
1239 | |||
1240 | // | ||
1241 | amb | 577 | // Submit form - perform the routing |
1242 | amb | 569 | // |
1243 | |||
1244 | function findRoute(type) | ||
1245 | { | ||
1246 | tab_select("results"); | ||
1247 | |||
1248 | amb | 572 | hideshow_hide('help_options'); |
1249 | amb | 569 | hideshow_hide('shortest'); |
1250 | hideshow_hide('quickest'); | ||
1251 | |||
1252 | amb | 577 | displayStatus("result","running"); |
1253 | amb | 569 | |
1254 | var url="router.cgi" + buildURLArguments(0) + ";type=" + type; | ||
1255 | |||
1256 | // Destroy the existing layer(s) | ||
1257 | |||
1258 | if(markersmoved || paramschanged) | ||
1259 | { | ||
1260 | if(layerGPX.shortest!=null) | ||
1261 | removeGPXTrace("shortest"); | ||
1262 | if(layerGPX.quickest!=null) | ||
1263 | removeGPXTrace("quickest"); | ||
1264 | markersmoved=false; | ||
1265 | paramschanged=false; | ||
1266 | } | ||
1267 | else if(layerGPX[type]!=null) | ||
1268 | removeGPXTrace(type); | ||
1269 | |||
1270 | // Use AJAX to run the router | ||
1271 | |||
1272 | routing_type=type; | ||
1273 | |||
1274 | OpenLayers.loadURL(url,null,null,runRouterSuccess,runRouterFailure); | ||
1275 | } | ||
1276 | |||
1277 | |||
1278 | // | ||
1279 | // Success in running router. | ||
1280 | // | ||
1281 | |||
1282 | function runRouterSuccess(response) | ||
1283 | { | ||
1284 | var lines=response.responseText.split('\n'); | ||
1285 | |||
1286 | var uuid=lines[0]; | ||
1287 | var cpuinfo=lines[1]; | ||
1288 | var distinfo=lines[2]; | ||
1289 | var message=lines[3]; | ||
1290 | |||
1291 | amb | 629 | var link; |
1292 | |||
1293 | amb | 569 | // Update the status message |
1294 | |||
1295 | if(message!="") | ||
1296 | { | ||
1297 | amb | 577 | displayStatus("result","error"); |
1298 | amb | 572 | hideshow_show('help_route'); |
1299 | amb | 629 | |
1300 | link=document.getElementById("router_log_error"); | ||
1301 | link.href="results.cgi?uuid=" + uuid + ";type=router;format=log"; | ||
1302 | |||
1303 | amb | 569 | return; |
1304 | } | ||
1305 | else | ||
1306 | { | ||
1307 | amb | 577 | displayStatus("result","complete"); |
1308 | amb | 572 | hideshow_hide('help_route'); |
1309 | amb | 629 | |
1310 | link=document.getElementById("router_log_complete"); | ||
1311 | link.href="results.cgi?uuid=" + uuid + ";type=router;format=log"; | ||
1312 | amb | 569 | } |
1313 | |||
1314 | // Update the routing result message | ||
1315 | |||
1316 | amb | 577 | displayStatus(routing_type,"info",distinfo.bold()); |
1317 | amb | 569 | |
1318 | amb | 577 | link=document.getElementById(routing_type + "_html"); |
1319 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=html"; | ||
1320 | link=document.getElementById(routing_type + "_gpx_track"); | ||
1321 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=gpx-track"; | ||
1322 | link=document.getElementById(routing_type + "_gpx_route"); | ||
1323 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=gpx-route"; | ||
1324 | link=document.getElementById(routing_type + "_text_all"); | ||
1325 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=text-all"; | ||
1326 | link=document.getElementById(routing_type + "_text"); | ||
1327 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=text"; | ||
1328 | amb | 569 | |
1329 | amb | 577 | var div_links=document.getElementById(routing_type + "_links"); |
1330 | div_links.style.display = ""; | ||
1331 | amb | 569 | |
1332 | // Add a GPX layer | ||
1333 | |||
1334 | var url="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=gpx-track"; | ||
1335 | |||
1336 | layerGPX[routing_type] = new OpenLayers.Layer.GML("GPX (" + routing_type + ")", url, | ||
1337 | { | ||
1338 | format: OpenLayers.Format.GPX, | ||
1339 | style: gpx_style[routing_type], | ||
1340 | projection: map.displayProjection | ||
1341 | }); | ||
1342 | |||
1343 | map.addLayer(layerGPX[routing_type]); | ||
1344 | |||
1345 | hideshow_show(routing_type); | ||
1346 | |||
1347 | displayResult(routing_type,uuid); | ||
1348 | } | ||
1349 | |||
1350 | |||
1351 | // | ||
1352 | // Failure in running router. | ||
1353 | // | ||
1354 | |||
1355 | function runRouterFailure(response) | ||
1356 | { | ||
1357 | amb | 577 | displayStatus("result","failed"); |
1358 | amb | 569 | } |
1359 | |||
1360 | |||
1361 | // | ||
1362 | amb | 577 | // Display the status |
1363 | // | ||
1364 | |||
1365 | function displayStatus(type,subtype,content) | ||
1366 | { | ||
1367 | var div_status=document.getElementById(type + "_status"); | ||
1368 | |||
1369 | var child=div_status.firstChild; | ||
1370 | |||
1371 | do | ||
1372 | { | ||
1373 | if(child.id != undefined) | ||
1374 | child.style.display="none"; | ||
1375 | |||
1376 | child=child.nextSibling; | ||
1377 | } | ||
1378 | while(child != undefined); | ||
1379 | |||
1380 | var span_status=document.getElementById(type + "_status_" + subtype); | ||
1381 | |||
1382 | span_status.style.display=""; | ||
1383 | |||
1384 | if(content != null) | ||
1385 | span_status.innerHTML=content; | ||
1386 | } | ||
1387 | |||
1388 | |||
1389 | // | ||
1390 | amb | 569 | // Display the route |
1391 | // | ||
1392 | |||
1393 | function displayResult(type,uuid) | ||
1394 | { | ||
1395 | routing_type = type; | ||
1396 | |||
1397 | // Add the route | ||
1398 | |||
1399 | amb | 577 | var url="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=html"; |
1400 | amb | 569 | |
1401 | // Use AJAX to get the route | ||
1402 | |||
1403 | OpenLayers.loadURL(url,null,null,getRouteSuccess,getRouteFailure); | ||
1404 | } | ||
1405 | |||
1406 | |||
1407 | // | ||
1408 | // Success in getting route. | ||
1409 | // | ||
1410 | |||
1411 | function getRouteSuccess(response) | ||
1412 | { | ||
1413 | var lines=response.responseText.split('\n'); | ||
1414 | amb | 577 | var div_route=document.getElementById(routing_type + "_route"); |
1415 | amb | 569 | |
1416 | amb | 577 | routepoints[routing_type]=[]; |
1417 | amb | 569 | |
1418 | amb | 577 | var points=routepoints[routing_type]; |
1419 | amb | 569 | |
1420 | amb | 577 | var table=0; |
1421 | var point=0; | ||
1422 | var total_table,total_word; | ||
1423 | amb | 569 | |
1424 | amb | 577 | for(var line=0;line<lines.length;line++) |
1425 | amb | 569 | { |
1426 | amb | 577 | var thisline=lines[line]; |
1427 | amb | 569 | |
1428 | amb | 577 | if(table==0) |
1429 | { | ||
1430 | if(thisline.match('<table>')) | ||
1431 | table=1; | ||
1432 | else | ||
1433 | continue; | ||
1434 | } | ||
1435 | amb | 574 | |
1436 | amb | 577 | if(thisline.match('</table>')) |
1437 | break; | ||
1438 | |||
1439 | if(thisline.match('<tr class=\'([a-z])\'>')) | ||
1440 | amb | 569 | { |
1441 | amb | 577 | var rowtype=RegExp.$1; |
1442 | amb | 569 | |
1443 | amb | 577 | if(rowtype=='c') |
1444 | { | ||
1445 | thisline.match('<td class=\'r\'> *([-0-9.]+) *([-0-9.]+)'); | ||
1446 | points[point]={lat: Number(RegExp.$1), lon: Number(RegExp.$2), html: "", highway: "", distance: "", total: ""}; | ||
1447 | amb | 574 | |
1448 | amb | 577 | point++; |
1449 | } | ||
1450 | else if(rowtype=='n') | ||
1451 | { | ||
1452 | points[point-1].html += thisline; | ||
1453 | } | ||
1454 | else if(rowtype=='s') | ||
1455 | { | ||
1456 | thisline.match('<span class=\'h\'>([^<]+)</span>'); | ||
1457 | points[point-1].highway = RegExp.$1; | ||
1458 | amb | 574 | |
1459 | amb | 577 | thisline.match('<span class=\'d\'>([^<]+)</span>'); |
1460 | points[point-1].distance = RegExp.$1; | ||
1461 | amb | 574 | |
1462 | amb | 577 | thisline.match('(<span class=\'j\'>[^<]+</span>)'); |
1463 | points[point-1].total = RegExp.$1; | ||
1464 | |||
1465 | thisline.match('^(.*).<span class=\'j\'>'); | ||
1466 | |||
1467 | points[point-1].html += RegExp.$1; | ||
1468 | } | ||
1469 | else if(rowtype=='t') | ||
1470 | { | ||
1471 | points[point-1].html += thisline; | ||
1472 | |||
1473 | thisline.match('^(.*<td class=\'r\'>)'); | ||
1474 | total_table = RegExp.$1; | ||
1475 | |||
1476 | thisline.match('<td class=\'l\'>([^<]+)<'); | ||
1477 | total_word = RegExp.$1; | ||
1478 | |||
1479 | thisline.match('<span class=\'j\'>([^<]+)</span>'); | ||
1480 | points[point-1].total = RegExp.$1; | ||
1481 | } | ||
1482 | amb | 569 | } |
1483 | } | ||
1484 | |||
1485 | amb | 577 | var result="<table onmouseout='highlight(\"" + routing_type + "\",-1)'>"; |
1486 | |||
1487 | for(var p=0;p<point-1;p++) | ||
1488 | { | ||
1489 | points[p].html += total_table + points[p].total; | ||
1490 | |||
1491 | result=result + "<tr onclick='zoomTo(\"" + routing_type + "\"," + p + ")'" + | ||
1492 | " onmouseover='highlight(\"" + routing_type + "\"," + p + ")'>" + | ||
1493 | "<td class='distance' title='" + points[p].distance + "'>#" + (p+1) + | ||
1494 | "<td class='highway'>" + points[p].highway; | ||
1495 | } | ||
1496 | |||
1497 | result=result + "<tr onclick='zoomTo(\"" + routing_type + "\"," + p + ")'" + | ||
1498 | " onmouseover='highlight(\"" + routing_type + "\"," + p + ")'>" + | ||
1499 | "<td colspan='2'>" + total_word + " " + points[p].total; | ||
1500 | |||
1501 | amb | 569 | result=result + "</table>"; |
1502 | |||
1503 | amb | 577 | div_route.innerHTML=result; |
1504 | amb | 569 | } |
1505 | |||
1506 | |||
1507 | // | ||
1508 | // Failure in getting route. | ||
1509 | // | ||
1510 | |||
1511 | function getRouteFailure(response) | ||
1512 | { | ||
1513 | amb | 577 | var div_route=document.getElementById(routing_type + "_route"); |
1514 | div_route.innerHTML = ""; | ||
1515 | amb | 569 | } |