﻿// JScript File
var LondonCCZMap; // 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.
    LondonCCZMap = new ISYSMap( document.getElementById("LondonCCZMapViewDiv"), 0, 0, 455, 300, 7001 ); // Div, X, Y, Width, Height, Map
    
    // Get the map view element
    var LondonCCZMapDiv = document.getElementById("LondonCCZMapViewDiv")
    
    // Wire up the mouse listeners to do dragging, scrolling and zooming
    LondonCCZMapDiv.onmousedown = function(event){LondonCCZMap.ISYSStartMoveMouse(event); };
    LondonCCZMapDiv.onmousemove = function(event){LondonCCZMap.ISYSProcessMoveMouse(event); };
    LondonCCZMapDiv.onmouseup = function(event){LondonCCZMap.ISYSStopMoveMouse(event); }; // Don't use with compass scroll
    LondonCCZMapDiv.ondblclick = function(event){LondonCCZMap.ISYSZoomInMouse(event); };

    // necessary to enable dragging on IE
    LondonCCZMapDiv.ondragstart = function() { return false; }
    
    // Set the mouse scroll method
    LondonCCZMap.ISYSScrollMethodDrag();
    
    // Quick zoom
    LondonCCZMap.ISYSZoomLevel(11);

    // Centre map on XY.
    var myCoordinateXY1 = new ISYSCoordinate();
    // myCoordinateXY1.X = 7830;
    // myCoordinateXY1.Y = 4350;
    myCoordinateXY1.X = 3915;
    myCoordinateXY1.Y = 2175;
    LondonCCZMap.ISYSCentreMapOnXY( myCoordinateXY1 );
    
	// Draw the map
    LondonCCZMap.ISYSDrawMap();

    //=================
    // Popup Sample Map
    //=================
    // Create a new map associated with the map view div.
    var LondonCCZPopup = new ISYSMap( document.getElementById("LondonCCZPopupSampleDiv"), 0, 0, 600, 600, 7001 ); // Div, X, Y, Width, Height, Map
    
    // Get the map view element
    var LondonCCZPopupDiv = document.getElementById("LondonCCZPopupSampleDiv")
    
    // Wire up the mouse listeners to do dragging, scrolling and zooming
    LondonCCZPopupDiv.onmousedown = function(event){LondonCCZPopup.ISYSStartMoveMouse(event); };
    LondonCCZPopupDiv.onmousemove = function(event){LondonCCZPopup.ISYSProcessMoveMouse(event); };
    LondonCCZPopupDiv.onmouseup = function(event){LondonCCZPopup.ISYSStopMoveMouse(event); };
    LondonCCZPopupDiv.ondblclick = function(event){LondonCCZPopup.ISYSZoomInMouse(event); };

    // necessary to enable dragging on IE
    LondonCCZPopupDiv.ondragstart = function(event) { return false; }
    
    // Set the mouse scroll method
    LondonCCZPopup.ISYSScrollMethodCompass();  // Only works on IE, defaults to ISYSScrollMethodDrag for other browsers
    
    // Quick zoom
    LondonCCZPopup.ISYSZoomLevel(9);

    // Centre map on same XY.
    var myCoordinateXY2 = new ISYSCoordinate();
    myCoordinateXY2.X = 1000;
    myCoordinateXY2.Y = 500;
    LondonCCZPopup.ISYSCentreMapOnXY( myCoordinateXY2 );
    
	// Draw the map
    LondonCCZPopup.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
    LondonCCZMap.ISYSRemoveDiv( "MyCirclePostcode1" );

    // Centre map
    var Result = LondonCCZMap.ISYSCentreMapOnLatLong( myCoordinateLatLong );

    // Check result
    if( Result )
    {
        // Quick zoom
        LondonCCZMap.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");
        LondonCCZMap.MapDiv.appendChild(MyDiv);
        MyImg = document.createElement("img");
        MyImg.src="pircle.png";
        MyImg.width="45";
        MyImg.height="45";
        MyImg.alt=""+Postcode;
        MyDiv.appendChild(MyImg);
        LondonCCZMap.ISYSAddDivLatLong( "MyCirclePostcode1", 23, 23, myCoordinateLatLong );
        LondonCCZMap.ISYSCentreMapOnLatLong( myCoordinateLatLong );
    }
    else
    {
        alert( "Postcode location is not on this map." );
    }
}
