Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/web/www/routino/router.openlayers.js
Parent Directory
|
Revision Log
Revision 1328 -
(hide annotations)
(download)
(as text)
Sat May 18 10:26:50 2013 UTC (11 years, 10 months ago) by amb
Original Path: trunk/web/www/routino/router.js
File MIME type: application/javascript
File size: 47545 byte(s)
Sat May 18 10:26:50 2013 UTC (11 years, 10 months ago) by amb
Original Path: trunk/web/www/routino/router.js
File MIME type: application/javascript
File size: 47545 byte(s)
Don't display the marker layers in the layer switcher control.
1 | amb | 569 | // |
2 | // Routino router web page Javascript | ||
3 | // | ||
4 | // Part of the Routino routing software. | ||
5 | // | ||
6 | amb | 1239 | // This file Copyright 2008-2013 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 | 987 | var vismarkers, markers, markersmoved, paramschanged; |
24 | amb | 985 | var homelat=null, homelon=null; |
25 | |||
26 | |||
27 | //////////////////////////////////////////////////////////////////////////////// | ||
28 | /////////////////////////////// Initialisation ///////////////////////////////// | ||
29 | //////////////////////////////////////////////////////////////////////////////// | ||
30 | |||
31 | amb | 577 | // Make a deep copy of the routino profile. |
32 | amb | 569 | |
33 | amb | 577 | var routino_default={}; |
34 | for(var l1 in routino) | ||
35 | if(typeof(routino[l1])!='object') | ||
36 | routino_default[l1]=routino[l1]; | ||
37 | else | ||
38 | { | ||
39 | routino_default[l1]={}; | ||
40 | for(var l2 in routino[l1]) | ||
41 | if(typeof(routino[l1][l2])!='object') | ||
42 | routino_default[l1][l2]=Number(routino[l1][l2]); | ||
43 | else | ||
44 | { | ||
45 | routino_default[l1][l2]={}; | ||
46 | for(var l3 in routino[l1][l2]) | ||
47 | routino_default[l1][l2][l3]=Number(routino[l1][l2][l3]); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | amb | 985 | // Store the latitude and longitude in the routino variable |
52 | amb | 577 | |
53 | amb | 985 | routino.point=[]; |
54 | amb | 1012 | for(var marker=1;marker<=mapprops.maxmarkers;marker++) |
55 | amb | 985 | { |
56 | routino.point[marker]={}; | ||
57 | |||
58 | routino.point[marker].lon=""; | ||
59 | routino.point[marker].lat=""; | ||
60 | amb | 1001 | routino.point[marker].search=""; |
61 | amb | 985 | routino.point[marker].active=false; |
62 | amb | 1034 | routino.point[marker].used=false; |
63 | amb | 1036 | routino.point[marker].home=false; |
64 | amb | 985 | } |
65 | |||
66 | // Process the URL query string and extract the arguments | ||
67 | |||
68 | var legal={"^lon" : "^[-0-9.]+$", | ||
69 | "^lat" : "^[-0-9.]+$", | ||
70 | "^zoom" : "^[0-9]+$", | ||
71 | |||
72 | "^lon[1-9]" : "^[-0-9.]+$", | ||
73 | "^lat[1-9]" : "^[-0-9.]+$", | ||
74 | amb | 1001 | "^search[1-9]" : "^.+$", |
75 | amb | 985 | "^transport" : "^[a-z]+$", |
76 | "^highway-[a-z]+" : "^[0-9.]+$", | ||
77 | "^speed-[a-z]+" : "^[0-9.]+$", | ||
78 | "^property-[a-z]+" : "^[0-9.]+$", | ||
79 | "^oneway" : "^(1|0|true|false|on|off)$", | ||
80 | "^turns" : "^(1|0|true|false|on|off)$", | ||
81 | "^weight" : "^[0-9.]+$", | ||
82 | "^height" : "^[0-9.]+$", | ||
83 | "^width" : "^[0-9.]+$", | ||
84 | "^length" : "^[0-9.]+$", | ||
85 | |||
86 | "^language" : "^[-a-zA-Z]+$"}; | ||
87 | |||
88 | var args={}; | ||
89 | |||
90 | if(location.search.length>1) | ||
91 | { | ||
92 | var query,queries; | ||
93 | |||
94 | query=location.search.replace(/^\?/,""); | ||
95 | query=query.replace(/;/g,'&'); | ||
96 | queries=query.split('&'); | ||
97 | |||
98 | for(var i=0;i<queries.length;i++) | ||
99 | { | ||
100 | queries[i].match(/^([^=]+)(=(.*))?$/); | ||
101 | |||
102 | k=RegExp.$1; | ||
103 | v=unescape(RegExp.$3); | ||
104 | |||
105 | for(var l in legal) | ||
106 | { | ||
107 | if(k.match(RegExp(l)) && v.match(RegExp(legal[l]))) | ||
108 | args[k]=v; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | |||
113 | |||
114 | amb | 987 | // |
115 | // Fill in the HTML - add the missing waypoints | ||
116 | // | ||
117 | |||
118 | amb | 1035 | function html_init() // called from router.html |
119 | amb | 987 | { |
120 | var waypoints=document.getElementById("waypoints"); | ||
121 | amb | 1005 | |
122 | amb | 987 | var waypoint_html=waypoints.rows[0].innerHTML; |
123 | amb | 1005 | waypoints.deleteRow(0); |
124 | amb | 987 | |
125 | amb | 1005 | var searchresults_html=waypoints.rows[0].innerHTML; |
126 | amb | 987 | waypoints.deleteRow(0); |
127 | |||
128 | amb | 1012 | for(var marker=mapprops.maxmarkers;marker>=1;marker--) |
129 | amb | 987 | { |
130 | amb | 1005 | var searchresults=waypoints.insertRow(0); |
131 | amb | 1011 | |
132 | amb | 1037 | searchresults.style.display="none"; |
133 | amb | 1005 | searchresults.id="searchresults" + marker; |
134 | amb | 1011 | searchresults.innerHTML=searchresults_html.split('XXX').join(marker); |
135 | amb | 987 | |
136 | amb | 1011 | var waypoint=waypoints.insertRow(0); |
137 | amb | 1005 | |
138 | amb | 1037 | waypoint.style.display="none"; |
139 | amb | 1005 | waypoint.id="waypoint" + marker; |
140 | amb | 1011 | waypoint.innerHTML=waypoint_html.split('XXX').join(marker); |
141 | amb | 987 | } |
142 | } | ||
143 | |||
144 | |||
145 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
146 | //////////////////////////////// Form handling ///////////////////////////////// | ||
147 | //////////////////////////////////////////////////////////////////////////////// | ||
148 | |||
149 | amb | 569 | // |
150 | // Form initialisation - fill in the uninitialised parts | ||
151 | // | ||
152 | |||
153 | amb | 1035 | function form_init() // called from router.html |
154 | amb | 569 | { |
155 | amb | 985 | // Fill in the waypoints |
156 | amb | 569 | |
157 | amb | 1039 | vismarkers=0; |
158 | amb | 569 | |
159 | amb | 1012 | for(var marker=mapprops.maxmarkers;marker>=1;marker--) |
160 | amb | 569 | { |
161 | amb | 985 | var lon=args["lon" + marker]; |
162 | var lat=args["lat" + marker]; | ||
163 | amb | 1001 | var search=args["search" + marker]; |
164 | amb | 577 | |
165 | amb | 1001 | if(lon != undefined && lat != undefined && search != undefined && lon != "" && lat != "" && search != "") |
166 | amb | 569 | { |
167 | amb | 1037 | markerAddForm(marker); |
168 | |||
169 | amb | 1001 | formSetSearch(marker,search); |
170 | amb | 1032 | formSetCoords(marker,lon,lat); |
171 | amb | 569 | |
172 | amb | 1032 | markerAddMap(marker); |
173 | |||
174 | amb | 1001 | markerSearch(marker); |
175 | |||
176 | amb | 1039 | vismarkers++; |
177 | amb | 569 | } |
178 | amb | 1001 | else if(lon != undefined && lat != undefined && lon != "" && lat != "") |
179 | { | ||
180 | amb | 1037 | markerAddForm(marker); |
181 | |||
182 | amb | 1032 | formSetCoords(marker,lon,lat); |
183 | amb | 1001 | |
184 | amb | 1032 | markerAddMap(marker); |
185 | |||
186 | amb | 1001 | markerCoords(marker); |
187 | |||
188 | amb | 1039 | vismarkers++; |
189 | amb | 1001 | } |
190 | else if(search != undefined && search != "") | ||
191 | { | ||
192 | amb | 1037 | markerAddForm(marker); |
193 | |||
194 | amb | 1001 | formSetSearch(marker,search); |
195 | |||
196 | markerSearch(marker); | ||
197 | |||
198 | DoSearch(marker); | ||
199 | |||
200 | amb | 1039 | vismarkers++; |
201 | amb | 1001 | } |
202 | amb | 1039 | else if(vismarkers || marker<=2) |
203 | { | ||
204 | amb | 1037 | markerAddForm(marker); |
205 | amb | 1016 | |
206 | amb | 1039 | vismarkers++; |
207 | } | ||
208 | |||
209 | amb | 1016 | var searchfield=document.forms["form"].elements["search" + marker]; |
210 | |||
211 | if(searchfield.addEventListener) | ||
212 | searchfield.addEventListener('keyup', searchOnReturnKey, false); | ||
213 | else if(searchfield.attachEvent) | ||
214 | searchfield.attachEvent('keyup', searchOnReturnKey); // Internet Explorer | ||
215 | amb | 985 | } |
216 | amb | 569 | |
217 | amb | 985 | // Update the transport type with the URL settings which updates all HTML forms to defaults. |
218 | amb | 574 | |
219 | amb | 985 | var transport=routino.transport; |
220 | amb | 569 | |
221 | amb | 985 | if(args["transport"] != undefined) |
222 | transport=args["transport"]; | ||
223 | amb | 577 | |
224 | amb | 985 | formSetTransport(transport); |
225 | amb | 577 | |
226 | amb | 985 | // Update the HTML with the URL settings |
227 | |||
228 | if(args["language"] != undefined) | ||
229 | formSetLanguage(args["language"]); | ||
230 | |||
231 | for(var key in routino.profile_highway) | ||
232 | if(args["highway-" + key] != undefined) | ||
233 | formSetHighway(key,args["highway-" + key]); | ||
234 | |||
235 | for(var key in routino.profile_speed) | ||
236 | if(args["speed-" + key] != undefined) | ||
237 | formSetSpeed(key,args["speed-" + key]); | ||
238 | |||
239 | for(var key in routino.profile_property) | ||
240 | if(args["property-" + key] != undefined) | ||
241 | formSetProperty(key,args["property-" + key]); | ||
242 | |||
243 | for(var key in routino.restrictions) | ||
244 | amb | 574 | { |
245 | amb | 985 | if(key=="oneway" || key=="turns") |
246 | amb | 577 | { |
247 | amb | 985 | if(args[key] != undefined) |
248 | formSetRestriction(key,args[key]); | ||
249 | amb | 577 | } |
250 | amb | 985 | else |
251 | { | ||
252 | if(args["restrict-" + key] != undefined) | ||
253 | formSetRestriction(key,args["restrict-" + key]); | ||
254 | } | ||
255 | amb | 574 | } |
256 | amb | 569 | |
257 | amb | 577 | // Get the home location cookie and compare to each waypoint |
258 | |||
259 | var cookies=document.cookie.split('; '); | ||
260 | |||
261 | for(var cookie=0;cookie<cookies.length;cookie++) | ||
262 | if(cookies[cookie].substr(0,"Routino-home".length)=="Routino-home") | ||
263 | { | ||
264 | var data=cookies[cookie].split(/[=:;]/); | ||
265 | |||
266 | if(data[1]=="lon") homelon=Number(data[2]); | ||
267 | if(data[3]=="lat") homelat=Number(data[4]); | ||
268 | } | ||
269 | |||
270 | if(homelon!=null && homelat!=null) | ||
271 | { | ||
272 | amb | 1039 | for(var m=1;m<=vismarkers;m++) |
273 | markerCheckHome(m); | ||
274 | amb | 577 | |
275 | // If the first location is empty and the cookie is set then fill it. | ||
276 | |||
277 | amb | 1034 | if(!routino.point[1].used) |
278 | amb | 1036 | markerMoveHome(1); |
279 | amb | 577 | } |
280 | amb | 569 | } |
281 | |||
282 | |||
283 | // | ||
284 | amb | 1016 | // Function to perform the search if the return key is pressed. |
285 | // (using 'onchange' only triggers once and is confusing when clicking outside the field). | ||
286 | // | ||
287 | |||
288 | function searchOnReturnKey(ev) | ||
289 | { | ||
290 | if(ev.keyCode==13) | ||
291 | if(this.name.match(/^search([0-9]+)$/)) | ||
292 | formSetSearch(RegExp.$1); | ||
293 | |||
294 | return(true); | ||
295 | } | ||
296 | |||
297 | |||
298 | // | ||
299 | amb | 577 | // Change of language in the form |
300 | // | ||
301 | |||
302 | amb | 1035 | function formSetLanguage(value) // called from router.html (with no arguments) |
303 | amb | 577 | { |
304 | amb | 985 | if(value == undefined) |
305 | { | ||
306 | for(var lang=0;lang<document.forms["form"].elements["language"].length;lang++) | ||
307 | if(document.forms["form"].elements["language"][lang].checked) | ||
308 | routino.language=document.forms["form"].elements["language"][lang].value; | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | for(var lang=0;lang<document.forms["form"].elements["language"].length;lang++) | ||
313 | if(document.forms["form"].elements["language"][lang].value==value) | ||
314 | document.forms["form"].elements["language"][lang].checked=true; | ||
315 | else | ||
316 | document.forms["form"].elements["language"][lang].checked=false; | ||
317 | amb | 577 | |
318 | amb | 985 | routino.language=value; |
319 | } | ||
320 | amb | 577 | } |
321 | |||
322 | |||
323 | // | ||
324 | amb | 569 | // Change of transport in the form |
325 | // | ||
326 | |||
327 | amb | 1035 | function formSetTransport(value) // called from router.html |
328 | amb | 569 | { |
329 | amb | 985 | routino.transport=value; |
330 | amb | 569 | |
331 | amb | 577 | for(var key in routino.transports) |
332 | document.forms["form"].elements["transport"][routino.transports[key]-1].checked=(key==routino.transport); | ||
333 | amb | 569 | |
334 | amb | 577 | for(var key in routino.profile_highway) |
335 | document.forms["form"].elements["highway-" + key].value=routino.profile_highway[key][routino.transport]; | ||
336 | amb | 569 | |
337 | amb | 577 | for(var key in routino.profile_speed) |
338 | document.forms["form"].elements["speed-" + key].value=routino.profile_speed[key][routino.transport]; | ||
339 | amb | 569 | |
340 | amb | 577 | for(var key in routino.profile_property) |
341 | document.forms["form"].elements["property-" + key].value=routino.profile_property[key][routino.transport]; | ||
342 | amb | 569 | |
343 | amb | 577 | for(var key in routino.restrictions) |
344 | amb | 569 | { |
345 | amb | 622 | if(key=="oneway" || key=="turns") |
346 | amb | 577 | document.forms["form"].elements["restrict-" + key].checked=routino.profile_restrictions[key][routino.transport]; |
347 | amb | 569 | else |
348 | amb | 577 | document.forms["form"].elements["restrict-" + key].value=routino.profile_restrictions[key][routino.transport]; |
349 | amb | 569 | } |
350 | |||
351 | paramschanged=true; | ||
352 | } | ||
353 | |||
354 | |||
355 | // | ||
356 | // Change of highway in the form | ||
357 | // | ||
358 | |||
359 | amb | 1035 | function formSetHighway(type,value) // called from router.html (with one argument) |
360 | amb | 569 | { |
361 | amb | 985 | if(value == undefined) |
362 | routino.profile_highway[type][routino.transport]=document.forms["form"].elements["highway-" + type].value; | ||
363 | else | ||
364 | { | ||
365 | document.forms["form"].elements["highway-" + type].value=value; | ||
366 | routino.profile_highway[type][routino.transport]=value; | ||
367 | } | ||
368 | amb | 569 | |
369 | paramschanged=true; | ||
370 | } | ||
371 | |||
372 | |||
373 | // | ||
374 | // Change of Speed in the form | ||
375 | // | ||
376 | |||
377 | amb | 1035 | function formSetSpeed(type,value) // called from router.html (with one argument) |
378 | amb | 569 | { |
379 | amb | 985 | if(value == undefined) |
380 | routino.profile_speed[type][routino.transport]=document.forms["form"].elements["speed-" + type].value; | ||
381 | else | ||
382 | { | ||
383 | document.forms["form"].elements["speed-" + type].value=value; | ||
384 | routino.profile_speed[type][routino.transport]=value; | ||
385 | } | ||
386 | amb | 569 | |
387 | paramschanged=true; | ||
388 | } | ||
389 | |||
390 | |||
391 | // | ||
392 | amb | 574 | // Change of Property in the form |
393 | // | ||
394 | |||
395 | amb | 1035 | function formSetProperty(type,value) // called from router.html (with one argument) |
396 | amb | 574 | { |
397 | amb | 985 | if(value == undefined) |
398 | routino.profile_property[type][routino.transport]=document.forms["form"].elements["property-" + type].value; | ||
399 | else | ||
400 | { | ||
401 | document.forms["form"].elements["property-" + type].value=value; | ||
402 | routino.profile_property[type][routino.transport]=value; | ||
403 | } | ||
404 | amb | 574 | |
405 | paramschanged=true; | ||
406 | } | ||
407 | |||
408 | |||
409 | // | ||
410 | amb | 622 | // Change of Restriction rule in the form |
411 | amb | 569 | // |
412 | |||
413 | amb | 1035 | function formSetRestriction(type,value) // called from router.html (with one argument) |
414 | amb | 569 | { |
415 | amb | 985 | if(value == undefined) |
416 | { | ||
417 | if(type=="oneway" || type=="turns") | ||
418 | routino.profile_restrictions[type][routino.transport]=document.forms["form"].elements["restrict-" + type].checked; | ||
419 | else | ||
420 | routino.profile_restrictions[type][routino.transport]=document.forms["form"].elements["restrict-" + type].value; | ||
421 | } | ||
422 | amb | 569 | else |
423 | amb | 985 | { |
424 | if(type=="oneway" || type=="turns") | ||
425 | document.forms["form"].elements["restrict-" + type].checked=value; | ||
426 | else | ||
427 | document.forms["form"].elements["restrict-" + type].value=value; | ||
428 | amb | 569 | |
429 | amb | 985 | routino.profile_restrictions[type][routino.transport]=value; |
430 | } | ||
431 | |||
432 | amb | 569 | paramschanged=true; |
433 | } | ||
434 | |||
435 | |||
436 | // | ||
437 | amb | 577 | // Set the feature coordinates from the form when the form changes. |
438 | // | ||
439 | |||
440 | amb | 1035 | function formSetCoords(marker,lon,lat) // called from router.html (with one argument) |
441 | amb | 577 | { |
442 | amb | 1005 | clearSearchResult(marker); |
443 | |||
444 | amb | 1032 | if(lon == undefined && lat == undefined) |
445 | amb | 985 | { |
446 | amb | 1034 | lon=document.forms["form"].elements["lon" + marker].value; |
447 | lat=document.forms["form"].elements["lat" + marker].value; | ||
448 | amb | 985 | } |
449 | amb | 1034 | |
450 | if(lon == "" && lat == "") | ||
451 | amb | 985 | { |
452 | amb | 1034 | document.forms["form"].elements["lon" + marker].value=""; |
453 | document.forms["form"].elements["lat" + marker].value=""; | ||
454 | amb | 985 | |
455 | amb | 1034 | routino.point[marker].lon=""; |
456 | routino.point[marker].lat="" | ||
457 | amb | 985 | } |
458 | amb | 1034 | else |
459 | { | ||
460 | if(lon=="") | ||
461 | { | ||
462 | var lonlat=map.getCenter().clone(); | ||
463 | lonlat.transform(epsg900913,epsg4326); | ||
464 | amb | 985 | |
465 | amb | 1034 | lon=lonlat.lon; |
466 | } | ||
467 | amb | 577 | |
468 | amb | 1034 | if(lon<-180) lon=-180; |
469 | if(lon>+180) lon=+180; | ||
470 | amb | 577 | |
471 | amb | 1034 | if(lat=="") |
472 | { | ||
473 | var lonlat=map.getCenter().clone(); | ||
474 | lonlat.transform(epsg900913,epsg4326); | ||
475 | amb | 577 | |
476 | amb | 1034 | lat=lonlat.lat; |
477 | } | ||
478 | amb | 577 | |
479 | amb | 1034 | if(lat<-90 ) lat=-90 ; |
480 | if(lat>+90 ) lat=+90 ; | ||
481 | amb | 577 | |
482 | amb | 1034 | var lonlat = new OpenLayers.LonLat(lon,lat); |
483 | lonlat.transform(epsg4326,epsg900913); | ||
484 | |||
485 | markers[marker].move(lonlat); | ||
486 | |||
487 | markersmoved=true; | ||
488 | |||
489 | document.forms["form"].elements["lon" + marker].value=format5f(lon); | ||
490 | document.forms["form"].elements["lat" + marker].value=format5f(lat); | ||
491 | |||
492 | routino.point[marker].lon=lon; | ||
493 | routino.point[marker].lat=lat; | ||
494 | routino.point[marker].used=true; | ||
495 | amb | 1039 | |
496 | markerCheckHome(marker); | ||
497 | amb | 1034 | } |
498 | amb | 577 | } |
499 | |||
500 | |||
501 | // | ||
502 | amb | 1032 | // Set the search field from the form when the form changes. |
503 | amb | 1001 | // |
504 | |||
505 | amb | 1035 | function formSetSearch(marker,search) // called from event handler linked to router.html (with one argument) |
506 | amb | 1001 | { |
507 | amb | 1005 | clearSearchResult(marker); |
508 | |||
509 | amb | 1001 | if(search == undefined) |
510 | { | ||
511 | routino.point[marker].search=document.forms["form"].elements["search" + marker].value; | ||
512 | |||
513 | DoSearch(marker); | ||
514 | } | ||
515 | else | ||
516 | { | ||
517 | document.forms["form"].elements["search" + marker].value=search; | ||
518 | |||
519 | routino.point[marker].search=search; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | |||
524 | // | ||
525 | amb | 577 | // Format a number in printf("%.5f") format. |
526 | // | ||
527 | |||
528 | function format5f(number) | ||
529 | { | ||
530 | var newnumber=Math.floor(number*100000+0.5); | ||
531 | var delta=0; | ||
532 | |||
533 | if(newnumber>=0 && newnumber<100000) delta= 100000; | ||
534 | if(newnumber<0 && newnumber>-100000) delta=-100000; | ||
535 | |||
536 | var string=String(newnumber+delta); | ||
537 | |||
538 | var intpart =string.substring(0,string.length-5); | ||
539 | var fracpart=string.substring(string.length-5,string.length); | ||
540 | |||
541 | if(delta>0) intpart="0"; | ||
542 | if(delta<0) intpart="-0"; | ||
543 | |||
544 | return(intpart + "." + fracpart); | ||
545 | } | ||
546 | |||
547 | |||
548 | // | ||
549 | // Build a set of URL arguments | ||
550 | // | ||
551 | |||
552 | amb | 986 | function buildURLArguments(lang) |
553 | amb | 577 | { |
554 | amb | 986 | var url= "transport=" + routino.transport; |
555 | amb | 577 | |
556 | for(var marker=1;marker<=vismarkers;marker++) | ||
557 | amb | 986 | if(routino.point[marker].active) |
558 | amb | 577 | { |
559 | amb | 985 | url=url + ";lon" + marker + "=" + routino.point[marker].lon; |
560 | url=url + ";lat" + marker + "=" + routino.point[marker].lat; | ||
561 | amb | 1001 | if(routino.point[marker].search != "") |
562 | url=url + ";search" + marker + "=" + encodeURIComponent(routino.point[marker].search); | ||
563 | amb | 577 | } |
564 | |||
565 | for(var key in routino.profile_highway) | ||
566 | if(routino.profile_highway[key][routino.transport]!=routino_default.profile_highway[key][routino.transport]) | ||
567 | url=url + ";highway-" + key + "=" + routino.profile_highway[key][routino.transport]; | ||
568 | |||
569 | for(var key in routino.profile_speed) | ||
570 | if(routino.profile_speed[key][routino.transport]!=routino_default.profile_speed[key][routino.transport]) | ||
571 | url=url + ";speed-" + key + "=" + routino.profile_speed[key][routino.transport]; | ||
572 | |||
573 | for(var key in routino.profile_property) | ||
574 | if(routino.profile_property[key][routino.transport]!=routino_default.profile_property[key][routino.transport]) | ||
575 | url=url + ";property-" + key + "=" + routino.profile_property[key][routino.transport]; | ||
576 | |||
577 | for(var key in routino.restrictions) | ||
578 | if(routino.profile_restrictions[key][routino.transport]!=routino_default.profile_restrictions[key][routino.transport]) | ||
579 | url=url + ";" + key + "=" + routino.profile_restrictions[key][routino.transport]; | ||
580 | |||
581 | amb | 986 | if(lang && routino.language) |
582 | amb | 577 | url=url + ";language=" + routino.language; |
583 | |||
584 | return(url); | ||
585 | } | ||
586 | |||
587 | |||
588 | // | ||
589 | amb | 986 | // Build a set of URL arguments for the map location |
590 | amb | 569 | // |
591 | |||
592 | amb | 986 | function buildMapArguments() |
593 | amb | 569 | { |
594 | amb | 1009 | var lonlat = map.getCenter().clone(); |
595 | lonlat.transform(epsg900913,epsg4326); | ||
596 | amb | 569 | |
597 | amb | 986 | var zoom = map.getZoom() + map.minZoomLevel; |
598 | |||
599 | return "lat=" + format5f(lonlat.lat) + ";lon=" + format5f(lonlat.lon) + ";zoom=" + zoom; | ||
600 | amb | 569 | } |
601 | |||
602 | |||
603 | // | ||
604 | amb | 986 | // Update a URL |
605 | // | ||
606 | |||
607 | amb | 1035 | function updateURL(element) // called from router.html |
608 | amb | 986 | { |
609 | if(element.id == "permalink_url") | ||
610 | element.href=location.pathname + "?" + buildURLArguments(true) + ";" + buildMapArguments(); | ||
611 | |||
612 | if(element.id == "visualiser_url") | ||
613 | element.href="visualiser.html" + "?" + buildMapArguments(); | ||
614 | |||
615 | if(element.id == "edit_url") | ||
616 | element.href="http://www.openstreetmap.org/edit" + "?" + buildMapArguments(); | ||
617 | |||
618 | if(element.id.match(/^lang_([a-zA-Z-]+)_url$/)) | ||
619 | element.href="router.html" + "." + RegExp.$1 + "?" + buildURLArguments(false) + ";" + buildMapArguments(); | ||
620 | } | ||
621 | |||
622 | |||
623 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
624 | ///////////////////////////////// Map handling ///////////////////////////////// | ||
625 | //////////////////////////////////////////////////////////////////////////////// | ||
626 | amb | 569 | |
627 | var map; | ||
628 | amb | 933 | var layerMap=[], layerVectors, layerGPX; |
629 | amb | 569 | var epsg4326, epsg900913; |
630 | |||
631 | amb | 985 | // |
632 | amb | 569 | // Initialise the 'map' object |
633 | // | ||
634 | |||
635 | amb | 1035 | function map_init() // called from router.html |
636 | amb | 569 | { |
637 | amb | 985 | lon =args["lon"]; |
638 | lat =args["lat"]; | ||
639 | zoom=args["zoom"]; | ||
640 | |||
641 | amb | 1260 | // Map URLs and limits are in mapprops.js. |
642 | amb | 577 | |
643 | amb | 569 | // |
644 | // Create the map | ||
645 | // | ||
646 | |||
647 | epsg4326=new OpenLayers.Projection("EPSG:4326"); | ||
648 | epsg900913=new OpenLayers.Projection("EPSG:900913"); | ||
649 | |||
650 | map = new OpenLayers.Map ("map", | ||
651 | { | ||
652 | controls:[ | ||
653 | new OpenLayers.Control.Navigation(), | ||
654 | new OpenLayers.Control.PanZoomBar(), | ||
655 | new OpenLayers.Control.ScaleLine(), | ||
656 | new OpenLayers.Control.LayerSwitcher() | ||
657 | ], | ||
658 | |||
659 | projection: epsg900913, | ||
660 | displayProjection: epsg4326, | ||
661 | |||
662 | amb | 933 | minZoomLevel: mapprops.zoomout, |
663 | numZoomLevels: mapprops.zoomin-mapprops.zoomout+1, | ||
664 | amb | 1018 | maxResolution: 156543.03390625 / Math.pow(2,mapprops.zoomout), |
665 | amb | 569 | |
666 | amb | 1013 | // These two lines are not needed with OpenLayers 2.12 |
667 | units: "m", | ||
668 | amb | 577 | maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34), |
669 | amb | 569 | |
670 | amb | 1013 | restrictedExtent: new OpenLayers.Bounds(mapprops.westedge,mapprops.southedge,mapprops.eastedge,mapprops.northedge).transform(epsg4326,epsg900913) |
671 | amb | 569 | }); |
672 | |||
673 | amb | 933 | // Add map tile layers |
674 | amb | 569 | |
675 | amb | 933 | for(var l=0;l < mapprops.mapdata.length;l++) |
676 | { | ||
677 | layerMap[l] = new OpenLayers.Layer.TMS(mapprops.mapdata[l].label, | ||
678 | amb | 1239 | mapprops.mapdata[l].tileurl, |
679 | amb | 933 | { |
680 | getURL: limitedUrl, | ||
681 | displayOutsideMaxExtent: true, | ||
682 | buffer: 1 | ||
683 | }); | ||
684 | map.addLayer(layerMap[l]); | ||
685 | } | ||
686 | amb | 569 | |
687 | amb | 1239 | // Update the attribution if the layer changes |
688 | amb | 569 | |
689 | amb | 1239 | map.events.register("changelayer",layerMap,change_attribution_event); |
690 | |||
691 | function change_attribution_event(event) | ||
692 | amb | 569 | { |
693 | amb | 1239 | for(var l=0;l < mapprops.mapdata.length;l++) |
694 | if(this[l] == event.layer) | ||
695 | change_attribution(l); | ||
696 | } | ||
697 | amb | 569 | |
698 | amb | 1239 | function change_attribution(l) |
699 | { | ||
700 | var data_url =mapprops.mapdata[l].attribution.data_url; | ||
701 | var data_text=mapprops.mapdata[l].attribution.data_text; | ||
702 | var tile_url =mapprops.mapdata[l].attribution.tile_url; | ||
703 | var tile_text=mapprops.mapdata[l].attribution.tile_text; | ||
704 | amb | 569 | |
705 | amb | 1239 | document.getElementById("attribution_data").innerHTML="<a href=\"" + data_url + "\" target=\"data_attribution\">" + data_text + "</a>"; |
706 | document.getElementById("attribution_tile").innerHTML="<a href=\"" + tile_url + "\" target=\"tile_attribution\">" + tile_text + "</a>"; | ||
707 | } | ||
708 | |||
709 | change_attribution(0); | ||
710 | |||
711 | // Get a URL for the tile (mostly copied from OpenLayers/Layer/XYZ.js). | ||
712 | |||
713 | function limitedUrl(bounds) | ||
714 | { | ||
715 | amb | 569 | var res = map.getResolution(); |
716 | amb | 1239 | |
717 | var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w)); | ||
718 | amb | 569 | var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); |
719 | amb | 1239 | var z = map.getZoom() + map.minZoomLevel; |
720 | |||
721 | amb | 569 | var limit = Math.pow(2, z); |
722 | amb | 1239 | x = ((x % limit) + limit) % limit; |
723 | amb | 569 | |
724 | amb | 1239 | var xyz = {'x': x, 'y': y, 'z': z}; |
725 | var url = this.url; | ||
726 | amb | 569 | |
727 | amb | 1239 | if (OpenLayers.Util.isArray(url)) |
728 | { | ||
729 | var s = '' + xyz.x + xyz.y + xyz.z; | ||
730 | url = this.selectUrl(s, url); | ||
731 | } | ||
732 | |||
733 | return OpenLayers.String.format(url, xyz); | ||
734 | amb | 569 | } |
735 | |||
736 | // Define a GPX layer but don't add it yet | ||
737 | |||
738 | layerGPX={shortest: null, quickest: null}; | ||
739 | |||
740 | gpx_style={shortest: new OpenLayers.Style({},{strokeWidth: 3, strokeColor: "#00FF00"}), | ||
741 | quickest: new OpenLayers.Style({},{strokeWidth: 3, strokeColor: "#0000FF"})}; | ||
742 | amb | 985 | |
743 | amb | 569 | // Add a vectors layer |
744 | amb | 985 | |
745 | amb | 1328 | layerVectors = new OpenLayers.Layer.Vector("Markers",{displayInLayerSwitcher: false}); |
746 | amb | 569 | map.addLayer(layerVectors); |
747 | |||
748 | // A set of markers | ||
749 | |||
750 | amb | 574 | markers={}; |
751 | amb | 569 | markersmoved=false; |
752 | paramschanged=false; | ||
753 | |||
754 | amb | 1012 | for(var marker=1;marker<=mapprops.maxmarkers;marker++) |
755 | amb | 569 | { |
756 | amb | 987 | markers[marker] = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0),{}, |
757 | new OpenLayers.Style({},{externalGraphic: 'icons/marker-' + marker + '-red.png', | ||
758 | fillColor: "white", | ||
759 | graphicYOffset: -25, | ||
760 | graphicWidth: 21, | ||
761 | graphicHeight: 25, | ||
762 | display: "none"})); | ||
763 | amb | 569 | |
764 | amb | 987 | layerVectors.addFeatures([markers[marker]]); |
765 | amb | 569 | } |
766 | |||
767 | // A function to drag the markers | ||
768 | |||
769 | var drag = new OpenLayers.Control.DragFeature(layerVectors, | ||
770 | {onDrag: dragMove, | ||
771 | onComplete: dragComplete }); | ||
772 | map.addControl(drag); | ||
773 | drag.activate(); | ||
774 | |||
775 | // Markers to highlight a selected point | ||
776 | |||
777 | amb | 577 | for(var highlight in highlights) |
778 | amb | 569 | { |
779 | highlights[highlight] = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,0),{}, | ||
780 | amb | 577 | new OpenLayers.Style({},{strokeColor: route_dark_colours[highlight], |
781 | amb | 574 | fillColor: "white", |
782 | amb | 569 | pointRadius: 10, |
783 | strokeWidth: 4, | ||
784 | fillOpacity: 0, | ||
785 | display: "none"})); | ||
786 | |||
787 | layerVectors.addFeatures([highlights[highlight]]); | ||
788 | } | ||
789 | |||
790 | amb | 574 | // A popup for routing results |
791 | |||
792 | amb | 577 | for(var popup in popups) |
793 | popups[popup] = createPopup(popup); | ||
794 | amb | 574 | |
795 | amb | 572 | // Set the map centre to the limited range specified |
796 | |||
797 | amb | 577 | map.setCenter(map.restrictedExtent.getCenterLonLat(), map.getZoomForExtent(map.restrictedExtent,true)); |
798 | amb | 572 | map.maxResolution = map.getResolution(); |
799 | |||
800 | amb | 569 | // Move the map |
801 | |||
802 | amb | 985 | if(lon != undefined && lat != undefined && zoom != undefined) |
803 | amb | 569 | { |
804 | amb | 933 | if(lon<mapprops.westedge) lon=mapprops.westedge; |
805 | if(lon>mapprops.eastedge) lon=mapprops.eastedge; | ||
806 | |||
807 | if(lat<mapprops.southedge) lat=mapprops.southedge; | ||
808 | if(lat>mapprops.northedge) lat=mapprops.northedge; | ||
809 | |||
810 | if(zoom<mapprops.zoomout) zoom=mapprops.zoomout; | ||
811 | if(zoom>mapprops.zoomin) zoom=mapprops.zoomin; | ||
812 | |||
813 | amb | 1009 | var lonlat = new OpenLayers.LonLat(lon,lat); |
814 | lonlat.transform(epsg4326,epsg900913); | ||
815 | amb | 569 | |
816 | map.moveTo(lonlat,zoom-map.minZoomLevel); | ||
817 | } | ||
818 | } | ||
819 | |||
820 | |||
821 | // | ||
822 | // OpenLayers.Control.DragFeature callback for a drag occuring. | ||
823 | // | ||
824 | |||
825 | function dragMove(feature,pixel) | ||
826 | { | ||
827 | amb | 574 | for(var marker in markers) |
828 | amb | 569 | if(feature==markers[marker]) |
829 | amb | 985 | dragSetForm(marker); |
830 | amb | 569 | } |
831 | |||
832 | |||
833 | // | ||
834 | // OpenLayers.Control.DragFeature callback for completing a drag. | ||
835 | // | ||
836 | |||
837 | function dragComplete(feature,pixel) | ||
838 | { | ||
839 | amb | 574 | for(var marker in markers) |
840 | amb | 569 | if(feature==markers[marker]) |
841 | amb | 985 | dragSetForm(marker); |
842 | amb | 569 | } |
843 | |||
844 | |||
845 | amb | 985 | // |
846 | // Set the feature coordinates in the form after dragging. | ||
847 | // | ||
848 | |||
849 | function dragSetForm(marker) | ||
850 | { | ||
851 | var lonlat = new OpenLayers.LonLat(markers[marker].geometry.x, markers[marker].geometry.y); | ||
852 | amb | 1009 | lonlat.transform(epsg900913,epsg4326); |
853 | amb | 985 | |
854 | var lon=format5f(lonlat.lon); | ||
855 | var lat=format5f(lonlat.lat); | ||
856 | |||
857 | formSetCoords(marker,lon,lat); | ||
858 | } | ||
859 | |||
860 | |||
861 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
862 | /////////////////////////////// Marker handling //////////////////////////////// | ||
863 | //////////////////////////////////////////////////////////////////////////////// | ||
864 | |||
865 | |||
866 | amb | 569 | // |
867 | amb | 574 | // Toggle a marker on the map. |
868 | amb | 569 | // |
869 | |||
870 | amb | 1035 | function markerToggleMap(marker) // called from router.html |
871 | amb | 569 | { |
872 | amb | 1034 | if(!routino.point[marker].used) |
873 | { | ||
874 | routino.point[marker].used=true; | ||
875 | markerCentre(marker); | ||
876 | markerCoords(marker); | ||
877 | } | ||
878 | amb | 1005 | |
879 | amb | 1032 | markerAddRemoveMap(marker,!routino.point[marker].active); |
880 | } | ||
881 | |||
882 | |||
883 | // | ||
884 | // Show or hide a marker on the map. | ||
885 | // | ||
886 | |||
887 | function markerAddRemoveMap(marker,active) | ||
888 | { | ||
889 | if(active) | ||
890 | markerAddMap(marker); | ||
891 | else | ||
892 | amb | 574 | markerRemoveMap(marker); |
893 | } | ||
894 | |||
895 | |||
896 | // | ||
897 | // Show a marker on the map. | ||
898 | // | ||
899 | |||
900 | function markerAddMap(marker) | ||
901 | { | ||
902 | amb | 1005 | clearSearchResult(marker); |
903 | |||
904 | amb | 577 | markers[marker].style.display = ""; |
905 | amb | 985 | routino.point[marker].active=true; |
906 | amb | 1034 | routino.point[marker].used=true; |
907 | amb | 574 | |
908 | amb | 577 | updateIcon(marker); |
909 | amb | 574 | |
910 | markersmoved=true; | ||
911 | } | ||
912 | |||
913 | |||
914 | // | ||
915 | // Remove a marker from the map. | ||
916 | // | ||
917 | |||
918 | function markerRemoveMap(marker) | ||
919 | { | ||
920 | amb | 1005 | clearSearchResult(marker); |
921 | |||
922 | amb | 577 | markers[marker].style.display = "none"; |
923 | amb | 985 | routino.point[marker].active=false; |
924 | amb | 574 | |
925 | amb | 577 | updateIcon(marker); |
926 | amb | 574 | |
927 | amb | 577 | markersmoved=true; |
928 | } | ||
929 | amb | 574 | |
930 | amb | 577 | |
931 | // | ||
932 | amb | 1001 | // Display search string for the marker |
933 | // | ||
934 | |||
935 | amb | 1035 | function markerSearch(marker) // called from router.html |
936 | amb | 1001 | { |
937 | amb | 1005 | clearSearchResult(marker); |
938 | |||
939 | amb | 1011 | document.getElementById("coords" + marker).style.display="none"; |
940 | document.getElementById("search" + marker).style.display=""; | ||
941 | amb | 1001 | } |
942 | |||
943 | |||
944 | // | ||
945 | // Display coordinates for the marker | ||
946 | // | ||
947 | |||
948 | amb | 1035 | function markerCoords(marker) // called from router.html |
949 | amb | 1001 | { |
950 | amb | 1005 | clearSearchResult(marker); |
951 | |||
952 | amb | 1011 | document.getElementById("search" + marker).style.display="none"; |
953 | document.getElementById("coords" + marker).style.display=""; | ||
954 | amb | 1001 | } |
955 | |||
956 | |||
957 | // | ||
958 | amb | 577 | // Centre the marker on the map |
959 | // | ||
960 | |||
961 | amb | 1035 | function markerCentre(marker) // called from router.html |
962 | amb | 577 | { |
963 | amb | 1034 | if(!routino.point[marker].used) |
964 | return; | ||
965 | |||
966 | amb | 1005 | clearSearchResult(marker); |
967 | |||
968 | amb | 985 | var lonlat=map.getCenter().clone(); |
969 | amb | 1009 | lonlat.transform(epsg900913,epsg4326); |
970 | amb | 577 | |
971 | amb | 1032 | formSetCoords(marker,lonlat.lon,lonlat.lat); |
972 | amb | 574 | } |
973 | |||
974 | |||
975 | // | ||
976 | amb | 984 | // Centre the map on the marker |
977 | // | ||
978 | |||
979 | amb | 1035 | function markerRecentre(marker) // called from router.html |
980 | amb | 984 | { |
981 | amb | 1034 | if(!routino.point[marker].used) |
982 | return; | ||
983 | |||
984 | amb | 1005 | clearSearchResult(marker); |
985 | |||
986 | amb | 985 | lon=routino.point[marker].lon; |
987 | lat=routino.point[marker].lat; | ||
988 | amb | 984 | |
989 | amb | 1009 | var lonlat = new OpenLayers.LonLat(lon,lat); |
990 | lonlat.transform(epsg4326,epsg900913); | ||
991 | amb | 984 | |
992 | map.panTo(lonlat); | ||
993 | } | ||
994 | |||
995 | |||
996 | // | ||
997 | amb | 574 | // Clear the current marker. |
998 | // | ||
999 | |||
1000 | amb | 1035 | function markerRemove(marker) // called from router.html |
1001 | amb | 574 | { |
1002 | amb | 1005 | clearSearchResult(marker); |
1003 | |||
1004 | amb | 1033 | for(var m=marker;m<vismarkers;m++) |
1005 | amb | 1039 | markerCopy(m,m+1); |
1006 | amb | 574 | |
1007 | amb | 1033 | markerRemoveForm(vismarkers--); |
1008 | amb | 574 | |
1009 | if(vismarkers==1) | ||
1010 | markerAddAfter(1); | ||
1011 | } | ||
1012 | |||
1013 | |||
1014 | // | ||
1015 | // Add a marker before the current one. | ||
1016 | // | ||
1017 | |||
1018 | function markerAddBefore(marker) | ||
1019 | { | ||
1020 | amb | 1005 | clearSearchResult(marker); |
1021 | |||
1022 | amb | 1012 | if(vismarkers==mapprops.maxmarkers || marker==1) |
1023 | amb | 574 | return false; |
1024 | |||
1025 | amb | 1033 | markerAddForm(++vismarkers); |
1026 | amb | 574 | |
1027 | amb | 1033 | for(var m=vismarkers;m>marker;m--) |
1028 | amb | 1039 | markerCopy(m,m-1); |
1029 | amb | 574 | |
1030 | amb | 1033 | markerClearForm(marker-1); |
1031 | amb | 574 | } |
1032 | |||
1033 | |||
1034 | // | ||
1035 | // Add a marker after the current one. | ||
1036 | // | ||
1037 | |||
1038 | amb | 1035 | function markerAddAfter(marker) // called from router.html |
1039 | amb | 574 | { |
1040 | amb | 1005 | clearSearchResult(marker); |
1041 | |||
1042 | amb | 1012 | if(vismarkers==mapprops.maxmarkers) |
1043 | amb | 574 | return false; |
1044 | |||
1045 | amb | 1033 | markerAddForm(++vismarkers); |
1046 | amb | 574 | |
1047 | amb | 1033 | for(var m=vismarkers;m>(marker+1);m--) |
1048 | amb | 1039 | markerCopy(m,m-1); |
1049 | amb | 574 | |
1050 | amb | 1033 | markerClearForm(marker+1); |
1051 | amb | 569 | } |
1052 | |||
1053 | |||
1054 | // | ||
1055 | amb | 577 | // Set this marker as the home location. |
1056 | // | ||
1057 | |||
1058 | amb | 1035 | function markerHome(marker) // called from router.html |
1059 | amb | 577 | { |
1060 | amb | 1034 | if(!routino.point[marker].used) |
1061 | amb | 1036 | { |
1062 | markerMoveHome(marker); | ||
1063 | } | ||
1064 | amb | 1039 | else |
1065 | { | ||
1066 | clearSearchResult(marker); | ||
1067 | amb | 1034 | |
1068 | amb | 1039 | markerSetClearHome(marker,!routino.point[marker].home); |
1069 | } | ||
1070 | amb | 577 | } |
1071 | |||
1072 | |||
1073 | // | ||
1074 | amb | 984 | // Set this marker as the current location. |
1075 | // | ||
1076 | |||
1077 | amb | 1035 | function markerLocate(marker) // called from router.html |
1078 | amb | 984 | { |
1079 | amb | 1005 | clearSearchResult(marker); |
1080 | |||
1081 | amb | 984 | if(navigator.geolocation) |
1082 | navigator.geolocation.getCurrentPosition( | ||
1083 | function(position) { | ||
1084 | amb | 1032 | formSetCoords(marker,position.coords.longitude,position.coords.latitude); |
1085 | markerAddMap(marker); | ||
1086 | amb | 984 | }); |
1087 | } | ||
1088 | |||
1089 | |||
1090 | // | ||
1091 | amb | 577 | // Update an icon to set colours and home or normal marker. |
1092 | // | ||
1093 | |||
1094 | function updateIcon(marker) | ||
1095 | { | ||
1096 | amb | 1036 | if(routino.point[marker].home) |
1097 | amb | 577 | { |
1098 | amb | 985 | if(routino.point[marker].active) |
1099 | amb | 577 | document.images["waypoint" + marker].src="icons/marker-home-red.png"; |
1100 | else | ||
1101 | document.images["waypoint" + marker].src="icons/marker-home-grey.png"; | ||
1102 | |||
1103 | markers[marker].style.externalGraphic="icons/marker-home-red.png"; | ||
1104 | } | ||
1105 | else | ||
1106 | { | ||
1107 | amb | 985 | if(routino.point[marker].active) |
1108 | amb | 577 | document.images["waypoint" + marker].src="icons/marker-" + marker + "-red.png"; |
1109 | else | ||
1110 | document.images["waypoint" + marker].src="icons/marker-" + marker + "-grey.png"; | ||
1111 | |||
1112 | markers[marker].style.externalGraphic="icons/marker-" + marker + "-red.png"; | ||
1113 | } | ||
1114 | |||
1115 | layerVectors.drawFeature(markers[marker]); | ||
1116 | } | ||
1117 | |||
1118 | |||
1119 | // | ||
1120 | amb | 1036 | // Move the marker to the home location |
1121 | amb | 577 | // |
1122 | |||
1123 | amb | 1036 | function markerMoveHome(marker) |
1124 | amb | 577 | { |
1125 | amb | 1036 | if(homelon==null || homelat==null) |
1126 | return; | ||
1127 | amb | 577 | |
1128 | amb | 1036 | routino.point[marker].home=true; |
1129 | routino.point[marker].used=true; | ||
1130 | amb | 577 | |
1131 | amb | 1036 | formSetCoords(marker,homelon,homelat); |
1132 | markerAddMap(marker); | ||
1133 | } | ||
1134 | |||
1135 | |||
1136 | // | ||
1137 | // Set or clear the home marker icon | ||
1138 | // | ||
1139 | |||
1140 | function markerSetClearHome(marker,home) | ||
1141 | { | ||
1142 | amb | 577 | var cookie; |
1143 | var date = new Date(); | ||
1144 | |||
1145 | amb | 1036 | if(home) |
1146 | amb | 577 | { |
1147 | amb | 1036 | homelat=routino.point[marker].lat; |
1148 | homelon=routino.point[marker].lon; | ||
1149 | amb | 577 | |
1150 | amb | 1036 | cookie="Routino-home=lon:" + homelon + ":lat:" + homelat; |
1151 | |||
1152 | amb | 577 | date.setUTCFullYear(date.getUTCFullYear()+5); |
1153 | |||
1154 | amb | 1036 | routino.point[marker].home=true; |
1155 | amb | 577 | } |
1156 | else | ||
1157 | { | ||
1158 | amb | 1036 | homelat=null; |
1159 | homelon=null; | ||
1160 | |||
1161 | amb | 577 | cookie="Routino-home=unset"; |
1162 | |||
1163 | date.setUTCFullYear(date.getUTCFullYear()-1); | ||
1164 | |||
1165 | amb | 1036 | routino.point[marker].home=false; |
1166 | amb | 577 | } |
1167 | |||
1168 | document.cookie=cookie + ";expires=" + date.toGMTString(); | ||
1169 | |||
1170 | amb | 1039 | updateIcon(marker); |
1171 | |||
1172 | amb | 1036 | for(m=1;m<=mapprops.maxmarkers;m++) |
1173 | amb | 1039 | markerCheckHome(m); |
1174 | } | ||
1175 | amb | 1036 | |
1176 | amb | 1039 | |
1177 | // | ||
1178 | // Check if a marker is the home marker | ||
1179 | // | ||
1180 | |||
1181 | function markerCheckHome(marker) | ||
1182 | { | ||
1183 | var home=routino.point[marker].home; | ||
1184 | |||
1185 | if(routino.point[marker].lon==homelon && routino.point[marker].lat==homelat) | ||
1186 | routino.point[marker].home=true; | ||
1187 | else | ||
1188 | routino.point[marker].home=false; | ||
1189 | |||
1190 | if(home!=routino.point[marker].home) | ||
1191 | updateIcon(marker); | ||
1192 | amb | 577 | } |
1193 | |||
1194 | |||
1195 | // | ||
1196 | amb | 574 | // Move this marker up. |
1197 | // | ||
1198 | |||
1199 | amb | 1035 | function markerMoveUp(marker) // called from router.html |
1200 | amb | 574 | { |
1201 | if(marker==1) | ||
1202 | amb | 984 | { |
1203 | for(var m=1;m<vismarkers;m++) | ||
1204 | markerSwap(m,m+1); | ||
1205 | } | ||
1206 | else | ||
1207 | markerSwap(marker,marker-1); | ||
1208 | amb | 574 | } |
1209 | |||
1210 | |||
1211 | // | ||
1212 | // Move this marker down. | ||
1213 | // | ||
1214 | |||
1215 | amb | 1035 | function markerMoveDown(marker) // called from router.html |
1216 | amb | 574 | { |
1217 | if(marker==vismarkers) | ||
1218 | amb | 984 | { |
1219 | for(var m=vismarkers;m>1;m--) | ||
1220 | markerSwap(m,m-1); | ||
1221 | } | ||
1222 | else | ||
1223 | markerSwap(marker,marker+1); | ||
1224 | amb | 574 | } |
1225 | |||
1226 | |||
1227 | // | ||
1228 | amb | 1039 | // Copy a marker from one place to another. |
1229 | amb | 1033 | // |
1230 | |||
1231 | amb | 1039 | function markerCopy(marker1,marker2) |
1232 | amb | 1033 | { |
1233 | for(var element in routino.point[marker2]) | ||
1234 | routino.point[marker1][element]=routino.point[marker2][element]; | ||
1235 | |||
1236 | document.getElementById("search" + marker1).style.display=document.getElementById("search" + marker2).style.display; | ||
1237 | |||
1238 | document.getElementById("coords" + marker1).style.display=document.getElementById("coords" + marker2).style.display; | ||
1239 | |||
1240 | document.forms["form"].elements["search" + marker1].value=document.forms["form"].elements["search" + marker2].value; | ||
1241 | |||
1242 | formSetCoords(marker1,routino.point[marker1].lon,routino.point[marker1].lat); | ||
1243 | |||
1244 | markerAddRemoveMap(marker1,routino.point[marker1].active); | ||
1245 | } | ||
1246 | |||
1247 | |||
1248 | // | ||
1249 | amb | 574 | // Swap a pair of markers. |
1250 | // | ||
1251 | |||
1252 | function markerSwap(marker1,marker2) | ||
1253 | { | ||
1254 | amb | 1033 | for(var element in routino.point[marker2]) |
1255 | { | ||
1256 | var temp=routino.point[marker1][element]; | ||
1257 | routino.point[marker1][element]=routino.point[marker2][element]; | ||
1258 | routino.point[marker2][element]=temp; | ||
1259 | } | ||
1260 | amb | 574 | |
1261 | amb | 1033 | var search_display=document.getElementById("search" + marker1).style.display; |
1262 | document.getElementById("search" + marker1).style.display=document.getElementById("search" + marker2).style.display; | ||
1263 | document.getElementById("search" + marker2).style.display=search_display; | ||
1264 | amb | 574 | |
1265 | amb | 1033 | var coords_display=document.getElementById("coords" + marker1).style.display; |
1266 | document.getElementById("coords" + marker1).style.display=document.getElementById("coords" + marker2).style.display; | ||
1267 | document.getElementById("coords" + marker2).style.display=coords_display; | ||
1268 | |||
1269 | var search_value=document.forms["form"].elements["search" + marker1].value; | ||
1270 | document.forms["form"].elements["search" + marker1].value=document.forms["form"].elements["search" + marker2].value; | ||
1271 | document.forms["form"].elements["search" + marker2].value=search_value; | ||
1272 | |||
1273 | formSetCoords(marker1,routino.point[marker1].lon,routino.point[marker1].lat); | ||
1274 | formSetCoords(marker2,routino.point[marker2].lon,routino.point[marker2].lat); | ||
1275 | |||
1276 | markerAddRemoveMap(marker1,routino.point[marker1].active); | ||
1277 | markerAddRemoveMap(marker2,routino.point[marker2].active); | ||
1278 | amb | 574 | } |
1279 | |||
1280 | |||
1281 | // | ||
1282 | // Reverse the markers. | ||
1283 | // | ||
1284 | |||
1285 | amb | 1035 | function markersReverse() // called from router.html |
1286 | amb | 574 | { |
1287 | for(var marker=1;marker<=vismarkers/2;marker++) | ||
1288 | markerSwap(marker,vismarkers+1-marker); | ||
1289 | } | ||
1290 | |||
1291 | |||
1292 | amb | 1033 | // |
1293 | amb | 1038 | // Close the loop. |
1294 | // | ||
1295 | |||
1296 | function markersLoop() // called from router.html | ||
1297 | { | ||
1298 | if(vismarkers==mapprops.maxmarkers) | ||
1299 | return false; | ||
1300 | |||
1301 | if(routino.point[vismarkers].lon==routino.point[1].lon && routino.point[vismarkers].lat==routino.point[1].lat) | ||
1302 | return false; | ||
1303 | |||
1304 | if(routino.point[vismarkers].used) | ||
1305 | markerAddForm(++vismarkers); | ||
1306 | |||
1307 | amb | 1039 | markerCopy(vismarkers,1); |
1308 | amb | 1038 | } |
1309 | |||
1310 | |||
1311 | // | ||
1312 | amb | 1033 | // Display the form for a marker |
1313 | // | ||
1314 | |||
1315 | function markerAddForm(marker) | ||
1316 | { | ||
1317 | document.getElementById("waypoint" + marker).style.display=""; | ||
1318 | } | ||
1319 | |||
1320 | |||
1321 | // | ||
1322 | // Hide the form for a marker | ||
1323 | // | ||
1324 | |||
1325 | function markerRemoveForm(marker) | ||
1326 | { | ||
1327 | document.getElementById("waypoint" + marker).style.display="none"; | ||
1328 | |||
1329 | markerClearForm(marker); | ||
1330 | } | ||
1331 | |||
1332 | |||
1333 | // | ||
1334 | // Clear the form for a marker | ||
1335 | // | ||
1336 | |||
1337 | function markerClearForm(marker) | ||
1338 | { | ||
1339 | markerRemoveMap(marker); | ||
1340 | markerCoords(marker); | ||
1341 | |||
1342 | formSetCoords(marker,"",""); | ||
1343 | formSetSearch(marker,""); | ||
1344 | |||
1345 | updateIcon(marker); | ||
1346 | |||
1347 | routino.point[marker].used=false; | ||
1348 | amb | 1036 | routino.point[marker].home=false; |
1349 | amb | 1033 | } |
1350 | |||
1351 | |||
1352 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
1353 | //////////////////////////// Route results handling //////////////////////////// | ||
1354 | //////////////////////////////////////////////////////////////////////////////// | ||
1355 | |||
1356 | var route_light_colours={shortest: "#60C060", quickest: "#6060C0"}; | ||
1357 | var route_dark_colours ={shortest: "#408040", quickest: "#404080"}; | ||
1358 | |||
1359 | var highlights={shortest: null, quickest: null}; | ||
1360 | var popups={shortest: null, quickest: null}; | ||
1361 | var routepoints={shortest: {}, quickest: {}}; | ||
1362 | var gpx_style={shortest: null, quickest: null}; | ||
1363 | |||
1364 | amb | 574 | // |
1365 | amb | 577 | // Zoom to a specific item in the route |
1366 | amb | 569 | // |
1367 | |||
1368 | amb | 577 | function zoomTo(type,line) |
1369 | amb | 569 | { |
1370 | amb | 1009 | var lonlat = new OpenLayers.LonLat(routepoints[type][line].lon,routepoints[type][line].lat); |
1371 | lonlat.transform(epsg4326,epsg900913); | ||
1372 | amb | 569 | |
1373 | amb | 577 | map.moveTo(lonlat,map.numZoomLevels-2); |
1374 | amb | 569 | } |
1375 | |||
1376 | |||
1377 | // | ||
1378 | amb | 577 | // Highlight a specific item in the route |
1379 | amb | 569 | // |
1380 | |||
1381 | amb | 577 | function highlight(type,line) |
1382 | amb | 569 | { |
1383 | amb | 577 | if(line==-1) |
1384 | { | ||
1385 | highlights[type].style.display = "none"; | ||
1386 | amb | 569 | |
1387 | amb | 577 | drawPopup(popups[type],null); |
1388 | amb | 569 | } |
1389 | amb | 577 | else |
1390 | amb | 569 | { |
1391 | amb | 577 | // Marker |
1392 | amb | 569 | |
1393 | amb | 1009 | var lonlat = new OpenLayers.LonLat(routepoints[type][line].lon,routepoints[type][line].lat); |
1394 | lonlat.transform(epsg4326,epsg900913); | ||
1395 | amb | 569 | |
1396 | amb | 577 | highlights[type].move(lonlat); |
1397 | amb | 569 | |
1398 | amb | 577 | if(highlights[type].style.display = "none") |
1399 | highlights[type].style.display = ""; | ||
1400 | amb | 569 | |
1401 | amb | 577 | // Popup |
1402 | amb | 569 | |
1403 | amb | 577 | drawPopup(popups[type],"<table>" + routepoints[type][line].html + "</table>"); |
1404 | } | ||
1405 | |||
1406 | layerVectors.drawFeature(highlights[type]); | ||
1407 | amb | 569 | } |
1408 | |||
1409 | |||
1410 | // | ||
1411 | amb | 577 | // Create a popup - not using OpenLayers because want it fixed on screen not fixed on map. |
1412 | amb | 569 | // |
1413 | |||
1414 | amb | 577 | function createPopup(type) |
1415 | amb | 569 | { |
1416 | amb | 577 | var popup=document.createElement('div'); |
1417 | amb | 569 | |
1418 | amb | 577 | popup.className = "popup"; |
1419 | amb | 569 | |
1420 | amb | 577 | popup.innerHTML = "<span></span>"; |
1421 | amb | 569 | |
1422 | amb | 577 | popup.style.display = "none"; |
1423 | amb | 569 | |
1424 | amb | 577 | popup.style.position = "fixed"; |
1425 | popup.style.top = "-4000px"; | ||
1426 | popup.style.left = "-4000px"; | ||
1427 | popup.style.zIndex = "100"; | ||
1428 | amb | 569 | |
1429 | amb | 577 | popup.style.padding = "5px"; |
1430 | amb | 569 | |
1431 | amb | 577 | popup.style.opacity=0.85; |
1432 | popup.style.backgroundColor=route_light_colours[type]; | ||
1433 | popup.style.border="4px solid " + route_dark_colours[type]; | ||
1434 | amb | 569 | |
1435 | amb | 577 | document.body.appendChild(popup); |
1436 | amb | 569 | |
1437 | amb | 577 | return(popup); |
1438 | amb | 569 | } |
1439 | |||
1440 | |||
1441 | // | ||
1442 | amb | 577 | // Draw a popup - not using OpenLayers because want it fixed on screen not fixed on map. |
1443 | amb | 569 | // |
1444 | |||
1445 | amb | 577 | function drawPopup(popup,html) |
1446 | amb | 569 | { |
1447 | amb | 577 | if(html==null) |
1448 | amb | 569 | { |
1449 | amb | 577 | popup.style.display="none"; |
1450 | return; | ||
1451 | } | ||
1452 | amb | 574 | |
1453 | amb | 577 | if(popup.style.display=="none") |
1454 | amb | 569 | { |
1455 | amb | 577 | var map_div=document.getElementById("map"); |
1456 | amb | 569 | |
1457 | amb | 577 | popup.style.left =map_div.offsetParent.offsetLeft+map_div.offsetLeft+60 + "px"; |
1458 | popup.style.top = map_div.offsetTop +30 + "px"; | ||
1459 | popup.style.width =map_div.clientWidth-100 + "px"; | ||
1460 | amb | 574 | |
1461 | amb | 577 | popup.style.display=""; |
1462 | amb | 569 | } |
1463 | |||
1464 | amb | 577 | popup.innerHTML=html; |
1465 | amb | 569 | } |
1466 | |||
1467 | |||
1468 | // | ||
1469 | amb | 577 | // Remove a GPX trace |
1470 | amb | 569 | // |
1471 | |||
1472 | amb | 577 | function removeGPXTrace(type) |
1473 | amb | 569 | { |
1474 | amb | 577 | map.removeLayer(layerGPX[type]); |
1475 | layerGPX[type].destroy(); | ||
1476 | layerGPX[type]=null; | ||
1477 | amb | 569 | |
1478 | amb | 577 | displayStatus(type,"no_info"); |
1479 | amb | 569 | |
1480 | amb | 1011 | document.getElementById(type + "_links").style.display = "none"; |
1481 | amb | 569 | |
1482 | amb | 1011 | document.getElementById(type + "_route").innerHTML = ""; |
1483 | amb | 569 | |
1484 | amb | 577 | hideshow_hide(type); |
1485 | } | ||
1486 | amb | 569 | |
1487 | amb | 574 | |
1488 | amb | 577 | //////////////////////////////////////////////////////////////////////////////// |
1489 | /////////////////////////////// Server handling //////////////////////////////// | ||
1490 | //////////////////////////////////////////////////////////////////////////////// | ||
1491 | amb | 569 | |
1492 | // | ||
1493 | // Display data statistics | ||
1494 | // | ||
1495 | |||
1496 | amb | 1035 | function displayStatistics() // called from router.html |
1497 | amb | 569 | { |
1498 | // Use AJAX to get the statistics | ||
1499 | |||
1500 | amb | 1013 | OpenLayers.Request.GET({url: "statistics.cgi", success: runStatisticsSuccess}); |
1501 | amb | 569 | } |
1502 | |||
1503 | |||
1504 | // | ||
1505 | amb | 577 | // Success in running data statistics generation. |
1506 | amb | 569 | // |
1507 | |||
1508 | function runStatisticsSuccess(response) | ||
1509 | { | ||
1510 | amb | 1011 | document.getElementById("statistics_data").innerHTML="<pre>" + response.responseText + "</pre>"; |
1511 | document.getElementById("statistics_link").style.display="none"; | ||
1512 | amb | 569 | } |
1513 | |||
1514 | |||
1515 | // | ||
1516 | amb | 577 | // Submit form - perform the routing |
1517 | amb | 569 | // |
1518 | |||
1519 | amb | 1035 | function findRoute(type) // called from router.html |
1520 | amb | 569 | { |
1521 | tab_select("results"); | ||
1522 | |||
1523 | amb | 572 | hideshow_hide('help_options'); |
1524 | amb | 569 | hideshow_hide('shortest'); |
1525 | hideshow_hide('quickest'); | ||
1526 | |||
1527 | amb | 577 | displayStatus("result","running"); |
1528 | amb | 569 | |
1529 | amb | 986 | var url="router.cgi" + "?" + buildURLArguments(true) + ";type=" + type; |
1530 | amb | 569 | |
1531 | // Destroy the existing layer(s) | ||
1532 | |||
1533 | if(markersmoved || paramschanged) | ||
1534 | { | ||
1535 | if(layerGPX.shortest!=null) | ||
1536 | removeGPXTrace("shortest"); | ||
1537 | if(layerGPX.quickest!=null) | ||
1538 | removeGPXTrace("quickest"); | ||
1539 | markersmoved=false; | ||
1540 | paramschanged=false; | ||
1541 | } | ||
1542 | else if(layerGPX[type]!=null) | ||
1543 | removeGPXTrace(type); | ||
1544 | |||
1545 | // Use AJAX to run the router | ||
1546 | |||
1547 | routing_type=type; | ||
1548 | |||
1549 | amb | 1013 | OpenLayers.Request.GET({url: url, success: runRouterSuccess, failure: runRouterFailure}); |
1550 | amb | 569 | } |
1551 | |||
1552 | |||
1553 | // | ||
1554 | // Success in running router. | ||
1555 | // | ||
1556 | |||
1557 | function runRouterSuccess(response) | ||
1558 | { | ||
1559 | var lines=response.responseText.split('\n'); | ||
1560 | |||
1561 | var uuid=lines[0]; | ||
1562 | amb | 1043 | var success=lines[1]; |
1563 | amb | 569 | |
1564 | amb | 629 | var link; |
1565 | |||
1566 | amb | 569 | // Update the status message |
1567 | |||
1568 | amb | 1043 | if(success=="ERROR") |
1569 | amb | 569 | { |
1570 | amb | 577 | displayStatus("result","error"); |
1571 | amb | 572 | hideshow_show('help_route'); |
1572 | amb | 629 | |
1573 | link=document.getElementById("router_log_error"); | ||
1574 | link.href="results.cgi?uuid=" + uuid + ";type=router;format=log"; | ||
1575 | |||
1576 | amb | 569 | return; |
1577 | } | ||
1578 | else | ||
1579 | { | ||
1580 | amb | 577 | displayStatus("result","complete"); |
1581 | amb | 572 | hideshow_hide('help_route'); |
1582 | amb | 629 | |
1583 | link=document.getElementById("router_log_complete"); | ||
1584 | link.href="results.cgi?uuid=" + uuid + ";type=router;format=log"; | ||
1585 | amb | 569 | } |
1586 | |||
1587 | // Update the routing result message | ||
1588 | |||
1589 | amb | 577 | link=document.getElementById(routing_type + "_html"); |
1590 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=html"; | ||
1591 | amb | 1011 | |
1592 | amb | 577 | link=document.getElementById(routing_type + "_gpx_track"); |
1593 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=gpx-track"; | ||
1594 | amb | 1011 | |
1595 | amb | 577 | link=document.getElementById(routing_type + "_gpx_route"); |
1596 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=gpx-route"; | ||
1597 | amb | 1011 | |
1598 | amb | 577 | link=document.getElementById(routing_type + "_text_all"); |
1599 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=text-all"; | ||
1600 | amb | 1011 | |
1601 | amb | 577 | link=document.getElementById(routing_type + "_text"); |
1602 | link.href="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=text"; | ||
1603 | amb | 569 | |
1604 | amb | 1011 | links=document.getElementById(routing_type + "_links").style.display = ""; |
1605 | amb | 569 | |
1606 | // Add a GPX layer | ||
1607 | |||
1608 | var url="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=gpx-track"; | ||
1609 | |||
1610 | amb | 1013 | layerGPX[routing_type] = new OpenLayers.Layer.Vector("GPX (" + routing_type + ")", |
1611 | { | ||
1612 | protocol: new OpenLayers.Protocol.HTTP({url: url, format: new OpenLayers.Format.GPX()}), | ||
1613 | strategies: [new OpenLayers.Strategy.Fixed()], | ||
1614 | style: gpx_style[routing_type], | ||
1615 | projection: map.displayProjection | ||
1616 | }); | ||
1617 | amb | 569 | |
1618 | map.addLayer(layerGPX[routing_type]); | ||
1619 | |||
1620 | hideshow_show(routing_type); | ||
1621 | |||
1622 | displayResult(routing_type,uuid); | ||
1623 | } | ||
1624 | |||
1625 | |||
1626 | // | ||
1627 | // Failure in running router. | ||
1628 | // | ||
1629 | |||
1630 | function runRouterFailure(response) | ||
1631 | { | ||
1632 | amb | 577 | displayStatus("result","failed"); |
1633 | amb | 569 | } |
1634 | |||
1635 | |||
1636 | // | ||
1637 | amb | 577 | // Display the status |
1638 | // | ||
1639 | |||
1640 | function displayStatus(type,subtype,content) | ||
1641 | { | ||
1642 | amb | 1011 | var child=document.getElementById(type + "_status").firstChild; |
1643 | amb | 577 | |
1644 | do | ||
1645 | { | ||
1646 | if(child.id != undefined) | ||
1647 | child.style.display="none"; | ||
1648 | |||
1649 | child=child.nextSibling; | ||
1650 | } | ||
1651 | while(child != undefined); | ||
1652 | |||
1653 | amb | 936 | var chosen_status=document.getElementById(type + "_status_" + subtype); |
1654 | amb | 577 | |
1655 | amb | 936 | chosen_status.style.display=""; |
1656 | amb | 577 | |
1657 | if(content != null) | ||
1658 | amb | 936 | chosen_status.innerHTML=content; |
1659 | amb | 577 | } |
1660 | |||
1661 | |||
1662 | // | ||
1663 | amb | 569 | // Display the route |
1664 | // | ||
1665 | |||
1666 | function displayResult(type,uuid) | ||
1667 | { | ||
1668 | routing_type = type; | ||
1669 | |||
1670 | // Add the route | ||
1671 | |||
1672 | amb | 577 | var url="results.cgi?uuid=" + uuid + ";type=" + routing_type + ";format=html"; |
1673 | amb | 569 | |
1674 | // Use AJAX to get the route | ||
1675 | |||
1676 | amb | 1013 | OpenLayers.Request.GET({url: url, success: getRouteSuccess, failure: getRouteFailure}); |
1677 | amb | 569 | } |
1678 | |||
1679 | |||
1680 | // | ||
1681 | // Success in getting route. | ||
1682 | // | ||
1683 | |||
1684 | function getRouteSuccess(response) | ||
1685 | { | ||
1686 | var lines=response.responseText.split('\n'); | ||
1687 | |||
1688 | amb | 577 | routepoints[routing_type]=[]; |
1689 | amb | 569 | |
1690 | amb | 577 | var points=routepoints[routing_type]; |
1691 | amb | 569 | |
1692 | amb | 577 | var table=0; |
1693 | var point=0; | ||
1694 | var total_table,total_word; | ||
1695 | amb | 569 | |
1696 | amb | 577 | for(var line=0;line<lines.length;line++) |
1697 | amb | 569 | { |
1698 | amb | 577 | var thisline=lines[line]; |
1699 | amb | 569 | |
1700 | amb | 577 | if(table==0) |
1701 | { | ||
1702 | if(thisline.match('<table>')) | ||
1703 | table=1; | ||
1704 | else | ||
1705 | continue; | ||
1706 | } | ||
1707 | amb | 574 | |
1708 | amb | 577 | if(thisline.match('</table>')) |
1709 | break; | ||
1710 | |||
1711 | if(thisline.match('<tr class=\'([a-z])\'>')) | ||
1712 | amb | 569 | { |
1713 | amb | 577 | var rowtype=RegExp.$1; |
1714 | amb | 569 | |
1715 | amb | 577 | if(rowtype=='c') |
1716 | { | ||
1717 | thisline.match('<td class=\'r\'> *([-0-9.]+) *([-0-9.]+)'); | ||
1718 | points[point]={lat: Number(RegExp.$1), lon: Number(RegExp.$2), html: "", highway: "", distance: "", total: ""}; | ||
1719 | amb | 574 | |
1720 | amb | 577 | point++; |
1721 | } | ||
1722 | else if(rowtype=='n') | ||
1723 | { | ||
1724 | points[point-1].html += thisline; | ||
1725 | } | ||
1726 | else if(rowtype=='s') | ||
1727 | { | ||
1728 | thisline.match('<span class=\'h\'>([^<]+)</span>'); | ||
1729 | points[point-1].highway = RegExp.$1; | ||
1730 | amb | 574 | |
1731 | amb | 577 | thisline.match('<span class=\'d\'>([^<]+)</span>'); |
1732 | points[point-1].distance = RegExp.$1; | ||
1733 | amb | 574 | |
1734 | amb | 577 | thisline.match('(<span class=\'j\'>[^<]+</span>)'); |
1735 | points[point-1].total = RegExp.$1; | ||
1736 | |||
1737 | thisline.match('^(.*).<span class=\'j\'>'); | ||
1738 | |||
1739 | points[point-1].html += RegExp.$1; | ||
1740 | } | ||
1741 | else if(rowtype=='t') | ||
1742 | { | ||
1743 | points[point-1].html += thisline; | ||
1744 | |||
1745 | thisline.match('^(.*<td class=\'r\'>)'); | ||
1746 | total_table = RegExp.$1; | ||
1747 | |||
1748 | thisline.match('<td class=\'l\'>([^<]+)<'); | ||
1749 | total_word = RegExp.$1; | ||
1750 | |||
1751 | thisline.match('<span class=\'j\'>([^<]+)</span>'); | ||
1752 | points[point-1].total = RegExp.$1; | ||
1753 | } | ||
1754 | amb | 569 | } |
1755 | } | ||
1756 | |||
1757 | amb | 935 | displayStatus(routing_type,"info",points[point-1].total.bold()); |
1758 | |||
1759 | amb | 577 | var result="<table onmouseout='highlight(\"" + routing_type + "\",-1)'>"; |
1760 | |||
1761 | for(var p=0;p<point-1;p++) | ||
1762 | { | ||
1763 | points[p].html += total_table + points[p].total; | ||
1764 | |||
1765 | result=result + "<tr onclick='zoomTo(\"" + routing_type + "\"," + p + ")'" + | ||
1766 | " onmouseover='highlight(\"" + routing_type + "\"," + p + ")'>" + | ||
1767 | "<td class='distance' title='" + points[p].distance + "'>#" + (p+1) + | ||
1768 | "<td class='highway'>" + points[p].highway; | ||
1769 | } | ||
1770 | |||
1771 | result=result + "<tr onclick='zoomTo(\"" + routing_type + "\"," + p + ")'" + | ||
1772 | " onmouseover='highlight(\"" + routing_type + "\"," + p + ")'>" + | ||
1773 | "<td colspan='2'>" + total_word + " " + points[p].total; | ||
1774 | |||
1775 | amb | 569 | result=result + "</table>"; |
1776 | |||
1777 | amb | 1011 | document.getElementById(routing_type + "_route").innerHTML=result; |
1778 | amb | 569 | } |
1779 | |||
1780 | |||
1781 | // | ||
1782 | // Failure in getting route. | ||
1783 | // | ||
1784 | |||
1785 | function getRouteFailure(response) | ||
1786 | { | ||
1787 | amb | 1011 | document.getElementById(routing_type + "_route").innerHTML = ""; |
1788 | amb | 569 | } |
1789 | amb | 1001 | |
1790 | |||
1791 | // | ||
1792 | // Perform a search | ||
1793 | // | ||
1794 | |||
1795 | function DoSearch(marker) | ||
1796 | { | ||
1797 | // Use AJAX to get the search result | ||
1798 | |||
1799 | var search=routino.point[marker].search; | ||
1800 | |||
1801 | amb | 1009 | var bounds=map.getExtent().clone(); |
1802 | bounds.transform(epsg900913,epsg4326); | ||
1803 | amb | 1001 | |
1804 | amb | 1008 | var url="search.cgi?marker=" + marker + |
1805 | amb | 1009 | ";left=" + format5f(bounds.left) + |
1806 | ";top=" + format5f(bounds.top) + | ||
1807 | ";right=" + format5f(bounds.right) + | ||
1808 | ";bottom=" + format5f(bounds.bottom) + | ||
1809 | amb | 1008 | ";search=" + encodeURIComponent(search); |
1810 | |||
1811 | amb | 1013 | OpenLayers.Request.GET({url: url, success: runSearchSuccess}); |
1812 | amb | 1001 | } |
1813 | |||
1814 | |||
1815 | amb | 1005 | var searchresults=[]; |
1816 | |||
1817 | amb | 1001 | // |
1818 | // Success in running search. | ||
1819 | // | ||
1820 | |||
1821 | function runSearchSuccess(response) | ||
1822 | { | ||
1823 | var lines=response.responseText.split('\n'); | ||
1824 | |||
1825 | var marker=lines[0]; | ||
1826 | var cpuinfo=lines[1]; // not used | ||
1827 | amb | 1005 | var message=lines[2]; // not used |
1828 | amb | 1001 | |
1829 | amb | 1005 | if(message != "") |
1830 | { | ||
1831 | alert(message); | ||
1832 | return; | ||
1833 | } | ||
1834 | amb | 1001 | |
1835 | amb | 1005 | searchresults[marker]=[]; |
1836 | |||
1837 | for(var line=3;line<lines.length;line++) | ||
1838 | { | ||
1839 | var thisline=lines[line]; | ||
1840 | |||
1841 | if(thisline=="") | ||
1842 | break; | ||
1843 | |||
1844 | thisline.match('([-.0-9]+) ([-.0-9]+) (.*)'); | ||
1845 | |||
1846 | searchresults[marker][searchresults[marker].length]={lat: Number(RegExp.$1), lon: Number(RegExp.$2), name: RegExp.$3}; | ||
1847 | } | ||
1848 | |||
1849 | if(searchresults[marker].length==1) | ||
1850 | { | ||
1851 | formSetSearch(marker,searchresults[marker][0].name); | ||
1852 | amb | 1032 | formSetCoords(marker,searchresults[marker][0].lon,searchresults[marker][0].lat); |
1853 | markerAddMap(marker); | ||
1854 | amb | 1005 | } |
1855 | else | ||
1856 | { | ||
1857 | var results=document.getElementById("searchresults" + marker); | ||
1858 | |||
1859 | var innerHTML="<td colspan=\"3\">"; | ||
1860 | |||
1861 | for(var n=0;n<searchresults[marker].length;n++) | ||
1862 | { | ||
1863 | if(n>0) | ||
1864 | innerHTML+="<br>"; | ||
1865 | |||
1866 | innerHTML+="<a href=\"#\" onclick=\"choseSearchResult(" + marker + "," + n + ")\">" + | ||
1867 | searchresults[marker][n].name + | ||
1868 | "</a>"; | ||
1869 | } | ||
1870 | |||
1871 | results.innerHTML=innerHTML; | ||
1872 | |||
1873 | results.style.display=""; | ||
1874 | } | ||
1875 | amb | 1001 | } |
1876 | amb | 1005 | |
1877 | |||
1878 | // | ||
1879 | // Display search results. | ||
1880 | // | ||
1881 | |||
1882 | function choseSearchResult(marker,n) | ||
1883 | { | ||
1884 | if(n>=0) | ||
1885 | { | ||
1886 | formSetSearch(marker,searchresults[marker][n].name); | ||
1887 | amb | 1032 | formSetCoords(marker,searchresults[marker][n].lon,searchresults[marker][n].lat); |
1888 | markerAddMap(marker); | ||
1889 | amb | 1005 | } |
1890 | } | ||
1891 | |||
1892 | |||
1893 | // | ||
1894 | // Clear search results. | ||
1895 | // | ||
1896 | |||
1897 | function clearSearchResult(marker) | ||
1898 | { | ||
1899 | amb | 1011 | document.getElementById("searchresults" + marker).style.display="none"; |
1900 | amb | 1005 | } |