I'm using QtLocation QML Map to display a big amount of items on a map. As with the number of items visible on the map the performance decreases, i would like to set visible only the items actually visible on the viewport. For this it would be handy to just calculate the visibility based on whether the item's coordinate is within the viewport, like:
visible: mapBase.visibleRegion.contains(model.item.coordinate)
But unfortunately the visibleRegion property is non-NOTIFYable, as stated in the documentation at http://doc.qt.io/qt-5/qml-qtlocation-map.html#visibleRegion-prop.
Is there any specific reason (like performance-issues) to not implement a notify signal for this property? Is there any way to workaround this, and set the visibility of a map item based on whether it's within the viewport?
From the current documentation, Since Qt 5.14 visibleRegion
now provides change notifications - so, if you use newer Qt, you will get this.
Note though - with Qt 6, Qt Location was changed significantly. Much of it was rewritten. Lots of the API remains the same, but a not-insigificant amount of the API has been changed or removed. visibleRegion
, however, is still present.
From the Qt 5.15 visibleRegion
docs:
visibleRegion : geoshape
This property holds the region which occupies the viewport of the map. The camera is positioned in the center of the shape, and at the largest integral zoom level possible which allows the whole shape to be visible on the screen. This implies that reading this property back shortly after having been set the returned area is equal or larger than the set area.
Setting this property implicitly changes the center and zoomLevel of the map. Any previously set value to those properties will be overridden.
Note: Since Qt 5.14 This property provides change notifications.
This property was introduced in Qt 5.6.
From the Qt 6.8 visibleRegion
docs:
visibleRegion : geoshape
This property holds the region which occupies the viewport of the map. The camera is positioned in the center of the shape, and at the largest integral zoom level possible which allows the whole shape to be visible on the screen. This implies that reading this property back shortly after having been set the returned area is equal or larger than the set area.
Setting this property implicitly changes the center and zoomLevel of the map. Any previously set value to those properties will be overridden.
Note: Since Qt 5.14 This property provides change notifications.
(Note that these are almost identical).