• 6148阅读
  • 2回复

[提问]关于qt quick开发地图程序的zoomout,zoomin [复制链接]

上一主题 下一主题
离线yangzl
 
只看楼主 倒序阅读 楼主  发表于: 2011-11-03
<BLOCKQUOTE ? restore>我使用qt quick的方式开发地图程序,在地图上用mapimage显示了一个图标,但是这个图标在地图放大缩小的时候屏幕位置不变,但是拖动地图时图标也跟着移动而且位置是正确的,这是怎么回事。在放大和缩小的时候我怎么控制这个图标的位置呢?
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.21173}
}
}

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


}


}
离线yangzl
只看该作者 1楼 发表于: 2011-11-03
如果我把maker移动个位置再zoomin zoomout,它改变的位置不正确。
离线yangzl
只看该作者 2楼 发表于: 2011-11-03
发现问题了,是我没有设置offset.x和offset.y
快速回复
限100 字节
 
上一个 下一个