Commit c5bfc4cf authored by dogmaphobic's avatar dogmaphobic

Adding ability to edit the way point (move it around).

It does not update anything internally. It just moves the path on the screen.
parent 125ece43
......@@ -482,6 +482,7 @@ Item {
heading: 0 // isNaN(MavManager.heading) ? 0 : MavManager.heading
latitude: mapBackground.visible ? ((MavManager.latitude === 0) ? 37.803784 : MavManager.latitude) : 37.803784
longitude: mapBackground.visible ? ((MavManager.longitude === 0) ? -122.462276 : MavManager.longitude) : -122.462276
readOnly: true
//interactive: !MavManager.mavPresent
z: 10
}
......
......@@ -52,6 +52,7 @@ Item {
property alias mapItem: map
property alias waypoints: polyLine
property alias mapMenu: mapTypeMenu
property alias readOnly: map.readOnly
Component.onCompleted: {
map.zoomLevel = 18
......@@ -142,8 +143,11 @@ Item {
polyLine.addCoordinate(coord);
map.addMarker(coord, MavManager.waypoints[i].id);
}
root.longitude = MavManager.waypoints[0].longitude
root.latitude = MavManager.waypoints[0].latitude
if (typeof MavManager.waypoints != 'undefined' && MavManager.waypoints.length > 0) {
root.longitude = MavManager.waypoints[0].longitude
root.latitude = MavManager.waypoints[0].latitude
}
map.changed = false
}
}
}
......@@ -166,10 +170,17 @@ Item {
Map {
id: map
property real lon: (longitude >= -180 && longitude <= 180) ? longitude : 0
property real lat: (latitude >= -90 && latitude <= 90) ? latitude : 0
property real lon: (longitude >= -180 && longitude <= 180) ? longitude : 0
property real lat: (latitude >= -90 && latitude <= 90) ? latitude : 0
property int currentMarker
property int pressX : -1
property int pressY : -1
property bool changed: false
property bool readOnly: false
property variant scaleLengths: [5, 10, 25, 50, 100, 150, 250, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000]
property variant markers
plugin: mapPlugin
width: 1
height: 1
......@@ -203,13 +214,23 @@ Item {
scaleTimer.restart()
}
function updateMarker(coord, wpid)
{
if(wpid < polyLine.path.length) {
var tmpPath = polyLine.path;
tmpPath[wpid] = coord;
polyLine.path = tmpPath;
map.changed = true;
}
}
function addMarker(coord, wpid)
{
var marker = Qt.createQmlObject ('QGCWaypoint {}', map)
map.addMapItem(marker)
marker.z = map.z + 1
marker.coordinate = coord
marker.waypointID.text = wpid
marker.waypointID = wpid
// Update list of markers
var count = map.markers.length
var myArray = []
......@@ -261,7 +282,7 @@ Item {
id: polyLine
visible: path.length > 1 && root.showWaypoints
line.width: 3
line.color: "#e35cd8"
line.color: map.changed ? "#f97a2e" : "#e35cd8"
smooth: true
antialiasing: true
}
......
......@@ -32,20 +32,50 @@ import QtLocation 5.3
MapQuickItem {
id: marker
property alias waypointID: number
anchorPoint.x: image.width / 2
anchorPoint.y: image.height / 2
property int waypointID: 0
anchorPoint.x: markerIcon.width / 2
anchorPoint.y: markerIcon.height / 2
sourceItem: Rectangle {
id: image
width: 24
height: 24
id: markerIcon
width: 30
height: 30
color: markerMouseArea.containsMouse ? (markerMouseArea.pressed ? Qt.rgba(0.69,0.2,0.68,0.25) : Qt.rgba(0.69,0.2,0.68,0.75)) : Qt.rgba(0,0,0,0.5)
radius: 8
border.color: Qt.rgba(0,0,0,0.75)
color: Qt.rgba(0,0,0,0.5)
Text {
id: number
anchors.centerIn: parent
font.pointSize: 10
font.pointSize: 11
font.weight: Font.DemiBold
color: "white"
text: marker.waypointID
}
MouseArea {
id: markerMouseArea
enabled: !map.readOnly
anchors.fill: parent
hoverEnabled: true
drag.target: marker
preventStealing: true
property int pressX : -1
property int pressY : -1
property int jitterThreshold : 4
onPressed : {
pressX = mouse.x;
pressY = mouse.y;
map.currentMarker = -1;
for (var i = 0; i < map.markers.length; i++) {
if (marker === map.markers[i]) {
map.currentMarker = i;
break;
}
}
}
onPositionChanged: {
if (Math.abs(pressX - mouse.x ) < jitterThreshold && Math.abs(pressY - mouse.y) < jitterThreshold) {
map.updateMarker(marker.coordinate, marker.waypointID)
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment