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. Scale Factor for MapQuickItem using ZoomLevel
Qt 6.11 is out! See what's new in the release blog

Scale Factor for MapQuickItem using ZoomLevel

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 2.8k Views 1 Watching
  • 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.
  • KillerSmathK Offline
    KillerSmathK Offline
    KillerSmath
    wrote on last edited by
    #1

    Hi there, i'm developing a personal project using QtLocation module.
    In a part of my project, i need to setup a Direcition Icon between 2 points to indicate what is the next step, but i've noticed that when i zoom in or zoom out my map, the scale factor of MapQuickItem and MapCircle are different.

    Example:

    Code

    MapCircle {
    
        color: "red"
        radius: 15
        center: QtPositioning.coordinate(-15.06568900, -57.17396500)
    
    }
    
    MapQuickItem{
    
        anchorPoint.x: rect.width / 2
        anchorPoint.y:  rect.height / 2
        coordinate: QtPositioning.coordinate(-15.06711, -57.17487)
    
        sourceItem: Rectangle{
            id: rect
            width: 25
            height: 25
            color: "blue"
        }
    
    }
    

    Zoom Level: 16

    0_1527484701501_zoomLevel16.png

    Zoom Level: 14.56

    0_1527484866906_zoomLevel14.54.png

    My question is: How can i calculate the scale factor using the zoom level of map to rezise my MapQuickItem objects ?

    @Computer Science Student - Brazil
    Web Developer and Researcher
    “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

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

      I believe for the MapCircle type that the radius is in meters, so it will become smaller as you zoom out. The MapQuickItem, the item size is in pixels, and the size will stay constant as you zoom in and out. So if you want them both to be the same size, I would change the MapCircle to also be a MapQuickItem with source item a rectangle with a radius that makes it a circle.

      If you want the MapQuickItem to scale as you zoom in similar to the MapCircle, you need to set its zoomLevel property to a value that is not zero. If you set the zoomLevel property to 15 for instance, then at zoom level 15 your MapQuickItem will be 1:1 scale. As in, if it was 20 pixels wide, it will be 20 pixels wide at zoom level 15. If you zoom out it will be smaller, and if you zoom in it will be larger

      1 Reply Last reply
      1
      • KillerSmathK Offline
        KillerSmathK Offline
        KillerSmath
        wrote on last edited by
        #3

        Earlier, i readed a bit of source code of MapQuickItem to check how the code resize the objects

         qreal scale = 1.0;
         // use 1+x to avoid fuzzy compare against zero
         if (!qFuzzyCompare(1.0 + zoomLevel_, 1.0))
             scale = std::pow(0.5, zoomLevel_ - map()->cameraData().zoomLevel());
          return scale;
        

        But now, with your explanation, i understood why they are using a zoomLevel variable to decide if the image needs to be rezise

        Thank you for the reply, i solved the problem with this code:

        MapQuickItem{
        
            anchorPoint.x: rect.width / 2
            anchorPoint.y:  rect.height / 2
            zoomLevel: 16 //set the zoomLevel (1:1 scale)
            coordinate: QtPositioning.coordinate(-15.06711, -57.17487)
        
            sourceItem: Rectangle{
                id: rect
                width: 25
                height: 25
                color: "blue"
            }
        
        }
        

        @Computer Science Student - Brazil
        Web Developer and Researcher
        “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

        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