56
56
sys .stderr .write ("Error: missing required packages. (%s)\n " % (str (e )))
57
57
raise
58
58
59
+ try :
60
+ import xyzservices
61
+ except ModuleNotFoundError as e :
62
+ sys .stderr .write ("Error: missing required packages. (%s)\n " % (str (e )))
63
+ raise
64
+
59
65
class widgets :
60
66
def __init__ (self ):
61
67
# dropdown menu for setting asset
@@ -417,18 +423,31 @@ def format(self):
417
423
"""
418
424
419
425
# define background ipyleaflet tiles
420
- basemaps = Bunch (
421
- Esri = Bunch (
422
- ArcticOceanBase = dict (name = 'Esri.ArcticOceanBase' ,crs = projections .EPSG5936 ,attribution = esri_attribution ,
423
- url = 'http://server.arcgisonline.com/ArcGIS/rest/services/Polar/Arctic_Ocean_Base/MapServer/tile/{z}/{y}/{x}' ,
424
- ),
425
- ArcticOceanReference = dict (name = 'Esri.ArcticOceanReference' ,crs = projections .EPSG5936 ,attribution = esri_attribution ,
426
- url = 'http://server.arcgisonline.com/ArcGIS/rest/services/Polar/Arctic_Ocean_Reference/MapServer/tile/{z}/{y}/{x}' ,
427
- ),
428
- AntarcticBasemap = dict (name = 'Esri.AntarcticBasemap' ,crs = projections .EPSG3031 ,attribution = noaa_attribution ,
429
- url = 'https://tiles.arcgis.com/tiles/C8EMgrsFcRFL6LrL/arcgis/rest/services/Antarctic_Basemap/MapServer/tile/{z}/{y}/{x}' ,
430
- )
431
- ),
426
+ basemaps = {
427
+ "Esri" : {
428
+ "ArcticOceanBase" : {
429
+ "name" : 'Esri.ArcticOceanBase' ,
430
+ "crs" : projections .EPSG5936 ,
431
+ "attribution" : esri_attribution ,
432
+ "url" : 'http://server.arcgisonline.com/ArcGIS/rest/services/Polar/Arctic_Ocean_Base/MapServer/tile/{z}/{y}/{x}'
433
+ },
434
+ "ArcticOceanReference" : {
435
+ "name" : 'Esri.ArcticOceanReference' ,
436
+ "crs" : projections .EPSG5936 ,
437
+ "attribution" : esri_attribution ,
438
+ "url" : 'http://server.arcgisonline.com/ArcGIS/rest/services/Polar/Arctic_Ocean_Reference/MapServer/tile/{z}/{y}/{x}'
439
+ },
440
+ "AntarcticBasemap" : {
441
+ "name" : 'Esri.AntarcticBasemap' ,
442
+ "crs" : projections .EPSG3031 ,
443
+ "attribution" :noaa_attribution ,
444
+ "url" : 'https://tiles.arcgis.com/tiles/C8EMgrsFcRFL6LrL/arcgis/rest/services/Antarctic_Basemap/MapServer/tile/{z}/{y}/{x}'
445
+ }
446
+ }
447
+ }
448
+
449
+ # define background ipyleaflet WMS layers
450
+ layers = Bunch (
432
451
GLIMS = Bunch (
433
452
glaciers = ipyleaflet .WMSLayer (
434
453
attribution = glims_attribution ,
@@ -439,6 +458,20 @@ def format(self):
439
458
)
440
459
)
441
460
461
+ # load basemap providers from dict
462
+ # https://github.com/geopandas/xyzservices/blob/main/xyzservices/lib.py
463
+ def _load_dict (data ):
464
+ providers = Bunch ()
465
+ for provider_name in data .keys ():
466
+ provider = data [provider_name ]
467
+ if "url" in provider .keys ():
468
+ providers [provider_name ] = xyzservices .lib .TileProvider (provider )
469
+ else :
470
+ providers [provider_name ] = Bunch (
471
+ {i : xyzservices .lib .TileProvider (provider [i ]) for i in provider .keys ()}
472
+ )
473
+ return providers
474
+
442
475
# draw ipyleaflet map
443
476
class leaflet :
444
477
def __init__ (self , projection , ** kwargs ):
@@ -448,22 +481,23 @@ def __init__(self, projection, **kwargs):
448
481
kwargs .setdefault ('cursor' ,True )
449
482
kwargs .setdefault ('center' ,(39 ,- 108 ))
450
483
kwargs .setdefault ('color' ,'green' )
484
+ providers = _load_dict (basemaps )
451
485
# create basemap in projection
452
486
if (projection == 'Global' ):
453
487
self .map = ipyleaflet .Map (center = kwargs ['center' ],
454
488
zoom = 9 , max_zoom = 15 ,
455
489
basemap = ipyleaflet .basemaps .Esri .WorldTopoMap )
456
- self .map .add_layer (basemaps .GLIMS .glaciers )
490
+ self .map .add_layer (layers .GLIMS .glaciers )
457
491
elif (projection == 'North' ):
458
492
self .map = ipyleaflet .Map (center = (90 ,0 ),
459
493
zoom = 5 , max_zoom = 24 ,
460
- basemap = basemaps .Esri .ArcticOceanBase ,
494
+ basemap = providers .Esri .ArcticOceanBase ,
461
495
crs = projections .EPSG5936 )
462
- self .map .add_layer (basemaps .Esri .ArcticOceanReference )
496
+ self .map .add_layer (providers .Esri .ArcticOceanReference )
463
497
elif (projection == 'South' ):
464
498
self .map = ipyleaflet .Map (center = (- 90 ,0 ),
465
499
zoom = 2 , max_zoom = 9 ,
466
- basemap = basemaps .Esri .AntarcticBasemap ,
500
+ basemap = providers .Esri .AntarcticBasemap ,
467
501
crs = projections .EPSG3031 )
468
502
# add control for zoom
469
503
if kwargs ['zoom' ]:
0 commit comments