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

Starting the draw with a javascript call ? #519

Open
flemmens opened this issue Apr 18, 2016 · 2 comments
Open

Starting the draw with a javascript call ? #519

flemmens opened this issue Apr 18, 2016 · 2 comments
Assignees
Labels

Comments

@flemmens
Copy link

Hi,

I am not sure if this could be an improvement suggestion or if this is something already possible:
can we start the drawing process with a javascript call rather than having to click on the toolbar ?

Something like myDrawControl.startdraw('polygon') ?

Thanks

@flemmens
Copy link
Author

OK, if found a way to do it:
$('.leaflet-draw-draw-circle')[0].click();

However this is not an elegant solution as it requires to have the toolbar in the DOM.

@ddproxy
Copy link
Member

ddproxy commented Apr 24, 2016

@flp-gpc - Going of a button event (e) there is the following.. You will have to tweak the code a bit to your needs though.

        toggleDrawn: function(e) {
            var shapeParameters = {
                shapeOptions: {
                    color: '#FF6633',
                    dashArray: '5',
                    clickable: false,
                    pointerEvents: 'none'
                }
            };
            currentDrawer = null;
                if (e.currentTarget.value == 'rectangle') {
                   currentDrawer = new L.Draw.Rectangle(map, shapeParameters);
                   currentDrawer.enable();
                } else if (e.currentTarget.value == 'polygon') {
                   clearCurrentDrawing();
                   currentDrawer = new L.Draw.Polygon(map, shapeParameters);
                    currentDrawer.enable();
                }
        },

@ddproxy ddproxy self-assigned this Apr 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants