terra-draw icon indicating copy to clipboard operation
terra-draw copied to clipboard

[Feature Request] There should be dedicated event for coordinate "drag end"

Open aircodepl opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe.

Hi. Calling 'onFinish' event on every change (coordinate drag end) is a bad idea. There should be more dedicated events created for this purpose.

There was this change request: https://github.com/JamesLMilner/terra-draw/issues/80

and done here: https://github.com/JamesLMilner/terra-draw/pull/82

Example:

I wish to force user to draw only 1 polygon on map. So I'm waiting for the finish event, to disable polygon mode. Managed to do it like this:

draw.on('finish, function () {
   draw.setMode('static');
   deactivateButtons();
});

I understand onFinish event as finishing some work, the whole task:

  • If user finished drawing polygon
  • If user finished editing polygon (clicked out of & deselected polygon)
  • If user finished dragging a polygon (clicked out of & deselected polygon)...

Currently, if user drags a coordinate it calls the finish event, which in my case deselects polygon and the select mode. User needs to select the polygon again... And again...

Describe your proposed idea for the solution to this problem

For me:

  • onChange should be called on the whole polygon drag, but onFinish works ok,
  • onChange & onDrag should be called on coordinate drag.

Describe alternatives you've considered

If onFinish needs to stay, then we need to know what was the action and which object did call it, examples:

draw.on('finish', function(e) {
   console.log(e.id); // prints same as current uuid 44d4b4d7-8b6c-4760-9c6c-c38989e785bb
   console.log(e.objectType); // prints 'coordinate', 'polygon' etc.
   console.log(e.action); // drag or coordinateDrag
});

Unfortunately, I don't have experience in designing open source product, so I cannot provide any professional examples/ideas.

This solution is important for me to provide advanced UX for user, so if you make a proper solution, I will gladly make a small $ contribution. Edit: Oh, you don't have the sponsor button yet lol.


For now I'm saving the last action and resetting mode only if it's not the Select mode to keep this mode running.

const MODE_CREATE = 'polygon';
const MODE_SELECT = 'select';

(...)

draw.on('finish', function () {
    if (lastModeChosen !== MODE_SELECT) {
         setStatic();
         deactivateButtons();
    }
});

aircodepl avatar May 21 '24 07:05 aircodepl