uiPane: uiPane
}).addTo(map);
- L.control.note({
+ L.OSM.note({
position: 'topright',
uiPane: uiPane
}).addTo(map);
- L.control.share({
+ L.OSM.share({
getUrl: getShortUrl,
uiPane: uiPane
}).addTo(map);
-L.OSM.Key = L.Control.extend({
- onAdd: function (map) {
- this._map = map;
- this._initLayout();
- return this.$container[0];
- },
-
- _initLayout: function () {
- var map = this._map;
+L.OSM.key = function(options) {
+ var control = L.control(options);
- this.$container = $('<div>')
+ control.onAdd = function (map) {
+ var $container = $('<div>')
.attr('class', 'control-key');
- var link = $('<a>')
+ $('<a>')
.attr('class', 'control-button')
.attr('href', '#')
.attr('title', 'Map Key')
.html('<span class="icon key"></span>')
- .appendTo(this.$container);
- }
-});
+ .appendTo($container);
-L.OSM.key = function(options) {
- return new L.OSM.Key(options);
+ return $container[0];
+ };
+
+ return control;
};
-L.OSM.Layers = L.Control.extend({
- onAdd: function (map) {
- this._map = map;
- this._initLayout();
- return this.$container[0];
- },
-
- _initLayout: function () {
- var map = this._map,
- layers = this.options.layers;
-
- this.$container = $('<div>')
+L.OSM.layers = function(options) {
+ var control = L.control(options);
+
+ control.onAdd = function (map) {
+ var layers = options.layers;
+
+ var $container = $('<div>')
.attr('class', 'control-layers');
var link = $('<a>')
.attr('href', '#')
.attr('title', 'Layers')
.html('<span class="icon layers"></span>')
- .appendTo(this.$container);
+ .on('click', toggle)
+ .appendTo($container);
- if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
- this.$ui = $('<div>')
- .attr('class', 'layers-ui')
- .appendTo(this.options.uiPane);
+ var $ui = $('<div>')
+ .attr('class', 'layers-ui')
+ .appendTo(options.uiPane);
- $('<h2>')
- .text(I18n.t('javascripts.map.layers.header'))
- .appendTo(this.$ui);
+ $('<h2>')
+ .text(I18n.t('javascripts.map.layers.header'))
+ .appendTo($ui);
+ if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
var overlaySection = $('<section>')
.addClass('overlay-layers')
- .appendTo(this.$ui);
+ .appendTo($ui);
$('<p>')
.text(I18n.t('javascripts.map.layers.overlays'))
var baseSection = $('<section>')
.addClass('base-layers')
- .appendTo(this.$ui);
+ .appendTo($ui);
$('<p>')
.text(I18n.t('javascripts.map.layers.base'))
});
});
- $(link).on('click', $.proxy(this.toggleLayers, this));
- },
+ function toggle(e) {
+ e.stopPropagation();
+ e.preventDefault();
- toggleLayers: function (e) {
- e.stopPropagation();
- e.preventDefault();
+ var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
- var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
+ if ($ui.is(':visible')) {
+ $(control.options.uiPane).hide();
+ controlContainer.css({paddingRight: '0'});
+ } else {
+ $(control.options.uiPane).show();
+ controlContainer.css({paddingRight: '230px'});
+ }
- if (this.$ui.is(':visible')) {
- $(this.options.uiPane).hide();
- controlContainer.css({paddingRight: '0'});
- } else {
- $(this.options.uiPane).show();
- controlContainer.css({paddingRight: '230px'});
+ $ui.find('.base-layers .leaflet-container').each(function() {
+ $(this).data('map').invalidateSize();
+ });
}
- this.$ui.find('.base-layers .leaflet-container').each(function() {
- $(this).data('map').invalidateSize();
- });
- }
-});
+ return $container[0];
+ };
-L.OSM.layers = function(options) {
- return new L.OSM.Layers(options);
+ return control;
};
-L.Control.Note = L.Control.extend({
- options: {
- position: 'topright',
- title: 'Notes',
- },
+L.OSM.note = function (options) {
+ var control = L.control(options);
- onAdd: function (map) {
- var className = 'control-note',
- container = L.DomUtil.create('div', className);
+ control.onAdd = function (map) {
+ var $container = $('<div>')
+ .attr('class', 'control-note');
- var link = L.DomUtil.create('a', 'control-button', container);
- link.innerHTML = "<span class='icon note'></span>";
- link.href = '#';
- link.title = this.options.title;
+ $('<a>')
+ .attr('class', 'control-button')
+ .attr('href', '#')
+ .attr('title', 'Notes')
+ .html('<span class="icon note"></span>')
+ .on('click', toggle)
+ .appendTo($container);
- L.DomEvent
- .on(link, 'click', L.DomEvent.stopPropagation)
- .on(link, 'click', L.DomEvent.preventDefault)
- .on(link, 'click', this._toggle, this)
- .on(link, 'dblclick', L.DomEvent.stopPropagation);
+ function toggle(e) {
+ e.stopPropagation();
+ e.preventDefault();
- this.map = map;
-
- return container;
- },
-
- // TODO: this relies on notesLayer on the map
- _toggle: function() {
- if (this.map.hasLayer(this.map.noteLayer)) {
- this.map.removeLayer(this.map.noteLayer);
- } else {
- this.map.addLayer(this.map.noteLayer);
- }
+ if (map.hasLayer(map.noteLayer)) {
+ map.removeLayer(map.noteLayer);
+ } else {
+ map.addLayer(map.noteLayer);
+ }
}
-});
-L.control.note = function(options) {
- return new L.Control.Note(options);
+ return $container[0];
+ };
+
+ return control;
};
-L.Control.Share = L.Control.extend({
- options: {
- position: 'topright',
- title: 'Share',
- url: function(map) {
- return '';
- }
- },
-
- onAdd: function (map) {
- var className = 'control-share',
- container = L.DomUtil.create('div', className);
-
- var link = L.DomUtil.create('a', 'control-button', container);
- link.innerHTML = "<span class='icon share'></span>";
- link.href = '#';
- link.title = this.options.title;
-
- this._uiPane = this.options.uiPane;
-
- this._map = map;
-
- var h2 = L.DomUtil.create('h2', '', this._uiPane);
- h2.innerHTML = I18n.t('javascripts.share.title');
-
- this._linkInput = L.DomUtil.create('input', '', this._uiPane);
-
- L.DomEvent
- .on(link, 'click', L.DomEvent.stopPropagation)
- .on(link, 'click', L.DomEvent.preventDefault)
- .on(link, 'click', this._toggle, this)
- .on(link, 'dblclick', L.DomEvent.stopPropagation);
-
- map.on('moveend layeradd layerremove', this._update, this);
-
- return container;
- },
-
- _update: function (e) {
- var center = this._map.getCenter().wrap();
- var layers = getMapLayers(this._map);
- this._linkInput.value = this.options.getUrl(this._map);
- },
-
- _toggle: function() {
- var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
-
- if ($(this._uiPane).is(':visible')) {
- $(this._uiPane).hide();
- controlContainer.css({paddingRight: '0'});
- } else {
- $(this._uiPane).show();
- controlContainer.css({paddingRight: '200px'});
- }
+L.OSM.share = function (options) {
+ var control = L.control(options);
+
+ control.onAdd = function (map) {
+ var $container = $('<div>')
+ .attr('class', 'control-share');
+
+ $('<a>')
+ .attr('class', 'control-button')
+ .attr('href', '#')
+ .attr('title', 'Share')
+ .html('<span class="icon share"></span>')
+ .on('click', toggle)
+ .appendTo($container);
+
+ var $ui = $('<div>')
+ .attr('class', 'share-ui')
+ .appendTo(options.uiPane);
+
+ $('<h2>')
+ .text(I18n.t('javascripts.share.title'))
+ .appendTo($ui);
+
+ var $input = $('<input>')
+ .appendTo($ui);
+
+ map.on('moveend layeradd layerremove', update);
+
+ function toggle(e) {
+ e.stopPropagation();
+ e.preventDefault();
+
+ var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
+
+ if ($ui.is(':visible')) {
+ $(control.options.uiPane).hide();
+ controlContainer.css({paddingRight: '0'});
+ } else {
+ $(control.options.uiPane).show();
+ controlContainer.css({paddingRight: '200px'});
+ }
}
-});
-L.control.share = function(options) {
- return new L.Control.Share(options);
+ function update() {
+ var center = map.getCenter().wrap();
+ var layers = getMapLayers(map);
+ $input.val(options.getUrl(map));
+ }
+
+ return $container[0];
+ };
+
+ return control;
};