﻿// Google Map GMap.js ##############################################################################
var map;
var le = 0;

// GMap

// ###############################################################################
// MAP FUNCTIONS
//      GMapAddLoadEvent();
//      InitGMap();
//      ReinitMap();
//      ClearAndReinit();
//      GetMapChangeSettings();
//      SaveCurrentView();
// ###############################################################################
function GMapAddLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function InitGMap() {
    if (GBrowserIsCompatible()) {
        // Set the size of the map
        ResizeMap();
        
        // Load the Map
        map = new GMap2(document.getElementById(MapControlViewMapID));
        map.setCenter(new GLatLng(MapCenterLocation.Lat, MapCenterLocation.Lon), MapZoomLevel);

        switch (cMapType) {
            case 5:
                map.setMapType(G_NORMAL_MAP);
                break;
            case 6:
                map.setMapType(G_SATELLITE_MAP);
                break;
            case 7:
                map.setMapType(G_HYBRID_MAP);
                break;
            case 8:
                map.setMapType(G_PHYSICAL_MAP);
                break;
        }
        
        map.setUIToDefault();
        document.getElementById(MapControlViewMapID).style.background = "";

        // Load the Custom MapMenu
        ActivateCustomMapMenu("GMap");
        
        // Initialise the MessageBox
        MapControlInitMessageBox("GMap")
        
        // Draw the data
        //GMapDrawData();
        MapDrawData();
    }
}

function ReInitMap() {
    MapCenterLocation.Lat = map.getCenter().lat();
    MapCenterLocation.Lon = map.getCenter().lng();
    MapZoomLevel = map.getZoom();
    switch (map.getCurrentMapType()) {
        case G_NORMAL_MAP:
            cMapType = 5;
        case G_SATELLITE_MAP:
            cMapType = 6;
            break;
        case G_HYBRID_MAP:
            cMapType = 7;
            break;
        case G_PHYSICAL_MAP:
            cMapType = 8;
            break;
    }
    InitGMap();
}

function ClearAndReinit() {
}

// Get all informations of the map, which are important for the change to another MapType
//function GMapGetMapChangeSettings() {
function GetMapChangeSettings() {
    infos = new Object();
    loc = map.getCenter();
    // Localize
    if (Sys.CultureInfo.CurrentCulture.name.indexOf('de') == 0) {
        infos.CenterLat = loc.lat().toString().replace('.', ',');
        infos.CenterLon = loc.lng().toString().replace('.', ',');
    } else {
        infos.CenterLat = loc.lat().toString();
        infos.CenterLon = loc.lng().toString();
    }
    infos.ZoomLevel = map.getZoom();
    infos.MapType = "GMap";
    if (map.getCurrentMapType() == G_SATELLITE_MAP || map.getCurrentMapType() == G_HYBRID_MAP)
        infos.MapView = "G_SATELLITE_MAP";
    if (map.getCurrentMapType() == G_PHYSICAL_MAP)
        infos.MapView = "G_PHYSICAL_MAP";
    if (map.getCurrentMapType() == G_NORMAL_MAP)
        infos.MapView = "G_NORMAL_MAP";
    
    return infos;
}
function SaveCurrentView() {

    cMapTypeString = "GoogleMap_Road";
    switch (map.getCurrentMapType()) {
        case G_NORMAL_MAP:
            //alert("Road");
            cMapTypeString = "GoogleMap_Road";
            break;
        case G_SATELLITE_MAP:
            //alert("Satellite");
            cMapTypeString = "GoogleMap_Satellite";
            break;
        case G_HYBRID_MAP:
            //alert("Hybrid");
            cMapTypeString = "GoogleMap_Hybrid";
            break;
        case G_PHYSICAL_MAP:
            //alert("Terrain");
            cMapTypeString = "GoogleMap_Terrain";
            break;
    }

    url = "/Controls/MapControlViewAsyncWorker.aspx";
    if (jsonMapDataRoutes != null) {
        routeID = jsonMapDataRoutes[0].ID;
        paramString = "Method=SaveCurrentViewRoute&RouteID=" + routeID + "&CurrentMapType=" + cMapTypeString;
    }
    if (jsonMapDataPOIs != null) {
        poiID = jsonMapDataPOIs[0].ID;
        paramString = "Method=SaveCurrentViewPOI&POIID=" + poiID + "&CurrentMapType=" + cMapTypeString;
    }
    SendAjaxRequest("GET", url, paramString, "OnSaveCurrentViewSuccess", "OnSaveCurrentViewFail");
}
function OnSaveCurrentViewSuccess(obj) {
    if (obj.Status == "FAIL")
        MapControlShowMessageBox(true, Resources_MapControlView.CustomMenuSaveMapTypeFailMessage, 3000);
    else
        MapControlShowMessageBox(true, Resources_MapControlView.CustomMenuSaveMapTypeSuccessMessage, 3000);
}
function OnSaveCurrentViewFail(obj) {
    MapControlShowMessageBox(true, Resources_MapControlView.CustomMenuSaveMapTypeFailMessage, 3000);
}

