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 2085 - (show annotations) (download) (as text)
Sat Nov 21 16:10:04 2020 UTC (4 years, 3 months ago) by amb
File MIME type: application/javascript
File size: 35211 byte(s)
Merge from trunk [update leaflet and openlayers versions].

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