openlayers3如何始终启用徒手绘制 [英] openlayers3 how to always enable freehand draw

查看:188
本文介绍了openlayers3如何始终启用徒手绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OpenLayers3 v3.5中,如何始终启用徒手绘制?启用徒手画的默认设置是通过ol.interaction.DrawfreehandCondition属性完成的,该属性当前默认设置为Shift键.

In OpenLayers3 v3.5, how do you always enable freehand draw? The default for enabling freehand draw is done through the freehandCondition property of ol.interaction.Draw, which is currently set to the shift key by default.

draw = new ol.interaction.Draw({
  source: drawLayer.getSource(),
  type: 'LineString',
  freehandCondition: ol.events.condition.shiftKeyOnly
});

但是我不想要那个.我不希望按下Shift键以启用徒手绘制.我希望通过单击并拖动来启用徒手绘制功能,而无需任何键修饰符.

But I dont want that. I dont want the shift key to be pressed to enable freehand. I want freehand to be enabled by click-and-drag without any key modifiers.

我尝试过:

freehandCondition: ol.events.condition.always

freehandCondition: ol.events.condition.click

freehandCondition: ol.events.condition.noModifierKeys

但是这些都不起作用.

But none of these work.

您可能想知道这样做是否可以平移地图,但是我已经通过更改默认交互方式来禁用平移,因此dragPan: false

You may wonder that by doing this would pan the map, but I've already disabled panning by changing my default interactions so that dragPan: false

推荐答案

您错过了文档ol.interaction.Drawcondition参数.它与freehandCondition冲突.

You missed in the documentation, the condition parameter for the ol.interaction.Draw. It conflicts with freehandCondition.

应该像下面(经过测试)

It should be like below (tested)

draw = new ol.interaction.Draw({
  source: drawLayer.getSource(),
  type: 'LineString',
   condition: ol.events.condition.singleClick,
   freehandCondition: ol.events.condition.noModifierKeys
});

查看此小提琴进行演示.

我可能错过了一个更好的选择.如果该行为与预期的行为不完全相同,则可能还需要尝试其他条件.

I may missed a better option. You may also need to try with other conditions if the behaviour is not exactly the expected one.

这篇关于openlayers3如何始终启用徒手绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