Skip to content
Permalink
Browse files

Use map width instead of diagonal for scale bar calculation based on …

…ellipsoid (because scale is often depending on direction)
  • Loading branch information
mhugent committed Aug 23, 2012
1 parent 15b46e6 commit 0c1aa34b1d4dbe374ec7b7616c7aefe52d54b82a
Showing with 5 additions and 6 deletions.
  1. +4 −5 src/core/composer/qgscomposerscalebar.cpp
  2. +1 −1 src/core/composer/qgscomposerscalebar.h
@@ -168,12 +168,11 @@ void QgsComposerScaleBar::refreshSegmentMillimeters()
QRectF composerItemRect = mComposerMap->rect();

//calculate size depending on mNumUnitsPerSegment
double itemDiagonal = sqrt( composerItemRect.width() * composerItemRect.width() + composerItemRect.height() * composerItemRect.height() );
mSegmentMillimeters = itemDiagonal / mapDiagonal() * mNumUnitsPerSegment;
mSegmentMillimeters = composerItemRect.width() / mapWidth() * mNumUnitsPerSegment;
}
}

double QgsComposerScaleBar::mapDiagonal() const
double QgsComposerScaleBar::mapWidth() const
{
if ( !mComposerMap )
{
@@ -183,7 +182,7 @@ double QgsComposerScaleBar::mapDiagonal() const
QgsRectangle composerMapRect = mComposerMap->extent();
if ( mUnits == MapUnits )
{
return sqrt( composerMapRect.width() * composerMapRect.width() + composerMapRect.height() * composerMapRect.height() );
return composerMapRect.width();
}
else
{
@@ -192,7 +191,7 @@ double QgsComposerScaleBar::mapDiagonal() const
da.setSourceCrs( mComposerMap->mapRenderer()->destinationCrs().srsid() );
QSettings s;
da.setEllipsoid( s.value( "/qgis/measure/ellipsoid", "WGS84" ).toString() );
double measure = da.measureLine( QgsPoint( composerMapRect.xMinimum(), composerMapRect.yMaximum() ), QgsPoint( composerMapRect.xMaximum(), composerMapRect.yMinimum() ) );
double measure = da.measureLine( QgsPoint( composerMapRect.xMinimum(), composerMapRect.yMinimum() ), QgsPoint( composerMapRect.xMaximum(), composerMapRect.yMinimum() ) );
if ( mUnits == Feet )
{
measure /= 0.3048;
@@ -199,7 +199,7 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
void refreshSegmentMillimeters();

/**Returns diagonal of composer map in selected units (map units / meters / feet)*/
double mapDiagonal() const;
double mapWidth() const;
};

#endif //QGSCOMPOSERSCALEBAR_H

1 comment on commit 0c1aa34

@homann

This comment has been minimized.

Copy link
Contributor

@homann homann commented on 0c1aa34 Aug 23, 2012

If the map is big enough, the scale is very different on different parts of the map. In other places in the code, scale is calculated in the center. Maybe we should use the same method everywhere

Please sign in to comment.
You can’t perform that action at this time.