geoman-io / leaflet-geoman

πŸ‚πŸ—ΊοΈ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

Undo/Redo Options #320

Closed agrimgupta92 closed 6 years ago

agrimgupta92 commented 6 years ago

Is there any plan to add the option to undo/redo in polygons/polylines? I see from previous issues that you plan to add them. Can you please tell when the feature will be ready or suggest a temporary/hacky way to get it to work? Update: I was able to get "undo" working as this pull request does this: https://github.com/codeofsumit/leaflet.pm/pull/284 Is it possible to add redo also?

codeofsumit commented 6 years ago

@agrimgupta92 I can't give any timelines, I work on leaflet.pm when I find the time. a solution to add redo is to do this inside your application. Whenever the user changes something, or "undoes" something, save the layer and show a "redo" button. When the user clicks it, overwrite the layer with the saved one.

I will add #284 soon, I'm not sure about redo though.

I will mark this issue as a feature request, especially for Redo. Anyone who is also interested in this, please give it an upvote πŸ‘

Falke-Design commented 3 years ago

Hey guys, let us discuss how this should work.

  1. For which modes / shapes should be undo / redo able to called?
  2. Should be undo / redo called per layer / mode or on the complete project? The problem will be, that if undo is called over the project, we need to save the order when which layer was changed, this is not so easy
  3. How often should be undo able to call? ...
henrikmaa commented 3 years ago

This is my idea of how it should work

Modes:

Edit: cancel was not in this feature request, but i think also cancel editing should be included in this.

This is my cancel edit just for inspiration

//this code is not perfect
//currentLayer  = e.target
//restoreLayer = e.target from pm:enable
//restoreLatLng = restoreLayer.getLatLng()

static cancelEditOnLayer = (map, currentLayer, restoreLayer, restoreLatLng) => {
    if (!(restoreLayer instanceof L.Polyline)) {
      restoreLayer.setLatLng(restoreLatLng)
    } else {
      restoreLayer.setLatLngs(restoreLatLng)
    }
    currentLayer.pm.disable()
  }