summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Garcia Montoro <[email protected]>2015-05-09 18:04:26 +0200
committerAlejandro Garcia Montoro <[email protected]>2015-05-27 20:52:46 +0200
commit1b1cc4c77848a18c8d10f9a226908cfed9b63a62 (patch)
treed75f2311e2857be04591244887d2078e7fb72713
parent75e3f377dfce4a69a11ae6cf05ce4d505756c6d1 (diff)
Fixes bug related with zone labelling.
The previous code misbehaved when calculating longitude lines labels. Passing the longitude as a qreal to lonToString make that some lines get their zone label wrong (e.g., when passing -114, the function received -114.00000001 and returned the zone associated to [-120,-114[, not the one associated to [-114,-108[; i.e., it returned 11 instead of 12. The current code avoids this problem passing the longitude increased in 3 degrees (i.e., it does not pass the limit of the zone interval but the middle of it)
-rw-r--r--src/lib/marble/geodata/data/GeoDataCoordinates.cpp4
-rw-r--r--src/plugins/render/graticule/GraticulePlugin.cpp30
2 files changed, 29 insertions, 5 deletions
diff --git a/src/lib/marble/geodata/data/GeoDataCoordinates.cpp b/src/lib/marble/geodata/data/GeoDataCoordinates.cpp
index 9673f91..e6a8f1a 100644
--- a/src/lib/marble/geodata/data/GeoDataCoordinates.cpp
+++ b/src/lib/marble/geodata/data/GeoDataCoordinates.cpp
@@ -955,7 +955,7 @@ QString GeoDataCoordinates::lonToString( qreal lon, GeoDataCoordinates::Notation
{
if( notation == GeoDataCoordinates::UTM ){
/**
- * FIXME: UTM needs lon + lat to know zone number and easting
+ * @FIXME: UTM needs lon + lat to know zone number and easting
* By now, this code returns the zone+easting of the point
* (lon, equator), but this can differ a lot at different locations
*/
@@ -969,7 +969,7 @@ QString GeoDataCoordinates::lonToString( qreal lon, GeoDataCoordinates::Notation
if(precision > 0){
QString eastingString = QString::number( GeoDataCoordinatesPrivate::lonLatToEasting(lonRad, 0), 'f', 2 );
- result + QString(" %1 m E").arg(eastingString);
+ result += QString(" %1 m E").arg(eastingString);
}
return result;
diff --git a/src/plugins/render/graticule/GraticulePlugin.cpp b/src/plugins/render/graticule/GraticulePlugin.cpp
index 04c496c..0d5d2e1 100644
--- a/src/plugins/render/graticule/GraticulePlugin.cpp
+++ b/src/plugins/render/graticule/GraticulePlugin.cpp
@@ -596,6 +596,9 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
GeoDataCoordinates::Notation notation = marbleModel()->planet()->id() == "sky" ? GeoDataCoordinates::Astro :
GeoDataCoordinates::defaultNotation();
+ // Set precision to 0 in UTM in order to show only zone number.
+ int precision = (notation == GeoDataCoordinates::UTM) ? 0 : -1;
+
// Longitude
qreal westLon = viewLatLonAltBox.west( GeoDataCoordinates::Degree );
qreal eastLon = viewLatLonAltBox.east( GeoDataCoordinates::Degree );
@@ -607,9 +610,15 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
( westLon == -180.0 && eastLon == +180.0 ) ) {
qreal itStep = westLineLon;
+ if (notation == GeoDataCoordinates::UTM ){
+ /* Add 3 degrees (half of a UTM zone) to the actual longitude,
+ * in order to avoid fuzziness like -119.999999999
+ */
+ itStep += 3;
+ }
+
while ( itStep < eastLineLon ) {
// Create a matching label
- int precision = (notation == GeoDataCoordinates::UTM) ? 0 : -1;
QString label = GeoDataCoordinates::lonToString( itStep,
notation, GeoDataCoordinates::Degree,
precision, 'g' );
@@ -635,12 +644,19 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
else {
qreal itStep = eastLineLon;
+ if (notation == GeoDataCoordinates::UTM ){
+ /* Add 3 degrees (half of a UTM zone) to the actual longitude,
+ * in order to avoid fuzziness like -119.999999999
+ */
+ itStep += 3;
+ }
+
while ( itStep < 180.0 ) {
// Create a matching label
QString label = GeoDataCoordinates::lonToString( itStep,
notation, GeoDataCoordinates::Degree,
- -1, 'g' );
+ precision, 'g' );
// No additional labels for the prime meridian and the antimeridian
@@ -661,12 +677,20 @@ void GraticulePlugin::renderLongitudeLines( GeoPainter *painter,
}
itStep = -180.0;
+
+ if (notation == GeoDataCoordinates::UTM ){
+ /* Add 3 degrees (half of a UTM zone) to the actual longitude,
+ * in order to avoid fuzziness like -119.999999999
+ */
+ itStep += 3;
+ }
+
while ( itStep < westLineLon ) {
// Create a matching label
QString label = GeoDataCoordinates::lonToString( itStep,
notation, GeoDataCoordinates::Degree,
- -1, 'g' );
+ precision, 'g' );
// No additional labels for the prime meridian and the antimeridian
if ( labelPositionFlags.testFlag( LineCenter ) && ( itStep == 0.0 || itStep == 180.0 || itStep == -180.0 ) )