Openlayers3 turn on by hand as always
In OpenLayers3 v3.5, how do you always enable hand draw? The default to enable drawing is done using the property freehandCondition
ol.interaction.Draw
, which is set to the shift key by default.
draw = new ol.interaction.Draw({
source: drawLayer.getSource(),
type: 'LineString',
freehandCondition: ol.events.condition.shiftKeyOnly
});
But I don’t want that. I dont want the shift key to be turned on by hand. I want freehand to be enabled with click and drag without any key modifiers.
I tried:
freehandCondition: ol.events.condition.always
freehandCondition: ol.events.condition.click
freehandCondition: ol.events.condition.noModifierKeys
But none of these works.
You might think that by doing this, copy the map, but I've already disabled panning, changing the default interaction to dragPan: false
source to share
You missed the documentation , the parameter condition
for ol.interaction.Draw
. He 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
});
Check out this fiddle for a demo.
I may be missing the best option. You may also need to try other conditions if the behavior is not exactly what you expected.
source to share