summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-09-14 18:00:49 (GMT)
committerBernhard Beschow <bbeschow@cs.tu-berlin.de>2016-10-03 14:41:32 (GMT)
commitb1a507ba5d9e2386bc2dd4b2432569910a5e030e (patch)
tree63a0f0aeaebf23a4d174110244cf7cb4f29ee9c1
parente2e3e1989783c8b5640ad703e2d7001d87f05dcc (diff)
have polygon and linear ring icons rendered by PlacemarkLayer
* makes the icons clickable, i.e. a placemark dialg can be shown
-rw-r--r--src/lib/marble/geodata/data/GeoDataPlacemark.cpp10
-rw-r--r--src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp45
-rw-r--r--src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h2
-rw-r--r--src/plugins/runner/osm/OsmWay.cpp6
4 files changed, 14 insertions, 49 deletions
diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
index bc658de..056df65 100644
--- a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
+++ b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
@@ -269,16 +269,20 @@ GeoDataCoordinates GeoDataPlacemark::coordinate( const QDateTime &dateTime, bool
if( p()->m_geometry ) {
// Beware: comparison between pointers, not strings.
- if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPointType ) {
+ if (p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPointType
+ || p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPolygonType
+ || p()->m_geometry->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
hasIcon = true;
- coord = static_cast<const GeoDataPoint *>( p()->m_geometry )->coordinates();
+ coord = p()->m_geometry->latLonAltBox().center();
} else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
const GeoDataMultiGeometry *multiGeometry = static_cast<const GeoDataMultiGeometry *>( p()->m_geometry );
QVector<GeoDataGeometry*>::ConstIterator it = multiGeometry->constBegin();
QVector<GeoDataGeometry*>::ConstIterator end = multiGeometry->constEnd();
for ( ; it != end; ++it ) {
- if ( (*it)->nodeType() == GeoDataTypes::GeoDataPointType ) {
+ if ((*it)->nodeType() == GeoDataTypes::GeoDataPointType
+ || (*it)->nodeType() == GeoDataTypes::GeoDataPolygonType
+ || (*it)->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
hasIcon = true;
break;
}
diff --git a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp
index e9f73d3..a44fa2a 100644
--- a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp
+++ b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.cpp
@@ -29,7 +29,6 @@ BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataPlac
const GeoDataPolygon *polygon)
: AbstractGeoPolygonGraphicsItem(placemark, polygon)
, m_buildingHeight(polygon->latLonAltBox().maxAltitude() - polygon->latLonAltBox().minAltitude())
- , m_buildingLabel(extractBuildingLabel(*placemark))
, m_entries(extractNamedEntries(*placemark))
{
setZValue(this->zValue() + m_buildingHeight);
@@ -45,7 +44,6 @@ BuildingGeoPolygonGraphicsItem::BuildingGeoPolygonGraphicsItem(const GeoDataPlac
const GeoDataLinearRing* ring)
: AbstractGeoPolygonGraphicsItem(placemark, ring)
, m_buildingHeight(ring->latLonAltBox().maxAltitude() - ring->latLonAltBox().minAltitude())
- , m_buildingLabel(extractBuildingLabel(*placemark))
, m_entries(extractNamedEntries(*placemark))
{
setZValue(this->zValue() + m_buildingHeight);
@@ -135,27 +133,6 @@ QPointF BuildingGeoPolygonGraphicsItem::buildingOffset(const QPointF &point, con
return QPointF(shiftX, shiftY);
}
-QString BuildingGeoPolygonGraphicsItem::extractBuildingLabel(const GeoDataPlacemark &placemark)
-{
- if (!placemark.name().isEmpty()) {
- return placemark.name();
- }
-
- const OsmPlacemarkData &osmData = placemark.osmData();
-
- auto tagIter = osmData.findTag(QStringLiteral("addr:housename"));
- if (tagIter != osmData.tagsEnd()) {
- return tagIter.value();
- }
-
- tagIter = osmData.findTag(QStringLiteral("addr:housenumber"));
- if (tagIter != osmData.tagsEnd()) {
- return tagIter.value();
- }
-
- return QString();
-}
-
QVector<BuildingGeoPolygonGraphicsItem::NamedEntry> BuildingGeoPolygonGraphicsItem::extractNamedEntries(const GeoDataPlacemark &placemark)
{
QVector<NamedEntry> entries;
@@ -200,7 +177,6 @@ void BuildingGeoPolygonGraphicsItem::paintRoof(GeoPainter* painter, const Viewpo
painter->save();
QPen const currentPen = configurePainter(painter, viewport);
- bool const hasIcon = !style()->iconStyle().iconPath().isEmpty();
qreal maxSize(0.0);
QPointF roofCenter;
@@ -214,7 +190,7 @@ void BuildingGeoPolygonGraphicsItem::paintRoof(GeoPainter* painter, const Viewpo
foreach(QPolygonF* outlinePolygon, outlinePolygons) {
QRectF const boundingRect = outlinePolygon->boundingRect();
QPolygonF buildingRoof;
- if (hasIcon || !m_buildingLabel.isEmpty() || !m_entries.isEmpty()) {
+ if (!m_entries.isEmpty()) {
QSizeF const polygonSize = boundingRect.size();
qreal size = polygonSize.width() * polygonSize.height();
if (size > maxSize) {
@@ -258,25 +234,6 @@ void BuildingGeoPolygonGraphicsItem::paintRoof(GeoPainter* painter, const Viewpo
painter->drawPolygon(*outlinePolygon);
painter->translate(-offset);
}
-
- if (hasIcon && !roofCenter.isNull()) {
- QImage const icon = style()->iconStyle().scaledIcon();
- QPointF const iconCenter(icon.size().width()/2.0, icon.size().height()/2.0);
- painter->drawImage(roofCenter-iconCenter, icon);
- } else if (drawAccurate3D && !m_buildingLabel.isEmpty() && !roofCenter.isNull()) {
- double const w2 = 0.5 * painter->fontMetrics().width(m_buildingLabel);
- double const ascent = painter->fontMetrics().ascent();
- double const descent = painter->fontMetrics().descent();
- double const a2 = 0.5 * painter->fontMetrics().ascent();
- QPointF const textPosition = roofCenter - QPointF(w2, -a2);
- if (buildingRoof.containsPoint(textPosition + QPointF(-2, -ascent), Qt::OddEvenFill)
- && buildingRoof.containsPoint(textPosition + QPointF(-2, descent), Qt::OddEvenFill)
- && buildingRoof.containsPoint(textPosition + QPointF(2+2*w2, descent), Qt::OddEvenFill)
- && buildingRoof.containsPoint(textPosition + QPointF(2+2*w2, -ascent), Qt::OddEvenFill)
- ) {
- painter->drawText(textPosition, m_buildingLabel);
- }
- }
}
// Render additional housenumbers at building entries
diff --git a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h
index bb7a662..64f7d6e 100644
--- a/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h
+++ b/src/lib/marble/geodata/graphicsitem/BuildingGeoPolygonGraphicsItem.h
@@ -46,12 +46,10 @@ private:
static QPointF centroid(const QPolygonF &polygon, double &area);
static void screenPolygons(const ViewportParams *viewport, const GeoDataPolygon* polygon,
QVector<QPolygonF*> &polygons, QVector<QPolygonF*> &outlines);
- static QString extractBuildingLabel(const GeoDataPlacemark &placemark);
static QVector<NamedEntry> extractNamedEntries(const GeoDataPlacemark &placemark);
private:
const double m_buildingHeight;
- const QString m_buildingLabel;
const QVector<NamedEntry> m_entries;
};
diff --git a/src/plugins/runner/osm/OsmWay.cpp b/src/plugins/runner/osm/OsmWay.cpp
index 1b2a02b..f369790 100644
--- a/src/plugins/runner/osm/OsmWay.cpp
+++ b/src/plugins/runner/osm/OsmWay.cpp
@@ -88,6 +88,12 @@ void OsmWay::create(GeoDataDocument *document, const OsmNodes &nodes, QSet<qint6
if (placemark->name().isEmpty()) {
placemark->setName(m_osmData.tagValue(QStringLiteral("ref")));
}
+ if (placemark->name().isEmpty()) {
+ placemark->setName(m_osmData.tagValue(QStringLiteral("addr:housename")));
+ }
+ if (placemark->name().isEmpty()) {
+ placemark->setName(m_osmData.tagValue(QStringLiteral("addr:housenumber")));
+ }
placemark->setOsmData(osmData);
placemark->setVisible(placemark->visualCategory() != GeoDataPlacemark::None);