8484 PROFILES ,
8585 PREFERENCES ,
8686)
87- from ORStools .utils import maptools , configmanager , transform , gui , exceptions
87+ from ORStools .utils import maptools , configmanager , gui , exceptions
8888from .ORStoolsDialogConfig import ORStoolsDialogConfigMain
8989
9090MAIN_WIDGET , _ = uic .loadUiType (gui .GuiUtils .get_ui_file_path ("ORStoolsDialogUI.ui" ))
@@ -415,6 +415,9 @@ def __init__(self, iface: QgisInterface, parent=None) -> None:
415415 lambda : self .color_duplicate_items (self .routing_fromline_list )
416416 )
417417
418+ self .last_crs = self .canvas .mapSettings ().destinationCrs ()
419+ self .canvas .destinationCrsChanged .connect (self ._on_crs_changed )
420+
418421 self .load_provider_combo_state ()
419422 self .provider_combo .activated .connect (self .save_selected_provider_state )
420423
@@ -435,6 +438,7 @@ def _save_vertices_to_layer(self) -> None:
435438 self .routing_fromline_list .item (x ).text ()
436439 for x in range (self .routing_fromline_list .count ())
437440 ]
441+ map_crs = self ._iface .mapCanvas ().mapSettings ().destinationCrs ()
438442
439443 if len (items ) > 0 :
440444 timestamp = datetime .now ().strftime ("%Y-%m-%d_%H:%M:%S" )
@@ -450,6 +454,7 @@ def _save_vertices_to_layer(self) -> None:
450454 feature .setAttributes ([idx ])
451455
452456 point_layer .dataProvider ().addFeature (feature )
457+ point_layer .setCrs (map_crs )
453458 QgsProject .instance ().addMapLayer (point_layer )
454459 self .canvas .refresh ()
455460
@@ -530,11 +535,7 @@ def _on_linetool_init(self) -> None:
530535
531536 def create_vertex (self , point , idx ):
532537 """Adds an item to QgsListWidget and annotates the point in the map canvas"""
533- map_crs = self .canvas .mapSettings ().destinationCrs ()
534-
535- transformer = transform .transformToWGS (map_crs )
536- point_wgs = transformer .transform (point )
537- self .routing_fromline_list .addItem (f"Point { idx } : { point_wgs .x ():.6f} , { point_wgs .y ():.6f} " )
538+ self .routing_fromline_list .addItem (f"Point { idx } : { point .x ():.6f} , { point .y ():.6f} " )
538539
539540 crs = self .canvas .mapSettings ().destinationCrs ()
540541 annotation = self ._linetool_annotate_point (point , idx , crs )
@@ -549,17 +550,20 @@ def _reindex_list_items(self) -> None:
549550 ]
550551 self .routing_fromline_list .clear ()
551552 self ._clear_annotations ()
552- crs = QgsCoordinateReferenceSystem (f"EPSG:{ 4326 } " )
553553 project_crs = self .canvas .mapSettings ().destinationCrs ()
554- for idx , x in enumerate (items ):
555- coords = x .split (":" )[1 ]
556- item = f"Point { idx } :{ coords } "
557- x , y = (float (i ) for i in coords .split (", " ))
554+ for idx , origin in enumerate (items ):
555+ origin_coords = origin .split (":" )[1 ]
556+ x , y = (float (i ) for i in origin_coords .split (", " ))
558557 point = QgsPointXY (x , y )
559558
560- self .routing_fromline_list . addItem ( item )
561- transform = QgsCoordinateTransform ( crs , project_crs , QgsProject . instance ())
559+ transform = QgsCoordinateTransform ( self .last_crs , project_crs , QgsProject . instance () )
560+
562561 point = transform .transform (point )
562+
563+ coords = f"{ point .x ():.6f} , { point .y ():.6f} "
564+ item = f"Point { idx } : { coords } "
565+ self .routing_fromline_list .addItem (item )
566+
563567 annotation = self ._linetool_annotate_point (point , idx )
564568 self .annotations .append (annotation )
565569 self .project .annotationManager ().addAnnotation (annotation )
@@ -606,3 +610,8 @@ def show(self):
606610 """Load the saved state when the window is shown"""
607611 super ().show ()
608612 self .load_provider_combo_state ()
613+
614+ def _on_crs_changed (self ) -> None :
615+ """Handle CRS change event."""
616+ self ._reindex_list_items ()
617+ self .last_crs = self .canvas .mapSettings ().destinationCrs ()
0 commit comments