简体   繁体   English

在“开放层3”中向矢量源添加圆

[英]Adding a circle to a vector source in Open Layers 3

My code goes like this: 我的代码是这样的:

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

I have tried 我努力了

circle.setCoordinates([x,y]);

and

circleFeature.setCoordinates([x,y]);

But each time I get 但是每次我得到

Object doesn't support property or method 'setCoordinates'. 对象不支持属性或方法“ setCoordinates”。

I guess I am not applying setCoordinates to the right object. 我想我没有将setCoordinates应用于正确的对象。 The example code from or own application that I need to replicate with a Circl simply has a LineString instead of a Circle, but I don't find how to use it with a Circle so far. 我需要用Circl复制的来自或自己的应用程序的示例代码只是具有LineString而不是Circle,但是到目前为止,我还没有找到如何在Circle中使用它的示例代码。

It should be: 它应该是:

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

So, you apply a style to the feature and if you want to setCoordinates you can use: 因此,您可以对要素应用样式,如果要设置坐标,则可以使用:

feature.getGeometry().setCoordinates(coordinate);

A Fiddle demo . 小提琴演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM