﻿/*************DBLayer*********************************************/


//Code From CDCGIS
/*動態控制圖層********************************************************************************/ 
var pDBLayer = null;
var pShpLayer = null;

var BrowserType = GetBrowserType(); //dean 判斷瀏覽器
function GetBrowserType() {//dean 判斷瀏覽器
    var agent = navigator.userAgent.toLowerCase();
    return agent.indexOf("msie") != -1 ? "ie" :
         agent.indexOf("safari") != -1 ? "safari" :
         agent.indexOf("opera") != -1 ? "opera" : "ff";
}


function LayerManager(objMapBase){
	var MapBase = objMapBase;
	var aryDBLayer = new Array();
	/*************************
	aryDBLayer[0][0] = 圖層物件
	aryDBLayer[0][1] = 圖層Index
	aryDBLayer[0][2] = 圖層類別
	aryDBLayer[0][3] = 圖層名稱
	aryDBLayer[0][4] = 圖層是否顯示
	aryDBLayer[0][5] = 圖層SQLQuery 或是 Shp檔名
	*************************/
	this.AddNRTShpLayer = function(strLayerName,LayerName,shpname,color1,color2,color3){
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new NRTShpLayer(MapBase,LayerName,shpname,null,1,color1,color2,color3);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1;
		aryDBLayer[aryDBLayer.length-1][2] = 'Poly';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
		aryDBLayer[aryDBLayer.length-1][5] = LayerName;
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
};
    this.AddTempLayer = function(shpFilePath, MaxLavel, LavelColor, POSTDATA) {//dean NH 貼SWG
       aryDBLayer[aryDBLayer.length] = new Array();
       aryDBLayer[aryDBLayer.length - 1][0] = new TempLayer(MapBase, shpFilePath, MaxLavel, LavelColor, POSTDATA);
       //aryDBLayer[aryDBLayer.length-1][1] = tempLayerName;
       aryDBLayer[aryDBLayer.length - 1][1] = "";
       aryDBLayer[aryDBLayer.length - 1][2] = true;
       aryDBLayer[aryDBLayer.length - 1][3] = '';
       aryDBLayer[aryDBLayer.length - 1][0].Show();
       MapBase.AddElement(aryDBLayer[aryDBLayer.length - 1][0]);
       return (aryDBLayer[aryDBLayer.length - 1][0]);
};
	this.AddShpLayer = function(strLayerName,LayerName,shpname,color1,color2,color3){
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new TempShpLayer(MapBase,LayerName,shpname,null,1,color1,color2,color3);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1;
		aryDBLayer[aryDBLayer.length-1][2] = 'Poly';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
		aryDBLayer[aryDBLayer.length-1][5] = LayerName;
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
	};
	//20080813韋銘以下旅運規劃用
	this.AddShpLayer2 = function(strLayerName,LayerName,shpname,x){
		 
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new TempShpLayer2(MapBase,LayerName,shpname,null,1,x);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1;
		aryDBLayer[aryDBLayer.length-1][2] = 'Poly';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
		aryDBLayer[aryDBLayer.length-1][5] = LayerName;
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
	};
	//20081105韋銘以上旅運規劃用
		this.AddShpLayer3 = function(strLayerName,LayerName,shpname,x){
		 
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new TempShpLayer3(MapBase,LayerName,shpname,null,1,x);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1;
		aryDBLayer[aryDBLayer.length-1][2] = 'Poly';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
		aryDBLayer[aryDBLayer.length-1][5] = LayerName;
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
	};
	//20081105韋銘以上旅運規劃用	
	//
//	this.AddMrtShpLayer = function() {//mrt用
//	var x = '#FFFF00';
//	    LayerName = '蘆洲線';
//	    shpname = '蘆洲線';
//	    aryDBLayer[aryDBLayer.length] = new Array();
//	    aryDBLayer[aryDBLayer.length - 1][0] = new TempMrtShpLayer(MapBase, LayerName, shpname, null, 1, x);
//	    aryDBLayer[aryDBLayer.length - 1][1] = aryDBLayer.length - 1;
//	    aryDBLayer[aryDBLayer.length - 1][2] = 'Poly';
//	    aryDBLayer[aryDBLayer.length - 1][3] = LayerName;
//	    aryDBLayer[aryDBLayer.length - 1][4] = true;
//	    aryDBLayer[aryDBLayer.length - 1][5] = shpname;
//	    aryDBLayer[aryDBLayer.length - 1][0].Show();
//	    MapBase.AddElement(aryDBLayer[aryDBLayer.length - 1][0]);
//	    return aryDBLayer.length - 1;
//	};
	//
	
	this.AddRouteLayer = function(strLayerName,strShpFileName,n){
		realShpFileName = strShpFileName;
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new BusRouteShpLayer(MapBase,strShpFileName,n);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1
		aryDBLayer[aryDBLayer.length-1][2] = 'Poly';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
		aryDBLayer[aryDBLayer.length-1][5] = strShpFileName;
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
	};
	this.ttcAddpLevelLayer = function(strLayerName,strShpFileName,pid){
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new ttcTempShpLayer(MapBase,strShpFileName,pid);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1;
		aryDBLayer[aryDBLayer.length-1][2] = 'Poly';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
		aryDBLayer[aryDBLayer.length-1][5] = strShpFileName;
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
	};
	this.AddNumberPoint= function(strLayerName,innerStr){
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new TempNumberPoint(MapBase,innerStr);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1;
		aryDBLayer[aryDBLayer.length-1][2] = 'Point';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
	//	aryDBLayer[aryDBLayer.length-1][5] = SQLStr;
		//aryDBLayer[aryDBLayer.length-1][0].setSQL(SQLStr);
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
	};
	this.AddVmlLayer= function(strLayerName,innerStr){
		aryDBLayer[aryDBLayer.length] = new Array();
		aryDBLayer[aryDBLayer.length-1][0] = new TempVmlLayer(MapBase,innerStr);
		aryDBLayer[aryDBLayer.length-1][1] = aryDBLayer.length-1;
		aryDBLayer[aryDBLayer.length-1][2] = 'Point';
		aryDBLayer[aryDBLayer.length-1][3] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][4] = true;
		aryDBLayer[aryDBLayer.length-1][5] = strLayerName;
		aryDBLayer[aryDBLayer.length-1][0].Show();
		MapBase.AddElement(aryDBLayer[aryDBLayer.length-1][0]);
		return aryDBLayer.length-1;
	};
	this.getLayerIndex =
	function (strLayerName){
		for(var forIndex=0;forIndex<aryDBLayer.length;forIndex++){
			if (aryDBLayer[forIndex][3] == strLayerName){
				return forIndex;
			}
		}
		return -1;
	}
	
	this.RemovePointLayer = function(intLayerIndex){
	//aryDBLayer[intLayerIndex][0].RemoveSelf();//dean NH SWG
	MapBase.RemoveElement(aryDBLayer[intLayerIndex][0]); //dean NH SWG
		aryDBLayer[intLayerIndex] = new Array();
	};
	
	this.RemovePointLayerTrue = function(intLayerIndex){
		if(aryDBLayer[intLayerIndex][0] != undefined)
		 { return true; }
		  else
		 { return false; }
		
	};
	
	this.RemoveAllLayer = function()
	{
		try
		{
			for (var intLayerIndex=0;intLayerIndex<aryDBLayer.length;intLayerIndex++)
			{
				aryDBLayer[intLayerIndex][0].RemoveSelf();
				aryDBLayer[intLayerIndex] = new Array();
			}	
		}
		catch(E){}
		aryDBLayer = new Array();
	};
	
	this.VisibleLayer = function(intLayerIndex){
		
		if (aryDBLayer[intLayerIndex][2]){
			aryDBLayer[intLayerIndex][0].Hide();
			aryDBLayer[intLayerIndex][2] = false;
			
		}else{
			this.ShowLayer(aryDBLayer[intLayerIndex][1]);
			aryDBLayer[intLayerIndex][2] = true;
		}
		
	};
	
	this.ShowLayer = function(intLayerIndex){
		aryDBLayer[intLayerIndex][0].Show();
	};
	
	this.HideLayer = function(intLayerIndex){
		aryDBLayer[intLayerIndex][0].Hide();
	};
	
	this.getLayerLength = function(){
		return aryDBLayer.length;
	};
}

