-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import QtQuick | ||
import QtQuick.Controls | ||
|
||
import org.qfield | ||
import org.qgis | ||
import Theme | ||
|
||
import "qrc:/qml" as QFieldItems | ||
|
||
Item { | ||
id: plugin | ||
|
||
property var mainWindow: iface.mainWindow() | ||
property var positionSource: iface.findItemByObjectName('positionSource') | ||
property var dashBoard: iface.findItemByObjectName('dashBoard') | ||
property var overlayFeatureFormDrawer: iface.findItemByObjectName('overlayFeatureFormDrawer') | ||
|
||
Component.onCompleted: { | ||
iface.addItemToPluginsToolbar(snapButton) | ||
} | ||
|
||
Loader { | ||
id: cameraLoader | ||
active: false | ||
sourceComponent: Component { | ||
id: cameraComponent | ||
|
||
QFieldItems.QFieldCamera { | ||
id: qfieldCamera | ||
visible: false | ||
|
||
Component.onCompleted: { | ||
open() | ||
} | ||
|
||
onFinished: (path) => { | ||
close() | ||
snap(path) | ||
} | ||
|
||
onCanceled: { | ||
close() | ||
} | ||
|
||
onClosed: { | ||
cameraLoader.active = false | ||
} | ||
} | ||
} | ||
} | ||
|
||
QfToolButton { | ||
id: snapButton | ||
bgcolor: Theme.darkGray | ||
iconSource: Theme.getThemeVectorIcon('ic_camera_photo_black_24dp') | ||
iconColor: Theme.mainColor | ||
round: true | ||
|
||
onClicked: { | ||
dashBoard.ensureEditableLayerSelected() | ||
|
||
if (!positionSource.active || !positionSource.positionInformation.latitudeValid || !positionSource.positionInformation.longitudeValid) { | ||
mainWindow.displayToast(qsTr('Snap requires positioning to be active and returning a valid position')) | ||
return | ||
} | ||
|
||
if (dashBoard.activeLayer.geometryType() != Qgis.GeometryType.Point) { | ||
mainWindow.displayToast(qsTr('Snap requires the active vector layer to be a point geometry')) | ||
return | ||
} | ||
|
||
let fieldNames = dashBoard.activeLayer.fields.names | ||
if (fieldNames.indexOf('photo') == -1 && fieldNames.indexOf('picture') == -1) { | ||
mainWindow.displayToast(qsTr('Snap requires the active vector layer to contain a field named \'photo\' or \'picture\'')) | ||
return | ||
} | ||
|
||
cameraLoader.active = true | ||
} | ||
} | ||
|
||
function snap(path) { | ||
let today = new Date() | ||
let relativePath = 'DCIM/' + today.getFullYear() | ||
+ (today.getMonth() +1 ).toString().padStart(2,0) | ||
+ today.getDate().toString().padStart(2,0) | ||
+ today.getHours().toString().padStart(2,0) | ||
+ today.getMinutes().toString().padStart(2,0) | ||
+ today.getSeconds().toString().padStart(2,0) | ||
+ '.' + FileUtils.fileSuffix(path) | ||
platformUtilities.renameFile(path, qgisProject.homePath + '/' + relativePath) | ||
|
||
let pos = positionSource.projectedPosition | ||
let wkt = 'POINT(' + pos.x + ' ' + pos.y + ')' | ||
|
||
let geometry = GeometryUtils.createGeometryFromWkt(wkt) | ||
let feature = FeatureUtils.createFeature(dashBoard.activeLayer, geometry) | ||
|
||
let fieldNames = feature.fields.names | ||
if (fieldNames.indexOf('photo') > -1) { | ||
feature.setAttribute(fieldNames.indexOf('photo'), relativePath) | ||
} else if (fieldNames.indexOf('picture') > -1) { | ||
feature.setAttribute(fieldNames.indexOf('picture'), relativePath) | ||
} | ||
|
||
overlayFeatureFormDrawer.featureModel.feature = feature | ||
overlayFeatureFormDrawer.state = 'Add' | ||
overlayFeatureFormDrawer.open() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[general] | ||
name=Snap! | ||
description=Digitize points through snapping photos | ||
author=OPENGIS.ch | ||
icon=icon.svg | ||
version=1.0 | ||
homepage=https://www.opengis.ch/ |