在 Open Layers 3 中向矢量源添加圆圈
Adding a circle to a vector source in Open Layers 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]);
和
circleFeature.setCoordinates([x,y]);
但是每次我得到
Object doesn't support property or method 'setCoordinates'.
我想我没有将 setCoordinates 应用于正确的对象。我需要用 Circl 复制的来自或自己的应用程序的示例代码只有一个 LineString 而不是 Circle,但到目前为止我还没有找到如何将它与 Circle 一起使用。
应该是:
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);
我的代码是这样的:
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]);
和
circleFeature.setCoordinates([x,y]);
但是每次我得到
Object doesn't support property or method 'setCoordinates'.
我想我没有将 setCoordinates 应用于正确的对象。我需要用 Circl 复制的来自或自己的应用程序的示例代码只有一个 LineString 而不是 Circle,但到目前为止我还没有找到如何将它与 Circle 一起使用。
应该是:
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);