I know how to make a predetermined polygon in OpenLayers (see below).

Please have a look at http://studio.netnrg.co.za/dev/rnd/blake.loizides/openlayers

var feature2 = new OpenLayers.Feature.Vector(
  OpenLayers.Geometry.fromWKT("POLYGON((-120.828125 -50.3515625, -80.1875 -80.0078125, -40.40625 -20.4140625, -120.828125 -50.3515625))"

I have made an edit circle (40 points in OpenLayers) (my client wanted to see a circle on the map for zones).

The problem I have is that I can only store the following details and not the 40 points or coordinates or vertices to make a circle in OpenLayers. I can only STORE 4 COORDINATES.

In the database I store the bounds top bottom left and right (bottom: -29.054153382197, left: 23.782779686138, right: 23.79286499053, top: -29.044068077805) I will replace the coordinates with the ones in my database.

The radius (525.627982303084)

And the center Longitude and Latitude (lon=23.787822338334,lat=-29.049110730001)

Now I made some calculations below.

My question is how do I now recreate a (circle) with the information I have above that is stored in my database?

I know how to get data from my database and display it on the map, what I don't know is how to make a circle if I can't store the 40 points and only have the radius, the bounds, and the center Lon/Lat to make a circle.

Please if anyone can help me I would be greatly appreciative.

I only want a circle for the look and for no other reason.

My Calculations

Circle from OpenLayers

1 Answer 1


I'm new to openlayers but this helped me you only need a center point (long lat) and a radius don't forget the function createGeodesicPolygon

Creating vector features onload in OpenLayers

there is a link to a demo

var origin = "new OpenLayers.Geometry.Point(Long Lat)"; 
//then set the radius here 
var polygon = createGeodesicPolygon(origin, RADIUS, 60, 0, map.getProjectionObject()) 

hope that helps

  • 1
    Yes, and for origin use the center point of your bounds by doing a myBounds.getCenterLonLat(). example: var originLonLat = myBounds.getCenterLonLat(); var origin = new OpenLayers.Geometry.Point(originLonLat.lon originLonLat.lat);
    – CaptDragon
    Commented Apr 18, 2012 at 17:30
  • 1
    Here's a working example of it using your example bounds from database. jsfiddle.net/4S5Ke/5
    – CaptDragon
    Commented Apr 18, 2012 at 17:42
  • 1
    And this one with your example radius: jsfiddle.net/4S5Ke/6
    – CaptDragon
    Commented Apr 18, 2012 at 17:45
  • Thanks Holly and Thanks CaptDragon that helped me alot . Thanks so much Commented Apr 18, 2012 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.