找回密码
 立即注册
收起左侧

qml中地图addMapParameter的使用

4
回复
8089
查看
[复制链接]
累计签到:2 天
连续签到:1 天
来源: 2018-10-9 14:21:34 显示全部楼层 |阅读模式
1Qter豆
在qt上使用qml(Map以及mapboxgl)开发地图的时候需要添加自定义的一些道路、建筑物等。用到官网中提到的:
  1. MapParameter {
  2.         type: "source"

  3.         property var name: "routeSource"
  4.         property var sourceType: "geojson"
  5.         property var data: '{ "type": "FeatureCollection", "features": \
  6.             [{ "type": "Feature", "properties": {}, "geometry": { \
  7.             "type": "LineString", "coordinates": [[ 24.934938848018646, \
  8.             60.16830257086771 ], [ 24.943315386772156, 60.16227776476442 ]]}}]}'
  9.     }

  10.     MapParameter {
  11.         type: "layer"

  12.         property var name: "route"
  13.         property var layerType: "line"
  14.         property var source: "routeSource"

  15.         // Draw under the first road label layer
  16.         // of the mapbox-streets style.
  17.         property var before: "road-label-small"
  18.     }
复制代码
但是该方法只能用于地图一开始的加载,项目中想用addMapParameter,用于后期获取数据之后再将sourcedata数据添加到地图的图层上。自己尝试了很多方法但是都不能构造addMapParameter中的

最佳答案

查看完整内容

额.... qml 构造对象的话,你觉得这样怎么样? var component = Qt.createComponent(“qrc:/public/MenuButtonCus.qml”); qml 里面是可以这样构造一个对象的,还是说,我理解错啦?
回复

使用道具 举报

累计签到:742 天
连续签到:1 天
2018-10-9 14:21:35 显示全部楼层
额.... qml 构造对象的话,你觉得这样怎么样?
var component = Qt.createComponent(“qrc:/public/MenuButtonCus.qml”);
qml 里面是可以这样构造一个对象的,还是说,我理解错啦?
回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2018-10-10 10:52:07 显示全部楼层
Since 发表于 2018-10-9 18:39
额.... qml 构造对象的话,你觉得这样怎么样?
var component = Qt.createComponent(“qrc:/public/MenuBut ...

我用的就是这种方式构造对象:
var markerComponenet = Qt.createComponent("MapParameterItem.qml")
if (markerComponenet.status == Component.Ready){}
但是我现在需要了解的是怎样构造或者定义一个MapParameter对象。在文件MapParameterItem.qml中我尝试使用过:
import QtQuick 2.5;
import QtLocation 5.6
MapParameter{}或者Item{}或者MapQuickItem {}都不正确。
回复

使用道具 举报

累计签到:742 天
连续签到:1 天
2018-10-10 18:35:18 显示全部楼层
你说的对象是什么意思,一个数据结构嘛?如果是要进行网络传输的 ,QML 应该做不到,然后
var obj = {"name":"nm"};这样也是一个对象,跟 JS是一样的,然后,我确实不晓得你是要用来干嘛的,这个对象~
回复

使用道具 举报

累计签到:2 天
连续签到:1 天
2018-10-11 09:55:10 显示全部楼层
Since 发表于 2018-10-10 18:35
你说的对象是什么意思,一个数据结构嘛?如果是要进行网络传输的 ,QML 应该做不到,然后
var obj = {"nam ...

构造的对象是为了给地图用的,方便加入图层。不是JS中的对象。如下是qt帮助文档的说明:

void addMapParameter(MapParameter parameter)

Adds a MapParameter object to the map. The effect of this call is dependent on the combination of the content of the MapParameter and the type of underlying QGeoMap. If a MapParameter that is not supported by the underlying QGeoMap gets added, the call has no effect.
The release of this API with Qt 5.9 is a Technology Preview.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了