//加入DB點位
function AddDBLayer(pMapBase)
{
	this.Create = function()
	{
		if (pDBLayer==null)
			pMapBase.AddElement(pDBLayer = new TempDBLayer(pMapBase));
			
		pDBLayer.Show();
	};
}
			
function OpenDBLayer()  // 決定要控制的圖層
{
	this.MapCommand = function(tEvent, pMapBase, hObj)
	{
		if (pDBLayer==null)
			return;
			
		if (pDBLayer.IsVisible())
			pDBLayer.Hide();
		else
			pDBLayer.Show();
	};
}
function OpenShpLayer(LayerName)  // 決定要控制的圖層
{
	this.MapCommand = function(tEvent, pMapBase, hObj)
	{
		if (pShpLayer==null)
			return;
		if (pShpLayer.IsVisible())
			pShpLayer.Hide();
		else
			pShpLayer.Show();
	};
}
function TempShpLayer(pMapBase, LayerName,shpname,pid,tp,color1,color2,color3)
{
	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0);
	var rbpt = pMapBase.ToMapPoint(w, h);
//public
	this.Visible = function(Visib) {if (Visib){ this.Show();} else{ this.Hide();}};
	this.IsVisible = function() {return m_hObj.style.visibility != "Hidden";};
	this.Hide = function() {
		m_hObj.style.visibility = "Hidden";
		};
	this.Show = function() {
		m_hObj.style.visibility = "visible";
		};
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	};

	var CalculatePos = function()
	{
		var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;
	};
	this.RebuildElement = null;
	this.UpdateElement = function(imgRatio) {CalculatePos();};
	this.RebuildElement = function() 
	{
		w = pMapBase.getClientWidth();
		h = pMapBase.getClientHeight();
		ltpt = pMapBase.ToMapPoint(0, 0);
		rbpt = pMapBase.ToMapPoint(w, h);
		var mlx = MapToRealPosX(ltpt.X);
		var mly = MapToRealPosY(ltpt.Y);
		var mrx = MapToRealPosX(rbpt.X);
		var mry = MapToRealPosY(rbpt.Y);
	  var mapurl='./aspx/AddImg.aspx?tp='+tp+'&mlx='+mlx+'&mly='+mly+'&mrx='+mrx+'&mry='+mry+'&w='+w+'&h='+h+'&color1='+color1+'&color2='+color2+'&color3='+color3;
	  switch(tp)
	  {
	  	case 1:
	  	mapurl=mapurl+'&sn='+shpname;
	  	break;
	  	case 2:
	  	mapurl=mapurl+'&id='+pid;
	  	break;
	  }
		CalculatePos();	
		m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";	
	};
