Subversion Repositories eFlore/Applications.cel

Rev

Rev 1093 | Rev 1108 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1093 Rev 1105
Line 77... Line 77...
77
	if (VILLE == 'Montpellier') {
77
	if (VILLE == 'Montpellier') {
78
		latLng = new google.maps.LatLng(43.61077, 3.87672);
78
		latLng = new google.maps.LatLng(43.61077, 3.87672);
79
	} else {
79
	} else {
80
		console.log('Ville:'+VILLE);
80
		console.log('Ville:'+VILLE);
81
	}
81
	}
-
 
82
	
-
 
83
	// Tentative de geocalisation
-
 
84
	if (navigator.geolocation) {
-
 
85
		navigator.geolocation.getCurrentPosition(function(position) {
-
 
86
			var latitude = position.coords.latitude;
-
 
87
			var longitude = position.coords.longitude;
-
 
88
			latLng = new google.maps.LatLng(latitude, longitude);
-
 
89
		});
-
 
90
	}
Line 82... Line 91...
82
 
91
 
83
	var options = {
92
	var options = {
84
		zoom: 16,
93
		zoom: 16,
85
		center: latLng,
94
		center: latLng,
Line 122... Line 131...
122
}
131
}
Line 123... Line 132...
123
 
132
 
Line 124... Line 133...
124
$(document).ready(function() {
133
$(document).ready(function() {
125
	
134
	
126
	initialiserGoogleMap();
-
 
127
  
-
 
128
	$(function() {
-
 
129
		// Tentative de geocalisation
-
 
130
		if (navigator.geolocation) {
-
 
131
			navigator.geolocation.getCurrentPosition(function(position) {
-
 
132
				var latitude = position.coords.latitude;
-
 
133
				var longitude = position.coords.longitude;
-
 
134
				var altitude = position.coords.altitude;
-
 
135
				var geocalisation = new google.maps.LatLng(latitude, longitude);
-
 
136
				marker.setPosition(geocalisation);
-
 
137
				map.setCenter(geocalisation);
-
 
138
				$('#adresse').val(codeLatLng(marker.getPosition()));
-
 
139
				mettreAJourMarkerPosition(marker.getPosition());
-
 
140
			});
-
 
141
		}   
135
	initialiserGoogleMap();
142
		
136
	
143
		// Autocompletion du champ adresse
137
	// Autocompletion du champ adresse
144
		$("#adresse").autocomplete({
138
	$("#rue").autocomplete({
145
			//Cette partie utilise geocoder pour extraire des valeurs d'adresse
139
		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
146
			source: function(request, response) {
-
 
147
				geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
-
 
148
					if (status == google.maps.GeocoderStatus.OK) {
-
 
149
						response($.map(results, function(item) {
-
 
150
							return {
-
 
151
								label: item.formatted_address,
-
 
152
								value: item.formatted_address,
-
 
153
								latitude: item.geometry.location.lat(),
-
 
154
								longitude: item.geometry.location.lng()
-
 
155
							}
-
 
156
						}));
-
 
157
					} else {
-
 
158
						afficherErreurGoogleMap(status);
-
 
159
					}
-
 
160
				})
-
 
161
			},
-
 
162
			// Cette partie est executee a la selection d'une adresse
-
 
163
			select: function(event, ui) {
-
 
164
				remplirChampLatitude(ui.item.latitude);
-
 
165
				remplirChampLongitude(ui.item.longitude);
-
 
166
				var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
-
 
167
				deplacerMarker(latLng);
-
 
168
				map.setCenter(latLng);
-
 
169
				map.setZoom(19);
-
 
170
			}
-
 
171
		});
-
 
172
		
-
 
173
		google.maps.event.addListener(marker, 'dragend', function() {
-
 
174
			trouverCommune(marker.getPosition());
140
		source: function(request, response) {
-
 
141
			geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
-
 
142
				if (status == google.maps.GeocoderStatus.OK) {
-
 
143
					response($.map(results, function(item) {
-
 
144
						var rue = "";
-
 
145
						$.each(item.address_components, function(){
-
 
146
							if (this.types[0] == "route" || this.types[0] == "street_address" ) {
-
 
147
								rue = this.short_name;
175
			geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
148
							}
176
				if (status == google.maps.GeocoderStatus.OK) {
149
						});
-
 
150
						var retour = {
177
					if (results[0]) {
151
							label: item.formatted_address,
-
 
152
							value: rue,
178
						$('#adresse').val(results[0].formatted_address);
153
							latitude: item.geometry.location.lat(),
-
 
154
							longitude: item.geometry.location.lng()
-
 
155
						};
179
						mettreAJourMarkerPosition(marker.getPosition());
156
						return retour;
180
					}
157
					}));
181
				} else  {
158
				} else {
182
					afficherErreurGoogleMap(status);
159
					afficherErreurGoogleMap(status);
183
				}
160
				}
184
			});
-
 
185
		});
-
 
186
	});
-
 
187
});
161
			})
