Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better expose ipyleaflet maps from remote files #1280

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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