-2

I have learned a Draw object in Openlayers.

I try to draw the dotted line when user moves the mouse. When user clicks the last and prev lines should be replaced on straight line.

How does it work, should I use two different drawing ayers and switch between them?

Or I can retrieve a last line from draw object and redraw it on straight line?

I try to use this sample from official document:

https://openlayers.org/en/latest/examples/measure-style.html

Daniella
  • 1
  • 2

1 Answers1

0

There is a solution: measure-style

  1. Set a tag when feature draw end
draw.on('drawend', function (e) {
    e.feature.set('finished',true)
    ...
});
  1. Rewrite style function to treat the two situations differently
function styleFunction(feature, segments, drawType, tip) {
  const stroke = style.getStroke()
  if (feature.get('finished'))
    stroke.setLineDash(null)
  else 
    stroke.setLineDash([10,10])
...
}
Chen
  • 16
  • 3
  • Simpler still when the styleFunction is called from the draw interaction it is passed `drawType`, so just test thaT f`unction styleFunction(feature, segments, drawType, tip) { style.getStroke().setLineDash(drawType ? [10, 10] : null);` https://codesandbox.io/s/measure-style-forked-35sy2g?file=/main.js – Mike Jun 30 '22 at 11:06