Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 31 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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