@@ -57,6 +57,7 @@ Ext.define('GeoExt.tree.LayerNode', {
57
57
"visibilitychanged" : this . onLayerVisibilityChanged ,
58
58
scope : this
59
59
} ) ;
60
+ this . enforceOneVisible ( ) ;
60
61
} ,
61
62
62
63
/**
@@ -109,6 +110,33 @@ Ext.define('GeoExt.tree.LayerNode', {
109
110
}
110
111
delete node . _visibilityChanging ;
111
112
}
113
+ this . enforceOneVisible ( ) ;
114
+ } ,
115
+
116
+ enforceOneVisible : function ( ) {
117
+ var attributes = this . target . data ;
118
+ var group = attributes . checkedGroup ;
119
+ // If we are in the baselayer group, the map will take care of
120
+ // enforcing visibility.
121
+ if ( group && group !== "gx_baselayer" ) {
122
+ var layer = this . target . get ( 'layer' ) ;
123
+ var checkedNodes = this . target . getOwnerTree ( ) . getChecked ( ) ;
124
+ var checkedCount = 0 ;
125
+ // enforce "not more than one visible"
126
+ Ext . each ( checkedNodes , function ( n ) {
127
+ var l = n . data . layer ;
128
+ if ( ! n . data . hidden && n . data . checkedGroup === group ) {
129
+ checkedCount ++ ;
130
+ if ( l != layer && attributes . checked ) {
131
+ l . setVisibility ( false ) ;
132
+ }
133
+ }
134
+ } ) ;
135
+ // enforce "at least one visible"
136
+ if ( checkedCount === 0 && attributes . checked == false ) {
137
+ layer . setVisibility ( true ) ;
138
+ }
139
+ }
112
140
}
113
141
114
142
} ) ;
0 commit comments