//private
	var m_hObj;
	var tmpArry = new Array();
//constructor
	m_hObj = pNode.ownerDocument.createElement("div");
	m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";		
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	m_hObj.style.width = w;
	m_hObj.style.height = h;
	m_hObj.style.visibility = "visible";
	this.RebuildElement();
	pNode.appendChild(m_hObj);
}
//捷運路線Shp
function NRTShpLayer(pMapBase, LayerName,shpname,pid,tp)
{
	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0);
	var rbpt = pMapBase.ToMapPoint(w, h);
//public
	this.Visible = function(Visib) {if (Visib){ this.Show();} else{ this.Hide();}};
	this.IsVisible = function() {return m_hObj.style.visibility != "Hidden";};
	this.Hide = function() {
	m_hObj.style.visibility = "Hidden";
		};
	this.Show = function() {
		m_hObj.style.visibility = "visible";
		};
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	};

	var CalculatePos = function()
	{
		var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;
	};
	this.RebuildElement = null;
	this.UpdateElement = function(imgRatio) {CalculatePos();};
	this.RebuildElement = function() 
	{
		w = pMapBase.getClientWidth();
		h = pMapBase.getClientHeight();
		ltpt = pMapBase.ToMapPoint(0, 0);
		rbpt = pMapBase.ToMapPoint(w, h);
		var mlx = MapToRealPosX(ltpt.X);
		var mly = MapToRealPosY(ltpt.Y);
		var mrx = MapToRealPosX(rbpt.X);
		var mry = MapToRealPosY(rbpt.Y);
	  var mapurl='./aspx/AddNRTImg.aspx?tp='+tp+'&mlx='+mlx+'&mly='+mly+'&mrx='+mrx+'&mry='+mry+'&w='+w+'&h='+h;
	  
	  switch(tp)
	  {
	  	case 1:
	  	mapurl=mapurl+'&sn='+shpname;
	  	break;
	  	case 2:
	  	mapurl=mapurl+'&id='+pid;
	  	break;
	  }
		CalculatePos();	
		m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";	
	};
//private
	var m_hObj;
	var tmpArry = new Array();
