Draw a circle with defined diameter in OpenLayers

一世执手 提交于 2019-12-06 11:52:19

Use the following function to create circular points around a point.

//pass the 
//@pointX, 
//@pointY, 
//@radius of circle (in your case diameter/2)
//@pointsToFind this is how detail you want the circle to be (360 if you want one point for each rad)

function createCirclePointCoords(circleCenterX,circleCenterY,circleRadius,pointsToFind){
      var angleToAdd = 360/pointsToFind;
      var coords = [];  
      var angle = 0;
        for (var i=0;i<pointsToFind;i++){
        angle = angle+angleToAdd;
            console.log(angle);
        var coordX = circleCenterX + circleRadius * Math.cos(angle*Math.PI/180);
        var coordY = circleCenterY + circleRadius * Math.sin(angle*Math.PI/180);
            coords.push([coordX,coordY]);
        }

    return coords;
    }

And then create a polygon out of the coordinates returned from the function

var circleCoords = createCirclePointCoords(0,0,1000,360);
var geom = new ol.geom.Polygon([
circleCoords
])
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!