| 31 |
aurelien |
1 |
var map;
|
|
|
2 |
var marker;
|
|
|
3 |
|
|
|
4 |
function ajouterListenerFormulaireSaisieLatLon() {
|
|
|
5 |
|
|
|
6 |
$('#cacher_afficher_lien').bind('click', function() {
|
|
|
7 |
$('#conteneur_liens_lat_lon').slideToggle();
|
|
|
8 |
return false;
|
|
|
9 |
});
|
|
|
10 |
|
|
|
11 |
/*$('#station_lat').bind('blur', function() {
|
|
|
12 |
verifierEtLocaliserCoordonnees();
|
|
|
13 |
});*/
|
|
|
14 |
|
|
|
15 |
/*$('#station_lon').bind('blur', function() {
|
|
|
16 |
verifierEtLocaliserCoordonnees();
|
|
|
17 |
});*/
|
|
|
18 |
|
|
|
19 |
$('#localiser_lat_lon').click(function() {
|
|
|
20 |
verifierEtLocaliserCoordonnees();
|
|
|
21 |
});
|
|
|
22 |
|
|
|
23 |
$('#conteneur_liens_lat_lon').hide();
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
function verifierEtLocaliserCoordonnees() {
|
|
|
27 |
|
|
|
28 |
var lat = $('#station_lat').val();
|
|
|
29 |
var lon = $('#station_lon').val();
|
|
|
30 |
|
|
|
31 |
if(!isNaN(lat) && lat.length > 0 && !isNaN(lon) && lon.length > 0) {
|
|
|
32 |
|
|
|
33 |
} else {
|
|
|
34 |
window.alert("coordonnées invalides");
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
var positionMarker = new google.maps.LatLng(lat, lon);
|
|
|
38 |
|
|
|
39 |
marker.setPosition(positionMarker);
|
|
|
40 |
map.setCenter(positionMarker);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
function mettreAJourValeursFormulaire(latlon) {
|
|
|
44 |
|
|
|
45 |
latlon = latlon.toString().split(',');
|
|
|
46 |
|
|
|
47 |
$('#station_lat').val(latlon[0].replace('(', ''));
|
|
|
48 |
$('#station_lon').val(latlon[1].replace(')', ''));
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
function initialiserCarte() {
|
|
|
52 |
|
|
|
53 |
var latlng = new google.maps.LatLng(47.0504, 2.2347);
|
|
|
54 |
var myOptions = {
|
|
|
55 |
zoom: 6,
|
|
|
56 |
center: latlng,
|
|
|
57 |
mapTypeId: google.maps.MapTypeId.HYBRID
|
|
|
58 |
};
|
|
|
59 |
|
|
|
60 |
map = new google.maps.Map(document.getElementById("map_canvas"),
|
|
|
61 |
myOptions);
|
|
|
62 |
|
|
|
63 |
marker = new google.maps.Marker({
|
|
|
64 |
position: latlng,
|
|
|
65 |
title:""
|
|
|
66 |
});
|
|
|
67 |
|
|
|
68 |
marker.setDraggable(true);
|
|
|
69 |
marker.setClickable(true);
|
|
|
70 |
|
|
|
71 |
google.maps.event.addListener(marker, 'dragend', function() {
|
|
|
72 |
mettreAJourValeursFormulaire(marker.getPosition())
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
// To add the marker to the map, call setMap();
|
|
|
76 |
marker.setMap(map);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
$(document).ready(function() {
|
|
|
80 |
initialiserCarte();
|
|
|
81 |
});
|
|
|
82 |
|
|
|
83 |
$('#conteneur_liens_lat_lon').ready(function() {
|
|
|
84 |
ajouterListenerFormulaireSaisieLatLon();
|
|
|
85 |
});
|