MapItemGroup QML Type
MapItemGroup 类型是用于存储地图项的容器。更多内容...
| Import Statement: | import QtLocation 6.12 |
| Since: | QtLocation 5.9 |
- 所有成员列表(包括继承的成员)
- MapItemGroup 是QML 地图插件的一部分。
详细说明
其目的是通过允许使用包含相互关联的地图元素及相关绑定的 qml 文件,从而实现代码模块化。
注意: 该 API 在 Qt 5.9中的发布 属于技术预览版。
使用示例
以下代码片段演示了如何使用 MapItemGroup 创建一个MapCircle :该多边形以坐标 (63, -18) 为中心,半径为 100 公里,内部填充红色,外围环绕着波浪状的绿色边框;整个多边形被包含在一个半透明的蓝色圆圈内,该圆圈通过MouseArea 控制,可移动整个组。 该组在名为 PolygonGroup.qml 的单独文件中定义:
import QtQuick
import QtPositioning
import QtLocation
MapItemGroup {
id: itemGroup
property alias position: mainCircle.center
property var radius: 100 * 1000
property var borderHeightPct : 0.3
MapCircle {
id: mainCircle
center : QtPositioning.coordinate(40, 0)
radius: itemGroup.radius * (1.0 + borderHeightPct)
opacity: 0.05
visible: true
color: 'blue'
MouseArea{
anchors.fill: parent
drag.target: parent
id: maItemGroup
}
}
MapCircle {
id: groupCircle
center: itemGroup.position
radius: itemGroup.radius
color: 'crimson'
onCenterChanged: {
groupPolyline.populateBorder();
}
}
MapPolyline {
id: groupPolyline
line.color: 'green'
line.width: 3
function populateBorder() {
groupPolyline.path = [] // clearing the path
var waveLength = 8.0;
var waveAmplitude = groupCircle.radius * borderHeightPct;
for (var i=0; i <= 360; i++) {
var wavePhase = (i/360.0 * 2.0 * Math.PI )* waveLength
var waveHeight = (Math.cos(wavePhase) + 1.0) / 2.0
groupPolyline.addCoordinate(groupCircle.center.atDistanceAndAzimuth(groupCircle.radius + waveAmplitude * waveHeight , i))
}
}
Component.onCompleted: {
populateBorder()
}
}
}PolygonGroup.qml 现已成为一个可重用的组件,可在地图中按以下方式使用:
Map {
id: map
PolygonGroup {
id: polygonGroup
position: QtPositioning.coordinate(63,-18)
}
}
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.