【问题标题】:Draw a circle with defined diameter in OpenLayers在 OpenLayers 中绘制具有定义直径的圆
【发布时间】:2015-11-30 10:29:40
【问题描述】:

我正在尝试编写一个代码,让我的用户在地图上定义一些点,一旦他们创建了一个点,程序应该在该点周围绘制一个具有定义直径(以公里或 ...)为单位的圆。

我可以画一个点,但我不知道如何处理我所说的。

这是我想要的示例:

【问题讨论】:

标签: openlayers-3


【解决方案1】:

使用以下函数围绕一个点创建圆形点。

//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
])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-28
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多