///返回含屏幕坐标的point对象
this.fromMapPoint=function(mapX,mapY)
{
var point = new PointObject() ;
point.x = getJX(mapX) ;
point.y = getWY(mapY) ;
return point ;
};
///返回含地图坐标的point对象
this.toMapPoint=function(screenX,screenY)
{
var point = new PointObject() ;
point.x = getScrX(screenX) ;
point.y = getScrY(screenY) ;
return point ;
};
//获得地图坐标
function getJX(scrX)
{
return (this.mapXMin+parseInt(scrX)/(document.body.clientWidth/(this.mapXMax - this.mapXMin)));
}
function getWY(scrY)
{
return (this.mapYMax-parseInt(scrY)/(document.body.clientHeight/(this.mapYMax-this.mapYMin)));
}
//获得屏幕坐标
function getScrX(mapX)
{
return (mapX - this.mapXMin) * document.body.clientWidth/(this.mapXMax-this.mapXMin) ;
}
function getScrY(mapY)
{
return (this.mapYMax - mapY) * document.body.clientHeight/(this.mapYMax-this.mapYMin) ;
}
///画图
///在不同环境下可更改此函数的实现
this.draw=function()
{
for (i=1;i<this.layers.count+1;i++)
{
this.drawLayer(this.layers.item(i)) ;
//this.control.innerHTML = this.stringBuilder.toString() ;
}
};
///绘制指定层
this.drawLayer=function(layerObject)
{
switch (layerObject.type)
{
case "tail" :
drawTailLayer(layerObject) ;
break;
case "denamic" :
drawDynamicLayer(this.control,layerObject) ;
break;
case "point" :
drawPointLayer(this.control,layerObject) ;
break;
case "line" :
break;
case "polygon" :
break;
}
};
//绘制监控层
function drawTailLayer(layerObject)
{
var sHTML ;
var tailObject = eval("div_tail") ;
var arr0 ;
for (i=1;i<layerObject.count+1;i++)
{
sHTML = '<div id="' + layerObject.item(i).id + '" name="' + layerObject.item(i).name + '"' ;
sHTML+= ' style="position:absolute;z-index:3;left:' + getScrX(layerObject.item(i).x) + ';top:' + getScrY(layerObject.item(i).y) + '">';
arr0 = layerObject.item(i).content.split(",") ;
if (arr0.length>0)
{
sHTML+= '<table border=0 width=108 bgcolor=#1949A1 cellspacing=1 cellpadding=0 style="font-size:9pt">' ;
sHTML+= '<tr><td>' ;
sHTML+= '<table border=0 width="100%" cellspacing=0 cellpadding=0>' ;
sHTML+= '<tr><td><img src="images/tail/tailtable_top.gif"></td></tr>' ;
sHTML+= '<tr><td background="images/tail/tailtable_bg.gif">' ;
sHTML+= '<table border=0 width="100%" cellspacing=0 cellpadding=3>' ;
for (j=0;j<arr0.length;j++)
{
sHTML+= '<tr><td height="20" style="color:white;font-size:9pt">' + arr0[j] + '</td></tr>' ;
}
sHTML+= '</table>' ;
sHTML+= '</td></tr></table>' ;
sHTML+= '</td></tr></table>' ;
}
sHTML+= '</div>' ;
tailObject.innerHTML+= sHTML ;
}
}
//绘制点层
function drawPointLayer(parentObject,layerObject)
{
var i ;
var oSB = new StringBuilder() ;
if (layerObject.symbol!=null)
{
for (i=1;i<=layerObject.count;i++)
{
//oSB.append(setPointVML(layerObject.item(i),layerObject.symbol)) ;
setPointVML(parentObject,layerObject.item(i),layerObject.symbol) ;
}
}
else
{
for (i=1;i<=layerObject.count;i++)
{
//oSB.append(setPointVML (layerObject.item(i))) ;
setPointVML (layerObject.item(i)) ;
}
}
return oSB ;
}
//绘制线层
function drawLineLayer(layerObject)
{
for (i=0;i<layerObject.count;i++)
{
if (layerObject.symbol!=null)
{
}
else
{
}
}
}
//绘制区层
function drawPolygonLayer(layerObject)
{
var sHTML ;
for (i=0;i<layerObject.count;i++)
{
if (layerObject.symbol!=null)
{
}
else
{
}
}
}
//绘制动态图层
function drawDynamicLayer(layerObject)
{
var sHTML ;
sHTML = "" ;
for (i=0;i<layerObject.count;i++)
{
if (layerObject.item(i).type == "point")
{
}
else if (layerObject.item(i).type == "line")
{
}
else if (layerObject.item(i).type == "polygon")
{
}
}
}
///客户端绘图更新
///在此处,更新的含义更多体现为更改各要素在屏幕的坐标,即left和top
this.refresh=function()
{
var obj ;
var i,j ;
for (i=1;i<this.layers.count+1;i++)
{
switch (this.layers.item(i).type)
{
case "tail":
for (j=1;j<this.layers.item(i).count+1;j++)
{
//alert(i + "," + j) ;
obj = eval(this.layers.item(i).item(j).id) ;
obj.style.left = getScrX(this.layers.item(i).item(j).x) ;
//alert(i+"&" + j + ":" + this.layers.item(i).item(j).x + "," + obj.style.left) ;
obj.style.top = getScrY(this.layers.item(i).item(j).y) ;
//alert(i+"&" + j + ":" + this.layers.item(i).item(j).y + "," + obj.style.top) ;
}
break;
case "point":
for (j=1;i<this.layers.item(i).count+1;j++)
{
obj = eval(this.layers.item(i).item(j).id) ;
obj.style.left = getScrX(this.layers.item(i).item(j).x) ;
alert(obj.style.left) ;
obj.style.top = getScrY(this.layers.item(i).item(j).y) ;
}
break;
case "" :
}
}
}
//画点对象
function setPointVML(parentObject,pointObject,symbolObject)
{
var sHTML = "" ;
switch (symbolObject.style)
{
//圆形
case 0 :
sHTML+='<v:oval' ;
if (pointObject.id!="")
sHTML+= " id=\"" + pointObject.id + "\"";
if (pointObject.name!="")
sHTML+= " name=\"" + pointObject.name + "\"";
sHTML+= ' style="position:relative;' ;
if (symbolObject.size>0)
{
if (pointObject.y!="")
sHTML+= 'top:' + (parseInt(pointObject.y)+symbolObject.size/2) + ';' ;
if (pointObject.x!="")
sHTML+= ' left:' + (parseInt(pointObject.x)+symbolObject.size/2) + ';' ;
sHTML+= 'width:' + symbolObject.size + ';' ;
sHTML+= 'height:' + symbolObject.size + ';' ;
}
if (symbolObject.color!="")
sHTML+= ' fillcolor="' + symbolObject.color + '"';
if (symbolObject.border>0)
{
sHTML+= ' strokeWeight="' + symbolObject.border + '"' ;
if (symbolObject.bordercolor>0)
sHTML+= ' strokeColor="' + symbolObject.bordercolor + '"' ;
}
sHTML+="></v:oval>" ;
break;
//矩形
case 1 :
sHTML+='<v:rect ' ;
if (pointObject.id!="")
sHTML+= " id=\"" + pointObject.id + "\"";
if (pointObject.name!="")
sHTML+= " id=\"" + pointObject.name + "\"";
sHTML+= ' style="position:relative;' ;
if (symbolObject.size>0)
{
if (pointObject.y!="")
{
sHTML+= 'top:' + String(parseInt(pointObject.y)+symbolObject.size/2) + ';' ;
}
if (pointObject.x!="")
sHTML+= ' left:' + (parseInt(pointObject.x)+parseInt(symbolObject.size/2)) + ';' ;
sHTML+= 'width:' + symbolObject.size + ';' ;
sHTML+= 'height:' + symbolObject.size + ';' ;
}
if (pointObject.color!="")
sHTML+= ' fillcolor="' + symbolObject.color + '"';
if (pointObject.border>0)
{
sHTML+= ' strokeWeight="' + symbolObject.border + '"' ;
if (symbolObject.bordercolor>0)
sHTML+= ' strokeColor="' + symbolObject.bordercolor + '"' ;
}
sHTML+="></v:rect>" ;
break;
//图片
case 10 :
sHTML+='<v:image ' ;
if (pointObject.id!="")
sHTML+= " id=\"" + pointObject.id + "\"" ;
if (pointObject.name!="")
sHTML+= " id=\"" + pointObject.name + "\"" ;
if (symbolObject.image!="")
{
sHTML+= ' src="' + symbolObject.image + '"' ;
sHTML+=' style="top:' + pointObject.y + ';left:' + pointObject.x + '"' ;
}
sHTML+= "></v:image>" ;
break;
}
var newPoint = document.createElement(sHTML) ;
parentObject.insertBefore(newPoint) ;
}
}
///layers集合
function Layers()
{
var pri_LayerArray = new Array() ;
this.count=pri_LayerArray.length ;
this.item=function(index)
{
return pri_LayerArray[index-1] ;
};
this.add=function(layer)
{
pri_LayerArray[pri_LayerArray.length] = layer ;
this.count=pri_LayerArray.length ;
};
this.remove=function(index)
{
var i ;
for (i=index;i<pri_LayerArray.length;i++)
{
pri_LayerArray[index-1] = pri_LayerArray[index] ;
}
pri_LayerArray[pri_LayerArray.length-1] = null ;
this.count=pri_LayerArray.length ;
}
}
///自我约束的layer模式,点线面图层需谨慎使用
///使用错误则不能自我判别
function LayerObject(layerid,layername)
{
var pri_objArray =new Array();
this.id = layerid ;
this.name = layername ;
this.visible = true ;
this.type = "dynamic" ;
this.symbol = null ;
this.count = pri_objArray.length ;
this.add=function(object)
{
pri_objArray[pri_objArray.length] = object ;
this.count = pri_objArray.length ;
} ;
this.item = function(index)
{
return pri_objArray[index-1] ;
}
this.remove=function(index)
{
for (i=index;i<this.count;i++)
{
pri_objArray[index-1] = pri_objArray[index] ;
}
pri_objArray[pri_objArray.length-1] = null ;
this.count = pri_objArray.length ;
}
this.setSymbol=function(object)
{
if (this.type == "dynamic")
{
return null ;
}
else
{
this.symbol = object ; //symbol赋值
}
}
}
//PolyLine对象
function PolyLineObject()
{
var pri_PolyLine = null;
var pri_Stroke = null ;
this.parent = null ;
this.id = "" ;
this.Points = new Points() ;
this.filled = "false" ;
this.startArrow = "" ;
this.endArrow = "" ;
this.dashStyle = "" ;
}
//点集合
function Points()
{
var pri_Points = new Array() ;
this.count = pri_Points.length ;
this.item=function(index)
{
return p_Points[index-1] ;
};
this.add=function(pointObject)
{
p_Points[p_Points.length] = pointObject ;
this.count = getLength() ;
};
this.remove=function(index)
{
var i ;
for (i=index;i<this.count;i++)
{
pri_Points[index-1] = pri_Points[index]
}
pri_Points[pri_Points.length-1] = null ;
this.count = getLength() ;
}
function getLength()
{
return p_Points.length ;
}
}
//线对象
function LineObject()
{
var line = null ;
this.parent = null ;
this.id = "" ;
this.fromX = 0 ;
this.fromY = 0 ;
this.toX = 0 ;
this.toY = 0 ;
this.symbol = new LineSymbol() ;
}
//点对象
function PointObject(id,name,code,x,y)
{
this.id = id ;
this.name = name ;
this.code = code ;
this.x = x ;
this.y = y ;
this.symbol = null ;
}
//监控对象
function TailObject()
{
this.id = "" ;
this.id = "" ;
this.x = "" ;
this.y = "" ;
this.content = "" ;
}
///范围
function Envelope(xmin,ymin,xmax,ymax)
{
this.xMin = xmin ;
this.yMin = ymin ;
this.xMax = xmax ;
this.yMax = ymax ;
}
function PointSymbol()
{
this.style=0 ;
this.size=10 ;
this.border=0 ;
this.color = "red" ;
this.bordercolor="" ;
this.transparency = 1 ;
this.image="" ; //如果style=image,给这个属性赋值(相对路径)
}
//字符串连接操作类,大量字符串累加的时候可提高效率
function StringBuilder(sString)
{
this.length=0;
this._current=0;
this._parts=[];
this._string=null;
if(sString!=null)
this.append(sString);
this.append=function(sString)
{
this.length+=(this._parts[this._current++]=String(sString)).length;
this._string=null;
return this;
}
this.appendSB = function(stringBuilder)
{
//for (i=0;i<stringBuilder.length;i++)
//{
// this.append(String(stringBuilder._parts[i])) ;
//}
this.append(stringBuilder.toString()) ;
return this ;
}
this.toString=function()
{
if(this._string!=null)
return this._string;
var s=this._parts.join("");
this._parts=[s];
this._current=1;
return this._string=s;
}
}