Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jun 20, 2024
1 parent e9a4dba commit 194bc28
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
25 changes: 22 additions & 3 deletions examples/test.jGIS
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
5 changes: 0 additions & 5 deletions python/jupytergis_core/install.json

This file was deleted.

19 changes: 12 additions & 7 deletions python/jupytergis_core/jupytergis_core/jgis_ydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
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


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:
Expand All @@ -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,
)

Expand All @@ -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", {}))
Expand All @@ -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")
)
2 changes: 0 additions & 2 deletions python/jupytergis_core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand All @@ -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]
Expand Down

0 comments on commit 194bc28

Please sign in to comment.