在 OpenLayers 中绘制具有定义直径的圆
Draw a circle with defined diameter in OpenLayers
我正在尝试编写一个代码,让我的用户在地图上定义一些点,一旦他们创建了一个点,程序应该围绕该点绘制一个具有定义直径(以公里或...为单位)的圆.
我可以得出一个观点,但我不知道如何处理我所说的。
这是我想要的示例:
使用以下函数围绕一个点创建圆点。
//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;
}
然后根据函数返回的坐标创建一个多边形
var circleCoords = createCirclePointCoords(0,0,1000,360);
var geom = new ol.geom.Polygon([
circleCoords
])
我正在尝试编写一个代码,让我的用户在地图上定义一些点,一旦他们创建了一个点,程序应该围绕该点绘制一个具有定义直径(以公里或...为单位)的圆.
我可以得出一个观点,但我不知道如何处理我所说的。
这是我想要的示例:
使用以下函数围绕一个点创建圆点。
//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;
}
然后根据函数返回的坐标创建一个多边形
var circleCoords = createCirclePointCoords(0,0,1000,360);
var geom = new ol.geom.Polygon([
circleCoords
])