//========================================================================
//青岛港式图 客户端程序,版权所有,中山大学
//作者: 胡如根
//修改:
//文件名:
//功能:
//最后修改时间:
//========================================================================
//将地图坐标转化为视图坐标
//将地图横坐标转化为视图横坐标
function MapToViewX(dMapX)
{
return parseInt(p_imgMapWidth/2 + (dMapX-p_midX) * p_scale);
}//将地图纵坐标转化为视图纵坐标
function MapToViewY(dMapY)
{
return parseInt(p_imgMapHeight/2 + (dMapY-p_midY) * p_scale);
}function MapToVewStr(x1,y1,x2,y2)
{
var strRes;

strRes= "'" + MapToViewX(x1) + ","
    + MapToViewY(y1) + ","
    + MapToViewX(x2) + ","
    + MapToViewY(y1) + "'"


return strRes;
}
//建立Berth对象function PortBerth(x1,y1,x2,y2,msg)
{
//var vx1,vy1,vx2,vy2;
this.vx1=0;
this.vy1=0;
this.vx2=0;
this.vy2=0;
this.x1=x1;
this.y1=y1;
this.x2=x2;
this.y2=y2;
this.msg=msg;
}PortBerth.prototype.changeViewPos=function()
{
this.vx1=MapToViewX(this.x1);
this.vy1=MapToViewY(this.y1);
this.vx2=MapToViewX(this.x2);
this.vy2=MapToViewY(this.y2);

}PortBerth.prototype.isInrect=function(x,y)
{
var bFlag;

bFlag=false;

if((this.vx1 < x) && (x < this.vx2) && (this.vy1 < y)&&(y < this.vy2)) bFlag=true;

return bFlag;
}PortBerth.prototype.debuginfo=function()
{
var strRes;


strRes = this.msg;
strRes = strRes + "p_midX=" + p_midX + " p_midY=" + p_midY + " p_scale=" + p_scale + "\n";

strRes = strRes + " x1= " + this.x1
+ " y1= " + this.y1
+ " x2= " + this.x2
+ " y2= " + this.y2 + "\n";

strRes = strRes + " vx1= " + this.vx1
+ " vy1= " + this.vy1
+ " vx2= " + this.vx2
+ " vy2= " + this.vy2 + "\n";
return strRes;}

解决方案 »

  1.   

    给你的例子是我做的一个地图程序用到得一个面向对象的例子,
    调用部分是:function onMouseClick(E){
    GetMouse(E);
    x2 = mouseX;
    y2 = mouseY;
    window.status= " x2=" + x2 + " y2=" + y2;
    var inBerth;
    inBerth=false;
    if((bTrackStarted==true)&&(event.srcElement.name=="WORKLAYER"))
    {
    OnTracking(E);
    }
    else //added 2004年6月16日
    { for(var i=0; i<berths.length; i++)
    {
    if(berths[i].isInrect(x2,y2))
    {
    //showHint("isInrect" + berths[i].debuginfo());
    //alert("bb");
    showHint(berths[i].msg);
    SelectMouseCursor("BERTH");
    inBerth=true;
    break;
    }

    }

    if(!inBerth) SelectMouseCursor("NORMAL");
    }
    return;
    }