我正在使用 ol.interaction.Draw 在我的 map 上绘制点。我想让用户每次点击“绘制”图标时都能绘制一个独特的点。 知道如何做到这一点吗?
这是交互代码:
function addInteraction() {
draw = new ol.interaction.Draw({
source: sourceComments,
type: "Point"
});
draw.on('drawend',
function(evt) {
// unset sketch
sketch = null;
var allFeatures = comments.getSource().getFeatures();
var format = new ol.format.GeoJSON();
document.getElementById('geometry').value = JSON.stringify(format.writeFeatures(allFeatures), null, 4);
}, this);
map.addInteraction(draw);
}
谢谢!
最佳答案
您可以在 drawend
事件中从 map 中删除交互。
var draw;
function addInteraction() {
draw = new ol.interaction.Draw({
source: sourceComments,
type: "Point"
});
draw.on('drawend', function(evt) {
//... unset sketch
map.removeInteraction(draw);
}, this);
map.addInteraction(draw);
}
关于javascript - 在 Openlayers 3 中只允许一个绘图功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27501026/