{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyleaflet import Map, Marker, MarkerCluster, GeoJSON, GeoData\n", "import geopandas" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cities = geopandas.read_file(\"zip://./geopandas_cities.zip\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geojson = cities.__geo_interface__" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geojson_layer = GeoJSON(\n", " data=geojson,\n", " point_style={\n", " \"radius\": 5,\n", " \"color\": \"red\",\n", " \"fillOpacity\": 0.8,\n", " \"fillColor\": \"blue\",\n", " \"weight\": 3,\n", " },\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = Map(center=(42.5, -41.6), zoom=2)\n", "m.add(\n", " MarkerCluster(\n", " markers=[geojson_layer], # The layer must be in a list or tuple\n", " disable_clustering_at_zoom=3,\n", " max_cluster_radius=100,\n", " )\n", ")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Its possible to mix markers and geojson layers\n", "mrk = [Marker(location=geolocation.coords[0][::-1]) for geolocation in cities.geometry]\n", "\n", "m = Map(center=(42.5, -41.6), zoom=2)\n", "m.add(\n", " MarkerCluster(\n", " markers=[geojson_layer] + mrk,\n", " disable_clustering_at_zoom=3,\n", " max_cluster_radius=100,\n", " )\n", ")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.7" } }, "nbformat": 4, "nbformat_minor": 4 }