Skip to content

Commit

Permalink
Merge pull request #3 from Nour-Cheour10/map-control
Browse files Browse the repository at this point in the history
Map control
  • Loading branch information
martinRenou authored May 17, 2024
2 parents dd1747d + 6ecf2b8 commit 00fe60d
Show file tree
Hide file tree
Showing 5 changed files with 2,260 additions and 2,054 deletions.
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

190 changes: 175 additions & 15 deletions examples/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -18,60 +18,220 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "757d5de3cec24c4e83d186b710dcfa59",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[0.0, 0.0])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = Map()\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"m.layers"
"m.zoom=4\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"layer = TileLayer()\n",
"layer.url = 'wdqjwndqwnd.png'\n",
"layer.url"
"m.center=[10.0,5.0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"m.add_layer(layer)"
"layere= TileLayer()\n",
"layere.url=\"https://{a-c}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"m.add_layer(layere)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[TileLayer(url='https://{a-c}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png')]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m.layers"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"m.remove_layer(layere)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m.layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"m.layers = []"
"m.clear_layers()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m.layers"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "59aea50b07f14f028e2fb5e01c43a461",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[0.0, 0.0])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m1 = Map(center=[0.0, 0.0], zoom=2)\n",
"m1"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m1.zoom\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0.0, 0.0]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m1.center"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -90,7 +250,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
32 changes: 23 additions & 9 deletions ipyopenlayers/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"""

from ipywidgets import DOMWidget, Widget, widget_serialization
from traitlets import Unicode, List, Instance
from traitlets import Unicode, List, Instance, CFloat
from ._frontend import module_name, module_version

def_loc = [0.0, 0.0]

class TileLayer(Widget):

Expand All @@ -21,13 +21,10 @@ class TileLayer(Widget):
_view_name = Unicode('TileLayerView').tag(sync=True)
_view_module = Unicode(module_name).tag(sync=True)
_view_module_version = Unicode(module_version).tag(sync=True)

url = Unicode().tag(sync=True)

url = Unicode('https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png').tag(sync=True)


class Map(DOMWidget):
"""TODO: Add docstring here
"""
_model_name = Unicode('MapModel').tag(sync=True)
_model_module = Unicode(module_name).tag(sync=True)
_model_module_version = Unicode(module_version).tag(sync=True)
Expand All @@ -36,9 +33,26 @@ class Map(DOMWidget):
_view_module_version = Unicode(module_version).tag(sync=True)

value = Unicode('Hello World').tag(sync=True)

center = List(def_loc).tag(sync=True, o=True)
zoom = CFloat(2).tag(sync=True, o=True)
layers = List(Instance(TileLayer)).tag(sync=True, **widget_serialization)

def __init__(self, center=None, zoom=None, **kwargs):
super().__init__(**kwargs)

if center is not None:
self.center = center

if zoom is not None:
self.zoom = zoom

def add_layer(self, layer):
# Copy layers (workaround ipywidgets issue)
self.layers = self.layers + [layer]

def remove_layer(self, layer):
self.layers = [x for x in self.layers if x != layer]

def clear_layers(self):
self.layers = []


Loading

0 comments on commit 00fe60d

Please sign in to comment.