[OpenLayers-Users] Display Coordinates
Arnd Wippermann
arnd.wippermann at web.de
Fri Nov 23 13:36:09 PST 2012
you have to set your variable mercator to the right projection.
from kml-pointtrack.js.php:
var mercator = new OpenLayers.Projection("EPSG:4326"); <!-- WGS84 -->
var geographic = new OpenLayers.Projection("EPSG:4326"); <!-- WGS84 -->
it should be
var mercator = new OpenLayers.Projection("EPSG:900913");
Arnd
_____
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Riggi
Valerio
Gesendet: Freitag, 23. November 2012 15:32
An: openlayers-users at lists.osgeo.org
Betreff: Re: [OpenLayers-Users] Display Coordinates
I was missing an "else if" on my code and the mercator was always setted to
EPSG:900913, now it seems to work but the wgs-84 version dosen't center the
map on the desired position:
center: new OpenLayers.LonLat(15.4386126995087,
38.2423138618469).transform(geographic, mercator)
why?
Many thanks
Valerio
Il 22/11/2012 22:08, Phil Scadden ha scritto:
Okay, you have added displayProjection.
So looking at the formatOutput function, I see.
lonLat now comes into the function as lat/lon in 4326.
you convert to mercator
However lonLat.transform changes lonLat.
try
var geoCoor = lonLat.clone();
geoCoor.transform(geographic, mercator);
var lat = lonLat.lat;
var long = lonLat.lon;
var ns = OpenLayers.Util.getFormattedLonLat(lat);
var ew = OpenLayers.Util.getFormattedLonLat(long,'lon');
return '<div style=\"color: green; font-size: 14px; font-weight: bold;
background-color: white; width: 700px; text-align: left;\">Coordinate: '
+ ns + ', ' + ew + ' (' + (Math.round(geoCoor.lat * 10000) / 10000) + ',
' + (Math.round(geoCoor.lon * 10000) / 10000) + ')' + '</div>';
}
Get used to using firebug or similar. It makes it easy to see what is
going on. Put breakpoint in formatOutput and then watch the values.
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
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20121123/a09dec1c/attachment.html>
More information about the Users
mailing list