//constructor
	m_hObj = pNode.ownerDocument.createElement("div");
	m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";		
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	m_hObj.style.width = w;
	m_hObj.style.height = h;
	m_hObj.style.visibility = "visible";
	this.RebuildElement();
	pNode.appendChild(m_hObj);
}
//動態公車路線Shp
function BusRouteShpLayer(pMapBase, LayerName,n)
{
	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0)
	var rbpt = pMapBase.ToMapPoint(w, h);
	//jon
	var setNewm_hObj = false;
	//public
	this.Visible = function(Visib) {if (Visib) this.Show(); else this.Hide();}
	this.IsVisible = function() {return m_hObj.style.visibility!= "Hidden";}
	this.Hide = function() {m_hObj.style.visibility = "Hidden";}
	this.Show = function() {m_hObj.style.visibility = "visible";}
	
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	}
	
	var CalculatePos = function()
	{
		var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;	
	}
	this.RebuildElement = null;
	this.UpdateElement = function(imgRatio) 
	{
		//判斷是否在 RebuildElement
		CalculatePos();
	}
	//private
	var m_hObj;
	//constructor
	m_hObj = pNode.ownerDocument.createElement("span");
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	this.RebuildElement = function() 
	{
		if (!this.IsVisible())
			return;
		
		//---------------	
		//RebuildElement 時 不重算 m_hObj 位置
		//setNewm_hObj = false;
		//---------------	
		w = pMapBase.getClientWidth();
		h = pMapBase.getClientHeight();
		ltpt = pMapBase.ToMapPoint(0, 0)
		rbpt = pMapBase.ToMapPoint(w, h);
		
		var TM2X = MapToRealPosX(ltpt.X);	//<---把SWG2的左上X丟入這個Function後會傳回地圖的實際座標
		var TM2Y = MapToRealPosY(ltpt.Y);	//<---把SWG2的左上Y丟入這個Function後會傳回地圖的實際座標
		var TMR2X=MapToRealPosX(rbpt.X);	//<---把SWG2的右下X丟入這個Function後會傳回地圖的實際座標
		var TMR2Y=MapToRealPosY(rbpt.Y);
		var color = '#ffffff';
		for(var i =0 ;i<RouteShp.length;i++)
			if(RouteShp[i].n == n )color = RouteShp[i].c;
		var mapurl = "../ASPX/busroute.aspx?Layer="+ LayerName + "&Left=" + TM2X + "&Top=" + TM2Y + "&Right=" + TMR2X + "&Bottom=" + TMR2Y + "&Width=" + w + "&Height=" + h + "&MaxNum=113"+
		"&Color1="+Convert_HexToTen(color.substr(1,2))+
		"&Color2="+Convert_HexToTen(color.substr(3,2))+
		"&Color3="+Convert_HexToTen(color.substr(5,2))
		;
		//complete 時 重算 m_hObj 位置
		setNewm_hObj = true;
		CalculatePos();
		m_hObj.style.visibility = "visible";
		m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + mapurl + "', sizingMethod='image')" ;
		}
	m_hObj.style.left = 0;
	m_hObj.style.top = 0;
	m_hObj.style.visibility = "visible"
	pNode.appendChild(m_hObj);
}

////20080813韋銘
function TempShpLayer2(pMapBase, LayerName,shpname,pid,tp,gxcx)
{
 	
	
	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0);
	var rbpt = pMapBase.ToMapPoint(w, h);
//public
	this.Visible = function(Visib) {if (Visib){ this.Show();} else{ this.Hide();}};
	this.IsVisible = function() {return m_hObj.style.visibility != "hidden";};
	this.Hide = function() {
		m_hObj.style.visibility = "hidden";
		};
	this.Show = function() {
		m_hObj.style.visibility = "visible";
		//this.RebuildElement();
		};
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	};

	var CalculatePos = function()
	{
		var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;
	};
	this.RebuildElement = null;
	this.UpdateElement = function(imgRatio) {CalculatePos();};
	this.RebuildElement = function() 
	{
		w = pMapBase.getClientWidth();
		h = pMapBase.getClientHeight();
		ltpt = pMapBase.ToMapPoint(0, 0);
		rbpt = pMapBase.ToMapPoint(w, h);
		var mlx = MapToRealPosX(ltpt.X);
		var mly = MapToRealPosY(ltpt.Y);
		var mrx = MapToRealPosX(rbpt.X);
		var mry = MapToRealPosY(rbpt.Y);
		var eLayerName=escape(LayerName);
	    var mapurl = "./ASPX/BusRouteShapefile.aspx?Layer="+ eLayerName + "&Left=" + mlx + "&Top=" + mly + "&Right=" + mrx + "&Bottom=" + mry + "&Width=" + w + "&Height=" + h + "&MaxNum=113"+"&Count="+gxcx;
	
			CalculatePos();	
			
		//m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";	
		// 小O
		//m_hObj.src = mapurl;
		m_hObj.style.background="url('"+mapurl+"')";
		// end
		// window.open(mapurl);
		/* 要在web.config裡加上這3行才可以貼出路線圖
		<compilation debug="true" defaultLanguage="c#"> //這行的下面三行要加
			<compilers>
				<compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/unsafe" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
			</compilers>
		*/
	};
//private
	var m_hObj;
	var tmpArry = new Array();
//constructor

	m_hObj = pNode.ownerDocument.createElement("div");
	m_hObj.style.background="url('"+mapurl+"')";
	if(agent.indexOf("firefox") == -1)
	    m_hObj.style.filter= "Alpha(Opacity=50)";/* for IE */
    else
	    m_hObj.style.Opacity = 0.5;/* for Firefox */
	    
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	m_hObj.style.width = w;
	m_hObj.style.height = h;
	//m_hObj.style.left=0;
	//m_hObj.style.top=0;
	m_hObj.style.visibility = "visible";
// end
	this.RebuildElement();
	pNode.appendChild(m_hObj);
}
////20080813韋銘
//以下1105韋銘TempShpLayer3
function TempShpLayer3(pMapBase, LayerName,shpname,pid,tp,gxcx)
{	
	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0);
	var rbpt = pMapBase.ToMapPoint(w, h);
