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.openlayers2.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2075 - (show annotations) (download) (as text)
Sat Nov 14 16:08:29 2020 UTC (4 years, 4 months ago) by amb
File MIME type: application/javascript
File size: 34680 byte(s)
Update the visualiser/fixme data as you move around the map.

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