diff --git a/src/map/mapsforge/rastertile.cpp b/src/map/mapsforge/rastertile.cpp index f9cff203..58fa02d2 100644 --- a/src/map/mapsforge/rastertile.cpp +++ b/src/map/mapsforge/rastertile.cpp @@ -79,11 +79,11 @@ static QString *pathLabel(const Style::TextRender *ri, MapData::Path &path, return 0; } -void RasterTile::processPoints(QList &textItems) +void RasterTile::processPointLabels(QList &textItems) { const Style &s = style(); QList labels(s.pointLabels(_zoom)); - QList symbols(s.symbols(_zoom)); + QList 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 &textItems) } } -void RasterTile::processAreaNames(const QRect &tileRect, +void RasterTile::processAreaLabels(const QRect &tileRect, QList &textItems) { const Style &s = style(); - QList instructions(s.areaLabels(_zoom)); - QSet set; + QList labels(s.areaLabels(_zoom)); + QList symbols(s.areaSymbols(_zoom)); - for (int i = 0; i < instructions.size(); i++) { - const Style::TextRender *ri = instructions.at(i); + 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; - for (int j = 0; j < _paths.size(); j++) { - MapData::Path &path = _paths[j]; - QString *label = 0; + if (!path.closed || !path.path.elementCount()) + continue; - 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)) - continue; - - 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); - if (item->isValid() && tileRect.contains(item->boundingRect().toRect()) - && !item->collides(textItems)) { - textItems.append(item); - set.insert(path.label); - } else - delete item; + 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, font, img, + color, 0, false); + if (item->isValid() && tileRect.contains(item->boundingRect().toRect()) + && !item->collides(textItems)) + textItems.append(item); + else + delete item; } } -void RasterTile::processStreetNames(const QRect &tileRect, +void RasterTile::processLineLabels(const QRect &tileRect, QList &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); diff --git a/src/map/mapsforge/rastertile.h b/src/map/mapsforge/rastertile.h index 23f69b11..e7feba84 100644 --- a/src/map/mapsforge/rastertile.h +++ b/src/map/mapsforge/rastertile.h @@ -71,9 +71,9 @@ private: QVector pathInstructions(); QPointF ll2xy(const Coordinates &c) const {return _transform.proj2img(_proj.ll2xy(c));} - void processPoints(QList &textItems); - void processAreaNames(const QRect &tileRect, QList &textItems); - void processStreetNames(const QRect &tileRect, QList &textItems); + void processPointLabels(QList &textItems); + void processAreaLabels(const QRect &tileRect, QList &textItems); + void processLineLabels(const QRect &tileRect, QList &textItems); QPainterPath painterPath(const Polygon &polygon) const; void drawTextItems(QPainter *painter, const QList &textItems); void drawPaths(QPainter *painter); diff --git a/src/map/mapsforge/style.cpp b/src/map/mapsforge/style.cpp index 4f4872c7..345e0a83 100644 --- a/src/map/mapsforge/style.cpp +++ b/src/map/mapsforge/style.cpp @@ -342,7 +342,7 @@ Style::Style(const QString &path) QVector Style::paths(int zoom, bool closed, const QVector &tags) const { - QVector ri; + QVector ri; for (int i = 0; i < _paths.size(); i++) if (_paths.at(i).rule().match(zoom, closed, tags)) @@ -353,10 +353,10 @@ QVector Style::paths(int zoom, bool closed, QList Style::pathLabels(int zoom) const { - QList list; + QList 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 Style::pathLabels(int zoom) const QList Style::pointLabels(int zoom) const { - QList list; + QList 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 Style::pointLabels(int zoom) const QList Style::areaLabels(int zoom) const { - QList list; + QList 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 Style::symbols(int zoom) const +QList Style::pointSymbols(int zoom) const { - QList list; + QList 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 Style::areaSymbols(int zoom) const +{ + QList 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; } diff --git a/src/map/mapsforge/style.h b/src/map/mapsforge/style.h index 185473f8..9fe05146 100644 --- a/src/map/mapsforge/style.h +++ b/src/map/mapsforge/style.h @@ -34,8 +34,6 @@ public: bool match(int zoom, bool closed, const QVector &tags) const; - const Range &zooms() const {return _zooms;} - private: enum Type { AnyType = 0, @@ -224,7 +222,8 @@ public: QList pathLabels(int zoom) const; QList pointLabels(int zoom) const; QList areaLabels(int zoom) const; - QList symbols(int zoom) const; + QList pointSymbols(int zoom) const; + QList areaSymbols(int zoom) const; private: QList _paths;