﻿enricofoschi.defineNamespace("enricofoschi.thirds.maps.virtualearth");

enricofoschi.thirds.maps.virtualearth = function() {
    //
}
enricofoschi.thirds.maps.virtualearth.prototype = {
    LoadDefaultMap : function(mapDiv) {
        if(!mapDiv) mapDiv = this.defaultDiv;
        this.currentMap = new VEMap(mapDiv);
        this.currentMap.LoadMap(new VELatLong(41.2, 15.03), 5 ,VEMapStyle.Road);
        return this.currentMap;
    },
    AddRoute : function(id, startX, startY, endX, endY) {
        var arrayStartEnd = [new VELatLong(parseFloat(startY),parseFloat(startX)), new VELatLong(parseFloat(endY),parseFloat(endX))];
        var newShape = new VEShape(VEShapeType.Polyline,arrayStartEnd);
        newShape.SetDescription("<a href=\"#\" onclick=\"return viewRoute("+id+");\">Visualizza dettagli</a>");
        this.currentMap.AddShape(newShape);
        var newRoute = new Object();
        newRoute.id = id;
        newRoute.startX = startX;
        newRoute.startY = startY;
        newRoute.endX = endX;
        newRoute.endY = endY;
        newRoute.shape = newShape;
        this.arRoutes.push(newRoute);
    },
    FocusRoute : function(id) {
        var currentRoute = this.FindRoutesById(id);
        if(currentRoute) {
            this.currentMap.ShowInfoBox(currentRoute.shape);
        }
    },
    FindRoutesById : function(id) {
        for(var i = 0; i < this.arRoutes.length; i++) {
            if(this.arRoutes[i].id == id) return this.arRoutes[i];
        }
        return;
    },
    
    arRoutes : new Array(),
    defaultDirections : null,
    defaultShape : null,
    currentMap : null,
    defaultDiv : "msMap"
}