//public
	this.Visible = function(Visib) {if (Visib){ this.Show();} else{ this.Hide();}};
	this.IsVisible = function() {return m_hObj.style.visibility != "hidden";};
	this.Hide = function() {
		m_hObj.style.visibility = "hidden";
		};
	this.Show = function() {
		m_hObj.style.visibility = "visible";
		//this.RebuildElement();
		};
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	};

	var CalculatePos = function()
	{
		var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;
	};
	this.RebuildElement = null;
	this.UpdateElement = function(imgRatio) {CalculatePos();};
	this.RebuildElement = function() 
	{
		w = pMapBase.getClientWidth();
		h = pMapBase.getClientHeight();
		ltpt = pMapBase.ToMapPoint(0, 0);
		rbpt = pMapBase.ToMapPoint(w, h);
		var mlx = MapToRealPosX(ltpt.X);
		var mly = MapToRealPosY(ltpt.Y);
		var mrx = MapToRealPosX(rbpt.X);
		var mry = MapToRealPosY(rbpt.Y);
		var eLayerName=escape(LayerName);
	    var mapurl = "./ASPX/BusRouteShapefile.aspx?Layer="+ eLayerName + "&Left=" + mlx + "&Top=" + mly + "&Right=" + mrx + "&Bottom=" + mry + "&Width=" + w + "&Height=" + h + "&MaxNum=113"+
		"&Color1="+Convert_HexToTen(gxcx.substr(1,2))+
		"&Color2="+Convert_HexToTen(gxcx.substr(3,2))+
		"&Color3="+Convert_HexToTen(gxcx.substr(5,2))
	
			CalculatePos();	
		//m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";	
		// 小O
		//m_hObj.src = mapurl;
		m_hObj.style.background="url('"+mapurl+"')";
		// end
		// window.open(mapurl);
		/* 要在web.config裡加上這3行才可以貼出路線圖
		<compilation debug="true" defaultLanguage="c#"> //這行的下面三行要加
			<compilers>
				<compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/unsafe" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
			</compilers>
		*/
	};
//private
	var m_hObj;
	var tmpArry = new Array();
//constructor

	m_hObj = pNode.ownerDocument.createElement("div");
	m_hObj.style.background="url('"+mapurl+"')";
		
	if(agent.indexOf("firefox") == -1)
	    m_hObj.style.filter= "Alpha(Opacity=50)";/* for IE */
    else
	    m_hObj.style.Opacity = 0.5;/* for Firefox */
	    
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	m_hObj.style.width = w;
	m_hObj.style.height = h;
	//m_hObj.style.left=0;
	//m_hObj.style.top=0;
	m_hObj.style.visibility = "visible";
// end
	
	this.RebuildElement();
	pNode.appendChild(m_hObj);
}
//以上1105韋銘TempShpLayer3


//列印
function doPrintPreview(){
  //打印預覽
  this.MapCommand = function(tEvent, pMapBase, hObj)
	{
  		WB.ExecWB(7,1);
	};
}
//連到ttc
function ttcTempShpLayer(pMapBase, LayerName, pid)
{

	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0);
	var rbpt = pMapBase.ToMapPoint(w, h);
	var mapurl;
//public
	this.Visible = function(Visib) {if (Visib){ this.Show();} else{ this.Hide();}};
	this.IsVisible = function() {return m_hObj.style.visibility != "Hidden";};
	this.Hide = function() {
		m_hObj.style.visibility = "Hidden";
		};
	this.Show = function() {
		m_hObj.style.visibility = "visible";
		};
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	};
	
	
	var CalculatePos = function()
	{
		var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;
	};
	
	this.RebuildElement = null;
	this.UpdateElement = function(imgRatio) {CalculatePos();};
	
	this.RebuildElement = function() 
	{
		w = pMapBase.getClientWidth();
		h = pMapBase.getClientHeight();
		ltpt = pMapBase.ToMapPoint(0, 0);
		rbpt = pMapBase.ToMapPoint(w, h);
		var TM2X = MapToRealPosX(ltpt.X);
		var TM2Y = MapToRealPosY(ltpt.Y);
		var TM2X2 = MapToRealPosX(rbpt.X);
		var TM2Y2 = MapToRealPosY(rbpt.Y);
		
		mapurl = './routing/GetImgPng.aspx?TM2X='+TM2X +'&TM2Y='+TM2Y +'&TM2X2='+TM2X2 +'&TM2Y2='+TM2Y2 +'&w='+w+'&h='+h+'&ID='+pid;
		//window.open('http://60.251.39.227/atis/aspx/GetImgPng.aspx?TM2X='+TM2X +'&TM2Y='+TM2Y +'&TM2X2='+TM2X2 +'&TM2Y2='+TM2Y2 +'&w='+w+'&h='+h+'&ID='+pid);
				CalculatePos();
		m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";	
	};

//private
	var m_hObj;
	var tmpArry = new Array();

