﻿var map = null,
    LA = null,
    pinPoint = null,
    pinPixel = null;

function GetMap() {
    if (document.getElementById('myMap')) {
        LA = new VELatLong(47, 2.75);
        map = new VEMap('myMap');
        map.SetDashboardSize(VEDashboardSize.Tiny);
        map.LoadMap(LA, 4, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);

        AddPin(50.7482405, 3.2177093, null, 'Wygwam Belux', '64 rue Victor Corne, 7700 Mouscron, Belgique', './Images/Icones/Geo/pin_be.png');
        AddPin(48.8774965, 2.3281525, null, 'Wygwam Paris', '3 rue Grenéta, 75003 Paris, France', './Images/Icones/Geo/pin_fr.png');
        AddPin(46.1972867, 6.1466730, null, 'Wygwam Suisse', 'Route des Jeunes 9, 1227 Acacias-Carouge (GE), Suisse', './Images/Icones/Geo/pin_sw.png');
        AddPin(50.6335550, 3.0214250, null, 'Wygwam', 'Euratechnologies, 165 Avenue de Bretagne, 59000 Lille, France', './Images/Icones/Geo/pin_fr.png');
    }
}

function getInfo() {
    var info;

    if (map.IsBirdseyeAvailable()) {
        var be = map.GetBirdseyeScene();

        info = "ID: " + be.GetID() + "\n";
        info += "thumbnail: " + be.GetThumbnailFilename() + "\n";
        info += "orientation: " + be.GetOrientation() + "\n";
        info += "height: " + be.GetHeight() + "\n";
        info += "width: " + be.GetWidth() + "\n";

        var pixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());

        info += "LatLongToPixel: " + pixel.x + ", " + pixel.y + "\n";

        // Check to see if the current birdseye view contains the pushpin pixel point.
        info += "contains pixel " + pinPixel.x + ", " + pinPixel.y + ": " +
            be.ContainsPixel(pinPixel.x, pinPixel.y, map.GetZoomLevel()) + "\n";

        // Check to see if the current view contains the pushpin LatLong.
        info += "contains latlong " + pinPoint + ": " + be.ContainsLatLong(pinPoint) + "\n";

        // This method may return null, depending on the selected view and map style.
        info += "latlong: " + map.PixelToLatLong(pixel);

        alert(info);
    }
    else {
        var center = map.GetCenter();

        info = "Zoom level:\t" + map.GetZoomLevel() + "\n";
        info += "Latitude:\t" + center.Latitude + "\n";
        info += "Longitude:\t" + center.Longitude;

        alert(info);
    }
}

function AddPin(lat, lon, iconurl, title, desc, sIcon) {
    var shape =
        new VEShape(VEShapeType.Pushpin,
        new VELatLong(lat, lon));
    shape.SetTitle(title);
    shape.SetDescription(desc);
    if(sIcon != "")
        shape.SetCustomIcon(sIcon);
    map.AddShape(shape);
}
