From 658bda6e40da65c317fd387ed1a2fcf628e7ed1b Mon Sep 17 00:00:00 2001 From: Christian Schmitt Date: Tue, 5 Mar 2013 18:24:44 +0100 Subject: [PATCH] MapWidget: Show counties and towns as well, depending on the zoom. Some colors added. --- src/GUI/MapWidget.cxx | 77 ++++++++++++++++++++++++++++++++++++-- src/GUI/MapWidget.hxx | 2 + src/Navaids/positioned.cxx | 4 +- 3 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/GUI/MapWidget.cxx b/src/GUI/MapWidget.cxx index af0d854c5..c0d1c0376 100644 --- a/src/GUI/MapWidget.cxx +++ b/src/GUI/MapWidget.cxx @@ -375,6 +375,7 @@ int MapData::_fontDescender = 0; const int MAX_ZOOM = 12; const int SHOW_DETAIL_ZOOM = 8; +const int SHOW_DETAIL2_ZOOM = 5; const int CURSOR_PAN_STEP = 32; MapWidget::MapWidget(int x, int y, int maxX, int maxY) : @@ -998,14 +999,20 @@ void MapWidget::drawNavaids() void MapWidget::drawPOIs() { - FGPositioned::TypeFilter f(FGPositioned::CITY); + FGPositioned::TypeFilter f(FGPositioned::COUNTRY); + f.addType(FGPositioned::CITY); + f.addType(FGPositioned::TOWN); FGPositioned::List poi = FGPositioned::findWithinRange(_projectionCenter, _drawRangeNm, &f); glLineWidth(1.0); for (unsigned int i=0; itype(); - if (ty == FGPositioned::CITY) { + if (ty == FGPositioned::COUNTRY) { + drawCountries((FGNavRecord*) poi[i].get()); + } else if (ty == FGPositioned::CITY) { drawCities((FGNavRecord*) poi[i].get()); + } else if (ty == FGPositioned::TOWN) { + drawTowns((FGNavRecord*) poi[i].get()); } } // of navaid iteration } @@ -1164,10 +1171,43 @@ void MapWidget::drawTunedLocalizer(SGPropertyNode_ptr radio) } } +void MapWidget::drawCountries(FGNavRecord* rec) +{ + if (_cachedZoom < 9) { + return; // hide labels beyond a certain zoom level + } + + SGVec2d pos = project(rec->geod()); + glColor3f(1.0, 1.0, 0.0); + + circleAt(pos, 4, 10); + + if (validDataForKey(rec)) { + setAnchorForKey(rec, pos); + return; + } + + char buffer[1024]; + ::snprintf(buffer, 1024, "%s", + rec->name().c_str()); + + MapData* d = createDataForKey(rec); + d->setPriority(200); + d->setLabel(rec->ident()); + d->setText(buffer); + d->setOffset(MapData::HALIGN_CENTER | MapData::VALIGN_BOTTOM, 10); + d->setAnchor(pos); + +} + void MapWidget::drawCities(FGNavRecord* rec) { + if (_cachedZoom > SHOW_DETAIL_ZOOM) { + return; // hide labels beyond a certain zoom level + } + SGVec2d pos = project(rec->geod()); - glColor3f(1.0, 1.0, 1.0); + glColor3f(0.0, 1.0, 0.0); circleAt(pos, 4, 8); @@ -1189,6 +1229,35 @@ void MapWidget::drawCities(FGNavRecord* rec) } +void MapWidget::drawTowns(FGNavRecord* rec) +{ + if (_cachedZoom > SHOW_DETAIL2_ZOOM) { + return; // hide labels beyond a certain zoom level + } + + SGVec2d pos = project(rec->geod()); + glColor3f(0.2, 1.0, 0.0); + + circleAt(pos, 4, 5); + + if (validDataForKey(rec)) { + setAnchorForKey(rec, pos); + return; + } + + char buffer[1024]; + ::snprintf(buffer, 1024, "%s", + rec->name().c_str()); + + MapData* d = createDataForKey(rec); + d->setPriority(40); + d->setLabel(rec->ident()); + d->setText(buffer); + d->setOffset(MapData::HALIGN_CENTER | MapData::VALIGN_BOTTOM, 10); + d->setAnchor(pos); + +} + /* void MapWidget::drawObstacle(FGPositioned* obs) { @@ -1442,7 +1511,7 @@ void MapWidget::drawHelipad(FGHelipad* hp) { SGVec2d pos = project(hp->geod()); glLineWidth(1.0); - glColor3f(1.0, 1.0, 1.0); + glColor3f(1.0, 0.0, 1.0); circleAt(pos, 16, 5.0); if (validDataForKey(hp)) { diff --git a/src/GUI/MapWidget.hxx b/src/GUI/MapWidget.hxx index 73990f078..780ff2e12 100644 --- a/src/GUI/MapWidget.hxx +++ b/src/GUI/MapWidget.hxx @@ -68,7 +68,9 @@ private: void drawVOR(bool tuned, FGNavRecord* nav); void drawFix(FGFix* fix); + void drawCountries(FGNavRecord* rec); void drawCities(FGNavRecord* rec); + void drawTowns(FGNavRecord* rec); void drawTraffic(); void drawAIAircraft(const SGPropertyNode* model, const SGGeod& pos, double hdg); diff --git a/src/Navaids/positioned.cxx b/src/Navaids/positioned.cxx index f6b706fd3..29e0ee0a4 100644 --- a/src/Navaids/positioned.cxx +++ b/src/Navaids/positioned.cxx @@ -360,7 +360,9 @@ FGPositioned::TypeFilter::pass(FGPositioned* aPos) const std::vector::const_iterator it = types.begin(), end = types.end(); for (; it != end; ++it) { - return aPos->type() == *it; + if (aPos->type() == *it) { + return true; + } } return false; -- 2.39.5