(→Hello Marble!) |
|||
| Line 12: | Line 12: | ||
| − | == | + | == Making changes to the map == |
| − | + | Now we want to modify the map: | |
| + | |||
| + | Again [http://api.kde.org/4.x-api/kdeedu/marble/classMarble_1_1MarbleWidget.html MarbleWidget] provides a convenient way to make changes to the overall look and feel: | ||
| + | |||
| + | We'd like to display a small weather map. So we switch on the satellite view, enable the clouds and enable the border lines. | ||
| − | |||
<code cppqt> | <code cppqt> | ||
| Line 21: | Line 24: | ||
#include <QtGui/QApplication> | #include <QtGui/QApplication> | ||
| + | #include <marble/global.h> | ||
#include <marble/MarbleWidget.h> | #include <marble/MarbleWidget.h> | ||
#include <marble/AbstractFloatItem.h> | #include <marble/AbstractFloatItem.h> | ||
| Line 36: | Line 40: | ||
mapWidget->setMapThemeId("earth/bluemarble/bluemarble.dgml"); | mapWidget->setMapThemeId("earth/bluemarble/bluemarble.dgml"); | ||
| + | mapWidget->setProjection( Mercator ); | ||
| + | |||
// Enable the cloud cover and enable the country borders | // Enable the cloud cover and enable the country borders | ||
mapWidget->setShowClouds( true ); | mapWidget->setShowClouds( true ); | ||
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
| Tutorial Series | Marble C++ Tutorial |
| Previous | C++, Qt |
| What's Next | Tutorial 3 - Marble's GeoPainter |
| Further Reading | n/a |
Now we want to modify the map:
Again MarbleWidget provides a convenient way to make changes to the overall look and feel:
We'd like to display a small weather map. So we switch on the satellite view, enable the clouds and enable the border lines.
using namespace Marble;
int main(int argc, char** argv) {
QApplication app(argc,argv);
// Create a Marble QWidget without a parent MarbleWidget *mapWidget = new MarbleWidget();
// Load the OpenStreetMap map
mapWidget->setMapThemeId("earth/bluemarble/bluemarble.dgml");
mapWidget->setProjection( Mercator );
// Enable the cloud cover and enable the country borders
mapWidget->setShowClouds( true );
mapWidget->setShowBorders( true );
// Hide the FloatItems: Compass and StatusBar
mapWidget->setShowOverviewMap(false);
mapWidget->setShowScaleBar(false);
foreach ( AbstractFloatItem * floatItem, mapWidget->floatItems() )
if ( floatItem && floatItem->nameId() == "compass" ) {
// Put the compass onto the left hand side
floatItem->setPosition( QPoint( 10, 10 ) );
// Make the content size of the compass smaller
floatItem->setContentSize( QSize( 50, 50 ) );
}
mapWidget->show();
return app.exec();
}
Save the code above as my_marble.cpp and compile it:
g++ -I /usr/include/qt4/ -o my_marble my_marble.cpp -lmarblewidget -lQtGui
If things go fine, execute ./my_marble and you end up with a fully usable OpenStreetMap application:
Here's a little checklist to tackle some problems that might arise when compiling the code above: