Rev 1 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?if (!isset($_POST['valid_station']) || sizeof($erreurs)>0) {?>Définissez vos stations d'observation :<br><form id="addr" action="#" method="get" onsubmit="return showAddress(this);" style="float:left;"><ul style="list-style-type:none;margin:0;padding:0;"><li><label for="lieu">Selectionnez la commune la plus proche de votre station :</label><input id="lieu" type="text" size="30" name="lieu" value=""/><input type="submit" value="Localiser" /></li><li>Ensuite, positionnez la pastille rouge sur votre station et donnez lui un nom.</li</ul></fieldset></form><div id="map" style="width:600px;height:400px;border:2px solid grey;margin:10px 0;clear:both;"></div><?php//Récupération des stations existantes//FONCTIONNEMENT_TESTE_ET_OK// les stations de l'observateur :$requete_stations = mysql_query("select STATION_ID, STATION_NOM, STATION_LATITUDE, STATION_LONGITUDE, STATION_ALTITUDE, STATION_ENVIRONNEMENT_ID, ENVIRONNEMENT_NOM from STATION, ENVIRONNEMENT where STATION.PARTICIPANT_ID=".$_SESSION['participant']." AND ENVIRONNEMENT_ID=STATION_ENVIRONNEMENT_ID ORDER BY STATION_NOM");$nb_requete_stations = @mysql_num_rows($requete_stations);$stations=array();echo "<br>";echo "</br>\n";echo "<b>Vos stations enregistrées (Cliquez sur le nom de la station pour ajouter de nouvelles espèces) :</b> <br>";?><form name="form_station" method="post" action="<?= $url_page ?>"><input type="hidden" name="etape" value="<?= $etape ?>"><input type="hidden" name="<?= $provenance ?>" value="1"><input type="hidden" name="<?= $provenance ?>etape" value="<?= $etape ?>"><?phpecho "<table id='tabstations'>";if ($nb_requete_stations > 0) {// Liste des stations$MOIS_EN_COURS = '09';$MOIS_RENTREE = '09'; // FIXME : quelle difference avec la variable precedente ?$mois = date('m');$annee = date('Y');//$annee=$annee+1;/*if ($mois > $MOIS_RENTREE) {$annee = $annee+1;}*/while ($station = mysql_fetch_assoc($requete_stations)) {$stations [] = $station;echo "<tr>";echo "<td><strong>Station : <a title=\"Ajouter de nouvelles espèces\" href=\"".$url_page."&station_id=".$station['STATION_ID']."\">".$station['STATION_NOM']."</a><strong></td>";// echo "<td>".$station['STATION_LATITUDE']."</td>";//echo "<td>".$station['STATION_LONGITUDE']."</td>";//echo "<td>".$station['STATION_ALTITUDE']."</td>";//echo "<td>"."<input type=\"submit\" class=\"submit\" name=\"".$station['STATION_ID']."\" value=\"Choisir cette station\"></td>";// A t-on des mesures associe a cette station ? Si oui on ne peut pas la modifier ni supprimer$requete_mesure = mysql_query("SELECT MESURE.SEQUENCE_ID FROM MESURE,SEQUENCE,STATION where MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID AND STATION.STATION_ID=SEQUENCE.STATION_ID AND STATION.PARTICIPANT_ID=".$_SESSION['participant']." AND STATION.STATION_ID=".$station['STATION_ID']);$nb_requete_mesure = mysql_num_rows($requete_mesure);$obs_existe=false;if ($nb_requete_mesure == 0) { // Pas de mesure on peut modifierecho "<td>"."<input type=\"submit\" class=\"submit\" name=\"".$station['STATION_ID']."\" value=\"Modifier\"></td>";}else {$obs_existe=true;echo "<td></td>";}echo "</tr>";$requete_obs_annee = mysql_query("select distinct SEQUENCE.SEQUENCE_ID, ESPECE_NOM_VERNACULAIRE, STATION_NOM from SEQUENCE,ESPECE,STATION,MESURE "."where ESPECE.ESPECE_ID=SEQUENCE.ESPECE_ID"." and MESURE.SEQUENCE_ID=SEQUENCE.SEQUENCE_ID"." and SEQUENCE.PARTICIPANT_ID=".$_SESSION['participant']." and STATION.STATION_ID=". $station['STATION_ID'] ." and STATION.STATION_ID=SEQUENCE.STATION_ID"." AND MESURE_DATE!='0000-00-00' and MESURE_DATE>'".($annee-2).'-'.($mois)."-01'"." and MESURE_DATE<'".($annee).'-'.($mois)."-01'"." order by STATION_NOM, ESPECE_NOM_VERNACULAIRE");$nb_requete_obs_annee = mysql_num_rows($requete_obs_annee);if (($nb_requete_obs_annee == 0) && ($obs_existe)) {echo "<tr>";echo "<td>Observations archivées </td>";echo "</tr>";}while ($obs = mysql_fetch_assoc($requete_obs_annee)) {echo "<tr>";echo "<td>Espèce : <a title=\"Ajouter/modifier des observations\" href=\"".$url_page."&sequence_id=".$obs['SEQUENCE_ID']."\">".$obs['ESPECE_NOM_VERNACULAIRE']."</a></td>";echo "</tr>";}echo "<tr>";echo "</tr>";echo "<tr>";echo "</tr>";}// On retient la premiere station pour centrage$init_lat=$stations[0]['STATION_LATITUDE'];$init_lon=$stations[0]['STATION_LONGITUDE'];}else {// Pas de stations : affichage centre carte france// FONCTIONNEMENT_TESTE_ET_OK$init_lat=45.545;$init_lon=3.249722;echo "<td><strong>Pas de station enregistrée</strong></td>";echo "<td></td>";echo "<td></td>";echo "<td></td>";echo "<td></td>";echo "<td></td>";echo "</tr>";}echo "</table>";echo "</form>";//$espece_encours=$obs[1];$commune_encours=$obs[2];/***** Selection des stations *****///Affichage des éventuelles erreursafficherErreurs($erreurs);?><form id="form_coordonnee" action="<?= $url_page ?>" method="post" style="float:left;"><input id="ll_latitude" name="ll_latitude" type="hidden" value="" /><input id="ll_latitude_dms" name="ll_latitude_dms" type="hidden" value="" /><input id="ll_longitude" name="ll_longitude" type="hidden" value="" /><input id="ll_longitude_dms" name="ll_longitude_dms" type="hidden" value="" /><input id="ll_altitude" name="ll_altitude" type="hidden" value="" /><input id="form_coordonnee_valider" name="valid_station" class="submit" type="hidden" value="Poursuivre" /><input type="hidden" name="etape" value="3"><input type="hidden" name="provenance" value="<?= $provenance ?>"></li></ul></form><?phpinclude_once 'modules/configuration/car_config.inc.php' ;if (PARTICIPANT_EST_ADULTE) {?><script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAnm2MSMmwsDuoh7THcVDnlBQH9AL26AfEfaraxwo1G6_adyVjPRRQE4Gx2u7MomK9DJWf9kMLJ9y-ZA" type="text/javascript"></script><?php}else {?><script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAFMANWib9GSm7T4W6AN9qzxRmHYqXwt_BUwczny2vFmnHz3sr3BTy_SMRJ-NzWXDUynHHSWQ7_aEZ6Q" type="text/javascript"></script><?php}// Centrage initial : premiere station ou ville d'inscriptionecho "<script type=\"text/javascript\">";echo "\n//<![CDATA[\n";echo "var init_lat = ".$init_lat.";\n";echo "var init_long = ".$init_lon.";\n";?>var largeur_carte = 690;var haureur_retrait = 330;var init_zoom = 10;// Contient la carte GoogleMapvar map;// Contient l'utilitaire permettant de trouver une adresse.var EfGeocoder;// Point de l'adresse saisie et à passer au GeoCodervar addrpnt;// L'icône à afficher sur la cartevar icon;function load() {// Vérification de la compatibilité du navigateurif (GBrowserIsCompatible()) {// Création de la cartemap = new GMap2(document.getElementById("map"));// Positionnement de la cartemap.setCenter(new GLatLng(init_lat, init_long), init_zoom);// Types de carte disponibles :map.addMapType(G_NORMAL_MAP);map.addMapType(G_SATELLITE_MAP);map.addMapType(G_PHYSICAL_MAP);// Bouton pour changer de type de carte (mixte, satellite, plan)map.addControl(new GMapTypeControl(1));// Définition du type de la carte par défautmap.setMapType(G_HYBRID_MAP);// Bouton large de déplancement et zoom apparaissant dans le coin haut gauchemap.addControl(new GLargeMapControl());// Pour hierarchiser les types de carte --> pas encore dans la version stable...//var mapControl = new GHierarchicalMapTypeControl();// Définition des relations des types de menus//mapControl.clearRelationships();//mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, 'Labels', false);// Ajout du controle après avoir spécifié les relations//map.addControl(mapControl);// Vue d'ensemble apparaissant dans le coin bas droitvar EfOverViewMap = new GOverviewMapControl();map.addControl(EfOverViewMap);var mini = EfOverViewMap.getOverviewMap();// ?map.enableContinuousZoom();// Zoom avec la molette de la sourismap.enableScrollWheelZoom();// Zoom avec le double clic de la sourismap.enableDoubleClickZoom();// Création du GéoCoderEfGeocoder = new GClientGeocoder() ;// Icone station enregistrees (vert)icon = new GIcon();icon.image = "http://www.google.com/mapfiles/ms/micons/green-dot.png";icon.shadow = "http://www.google.com/mapfiles/shadow50.png";icon.iconSize = new GSize(34, 34);icon.shadowSize = new GSize(37, 34);icon.iconAnchor = new GPoint(16, 34);// Pour affichage infobulleicon.infoWindowAnchor = new GPoint(5,1);// Icone nouvelle station (rouge) ou station en modificationNicon = new GIcon();Nicon.image = "http://www.google.com/mapfiles/ms/micons/red-dot.png";Nicon.shadow = "http://www.google.com/mapfiles/shadow50.png";Nicon.iconSize = new GSize(34, 34);Nicon.shadowSize = new GSize(37, 34);Nicon.iconAnchor = new GPoint(16, 34);// Pour affichage infobulleNicon.infoWindowAnchor = new GPoint(5,1);// Creates a marker at the given point with the given number labelfunction createMarker(point, text, altitude, envir) {var marker = new GMarker(point,icon);var html = text;GEvent.addListener(marker, "click", function() {map.setCenter(marker.getPoint());afficherInfo(marker.getPoint());afficherMasque(marker,text,altitude,envir);});return marker;}// Affichage des stations presentes TODO : et si plusieurs stations au meme endroit ? Utiliser cluster ?<? foreach($stations as $station) { ?>var point = new GLatLng(<?= $station['STATION_LATITUDE'] ?>, <?= $station['STATION_LONGITUDE'] ?>);map.addOverlay(createMarker(point, "<?= $station['STATION_NOM'] ?>","<?= $station['STATION_ALTITUDE'] ?>", "<?= $station['ENVIRONNEMENT_NOM'] ?>"));<? } ?>}}function showAddress(form) {if (form.lieu.value != '') {var lieu = form.lieu.value;EfGeocoder.getLatLng(lieu, function(position) {if (!position) {alert('Le lieu "'+lieu+'" est introuvable! Veuillez essayer un autre nom.')} else {placerMarkeur(position);map.setCenter(position, 14) ;}// Vidage du champ du formulaireform.lieu.value = '';});} else {var position = new GLatLng(form.lati.value, form.longi.value);placerMarkeur(position);map.setCenter(position, 14);// Vidage des champs du formulaireform.lati.value = '';form.longi.value = '';}return false;}// Ajout d'un nouveau marqueur dragable , depuis le geocodage uniquement (blocage du clic depuis la carte)function placerMarkeur(position) {if (addrpnt) {map.removeOverlay(addrpnt);}addrpnt = new GMarker(position, {icon: Nicon, draggable: true, title: 'Click sur la carte!'}) ;addrpnt.enableDragging() ;map.addOverlay(addrpnt) ;GEvent.addListener(addrpnt,'dragend',function() {map.setCenter(addrpnt.getPoint());afficherInfo(addrpnt.getPoint());afficherMasque(addrpnt,"");}) ;GEvent.addListener(addrpnt, "click", function() {map.setCenter(addrpnt.getPoint());afficherInfo(addrpnt.getPoint());afficherMasque(addrpnt,"");});afficherInfo(position);}// Masque de mise a jour station :function afficherMasque(position,nom,altitude,envir) {// On recupere les données du formulaire (caché) , notamment pour traiter simplement l'appel asynchrone de recup altitudevar html = "<table>";if (nom.length>0) {html = html + "<tr><td>Station :</td> <td>" + nom + "</td> </tr>";html = html + "<tr><td>Environnement :</td> <td>" + envir + "</td> </tr>";html = html + "</td></tr>";}else {html = html + "<tr><td>Station</td> <td><input type='text' id='nom_station' value=''/> </td> </tr>";<?$requete_environnement = mysql_query("select ENVIRONNEMENT_ID, ENVIRONNEMENT_NOM from ENVIRONNEMENT");?>html = html + "<tr><td>Environnement :</td>";html = html + "<td><select id='environnement_id' name='environnement'>";<? while ($env = mysql_fetch_row($requete_environnement)) { ?>html = html + "<option value='<?= $env[0] ?>'><?= $env[1] ?>";<? } ?>html = html + "</select></td></tr>";}html = html + "<tr><td>Latitude :</td> <td>" +document.getElementById('ll_latitude').value + "</td> </tr>" ;html = html + "<tr><td>Latitude :</td> <td>" +document.getElementById('ll_latitude').value + "</td> </tr>" ;html = html + "<tr><td>Longitude :</td> <td>" + document.getElementById('ll_longitude').value + "</td> </tr>";if (altitude) {html = html + "<tr><td>Altitude :</td> <td>" + altitude + "</td> </tr>";}else {html = html + "<tr><td>Altitude :</td> <td>" + document.getElementById('ll_altitude').value + "</td> </tr>";}if (nom.length==0) {html = html + "<tr><td></td><td><input type='button' value='Enregistrer' onclick='saveData()'/></td></tr>";}position.openInfoWindow(html);}// Sauvegarde station// TODO : Retrouver marker depuis lat/lonfunction saveData() {var nom_station = escape(document.getElementById("nom_station").value);var lat_station = document.getElementById("ll_latitude").value;var lon_station = document.getElementById("ll_longitude").value;var alt_station = document.getElementById("ll_altitude").value;var environnement_id = document.getElementById("environnement_id").value;var url = "modules/observations/sauvegarde_station.php?nom_station=" + nom_station + "&action=C" + "&lat_station=" + lat_station +"&lon_station=" + lon_station + "&environnement_id=" + environnement_id + "&alt_station=" + alt_station + "&participant_id=<?= $_SESSION['participant'] ?>";GDownloadUrl(url, function(data, responseCode) {if (responseCode == 200 && data.length <= 1) {window.location = "<?= $url_page ?>";}});}function afficherInfo(position) {var form = document.getElementById('form_coordonnee');afficherCoordonnees(position.lat().toString(), position.lng().toString());}function afficherCoordonnees(lati, longi) {var ellipsoid = 21;// 21 = WGS-84 (voir geo_constants)var xtm = 0;// 0 = UTM et 1= MTMvar Coordonnee = calculer_coordonnee(lati, longi, ellipsoid, xtm);// Nous affichons des informations.document.getElementById('ll_latitude').value = Coordonnee.latitude.toFixed(4);document.getElementById('ll_longitude').value = Coordonnee.longitude.toFixed(4);document.getElementById('ll_latitude_dms').value = Coordonnee.latitude_dms;document.getElementById('ll_longitude_dms').value = Coordonnee.longitude_dms;// Calcul altitudevar script = document.createElement('script');document.body.appendChild(script);script.src = 'http://ws.geonames.org/' + "srtm3" + 'JSON?lat=' + lati + '&lng=' + longi + '&callback=GetAltitude';}function GetAltitude(result ) {document.getElementById('ll_altitude').value = result.srtm3;}window.onload = loadwindow.onunload = GUnload/* A supprimer ? *//* Source : Code provenant du site http://pages.globetrotter.net/roule/utmgoogle.htm*/var deg2rad = Math.PI / 180;/** Fonction de transformation de coordonnées géographiques entre ellipsoide.* Source : http://home.hiwaay.net/~taylorc/bookshelf/math-science/geodesy/datum/transform/molodensky/* Licence : "The source code in the listing below may be copied and reused without restriction, but it is offered AS-IS with NO WARRANTY."** Parameters:* from: The geodetic position to be translated. (objet : GeodeticPosition)* from_a: The semi-major axis of the "from" ellipsoid. (double)* from_f: Flattening of the "from" ellipsoid. (double)* from_esq: Eccentricity-squared of the "from" ellipsoid. (double)* da: Change in semi-major axis length (meters); "to" minus "from"* df: Change in flattening; "to" minus "from" (double)* dx: Change in x between "from" and "to" datum. (double)* dy: Change in y between "from" and "to" datum. (double)* dz: Change in z between "from" and "to" datum. (double)** Paramêtres :* from : l'objet GeodesiquePosition à transformer (contient latitute, longitude et hauteur)* from_a : le demi grand axe (=a) de l'ellipsoïde utilisé pour la position géodésique contenu dans l'objet "from".* from_f : l'applatissement (=f) = 1/valeur... de l'ellipsoïde de l'objet "from"* from_esq : l'excentricité au carré de l'ellipsoïde de l'objet "from"* da : différence de demi grand axe (en metres) entre l'ellipsoïde "to" et "from".* df : différence d'applatissement entre l'ellipsoïde "to" et "from".* dx : différence pour l'axe x entre l'ellipsoïde "to" et "from".* dy : différence pour l'axe y entre l'ellipsoïde "to" et "from".* dz : différence pour l'axe z entre l'ellipsoïde "to" et "from".*/function transform(from, from_a, from_f, from_esq, da, df, dx, dy, dz) {var slat = Math.sin (from.lat);var clat = Math.cos (from.lat);var slon = Math.sin (from.lon);var clon = Math.cos (from.lon);var ssqlat = slat * slat;// "a divided by b"var adb = 1.0 / (1.0 - from_f);var dlat, dlon, dh;var rn = from_a / Math.sqrt (1.0 - from_esq * ssqlat);var rm = from_a * (1. - from_esq) / Math.pow ((1.0 - from_esq * ssqlat), 1.5);dlat = (((((-dx * slat * clon - dy * slat * slon) + dz * clat) + (da * ((rn * from_esq * slat * clat) / from_a))) + (df * (rm * adb + rn / adb) * slat * clat))) / (rm + from.h);dlon = (-dx * slon + dy * clon) / ((rn + from.h) * clat);dh = (dx * clat * clon) + (dy * clat * slon) + (dz * slat) - (da * (from_a / rn)) + ((df * rn * ssqlat) / adb);// Retour des données sous forme d'objetvar GeodeticPosition = { lon: from.lon + dlon,lat: from.lat + dlat,h: from.h + dh};return GeodeticPosition;}function test_transform() {var PositionNtf = { lon: 7.7372, lat: 48.6, h: 0 };var PositionWGS84 = transform(PositionNtf, 6378249.2, 0.00340755, 0.0068034881, -112.2, 0.00005474, -168, -60, 320);alert('Longitude : ' + PositionWGS84.lon + 'Latitude : ' + PositionWGS84.lat + 'Hauteur : ' + PositionWGS84.h);}// Indiquer l'ellipsoid par son index dans le table et pour le xtm mettre 0 pour l'UTM et 1 pour le MTM (?)function geo_constants(ellipsoid, xtm) {// returns ellipsoid valuesellipsoid_axis = new Array(); // valeur du demi grand axe (a) de l'ellipsoïdeellipsoid_eccen = new Array(); // valeur de l'excentricité au carré (e²) de l'ellipsoïdeellipsoid_axis[0] = 6377563.396; ellipsoid_eccen[0] = 0.00667054; //airyellipsoid_axis[1] = 6377340.189; ellipsoid_eccen[1] = 0.00667054; // mod airyellipsoid_axis[2] = 6378160; ellipsoid_eccen[2] = 0.006694542; //aust nationalellipsoid_axis[3] = 6377397.155; ellipsoid_eccen[3] = 0.006674372; //bessel 1841ellipsoid_axis[4] = 6378206.4; ellipsoid_eccen[4] = 0.006768658; //clarke 1866 == NAD 27 (TBC)ellipsoid_axis[5] = 6378249.145; ellipsoid_eccen[5] = 0.006803511; //clarke 1880ellipsoid_axis[6] = 6377276.345; ellipsoid_eccen[6] = 0.00637847; //everestellipsoid_axis[7] = 6377304.063; ellipsoid_eccen[7] = 0.006637847; // mod everestellipsoid_axis[8] = 6378166; ellipsoid_eccen[8] = 0.006693422; //fischer 1960ellipsoid_axis[9] = 6378150; ellipsoid_eccen[9] = 0.006693422; //fischer 1968ellipsoid_axis[10] = 6378155; ellipsoid_eccen[10] = 0.006693422; // mod fischerellipsoid_axis[11] = 6378160; ellipsoid_eccen[11] = 0.006694605; //grs 1967ellipsoid_axis[12] = 6378137; ellipsoid_eccen[12] = 0.00669438; // grs 1980ellipsoid_axis[13] = 6378200; ellipsoid_eccen[13] = 0.006693422; // helmert 1906ellipsoid_axis[14] = 6378270; ellipsoid_eccen[14] = 0.006693422; // houghellipsoid_axis[15] = 6378388; ellipsoid_eccen[15] = 0.00672267; // int24ellipsoid_axis[16] = 6378245; ellipsoid_eccen[16] = 0.006693422; // krassovskyellipsoid_axis[17] = 6378160; ellipsoid_eccen[17] = 0.006694542; // s americaellipsoid_axis[18] = 6378165; ellipsoid_eccen[18] = 0.006693422; // wgs-60ellipsoid_axis[19] = 6378145; ellipsoid_eccen[19] = 0.006694542; // wgs-66ellipsoid_axis[20] = 6378135; ellipsoid_eccen[20] = 0.006694318; // wgs-72ellipsoid_axis[21] = 6378137; ellipsoid_eccen[21] = 0.00669438; //wgs-84 (et NAD83 : pourquoi mis avec WGS84 ?)if (ellipsoid == 0) {ellipsoid = 22;}--ellipsoid; // table indexed differentlyif (xtm == 1) {// WAS: if (ellipsoid > 22)scaleTm = 0.9999;eastingOrg = 304800.;} else {scaleTm = 0.9996;eastingOrg = 500000.;}// Retour des données sous forme d'objetvar ellipsoid = { axis: ellipsoid_axis[ellipsoid],eccentricity: ellipsoid_eccen[ellipsoid],eastingOrg: eastingOrg,scaleTm: scaleTm};return ellipsoid;}/**This routine determines the correct UTM letter designator for the given latitude* returns 'Z' if latitude is outside the UTM limits of 84N to 80S*/function get_zoneletter(lat) {var zoneletter;if ((84 >= lat) && (lat >= 72)) zoneletter = 'X';else if ((72 > lat) && (lat >= 64)) zoneletter = 'W';else if ((64 > lat) && (lat >= 56)) zoneletter = 'V';else if ((56 > lat) && (lat >= 48)) zoneletter = 'U';else if ((48 > lat) && (lat >= 40)) zoneletter = 'T';else if ((40 > lat) && (lat >= 32)) zoneletter = 'S';else if ((32 > lat) && (lat >= 24)) zoneletter = 'R';else if ((24 > lat) && (lat >= 16)) zoneletter = 'Q';else if ((16 > lat) && (lat >= 8)) zoneletter = 'P';else if (( 8 > lat) && (lat >= 0)) zoneletter = 'N';else if (( 0 > lat) && (lat >= -8)) zoneletter = 'M';else if ((-8> lat) && (lat >= -16)) zoneletter = 'L';else if ((-16 > lat) && (lat >= -24)) zoneletter = 'K';else if ((-24 > lat) && (lat >= -32)) zoneletter = 'J';else if ((-32 > lat) && (lat >= -40)) zoneletter = 'H';else if ((-40 > lat) && (lat >= -48)) zoneletter = 'G';else if ((-48 > lat) && (lat >= -56)) zoneletter = 'F';else if ((-56 > lat) && (lat >= -64)) zoneletter = 'E';else if ((-64 > lat) && (lat >= -72)) zoneletter = 'D';else if ((-72 > lat) && (lat >= -80)) zoneletter = 'C';else zoneletter = chr(32 + 66); //This is here as an error flag to show that the Latitude is outside the UTM limitsreturn zoneletter;}function parseCoordinate(coordinate, type, format, spaced) {var coordd;var coordm;var coords;var coordh = 0;if (coordinate.search(/(^ *-|[WOS])/i) >= 0) {coordh = -1;}if (coordinate.search(/(^ *\+|[NE])/i) >= 0) {coordh = 1;}// if (coordinate.search(/[EW]/i) >= 0 && !type) { type = 'lon'; }// if (coordinate.search(/[NS]/i) >= 0 && !type) { type = 'lat'; }coordinate = coordinate.replace(/,/g, '.'); // french commas// not sure really needed.coordinate = coordinate.replace(/[NESWO+\-]/gi,' '); // add also: °, ', " -- or replace everything that is not a number or a dot// alert("coordinate = " + coordinate);if (coordinate.search(/[0-9]/i) < 0) {alert("Can't parse input field");coordd = "";return;}// http://www.gpsvisualizer.com/calculators// http://www.javascriptkit.com/javatutors/redev2.shtmlvar parts = coordinate.match(/([0-9\.\-]+)[^0-9\.]*([0-9\.]+)?[^0-9\.]*([0-9\.]+)?/);// / (one or more) /// ([0-9\.\-]+) digits, dot or -, one set// [^0-9\.]* separator// ([0-9\.]+)? digits, dot, zero or one set// [^0-9\.]* separator// ([0-9\.]+)? digits, dot, zero or one set// *: 0|more +: 1|more ?: 0|1 http://www.javascriptkit.com/javatutors/redev2.shtmlif (!parts[1]) {alert("Can't parse input field");coordd = '';return;} else {coordd = parts[1];if (parts[2]) {coordm = parts[2];} else {coordm = 0;}if (parts[3]) {coords = parts[3];} else {coords = 0;}// n = parseFloat(parts[1]);// if (parts[2]) { n = n + parseFloat(parts[2])/60; }// if (parts[3]) { n = n + parseFloat(parts[3])/3600; }}// Retour des données sous forme d'objetvar Coordonnee = { coordd: coordd,coordm: coordm,coords: coords,coordh: coordh};return Coordonnee;}function validate_dms(latd, latm, lats, latb, lonm, lond, lons, lonb) {var valid = 1;if (Math.abs(Number(latd)) >= 90)valid = 0;if (Number(latm) >= 60)valid = 0;if (Number(lats) >= 60)valid = 0;if (Math.abs(Number(lond)) >= 180)valid = 0;if (Number(lonm) >= 60)valid = 0;if (Number(lons) >= 60)valid = 0;return(valid);}// convert decimal degrees to dmsfunction convertir_en_dms(lat, lon) {var latbrg = 1;var lonbrg = 2;if (lat < 0)latbrg = 2if (lon < 0)lonbrg = 1;// LEW: have to round here, else could end up with 60 seconds :-)var tlat = Math.abs(lat) + 0.5 / 360000; // round up 0.005 seconds (1/100th)var tlon = Math.abs(lon) + 0.5 / 360000;var tlatdm = Math.abs(lat) + 0.5 / 60000; // round up 0.0005 minutes (1/1000th)var tlondm = Math.abs(lon) + 0.5 / 60000;var deglat = Math.floor(tlat);var t = (tlat - deglat) * 60;var minlat = Math.floor(t);var minlatdm = Math.floor((tlatdm - Math.floor(tlatdm)) * 60 * 1000) / 1000;var seclat = (t - minlat) * 60;seclat = Math.floor(seclat * 100) / 100; // works in js 1.4// seclat = seclat.toFixed(2); // 2 decimal places js 1.5 and latervar deglon = Math.floor(tlon);t = (tlon - deglon) * 60;var minlon = Math.floor(t);var minlondm = Math.floor((tlondm - Math.floor(tlondm)) * 60 * 1000) / 1000;var seclon = (t - minlon) * 60;seclon = Math.floor(seclon * 100) / 100; // js 1.4// seclon = seclon.toFixed(2); // js 1.5 and latervar latb = '';if (latbrg > 0) {latb = 'N';// 1 = N (nord)} else {latb = 'S';// 2 = S (sud)}var latdms = deglat + "° " + minlat + "' " + seclat + "\"";var lonb = '';if (lonbrg > 0) {lonb = 'E'; // 2 = E (est)} else {lonb = 'W';// 1 = W (west)}var londms = deglon + "° " + minlon + "' " + seclon + "\"";var chaine_latlon_dms = latdms + ' ' + latb + ' ' + londms + ' ' + lonb;// Retour des données sous forme d'objetvar LatLongDms = { lat: lat,lat_degre: Math.floor(tlatdm),lat_min: minlatdm,lat_s: seclat,lat_direction:latb,lat_dms:latdms,lon: lon,lon_degre: Math.floor(tlondm),lon_min: minlondm,lon_s: seclon,lon_direction:lonb,lon_dms:londms,ll_dms:chaine_latlon_dms};return LatLongDms;}function calculer_coordonnee(lati, longi, ellips, xtm) {// Récupération de l'ellipsoidevar ellipsoid = geo_constants(ellips, xtm);var axis = ellipsoid.axis;var eccent = ellipsoid.eccentricity;var scaleTm = ellipsoid.scaleTm;var eastingOrg = ellipsoid.eastingOrg;// Nous parsons la latitude saisievar CoordonneeLat = parseCoordinate(lati);var latb = '';// videif (CoordonneeLat.coordh != 0) {if (CoordonneeLat.coordh > 0) {latb = 'N';// 1 = N (nord)} else {latb = 'S';// 2 = S (sud)}}var latd = CoordonneeLat.coordd;var latm = CoordonneeLat.coordm;var lats = CoordonneeLat.coords;// Nous parsons la longitude saisievar CoordonneeLon = parseCoordinate(longi);var lonb = '';// videif (CoordonneeLon.coordh != 0) {if (CoordonneeLon.coordh > 0) {lonb = 'E'; // 2 = E (est)} else {lonb = 'W';// 1 = W (west)}}var lond = CoordonneeLon.coordd;var lonm = CoordonneeLon.coordm;var lons = CoordonneeLon.coords;// cope with blank fieldsif (latd == '' || lond == '') {alert("Latitude and longitude degrees must be entered");return;}// Indication de la direction par défaut pour la latitude et la longitude en Franceif (latb == '') {latb = 'N';// 1 = N (Nord)}if (lonb == '') {lonb = 'E';// 2 = E (Est)}// Validationvar valid = validate_dms(latd, latm, lats, latb, lonm, lond, lons, lonb);if (valid == 0) {alert("Invalid degrees, minutes or seconds");return;}var lat = Number(latd);lat = lat + Number(latm) / 60;lat = lat + Number(lats) / 3600;if (latb == 'S') { // 2 = Slat = lat * -1;}var lon = Number(lond);lon = lon + Number(lonm) / 60;lon = lon + Number(lons) / 3600;if (lonb == 'W') { // 1 = Wlon = lon * -1;}if (lat >= 84 || lat <= -80) {alert("UTM latitudes should be between 84N and 80S\nCalculation will proceed anyway as locator will be valid.");}var k0 = scaleTm;var latrad = lat * deg2rad;var longrad = lon * deg2rad;var zonenum = Math.floor((lon + 180) / 6) + 1;// @dc (180 - (-70.5))/3 - 76if (eastingOrg == 304800.) {zonenum = Math.floor((180 - lon) / 3) - 76; // MTM, only in Quebecif (zonenum < 3 || zonenum > 10) {alert("MTM zone numbers only confirmed for 3-10, province of Quebec\nContinuing anyway");}}if (lat >= 56.0 && lat < 64.0 && lon >= 3.0 && lon < 12.0 ) {zonenum = 32;}// Zones speciales pour Svalbardif( lat >= 72.0 && lat < 84.0 ) {if (lon >= 0.0 && lon < 9.0 ) zonenum = 31;else if ( lon >= 9.0 && lon < 21.0 ) zonenum = 33;else if ( lon >= 21.0 && lon < 33.0 ) zonenum = 35;else if ( lon >= 33.0 && lon < 42.0 ) zonenum = 37;}var lonorig = (zonenum - 1) * 6 - 180 + 3; //+3 puts origin in middle of zone// @dc 180 - (7+76) * 3 - 1.5if (eastingOrg == 304800.) {lonorig = 180 - (zonenum + 76) * 3 - 1.5;}var lonorigrad = lonorig * deg2rad;//Récupération de la lettre du fuseau xTMvar letter = get_zoneletter(lat);// Calcul xTMvar eccPrimeSquared = (eccent) / (1 - eccent);var N = axis / Math.sqrt(1 - eccent * Math.sin(latrad) * Math.sin(latrad));var T = Math.tan(latrad) * Math.tan(latrad);var C = eccPrimeSquared * Math.cos(latrad) * Math.cos(latrad);var A = Math.cos(latrad) * (longrad - lonorigrad);var M = axis * ((1 - eccent / 4 - 3 * eccent * eccent / 64 - 5 * eccent * eccent * eccent / 256) * latrad - (3 * eccent / 8 + 3 * eccent * eccent / 32 + 45 * eccent * eccent *eccent / 1024) * Math.sin(2 * latrad) + (15 * eccent * eccent / 256 + 45 * eccent * eccent * eccent / 1024) * Math.sin(4 * latrad) - (35 * eccent * eccent * eccent / 3072) * Math.sin(6 * latrad));var easting = (k0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120) + eastingOrg);var northing = (k0 * (M + N * Math.tan(latrad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720)));if (lat < 0) {northing += 10000000.0; //10000000 meter offset for southern hemisphere}// xTM// Arrondi au nombre supérieur// alert("easting = " + easting);preciseEasting = easting;easting = Math.floor(easting + .5);// alert("easting = " + easting);// alert("northing = " + northing);preciseNorthing = northing;northing = Math.floor(northing + .5);// alert("northing = " + northing);var chaine_xtm = '';var x_tm = '';if (eastingOrg == 304800.) {chaine_xtm = zonenum + ' ' + easting + 'm E ' + northing + 'm N';x_tm = 'MTM';} else {chaine_xtm = zonenum + letter + ' ' + easting + 'm E ' + northing + 'm N';x_tm = 'UTM';}// Latitude/Longitudevar chaine_latlon = lat + ' ' + latb + ' ' + lon + ' ' + lonb;var LatLongDms = convertir_en_dms(lat,lon);// Retour des données sous forme d'objetvar Coordonnee = { xtm: x_tm,nord: northing,est: easting,zone_numero: zonenum,zone_lettre: letter,xtm_chaine: chaine_xtm,latitude:lat,longitude:lon,ll_chaine: chaine_latlon,latitude_dms:LatLongDms.lat_dms,longitude_dms:LatLongDms.lon_dms,ll_chaine_dms: LatLongDms.ll_dms};return Coordonnee;}//]]></script><?}?>