├── LICENSE ├── README.md ├── leaflet-messagebox.css └── leaflet-messagebox.js /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Martijn Grendelman 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of leaflet-messagebox nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A Leaflet plugin to display a temporary message on a map. 2 | ([Demo](https://www.grendelman.net/leaflet/)) 3 | 4 | # Leaflet.Messagebox 5 | 6 | Leaflet.Messagebox is a simple control to display a temporary message, like an 7 | error, on a [Leaflet](http://leafletjs.com/) map. The message is hidden after 8 | a configurable timeout. 9 | 10 | ## Using the Messagebox 11 | 12 | There a are two ways to add the messagebox to the map. First: 13 | 14 | var options = { timeout: 5000 } 15 | var box = L.control.messagebox(options).addTo(map); 16 | 17 | or, add it on map initialization: 18 | 19 | var map = L.map( 'mapdiv', {'messagebox': true, ...} ); 20 | map.messagebox.options.timeout = 5000; 21 | 22 | Then, show a message/alert: 23 | 24 | box.show( 'This is the message' ); 25 | 26 | or, when implicitly used with the map: 27 | 28 | map.messagebox.show( 'This is the message' ); 29 | 30 | ## Available Options: 31 | 32 | There are only two options: 33 | 34 | `position:` (string) The standard Leaflet.Control position parameter. Optional, defaults to 'topright' 35 | 36 | `timeout:` (integer) The duration the messagebox/notification is shown in milliseconds. Optional, defaults to 3000 (3 sec). 37 | 38 | ## Styling ## 39 | 40 | The messagebox can be styled with CSS, see [the css file]( leaflet-messagebox.css) for details. 41 | 42 | # License 43 | 44 | Leaflet.Messagebox is free software. Please see [LICENSE](LICENSE) for details. 45 | 46 | # Misc 47 | Alternatives names of the plugin: **Leaflet notifications** and **Leaflet alerts** 48 | 49 | -------------------------------------------------------------------------------- /leaflet-messagebox.css: -------------------------------------------------------------------------------- 1 | .leaflet-control-messagebox { 2 | display: none; /* Initially hidden */ 3 | border: 2px solid red; 4 | background-color: white; 5 | padding: 3px 10px; 6 | } 7 | -------------------------------------------------------------------------------- /leaflet-messagebox.js: -------------------------------------------------------------------------------- 1 | L.Control.Messagebox = L.Control.extend({ 2 | options: { 3 | position: 'topright', 4 | timeout: 3000 5 | }, 6 | 7 | onAdd: function (map) { 8 | this._container = L.DomUtil.create('div', 'leaflet-control-messagebox'); 9 | //L.DomEvent.disableClickPropagation(this._container); 10 | return this._container; 11 | }, 12 | 13 | show: function (message, timeout) { 14 | var elem = this._container; 15 | elem.innerHTML = message; 16 | elem.style.display = 'block'; 17 | 18 | timeout = timeout || this.options.timeout; 19 | 20 | if (typeof this.timeoutID == 'number') { 21 | clearTimeout(this.timeoutID); 22 | } 23 | this.timeoutID = setTimeout(function () { 24 | elem.style.display = 'none'; 25 | }, timeout); 26 | } 27 | }); 28 | 29 | L.Map.mergeOptions({ 30 | messagebox: false 31 | }); 32 | 33 | L.Map.addInitHook(function () { 34 | if (this.options.messagebox) { 35 | this.messagebox = new L.Control.Messagebox(); 36 | this.addControl(this.messagebox); 37 | } 38 | }); 39 | 40 | L.control.messagebox = function (options) { 41 | return new L.Control.Messagebox(options); 42 | }; 43 | --------------------------------------------------------------------------------