move portal level layer enable/disable out of status bar code into a map.on(zoomend) event instead

This commit is contained in:
Jon Atkins 2014-03-19 04:44:20 +00:00
parent 584b8bcd72
commit 4dd944a642
2 changed files with 18 additions and 9 deletions

View File

@ -78,6 +78,21 @@ window.setupLayerChooserStatusRecorder = function() {
}); });
} }
window.layerChooserSetDisabledStates = function() {
// layer selector - enable/disable layers that aren't visible due to zoom level
var minlvl = getMinPortalLevel();
var portalSelection = $('.leaflet-control-layers-overlays label');
//it's an array - 0=unclaimed, 1=lvl 1, 2=lvl 2, ..., 8=lvl 8 - 9 relevant entries
//mark all levels below (but not at) minlvl as disabled
portalSelection.slice(0, minlvl).addClass('disabled').attr('title', 'Zoom in to show those.');
//and all from minlvl to 8 as enabled
portalSelection.slice(minlvl, 8+1).removeClass('disabled').attr('title', '');
//TODO? some generic mechanism where other layers can have their disabled state marked on/off? a few
//plugins have code to do it by hand already
}
window.setupStyles = function() { window.setupStyles = function() {
$('head').append('<style>' + $('head').append('<style>' +
[ '#largepreview.enl img { border:2px solid '+COLORS[TEAM_ENL]+'; } ', [ '#largepreview.enl img { border:2px solid '+COLORS[TEAM_ENL]+'; } ',
@ -279,6 +294,9 @@ window.setupMap = function() {
map.on('movestart', function() { window.mapRunsUserAction = true; window.requests.abort(); window.startRefreshTimeout(-1); }); map.on('movestart', function() { window.mapRunsUserAction = true; window.requests.abort(); window.startRefreshTimeout(-1); });
map.on('moveend', function() { window.mapRunsUserAction = false; window.startRefreshTimeout(ON_MOVE_REFRESH*1000); }); map.on('moveend', function() { window.mapRunsUserAction = false; window.startRefreshTimeout(ON_MOVE_REFRESH*1000); });
map.on('zoomend', function() { window.layerChooserSetDisabledStates(); });
window.layerChooserSetDisabledStates();
// on zoomend, check to see the zoom level is an int, and reset the view if not // on zoomend, check to see the zoom level is an int, and reset the view if not
// (there's a bug on mobile where zoom levels sometimes end up as fractional levels. this causes the base map to be invisible) // (there's a bug on mobile where zoom levels sometimes end up as fractional levels. this causes the base map to be invisible)
map.on('zoomend', function() { map.on('zoomend', function() {

View File

@ -71,15 +71,6 @@ window.renderUpdateStatus = function() {
if (window.failedRequestCount > 0) if (window.failedRequestCount > 0)
t += ' <span style="color:#f66">' + window.failedRequestCount + ' failed</span>' t += ' <span style="color:#f66">' + window.failedRequestCount + ' failed</span>'
// layer selector - enable/disable layers that aren't visible due to zoom level
//FIXME! move this somewhere more suitable!
var portalSelection = $('.leaflet-control-layers-overlays label');
//it's an array - 0=unclaimed, 1=lvl 1, 2=lvl 2, ..., 8=lvl 8 - 9 relevant entries
//mark all levels below (but not at) minlvl as disabled
portalSelection.slice(0, minlvl).addClass('disabled').attr('title', 'Zoom in to show those.');
//and all from minlvl to 8 as enabled
portalSelection.slice(minlvl, 8+1).removeClass('disabled').attr('title', '');
$('#innerstatus').html(t); $('#innerstatus').html(t);