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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1491 - (show annotations) (download) (as text)
Sat Jan 25 14:11:06 2014 UTC (11 years, 1 month ago) by amb
File MIME type: application/javascript
File size: 30175 byte(s)
Add the option to use Leaflet Javascript library instead of OpenLayers.
Dynamically load the appropriate Javascript library based on mapprops.js.

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