MapPolyline QML Type

MapPolyline 类型用于在地图上显示折线。更多

Import Statement: import QtLocation 6.10
Since: QtLocation 5.0

属性

方法

详细说明

MapPolyline 类型可在地图上显示一条多段线,该多段线以坐标有序列表的形式指定。

使用addCoordinateremoveCoordinate 方法可随时添加或删除坐标。它们也可以像 QML 中的其他列表元素一样被修改:

mapPolyline.path[0].latitude = 5;

默认情况下,多段线显示为 1 像素粗的黑线。可使用line.widthline.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

line.color : color

line.width : int

该属性是线条属性组的一部分。线条属性组包含用于绘制线条的宽度和颜色。

宽度以像素为单位,与地图缩放级别无关。默认值对应宽度为 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)

在给定的index 处为路径插入coordinate

此方法在 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)

用新的coordinate 替换当前路径中位于给定index 的坐标。

此方法在 QtLocation 5.6 中引入。

另请参阅 addCoordinate,insertCoordinate,removeCoordinate, 和path


void setPath(geopath path)

使用 geopath 类型设置path

另请参阅 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.