gpt4 book ai didi

javascript - OpenLayers 3不绘制多边形

转载 作者:行者123 更新时间:2023-12-03 08:59:35 24 4
gpt4 key购买 nike

我正在使用 OpenLayers 3,并且尝试使用给定坐标绘制多边形,但未绘制多边形。这是我尝试过的:

var source = new ol.source.Vector();

var ring = [
[3139880.24789847, 5961935.332187176], [3179627.5026067616, 5972025.01992082],
[3146606.706387566, 5927997.291628557], [3186353.9610958574, 5939615.719927904]];

draw = new ol.interaction.Draw({
source: source,
type: 'Polygon',
geometryFunction: ring,
});

draw.on('drawend', function (e) {
var id = guid();
e.feature.featureID = id;
e.feature.setProperties({
'id': id,
'name': 'Polygon',
'description': 'Some values'
})
map.removeInteraction(draw);
});
map.addInteraction(draw);

最佳答案

由于您已经有了坐标,所以我认为 ol.interaction.Draw() 不合适。绘制适用于用户能够在 map 上绘制的情况。

只需使用矢量图层并将其添加到 map 中,如下所示:

var feature = new ol.Feature({
geometry: new ol.geom.Polygon(coordinates)
});

var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [ feature ]
})
});

map.add(vectorLayer);

关于javascript - OpenLayers 3不绘制多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32351796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com