【问题标题】:Custom map overlays using Marble使用 Marble 自定义地图叠加层
【发布时间】:2019-04-16 11:27:15
【问题描述】:

我正在尝试在 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();
}

【问题讨论】:

    标签: c++ qt marble


    【解决方案1】:

    更新:

    您可以使用RenderPlugin 和setVisible 以编程方式启用/禁用插件:

    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()s 的std::vector&lt;QString&gt;。

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 2020-09-07
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      相关资源
      最近更新 更多