Skip to content

Commit

Permalink
Refactor the legend into an ipywidgets subclass (#1722)
Browse files Browse the repository at this point in the history
* Refactor legend

* Add backward compatibility and update notebook

---------

Co-authored-by: Qiusheng Wu <giswqs@gmail.com>
  • Loading branch information
jgarcia525 and giswqs committed Sep 24, 2023
1 parent beb3410 commit 7383389
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 235 deletions.
33 changes: 17 additions & 16 deletions docs/notebooks/14_legends.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.show_youtube('NwnW_qOkNRw')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -87,7 +78,7 @@
"Map.add_basemap('HYBRID')\n",
"landcover = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019').select('landcover')\n",
"Map.addLayer(landcover, {}, 'NLCD Land Cover')\n",
"Map.add_legend(builtin_legend='NLCD')\n",
"Map.add_legend(builtin_legend='NLCD', title='NLCD Land Cover')\n",
"Map"
]
},
Expand Down Expand Up @@ -169,7 +160,7 @@
"# legend_colors = [(255, 0, 0), (127, 255, 0), (127, 18, 25), (36, 70, 180), (96, 68 123)]\n",
"\n",
"Map.add_legend(\n",
" legend_keys=legend_keys, legend_colors=legend_colors, position='bottomleft'\n",
" keys=legend_keys, colors=legend_colors, position='bottomleft'\n",
")\n",
"Map"
]
Expand Down Expand Up @@ -215,7 +206,7 @@
"landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')\n",
"Map.addLayer(landcover, {}, 'NLCD Land Cover')\n",
"\n",
"Map.add_legend(legend_title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)\n",
"Map.add_legend(title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)\n",
"Map"
]
},
Expand All @@ -239,7 +230,6 @@
"Map = geemap.Map()\n",
"\n",
"ee_class_table = \"\"\"\n",
"\n",
"Value\tColor\tDescription\n",
"0\t1c0dff\tWater\n",
"1\t05450a\tEvergreen needleleaf forest\n",
Expand All @@ -259,15 +249,14 @@
"15\t69fff8\tSnow and ice\n",
"16\tf9ffa4\tBarren or sparsely vegetated\n",
"254\tffffff\tUnclassified\n",
"\n",
"\"\"\"\n",
"\n",
"landcover = ee.Image('MODIS/051/MCD12Q1/2013_01_01').select('Land_Cover_Type_1')\n",
"Map.setCenter(6.746, 46.529, 2)\n",
"Map.addLayer(landcover, {}, 'MODIS Land Cover')\n",
"\n",
"legend_dict = geemap.legend_from_ee(ee_class_table)\n",
"Map.add_legend(legend_title=\"MODIS Global Land Cover\", legend_dict=legend_dict)\n",
"Map.add_legend(title=\"MODIS Global Land Cover\", legend_dict=legend_dict)\n",
"\n",
"Map"
]
Expand All @@ -278,8 +267,20 @@
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}
33 changes: 17 additions & 16 deletions examples/notebooks/14_legends.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@
"import geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"geemap.show_youtube('NwnW_qOkNRw')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -87,7 +78,7 @@
"Map.add_basemap('HYBRID')\n",
"landcover = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019').select('landcover')\n",
"Map.addLayer(landcover, {}, 'NLCD Land Cover')\n",
"Map.add_legend(builtin_legend='NLCD')\n",
"Map.add_legend(builtin_legend='NLCD', title='NLCD Land Cover')\n",
"Map"
]
},
Expand Down Expand Up @@ -169,7 +160,7 @@
"# legend_colors = [(255, 0, 0), (127, 255, 0), (127, 18, 25), (36, 70, 180), (96, 68 123)]\n",
"\n",
"Map.add_legend(\n",
" legend_keys=legend_keys, legend_colors=legend_colors, position='bottomleft'\n",
" keys=legend_keys, colors=legend_colors, position='bottomleft'\n",
")\n",
"Map"
]
Expand Down Expand Up @@ -215,7 +206,7 @@
"landcover = ee.Image('USGS/NLCD/NLCD2016').select('landcover')\n",
"Map.addLayer(landcover, {}, 'NLCD Land Cover')\n",
"\n",
"Map.add_legend(legend_title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)\n",
"Map.add_legend(title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)\n",
"Map"
]
},
Expand All @@ -239,7 +230,6 @@
"Map = geemap.Map()\n",
"\n",
"ee_class_table = \"\"\"\n",
"\n",
"Value\tColor\tDescription\n",
"0\t1c0dff\tWater\n",
"1\t05450a\tEvergreen needleleaf forest\n",
Expand All @@ -259,15 +249,14 @@
"15\t69fff8\tSnow and ice\n",
"16\tf9ffa4\tBarren or sparsely vegetated\n",
"254\tffffff\tUnclassified\n",
"\n",
"\"\"\"\n",
"\n",
"landcover = ee.Image('MODIS/051/MCD12Q1/2013_01_01').select('Land_Cover_Type_1')\n",
"Map.setCenter(6.746, 46.529, 2)\n",
"Map.addLayer(landcover, {}, 'MODIS Land Cover')\n",
"\n",
"legend_dict = geemap.legend_from_ee(ee_class_table)\n",
"Map.add_legend(legend_title=\"MODIS Global Land Cover\", legend_dict=legend_dict)\n",
"Map.add_legend(title=\"MODIS Global Land Cover\", legend_dict=legend_dict)\n",
"\n",
"Map"
]
Expand All @@ -278,8 +267,20 @@
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit 7383389

Please sign in to comment.