<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#ffffff">
Regular Polygons are fine for many applications. I needed range
rings for ocean races, which did not correctly reflect the
projection of the map. Although it projected like a nice round
circle, the correct shape should have been oval.<br>
<br>
Did not find a geographic circle function in OL, so I adapted one
from one found online.<br>
<br>
I present it here should anyone want it, or have a better idea, or
want to point out that this was in OL all along.<br>
<br>
<b>function GeoCircle(latin, lonin, radius)// thanks to VE site for
basic algo. Returns an OL Polygon of diameter in nautical miles<br>
{<br>
var locs = new Array();<br>
var lat1 = latin * Math.PI/180.0;<br>
var lon1 = lonin * Math.PI/180.0;<br>
var d = radius/3440.07;// change this value to the radius of
the Earth in your units<br>
var x;<br>
for (x = 0; x <= 360; x+=6) //gives 60 points. More than
enough for a smooth circle most likely<br>
{<br>
var tc = (x / 90)* Math.PI / 2;<br>
var lat =
Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc));<br>
lat = 180.0 * lat / Math.PI;<br>
var lon;<br>
if (Math.cos(lat1)==0)<br>
{<br>
lon=lonin; // endpoint a pole<br>
}<br>
else<br>
{<br>
lon = ((lon1 - Math.asin(Math.sin(tc) *
Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI;<br>
}<br>
lon = 180.0 * lon / Math.PI;<br>
var loc = new pt(lon,lat);<br>
locs.push(loc);<br>
}<br>
var poly = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Polygon(new
OpenLayers.Geometry.LinearRing(locs)));<br>
<br>
return poly; //this can be added to a map<br>
}<br>
</b><br>
</body>
</html>