var map; var municipalitiesTagMap = {}; var municipalitiesInfoByCountry = new Array(); var municipalitiesInfo = {}; var countryPolygons = {}; var country = null; var infoWindow; var coordfilename = "liten.json.sverige"; var opacityOfPolygon = 0.8; var today = new Date(new Date().getTime()); var dd = today.getDate(); var mm = today.getMonth() + 1; var yyyy = today.getFullYear(); if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } today = yyyy + "-" + mm + "-" + dd; var lastSelectedDate = today; var municipalitiesByCountry = {}; var municipalities = new Array(); // loads map data function loadData(date) { $("#loader").show(); if (typeof date == 'undefined') date = lastSelectedDate; // coordfilename = "liten.json."+country.country; // coordfilename = "liten.json.sverige"; if(municipalitiesByCountry[country.code] == null) loadMap(country.code); // loadInfo(date, country.code); loadInfo(date, 1); loadList(country.code); } // refreshes map view function reloadAll(date) { if (typeof date == 'undefined') date = lastSelectedDate; countries = {}; var boxes = document.getElementsByName('country[]'); $.each(boxes, function(index, box) { if (this.checked == true) { clearMap(box.value); countries[box.value] = new Object({ country: box.id, code: box.value }); } }); $.each(countries, function() { country = new Object({ country: this.country, code: this.code }); loadData(date); }); } // initializes map and datepicker $(function () { if(preSelect == "") preSelect = "sverige"; $("#tabs input").prop("checked", false); $("."+preSelect).prop("checked", true); country = new Object({ country: $("#"+preSelect).attr('id'), code: $("#"+preSelect).attr('value') }); $("#tabs").tabs({ show: function () { }, select: function(event, ui) { reloadAll(); } }); $("#datepicker").datepicker({ maxDate: '-0d', defaultDate: -0, autoSize: true, firstDay: 1, dateFormat: 'yy-mm-dd', onSelect: function (dateText, inst) { $("#loader").show(); lastSelectedDate = dateText; reloadAll(dateText); }, monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'], monthNamesShort : ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], }); // var mapOptions = { // center: new google.maps.LatLng(63.027722, 15.58136), // zoom: 5, // mapTypeId: google.maps.MapTypeId.ROADMAP, // rotateControl: false, // overviewMapControl: false, // streetViewControl: false, // panControl: false, // mapTypeControl: false //}; // map = new google.maps.Map(document.getElementById("map_canvas"), // mapOptions); //OpenStreetMap var map = L.map('map').setView([63, 15], 5); L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiYWluYWxpIiwiYSI6ImNpbHByY2F1NjAwNDJ2c2x5cWF4MzZqMzIifQ.vF1prEJwU_1QSmNSWh5-fQ', { maxZoom: 18, attribution: 'Map data © OpenStreetMap contributors, ' + 'CC-BY-SA, ' + 'Imagery © Mapbox', id: 'mapbox.streets' }).addTo(map); loadData(); }); // loads municipalities map data function loadMap(code) { municipalities = new Array(); $.ajax({ async: false, type: "GET", url: coordfilename + "?_=" + new Date().getTime(), dataType: "json", success: function (d) { if(d.features) { $(d.features).each(function () { municipalities.push(this); }); } if(d.municipalities) { $(d.municipalities.municipality).each(function () { municipalities.push(this); }); } }, complete: function() { municipalitiesByCountry[code] = municipalities; } }); } // loads municipalities status data function loadInfo(date, code) { municipalitiesInfo = {}; $.ajax({ async: false, type: "GET", url: "createJson.php?date=" + date + "&code=" + code, dataType: "json", cache: false, contentType: "application/json", success: function (data) { $(data.municipalities.municipality).each(function () { municipalitiesInfo[this.knnr] = this; }); }, error: function (xhr, status, error) { $("#loader").hide(); }, complete: function() { municipalitiesInfoByCountry[code] = municipalitiesInfo; } }); } var cntTotalDomains = 0; var cntpm25_realtime = 0; var cntpm25_yearly = 0; var cntpm25_highres = 0; var cntpm25_y2y = 0; var cntpm25_density = 0; // adds polygon for each municipality loaded function loadList(code) { setTimeout(function () { cntTotalDomains = 0; cntpm25_realtime = 0; cntpm25_yearly = 0; cntpm25_highres = 0; cntpm25_y2y = 0; cntpm25_density = 0; countryPolygons[code] = {}; $.each(municipalitiesByCountry[code], function () { $(this).each(function () { addPolygon(this, code); }); }); var pm25CheckInfoString = "[MISSING: PM25CHECK_RESULT:1]"; pm25CheckInfoString = pm25CheckInfoString.replace(/\{0\}/, cntTotalDomains.toString()); pm25CheckInfoString = pm25CheckInfoString.replace(/\{1\}/, lastSelectedDate); pm25CheckInfoString = pm25CheckInfoString.replace(/\{2\}/, cntpm25_density.toString()); pm25CheckInfoString = pm25CheckInfoString.replace(/\{3\}/, cntpm25_y2y.toString()); pm25CheckInfoString = pm25CheckInfoString.replace(/\{4\}/, cntpm25_highres.toString()); pm25CheckInfoString = pm25CheckInfoString.replace(/\{5\}/, cntpm25_yearly.toString()); setTimeout(function () { $("#loader").hide(); }, 1); statistics(); }, 1); } // prints statistics of secured municipalities function statistics() { var totalDomains = 0; var pm10Domains = 0; //secureDomains blir pm10Domains var pm25Domains = 0; //ipv6Domains blir pm25Domains $("#tabs").tabs().tabs('option', 'selected') == 0 ? tab = 0 : tab = 1; if(tab == 0) var stats = "{0} of {1} municipalities secured."; else var stats = "{0} of {1} municipalities have complete data."; var boxes = document.getElementsByName('country[]'); $.each(boxes, function(index, box) { if (this.checked == true) { $.each(countryPolygons[this.value], function() { totalDomains++; if(this[0].secure) pm10Domains++; if(this[0].ipv6) pm25Domains++; }); } }); if(tab == 0) stats = stats.replace(/\{0\}/, pm10Domains); else stats = stats.replace(/\{0\}/, pm25Domains); stats = stats.replace(/\{1\}/, totalDomains); $('#statistics').text(stats); } // function that actually adds the polygons to the map function addPolygon(municipality, code) { var secure = true; var ipv6 = true; if (typeof municipality.knnr !== 'undefined') var knnr = municipality.knnr.toString(); if (typeof municipality.properties !== 'undefined') { if(typeof municipality.properties.code !== 'undefined') { var knnr = municipality.properties.code.toString(); } if (typeof municipality.properties.KOMKODE !== 'undefined') { var knnr = municipality.properties.KOMKODE.toString(); } if (typeof municipality.properties.KOMM !== 'undefined') { var knnr = municipality.properties.KOMM.toString(); } } var info = municipalitiesInfoByCountry[code][knnr]; var polyCoords = new Array(); if (info != null) { cntTotalDomains++; try{ if( info.realtime25.length == 1) {cntpm25_realtime++;secure = false} if( info.yearly25 == 1) cntpm25_yearly++; else secure = false; if( info.highres25.length > 0) {cntpm25_highres++;secure = false} if( info.y2y25.length > 0) {cntpm25_y2y++;secure = false} if( info.density25 == 1) {cntpm25_density++;secure = false} } catch(e){} // depending on the structure of the data in the municipalities' coordinates files different // methods for extracting the data is used if(typeof municipality.geometry !== 'undefined') { if(typeof municipality.geometry.geometries !== 'undefined') { $(eval(municipality.geometry.geometries)).each(function () { $(eval(this)).each(function () { $(eval(this.coordinates)).each(function () { $(eval(this)).each(function () { lat = this[1]; lng = this[0]; polyCoords.push(new google.maps.LatLng(lat, lng)); }); }); }); }); } if (typeof municipality.geometry.coordinates !== 'undefined') { $(eval(municipality.geometry.coordinates)).each(function () { if(municipality.geometry.type == 'MultiPolygon') { $(eval(this)).each(function () { $(eval(this)).each(function () { lat = this[1]; lng = this[0]; polyCoords.push(new google.maps.LatLng(lat, lng)); }); }); } else { $(eval(this)).each(function () { lat = this[1]; lng = this[0]; polyCoords.push(new google.maps.LatLng(lat, lng)); }); } }); } } if (typeof municipality.coords !== 'undefined') { $(eval(municipality.coords)).each(function () { var lat_long = this.toString().split(','); lat = lat_long[0]; lng = lat_long[1]; polyCoords.push(new google.maps.LatLng(lat, lng)); }); } var hasYearly25 = (info.yearly25 != null && $(info.yearly25).size() > 0); var hasY2y25 = (info.y2y25 != null && $(info.y2y25).size() > 0); var isComplete25 = $("#complete25").is(':checked'); var show = true; var color = "fff"; // the polygons are colored and shown depending on which filters are selected if ($("#tabs").tabs().tabs('option', 'selected') == 0) { show = !$("#complete25").is(':checked') && !$("#highres25").is(':checked') && !$("#y2y25").is(':checked') && !$("#yearly25").is(':checked'); var noneSelected = $("#tabs input[value='realtime25']:checked").size()- $("#tabs input#complete25[type='checkbox']:checked").size() == 0; if (($("#highres25").is(':checked') || noneSelected) && !hasYearly25 && !hasWarnings) { show = true; if (info.y2y25 == 1) color = "0f0"; else color = "eaea6a"; // unsigned but without error if (isComplete25 && info.y2y25 != 1) show = false; } if (($("#y2y25").is(':checked') || noneSelected) && hasY2y25) { show = true; color = "f90" if (isComplete25 && info.y2y25 != 1) show = false; } if (($("#yearly25").is(':checked') || noneSelected) && hasYearly25) { show = true; color = "f00" if (isComplete25 && info.y2y25 != 1) show = false; } } if ($("#tabs").tabs().tabs('option', 'selected') == 1) { show = true; if ($("#pm25_realtime").is(':checked') && info.realtime25 != 1) { show = false; } if ($("#pm25_yearly").is(':checked') && info.yearly25 != 1) { show = false; } if ($("#pm25_highres").is(':checked') && info.highres25 != 1) { show = false; } color = "0f0"; if (info.realtime25 != 1 || info.yearly25 != 1 || info.highres25 != 1) {color = "f90"; ipv6 = false;} if (info.realtime25 != 1 && info.yearly25 != 1 && info.highres25 != 1) {color = "f00"; ipv6 = false;} } // adds a municipality's polygons to an array because some municipalities have areas not connected by land function createPolygon() { countryPolygons[code][info.knnr] = new Array(new google.maps.Polygon({ paths: polyCoords, strokeColor: "#000", strokeOpacity: 0.8, strokeWeight: color == "fff" ? 0.5 : 0.5, fillColor: "#" + color, fillOpacity: color == "fff" ? 0 : opacityOfPolygon, countryCode: code, pm10: pm10, pm25: pm25 })); countryPolygons[code][info.knnr].slice(-1).pop().setMap(map); } function pushPolygon() { countryPolygons[code][info.knnr].push(new google.maps.Polygon({ paths: polyCoords, strokeColor: "#000", strokeOpacity: 0.8, strokeWeight: color == "fff" ? 0.5 : 0.5, fillColor: "#" + color, fillOpacity: color == "fff" ? 0 : opacityOfPolygon, countryCode: code, pm10: pm10, pm25: pm25 })); countryPolygons[code][info.knnr].slice(-1).pop().setMap(map); } if (countryPolygons[code][info.knnr] == null) { createPolygon(); } else { pushPolygon(); } if (!show) { if (typeof countryPolygons[code][info.knnr] !== 'undefined') { $.each(countryPolygons[code][info.knnr], function() { this.setOptions({ fillOpacity: 0.0, strokeWeight: 0.5 }); }); } } // click listener on the map to show info of municipalities google.maps.event.addListener(countryPolygons[code][info.knnr].slice(-1).pop(), "click", function (event) { var vertices = this.getPath(); var contentString = "

