I want to create a marker and buffer around it with a given radius on map click event. Marker is displayed successfully but the polygon doesn't display. I guess there is problem in projection setting. Here are the projection settings for my map.

projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG: 4326")

The event handler is as under.

    radius = 3000;
    var sides = 50;

    if (!markersLayer) {
        markersLayer = new OpenLayers.Layer.Markers("Markers");
        bufferLayer = new OpenLayers.Layer.Vector("Buffer Layer");
    position = map.getLonLatFromPixel(e.xy);

    //Create Marker
    var size = new OpenLayers.Size(15, 15);
    var offset = new OpenLayers.Pixel( - (size.w / 2), -size.h);
    var icon = new OpenLayers.Icon(iconURL, size, offset);
    var marker = new OpenLayers.Marker(position, icon);
    // Cleanup Markers First

    //Create Polygon
    var circle = new OpenLayers.Geometry.Polygon.createRegularPolygon(position, radius, sides, 0);
    var circleFeature = new OpenLayers.Feature.Vector(circle);
    var circleFeatures = [];
    // Cleanup Features First

According to http://osgeo-org.1560.x6.nabble.com/new-OpenLayers-Geometry-Polygon-createRegularPolygon-td3969939.html


http://dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/OpenLayers/Geometry/Polygon-js.html#OpenLayers.Geometry.Polygon.createRegularPolygon you need to hand over a point Geometry.

The coordinates of the point are not what the function expects.

You might refer to OpenLayers - Cannot draw a circle using createRegularPolygon and How to draw a polygon with preset length in OpenLayers? for working examples.

  • Thanks finally able to do it, just converted the position object to point using var center_point = new OpenLayers.Geometry.Point(position.lon, position.lat); – Mk Swati Sep 10 '15 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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