Skip to content

Commit

Permalink
Use map width instead of diagonal for scale bar calculation based on …
Browse files Browse the repository at this point in the history
…ellipsoid (because scale is often depending on direction)
  • Loading branch information
mhugent committed Aug 23, 2012
1 parent 15b46e6 commit 0c1aa34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/core/composer/qgscomposerscalebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerscalebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit 0c1aa34

@homann
Copy link
Contributor

@homann homann commented on 0c1aa34 Aug 23, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.