Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I added a vector layer to my main map with the controls like the example from openlayers: http://openlayers.org/dev/examples/draw-feature.html

Now when I want to get the resulting lonlat from the point that was drawn I get strange results:

({id:"OpenLayers.Geometry.Point_81", x:6418264.3901563, y:7161906.3780079, 
      bounds:{left:6418264.3901563, bottom:7161906.3780079, right:6418264.3901563,
              top:7161906.3780079}})

The main map is constructed like this:

map = new OpenLayers.Map( $('map'), {
    sphericalMercator: true,
    //maxResolution: '360/512',
    maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
    projection: "EPSG:900913",
    displayProjection: new OpenLayers.Projection("EPSG:4326"),
    tileOrigin: new OpenLayers.LonLat(-180, -90),
    controls: [new OpenLayers.Control.Navigation({dragPanOptions: {enableKinetic: true}}),
                   new OpenLayers.Control.MousePosition(),new OpenLayers.Control.Zoom()],
eventListeners:{"moveend":mapEvent}
                                         });

Can somebody give me a hint, it's probably an easy thing but I'm quite new to openlayers and javascript in general :-)

Something with the conversion of projection ?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

this is not a strange result, it gives you coordinate as map.projection which you have defined in map options projection: "EPSG:900913"

try to use .transform method:

vectorLayers.features[1].geometry.transform(map.projection, map.displayProjection);

i hope it helps you...

share|improve this answer
    
SUPERB! I should've posted here much earlier, stuck on this for 48hours - solved in 5min. now Thank you very much. –  jonas Sep 14 '12 at 13:18
    
you're welcome :) –  Aragon Sep 14 '12 at 13:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.