MapPolyline QML Type
MapPolyline 类型可在地图上显示一条多线段。更多...
| Import Statement: | import QtLocation 6.12 |
| Since: | QtLocation 5.0 |
- 所有成员列表(包括继承的成员)
- MapPolyline 是QML Maps 插件的一部分。
属性
- autoFadeIn : bool
- line
- line.color : color
- line.width : int
- path : list<coordinate>
- referenceSurface : enum
(since 6.5)
方法
- void addCoordinate(coordinate)
- coordinate containsCoordinate(coordinate)
(since QtLocation 5.6) - coordinate coordinateAt(index)
(since QtLocation 5.6) - void insertCoordinate(index, coordinate)
(since QtLocation 5.6) - int pathLength()
(since QtLocation 5.6) - void removeCoordinate(coordinate)
- void removeCoordinate(index)
(since QtLocation 5.6) - void replaceCoordinate(index, coordinate)
(since QtLocation 5.6) - void setPath(geoPath path)
详细说明
MapPolyline 类型会在地图上显示一条多线段,该多线段由一个按顺序排列的coordinates 列表指定。
可随时使用 `addCoordinate ` 和 `removeCoordinate ` 方法添加或移除坐标。此外,这些坐标也可像 QML 中的任何其他列表元素一样进行修改:
mapPolyline.path[0].latitude = 5;默认情况下,多线段以 1 像素宽的黑色线条显示。可通过line.width 和line.color 属性更改此设置。
使用示例
以下代码片段展示了一个包含 4 个点的 MapPolyline,其形状类似于“问号”(?)的上部,位于澳大利亚布里斯班附近。绘制的线条宽度为 3 像素,颜色为绿色。
Map {
MapPolyline {
line.width: 3
line.color: 'green'
path: [
{ latitude: -27, longitude: 153.0 },
{ latitude: -27, longitude: 154.1 },
{ latitude: -28, longitude: 153.5 },
{ latitude: -29, longitude: 153.5 }
]
}
}
属性文档
autoFadeIn : bool
该属性决定在从非常低的缩放级别开始放大地图时,该图元是否会自动淡入。默认情况下,该属性值为true 。将该属性设置为false 将导致地图图元始终采用QtQuick::Item::opacity 属性指定的不透明度,该属性的默认值为1.0。
line group
该属性属于“线条”属性组。 “线条”属性组包含用于绘制线条的宽度和颜色。
宽度以像素为单位,且与地图的缩放级别无关。默认值对应一条宽度为 1 像素的黑色边框。
若不显示线条,请将宽度设为 0 或使用透明颜色。
path : list<coordinate>
该属性存储了定义多段线的坐标的有序列表。
referenceSurface : enum [since 6.5]
该属性用于确定折线的参考表面。如果将其设置为QLocation::ReferenceSurface::Map ,则折线的顶点在地图上将通过直线连接;如果将其设置为QLocation::ReferenceSurface::Globe ,则顶点将沿大圆路径连接,该路径描述了球面上两点之间的最短连接路径。默认值为QLocation::ReferenceSurface::Map 。
该属性在 Qt 6.5 中引入。
方法文档
void addCoordinate(coordinate)
将指定的coordinate 添加到路径末尾。
另请参阅 insertCoordinate 、removeCoordinate 和path 。
[since QtLocation 5.6] coordinate containsCoordinate(coordinate)
如果给定的coordinate 是路径的一部分,则返回true。
该方法在 QtLocation 5.6 中引入。
[since QtLocation 5.6] coordinate coordinateAt(index)
获取给定index 处多线段的坐标。如果索引超出路径边界,则返回无效坐标。
该方法在 QtLocation 5.6 中引入。
[since QtLocation 5.6] void insertCoordinate(index, coordinate)
将一个coordinate 插入到指定index 处的路径中。
该方法在 QtLocation 5.6 中引入。
另请参阅 addCoordinate 、removeCoordinate 以及path 。
[since QtLocation 5.6] int pathLength()
返回多段线的坐标个数。
该方法自 QtLocation 5.6 起引入。
另请参阅 path 。
void removeCoordinate(coordinate)
从路径中移除coordinate 。如果存在多个相同的坐标,则移除最后添加的一个。
如果路径中不存在coordinate ,则此方法不执行任何操作。
另请参阅 addCoordinate 、insertCoordinate 和path 。
[since QtLocation 5.6] void removeCoordinate(index)
从路径中删除位于指定index 处的坐标。
如果index 无效,则此方法不执行任何操作。
此方法自 QtLocation 5.6 起引入。
另请参阅 addCoordinate 、insertCoordinate 和path 。
[since QtLocation 5.6] void replaceCoordinate(index, coordinate)
将当前路径中位于给定坐标index 处的坐标替换为新坐标coordinate 。
该方法在 QtLocation 5.6 中引入。
另请参阅 addCoordinate 、insertCoordinate 、removeCoordinate 以及path 。
void setPath(geoPath path)
使用geoPath 类型设置path 。
另请参阅 path 。
© 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.