44,6 → 44,10 |
|
//+----------------------------------------------------------------------------------------------------------+ |
// PRÉCHARGEMENT DU FORMULAIRE |
var latLngDebPre = {lat: null, lng: null}, |
latLngFinPre = {lat: null, lng: null}, |
okPourChargementCarte = 2; |
|
$(document).ready(function() { |
if (OBS_ID != '') { |
chargerInfoObs(); |
71,27 → 75,55 |
function prechargerForm(infos) { |
$('input[name="station"]').val(infos.station); |
|
var dateParts = infos.dateObservation.split('-'); |
var dateObs = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]); |
var dateObsStr = ('0' + dateObs.getDate()).slice(-2) + '/' + |
('0' + (dateObs.getMonth()+1)).slice(-2) + '/' + |
dateObs.getFullYear(); |
$('input[name="date"]').val(dateObsStr); |
//console.log(infos.extension); |
if (infos.extension) { |
var ext = infos.extension; |
if (ext.latitudeDebutRue && ext.longitudeDebutRue && ext.latitudeFinRue && ext.longitudeFinRue) { |
okPourChargementCarte--; |
latLngDebPre.lat = parseFloat(ext.latitudeDebutRue.valeur); |
latLngDebPre.lng = parseFloat(ext.longitudeDebutRue.valeur); |
latLngFinPre.lat = parseFloat(ext.latitudeFinRue.valeur); |
latLngFinPre.lng = parseFloat(ext.longitudeFinRue.valeur); |
prechargerRue(); |
} |
|
$.each(infos.extension, function(index, value) { |
if ($('[name="' + index + '"]').hasClass('slider')) { |
console.log('select[name="' + index + '"] option[value="' + value.valeur + '"]'); |
$('select[name="' + index + '"] option[value="' + value.valeur + '"]') |
var chpsARemplir = ['adresse', 'typoUrbaine', 'revetementSol', 'presenceZoneVegetalise', 'hauteurBatimentAvoisinant', |
'intensiteGestion', 'periodiciteTraitementPhyto', 'dateArretTraitementPhyto', 'itineraireGestion']; |
$.each(infos.extension, function(nomDuChp, value) { |
if (chpsARemplir.indexOf(nomDuChp) >= 0) { |
if ($('[name="' + nomDuChp + '"]').hasClass('slider')) { |
$('select[name="' + nomDuChp + '"] option[value="' + value.valeur + '"]') |
.attr('selected', 'selected'); |
var selectedIndexOptions = $('select[name="' + index + '"]').prop('selectedIndex') + 1; |
console.log(selectedIndexOptions); |
$('[name="' + index + '"]').parent().find('.horizontal-slider').slider('value', selectedIndexOptions); |
var selectedIndexOptions = $('select[name="' + nomDuChp + '"]').prop('selectedIndex') + 1; |
$('[name="' + nomDuChp + '"]').parent().find('.horizontal-slider').slider('value', selectedIndexOptions); |
|
if (nomDuChp == 'periodiciteTraitementPhyto') { |
$('[name="periodiciteTraitementPhyto"]').trigger('change'); |
} |
} else { |
$('[name="' + index + '"]').val(value.valeur); |
$('[name="' + nomDuChp + '"]').val(value.valeur); |
} |
} |
}); |
} |
} |
|
function prechargerRue() { |
//console.log('okPourChargementCarte : '+okPourChargementCarte); |
if (okPourChargementCarte == 0) { |
latLngDeb = new google.maps.LatLng(latLngDebPre.lat, latLngDebPre.lng); |
markerDeb = undefined; |
initialiserMarkerDeb(); |
deplacerMarkerDeb(latLngDeb); |
premierDeplacement = false; |
markerFin = undefined; |
latLngFin = new google.maps.LatLng(latLngFinPre.lat, latLngFinPre.lng); |
initialiserMarkerFin(); |
deplacerMakerFin(latLngFin) |
surDeplacementMarkerFin(); |
map.setZoom(16); |
} |
} |
|
//+----------------------------------------------------------------------------------------------------------+ |
//FORM IDENTITE : gestion de l'observateur |
223,17 → 255,15 |
}, |
// Cette partie est executee a la selection d'une adresse |
select: function(event, ui) { |
var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude); |
deplacerMarker(latLng); |
var nouvellePosition = new google.maps.LatLng(ui.item.latitude, ui.item.longitude); |
initialiserMarkerDeb(); |
deplacerMarkerDeb(nouvellePosition); |
map.setZoom(16); |
afficherEtapeGeolocalisation(2); |
} |
}); |
|
$('#geolocaliser').on('click', geolocaliser); |
|
google.maps.event.addListener(markerDeb, 'dragend', surDeplacementMarkerDeb); |
|
google.maps.event.addListener(map, 'click', surClickDansCarte); |
}); |
|
function initialiserGoogleMap(){ |
266,9 → 296,31 |
map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas |
map.mapTypes.set('OSM', osmMapType); |
|
// Ajout de l'évènment sur click dans Carte |
google.maps.event.addListener(map, 'click', surClickDansCarte); |
|
// Lorsque la carte est chargée, on vérifie si on peut précharger des données |
google.maps.event.addListenerOnce(map, 'idle', function(){ |
if (OBS_ID == '') { |
// Initialisation du marker de début de rue |
initialiserMarkerDeb(); |
// Tentative de geocalisation si aucune obs à précharger |
if (OBS_ID == '') { |
tenterGeolocalisation(); |
} |
} else { |
okPourChargementCarte--; |
prechargerRue(); |
} |
}); |
|
// Création du Geocoder |
geocoder = new google.maps.Geocoder(); |
} |
|
function initialiserMarkerDeb() { |
premierDeplacement = true; |
if (markerDeb == undefined) { |
// Marqueur de début de Rue |
markerDeb = new google.maps.Marker({ |
map: map, |
277,79 → 329,43 |
icon: GOOGLE_MAP_MARQUEUR_DEBUT_URL, |
position: latLngDeb |
}); |
initialiserMarkerDeb(latLngDeb); |
|
// Tentative de geocalisation |
tenterGeolocalisation(); |
google.maps.event.addListener(markerDeb, 'dragend', surDeplacementMarkerDeb); |
} |
|
function afficherErreurGoogleMap(status) { |
if (DEBUG) { |
$('#dialogue-google-map .contenu').empty().append( |
'<pre class="msg-erreur">'+ |
"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+ |
'</pre>'); |
afficherPanneau('#dialogue-google-map'); |
latLngFin = latLngDeb; |
if (markerFin != undefined) { |
markerFin.setMap(null); |
} |
latLngCentre = latLngDeb; |
if (ligneRue != undefined) { |
ligneRue.setMap(null); |
} |
|
function geolocaliser(event) { |
var latitude = $('#latitude').val(), |
longitude = $('#longitude').val(); |
latLng = new google.maps.LatLng(latitude, longitude); |
deplacerMarker(latLng); |
afficherEtapeGeolocalisation(2); |
map.setZoom(16); |
arreter(event); |
} |
|
function surDeplacementMarkerDeb() { |
trouverCommune(markerDeb.getPosition()); |
mettreAJourMarkerPosition(markerDeb.getPosition()); |
deplacerMarker(markerDeb.getPosition()); |
deplacerMarkerDeb(markerDeb.getPosition()); |
} |
|
function surClickDansCarte(event) { |
deplacerMarker(event.latLng); |
} |
|
function initialiserMarkerDeb(latLng) { |
if (markerDeb != undefined) { |
markerDeb.setPosition(latLng); |
map.setCenter(latLng); |
mettreAJourMarkerPosition(latLng); |
trouverCommune(latLng); |
} |
} |
|
function tenterGeolocalisation() { |
if (navigator.geolocation) { |
navigator.geolocation.getCurrentPosition(function(position) { |
var latitude = position.coords.latitude, |
longitude = position.coords.longitude; |
latLngDeb = new google.maps.LatLng(latitude, longitude); |
latLngFin = latLngDeb; |
// si l'utilisateur géolocalise sa ville alors le premier déplacement doit être réinitialisé |
premierDeplacement = true; |
deplacerMarker(latLngDeb); |
map.setZoom(16); |
}); |
} |
} |
|
function deplacerMarker(latLng) { |
if (markerDeb != undefined) { |
latLngDeb = latLng; |
function deplacerMarkerDeb(nouvellePosition) { |
latLngDeb = nouvellePosition; |
markerDeb.setPosition(latLngDeb); |
map.setCenter(latLngDeb); |
mettreAJourStationPosition(latLngDeb); |
trouverCommune(latLngDeb); |
|
if (!premierDeplacement) { |
if (markerFin != undefined) { |
markerFin.setMap(null); |
if (premierDeplacement) { |
initialiserMarkerDeb(); |
premierDeplacement = false; |
} else { |
var nouvellePositionFin = new google.maps.LatLng(latLngDeb.lat(), latLngDeb.lng() + 0.0010); |
initialiserMarkerFin(); |
deplacerMakerFin(nouvellePositionFin) |
afficherEtapeGeolocalisation(3); |
} |
} |
|
latLngFin = new google.maps.LatLng(latLngDeb.lat(), latLngDeb.lng() + 0.0010); |
function initialiserMarkerFin() { |
if (markerFin == undefined) { |
markerFin = new google.maps.Marker({ |
map: map, |
draggable: true, |
357,27 → 373,25 |
icon: GOOGLE_MAP_MARQUEUR_FIN_URL, |
position: latLngFin |
}); |
google.maps.event.addListener(markerFin, 'dragend', function() { |
dessinerLigneRue(markerDeb.getPosition(), markerFin.getPosition()); |
latLngDeb = markerDeb.getPosition(); |
latLngFin = markerFin.getPosition(); |
latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLngDeb.lat())/2, (latLngFin.lng() + latLngDeb.lng())/2); |
mettreAJourMarkerPosition(latLngCentre); |
afficherEtapeGeolocalisation(4); |
}); |
|
dessinerLigneRue(latLngDeb, latLngFin); |
|
latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLngDeb.lat())/2, (latLngFin.lng() + latLngDeb.lng())/2); |
mettreAJourMarkerPosition(latLngCentre); |
afficherEtapeGeolocalisation(3); |
google.maps.event.addListener(markerFin, 'dragend', surDeplacementMarkerFin); |
} else { |
mettreAJourMarkerPosition(latLngDeb); |
markerFin.setMap(null); |
} |
premierDeplacement = false; |
} |
|
function deplacerMakerFin(nouvellePosition) { |
latLngFin = nouvellePosition; |
markerFin.setMap(map); |
markerFin.setPosition(latLngFin); |
dessinerLigneRue(latLngDeb, latLngFin); |
} |
|
function surDeplacementMarkerFin() { |
dessinerLigneRue(markerDeb.getPosition(), markerFin.getPosition()); |
afficherCentreRue(); |
afficherEtapeGeolocalisation(4); |
} |
|
function dessinerLigneRue(pointDebut, pointFin) { |
if (ligneRue != undefined) { |
ligneRue.setMap(null); |
393,12 → 407,14 |
ligneRue.setMap(map); |
} |
|
function afficherEtapeGeolocalisation(numEtape) { |
$('.liste_indication_geolocalisation').children().hide(); |
$('.liste_indication_geolocalisation :nth-child('+numEtape+')').show(); |
function afficherCentreRue() { |
latLngDeb = markerDeb.getPosition(); |
latLngFin = markerFin.getPosition(); |
latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLngDeb.lat())/2, (latLngFin.lng() + latLngDeb.lng())/2); |
mettreAJourStationPosition(latLngCentre); |
} |
|
function mettreAJourMarkerPosition(latLng) { |
function mettreAJourStationPosition(latLng) { |
var lat = latLng.lat().toFixed(5), |
lng = latLng.lng().toFixed(5); |
remplirChampLatitude(lat); |
481,7 → 497,50 |
}); |
} |
|
function afficherEtapeGeolocalisation(numEtape) { |
$('.liste_indication_geolocalisation').children().hide(); |
$('.liste_indication_geolocalisation :nth-child('+numEtape+')').show(); |
} |
|
function afficherErreurGoogleMap(status) { |
if (DEBUG) { |
$('#dialogue-google-map .contenu').empty().append( |
'<pre class="msg-erreur">'+ |
"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+ |
'</pre>'); |
afficherPanneau('#dialogue-google-map'); |
} |
} |
|
function geolocaliser(event) { |
var latitude = $('#latitude').val(), |
longitude = $('#longitude').val(), |
nouvellePosition = new google.maps.LatLng(latitude, longitude); |
initialiserMarkerDeb(); |
deplacerMarkerDeb(nouvellePosition); |
afficherEtapeGeolocalisation(2); |
map.setZoom(16); |
arreter(event); |
} |
|
function tenterGeolocalisation() { |
if (navigator.geolocation) { |
navigator.geolocation.getCurrentPosition(function(position) { |
var latitude = position.coords.latitude, |
longitude = position.coords.longitude, |
nouvellePosition = new google.maps.LatLng(latitude, longitude); |
initialiserMarkerDeb(); |
deplacerMarkerDeb(nouvellePosition); |
map.setZoom(16); |
}); |
} |
} |
|
function surClickDansCarte(event) { |
deplacerMarkerDeb(event.latLng); |
} |
|
|
//+---------------------------------------------------------------------------------------------------------+ |
//AUTO-COMPLÉTION Noms Scientifiques |
|
679,20 → 738,8 |
transformerEnSlider('#vitesse-croissance'); |
|
// Afficher/Cacher champs cachés par défaut |
$('#periodicite-traitement-phyto').on('change', function() { |
if ($(this).val() === 'jamais') { |
$('#datp-zone').removeClass('hidden'); |
} else { |
$('#datp-zone').addClass('hidden'); |
} |
}); |
$('#taxon-liste').on('change', function() { |
if ($(this).val() === '?') { |
$('#taxon-input-groupe').removeClass('hidden'); |
} else { |
$('#taxon-input-groupe').addClass('hidden'); |
} |
}); |
$('#periodicite-traitement-phyto').on('change', surChangementPeriodiciteTraitementPhyto); |
$('#taxon-liste').on('change', surChangementTaxonListe); |
|
$('.alert .close').on('click', fermerPanneauAlert); |
|
803,6 → 850,22 |
}); |
} |
|
function surChangementPeriodiciteTraitementPhyto() { |
if ($('#periodicite-traitement-phyto').val() === 'jamais') { |
$('#datp-zone').removeClass('hidden'); |
} else { |
$('#datp-zone').addClass('hidden'); |
} |
} |
|
function surChangementTaxonListe() { |
if ($('#taxon-liste').val() === '?') { |
$('#taxon-input-groupe').removeClass('hidden'); |
} else { |
$('#taxon-input-groupe').addClass('hidden'); |
} |
} |
|
function configurerDatePicker(selector) { |
$.datepicker.setDefaults($.datepicker.regional['fr']); |
$(selector).datepicker({ |