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



我在学习本教程的同时尝试在 Marble 中创建自定义叠加层。我的代码与示例中的代码相同。

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

我希望它只是静态的,无法与之交互。

似乎没有任何明显的标志要设置或函数要覆盖(因此我可以忽略所有用户事件(。

有什么想法吗?


根据要求进行代码:

#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();
}

更新:

您可以使用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是插件nameId() std::vector<QString>

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

QList<RenderPlugin *> renderPluginList = mapWidget->renderPlugins();
for (RenderPlugin *renderPlugin : renderPluginList) {
  if (renderPlugin->nameId() == "annotation")
  {
     renderPlugin->setVisible(false);
  }
}

如果您仍然遇到此问题,要检查的一件事是plugins/目录中是否有AnnotationPlugin(如果在 Windows 上.dll(。该插件允许移动和调整MarbleWidget地图上的各种要素的大小。

最新更新