function AdjustMapBounds(NWPoint, SEPoint) {
    adjustBounds = new GLatLngBounds(new GLatLng(NWPoint.Lat, NWPoint.Lon), new GLatLng(SEPoint.Lat, SEPoint.Lon));
    boundZoom = map.getBoundsZoomLevel(adjustBounds);
    map.setZoom(boundZoom);
}


// ###############################################################################
// DRAW DATA TO THE MAP
// ###############################################################################
function CWMapDrawPin(type, lat, lon, html, poiTypeID) {
    if (!poiTypeID)
        poiTypeID = 0;
    
    var myicon = new GIcon(G_DEFAULT_ICON);
    switch (type) {
        case "startend":
        case "startendWithPicture":
            myicon.image = "/App_Themes/CWDefault/MapIcons/Pin_Loop.png";
            myicon.iconSize = new GSize(41, 58);
            myicon.iconAnchor = new GPoint(22, 51);
            myicon.infoWindowAnchor = new GPoint(0, 0);
            myicon.imageMap = new Array(0, 0, 41, 0, 41, 58, 0, 58);
            break;
        case "start":
        case "startWithPicture":
            myicon.image = "/App_Themes/CWDefault/MapIcons/Pin_Start.png";
            myicon.iconSize = new GSize(41, 58);
            myicon.iconAnchor = new GPoint(22, 51);
            myicon.infoWindowAnchor = new GPoint(0, 0);
            myicon.imageMap = new Array(0, 0, 41, 0, 41, 58, 0, 58);
            break;
        case "end":
        case "endWithPicture":
            myicon.image = "/App_Themes/CWDefault/MapIcons/Pin_End.png";
            myicon.iconSize = new GSize(41, 58);
            myicon.iconAnchor = new GPoint(22, 51);
            myicon.infoWindowAnchor = new GPoint(0, 0);
            myicon.imageMap = new Array(0, 0, 41, 0, 41, 58, 0, 58);
            break;
        case "picture":
            myicon.image = "/App_Themes/CWDefault/MapIcons/Pin_Photo.png";
            myicon.iconSize = new GSize(41, 41);
            myicon.iconAnchor = new GPoint(19, 35);
            myicon.infoWindowAnchor = new GPoint(25, 40);
            myicon.imageMap = new Array(0, 0, 41, 0, 41, 41, 0, 41);
            break;
        case "poi":
            myicon.image = String.format("/App_Themes/CWDefault/PoiIcons/POIPin-{0}_small.png", poiTypeID);
            myicon.iconSize = new GSize(35, 45);
            myicon.iconAnchor = new GPoint(18, 39);
            myicon.infoWindowAnchor = new GPoint(25, 40);
            myicon.imageMap = new Array(0, 0, 35, 0, 35, 45, 0, 45);
            break;
        case "comment":
            myicon.image = "/App_Themes/CWDefault/MapIcons/Pin_Comment.png";
            myicon.iconSize = new GSize(41, 41);
            myicon.iconAnchor = new GPoint(19, 35);
            myicon.infoWindowAnchor = new GPoint(25, 40);
            myicon.imageMap = new Array(0, 0, 41, 0, 41, 41, 0, 41);
            break;
        case "wiki":
            myicon.image = "/images/Wikipedia_Icon_kl.png";
            myicon.iconSize = new GSize(24, 24);
            myicon.iconAnchor = new GPoint(13, 20);
            myicon.infoWindowAnchor = new GPoint(15, 24);
            myicon.imageMap = new Array(0, 0, 24, 0, 24, 24, 0, 24);
    }
    
    // Marker
    markeropts = {
        icon: myicon
    };
    point = new GLatLng(lat, lon);
    var marker = new GMarker(point, markeropts);
    GEvent.addListener(marker, "mouseover", function() {
        marker.openInfoWindowHtml(html);
    });

    //return marker;
    map.addOverlay(marker);

    return marker;
}

