From 0a7aade22862d6015ded6231f34b431610b1b2fa Mon Sep 17 00:00:00 2001 From: Atakan ERDOGAN Date: Wed, 21 Feb 2024 16:35:34 +0300 Subject: [PATCH] Update after environment(kentcbs) --- docs/examples/folium.ipynb | 2 +- docs/examples/kentcbs.ipynb | 521 ++++++++++++++++++++++++++++++++---- kentcbs/kentcbs.py | 70 ++++- 3 files changed, 540 insertions(+), 53 deletions(-) diff --git a/docs/examples/folium.ipynb b/docs/examples/folium.ipynb index 158af83..ddb50d6 100644 --- a/docs/examples/folium.ipynb +++ b/docs/examples/folium.ipynb @@ -136,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "0.0.0" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/docs/examples/kentcbs.ipynb b/docs/examples/kentcbs.ipynb index cd770bb..eeb2f73 100644 --- a/docs/examples/kentcbs.ipynb +++ b/docs/examples/kentcbs.ipynb @@ -12,27 +12,44 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url =\"https://nominaim.openstreetmap.org/search?format=json&q={s}\"" + ] + }, + { + "cell_type": "code", + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "c0b0499e458d4bd29b4177156a304b9c", + "model_id": "aa0cd2b2785148fd8e140d06020a85a4", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Map(center=[36, 36], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_tex…" + "Map(center=[19.1646, 72.8493], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zo…" ] }, - "execution_count": 16, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m = kentcbs.Map(center=[36,36],zoom=4)\n", + "m = kentcbs.Map(zoom=3, center=[19.1646, 72.8493])\n", + "\n", + "\n", + "m.add(SearchControl(\n", + " position=\"topleft\",\n", + " url='https://nominatim.openstreetmap.org/search?format=json&q={s}',\n", + " zoom=5,\n", + "))\n", + "\n", "m" ] }, @@ -42,85 +59,487 @@ "metadata": {}, "outputs": [], "source": [ - "url =\"https://nominaim.openstreetmap.org/search?format=json&q={s}\"" + "m.add_search_control(position='topleft', zoom=4, url=url)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + ">>> import xyzservices.providers as xyz" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 24, "metadata": {}, "outputs": [ { "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "d15be159863b4de3810e4c7fec122f7e", - "version_major": 2, - "version_minor": 0 - }, + "text/html": [ + "\n", + "
\n", + " \n", + "
\n", + "
\n", + "
xyzservices.Bunch
\n", + "
9 items
\n", + "
\n", + "
\n", + "
    \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.OpenCycleMap
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    cycle
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.Transport
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    transport
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.TransportDark
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    transport-dark
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.SpinalMap
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    spinal-map
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.Landscape
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    landscape
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.Outdoors
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    outdoors
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.Pioneer
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    pioneer
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.MobileAtlas
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    mobile-atlas
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
  • \n", + " \n", + " \n", + "
    \n", + " \n", + "
    \n", + " \n", + "
    \n", + "
    \n", + "
    xyzservices.TileProvider
    \n", + "
    Thunderforest.Neighbourhood
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    url
    https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}
    html_attribution
    © Thunderforest, © OpenStreetMap contributors
    attribution
    (C) Thunderforest, (C) OpenStreetMap contributors
    variant
    neighbourhood
    apikey
    max_zoom
    22
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + " \n", + "
    \n", + "
  • \n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " " + ], "text/plain": [ - "Map(center=[36, 36], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_tex…" + "{'OpenCycleMap': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'cycle',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.OpenCycleMap'},\n", + " 'Transport': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'transport',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.Transport'},\n", + " 'TransportDark': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'transport-dark',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.TransportDark'},\n", + " 'SpinalMap': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'spinal-map',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.SpinalMap'},\n", + " 'Landscape': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'landscape',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.Landscape'},\n", + " 'Outdoors': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'outdoors',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.Outdoors'},\n", + " 'Pioneer': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'pioneer',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.Pioneer'},\n", + " 'MobileAtlas': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'mobile-atlas',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.MobileAtlas'},\n", + " 'Neighbourhood': {'url': 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}',\n", + " 'html_attribution': '© Thunderforest, © OpenStreetMap contributors',\n", + " 'attribution': '(C) Thunderforest, (C) OpenStreetMap contributors',\n", + " 'variant': 'neighbourhood',\n", + " 'apikey': '',\n", + " 'max_zoom': 22,\n", + " 'name': 'Thunderforest.Neighbourhood'}}" ] }, - "execution_count": 5, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "m = kentcbs.Map(center=[36,36],zoom=4)\n", - "m.add_search_control(position='topleft', zoom=4, url=url)\n", - "m" + "xyz.Thunderforest" ] }, { "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 9, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (3589052190.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m Cell \u001b[1;32mIn[25], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m https://{s}.tile.thunderforest.com/{Landscape}/{z}/{x}/{y}.png?apikey={apikey}\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ - "m.add_search_control(position='topleft', zoom=4, url=url)" + "\n", + "https://{s}.tile.thunderforest.com/{Landscape}/{z}/{x}/{y}.png?apikey={apikey}" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 26, "metadata": {}, "outputs": [ { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "aa0cd2b2785148fd8e140d06020a85a4", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Map(center=[19.1646, 72.8493], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zo…" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" + "ename": "AttributeError", + "evalue": "'Map' object has no attribute 'add_tile_layer'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[26], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd_tile_layer\u001b[49m(url\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhttps://\u001b[39m\u001b[38;5;132;01m{s}\u001b[39;00m\u001b[38;5;124m.tile.thunderforest.com/\u001b[39m\u001b[38;5;132;01m{Landscape}\u001b[39;00m\u001b[38;5;124m/\u001b[39m\u001b[38;5;132;01m{z}\u001b[39;00m\u001b[38;5;124m/\u001b[39m\u001b[38;5;132;01m{x}\u001b[39;00m\u001b[38;5;124m/\u001b[39m\u001b[38;5;132;01m{y}\u001b[39;00m\u001b[38;5;124m.png?apikey=\u001b[39m\u001b[38;5;132;01m{apikey}\u001b[39;00m\u001b[38;5;124m'\u001b[39m, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThunderforest\u001b[39m\u001b[38;5;124m'\u001b[39m, attr\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThunderforest\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", + "\u001b[1;31mAttributeError\u001b[0m: 'Map' object has no attribute 'add_tile_layer'" + ] } ], "source": [ - "m = kentcbs.Map(zoom=3, center=[19.1646, 72.8493])\n", - "\n", - "\n", - "m.add(SearchControl(\n", - " position=\"topleft\",\n", - " url='https://nominatim.openstreetmap.org/search?format=json&q={s}',\n", - " zoom=5,\n", - "))\n", - "\n", - "m" + "m.add_tile_layer(url='https://{s}.tile.thunderforest.com/{Landscape}/{z}/{x}/{y}.png?apikey={apikey}', name='Thunderforest', attr='Thunderforest')" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/kentcbs/kentcbs.py b/kentcbs/kentcbs.py index 507c6b1..9a6b891 100644 --- a/kentcbs/kentcbs.py +++ b/kentcbs/kentcbs.py @@ -13,13 +13,81 @@ def __init__(self, center=[20,0], zoom=2, **kwargs) -> None: super().__init__(center=center, zoom=zoom,**kwargs) + if "layer_control" not in kwargs: + kwargs["layer_control"] = True + + if kwargs["search_control"]: + self.add_layers_control() + def add_search_control(self, position="topleft", **kwargs): + """_summary_ + + Args: + position (str, optional): _description_. Defaults to "topleft". + """ + if "url" not in kwargs: + kwargs["url"] = "https://nominatim.openstreetmap.org/search?format=json&q={s}" - search_control = ipyleaflet.SearchControl(**kwargs) + search_control = ipyleaflet.SearchControl(position=position,**kwargs) self.add_control(search_control) + def add_draw_control(self, position="topleft", **kwargs): + """_summary_ + + Args: + position (str, optional): _description_. Defaults to "topleft". + """ + draw_control = ipyleaflet.DrawControl(position=position,**kwargs) + self.add_control(draw_control) + """_summary_ + """ + draw_control.polyline = { + "shapeOptions": { + "color": "#6bc2e5", + "weight": 8, + "opacity": 1.0 + } + } + draw_control.polygon = { + "shapeOptions": { + "fillColor": "#6be5c3", + "color": "#6be5c3", + "fillOpacity": 1.0 + }, + "drawError": { + "color": "#dd253b", + "message": "Oups!" + }, + "allowIntersection": False + } + draw_control.circle = { + "shapeOptions": { + "fillColor": "#efed69", + "color": "#efed69", + "fillOpacity": 1.0 + } + } + draw_control.rectangle = { + "shapeOptions": { + "fillColor": "#fca45d", + "color": "#fca45d", + "fillOpacity": 1.0 + } + } + + self.add_control(draw_control) + + + + + def add_layers_control(self, position='topright',**kwargs): + + layers_control = ipyleaflet.LayersControl(position=position,**kwargs) + self.add_control(layers_control) + +