+ if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
+ var overlaySection = $('<div>')
+ .attr('class', 'section overlay-layers')
+ .appendTo($ui);
+
+ $('<p>')
+ .text(I18n.t('javascripts.map.layers.overlays'))
+ .attr("class", "deemphasize")
+ .appendTo(overlaySection);
+
+ var list = $('<ul>')
+ .appendTo(overlaySection);
+
+ function addOverlay(layer, name, maxArea) {
+ var refName = name.split(' ').join('_').toLowerCase();
+ var item = $('<li>')
+ .attr('class', refName)
+ .tooltip({
+ placement: 'top'
+ })
+ .appendTo(list);
+
+ var label = $('<label>')
+ .appendTo(item);
+
+ var checked = map.hasLayer(layer);
+
+ var input = $('<input>')
+ .attr('type', 'checkbox')
+ .prop('checked', checked)
+ .appendTo(label);
+
+ label.append(name);
+
+ input.on('change', function() {
+ checked = input.is(':checked');
+ if (checked) {
+ map.addLayer(layer);
+ } else {
+ map.removeLayer(layer);
+ }
+ map.fire('overlaylayerchange', {layer: layer});
+ });
+
+ map.on('layeradd layerremove', function() {
+ input.prop('checked', map.hasLayer(layer));
+ });
+
+ map.on('zoomend', function() {
+ var disabled = map.getBounds().getSize() >= maxArea;
+ $(input).prop('disabled', disabled);
+
+ if (disabled && $(input).is(':checked')) {
+ $(input).prop('checked', false)
+ .trigger('change');
+ checked = true;
+ } else if (!disabled && !$(input).is(':checked') && checked) {
+ $(input).prop('checked', true)
+ .trigger('change');
+ }
+
+ layer.fire('statechange', {disabled: disabled, checked: checked});
+
+ $(item).attr('class', disabled ? 'disabled' : '');
+ item.attr('data-original-title', disabled ?
+ I18n.t('javascripts.site.' + refName + '_zoom_in_tooltip') : '');
+ });
+ }
+
+ addOverlay(map.noteLayer, I18n.t('javascripts.map.layers.notes'), OSM.MAX_NOTE_REQUEST_AREA);
+ addOverlay(map.dataLayer, I18n.t('javascripts.map.layers.data'), OSM.MAX_REQUEST_AREA);
+ }
+