Display labels overlapping between tiles

(requires unique feature IDs in PBF data - OpenMapTiles >= v3.7)
This commit is contained in:
Martin Tůma 2018-11-10 00:17:00 +01:00
parent 71895813ab
commit b7fb925178
2 changed files with 7 additions and 9 deletions

View File

@ -69,6 +69,11 @@ private:
const vector_tile::Tile_Feature *_data; const vector_tile::Tile_Feature *_data;
}; };
bool cmp(const Feature &f1, const Feature &f2)
{
return f1.data()->id() < f2.data()->id();
}
class Layer class Layer
{ {
public: public:
@ -84,6 +89,7 @@ public:
for (int i = 0; i < data->features_size(); i++) for (int i = 0; i < data->features_size(); i++)
_features.append(Feature(&(data->features(i)), &keys, &values)); _features.append(Feature(&(data->features(i)), &keys, &values));
qSort(_features.begin(), _features.end(), cmp);
} }
const QList<Feature> &features() const {return _features;} const QList<Feature> &features() const {return _features;}

View File

@ -139,18 +139,10 @@ void Text::addLabel(const QString &text, const QPointF &pos, const QFont &font,
{ {
if (text.isEmpty()) if (text.isEmpty())
return; return;
if (!sceneRect().contains(pos))
return;
TextItem *ti = new TextItem(text, pos, font, maxTextWidth); TextItem *ti = new TextItem(text, pos, font, maxTextWidth);
addItem(ti);
if (!sceneRect().contains(ti->sceneBoundingRect())) {
delete ti;
return;
}
ti->setPen(pen); ti->setPen(pen);
addItem(ti);
QList<QGraphicsItem*> ci = collidingItems(ti); QList<QGraphicsItem*> ci = collidingItems(ti);
for (int i = 0; i < ci.size(); i++) for (int i = 0; i < ci.size(); i++)
ci[i]->setVisible(false); ci[i]->setVisible(false);