Skip to content

Commit

Permalink
Added split-panel map opengeos#7
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed May 29, 2021
1 parent da729b4 commit aff3a0e
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/
*.so

# Distribution / packaging
testing/
.Python
env/
build/
Expand Down
132 changes: 132 additions & 0 deletions docs/notebooks/12_split_map.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import leafmap.leafmap as leafmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# leafmap.update_package()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(leafmap.basemap_tiles.keys())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"leafmap.split_map(left_layer=\"ROADMAP\", right_layer=\"HYBRID\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"leafmap.split_map(left_layer=\"Esri.WorldTopoMap\", right_layer=\"OpenTopoMap\", zoom_control=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"leafmap.split_map(left_layer=\"NLCD 2001 CONUS Land Cover\", right_layer=\"NLCD 2016 CONUS Land Cover\", \n",
" left_label = \"2001\", right_label=\"2016\", label_position=\"bottom\", center=[36.1, -114.9], zoom=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/ICuhdzW.gif)"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
132 changes: 132 additions & 0 deletions examples/notebooks/12_split_map.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import leafmap.leafmap as leafmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# leafmap.update_package()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(leafmap.basemap_tiles.keys())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"leafmap.split_map(left_layer=\"ROADMAP\", right_layer=\"HYBRID\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"leafmap.split_map(left_layer=\"Esri.WorldTopoMap\", right_layer=\"OpenTopoMap\", zoom_control=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"leafmap.split_map(left_layer=\"NLCD 2001 CONUS Land Cover\", right_layer=\"NLCD 2016 CONUS Land Cover\", \n",
" left_label = \"2001\", right_label=\"2016\", label_position=\"bottom\", center=[36.1, -114.9], zoom=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/ICuhdzW.gif)"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
76 changes: 76 additions & 0 deletions leafmap/leafmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,3 +1532,79 @@ def linked_maps(
grid[i, j] = output

return grid


def split_map(
left_layer="ROADMAP",
right_layer="HYBRID",
left_label=None,
right_label=None,
label_position="bottom",
**kwargs,
):
"""Creates a split-panel map.
Args:
left_layer (str | ipyleaflet Layer instance, optional): A string from the built-in basemaps (leafmap.basemap_tiles.keys()) or an ipyleaflet Layer instance. Defaults to "ROADMAP".
right_layer (str | ipyleaflet Layer instance, optional): A string from the built-in basemaps (leafmap.basemap_tiles.keys()) or an ipyleaflet Layer instance. . Defaults to "HYBRID".
left_label (str, optional): A label for the left layer to be shown on the map. Defaults to None.
right_label (str, optional): A label for the right layer to be shown on the map. . Defaults to None.
label_position (str, optional): Position of the labels, can be either "top" or "bottom". Defaults to "bottom".
Raises:
Exception: If the provided layer is invalid.
Returns:
leafmap.Map: The Map instance.
"""
if "draw_control" not in kwargs:
kwargs["draw_control"] = False
if "toolbar_control" not in kwargs:
kwargs["toolbar_control"] = False
if "measure_control" not in kwargs:
kwargs["measure_control"] = False
if "fullscreen_control" not in kwargs:
kwargs["fullscreen_control"] = False
if "scale_control" not in kwargs:
kwargs["scale_control"] = False

if left_layer in basemap_tiles:
left_layer = basemap_tiles[left_layer]
if right_layer in basemap_tiles:
right_layer = basemap_tiles[right_layer]

m = Map(**kwargs)

try:
control = ipyleaflet.SplitMapControl(
left_layer=left_layer, right_layer=right_layer
)
m.add_control(control)

if left_label is not None:
label1 = widgets.Label(
str(left_label), layout=widgets.Layout(padding="0px 5px 0px 5px")
)
if label_position == "bottom":
position = "bottomleft"
else:
position = "topleft"
left_control = WidgetControl(widget=label1, position=position)
m.add_control(left_control)

if right_label is not None:
label2 = widgets.Label(
str(right_label), layout=widgets.Layout(padding="0px 5px 0px 5px")
)
if label_position == "bottom":
position = "bottomright"
else:
position = "topright"
right_control = WidgetControl(widget=label2, position=position)
m.add_control(right_control)

except Exception as e:
print("The provided layers are invalid.")
raise Exception(e)

return m
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ nav:
- notebooks/09_csv_to_points.ipynb
- notebooks/10_add_vector.ipynb
- notebooks/11_linked_maps.ipynb
- notebooks/12_split_map.ipynb

0 comments on commit aff3a0e

Please sign in to comment.