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);