@@ -1023,6 +1023,15 @@ var LayerManager = function () {
1023
1023
} ) ;
1024
1024
return result ;
1025
1025
}
1026
+ } , {
1027
+ key : "getAllGroupNames" ,
1028
+ value : function getAllGroupNames ( ) {
1029
+ var result = [ ] ;
1030
+ _jquery2 . default . each ( this . _groupContainers , function ( k , v ) {
1031
+ result . push ( k ) ;
1032
+ } ) ;
1033
+ return result ;
1034
+ }
1026
1035
} , {
1027
1036
key : "clearGroup" ,
1028
1037
value : function clearGroup ( group ) {
@@ -1930,6 +1939,49 @@ methods.showGroup = function (group) {
1930
1939
} ) ;
1931
1940
} ;
1932
1941
1942
+ function setupShowHideGroupsOnZoom ( map ) {
1943
+ if ( map . leafletr . _hasInitializedShowHideGroups ) {
1944
+ return ;
1945
+ }
1946
+ map . leafletr . _hasInitializedShowHideGroups = true ;
1947
+
1948
+ function setVisibility ( layer , visible ) {
1949
+ if ( visible !== map . hasLayer ( layer ) ) {
1950
+ if ( visible ) map . addLayer ( layer ) ; else map . removeLayer ( layer ) ;
1951
+ }
1952
+ }
1953
+
1954
+ function showHideGroupsOnZoom ( ) {
1955
+ if ( ! map . layerManager ) return ;
1956
+
1957
+ var zoom = map . getZoom ( ) ;
1958
+ map . layerManager . getAllGroupNames ( ) . forEach ( function ( group ) {
1959
+ var layer = map . layerManager . getLayerGroup ( group , false ) ;
1960
+ if ( layer && typeof layer . zoomLevels !== "undefined" ) {
1961
+ setVisibility ( layer , layer . zoomLevels === true || layer . zoomLevels . indexOf ( zoom ) >= 0 ) ;
1962
+ }
1963
+ } ) ;
1964
+ }
1965
+
1966
+ map . showHideGroupsOnZoom = showHideGroupsOnZoom ;
1967
+ map . on ( "zoomend" , showHideGroupsOnZoom ) ;
1968
+ }
1969
+
1970
+ methods . setGroupOptions = function ( group , options ) {
1971
+ var _this8 = this ;
1972
+
1973
+ _jquery2 . default . each ( ( 0 , _util . asArray ) ( group ) , function ( i , g ) {
1974
+ var layer = _this8 . layerManager . getLayerGroup ( g , true ) ;
1975
+ // This slightly tortured check is because 0 is a valid value for zoomLevels
1976
+ if ( typeof options . zoomLevels !== "undefined" && options . zoomLevels !== null ) {
1977
+ layer . zoomLevels = ( 0 , _util . asArray ) ( options . zoomLevels ) ;
1978
+ }
1979
+ } ) ;
1980
+
1981
+ setupShowHideGroupsOnZoom ( this ) ;
1982
+ this . showHideGroupsOnZoom ( ) ;
1983
+ } ;
1984
+
1933
1985
methods . addRasterImage = function ( uri , bounds , opacity , attribution , layerId , group ) {
1934
1986
// uri is a data URI containing an image. We want to paint this image as a
1935
1987
// layer at (top-left) bounds[0] to (bottom-right) bounds[1].
@@ -2213,7 +2265,7 @@ methods.removeMeasure = function () {
2213
2265
} ;
2214
2266
2215
2267
methods . addSelect = function ( ctGroup ) {
2216
- var _this8 = this ;
2268
+ var _this9 = this ;
2217
2269
2218
2270
methods . removeSelect . call ( this ) ;
2219
2271
@@ -2224,42 +2276,42 @@ methods.addSelect = function (ctGroup) {
2224
2276
title : "Make a selection" ,
2225
2277
onClick : function onClick ( btn , map ) {
2226
2278
btn . state ( "select-active" ) ;
2227
- _this8 . _locationFilter = new _leaflet2 . default . LocationFilter2 ( ) ;
2279
+ _this9 . _locationFilter = new _leaflet2 . default . LocationFilter2 ( ) ;
2228
2280
2229
2281
if ( ctGroup ) {
2230
2282
( function ( ) {
2231
2283
var selectionHandle = new global . crosstalk . SelectionHandle ( ctGroup ) ;
2232
2284
selectionHandle . on ( "change" , function ( e ) {
2233
2285
if ( e . sender !== selectionHandle ) {
2234
- if ( _this8 . _locationFilter ) {
2235
- _this8 . _locationFilter . disable ( ) ;
2286
+ if ( _this9 . _locationFilter ) {
2287
+ _this9 . _locationFilter . disable ( ) ;
2236
2288
btn . state ( "select-inactive" ) ;
2237
2289
}
2238
2290
}
2239
2291
} ) ;
2240
2292
var handler = function handler ( e ) {
2241
- _this8 . layerManager . brush ( _this8 . _locationFilter . getBounds ( ) , { sender : selectionHandle } ) ;
2293
+ _this9 . layerManager . brush ( _this9 . _locationFilter . getBounds ( ) , { sender : selectionHandle } ) ;
2242
2294
} ;
2243
- _this8 . _locationFilter . on ( "enabled" , handler ) ;
2244
- _this8 . _locationFilter . on ( "change" , handler ) ;
2245
- _this8 . _locationFilter . on ( "disabled" , function ( ) {
2295
+ _this9 . _locationFilter . on ( "enabled" , handler ) ;
2296
+ _this9 . _locationFilter . on ( "change" , handler ) ;
2297
+ _this9 . _locationFilter . on ( "disabled" , function ( ) {
2246
2298
selectionHandle . close ( ) ;
2247
- _this8 . _locationFilter = null ;
2299
+ _this9 . _locationFilter = null ;
2248
2300
} ) ;
2249
2301
} ) ( ) ;
2250
2302
}
2251
2303
2252
- _this8 . _locationFilter . addTo ( map ) ;
2304
+ _this9 . _locationFilter . addTo ( map ) ;
2253
2305
}
2254
2306
} , {
2255
2307
stateName : "select-active" ,
2256
2308
icon : "ion-close-round" ,
2257
2309
title : "Dismiss selection" ,
2258
2310
onClick : function onClick ( btn , map ) {
2259
2311
btn . state ( "select-inactive" ) ;
2260
- _this8 . _locationFilter . disable ( ) ;
2312
+ _this9 . _locationFilter . disable ( ) ;
2261
2313
// If explicitly dismissed, clear the crosstalk selections
2262
- _this8 . layerManager . unbrush ( ) ;
2314
+ _this9 . layerManager . unbrush ( ) ;
2263
2315
}
2264
2316
} ]
2265
2317
} ) ;
0 commit comments