1
0
Fork 0

MapWidget: Show counties and towns as well, depending on the zoom.

Some colors added.
This commit is contained in:
Christian Schmitt 2013-03-05 18:24:44 +01:00
parent c7e846bd2a
commit 658bda6e40
3 changed files with 78 additions and 5 deletions

View file

@ -375,6 +375,7 @@ int MapData::_fontDescender = 0;
const int MAX_ZOOM = 12; const int MAX_ZOOM = 12;
const int SHOW_DETAIL_ZOOM = 8; const int SHOW_DETAIL_ZOOM = 8;
const int SHOW_DETAIL2_ZOOM = 5;
const int CURSOR_PAN_STEP = 32; const int CURSOR_PAN_STEP = 32;
MapWidget::MapWidget(int x, int y, int maxX, int maxY) : MapWidget::MapWidget(int x, int y, int maxX, int maxY) :
@ -998,14 +999,20 @@ void MapWidget::drawNavaids()
void MapWidget::drawPOIs() 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); FGPositioned::List poi = FGPositioned::findWithinRange(_projectionCenter, _drawRangeNm, &f);
glLineWidth(1.0); glLineWidth(1.0);
for (unsigned int i=0; i<poi.size(); ++i) { for (unsigned int i=0; i<poi.size(); ++i) {
FGPositioned::Type ty = poi[i]->type(); FGPositioned::Type ty = poi[i]->type();
if (ty == FGPositioned::CITY) { if (ty == FGPositioned::COUNTRY) {
drawCountries((FGNavRecord*) poi[i].get());
} else if (ty == FGPositioned::CITY) {
drawCities((FGNavRecord*) poi[i].get()); drawCities((FGNavRecord*) poi[i].get());
} else if (ty == FGPositioned::TOWN) {
drawTowns((FGNavRecord*) poi[i].get());
} }
} // of navaid iteration } // 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) void MapWidget::drawCities(FGNavRecord* rec)
{ {
if (_cachedZoom > SHOW_DETAIL_ZOOM) {
return; // hide labels beyond a certain zoom level
}
SGVec2d pos = project(rec->geod()); SGVec2d pos = project(rec->geod());
glColor3f(1.0, 1.0, 1.0); glColor3f(0.0, 1.0, 0.0);
circleAt(pos, 4, 8); 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) void MapWidget::drawObstacle(FGPositioned* obs)
{ {
@ -1442,7 +1511,7 @@ void MapWidget::drawHelipad(FGHelipad* hp)
{ {
SGVec2d pos = project(hp->geod()); SGVec2d pos = project(hp->geod());
glLineWidth(1.0); glLineWidth(1.0);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 0.0, 1.0);
circleAt(pos, 16, 5.0); circleAt(pos, 16, 5.0);
if (validDataForKey(hp)) { if (validDataForKey(hp)) {

View file

@ -68,7 +68,9 @@ private:
void drawVOR(bool tuned, FGNavRecord* nav); void drawVOR(bool tuned, FGNavRecord* nav);
void drawFix(FGFix* fix); void drawFix(FGFix* fix);
void drawCountries(FGNavRecord* rec);
void drawCities(FGNavRecord* rec); void drawCities(FGNavRecord* rec);
void drawTowns(FGNavRecord* rec);
void drawTraffic(); void drawTraffic();
void drawAIAircraft(const SGPropertyNode* model, const SGGeod& pos, double hdg); void drawAIAircraft(const SGPropertyNode* model, const SGGeod& pos, double hdg);

View file

@ -360,7 +360,9 @@ FGPositioned::TypeFilter::pass(FGPositioned* aPos) const
std::vector<Type>::const_iterator it = types.begin(), std::vector<Type>::const_iterator it = types.begin(),
end = types.end(); end = types.end();
for (; it != end; ++it) { for (; it != end; ++it) {
return aPos->type() == *it; if (aPos->type() == *it) {
return true;
}
} }
return false; return false;