188
 
162
		},
189
// Transforme les coordonnés en adresse (reverse geocoder)
-
 
190
function codeLatLng() {
-
 
191
	var lat = parseFloat(document.getElementById("latitude").value);
163
		// Cette partie est executee a la selection d'une adresse
192
	var lng = parseFloat(document.getElementById("longitude").value);
-
 
193
	var latlng = new google.maps.LatLng(lat, lng);
-
 
194
	geocoder.geocode({'latLng': latlng}, function(results, status) {
-
 
195
		if (status == google.maps.GeocoderStatus.OK) {
-
 
196
			if (results[0]) {
164
		select: function(event, ui) {
197
				marker.setPosition(latlng);
-
 
198
				map.setCenter(latlng);
-
 
199
				$('#adresse').val(results[0].formatted_address);
-
 
200
			}
-
 
201
		} else {
165
			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
202
			afficherErreurGoogleMap(status);
166
			deplacerMarker(latLng);
203
		}
167
		}
-
 
168
	});
-
 
169
	
-
 
170
	$("#geolocaliser").click(function() {
-
 
171
		var latitude = $('#latitude').val();
-
 
172
		var longitude = $('#longitude').val();
-
 
173
		latLng = new google.maps.LatLng(latitude, longitude);
-
 
174
		deplacerMarker(latLng);
-
 
175
	});
-
 
176
	
-
 
177
	google.maps.event.addListener(marker, 'dragend', function() {
-
 
178
		trouverCommune(marker.getPosition());
-
 
179
		mettreAJourMarkerPosition(marker.getPosition());
-
 
180
	});
-
 
181
	
-
 
182
	google.maps.event.addListener(map, 'click', function(event) {
-
 
183
		deplacerMarker(event.latLng);
Line 204... Line 184...
204
	});
184
	});
205
}
185
});
206
 
186
 
207
function afficherErreurGoogleMap(status) {
187
function afficherErreurGoogleMap(status) {
Line 212... Line 192...
212
			'</pre>');
192
			'</pre>');
213
		$("#dialogue-google-map").dialog();
193
		$("#dialogue-google-map").dialog();
214
	}
194
	}
215
}
195
}
Line 216... Line 196...
216
 
196
 
217
function deplacerMarker(latLon) {
197
function deplacerMarker(latLng) {
218
	if (marker != undefined) {
198
	if (marker != undefined) {
-
 
199
		marker.setPosition(latLng);
-
 
200
		map.setCenter(latLng);
219
		marker.setPosition(latLon);
201
		//map.setZoom(18);
220
		mettreAJourMarkerPosition(marker.getPosition());
202
		mettreAJourMarkerPosition(latLng);
221
		trouverCommune(marker.getPosition());
203
		trouverCommune(latLng);
222
	}
204
	}
Line 223... Line 205...
223
}
205
}
224
 
206
 
Line 389... Line 371...
389
				'famille' : taxons[numNomSel]['famille'],
371
				'famille' : taxons[numNomSel]['famille'],
390
				'nom_fr' : taxons[numNomSel]['nom_fr'],
372
				'nom_fr' : taxons[numNomSel]['nom_fr'],
391
				'milieu' : $('input[name=milieu]:checked').val(),
373
				'milieu' : $('input[name=milieu]:checked').val(),
392
				'latitude' : $("#latitude").val(),
374
				'latitude' : $("#latitude").val(),
393
				'longitude' : $("#longitude").val(),
375
				'longitude' : $("#longitude").val(),
394
				'commune_nom' : '',// TODO : utiliser le web service
376
				'commune_nom' : $("#commune-nom").text(),
395
				'commune_code_insee' : '',// TODO : utiliser le web service
377
				'commune_code_insee' : $("#commune-code-insee").text(),
396
				'lieu_dit' : $("#rue").val(),
378
				'lieu_dit' : $("#rue").val(),
397
				'station' : $("#rue_num_debut").val()+'-'+$("#rue_num_fin").val()+'-'+$("#rue_cote").val(),
379
				'station' : $("#rue_num_debut").val()+'-'+$("#rue_num_fin").val()+'-'+$("#rue_cote").val(),
398
				'notes' : $("#notes").val(),
380
				'notes' : $("#notes").val(),
399
				//Ajout des champs images
381
				//Ajout des champs images
400
				'image_nom' : $("#miniature-img").attr('alt'),
382
				'image_nom' : $("#miniature-img").attr('alt'),