/* */ var map; var drawnItems; var statsControl; var drawControl; // http://stackoverflow.com/a/18324384/661150 function callAjax(url, callback) { var xmlhttp; // compatible with IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4 && xmlhttp.status == 200){ callback(xmlhttp.responseText); } } xmlhttp.open("GET", url, true); xmlhttp.send(); } function gitmap_reload() { callAjax("read.cgi", (function(req) { var map = window.map; drawnItems.clearLayers(); var objects = JSON.parse(req).objects; var num_objects = objects.length; for (var i=0; iroster'; text2 = ''; popup = gitmap_file+' '+text1+' '+text2; } marker.options.id=gitmap_file; marker.bindLabel(gitmap_file, { noHide: true }); marker.bindPopup(popup); drawnItems.addLayer(marker); } if (drawControl == null) { // add drawControl only after some drawnItems exist, so // it is not shown disabled drawControl = new L.Control.Draw({ draw: { position: 'topleft', polygon: false, rectangle: false, polyline: false, circle: false }, edit: { featureGroup: drawnItems } }); map.addControl(drawControl); } })); callAjax("summary.cgi", function(req) { var sc = window.statsControl; var leaflet = 'Leaflet'; sc.setPrefix (req + ' | ' + leaflet); }); } function gitmap_setup() { var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', osmAttrib = '© OpenStreetMap contributors', osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}); map = new L.Map('map', {layers: [osm], attributionControl: false, center: new L.LatLng(0, 0), zoom: 2 }); drawnItems = new L.MarkerClusterGroup({maxClusterRadius: 45}); // new L.FeatureGroup(); map.addLayer(drawnItems); gitmap_reload(); // drawcontrol formerly added here var refreshButton = new L.easyButton('icon ion-refresh', function() {gitmap_reload();}); refreshButton.button.style.fontSize = '18px'; map.addControl (refreshButton); var helpButton = new L.easyButton('icon ion-help-circled', function() {open("about.html");}); helpButton.button.style.fontSize = '18px'; map.addControl (helpButton); var controlSearch = new L.Control.Search({layer: drawnItems, propertyName: 'id', initial: false, zoom: 12}); map.addControl( controlSearch ); statsControl = new L.control.attribution({position:'bottomright', prefix:''}); map.addControl(statsControl); scaleControl = new L.control.scale(); map.addControl(scaleControl); terminator = new L.terminator(); terminator.options.opacity=0.2; terminator.options.fillOpacity=0.2; terminator.addTo(map); setInterval(function() {updateTerminator(terminator);}, 60000); // 1 minute function updateTerminator(t) { var t2 = L.terminator(); t.setLatLngs(t2.getLatLngs()); t.redraw(); } // called after new marker is created map.on('draw:created', function (e) { var type = e.layerType, layer = e.layer; if (type !== 'marker') return; var userid = prompt("Marker name (e.g., kerberos userid):", ""); if (userid != null) { layer.options.id=userid; layer.bindPopup(userid); drawnItems.addLayer(layer); callAjax("write.cgi?op=new"+ "&id="+encodeURIComponent(userid)+ "&location="+encodeURIComponent(JSON.stringify(layer.getLatLng()))+ "&options="+encodeURIComponent("{}"), function(req){alert("response:\n"+req); gitmap_reload();}); } }); map.on('draw:edited', function (e) { e.layers.eachLayer(function (layer) { var type = layer.layerType; var userid = layer.options.id; callAjax("write.cgi?op=edit"+ "&id="+encodeURIComponent(userid)+ "&location="+encodeURIComponent(JSON.stringify(layer.getLatLng()))+ "&options="+encodeURIComponent("{}"), function(req){alert("response:\n"+req); gitmap_reload();}); }); }); map.on('draw:deleted', function (e) { e.layers.eachLayer(function (layer) { var type = layer.layerType; var userid = layer.options.id; callAjax("write.cgi?op=delete"+ "&id="+encodeURIComponent(userid), function(req){alert("response:\n"+req); gitmap_reload();}); }); }); }