Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft swipe position #32

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions css/widget.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@
overflow: hidden;
flex: 1 1 auto;
}

.swiper-container {
position: absolute;
top: 10px;
left: 10px;
z-index: 1000;
background: rgba(255, 255, 255, 0.8);
padding: 5px;
border-radius: 4px;
}

.swipe {
width: 100%;
margin: 0;
}
222 changes: 178 additions & 44 deletions examples/RasterLayer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,34 @@
"metadata": {},
"outputs": [],
"source": [
"from ipyopenlayers import Map, RasterTileLayer"
"from ipyopenlayers import Map, RasterTileLayer,SplitMapControl, ZoomSlider"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import configparser\n",
"config = configparser.ConfigParser()\n",
"config.read('.config.ini')\n",
"key = config['DEFAULT']['key']"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bf54f7b270eb4c12ba2fbcaeea2583da",
"model_id": "eb8f7885d1b94654942794f633a79e87",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[4.299875503991089, 46.85012303279379], zoom=0.0)"
"Map(center=[0.0, 0.0])"
]
},
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = Map(center=[4.299875503991089, 46.85012303279379], zoom=0)\n",
"m = Map()\n",
"m"
]
},
Expand All @@ -74,64 +62,210 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"m.add_layer(layere) "
"layer_b=RasterTileLayer(url='https://{a-c}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png')"
]
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"attributions = '<a href=\"https://www.maptiler.com/copyright/\" target=\"_blank\">&copy; MapTiler</a> ' +'<a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">&copy; OpenStreetMap contributors</a>';\n",
"\n",
"raster = RasterTileLayer(attributions=attributions,url='https://api.maptiler.com/maps/dataviz-dark/{z}/{x}/{y}.png?key=' + key,\n",
" tileSize= 512)\n",
"m.add_layer(raster) "
"m.add_layer(layere) "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"m.remove_layer(raster)"
"zoom=ZoomSlider()\n",
"m.add_control(zoom)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"jupyter": {
"source_hidden": true
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eb8f7885d1b94654942794f633a79e87",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[0.0, 0.0])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
},
],
"source": [
"m.remove(zoom)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"attributions = [\n",
" '&copy; <a href=\"https://www.maptiler.com/copyright/\" target=\"_blank\">MapTiler</a>',\n",
" '&copy; <a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\">OpenStreetMap contributors</a>'\n",
"]\n",
"\n",
"rasterlay = RasterTileLayer(url=f'https://api.maptiler.com/maps/satellite/{{z}}/{{x}}/{{y}}.jpg?key={key}',attributions=attributions,tileSize=512,maxZoom=20)\n",
"m.add_layer(rasterlay)"
"split = SplitMapControl(left_layer=layer_b)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"m.remove_layer(rasterlay)"
"m.add_control(split)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "118567532fa24b9bbfe23392434a10ff",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[0.0, 0.0], layers=[RasterTileLayer()], zoom=3.1446582428318823)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m.remove(split)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m.controls"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9ca94f4d55c341d88bec99d839f1d744",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[47.167155938883134, 33.72586333359965], layers=[RasterTileLayer()])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[0.00033276346057838606, 0.011182868644951327], controls=[SplitMapControl(left_layer=RasterTileLaye…"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"m.remove_control(split)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "249f37982ae74162851c0f1b99a36b1a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[0.00033276346057838606, 0.011182868644951327], layers=[RasterTileLayer()], zoom=1.9997517395318722…"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion ipyopenlayers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) QuantStack.
# Distributed under the terms of the Modified BSD License.

from .Map import *
from .openlayers import *
from ._version import __version__, version_info

def _jupyter_labextension_paths():
Expand Down
44 changes: 37 additions & 7 deletions ipyopenlayers/Map.py → ipyopenlayers/openlayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class HeatmapLayer(Layer):
blur =Int(15).tag(sync=True)
radius = Int(8).tag(sync=True)




class BaseOverlay(DOMWidget):

_model_module = Unicode(module_name).tag(sync=True)
Expand All @@ -87,7 +84,6 @@ class ImageOverlay (BaseOverlay):
class VideoOverlay (BaseOverlay):
_view_name = Unicode('VideoOverlayView').tag(sync=True)
_model_name = Unicode('VideoOverlayModel').tag(sync=True)

video_url = Unicode('').tag(sync=True)

class PopupOverlay (BaseOverlay):
Expand Down Expand Up @@ -121,6 +117,14 @@ class MousePosition(BaseControl):
_view_name = Unicode('MousePositionView').tag(sync=True)
_model_name = Unicode('MousePositionModel').tag(sync=True)

class SplitMapControl(BaseControl):
_model_name = Unicode('SplitMapControlModel').tag(sync=True)
_view_name = Unicode('SplitMapControlView').tag(sync=True)
left_layer = Instance(Layer).tag(sync=True, **widget_serialization)
#right_layer = Instance(Layer).tag(sync=True, **widget_serialization)
swipe_position = Int(50).tag(sync=True)



class Map(DOMWidget):
_model_name = Unicode('MapModel').tag(sync=True)
Expand All @@ -137,7 +141,6 @@ class Map(DOMWidget):
controls=List(Instance(BaseControl)).tag(sync=True, **widget_serialization)



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

Expand All @@ -163,7 +166,34 @@ def add_control(self, control):

def remove_control(self, control):
self.controls = [x for x in self.controls if x != control]



def remove(self, item):
"""Remove an item from the map : either a layer or a control.

Parameters
----------
item: Layer or Control instance
The layer or control to remove.
"""
if isinstance(item, Layer):
self.layers = tuple(
[layer for layer in self.layers if layer.model_id != item.model_id]
)

elif isinstance(item, BaseControl):
self.controls = tuple(
[
control
for control in self.controls
if control.model_id != item.model_id
]
)
return self

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




Loading
Loading