Skip to content

Commit

Permalink
Allow more labels for same symbol-id
Browse files Browse the repository at this point in the history
  • Loading branch information
tumic0 committed Nov 23, 2024
1 parent 93775a5 commit cccda73
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
9 changes: 9 additions & 0 deletions data/style/style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -586,18 +586,27 @@
<rule e="node" k="name" v="*">
<symbol id="peak" src=":/POI/mountain-11.svg" symbol-width="11" priority="10"/>
<caption fill="#000000" font-size="10" font-family="serif" font-style="italic" k="name" stroke="#FFFFFF" stroke-width="2" symbol-id="peak"/>
<rule e="node" k="*" v="*" zoom-min="14">
<caption fill="#000000" font-size="10" font-family="serif" font-style="italic" k="ele" stroke="#FFFFFF" stroke-width="2" symbol-id="peak" priority="-1"/>
</rule>
</rule>
</rule>
<rule e="node" k="natural" v="saddle" zoom-min="13">
<rule e="node" k="name" v="*">
<symbol id="saddle" src=":/symbols/saddle.svg" symbol-width="9" symbol-height="11" priority="9"/>
<caption fill="#000000" font-size="10" font-family="serif" font-style="italic" k="name" stroke="#FFFFFF" stroke-width="2" symbol-id="saddle"/>
<rule e="node" k="*" v="*" zoom-min="14">
<caption fill="#000000" font-size="10" font-family="serif" font-style="italic" k="ele" stroke="#FFFFFF" stroke-width="2" symbol-id="saddle" priority="-1"/>
</rule>
</rule>
</rule>
<rule e="node" k="natural" v="volcano" zoom-min="13">
<rule e="node" k="name" v="*">
<symbol id="volcano" src=":/POI/volcano-11.svg" symbol-width="11" priority="10"/>
<caption fill="#000000" font-size="10" font-family="serif" font-style="italic" k="name" stroke="#FFFFFF" stroke-width="2" symbol-id="volcano"/>
<rule e="node" k="*" v="*" zoom-min="14">
<caption fill="#000000" font-size="10" font-family="serif" font-style="italic" k="ele" stroke="#FFFFFF" stroke-width="2" symbol-id="volcano" priority="-1"/>
</rule>
</rule>
</rule>
<rule e="node" k="waterway" v="waterfall" zoom-min="15">
Expand Down
12 changes: 9 additions & 3 deletions src/map/mapsforge/rastertile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void RasterTile::processLabels(const QList<MapData::Point> &points,
const MapData::Point &point = points.at(i);
const Style::TextRender *ti = 0;
const Style::Symbol *si = 0;
const QByteArray *lbl = 0;
QList<const QByteArray *> ll;

for (int j = 0; j < symbols.size(); j++) {
const Style::Symbol *ri = symbols.at(j);
Expand All @@ -98,17 +98,23 @@ void RasterTile::processLabels(const QList<MapData::Point> &points,
for (int j = 0; j < labels.size(); j++) {
const Style::TextRender *ri = labels.at(j);
if (ri->rule().match(point.center(), point.tags)) {
const QByteArray *lbl;
if ((lbl = label(ri->key(), point.tags))) {
if (!si || si->id() == ri->symbolId()) {
if (!si) {
ti = ri;
ll.append(lbl);
break;
} else if (si->id() == ri->symbolId()) {
if (!ti)
ti = ri;
ll.append(lbl);
}
}
}
}

if (ti || si)
items.append(Label(&point, lbl, si, ti));
items.append(Label(&point, ll, si, ti));
}

std::sort(items.begin(), items.end());
Expand Down
25 changes: 19 additions & 6 deletions src/map/mapsforge/rastertile.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class RasterTile
};

struct Label {
Label(const MapData::Point *p, const QByteArray *lbl,
Label(const MapData::Point *p, const QList<const QByteArray *> lbl,
const Style::Symbol *si, const Style::TextRender *ti)
: point(p), lbl(lbl), ti(ti), si(si)
: point(p), ti(ti), si(si), lbl(lbl)
{
Q_ASSERT(si || ti);
}
Expand All @@ -61,9 +61,9 @@ class RasterTile
int priority() const {return si ? si->priority() : ti->priority();}

const MapData::Point *point;
const QByteArray *lbl;
const Style::TextRender *ti;
const Style::Symbol *si;
QList<const QByteArray *> lbl;
};

struct LineLabel {
Expand Down Expand Up @@ -170,15 +170,28 @@ class RasterTile
class PointItem : public TextPointItem
{
public:
PointItem(const QPoint &point, const QByteArray *label,
PointItem(const QPoint &point, const QList<const QByteArray *> &lbl,
const QFont *font, const QImage *img, const QColor *color,
const QColor *haloColor) : TextPointItem(point,
label ? new QString(*label) : 0, font, img, color, haloColor, 0) {}
const QColor *haloColor) : TextPointItem(point, label(lbl),
font, img, color, haloColor, 0) {}
PointItem(const QPoint &point, const QByteArray *label,
const QFont *font, const QColor *color, const QColor *bgColor)
: TextPointItem(point, label ? new QString(*label) : 0, font, 0,
color, 0, bgColor) {}
~PointItem() {delete _text;}

private:
static QString *label(const QList<const QByteArray*> &ll)
{
if (ll.isEmpty())
return 0;

QString *ret = new QString(*ll.first());
for (int i = 1; i < ll.size(); i++)
ret->append("\n" + *ll.at(i));

return ret;
}
};

class PathItem : public TextPathItem
Expand Down

0 comments on commit cccda73

Please sign in to comment.