DomTomCat
DomTomCat

Reputation: 8569

MapQuickItem invisible in model/view delegate

Adding a new QtQuick application in QtCreator and replaceing the main.qml with the following code will result in an application which adds a MapCircle at the place of the mouse click. However, if I replace the delegate: MapCircle [...] with a custem delegate: MapQuickItem [...], the item will be added (see console log), however it is not displayed.

The same MapQuickItem [...] block as fixed object within Map {...} and some coordinate will be displayed.

Am I missing something or might this be a bug?

import QtQuick 2.6
import QtQuick.Window 2.2
import QtPositioning 5.5
import QtLocation 5.6

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    MainForm {
        anchors.fill: parent

        ListModel {
            id: mapModel
        }

        Map {
            id: map
            anchors.centerIn: parent
            anchors.fill: parent
            plugin: Plugin {
                name: "osm" // "mapboxgl", "esri", ...
            }

            MapItemView {
                model: mapModel
                /* // the following code won't display the MapQuickItem item
                delegate: MapQuickItem {
                    sourceItem: Rectangle {
                        width: 14
                        height: 14
                        color: "#2ad3f9"
                        radius: 7
                    }
                    anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
                    coordinate {
                        latitude: lat
                        longitude: lon
                    }
                } */
                // this works as expected
                delegate: MapCircle {
                    radius: 8000
                    color: 'blue'
                    center {
                        latitude: lat
                        longitude: lon
                    }
                }
            }
            MouseArea
            {
                anchors.fill: parent
                onClicked:
                {
                    var coord = map.toCoordinate(Qt.point(mouse.x, mouse.y))
                    mapModel.append({lat : coord.latitude, lon: coord.longitude});
                    console.log(mapModel.count)
                }
            }
        }
    }
}

Upvotes: 1

Views: 597

Answers (1)

DomTomCat
DomTomCat

Reputation: 8569

Explicitly casting the coordinate to QtPositioning.coordinate will do the trick:

MapItemView {
    model: mapModel
    delegate: MapQuickItem {
        sourceItem: Rectangle {
            width: 14
            height: 14
            color: "#2ad3f9"
            radius: 7
        }
        anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
        coordinate : QtPositioning.coordinate(lat, lon)
    }
}

Upvotes: 2

Related Questions