>我添加了绘制交互以绘制默认手绘多边形的条件是 SHIFT 键,但如果在手机和平板电脑中打开地图,我们如何绘制。
drawOptions.type = 'Polygon';
this.draw = new ol.interaction.Draw(drawOptions);
this.draw.on('drawend', lang.hitch(this, "drawEnd"));
我们怎么画画? 他们还有其他条件我可以给出吗?
有几种方法可以暂停拖动平移并在 OL3 中启用手绘。 以下是设置 freeHandCondition 的一种方法(其中变量 shapeGeom 是 Point、LineString 或 Polygon):
function drawInteraction() {
if (shapeGeom == 'Point') {
draw = new ol.interaction.Draw({
features: drawfeature,
type: shapeGeom,
})
} else {
draw = new ol.interaction.Draw({
features: drawfeature,
type: shapeGeom,
freehandCondition: ol.events.condition.always,
condition: ol.events.condition.never,
})
}
map.addInteraction(draw);
}
启动绘制操作时,暂停拖动。
map.getInteractions().forEach(function(interaction) {
if (interaction instanceof ol.interaction.DragPan) {
interaction.setActive(false);
}
}, this);
然后,在绘制要素后恢复拖动。
draw.on('drawend', function(event){
map.addInteraction(new ol.interaction.DragPan)});
OL3 的 API 文档包含有关 freeHandCondition 和 DragPan 元素的信息,其中包含这些链接。