QML Element MapMouseArea in QtMobility



  • Hi:

    I am trying to add a MapMouseArea on the QML Map element. However, I am getting an error that

    "MapMouseArea is not a type"

    Here is my code

    @
    import QtQuick 1.0
    import Qt 4.7
    import QtMobility.location 1.2

    Rectangle {
    id: test
    width: 800
    height: 400
    Text {
    text: "test"
    anchors.centerIn: parent
    }

    PositionSource {
                id: positionSource
                updateInterval: 1000
                active: true
                // nmeaSource: "nmealog.txt"
        }
    
    Rectangle {
        id: mapWindow
        x: 21
        y: 18
        width: 425
        height:  360
        color: "#80ff0000"
        Text {
            text:  "Map Window"
            anchors.baselineOffset:  10
        }
    
        Map {
            id: map
            z : 1
            plugin : Plugin {
                                name : "nokia"
                            }
            size.width: parent.width
            size.height: parent.height
            zoomLevel: 7
            center: Coordinate {
                latitude: 43.9
                longitude: -79.45
            }
    
            MapText { text: "Hello"; font.capitalization: Font.AllLowercase }
    
            MapMouseArea {
                property int lastX : -1
                property int lastY : -1
    
                onPressed : {
                    lastX = mouse.x
                    lastY = mouse.y
                }
                onReleased : {
                    lastX = -1
                    lastY = -1
                }
                onPositionChanged: {
                    if (mouse.button == Qt.LeftButton) {
                        if ((lastX != -1) && (lastY != -1)) {
                            var dx = mouse.x - lastX
                            var dy = mouse.y - lastY
                            map.pan(-dx, -dy)
                        }
                        lastX = mouse.x
                        lastY = mouse.y
                    }
                }
                onDoubleClicked: {
                    map.center = mouse.coordinate
                    map.zoomLevel += 1
                    lastX = -1
                    lastY = -1
                }
            }
        }
    
        Keys.onPressed: {
            if (event.key == Qt.Key_Plus) {
                map.zoomLevel += 1
            } else if (event.key == Qt.Key_Minus) {
                map.zoomLevel -= 1
            } else if (event.key == Qt.Key_T) {
                if (map.mapType == Map.StreetMap) {
                    map.mapType = Map.SatelliteMapDay
                } else if (map.mapType == Map.SatelliteMapDay) {
                    map.mapType = Map.StreetMap
                }
            }
        }
    
    }
    

    }
    @

    Thanks for your help....

    ssa21



  • From the doc:
    @A MapMouseArea is an invisible item that is typically used in conjunction with a visible map object or map item in order to provide mouse handling.@

    I think that the this would actually work better for you:
    @
    MouseArea {
    anchors.fill: map
    property int lastX : -1
    property int lastY : -1

                onPressed : {
                    lastX = mouse.x
                    lastY = mouse.y
                }
                onReleased : {
                    lastX = -1
                    lastY = -1
                }
                onPositionChanged: {
                    if (mouse.button == Qt.LeftButton) {
                        if ((lastX != -1) && (lastY != -1)) {
                            var dx = mouse.x - lastX
                            var dy = mouse.y - lastY
                            map.pan(-dx, -dy)
                        }
                        lastX = mouse.x
                        lastY = mouse.y
                    }
                }
                onDoubleClicked: {
                    map.center = mouse.coordinate
                    map.zoomLevel += 1
                    lastX = -1
                    lastY = -1
                }
            }
    

    @



  • Thanks kkrzewniak:

    That seemed to work with minor changes. I realized that the main reason original code was not working was because I was running the code on Fremantle emulator. Recreating the project as a Haramattan project seemed to do the trick.

    Thanks again for your help...

    ssa21


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.