1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Various ENC rendering improvements

This commit is contained in:
Martin Tůma 2023-03-24 22:54:53 +01:00
parent 54d6016b1a
commit dbe407d9d9
10 changed files with 87 additions and 72 deletions

View File

@ -197,6 +197,7 @@
<file alias="light.png">icons/map/marine/light.png</file>
<file alias="building.png">icons/map/marine/building.png</file>
<file alias="fog-signal.png">icons/map/marine/fog-signal.png</file>
<file alias="construction.png">icons/map/marine/construction.png</file>
</qresource>
<!-- Mapsforge rendertheme -->

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 310 B

View File

@ -15,9 +15,10 @@ public:
bool operator!=(const Range &other) const
{return _min != other._min || _max != other._max;}
int size() const {return (_max - _min);}
int min() const {return _min;}
int max() const {return _max;}
int size() const {return (_max - _min);}
int mid() const {return _min + size()/2;}
bool isValid() const {return size() >= 0;}
bool isNull() const {return _min == 0 && _max == 0;}

View File

@ -54,6 +54,7 @@ static QMap<uint,uint> orderMapInit()
map.insert(TYPE(PILBOP), 28);
map.insert(TYPE(SISTAT), 29);
map.insert(TYPE(I_SISTAT), 29);
map.insert(TYPE(RDOCAL), 30);
map.insert(TYPE(I_RDOCAL), 30);
map.insert(TYPE(I_TRNBSN), 31);
map.insert(TYPE(HRBFAC), 32);
@ -65,11 +66,12 @@ static QMap<uint,uint> orderMapInit()
map.insert(TYPE(I_CRANES), 35);
map.insert(TYPE(I_WTWGAG), 36);
map.insert(TYPE(PYLONS), 37);
map.insert(TYPE(LNDMRK), 38);
map.insert(TYPE(SILTNK), 39);
map.insert(TYPE(LNDELV), 40);
map.insert(TYPE(SMCFAC), 41);
map.insert(TYPE(BUISGL), 42);
map.insert(TYPE(SLCONS), 38);
map.insert(TYPE(LNDMRK), 39);
map.insert(TYPE(SILTNK), 40);
map.insert(TYPE(LNDELV), 41);
map.insert(TYPE(SMCFAC), 42);
map.insert(TYPE(BUISGL), 43);
map.insert(TYPE(I_DISMAR), 0xFFFFFFFE);
map.insert(TYPE(SOUNDG), 0xFFFFFFFF);
@ -248,7 +250,8 @@ MapData::Point::Point(uint type, const Coordinates &c, const QString &label,
if (type>>16 == I_DISMAR && params.size()) {
_label = hUnits((type>>8)&0xFF) + " " + QString::fromLatin1(params.at(0));
_type = SUBTYPE(I_DISMAR, type & 0xFF);
} else if (type == TYPE(I_RDOCAL) && params.size() > 1) {
} else if ((type == TYPE(I_RDOCAL) || type == TYPE(RDOCAL))
&& params.size() > 1) {
if (!params.at(1).isEmpty())
_label = QString("VHF ") + QString::fromLatin1(params.at(1));
_param = QVariant(params.at(0).toDouble());
@ -542,9 +545,11 @@ MapData::Attr MapData::pointAttr(const ISO8211::Record &r, uint OBJL)
subtype |= av.at(1).toByteArray().toUInt() << 8;
if ((OBJL == I_DISMAR && key == I_WTWDIS)
|| (OBJL == RDOCAL && key == ORIENT)
|| (OBJL == I_RDOCAL && key == ORIENT))
params[0] = av.at(1).toByteArray();
if (OBJL == I_RDOCAL && key == COMCHA)
if ((OBJL == I_RDOCAL && key == COMCHA)
|| (OBJL == RDOCAL && key == COMCHA))
params[1] = av.at(1).toByteArray();
}

View File

@ -64,6 +64,7 @@
#define PYLONS 98
#define RADSTA 102
#define RTPBCN 103
#define RDOCAL 104
#define RDOSTA 105
#define RAILWY 106
#define RCRTCL 108

View File

@ -13,6 +13,19 @@ using namespace ENC;
#define TSSLPT_SIZE 0.005 /* ll */
#define RDOCAL_SIZE 12 /* px */
class PointItem : public TextPointItem
{
public:
PointItem(const QPoint &point, const QString *text, const QFont *font,
const QImage *img, const QImage *rimg, const QColor *color,
const QColor *haloColor) : TextPointItem(point, text, font, img, color,
haloColor, 0, ICON_PADDING), _rimg(rimg) {}
~PointItem() {delete _rimg;}
private:
const QImage *_rimg;
};
typedef QMap<Coordinates, const MapData::Point*> PointMap;
const float C1 = 0.866025f; /* sqrt(3)/2 */
@ -130,31 +143,21 @@ static QImage *rdocalArrow(qreal angle)
static QImage *image(uint type, const QVariant &param)
{
if (type>>16 == I_RDOCAL)
if (type>>16 == RDOCAL || type>>16 == I_RDOCAL)
return rdocalArrow(deg2rad(90 - param.toDouble()));
else
return 0;
}
static TextPointItem *pointItem(const QPoint &pos, const QString *label,
const QFont *fnt, const QImage *img, const QColor *color,
const QColor *hColor, const QList<TextItem*> &textItems)
static bool showLabel(const QImage *img, const Range &range, int zoom, int type)
{
TextPointItem *item = new TextPointItem(pos, label, fnt, img, color,
hColor, 0, ICON_PADDING);
if (item->isValid() && !item->collides(textItems))
return item;
delete item;
if (type>>16 == I_DISMAR)
return true;
if (!img)
return 0;
if ((img || type>>16 == SOUNDG) && zoom < range.mid())
return false;
item = new TextPointItem(pos, 0, 0, img, 0, 0, 0, 0);
if (item->isValid() && !item->collides(textItems))
return item;
delete item;
return 0;
return true;
}
QPainterPath RasterTile::painterPath(const Polygon &polygon) const
@ -301,7 +304,7 @@ void RasterTile::processPolygons(QList<TextItem*> &textItems)
}
void RasterTile::processPoints(QList<TextItem*> &textItems,
QList<TextItem*> &lights, QList<QImage*> &images)
QList<TextItem*> &lights)
{
const Style &s = style();
PointMap lightsMap, signalsMap;
@ -323,13 +326,15 @@ void RasterTile::processPoints(QList<TextItem*> &textItems,
/* Everything else */
for ( ; i < _points.size(); i++) {
const MapData::Point *point = _points.at(i);
QPoint pos(ll2xy(point->pos()).toPoint());
const Style::Point &style = s.point(point->type());
const QString *label = point->label().isEmpty() ? 0 : &(point->label());
QImage *rimg = style.img().isNull()
? image(point->type(), point->param()) : 0;
const QImage *img = style.img().isNull() ? rimg : &style.img();
const QFont *fnt = font(style.textFontSize());
const QFont *fnt = showLabel(img, _zooms, _zoom, point->type())
? font(style.textFontSize()) : 0;
const QColor *color = &style.textColor();
const QColor *hColor = style.haloColor().isValid()
? &style.haloColor() : 0;
@ -337,19 +342,16 @@ void RasterTile::processPoints(QList<TextItem*> &textItems,
if ((!label || !fnt) && !img)
continue;
QPoint pos(ll2xy(point->pos()).toPoint());
TextPointItem *item = pointItem(pos, label, fnt, img, color, hColor,
textItems);
if (item) {
PointItem *item = new PointItem(pos, label, fnt, img, rimg, color,
hColor);
if (item->isValid() && !item->collides(textItems)) {
textItems.append(item);
if (rimg)
images.append(rimg);
if (lightsMap.contains(point->pos()))
lights.append(new TextPointItem(pos, 0, 0, light(), 0, 0, 0, 0));
if (signalsMap.contains(point->pos()))
lights.append(new TextPointItem(pos, 0, 0, signal(), 0, 0, 0, 0));
} else
delete rimg;
delete item;
}
}
@ -381,13 +383,12 @@ void RasterTile::processLines(QList<TextItem*> &textItems)
void RasterTile::render()
{
QList<TextItem*> textItems, lights;
QList<QImage*> images;
_pixmap.setDevicePixelRatio(_ratio);
_pixmap.fill(Qt::transparent);
processPolygons(textItems);
processPoints(textItems, lights, images);
processPoints(textItems, lights);
processLines(textItems);
QPainter painter(&_pixmap);
@ -404,7 +405,6 @@ void RasterTile::render()
qDeleteAll(textItems);
qDeleteAll(lights);
qDeleteAll(images);
//painter.setPen(Qt::red);
//painter.setBrush(Qt::NoBrush);

View File

@ -13,12 +13,14 @@ namespace ENC {
class RasterTile
{
public:
RasterTile(const Projection &proj, const Transform &transform, int zoom,
const QRect &rect, qreal ratio, const QList<MapData::Line*> &lines,
const QList<MapData::Poly*> &polygons, const QList<MapData::Point*> &points)
: _proj(proj), _transform(transform), _zoom(zoom), _rect(rect),
_ratio(ratio), _pixmap(rect.width() * ratio, rect.height() * ratio),
_lines(lines), _polygons(polygons), _points(points), _valid(false) {}
RasterTile(const Projection &proj, const Transform &transform,
const Range &zooms, int zoom, const QRect &rect, qreal ratio,
const QList<MapData::Line*> &lines, const QList<MapData::Poly*> &polygons,
const QList<MapData::Point*> &points)
: _proj(proj), _transform(transform), _zooms(zooms), _zoom(zoom),
_rect(rect), _ratio(ratio),
_pixmap(rect.width() * ratio, rect.height() * ratio), _lines(lines),
_polygons(polygons), _points(points), _valid(false) {}
int zoom() const {return _zoom;}
QPoint xy() const {return _rect.topLeft();}
@ -33,8 +35,7 @@ private:
QPainterPath painterPath(const Polygon &polygon) const;
QPolygonF polyline(const QVector<Coordinates> &path) const;
QPolygonF tsslptArrow(const Coordinates &c, qreal angle) const;
void processPoints(QList<TextItem*> &textItems, QList<TextItem *> &lights,
QList<QImage*> &images);
void processPoints(QList<TextItem*> &textItems, QList<TextItem *> &lights);
void processLines(QList<TextItem*> &textItems);
void processPolygons(QList<TextItem*> &textItems);
void drawBitmapPath(QPainter *painter, const QImage &img,
@ -46,6 +47,7 @@ private:
Projection _proj;
Transform _transform;
Range _zooms;
int _zoom;
QRect _rect;
qreal _ratio;

View File

@ -236,12 +236,12 @@ void Style::pointStyle()
Small);
_points[TYPE(CRANES)] = Point(QImage(":/marine/crane.png"));
_points[TYPE(I_CRANES)] = Point(QImage(":/marine/crane.png"));
_points[SUBTYPE(I_DISMAR, 1)] = Point(QImage(":/marine/distance-mark.png"));
_points[SUBTYPE(I_DISMAR, 1)] = Point(QImage(":/marine/distance-mark.png"),
Small);
_points[SUBTYPE(I_DISMAR, 1)].setTextColor(QColor("#ffffff"));
_points[SUBTYPE(I_DISMAR, 1)].setTextFontSize(Small);
_points[SUBTYPE(I_DISMAR, 1)].setHaloColor(QColor());
_points[SUBTYPE(I_DISMAR, 2)] = Point(QImage(":/marine/distance-mark-land.png"));
_points[SUBTYPE(I_DISMAR, 2)].setTextFontSize(Small);
_points[SUBTYPE(I_DISMAR, 2)] = Point(QImage(":/marine/distance-mark-land.png"),
Small);
_points[SUBTYPE(I_DISMAR, 2)].setHaloColor(QColor());
_points[SUBTYPE(I_DISMAR, 3)] = _points[SUBTYPE(I_DISMAR, 2)];
_points[SUBTYPE(I_DISMAR, 4)] = _points[SUBTYPE(I_DISMAR, 2)];
@ -260,28 +260,33 @@ void Style::pointStyle()
_points[SUBTYPE(WATTUR, 4)] = Point(QImage(":/marine/overfalls.png"));
_points[TYPE(PILBOP)] = Point(QImage(":/marine/boarding-place.png"));
_points[TYPE(SISTAT)] = Point(QImage(":/marine/pylon.png"));
_points[TYPE(SLCONS)] = Point(QImage(":/marine/construction.png"));
_points[SUBTYPE(SMCFAC, 7)] = Point(QImage(":/POI/restaurant-11.png"));
_points[SUBTYPE(SMCFAC, 11)] = Point(QImage(":/POI/pharmacy-11.png"));
_points[SUBTYPE(SMCFAC, 12)] = Point(QImage(":/POI/drinking-water-11.png"));
_points[SUBTYPE(SMCFAC, 13)] = Point(QImage(":/POI/fuel-11.png"));
_points[SUBTYPE(SMCFAC, 18)] = Point(QImage(":/POI/toilet-11.png"));
_points[SUBTYPE(SMCFAC, 20)] = Point(QImage(":/POI/telephone-11.png"));
_points[SUBTYPE(SMCFAC, 22)] = Point(QImage(":/POI/parking-11.png"));
_points[SUBTYPE(SMCFAC, 25)] = Point(QImage(":/POI/campsite-11.png"));
_points[TYPE(BUISGL)] = Point(QImage(":/marine/building.png"));
_points[SUBTYPE(BUISGL, 2)] = Point(QImage(":/POI/harbor-11.png"));
_points[SUBTYPE(BUISGL, 5)] = Point(QImage(":/POI/hospital-11.png"));
_points[SUBTYPE(BUISGL, 6)] = Point(QImage(":/POI/post-11.png"));
_points[SUBTYPE(BUISGL, 7)] = Point(QImage(":/POI/lodging-11.png"));
_points[SUBTYPE(BUISGL, 9)] = Point(QImage(":/POI/police-11.png"));
_points[SUBTYPE(BUISGL, 13)] = Point(QImage(":/POI/bank-11.png"));
_points[SUBTYPE(BUISGL, 19)] = Point(QImage(":/POI/school-11.png"));
_points[SUBTYPE(BUISGL, 20)] = Point(QImage(":/POI/religious-christian-11.png"));
_points[SUBTYPE(BUISGL, 22)] = Point(QImage(":/POI/religious-jewish-11.png"));
_points[SUBTYPE(BUISGL, 26)] = Point(QImage(":/POI/religious-muslim-11.png"));
_points[SUBTYPE(BUISGL, 33)] = Point(QImage(":/marine/pylon.png"));
_points[SUBTYPE(BUISGL, 42)] = Point(QImage(":/POI/bus-11.png"));
_points[SUBTYPE(SMCFAC, 7)] = Point(QImage(":/POI/restaurant-11.png"), Small);
_points[SUBTYPE(SMCFAC, 11)] = Point(QImage(":/POI/pharmacy-11.png"), Small);
_points[SUBTYPE(SMCFAC, 12)] = Point(QImage(":/POI/drinking-water-11.png"),
Small);
_points[SUBTYPE(SMCFAC, 13)] = Point(QImage(":/POI/fuel-11.png"), Small);
_points[SUBTYPE(SMCFAC, 18)] = Point(QImage(":/POI/toilet-11.png"), Small);
_points[SUBTYPE(SMCFAC, 20)] = Point(QImage(":/POI/telephone-11.png"), Small);
_points[SUBTYPE(SMCFAC, 22)] = Point(QImage(":/POI/parking-11.png"), Small);
_points[SUBTYPE(SMCFAC, 25)] = Point(QImage(":/POI/campsite-11.png"), Small);
_points[TYPE(BUISGL)] = Point(QImage(":/marine/building.png"), Small);
_points[SUBTYPE(BUISGL, 2)] = Point(QImage(":/POI/harbor-11.png"), Small);
_points[SUBTYPE(BUISGL, 5)] = Point(QImage(":/POI/hospital-11.png"), Small);
_points[SUBTYPE(BUISGL, 6)] = Point(QImage(":/POI/post-11.png"), Small);
_points[SUBTYPE(BUISGL, 7)] = Point(QImage(":/POI/lodging-11.png"), Small);
_points[SUBTYPE(BUISGL, 9)] = Point(QImage(":/POI/police-11.png"), Small);
_points[SUBTYPE(BUISGL, 13)] = Point(QImage(":/POI/bank-11.png"), Small);
_points[SUBTYPE(BUISGL, 19)] = Point(QImage(":/POI/school-11.png"), Small);
_points[SUBTYPE(BUISGL, 20)] = Point(QImage(":/POI/religious-christian-11.png"),
Small);
_points[SUBTYPE(BUISGL, 22)] = Point(QImage(":/POI/religious-jewish-11.png"),
Small);
_points[SUBTYPE(BUISGL, 26)] = Point(QImage(":/POI/religious-muslim-11.png"),
Small);
_points[SUBTYPE(BUISGL, 33)] = Point(QImage(":/marine/pylon.png"), Small);
_points[SUBTYPE(BUISGL, 42)] = Point(QImage(":/POI/bus-11.png"), Small);
}
Style::Style()

View File

@ -195,8 +195,8 @@ void ENCMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
_transform.img2proj(pointRect.bottomRight()));
_data.points(pointRectD.toRectC(_projection, 20), &points);
tiles.append(RasterTile(_projection, _transform, _zoom,
QRect(ttl, QSize(TILE_SIZE, TILE_SIZE)), _tileRatio,
tiles.append(RasterTile(_projection, _transform, _data.zooms(),
_zoom, QRect(ttl, QSize(TILE_SIZE, TILE_SIZE)), _tileRatio,
lines, polygons, points));
}
}