Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Trouble with MapPolyLine and ListModel

    QML and Qt Quick
    2
    3
    884
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mikkie last edited by

      I have a ListModel with some coordinates. When I assign this model to the "path" property of the MapPolyLine, no line displays. I can use the addCoordinate to add points manually and that does draw the line. The code below is inside my Map{}.

      Pointers would be welcome, perhaps also pointer to good book on QML that would explain/stop problems like this.

          ListModel
          {
              id: assetsPolylineList
              ListElement
              {
                  latitude: -28.9
                  longitude: 25.1
              }
              ListElement
              {
                  latitude: -28.2
                  longitude: 25.3
              }
              ListElement
              {
                  latitude: -28.4
                  longitude: 25.5
              }
              ListElement
              {
                  latitude: -28.6
                  longitude: 25.7
              }
          }
          
          MapPolyline
          {
              id: assetsPolyline
              line.color: "red"
              line.width: 5
              visible : true
              path : assetsPolylineList
          }
      
      1 Reply Last reply Reply Quote 0
      • Pablo J. Rogina
        Pablo J. Rogina last edited by

        @Mikkie I guess you need to use a QML list not a ListModel
        In addition, why you cannot specify the list directly for the path property as shown here?

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 1
        • Pablo J. Rogina
          Pablo J. Rogina last edited by

          @Mikkie UPDATE: I was able to play with some code in order to get a simple QML list from the ListModel. Here's a snippet of my working code:

              Map {
                  id: map
                  anchors.fill: parent
                  plugin: mapPlugin
                  center: QtPositioning.coordinate(-28.2, 25.3)
                  zoomLevel: 8
                  function assetsPolylineListAsList() {
                      var list = []
                      for(var i = 0; i < assetsPolylineList.count; ++i) {
                          list.push(
                              {
                                  latitude: assetsPolylineList.get(i).latitude,
                                  longitude: assetsPolylineList.get(i).longitude
                              }
                          );
                      }
                      return list
                  }
                  MapPolyline
                  {
                      id: assetsPolyline
                      line.color: "blue"
                      line.width: 3
                      visible : true
                      path : map.assetsPolylineListAsList()
                  }
          

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply Reply Quote 0
          • First post
            Last post