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);
我正在使用 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);