From df49a6e07df23e4475cf4d136fb2cb92a312a1cf Mon Sep 17 00:00:00 2001 From: VitorVieiraZ Date: Fri, 23 Aug 2024 11:12:49 -0300 Subject: [PATCH] new properties --- app/maptools/measurementmaptool.cpp | 15 ++++++++++----- app/maptools/measurementmaptool.h | 3 +++ app/qml/map/MMMeasurementTools.qml | 20 +++++++------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/maptools/measurementmaptool.cpp b/app/maptools/measurementmaptool.cpp index f1db80c7aa..a95419141e 100644 --- a/app/maptools/measurementmaptool.cpp +++ b/app/maptools/measurementmaptool.cpp @@ -86,9 +86,11 @@ double MeasurementMapTool::updateDistance( const QgsPoint &crosshairPoint ) QgsPoint lastPoint = mPoints.last(); - double distance = QgsDistanceArea().measureLine( crosshairPoint, lastPoint ); + QgsDistanceArea mDistanceArea; + mDistanceArea.setEllipsoid( QStringLiteral( "WGS84" ) ); + mDistanceArea.setSourceCrs( mapSettings()->destinationCrs(), mapSettings()->transformContext() ); - return distance; + return mDistanceArea.measureLine( crosshairPoint, lastPoint ); } void MeasurementMapTool::closeShape() @@ -106,9 +108,12 @@ void MeasurementMapTool::closeShape() setRecordedGeometry( polygonGeometry ); - QgsDistanceArea distanceArea; - double area = distanceArea.measureArea( polygonGeometry ); - double perimeter = distanceArea.measurePerimeter( polygonGeometry ); + QgsDistanceArea mDistanceArea; + mDistanceArea.setEllipsoid( QStringLiteral( "WGS84" ) ); + mDistanceArea.setSourceCrs( mapSettings()->destinationCrs(), mapSettings()->transformContext() ); + + double area = mDistanceArea.measureArea( polygonGeometry ); + double perimeter = mDistanceArea.measurePerimeter( polygonGeometry ); emit shapeAreaAndPerimeter( area , perimeter ); emit canCloseShape( false ); diff --git a/app/maptools/measurementmaptool.h b/app/maptools/measurementmaptool.h index d56e9bf933..01904ad8f0 100644 --- a/app/maptools/measurementmaptool.h +++ b/app/maptools/measurementmaptool.h @@ -49,6 +49,9 @@ class MeasurementMapTool : public AbstractMapTool const QgsGeometry &recordedGeometry() const; void setRecordedGeometry( const QgsGeometry &newRecordedGeometry ); + QgsVectorLayer *activeLayer() const; + void setActiveLayer( QgsVectorLayer *newActiveLayer ); + signals: void recordedGeometryChanged( const QgsGeometry &recordedGeometry ); diff --git a/app/qml/map/MMMeasurementTools.qml b/app/qml/map/MMMeasurementTools.qml index 3bb9f55fc3..32e52a1f9a 100644 --- a/app/qml/map/MMMeasurementTools.qml +++ b/app/qml/map/MMMeasurementTools.qml @@ -25,21 +25,18 @@ Item { signal finishMeasurement() + Component.onCompleted: map.mapSettings.extentChanged.connect( onScreenPositionChanged ) + Component.onDestruction: map.mapSettings.extentChanged.disconnect( onScreenPositionChanged ) + MM.MeasurementMapTool { id: mapTool mapSettings: root.map.mapSettings - onCanCloseShape: function( canClose ) { - measurePanel.canCloseShape = canClose; - } - + onCanCloseShape: function( canClose ) { measurePanel.canCloseShape = canClose; } + onCanUndo: function( canUndo ) { measurePanel.canUndo = canUndo; } onShapeAreaAndPerimeter: function( area, perimeter) { - measurePanel.area = area.toFixed( 1 ) + " m²";; - measurePanel.perimeter = perimeter.toFixed( 1 ) + " m";; - } - - onCanUndo: function( canUndo ) { - measurePanel.canUndo = canUndo; + measurePanel.area = area.toFixed( 1 ) + " m²"; + measurePanel.perimeter = perimeter.toFixed( 1 ) + " m"; } } @@ -147,7 +144,4 @@ Item { measurePanel.canCloseShape = false mapTool.repeat() } - - - Component.onCompleted: map.mapSettings.extentChanged.connect( onScreenPositionChanged ) }