【QT】QT的学习:qml中MapParameter的使用

系统:Ubuntu

环境:qt

地图插件:mapboxgl

(1)在地图上增加图层,(地图上画点\线\面等跟js接口一致)官网上例子:

Map {
      plugin: Plugin { name: "mapboxgl" }

      center: QtPositioning.coordinate(60.170448, 24.942046) // Helsinki
      zoomLevel: 12

      MapParameter {
          type: "source"

          property var name: "routeSource"
          property var sourceType: "geojson"
          property var data: '{ "type": "FeatureCollection", "features": \
              [{ "type": "Feature", "properties": {}, "geometry": { \
              "type": "LineString", "coordinates": [[ 24.934938848018646, \
              60.16830257086771 ], [ 24.943315386772156, 60.16227776476442 ]]}}]}'
      }

      MapParameter {
          type: "layer"

          property var name: "route"
          property var layerType: "line"
          property var source: "routeSource"

          // Draw under the first road label layer
          // of the mapbox-streets style.
          property var before: "road-label-small"
      }

      MapParameter {
          type: "paint"

          property var layer: "route"
          property var lineColor: "blue"
          property var lineWidth: 8.0
      }

      MapParameter {
          type: "layout"

          property var layer: "route"
          property var lineJoin: "round"
          property var lineCap: "round"
      }
  }

注:其中,type是source的数据源data是geojson的格式:因此data也可以写成:

MapParameter {
      type: "source"

      property var name: "routeSource"
      property var sourceType: "geojson
      property var data: ":source.geojson"
    }

(2)如果想要对数据源进行修改,可以设置id,如:source然后source.data = ":source2.geojson"

MapParameter {
      id:source
      type: "source"

      property var name: "routeSource"
      property var sourceType: "geojson
      property var data: ":source.geojson"
    }

或者 

MapParameter {
      id:source
      type: "source"

      property var name: "routeSource"
      property var sourceType: "geojson
      property var data: '{ "type": "FeatureCollection", "features":[]}'
    }
Component.onCompleted:
{
    var sourceData = '{ "type": "FeatureCollection", "features":[]}'//这是空值
    source.data = sourceData
}

(3)可以通过addMapparameter形式添加:例如:

var param = Qt.createQmlObject('import QtLocation 5.9; MapParameter { \
                            type: "paint"; \
                            property var layer: "water"; \
                            property var fillColor: "red"; \
                        }', map)

                        map.addMapParameter(param)

同样的source\layer\paint\layout也是都可以通过该方式添加.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值