[solved] map zoomout and zoomin problem



  • i draw a icon in the map,but when the map zoomin and zoomout ,the icon's position does not moved and is always at that screen position.

    but if i moved the icon to another screen position.and zoomin or zoomout ,this icon moved incorrect,why?
    @
    import QtQuick 1.1
    import QtMobility.location 1.2

    Item {
    id: page
    anchors.fill: parent
    focus: true
    property int selectedIcon: -1; // selected icon

    property int xwitdh: 26; // icon width
    property int xhight: 26; // icon hight
    property int zoom_tmp;
    TitleBar { id: titleBar; appname: "Map Markers"; z: 5; width: parent.width; height: 40; opacity: 0.8 }

    function selectMarkerIcon(mx, my){

    {
    var topLeftPoint = map.toScreenPosition(maker.coordinate);

    var xStart = parseInt(topLeftPoint.x);
    var yStart = parseInt(topLeftPoint.y);

    if((mx >= xStart) && (my >= yStart)
    && (mx <= (xStart + xwitdh)) && (my <= (yStart + xhight))){
    return 0;
    }
    }

    return -1;
    }

    Rectangle {
    id: dataArea
    anchors.top: titleBar.bottom
    anchors.bottom: parent.bottom
    width: parent.width
    color: "#343434"

    Map {
    id: map
    anchors.fill: parent
    zoomLevel: 10
    center: Coordinate {latitude: 52.45705; longitude: 13.41173}
    plugin: Plugin {
    name: "nokia"
    }

    MapImage {
    id:maker
    source: "images/button-green.png"
    coordinate: Coordinate {latitude: 52.45705; longitude: 13.41173}
    }
    }

    MouseArea {
    id: mousearea

    property bool __isPanning: false
    property int __lastX: -1
    property int __lastY: -1

    anchors.fill : parent

    onPressed: {

    selectedIcon = selectMarkerIcon(mouse.x,mouse.y)

    if(selectedIcon >= 0 ){
    maker.source = "images/button-red.png";
    }else{
    __isPanning = true
    __lastX = mouse.x
    __lastY = mouse.y
    }
    }

    onReleased: {
    if(selectedIcon >= 0){
    maker.source = "images/button-green.png";
    }
    selectedIcon = -1;

    __isPanning = false
    }

    onPositionChanged: {
    if(selectedIcon >= 0 ){
    maker.coordinate = map.toCoordinate(Qt.point((mouse.x - (xwitdh / 2)),(mouse.y - (xhight / 2))));
    }else if (__isPanning) {
    var dx = mouse.x - __lastX
    var dy = mouse.y - __lastY
    map.pan(-dx, -dy)
    __lastX = mouse.x
    __lastY = mouse.y
    }
    }

    onCanceled: {
    if(selectedIcon >= 0){
    maker.source = "images/button-green.png";
    }
    selectedIcon = -1;

    __isPanning = false;
    }
    }

    Rectangle {
    id: slidder
    anchors.top: parent.top
    anchors.right: parent.right
    anchors.rightMargin: 4;
    anchors.topMargin: 4;
    anchors.bottomMargin: 4;
    anchors.bottom: parent.bottom
    width: 20;
    border.color : "#555555"
    border.width : 2
    color: "#40000000"

    Rectangle {
    id: handle; width: 20; height: 20
    y: ((map.zoomLevel - map.minimumZoomLevel) * ((slidder.height - handle.height) / (map.maximumZoomLevel - map.minimumZoomLevel)));
    color: "white"
    MouseArea {
    anchors.fill: parent
    drag.target: parent; drag.axis: "YAxis"
    drag.minimumY: 0; drag.maximumY: slidder.height - handle.height

    onReleased:{
    zoom_tmp = map.minimumZoomLevel + (handle.y / ((slidder.height - handle.height) / (map.maximumZoomLevel - map.minimumZoomLevel)));
    map.zoomLevel = zoom_tmp;
    }
    }
    }
    }

    }

    } @

    [edit, typo in title fixed, please add @ code tags around your code as i did for you, Eddy]



  • i found the problem is th mapimage's offset.x and offset.y i have not to set for the image.thank you


Log in to reply
 

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