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,
radius,
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));
vectorLayerWaypoint.addComponent(circle);
[/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,
int numberOfPoints, double radiusMeter) {
// init
if (numberOfPoints < 4) {
numberOfPoints = 4;
}
if (radiusMeter <= 0) {
radiusMeter = 100;
}
Point points = new Point[numberOfPoints+1]
;

	// convert coordinates to radians
	double rlat1= Math.toRadians(centerLat);
	double rlon1= Math.toRadians(centerLon);
	
	// angle between 2 points
	double theta = 360.0/(double)numberOfPoints;
	
	// normalize linear distance to radian angle
	double radialDistance= radiusMeter / IMapConstants.EARTH_MEASURE_METERS;
	// some helpers
	double radialBearing, rlat, rlon;
	
	// 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++) {
		radialBearing = Math.toRadians((double)i*theta);
		rlat = 
				Math.asin( Math.sin(rlat1) * Math.cos(radialDistance) 
				+ Math.cos(rlat1) * Math.sin(radialDistance) * Math.cos(radialBearing) );
		// check for endpoint of pole
		if (Math.cos(rlat) == 0 || Math.abs(Math.cos(rlat)) < IMapConstants.EARTH_POLE_THRESHOLD) {
			rlon = rlon1;
		} else {
			rlon = ( (rlon1 - Math.asin( Math.sin(radialBearing) * Math.sin(radialDistance) / Math.cos(rlat) 
					) 
					+ 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