在OpenLayers中绘制具有定义直径的圆 [英] Draw a circle with defined diameter in OpenLayers
本文介绍了在OpenLayers中绘制具有定义直径的圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写代码,让我的用户在地图上定义一些点,一旦他们创建了一个点,程序应在该点周围绘制一个具有定义的直径(以千米或...为单位)的圆.
I'm trying to write a code which let my users define some points on the map and once they created a point, the program should draw a circle with defined diameter(in kilometers or ... ) around the point.
我可以指出一点,但我不知道该如何处理我所说的话.
I can draw a point but I don't know how I could handle what I said.
以下是我想要的例子:
推荐答案
使用以下函数在一个点周围创建圆点.
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
])
这篇关于在OpenLayers中绘制具有定义直径的圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文