forked from opengisch/qfield-geomapfish-locator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
69 lines (58 loc) · 2.17 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import QtQuick
import QtQuick.Controls
import org.qfield
import org.qgis
import Theme
Item {
id: plugin
property var mainWindow: iface.mainWindow()
property var mapCanvas: iface.mapCanvas()
Component.onCompleted: {
geoMapFishLocatorFilter.locatorBridge.registerQFieldLocatorFilter(geoMapFishLocatorFilter);
}
Component.onDestruction: {
geoMapFishLocatorFilter.locatorBridge.deregisterQFieldLocatorFilter(geoMapFishLocatorFilter);
}
QFieldLocatorFilter {
id: geoMapFishLocatorFilter
name: "GeoMapFish"
displayName: "GeoMapFish"
prefix: "gmf"
locatorBridge: iface.findItemByObjectName('locatorBridge')
parameters: {
"service_url": "https://www.sigip.ch/search",
"service_crs": "EPSG:2056"
}
source: Qt.resolvedUrl('geomapfish.qml')
function triggerResult(result) {
if (result.userData.type === Qgis.GeometryType.Point) {
const centroid = GeometryUtils.reprojectPoint(
GeometryUtils.centroid(result.userData),
CoordinateReferenceSystemUtils.fromDescription(parameters["service_crs"]),
mapCanvas.mapSettings.destinationCrs
)
mapCanvas.mapSettings.setCenter(centroid, true);
} else {
const extent = GeometryUtils.reprojectRectangle(
GeometryUtils.boundingBox(result.userData),
CoordinateReferenceSystemUtils.fromDescription(parameters["service_crs"]),
mapCanvas.mapSettings.destinationCrs
)
mapCanvas.mapSettings.setExtent(extent, true);
}
locatorBridge.locatorHighlightGeometry.qgsGeometry = result.userData;
locatorBridge.locatorHighlightGeometry.crs = CoordinateReferenceSystemUtils.fromDescription(parameters["service_crs"]);
}
function triggerResultFromAction(result, actionId) {
if (actionId === 1) {
let navigation = iface.findItemByObjectName('navigation')
const centroid = GeometryUtils.reprojectPoint(
GeometryUtils.centroid(result.userData),
CoordinateReferenceSystemUtils.fromDescription(parameters["service_crs"]),
mapCanvas.mapSettings.destinationCrs
)
navigation.destination = centroid
}
}
}
}