@@ -496,6 +496,30 @@ function preventUnintendedZoomOnScroll(map) {
496
496
} ) ;
497
497
}
498
498
499
+ function setupShowHideGroupsOnZoom ( map ) {
500
+ function setVisibility ( layer , visible ) {
501
+ if ( visible !== map . hasLayer ( layer ) ) {
502
+ if ( visible ) map . addLayer ( layer ) ; else map . removeLayer ( layer ) ;
503
+ }
504
+ }
505
+
506
+ function showHideGroupsOnZoom ( ) {
507
+ if ( ! map . layerManager ) return ;
508
+
509
+ var zoom = map . getZoom ( ) ;
510
+ map . layerManager . getAllGroupNames ( ) . forEach ( function ( group ) {
511
+ var layer = map . layerManager . getLayerGroup ( group , false ) ;
512
+ if ( layer && typeof layer . zoomLevels !== "undefined" ) {
513
+ setVisibility ( layer , layer . zoomLevels === true || layer . zoomLevels . indexOf ( zoom ) >= 0 ) ;
514
+ }
515
+ } ) ;
516
+ }
517
+
518
+ map . showHideGroupsOnZoom = showHideGroupsOnZoom ;
519
+ map . on ( "zoomend" , showHideGroupsOnZoom ) ;
520
+ showHideGroupsOnZoom ( ) ;
521
+ }
522
+
499
523
_htmlwidgets2 . default . widget ( {
500
524
501
525
name : "leaflet" ,
@@ -534,6 +558,7 @@ _htmlwidgets2.default.widget({
534
558
}
535
559
536
560
preventUnintendedZoomOnScroll ( map ) ;
561
+ setupShowHideGroupsOnZoom ( map ) ;
537
562
538
563
// Store some state in the map object
539
564
map . leafletr = {
@@ -1023,6 +1048,15 @@ var LayerManager = function () {
1023
1048
} ) ;
1024
1049
return result ;
1025
1050
}
1051
+ } , {
1052
+ key : "getAllGroupNames" ,
1053
+ value : function getAllGroupNames ( ) {
1054
+ var result = [ ] ;
1055
+ _jquery2 . default . each ( this . _groupContainers , function ( k , v ) {
1056
+ result . push ( k ) ;
1057
+ } ) ;
1058
+ return result ;
1059
+ }
1026
1060
} , {
1027
1061
key : "clearGroup" ,
1028
1062
value : function clearGroup ( group ) {
@@ -1930,6 +1964,18 @@ methods.showGroup = function (group) {
1930
1964
} ) ;
1931
1965
} ;
1932
1966
1967
+ methods . setGroupOptions = function ( group , options ) {
1968
+ var _this8 = this ;
1969
+
1970
+ _jquery2 . default . each ( ( 0 , _util . asArray ) ( group ) , function ( i , g ) {
1971
+ var layer = _this8 . layerManager . getLayerGroup ( g , true ) ;
1972
+ if ( options . zoomLevels ) {
1973
+ layer . zoomLevels = options . zoomLevels ;
1974
+ }
1975
+ } ) ;
1976
+ this . showHideGroupsOnZoom ( ) ;
1977
+ } ;
1978
+
1933
1979
methods . addRasterImage = function ( uri , bounds , opacity , attribution , layerId , group ) {
1934
1980
// uri is a data URI containing an image. We want to paint this image as a
1935
1981
// layer at (top-left) bounds[0] to (bottom-right) bounds[1].
@@ -2213,7 +2259,7 @@ methods.removeMeasure = function () {
2213
2259
} ;
2214
2260
2215
2261
methods . addSelect = function ( ctGroup ) {
2216
- var _this8 = this ;
2262
+ var _this9 = this ;
2217
2263
2218
2264
methods . removeSelect . call ( this ) ;
2219
2265
@@ -2224,42 +2270,42 @@ methods.addSelect = function (ctGroup) {
2224
2270
title : "Make a selection" ,
2225
2271
onClick : function onClick ( btn , map ) {
2226
2272
btn . state ( "select-active" ) ;
2227
- _this8 . _locationFilter = new _leaflet2 . default . LocationFilter2 ( ) ;
2273
+ _this9 . _locationFilter = new _leaflet2 . default . LocationFilter2 ( ) ;
2228
2274
2229
2275
if ( ctGroup ) {
2230
2276
( function ( ) {
2231
2277
var selectionHandle = new global . crosstalk . SelectionHandle ( ctGroup ) ;
2232
2278
selectionHandle . on ( "change" , function ( e ) {
2233
2279
if ( e . sender !== selectionHandle ) {
2234
- if ( _this8 . _locationFilter ) {
2235
- _this8 . _locationFilter . disable ( ) ;
2280
+ if ( _this9 . _locationFilter ) {
2281
+ _this9 . _locationFilter . disable ( ) ;
2236
2282
btn . state ( "select-inactive" ) ;
2237
2283
}
2238
2284
}
2239
2285
} ) ;
2240
2286
var handler = function handler ( e ) {
2241
- _this8 . layerManager . brush ( _this8 . _locationFilter . getBounds ( ) , { sender : selectionHandle } ) ;
2287
+ _this9 . layerManager . brush ( _this9 . _locationFilter . getBounds ( ) , { sender : selectionHandle } ) ;
2242
2288
} ;
2243
- _this8 . _locationFilter . on ( "enabled" , handler ) ;
2244
- _this8 . _locationFilter . on ( "change" , handler ) ;
2245
- _this8 . _locationFilter . on ( "disabled" , function ( ) {
2289
+ _this9 . _locationFilter . on ( "enabled" , handler ) ;
2290
+ _this9 . _locationFilter . on ( "change" , handler ) ;
2291
+ _this9 . _locationFilter . on ( "disabled" , function ( ) {
2246
2292
selectionHandle . close ( ) ;
2247
- _this8 . _locationFilter = null ;
2293
+ _this9 . _locationFilter = null ;
2248
2294
} ) ;
2249
2295
} ) ( ) ;
2250
2296
}
2251
2297
2252
- _this8 . _locationFilter . addTo ( map ) ;
2298
+ _this9 . _locationFilter . addTo ( map ) ;
2253
2299
}
2254
2300
} , {
2255
2301
stateName : "select-active" ,
2256
2302
icon : "ion-close-round" ,
2257
2303
title : "Dismiss selection" ,
2258
2304
onClick : function onClick ( btn , map ) {
2259
2305
btn . state ( "select-inactive" ) ;
2260
- _this8 . _locationFilter . disable ( ) ;
2306
+ _this9 . _locationFilter . disable ( ) ;
2261
2307
// If explicitly dismissed, clear the crosstalk selections
2262
- _this8 . layerManager . unbrush ( ) ;
2308
+ _this9 . layerManager . unbrush ( ) ;
2263
2309
}
2264
2310
} ]
2265
2311
} ) ;
0 commit comments