Skip to content

Commit 0c1aa34

Browse files
committedAug 23, 2012
Use map width instead of diagonal for scale bar calculation based on ellipsoid (because scale is often depending on direction)
1 parent 15b46e6 commit 0c1aa34

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed
 

‎src/core/composer/qgscomposerscalebar.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,11 @@ void QgsComposerScaleBar::refreshSegmentMillimeters()
168168
QRectF composerItemRect = mComposerMap->rect();
169169

170170
//calculate size depending on mNumUnitsPerSegment
171-
double itemDiagonal = sqrt( composerItemRect.width() * composerItemRect.width() + composerItemRect.height() * composerItemRect.height() );
172-
mSegmentMillimeters = itemDiagonal / mapDiagonal() * mNumUnitsPerSegment;
171+
mSegmentMillimeters = composerItemRect.width() / mapWidth() * mNumUnitsPerSegment;
173172
}
174173
}
175174

176-
double QgsComposerScaleBar::mapDiagonal() const
175+
double QgsComposerScaleBar::mapWidth() const
177176
{
178177
if ( !mComposerMap )
179178
{
@@ -183,7 +182,7 @@ double QgsComposerScaleBar::mapDiagonal() const
183182
QgsRectangle composerMapRect = mComposerMap->extent();
184183
if ( mUnits == MapUnits )
185184
{
186-
return sqrt( composerMapRect.width() * composerMapRect.width() + composerMapRect.height() * composerMapRect.height() );
185+
return composerMapRect.width();
187186
}
188187
else
189188
{
@@ -192,7 +191,7 @@ double QgsComposerScaleBar::mapDiagonal() const
192191
da.setSourceCrs( mComposerMap->mapRenderer()->destinationCrs().srsid() );
193192
QSettings s;
194193
da.setEllipsoid( s.value( "/qgis/measure/ellipsoid", "WGS84" ).toString() );
195-
double measure = da.measureLine( QgsPoint( composerMapRect.xMinimum(), composerMapRect.yMaximum() ), QgsPoint( composerMapRect.xMaximum(), composerMapRect.yMinimum() ) );
194+
double measure = da.measureLine( QgsPoint( composerMapRect.xMinimum(), composerMapRect.yMinimum() ), QgsPoint( composerMapRect.xMaximum(), composerMapRect.yMinimum() ) );
196195
if ( mUnits == Feet )
197196
{
198197
measure /= 0.3048;

‎src/core/composer/qgscomposerscalebar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
199199
void refreshSegmentMillimeters();
200200

201201
/**Returns diagonal of composer map in selected units (map units / meters / feet)*/
202-
double mapDiagonal() const;
202+
double mapWidth() const;
203203
};
204204

205205
#endif //QGSCOMPOSERSCALEBAR_H

1 commit comments

Comments
 (1)

homann commented on Aug 23, 2012

@homann
Contributor

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.