Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/web/www/routino/visualiser.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1239 - (show annotations) (download) (as text)
Sat Jan 19 17:23:38 2013 UTC (12 years, 1 month ago) by amb
File MIME type: application/javascript
File size: 24850 byte(s)
Added MapQuest as an optional map layer, added layer specific attributions to
mapprops.js.

1 //
2 // Routino data visualiser web page Javascript
3 //
4 // Part of the Routino routing software.
5 //
6 // This file Copyright 2008-2013 Andrew M. Bishop
7 //
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
23 //
24 // Data types
25 //
26
27 var data_types=[
28 "junctions",
29 "super",
30 "oneway",
31 "highway",
32 "transport",
33 "barrier",
34 "turns",
35 "speed",
36 "weight",
37 "height",
38 "width",
39 "length"
40 ];
41
42
43 //
44 // Junction styles
45 //
46
47 var junction_colours={
48 0: "#FFFFFF",
49 1: "#FF0000",
50 2: "#FFFF00",
51 3: "#00FF00",
52 4: "#8B4513",
53 5: "#00BFFF",
54 6: "#FF69B4",
55 7: "#000000",
56 8: "#000000",
57 9: "#000000"
58 };
59
60 var junction_styles={};
61
62
63 //
64 // Super styles
65 //
66
67 var super_node_style,super_segment_style;
68
69
70 //
71 // Oneway and turn restriction styles
72 //
73
74 var hex={0: "00", 1: "11", 2: "22", 3: "33", 4: "44", 5: "55", 6: "66", 7: "77",
75 8: "88", 9: "99", 10: "AA", 11: "BB", 12: "CC", 13: "DD", 14: "EE", 15: "FF"};
76
77 var turn_restriction_style;
78
79
80 ////////////////////////////////////////////////////////////////////////////////
81 /////////////////////////////// Initialisation /////////////////////////////////
82 ////////////////////////////////////////////////////////////////////////////////
83
84 // Process the URL query string and extract the arguments
85
86 var legal={"^lon" : "^[-0-9.]+$",
87 "^lat" : "^[-0-9.]+$",
88 "^zoom" : "^[0-9]+$"};
89
90 var args={};
91
92 if(location.search.length>1)
93 {
94 var query,queries;
95
96 query=location.search.replace(/^\?/,"");
97 query=query.replace(/;/g,'&');
98 queries=query.split('&');
99
100 for(var i=0;i<queries.length;i++)
101 {
102 queries[i].match(/^([^=]+)(=(.*))?$/);
103
104 k=RegExp.$1;
105 v=unescape(RegExp.$3);
106
107 for(var l in legal)
108 {
109 if(k.match(RegExp(l)) && v.match(RegExp(legal[l])))
110 args[k]=v;
111 }
112 }
113 }
114
115
116 ////////////////////////////////////////////////////////////////////////////////
117 ///////////////////////////////// Map handling /////////////////////////////////
118 ////////////////////////////////////////////////////////////////////////////////
119
120 var map;
121 var layerMap=[], layerVectors, layerBoxes;
122 var epsg4326, epsg900913;
123
124 var box;
125
126 //
127 // Initialise the 'map' object
128 //
129
130 function map_init() // called from visualiser.html
131 {
132 lon =args["lon"];
133 lat =args["lat"];
134 zoom=args["zoom"];
135
136 // Map properties (North/South and East/West limits and zoom in/out limits) are now in mapprops.js
137 // Map URLs are now in mapprops.js
138
139 //
140 // Create the map
141 //
142
143 epsg4326=new OpenLayers.Projection("EPSG:4326");
144 epsg900913=new OpenLayers.Projection("EPSG:900913");
145
146 map = new OpenLayers.Map ("map",
147 {
148 controls:[
149 new OpenLayers.Control.Navigation(),
150 new OpenLayers.Control.PanZoomBar(),
151 new OpenLayers.Control.ScaleLine(),
152 new OpenLayers.Control.LayerSwitcher()
153 ],
154
155 projection: epsg900913,
156 displayProjection: epsg4326,
157
158 minZoomLevel: mapprops.zoomout,
159 numZoomLevels: mapprops.zoomin-mapprops.zoomout+1,
160 maxResolution: 156543.03390625 / Math.pow(2,mapprops.zoomout),
161
162 // These two lines are not needed with OpenLayers 2.12
163 units: "m",
164 maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
165
166 restrictedExtent: new OpenLayers.Bounds(mapprops.westedge,mapprops.southedge,mapprops.eastedge,mapprops.northedge).transform(epsg4326,epsg900913)
167 });
168
169 // Add map tile layers
170
171 for(var l=0;l < mapprops.mapdata.length;l++)
172 {
173 layerMap[l] = new OpenLayers.Layer.TMS(mapprops.mapdata[l].label,
174 mapprops.mapdata[l].tileurl,
175 {
176 getURL: limitedUrl,
177 displayOutsideMaxExtent: true,
178 buffer: 1
179 });
180 map.addLayer(layerMap[l]);
181 }
182
183 // Update the attribution if the layer changes
184
185 map.events.register("changelayer",layerMap,change_attribution_event);
186
187 function change_attribution_event(event)
188 {
189 for(var l=0;l < mapprops.mapdata.length;l++)
190 if(this[l] == event.layer)
191 change_attribution(l);
192 }
193
194 function change_attribution(l)
195 {
196 var data_url =mapprops.mapdata[l].attribution.data_url;
197 var data_text=mapprops.mapdata[l].attribution.data_text;
198 var tile_url =mapprops.mapdata[l].attribution.tile_url;
199 var tile_text=mapprops.mapdata[l].attribution.tile_text;
200
201 document.getElementById("attribution_data").innerHTML="<a href=\"" + data_url + "\" target=\"data_attribution\">" + data_text + "</a>";
202 document.getElementById("attribution_tile").innerHTML="<a href=\"" + tile_url + "\" target=\"tile_attribution\">" + tile_text + "</a>";
203 }
204
205 change_attribution(0);
206
207 // Get a URL for the tile (mostly copied from OpenLayers/Layer/XYZ.js).
208
209 function limitedUrl(bounds)
210 {
211 var res = map.getResolution();
212 var res = this.getServerResolution();
213
214 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
215 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
216 var z = map.getZoom() + map.minZoomLevel;
217
218 var limit = Math.pow(2, z);
219 x = ((x % limit) + limit) % limit;
220
221 var xyz = {'x': x, 'y': y, 'z': z};
222 var url = this.url;
223
224 if (OpenLayers.Util.isArray(url))
225 {
226 var s = '' + xyz.x + xyz.y + xyz.z;
227 url = this.selectUrl(s, url);
228 }
229
230 return OpenLayers.String.format(url, xyz);
231 }
232
233 // Add a vectors layer
234
235 layerVectors = new OpenLayers.Layer.Vector("Markers");
236 map.addLayer(layerVectors);
237
238 for(var colour in junction_colours)
239 junction_styles[colour]=new OpenLayers.Style({},{stroke: false, pointRadius: 2,fillColor: junction_colours[colour]});
240
241 super_node_style =new OpenLayers.Style({},{stroke: false, pointRadius: 3,fillColor : "#FF0000"});
242 super_segment_style=new OpenLayers.Style({},{fill: false , strokeWidth: 2,strokeColor: "#FF0000"});
243
244 turn_restriction_style=new OpenLayers.Style({},{fill: false, strokeWidth: 2,strokeColor: "#FF0000"});
245
246 // Add a boxes layer
247
248 layerBoxes = new OpenLayers.Layer.Boxes("Boundary");
249 map.addLayer(layerBoxes);
250
251 box=null;
252
253 // Set the map centre to the limited range specified
254
255 map.setCenter(map.restrictedExtent.getCenterLonLat(), map.getZoomForExtent(map.restrictedExtent,true));
256 map.maxResolution = map.getResolution();
257
258 // Move the map
259
260 if(lon != undefined && lat != undefined && zoom != undefined)
261 {
262 if(lon<mapprops.westedge) lon=mapprops.westedge;
263 if(lon>mapprops.eastedge) lon=mapprops.eastedge;
264
265 if(lat<mapprops.southedge) lat=mapprops.southedge;
266 if(lat>mapprops.northedge) lat=mapprops.northedge;
267
268 if(zoom<mapprops.zoomout) zoom=mapprops.zoomout;
269 if(zoom>mapprops.zoomin) zoom=mapprops.zoomin;
270
271 var lonlat = new OpenLayers.LonLat(lon,lat);
272 lonlat.transform(epsg4326,epsg900913);
273
274 map.moveTo(lonlat,zoom-map.minZoomLevel);
275 }
276 }
277
278
279 //
280 // Format a number in printf("%.5f") format.
281 //
282
283 function format5f(number)
284 {
285 var newnumber=Math.floor(number*100000+0.5);
286 var delta=0;
287
288 if(newnumber>=0 && newnumber<100000) delta= 100000;
289 if(newnumber<0 && newnumber>-100000) delta=-100000;
290
291 var string=String(newnumber+delta);
292
293 var intpart =string.substring(0,string.length-5);
294 var fracpart=string.substring(string.length-5,string.length);
295
296 if(delta>0) intpart="0";
297 if(delta<0) intpart="-0";
298
299 return(intpart + "." + fracpart);
300 }
301
302
303 //
304 // Build a set of URL arguments for the map location
305 //
306
307 function buildMapArguments()
308 {
309 var lonlat = map.getCenter().clone();
310 lonlat.transform(epsg900913,epsg4326);
311
312 var zoom = map.getZoom() + map.minZoomLevel;
313
314 return "lat=" + format5f(lonlat.lat) + ";lon=" + format5f(lonlat.lon) + ";zoom=" + zoom;
315 }
316
317
318 //
319 // Update a URL
320 //
321
322 function updateURL(element) // called from visualiser.html
323 {
324 if(element.id == "permalink_url")
325 element.href=location.pathname + "?" + buildMapArguments();
326
327 if(element.id == "router_url")
328 element.href="router.html" + "?" + buildMapArguments();
329
330 if(element.id == "edit_url")
331 element.href="http://www.openstreetmap.org/edit" + "?" + buildMapArguments();
332
333 if(element.id.match(/^lang_([a-zA-Z-]+)_url$/))
334 element.href="visualiser.html" + "." + RegExp.$1 + "?" + buildMapArguments();
335 }
336
337
338 ////////////////////////////////////////////////////////////////////////////////
339 /////////////////////////////// Server handling ////////////////////////////////
340 ////////////////////////////////////////////////////////////////////////////////
341
342 //
343 // Display the status
344 //
345
346 function displayStatus(type,subtype,content)
347 {
348 var child=document.getElementById("result_status").firstChild;
349
350 do
351 {
352 if(child.id != undefined)
353 child.style.display="none";
354
355 child=child.nextSibling;
356 }
357 while(child != undefined);
358
359 var chosen_status=document.getElementById("result_status_" + type);
360
361 chosen_status.style.display="";
362
363 if(subtype != null)
364 {
365 var format_status=document.getElementById("result_status_" + subtype).innerHTML;
366
367 chosen_status.innerHTML=format_status.replace('#',String(content));
368 }
369 }
370
371
372 //
373 // Display data statistics
374 //
375
376 function displayStatistics()
377 {
378 // Use AJAX to get the statistics
379
380 OpenLayers.Request.GET({url: "statistics.cgi", success: runStatisticsSuccess});
381 }
382
383
384 //
385 // Success in running data statistics generation.
386 //
387
388 function runStatisticsSuccess(response)
389 {
390 document.getElementById("statistics_data").innerHTML="<pre>" + response.responseText + "</pre>";
391 document.getElementById("statistics_link").style.display="none";
392 }
393
394
395 //
396 // Get the requested data
397 //
398
399 function displayData(datatype) // called from visualiser.html
400 {
401 for(var data in data_types)
402 hideshow_hide(data_types[data]);
403
404 if(datatype != "")
405 hideshow_show(datatype);
406
407 // Delete the old data
408
409 layerVectors.destroyFeatures();
410
411 if(box != null)
412 layerBoxes.removeMarker(box);
413 box=null;
414
415 // Print the status
416
417 displayStatus("no_data");
418
419 // Return if just here to clear the data
420
421 if(datatype == "")
422 return;
423
424 // Get the new data
425
426 var mapbounds=map.getExtent().clone();
427 mapbounds.transform(epsg900913,epsg4326);
428
429 var url="visualiser.cgi";
430
431 url=url + "?lonmin=" + mapbounds.left;
432 url=url + ";latmin=" + mapbounds.bottom;
433 url=url + ";lonmax=" + mapbounds.right;
434 url=url + ";latmax=" + mapbounds.top;
435 url=url + ";data=" + datatype;
436
437 // Use AJAX to get the data
438
439 switch(datatype)
440 {
441 case 'junctions':
442 OpenLayers.Request.GET({url: url, success: runJunctionsSuccess, failure: runFailure});
443 break;
444 case 'super':
445 OpenLayers.Request.GET({url: url, success: runSuperSuccess, faliure: runFailure});
446 break;
447 case 'oneway':
448 OpenLayers.Request.GET({url: url, success: runOnewaySuccess, failure: runFailure});
449 break;
450 case 'highway':
451 var highways=document.forms["highways"].elements["highway"];
452 for(var h in highways)
453 if(highways[h].checked)
454 highway=highways[h].value;
455 url+="-" + highway;
456 OpenLayers.Request.GET({url: url, success: runHighwaySuccess, falure: runFailure});
457 break;
458 case 'transport':
459 var transports=document.forms["transports"].elements["transport"];
460 for(var t in transports)
461 if(transports[t].checked)
462 transport=transports[t].value;
463 url+="-" + transport;
464 OpenLayers.Request.GET({url: url, success: runTransportSuccess, failure: runFailure});
465 break;
466 case 'barrier':
467 var transports=document.forms["barriers"].elements["barrier"];
468 for(var t in transports)
469 if(transports[t].checked)
470 transport=transports[t].value;
471 url+="-" + transport;
472 OpenLayers.Request.GET({url: url, success: runBarrierSuccess, failure: runFailure});
473 break;
474 case 'turns':
475 OpenLayers.Request.GET({url: url, success: runTurnsSuccess, failure: runFailure});
476 break;
477 case 'speed':
478 case 'weight':
479 case 'height':
480 case 'width':
481 case 'length':
482 OpenLayers.Request.GET({url: url, success: runLimitSuccess, failure: runFailure});
483 break;
484 }
485 }
486
487
488 //
489 // Success in getting the junctions.
490 //
491
492 function runJunctionsSuccess(response)
493 {
494 var lines=response.responseText.split('\n');
495
496 var features=[];
497
498 for(var line=0;line<lines.length;line++)
499 {
500 var words=lines[line].split(' ');
501
502 if(line == 0)
503 {
504 var lat1=words[0];
505 var lon1=words[1];
506 var lat2=words[2];
507 var lon2=words[3];
508
509 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
510
511 box = new OpenLayers.Marker.Box(bounds);
512
513 layerBoxes.addMarker(box);
514 }
515 else if(words[0] != "")
516 {
517 var lat=words[0];
518 var lon=words[1];
519 var count=words[2];
520
521 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
522
523 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
524
525 features.push(new OpenLayers.Feature.Vector(point,{},junction_styles[count]));
526 }
527 }
528
529 layerVectors.addFeatures(features);
530
531 displayStatus("data","junctions",lines.length-2);
532 }
533
534
535 //
536 // Success in getting the super-node and super-segments
537 //
538
539 function runSuperSuccess(response)
540 {
541 var lines=response.responseText.split('\n');
542
543 var features=[];
544
545 var nodepoint;
546
547 for(var line=0;line<lines.length;line++)
548 {
549 var words=lines[line].split(' ');
550
551 if(line == 0)
552 {
553 var lat1=words[0];
554 var lon1=words[1];
555 var lat2=words[2];
556 var lon2=words[3];
557
558 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
559
560 box = new OpenLayers.Marker.Box(bounds);
561
562 layerBoxes.addMarker(box);
563 }
564 else if(words[0] != "")
565 {
566 var lat=words[0];
567 var lon=words[1];
568 var type=words[2];
569
570 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
571
572 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
573
574 if(type == "n")
575 {
576 nodepoint=point;
577
578 features.push(new OpenLayers.Feature.Vector(point,{},super_node_style));
579 }
580 else
581 {
582 var segment = new OpenLayers.Geometry.LineString([nodepoint,point]);
583
584 features.push(new OpenLayers.Feature.Vector(segment,{},super_segment_style));
585 }
586 }
587 }
588
589 layerVectors.addFeatures(features);
590
591 displayStatus("data","super",lines.length-2);
592 }
593
594
595 //
596 // Success in getting the oneway data
597 //
598
599 function runOnewaySuccess(response)
600 {
601 var lines=response.responseText.split('\n');
602
603 var features=[];
604
605 for(var line=0;line<lines.length;line++)
606 {
607 var words=lines[line].split(' ');
608
609 if(line == 0)
610 {
611 var lat1=words[0];
612 var lon1=words[1];
613 var lat2=words[2];
614 var lon2=words[3];
615
616 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
617
618 box = new OpenLayers.Marker.Box(bounds);
619
620 layerBoxes.addMarker(box);
621 }
622 else if(words[0] != "")
623 {
624 var lat1=words[0];
625 var lon1=words[1];
626 var lat2=words[2];
627 var lon2=words[3];
628
629 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
630 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
631
632 //var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
633 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
634
635 var dlat = lonlat2.lat-lonlat1.lat;
636 var dlon = lonlat2.lon-lonlat1.lon;
637 var dist = Math.sqrt(dlat*dlat+dlon*dlon)/10;
638 var ang = Math.atan2(dlat,dlon);
639
640 var point3 = new OpenLayers.Geometry.Point(lonlat1.lon+dlat/dist,lonlat1.lat-dlon/dist);
641 var point4 = new OpenLayers.Geometry.Point(lonlat1.lon-dlat/dist,lonlat1.lat+dlon/dist);
642
643 var segment = new OpenLayers.Geometry.LineString([point2,point3,point4,point2]);
644
645 var r=Math.round(7.5+7.9*Math.cos(ang));
646 var g=Math.round(7.5+7.9*Math.cos(ang+2.0943951));
647 var b=Math.round(7.5+7.9*Math.cos(ang-2.0943951));
648 var colour = "#" + hex[r] + hex[g] + hex[b];
649
650 var style=new OpenLayers.Style({},{strokeWidth: 2,strokeColor: colour});
651
652 features.push(new OpenLayers.Feature.Vector(segment,{},style));
653 }
654 }
655
656 layerVectors.addFeatures(features);
657
658 displayStatus("data","oneway",lines.length-2);
659 }
660
661
662 //
663 // Success in getting the highway data
664 //
665
666 function runHighwaySuccess(response)
667 {
668 var lines=response.responseText.split('\n');
669
670 var features=[];
671
672 for(var line=0;line<lines.length;line++)
673 {
674 var words=lines[line].split(' ');
675
676 if(line == 0)
677 {
678 var lat1=words[0];
679 var lon1=words[1];
680 var lat2=words[2];
681 var lon2=words[3];
682
683 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
684
685 box = new OpenLayers.Marker.Box(bounds);
686
687 layerBoxes.addMarker(box);
688 }
689 else if(words[0] != "")
690 {
691 var lat1=words[0];
692 var lon1=words[1];
693 var lat2=words[2];
694 var lon2=words[3];
695
696 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
697 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
698
699 var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
700 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
701
702 var segment = new OpenLayers.Geometry.LineString([point1,point2]);
703
704 features.push(new OpenLayers.Feature.Vector(segment,{},super_segment_style));
705 }
706 }
707
708 layerVectors.addFeatures(features);
709
710 displayStatus("data","highway",lines.length-2);
711 }
712
713
714 //
715 // Success in getting the transport data
716 //
717
718 function runTransportSuccess(response)
719 {
720 var lines=response.responseText.split('\n');
721
722 var features=[];
723
724 for(var line=0;line<lines.length;line++)
725 {
726 var words=lines[line].split(' ');
727
728 if(line == 0)
729 {
730 var lat1=words[0];
731 var lon1=words[1];
732 var lat2=words[2];
733 var lon2=words[3];
734
735 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
736
737 box = new OpenLayers.Marker.Box(bounds);
738
739 layerBoxes.addMarker(box);
740 }
741 else if(words[0] != "")
742 {
743 var lat1=words[0];
744 var lon1=words[1];
745 var lat2=words[2];
746 var lon2=words[3];
747
748 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
749 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
750
751 var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
752 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
753
754 var segment = new OpenLayers.Geometry.LineString([point1,point2]);
755
756 features.push(new OpenLayers.Feature.Vector(segment,{},super_segment_style));
757 }
758 }
759
760 layerVectors.addFeatures(features);
761
762 displayStatus("data","transport",lines.length-2);
763 }
764
765
766 //
767 // Success in getting the barrier data
768 //
769
770 function runBarrierSuccess(response)
771 {
772 var lines=response.responseText.split('\n');
773
774 var features=[];
775
776 for(var line=0;line<lines.length;line++)
777 {
778 var words=lines[line].split(' ');
779
780 if(line == 0)
781 {
782 var lat1=words[0];
783 var lon1=words[1];
784 var lat2=words[2];
785 var lon2=words[3];
786
787 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
788
789 box = new OpenLayers.Marker.Box(bounds);
790
791 layerBoxes.addMarker(box);
792 }
793 else if(words[0] != "")
794 {
795 var lat=words[0];
796 var lon=words[1];
797
798 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
799
800 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
801
802 features.push(new OpenLayers.Feature.Vector(point,{},super_node_style));
803 }
804 }
805
806 layerVectors.addFeatures(features);
807
808 displayStatus("data","barrier",lines.length-2);
809 }
810
811
812 //
813 // Success in getting the turn restrictions data
814 //
815
816 function runTurnsSuccess(response)
817 {
818 var lines=response.responseText.split('\n');
819
820 var features=[];
821
822 for(var line=0;line<lines.length;line++)
823 {
824 var words=lines[line].split(' ');
825
826 if(line == 0)
827 {
828 var lat1=words[0];
829 var lon1=words[1];
830 var lat2=words[2];
831 var lon2=words[3];
832
833 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
834
835 box = new OpenLayers.Marker.Box(bounds);
836
837 layerBoxes.addMarker(box);
838 }
839 else if(words[0] != "")
840 {
841 var lat1=words[0];
842 var lon1=words[1];
843 var lat2=words[2];
844 var lon2=words[3];
845 var lat3=words[4];
846 var lon3=words[5];
847
848 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
849 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
850 var lonlat3= new OpenLayers.LonLat(lon3,lat3).transform(epsg4326,epsg900913);
851
852 var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
853 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
854 var point3 = new OpenLayers.Geometry.Point(lonlat3.lon,lonlat3.lat);
855
856 var segments = new OpenLayers.Geometry.LineString([point1,point2,point3]);
857
858 features.push(new OpenLayers.Feature.Vector(segments,{},turn_restriction_style));
859 }
860 }
861
862 layerVectors.addFeatures(features);
863
864 displayStatus("data","turns",lines.length-2);
865 }
866
867
868 //
869 // Success in getting the speed/weight/height/width/length limits
870 //
871
872 function runLimitSuccess(response)
873 {
874 var lines=response.responseText.split('\n');
875
876 var features=[];
877
878 var nodelonlat;
879
880 for(var line=0;line<lines.length;line++)
881 {
882 var words=lines[line].split(' ');
883
884 if(line == 0)
885 {
886 var lat1=words[0];
887 var lon1=words[1];
888 var lat2=words[2];
889 var lon2=words[3];
890
891 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
892
893 box = new OpenLayers.Marker.Box(bounds);
894
895 layerBoxes.addMarker(box);
896 }
897 else if(words[0] != "")
898 {
899 var lat=words[0];
900 var lon=words[1];
901 var number=words[2];
902
903 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
904
905 if(number == undefined)
906 {
907 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
908
909 nodelonlat=lonlat;
910
911 features.push(new OpenLayers.Feature.Vector(point,{},junction_styles[1]));
912 }
913 else
914 {
915 var dlat = lonlat.lat-nodelonlat.lat;
916 var dlon = lonlat.lon-nodelonlat.lon;
917 var dist = Math.sqrt(dlat*dlat+dlon*dlon)/60;
918
919 var point = new OpenLayers.Geometry.Point(nodelonlat.lon+dlon/dist,nodelonlat.lat+dlat/dist);
920
921 features.push(new OpenLayers.Feature.Vector(point,{},
922 new OpenLayers.Style({},{externalGraphic: 'icons/limit-' + number + '.png',
923 graphicYOffset: -9,
924 graphicWidth: 19,
925 graphicHeight: 19})));
926 }
927 }
928 }
929
930 layerVectors.addFeatures(features);
931
932 displayStatus("data","limit",lines.length-2);
933 }
934
935
936 //
937 // Failure in getting data.
938 //
939
940 function runFailure(response)
941 {
942 displayStatus("error");
943 }