﻿// 22/02/2008  Plot the Features
// 22/02/2008  Unit Test Complete
// 20/03/2008  Labels added

var map;


function LoadMap() {
  //alert("LoadMap");
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(50.70213,-2.18160), 16);
//    GEvent.addListener(map, "load", function () {alert("BAZ");});
    map.addControl(new GMapTypeControl());
    map.addControl(new GLargeMapControl());
    map.setMapType(G_HYBRID_MAP);}
    var tout=setTimeout("Startup()",1000);
}

function ShowPoint(flat, flng, fname, fhtml, fid) {
    //alert(flat + ":" + flng + ":" + fname);
    var point = new GLatLng(flat, flng);
    var marker = new GMarker(point);
//    GEvent.addListener(marker, "click", function() {map.openInfoWindowHtml(point,fname+"</br></br><img src='http://farm3.static.flickr.com/2094/2342831141_ebbe95bfa9_m.jpg' alt='Working'/> ")});
    GEvent.addListener(marker, "click", function() {map.openInfoWindowHtml(point,fhtml)});
    map.addOverlay(marker);
    var Label = new GLabel(new GLatLng(flat, flng), fname, "#ff0000");
    map.addOverlay(Label);

}

function ShowLine(points, fname, fhtml, fid, fcol) {
    var PolyLine = eval(points);
    var pline = new GPolyline(PolyLine, fcol, 5);
//    GEvent.addListener(pline, "click", function() {map.openInfoWindowHtml(PolyLine[1],fname)});
    GEvent.addListener(pline, "click", function() {map.openInfoWindowHtml(PolyLine[1],fhtml)});
    map.addOverlay(pline);
    var Label = new GLabel(PolyLine[1], fname, fcol);
    map.addOverlay(Label);
}

function ShowShape(points, fname, fhtml, fid, fcol) {
    var SumX=0;
    var SumY=0;
    var PolyLine = eval(points);
    PolyLine.push(PolyLine[0]);
    var pshape = new GPolygon(PolyLine, null, 3, 0.7, fcol, 0.5 )
//    GEvent.addListener(pshape, "click", function() {map.openInfoWindowHtml(PolyLine[1],fname)});
    GEvent.addListener(pshape, "click", function() {map.openInfoWindowHtml(PolyLine[1],fhtml)});
    map.addOverlay(pshape);
    // Find centre of shape for label
    for(I=0;I<PolyLine.length;I++) {
        var PolyPoint = String(PolyLine[I]);
        SumX += Number(PolyPoint.slice(1,PolyPoint.indexOf(",")));
        SumY += Number(PolyPoint.slice(PolyPoint.indexOf(",")+1,-1));
    }
    SumX = SumX / PolyLine.length;
    SumY = SumY / PolyLine.length;
    var Label = new GLabel(new GLatLng(SumX,SumY), fname, fcol);
    map.addOverlay(Label);
}
