如何在Openlayers 3中获取用户绘制圆的坐标?

问题描述 投票:1回答:2

我在Openlayers3中有一个静态图像层,用户可以在其中绘制圆形,点和多边形等特征。

我可以使用以下代码获取Point,Polygon和LineString的坐标:

draw_interaction.on('drawend', function(event) {
    var geoJsonGeom = new ol.format.GeoJSON();    
    var pp = geoJsonGeom.writeGeometry(event.feature.getGeometry());
    console.log(pp);
});

这会按预期输出坐标:

"{"type":"Point","coordinates":[1441.9187662124637,1365.3125032424925]}"

但是,我无法弄清楚如何获得Circle的坐标。 Circle的输出如下所示:

"{"type":"GeometryCollection","geometries":[]}"

Openlayers版本是v3.5.0。

编辑:为了获得中心和半径,你必须使用特征本身,而不是它的GeoJSON输出(因为GeojSON没有圆):

var circle = event.feature.getGeometry();
console.log('radius:' + circle.getRadius());
console.log('center:' + circle.getCenter());
openlayers-3
2个回答
2
投票

GeoJSON没有圆几何。正确的解决方案是在序列化之前用多边形近似圆。您可以使用ol.interaction.Draw的新几何选项来实现这一点。请参阅:https://github.com/openlayers/ol3/pull/3673有关该主题的更深入讨论,请参阅此github问题:https://github.com/openlayers/ol3/pull/3434


-1
投票
draw_interaction.on('drawend', function(event) {
    var geoJsonGeom = new ol.format.GeoJSON();    
    var pp = geoJsonGeom.writeGeometry(event.feature.getGeometry());
    console.log(pp);
});

效果很好

© www.soinside.com 2019 - 2024. All rights reserved.