@@ -1758,6 +1758,8 @@ methods.clearControls = function () {
1758
1758
} ;
1759
1759
1760
1760
methods . addLegend = function ( options ) {
1761
+ var _this5 = this ;
1762
+
1761
1763
var legend = _leaflet2 . default . control ( { position : options . position } ) ;
1762
1764
var gradSpan = void 0 ;
1763
1765
@@ -1856,35 +1858,56 @@ methods.addLegend = function (options) {
1856
1858
return div ;
1857
1859
} ;
1858
1860
1861
+ if ( options . group ) {
1862
+ ( function ( ) {
1863
+ // Auto generate a layerID if not provided
1864
+ if ( ! options . layerId ) {
1865
+ options . layerId = _leaflet2 . default . stamp ( legend ) ;
1866
+ }
1867
+
1868
+ var map = _this5 ;
1869
+ map . on ( "overlayadd" , function ( e ) {
1870
+ if ( e . name === options . group ) {
1871
+ map . controls . add ( legend , options . layerId ) ;
1872
+ }
1873
+ } ) ;
1874
+ map . on ( "overlayremove" , function ( e ) {
1875
+ if ( e . name === options . group ) {
1876
+ map . controls . remove ( options . layerId ) ;
1877
+ }
1878
+ } ) ;
1879
+ } ) ( ) ;
1880
+ }
1881
+
1859
1882
this . controls . add ( legend , options . layerId ) ;
1860
1883
} ;
1861
1884
1862
1885
methods . addLayersControl = function ( baseGroups , overlayGroups , options ) {
1863
- var _this5 = this ;
1886
+ var _this6 = this ;
1864
1887
1865
1888
// Only allow one layers control at a time
1866
1889
methods . removeLayersControl . call ( this ) ;
1867
1890
1868
1891
var firstLayer = true ;
1869
1892
var base = { } ;
1870
1893
_jquery2 . default . each ( ( 0 , _util . asArray ) ( baseGroups ) , function ( i , g ) {
1871
- var layer = _this5 . layerManager . getLayerGroup ( g , true ) ;
1894
+ var layer = _this6 . layerManager . getLayerGroup ( g , true ) ;
1872
1895
if ( layer ) {
1873
1896
base [ g ] = layer ;
1874
1897
1875
1898
// Check if >1 base layers are visible; if so, hide all but the first one
1876
- if ( _this5 . hasLayer ( layer ) ) {
1899
+ if ( _this6 . hasLayer ( layer ) ) {
1877
1900
if ( firstLayer ) {
1878
1901
firstLayer = false ;
1879
1902
} else {
1880
- _this5 . removeLayer ( layer ) ;
1903
+ _this6 . removeLayer ( layer ) ;
1881
1904
}
1882
1905
}
1883
1906
}
1884
1907
} ) ;
1885
1908
var overlay = { } ;
1886
1909
_jquery2 . default . each ( ( 0 , _util . asArray ) ( overlayGroups ) , function ( i , g ) {
1887
- var layer = _this5 . layerManager . getLayerGroup ( g , true ) ;
1910
+ var layer = _this6 . layerManager . getLayerGroup ( g , true ) ;
1888
1911
if ( layer ) {
1889
1912
overlay [ g ] = layer ;
1890
1913
}
@@ -1918,23 +1941,23 @@ methods.removeScaleBar = function () {
1918
1941
} ;
1919
1942
1920
1943
methods . hideGroup = function ( group ) {
1921
- var _this6 = this ;
1944
+ var _this7 = this ;
1922
1945
1923
1946
_jquery2 . default . each ( ( 0 , _util . asArray ) ( group ) , function ( i , g ) {
1924
- var layer = _this6 . layerManager . getLayerGroup ( g , true ) ;
1947
+ var layer = _this7 . layerManager . getLayerGroup ( g , true ) ;
1925
1948
if ( layer ) {
1926
- _this6 . removeLayer ( layer ) ;
1949
+ _this7 . removeLayer ( layer ) ;
1927
1950
}
1928
1951
} ) ;
1929
1952
} ;
1930
1953
1931
1954
methods . showGroup = function ( group ) {
1932
- var _this7 = this ;
1955
+ var _this8 = this ;
1933
1956
1934
1957
_jquery2 . default . each ( ( 0 , _util . asArray ) ( group ) , function ( i , g ) {
1935
- var layer = _this7 . layerManager . getLayerGroup ( g , true ) ;
1958
+ var layer = _this8 . layerManager . getLayerGroup ( g , true ) ;
1936
1959
if ( layer ) {
1937
- _this7 . addLayer ( layer ) ;
1960
+ _this8 . addLayer ( layer ) ;
1938
1961
}
1939
1962
} ) ;
1940
1963
} ;
@@ -1968,10 +1991,10 @@ function setupShowHideGroupsOnZoom(map) {
1968
1991
}
1969
1992
1970
1993
methods . setGroupOptions = function ( group , options ) {
1971
- var _this8 = this ;
1994
+ var _this9 = this ;
1972
1995
1973
1996
_jquery2 . default . each ( ( 0 , _util . asArray ) ( group ) , function ( i , g ) {
1974
- var layer = _this8 . layerManager . getLayerGroup ( g , true ) ;
1997
+ var layer = _this9 . layerManager . getLayerGroup ( g , true ) ;
1975
1998
// This slightly tortured check is because 0 is a valid value for zoomLevels
1976
1999
if ( typeof options . zoomLevels !== "undefined" && options . zoomLevels !== null ) {
1977
2000
layer . zoomLevels = ( 0 , _util . asArray ) ( options . zoomLevels ) ;
@@ -2107,7 +2130,7 @@ methods.addRasterImage = function (uri, bounds, opacity, attribution, layerId, g
2107
2130
canvasTiles . drawTile = function ( canvas , tilePoint , zoom ) {
2108
2131
getImageData ( function ( imgData , w , h , mipmapper ) {
2109
2132
try {
2110
- var _ret7 = function ( ) {
2133
+ var _ret8 = function ( ) {
2111
2134
// The Context2D we'll being drawing onto. It's always 256x256.
2112
2135
var ctx = canvas . getContext ( "2d" ) ;
2113
2136
@@ -2231,7 +2254,7 @@ methods.addRasterImage = function (uri, bounds, opacity, attribution, layerId, g
2231
2254
}
2232
2255
} ( ) ;
2233
2256
2234
- if ( ( typeof _ret7 === "undefined" ? "undefined" : _typeof ( _ret7 ) ) === "object" ) return _ret7 . v ;
2257
+ if ( ( typeof _ret8 === "undefined" ? "undefined" : _typeof ( _ret8 ) ) === "object" ) return _ret8 . v ;
2235
2258
} finally {
2236
2259
canvasTiles . tileDrawn ( canvas ) ;
2237
2260
}
@@ -2265,7 +2288,7 @@ methods.removeMeasure = function () {
2265
2288
} ;
2266
2289
2267
2290
methods . addSelect = function ( ctGroup ) {
2268
- var _this9 = this ;
2291
+ var _this10 = this ;
2269
2292
2270
2293
methods . removeSelect . call ( this ) ;
2271
2294
@@ -2276,42 +2299,42 @@ methods.addSelect = function (ctGroup) {
2276
2299
title : "Make a selection" ,
2277
2300
onClick : function onClick ( btn , map ) {
2278
2301
btn . state ( "select-active" ) ;
2279
- _this9 . _locationFilter = new _leaflet2 . default . LocationFilter2 ( ) ;
2302
+ _this10 . _locationFilter = new _leaflet2 . default . LocationFilter2 ( ) ;
2280
2303
2281
2304
if ( ctGroup ) {
2282
2305
( function ( ) {
2283
2306
var selectionHandle = new global . crosstalk . SelectionHandle ( ctGroup ) ;
2284
2307
selectionHandle . on ( "change" , function ( e ) {
2285
2308
if ( e . sender !== selectionHandle ) {
2286
- if ( _this9 . _locationFilter ) {
2287
- _this9 . _locationFilter . disable ( ) ;
2309
+ if ( _this10 . _locationFilter ) {
2310
+ _this10 . _locationFilter . disable ( ) ;
2288
2311
btn . state ( "select-inactive" ) ;
2289
2312
}
2290
2313
}
2291
2314
} ) ;
2292
2315
var handler = function handler ( e ) {
2293
- _this9 . layerManager . brush ( _this9 . _locationFilter . getBounds ( ) , { sender : selectionHandle } ) ;
2316
+ _this10 . layerManager . brush ( _this10 . _locationFilter . getBounds ( ) , { sender : selectionHandle } ) ;
2294
2317
} ;
2295
- _this9 . _locationFilter . on ( "enabled" , handler ) ;
2296
- _this9 . _locationFilter . on ( "change" , handler ) ;
2297
- _this9 . _locationFilter . on ( "disabled" , function ( ) {
2318
+ _this10 . _locationFilter . on ( "enabled" , handler ) ;
2319
+ _this10 . _locationFilter . on ( "change" , handler ) ;
2320
+ _this10 . _locationFilter . on ( "disabled" , function ( ) {
2298
2321
selectionHandle . close ( ) ;
2299
- _this9 . _locationFilter = null ;
2322
+ _this10 . _locationFilter = null ;
2300
2323
} ) ;
2301
2324
} ) ( ) ;
2302
2325
}
2303
2326
2304
- _this9 . _locationFilter . addTo ( map ) ;
2327
+ _this10 . _locationFilter . addTo ( map ) ;
2305
2328
}
2306
2329
} , {
2307
2330
stateName : "select-active" ,
2308
2331
icon : "ion-close-round" ,
2309
2332
title : "Dismiss selection" ,
2310
2333
onClick : function onClick ( btn , map ) {
2311
2334
btn . state ( "select-inactive" ) ;
2312
- _this9 . _locationFilter . disable ( ) ;
2335
+ _this10 . _locationFilter . disable ( ) ;
2313
2336
// If explicitly dismissed, clear the crosstalk selections
2314
- _this9 . layerManager . unbrush ( ) ;
2337
+ _this10 . layerManager . unbrush ( ) ;
2315
2338
}
2316
2339
} ]
2317
2340
} ) ;
@@ -2348,7 +2371,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
2348
2371
// pixel of the original image has some contribution to the downscaled image)
2349
2372
// as opposed to a single-step downscaling which will discard a lot of data
2350
2373
// (and with sparse images at small scales can give very surprising results).
2351
-
2352
2374
var Mipmapper = function ( ) {
2353
2375
function Mipmapper ( img ) {
2354
2376
_classCallCheck ( this , Mipmapper ) ;
0 commit comments