Skip to content

Commit

Permalink
Fixed symbol/label display priority
Browse files Browse the repository at this point in the history
  • Loading branch information
tumic0 committed Nov 7, 2024
1 parent 62ef1f4 commit 9b0fb8b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/map/mapsforge/rastertile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ void RasterTile::processPointLabels(const QList<MapData::Point> &points,

for (int j = 0; j < symbols.size(); j++) {
const Style::Symbol *ri = symbols.at(j);

if (ri->rule().match(point.tags))
if (!si || si->priority() < ri->priority())
si = ri;
if (ri->rule().match(point.tags)) {
si = ri;
break;
}
}

for (int j = 0; j < labels.size(); j++) {
const Style::TextRender *ri = labels.at(j);
if (ri->rule().match(point.tags)) {
if ((lbl = label(ri->key(), point.tags))) {
if (si && si->id() != ri->symbolId())
continue;
if (!ti || ti->priority() < ri->priority())
if (!si || si->id() == ri->symbolId()) {
ti = ri;
break;
}
}
}
}
Expand Down Expand Up @@ -166,21 +166,20 @@ void RasterTile::processAreaLabels(const QVector<PainterPath> &paths,

for (int j = 0; j < symbols.size(); j++) {
const Style::Symbol *ri = symbols.at(j);

if (ri->rule().match(path.path->closed, path.path->tags))
if (!si || si->priority() < ri->priority())
si = ri;
if (ri->rule().match(path.path->closed, path.path->tags)) {
si = ri;
break;
}
}

for (int j = 0; j < labels.size(); j++) {
const Style::TextRender *ri = labels.at(j);
if (ri->rule().match(path.path->closed, path.path->tags)) {
if ((lbl = label(ri->key(), path.path->tags))) {
if (si && si->id() != ri->symbolId())
continue;

ti = ri;
break;
if (!si || si->id() == ri->symbolId()) {
ti = ri;
break;
}
}
}
}
Expand Down Expand Up @@ -232,20 +231,23 @@ void RasterTile::processLineLabels(const QVector<PainterPath> &paths,
if (path.path->closed)
continue;

for (int j = 0; j < labels.size(); j++) {
const Style::TextRender *ri = labels.at(j);
for (int j = 0; j < symbols.size(); j++) {
const Style::Symbol *ri = symbols.at(j);
if (ri->rule().match(path.path->closed, path.path->tags)) {
if ((lbl = label(ri->key(), path.path->tags)))
ti = ri;
si = ri;
break;
}
}

for (int j = 0; j < symbols.size(); j++) {
const Style::Symbol *ri = symbols.at(j);
for (int j = 0; j < labels.size(); j++) {
const Style::TextRender *ri = labels.at(j);
if (ri->rule().match(path.path->closed, path.path->tags)) {
si = ri;
break;
if ((lbl = label(ri->key(), path.path->tags))) {
if (!si || si->id() == ri->symbolId()) {
ti = ri;
break;
}
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/map/mapsforge/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ static QList<QByteArray> valList(const QList<QByteArray> &in)
return out;
}

static bool symbolCmp(const Style::Symbol &a, const Style::Symbol &b)
{
return a.priority() > b.priority();
}

static bool labelCmp(const Style::TextRender &a, const Style::TextRender &b)
{
return a.priority() > b.priority();
}

const Style::Menu::Layer *Style::Menu::findLayer(const QString &id) const
{
for (int i = 0; i < _layers.size(); i++)
Expand Down Expand Up @@ -759,6 +769,12 @@ void Style::load(const MapData &data, qreal ratio)

if (!QFileInfo::exists(path) || !loadXml(path, data, ratio))
loadXml(":/mapsforge/default.xml", data, ratio);

std::sort(_symbols.begin(), _symbols.end(), symbolCmp);
std::sort(_lineSymbols.begin(), _lineSymbols.end(), symbolCmp);
std::stable_sort(_pointLabels.begin(), _pointLabels.end(), labelCmp);
std::stable_sort(_areaLabels.begin(), _areaLabels.end(), labelCmp);
std::stable_sort(_pathLabels.begin(), _pathLabels.end(), labelCmp);
}

void Style::clear()
Expand Down

0 comments on commit 9b0fb8b

Please sign in to comment.