{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/solara-geemap/blob/main/notebooks/04_split_map.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# %pip install -U geemap solara" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap\n", "import solara\n", "\n", "\n", "class Map(geemap.Map):\n", " def __init__(self, **kwargs):\n", " super().__init__(**kwargs)\n", " self.add_ee_data()\n", "\n", " def add_ee_data(self):\n", " # Select the eight NLCD epochs after 2000.\n", " years = [\"2001\", \"2004\", \"2006\", \"2008\", \"2011\", \"2013\", \"2016\", \"2019\"]\n", "\n", " # Get an NLCD image by year.\n", " def getNLCD(year):\n", " # Import the NLCD collection.\n", " dataset = ee.ImageCollection(\"USGS/NLCD_RELEASES/2019_REL/NLCD\")\n", "\n", " # Filter the collection by year.\n", " nlcd = dataset.filter(ee.Filter.eq(\"system:index\", year)).first()\n", "\n", " # Select the land cover band.\n", " landcover = nlcd.select(\"landcover\")\n", " return landcover\n", "\n", " ## Create an NLCD image collection for the selected years.\n", " collection = ee.ImageCollection(ee.List(years).map(lambda year: getNLCD(year)))\n", "\n", " # Create a list of labels to populate the dropdown list.\n", " labels = [f\"NLCD {year}\" for year in years]\n", "\n", " # Add a split-panel map for visualizing NLCD land cover change.\n", " self.ts_inspector(\n", " left_ts=collection,\n", " right_ts=collection,\n", " left_names=labels,\n", " right_names=labels,\n", " )\n", "\n", " # Add the NLCD legend to the map.\n", " self.add_legend(\n", " title=\"NLCD Land Cover Type\",\n", " builtin_legend=\"NLCD\",\n", " height=\"460px\",\n", " add_header=False,\n", " )\n", "\n", "\n", "@solara.component\n", "def Page():\n", " with solara.Column(style={\"min-width\": \"500px\", \"isolation\": \"isolate\"}):\n", " Map.element(\n", " center=[40, -100],\n", " zoom=4,\n", " height=\"600px\",\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Page()" ] } ], "metadata": { "kernelspec": { "display_name": "geo", "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.8" } }, "nbformat": 4, "nbformat_minor": 2 }