Arc layer
In [ ]:
Copied!
# %pip install leafmap
# %pip install leafmap
In [ ]:
Copied!
import pandas as pd
import geopandas as gpd
import ipywidgets as widgets
import leafmap.maplibregl as leafmap
import pandas as pd
import geopandas as gpd
import ipywidgets as widgets
import leafmap.maplibregl as leafmap
In [ ]:
Copied!
route_url = (
"https://github.com/opengeos/datasets/releases/download/world/airport_routes.csv"
)
df = pd.read_csv(route_url)
df.head()
route_url = (
"https://github.com/opengeos/datasets/releases/download/world/airport_routes.csv"
)
df = pd.read_csv(route_url)
df.head()
In [ ]:
Copied!
airport_url = (
"https://github.com/opengeos/datasets/releases/download/world/airports.geojson"
)
gdf = gpd.read_file(airport_url)
gdf.head()
airport_url = (
"https://github.com/opengeos/datasets/releases/download/world/airports.geojson"
)
gdf = gpd.read_file(airport_url)
gdf.head()
In [ ]:
Copied!
m = leafmap.Map(style="liberty")
m.add_gdf(gdf, name="Airports", fit_bounds=False)
container = m.create_container()
m = leafmap.Map(style="liberty")
m.add_gdf(gdf, name="Airports", fit_bounds=False)
container = m.create_container()
In [ ]:
Copied!
dropdown = widgets.Dropdown(
description="Airport", options=df["src_airport"].unique().tolist(), value=None
)
map_widget = widgets.VBox([m.container])
main_widget = widgets.VBox([dropdown, map_widget])
def on_airport_change(change):
if change["new"]:
airport = change["new"]
selected_df = df[df["src_airport"] == airport]
dst_airports = selected_df["dst_airport"].unique().tolist() + [airport]
selected_gdf = gdf[gdf["id"].isin(dst_airports)]
m = leafmap.Map(style="liberty")
m.add_basemap(
"Esri.WorldImagery", visible=False, before_id=m.first_symbol_layer_id
)
m.add_gdf(selected_gdf, name="Airports", fit_bounds=False)
m.add_arc_layer(
selected_df,
src_lon="src_lon",
src_lat="src_lat",
dst_lon="dst_lon",
dst_lat="dst_lat",
)
m.create_container()
map_widget.children = [m.container]
dropdown.observe(on_airport_change, names="value")
main_widget
dropdown = widgets.Dropdown(
description="Airport", options=df["src_airport"].unique().tolist(), value=None
)
map_widget = widgets.VBox([m.container])
main_widget = widgets.VBox([dropdown, map_widget])
def on_airport_change(change):
if change["new"]:
airport = change["new"]
selected_df = df[df["src_airport"] == airport]
dst_airports = selected_df["dst_airport"].unique().tolist() + [airport]
selected_gdf = gdf[gdf["id"].isin(dst_airports)]
m = leafmap.Map(style="liberty")
m.add_basemap(
"Esri.WorldImagery", visible=False, before_id=m.first_symbol_layer_id
)
m.add_gdf(selected_gdf, name="Airports", fit_bounds=False)
m.add_arc_layer(
selected_df,
src_lon="src_lon",
src_lat="src_lat",
dst_lon="dst_lon",
dst_lat="dst_lat",
)
m.create_container()
map_widget.children = [m.container]
dropdown.observe(on_airport_change, names="value")
main_widget