[英]openlayers3 how to always enable freehand draw
In OpenLayers3 v3.5, how do you always enable freehand draw? 在OpenLayers3 v3.5中,你如何始终启用徒手画? 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. 启用徒手绘制的默认设置是通过
ol.interaction.Draw
的freehandCondition
属性完成的,默认情况下,该属性当前设置为shift键。
draw = new ol.interaction.Draw({
source: drawLayer.getSource(),
type: 'LineString',
freehandCondition: ol.events.condition.shiftKeyOnly
});
But I dont want that. 但我不想那样。 I dont want the shift key to be pressed to enable freehand.
我不希望按下shift键来启用徒手画。 I want freehand to be enabled by click-and-drag without any key modifiers.
我希望通过单击并拖动而不使用任何键修饰符来启用徒手画。
I've tried: 我试过了:
freehandCondition: ol.events.condition.always
freehandCondition: ol.events.condition.click
freehandCondition: ol.events.condition.noModifierKeys
But none of these work. 但这些都不起作用。
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
您可能想知道通过这样做会平移地图,但我已经通过更改我的默认交互禁用平移,以便
dragPan: false
You missed in the documentation , the condition
parameter for the ol.interaction.Draw
. 你错过了文档 ,
ol.interaction.Draw
的condition
参数。 It conflicts with freehandCondition
. 它与
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
});
Look at this Fiddle for a demo. 看看这个小提琴进行演示。
I may missed a better option. 我可能错过了一个更好的选择。 You may also need to try with other conditions if the behaviour is not exactly the expected one.
如果行为不完全符合预期,您可能还需要尝试其他条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.