Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1093 Rev 1105
Line 78... Line 78...
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
	}
Line -... Line 82...
-
 
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
	}
82
 
91
 
83
	var options = {
92
	var options = {
84
		zoom: 16,
93
		zoom: 16,
85
		center: latLng,
94
		center: latLng,
86
		mapTypeId: google.maps.MapTypeId.HYBRID,
95
		mapTypeId: google.maps.MapTypeId.HYBRID,
Line 123... Line 132...
123
 
132
 
Line 124... Line 133...
124
$(document).ready(function() {
133
$(document).ready(function() {
Line 125... Line -...
125
	
-
 
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
			});
134
	
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) {
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
				geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
147
								rue = this.short_name;
148
					if (status == google.maps.GeocoderStatus.OK) {
148
							}
149
						response($.map(results, function(item) {
149
						});
150
							return {
150
						var retour = {
151
								label: item.formatted_address,
151
							label: item.formatted_address,
152
								value: item.formatted_address,
152
							value: rue,
-
 
153
							latitude: item.geometry.location.lat(),
153
								latitude: item.geometry.location.lat(),
154
							longitude: item.geometry.location.lng()
154
								longitude: item.geometry.location.lng()
155
						};
155
							}
156
						return retour;
156
						}));
157
					}));
157
					} else {
158
				} else {
158
						afficherErreurGoogleMap(status);
159
					afficherErreurGoogleMap(status);
159
					}
160
				}
160
				})
161
			})
161
			},
-
 
162
			// Cette partie est executee a la selection d'une adresse
-
 
163
			select: function(event, ui) {
162
		},
164
				remplirChampLatitude(ui.item.latitude);
163
		// Cette partie est executee a la selection d'une adresse
165
				remplirChampLongitude(ui.item.longitude);
-
 
166
				var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
-
 
167
				deplacerMarker(latLng);
164
		select: function(event, ui) {
168
				map.setCenter(latLng);
165
			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
Line -... Line 166...
-
 
166
			deplacerMarker(latLng);
-
 
167
		}
-
 
168
	});
-
 
169
	
-
 
170
	$("#geolocaliser").click(function() {
-
 
171
		var latitude = $('#latitude').val();
-
 
172
		var longitude = $('#longitude').val();
169
				map.setZoom(19);
173
		latLng = new google.maps.LatLng(latitude, longitude);
170
			}
174
		deplacerMarker(latLng);
171
		});
-
 
172
		
-
 
173
		google.maps.event.addListener(marker, 'dragend', function() {
-
 
174
			trouverCommune(marker.getPosition());
-
 
175
			geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
175
	});
176
				if (status == google.maps.GeocoderStatus.OK) {
-
 
177
					if (results[0]) {
-
 
178
						$('#adresse').val(results[0].formatted_address);
-
 
179
						mettreAJourMarkerPosition(marker.getPosition());
-
 
180
					}
-
 
181
				} else  {
-
 
182
					afficherErreurGoogleMap(status);
-
 
183
				}
176
	
Line 184... Line -...
184
			});
-
 
185
		});
-
 
186
	});
-
 
187
});
-
 
188
 
-
 
189
// Transforme les coordonnés en adresse (reverse geocoder)
177
	google.maps.event.addListener(marker, 'dragend', function() {
190
function codeLatLng() {
-
 
191
	var lat = parseFloat(document.getElementById("latitude").value);
-
 
192
	var lng = parseFloat(document.getElementById("longitude").value);
178
		trouverCommune(marker.getPosition());
193
	var latlng = new google.maps.LatLng(lat, lng);
-
 
194
	geocoder.geocode({'latLng': latlng}, function(results, status) {
-
 
195
		if (status == google.maps.GeocoderStatus.OK) {
179
		mettreAJourMarkerPosition(marker.getPosition());
196
			if (results[0]) {
-
 
197
				marker.setPosition(latlng);
-
 
198
				map.setCenter(latlng);
-
 
199
				$('#adresse').val(results[0].formatted_address);
180
	});
200
			}
-
 
Line 201... Line 181...
201
		} else {
181
	
202
			afficherErreurGoogleMap(status);
182
	google.maps.event.addListener(map, 'click', function(event) {
203
		}
183
		deplacerMarker(event.latLng);
204
	});
184
	});
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'),