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