如何从 DrawRegular 交互ol-ext,ol3中获取半径和中心坐标?

问题描述

我正在尝试存储具有中心坐标和半径的圆形几何图形。 “e.feature.getGeometry().geTradius()”和“getCenter()”失败。

我需要检测它是一个圆,然后将中心坐标和半径存储在 DB 中。但是如果它是一个多边形,那么我需要用它的类型来存储坐标,比如三角形,那么我不应该按预期检查它的中心坐标或半径。

var view = new ol.View({
    center: ol.proj.fromLonLat([35.14,38.81]),zoom: 7,projection: 'epsg:900913',displayProjection: 'epsg:4326',units: "m",crossOrigin: "anonymous"
})
var attr = new ol.control.Attribution({
    collapsible: true,label: "A",collapsed: true,tipLabel: "TEST"
});


var map = new ol.Map({

    controls: ol.control.defaults({ attribution: true }).extend([
        new ol.control.Attribution({
            collapsible: true,label: "i",tipLabel: "TEST",collapseLabel: "T"

        }),new ol.control.FullScreen({
            source: 'fullscreen',})
    ]),layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        })
    ],target: 'map',view: view



});



// New vector layer
var vector = new ol.layer.Vector({
    name: 'Vecteur',source: new ol.source.Vector()
});
map.addLayer(vector);

var interaction = new ol.interaction.DrawRegular({
    source: vector.getSource(),sides: 2,// this value will come from page after i fixed this problem.
    canRotate: true 
});
map.addInteraction(interaction);
interaction.on('drawstart',function (e) {
    // e.feature.on('change',function (){console.log('change');})
});

// Events handlers
interaction.on('drawing',function (e) {
    if (e.feature.getGeometry().getArea)
        var area = (e.feature.getGeometry().getArea() / 1000000).toFixed(2);
        console.log("area(km2):"+area)
});

interaction.on('drawend',function (e) {
// I need to check type of geometry too. it's a circle or triangle etc.
    if (e.feature.getGeometry().getArea) {

        var geometry = e.feature.getGeometry();
        var radius = geometry.geTradius(); // !!FAIL HERE!!
        var center = geometry.getCenter();
        console.log("radius:" + radius);
        console.log("center coordinatesı:");
        console.dir(center);
    }
});
// I'll draw circles on the map with coordinates which come from DB.
//var circle = new ol.geom.Circle(ol.proj.transform([-73.5971431341708,45.5323780468158],'epsg:4326','epsg:3857'),1000);

//var CircleFeature = new ol.Feature(circle);
.`

我使用 ol-ext 库和 ol3。 希望你帮帮我!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)