Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QML Element MapMouseArea in QtMobility
Forum Updated to NodeBB v4.3 + New Features

QML Element MapMouseArea in QtMobility

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 2.7k 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.
  • S Offline
    S Offline
    ssa21
    wrote on 1 Jul 2011, 14:32 last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kkrzewniak
      wrote on 1 Jul 2011, 16:32 last edited by
      #2

      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
                  }
              }
      

      @

      Me, Grimlock, not "nice dino". ME BASH BRAINS!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        ssa21
        wrote on 2 Jul 2011, 11:16 last edited by
        #3

        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

        1 Reply Last reply
        0

        1/3

        1 Jul 2011, 14:32

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved