[OpenLayers-Users] Mercator and getLonLatFromPixel

Christopher Schmidt crschmidt at metacarta.com
Tue Jan 23 21:54:40 EST 2007


On Tue, Jan 23, 2007 at 04:19:04PM -0800, Ben Brehmer wrote:
> 
> I was wondering if there is a way to get the correct lon/lat from a 
> pixel if the basemap is projected in mercator?
> 
> Right now the getLonLatFromPixel() function returns a latitude/longitude 
> which is incorrect since my map is actually projected in mercator.

There is currently no way to return a longitude and latitude when the
map is in non-degree units. There is a set of functions I've written for
doing this translation in Javascript: it is included in 

http://labs.metacarta.com/osm/osm.js

The functions are:

function rad_deg(ang) {
function deg_rad(ang) {
function merc_x(lon) {
function unmerc_x(lon) {
function unmerc_y(y) {
function merc_y(lat) {
function merc(x,y) {

These functions are direct translations of the proj.4 code to
Javascript. unmerc_x and unmerc_y are functions to take mercator values
and convert them to degrees.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list