diff --git a/python/jupytergis_core/jupytergis_core/jgis_ydoc.py b/python/jupytergis_core/jupytergis_core/jgis_ydoc.py index 10ca54912..5231bba4a 100644 --- a/python/jupytergis_core/jupytergis_core/jgis_ydoc.py +++ b/python/jupytergis_core/jupytergis_core/jgis_ydoc.py @@ -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, diff --git a/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py b/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py index b0f1d4772..a614a9bbb 100644 --- a/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py +++ b/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py @@ -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. @@ -156,6 +157,7 @@ def add_raster_layer( source = { "type": SourceType.RasterSource, "name": f"{name} Source", + "transient": transient, "parameters": { "url": url, "minZoom": 0, @@ -174,6 +176,7 @@ def add_raster_layer( "type": LayerType.RasterLayer, "name": name, "visible": True, + "transient": transient, "parameters": {"source": source_id, "opacity": opacity}, } @@ -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] @@ -874,6 +878,7 @@ def create_layer( parent=parent, name=name, visible=visible, + transient=transient, type=object_type, parameters=obj_params, filters=filters, @@ -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 = {} @@ -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