diff --git a/leafmap/maplibregl.py b/leafmap/maplibregl.py index bc812dbac2..b0bb28a36f 100644 --- a/leafmap/maplibregl.py +++ b/leafmap/maplibregl.py @@ -3635,7 +3635,12 @@ def add_gps_trace( raise FileNotFoundError(f"File not found: {data}") if isinstance(data, str): + tmp_file = os.path.splitext(data)[0] + "_tmp.csv" gdf = common.points_from_xy(data, x=x, y=y) + # If the temporary file exists, read the annotations from it + if os.path.exists(tmp_file): + df = pd.read_csv(tmp_file) + gdf[ann_column] = df[ann_column] elif isinstance(data, gpd.GeoDataFrame): gdf = data else: @@ -4587,6 +4592,7 @@ def features_change(change): def on_save_click(b): output.clear_output() download_widget.clear_output() + m.gdf.loc[m.gdf[ann_column_edited] == "selected", ann_column] = dropdown.value m.gdf.loc[m.gdf[ann_column_edited] == "selected", ann_column_edited] = ( dropdown.value @@ -4614,6 +4620,10 @@ def on_save_click(b): m.gdf[ann_column_edited] = m.gdf[ann_column] m.set_data(layer_name, m.gdf.__geo_interface__) + # Save the annotation to a temporary file + temp_file = os.path.splitext(filename)[0] + "_tmp.csv" + m.gdf[[ann_column]].to_csv(temp_file, index=False) + save.on_click(on_save_click) def on_export_click(b): @@ -4662,6 +4672,11 @@ def on_export_click(b): print(f"Saved CSV: {os.path.basename(output_csv)}") print(f"Saved GeoJSON: {os.path.basename(output_geojson)}") + # Remove the temporary file if it exists + tmp_file = os.path.splitext(filename)[0] + "_tmp.csv" + if os.path.exists(tmp_file): + os.remove(tmp_file) + export.on_click(on_export_click) def on_reset_click(b):