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 have an OSM-Layer as a base layer. When I create a vector I have to define the coordinates in meter.
Is there a way to use degrees right a way without reprojecting them beforehand to meters?

var p0 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(13.39, 52.5));

share|improve this question

2 Answers 2

You can Transform on the fly, using the following code:

var geographic = new OpenLayers.Projection("EPSG:4326");
var mercator = new OpenLayers.Projection("EPSG:900913");
var p0 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(13.39, 52.5).transform(geographic,mercator));
share|improve this answer
    
Thanks but is there no way to set the EPSG:4326 projection to the map or the layer so that everything will work with degrees? –  strangeoptics Aug 16 '13 at 10:58
1  
If you are using OSM layer, then the tiles are available only in EPSG:3857. If you want the map to be in EPSG:4326, then you cannot use the default OSM Layer in it. –  Devdatta Tengshe Aug 16 '13 at 11:01
    
So you say there is no way to use degrees with the OSM Layer when working with Features? I have to reproject everything manually. –  strangeoptics Aug 16 '13 at 11:08
    
@strangeoptics See my Update –  Devdatta Tengshe Aug 16 '13 at 11:10
1  
@strangeoptics: I rolled back the update, because as you have experienced, just setting the spatial reference on the layer does not work with manual Features. It works in other cases like using the WFS protocol, or using the KML protocol. –  Devdatta Tengshe Aug 19 '13 at 9:59

You can define the projection of your layer. OpenLayers will reproject it automatically for you.

share|improve this answer
    
Maybe you can elaborate how to define it in OpenLayers. Might help the OP. –  Curlew Aug 16 '13 at 12:49
    
@Devdatta Tengshe: has done it in his answer –  neogeomat Aug 16 '13 at 16:25

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.