From 6ca1e3b67c70539e9a24d42d31945bc8e21e49f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 11 Nov 2024 08:53:17 +0100 Subject: [PATCH] Improved area labels layout --- src/map/mapsforge/rastertile.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/map/mapsforge/rastertile.cpp b/src/map/mapsforge/rastertile.cpp index f013bea5..a62edade 100644 --- a/src/map/mapsforge/rastertile.cpp +++ b/src/map/mapsforge/rastertile.cpp @@ -16,6 +16,13 @@ using namespace Mapsforge; static double LIMIT = cos(deg2rad(170)); +static bool rectNearPolygon(const QPainterPath &path, const QRectF &rect) +{ + return (path.boundingRect().contains(rect) + && (path.contains(rect.topLeft()) || path.contains(rect.topRight()) + || path.contains(rect.bottomLeft()) || path.contains(rect.bottomRight()))); +} + static QPointF centroid(const QPainterPath &polygon) { qreal area = 0; @@ -208,6 +215,7 @@ void RasterTile::processAreaLabels(const QVector &paths, PointItem *item = new PointItem(pos.toPoint(), p.lbl, font, img, color, hColor); if (item->isValid() && _rect.contains(item->boundingRect().toRect()) + && rectNearPolygon(p.p->pp, item->boundingRect()) && !item->collides(textItems)) { textItems.append(item); if (p.ti && p.lbl)