openlayers / ol2

OpenLayers v2 - deprecated!
Other
1.48k stars 771 forks source link

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

Open balajiputhiran opened 6 years ago

balajiputhiran commented 6 years ago

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 commented 4 years ago

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