Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 向开放层3中的矢量源添加圆_Javascript_Coordinates_Geometry_Layer_Openlayers 3 - Fatal编程技术网

Javascript 向开放层3中的矢量源添加圆

Javascript 向开放层3中的矢量源添加圆,javascript,coordinates,geometry,layer,openlayers-3,Javascript,Coordinates,Geometry,Layer,Openlayers 3,我的代码是这样的: var circle = new ol.style.Circle({ radius: 5, fill: null, stroke: new ol.style.Stroke({ color: 'rgba(255,0,0,0.9)', width: 3 })

我的代码是这样的:

var circle = new ol.style.Circle({
                radius: 5,
                fill: null,
                stroke: new ol.style.Stroke({
                    color: 'rgba(255,0,0,0.9)',
                    width: 3
                })
            });
var circleFeature = new ol.Feature(circle);
我试过了

circle.setCoordinates([x,y]);

但每次我

对象不支持属性或方法“setCoordinates”

我想我并没有将setCoordinates应用于正确的对象。我需要用圆圈复制的来自或自己的应用程序的示例代码只是一个LineString,而不是一个圆圈,但我还没有找到如何将其用于圆圈。

应该是:

var circle = new ol.style.Style({
    image: new ol.style.Circle({
        radius: 5,
        fill: null,
        stroke: new ol.style.Stroke({
            color: 'rgba(255,0,0,0.9)',
            width: 3
        })
    })
});

var feature = new ol.Feature(
    new ol.geom.Point([0, 0])
);
feature.setStyle(circle);
vectorSource.addFeature(feature);
因此,可以将样式应用于特征,如果要设置坐标,可以使用:

feature.getGeometry().setCoordinates(coordinate);

.

我遇到的问题之一似乎是,我使用的是ol.style.Circle,而不是ol.geom.Circle。
feature.getGeometry().setCoordinates(coordinate);