﻿
var map = null;
var language;
var latitude;
var longitude;
var title;
var description;
var zoom = 16;
var style;

function GetMap(){
    //Lat & Lng Bergamo: 45.7040570355124200, 9.6629476547241200
    
    var lat_lng = new VELatLong(latitude, longitude);

    map = new VEMap('map');
    map.LoadMap();
    
    switch(style) {
        case 'aerial': 
            map.SetMapStyle(VEMapStyle.Aerial);
            break;
        default: 
            map.SetMapStyle(VEMapStyle.Road);
            break;
    }

    LoadPlacesLayer('POI/'+ language +'/1.xml', 'POI/Images/1.gif');    //Aeroporti
    LoadPlacesLayer('POI/'+ language +'/2.xml', 'POI/Images/2.gif');    //Centro Storico
    LoadPlacesLayer('POI/'+ language +'/3.xml', 'POI/Images/3.gif');    //Stazioni
    LoadPlacesLayer('POI/'+ language +'/4.xml', 'POI/Images/4.gif');    //Laghi
    LoadPlacesLayer('POI/'+ language +'/7.xml', 'POI/Images/7.gif');    //Teatri
    LoadPlacesLayer('POI/'+ language +'/8.xml', 'POI/Images/8.gif');    //Fiere
    LoadPlacesLayer('POI/'+ language +'/9.xml', 'POI/Images/9.gif');    //Ospedali
    LoadPlacesLayer('POI/'+ language +'/10.xml', 'POI/Images/10.gif');  //Stadio
    LoadPlacesLayer('POI/'+ language +'/11.xml', 'POI/Images/11.gif');  //Attrazioni (Gardaland)
    LoadPlacesLayer('POI/'+ language +'/12.xml', 'POI/Images/12.gif');  //Città
    LoadPlacesLayer('POI/'+ language +'/13.xml', 'POI/Images/13.gif');  //Autostazioni
    
    AddPushPin(lat_lng, title, description);
    map.SetCenterAndZoom(lat_lng, zoom);
}

function AddPushPin(lat_lng, title, description) {
    var pushpin = new VEShape(VEShapeType.Pushpin, lat_lng);
    
    pushpin.SetTitle(title);
    pushpin.SetCustomIcon('POI/images/pushpin_ico.gif');
    pushpin.SetDescription(description);
    
    map.AddShape(pushpin);
}

function LoadPlacesLayer(src, IconUrl) {
    var layer = new VEShapeLayer();
    var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, src, layer);
    
    map.ImportShapeLayerData(veLayerSpec, function() {
        var numShapes = layer.GetShapeCount();
        var s, n, icon;
		 
        for (var i = 0; i < numShapes; ++i) {
		    s = layer.GetShapeByIndex(i);
				
		    n = i + 1;
		    icon = IconUrl;
		    s.SetCustomIcon(icon);
        }
    }, false);
}

function OpenMap(url, structure, style) {
    window.open(url + '?structure='+ structure + '&style='+ style +'','map','width=990,height=500');
}
