mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-31 09:05:14 +01:00
Improved area labels rendering
This commit is contained in:
parent
c29acb1aea
commit
a4e39a98c0
@ -79,11 +79,11 @@ static QString *pathLabel(const Style::TextRender *ri, MapData::Path &path,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RasterTile::processPoints(QList<TextItem*> &textItems)
|
||||
void RasterTile::processPointLabels(QList<TextItem*> &textItems)
|
||||
{
|
||||
const Style &s = style();
|
||||
QList<const Style::TextRender*> labels(s.pointLabels(_zoom));
|
||||
QList<const Style::Symbol*> symbols(s.symbols(_zoom));
|
||||
QList<const Style::Symbol*> symbols(s.pointSymbols(_zoom));
|
||||
|
||||
for (int i = 0; i < _points.size(); i++) {
|
||||
MapData::Point &point = _points[i];
|
||||
@ -125,45 +125,60 @@ void RasterTile::processPoints(QList<TextItem*> &textItems)
|
||||
}
|
||||
}
|
||||
|
||||
void RasterTile::processAreaNames(const QRect &tileRect,
|
||||
void RasterTile::processAreaLabels(const QRect &tileRect,
|
||||
QList<TextItem*> &textItems)
|
||||
{
|
||||
const Style &s = style();
|
||||
QList<const Style::TextRender*> instructions(s.areaLabels(_zoom));
|
||||
QSet<QString> set;
|
||||
QList<const Style::TextRender*> labels(s.areaLabels(_zoom));
|
||||
QList<const Style::Symbol*> symbols(s.areaSymbols(_zoom));
|
||||
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
const Style::TextRender *ri = instructions.at(i);
|
||||
|
||||
for (int j = 0; j < _paths.size(); j++) {
|
||||
MapData::Path &path = _paths[j];
|
||||
for (int i = 0; i < _paths.size(); i++) {
|
||||
MapData::Path &path = _paths[i];
|
||||
QString *label = 0;
|
||||
const Style::TextRender *ti = 0;
|
||||
const Style::Symbol *si = 0;
|
||||
|
||||
if (!path.closed || !path.path.elementCount())
|
||||
continue;
|
||||
if (!ri->rule().match(path.closed, path.tags))
|
||||
continue;
|
||||
if (!(label = pathLabel(ri, path)))
|
||||
continue;
|
||||
if (set.contains(path.label))
|
||||
|
||||
for (int j = 0; j < labels.size(); j++) {
|
||||
const Style::TextRender *ri = labels.at(j);
|
||||
if (ri->rule().match(path.closed, path.tags)) {
|
||||
if ((label = pathLabel(ri, path))) {
|
||||
ti = ri;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < symbols.size(); j++) {
|
||||
const Style::Symbol *ri = symbols.at(j);
|
||||
if (ri->rule().match(path.tags)) {
|
||||
si = ri;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ti && !si)
|
||||
continue;
|
||||
|
||||
const QImage *img = si ? &si->img() : 0;
|
||||
const QFont *font = ti ? &ti->font() : 0;
|
||||
const QColor *color = ti ? &ti->fillColor() : 0;
|
||||
QPointF pos = path.labelPos.isNull()
|
||||
? centroid(path.path) : ll2xy(path.labelPos);
|
||||
|
||||
TextPointItem *item = new TextPointItem(pos.toPoint(), label,
|
||||
&ri->font(), 0, &ri->fillColor(), 0, false);
|
||||
TextPointItem *item = new TextPointItem(pos.toPoint(), label, font, img,
|
||||
color, 0, false);
|
||||
if (item->isValid() && tileRect.contains(item->boundingRect().toRect())
|
||||
&& !item->collides(textItems)) {
|
||||
&& !item->collides(textItems))
|
||||
textItems.append(item);
|
||||
set.insert(path.label);
|
||||
} else
|
||||
else
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RasterTile::processStreetNames(const QRect &tileRect,
|
||||
void RasterTile::processLineLabels(const QRect &tileRect,
|
||||
QList<TextItem*> &textItems)
|
||||
{
|
||||
const Style &s = style();
|
||||
@ -307,9 +322,9 @@ void RasterTile::render()
|
||||
|
||||
drawPaths(&painter);
|
||||
|
||||
processPoints(textItems);
|
||||
processAreaNames(tileRect, textItems);
|
||||
processStreetNames(tileRect, textItems);
|
||||
processPointLabels(textItems);
|
||||
processAreaLabels(tileRect, textItems);
|
||||
processLineLabels(tileRect, textItems);
|
||||
drawTextItems(&painter, textItems);
|
||||
|
||||
//painter.setPen(Qt::red);
|
||||
|
@ -71,9 +71,9 @@ private:
|
||||
QVector<PathInstruction> pathInstructions();
|
||||
QPointF ll2xy(const Coordinates &c) const
|
||||
{return _transform.proj2img(_proj.ll2xy(c));}
|
||||
void processPoints(QList<TextItem*> &textItems);
|
||||
void processAreaNames(const QRect &tileRect, QList<TextItem*> &textItems);
|
||||
void processStreetNames(const QRect &tileRect, QList<TextItem*> &textItems);
|
||||
void processPointLabels(QList<TextItem*> &textItems);
|
||||
void processAreaLabels(const QRect &tileRect, QList<TextItem*> &textItems);
|
||||
void processLineLabels(const QRect &tileRect, QList<TextItem*> &textItems);
|
||||
QPainterPath painterPath(const Polygon &polygon) const;
|
||||
void drawTextItems(QPainter *painter, const QList<TextItem*> &textItems);
|
||||
void drawPaths(QPainter *painter);
|
||||
|
@ -342,7 +342,7 @@ Style::Style(const QString &path)
|
||||
QVector<const Style::PathRender *> Style::paths(int zoom, bool closed,
|
||||
const QVector<MapData::Tag> &tags) const
|
||||
{
|
||||
QVector<const Style::PathRender*> ri;
|
||||
QVector<const PathRender*> ri;
|
||||
|
||||
for (int i = 0; i < _paths.size(); i++)
|
||||
if (_paths.at(i).rule().match(zoom, closed, tags))
|
||||
@ -353,10 +353,10 @@ QVector<const Style::PathRender *> Style::paths(int zoom, bool closed,
|
||||
|
||||
QList<const Style::TextRender*> Style::pathLabels(int zoom) const
|
||||
{
|
||||
QList<const Style::TextRender*> list;
|
||||
QList<const TextRender*> list;
|
||||
|
||||
for (int i = 0; i < _pathLabels.size(); i++)
|
||||
if (_pathLabels.at(i).rule().zooms().contains(zoom))
|
||||
if (_pathLabels.at(i).rule()._zooms.contains(zoom))
|
||||
list.append(&_pathLabels.at(i));
|
||||
|
||||
return list;
|
||||
@ -364,10 +364,10 @@ QList<const Style::TextRender*> Style::pathLabels(int zoom) const
|
||||
|
||||
QList<const Style::TextRender*> Style::pointLabels(int zoom) const
|
||||
{
|
||||
QList<const Style::TextRender*> list;
|
||||
QList<const TextRender*> list;
|
||||
|
||||
for (int i = 0; i < _pointLabels.size(); i++)
|
||||
if (_pointLabels.at(i).rule().zooms().contains(zoom))
|
||||
if (_pointLabels.at(i).rule()._zooms.contains(zoom))
|
||||
list.append(&_pointLabels.at(i));
|
||||
|
||||
return list;
|
||||
@ -375,22 +375,41 @@ QList<const Style::TextRender*> Style::pointLabels(int zoom) const
|
||||
|
||||
QList<const Style::TextRender*> Style::areaLabels(int zoom) const
|
||||
{
|
||||
QList<const Style::TextRender*> list;
|
||||
QList<const TextRender*> list;
|
||||
|
||||
for (int i = 0; i < _areaLabels.size(); i++)
|
||||
if (_areaLabels.at(i).rule().zooms().contains(zoom))
|
||||
if (_areaLabels.at(i).rule()._zooms.contains(zoom))
|
||||
list.append(&_areaLabels.at(i));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<const Style::Symbol*> Style::symbols(int zoom) const
|
||||
QList<const Style::Symbol*> Style::pointSymbols(int zoom) const
|
||||
{
|
||||
QList<const Style::Symbol*> list;
|
||||
QList<const Symbol*> list;
|
||||
|
||||
for (int i = 0; i < _symbols.size(); i++)
|
||||
if (_symbols.at(i).rule().zooms().contains(zoom))
|
||||
list.append(&_symbols.at(i));
|
||||
for (int i = 0; i < _symbols.size(); i++) {
|
||||
const Symbol &symbol = _symbols.at(i);
|
||||
const Rule & rule = symbol.rule();
|
||||
if (rule._zooms.contains(zoom) && (rule._type == Rule::AnyType
|
||||
|| rule._type == Rule::NodeType))
|
||||
list.append(&symbol);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<const Style::Symbol*> Style::areaSymbols(int zoom) const
|
||||
{
|
||||
QList<const Symbol*> list;
|
||||
|
||||
for (int i = 0; i < _symbols.size(); i++) {
|
||||
const Symbol &symbol = _symbols.at(i);
|
||||
const Rule & rule = symbol.rule();
|
||||
if (rule._zooms.contains(zoom) && (rule._type == Rule::AnyType
|
||||
|| rule._type == Rule::WayType))
|
||||
list.append(&symbol);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
@ -34,8 +34,6 @@ public:
|
||||
bool match(int zoom, bool closed,
|
||||
const QVector<MapData::Tag> &tags) const;
|
||||
|
||||
const Range &zooms() const {return _zooms;}
|
||||
|
||||
private:
|
||||
enum Type {
|
||||
AnyType = 0,
|
||||
@ -224,7 +222,8 @@ public:
|
||||
QList<const TextRender*> pathLabels(int zoom) const;
|
||||
QList<const TextRender*> pointLabels(int zoom) const;
|
||||
QList<const TextRender*> areaLabels(int zoom) const;
|
||||
QList<const Symbol*> symbols(int zoom) const;
|
||||
QList<const Symbol*> pointSymbols(int zoom) const;
|
||||
QList<const Symbol*> areaSymbols(int zoom) const;
|
||||
|
||||
private:
|
||||
QList<PathRender> _paths;
|
||||
|
Loading…
x
Reference in New Issue
Block a user