hey everybody i try to add several distinct lines on QML map embeded in widgets application.
I plot markers on the MAP with a MapQuickItem from a JSON and in this JSON there are some lineString that I would like to add too but they are linked to each other
I do this .
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(59.441706425544,19.50356807068)
zoomLevel: 5
property geoCoordinate startCentroid
WheelHandler { // zoom molette
id: wheel
rotationScale: 1/100
property: "zoomLevel"
}
DragHandler {
id: drag
target: null
onTranslationChanged: (delta) => map.pan(-delta.x, -delta.y)
}
MapCircle {
id:cl
center: lignes
radius: 20000
color: 'black'
}
MapItemView
{
model: pl
MapPolyline{
id:pl
line.color: "blue"
width: 2
visible: true
path: pl
}
}
Component.onCompleted: {
var JsonString = '{"features":[{"geometry":{"coordinates":[19.50356807068,59.441706425544],"type":"Point"},"properties":{"color":"Red","name":"Svenska Högarna"},"type":"Feature"},{"geometry":{"coordinates":[18.474967922139,57.474603476726],"type":"Point"},"properties":{"color":"Red","name":"Gotland Island"},"type":"Feature"},{"geometry":{"coordinates":[[23.958410829456,61.156042630065],[23.040209031792,61.150377804625]],"type":"LineString"},"type":"Feature"},{"geometry":{"coordinates":[[24.958410829456,60.156042630065],[25.040209031792,60.150377804625]],"type":"LineString"},"type":"Feature"},{"geometry":{"coordinates":[24.958410829456,60.156042630065],"type":"Point"},"properties":{"color":"Red","name":""},"type":"Feature"},{"geometry":{"coordinates":[25.040209031792,60.150377804625],"type":"Point"},"properties":{"color":"Green","name":""},"type":"Feature"},{"geometry":{"coordinates":[[24.9945,60.1518],[23.1585,59.1111],[21.1988,59.5741],[20.0335,59.8579],[19.4794,59.4686],[18.1034,58.4287],[17.89,57.3109],[17.789,56.5184],[18.6508,56.8946],[20.2978,57.6451],[21.3818,58.618],[21.9284,59.0893],[22.9255,59.2777],[24.2345,59.5249],[24.9983,60.1533]],"type":"LineString"},"properties":{"color":"white"},"type":"Feature"}],"type":"FeatureCollection"}'
var data = JSON.parse(JsonString);
var list = data["features"];
var path = []
for (var i in list)
{
if (list[i]["geometry"]["type"]==="LineString")
{
for(var j in list[i]["geometry"]["coordinates"])
{
path.push(
{
latitude:list[i]["geometry"]["coordinates"][j][1],
longitude:list[i]["geometry"]["coordinates"][j][0]
})
}
pl.path = path
console.log(path[0].latitude)
}
}
}
}
}
how can I solve the problem ? could you help me please
New contributor
Laura Lyon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.