Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aircodepl opened this issue May 21, 2024 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@aircodepl
Copy link
Contributor

aircodepl commented May 21, 2024

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:
#80

and done here:
#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();
    }
});

@JamesLMilner
Copy link
Owner

Hey @aircodepl - thanks for raising this. I am going to try and address this with #261 . This will allow you to determine why the onFinish event was called and from which mode. I hope this helps!

@JamesLMilner
Copy link
Owner

This should be resolved now 👍🏻 Please feel free to open a new issue if there are any concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants