openlayers3如何始终启用徒手绘制

openlayers3 how to always enable freehand draw

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

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

但我不想这样。我不想按下 shift 键来启用徒手操作。我希望在没有任何键修饰符的情况下通过单击并拖动来启用手绘。

我试过:

freehandCondition: ol.events.condition.always

freehandCondition: ol.events.condition.click

freehandCondition: ol.events.condition.noModifierKeys

但是 none 这些工作。

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

您在 the documentation 中遗漏了 ol.interaction.Drawcondition 参数。它与 freehandCondition.

冲突

应该像下面这样(已测试)

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

查看 this Fiddle 的演示。

我可能错过了更好的选择。如果行为不完全符合预期,您可能还需要尝试其他条件。