" + (info == null ? knnr : info.name) + "

"; var pm25String = "Without remarks in DNSCheck but not signed"; if (info.yearly25 == 1) pm25String = "Signed with DNSSEC and without remarks"; if (info.yearly25 == 1 && hasY2y25) pm25String = "Signed with DNSSEC but with warnings"; if (info.yearly25 != 1 && (hasY2y25 || hasYearly25)) pm25String = "Warnings in DNSCheck"; if (info.yearly25 == 1) dnsString = "Signed with DNSSEC and without remarks"; if (info.yearly25 == 1 && hasY2y25) pm25String = "Signed with DNSSEC but with warnings"; if (info.yearly25 != 1&& (hasY2y25 || hasYearly25)) dnsString = "Warnings in DNSCheck"; if (hasYearly25) pm25String = "Error in DNSCheck"; contentString += "DNSSEC: " + dnsString + "
"; contentString += "Contact: " + info.contact + "
"; if (info.isRecursive == 1) contentString += "DNS is: Recursive
"; contentString += generateListFromArray("Warnings", info.warnings); contentString += generateListFromArray("Errors", info.errors); contentString += generateListFromArray("DNS Entries", info.dnsList); if (info.url != null) { contentString += "
Visit: " + info.url + "
"; } infowindow.setContent(contentString); infowindow.setPosition(event.latLng); infowindow.open(map); }); } infowindow = new google.maps.InfoWindow(); } function getValueOfFirstAttribute(object) { var firstProp; for (var key in object) { if (object.hasOwnProperty(key)) { return object[key]; } } return null; } function generateListFromArray(title, arr) { if (arr != null && $(arr).size() > 0) { var result = "
" + title + "
"; $(arr).each(function () { result += "" + (getValueOfFirstAttribute(this) == null ? "" : getValueOfFirstAttribute(this)) + "
"; }); return result; } return ""; } // clears the map of polygons function clearMap(code) { $.each(countryPolygons[code], function() { $.each(this, function() { this.setMap(null); }); }); statistics(); } // makes sure the same checkboxes are selected between tabs function checkBox(box) { var boxes = document.getElementsByName('country[]'); var boxes2 = document.getElementsByName('country2[]'); if(!box.checked) { boxes[box.value-1].checked = false; boxes2[box.value-1].checked = false; } else { boxes[box.value-1].checked = true; boxes2[box.value-1].checked = true; } if(box.checked) { country = new Object({ country: boxes[box.value-1].id, code: box.value }); } else { clearMap(box.value); return; } loadData(); } // select all PM10 filters function selectAllPm10() { if(document.getElementById('allpm10').checked == true) { document.getElementById('pm10_realtime').checked = true; document.getElementById('pm10_yearly').checked = true; document.getElementById('pm10_highres').checked = true; document.getElementById('pm10_y2y').checked = true; document.getElementById('pm10_density').checked = true; } else { document.getElementById('pm10_realtime').checked = false; document.getElementById('pm10_yearly').checked = false; document.getElementById('pm10_highres').checked = false; document.getElementById('pm10_y2y').checked = false; document.getElementById('pm10_density').checked = false; } reloadAll(); } // select all PM2.5 filters function selectAllPm25() { if(document.getElementById('allpm25').checked == true) { document.getElementById('pm25_realtime').checked = true; document.getElementById('pm25_yearly').checked = true; document.getElementById('pm25_highres').checked = true; document.getElementById('pm25_y2y').checked = true; document.getElementById('pm25_density').checked = true; } else { document.getElementById('pm25_realtime').checked = false; document.getElementById('pm25_yearly').checked = false; document.getElementById('pm25_highres').checked = false; document.getElementById('pm25_y2y').checked = false; document.getElementById('pm25_density').checked = false; } reloadAll(); } // select all NO2 filters function selectAllNo2() { if(document.getElementById('allno2').checked == true) { document.getElementById('no2_realtime').checked = true; document.getElementById('no2_yearly').checked = true; document.getElementById('no2_highres').checked = true; document.getElementById('no2_y2y').checked = true; document.getElementById('no2_density').checked = true; } else { document.getElementById('no2_realtime').checked = false; document.getElementById('no2_yearly').checked = false; document.getElementById('no2_highres').checked = false; document.getElementById('no2_y2y').checked = false; document.getElementById('no2_density').checked = false; } reloadAll(); }