├── LICENSE ├── README.md └── L.Control.Button.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Jerroyd Moore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | leaflet-button 2 | ============== 3 | 4 | A simple button control for the [Leaflet](http://leafletjs.com) map framework 5 | 6 | 7 | ## Options 8 | The button can be configured with these options 9 | - **position**: the position of the button. Valid positions are the normal positions for leaflet controls: `topright`, 10 | `topleft`, `bottomright`, and `bottomleft`. 11 | - **className**: additional css classes you wish to add to the button. 12 | - **toggleButton**: Turns the button into a toggle button. The value of toggleButton will be the css Class that is toggled on and off. 13 | 14 | ## A Simple Example 15 | 16 | ```javascript 17 | var button = new L.Control.Button('Click me'); 18 | button.addTo(map); 19 | button.on('click', function () { 20 | alert('you clicked the button!'); 21 | }); 22 | ``` 23 | 24 | ## Adding a Toggle button 25 | Setting the option `toggleButton` will turn button into a toggle button. The value you set `toggleButton` 26 | is the css class added to the button, so you can style against it. 27 | 28 | In your click handler, you can use the `isToggled()` method to peform conditional actions 29 | ```javascript 30 | var button = new L.Control.Button('Toggle me', { 31 | toggleButton: 'active' 32 | }); 33 | button.addTo(map); 34 | button.on('click', function () { 35 | if (button.isToggled()) { 36 | sidebar.hide(); 37 | } else { 38 | sidebar.show(); 39 | } 40 | }); 41 | ``` 42 | 43 | ## Further Customizing your button 44 | You can use an existing button in your document instead of the default button. 45 | ```html 46 | 47 | ``` 48 | Create a new button using a reference to the existing button: 49 | ```javascript 50 | var button = new L.Control.Button(L.DomUtil.get('helpbutton'), { toggleButton: 'active' }); 51 | button.addTo(map); 52 | button.on('click', function () { 53 | window.location.href = 'http://www.yourdomain.com/help' 54 | }); 55 | ``` 56 | 57 | ## Example of Integrating it with [L.sidebar](https://github.com/Turbo87/leaflet-sidebar) 58 | ```html 59 | 60 |