[OpenLayers-Users] need help with projection issues

Christopher Schmidt crschmidt at metacarta.com
Fri Jan 18 11:31:45 EST 2008


On Fri, Jan 18, 2008 at 05:04:30PM +0100, O. Baum wrote:
> Hi Thomas, all,
> 
> 2008/1/16, Thomas Wood <grand.edgemaster at gmail.com>:
> > Yes, you will. displayProjection just tells controls to reproject
> > before displaying or parsing coords they use.
> >
> > Reprojecting is fairly simple: [...]
> 
> ok, that works.
> 
> BUT if I want to draw a circle with the help of
> OpenLayers.Geometry.Polygon.createRegularPolygon() it becomes an
> ellipse. :(
> I'm using this code:
> 
> ---8<---------------------------------
> var circOrigin = new OpenLayers.Geometry.Point( 10.00, 49.50 );
> var circStyle = OpenLayers.Util.extend( {},
> OpenLayers.Feature.Vector.style["default"] );
> var circleFeature = new OpenLayers.Feature.Vector(
>  OpenLayers.Geometry.Polygon.createRegularPolygon( circOrigin, 0.001, 20, 0 ),
>  null,
>  circStyle );
> circleFeature.geometry.transform( new
> OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913") );
> vectors.addFeatures( [circleFeature] );
> --->8---------------------------------
> 
> 2 questions:
> 
> a) How and where can I apply the transformation so my circle is
> 'really' (i.e. on the map) a circle?
> b) In what units is the radius given? How can I calulate it from Meters?

Both of these questions can be answered by reprojecting your poitn
*before* you create the polygon.

var circOrigin = new OpenLayers.Geometry.Point( 10.00, 49.50 );
circOrigin.geometry.transform( new
OpenLayers.Projection("EPSG:4326"), new
OpenLayers.Projection("EPSG:900913") );

var circStyle = OpenLayers.Util.extend( {},
OpenLayers.Feature.Vector.style["default"] );
var circleFeature = new OpenLayers.Feature.Vector(
 OpenLayers.Geometry.Polygon.createRegularPolygon( circOrigin, 100 /* meters */, 20, 0 ),
 null,
 circStyle );
vectors.addFeatures( [circleFeature] );

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list