//constructor

	m_hObj = pNode.ownerDocument.createElement("div");
	m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";		
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	m_hObj.style.width = w;
	m_hObj.style.height = h;
	m_hObj.style.visibility = "visible";
	this.RebuildElement();
	pNode.appendChild(m_hObj);
}

function TempVmlLayer(pMapBase,innerStr)
{
	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0);
	var rbpt = pMapBase.ToMapPoint(w, h);
//public
	this.Visible = function(Visib) {if (Visib){ this.Show(); }else {this.Hide();}};
	this.IsVisible = function() {return m_hObj.style.visibility != "Hidden";};
	this.Hide = function() {m_hObj.style.visibility = "Hidden";};
	this.Show = function() {m_hObj.style.visibility = "visible";};
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	};
	
	var CalculatePos = function()
	{
	var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;
	};
	
	this.UpdateElement = function(imgRatio) {CalculatePos();};
  this.RebuildElement = function() 
	{
		var tmpa = innerStr.split(';');
		var sss='';
		ltpt = pMapBase.ToMapPoint(0, 0);
		rbpt = pMapBase.ToMapPoint(w, h);
		for ( i=0; i< tmpa.length-1; i++)
		{
			
			tmpaa = tmpa[i].split(',');
			for ( j=0; j<tmpaa.length; j=j+2 )
			{
		  	ScreenClientPt =pMapBase.FromMapPoint(RealToMapPosX(tmpaa[j]),RealToMapPosY(tmpaa[j+1]));
		  	sss=sss+ScreenClientPt.X+ ','+ScreenClientPt.Y+',';
		  }
		}


		var ass=' <v:polyline style="Z-INDEX:1;LEFT:0;POSITION:absolute;TOP:0" points="'+sss+'" filled="f" strokecolor="#0000ff" strokeweight="3pt"/>';
      m_hObj.style.left = 0;
	  m_hObj.style.top = 0;	
	  m_hObj.innerHTML =ass;
	  CalculatePos();
		m_hObj.style.visibility = "visible";
	};

//private
	var m_hObj;
