Skip to content

Commit

Permalink
feat: Allow user to specify center and zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Jan 15, 2025
1 parent 4a793c2 commit d6e6616
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions jupyter/uvdat_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
import ipywidgets as widgets
import requests

CENTER = [42.36, -71.06]
ZOOM = 14
DEFAULT_CENTER = [42.36, -71.06]
DEFAULT_ZOOM = 14


class LayerRepresentation:
def __init__(self, layer, api_url, session, token):
def __init__(self, layer, api_url, session, token, center, zoom):
self.layer = layer
self.session = session
self.api_url = api_url
self.token = token
self.center = center
self.zoom = zoom

self.output = widgets.Output()
self.frame_index = 0
Expand All @@ -43,8 +45,8 @@ def __init__(self, layer, api_url, session, token):
self.map = Map(
crs=projections.EPSG3857,
basemap=basemaps.OpenStreetMap.Mapnik,
center=CENTER,
zoom=ZOOM,
center=self.center,
zoom=self.zoom,
max_zoom=20,
min_zoom=0,
scroll_wheel_zoom=True,
Expand Down Expand Up @@ -120,7 +122,7 @@ def get_widget(self):


class UVDATExplorer:
def __init__(self, api_url=None, email=None, password=None):
def __init__(self, api_url=None, email=None, password=None, center=None, zoom=None):
if api_url is None:
msg = 'UVDATExplorer missing argument: %s must be specified.'
raise ValueError(msg % '`api_url`')
Expand All @@ -132,6 +134,8 @@ def __init__(self, api_url=None, email=None, password=None):
self.authenticated = False
self.email = email
self.password = password
self.center = center or DEFAULT_CENTER
self.zoom = zoom or DEFAULT_ZOOM

# Widgets
self.tree = None
Expand Down Expand Up @@ -228,7 +232,14 @@ def select_layer(self, event):
node_id = node._id
layer = self.tree_nodes[node_id]

self.map = LayerRepresentation(layer, self.api_url, self.session, self.token)
self.map = LayerRepresentation(
layer,
self.api_url,
self.session,
self.token,
self.center,
self.zoom,
)
children = [self.tree, self.output, self.map.get_widget()]
self.update_display(children)

Expand Down

0 comments on commit d6e6616

Please sign in to comment.