mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 19:49:15 +02:00
Added hillshading to vector maps
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
#include "map/textpointitem.h"
|
||||
#include "map/bitmapline.h"
|
||||
#include "map/rectd.h"
|
||||
#include "map/hillshading.h"
|
||||
#include "data/dem.h"
|
||||
#include "style.h"
|
||||
#include "lblfile.h"
|
||||
#include "rastertile.h"
|
||||
@ -292,10 +294,10 @@ void RasterTile::processStreetNames(const QList<MapData::Poly> &lines,
|
||||
if (style.img().isNull() && style.foreground() == Qt::NoPen)
|
||||
continue;
|
||||
|
||||
const QFont *fnt = _data->style()->font(style.textFontSize(),
|
||||
const QFont *fnt = _data->style()->font(style.text().size(),
|
||||
Style::Small);
|
||||
const QColor *color = style.textColor().isValid()
|
||||
? &style.textColor() : 0;
|
||||
const QColor *color = style.text().color().isValid()
|
||||
? &style.text().color() : 0;
|
||||
const QColor *hColor = Style::isContourLine(poly.type) ? 0 : &haloColor;
|
||||
const QImage *img = poly.oneway
|
||||
? Style::isWaterLine(poly.type)
|
||||
@ -353,7 +355,7 @@ void RasterTile::processShields(const QList<MapData::Poly> &lines,
|
||||
it != shields.constEnd(); ++it) {
|
||||
const QPolygonF &p = it.value();
|
||||
QRectF rect(p.boundingRect() & _rect);
|
||||
if (AREA(rect) < AREA(QRect(0, 0, _pixmap.width()/4, _pixmap.width()/4)))
|
||||
if (AREA(rect) < AREA(QRect(0, 0, _rect.width()/4, _rect.width()/4)))
|
||||
continue;
|
||||
|
||||
QMap<qreal, int> map;
|
||||
@ -403,10 +405,10 @@ void RasterTile::processPoints(QList<MapData::Point> &points,
|
||||
? 0 : &(point.label.text());
|
||||
const QImage *img = style.img().isNull() ? 0 : &style.img();
|
||||
const QFont *fnt = poi
|
||||
? poiFont(style.textFontSize(), _zoom, point.classLabel)
|
||||
: _data->style()->font(style.textFontSize());
|
||||
const QColor *color = style.textColor().isValid()
|
||||
? &style.textColor() : &textColor;
|
||||
? poiFont(style.text().size(), _zoom, point.classLabel)
|
||||
: _data->style()->font(style.text().size());
|
||||
const QColor *color = style.text().color().isValid()
|
||||
? &style.text().color() : &textColor;
|
||||
const QColor *hcolor = Style::isDepthPoint(point.type)
|
||||
? 0 : &haloColor;
|
||||
|
||||
@ -443,8 +445,29 @@ void RasterTile::fetchData(QList<MapData::Poly> &polygons,
|
||||
_data->points(pointRectD.toRectC(_proj, 20), _zoom, &points);
|
||||
}
|
||||
|
||||
Matrix RasterTile::elevation() const
|
||||
{
|
||||
Matrix m(_rect.height() + 2, _rect.width() + 2);
|
||||
|
||||
int left = _rect.left() - 1;
|
||||
int right = _rect.right() + 1;
|
||||
int top = _rect.top() - 1;
|
||||
int bottom = _rect.bottom() + 1;
|
||||
|
||||
DEM::lock();
|
||||
for (int y = top; y <= bottom; y++) {
|
||||
for (int x = left; x <= right; x++)
|
||||
m.m(y - top, x - left) = DEM::elevation(xy2ll(QPointF(x, y)));
|
||||
}
|
||||
DEM::unlock();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void RasterTile::render()
|
||||
{
|
||||
QImage img(_rect.width() * _ratio, _rect.height() * _ratio,
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
QList<MapData::Poly> polygons;
|
||||
QList<MapData::Poly> lines;
|
||||
QList<MapData::Point> points;
|
||||
@ -463,21 +486,23 @@ void RasterTile::render()
|
||||
processPolygons(polygons, textItems);
|
||||
processLines(lines, textItems, arrows);
|
||||
|
||||
_pixmap.setDevicePixelRatio(_ratio);
|
||||
_pixmap.fill(Qt::transparent);
|
||||
img.setDevicePixelRatio(_ratio);
|
||||
img.fill(Qt::transparent);
|
||||
|
||||
QPainter painter(&_pixmap);
|
||||
QPainter painter(&img);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.translate(-_rect.x(), -_rect.y());
|
||||
|
||||
drawPolygons(&painter, polygons);
|
||||
if (_hillShading && _zoom >= 18 && _zoom <= 24)
|
||||
painter.drawImage(_rect.x(), _rect.y(), HillShading::render(elevation()));
|
||||
drawLines(&painter, lines);
|
||||
drawTextItems(&painter, textItems);
|
||||
|
||||
qDeleteAll(textItems);
|
||||
|
||||
_valid = true;
|
||||
_pixmap = QPixmap::fromImage(img);
|
||||
|
||||
//painter.setPen(Qt::red);
|
||||
//painter.setRenderHint(QPainter::Antialiasing, false);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "mapdata.h"
|
||||
#include "map/projection.h"
|
||||
#include "map/transform.h"
|
||||
#include "map/matrix.h"
|
||||
#include "style.h"
|
||||
|
||||
class QPainter;
|
||||
@ -17,15 +18,14 @@ class RasterTile
|
||||
{
|
||||
public:
|
||||
RasterTile(const Projection &proj, const Transform &transform, MapData *data,
|
||||
int zoom, const QRect &rect, qreal ratio, const QString &key)
|
||||
int zoom, const QRect &rect, qreal ratio, const QString &key,
|
||||
bool hillShading)
|
||||
: _proj(proj), _transform(transform), _data(data), _zoom(zoom),
|
||||
_rect(rect), _ratio(ratio), _key(key),
|
||||
_pixmap(rect.width() * ratio, rect.height() * ratio), _valid(false) {}
|
||||
_rect(rect), _ratio(ratio), _key(key), _hillShading(hillShading) {}
|
||||
|
||||
const QString &key() const {return _key;}
|
||||
QPoint xy() const {return _rect.topLeft();}
|
||||
const QPixmap &pixmap() const {return _pixmap;}
|
||||
bool isValid() const {return _valid;}
|
||||
|
||||
void render();
|
||||
|
||||
@ -34,6 +34,8 @@ private:
|
||||
QList<MapData::Point> &points);
|
||||
QPointF ll2xy(const Coordinates &c) const
|
||||
{return _transform.proj2img(_proj.ll2xy(c));}
|
||||
Coordinates xy2ll(const QPointF &p) const
|
||||
{return _proj.xy2ll(_transform.img2proj(p));}
|
||||
void ll2xy(QList<MapData::Poly> &polys);
|
||||
void ll2xy(QList<MapData::Point> &points);
|
||||
|
||||
@ -55,6 +57,8 @@ private:
|
||||
const QFont *poiFont(Style::FontSize size = Style::Normal,
|
||||
int zoom = -1, bool extended = false);
|
||||
|
||||
Matrix elevation() const;
|
||||
|
||||
Projection _proj;
|
||||
Transform _transform;
|
||||
MapData *_data;
|
||||
@ -63,7 +67,7 @@ private:
|
||||
qreal _ratio;
|
||||
QString _key;
|
||||
QPixmap _pixmap;
|
||||
bool _valid;
|
||||
bool _hillShading;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1332,6 +1332,12 @@ static QString brushColor(const QBrush &brush)
|
||||
return (brush == Qt::NoBrush) ? "None" : brush.color().name();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Style::Font &font)
|
||||
{
|
||||
dbg.nospace() << "Font(" << font.color() << ", " << font.size() << ")";
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Style::Polygon &polygon)
|
||||
{
|
||||
dbg.nospace() << "Polygon(" << brushColor(polygon.brush()) << ", "
|
||||
@ -1342,14 +1348,15 @@ QDebug operator<<(QDebug dbg, const Style::Polygon &polygon)
|
||||
QDebug operator<<(QDebug dbg, const Style::Line &line)
|
||||
{
|
||||
dbg.nospace() << "Line(" << penColor(line.foreground()) << ", "
|
||||
<< penColor(line.background()) << ", " << !line.img().isNull() << ")";
|
||||
<< penColor(line.background()) << ", " << !line.img().isNull() << ", "
|
||||
<< line.text() << ")";
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Style::Point &point)
|
||||
{
|
||||
dbg.nospace() << "Point(" << point.textFontSize() << ", "
|
||||
<< point.textColor() << ", " << !point.img().isNull() << ")";
|
||||
dbg.nospace() << "Point(" << point.text() << ", " << !point.img().isNull()
|
||||
<< ")";
|
||||
return dbg.space();
|
||||
}
|
||||
#endif // QT_NO_DEBUG
|
||||
|
@ -23,6 +23,21 @@ public:
|
||||
ExtraSmall = 5
|
||||
};
|
||||
|
||||
class Font {
|
||||
public:
|
||||
Font() :_size(NotSet) {}
|
||||
Font(const QColor &color, FontSize size) : _color(color), _size(size) {}
|
||||
|
||||
const QColor &color() const {return _color;}
|
||||
FontSize size() const {return _size;}
|
||||
void setColor(const QColor &color) {_color = color;}
|
||||
void setSize(FontSize size) {_size = size;}
|
||||
|
||||
private:
|
||||
QColor _color;
|
||||
FontSize _size;
|
||||
};
|
||||
|
||||
class Polygon {
|
||||
public:
|
||||
Polygon() : _brush(Qt::NoBrush), _pen(Qt::NoPen) {}
|
||||
@ -42,49 +57,46 @@ public:
|
||||
|
||||
class Line {
|
||||
public:
|
||||
Line() : _foreground(Qt::NoPen), _background(Qt::NoPen),
|
||||
_textFontSize(NotSet) {}
|
||||
Line() : _foreground(Qt::NoPen), _background(Qt::NoPen) {}
|
||||
Line(const QPen &foreground, const QPen &background = Qt::NoPen)
|
||||
: _foreground(foreground), _background(background),
|
||||
_textFontSize(NotSet) {}
|
||||
: _foreground(foreground), _background(background) {}
|
||||
Line(const QImage &img)
|
||||
: _foreground(Qt::NoPen), _background(Qt::NoPen),
|
||||
_textFontSize(NotSet), _img(img.convertToFormat(
|
||||
QImage::Format_ARGB32_Premultiplied)) {}
|
||||
|
||||
void setTextColor(const QColor &color) {_textColor = color;}
|
||||
void setTextFontSize(FontSize size) {_textFontSize = size;}
|
||||
_img(img.convertToFormat(QImage::Format_ARGB32_Premultiplied)) {}
|
||||
|
||||
const QPen &foreground() const {return _foreground;}
|
||||
const QPen &background() const {return _background;}
|
||||
const QColor &textColor() const {return _textColor;}
|
||||
FontSize textFontSize() const {return _textFontSize;}
|
||||
const Font &text() const {return _text;}
|
||||
const QImage &img() const {return _img;}
|
||||
|
||||
private:
|
||||
friend class Style;
|
||||
|
||||
void setTextColor(const QColor &color) {_text.setColor(color);}
|
||||
void setTextFontSize(FontSize size) {_text.setSize(size);}
|
||||
|
||||
QPen _foreground, _background;
|
||||
QColor _textColor;
|
||||
FontSize _textFontSize;
|
||||
Font _text;
|
||||
QImage _img;
|
||||
};
|
||||
|
||||
class Point {
|
||||
public:
|
||||
Point() : _textFontSize(NotSet) {}
|
||||
Point() {}
|
||||
Point(FontSize fontSize, const QColor &textColor = QColor())
|
||||
: _textColor(textColor), _textFontSize(fontSize) {}
|
||||
Point(const QImage &img) : _textFontSize(NotSet), _img(img) {}
|
||||
: _text(textColor, fontSize) {}
|
||||
Point(const QImage &img) : _img(img) {}
|
||||
|
||||
void setTextColor(const QColor &color) {_textColor = color;}
|
||||
void setTextFontSize(FontSize size) {_textFontSize = size;}
|
||||
|
||||
const QColor &textColor() const {return _textColor;}
|
||||
FontSize textFontSize() const {return _textFontSize;}
|
||||
const Font &text() const {return _text;}
|
||||
const QImage &img() const {return _img;}
|
||||
|
||||
private:
|
||||
QColor _textColor;
|
||||
FontSize _textFontSize;
|
||||
friend class Style;
|
||||
|
||||
void setTextColor(const QColor &color) {_text.setColor(color);}
|
||||
void setTextFontSize(FontSize size) {_text.setSize(size);}
|
||||
|
||||
Font _text;
|
||||
QImage _img;
|
||||
};
|
||||
|
||||
@ -183,6 +195,7 @@ private:
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
QDebug operator<<(QDebug dbg, const IMG::Style::Font &font);
|
||||
QDebug operator<<(QDebug dbg, const IMG::Style::Polygon &polygon);
|
||||
QDebug operator<<(QDebug dbg, const IMG::Style::Line &line);
|
||||
QDebug operator<<(QDebug dbg, const IMG::Style::Point &point);
|
||||
|
Reference in New Issue
Block a user