Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QML Element MapMouseArea in QtMobility

    Mobile and Embedded
    2
    3
    2512
    Loading More Posts
    • 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
      ssa21 last edited by

      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 Reply Quote 0
      • K
        kkrzewniak last edited by

        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 Reply Quote 0
        • S
          ssa21 last edited by

          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 Reply Quote 0
          • First post
            Last post