]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.share.js
generate short link kind of
[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         url: function(map) {
8             return '';
9         }
10     },
11
12     onAdd: function (map) {
13         var className = 'leaflet-control-locate',
14             classNames = className + ' leaflet-control-zoom leaflet-bar leaflet-control',
15             container = L.DomUtil.create('div', classNames);
16
17         var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', container);
18         link.href = '#';
19         link.title = this.options.title;
20
21         this._uiPane = L.DomUtil.create('div', 'leaflet-map-ui', map._container);
22         this._linkInput = L.DomUtil.create('input', '', this._uiPane);
23
24         L.DomEvent
25             .on(link, 'click', L.DomEvent.stopPropagation)
26             .on(link, 'click', L.DomEvent.preventDefault)
27             .on(link, 'click', this._toggle, this)
28             .on(link, 'dblclick', L.DomEvent.stopPropagation);
29
30         map.on('moveend layeradd layerremove', this._update, this);
31
32         return container;
33     },
34
35     _update: function (e) {
36         var center = map.getCenter().wrap();
37         var layers = getMapLayers();
38         this._linkInput.value = this.options.getUrl(map);
39     },
40
41     _toggle: function() {
42         var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
43
44         if ($(this._uiPane).is(':visible')) {
45             $(this._uiPane).hide();
46             controlContainer.css({paddingRight: '0'});
47         } else {
48             $(this._uiPane).show();
49             controlContainer.css({paddingRight: '200px'});
50         }
51     }
52 });
53
54 L.control.share = function(options) {
55     return new L.Control.Share(options);
56 };