Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 31 | Blame | Last modification | View Log | RSS feed

var map;
var marker;

function ajouterListenerFormulaireSaisieLatLon() {
        
        $('#cacher_afficher_lien').bind('click', function() {
                $('#conteneur_liens_lat_lon').slideToggle();
                return false;
        });
        
        $('#station_lat').bind('blur', function() {
                verifierEtLocaliserCoordonnees();
        });
        
        $('#station_lon').bind('blur', function() {
                verifierEtLocaliserCoordonnees();
        });
        
        $('#localiser_lat_lon').click(function() {
                verifierEtLocaliserCoordonnees();
        });
        
        $('#conteneur_liens_lat_lon').hide();
}

function verifierEtLocaliserCoordonnees() {
        
        var lat = $('#station_lat').val();
        var lon = $('#station_lon').val();
        
        if(!isNaN(lat) && lat.length > 0 && !isNaN(lon) && lon.length > 0) {
                
        } else {
                window.alert("coordonnées invalides");
        }
        
        var positionMarker = new google.maps.LatLng(lat, lon);
        
        marker.setPosition(positionMarker);
        map.setCenter(positionMarker);
}

function mettreAJourValeursFormulaire(latlon) {

        latlon = latlon.toString().split(','); 
        
        $('#station_lat').val(latlon[0].replace('(', ''));
        $('#station_lon').val(latlon[1].replace(')', ''));
}

function initialiserCarte() {

        var latlng = new google.maps.LatLng(47.0504, 2.2347);
        var myOptions = {
                zoom: 6,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.HYBRID
        };

        map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
        
        marker = new google.maps.Marker({
              position: latlng,
              title:""
        });
        
        marker.setDraggable(true);
        marker.setClickable(true);
        
        google.maps.event.addListener(marker, 'dragend', function() {   
                mettreAJourValeursFormulaire(marker.getPosition())
        });

        // To add the marker to the map, call setMap();
        marker.setMap(map); 
}

$(document).ready(function() {
        initialiserCarte();
});

$('#conteneur_liens_lat_lon').ready(function() {
        ajouterListenerFormulaireSaisieLatLon();
});