Attribuer un sourceItem différent selon un fichier JSON
bonjour a tous
j'essaie de faire une petit application qml qui place des markers sur le fond de carte openstreetmap et j'ai un peu de mal
je suis arrivé a placer mes points a partir d'un json
mais la ou je bloque c'est pour leurs assigner une image différente en fonction du type défini dans le json (vert pour tribord, rouge pour babord)
j'ai regardé du coté de Loader {sourceComponent: ... } mais je n'arrive a rien
si quelqu'un pouvait me donner un petit coup de main je serais ravi
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
import QtQuick
import QtQuick.Dialogs
import QtQuick.Controls
import QtPositioning
import QtLocation
import QtCore
import QtQuick.Controls.Basic
Rectangle {
anchors.fill: parent
Plugin {
id: mapPlugin
name: "osm"
}
Map {
id: map
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(0, 0)
zoomLevel: 6
property geoCoordinate startCentroid
WheelHandler { // zoom molette
id: wheel
rotationScale: 1/100
property: "zoomLevel"
}
DragHandler { // deplacement carte clic souris
id: drag
target: null
onTranslationChanged: (delta) => map.pan(-delta.x, -delta.y)
}
MapItemView
{
ListModel
{
id:locationModel
}
model: locationModel
delegate: MapQuickItem {
coordinate: QtPositioning.coordinate(lat, lon)
anchorPoint: Qt.point(10,10)
sourceItem: Image
{
id: image1
source: "http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_green.png"
}
Image
{
id: image2
source: "http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_red.png"
}
}
Component.onCompleted: {
var JsonString = '{
"checkpoints": [
{
"lat": 36.79072561135,
"lon": 24.239543947454,
"type" : "babord"
},
{
"lat": 36.812183283469,
"lon": 24.521191573463,
"type" : "babord"
},
{
"lat": 36.645232224364,
"lon": 24.324047435304,
"type" : "tribord"
},
{
"lat": 36.631574526733,
"lon": 24.317392955493,
"type" : "babord"
},
{
"lat": 36.612890914041,
"lon": 24.928504581399,
"type" : "tribord"
}
]
}'
var data = JSON.parse(JsonString);
locationModel.clear();
var list = data["checkpoints"];
for (var i in list)
{
locationModel.append({lat: list[i]["lat"],lon: list[i]["lon"], type:list[i]["type"]})
}
}
}
} |
merci d'avance