function CWMapDrawRoute(data, lineColor, lineAlpha) {
    if (lineAlpha == null) {
        lineAlpha = 0.7;
    }
    if (lineColor == null) {
        if (data.MainRouteTypeID == 19 || data.MainRouteTypeID == 24 || data.MainRouteTypeID == 27)
            lineColor = "#0000FF";
        else
            lineColor = "#FF0000";
    }
    
    GTrackPoints = new Array();
    for (var t = 0; t < data.TrackPoints.length; t++) {
        GTrackPoints.push(new GLatLng(data.TrackPoints[t].Lat, data.TrackPoints[t].Lon));
    }
    overlay = new GPolyline(GTrackPoints, lineColor, 3, lineAlpha);
    map.addOverlay(overlay);
}



// ###############################################################################
// ADD POIS AND COMMENTS TO THE MAP
// ###############################################################################
function MapAddPOI(Description) {
    myicon = new GIcon(G_DEFAULT_ICON);
    myicon.image = String.format("/App_Themes/CWDefault/PoiIcons/POIPin-{0}_small.png", 1);
    myicon.iconSize = new GSize(35, 45);
    myicon.iconAnchor = new GPoint(18, 39);
    myicon.infoWindowAnchor = new GPoint(25, 40);
    myicon.imageMap = new Array(0, 0, 35, 0, 35, 45, 0, 45);
    markeropts = {
        icon: myicon,
        draggable:true,
        bouncy:false,
        dragCrossMove:true
    };
    loc = map.getCenter();
    AddMarker = new GMarker(loc, markeropts);
    POIDescription = Description;
    
    GEvent.addListener(AddMarker, "mouseover", function() {
        AddMarker.openInfoWindowHtml(String.format(POIDescription, jsonMapDataRoutes[0].ID, loc.lat().toString().replace('.', ','), loc.lng().toString().replace('.', ',')));
    });
    GEvent.addListener(AddMarker, "dragstart", function() {
        map.closeInfoWindow();
    });
    GEvent.addListener(AddMarker, "dragend", function() {
        AddMarker.openInfoWindowHtml(String.format(POIDescription, jsonMapDataRoutes[0].ID, AddMarker.getLatLng().lat().toString().replace('.', ','), AddMarker.getLatLng().lng().toString().replace('.', ',')));
    });
    
    // Add the Marker on the map
    map.addOverlay(AddMarker);
    // Open the Infowindow when the marker is added to the map
    AddMarker.openInfoWindowHtml(String.format(POIDescription, jsonMapDataRoutes[0].ID, loc.lat().toString().replace('.', ','), loc.lng().toString().replace('.', ',')));
}
function MapCancelAddPOI() {
    map.removeOverlay(AddMarker);
}
// ADD COMMENT to the map ##############################
function MapAddComment(Description) {

    myicon = new GIcon(G_DEFAULT_ICON);
    myicon.image = "/App_Themes/CWDefault/MapIcons/Pin_Comment.png";
    myicon.iconSize = new GSize(41, 41);
    myicon.iconAnchor = new GPoint(19, 35);
    myicon.infoWindowAnchor = new GPoint(25, 40);
    myicon.imageMap = new Array(0, 0, 41, 0, 41, 41, 0, 41);
    markeropts = {
        icon: myicon,
        draggable: true,
        bouncy: false,
        dragCrossMove: true
    };
    loc = map.getCenter();
    AddMarker = new GMarker(loc, markeropts);

    GEvent.addListener(AddMarker, "mouseover", function() {
        AddMarker.openInfoWindowHtml(Description);
    });
    GEvent.addListener(AddMarker, "dragstart", function() {
        map.closeInfoWindow();
    });
    GEvent.addListener(AddMarker, "dragend", function() {
        AddMarker.openInfoWindowHtml(Description);
        if (Sys.CultureInfo.CurrentCulture.name.indexOf('de') > 0) {
            document.getElementById(CCGeocodedCommentLatitude).value = AddMarker.getLatLng().lat().toString().replace('.', ',');
            document.getElementById(CCGeocodedCommentLongitude).value = AddMarker.getLatLng().lng().toString().replace('.', ',');
        } else {
            document.getElementById(CCGeocodedCommentLatitude).value = AddMarker.getLatLng().lat().toString();
            document.getElementById(CCGeocodedCommentLongitude).value = AddMarker.getLatLng().lng().toString();
        }
    });

    // Add the Marker on the map
    map.addOverlay(AddMarker);
    // Open the Infowindow when the marker is added to the map
    AddMarker.openInfoWindowHtml(Description);

    // Localize the coordinates
    if (Sys.CultureInfo.CurrentCulture.name.indexOf('de') > 0) {
        document.getElementById(CCGeocodedCommentLatitude).value = loc.lat().toString().replace('.', ',');
        document.getElementById(CCGeocodedCommentLongitude).value = loc.lng().toString().replace('.', ',');
    } else {
        document.getElementById(CCGeocodedCommentLatitude).value = loc.lat().toString();
        document.getElementById(CCGeocodedCommentLongitude).value = loc.lng().toString();
    }
}
function MapCancelAddComment() {
    map.removeOverlay(AddMarker);
}



