[OpenLayers-Users] mousePositionControl and google Elevation
service - better way to do this?
Roald de Wit
list at rdewit.net
Thu Sep 22 00:54:14 EDT 2011
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 + ' ,' +
> results[0].elevation.toFixed(1)+'m' + '<BR>' + measurementOut;
> }
> }
> });
> }
> return newHtml + '<BR>' + measurementOut;
> }
> });
>
>
>
More information about the Users
mailing list