Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

For a project I am working on, I need to be able to put a polygon on a map using OpenLayers, based on a variable point that can be set by a user. The polygon is an isosceles triangle of which two legs should be exactly 1 kilometer and should originate from a point set by the user under an angle of 90 degrees. Does anyone know how this can be done?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The standard way to add a regular polygon to an OpenLayers map is with the createRegularPolygon method.

Here's an example:

var lat = 40.12345
var lon = -90.54321
var center_point = new OpenLayers.Geometry.Point(lon, lat);
var triangle = new OpenLayers.Geometry.Polygon.createRegularPolygon(center_point, 1.2, 3, 90);

In this example the lon/lat values are in degrees (e.g., EPSG:4326), and the radius (1.2) is in those map units as well.

EDIT: If you want a circle instead of a triangle, change the "sides" parameter (3 in the example above) to 20, which gives a good approximation of a circle.

share|improve this answer
    
Very useful! Can you show how to create a circle ? –  Magno C Dec 6 '12 at 16:43
1  
I edited the answer to show how to make a circle. I hope that helps. –  katahdin Dec 6 '12 at 17:02
    
Thanks a lot! helped 2 users in one shot !! Thumbs UP! –  Magno C Dec 6 '12 at 18:06
    
@Michiel Mark the answer and answered if you think he answered your question. –  CaptDragon Dec 6 '12 at 18:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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