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

Do undo/crtl+z during a draw? #236

Closed
ketesagarana opened this issue Dec 5, 2013 · 10 comments
Closed

Do undo/crtl+z during a draw? #236

ketesagarana opened this issue Dec 5, 2013 · 10 comments

Comments

@ketesagarana
Copy link

I am drawing a polygon and do a wrong line. How can I undo this action, without redo all the polygon?

@peterb-2795
Copy link

+1 for this, should also include backspace on line input and when at initial point of input, one further backspace cancels the action completely. Equally, a ctl+z on a point input would cancel the point input. The suggestion above would be a very useful addition to functionality....

@Zverik
Copy link
Contributor

Zverik commented Dec 9, 2013

Duplicate for #229

Zverik added a commit to Zverik/Leaflet.draw that referenced this issue Dec 10, 2013
jacobtoye added a commit that referenced this issue Dec 19, 2013
Refactor toolbars, add "delete last point" action (fix #229, #236 and probably some others)
@ketesagarana
Copy link
Author

This is really great!!! This is already on official version?

@Zverik
Copy link
Contributor

Zverik commented Dec 19, 2013

Yes, it is merged and in the build.

@ketesagarana
Copy link
Author

I updated all the js, css and images, but it's hapening this error:

Uncaught TypeError: Cannot read property 'tooltip' of undefined 02_leafletdraw.js:9
L.Draw.Rectangle.L.Draw.SimpleShape.extend.initialize 02_leafletdraw.js:9
e 01_leaflet.js:6
L.DrawToolbar.L.Toolbar.extend.getModeHandlers 02_leafletdraw.js:10
L.Toolbar.L.Class.extend.addToolbar 02_leafletdraw.js:9
L.Control.Draw.L.Control.extend.onAdd 02_leafletdraw.js:9
o.Control.o.Class.extend.addTo 01_leaflet.js:9
o.Map.include.addControl 01_leaflet.js:9

I have to update only leaflet and leaflet.draw? I'm using the version 0.2.3-dev of the leaflet.draw and 0.7-dev of the leaflet.

@ketesagarana
Copy link
Author

I found the problem!
I needed to change the language of the components and I did override the L.drawLocal variables.
But I'm not working with all the shapes.So, I was defining the handlers only of the shapes that I was working.

The new leaflet.draw wait all the handlers defined.

@Zverik
Copy link
Contributor

Zverik commented Dec 19, 2013

It seems you did something very unusual. Override? What handlers? What do you mean by defining them? Doesn't regular string assignment work for you?

@ketesagarana
Copy link
Author

I'm working only with polygons and I did this to change the language:

L.drawLocal = {
            draw: {
                toolbar: {
                    actions: {
                        title:  functionThatReturnTheTextOnCorrectLanguage(),
                        text:  functionThatReturnTheTextOnCorrectLanguage()
                    },
                    undo: {
                        title: 'Delete last point drawn',
                        text: 'Delete last point'
                    },
                    buttons: {
                        polygon:  functionThatReturnTheTextOnCorrectLanguage()
                    }
                },
                handlers: {
                    polyline: {
                        error:  functionThatReturnTheTextOnCorrectLanguage()
                    },
                    polygon: {
                        tooltip: {
                            start:  functionThatReturnTheTextOnCorrectLanguage(),
                            cont:  functionThatReturnTheTextOnCorrectLanguage(),
                            end:  functionThatReturnTheTextOnCorrectLanguage()
                        }
                    },
                }
            },
            edit: {
                toolbar: {
                    actions: {
                        save: {
                            title:  functionThatReturnTheTextOnCorrectLanguage(),
                            text:  functionThatReturnTheTextOnCorrectLanguage()
                        },
                        cancel: {
                            title:  functionThatReturnTheTextOnCorrectLanguage(),
                            text:  functionThatReturnTheTextOnCorrectLanguage()
                        }
                    },
                    buttons: {
                        edit:  functionThatReturnTheTextOnCorrectLanguage(),
                        editDisabled: functionThatReturnTheTextOnCorrectLanguage(),
                        remove:  functionThatReturnTheTextOnCorrectLanguage(),
                        removeDisabled:   functionThatReturnTheTextOnCorrectLanguage()
                    }
                },
                handlers: {
                    edit: {
                        tooltip: {
                            text:  functionThatReturnTheTextOnCorrectLanguage(),
                            subtext:  functionThatReturnTheTextOnCorrectLanguage()
                        }
                    },
                    remove: {
                        tooltip: {
                            text: functionThatReturnTheTextOnCorrectLanguage()
                        }
                    }
                }
            }
        };

What should be the correct form to do this?
P.S: I did this on my file. I did not change the plugin file.

@Zverik
Copy link
Contributor

Zverik commented Dec 19, 2013

Well, you are completely redefining a class from the library, so no wonder you get errors when you skip properties. Base version of the object is gone by that time.

I recomment using plain assignments, like

L.drawLocal.draw.toolbar.actions.title = functionThatReturnTheTextOnCorrectLanguage();
L.drawLocal.draw.toolbar.actions.text =  functionThatReturnTheTextOnCorrectLanguage();
L.drawLocal.draw.toolbar.buttons.polygon = functionThatReturnTheTextOnCorrectLanguage();
L.drawLocal.draw.handlers.polyline.error = functionThatReturnTheTextOnCorrectLanguage();
L.drawLocal.draw.handlers.polygon.tooltip.start = functionThatReturnTheTextOnCorrectLanguage();
L.drawLocal.draw.handlers.polygon.tooltip.cont = functionThatReturnTheTextOnCorrectLanguage();
L.drawLocal.draw.handlers.polygon.tooltip.end = functionThatReturnTheTextOnCorrectLanguage();
// ... and so on ...

This is still bad design (you should cache everything), but at least it will work after the library is updated.

@ketesagarana
Copy link
Author

Thank you so much @Zverik ! Works perfectly.

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

No branches or pull requests

3 participants