{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# GeoLibre in Jupyter\n", "\n", "The full GeoLibre GIS app, embedded in a notebook cell, with a leafmap-style Python API.\n", "Run the cells below one at a time. After the map renders, edits you make in the UI (panning,\n", "adding layers) are readable back from Python." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "# %pip install geolibre" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "from geolibre import Map\n", "\n", "m = Map(center=(-100, 40), zoom=4, height=\"800px\")\n", "m" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "## Add a GeoJSON layer\n", "\n", "`add_geojson` accepts a dict, a file path, a URL, a JSON string, or a GeoDataFrame." ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "url = (\n", " \"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson\"\n", ")\n", "m.add_geojson(url, name=\"World Cities\", circleRadius=4, fillColor=\"#ef4444\")" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "## Add a raster XYZ tile layer and move the view" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "m.add_tile_layer(\n", " \"https://tile.openstreetmap.org/{z}/{x}/{y}.png\",\n", " name=\"OpenStreetMap\",\n", " attribution=\"(c) OpenStreetMap contributors\",\n", ")\n", "m.set_center(-122.4, 37.77, zoom=10)" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "## Add a Cloud Optimized GeoTIFF (COG)" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "m.add_cog(\n", " \"https://data.source.coop/giswqs/opengeos/nlcd_2021_land_cover_30m.tif\",\n", " name=\"Raster\",\n", ")" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "## Read state back from the UI\n", "\n", "Pan or zoom the map above, then run this cell. The center reflects the live UI view." ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "proj = m.to_project()\n", "print(\"center:\", proj[\"mapView\"][\"center\"], \"zoom:\", round(proj[\"mapView\"][\"zoom\"], 2))\n", "print(\"layers:\", [layer[\"name\"] for layer in proj[\"layers\"]])" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "## Save and reload a project" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "m.save_project(\"my-map.geolibre.json\")\n", "\n", "m2 = Map()\n", "m2.load_project(\"my-map.geolibre.json\")\n", "m2" ] } ], "metadata": { "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.12.12" } }, "nbformat": 4, "nbformat_minor": 5 }