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