File indexing completed on 2024-12-08 09:32:22

0001 #include <QApplication>
0002 #include <QTreeView>
0003 
0004 #include <marble/MarbleWidget.h>
0005 #include <marble/MarbleModel.h>
0006 
0007 #include <marble/GeoDataDocument.h>
0008 #include <marble/GeoDataCoordinates.h>
0009 #include <marble/GeoDataPlacemark.h>
0010 #include <marble/GeoDataLineString.h>
0011 #include <marble/GeoDataLinearRing.h>
0012 #include <marble/GeoDataTreeModel.h>
0013 #include <marble/GeoDataStyle.h>
0014 #include <marble/GeoDataIconStyle.h>
0015 #include <marble/GeoDataLineStyle.h>
0016 #include <marble/GeoDataPolyStyle.h>
0017 
0018 #include <cstdio>
0019 
0020 using namespace Marble;
0021 
0022 void addPoints( GeoDataLinearRing &linearRing ) {
0023 
0024     linearRing << GeoDataCoordinates(25.97226722704463, 44.43497647488007, 0, GeoDataCoordinates::Degree )
0025                     << GeoDataCoordinates(26.04711276456992, 44.4420741223712, 0, GeoDataCoordinates::Degree )
0026                     << GeoDataCoordinates(25.99712510557899, 44.48015825036597, 0, GeoDataCoordinates::Degree )
0027                     << GeoDataCoordinates(26.11268978668501, 44.53902366720936, 0, GeoDataCoordinates::Degree )
0028                     << GeoDataCoordinates(26.12777496065434, 44.48972441010599, 0, GeoDataCoordinates::Degree )
0029                     << GeoDataCoordinates(26.17769825773425, 44.47685689461117, 0, GeoDataCoordinates::Degree )
0030                     << GeoDataCoordinates(26.16489863910029, 44.45366647920105, 0, GeoDataCoordinates::Degree )
0031                     << GeoDataCoordinates(26.23394105442375, 44.43247765101769, 0, GeoDataCoordinates::Degree )
0032                     << GeoDataCoordinates(26.23388161223319, 44.40720014793351, 0, GeoDataCoordinates::Degree )
0033                     << GeoDataCoordinates(26.18689640043445, 44.40683215952335, 0, GeoDataCoordinates::Degree )
0034                     << GeoDataCoordinates(26.1462530009004, 44.36252655873379, 0, GeoDataCoordinates::Degree )
0035                     << GeoDataCoordinates(25.97226722704463, 44.43497647488007, 0, GeoDataCoordinates::Degree );
0036 
0037 }
0038 
0039 void createStyleBucharest( GeoDataStyle &style ) {
0040     GeoDataLineStyle lineStyle( QColor( 255, 0, 0, 90 ) );
0041     lineStyle.setWidth ( 8 );
0042 
0043     GeoDataPolyStyle polyStyle( QColor( 255, 0, 0, 40 ) );
0044     polyStyle.setFill( true );
0045 
0046     style.setLineStyle( lineStyle );
0047     style.setPolyStyle( polyStyle );
0048 }
0049 
0050 void createStyleArch( GeoDataStyle &style ) {
0051     GeoDataIconStyle iconStyle;
0052     iconStyle.setIconPath( "bucharest_small.jpg" );
0053     style.setIconStyle( iconStyle );
0054 }
0055 
0056 int main(int argc, char** argv) {
0057 
0058     QApplication app(argc,argv);
0059 
0060     // Create a Marble QWidget without a parent
0061     MarbleWidget *mapWidget = new MarbleWidget();
0062 
0063     // Load the OpenStreetMap map
0064     mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
0065 
0066     //Create the Linear Ring (polygon) representing Bucharest's boundaries and include it in a placemark
0067     GeoDataLinearRing *Bucharest = new GeoDataLinearRing;
0068     addPoints( *Bucharest );
0069 
0070     GeoDataPlacemark *placemarkBucharest = new GeoDataPlacemark;
0071     placemarkBucharest->setGeometry( Bucharest );
0072 
0073     //Create the placemark representing the Arch of Triumph
0074     GeoDataPlacemark *placemarkArch = new GeoDataPlacemark( "Arch of Triumph" );
0075     placemarkArch->setCoordinate( 26.0783, 44.4671, 0, GeoDataCoordinates::Degree );
0076 
0077 
0078     //Add styles (icons, colors, etc.) to the two placemarks
0079     GeoDataStyle::Ptr styleBucharest(new GeoDataStyle);
0080     GeoDataStyle::Ptr styleArch(new GeoDataStyle);
0081 
0082     createStyleBucharest( *styleBucharest );
0083     placemarkBucharest->setStyle( styleBucharest );
0084 
0085     createStyleArch ( *styleArch );
0086     placemarkArch->setStyle( styleArch );
0087 
0088 
0089     //Create the document and add the two placemarks (the point representing the Arch of Triumph and the polygon with Bucharest's boundaries)
0090     GeoDataDocument *document = new GeoDataDocument;
0091     document->append( placemarkBucharest );
0092     document->append( placemarkArch );
0093 
0094     // Add the document to MarbleWidget's tree model
0095     mapWidget->model()->treeModel()->addDocument( document );
0096 
0097         // Center the map on Bucharest and set the zoom
0098     mapWidget->centerOn( GeoDataCoordinates( 26.0783, 44.4671, 0, GeoDataCoordinates::Degree ) );
0099     mapWidget->zoomView( 2400 );
0100 
0101 
0102     mapWidget->show();
0103 
0104     return app.exec();
0105 }