//constructor
	m_hObj = pNode.ownerDocument.createElement("div");
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	//ObjDBMap.style.border = "solid 1px green";
	this.RebuildElement();
	
	pNode.appendChild(m_hObj);
}
function TempNumberPoint(pMapBase,innerStr)
{
	var pNode = pMapBase.getHObject();
	var w = pMapBase.getClientWidth();
	var h = pMapBase.getClientHeight();
	var ltpt = pMapBase.ToMapPoint(0, 0);
	var rbpt = pMapBase.ToMapPoint(w, h);
//public
	this.Visible = function(Visib) {if (Visib){ this.Show(); }else {this.Hide();}};
	this.IsVisible = function() {return m_hObj.style.visibility != "Hidden";};
	this.Hide = function() {m_hObj.style.visibility = "Hidden";};
	this.Show = function() {m_hObj.style.visibility = "visible";};
	this.RemoveSelf = function()
	{
		pNode.removeChild(m_hObj);
		m_MapBase = null;
	};
	
	var CalculatePos = function()
	{
	var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
		m_hObj.style.left = pt.X;
		m_hObj.style.top = pt.Y;
		var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
		m_hObj.style.width = ept.X - pt.X;//cltWidth * imgRatio;
		m_hObj.style.height = ept.Y - pt.Y;//cltHeight * imgRatio;
	};
	
//this.RebuildElement = null;
	this.UpdateElement = function(imgRatio) {CalculatePos();};
    this.RebuildElement = function() 
	{
			
	  var w = pMapBase.getClientWidth();
	  var	h = pMapBase.getClientHeight();
	  ltpt = pMapBase.ToMapPoint(0, 0);
		rbpt = pMapBase.ToMapPoint(w, h);
	  var i;
	  var tmpa = new Array();			
    var aaa= function(xx,yy,sx,sy,pic,num)
    {
    	 ScreenClientPt =pMapBase.FromMapPoint(RealToMapPosX(xx),RealToMapPosY(yy));	
    	 tmpa.push('<div style="position: absolute; z-index: 1; left:');
    	 tmpa.push(ScreenClientPt.X-sx);
    	 tmpa.push('px; top:');
    	 tmpa.push(ScreenClientPt.Y-sy);
    	 tmpa.push('px;width:18" align="center" >');	
    	 tmpa.push('<img src="images/print/'+pic+'" style="position: absolute;left:0;top:0;z-index:-1" ><font color="#FFFFFF" size="2">');
    	 tmpa.push(num);
    	 tmpa.push('</font></div>');
    };
	
	  aaa(Coordinate[0],Coordinate[1],16,16,'se0.gif','');
	  for ( i=2; i<(Coordinate.length)/2;i++)
	  {
	     aaa(Coordinate[i*2],Coordinate[i*2+1],9,9,'RedRound.GIF',i-1);
	  }
    aaa(Coordinate[2],Coordinate[3],16,16,'se1.gif','');
    m_hObj.style.left = 0;
	  m_hObj.style.top = 0;	
	  m_hObj.innerHTML =tmpa.join('');
	  CalculatePos();
		m_hObj.style.visibility = "visible";
	};

//private
	var m_hObj;
//constructor
	m_hObj = pNode.ownerDocument.createElement("div");
	m_hObj.style.position = "absolute";
	m_hObj.style.MozUserSelect="none";
	m_hObj.style.visibility = "visible";
	//ObjDBMap.style.border = "solid 1px green";
	this.RebuildElement();
	
	pNode.appendChild(m_hObj);
}
//
//dean 貼蘆洲線SHP
function TempMrtShpLayer(pMapBase, LayerName, shpname, pid, tp, gxcx) {
    var pNode = pMapBase.getHObject();
    var w = pMapBase.getClientWidth();
    var h = pMapBase.getClientHeight();
    var ltpt = pMapBase.ToMapPoint(0, 0);
    var rbpt = pMapBase.ToMapPoint(w, h);
    //public
    this.Visible = function(Visib) { if (Visib) { this.Show(); } else { this.Hide(); } };
    this.IsVisible = function() { return m_hObj.style.visibility != "hidden"; };
    this.Hide = function() {
        m_hObj.style.visibility = "hidden";
    };
    this.Show = function() {
        m_hObj.style.visibility = "visible";
        //this.RebuildElement();
    };
    this.RemoveSelf = function() {
        pNode.removeChild(m_hObj);
        m_MapBase = null;
    };

    var CalculatePos = function() {
        var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
        m_hObj.style.left = pt.X;
        m_hObj.style.top = pt.Y;
        var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
        m_hObj.style.width = ept.X - pt.X; //cltWidth * imgRatio;
        m_hObj.style.height = ept.Y - pt.Y; //cltHeight * imgRatio;
    };
    this.RebuildElement = null;
    this.UpdateElement = function(imgRatio) { CalculatePos(); };
    this.RebuildElement = function() {
        w = pMapBase.getClientWidth();
        h = pMapBase.getClientHeight();
        ltpt = pMapBase.ToMapPoint(0, 0);
        rbpt = pMapBase.ToMapPoint(w, h);
        var mlx = MapToRealPosX(ltpt.X);
        var mly = MapToRealPosY(ltpt.Y);
        var mrx = MapToRealPosX(rbpt.X);
        var mry = MapToRealPosY(rbpt.Y);
        var eLayerName = escape(LayerName);
        var mapurl = "./ASPX/MRTShapefile.aspx?Left=" + mlx + "&Top=" + mly + "&Right=" + mrx + "&Bottom=" + mry + "&Width=" + w + "&Height=" + h
        CalculatePos();
        //m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+mapurl+"\')";	
        // 小O
        //m_hObj.src = mapurl;
        m_hObj.style.background = "url('" + mapurl + "')";
        // end
        // window.open(mapurl);

    };

    var m_hObj;
    var tmpArry = new Array();
    //constructor

    m_hObj = pNode.ownerDocument.createElement("div");
    m_hObj.style.background = "url('" + mapurl + "')";

    if (agent.indexOf("firefox") == -1)
        m_hObj.style.filter = "Alpha(Opacity=50)"; /* for IE */
    else
        m_hObj.style.Opacity = 0.5; /* for Firefox */

    m_hObj.style.position = "absolute";
    m_hObj.style.MozUserSelect = "none";
    m_hObj.style.visibility = "visible";
    m_hObj.style.width = w;
    m_hObj.style.height = h;
    //m_hObj.style.left=0;
    //m_hObj.style.top=0;
    m_hObj.style.visibility = "visible";
    // end

    this.RebuildElement();
    pNode.appendChild(m_hObj);
}

