]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.share.js
Work on layers UI
[rails.git] / app / assets / javascripts / leaflet.share.js
1 L.Control.Share = L.Control.extend({
2     options: {
3         position: 'topright',
4         title: 'Share',
5         url: function(map) {
6             return '';
7         }
8     },
9
10     onAdd: function (map) {
11         var className = 'control-share',
12             container = L.DomUtil.create('div', className);
13
14         var link = L.DomUtil.create('a', 'control-button', container);
15         link.innerHTML = "<span class='icon share'></span>";
16         link.href = '#';
17         link.title = this.options.title;
18
19         this._uiPane = this.options.uiPane;
20
21         var h2 = L.DomUtil.create('h2', '', this._uiPane);
22         h2.innerHTML = I18n.t('javascripts.share.title');
23
24         this._linkInput = L.DomUtil.create('input', '', this._uiPane);
25
26         L.DomEvent
27             .on(link, 'click', L.DomEvent.stopPropagation)
28             .on(link, 'click', L.DomEvent.preventDefault)
29             .on(link, 'click', this._toggle, this)
30             .on(link, 'dblclick', L.DomEvent.stopPropagation);
31
32         map.on('moveend layeradd layerremove', this._update, this);
33
34         return container;
35     },
36
37     _update: function (e) {
38         var center = map.getCenter().wrap();
39         var layers = getMapLayers();
40         this._linkInput.value = this.options.getUrl(map);
41     },
42
43     _toggle: function() {
44         var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
45
46         if ($(this._uiPane).is(':visible')) {
47             $(this._uiPane).hide();
48             controlContainer.css({paddingRight: '0'});
49         } else {
50             $(this._uiPane).show();
51             controlContainer.css({paddingRight: '200px'});
52         }
53     }
54 });
55
56 L.control.share = function(options) {
57     return new L.Control.Share(options);
58 };