MapRectangle QML Type
MapRectangle 类型可在地图上显示一个矩形。更多内容...
| Import Statement: | import QtLocation 6.12 |
| Since: | QtLocation 5.5 |
- 所有成员列表(包括继承的成员)
- MapRectangle 是QML 地图插件的一部分。
属性
- autoFadeIn : bool
- border
- border.color : color
- border.width : int
- bottomRight : coordinate
- color : color
- opacity : real
- referenceSurface : enum
(since 6.5) - topLeft : coordinate
详细说明
MapRectangle 类型在地图上显示一个矩形。矩形是 Polygon 的特例,具有恰好 4 个顶点和 4 条“直线”边。 在此情况下,“直线”是指左上角点的纬度与右上角点的纬度相同(即顶边),左下角点的纬度与右下角点的纬度相同(即底边)。 同样,左侧的点具有相同的经度,右侧的点也具有相同的经度。
要指定该矩形,需要一个topLeft 和bottomRight 点,二者均由geoCoordinate 给出。
默认情况下,矩形以透明填充和 1 像素宽的黑色边框显示。可通过color 、border.color 和border.width 属性更改此设置。
注意: 与MapPolygon 类型类似, MapRectangles属于地理对象,因此拖动MapRectangle会导致其顶点在地理坐标系中重新计算。当拖动至不同纬度时,该对象会呈现出拉伸的视觉效果,但其边线仍保持笔直。
使用示例
以下代码片段展示了一张包含 MapRectangle 的地图,该矩形范围为 (-27, 153) 至 (-28, 153.5),位于澳大利亚布里斯班附近。矩形内部填充为绿色,并带有 2 像素宽的黑色边框。
Map {
MapRectangle {
color: 'green'
border.width: 2
topLeft {
latitude: -27
longitude: 153
}
bottomRight {
latitude: -28
longitude: 153.5
}
}
}
属性文档
autoFadeIn : bool
该属性控制在从非常低的缩放级别开始放大地图时,地图元素是否自动淡入。默认情况下,该属性设置为true 。将该属性设置为false 会使地图元素始终采用QtQuick::Item::opacity 属性指定的不透明度,该属性的默认值为1.0。
border group
该属性属于边框属性组。边框属性组包含用于绘制矩形边框的宽度和颜色。宽度以像素为单位,且与地图的缩放级别无关。
默认值对应宽度为 1 像素的黑色边框。若要显示无边框,请将宽度设为 0 或使用透明颜色。
bottomRight : coordinate
该属性存储MapRectangle 的右下角坐标,可用于获取其经度、纬度和海拔。
color : color
此属性用于指定矩形的填充颜色。若不进行填充,请使用透明色。
opacity : real
该属性用于指定项的不透明度。不透明度以介于 0(完全透明)和 1(完全不透明)之间的数值表示。默认值为 1。
不透明度为 0 的项目仍会接收鼠标事件。若要阻止鼠标事件,请将该项目的 visible 属性设置为 false。
referenceSurface : enum [since 6.5]
该属性用于确定矩形的参考表面。如果将其设置为QLocation::ReferenceSurface::Map ,则地图上各边点将通过直线连接;如果将其设置为QLocation::ReferenceSurface::Globe ,则各边点将沿大圆路径连接,该路径描述了球面上两点之间的最短连接路径。默认值为QLocation::ReferenceSurface::Map 。
该属性在 Qt 6.5 中引入。
topLeft : coordinate
该属性存储MapRectangle 的左上角坐标,可用于获取其经度、纬度和海拔高度。
© 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.