﻿// JScript File
var LondonLEZMap; // Moved out here so we can use it in multiple functions
var Postcode;

function ContentPageLoad()
{
    //====================
    // Embedded Sample Map
    //====================
    // Create a new map associated with the map view div.
    LondonLEZMap = new ISYSMap( document.getElementById("LondonLEZMapViewDiv"), 0, 0, 455, 300, 7002 ); // Div, X, Y, Width, Height, Map
    
    // Get the map view element
    var LondonLEZMapDiv = document.getElementById("LondonLEZMapViewDiv")
    
    // Wire up the mouse listeners to do dragging, scrolling and zooming
    LondonLEZMapDiv.onmousedown = function(event){LondonLEZMap.ISYSStartMoveMouse(event); };
    LondonLEZMapDiv.onmousemove = function(event){LondonLEZMap.ISYSProcessMoveMouse(event); };
    LondonLEZMapDiv.onmouseup = function(event){LondonLEZMap.ISYSStopMoveMouse(event); }; // Don't use with compass scroll
    LondonLEZMapDiv.ondblclick = function(event){LondonLEZMap.ISYSZoomInMouse(event); };

    // necessary to enable dragging on IE
    LondonLEZMapDiv.ondragstart = function() { return false; }
    
    // Set the mouse scroll method
    LondonLEZMap.ISYSScrollMethodDrag();
    
    // Quick zoom
    LondonLEZMap.ISYSZoomLevel(7);

    // Centre map on XY.
    var myCoordinateXY1 = new ISYSCoordinate();
    // myCoordinateXY1.X = 7830;
    // myCoordinateXY1.Y = 4350;
    myCoordinateXY1.X = 700;
    myCoordinateXY1.Y = 350;
    LondonLEZMap.ISYSCentreMapOnXY( myCoordinateXY1 );
    
	// Draw the map
    LondonLEZMap.ISYSDrawMap();

    //=================
    // Popup Sample Map
    //=================
    // Create a new map associated with the map view div.
    var LondonLEZPopup = new ISYSMap( document.getElementById("LondonLEZPopupSampleDiv"), 0, 0, 600, 600, 7002 ); // Div, X, Y, Width, Height, Map
    
    // Get the map view element
    var LondonLEZPopupDiv = document.getElementById("LondonLEZPopupSampleDiv")
    
    // Wire up the mouse listeners to do dragging, scrolling and zooming
    LondonLEZPopupDiv.onmousedown = function(event){LondonLEZPopup.ISYSStartMoveMouse(event); };
    LondonLEZPopupDiv.onmousemove = function(event){LondonLEZPopup.ISYSProcessMoveMouse(event); };
    LondonLEZPopupDiv.onmouseup = function(event){LondonLEZPopup.ISYSStopMoveMouse(event); };
    LondonLEZPopupDiv.ondblclick = function(event){LondonLEZPopup.ISYSZoomInMouse(event); };

    // necessary to enable dragging on IE
    LondonLEZPopupDiv.ondragstart = function(event) { return false; }
    
    // Set the mouse scroll method
    LondonLEZPopup.ISYSScrollMethodCompass();  // Only works on IE, defaults to ISYSScrollMethodDrag for other browsers
    
    // Quick zoom
    LondonLEZPopup.ISYSZoomLevel(7);

    // Centre map on same XY.
    var myCoordinateXY2 = new ISYSCoordinate();
    myCoordinateXY2.X = 700;
    myCoordinateXY2.Y = 350;
    LondonLEZPopup.ISYSCentreMapOnXY( myCoordinateXY2 );
    
	// Draw the map
    LondonLEZPopup.ISYSDrawMap();
}

function myLocatePostcode()
{
    // html text box
    Postcode = document.getElementById("TextPostcode").value.toUpperCase();
    
    ISYSGetPostcodeLatLong( Postcode ); // Callback function, calls ISYSGetPostcodeLatLongComplete() on completion
}

function ISYSGetPostcodeLatLongComplete( Latitude, Longitude )
{
    var myCoordinateLatLong = new ISYSCoordinate();
    myCoordinateLatLong.Latitude = Latitude;
    myCoordinateLatLong.Longitude = Longitude;

    // Remove old circle, if there is one
    LondonLEZMap.ISYSRemoveDiv( "MyCirclePostcode1" );

    // Centre map
    var Result = LondonLEZMap.ISYSCentreMapOnLatLong( myCoordinateLatLong );

    // Check result
    if( Result )
    {
        // Quick zoom
        LondonLEZMap.ISYSZoomLevel(11);

        // Draw new circle
        var MyDiv = document.createElement("div");
        MyDiv.style.position = "absolute";
        MyDiv.style.width = "45px";
        MyDiv.style.height = "45px";
        MyDiv.style.left = "-45px";
        MyDiv.style.top = "-45px";
        MyDiv.style.zIndex = "3";
        MyDiv.setAttribute("id", "MyCirclePostcode1");
        LondonLEZMap.MapDiv.appendChild(MyDiv);
        MyImg = document.createElement("img");
        MyImg.src="pircle.png";
        MyImg.width="45";
        MyImg.height="45";
        MyImg.alt=""+Postcode;
        MyDiv.appendChild(MyImg);
        LondonLEZMap.ISYSAddDivLatLong( "MyCirclePostcode1", 23, 23, myCoordinateLatLong );
        LondonLEZMap.ISYSCentreMapOnLatLong( myCoordinateLatLong );
    }
    else
    {
        alert( "Postcode location is not on this map." );
    }
}
