tileDebug.map = map;
tileDebug.mapParams = mapParams;
tileDebug.layerParams = layerParams;
tileDebug.osmLayer = osmLayer;
function change_controls(evt) {
var ctl = $(evt.target),
param = ctl.attr('param-name'),
value = ctl.val();
if (ctl.is('[type="checkbox"]')) {
value = ctl.is(':checked') ? 'true' : 'false';
}
if (value === '' && ctl.attr('placeholder')) {
value = ctl.attr('placeholder');
}
if (!param || value === query[param]) {
return;
}
var processedValue = (ctl.is('[type="checkbox"]') ?
(value === 'true') : value);
switch (param) {
case 'allowRotation':
mapParams.allowRotation = get_allow_rotation(value);
map.allowRotation(mapParams.allowRotation);
break;
case 'animateZoom':
map.interactor().options(
value === 'true' ? zoomAnimationEnabled : zoomAnimationDisabled);
break;
case 'debug':
$('#map').toggleClass('debug-label', (
value === 'true' || value === 'all'))
.toggleClass('debug-border', (
value === 'border' || value === 'all'));
break;
case 'discrete':
mapParams.discreteZoom = processedValue;
map.discreteZoom(processedValue);
break;
case 'fade':
$('#map').toggleClass('fade-image', processedValue);
break;
case 'lower':
layerParams.keepLower = (value === 'true');
break;
case 'max': case 'min':
mapParams[param] = parseFloat(value);
map.zoomRange(mapParams);
break;
case 'projection':
map.camera().projection = value;
break;
case 'renderer':
layerParams[param] = value;
if (layerParams.renderer === 'html') {
layerParams.renderer = null;
}
if (layerParams.renderer === 'default') {
layerParams.renderer = undefined;
}
map.deleteLayer(osmLayer);
osmLayer = map.createLayer('osm', layerParams);
tileDebug.osmLayer = osmLayer;
break;
case 'round':
layerParams.tileRounding = Math[value];
break;
case 'spring':
map.interactor().options(
value === 'true' ? springEnabled : springDisabled);
break;
case 'url':
var url = processedValue;
layerParams[param] = processedValue;
if (url.indexOf('/') >= 0) {
osmLayer.url(url);
osmLayer._options.maxLevel = query.maxLevel ? parseInt(query.maxLevel, 10) : 25;
osmLayer._options.minLevel = query.minLevel ? parseInt(query.minLevel, 10) : 0;
} else {
osmLayer.source(url);
}
break;
case 'x': case 'y':
var coord = map.center();
coord[param] = mapParams[param] = parseFloat(value);
map.center(coord);
break;
case 'zoom':
mapParams[param] = processedValue = parseFloat(value);
map.zoom(processedValue);
break;
default:
if (ctl.is('.layerparam')) {
layerParams[param] = processedValue;
if (osmLayer[param]) {
osmLayer[param](processedValue);
}
} else if (ctl.is('.mapparam')) {
mapParams[param] = processedValue;
if (map[param]) {
map[param](processedValue);
}
} else {
return;
}
break;
}
if (ctl.is('.layerparam,.cameraparam') && ctl.attr('reload') === 'true') {
map.deleteLayer(osmLayer);
osmLayer = map.createLayer('osm', layerParams);
tileDebug.osmLayer = osmLayer;
}