[OpenLayers-Users] Display Coordinates

Arnd Wippermann arnd.wippermann at web.de
Thu Nov 22 13:18:10 PST 2012


your link
 <http://www.intornoamessina.it/tracking/>
http://www.intornoamessina.it/tracking/
 
points to a map with the projection EPSG:900913.
 
<script src="kml-pointtrack.js.php?wgs84"></script>
->
    map = new OpenLayers.Map({
        div: "map",
        projection: mercator,
        displayProjection: geographic,
        layers: [
            new OpenLayers.Layer.OSM('Spherical Mercator'),            
            new OpenLayers.Layer.PointTrack("Tracks", {

The coordinates of MousePosition jumps as seen before. The projected
coordinates are correct.
The tricky part is
 
var geoCoor = lonLat.transform(geographic, mercator);
 
You have forgotten to clone the lonLat. The transformation changes the
coordinates of lonLat to mercator!
So both variables geoCoor and lonLat hold the same projected coordinates.
And OpenLayers.Util.getFormattedLonLat(lat); gets projected coordinates,
that leads to a wrong formated output.
 
This is the right way:
var geoCoor = lonLat.clone().transform(geographic, mercator);

geoCoor gets projected coordinates without changing the coordinates of
lonLat.

Good luck,
Arnd 
 
 
  _____  

Von: Riggi Valerio [mailto:vash.84 at virgilio.it] 
Gesendet: Donnerstag, 22. November 2012 11:15
An: openlayers-users at lists.osgeo.org
Cc: arnd.wippermann at web.de
Betreff: Re: AW: [OpenLayers-Users] Display Coordinates


I corrected the code but still I don't understand a thing.. when I go on the
WGS-84 map (http://www.intornoamessina.it/tracking/) and I point the mouse
at a certain point of coordinate -93.2735, 44.8349 the result is like
4613718.1118, 1718560.9374, should not be like the coordinates before?

Many Thanks
Valerio

Il 21/11/2012 20:16, Arnd Wippermann ha scritto:


OpenLayers.Util.getFormattedLonLat(lat) is for formating geographic
coordinates,

but you pass projected coordinates to the function. That's the reason for
the strange output.
 
Util.js:
OpenLayers.Util.getFormattedLonLat = function(coordinate, axis, dmsOption) {
    if (!dmsOption) {
        dmsOption = 'dms';    //default to show degree, minutes, seconds
    }
 
 coordinate = (coordinate+540)%360 - 180; // normalize for sphere being
round
...
 
Choose displayProjection: geographic and if you want to output your
mousemove coordinates also in the projected coordinates,
you have to transform them.
 
            formatOutput: function(lonLat) {
                var geoCoor = lonLat.clone().transform(geographic,
mercator);
                var lat = lonLat.lat;
...
 
 
see:
http://gis.ibbeck.de/ginfo/apps/OLExamples/OL212/PointTrack_Boaga_Projection
.asp
 
Regard,
Arnd

  _____  

Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Riggi
Valerio
Gesendet: Mittwoch, 21. November 2012 11:30
An: openlayers-users at lists.osgeo.org
Betreff: Re: [OpenLayers-Users] Display Coordinates


Cit.:
Set the displayProjection property when you create the map to the projection
(not the projection code) that you want the coordinates to be in.  (looks
like it should be a projection created from EPSG:4326) The lat/lon being
passed into the mousecontrol event will be in this projection. It look to me
like you are getting in projected coordinates but trying to use them as
lat/long.

Done but the problem remains.

Il 20/11/2012 15:28, Riggi Valerio ha scritto:


Hi, I'm tryng to display the coordinates on mouse over the map, on a WGS84
map and on a Gauss-Boaga map but coordinate seems strange to me, is there
some error? I'm using the example bellow:

This is the WGS84 map <http://www.intornoamessina.it/tracking/index.php>
and this is the Gauss-Boaga Map
<http://www.intornoamessina.it/tracking/index.php?gauss> 

And this is the example code I used:

    map.addControl(
                new OpenLayers.Control.MousePosition({
                    prefix: '<div style=\"color: green; font-size: 14px;
font-weight: bold; background-color: white; width: 500px; text-align:
left;\">Coordinate: ',
                    suffix: '</div>',
                    separator: ' | ',
                    numDigits: 2,
                    emptyString: '<div style=\"color: red; font-size: 14px;
font-weight: bold; background-color: white; width: 500px; text-align:
left;\">Mouse non sulla mappa.</div>'
                })
            );
    map.events.register("mousemove", map, function(e) {
                var position = this.events.getMousePosition(e);
                OpenLayers.Util.getElement("coords").innerHTML = position;
            });
    map.addControl(new OpenLayers.Control.Attribution());

Thanks
Valerio

 

_______________________________________________

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/20121122/6c5dcb55/attachment.html>


More information about the Users mailing list