QML MapView
-
Hello, I'm exploring use of MapView{} and it's almost working how I'd like it to. I've found that it can work within a ScrollView{} and so forth, without user scrolling down stopping the user from interacting with map unlike the Map{}
Suppose that we have a QML file called "StreetMap.qml"
I've tried to cut out the irrelevant code. Just picture it has nesting like thisItem { id: _map_container property var coordinate: QtPositioning.coordinate(latitude, longitude) Plugin { id: myPlugin } MapView { anchors.fill: parent map { plugin: myPlugin center: _map_container.coordinate } } }
The problem I'm having is if I add a MapQuickItem nested in our map {}
MapQuickItem { id: marker coordinate: _map_container.coordinate anchorPoint.x: 10 anchorPoint.y: 10 sourceItem: Image { source: "qrc:/MapsModule/map_marker.png" width: 24 height: 24 fillMode: Image.PreserveAspectFit smooth: true } // Debugging: Log where the marker is placed Component.onCompleted: { console.log("Marker placed at latitude: " + _map_container.latitude + ", longitude: " + _map_container.longitude) } }
The map no longer renders. I see this error message
W/default : qrc:/MapsModule/StreetMap.qml:78 Cannot assign a value directly to a grouped property
If I have MapQuickItem nested in our MapView {}, not the map{} then the map renders and it says that the marker is at the latitude and longitude we want from our console.log but nothing is rendered on the screen at this position
If I have MapQuickItem nested in a Map {} (not a map{}) and there's no MapView {} at all then the Map{} and MapQuickItem{} renders on the screen but I lose the features provided from the MapView{} like the interactive movement
Perhaps it's not possible to have a MapQuickItem in a map in a map view or perhaps there's a problem with how I'm approaching this
Let me know if you have any idea what this "Cannot assign a value directly to a grouped property" means and if there's any way around it or whatever else might be making the map unavailable the moment we have our MapQuickItem{} in a map{} of a MapView{}
-
I think you should not try to redefine the map instance that is already contained in MapView.
Maybe this works:MapView { id: myMapView map.plugin: myPlugin map.center: _map_container.coordinate ... MapQuickItem { parent: myMapView.map ... } }
-
I think the problem is the grouped property syntax (
map { ... }
) as mentioned in the error message, try the following instead:MapView { map: Map { MapQuickItem {} } }
-
I think it is correct for the MapQuickItems to be parented to the Map, not to the MapView.
What line actually is the one from the error message (StreetMap.qml:78)?
I do it this way, but it might be unrelated:
map.plugin: myPlugin map.center: _map_container.coordinate
-
Hello Kai, I believe so too
Here's the exact output I see
Note that the complaint about the StackView is really a side effect of the other complaint of not being able to assign a value directly to a grouped property
In case, it's not possible, I also posted this as a suggestion
https://bugreports.qt.io/browse/QTBUG-133696And have full code posted there as a .txt file
Perhaps if it's not possible too, I believe it might be possible to use a GeocodeModel {} and MapRoute {} to have it set-up so can show route between a beginning and end destination with both points marked on the map (but I'm new to using Qt Location so don't quote me on that). If so, that could be an alternative approach I could explore instead of attempting to render a single marker on the map with MapQuickItem {}
-
I think you should not try to redefine the map instance that is already contained in MapView.
Maybe this works:MapView { id: myMapView map.plugin: myPlugin map.center: _map_container.coordinate ... MapQuickItem { parent: myMapView.map ... } }
-
K Kory has marked this topic as solved