﻿
/*
GetElementByID(..),CreateMarkerGroups(..) method(s) are located in javascripts/Googlemaps/GlobalFunction.js file
*/
var googleMap;

//4 icons for each direction
var cameraGEIcon = new GIcon();
var cameraGWIcon = new GIcon();
var cameraGNIcon = new GIcon();
var cameraGSIcon = new GIcon();

var signGEIcon = new GIcon();
var signGWIcon = new GIcon();
var signGNIcon = new GIcon();
var signGSIcon = new GIcon();

var signGEBlankIcon = new GIcon();
var signGWBlankIcon = new GIcon();
var signGNBlankIcon = new GIcon();
var signGSBlankIcon = new GIcon();

var eventGIcon              = new GIcon();
var constructionGIcon       = new GIcon();
var plannedEventGIcon       = new GIcon();

var tatsFlashingGIcon = new GIcon();
var tatsNonFlashingGIcon = new GIcon();
var tatsNoReadingGIcon = new GIcon();

var iconDir = "images/google/icons/";

//We need to make sure if the client side browser allows google operations
if (GBrowserIsCompatible()) {

	//This method will be called by Master page to load map onto the calling oe default page
    function SetMap(cityLongitudeCenter, cityLatitudeCenter, cityZoomLevel) {

        tatsFlashingGIcon.image = iconDir + "sm_tats_flashing.gif";
        tatsFlashingGIcon.iconSize = new GSize(21, 18);
        tatsFlashingGIcon.iconAnchor = new GPoint(11, 11);
        tatsFlashingGIcon.infoWindowAnchor = new GPoint(11, 11);

        tatsNonFlashingGIcon.image = iconDir + "sm_tats.gif";
        tatsNonFlashingGIcon.iconSize = new GSize(21, 18);
        tatsNonFlashingGIcon.iconAnchor = new GPoint(11, 11);
        tatsNonFlashingGIcon.infoWindowAnchor = new GPoint(11, 11);

        tatsNoReadingGIcon.image = iconDir + "sm_tats_gray.gif";
        tatsNoReadingGIcon.iconSize = new GSize(21, 18);
        tatsNoReadingGIcon.iconAnchor = new GPoint(11, 11);
        tatsNoReadingGIcon.infoWindowAnchor = new GPoint(11, 11);
        
        cameraGEIcon.image = iconDir + "iconCCTVE_Blue.gif";
        cameraGEIcon.iconSize = new GSize(16, 6);
        cameraGEIcon.iconAnchor = new GPoint(11, 11);
        cameraGEIcon.infoWindowAnchor = new GPoint(11, 11);

        cameraGWIcon.image = iconDir + "iconCCTVW_Blue.gif";
        cameraGWIcon.iconSize = new GSize(16, 6);
        cameraGWIcon.iconAnchor = new GPoint(11, 11);
        cameraGWIcon.infoWindowAnchor = new GPoint(11, 11);

        cameraGNIcon.image = iconDir + "iconCCTVN_Blue.gif";
        cameraGNIcon.iconSize = new GSize(6, 16);
        cameraGNIcon.iconAnchor = new GPoint(11, 11);
        cameraGNIcon.infoWindowAnchor = new GPoint(11, 11);

        cameraGSIcon.image = iconDir + "iconCCTVS_Blue.gif";
        cameraGSIcon.iconSize = new GSize(6, 16);
        cameraGSIcon.iconAnchor = new GPoint(11, 11);
        cameraGSIcon.infoWindowAnchor = new GPoint(11, 11);
        

        signGEIcon.image = iconDir + "iconSignE_yellow.gif";
        signGEIcon.iconSize = new GSize(12,21);
        signGEIcon.iconAnchor = new GPoint(11,11);
        signGEIcon.infoWindowAnchor = new GPoint(11, 11);

        signGWIcon.image = iconDir + "iconSignW_yellow.gif";
        signGWIcon.iconSize = new GSize(12, 21);
        signGWIcon.iconAnchor = new GPoint(11, 11);
        signGWIcon.infoWindowAnchor = new GPoint(11, 11);

        signGNIcon.image = iconDir + "iconSignN_yellow.gif";
        signGNIcon.iconSize = new GSize(21, 12);
        signGNIcon.iconAnchor = new GPoint(11, 11);
        signGNIcon.infoWindowAnchor = new GPoint(11, 11);

        signGSIcon.image = iconDir + "iconSignS_yellow.gif";
        signGSIcon.iconSize = new GSize(21, 12);
        signGSIcon.iconAnchor = new GPoint(11, 11);
        signGSIcon.infoWindowAnchor = new GPoint(11, 11);


        signGEBlankIcon.image = iconDir + "iconSignE_blank.gif";
        signGEBlankIcon.iconSize = new GSize(12, 21);
        signGEBlankIcon.iconAnchor = new GPoint(11, 11);
        signGEBlankIcon.infoWindowAnchor = new GPoint(11, 11);

        signGWBlankIcon.image = iconDir + "iconSignW_blank.gif";
        signGWBlankIcon.iconSize = new GSize(12, 21);
        signGWBlankIcon.iconAnchor = new GPoint(11, 11);
        signGWBlankIcon.infoWindowAnchor = new GPoint(11, 11);

        signGNBlankIcon.image = iconDir + "iconSignN_blank.gif";
        signGNBlankIcon.iconSize = new GSize(21, 12);
        signGNBlankIcon.iconAnchor = new GPoint(11, 11);
        signGNBlankIcon.infoWindowAnchor = new GPoint(11, 11);

        signGSBlankIcon.image = iconDir + "iconSignS_blank.gif";
        signGSBlankIcon.iconSize = new GSize(21, 12);
        signGSBlankIcon.iconAnchor = new GPoint(11, 11);
        signGSBlankIcon.infoWindowAnchor = new GPoint(11, 11);
        
        eventGIcon.image = iconDir + "inc_h.gif";
        eventGIcon.iconSize = new GSize(18,18);
        eventGIcon.iconAnchor = new GPoint(11,11);
        eventGIcon.infoWindowAnchor = new GPoint(11, 11);
        
        constructionGIcon.image = iconDir + "sm_construction.gif";
        constructionGIcon.iconSize = new GSize(21,18);
        constructionGIcon.iconAnchor = new GPoint(11,11);
        constructionGIcon.infoWindowAnchor = new GPoint(11, 11);

        plannedEventGIcon.image = iconDir + "inc_planned.gif";
        plannedEventGIcon.iconSize = new GSize(18, 18);
        plannedEventGIcon.iconAnchor = new GPoint(11, 11);
        plannedEventGIcon.infoWindowAnchor = new GPoint(11, 11);
        
        googleMap = new GMap2(GetElementByID("map"));
        googleMap.addControl(new GLargeMapControl());
        googleMap.addControl(new GMapTypeControl());
        googleMap.addControl(new GScaleControl());
            
        //The LargeMapControl scale should only be allowed to zoom to certain levels
        G_NORMAL_MAP.getMinimumResolution = function() { return _minZoomLevel; }
        G_NORMAL_MAP.getMaximumResolution = function() { return _maxZoomLevel; }

        G_HYBRID_MAP.getMinimumResolution = function() { return _minZoomLevel; }
        G_HYBRID_MAP.getMaximumResolution = function() { return _maxZoomLevel; }

        G_PHYSICAL_MAP.getMinimumResolution = function() { return _minZoomLevel; }
        G_PHYSICAL_MAP.getMaximumResolution = function() { return _maxZoomLevel; } 
        
        googleMap.addMapType(G_PHYSICAL_MAP); //Add terrain option
        googleMap.removeMapType(G_SATELLITE_MAP); //Remove satelitte option
        
        //Options to go with map view
        /*G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP, G_PHYSICAL_MAP */
        
        GEvent.addListener(googleMap, 'zoomend', function(oldZ, newZ) { CheckZoom(oldZ, newZ); });
        SetMapCenterFromCookies();
        GEvent.addListener(googleMap,'load',CreateMarkerGroups('NEWDATA'));
        GEvent.addListener(googleMap, 'dragend', SetDefaultMap);
        googleMap.disableDoubleClickZoom();
        googleMap.enableContinuousZoom();

        //Tiles will not show up if map is not set to Normal map type first before setting it to Physical map (terrain)
        googleMap.setMapType(G_NORMAL_MAP);
        googleMap.setMapType(G_PHYSICAL_MAP);
    }
}
else
{
    alert("Your browser is not compatible with Google Maps. Acceptable browsers include Internet Explorer 6 or better and Firefox 1.5 or better.");
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Purpose:
//      This is used to set up the map to use custom tiling. The custom tiling is used to draw the traffic lines
//      on the map. This is being done as an optimization since the polylines were too slow due to there being so
//      many points.
//
//
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function setupMapForCustomTiling() {
    //Create the tile layer object
    var detailLayer = new GTileLayer(new GCopyrightCollection(''));

    // Callback method to retrieve the URL of the tile
    detailLayer.getTileUrl = GoogleMapFileCallback;

    detailLayer.isPng = function() {
        //This uses PNG's
        return true;
    }

    //add your tiles to the normal map projection

    G_PHYSICAL_MAP.getTileLayers().push(detailLayer);
    G_NORMAL_MAP.getTileLayers().push(detailLayer);
    G_HYBRID_MAP.getTileLayers().push(detailLayer);
    
   
    // By using the add overlay method the tiles can be refreshed with the rest of the maps.
    googleMap.addOverlay(new GTileLayerOverlay(detailLayer));

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Purpose:
//      This is the callback method that the Google Map will call in order to get the URL for the tile that will
//      be placed over the google map.
//
//  Parameters:
//      tile:
//          This holds the x and y coordinates of the tile that will be retrieved from the server.
//
//      zoom:
//          This holds the zoom level for the tile that is being displayed.
//
//  Return:
//      The url of the web page that will return of the tile. This includes any arguments.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GoogleMapFileCallback(tile, zoom) {

    var tileURL = _simulateEnviornment == "true" ? 
                _googleTileServer + "?x=" + tile.x + "&y=" + tile.y + "&zoom=" + zoom + "&z=" + Math.random().toString() :
                "GoogleMapsFile.aspx?x=" + tile.x + "&y=" + tile.y + "&zoom=" + zoom + "&z=" + Math.random().toString() ;
                
           
    return tileURL;
}

