Routino SVN Repository Browser

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

ViewVC logotype

Contents of /branches/destination-access/web/www/routino/visualiser.openlayers2.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2008 - (show annotations) (download) (as text)
Sun Sep 1 14:49:11 2019 UTC (5 years, 6 months ago) by amb
File MIME type: application/javascript
File size: 34627 byte(s)
Merge from trunk (renaming of openlayers to openlayers2).

1 //
2 // Routino data visualiser web page Javascript
3 //
4 // Part of the Routino routing software.
5 //
6 // This file Copyright 2008-2014 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 "waytype",
31 "highway",
32 "transport",
33 "destination",
34 "barrier",
35 "turns",
36 "speed",
37 "weight",
38 "height",
39 "width",
40 "length",
41 "property",
42 "errorlogs"
43 ];
44
45
46 ////////////////////////////////////////////////////////////////////////////////
47 /////////////////////////////// Initialisation /////////////////////////////////
48 ////////////////////////////////////////////////////////////////////////////////
49
50 // Process the URL query string and extract the arguments
51
52 var legal={"^lon" : "^[-0-9.]+$",
53 "^lat" : "^[-0-9.]+$",
54 "^zoom" : "^[0-9]+$"};
55
56 var args={};
57
58 if(location.search.length>1)
59 {
60 var query,queries;
61
62 query=location.search.replace(/^\?/,"");
63 query=query.replace(/;/g,"&");
64 queries=query.split("&");
65
66 for(var i=0;i<queries.length;i++)
67 {
68 queries[i].match(/^([^=]+)(=(.*))?$/);
69
70 var k=RegExp.$1;
71 var v=decodeURIComponent(RegExp.$3);
72
73 for(var l in legal)
74 {
75 if(k.match(RegExp(l)) && v.match(RegExp(legal[l])))
76 args[k]=v;
77 }
78 }
79 }
80
81
82 ////////////////////////////////////////////////////////////////////////////////
83 ///////////////////////////////// Map handling /////////////////////////////////
84 ////////////////////////////////////////////////////////////////////////////////
85
86 var map;
87 var layerMap=[], layerHighlights, layerVectors, layerBoxes;
88 var epsg4326, epsg900913;
89 var box;
90 var select;
91
92 //
93 // Initialise the 'map' object
94 //
95
96 function map_init() // called from visualiser.html
97 {
98 // Create the map (Map URLs and limits are in mapprops.js)
99
100 epsg4326=new OpenLayers.Projection("EPSG:4326");
101 epsg900913=new OpenLayers.Projection("EPSG:900913");
102
103 map = new OpenLayers.Map ("map",
104 {
105 controls:[
106 new OpenLayers.Control.Navigation(),
107 new OpenLayers.Control.PanZoomBar(),
108 new OpenLayers.Control.ScaleLine(),
109 new OpenLayers.Control.LayerSwitcher()
110 ],
111
112 projection: epsg900913,
113 displayProjection: epsg4326,
114
115 minZoomLevel: mapprops.zoomout,
116 numZoomLevels: mapprops.zoomin-mapprops.zoomout+1,
117 maxResolution: 156543.03390625 / Math.pow(2,mapprops.zoomout),
118
119 restrictedExtent: new OpenLayers.Bounds(mapprops.westedge,mapprops.southedge,mapprops.eastedge,mapprops.northedge).transform(epsg4326,epsg900913)
120 });
121
122 // Get a URL for the tile (mostly copied from OpenLayers/Layer/XYZ.js).
123
124 function limitedUrl(bounds)
125 {
126 var res = this.map.getResolution();
127
128 var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
129 var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
130 var z = this.map.getZoom() + this.map.minZoomLevel;
131
132 var limit = Math.pow(2, z);
133 x = ((x % limit) + limit) % limit;
134
135 var xyz = {"x": x, "y": y, "z": z};
136 var url = this.url;
137
138 if (OpenLayers.Util.isArray(url))
139 {
140 var s = "" + xyz.x + xyz.y + xyz.z;
141 url = this.selectUrl(s, url);
142 }
143
144 return OpenLayers.String.format(url, xyz);
145 }
146
147 // Add map tile layers
148
149 for(var l=0; l<mapprops.mapdata.length; l++)
150 {
151 var urls;
152
153 if(OpenLayers.Util.isArray(mapprops.mapdata[l].tiles.subdomains))
154 {
155 urls=[];
156
157 for(var s=0; s<mapprops.mapdata[l].tiles.subdomains.length; s++)
158 urls.push(mapprops.mapdata[l].tiles.url.replace(/\${s}/,mapprops.mapdata[l].tiles.subdomains[s]));
159 }
160 else
161 urls=mapprops.mapdata[l].tiles.url;
162
163 layerMap[l] = new OpenLayers.Layer.TMS(mapprops.mapdata[l].label,
164 urls,
165 {
166 getURL: limitedUrl,
167 displayOutsideMaxExtent: true,
168 buffer: 1
169 });
170 map.addLayer(layerMap[l]);
171 }
172
173 // Update the attribution if the layer changes
174
175 function change_attribution_event(event)
176 {
177 for(var l=0; l<mapprops.mapdata.length; l++)
178 if(layerMap[l] == event.layer)
179 change_attribution(l);
180 }
181
182 map.events.register("changelayer",layerMap,change_attribution_event);
183
184 function change_attribution(l)
185 {
186 var data_url =mapprops.mapdata[l].attribution.data_url;
187 var data_text=mapprops.mapdata[l].attribution.data_text;
188 var tile_url =mapprops.mapdata[l].attribution.tile_url;
189 var tile_text=mapprops.mapdata[l].attribution.tile_text;
190
191 document.getElementById("attribution_data").innerHTML="<a href=\"" + data_url + "\" target=\"data_attribution\">" + data_text + "</a>";
192 document.getElementById("attribution_tile").innerHTML="<a href=\"" + tile_url + "\" target=\"tile_attribution\">" + tile_text + "</a>";
193 }
194
195 change_attribution(0);
196
197 // Add two vectors layers (one for highlights that display behind the vectors)
198
199 layerHighlights = new OpenLayers.Layer.Vector("Highlights",{displayInLayerSwitcher: false});
200 map.addLayer(layerHighlights);
201
202 layerVectors = new OpenLayers.Layer.Vector("Markers",{displayInLayerSwitcher: false});
203 map.addLayer(layerVectors);
204
205 // Handle feature selection and popup
206
207 select = new OpenLayers.Control.SelectFeature(layerVectors,
208 {onSelect: selectFeature, onUnselect: unselectFeature});
209
210 map.addControl(select);
211 select.activate();
212
213 createPopup();
214
215 // Add a boxes layer
216
217 layerBoxes = new OpenLayers.Layer.Boxes("Boundary",{displayInLayerSwitcher: false});
218 map.addLayer(layerBoxes);
219
220 box=null;
221
222 // Move the map
223
224 map.events.register("moveend", map, updateURLs);
225
226 var lon =args["lon"];
227 var lat =args["lat"];
228 var zoom=args["zoom"];
229
230 if(lon !== undefined && lat !== undefined && zoom !== undefined)
231 {
232 if(lon<mapprops.westedge) lon=mapprops.westedge;
233 if(lon>mapprops.eastedge) lon=mapprops.eastedge;
234
235 if(lat<mapprops.southedge) lat=mapprops.southedge;
236 if(lat>mapprops.northedge) lat=mapprops.northedge;
237
238 if(zoom<mapprops.zoomout) zoom=mapprops.zoomout;
239 if(zoom>mapprops.zoomin) zoom=mapprops.zoomin;
240
241 var lonlat = new OpenLayers.LonLat(lon,lat);
242 lonlat.transform(epsg4326,epsg900913);
243
244 map.moveTo(lonlat,zoom-map.minZoomLevel);
245 }
246 else
247 {
248 map.setCenter(map.restrictedExtent.getCenterLonLat(), map.getZoomForExtent(map.restrictedExtent,true));
249 map.maxResolution = map.getResolution();
250 }
251
252 // Unhide editing URL if variable set
253
254 if(mapprops.editurl !== undefined && mapprops.editurl !== "")
255 {
256 var edit_url=document.getElementById("edit_url");
257
258 edit_url.style.display="";
259 edit_url.href=mapprops.editurl;
260 }
261
262 updateURLs();
263 }
264
265
266 //
267 // Format a number in printf("%.5f") format.
268 //
269
270 function format5f(number)
271 {
272 var newnumber=Math.floor(number*100000+0.5);
273 var delta=0;
274
275 if(newnumber>=0 && newnumber<100000) delta= 100000;
276 if(newnumber<0 && newnumber>-100000) delta=-100000;
277
278 var string=String(newnumber+delta);
279
280 var intpart =string.substring(0,string.length-5);
281 var fracpart=string.substring(string.length-5,string.length);
282
283 if(delta>0) intpart="0";
284 if(delta<0) intpart="-0";
285
286 return(intpart + "." + fracpart);
287 }
288
289
290 //
291 // Build a set of URL arguments for the map location
292 //
293
294 function buildMapArguments()
295 {
296 var lonlat = map.getCenter().clone();
297 lonlat.transform(epsg900913,epsg4326);
298
299 var zoom = map.getZoom() + map.minZoomLevel;
300
301 return "lat=" + format5f(lonlat.lat) + ";lon=" + format5f(lonlat.lon) + ";zoom=" + zoom;
302 }
303
304
305 //
306 // Update the URLs
307 //
308
309 function updateURLs()
310 {
311 var mapargs=buildMapArguments();
312
313 var links=document.getElementsByTagName("a");
314
315 for(var i=0; i<links.length; i++)
316 {
317 var element=links[i];
318
319 if(element.id == "permalink_url")
320 element.href=location.pathname + "?" + mapargs;
321
322 if(element.id == "router_url")
323 element.href="router.html" + "?" + mapargs;
324
325 if(element.id == "edit_url")
326 element.href=mapprops.editurl + "?" + mapargs;
327
328 if(element.id.match(/^lang_([a-zA-Z-]+)_url$/))
329 element.href="visualiser.html" + "." + RegExp.$1 + "?" + mapargs;
330 }
331 }
332
333
334 ////////////////////////////////////////////////////////////////////////////////
335 ///////////////////////// Popup and selection handling /////////////////////////
336 ////////////////////////////////////////////////////////////////////////////////
337
338 var popup=null;
339
340 //
341 // Create a popup - independent of map because want it fixed on screen not fixed on map.
342 //
343
344 function createPopup()
345 {
346 popup=document.createElement("div");
347
348 popup.className = "popup";
349
350 popup.innerHTML = "<span></span>";
351
352 popup.style.display = "none";
353
354 popup.style.position = "fixed";
355 popup.style.top = "-4000px";
356 popup.style.left = "-4000px";
357 popup.style.zIndex = "100";
358
359 popup.style.padding = "5px";
360
361 popup.style.opacity=0.85;
362 popup.style.backgroundColor="#C0C0C0";
363 popup.style.border="4px solid #404040";
364
365 document.body.appendChild(popup);
366 }
367
368
369 //
370 // Draw a popup - independent of map because want it fixed on screen not fixed on map.
371 //
372
373 function drawPopup(html)
374 {
375 if(html===null)
376 {
377 popup.style.display="none";
378 return;
379 }
380
381 if(popup.style.display=="none")
382 {
383 var map_div=document.getElementById("map");
384
385 popup.style.left =map_div.offsetParent.offsetLeft+map_div.offsetLeft+60 + "px";
386 popup.style.top = map_div.offsetTop +30 + "px";
387 popup.style.width =map_div.clientWidth-120 + "px";
388
389 popup.style.display="";
390 }
391
392 var close="<span style='float: right; cursor: pointer;' onclick='drawPopup(null)'>X</span>";
393
394 popup.innerHTML=close+html;
395 }
396
397
398 //
399 // Select a feature
400 //
401
402 function selectFeature(feature)
403 {
404 if(feature.attributes.dump)
405 ajaxGET("visualiser.cgi?dump=" + feature.attributes.dump, runDumpSuccess);
406
407 layerHighlights.destroyFeatures();
408
409 var highlight_style = new OpenLayers.Style({},{strokeColor: "#F0F000",strokeWidth: 8,
410 fillColor: "#F0F000",pointRadius: 4});
411
412 var highlight = new OpenLayers.Feature.Vector(feature.geometry.clone(),{},highlight_style);
413
414 layerHighlights.addFeatures([highlight]);
415 }
416
417
418 //
419 // Un-select a feature
420 //
421
422 function unselectFeature(feature)
423 {
424 layerHighlights.destroyFeatures();
425
426 drawPopup(null);
427 }
428
429
430 //
431 // Display the dump data
432 //
433
434 function runDumpSuccess(response)
435 {
436 var string=response.responseText;
437
438 if(mapprops.editurl !== undefined && mapprops.editurl !== "")
439 {
440 var types=["node", "way", "relation"];
441 var Types=["Node", "Way", "Relation"];
442
443 for(var t in types)
444 {
445 var Type=Types[t];
446 var type=types[t];
447
448 var regexp=RegExp(Type + " [0-9]+");
449
450 var match;
451
452 while((match=string.match(regexp)) !== null)
453 {
454 match=String(match);
455
456 var id=match.slice(1+type.length,match.length);
457
458 string=string.replace(regexp,Type + " <a href='" + mapprops.browseurl + "/" + type + "/" + id + "' target='" + type + id + "'>" + id + "</a>");
459 }
460 }
461 }
462
463 drawPopup(string.split("\n").join("<br>"));
464 }
465
466
467 ////////////////////////////////////////////////////////////////////////////////
468 /////////////////////////////// Server handling ////////////////////////////////
469 ////////////////////////////////////////////////////////////////////////////////
470
471 //
472 // Define an AJAX request object
473 //
474
475 function ajaxGET(url,success,failure,state)
476 {
477 var ajaxRequest=new XMLHttpRequest();
478
479 function ajaxGOT(options) {
480 if(this.readyState==4)
481 if(this.status==200)
482 { if(typeof(options.success)=="function") options.success(this,options.state); }
483 else
484 { if(typeof(options.failure)=="function") options.failure(this,options.state); }
485 }
486
487 ajaxRequest.onreadystatechange = function(){ ajaxGOT.call(ajaxRequest,{success: success, failure: failure, state: state}); };
488 ajaxRequest.open("GET", url, true);
489 ajaxRequest.send(null);
490 }
491
492
493 //
494 // Display the status
495 //
496
497 function displayStatus(type,subtype,content)
498 {
499 var child=document.getElementById("result_status").firstChild;
500
501 do
502 {
503 if(child.id !== undefined)
504 child.style.display="none";
505
506 child=child.nextSibling;
507 }
508 while(child !== null);
509
510 var chosen_status=document.getElementById("result_status_" + type);
511
512 chosen_status.style.display="";
513
514 if(subtype !== undefined)
515 {
516 var format_status=document.getElementById("result_status_" + subtype).innerHTML;
517
518 chosen_status.innerHTML=format_status.replace("#",String(content));
519 }
520 }
521
522
523 //
524 // Display data statistics
525 //
526
527 function displayStatistics()
528 {
529 // Use AJAX to get the statistics
530
531 ajaxGET("statistics.cgi", runStatisticsSuccess);
532 }
533
534
535 //
536 // Success in running data statistics generation.
537 //
538
539 function runStatisticsSuccess(response)
540 {
541 document.getElementById("statistics_data").innerHTML="<pre>" + response.responseText + "</pre>";
542 document.getElementById("statistics_link").style.display="none";
543 }
544
545
546 //
547 // Get the requested data
548 //
549
550 function displayData(datatype) // called from visualiser.html
551 {
552 for(var data in data_types)
553 hideshow_hide(data_types[data]);
554
555 if(datatype !== "")
556 hideshow_show(datatype);
557
558 // Delete the old data
559
560 unselectFeature();
561
562 select.deactivate();
563
564 layerVectors.destroyFeatures();
565 layerHighlights.destroyFeatures();
566
567 if(box !== null)
568 layerBoxes.removeMarker(box);
569 box=null;
570
571 // Print the status
572
573 displayStatus("no_data");
574
575 // Return if just here to clear the data
576
577 if(datatype === "")
578 return;
579
580 // Get the new data
581
582 var mapbounds=map.getExtent().clone();
583 mapbounds.transform(epsg900913,epsg4326);
584
585 var url="visualiser.cgi";
586
587 url=url + "?lonmin=" + format5f(mapbounds.left);
588 url=url + ";latmin=" + format5f(mapbounds.bottom);
589 url=url + ";lonmax=" + format5f(mapbounds.right);
590 url=url + ";latmax=" + format5f(mapbounds.top);
591 url=url + ";data=" + datatype;
592
593 // Use AJAX to get the data
594
595 switch(datatype)
596 {
597 case "junctions":
598 ajaxGET(url, runJunctionsSuccess, runFailure);
599 break;
600 case "super":
601 ajaxGET(url, runSuperSuccess, runFailure);
602 break;
603 case "waytype":
604 var waytype;
605 var waytypes=document.forms["waytypes"].elements["waytype"];
606 for(var h in waytypes)
607 if(waytypes[h].checked)
608 waytype=waytypes[h].value;
609 url+="-" + waytype;
610 ajaxGET(url, runWaytypeSuccess, runFailure);
611 break;
612 case "highway":
613 var highway;
614 var highways=document.forms["highways"].elements["highway"];
615 for(var h in highways)
616 if(highways[h].checked)
617 highway=highways[h].value;
618 url+="-" + highway;
619 ajaxGET(url, runHighwaySuccess, runFailure);
620 break;
621 case "transport":
622 var transport;
623 var transports=document.forms["transports"].elements["transport"];
624 for(var t in transports)
625 if(transports[t].checked)
626 transport=transports[t].value;
627 url+="-" + transport;
628 ajaxGET(url, runTransportSuccess, runFailure);
629 break;
630 case "destination":
631 var transport;
632 var transports=document.forms["destinations"].elements["destination"];
633 for(var t in transports)
634 if(transports[t].checked)
635 transport=transports[t].value;
636 url+="-" + transport;
637 ajaxGET(url, runTransportSuccess, runFailure);
638 break;
639 case "barrier":
640 var transport;
641 var transports=document.forms["barriers"].elements["barrier"];
642 for(var t in transports)
643 if(transports[t].checked)
644 transport=transports[t].value;
645 url+="-" + transport;
646 ajaxGET(url, runBarrierSuccess, runFailure);
647 break;
648 case "turns":
649 ajaxGET(url, runTurnsSuccess, runFailure);
650 break;
651 case "speed":
652 case "weight":
653 case "height":
654 case "width":
655 case "length":
656 ajaxGET(url, runLimitSuccess, runFailure);
657 break;
658 case "property":
659 var property;
660 var properties=document.forms["properties"].elements["property"];
661 for(var p in properties)
662 if(properties[p].checked)
663 property=properties[p].value;
664 url+="-" + property;
665 ajaxGET(url, runPropertySuccess, runFailure);
666 break;
667 case "errorlogs":
668 ajaxGET(url, runErrorlogSuccess, runFailure);
669 break;
670 }
671 }
672
673
674 //
675 // Success in getting the junctions.
676 //
677
678 function runJunctionsSuccess(response)
679 {
680 var lines=response.responseText.split("\n");
681
682 var junction_colours={
683 0: "#FFFFFF",
684 1: "#FF0000",
685 2: "#FFFF00",
686 3: "#00FF00",
687 4: "#8B4513",
688 5: "#00BFFF",
689 6: "#FF69B4",
690 7: "#000000",
691 8: "#000000",
692 9: "#000000"
693 };
694
695 var styles={};
696
697 for(var colour in junction_colours)
698 styles[colour]=new OpenLayers.Style({},{stroke: false,
699 pointRadius: 2,fillColor: junction_colours[colour],
700 cursor: "pointer"});
701
702 var features=[];
703
704 for(var line=0;line<lines.length;line++)
705 {
706 var words=lines[line].split(" ");
707
708 if(line === 0)
709 {
710 var lat1=words[0];
711 var lon1=words[1];
712 var lat2=words[2];
713 var lon2=words[3];
714
715 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
716
717 box = new OpenLayers.Marker.Box(bounds);
718
719 layerBoxes.addMarker(box);
720 }
721 else if(words[0] !== "")
722 {
723 var dump=words[0];
724 var lat=words[1];
725 var lon=words[2];
726 var count=words[3];
727
728 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
729
730 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
731
732 features.push(new OpenLayers.Feature.Vector(point,{dump: dump},styles[count]));
733 }
734 }
735
736 select.activate();
737
738 layerVectors.addFeatures(features);
739
740 displayStatus("data","junctions",lines.length-2);
741 }
742
743
744 //
745 // Success in getting the super-node and super-segments
746 //
747
748 function runSuperSuccess(response)
749 {
750 var lines=response.responseText.split("\n");
751
752 var node_style = new OpenLayers.Style({},{stroke: false,
753 pointRadius: 4,fillColor: "#FF0000",
754 cursor: "pointer"});
755
756 var segment_style = new OpenLayers.Style({},{fill: false,
757 strokeWidth: 2,strokeColor: "#FF0000",
758 cursor: "pointer"});
759
760 var features=[];
761
762 var nodepoint;
763
764 for(var line=0;line<lines.length;line++)
765 {
766 var words=lines[line].split(" ");
767
768 if(line === 0)
769 {
770 var lat1=words[0];
771 var lon1=words[1];
772 var lat2=words[2];
773 var lon2=words[3];
774
775 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
776
777 box = new OpenLayers.Marker.Box(bounds);
778
779 layerBoxes.addMarker(box);
780 }
781 else if(words[0] !== "")
782 {
783 var dump=words[0];
784 var lat=words[1];
785 var lon=words[2];
786
787 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
788
789 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
790
791 if(dump.charAt(0) == "n")
792 {
793 nodepoint=point;
794
795 features.push(new OpenLayers.Feature.Vector(point,{dump: dump},node_style));
796 }
797 else
798 {
799 var segment = new OpenLayers.Geometry.LineString([nodepoint,point]);
800
801 features.push(new OpenLayers.Feature.Vector(segment,{dump: dump},segment_style));
802 }
803 }
804 }
805
806 select.activate();
807
808 layerVectors.addFeatures(features);
809
810 displayStatus("data","super",lines.length-2);
811 }
812
813
814 //
815 // Success in getting the waytype data
816 //
817
818 function runWaytypeSuccess(response)
819 {
820 var hex={0: "00", 1: "11", 2: "22", 3: "33", 4: "44", 5: "55", 6: "66", 7: "77",
821 8: "88", 9: "99", 10: "AA", 11: "BB", 12: "CC", 13: "DD", 14: "EE", 15: "FF"};
822
823 var lines=response.responseText.split("\n");
824
825 var features=[];
826
827 for(var line=0;line<lines.length;line++)
828 {
829 var words=lines[line].split(" ");
830
831 if(line === 0)
832 {
833 var lat1=words[0];
834 var lon1=words[1];
835 var lat2=words[2];
836 var lon2=words[3];
837
838 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
839
840 box = new OpenLayers.Marker.Box(bounds);
841
842 layerBoxes.addMarker(box);
843 }
844 else if(words[0] !== "")
845 {
846 var dump=words[0];
847 var lat1=words[1];
848 var lon1=words[2];
849 var lat2=words[3];
850 var lon2=words[4];
851
852 var lonlat1 = new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
853 var lonlat2 = new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
854
855 //var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
856 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
857
858 var dlat = lonlat2.lat-lonlat1.lat;
859 var dlon = lonlat2.lon-lonlat1.lon;
860 var dist = Math.sqrt(dlat*dlat+dlon*dlon)/10;
861 var ang = Math.atan2(dlat,dlon);
862
863 var point3 = new OpenLayers.Geometry.Point(lonlat1.lon+dlat/dist,lonlat1.lat-dlon/dist);
864 var point4 = new OpenLayers.Geometry.Point(lonlat1.lon-dlat/dist,lonlat1.lat+dlon/dist);
865
866 var r=Math.round(7.5+7.9*Math.cos(ang));
867 var g=Math.round(7.5+7.9*Math.cos(ang+2.0943951));
868 var b=Math.round(7.5+7.9*Math.cos(ang-2.0943951));
869 var colour = "#" + hex[r] + hex[g] + hex[b];
870
871 var segment = new OpenLayers.Geometry.LineString([point2,point3,point4,point2]);
872
873 var style=new OpenLayers.Style({},{strokeWidth: 2,strokeColor: colour, cursor: "pointer"});
874
875 features.push(new OpenLayers.Feature.Vector(segment,{dump: dump},style));
876 }
877 }
878
879 select.activate();
880
881 layerVectors.addFeatures(features);
882
883 displayStatus("data","waytype",lines.length-2);
884 }
885
886
887 //
888 // Success in getting the highway data
889 //
890
891 function runHighwaySuccess(response)
892 {
893 var lines=response.responseText.split("\n");
894
895 var style = new OpenLayers.Style({},{fill: false,
896 strokeWidth: 2,strokeColor: "#FF0000",
897 cursor: "pointer"});
898
899 var features=[];
900
901 for(var line=0;line<lines.length;line++)
902 {
903 var words=lines[line].split(" ");
904
905 if(line === 0)
906 {
907 var lat1=words[0];
908 var lon1=words[1];
909 var lat2=words[2];
910 var lon2=words[3];
911
912 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
913
914 box = new OpenLayers.Marker.Box(bounds);
915
916 layerBoxes.addMarker(box);
917 }
918 else if(words[0] !== "")
919 {
920 var dump=words[0];
921 var lat1=words[1];
922 var lon1=words[2];
923 var lat2=words[3];
924 var lon2=words[4];
925
926 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
927 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
928
929 var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
930 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
931
932 var segment = new OpenLayers.Geometry.LineString([point1,point2]);
933
934 features.push(new OpenLayers.Feature.Vector(segment,{dump: dump},style));
935 }
936 }
937
938 select.activate();
939
940 layerVectors.addFeatures(features);
941
942 displayStatus("data","highway",lines.length-2);
943 }
944
945
946 //
947 // Success in getting the transport data
948 //
949
950 function runTransportSuccess(response)
951 {
952 var lines=response.responseText.split("\n");
953
954 var style = new OpenLayers.Style({},{fill: false,
955 strokeWidth: 2,strokeColor: "#FF0000",
956 cursor: "pointer"});
957
958 var features=[];
959
960 for(var line=0;line<lines.length;line++)
961 {
962 var words=lines[line].split(" ");
963
964 if(line === 0)
965 {
966 var lat1=words[0];
967 var lon1=words[1];
968 var lat2=words[2];
969 var lon2=words[3];
970
971 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
972
973 box = new OpenLayers.Marker.Box(bounds);
974
975 layerBoxes.addMarker(box);
976 }
977 else if(words[0] !== "")
978 {
979 var dump=words[0];
980 var lat1=words[1];
981 var lon1=words[2];
982 var lat2=words[3];
983 var lon2=words[4];
984
985 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
986 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
987
988 var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
989 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
990
991 var segment = new OpenLayers.Geometry.LineString([point1,point2]);
992
993 features.push(new OpenLayers.Feature.Vector(segment,{dump: dump},style));
994 }
995 }
996
997 select.activate();
998
999 layerVectors.addFeatures(features);
1000
1001 displayStatus("data","transport",lines.length-2);
1002 }
1003
1004
1005 //
1006 // Success in getting the barrier data
1007 //
1008
1009 function runBarrierSuccess(response)
1010 {
1011 var lines=response.responseText.split("\n");
1012
1013 var style = new OpenLayers.Style({},{stroke: false,
1014 pointRadius: 3,fillColor: "#FF0000",
1015 cursor: "pointer"});
1016
1017 var features=[];
1018
1019 for(var line=0;line<lines.length;line++)
1020 {
1021 var words=lines[line].split(" ");
1022
1023 if(line === 0)
1024 {
1025 var lat1=words[0];
1026 var lon1=words[1];
1027 var lat2=words[2];
1028 var lon2=words[3];
1029
1030 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
1031
1032 box = new OpenLayers.Marker.Box(bounds);
1033
1034 layerBoxes.addMarker(box);
1035 }
1036 else if(words[0] !== "")
1037 {
1038 var dump=words[0];
1039 var lat=words[1];
1040 var lon=words[2];
1041
1042 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
1043
1044 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
1045
1046 features.push(new OpenLayers.Feature.Vector(point,{dump: dump},style));
1047 }
1048 }
1049
1050 select.activate();
1051
1052 layerVectors.addFeatures(features);
1053
1054 displayStatus("data","barrier",lines.length-2);
1055 }
1056
1057
1058 //
1059 // Success in getting the turn restrictions data
1060 //
1061
1062 function runTurnsSuccess(response)
1063 {
1064 var lines=response.responseText.split("\n");
1065
1066 var style = new OpenLayers.Style({},{fill: false,
1067 strokeWidth: 2,strokeColor: "#FF0000",
1068 cursor: "pointer"});
1069
1070 var features=[];
1071
1072 for(var line=0;line<lines.length;line++)
1073 {
1074 var words=lines[line].split(" ");
1075
1076 if(line === 0)
1077 {
1078 var lat1=words[0];
1079 var lon1=words[1];
1080 var lat2=words[2];
1081 var lon2=words[3];
1082
1083 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
1084
1085 box = new OpenLayers.Marker.Box(bounds);
1086
1087 layerBoxes.addMarker(box);
1088 }
1089 else if(words[0] !== "")
1090 {
1091 var dump=words[0];
1092 var lat1=words[1];
1093 var lon1=words[2];
1094 var lat2=words[3];
1095 var lon2=words[4];
1096 var lat3=words[5];
1097 var lon3=words[6];
1098
1099 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
1100 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
1101 var lonlat3= new OpenLayers.LonLat(lon3,lat3).transform(epsg4326,epsg900913);
1102
1103 var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
1104 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
1105 var point3 = new OpenLayers.Geometry.Point(lonlat3.lon,lonlat3.lat);
1106
1107 var segments = new OpenLayers.Geometry.LineString([point1,point2,point3]);
1108
1109 features.push(new OpenLayers.Feature.Vector(segments,{dump: dump},style));
1110 }
1111 }
1112
1113 select.activate();
1114
1115 layerVectors.addFeatures(features);
1116
1117 displayStatus("data","turns",lines.length-2);
1118 }
1119
1120
1121 //
1122 // Success in getting the speed/weight/height/width/length limits
1123 //
1124
1125 function runLimitSuccess(response)
1126 {
1127 var lines=response.responseText.split("\n");
1128
1129 var node_style = new OpenLayers.Style({},{stroke: false,
1130 pointRadius: 3,fillColor: "#FF0000",
1131 cursor: "pointer"});
1132
1133 var segment_style = new OpenLayers.Style({},{fill: false,
1134 strokeWidth: 2,strokeColor: "#FF0000",
1135 cursor: "pointer"});
1136
1137 var features=[];
1138
1139 var nodepoint;
1140 var nodelonlat;
1141
1142 for(var line=0;line<lines.length;line++)
1143 {
1144 var words=lines[line].split(" ");
1145
1146 if(line === 0)
1147 {
1148 var lat1=words[0];
1149 var lon1=words[1];
1150 var lat2=words[2];
1151 var lon2=words[3];
1152
1153 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
1154
1155 box = new OpenLayers.Marker.Box(bounds);
1156
1157 layerBoxes.addMarker(box);
1158 }
1159 else if(words[0] !== "")
1160 {
1161 var dump=words[0];
1162 var lat=words[1];
1163 var lon=words[2];
1164 var number=words[3];
1165
1166 var lonlat= new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
1167
1168 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
1169
1170 if(number === undefined)
1171 {
1172 nodelonlat=lonlat;
1173 nodepoint = point;
1174
1175 features.push(new OpenLayers.Feature.Vector(point,{dump: dump},node_style));
1176 }
1177 else
1178 {
1179 var segment = new OpenLayers.Geometry.LineString([nodepoint,point]);
1180
1181 features.push(new OpenLayers.Feature.Vector(segment,{dump: dump},segment_style));
1182
1183 var dlat = lonlat.lat-nodelonlat.lat;
1184 var dlon = lonlat.lon-nodelonlat.lon;
1185 var dist = Math.sqrt(dlat*dlat+dlon*dlon)/120;
1186
1187 point = new OpenLayers.Geometry.Point(nodelonlat.lon+dlon/dist,nodelonlat.lat+dlat/dist);
1188
1189 features.push(new OpenLayers.Feature.Vector(point,{dump: dump},
1190 new OpenLayers.Style({},{externalGraphic: "icons/limit-" + number + ".png",
1191 graphicYOffset: -9,
1192 graphicWidth: 19,
1193 graphicHeight: 19})));
1194 }
1195 }
1196 }
1197
1198 select.activate();
1199
1200 layerVectors.addFeatures(features);
1201
1202 displayStatus("data","limit",lines.length-2);
1203 }
1204
1205
1206 //
1207 // Success in getting the property data
1208 //
1209
1210 function runPropertySuccess(response)
1211 {
1212 var lines=response.responseText.split("\n");
1213
1214 var style = new OpenLayers.Style({},{fill: false,
1215 strokeWidth: 2,strokeColor: "#FF0000",
1216 cursor: "pointer"});
1217
1218 var features=[];
1219
1220 for(var line=0;line<lines.length;line++)
1221 {
1222 var words=lines[line].split(" ");
1223
1224 if(line === 0)
1225 {
1226 var lat1=words[0];
1227 var lon1=words[1];
1228 var lat2=words[2];
1229 var lon2=words[3];
1230
1231 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
1232
1233 box = new OpenLayers.Marker.Box(bounds);
1234
1235 layerBoxes.addMarker(box);
1236 }
1237 else if(words[0] !== "")
1238 {
1239 var dump=words[0];
1240 var lat1=words[1];
1241 var lon1=words[2];
1242 var lat2=words[3];
1243 var lon2=words[4];
1244
1245 var lonlat1= new OpenLayers.LonLat(lon1,lat1).transform(epsg4326,epsg900913);
1246 var lonlat2= new OpenLayers.LonLat(lon2,lat2).transform(epsg4326,epsg900913);
1247
1248 var point1 = new OpenLayers.Geometry.Point(lonlat1.lon,lonlat1.lat);
1249 var point2 = new OpenLayers.Geometry.Point(lonlat2.lon,lonlat2.lat);
1250
1251 var segment = new OpenLayers.Geometry.LineString([point1,point2]);
1252
1253 features.push(new OpenLayers.Feature.Vector(segment,{dump: dump},style));
1254 }
1255 }
1256
1257 select.activate();
1258
1259 layerVectors.addFeatures(features);
1260
1261 displayStatus("data","property",lines.length-2);
1262 }
1263
1264
1265 //
1266 // Success in getting the error log data
1267 //
1268
1269 function runErrorlogSuccess(response)
1270 {
1271 var lines=response.responseText.split("\n");
1272
1273 var style = new OpenLayers.Style({},{stroke: false,
1274 pointRadius: 3,fillColor: "#FF0000",
1275 cursor: "pointer"});
1276
1277 var features=[];
1278
1279 for(var line=0;line<lines.length;line++)
1280 {
1281 var words=lines[line].split(" ");
1282
1283 if(line === 0)
1284 {
1285 var lat1=words[0];
1286 var lon1=words[1];
1287 var lat2=words[2];
1288 var lon2=words[3];
1289
1290 var bounds = new OpenLayers.Bounds(lon1,lat1,lon2,lat2).transform(epsg4326,epsg900913);
1291
1292 box = new OpenLayers.Marker.Box(bounds);
1293
1294 layerBoxes.addMarker(box);
1295 }
1296 else if(words[0] !== "")
1297 {
1298 var dump=words[0];
1299 var lat=words[1];
1300 var lon=words[2];
1301
1302 var lonlat = new OpenLayers.LonLat(lon,lat).transform(epsg4326,epsg900913);
1303
1304 var point = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
1305
1306 features.push(new OpenLayers.Feature.Vector(point,{dump: dump},style));
1307 }
1308 }
1309
1310 select.activate();
1311
1312 layerVectors.addFeatures(features);
1313
1314 displayStatus("data","errorlogs",lines.length-2);
1315 }
1316
1317
1318 //
1319 // Failure in getting data.
1320 //
1321
1322 function runFailure(response)
1323 {
1324 displayStatus("failed");
1325 }