Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webGL option for rendering GPS traces #996

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3953,6 +3953,9 @@ def edit_gps_trace(
fig_width: str = "1550px",
fig_height: str = "300px",
time_format: str = "%Y-%m-%d %H:%M:%S",
stroke_color: str = "lightgray",
circle_size: int = 48,
webGL: bool = False,
**kwargs,
) -> Any:
"""
Expand All @@ -3969,18 +3972,31 @@ def edit_gps_trace(
fig_width (str, optional): The width of the figure. Defaults to "1550px".
fig_height (str, optional): The height of the figure. Defaults to "300px".
time_format (str, optional): The time format for the timestamp. Defaults to "%Y-%m-%d %H:%M:%S".
stroke_color (str, optional): The stroke color of the GPS trace points. Defaults to "lightgray".
circle_size (int, optional): The size of the GPS trace points. Defaults to 48.
webGL (bool, optional): Whether to use WebGL (bqplot-gl) for rendering. Defaults to False.
**kwargs: Additional keyword arguments.

Returns:
Any: The main widget containing the map and the editing interface.
"""

from datetime import datetime
from bqplot import LinearScale, Scatter, Figure, PanZoom
from bqplot import LinearScale, Figure, PanZoom
import bqplot as bq
from ipywidgets import VBox, Button
import ipywidgets as widgets

if webGL:
try:
from bqplot_gl import ScatterGL as Scatter
except ImportError:
raise ImportError(
"Please install bqplot_gl using 'pip install --pre bqplot-gl'"
)
else:
from bqplot import Scatter

output = widgets.Output()
download_widget = widgets.Output()

Expand Down Expand Up @@ -4023,10 +4039,10 @@ def edit_gps_trace(
scales={"x": x_sc, "y": y_sc},
colors=[color],
marker="circle",
stroke="lightgray",
stroke=stroke_color,
unselected_style={"opacity": 0.1},
selected_style={"opacity": 1.0},
default_size=48, # Set a smaller default marker size
default_size=circle_size, # Set a smaller default marker size
display_legend=False,
labels=[str(cat)], # Add the category label for the legend
)
Expand Down Expand Up @@ -4229,6 +4245,7 @@ def draw_change(lng_lat):

def features_change(change):
if change["new"]:

selected_features = multi_select.value
children = []
additonal_scatters.clear()
Expand All @@ -4243,6 +4260,7 @@ def features_change(change):
# Create scatter plots for each annotation category with the appropriate colors and labels
scatters = []
for cat, color in colormap.items():

if (
cat != "selected"
): # Exclude 'selected' from data points (only for highlighting selection)
Expand All @@ -4253,12 +4271,14 @@ def features_change(change):
scales={"x": x_sc, "y": y_sc2},
colors=[color],
marker="circle",
stroke="lightgray",
stroke=stroke_color,
unselected_style={"opacity": 0.1},
selected_style={"opacity": 1.0},
default_size=48, # Set a smaller default marker size
default_size=circle_size, # Set a smaller default marker size
display_legend=False,
labels=[cat], # Add the category label for the legend
labels=[
str(cat)
], # Add the category label for the legend
)
scatters.append(scatter)
additonal_scatters.append(scatters)
Expand All @@ -4272,7 +4292,9 @@ def features_change(change):
fig.axes = [
bq.Axis(scale=x_sc, label="Time"),
bq.Axis(
scale=y_sc2, orientation="vertical", label=selected_feature
scale=y_sc2,
orientation="vertical",
label=selected_feature,
),
]

Expand Down