# OpenLayers HowTo create Circle ?

perhaps I have overlooked something, but I didn’t found a way to create a circle Area
something like described here:

createRegularPolygon

OpenLayers.Geometry.Polygon.createRegularPolygon = function( origin,
sides,
rotation )

would be great to be able to do this

found it out how to create a Circle.
Using a Polyline Vector it works:

[font=Courier New]

Vector circle = new PolyLine();
circle.setCaption(“Circle”);
circle.setPoints(generateCircleOfPoints(centerLon, centerLat, 60, 100));
[/font]

[font=Courier New]

public static final int EARTH_MEASURE_METERS = 6371010; //\$NON-NLS-1\$
public static final double EARTH_POLE_THRESHOLD = 0.000001; //\$NON-NLS-1\$

public static Point generateCircleOfPoints(double centerLon, double centerLat,
// init
if (numberOfPoints < 4) {
numberOfPoints = 4;
}
}
Point points = new Point[numberOfPoints+1]
;

``````	// convert coordinates to radians

// angle between 2 points
double theta = 360.0/(double)numberOfPoints;

// normalize linear distance to radian angle
// some helpers

// final coordinates
double lat, lon;
logger.debug("Center lon: "+centerLon+" lat: "+centerLat);
// loop through the array and write path linestrings
for (int i = 0; i < numberOfPoints; i++) {
rlat =
// check for endpoint of pole
if (Math.cos(rlat) == 0 || Math.abs(Math.cos(rlat)) < IMapConstants.EARTH_POLE_THRESHOLD) {
rlon = rlon1;
} else {
)
+ Math.PI ) % (2*Math.PI) ) - Math.PI;
}
lat = Math.toDegrees(rlat);
lon = Math.toDegrees(rlon);

logger.debug("lon: "+lon+" lat: "+lat);
// write results
points[i]
``````

= new Point(
lon,
lat);
}
// close the circle
points[numberOfPoints]
= points[0]
;
return points;
}

[/font]

Hi,

I guess that is something similar that the OL api does on the client side. To use the JavaScript (browser) for calculating circle polylines, it would require asynchronous API. I guess some using some real Java GIS library would make more sense.

cheers,
matti

do you know about a Java GIS library compatible to Eclipse Public License (EPL) or Apache ?

GeoTools is LGPL, so it’s problematic to be used in EPL Licensed Open Source Products