//dean NH 貼SWG
function TempLayer(pMapBase, shpFileFolder, MaxLavel, LavelColor, POSTDATA) {

    var pNode = pMapBase.getHObject();
    var w = pMapBase.getClientWidth();
    var h = pMapBase.getClientHeight();
    var ltpt = pMapBase.ToMapPoint(0, 0)
    var rbpt = pMapBase.ToMapPoint(w, h);
    //public
    this.Visible = function(Visib) { if (Visib) this.Show(); else this.Hide(); }
    this.IsVisible = function() { return m_hObj.style.visibility != "hidden"; }
    this.Hide = function() {
        m_hObj.style.visibility = "hidden";
    }
    this.Show = function() {
        m_hObj.style.visibility = "visible";
        this.RebuildElement();
    }
    this.RemoveSelf = function() {
        pNode.removeChild(m_hObj);
        m_MapBase = null;
    }


    var CalculatePos = function() {
        var pt = pMapBase.FromMapPoint(ltpt.X, ltpt.Y);
        m_hObj.style.left = pt.X;
        m_hObj.style.top = pt.Y;
        var ept = pMapBase.FromMapPoint(rbpt.X, rbpt.Y);
        m_hObj.style.width = ept.X - pt.X; //cltWidth * imgRatio;
        m_hObj.style.height = ept.Y - pt.Y; //cltHeight * imgRatio;
    }

    this.RebuildElement = null;
    this.UpdateElement = function(imgRatio) {
        //window.status = "Update";
        m_hObj.style.display = "none";
        CalculatePos();
    }
    this.SetTransparency = function() {
        m_hObj.filters.item("DXImageTransform.Microsoft.Alpha").Opacity = tImgTrans;
    }

    //private
    var m_hObj;

    //constructor

    m_hObj = pNode.ownerDocument.createElement("img");
    m_hObj.style.filter = "progid:DXImageTransform.Microsoft.Chroma(Color=#FFFFFF)" //99CCFF
    //m_hObj.style.filter = "progid:DXImageTransform.Microsoft.Chroma(Color=#FFFFFF)"
						+ "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + tImgTrans + ")";
    //m_hObj.filters.item("DXImageTransform.Microsoft.Chroma").Color = "#BDDBF2";
    //m_hObj.filters.item("DXImageTransform.Microsoft.Alpha").Opacity = tImgTrans;
    //m_hObj = pNode.ownerDocument.createElement("div");
    //m_hObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=50, style=0)";

    m_hObj.style.position = "absolute";
    m_hObj.style.MozUserSelect = "none";
    m_hObj.style.visibility = "visible";

    this.RebuildElement = function() {
        if (!this.IsVisible())
            return;
        w = pMapBase.getClientWidth();
        h = pMapBase.getClientHeight();
        ltpt = pMapBase.ToMapPoint(0, 0)
        rbpt = pMapBase.ToMapPoint(w, h);


        mapurl = "ASPX/ServerMap.aspx?FileFolder=" + shpFileFolder + "&POSTDATA=" + escape(POSTDATA) + "&Left=" + ltpt.X + "&Top=" + ltpt.Y + "&Right=" + rbpt.X + "&Bottom=" + rbpt.Y + "&Width=" + w + "&Height=" + h;
        //mapurl = "ASPX/ServerMap.aspx?FileFolder=Shp\&POSTDATA=%u5317%u7E23%u90FD%u5E02%u8A08%u756B@%u5927%u5167%u79D1&Left=-0.57421875&Top=-0.10546875&Right=1.57421875&Bottom=1.10546875&Width=1100&Height=620";
        //window.open("").document.write(mapurl);
        //window.open(mapurl);
        //m_hObj.style.backgroundImage = "url(" + mapurl + ")";
        //m_hObj.style.visibility = "visible";
        //m_hObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + mapurl + "', sizingMethod='scale')"
        //	+	"progid:DXImageTransform.Microsoft.Alpha(opacity=" + tImgTrans +")"
        //	+	"progid:DXImageTransform.Microsoft.Chroma(color=#BDDBF2)";
        //	+	"progid:DXImageTransform.Microsoft.Alpha(opacity=" + tImgTrans +")";
        window.status = "Rebuild";
        m_hObj.onreadystatechange = function() {
            window.status = "";
            if (m_hObj.readyState == "complete") {
                CalculatePos();
                m_hObj.style.display = "";
            }
        }
        m_hObj.src = mapurl;
        //window.open(mapurl);
        //window.open("ASPX/ServerMap.aspx?FileFolder=Shp\&POSTDATA=%u5317%u7E23%u90FD%u5E02%u8A08%u756B@%u5927%u5167%u79D12&Left=0.6120638565917853&Top=0.24053250393944514&Right=0.6997103409667853&Bottom=0.27471219143944514&Width=1436&Height=560");
    }
    //m_hObj.src = mapurl;
    m_hObj.style.width = w;
    m_hObj.style.height = h;
    m_hObj.style.visibility = "visible"
    //this.RebuildElement();
    pNode.appendChild(m_hObj);
    //    pMapBase.putMapLevel(parseInt(2));
    //    pMapBase.RefreshMap(true,true);
}

function AddActiveLayer(pMapBase) {
    var lyrMng = mLayerManager;
    var LayerObj = null;
    this.getLayerObj = function()
    { return LayerObj; }
    this.refreshLayer = function() {
        var ShpFolder = "Shp\\";

        if (LayerObj != null) this.removeLayer();
        LayerObj = lyrMng.AddTempLayer(ShpFolder, null, null, POSTDATA);

    }
    this.removeLayer = function() {
        lyrMng.RemoveTempLayer(LayerObj);

    }
    this.SetTrans = function() {
        if (LayerObj != null)
            LayerObj.SetTransparency();
    }
    this.SetTmpLayerVisible = function(Visib) {
        LayerObj.Visible(Visib);
    }
}
//-------------------------------------------------------------------------------------------
