MapRectangle QML Type | Qt Location 5.15.18

- Qt 5.15
- Qt Location
- QML Types
- MapRectangle QML Type
- Qt 5.15.18 Reference Documentation

# MapRectangle QML Type

The MapRectangle type displays a rectangle on a Map. More...

Import Statement: | import QtLocation 5.15
Since: | QtLocation 5.5

- List of all members, including inherited members

## Properties

- autoFadeIn : bool
- backend : MapRectangle.Backend
- border
  - border.color : color
  - border.width : int
- bottomRight : coordinate
- color : color
- opacity : real
- topLeft : coordinate

## Detailed Description

The MapRectangle type displays a rectangle on a Map. Rectangles are a special case of Polygon with exactly 4 vertices and 4 "straight" edges. In this case, "straight" means that the top-left point has the same latitude as the top-right point (the top edge), and the bottom-left point has the same latitude as the bottom-right point (the bottom edge). Similarly, the points on the left side have the same longitude, and the points on the right side have the same longitude.

To specify the rectangle, it requires a topLeft and bottomRight point, both given by a coordinate.

By default, the rectangle is displayed with transparent fill and a 1-pixel thick black border. This can be changed using the color, border.color and border.width properties.

Note: Similar to the MapPolygon type, MapRectangles are geographic items, thus dragging a MapRectangle causes its vertices to be recalculated in the geographic coordinate space. Apparent stretching of the item occurs when dragged to the a different latitude, however, its edges remain straight.

### Performance

MapRectangles have a rendering cost identical to a MapPolygon with 4 vertices.

Like the other map objects, MapRectangle is normally drawn without a smooth appearance. Setting the opacity property will force the object to be blended, which decreases performance considerably depending on the hardware in use.

### Example Usage

The following snippet shows a map containing a MapRectangle, spanning from (-27, 153) to (-28, 153.5), near Brisbane, Australia. The rectangle is filled in green, with a 2 pixel black border.

     Map {
         MapRectangle {
             color: 'green'
             border.width: 2
             topLeft {
                 latitude: -27
                 longitude: 153
             }
             bottomRight {
                 latitude: -28
                 longitude: 153.5
             }
         }
     }

## Property Documentation

autoFadeIn : bool

This property holds whether the item automatically fades in when zooming into the map starting from very low zoom levels. By default this is `true`. Setting this property to `false` causes the map item to always have the opacity specified with the QtQuick::Item::opacity property, which is 1.0 by default.

This property was introduced in Qt 5.14.

backend : MapRectangle.Backend

This property holds which backend is in use to render the map item. Valid values are MapRectangle.Software and MapRectangle.OpenGL. The default value is MapRectangle.Software.

Note: The release of this API with Qt 5.15 is a Technology Preview. Ideally, as the OpenGL backends for map items mature, there will be no more need to also offer the legacy software-projection backend. So this property will likely disappear at some later point. To select OpenGL-accelerated item backends without using this property, it is also possible to set the environment variable QTLOCATION_OPENGL_ITEMS to 1. Also note that all current OpenGL backends won't work as expected when enabling layers on the individual item, or when running on OpenGL core profiles greater than 2.x.

This property was introduced in Qt 5.15.

border group
border.color : color
border.width : int

This property is part of the border property group. The border property group holds the width and color used to draw the border of the rectangle. The width is in pixels and is independent of the zoom level of the map.

The default values correspond to a black border with a width of 1 pixel. For no line, use a width of 0 or a transparent color.

bottomRight : coordinate

This property holds the bottom-right coordinate of the MapRectangle which can be used to retrieve its longitude, latitude and altitude.

color : color

This property holds the fill color of the rectangle. For no fill, use a transparent color.

opacity : real

This property holds the opacity of the item. Opacity is specified as a number between 0 (fully transparent) and 1 (fully opaque). The default is 1.

An item with 0 opacity will still receive mouse events. To stop mouse events, set the visible property of the item to false.

topLeft : coordinate

This property holds the top-left coordinate of the MapRectangle which can be used to retrieve its longitude, latitude and altitude.