question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Draw Interaction removeLastPoint not acting as expected

See original GitHub issue

Describe the bug When enabling the Draw interaction and calling the removeLastPoint function, the draw layer does not update.

To Reproduce Steps to reproduce the behavior:

  1. Add the Draw Interaction to the map with type: 'Polygon'
  2. Draw a polygon and mid draw, call the removeLastPoint function
  3. Observe that the polygon you were drawing does not update
  4. Call removeLastPoint again and find that the line segment that was supposed to be removed in the 1st call is now removed.
  5. Click on the map again to resume drawing and see that the segment of call 2 is now removed and drawing has commenced as expected

Expected behavior On removeLastPoint call, update the map with the original geometry with the last drawn segment removed

Relevant Code https://github.com/openlayers/openlayers/blob/v6.3.1/src/ol/interaction/Draw.js#L817

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ahocevarcommented, Jul 15, 2021

The cleanest solution is probably to render the sketch point in some way, but with a modified condition you could make the sketch point appear at the last clicked location:

    condition: (event) => {
      if (
        event.originalEvent.pointerType === "mouse" &&
        event.originalEvent.button === 2
      ) {
        draw.removeLastPoint();
        const moveEvent = new MapBrowserEvent("pointermove", map, event.originalEvent);
        draw.handleEvent(moveEvent);
        draw.handleEvent(moveEvent);
        return false;
      }
      return true;
    }
0reactions
JackD83commented, Jul 15, 2021

I think this problematic if I remove the second point of a line or polygon. If I have a style that does not draw single points and remove the second point, the whole feature disappears until I move the mouse. This was seen as error by the users.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove last point from Draw Interaction in Ol3 - Stack Overflow
The following code do not work. It seems to remove it when it draw the area part, but the vertex is stil there....
Read more >
Opening A Closed Polygon In Openlayers To Continue Drawing
Describe the bug When enabling the Draw interaction and calling the removeLastPoint function the draw layer does not update. To Reproduce Steps to...
Read more >
Undoing last point when drawing linestring in OpenLayers 3?
Since OpenLayers 3.9.0, this is as simple as using the removeLastPoint method of the DrawInteraction . So you can do something like this:...
Read more >
OpenLayers v4.6.5 API - Class: Draw
Geometry name to use for features created by the draw interaction. condition, ol. ... Remove last point of the feature currently being drawn....
Read more >
Creating Lively Regions: February 2002, Volume 8 Number 2 | PDF ...
Similarly, buttons and menu items always look like you expect them to look, so youre accustomed to using them no matter what application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found