Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-56071

Map's visibleRegion property isn't "readable" inside QML

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.9.0 Alpha
    • 5.7.0
    • Location
    • None

    Description

      Map.visibleRegion

      Goal: I want to get the current window coordinates of a map view, because I want to have an element appear offscreen and then animate to its final location.

      http://doc.qt.io/qt-5/qml-qtlocation-map.html#visibleRegion-prop exists for fetching the geocoordinates of the map, window, but it returns a geoshape, http://doc.qt.io/qt-5/qml-geoshape.html.

      The geoshape is the parent class of a georectangle, but javascript doesn't seem to support casting from one generic data type to another. Since there are no Q_INVOKABLE methods associated with geoshape which will fetch the child class, the end result is that for all intents and purposes the data stored inside the geoshape can't be accessed via QML.

      The converse, setting it, is demonstrated by https://bugreports.qt.io/browse/QTBUG-50990 and works fine.

      There are several workarounds possible to achieve the goal, such as converting the 0,0 and map.width,map.height to geocoordinates, or by simply accessing this variable through C++, where it can be dynamically cast. However, they do not seem as clean an approach since visibleRegion is already present.

      Can a Map ever be circular, or is it possible for visibleRegion to by default return a georectangle instead of a geoshape?

      If this situation cannot be solved, could the workaround be documented in the official Qt docs?

      ===========================
      P.S. Here's an example workaround. It grabs the top left corner of the map via the toCoordinate() method.

      Behavior on coordinate {
          CoordinateAnimation {
              // The marker arrives from the top of the map, directly above the final location
              from: QtPositioning.coordinate(map.toCoordinate(0, 0).latitude, longitude)
          }
      }
      

      and here's what I'd like to do:

      Behavior on coordinate {
          CoordinateAnimation {
              // The marker arrives from the top of the map, directly above the final location
              from: QtPositioning.coordinate(map.visibleRegion.topLeft.latitude, longitude)
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            paangele Paolo Angelelli
            kubark42_ Kenz Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes