Skip to content

Instantly share code, notes, and snippets.

@stephenquan
Last active April 6, 2018 05:35
Show Gist options
  • Save stephenquan/eb9ab90af7cdf0c0b7c6dbb1f8b6abed to your computer and use it in GitHub Desktop.
Save stephenquan/eb9ab90af7cdf0c0b7c6dbb1f8b6abed to your computer and use it in GitHub Desktop.
appstudio-positionsource-sample.qml
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import ArcGIS.AppFramework.Devices 1.0
import ArcGIS.AppFramework.Positioning 1.0
Item {
property DeviceListModel deviceListModel: discoveryAgent.devices
property Device currentDevice
property Position currentPosition
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
ComboBox {
id: comboBox
Layout.fillWidth: true
model: deviceListModel
textRole: "name"
onCurrentTextChanged: selectDevice(deviceListModel.get(currentIndex))
}
ListView {
id: listView
property var fields: [
"latitude",
"longitude",
"altitude",
"timestamp",
"speed",
"horizontalAccuracy",
"verticalAccuracy",
"direction",
"verticalSpeed",
"magneticVariation",
"hdop",
"pdop",
"gdop",
"vdop",
"fixType",
"differentialAge",
"referenceStationId",
"satellitesVisible",
"satellitesInUse",
"positionAccuracy",
"geoidSeparation"
]
Layout.fillWidth: true
Layout.fillHeight: true
model: currentPosition != null ? fields : 0
delegate: Text { text: "%1: %2".arg(modelData).arg(getPositionValue(modelData)) }
}
}
DeviceDiscoveryAgent {
id: discoveryAgent
}
NmeaSource {
id: nmeaSource
}
PositionSource {
id: positionSource
active: false
nmeaSource: nmeaSource
onPositionChanged: currentPosition = position
}
Connections {
target: deviceListModel
onCountChanged: if (comboBox.currentIndex == -1 && deviceListModel.count > 0) { comboBox.currentIndex = 0; }
}
function selectDevice(device) {
positionSource.active = false;
currentDevice = device;
nmeaSource.source = currentDevice;
positionSource.active = true;
}
function getPositionValue(key) {
var nan = "NaN";
if (!currentPosition) return nan;
if (!currentPosition[key + "Valid"]) return nan;
return currentPosition.coordinate[key] || currentPosition[key];
}
Component.onCompleted: discoveryAgent.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment