Skip to content
Open
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
23 changes: 20 additions & 3 deletions python/jupytergis_core/jupytergis_core/jgis_ydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,28 @@ def get(self) -> str:
:return: Document's content.
:rtype: Any
"""
layers = self._ylayers.to_py()
sources = self._ysources.to_py()
# don't save transient layers and sources to disk
transient_layers = [
key for key, val in self._ylayers.to_py().items() if val["transient"]
]
transient_sources = [
key for key, val in self._ysources.to_py().items() if val["transient"]
]
layers = {
key: val
for key, val in self._ylayers.to_py().items()
if key not in transient_layers
}
sources = {
key: val
for key, val in self._ysources.to_py().items()
if key not in transient_sources
}
options = self._yoptions.to_py()
meta = self._ymetadata.to_py()
layers_tree = self._ylayerTree.to_py()
layers_tree = [
idx for idx in self._ylayerTree.to_py() if idx not in transient_layers
]
return json.dumps(
dict(
schemaVersion=SCHEMA_VERSION,
Expand Down
14 changes: 12 additions & 2 deletions python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def add_raster_layer(
name: str = "Raster Layer",
attribution: str = "",
opacity: float = 1,
transient: bool = False,
):
"""
Add a Raster Layer to the document.
Expand All @@ -156,6 +157,7 @@ def add_raster_layer(
source = {
"type": SourceType.RasterSource,
"name": f"{name} Source",
"transient": transient,
"parameters": {
"url": url,
"minZoom": 0,
Expand All @@ -174,6 +176,7 @@ def add_raster_layer(
"type": LayerType.RasterLayer,
"name": name,
"visible": True,
"transient": transient,
"parameters": {"source": source_id, "opacity": opacity},
}

Expand Down Expand Up @@ -861,7 +864,8 @@ def create_layer(
) -> Optional[JGISLayer]:
object_type = data.get("type", None)
name: str = data.get("name", None)
visible: str = data.get("visible", True)
visible: bool = data.get("visible", True)
transient: bool = data.get("transient", False)
filters = data.get("filters", None)
if object_type and object_type in self._factories:
Model = self._factories[object_type]
Expand All @@ -874,6 +878,7 @@ def create_layer(
parent=parent,
name=name,
visible=visible,
transient=transient,
type=object_type,
parameters=obj_params,
filters=filters,
Expand All @@ -886,6 +891,7 @@ def create_source(
) -> Optional[JGISSource]:
object_type = data.get("type", None)
name: str = data.get("name", None)
transient: bool = data.get("transient", False)
if object_type and object_type in self._factories:
Model = self._factories[object_type]
args = {}
Expand All @@ -894,7 +900,11 @@ def create_source(
args[field] = params.get(field, None)
obj_params = Model(**args)
return JGISSource(
parent=parent, name=name, type=object_type, parameters=obj_params
parent=parent,
name=name,
transient=transient,
type=object_type,
parameters=obj_params,
)

return None
Expand Down
Loading