[OpenLayers-Users] How to inverse the display of Lon/Lat in OpenLayers.Control.MousePosition?

Andreas Hocevar ahocevar at opengeo.org
Fri Mar 27 17:06:42 EDT 2009


Hi,

On Thu, Mar 26, 2009 at 7:56 PM, kngai <kevin.ngai at ec.gc.ca> wrote:
>
> Currently, OpenLayers.Control.MousePosition only displays the coordinates as LON/LAT. I want to inverse that and display it as LAT/LON instead. I can't seem to find an option that allows this.
> Is there some of option to do this in Openlayers without having to do some custom string manipulation?

You could create your control like this:

var pos = new OpenLayers.Control.MousePosition({
    formatOutput: function(lonLat) {
        var digits = parseInt(this.numDigits);
        var newHtml =
            this.prefix +
            lonLat.lat.toFixed(digits) +
            this.separator +
            lonLat.lon.toFixed(digits) +
            this.suffix;
        return newHtml;
     },
});

You can create any custom output by overriding the formatOutput function.

Regards,
Andreas.

-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list