[OpenLayers-Users] mousePositionControl and google Elevation service - better way to do this?

Phil Scadden p.scadden at gns.cri.nz
Thu Sep 22 00:41:58 EDT 2011


I have successfully got google elevation service to add elevation to end 
of a mouse position string.
Some crude code for this below...

While this works, it effectively queues up a lot of requests while the 
mousemoves. More effective would be elevation only when mouse stops 
moving but can you detect this in js? I am reluctant to do increase 
granularity much.

       elevator = new google.maps.ElevationService();
     mousePositionControl = new OpenLayers.Control.MousePosition({
         formatOutput: function (lonLat) {
             var digits = parseInt(this.numDigits);
             newHtml = this.prefix + 'Lat/Long:<BR>' + 
lonLat.lat.toFixed(digits) + this.separator + lonLat.lon.toFixed(digits) 
+ this.suffix;
             if (map.displayProjection.proj.units == "m") {
                 digits = 1;
                 newHtml = this.prefix + 'East/North:<BR>' + 
lonLat.lon.toFixed(digits) + this.separator + lonLat.lat.toFixed(digits) 
+ this.suffix;
             }
             newHtml = scaleOut + '<BR>' + newHtml ;
             if (elevator) {
                 var locations = [];
                 locations.push( new google.maps.LatLng(lonLat.lat, 
lonLat.lon));
                 var positionalRequest = {'locations': locations };

                 // Initiate the location request
                 elevator.getElevationForLocations(positionalRequest, 
function(results, status) {
                   if (status == google.maps.ElevationStatus.OK){
                        // Retrieve the first result
                     if (results[0]){
                         var el = 
document.getElementById(mousePositionControl.element.id);
                         el.innerHTML = newHtml + '&nbsp;,' + 
results[0].elevation.toFixed(1)+'m' + '<BR>' + measurementOut;
                     }
                   }
                 });
             }
             return newHtml + '<BR>' + measurementOut;
         }
     });



-- 
Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St, 
Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477 5232


Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.



More information about the Users mailing list