diff --git a/gpxsee.qrc b/gpxsee.qrc index be537c0f..ab25cd7b 100644 --- a/gpxsee.qrc +++ b/gpxsee.qrc @@ -194,6 +194,7 @@ icons/map/marine/breakers.png icons/map/marine/overfalls.png icons/map/marine/boarding-place.png + icons/map/marine/light.png diff --git a/icons/map/marine/light.png b/icons/map/marine/light.png new file mode 100644 index 00000000..a11ed95f Binary files /dev/null and b/icons/map/marine/light.png differ diff --git a/src/common/coordinates.h b/src/common/coordinates.h index cfdb39c7..5e5439d9 100644 --- a/src/common/coordinates.h +++ b/src/common/coordinates.h @@ -38,6 +38,15 @@ inline bool operator==(const Coordinates &c1, const Coordinates &c2) {return (c1.lat() == c2.lat() && c1.lon() == c2.lon());} inline bool operator!=(const Coordinates &c1, const Coordinates &c2) {return !(c1 == c2);} +inline bool operator<(const Coordinates &c1, const Coordinates &c2) +{ + if (c1.lon() < c2.lon()) + return true; + else if (c1.lon() > c2.lon()) + return false; + else + return (c1.lat() < c2.lat()); +} #ifndef QT_NO_DEBUG QDebug operator<<(QDebug dbg, const Coordinates &c); diff --git a/src/map/ENC/mapdata.cpp b/src/map/ENC/mapdata.cpp index 99e0a9ad..489374d9 100644 --- a/src/map/ENC/mapdata.cpp +++ b/src/map/ENC/mapdata.cpp @@ -19,32 +19,33 @@ static QMap orderMapInit() { QMap map; - map.insert(TYPE(CGUSTA), 0); - map.insert(SUBTYPE(BUAARE, 1), 1); - map.insert(SUBTYPE(BUAARE, 5), 2); - map.insert(SUBTYPE(BUAARE, 4), 3); - map.insert(SUBTYPE(BUAARE, 3), 4); - map.insert(SUBTYPE(BUAARE, 2), 5); - map.insert(SUBTYPE(BUAARE, 6), 6); - map.insert(SUBTYPE(BUAARE, 0), 7); - map.insert(TYPE(RDOSTA), 8); - map.insert(TYPE(RADSTA), 9); - map.insert(TYPE(RTPBCN), 10); - map.insert(TYPE(BCNISD), 11); - map.insert(TYPE(BCNLAT), 12); - map.insert(TYPE(I_BCNLAT), 12); - map.insert(TYPE(BCNSAW), 13); - map.insert(TYPE(BCNSPP), 14); - map.insert(TYPE(BOYCAR), 15); - map.insert(TYPE(BOYINB), 16); - map.insert(TYPE(BOYISD), 17); - map.insert(TYPE(BOYLAT), 18); - map.insert(TYPE(I_BOYLAT), 18); - map.insert(TYPE(BOYSAW), 19); - map.insert(TYPE(BOYSPP), 20); - map.insert(TYPE(MORFAC), 21); - map.insert(TYPE(OFSPLF), 22); - map.insert(TYPE(LIGHTS), 23); + map.insert(TYPE(LIGHTS), 0); + + map.insert(TYPE(CGUSTA), 1); + map.insert(SUBTYPE(BUAARE, 1), 2); + map.insert(SUBTYPE(BUAARE, 5), 3); + map.insert(SUBTYPE(BUAARE, 4), 4); + map.insert(SUBTYPE(BUAARE, 3), 5); + map.insert(SUBTYPE(BUAARE, 2), 6); + map.insert(SUBTYPE(BUAARE, 6), 7); + map.insert(SUBTYPE(BUAARE, 0), 8); + map.insert(TYPE(RDOSTA), 9); + map.insert(TYPE(RADSTA), 10); + map.insert(TYPE(RTPBCN), 11); + map.insert(TYPE(BCNISD), 12); + map.insert(TYPE(BCNLAT), 13); + map.insert(TYPE(I_BCNLAT), 13); + map.insert(TYPE(BCNSAW), 14); + map.insert(TYPE(BCNSPP), 15); + map.insert(TYPE(BOYCAR), 16); + map.insert(TYPE(BOYINB), 17); + map.insert(TYPE(BOYISD), 18); + map.insert(TYPE(BOYLAT), 19); + map.insert(TYPE(I_BOYLAT), 19); + map.insert(TYPE(BOYSAW), 20); + map.insert(TYPE(BOYSPP), 21); + map.insert(TYPE(MORFAC), 22); + map.insert(TYPE(OFSPLF), 23); map.insert(TYPE(OBSTRN), 24); map.insert(TYPE(WRECKS), 25); map.insert(TYPE(UWTROC), 26); diff --git a/src/map/ENC/rastertile.cpp b/src/map/ENC/rastertile.cpp index 4d0dc898..2d45d160 100644 --- a/src/map/ENC/rastertile.cpp +++ b/src/map/ENC/rastertile.cpp @@ -13,6 +13,8 @@ using namespace ENC; #define TSSLPT_SIZE 0.005 /* ll */ #define RDOCAL_SIZE 12 /* px */ +typedef QMap PointMap; + const float C1 = 0.866025f; /* sqrt(3)/2 */ static const QColor haloColor(Qt::white); @@ -49,6 +51,12 @@ static QFont *font(Style::FontSize size) } } +static const QImage *light() +{ + static QImage img(":/marine/light.png"); + return &img; +} + static const Style& style() { static Style s; @@ -266,13 +274,25 @@ void RasterTile::processPolygons(QList &textItems) } void RasterTile::processPoints(QList &textItems, - QList &images) + QList &lights, QList &images) { const Style &s = style(); + PointMap lightsMap; + int i; std::sort(_points.begin(), _points.end(), pointLess); - for (int i = 0; i < _points.size(); i++) { + /* Lights */ + for (i = 0; i < _points.size(); i++) { + const MapData::Point *point = _points.at(i); + if (point->type()>>16 == LIGHTS) + lightsMap.insert(point->pos(), point); + else + break; + } + + /* Everything else */ + for ( ; i < _points.size(); i++) { const MapData::Point *point = _points.at(i); const Style::Point &style = s.point(point->type()); @@ -288,12 +308,17 @@ void RasterTile::processPoints(QList &textItems, if ((!label || !fnt) && !img) continue; - TextPointItem *item = new TextPointItem(ll2xy(point->pos()).toPoint(), - label, fnt, img, color, hColor, 0, ICON_PADDING); + QPoint pos(ll2xy(point->pos()).toPoint()); + TextPointItem *item = new TextPointItem(pos, label, fnt, img, color, + hColor, 0, ICON_PADDING); if (item->isValid() && !item->collides(textItems)) { textItems.append(item); if (rimg) images.append(rimg); + const PointMap::const_iterator it = lightsMap.find(point->pos()); + if (it != lightsMap.constEnd()) + lights.append(new TextPointItem(pos, 0, 0, light(), 0, 0, 0, + ICON_PADDING)); } else { delete item; delete rimg; @@ -328,14 +353,14 @@ void RasterTile::processLines(QList &textItems) void RasterTile::render() { - QList textItems; + QList textItems, lights; QList images; _pixmap.setDevicePixelRatio(_ratio); _pixmap.fill(Qt::transparent); processPolygons(textItems); - processPoints(textItems, images); + processPoints(textItems, lights, images); processLines(textItems); QPainter painter(&_pixmap); @@ -347,9 +372,11 @@ void RasterTile::render() drawLines(&painter); drawArrows(&painter); + drawTextItems(&painter, lights); drawTextItems(&painter, textItems); qDeleteAll(textItems); + qDeleteAll(lights); qDeleteAll(images); //painter.setPen(Qt::red); diff --git a/src/map/ENC/rastertile.h b/src/map/ENC/rastertile.h index 7acf2a58..eac85e6f 100644 --- a/src/map/ENC/rastertile.h +++ b/src/map/ENC/rastertile.h @@ -33,7 +33,8 @@ private: QPainterPath painterPath(const Polygon &polygon) const; QPolygonF polyline(const QVector &path) const; QPolygonF tsslptArrow(const Coordinates &c, qreal angle) const; - void processPoints(QList &textItems, QList &images); + void processPoints(QList &textItems, QList &lights, + QList &images); void processLines(QList &textItems); void processPolygons(QList &textItems); void drawBitmapPath(QPainter *painter, const QImage &img,