var map = null; var physicalMaxLevel; var geocoder = null; var reloadcon = null; var countboxText = null; var overlays = new Array(); overlays["newmarker"] = null; overlays["ruler"] = new Array(); overlays["locations"] = new Array(); overlays["links"] = new Array(); var locations = new Array(); var links = new Array(); function initialize(lat, lng, res) { if (!checkBrowser()) { return; } map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(lat, lng), res); map.disableDoubleClickZoom(); map.enableScrollWheelZoom(); map.removeMapType(G_HYBRID_MAP); map.removeMapType(G_SATELLITE_MAP); map.addMapType(G_PHYSICAL_MAP); map.setMapType(G_PHYSICAL_MAP); physicalMaxLevel = map.getCurrentMapType().getMaximumResolution(); if(res > physicalMaxLevel) { map.setMapType(G_NORMAL_MAP); map.setZoom(res); } map.addControl(new RulerControl()); reloadcon = new ReloadControl(); map.addControl(reloadcon); map.addControl(new GSmallMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,20))); map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(50,10))); GEvent.addListener(map, "addoverlay", onAddOverlay); GEvent.addListener(map, "zoomend", onZoom); GEvent.addListener(map, "click", onMapClick); var mt = map.getMapTypes(); for (var i=0; i physicalMaxLevel) { map.setMapType(G_NORMAL_MAP); } } function onMapClick(overlay, point) { if(!overlay) { setNewMarker(point); } } function onData(data, responseCode) { if (responseCode < 200 || responseCode > 299) { reloadcon.finished(); return alert("Fehler: Konnte die Daten nicht laden!\n(Server Antwort-Code: " + responseCode + ")"); } reloadcon.loaded(); xmlData = GXml.parse(data); for(var loc in overlays["locations"]) { map.removeOverlay(overlays["locations"][loc]); } overlays["locations"] = []; locations = []; drawLocations(xmlData); for(var link in overlays["links"]) { map.removeOverlay(overlays["links"][link]); } overlays["links"] = []; links = []; drawLinks(xmlData); var element = xmlData.getElementsByTagName("count"); var count = element[0].getAttribute("number"); countboxText.data = "Aktiv: " + count; reloadcon.finished(); } function drawLocations(xmlData) { var element = xmlData.getElementsByTagName("node"); for (var i = 0; i< element.length; i++) { var id = parseInt(element[i].getAttribute("id")); locations[id] = new Location(element[i]); var marker = new GMarker(locations[id].point, {icon: makeIcon(locations[id].state)}); marker.overlaytype = "location"; marker.locid = id; GEvent.addListener(marker, "click", onLocationClick); map.addOverlay(marker); } if(document.visibleform.elements["offline"].checked) { toggleVisible("offline"); } if(document.visibleform.elements["online"].checked) { toggleVisible("online"); } } function Location(element) { var location = new Object(); location.name = element.getAttribute("name"); var lat = parseFloat(element.getAttribute("lat")); var lng = parseFloat(element.getAttribute("lng")); location.point = new GLatLng(lat, lng); location.pixel_x = parseInt(element.getAttribute("pixel_x")); location.pixel_y = parseInt(element.getAttribute("pixel_y")); location.state = element.getAttribute("state"); location.gallery_link = element.getAttribute("gallery_link"); return location; } function onLocationClick(latlng) { var html = '
'; html += '' + locations[this.locid].name + ''; html += ''; html += ''; html += ''; html += ''; html += ''; if(locations[this.locid].gallery_link) { html += ''; } else { html += ''; } html += '
Breitengrad: ' + convertCoords(locations[this.locid].point.lat()) + '
Längengrad: ' + convertCoords(locations[this.locid].point.lng()) + '
Datenbank: Link
Smokeping: Link
Galerie: Link
Galerie: Link
'; html += '
'; this.openInfoWindowHtml(html); } function convertCoords(x) { var deg = Math.floor(x); var min = (x - deg) * 60; var sec = (min - Math.floor(min)) * 60; return deg + "° " + Math.floor(min) + "' " + sec.toFixed(0) + "\""; } function drawLinks(xmlData) { var element = xmlData.getElementsByTagName("link"); for (var i = 0; i< element.length; i++) { var id = element[i].getAttribute("from") + "-" + element[i].getAttribute("to"); links[id] = new Link(element[i]); var line = new GPolyline([links[id].frompoint, links[id].topoint], makeColor(Math.floor(links[id].value)), makeWeight(Math.floor(links[id].value))); line.overlaytype = "link"; line.linkid = id; map.addOverlay(line); } if(document.visibleform.elements["bad"].checked) { toggleVisible("bad"); } if(document.visibleform.elements["middle"].checked) { toggleVisible("middle"); } if(document.visibleform.elements["good"].checked) { toggleVisible("good"); } if(document.visibleform.elements["tunnel"].checked) { toggleVisible("tunnel"); } } function Link(element) { var link = new Object(); link.from = element.getAttribute("from"); link.fromid = parseInt(element.getAttribute("fromid")); var lat = parseFloat(element.getAttribute("latfrom")); var lng = parseFloat(element.getAttribute("lngfrom")); link.frompoint = new GLatLng(lat, lng); link.to = element.getAttribute("to"); link.toid = parseInt(element.getAttribute("toid")); lat = parseFloat(element.getAttribute("latto")); lng = parseFloat(element.getAttribute("lngto")); link.topoint = new GLatLng(lat, lng); link.value = parseFloat(element.getAttribute("value")); return link; } function makeColor(value) { switch(value) { case -1: return '#0000FF'; case 0: return '#FF0000'; case 1: return '#33bb33'; case 2: return '#66bb33'; case 3: return '#ff9900'; case 4: return '#ffcc00'; case 5: return '#cccc33'; default: return '#666666' } } function makeWeight(value) { switch(value) { case -1: return 2; case 0: return 1; case 1: return 3; case 2: return 2; case 3: return 1; case 4: return 1; case 5: return 1; default: return 1; } } function makeIcon(type) { var icon = new GIcon(); switch(type) { case 'ruler': icon.image = "./img/marker_blue.png"; break; case 'newnode': icon.image = "./img/marker_darkred.png"; break; case 'online': icon.image = "./img/marker_online.png"; break; case 'tunnel': icon.image = "./img/marker_tunnel.png"; break; case 'offline': icon.image = "./img/marker_offline.png"; break; } icon.iconSize = new GSize(12,20); icon.iconAnchor = new GPoint(6,20); icon.infoWindowAnchor = new GPoint(5,1); return icon } function toggleVisible(element) { var elements = Object(); switch(element) { case 'offline': elements.overlays = overlays["locations"]; elements.select = new Function("id", "return (locations[overlays['locations'][id].locid].state == 'offline');"); break; case 'online': elements.overlays = overlays["locations"]; elements.select = new Function("id", "return (locations[overlays['locations'][id].locid].state != 'offline');"); break; case 'bad': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value >= 6);"); break; case 'middle': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value >= 3 && links[overlays['links'][id].linkid].value < 6);"); break; case 'good': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value >= 0 && links[overlays['links'][id].linkid].value < 3);"); break; case 'tunnel': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value == -1);"); break; } if(document.visibleform.elements[element].checked) { hideElements(elements); } else { showElements(elements); } } function hideElements(elements) { for(var o in elements.overlays) if(elements.select(o)) elements.overlays[o].hide(); } function showElements(elements) { for(var o in elements.overlays) if(elements.select(o)) elements.overlays[o].show(); } function centerAndZoom(lat, lng) { map.setCenter(new GLatLng(lat, lng), 17); } function addNewNodeText(point) { var x_startpoint = 4080; var lng_startpoint = 15.43844103813; var dx_dlng = 50675.5176; var y_startpoint = 4806; var lat_startpoint = 47.07177327969; var dy_dlat = 75505.521; var pixel_x = parseInt(Math.floor(x_startpoint + (point.x - lng_startpoint) * dx_dlng)); var pixel_y = parseInt(Math.floor(y_startpoint - (point.y - lat_startpoint) * dy_dlat)); var link = 'https://manman.graz.funkfeuer.at/location/new?'; link += 'z_x=' + Math.floor(pixel_x % 100) + '&z_y=' + Math.floor(pixel_y % 100); link += '&c=' + Math.floor(pixel_x / 100) + '&r=' + Math.floor(pixel_y / 100); var html = 'Neuen Knoten eintragen
Nutzen sie den Zoombereich aus!


'; html += ''; html += ''; html += ''; html += ''; html += ''; html += '
Breitengrad: ' + convertCoords(point.y) + ' 
Längengrad: ' + convertCoords(point.x)+ ' 
'; return html; } function setNewMarker(point) { var marker = new GMarker(point,{icon: makeIcon('newnode'), draggable: true}); GEvent.addListener(marker, "dragstart", function() { this.autoclosed = true; this.closeInfoWindow(); }); GEvent.addListener(marker, "dragend", function(point) { this.openInfoWindowHtml(addNewNodeText(point)); }); GEvent.addListener(marker, "infowindowclose", function () { if(this.autoclosed == true) { this.autoclosed = false; } else { map.removeOverlay(overlays["newmarker"]); overlays["newmarker"] = null; } }); marker.overlaytype = "newmarker"; map.addOverlay(marker); marker.openInfoWindowHtml(addNewNodeText(point)); } function fflogin(username, password) { var postbody = "username=" + encodeURIComponent(username) + "&password=" + encodeURIComponent(password) + "&login=Einloggen#"; GDownloadUrl("login.php", onFFLogin, postbody); } function onFFLogin(data, responseCode) { if (responseCode < 200 || responseCode > 299) { return alert("Fehler: Konnte die Daten nicht laden!\n(Server Antwort-Code: " + responseCode + ")"); } xmlData = GXml.parse(data); var error = xmlData.getElementsByTagName("error"); if(error.length > 0) { alert(error[0].getAttribute("string")); } else { var status = xmlData.getElementsByTagName("status"); if(status[0].getAttribute("code") == "logged_in") { var username = xmlData.getElementsByTagName("username")[0].getAttribute("name"); showFFLogout(username); reloadcon.started(); GDownloadUrl("data.php", onData); } } } function showFFLogin() { var html = '
'; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += '
Benutzername:
Passwort:
'; document.getElementById("loginbox").innerHTML = html; } function fflogout() { var postbody = "logout=Ausloggen#"; GDownloadUrl("login.php", onFFLogout, postbody); } function onFFLogout(data, responseCode) { if (responseCode < 200 || responseCode > 299) { return alert("Fehler: Konnte die Daten nicht laden!\n(Server Antwort-Code: " + responseCode + ")"); } xmlData = GXml.parse(data); var error = xmlData.getElementsByTagName("error"); if(error.length > 0) { alert(error[0].getAttribute("string")); } else { showFFLogin(); reloadcon.started(); GDownloadUrl("data.php", onData); } } function showFFLogout(username) { var html = '
'; html += 'Sie sind eingeloggt als:
'; html += ''+username+'   ' html += '
'; document.getElementById("loginbox").innerHTML = html; } function showAddress(address) { if (geocoder) { address += ", Graz, Austria"; geocoder.getLatLng(address, function(point) { if (!point) { alert(address + " nicht gefunden"); } else { map.setCenter(point); setNewMarker(point); } }); } } function ReloadControl() { } ReloadControl.prototype = new GControl(); ReloadControl.prototype.initialize = function(map) { var container = document.createElement("div"); var btnDiv = document.createElement("div"); btnDiv.className = "btn"; btnDiv.id = "reloadbtn"; container.appendChild(btnDiv); btnText = document.createTextNode("Daten neu laden"); btnDiv.appendChild(btnText); GEvent.addDomListener(btnDiv, "click", function() { reloadcon.started(); GDownloadUrl("data.php", onData); }); map.getContainer().appendChild(container); return container; } ReloadControl.prototype.started = function() { btnText.data = "wird geladen..."; } ReloadControl.prototype.loaded = function() { btnText.data = "wird verarbeitet..."; } ReloadControl.prototype.finished = function() { btnText.data = "Daten neu laden"; } ReloadControl.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7)); } function RulerControl() { } RulerControl.prototype = new GControl(); RulerControl.prototype.initialize = function(map) { var btnText; var distBoxOuter; var distBox; var distText; function measure() { if(overlays["ruler"]["marker1"] && overlays["ruler"]["marker2"]) { var line = [overlays["ruler"]["marker1"].getPoint(), overlays["ruler"]["marker2"].getPoint()]; var dist = overlays["ruler"]["marker1"].getPoint().distanceFrom(overlays["ruler"]["marker2"].getPoint()); dist = dist.toFixed(0)+" m"; if(parseInt(dist) > 10000) { dist = (parseInt(dist)/1000).toFixed(1) + " km"; } distText.data = "Entfernung: " + dist; var poly = new GPolyline(line,'#FFFF00', 8, 1) poly.overlaytype = "ruler"; poly.overlaysubtype = "line"; map.addOverlay(poly); } } function clr(){ for(var o in overlays["ruler"]) { map.removeOverlay(overlays["ruler"][o]); } overlays["ruler"] = []; distBox.style.visibility = "hidden"; btnText.data = "Entfernung messen"; } var container = document.createElement("div"); var btnDiv = document.createElement("div"); btnDiv.className = "btn"; btnDiv.id = "rulerbtn"; container.appendChild(btnDiv); btnText = document.createTextNode("Entfernung messen"); btnDiv.appendChild(btnText); GEvent.addDomListener(btnDiv, "click", function() { for(var o in overlays["ruler"]) { if(overlays["ruler"][o]) { clr(); return; } } btnText.data = "Messung beenden"; distText.data = "Entfernung: 0 m"; distBox.style.visibility = "visible"; var pnt = map.getCenter(); marker1 = new GMarker(pnt, {icon: makeIcon('ruler'), draggable: true}); marker1.overlaytype = "ruler"; marker1.overlaysubtype = "marker1"; map.addOverlay(marker1); marker2 = new GMarker(pnt, {icon: makeIcon('ruler'), draggable: true}); marker2.overlaytype = "ruler"; marker2.overlaysubtype = "marker2"; map.addOverlay(marker2); GEvent.addListener(marker1, "drag", function() { measure(); }); GEvent.addListener(marker2, "drag", function() { measure(); }); }); distBoxOuter = document.createElement("div"); distBoxOuter.id = "distboxouter"; distBox = document.createElement("div"); distBox.className = "box"; distBox.id = "distbox"; distBox.style.visibility = "hidden"; distText = document.createTextNode("Entfernung: ? m"); distBox.appendChild(distText); distBoxOuter.appendChild(distBox); document.getElementById("map").appendChild(distBoxOuter); map.getContainer().appendChild(container); return container; } RulerControl.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(7, 7)); }