0
votes

I'm stuck on the way mapReady works into QML.

According to the doc http://doc.qt.io/qt-5/qml-qtlocation-map.html#mapReady-prop, it's advised to use the signal emitted for this property in place of Component.onCompleted

From this simple main.qml code

import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6

Window {
    width: 512
    height: 512
    visible: true

    Item{
        anchors.fill: parent
        objectName: "bboxObj"

        Map {
            anchors.fill: parent
            id: map
            plugin: Plugin{name: "osm"}
            zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2
            center: QtPositioning.coordinate(59.91, 10.75) // Oslo
        }

        Component.onCompleted:{
            console.log("mapReady : " + map.mapReady)
            console.log("visibleRegion : " + map.visibleRegion.boundingGeoRectangle())
        }

    }

}

The results is :

qml: mapReady : false
qml: visibleRegion : QGeoRectangle({nan, nan}, {nan, nan})

How use this onMapReady to invoke visibleRegion after the map is ready ?

I have tried this, without success :

Map.onMapReadyChanged: {
    console.log("mapReady : " + map.mapReady)
    console.log("visibleRegion : " + map.visibleRegion.boundingGeoRectangle())
    console.log("visibleRegion.isValid : " + map.visibleRegion.isValid)
    console.log("visibleRegion.isEmpty : " + map.visibleRegion.isEmpty)
}
1

1 Answers

1
votes

you don't use Map.onMapReadyChanged, but only onMapReadyChanged inside the Map element