// ###############################################################################
// ADD COMMENTS TO MAP
//      External Function Support for (CommentList.ascx)
// ###############################################################################
var CommentOnMapArray = null;
function AddCommentOnMap(comment, GeocodedHeaderText) {
    var description = CreateCommentPopup();
    description = String.format(description, ResGeocodedCommentHeader, unescape(comment.Text), comment.CreatedByUserAvatar.replace("_thumb25_", "_thumb50_"), comment.CreatedByUserLink, comment.CreatedByUserDisplayName, comment.PostedTime);
    //var marker = GMapCreatePin("comment", new GLatLng(comment.Latitude, comment.Longitude), description);
    var marker = CWMapDrawPin("comment", comment.Latitude, comment.Longitude, description);
    
    if (CommentOnMapArray == null) {
        CommentOnMapArray = new Array();
    }
    CommentOnMapArray.push(marker);
}
// External Function Support for (CommentList.ascx)
function DeleteAllCommentsOnMap() {
    if (CommentOnMapArray != null) {
        for (var i = 0; i < CommentOnMapArray.length; i++) {
            map.removeOverlay(CommentOnMapArray[i]);
        }
    }
}


// ###############################################################################
// SEARCH THE MAP
// ###############################################################################
function SearchAndMoveMap(searchstring) {
    try {
        geocoder = new GClientGeocoder();
        geocoder.getLatLng(searchstring, SearchCallback);
    }
    catch (e) {
        alert(e.message);
    }
}
function SearchCallback(point) {
    if (point != null) {
        map.panTo(point);
    }
    else {
        alert("No Location was found. Try another search query...");
    }
}



// ###############################################################################
// ADDITIONAL MAP INFOS (wiki, weather, mountain names
// ###############################################################################
var WikiEntriesOnMapArray = null;
var WeatherEntriesOnMapArray = null;
var MountainEntriesOnMapArray = null;

