﻿Entities.prototype.afficherCarte = function (e) {

    var latitude = e.Latitude;
    var longitude = e.Longitude;
    var adresse = e.Adresse;

    if (!latitude || !longitude) {
        //Recherche par l'adresse
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode({
            'address': adresse
        }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var res = results[0].geometry.location;
                e.Latitude = res.lat();
                e.Longitude = res.lng();
                creerMap(e);
            }
        });
    }
    else {
        e.Latitude = latitude;
        e.Longitude = longitude;

        if (!latitude || !longitude) {
            //France
            e.Latitude = 46.227638;
            e.Longitude = 2.213749;
            e.Zoom = 5;
        }
        creerMap(e);
    }
};

function creerMap(e) {
    var latlng = new google.maps.LatLng(e.Latitude, e.Longitude);
    var ImageUrl = e.ImageUrl;
    if (!e.Zoom)
        e.Zoom = 15;
    var myOptions = {
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: latlng,
        zoom: e.Zoom,
        mapTypeControl: false,
        streetViewControl: false,
        zoomControl: false,
        disableDoubleClickZoom: true,
        draggable: false,
        scrollwheel: false
    }
    
    var map = new google.maps.Map(document.getElementById(e.IdDiv), myOptions);
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon: ImageUrl
    });
   

}
