From 194bc286037d57aff6850b976b148f5ed2e4de98 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Thu, 20 Jun 2024 15:45:45 +0200 Subject: [PATCH] Iterate --- examples/test.jGIS | 25 ++++++++++++++++--- python/jupytergis_core/install.json | 5 ---- .../jupytergis_core/jgis_ydoc.py | 19 ++++++++------ python/jupytergis_core/pyproject.toml | 2 -- 4 files changed, 34 insertions(+), 17 deletions(-) delete mode 100644 python/jupytergis_core/install.json diff --git a/examples/test.jGIS b/examples/test.jGIS index 4c8096df..e98c00f5 100644 --- a/examples/test.jGIS +++ b/examples/test.jGIS @@ -1,5 +1,24 @@ { - "layers": {}, - "sources": {}, + "sources": { + "699facc9-e7c4-4f38-acf1-1fd7f02d9f36": { + "type": "RasterSource", + "name": "RasterSource", + "parameters": { + "url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png", + "minZoom": 0, + "maxZoom": 24 + } + } + }, + "layers": { + "2467576f-b527-4cb7-998d-fa1d056fb8a1": { + "type": "RasterLayer", + "parameters": { + "source": "699facc9-e7c4-4f38-acf1-1fd7f02d9f36" + }, + "visible": true, + "name": "RasterSource Layer" + } + }, "options": {} -} +} \ No newline at end of file diff --git a/python/jupytergis_core/install.json b/python/jupytergis_core/install.json deleted file mode 100644 index 5d1e6e3f..00000000 --- a/python/jupytergis_core/install.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "packageManager": "python", - "packageName": "jupytergis_core", - "uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupytergis_core" -} diff --git a/python/jupytergis_core/jupytergis_core/jgis_ydoc.py b/python/jupytergis_core/jupytergis_core/jgis_ydoc.py index 86f7ebd6..e2a9449f 100644 --- a/python/jupytergis_core/jupytergis_core/jgis_ydoc.py +++ b/python/jupytergis_core/jupytergis_core/jgis_ydoc.py @@ -2,7 +2,7 @@ from typing import Any, Callable from functools import partial -from pycrdt import Array, Map, Text +from pycrdt import Map, Text from jupyter_ydoc.ybasedoc import YBaseDoc @@ -10,7 +10,8 @@ class YJGIS(YBaseDoc): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._ydoc["source"] = self._ysource = Text() - self._ydoc["layers"] = self._ylayers = Array() + self._ydoc["layers"] = self._ylayers = Map() + self._ydoc["sources"] = self._ysources = Map() self._ydoc["options"] = self._yoptions = Map() def version(self) -> str: @@ -23,9 +24,10 @@ def get(self) -> str: :rtype: Any """ layers = self._ylayers.to_py() + sources = self._ysources.to_py() options = self._yoptions.to_py() return json.dumps( - dict(layers=layers, options=options), + dict(layers=layers, sources=sources, options=options), indent=2, ) @@ -36,12 +38,12 @@ def set(self, value: str) -> None: :type value: Any """ valueDict = json.loads(value) - newObj = [] - for obj in valueDict["layers"]: - newObj.append(Map(obj)) self._ylayers.clear() - self._ylayers.extend(newObj) + self._ylayers.update(valueDict.get("layers", {})) + + self._ysources.clear() + self._ysources.update(valueDict.get("sources", {})) self._yoptions.clear() self._yoptions.update(valueDict.get("options", {})) @@ -57,6 +59,9 @@ def observe(self, callback: Callable[[str, Any], None]): self._subscriptions[self._ylayers] = self._ylayers.observe_deep( partial(callback, "layers") ) + self._subscriptions[self._ysources] = self._ysources.observe_deep( + partial(callback, "sources") + ) self._subscriptions[self._yoptions] = self._yoptions.observe_deep( partial(callback, "options") ) diff --git a/python/jupytergis_core/pyproject.toml b/python/jupytergis_core/pyproject.toml index b7a650e3..3ed27835 100644 --- a/python/jupytergis_core/pyproject.toml +++ b/python/jupytergis_core/pyproject.toml @@ -19,7 +19,6 @@ classifiers = [ "Programming Language :: Python :: 3.12", ] dependencies = [ - "jupyter_server>=2.0.6,<3", "jupyter_ydoc>=2,<3", "jupyter-collaboration>=2,<3", ] @@ -43,7 +42,6 @@ artifacts = ["jupytergis_core/labextension"] exclude = [".github", "binder"] [tool.hatch.build.targets.wheel.shared-data] -"install.json" = "share/jupyter/labextensions/@jupytergis/jupytergis-core/install.json" "jupytergis_core/labextension" = "share/jupyter/labextensions/@jupytergis/jupytergis-core" [tool.hatch.build.hooks.version]