Skip to content

Commit

Permalink
fix: annotations stay after saving
Browse files Browse the repository at this point in the history
  • Loading branch information
merydian committed Mar 4, 2024
1 parent db0dcad commit 9d7964f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ def __init__(self, iface, parent=None):
self.routing_fromline_list.model().rowsMoved.connect(self._reindex_list_items)
self.routing_fromline_list.model().rowsRemoved.connect(self._reindex_list_items)

self.annotation_canvas = self._iface.mapCanvas()

def _save_vertices_to_layer(self):
"""Saves the vertices list to a temp layer"""
items = [
Expand Down Expand Up @@ -526,11 +528,12 @@ def _linetool_annotate_point(self, point, idx, crs=None):
annotation.setMapPosition(point)
annotation.setMapPositionCrs(crs)

return QgsMapCanvasAnnotationItem(annotation, self._iface.mapCanvas()).annotation()
return QgsMapCanvasAnnotationItem(annotation, self.annotation_canvas).annotation()

def _clear_annotations(self):
"""Clears annotations"""
for annotation in self.annotations:
for annotation_item in self.annotation_canvas.annotationItems():
annotation = annotation_item.annotation()
if annotation in self.project.annotationManager().annotations():
self.project.annotationManager().removeAnnotation(annotation)
self.annotations = []
Expand Down Expand Up @@ -562,7 +565,6 @@ def _on_linetool_map_click(self, point, idx):
self.routing_fromline_list.addItem(f"Point {idx}: {point_wgs.x():.6f}, {point_wgs.y():.6f}")

annotation = self._linetool_annotate_point(point, idx)
self.annotations.append(annotation)
self.project.annotationManager().addAnnotation(annotation)

def _reindex_list_items(self):
Expand All @@ -582,7 +584,6 @@ def _reindex_list_items(self):

self.routing_fromline_list.addItem(item)
annotation = self._linetool_annotate_point(point, idx, crs)
self.annotations.append(annotation)
self.project.annotationManager().addAnnotation(annotation)

def _on_linetool_map_doubleclick(self):
Expand Down

0 comments on commit 9d7964f

Please sign in to comment.