mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-28 03:59:15 +02:00
Added support for lineSymbols in Mapsforge maps
This commit is contained in:
@ -207,33 +207,58 @@ void RasterTile::processAreaLabels(const QVector<PainterPath> &paths,
|
||||
void RasterTile::processLineLabels(const QVector<PainterPath> &paths,
|
||||
QList<TextItem*> &textItems) const
|
||||
{
|
||||
QList<const Style::TextRender*> instructions(_style->pathLabels(_zoom));
|
||||
QList<const Style::TextRender*> labels(_style->pathLabels(_zoom));
|
||||
QList<const Style::Symbol*> symbols(_style->lineSymbols(_zoom));
|
||||
QSet<QByteArray> set;
|
||||
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
const Style::TextRender *ri = instructions.at(i);
|
||||
for (int i = 0; i < paths.size(); i++) {
|
||||
const PainterPath &path = paths.at(i);
|
||||
const Style::TextRender *ti = 0;
|
||||
const Style::Symbol *si = 0;
|
||||
const QByteArray *lbl = 0;
|
||||
bool limit = false;
|
||||
|
||||
for (int i = 0; i < paths.size(); i++) {
|
||||
const PainterPath &path = paths.at(i);
|
||||
const QByteArray *lbl = label(ri->key(), path.path->tags);
|
||||
if (path.path->closed)
|
||||
continue;
|
||||
|
||||
if (!lbl)
|
||||
continue;
|
||||
if (!ri->rule().match(path.path->closed, path.path->tags))
|
||||
continue;
|
||||
bool limit = (ri->key() == ID_ELE || ri->key() == ID_REF);
|
||||
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)))
|
||||
ti = ri;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < symbols.size(); j++) {
|
||||
const Style::Symbol *ri = symbols.at(j);
|
||||
if (ri->rule().match(path.path->tags)) {
|
||||
si = ri;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ti && !si)
|
||||
continue;
|
||||
if (ti) {
|
||||
limit = (ti->key() == ID_ELE || ti->key() == ID_REF);
|
||||
if (limit && set.contains(*lbl))
|
||||
continue;
|
||||
|
||||
PathItem *item = new PathItem(path.pp, lbl, _rect, &ri->font(),
|
||||
&ri->fillColor(), haloColor(ri));
|
||||
if (item->isValid() && !item->collides(textItems)) {
|
||||
textItems.append(item);
|
||||
if (limit)
|
||||
set.insert(*lbl);
|
||||
} else
|
||||
delete item;
|
||||
}
|
||||
|
||||
const QImage *img = si ? &si->img() : 0;
|
||||
const QFont *font = ti ? &ti->font() : 0;
|
||||
const QColor *color = ti ? &ti->fillColor() : 0;
|
||||
const QColor *hColor = ti ? haloColor(ti) : 0;
|
||||
|
||||
PathItem *item = new PathItem(path.pp, lbl, img, _rect, font, color,
|
||||
hColor);
|
||||
if (item->isValid() && !item->collides(textItems)) {
|
||||
textItems.append(item);
|
||||
if (limit)
|
||||
set.insert(*lbl);
|
||||
} else
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,6 +434,7 @@ void RasterTile::render()
|
||||
|
||||
QPainter painter(&_pixmap);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter.translate(-_rect.x(), -_rect.y());
|
||||
|
||||
drawPaths(&painter, paths, points, renderPaths);
|
||||
@ -420,7 +446,8 @@ void RasterTile::render()
|
||||
|
||||
//painter.setPen(Qt::red);
|
||||
//painter.setBrush(Qt::NoBrush);
|
||||
//painter.drawRect(QRect(_rect.topLeft(), _pixmap.size()));
|
||||
//painter.setRenderHint(QPainter::Antialiasing, false);
|
||||
//painter.drawRect(_rect);
|
||||
|
||||
qDeleteAll(textItems);
|
||||
|
||||
|
@ -137,9 +137,10 @@ private:
|
||||
{
|
||||
public:
|
||||
PathItem(const QPainterPath &line, const QByteArray *label,
|
||||
const QRect &tileRect, const QFont *font, const QColor *color,
|
||||
const QColor *haloColor) : TextPathItem(line,
|
||||
label ? new QString(*label) : 0, tileRect, font, color, haloColor) {}
|
||||
const QImage *img, const QRect &tileRect, const QFont *font,
|
||||
const QColor *color, const QColor *haloColor) : TextPathItem(line,
|
||||
label ? new QString(*label) : 0, tileRect, font, color, haloColor,
|
||||
img) {}
|
||||
~PathItem() {delete _text;}
|
||||
};
|
||||
|
||||
|
@ -419,7 +419,7 @@ void Style::text(QXmlStreamReader &reader, const MapData &data, const Rule &rule
|
||||
}
|
||||
|
||||
void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
const Rule &rule)
|
||||
const Rule &rule, QList<Symbol> &list)
|
||||
{
|
||||
Symbol ri(rule);
|
||||
const QXmlStreamAttributes &attr = reader.attributes();
|
||||
@ -457,7 +457,7 @@ void Style::symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
|
||||
ri._img = image(file, width, height, ratio);
|
||||
|
||||
_symbols.append(ri);
|
||||
list.append(ri);
|
||||
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
@ -529,7 +529,9 @@ void Style::rule(QXmlStreamReader &reader, const QString &dir,
|
||||
text(reader, data, r, list);
|
||||
}
|
||||
else if (reader.name() == QLatin1String("symbol"))
|
||||
symbol(reader, dir, ratio, r);
|
||||
symbol(reader, dir, ratio, r, _symbols);
|
||||
else if (reader.name() == QLatin1String("lineSymbol"))
|
||||
symbol(reader, dir, ratio, r, _lineSymbols);
|
||||
else
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
@ -716,7 +718,7 @@ QList<const Style::Symbol*> Style::pointSymbols(int zoom) const
|
||||
|
||||
for (int i = 0; i < _symbols.size(); i++) {
|
||||
const Symbol &symbol = _symbols.at(i);
|
||||
const Rule & rule = symbol.rule();
|
||||
const Rule &rule = symbol.rule();
|
||||
if (rule._zooms.contains(zoom) && (rule._type == Rule::AnyType
|
||||
|| rule._type == Rule::NodeType))
|
||||
list.append(&symbol);
|
||||
@ -725,6 +727,19 @@ QList<const Style::Symbol*> Style::pointSymbols(int zoom) const
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<const Style::Symbol*> Style::lineSymbols(int zoom) const
|
||||
{
|
||||
QList<const Symbol*> list;
|
||||
|
||||
for (int i = 0; i < _lineSymbols.size(); i++) {
|
||||
const Symbol &symbol = _lineSymbols.at(i);
|
||||
if (symbol.rule()._zooms.contains(zoom))
|
||||
list.append(&symbol);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<const Style::Symbol*> Style::areaSymbols(int zoom) const
|
||||
{
|
||||
QList<const Symbol*> list;
|
||||
|
@ -236,6 +236,7 @@ public:
|
||||
QList<const TextRender*> areaLabels(int zoom) const;
|
||||
QList<const Symbol*> pointSymbols(int zoom) const;
|
||||
QList<const Symbol*> areaSymbols(int zoom) const;
|
||||
QList<const Symbol*> lineSymbols(int zoom) const;
|
||||
|
||||
private:
|
||||
class Menu {
|
||||
@ -282,6 +283,7 @@ private:
|
||||
QList<CircleRender> _circles;
|
||||
QList<TextRender> _pathLabels, _pointLabels, _areaLabels;
|
||||
QList<Symbol> _symbols;
|
||||
QList<Symbol> _lineSymbols;
|
||||
|
||||
bool loadXml(const QString &path, const MapData &data, qreal ratio);
|
||||
void rendertheme(QXmlStreamReader &reader, const QString &dir,
|
||||
@ -298,7 +300,7 @@ private:
|
||||
void text(QXmlStreamReader &reader, const MapData &data, const Rule &rule,
|
||||
QList<QList<TextRender> *> &lists);
|
||||
void symbol(QXmlStreamReader &reader, const QString &dir, qreal ratio,
|
||||
const Rule &rule);
|
||||
const Rule &rule, QList<Symbol> &list);
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user