Ignore:
Timestamp:
Feb 25, 2011, 12:44:14 PM (13 years ago)
Author:
cljosse
Message:

[edit_gmaps] adding support to the altitude.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/edit_gmaps/admin/js/JScript.js

    r8501 r9377  
    8080
    8181            google.maps.event.addListener(marker,
    82         'dragend',
    83         function () {
    84             updateMarkerStatus('Drag ended');
    85             geocodePosition(marker.getPosition());
    86            
    87             }
     82                                            'dragend',
     83                                            function () {
     84
     85                                             
     86                                     
     87                                              // getElevation({ latLng: marker.getPosition() });
     88                                                geocodePosition(marker.getPosition());
     89                                                updateMarkerStatus('Drag ended');
     90                                                getElevation({ 'latLng': marker.getPosition() });
     91                                                document.Envoie.alt.value = coordinates.ALT;
     92
     93                                            }
    8894        );
    8995
    90 
    91 
    92                         // Update current position info.   
     96       // styleIcon = new StyledIcon(StyledIconTypes.BUBBLE, { color: "#cccccc", text: "Drag Me!" });
     97       // var styleMaker1 = new StyledMarker({ styleIcon: styleIcon, position: new google.maps.LatLng(37.383477473067, -121.880502070713), map: map, draggable: true });
     98
     99       // google.maps.event.addDomListener(styleMaker1, "dragend", getElevation);
     100                                            // Update current position info.   
     101
    93102                       updateMarkerPosition(LatLng);
    94103                       geocodePosition(LatLng);
    95              
     104                       getElevation({ 'latLng': marker.getPosition() });
     105                       document.Envoie.alt.value = coordinates.ALT;
    96106                  return false;
    97107   
     
    109119                document.Envoie.lat.value=latLng.lat() ;
    110120                document.Envoie.lon.value = latLng.lng();
    111                
    112                
     121                dms_frac = dec2dms(latLng.lng());
     122                if (dms_frac.Degre < 0)
     123                    document.Envoie.lonRef.value = "W";
     124                else
     125                    document.Envoie.lonRef.value = "E";
     126                document.Envoie.lonDMS.value = Math.abs(dms_frac.Degre) +"/1" + " " + dms_frac.Minute +"/1" + " " +    dms_frac.Numerator + "/" + dms_frac.Denominator;
     127                dms_frac = dec2dms(latLng.lat());
     128                if (dms_frac.Degre < 0)
     129                    document.Envoie.latRef.value = "S";
     130                else
     131                    document.Envoie.latRef.value = "N";
     132                document.Envoie.latDMS.value = Math.abs(dms_frac.Degre) + "/1" + " " + dms_frac.Minute + "/1" + " " + dms_frac.Numerator + "/" + dms_frac.Denominator;
     133                update_datas();
     134            }
     135
     136
     137                function update_datas() {
     138                n= jQuery(document.EditJPEG);
     139
     140                jQuery.each(n[0], function (i) {
     141
     142
     143                    n00 = this;
     144                    n0 = n00.id;
     145                    n1 = n00.name;
     146                    n2 = jQuery(n00).val();
     147                    try {
     148                        if (n0 == "alt") {
     149                            n3 = dec2frac(document.Envoie[n0].value);
     150                            n3 = n3.Numerator + "/" + n3.Denominator;
     151                            jQuery(this).val(n3);
     152                        }
     153                        else {
     154                            n3 = document.Envoie[n0].value;
     155                            jQuery(this).val(n3);
     156                        }
     157                    }
     158                    catch (e) {
     159                        n3 = n0;
     160                    }
     161
     162
     163
     164                }
     165                )
     166
     167                   
     168
    113169                }
    114170           
     
    119175            }
    120176
    121 
    122        
    123 
    124 
    125         function geocodePosition(pos) {
    126             geocoder.geocode({ 'latLng': pos },
    127                function (results, status) {
     177            function getElevation(event) {
     178                var elevator = new google.maps.ElevationService();
     179                var locations = [];
     180
     181                // Retrieve the clicked location and push it on the array
     182                var clickedLocation = event.latLng;
     183                locations.push(clickedLocation);
     184
     185                // Create a LocationElevationRequest object using the array's one value
     186                var positionalRequest = {
     187                    'locations': locations
     188                }
     189
     190                // Initiate the location request
     191                if (elevator) {
     192                    elevator.getElevationForLocations(positionalRequest, function (results, status) {
     193                        if (status == google.maps.ElevationStatus.OK) {
     194
     195                            // Retrieve the first result
     196                            if (results[0]) {
     197                                coordinates.ALT = results[0].elevation;
     198                                document.Envoie.alt.value = coordinates.ALT;
     199                                update_datas();
     200                                   //styleIcon.set("text", "Elevation: " + results[0].elevation + "m");
     201                            } else {
     202                               // alert("No results found");
     203                            }
     204                        } else {
     205                            alert("Elevation service failed due to: " + status);
     206                        }
     207                    });
     208                }
     209            }
     210
     211
     212
     213            function geocodePosition(pos) {
     214                     geocoder.geocode({ 'latLng': pos },
     215                    function (results, status) {
    128216                   /* Si le géocodage inversé a réussi */
    129217                   if (status == google.maps.GeocoderStatus.OK) {
     
    198286
    199287        coordinates = { ADRESSE: jQuery("#match").val(),
    200                         LAT:0,LON:0,ZOOM: 18
     288                        LAT:0,LON:0,ZOOM: 18 ,ALT:0
    201289                       };
    202290        codeAddress();
     
    212300        if (Code != 13) return true;
    213301        coordinates = { ADRESSE: jQuery("#match").val(),
    214                         LAT:0,LON:0,ZOOM: 18
     302            LAT: 0, LON: 0, ZOOM: 18, ALT: 0
    215303                       };
    216304        codeAddress();
     
    221309});
    222310
     311
     312
     313
     314  // DECIMAL TO FRACTION
     315  //
     316  function dec2frac( valeur_decimal ) {
     317     decimal = valeur_decimal.toString() ;
     318      num = '';
     319      den = 1;
     320      dec = false;
     321
     322      // find least reduced fractional form of number
     323      for( i = 0, ix =   decimal.length  ; i < ix; i++ )
     324      {
     325      // build the denominator as we 'shift' the decimal to the right
     326      if( dec ) den *= 10;
     327
     328      // find the decimal place/ build the numberator
     329      if( decimal.charAt(i) == '.' ) dec = true;
     330      else num += decimal.charAt(i);
     331      }
     332      num = parseInt(num);
     333 
     334      // whole number, just return it
     335      if( den == 1 ) return num;
     336
     337      num2 = num;
     338      den2 = den;
     339      rem  = 1;
     340      // Euclid's Algorithm (to find the gcd)
     341      while( num2 % den2 ) {
     342      rem = num2 % den2;
     343      num2 = den2;
     344      den2 = rem;
     345      }
     346      if( den2 != den ) rem = den2;
     347      ret1 = { Numerator: (num / rem), Denominator: (den / rem) };
     348      // new Array()
     349    // ret1->Numerator =(num / rem ) ;
     350    // ret1->Denominator=(den / rem);
     351
     352      // now $rem holds the gcd of the numerator and denominator of our fraction
     353      return ret1;
     354     
     355  }
     356
     357function dec2dms(l) {
     358    sign = 1;
     359    if (l < 0) { sign = -1; }
     360    l = Math.abs(Math.round(l * 1000000.))
     361    d = Math.floor(l / 1000000) * sign;
     362    m = Math.floor(((l / 1000000) - Math.floor(l / 1000000)) * 60);
     363    s = Math.floor(((((l / 1000000) - Math.floor(l / 1000000)) * 60) - Math.floor(((l / 1000000) - Math.floor(l / 1000000)) * 60)) * 100000) * 60 / 100000;
     364    frac_s = dec2frac(s);
     365    s2 = (frac_s.Numerator / frac_s.Denominator);
     366    return { dms: d + "° " + m + "' " + s + "''",
     367        Degre:d, Minute:m,Sec:s,
     368        Numerator: frac_s.Numerator,
     369        Denominator:frac_s.Denominator};
     370}
     371
Note: See TracChangeset for help on using the changeset viewer.