Skip to content

Show/hide buttons (first draft) #235

Open
wants to merge 1 commit into from

4 participants

@eonlepapillon

Added two public methods to the draw controller.

drawControl.hideButton();
drawControl.showButton();

They have two parameters.
First param is the button type: polyline, polygon, rectangle, circle, marker, edit, etc.
Second param is the class name to use to show/hide, otherwise it uses 'leaflet-draw-hidden'.

Show or hide all buttons

drawControl.hideButton();
drawControl.showButton();
drawControl.hideButton(undefined, 'hidden');
drawControl.showButton(undefined, 'hidden');

Show or hide one buttons

drawControl.hideButton('circle');
drawControl.showButton('circle'));
drawControl.hideButton('circle'), 'hidden');
drawControl.showButton('circle'), 'hidden');

Show or hide more buttons

drawControl.hideButton(['circle', 'marker']);
drawControl.showButton(['circle', 'marker']));
drawControl.hideButton(['circle', 'marker']), 'hidden');
drawControl.showButton(['circle', 'marker']), 'hidden');
eonlepapillon Show/hide buttons (first draft)
Added two public methods to the draw controller.
drawControl.hideButton()
drawControl.showButton()
7184d28
@wuher
wuher commented Feb 26, 2014

Does this completely hide the button, or only disable (gray out)? My use case is to allow user only draw a single rectangle on map. So, after that I would like to disable (gray out) the rectangle button.

@eonlepapillon

It's hides and shows the buttons by css. You can overrules the css rules. Or provide a toggleClass ('hidden' in the example above). Success!

@jacobtoye jacobtoye commented on the diff Mar 10, 2014
src/Control.Draw.js
@@ -86,6 +102,17 @@ L.Control.Draw = L.Control.extend({
this._toolbars[toolbarId].disable();
}
}
+ },
+
+ _toggleButton: function (options) {
+ // loop over the toolbars to find the right buttons
+ for (var toolbarId in this._toolbars) {
+ if (this._toolbars.hasOwnProperty(toolbarId)) {
+ if(this._toolbars[toolbarId].toggleButton){
@jacobtoye
Leaflet member
jacobtoye added a note Mar 10, 2014

is toggleButton meant to be _toggleButton?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ddproxy ddproxy added the enhancement label Mar 7, 2016
@ddproxy ddproxy added this to the 0.4.0 milestone Mar 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.