[Marble-commits] branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data
Patrick Spendrin
ps_ml at gmx.de
Mon Jul 13 23:56:59 CEST 2009
SVN commit 996142 by sengels:
fix centering of Placemarks which do not have a coordinate by using the center of the latlonaltbox
BUG:200052
M +12 -0 GeoDataLatLonAltBox.cpp
M +6 -0 GeoDataLatLonAltBox.h
M +10 -0 GeoDataLatLonBox.cpp
M +6 -0 GeoDataLatLonBox.h
M +23 -3 GeoDataPlacemark.cpp
--- branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data/GeoDataLatLonAltBox.cpp #996141:996142
@@ -113,6 +113,18 @@
return d->m_altitudeMode;
}
+GeoDataCoordinates GeoDataLatLonAltBox::center() const
+{
+ if( crossesDateLine() )
+ return GeoDataCoordinates( east() + 2 * M_PI - (east() + 2 * M_PI - west()) / 2,
+ north() - (north() - south()) / 2,
+ d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
+ else
+ return GeoDataCoordinates( east() - (east() - west()) / 2,
+ north() - (north() - south()) / 2,
+ d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
+}
+
void GeoDataLatLonAltBox::setAltitudeMode( const AltitudeMode altitudeMode )
{
d->m_altitudeMode = altitudeMode;
--- branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data/GeoDataLatLonAltBox.h #996141:996142
@@ -105,6 +105,12 @@
*/
bool isNull() const;
+ /**
+ * @brief returns the center of this box
+ * @return a coordinate, body-center of the box
+ */
+ virtual GeoDataCoordinates center() const;
+
/// Serialize the contents of the feature to @p stream.
virtual void pack( QDataStream& stream ) const;
/// Unserialize the contents of the feature from @p stream.
--- branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data/GeoDataLatLonBox.cpp #996141:996142
@@ -255,6 +255,16 @@
return false;
}
+GeoDataCoordinates GeoDataLatLonBox::center() const
+{
+ if( crossesDateLine() )
+ return GeoDataCoordinates( east() + 2 * M_PI - (east() + 2 * M_PI - west()) / 2,
+ north() - (north() - south()) / 2 );
+ else
+ return GeoDataCoordinates( east() - (east() - west()) / 2,
+ north() - (north() - south()) / 2 );
+}
+
bool GeoDataLatLonBox::containsPole( Marble::Pole pole ) const
{
switch ( pole ) {
--- branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data/GeoDataLatLonBox.h #996141:996142
@@ -112,6 +112,12 @@
bool crossesDateLine() const;
/**
+ * @brief returns the center of this box
+ * @return a coordinate, face-center of the box
+ */
+ virtual GeoDataCoordinates center() const;
+
+ /**
* @brief Detect whether the bounding box contains one of the poles.
* @return @c true the bounding box contains one of the poles.
* @c false the bounding box doesn't contain one of the poles.
--- branches/KDE/4.3/kdeedu/marble/src/lib/geodata/data/GeoDataPlacemark.cpp #996141:996142
@@ -67,13 +67,33 @@
GeoDataCoordinates GeoDataPlacemark::coordinate() const
{
- return static_cast<GeoDataCoordinates>( p()->m_coordinate );
+ if( p()->m_geometry &&
+ ( p()->m_geometry->geometryId() == GeoDataLineStringId ||
+ p()->m_geometry->geometryId() == GeoDataLinearRingId ) ) {
+ return GeoDataLatLonAltBox::fromLineString( *p()->m_geometry ).center();
+ } else if( p()->m_geometry && p()->m_geometry->geometryId() == GeoDataPolygonId ) {
+ return GeoDataLatLonAltBox::fromLineString( static_cast<GeoDataPolygon*>(p()->m_geometry)->outerBoundary() ).center();
+ } else {
+ return static_cast<GeoDataCoordinates>( p()->m_coordinate );
+ }
}
void GeoDataPlacemark::coordinate( qreal& lon, qreal& lat, qreal& alt ) const
{
- p()->m_coordinate.geoCoordinates( lon, lat );
- alt = p()->m_coordinate.altitude();
+ if( p()->m_geometry &&
+ ( p()->m_geometry->geometryId() == GeoDataLineStringId ||
+ p()->m_geometry->geometryId() == GeoDataLinearRingId ) ) {
+ const GeoDataCoordinates coord = GeoDataLatLonAltBox::fromLineString( *p()->m_geometry ).center();
+ coord.geoCoordinates( lon, lat );
+ alt = coord.altitude();
+ } else if( p()->m_geometry && p()->m_geometry->geometryId() == GeoDataPolygonId ) {
+ const GeoDataCoordinates coord = GeoDataLatLonAltBox::fromLineString( static_cast<GeoDataPolygon*>(p()->m_geometry)->outerBoundary() ).center();
+ coord.geoCoordinates( lon, lat );
+ alt = coord.altitude();
+ } else {
+ p()->m_coordinate.geoCoordinates( lon, lat );
+ alt = p()->m_coordinate.altitude();
+ }
}
void GeoDataPlacemark::setCoordinate( qreal lon, qreal lat, qreal alt )
More information about the Marble-commits
mailing list