使用大理石自定义地图叠加

时间:2019-04-16 11:27:15

标签: c++ qt marble

在遵循Marble教程的同时,我试图在this中创建自定义叠加层。我的代码与示例中的代码相同。

一切似乎都很好,但是生成的图层可以编辑,因此我可以单击它并更改其大小。

我希望它在背景上是静态的,无法与之交互。

似乎没有明显的设置或覆盖功能(以便我可以忽略所有用户事件)。

有什么想法吗?


根据要求输入代码:

#include <QDebug>
#include <QFileInfo>
#include <QApplication>
#include <QImage>

#include <marble/MarbleWidget.h>
#include <marble/GeoDataDocument.h>
#include <marble/GeoDataGroundOverlay.h>
#include <marble/GeoDataTreeModel.h>
#include <marble/MarbleModel.h>

using namespace Marble;

int main(int argc, char** argv) {

    QApplication app(argc,argv);

    QFileInfo inputFile( app.arguments().last() );
    if ( app.arguments().size() < 2 || !inputFile.exists() ) {
        qWarning() << "Usage: " << app.arguments().first() << "file.png";
        return 1;
    }

    // Create a Marble QWidget without a parent
    MarbleWidget *mapWidget = new MarbleWidget();

    // Load the Satellite map
    mapWidget->setMapThemeId( "earth/bluemarble/bluemarble.dgml" );

    // Create a bounding box from the given corner points
    GeoDataLatLonBox box( 55, 48, 14.5, 6, GeoDataCoordinates::Degree );
    box.setRotation( 0, GeoDataCoordinates::Degree );

    // Create an overlay and assign the image to render and its bounding box to it
    GeoDataGroundOverlay *overlay = new GeoDataGroundOverlay;
    overlay->setLatLonBox( box );
    overlay->setIcon( QImage( inputFile.absoluteFilePath() ) );

    // Create a document as a container for the overlay
    GeoDataDocument *document = new GeoDataDocument();
    document->append( overlay );

    // Add the document to MarbleWidget's tree model
    mapWidget->model()->treeModel()->addDocument( document );

    mapWidget->show();

    return app.exec();
}

1 个答案:

答案 0 :(得分:0)

更新

您可以使用RenderPluginsetVisible以编程方式启用/禁用插件:

QList<RenderPlugin *> renderPluginList = marbleWidget->renderPlugins();
for (RenderPlugin *renderPlugin : renderPluginList) {
  if (std::find(plugin_list.begin(), plugin_list.end(), renderPlugin->nameId()) != plugin_list.end())
  {
     renderPlugin->setVisible(true);
  }
  else
  {
     renderPlugin->setVisible(false);
  }
}

其中plugin_list是插件std::vector<QString>的{​​{1}}。

要仅禁用注释插件,可以使用:

nameId()

如果您仍然遇到此问题,请检查一下QList<RenderPlugin *> renderPluginList = mapWidget->renderPlugins(); for (RenderPlugin *renderPlugin : renderPluginList) { if (renderPlugin->nameId() == "annotation") { renderPlugin->setVisible(false); } } 目录中是否有AnnotationPlugin(如果是Windows,则为.dll)。此插件可用于在plugins/地图上移动和调整各种功能。

相关问题