本页内容

MapRoute QML Type

MapRoute 类型会在地图上显示一条路线。更多内容...

Import Statement: import QtLocation 6.12
Since: QtLocation 5.0

属性

详细说明

MapRoute 类型将通过RouteModel 或其他方式获取的路线,以多线段的形式显示在地图上,该多线段遵循该路线的路径。

MapRoute 实际上是一个MapPolyline ,但其路径是通过route 属性指定的,而非直接在coordinates 中指定。

默认情况下,路线显示为1像素宽的黑色线条。可通过line.width 和line.color 属性进行修改。

使用示例

以下是在map 上绘制route 的方法:

import QtQuick
import QtPositioning
import QtLocation

Map {
    RouteModel {
        id: routeModel
    }

    MapItemView {
        model: routeModel
        delegate: routeDelegate
    }

    Component {
        id: routeDelegate

        MapRoute {
            route: routeData
            line.color: "blue"
            line.width: 5
            smooth: true
            opacity: 0.8
        }
    }
}

属性文档

line group

line.color : color

line.width : int

该属性属于“线”属性组。 “线”属性组包含用于绘制线的宽度和颜色。

宽度以像素为单位,且与地图的缩放级别无关。默认值对应一条宽度为 1 像素的黑色边框。

若不显示线条,请将宽度设为 0 或使用透明颜色。

route : Route

该属性存储待绘制的路线,可用于表示一条地理路线。

© 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.