[OpenLayers-Users] need help with projection issues

Kris Geusebroek kgeusebroek at xebia.com
Wed May 6 02:15:29 EDT 2009


Hi,

There is a function in OpenLayers to do that. Works like this:

var circle =
OpenLayers.Geometry.Polygon.createRegularPolygon(feature.geometry, 50,
50) layer.addFeatures(new OpenLayers.Feature.Vector(circle));

the function expects 4 parameters of which I supply 3:
- 1. The point where circlecenter must be at
- 2. The radius in unit's of the map (in my case meters)
- 3. The number of sides (50 makes a nice circle)

The 4th parameter is the angle to start drawing but that doesn't make
sense for a circle

Cheers Kris

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of newbie
Sent: Tuesday, May 05, 2009 5:11 PM
To: users at openlayers.org
Subject: Re: [OpenLayers-Users] need help with projection issues


Dear All,
          If I need a circle based on a radius of 50m which function
must I
use ? I just have a lat and long only. Thank you.

Christopher Schmidt-2 wrote:
> 
> 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
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context:
http://n2.nabble.com/need-help-with-projection-issues-tp1827236p2797350.
html
Sent from the OpenLayers Users mailing list archive at Nabble.com.

_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users



More information about the Users mailing list