Quantcast

mousePositionControl and google Elevation service - better way to do this?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

mousePositionControl and google Elevation service - better way to do this?

Phil Scadden
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.

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mousePositionControl and google Elevation service - better way to do this?

Roald de Wit-3
Hi Phil,

This example might help:

http://openlayers.org/dev/examples/hover-handler.html

Regards, Roald

On 22/09/11 14:41, Phil Scadden wrote:

> 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;
>           }
>       });
>
>
>
_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Loading...