summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-07-23 13:13:03 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-07-23 14:10:40 (GMT)
commit0a8a426f05e364501ff3feb1580a4d31b138da75 (patch)
tree2093199c6e8265cdab96b19290ccd82bb7c439f6
parent37a937f791d892728838068212d9bd4c85ee1ee5 (diff)
Add whichBuildingAt with a similar purpose to whichFeatureAt
-rw-r--r--src/lib/marble/MarbleMap.cpp5
-rw-r--r--src/lib/marble/MarbleMap.h2
-rw-r--r--src/lib/marble/layers/GeometryLayer.cpp29
-rw-r--r--src/lib/marble/layers/GeometryLayer.h2
4 files changed, 38 insertions, 0 deletions
diff --git a/src/lib/marble/MarbleMap.cpp b/src/lib/marble/MarbleMap.cpp
index fe4ea7f..0df7dd3 100644
--- a/src/lib/marble/MarbleMap.cpp
+++ b/src/lib/marble/MarbleMap.cpp
@@ -505,6 +505,11 @@ QVector<const GeoDataFeature*> MarbleMap::whichFeatureAt( const QPoint& curpos )
return d->m_placemarkLayer.whichPlacemarkAt( curpos ) + d->m_geometryLayer.whichFeatureAt( curpos, viewport() );
}
+QVector<const GeoDataFeature*> MarbleMap::whichBuildingAt(const QPoint& curpos) const
+{
+ return d->m_geometryLayer.whichBuildingAt(curpos, viewport());
+}
+
void MarbleMap::reload()
{
d->m_textureLayer.reload();
diff --git a/src/lib/marble/MarbleMap.h b/src/lib/marble/MarbleMap.h
index 34ded24..8efb997 100644
--- a/src/lib/marble/MarbleMap.h
+++ b/src/lib/marble/MarbleMap.h
@@ -222,6 +222,8 @@ class MARBLE_EXPORT MarbleMap : public QObject
QVector<const GeoDataFeature *> whichFeatureAt( const QPoint& ) const;
+ QVector<const GeoDataFeature*> whichBuildingAt(const QPoint& curpos) const;
+
/**
* @brief Return the property value by name.
* @return The property value (usually: visibility).
diff --git a/src/lib/marble/layers/GeometryLayer.cpp b/src/lib/marble/layers/GeometryLayer.cpp
index 947ddfe..3f2b761 100644
--- a/src/lib/marble/layers/GeometryLayer.cpp
+++ b/src/lib/marble/layers/GeometryLayer.cpp
@@ -425,6 +425,35 @@ QVector<const GeoDataFeature*> GeometryLayer::whichFeatureAt(const QPoint &curpo
return result;
}
+QVector<const GeoDataFeature *> GeometryLayer::whichBuildingAt(const QPoint &curpos, const ViewportParams *viewport)
+{
+ QVector<const GeoDataFeature*> result;
+ qreal lon, lat;
+ if (!viewport->geoCoordinates(curpos.x(), curpos.y(), lon, lat, GeoDataCoordinates::Radian)) {
+ return result;
+ }
+ GeoDataCoordinates const coordinates = GeoDataCoordinates(lon, lat);
+
+ const int maxZoom = qMin<int>(qMax<int>(qLn(viewport->radius()*4/256)/qLn(2.0), 1), d->m_styleBuilder->maximumZoomLevel());
+ foreach ( GeoGraphicsItem * item, d->m_scene.items( viewport->viewLatLonAltBox(), maxZoom ) ) {
+ if (item->feature()->visualCategory() == GeoDataFeature::Building && item->feature()->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
+ const GeoDataPlacemark* placemark = static_cast<const GeoDataPlacemark*>(item->feature());
+ if (placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType) {
+ const GeoDataPolygon *polygon = static_cast<const GeoDataPolygon*>(placemark->geometry());
+ if (polygon->contains(coordinates)) {
+ result << item->feature();
+ }
+ } else if (placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
+ const GeoDataLinearRing *ring = static_cast<const GeoDataLinearRing*>(placemark->geometry());
+ if (ring->contains(coordinates)) {
+ result << item->feature();
+ }
+ }
+ }
+ }
+ return result;
+}
+
void GeometryLayer::handleHighlight( qreal lon, qreal lat, GeoDataCoordinates::Unit unit )
{
GeoDataCoordinates clickedPoint( lon, lat, 0, unit );
diff --git a/src/lib/marble/layers/GeometryLayer.h b/src/lib/marble/layers/GeometryLayer.h
index 6c925f1..217225a 100644
--- a/src/lib/marble/layers/GeometryLayer.h
+++ b/src/lib/marble/layers/GeometryLayer.h
@@ -50,6 +50,8 @@ public:
QVector<const GeoDataFeature*> whichFeatureAt( const QPoint& curpos, const ViewportParams * viewport );
+ QVector<const GeoDataFeature*> whichBuildingAt(const QPoint& curpos, const ViewportParams * viewport);
+
public Q_SLOTS:
void addPlacemarks( const QModelIndex& index, int first, int last );
void removePlacemarks( const QModelIndex& index, int first, int last );