openlayers3 how to always enable freehand draw

守給你的承諾、 提交于 2019-12-23 19:36:54

问题


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
});

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.

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


回答1:


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
});

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.



来源:https://stackoverflow.com/questions/30420416/openlayers3-how-to-always-enable-freehand-draw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!