From 05d46e7e57e3820f2976eabb618e6927dd88bfc6 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 29 Aug 2023 11:17:39 -0400 Subject: [PATCH] Better expose ipyleaflet maps from remote files --- CHANGELOG.md | 3 +++ large_image/tilesource/jupyter.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6225574a5..40c661dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/large_image/tilesource/jupyter.py b/large_image/tilesource/jupyter.py index a5c757321..86e0fb3c9 100644 --- a/large_image/tilesource/jupyter.py +++ b/large_image/tilesource/jupyter.py @@ -19,6 +19,7 @@ import weakref from large_image.exceptions import TileSourceXYZRangeError +from large_image.tilesource.utilities import JSONDict try: import ipyleaflet @@ -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: @@ -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 @@ -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