// Wiki -----------------
function MapControlGMapAddWikiEntries() {
    NWLatLong = map.fromContainerPixelToLatLng(new GPoint(0, 0));
    var mapBox = Sys.UI.DomElement.getBounds(document.getElementById(MapControlViewMapID));
    SELatLong = map.fromContainerPixelToLatLng(new GPoint(mapBox.width, mapBox.height));
    
    MapControlShowMessageBox(true, "Please wait while retrieving wikipedia data...", 3000);
    LeaveYourTracks.com.WSAjax.AJAXSvc.GetWikiByBoundingBox(NWLatLong.lat(), SELatLong.lat(), SELatLong.lng(), NWLatLong.lng(), "de", MapControlGMapAddWikiEntries_success, MapControlGMapAddWikiEntries_Failed);
}
function MapControlGMapAddWikiEntries_success(e) {
    var wikiData = Sys.Serialization.JavaScriptSerializer.deserialize(e);
    var entriesFound = 0;

    if (wikiData.geonames && wikiData.geonames.length > 0) {
        Array.forEach(wikiData.geonames, MapControlGMapAddWikiPushpin);
        entriesFound = wikiData.geonames.length;
    }

    if (entriesFound > 0) {
        var message = String.format("{0} wikipedia entries found.", entriesFound);
        MapControlShowMessageBox(true, message, 2000);
    }
    else {
        MapControlShowMessageBox(true, "No Wikipedia entries found. Please try again.", 5000);
    }
}
function MapControlGMapAddWikiEntries_Failed(e) {
    MapControlShowMessageBox(true, "Error while connecting to the remote web service. Please try again later.", 5000);
}
function MapControlGMapAddWikiPushpin(entry) {
    var htmlImage = "<div style=\"width:300px; font-size:12px;\"><br/><b>Summary: </b> {1}<br/>" +
            "<br/><img src=\"{3}\" alt=\"Thumbnail\" /><br/><br/><b>Wikipedia-Link: </b><a href=\"http://{2}\" target=\"_new\" >{0}</a></div>";
    var htmlNoImage = "<div style=\"width:300px; font-size:12px;\"><br/><b>Summary: </b> {1}<br/>" +
            "<br/><br/><b>Wikipedia-Link: </b><a href=\"http://{2}\" target=\"_new\" >{0}</a></div>";
    var description = "";
    if (entry.thumbnailImg == undefined)
        description = String.format(htmlNoImage,
            entry.title, entry.summary, escape(entry.wikipediaUrl));
    else
        description = String.format(htmlImage,
            entry.title, entry.summary, escape(entry.wikipediaUrl),
            escape(entry.thumbnailImg));

    //var marker = GMapCreatePin("wiki", new GLatLng(entry.lat, entry.lng), description);
    var marker = CWMapDrawPin("wiki", entry.lat, entry.lng, description);

    // Add entry on the map & in the array
    if (WikiEntriesOnMapArray == null) {
        WikiEntriesOnMapArray = new Array();
    }
    WikiEntriesOnMapArray.push(marker);
}

// Weather --------------------------------
function MapControlGMapAddWeatherInfos() {
    var center = map.getCenter();
    LeaveYourTracks.com.WSAjax.AJAXSvc.GetWeatherByLocation(center.lat(), center.lng(), MapControlGMapAddWeatherInfos_success, MapControlGMapAddWeatherInfos_Failed);
    MapControlShowMessageBox(true, "Please wait while retrieving weather data...");
}
function MapControlGMapAddWeatherInfos_Failed(e) {
    MapControlShowMessageBox(true, "Error while connecting to the remote web service. Please try again later.", 5000);
}
function MapControlGMapAddWeatherInfos_success(e) {
    var weatherData = Sys.Serialization.JavaScriptSerializer.deserialize(e);
    var stationsFound = 0;
    if (weatherData.weatherObservations && weatherData.weatherObservations.length > 0) {
        Array.forEach(weatherData.weatherObservations, MapControlGMapAddWeatherPushpin);
        stationsFound = weatherData.weatherObservations.length;
    }
    if (stationsFound > 0) {
        var message = String.format("Data was retrieved for {0} weather stations.", stationsFound);
        MapControlShowMessageBox(true, message, 2000);
    }
    else {
        MapControlShowMessageBox(true, "No weather data was found. Please try again.", 5000);
    }
}
function MapControlGMapAddWeatherPushpin(observation) {
    var icon;
    // The observation time is parsed in order to determine 
    // whether the observation was taken during the day or 
    // the night and choose an appropriate icon.
    // The format of the returned date is yyyy-MM-dd hh:mm:ss 
    var d = observation.datetime;
    var date = new Date(d.substr(0, 4), d.substr(5, 2), d.substr(8, 2),
                        d.substr(11, 2), d.substr(14, 2), d.substr(17, 2));

    var isDay = (date.getHours() > 6 && date.getHours() < 20);

    switch (observation.clouds) {
        case 'clear sky':
            if (isDay) icon = '32'; else icon = '31';
            break;
        case 'few clouds':
            if (isDay) icon = '30'; else icon = '29';
            break;
        case 'scattered clouds':
            if (isDay) icon = '28'; else icon = '27';
            break;
        case 'broken clouds':
            icon = '26';
            break;
        case 'overcast':
        case 'vertical visibility':
            icon = '23';
            break;
        default:
            icon = 'NA';
    }
    // The wind speed is converted from knots to m/s 
    var windSpeedMs = Math.round(observation.windSpeed * 0.5144444 * 100) / 100;

    var html = "<div style=\"width:300px; font-size:12px;\"><em>{0}</em><br/><b>Clouds:</b> {1}<br/><b>Weather condition:</b> {2}<br/>" +
            "<b>Temperature:</b> {3} °C<br/><b>Dew Point:</b> {4} °C<br/>" +
            "<b>Wind:</b> {5}kt ({6} m/s) from {7}°<br/><b>Altimeter:</b> {8} hPa</div>";
    var details = String.format(html,
            observation.datetime, observation.clouds, observation.weatherCondition,
            observation.temperature, observation.dewPoint, observation.windSpeed,
            windSpeedMs, observation.windDirection, observation.hectoPascAltimeter);


    // Add Marker
    var myicon = new GIcon(G_DEFAULT_ICON);
    myicon.image = String.format("/images/{0}.png", icon);
    myicon.iconSize = new GSize(48, 48);
    myicon.iconAnchor = new GPoint(26, 40);
    myicon.infoWindowAnchor = new GPoint(30, 48);
    myicon.imageMap = new Array(0, 0, 48, 0, 48, 48, 0, 48);
    markeropts = {
        icon: myicon
    };
    var marker = new GMarker(new GLatLng(observation.lat, observation.lng), markeropts);
    GEvent.addListener(marker, "mouseover", function() {
        marker.openInfoWindowHtml(details);
    });
    

    // Add entry on the map & in the array
    if (WeatherEntriesOnMapArray == null) {
        WeatherEntriesOnMapArray = new Array();
    }
    WeatherEntriesOnMapArray.push(marker);
    map.addOverlay(marker);
}


