Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML map proper markers instantiating

QML map proper markers instantiating

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.8k Views
  • 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.
  • b2softB Offline
    b2softB Offline
    b2soft
    wrote on last edited by
    #1

    Hello.
    I have a map(OpenStreetMaps) displayed using Map.qml ( Window { ... Map {...} } )
    I have a Marker.qml file (based on MapQuickItem). All is OK, when I place this marker statically to my map Map { ... Marker { params } }.

    I want to place N markers (that, sure, have coords and other params). Markers params defined in somefile.txt and this file is parsed using C++.

    The question is how to proper/faster/correctly instantiate and place parsed points to Map? Should I do method in Map.qml like a addMarker(position, name) { map.addMapItem( ? ) }?
    Or should I place this marker using only C++, like get Map container and invoke addMapItem on some "map-projected" class?

    Please, help me to understand pipeline of this.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Schluchti
      wrote on last edited by
      #2

      I have realized something similar with a MapItemView and a custom model (defined in C++ and exposed to QML).

      see http://doc.qt.io/qt-5/qml-qtlocation-mapitemview.html

      My previous approach was based on addMapItem, but in my opinion a custom model is nicer, cleaner and also better maintainable...but that's just my personal opinion, I don't know if there are any actual performance differences.

      Want to read more about Qt?

      https://gympulsr.com/blog/qt/

      Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

      1 Reply Last reply
      0
      • b2softB Offline
        b2softB Offline
        b2soft
        wrote on last edited by
        #3

        With your way I simply need to add child item to parent map Item?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Schluchti
          wrote on last edited by
          #4

          I am currently not at home, so I can't provide you a code snippet, but what you would need to do is implement your own model by subclassing QAbstractListModel and providing a latitude and longitude role. You can then either expose your model to QML and populate it there or expose the already populated model to QML.

          Have a look at https://github.com/a-team-fr/MeetupMobileQtQml/blob/master/160125/DemoProject/main.qml
          In that example a XML Listmodel is used, but the principle is the same.

          Want to read more about Qt?

          https://gympulsr.com/blog/qt/

          Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

          1 Reply Last reply
          0
          • LorenzL Offline
            LorenzL Offline
            Lorenz
            wrote on last edited by
            #5

            Hi b2soft,

            You can also take a look at the V-Play Map Example.

            There, we demonstrate how to create markers from an XML file and create an XML List Model from it, which we use for our markers. See this QML file. Thus, If you decide to change your marker source from a simple .txt file to XML, you could use this approach as well.

            Note that this example uses awesome components of V-Play Engine that simplify the task, but the concept should also be applicable for stock Qt apps.

            Cheers,
            Lorenz

            Developer @ V-Play Engine - http://v-play.net/qt

            V-Play simplifies

            • Game Development with Qt
            • Mobile App Dev with Qt esp. iOS & Android

            What others say
            V-Play scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved