]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.note.js
starting to cleanup+style map controls.
[rails.git] / app / assets / javascripts / leaflet.note.js
1 L.Control.Note = L.Control.extend({
2     options: {
3         position: 'topright',
4         title: 'Notes',
5     },
6
7     onAdd: function (map) {
8         var className = 'control-note',
9             container = L.DomUtil.create('div', className);
10
11         var link = L.DomUtil.create('a', 'control-button', container);
12         link.innerHTML = "<span class='icon note'></span>";
13         link.href = '#';
14         link.title = this.options.title;
15
16         L.DomEvent
17             .on(link, 'click', L.DomEvent.stopPropagation)
18             .on(link, 'click', L.DomEvent.preventDefault)
19             .on(link, 'click', this._toggle, this)
20             .on(link, 'dblclick', L.DomEvent.stopPropagation);
21
22         this.map = map;
23
24         return container;
25     },
26
27     // TODO: this relies on notesLayer on the map
28     _toggle: function() {
29         if (this.map.hasLayer(this.map.noteLayer)) {
30             this.map.removeLayer(this.map.noteLayer);
31         } else {
32             this.map.addLayer(this.map.noteLayer);
33         }
34     }
35 });
36
37 L.control.note = function(options) {
38     return new L.Control.Note(options);
39 };