I have a problem with the QGroundMap overriding. I have a custom QGround widget and I need to draw multiple MapPolyline objects on a QGroundMap dynamically, but the only way to do that is to inject it directly by using this code.
Component.onCompleted: {
objMgr.createObjects([mapLine], _root.mapControl, true /* parentObjectIsMap */)
}
Standard MapItemView and other elements are not working properly.
I am trying to instantiate multiple MapPolyLine objects, but it`s not working properly either:
Instantiator {
id: testInstantiator
model: globalCoordinates
function getIndex(index) {
console.log("currentIndexIs")
console.log(index)
return index
}
delegate: Component {
id: mapLine
MapPolyline {
id: targetPolyLine
line.width: 3
line.color: "red"
z: QGroundControl.zOrderWaypointLines
path: testInstantiator.model[index]
}
}
}
And my globalCoordinates model looks like this:
property var globalCoordinates: [
[QtPositioning.coordinate(42, 13), QtPositioning.coordinate(42, 18)],
[QtPositioning.coordinate(42, 13), QtPositioning.coordinate(42, 20)],
[QtPositioning.coordinate(42, 13), QtPositioning.coordinate(42, 22)],
[QtPositioning.coordinate(42, 13), QtPositioning.coordinate(42, 24)],
[QtPositioning.coordinate(42, 13), QtPositioning.coordinate(42, 26)]
]
The only way to draw a line inside the instantiator is to replace index with a number, like this:
Instantiator {
id: testInstantiator
model: globalCoordinates
function getIndex(index) {
console.log("currentIndexIs")
console.log(index)
return index
}
delegate: Component {
id: mapLine
MapPolyline {
id: targetPolyLine
line.width: 3
line.color: "red"
z: QGroundControl.zOrderWaypointLines
path: testInstantiator.model[1] //it will draw a single line
}
}
}
I suspect, that Instantiator can not delegate Component more than one time. Or it cannot transfer properly all necessary data.
Are there any ways to inject MapPolyLine to a QGroundMap, or delegate the injected Component properly?
You can use
MapItemView
. If your model was a simple array, we can set the model tolength - 1
. Then we just useindex
andindex + 1
to construct theMapPoyline