MapPolyline QML Type
MapPolyline 类型用于在地图上显示折线。更多
Import Statement: | import QtLocation 6.9 |
Since: | QtLocation 5.0 |
- 所有成员(包括继承成员)列表
- MapPolyline 是QML 地图插件的一部分。
属性
- 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 的有序列表形式指定。路径上的coordinates 添加到 Polyline 后不能直接更改。相反,可以将path 复制到一个 var 中,修改副本并将副本重新分配回path 。
var path = mapPolyline.path; path[0].latitude = 5; mapPolyline.path = path;
也可以使用addCoordinate 和removeCoordinate 方法随时添加和删除坐标。
默认情况下,多段线显示为 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。
该属性是线条属性组的一部分。线条属性组包含用于绘制线条的宽度和颜色。
宽度以像素为单位,与地图缩放级别无关。默认值对应宽度为 1 像素的黑色边框。
如果没有线条,则使用 0 宽度或透明色。
path : list<coordinate> |
该属性包含定义折线的有序坐标列表。
referenceSurface : enum |
该属性决定了多段线的参考面。如果设置为QLocation::ReferenceSurface::Map ,则多段线的顶点将与地图上的直线相连。如果设置为QLocation::ReferenceSurface::Globe ,顶点将按照描述球面上两点最短连接的大圆路径连接。默认值为QLocation::ReferenceSurface::Map 。
此属性在 Qt 6.5 中引入。
方法文档
void addCoordinate(coordinate) |
将指定的coordinate 添加到路径的末端。
另请参阅 insertCoordinate,removeCoordinate, 和path 。
|
如果给定的coordinate 是路径的一部分,则返回 true。
此方法在 QtLocation 5.6 中引入。
|
获取多段线在给定index 处的坐标。如果索引超出了路径的边界,则返回无效坐标。
此方法在 QtLocation 5.6 中引入。
|
void removeCoordinate(coordinate) |
从路径中删除coordinate 。如果同一坐标有多个实例,则删除最后添加的那个。
如果coordinate 不在路径中,该方法不会执行任何操作。
另请参阅 addCoordinate,insertCoordinate, 和path 。
|
从给定index 的路径中删除一个坐标。
如果index 无效,则此方法不会执行任何操作。
此方法在 QtLocation 5.6 中引入。
另请参阅 addCoordinate,insertCoordinate, 和path 。
|
用新的coordinate 替换当前路径中位于给定index 的坐标。
此方法在 QtLocation 5.6 中引入。
另请参阅 addCoordinate,insertCoordinate,removeCoordinate, 和path 。
© 2025 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.