From c353d9aae6e1f599172d712a90bf35a81227a79e Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 26 Aug 2011 13:13:03 +0800 Subject: [PATCH] Add hidebydefault option for regions layers --- src/main/resources/configuration.txt | 6 ++++++ web/css/dynmap_style.css | 8 ++++++++ web/js/regions.js | 25 ++++++++++++++++--------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index 6ea8aa54..c5f218a9 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -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" diff --git a/web/css/dynmap_style.css b/web/css/dynmap_style.css index c702a54a..2f7b9aa3 100644 --- a/web/css/dynmap_style.css +++ b/web/css/dynmap_style.css @@ -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; } diff --git a/web/js/regions.js b/web/js/regions.js index e3ea82fe..5e45f49f 100644 --- a/web/js/regions.js +++ b/web/js/regions.js @@ -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); }); } \ No newline at end of file