c – QML地图:大量显示的项目
发布时间:2020-12-16 06:53:35 所属栏目:百科 来源:网络整理
导读:在QML位置模块提供的地图上显示大量MapItem时,我遇到了性能问题.我已经在这里问了这个问题( https://forum.qt.io/topic/79229/large-amount-of-qml-mapitems),但没有人可以帮助我,所以我想在这里尝试一次.我也发现了这个问题( How to use the QML/QtLocation
在QML位置模块提供的地图上显示大量MapItem时,我遇到了性能问题.我已经在这里问了这个问题(
https://forum.qt.io/topic/79229/large-amount-of-qml-mapitems),但没有人可以帮助我,所以我想在这里尝试一次.我也发现了这个问题(
How to use the QML/QtLocation module for displaying a large amount of offline data on a map?),但在添加另一个依赖项之前,我想看看我的代码是否可以改进,以便QML可以在没有任何帮助的情况下处理这种情况.
我目前正在尝试将大量项目绘制到QML地图上(30,000 – 120,000点).这些项目应根据QSlider的位置进行更新.性能从大约1,000个项目强烈下降,当我使用30,000时需要几分钟,直到QML Map将所有数据可视化并再次响应.我有一台绝对能够完成这项任务的机器,所以我认为问题是QML.我使用的是Qt 5.8. 有没有办法改善这种性能,或者只是不可能用QML-map一次绘制如此多的MapItem?我用图像尝试了MapCircles,Polylines,Polygons和MapQuickItems,但对我而言,性能问题似乎只是因为添加了这么多的MapItems而产生,因为我看不出这些类型之间处理时间的显着差异. 我在地图上可以看到更多数据,每次移动QSlider时都不应该刷新.即使我试图清除所有MapItem并添加新的MapItem用于性能测试,但即使这样也没有改善性能. 我的代码(有点抽象)看起来像这样: ///-------------- Widget.cpp-----------------/// void ProcessInput(int qslider_pos) { QVariantList lat_vec; QVariantList lon_vec; // Fill vectors with lateral and longitudinal positions // ... // Clean current points on map and draw new ones SendToQmlFuncRemovePoints(); SendToQmlFuncAddPoints(lat_vec,lon_vec); } void QmlConnector::SendToQmlFuncRemovePoints() { QVariant returnedValue; QMetaObject::invokeMethod(QmlMapSingleton::instance()->GetRoot(),"remove_points",Q_RETURN_ARG(QVariant,returnedValue)); } void QmlConnector::SendToQmlFuncAddPoints(QVariantList input_one,QVariantList input_two) { QVariant returnedValue; QMetaObject::invokeMethod(QmlMapSingleton::instance()->GetRoot(),"add_points",returnedValue),Q_ARG(QVariant,QVariant::fromValue(input_one)),QVariant::fromValue(input_two))); } . ///-------------- Map.qml -----------------/// Map { anchors.fill: parent property variant points: ({}) property int pointCounter: 0 Plugin { id: osmplugin name: "osm" PluginParameter { name: "osm.mapping.highdpi_tiles"; value: true } } Component.onCompleted: { points = new Array(); } id: map plugin: osmplugin //Javascript functions function add_points(array_lat,array_lon) { var myArray = new Array() var component = Qt.createComponent("mapcircle.qml"); for (var i=0; i<array_lat.length; i++) { var object = component.createObject(map,{ "center": QtPositioning.coordinate(array_lat[i],array_lon[i]}) map.addMapItem(object) myArray.push(object) } map.points = myArray } function remove_points() { var count = map.points.length for (var i = 0; i<count; i++){ map.removeMapItem(map.points[i]) map.points[i].destroy() } map.points = [] } } . ///-------------- mapcircle.qml -----------------/// import QtQuick 2.0 import QtLocation 5.6 MapCircle { radius: 1 border.width: 0 color: 'green' } 解决方法
Qt说,性能会随着添加到地图中的元素数量而减少.你是否需要在同一时间在地图上看到所有的点,如果没有,你可以玩可见性. 难道你不能使用QQuickPaintedItem来绘制C中的点并将其包装到MapQuickItem中,如果你有多个多边形,例如?但也有一些限制,你不能显示大图像. 如果您需要所有点,也许您可??以根据地图缩放级别获得不同的点,并减少以小缩放级别添加到地图的点数,如同在其他组中推荐的那样…
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |