问题
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