From 551c3222b65f5c68d2e0e45ddff7c5e814316ed1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 6 Dec 2008 09:48:44 +0000 Subject: added drawLocations --- map.js | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'map.js') diff --git a/map.js b/map.js index e264429..bd03cc0 100644 --- a/map.js +++ b/map.js @@ -1,10 +1,11 @@ var map = null; var physicalMaxLevel; -var xmlData = null; var geocoder = null; var overlays = new Array(); overlays["newmarker"] = null; overlays["ruler"] = new Array(); +overlays["locations"] = new Array(); +var locations = new Array(); function initialize(lat, lng, res) { if (!checkBrowser()) { @@ -42,7 +43,7 @@ function initialize(lat, lng, res) { geocoder = new GClientGeocoder(); -// GDownloadUrl("data.php", onData); + GDownloadUrl("data.php", onData); } function checkBrowser() { @@ -59,6 +60,7 @@ function checkBrowser() { function onAddOverlay(overlay) { switch(overlay.overlaytype) { + case "location": overlays["locations"].push(overlay); break; case "newmarker": { if(overlays["newmarker"]) { map.removeOverlay(overlays["newmarker"]); @@ -96,7 +98,39 @@ function onData(data, responseCode) { } xmlData = GXml.parse(data); - // TODO: add data import and comment in GDownloadUrl() at initialize() + for(var loc in overlays["locations"]) { + map.removeOverlay(overlays["locations"][loc]); + } + overlays["locations"] = []; + locations = []; + drawLocations(xmlData); +} + +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; + map.addOverlay(marker); + } +} + +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 addNewNodeText(point) { @@ -109,7 +143,10 @@ function makeIcon(type) { switch(type) { case 'ruler': icon.image = "./img/marker_blue.png"; break; - case 'newnode': icon.image = "./img/marker_darkred.png"; + 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); -- cgit v1.2.1