Skip to content

Commit

Permalink
Merge pull request #1280 from girder/jupyter-file
Browse files Browse the repository at this point in the history
Better expose ipyleaflet maps from remote files
  • Loading branch information
manthey authored Aug 29, 2023
2 parents 6fe2935 + 05d46e7 commit cc39996
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.23.5

### Improvements
- Better expose ipyleaflet maps from remote files ([#1280](../../pull/1280))

### Bug Fixes
- Fix modifying annotations anonymously ([#1279](../../pull/1279))

Expand Down
15 changes: 14 additions & 1 deletion large_image/tilesource/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import weakref

from large_image.exceptions import TileSourceXYZRangeError
from large_image.tilesource.utilities import JSONDict

try:
import ipyleaflet
Expand Down Expand Up @@ -117,9 +118,12 @@ def __init__(self, *, ts=None, metadata=None, url=None, gc=None, id=None, resour
self._layer = self._map = self._metadata = None
self._ts = ts
if (not url or not metadata) and gc and (id or resource):
fileId = None
if id is None:
entry = gc.get('resource/lookup', parameters={'path': resource})
if entry:
if entry.get('_modelType') == 'file':
fileId = entry['_id']
id = entry['itemId'] if entry.get('_modelType') == 'file' else entry['_id']
if id:
try:
Expand All @@ -133,8 +137,9 @@ def __init__(self, *, ts=None, metadata=None, url=None, gc=None, id=None, resour
metadata = gc.get(f'item/{id}/tiles' + suffix)
if metadata.get('geospatial') and metadata.get('projection'):
url += suffix
self._id = id
else:
self._ts = self._get_temp_source(gc, id)
self._ts = self._get_temp_source(gc, fileId or id)
if url and metadata:
self._metadata = metadata
self._url = url
Expand Down Expand Up @@ -275,6 +280,14 @@ def layer(self):
def map(self):
return self._map

@property
def metadata(self):
return JSONDict(self._metadata)

@property
def id(self):
return getattr(self, '_id', None)

def to_map(self, coordinate):
"""
Convert a coordinate from the image or projected image space to the map
Expand Down

0 comments on commit cc39996

Please sign in to comment.