Commit 0a8a426f authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Add whichBuildingAt with a similar purpose to whichFeatureAt

parent 37a937f7
......@@ -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();
......
......@@ -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).
......
......@@ -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 );
......
......@@ -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 );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment