GeoDataLatLonAltBox EquirectProjection::latLonAltBox( const QRect& screenRect, const ViewportParams *viewport ) const { qreal west; qreal north = 90*DEG2RAD; geoCoordinates( screenRect.left(), screenRect.top(), viewport, west, north, GeoDataCoordinates::Radian ); qreal east; qreal south = -90*DEG2RAD; geoCoordinates( screenRect.right(), screenRect.bottom(), viewport, east, south, GeoDataCoordinates::Radian ); // For the case where the whole viewport gets covered there is a // pretty dirty and generic detection algorithm: GeoDataLatLonAltBox latLonAltBox; latLonAltBox.setNorth( north, GeoDataCoordinates::Radian ); latLonAltBox.setSouth( south, GeoDataCoordinates::Radian ); latLonAltBox.setWest( west, GeoDataCoordinates::Radian ); latLonAltBox.setEast( east, GeoDataCoordinates::Radian ); latLonAltBox.setMinAltitude( -100000000.0 ); latLonAltBox.setMaxAltitude( 100000000000000.0 ); // Convenience variables int radius = viewport->radius(); int width = viewport->width(); // The remaining algorithm should be pretty generic for all kinds of // flat projections: int xRepeatDistance = 4 * radius; if ( width >= xRepeatDistance ) { latLonAltBox.setWest( -M_PI ); latLonAltBox.setEast( +M_PI ); } // Now we need to check whether maxLat (e.g. the north pole) gets displayed // inside the viewport. // We need a point on the screen at maxLat that definitely gets displayed: qreal averageLongitude = latLonAltBox.east(); GeoDataCoordinates maxLatPoint( averageLongitude, maxLat(), 0.0, GeoDataCoordinates::Radian ); GeoDataCoordinates minLatPoint( averageLongitude, minLat(), 0.0, GeoDataCoordinates::Radian ); qreal dummyX, dummyY; // not needed if ( screenCoordinates( maxLatPoint, viewport, dummyX, dummyY ) ) { latLonAltBox.setEast( +M_PI ); latLonAltBox.setWest( -M_PI ); } if ( screenCoordinates( minLatPoint, viewport, dummyX, dummyY ) ) { latLonAltBox.setEast( +M_PI ); latLonAltBox.setWest( -M_PI ); } return latLonAltBox; }
void TestGeoDataLatLonAltBox::testAltitude() { QFETCH(qreal, alt); GeoDataLatLonAltBox box; box.setMinAltitude(alt); QCOMPARE(box.minAltitude(), alt); box.setMaxAltitude(alt); QCOMPARE(box.maxAltitude(), alt); }
GeoDataLatLonAltBox GeoDataLatLonAltBox::fromLineString( const GeoDataLineString& lineString ) { // If the line string is empty return a boundingbox that contains everything if ( lineString.size() == 0 ) { return GeoDataLatLonAltBox(); } const qreal altitude = lineString.first().altitude(); GeoDataLatLonAltBox temp ( GeoDataLatLonBox::fromLineString( lineString ), altitude, altitude ); qreal maxAltitude = altitude; qreal minAltitude = altitude; // If there's only a single node stored then the boundingbox only contains that point if ( lineString.size() == 1 ) { temp.setMinAltitude( minAltitude ); temp.setMaxAltitude( maxAltitude ); return temp; } QVector<GeoDataCoordinates>::ConstIterator it( lineString.constBegin() ); QVector<GeoDataCoordinates>::ConstIterator itEnd( lineString.constEnd() ); for ( ; it != itEnd; ++it ) { // Get coordinates and normalize them to the desired range. const qreal altitude = (it)->altitude(); // Determining the maximum and minimum latitude if ( altitude > maxAltitude ) maxAltitude = altitude; if ( altitude < minAltitude ) minAltitude = altitude; } temp.setMinAltitude( minAltitude ); temp.setMaxAltitude( maxAltitude ); return temp; }