Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
balajiputhiran opened this issue Jun 29, 2018 · 1 comment
Open

Comments

@balajiputhiran
Copy link

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();

}

@chenyunping66
Copy link

chenyunping66 commented Oct 23, 2019

请问你这个问题解决了吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants