Add hidebydefault option for regions layers

This commit is contained in:
Mike Primm 2011-08-26 00:13:03 -05:00
parent c6cccf6899
commit aee7ea2d49
3 changed files with 30 additions and 9 deletions

View File

@ -91,6 +91,8 @@ components:
# customstyle:
# homebase:
# strokeColor: "#00FF00"
# # Optional - make layer hidden by default
# hidebydefault: true
#- class: org.dynmap.regions.RegionsComponent
# type: regions
@ -122,6 +124,8 @@ components:
# groupstyle:
# homebase:
# strokeColor: "#007F00"
# # Optional - make layer hidden by default
# hidebydefault: true
#- class: org.dynmap.regions.RegionsComponent
# type: regions
@ -150,6 +154,8 @@ components:
# groupstyle:
# MyNation:
# strokeColor: "#007F00"
# # Optional - make layer hidden by default
# hidebydefault: true
#- class: org.dynmap.TestComponent
# stuff: "This is some configuration-value"

View File

@ -35,6 +35,14 @@
font-weight: bold;
}
.leaflet-control-layers {
background-color: #bbb;
}
.leaflet-control-layers:hover {
background-color: #fff;
}
.leaflet-control-zoom-in {
background-color: #eee;
}

View File

@ -162,12 +162,10 @@ componentconstructors['regions'] = function(dynmap, configuration) {
loadcss('css/regions.css');
var regionType = configuration.name;
loadjs('js/regions_' + regionType + '.js', function() {
var activeLayer = undefined;
configuration.activeLayer = undefined;
function undraw() {
if (activeLayer) {
dynmap.layercontrol.removeLayer(activeLayer);
dynmap.map.removeLayer(activeLayer);
activeLayer = undefined;
if (configuration.activeLayer) {
configuration.activeLayer.clearLayers();
}
}
function redraw() {
@ -182,15 +180,24 @@ componentconstructors['regions'] = function(dynmap, configuration) {
createOutlineLayer: configuration.use3dregions ? create3DOutlineLayer : create2DOutlineLayer,
getStyle: getStyle,
result: function(regionsLayer) {
activeLayer = regionsLayer;
dynmap.map.addLayer(activeLayer);
dynmap.layercontrol.addOverlay(activeLayer, regionType);
if(configuration.activeLayer) { /* Not first time */
for(var i in regionsLayer._layers) {
configuration.activeLayer.addLayer(regionsLayer._layers[i]);
}
regionsLayer.clearLayers();
}
else {
configuration.activeLayer = regionsLayer;
if(!configuration.hidebydefault)
dynmap.map.addLayer(configuration.activeLayer);
dynmap.layercontrol.addOverlay(configuration.activeLayer, regionType);
}
}
}));
}
}
$(dynmap).bind('mapchanged', redraw);
$(dynmap).bind('mapchanging', undraw);
redraw();
redraw(true);
});
}