FemaLocalSoftware/map.qml
lopata29435_NSK 3af06d02ec finish
2025-01-08 05:13:48 +07:00

89 lines
2.4 KiB
QML

import QtQuick 2.15
import QtLocation 5.15
import QtPositioning 5.15
Item {
anchors.fill: parent
Map {
id: map
anchors.fill: parent
plugin: Plugin {
name: "osm"
PluginParameter {
name: "osm.mapping.custom.host"
value: "https://tile.openstreetmap.org/"
}
PluginParameter {
name: "osm.mapping.providersrepository.disabled"
value: "true"
}
}
center: QtPositioning.coordinate(mapCenter.latitude, mapCenter.longitude)
zoomLevel: 15
Repeater {
model: pointsList
MapQuickItem {
id: point
coordinate: modelData
anchorPoint.x: 10
anchorPoint.y: 10
sourceItem: Rectangle {
width: 20
height: 20
color: "red"
radius: 10
}
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
drag.target: map
property real startLat: map.center.latitude
property real startLon: map.center.longitude
property real startX: 0
property real startY: 0
property real zoomFactor: Math.pow(2, map.zoomLevel - 15)
cursorShape: Qt.ArrowCursor
onPressed: {
startLat = map.center.latitude
startLon = map.center.longitude
startX = mouseArea.mouseX
startY = mouseArea.mouseY
}
onPositionChanged: {
var dx = mouseArea.mouseX - startX
var dy = mouseArea.mouseY - startY
var factor = Math.pow(2, 15 - map.zoomLevel) * 0.00005;
map.center = QtPositioning.coordinate(
startLat - dy * -factor,
startLon + dx * -factor
)
}
onWheel: {
if (wheel.angleDelta.y < 0) {
map.zoomLevel -= 1
} else {
map.zoomLevel += 1
}
map.zoomLevel = Math.max(1, Math.min(map.zoomLevel, 18));
}
onContainsMouseChanged: {
cursorShape = mouseArea.containsMouse ? Qt.ClosedHandCursor : Qt.ArrowCursor
}
}
}
}