praks5432
praks5432

Reputation: 7792

Circle not showing in OpenLayers

Extremely new to OpenLayers and trying to draw a circle on a map around a clicked origin. I have this code -

circleLayer = new OpenLayers.Layer.Vector "Circle Search"
circle = new OpenLayers.Geometry.Polygon.createRegularPolygon(
  new OpenLayers.Geometry.Point(lat,lon),
  100,
  30
  )
console.log(circle)
feature = new OpenLayers.Feature.Vector(circle)
circleLayer.addFeatures(feature)
mapApp.map.openLayersMap.addLayer circleLayer

But the circle is not showing up, and I'm not sure why. Can anyone tell me?

Upvotes: 0

Views: 272

Answers (1)

JJones
JJones

Reputation: 812

Are you converting your lat lon to the projection used by your map?

Test: Try using 0,0 for lon,lat with a bigger circle and see if it appears off the coast of east-central Africa.

If that's the problem then here's how you do the transform:

add at the top:

 projLatLon = new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
 projMap = new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection

then the third line of your example code becomes:

 new OpenLayers.Geometry.Point(lat,lon).transform(projLatLon,projMap),

Upvotes: 3

Related Questions