[Qt-qml] Tile map widget

Cornelius Hald hald at icandy.de
Thu Sep 30 18:18:54 CEST 2010


Hi Eduardo!

On Thu, 2010-09-30 at 00:50 -0300, Eduardo Fleury wrote:
> 
> 
> On Wed, Sep 29, 2010 at 5:42 PM, Cornelius Hald <hald at icandy.de>
> wrote:
>         Thats a pity...
>         
>         > Alternative solutions are to either 1) handle mouse events
>         yourself,
>         > or 2) use both a map widget _and_ a flickable widget, the
>         latter being
>         > used to feed the former with the geometry to be drawn.
>         
>         
>         I'm currently looking at option 1) but reimplementing the
>         whole kinetic
>         scrolling is a bit of a pain :)
>         
> 
> Yep, and besides being a pain, it's code to be maintained. If tomorrow
> Flickable gets updated and its kinetic scrolling becomes super snappy,
> or some new cool feature is added, you won't get it, and worse, the
> map thing will have a (potentially) different scrolling behavior than
> other parts of the application that happen to use ListView or
> Flickable.

Very true...

>  
>         How do you think option 2) could work? I probably can't create
>         a
>         flickable in 1:1 map size.
> 
> I haven't gone deep into this idea but one idea is to have a Flickable
> without anything inside it, but set "contentHeight" and "contentWidth"
> to the scrollable size of the map, in the given zoom scale. Then
> behind it put the map widget, which I'm assuming will have offsetX and
> offsetY properties to define which part of the map should be drawn at
> a given moment. These two could then be put together in a wrapper QML
> item with bindings.
> 
> Something like:
> 
> ------- 8< -------  
> MapWidget.qml
> 
> Item {
>     id: root
> 
>     MapTiles {
>         id: map
>         anchors.fill: parent
>         xOffset: flickable.contentX
>         yOffset: flickable.contentY
>     }
> 
>     Flickable {
>         id: flickable
>         anchors.fill: parent
>         contentWidth: map.mapWidth   // Size in pixels needed to show
> the whole map w/ current scale
>         contentHeight: map.mapHeight
>     }
> }
> 
> ------- >8 -------
> 
>  In the above example:
> - MapWidget would be the widget/viewport you use in your application.
> Could have a size of, 400x400 pixels for instance.
> - MapTiles would be a C++ component able to contact map servers, do
> tiling, etc, etc.
>   It would provide the size of the current map in the current scale
> through the read-only properties mapWidth and mapHeight.
>   For instance, the map could be 2000x2000 pixels in 1:1 scale,
> 1000x1000 pixels in 1:2 scale and so forth. This is used to limit the
> amount one can flick the map around.
>   It would also use the properties xOffset and yOffset to define which
> parts of the map will be drawn. For instance, a 2000x2000 map when
> centered would provide offset values of 800x800, which given the size
> of MapTiles, would cause the map section (x: 800, y:800, width: 400,
> height: 400) to be drawn by MapTiles.
> 
> Does that make sense?

As far as I can tell it makes sense :) Thanks a lot for the detailed
explanation. However, now that Michael pointed me to the map widget of
qt-mobility I think I first should have a closer look at it. My first
impression is, that it doesn't support kinetic scrolling, but I have to
check that again. On the other hand it supports a lot of things I've not
even thought about ;)

Cheers,
Conny






More information about the Qt-qml mailing list