{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "PCmgbtUcTUh1" }, "source": [ "# Leaflet example\n", "\n", "This page demonstrates how to use Python, Folium and Leaflet to visualise the example OFDS JSON data. Download this page as a Jupyter Notebook: {nb-download}`leaflet.ipynb`." ] }, { "cell_type": "markdown", "metadata": { "id": "T4nQuXj4W15b" }, "source": [ "## Get the data" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "id": "rGX-arfoTUh2" }, "outputs": [], "source": [ "import json\n", "import folium\n", "import requests\n", "\n", "r = requests.get(\"https://raw.githubusercontent.com/Open-Telecoms-Data/open-fibre-data-standard/refs/heads/0.3/examples/json/network-package.json\")\n", "data = r.json()\n", "network = data['networks'][0]" ] }, { "cell_type": "markdown", "metadata": { "id": "gHUO3Rsua0Tp" }, "source": [ "## Create map and add features" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Ze6alsXMT5U6" }, "outputs": [], "source": [ "# Create map\n", "m = folium.Map(location=[6.4363794,-1.547332], zoom_start=8)\n", "\n", "## Add nodes\n", "for node in network[\"nodes\"]:\n", " folium.CircleMarker(\n", " # Reverse coordinate ordering\n", " location=node[\"location\"][\"coordinates\"][::-1],\n", " radius=5,\n", " # Style based on accessPoint attribute value\n", " color=\"blue\" if node.get(\"accessPoint\") else \"red\",\n", " fill=True,\n", " # Create popup with attribute values\n", " popup=f\"Name: {node[\"name\"]}

Status: {node[\"status\"]}

Access point: {node[\"accessPoint\"]}\"\n", " ).add_to(m)\n", "\n", "## Add spans\n", "for span in network[\"spans\"]:\n", " folium.PolyLine(\n", " locations=[coordinates[::-1] for coordinates in span[\"route\"][\"coordinates\"]],\n", " popup=f\"Name: {span[\"name\"]}

Status: {span[\"status\"]}\"\n", " ).add_to(m)" ] }, { "cell_type": "markdown", "metadata": { "id": "9B4r6LEja-7f" }, "source": [ "## Display map" ] }, { "cell_type": "code", "execution_count": 50, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 483 }, "id": "qV0lfuk8XkMw", "outputId": "ac56c363-da48-45e3-959d-4b2972ce606a" }, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "v5hCuw3YYGG2" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.8.0" } }, "nbformat": 4, "nbformat_minor": 0 }