繁体   English   中英

OpenLayers 3不绘制多边形

[英]OpenLayers 3 doesn't draw the polygon

我正在使用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()不适合。 绘制用于用户能够在地图上绘制的情况。

只需使用矢量层,然后将其添加到地图即可,如下所示:

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

暂无
暂无

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

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