// Mountain names ---------------------
function MapControlGMapAddMountainNames() {
    var center = map.getCenter();
    LeaveYourTracks.com.WSAjax.AJAXSvc.GetMountainNames(center.lat(), center.lng(), MapControlGMapAddMountainNames_success, MapControlGMapAddMountainNames_Failed);
    MapControlShowMessageBox(true, "Please wait while retrieving mountain data...", 3000);
}
function MapControlGMapAddMountainNames_Failed(e) {
    MapControlShowMessageBox(true, "Error while connecting to the remote web service. Please try again later.", 5000);
}
function MapControlGMapAddMountainNames_success(e) {
    var MountainNames;
    var entriesFound = 0;

    for (i = 0; i < e.length; i++) {
        var Mountain = e[i];
        MapControlGMapAddMountainNamePushpin(Mountain);
    }

    if (e.length > 0) {
        var message = String.format("{0} mountains found.", e.length);
        MapControlShowMessageBox(true, message, 5000);
    }
    else {
        MapControlShowMessageBox(true, "No mountains found...", 5000);
    }
}
function MapControlGMapAddMountainNamePushpin(Mountain) {
    // Add Marker
    var myicon = new GIcon(G_DEFAULT_ICON);
    myicon.image = Mountain.PinURL;
    //alert(Mountain.PinURL);
    
    var bild = new Image();
    bild.src = Mountain.PinURL;
    bild.onload = function(e) {
        // Show Mountain Names when the pictures are loaded
        myicon.iconSize = new GSize(bild.width, 23);
        markeropts = {
            icon: myicon
        };
        var marker = new GMarker(new GLatLng(Mountain.Latitude, Mountain.Longitude), markeropts);

        // Add entry on the map & in the array
        if (MountainEntriesOnMapArray == null) {
            MountainEntriesOnMapArray = new Array();
        }
        MountainEntriesOnMapArray.push(marker);
        map.addOverlay(marker);
    }
}


// Clear all infos -----------
function MapControlGMapClearAdditionalInfosOnMap() {
    // Wiki Entries
    if (WikiEntriesOnMapArray != null) {
        for (var i = 0; i < WikiEntriesOnMapArray.length; i++) {
            map.removeOverlay(WikiEntriesOnMapArray[i]);
        }
    }
    WikiEntriesOnMapArray = null;
    // Weather Info Entries
    if (WeatherEntriesOnMapArray != null) {
        for (var i = 0; i < WeatherEntriesOnMapArray.length; i++) {
            map.removeOverlay(WeatherEntriesOnMapArray[i]);
        }
    }
    WeatherEntriesOnMapArray = null;
    // Mountain Name Entries
    if (MountainEntriesOnMapArray != null) {
        for (var i = 0; i < MountainEntriesOnMapArray.length; i++) {
            map.removeOverlay(MountainEntriesOnMapArray[i]);
        }
    }
    MountainEntriesOnMapArray = null;
}
