C

Qt Cluster: Rendering and Recovery from Main UI Failure

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

// This file is part of the Qt Safe Renderer module

import QtQuick
import QtLocation
import QtPositioning
import QtGraphicalEffects
import ClusterDemo

Item {
    width: root.width / 3
    height: width

    Map {
        id: map
        width: parent.width + 300
        height: parent.height + 300
        x: -150
        y: -150
        property real speed

        plugin: Plugin {
            id: plugin
            preferred: ["mapbox"]
            PluginParameter { name: "mapbox.access_token"; value: "pk.eyJ1IjoicXRjbHVzdGVyIiwiYSI6ImZiYTNiM2I0MDE2NmNlYmY0ZmM5NWMzZDVmYzI4NjFlIn0.uk3t7Oi9lDByIJd2E0vRWg" }
            PluginParameter { name: "mapbox.map_id"; value: "qtcluster.ndeb6ce6" }
        }

        center: QtPositioning.coordinate(ValueSource.latitude, ValueSource.longitude)

        zoomLevel: 16

        enabled: false

        rotation: -ValueSource.direction

        Behavior on rotation {
            RotationAnimation {
                duration: 2000
                direction: RotationAnimation.Shortest
            }
        }

// uncomment ifndef QTIVIVEHICLEFUNCTIONS
//        PositionSource {
//            id: positionSource
//            nmeaSource: "qrc:/qml/route.txt"
//            onPositionChanged: {

//                if (position.speedValid) {
//                    // center the map on the current position
//                    if (position.direction > 0) {
//                        map.rotation = -position.direction
//                        map.center = position.coordinate
//                    }

//                    ValueSource.kph = position.speed * 3.6
//                    ValueSource.oldSpeed.shift()
//                    ValueSource.oldSpeed.push(position.speed * 3.6)
//                    ValueSource.speedChanged()
//                    //routeStopped.restart()
//                }
//            }
//        }
//        Component.onCompleted:{
//            positionSource.start()
//            //routeStopped.running = true
//        }
// end comment

        Behavior on center {
            id: centerBehavior
            enabled: true
            CoordinateAnimation { duration: 1500 }
        }
    }

    FastBlur {
        anchors.fill: map
        source: map
        radius: 0.01
        rotation: map.rotation
    }

    Image {
        id: positionImage
        anchors.centerIn: parent
        source: mapPositionImage
    }

    Text {
        color: "white"
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottomMargin: (ValueSource.carId === 0) ? 75 : 0
        font.pixelSize: 9
        text:"© Mapbox © OpenStreetMap"
    }
}