Skip to content

How to Convert Circle Polygon Geometry to Line in openlayers 2 #1529

@balajiputhiran

Description

@balajiputhiran

When user click on the map circle will be create based on user input radius values.I have to convert circle polygon Geometry to Line.When i am using new OpenLayers.Geometry.LinearRing(pGeometry.getVertices); it's not working properly i don't know how to do ? If anyone sort out my issue why i can't able to convert circle polygon to line.I thought if maybe Geometry format problem.I am not sure.Please help to sort out my issue

function initCircleDrawer() {

if (splitLayers.tempPoints == null) {
    splitLayers.createcircle = new OpenLayers.Layer.Vector("Temporary Circle", {
        styleMap: new OpenLayers.StyleMap({
            'default': {
                graphicName: "square",
                pointRadius: 5,
                fillColor: "white",
                fillOpacity: 0,
                strokeWidth: 0,
                strokeColor: "blue"
            }
        })

    });
    editMap.addLayer(splitLayers.createcircle);

    splitLayers.createcircle.events.on({
        featureadded: pointAdded
    });
}
var radiusvalue = document.getElementById("radiusbox").value;

var radius = radiusvalue;

var rd1 = 0;
if (!isNaN(radius)) {
    rd1 = Number(radius);
}
rd1 = rd1 / (bt_status.scaleFactor * bt_status.conversionFactor);

var mycircle = OpenLayers.Geometry.Polygon.createRegularPolygon(0, 0, 20, 0);

var featurecircle = new OpenLayers.Feature.Vector(mycircle);

splitLayers.createcircle.addFeatures([featurecircle]);



OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
    defaultHandlerOptions: {
        'single': true,
        'double': false,
        'pixelTolerance': 0,
        'stopSingle': false,
        'stopDouble': false
    },
    initialize: function (options) {
        this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions);

        OpenLayers.Control.prototype.initialize.apply(
                this, arguments
                );
        this.handler = new OpenLayers.Handler.Click(
                this, {
                    'click': this.trigger
                }, this.handlerOptions
                );
    },
    trigger: function (e) {
   
        var lonlat = editMap.getLonLatFromPixel(e.xy);
       
        var newPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
     
        splitLayers.createcircle.removeFeatures([featurecircle]);

        var mycircle = OpenLayers.Geometry.Polygon.createRegularPolygon(
                newPoint,
                rd1,
                40,
                0
                );
        
       alert(mycircle);  

       var line = new openlayers.geometry.linearring(mycircle.getvertices);
	   
        featurecircle = new OpenLayers.Feature.Vector(line);

        splitLayers.createcircle.addFeatures([featurecircle]);

    }
});
var click = new OpenLayers.Control.Click();
editMap.addControl(click);
click.activate();

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions