Files
neochat/src/qml/LocationsPage.qml
Joshua Goins 1c0a5edd2e LocationHelper: Move clamp from zoomToFit to QML
The OSM plugin has a different zoom tolerance than what we're hardcoding
here. This fixes the map looking funky from being too zoomed while
trying to fit multiple location points at once.

(cherry picked from commit 15d6287995)
2024-09-02 09:28:15 -04:00

73 lines
2.0 KiB
QML

// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick
import QtLocation
import QtPositioning
import org.kde.kirigami as Kirigami
import org.kde.neochat
Kirigami.Page {
id: root
required property var room
title: i18nc("Locations on a map", "Locations")
padding: 0
MapView {
id: mapView
anchors.fill: parent
map.plugin: OsmLocationPlugin.plugin
visible: mapView.map.mapItems.length !== 0
map.center: {
let c = LocationHelper.center(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox));
return QtPositioning.coordinate(c.y, c.x);
}
map.zoomLevel: {
const zoom = LocationHelper.zoomToFit(LocationHelper.unite(locationsModel.boundingBox, liveLocationsModel.boundingBox), mapView.width, mapView.height)
return Math.min(Math.max(zoom, map.minimumZoomLevel), map.maximumZoomLevel);
}
MapItemView {
Component.onCompleted: mapView.map.addMapItemView(this)
anchors.fill: parent
model: LocationsModel {
id: locationsModel
room: root.room
}
delegate: LocationMapItem {
isLive: false
heading: NaN
}
}
MapItemView {
Component.onCompleted: mapView.map.addMapItemView(this)
anchors.fill: parent
model: LiveLocationsModel {
id: liveLocationsModel
room: root.room
}
delegate: LocationMapItem {}
}
Connections {
target: mapView.map
function onCopyrightLinkActivated(link: string) {
Qt.openUrlExternally(link);
}
}
}
Kirigami.PlaceholderMessage {
text: i18n("There are no locations shared in this room.")
visible: mapView.map.mapItems.length === 0
anchors.centerIn: parent
}
}