I'm trying to make buildings on map clickable using MouseArea. I tried using GeocodeModel with query "building" which was obviously stupid idea. Then I tried getting mapItems : list of Map Object and printing them on the console, but that: "qml: Map items: []" was the only result. Now I'm thinking if it is even possible without going into implementation side of maybe delegate of Map if such thing exists :P Why there is nothing in mapItems ? Are they in some way private in Map ?
My shortened code:
Window {
visible: true
width: 640
height: 480
Map {
id: map
anchors.fill: parent
plugin: Plugin{
name: "osm"
}
zoomLevel: 15
Component.onCompleted: {
console.log("Map items: ", map.mapItems);
}
}
GeocodeModel{
id: geoModel
plugin: Plugin{
name: "osm"
}
autoUpdate: true
query: "building"
limit: -1
onLocationsChanged: {
map.center = geoModel.get(0).coordinate
console.log(count);
}
}
Related
By following a part of this example
display multiple routes on a map using RouteMap QML Qt
I'm trying to show a route inside a MapView in a QML view of my QT application, by using the following code; but the route don't appear. No errors are appearing in the output console. Did I do something wrong?
Map {
anchors.fill: parent
plugin: mapboxglPlugin
center: QtPositioning.coordinate(60.170448, 24.942046) // Oslo
zoomLevel: 16
id: mapMain
copyrightsVisible: false
RouteModel {
id: rm
plugin: mapboxglPlugin
query: RouteQuery {id: routeQuery }
Component.onCompleted: {
routeQuery.addWaypoint(QtPositioning.coordinate(60.170448, 24.942046));
routeQuery.addWaypoint(QtPositioning.coordinate(62.170448, 23.942046));
update();
}
}
MapItemView {
model: rm
delegate: Component{
MapRoute {
route: routeData
line.color: "green"
line.width: 5
smooth: true
}
}
}
}
I have an issue with trying to display QML MapCircle on a Window when I use the Mapboxgl plugin.
I have a model which is populated from C++ and is shown on the map when the user clicks a button. Here is a snippet:
MapItemView{
model:disksModel
delegate:MapCircle{
border.color: "red"
border.width: 1
center: QtPositioning.coordinate(model.latitude, model.longitude)
radius: 53
}
}
When I use osm or esri as my plugin,
plugin:Plugin{
name:"esri"
}
I get the following which is what I expect: but using mapbox, the circles aren't displayed.
plugin:Plugin{
name:"mapboxgl"
PluginParameter {
name: "mapboxgl.mapping.use_fbo"
value: true
}
PluginParameter {
name: "mapboxgl.mapping.items.insert_before"
value: "aerialway"
}
}
However, if I change my model to use something like a MapQuickItem and then use something like a Marker,
MapItemView{
model:disksModel
delegate:MapQuickItem{
sourceItem: Image{
id:waypointMarker
opacity: .75
sourceSize.width:80
sourceSize.height:80
source: "../images/marker.png"
}
coordinate: QtPositioning.coordinate(model.latitude, model.longitude)
anchorPoint.x: waypointMarker.width/2
anchorPoint.y: waypointMarker.height/2
}
}
The coordinates of interest are then marked on the screen
. Does anyone know a workaround or fix for this?
I wanted to implement a function that users can drag the marker (which is defined as MapQuickItem) on the map and automatically change its path (which is defined as MapPolyline). Currently I can only drag the marker but don't know how to change its path.
If I want to define a DropArea under the Map and call the MapPolyline.removeCoordinate() function to change the path, how to visit the index in the delegate? And I'm not sure if this idea will work.
Here is the code:
Map {
id: map
anchors.fill: parent
plugin: mapPlugin
zoomLevel: 14
activeMapType: supportedMapTypes[7]
/* maker */
MouseArea {
anchors.fill: parent
onClicked: {
var crd = map.toCoordinate(Qt.point(mouseX, mouseY))
console.log(crd)
markerModel.append({ "latitude": crd.latitude, "longitude": crd.longitude})
line.addCoordinate(crd)
}
}
MapItemGroup {
MapPolyline {
id: line
line.width: 3
line.color: "#515151"
}
MapItemView {
add: Transition {}
remove: Transition {}
model: ListModel {
id: markerModel
}
delegate:
MapQuickItem {
id: marker
coordinate: QtPositioning.coordinate(latitude, longitude)
anchorPoint: Qt.point(markerImage.width * 0.5, markerImage.height * 0.5)
sourceItem: Image {
id: markerImage
z: 5
width: 30
height: 30
source: index <= 0 ? "Images/starting point.svg" : "Images/point black.svg"
MouseArea {
anchors.fill: parent
onClicked: {
line.removeCoordinate(index);
markerModel.remove(index);
}
drag.target: marker
}
}
}
/* maker */
}
}
}
I have tried several methods to solve the problem.
This method is not feasible cos the event (drag.onActiveChanged) is triggered only at the moment that the drag event happens.
drag.onActiveChanged: {
if(mouseArea.drag.active) {
line.replaceCoordinate(index, marker.coordinate);
}
}
I tried to define a DropArea under the Map and called the drag.ondragStarted() function to trigger the event, but I didn't figure out how to visit the index in the delegate, then I gave up.
It worked! When I dragged the marker on the map, the path automatically changed! The event (onPositionChanged) is triggered everytime the coordinate of marker changes.
onPositionChanged: {
line.replaceCoordinate(index, marker.coordinate);
}
Thank myself :-)
Currently I have this map. My problem is that the plugin parameter "osm.mapping.offline.directory" loads all tiles in the cache. If I have 20000 tiles in the folder he tries to load all those tiles. This takes a lot of time.
How can I tell the OSM Plugin how many tiles he should load.
If this does not work, have I write a new plugin?
Map
{
id: map
anchors.fill: parent
zoomLevel: 14
property bool isMapOnline = false
Component.onCompleted: map.plugin = _guiMap.mapIsOnline ? osmPlugin : offlinePlugin
Plugin
{
id: osmPlugin
name: "osm"
PluginParameter { name: "osm.mapping.host"; value: "http://tile.openstreetmap.org/" }
PluginParameter { name: "osm.mapping.providersrepository.disabled"; value: "true" }
}
Plugin
{
id: offlinePlugin
name: "osm"
PluginParameter { name: "osm.mapping.offline.directory"; value: "C:/Tiles" }
}
I have a working solution which looks very similar to yours.
First, fix the syntax error in your property initialization.
property bool isMapOnline: false
Second, replace
Component.onCompleted: map.plugin = _guiMap.mapIsOnline ? osmPlugin : offlinePlugin
with
plugin: isMapOnline ? osmPlugin : offlinePlugin
There are some other minor differences; however, this should get you working.
I want to display a list of routes on a map using Qt Location properties, I was able to display one route, but I don't know how to display multiple ones. Here's my code:
RouteModel {
id: routeModel
plugin: somePlugin
query: RouteQuery {}
Component.onCompleted: {
query.addWaypoint(QtPositioning.coordinate(26.328045523310905, 50.080033033011546));
query.addWaypoint(QtPositioning.coordinate(26.333615791655415, 50.097984054173025));
routeModel.update();
query.addWaypoint(QtPositioning.coordinate(26.291584, 50.199094));
query.addWaypoint(QtPositioning.coordinate(26.288128, 50.188725));
routeModel.update();
}
onStatusChanged: console.debug("current route model status", status, count, errorString)
}
I wish for each couple of addWayPoints to be a distinct route. How canI achieve that?
I added multiple models with their correspondent mapitemview, still it didn't work.
RouteModel {
id: routeModel
plugin: somePlugin
query: RouteQuery {}
Component.onCompleted: {
query.addWaypoint(QtPositioning.coordinate(26.328045523310905, 50.080033033011546));
query.addWaypoint(QtPositioning.coordinate(26.333615791655415, 50.097984054173025));
routeModel.update();
}
}
RouteModel {
id: rm
plugin: somePlugin
query: RouteQuery {}
Component.onCompleted: {
query.addWaypoint(QtPositioning.coordinate(26.291584, 50.199094));
query.addWaypoint(QtPositioning.coordinate(26.288128, 50.188725));
rm.update();
}
}
RouteModel {
id: rm1
plugin: somePlugin
query: RouteQuery {}
Component.onCompleted: {
query.addWaypoint(QtPositioning.coordinate(26.278496, 50.203740));
query.addWaypoint(QtPositioning.coordinate(26.272351, 50.185939));
rm.update();
}
}
Map {
id: map
anchors.fill: parent
plugin: somePlugin
center: magione
gesture.enabled: true
zoomLevel: 13
MapItemView {
model: routeModel
delegate: MapRoute {
route: routeData
line.color: "blue"
line.width: 5
smooth: true
}
}
MapItemView {
model: rm
delegate: MapRoute {
route: routeData1
line.color: "green"
line.width: 5
smooth: true
}
}
MapItemView {
model: rm2
delegate: MapRoute {
route: routeData2
line.color: "black"
line.width: 5
smooth: true
}
}
}
I was just trying to do the same task, just accomplished IT. As in your first attempt, you should add multiple addWayPoints, but update the model only once at the end. Here is an example of a route visiting the following places A->B->C->A
Component.onCompleted:
{
query.addWaypoint(QtPositioning.coordinate(-25.402340, -49.248682));
query.addWaypoint(QtPositioning.coordinate(-25.392142, -49.202556));
query.addWaypoint(QtPositioning.coordinate(-25.372512, -49.227785));
query.addWaypoint(QtPositioning.coordinate(-25.402340, -49.248682));
routeModel.update();
}
Results in: Multiple routes:
Just wondering now how do I get pinpoints at each route stoppoint.
Showing all routes returned from a query normally works out of the box (assuming the plugin you are using gives you more than one result per route request).
If you want to simultaneously display routes for multiple requests, you need one model/view per request you want to simultaneously display
I finish pointing out that, in your example, you are using the model roles wrong.
There is no such routeData1 or routeData2, but only routeData, and you should use this role every time you try to access the route data from a route model.