我想拖动一个两个MapQuickItem,它是在组件内部声明的,并从地图上获得实时坐标。MapQuickItem组件是一个具有红色和绿色的矩形。我想要两个同时拖动两个矩形,当它们在相同的坐标。如何在地图上使用相同的坐标同时拖动两个组件。
Map {
id: map
anchors.fill: parent
activeMapType: supportedMapTypes[1];
zoomLevel: 18
plugin: hereMaps
center: QtPositioning.coordinate(19.997454, 73.789803)
MapItemView {
id: markerItem
model: [
{ id: "marker1", color: "red" },
{ id: "marker2", color: "green" },
]
delegate: mapMarkerComponent
}
Component {
id : mapMarkerComponent
MapQuickItem {
id: mapMarker
coordinate: QtPositioning.coordinate(19.997454, 73.789803)
sourceItem: Rectangle {
id: handle
color: modelData.color
width: 40
height: 40
MouseArea {
drag.target: parent
anchors.fill: parent
}
onXChanged: {
mapMarker.x += x
}
onYChanged: {
mapMarker.y += y
}
}
}
}
}发布于 2020-05-19 19:08:53
在这里,对我有效的代码,即拖拽marker2隐式地拖拽marker1。
Map {
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(59.91, 10.75) // Oslo
zoomLevel: 14
MapQuickItem {
id: marker1
anchorPoint.x: 15
anchorPoint.y: 15
sourceItem: Rectangle {
id: rect1
width: 30
height: 30
radius: 15
color: "#8000FF00"
}
coordinate: QtPositioning.coordinate(marker2.coordinate.latitude + 0.005, marker2.coordinate.longitude)
}
MapQuickItem {
id: marker2
anchorPoint.x: 10
anchorPoint.y: 10
sourceItem: Rectangle {
id: rect2
width: 20
height: 20
radius: 10
color: "#800000FF"
MouseArea {
drag.target: parent
anchors.fill: parent
}
onXChanged: marker2.x += x;
onYChanged: marker2.y += y;
}
coordinate: QtPositioning.coordinate(59.91, 10.75)
}
}https://stackoverflow.com/questions/61867340
复制相似问题