]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.share.js
Start layers pane
[rails.git] / app / assets / javascripts / leaflet.share.js
1 //= require templates/map/share
2
3 L.Control.Share = L.Control.extend({
4     options: {
5         position: 'topright',
6         title: 'Share'
7     },
8
9     onAdd: function (map) {
10         var className = 'leaflet-control-locate',
11             classNames = className + ' leaflet-control-zoom leaflet-bar leaflet-control',
12             container = L.DomUtil.create('div', classNames);
13
14         var self = this;
15         this._layer = new L.LayerGroup();
16         this._layer.addTo(map);
17         this._event = undefined;
18
19         var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', container);
20         link.href = '#';
21         link.title = this.options.title;
22
23         this._uiPane = L.DomUtil.create('div', 'leaflet-map-ui', map._container);
24
25         L.DomEvent
26             .on(link, 'click', L.DomEvent.stopPropagation)
27             .on(link, 'click', L.DomEvent.preventDefault)
28             .on(link, 'click', this.toggle, this)
29             .on(link, 'dblclick', L.DomEvent.stopPropagation);
30
31         return container;
32     },
33
34     toggle: function() {
35         var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
36
37         if ($(this._uiPane).is(':visible')) {
38             $(this._uiPane).hide();
39             controlContainer.css({paddingRight: '0'});
40         } else {
41             $(this._uiPane)
42                 .show()
43                 .html(JST["templates/map/share"]());
44             controlContainer.css({paddingRight: '200px'});
45         }
46     }
47 });
48
49 L.control.share = function(options) {
50     return new L.Control.Share(options);
51 };