// // Routino (extras) fixme web page Javascript // // Part of the Routino routing software. // // This file Copyright 2008-2014, 2019, 2020 Andrew M. Bishop // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // //////////////////////////////////////////////////////////////////////////////// /////////////////////////////// Initialisation ///////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Process the URL query string and extract the arguments var legal={"^lon" : "^[-0-9.]+$", "^lat" : "^[-0-9.]+$", "^zoom" : "^[-0-9.]+$"}; var args={}; if(location.search.length>1) { var query,queries; query=location.search.replace(/^\?/,""); query=query.replace(/;/g,"&"); queries=query.split("&"); for(var i=0;i" + data_text + ""; document.getElementById("attribution_tile").innerHTML="" + tile_text + ""; } change_attribution(0); // Add two vectors layers (one for highlights that display behind the vectors) layerVectors = L.layerGroup(); map.addLayer(layerVectors); layerHighlights = L.layerGroup(); map.addLayer(layerHighlights); // Handle popup createPopup(); // Move the map map.on("moveend", (function() { displayMoreData();})); var lon =args["lon"]; var lat =args["lat"]; var zoom=args["zoom"]; if(lon !== undefined && lat !== undefined && zoom !== undefined) { lat = Number(lat); lon = Number(lon); zoom = Number.parseInt(Number(zoom)+0.5); if(lonmapprops.eastedge) lon=mapprops.eastedge; if(latmapprops.northedge) lat=mapprops.northedge; if(zoommapprops.zoomin) zoom=mapprops.zoomin; map.setView(L.latLng(lat,lon),zoom); } else map.fitBounds(map.options.maxBounds); // Unhide editing URL if variable set if(mapprops.editurl !== undefined && mapprops.editurl !== "") { var edit_url=document.getElementById("edit_url"); edit_url.style.display=""; edit_url.href=mapprops.editurl; } updateURLs(false); } // // Format a number in printf("%.5f") format. // function format5f(number) { var newnumber=Math.floor(number*100000+0.5); var delta=0; if(newnumber>=0 && newnumber<100000) delta= 100000; if(newnumber<0 && newnumber>-100000) delta=-100000; var string=String(newnumber+delta); var intpart =string.substring(0,string.length-5); var fracpart=string.substring(string.length-5,string.length); if(delta>0) intpart="0"; if(delta<0) intpart="-0"; return(intpart + "." + fracpart); } // // Build a set of URL arguments for the map location // function buildMapArguments() { var lonlat = map.getCenter(); var zoom = map.getZoom(); return "lat=" + format5f(lonlat.lat) + ";lon=" + format5f(lonlat.lng) + ";zoom=" + zoom; } // // Update the URLs // function updateURLs(addhistory) { var mapargs=buildMapArguments(); var libargs=";library=" + mapprops.library; if(!mapprops.libraries) libargs=""; var links=document.getElementsByTagName("a"); for(var i=0; i" + id + "'"); } } } drawPopup(string.split("><").join(">
<").split("
<tag").join("
  <tag")); } //////////////////////////////////////////////////////////////////////////////// /////////////////////////////// Server handling //////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // Define an AJAX request object // function ajaxGET(url,success,failure,state) { var ajaxRequest=new XMLHttpRequest(); function ajaxGOT(options) { if(this.readyState==4) if(this.status==200) { if(typeof(options.success)=="function") options.success(this,options.state); } else { if(typeof(options.failure)=="function") options.failure(this,options.state); } } ajaxRequest.onreadystatechange = function(){ ajaxGOT.call(ajaxRequest,{success: success, failure: failure, state: state}); }; ajaxRequest.open("GET", url, true); ajaxRequest.send(null); } // // Display the status // function displayStatus(type,subtype,content) { var child=document.getElementById("result_status").firstChild; do { if(child.id !== undefined) child.style.display="none"; child=child.nextSibling; } while(child !== null); var chosen_status=document.getElementById("result_status_" + type); chosen_status.style.display=""; if(subtype !== undefined) { var format_status=document.getElementById("result_status_" + subtype).innerHTML; chosen_status.innerHTML=format_status.replace("#",String(content)); } } // // Display data statistics // function displayStatistics() { // Use AJAX to get the statistics ajaxGET("fixme.cgi?statistics=yes", runStatisticsSuccess); } // // Success in running data statistics generation. // function runStatisticsSuccess(response) { document.getElementById("statistics_data").innerHTML="
" + response.responseText + "
"; document.getElementById("statistics_link").style.display="none"; } // // Get the requested data // function displayData(datatype) // called from fixme.html { // Delete the old data vectorData=[]; unselectFeature(); layerVectors.clearLayers(); // Print the status displayStatus("no_data"); // Return if just here to clear the data if(datatype === "") return; displayMoreData(); } function displayMoreData() { // Get the new data var mapbounds=map.getBounds(); var url="fixme.cgi"; url=url + "?lonmin=" + format5f(mapbounds.getWest()); url=url + ";latmin=" + format5f(mapbounds.getSouth()); url=url + ";lonmax=" + format5f(mapbounds.getEast()); url=url + ";latmax=" + format5f(mapbounds.getNorth()); url=url + ";data=fixmes"; // Use AJAX to get the data ajaxGET(url, runFixmeSuccess, runFailure); updateURLs(true); } // // Success in getting the error log data // function runFixmeSuccess(response) { var lines=response.responseText.split("\n"); for(var line=0;line