簡體   English   中英

在“開放層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]);

但是每次我得到

對象不支持屬性或方法“ 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);

小提琴演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM