﻿_dgmap4path = "easymap/";



//alert(typeof(_ezmappath));
if(typeof(_ezmappath) != 'undefined') _dgmap4path = _ezmappath;
tArray = location.href.split('/');
if(tArray[tArray.length-1] == "map.htm" || tArray[tArray.length-1] == "wmap.htm")
{
	_dgmap4path = "";
}

document.write("<script type='text/javascript' src='" + _dgmap4path + "inc/yoext.js'></script>");
//document.oncontextmenu = function() {return false;}

//ini 新增參數
var _wmsMode = 0;

var digimap4s = [];
var _menuX = null, _menuY = null;

function digimap4(a)
{
	var tmi = document.createElement('iframe');
	tmi.frameBorder = 0;
	tmi.src = _dgmap4path + 'map.htm';
	
	tmic = tmi.cloneNode(true);
	tmic.id = "_" + a.id + "_instance_";
	tmic.name = "_" + a.id + "_instance_";
	a.appendChild(tmic);
	
	a.style.width = (a.style.width == null) ? ((parseInt(a.parentNode.offsetWidth))+'px') : a.style.width;
	a.style.height = (a.style.height == null) ? ((parseInt(a.parentNode.offsetHeight)) + 'px') : a.style.height;
	
	//mi = "<iframe id='_"+a.id+"_instance_' name='"+'_'+a.id+'_instance_'+"' style='frameborder:0px;border:0px;overflow:hidden;width:"+parseInt(a.style.width)+"px;height:"+parseInt(a.style.height)+"px;' frameborder=0px src='map.htm'></iframe>";
	//a.innerHTML = mi;
	tmic.style.width = parseInt(a.style.width) + "px";
	tmic.style.height = parseInt(a.style.height) + "px";
	
	this.div = a;
	this.instance = frames['_' + a.id + '_instance_'];
	
	this.resize = function(rw, rh)
	{
		a.style.width = rw + 'px';
		a.style.height = rh + 'px';
		if(!document.all)
		{
			document.getElementById('_' + a.id + '_instance_').style.width = rw + 'px';
			document.getElementById('_' + a.id + '_instance_').style.height = rh + 'px';
		}
		try
		{
			this.instance.resizeTo(rw, rh);
			this.instance.mapResize(rw, rh);
		}
		catch(e){}
		return true;
	}

	this.zoomToXY = function(txy, tz)
	{
		if(txy == null || tz == null)
		{
			return false;
		}
		else
		{
			this.instance.zoomTo(txy,tz);
			return true;
		}
	}

	this.goXY = function(txy)
	{
		if(txy == null)
		{
			return false;	
		}
		else
		{
			this.instance.zoomTo(txy,this.getZoomLevel());
			return true;
		}
	}
	
	this.zoomTo = function(tz)
	{
		if(tz == null)
		{
			return false;	
		}
		else
		{
			this.instance.zoomTo(new dgXY(this.getCX(),this.getCY()),tz);
			return true;
		}
	}

	this.setZoomLevel = function(zoom)
	{
		this.instance.cz = zoom ;
	}

	this.panTo = function(tz,dis)
	{
		this.instance.exPanTo(tz,dis);
	}

	this.zoomIn = function()
	{
		this.instance.zoomIn();
		return true;
	}

	this.zoomOut = function()
	{
		this.instance.zoomOut();
		return true;
	}

	this.addItem = function(obj)
	{
		var _tmpary = [];
		if(isArray(obj))
		{
			_tmpary = obj;	
		}
		else
		{
			_tmpary.push(obj);	
		}
		
		for(iv=0;iv<_tmpary.length;iv++)
		{
			_tmpary[iv].instance = this.instance;
		}
		this.instance.addItem(obj);
		return true;
	}

	this.removeItem = function(obj)
	{
		this.instance.removeItem(obj);
		return true;
	}

	this.getCX = function()
	{
		return this.instance.cx;
	}

	this.getCY = function()
	{
		return this.instance.cy;
	}

	this.getCenter = function()
	{
		return new dgXY(this.getCX(),this.getCY());
	}

	this.getRectBound = function()
	{
		ltX = this.getCX() - this.getWidth()*this.getXScale()/2;
		ltY = this.getCY() + this.getHeight()*this.getYScale()/2;
		rbX = this.getCX() + this.getWidth()*this.getXScale()/2;
		rbY = this.getCY() - this.getHeight()*this.getYScale()/2;
		
		return [ltX, ltY, rbX, rbY];
	}

	this.getZoomLevel = function()
	{
		return this.instance.cz;
	}

	this.getPScale = function()
	{
		return this.instance.pscale;
	}

	this.getXScale = function()
	{
		return this.instance.xscale;
	}

	this.getYScale = function()
	{
		return this.instance.yscale;
	}

	this.getWidth = function()
	{
		return this.instance.vw;
	}

	this.getHeight = function()
	{
		return this.instance.vh;
	}
	
	this.getMapName = function()
	{
		return this.instance.mname;
	}
	
	this.getStatusBar = function()
	{
		return this.instance.stdiv;
	}

	this.setScaleBarXY = function(ixy)
	{
		this.instance.isbxy = (this.instance.isbxy == null) ? ixy : this.instance.isbxy;
		this.instance.sbdiv.style.left = ixy[0] + 'px';
		this.instance.sbdiv.style.top = ixy[1] + 'px';
	}
	
	this.switchMapType = function(mname, zl)
	{
		if(mname == null)
		{
			return false;
		}
		else if(zl == null)
		{
			return this.instance.msSwitch(mname, this.getZoomLevel());
		}
		else
		{
			return this.instance.msSwitch(mname, zl);
		}
	}

	this.addMapControl = function(itxy)
	{
		this.instance.addMapControl(itxy);
	}
	
	this.addMapTypeSelector = function(stype,itxy)
	{
		this.instance.addMapTypeSelector(stype,itxy);
	}
	
	this.addWMap = function(imc,ifuncs)
	{
		this.instance.addWMap(imc,ifuncs);
	}

	this.clearMarker = function()
	{
		try
		{
			this.instance.clearMarker();
		}
		catch(e)
		{
			return false;
		}
		return true;
	}

	this.clearDraw = function()
	{
		this.instance.clearDraw();
		return true;
	}

	this.openInfoWindow = function(xy,wobj,ww,wh)
	{
		this.instance.openInfoWindow(xy,wobj,ww,wh);
		return true;
	}
	
	this.closeInfoWindow = function()
	{
		this.instance.closeInfoWindow();
		return true;
	}
	
	this.refreshMap = function()
	{
		this.instance.reloadMapPic();
	}
	
	this.setDrawMode = function(dtype,rfunc,afunc)
	{
		if(dtype)
		{
			this.instance.sDrawMode(dtype,rfunc,afunc);
		}
	}
	
	this.getDrawResult = function()
	{
		return this.instance.drawRval;
	}

	this.getDrawResultObject = function()
	{
		return this.instance.drawRobj;
	}

	this.clearDrawResult = function()
	{
		this.instance.drawRval = null;
	}
	
	this.isDrawMode = function(tf)
	{
		if(this.instance.actMode == 'draw')	return true;
		else	return false;	
	}

	this.setDraggable = function(tf)
	{
		this.instance.setMapDraggable(tf);
	}

	this.setMapControlV = function(tf)
	{
		this.instance.setMapControlV(tf);
	}
	
	this.setWMapV = function(tf)
	{
		this.instance.setWMapV(tf);
	}

	this.setMapTypeSelectorV = function(tf)
	{
		this.instance.setMapTypeSelectorV(tf);
	}
	
	this.revXY = function(px, py)
	{
		reval = new dgXY(this.instance.revX(px), this.instance.revY(py));
		return reval;
	}
	
	this.tranXY = function(idgxy)
	{
		reval = [this.instance.tranX(idgxy.x),this.instance.tranY(idgxy.y)];
		return reval;
	}
	
	this.attachEvent = function(etype,cfunc)
	{
		this.instance.attachEvent(etype,cfunc);
	}
	
	this.addMapPickProc = function(pfunc)
	{
		this.instance.pickProc = pfunc;
	}
	this.addMapDragProc = function(pfunc)
	{
		this.instance.dragProc = pfunc;
	}
	this.addMapDropProc = function(pfunc)
	{
		this.instance.dropProc = pfunc;
	}
	this.addPanProc = function(pfunc)
	{
		this.instance.panProc = pfunc;
	}
	this.addZoomProc = function(pfunc)
	{
		this.instance.zoomProc = pfunc;
	}
	this.addEZQuery = function(pfunc)
	{
		this.instance.ezProc = pfunc;
	}
	
	this.getBestZoomByScale = function(ixscale, iyscale)
	{
		return this.instance.getBestZoomByScale(ixscale, iyscale);
	}
	
	this.setWMSMode = function(wmode, wurl, wpara, minZ, maxZ)
	{
		if(wmode != null)	this.instance._wmsMode = wmode;
		if(wurl != null)	this.instance._wmsUrl = wurl;
		if(wpara != null)
		{
			this.instance._wmsPara = wpara;
			if(typeof(wpara) != 'string')
			{
				wpara.action = wurl;
				wpara.target = '_wmsFrame_';
			}
		}
		if(minZ != null)	this.instance._wmsMinZ = minZ;
		if(maxZ != null)	this.instance._wmsMaxZ = maxZ;
		return this.instance.document.getElementById("_wmsPIC_");
	}

	this.createDiv = function()
	{
		tmpdiv = this.instance.document.createElement('div');
		this.instance.document.body.appendChild(tmpdiv);
		return tmpdiv;
	}
	
	this.removeDiv = function(rdiv)
	{
		return this.instance.document.body.removeChild(tmpdiv);
	}
	
	this.getWMSMode = function(mPara)
	{
		if(mPara == 'Mode') 
			return 	this.instance._wmsMode ;
		else if (mPara == 'Url') 
			return 	this.instance._wmsUrl ;
		else if (mPara == 'Para') 
			return 	this.instance._wmsPara ;
		else
			return null;
	}
	
	this.refreshWMS = function()
	{
		this.instance.getWMS();
	}

	this.getUpperZoomByBoundary = function(ixy1, ixy2)
	{
		if(ixy1 != null && ixy2 != null)	this.instance.getUpperZoomByBoundary(ixy1, ixy2);
		return;
	}
	
	this.getScaleByZoom = function(izoom)
	{
		return this.instance.getScaleByZoom(izoom);
	}

	this.wheelZoom = function(tf)
	{
		this.instance.swheelZoom(tf);
	}

	this.getPicPath = function(ox,oy)
	{
		return this.instance.getPicPath(ox,oy);
	}

	this.getRectPic4 = function(x1,y1,x2,y2)
	{
	
		return this.instance.getRectPic4(x1,y1,x2,y2);
	}

	this.getRectPic = function()
	{
	
		return this.instance.getRectPic();
	}
	
	this.getRectPicBBOX = function()
	{
	
		return this.instance.getRectPicBBOX();
	}

	this.getRectPicBBOX4 = function(x1,y1,x2,y2)
	{
	
		return this.instance.getRectPicBBOX4(x1,y1,x2,y2);
	}

	digimap4s.push(this);
	
}
var easymap = digimap4, ezmap = digimap4;

function dgXY(cdx,cdy,tf)
{
	this.x = (cdx == null) ? null : parseFloat(cdx);
	this.y = (cdy == null) ? null : parseFloat(cdy);
	this.os = (tf == null) ? false : tf;
	return this;
}

function dgIcon(isrc, iw, ih)
{
	this.src = (isrc == null) ? null : isrc;
	this.width = (iw == null) ? 0 : iw;
	this.height = (ih == null) ? 0 : ih;

	this.image = document.createElement('img');
	this.image.src = this.src;
	this.image.style.cssText = 'position:absolute;left:'+(-this.width/2)+'px;top:'+(-this.height/2)+'px';

	return this;
}

function dgMarker(xy,mobj,da)
{
	this.type = 'marker';
	this.xy = (xy == null) ? null : xy;
	this.drag = (da == null) ? false : da;
	this.id = null;
	this.htmlstr = null;
	this.instance = null;

	tmpobj = (mobj == null)? (dg_DEFAULT_ICON) : mobj;
	
	if(tmpobj instanceof dgIcon)
	{
		tmpdiv = document.createElement('div');
		tmpdiv.appendChild(tmpobj.image);
		this.htmlstr = tmpdiv.innerHTML;
	}
	else if(typeof(tmpobj) == 'object')
	{
		tmpdiv = document.createElement('div');
		tmpdiv.appendChild(tmpobj);
		this.htmlstr = tmpdiv.innerHTML;
	}
	else if(typeof(tmpobj) == 'string')
	{
		this.htmlstr = 	tmpobj;
	}

	this.getXY = function()
	{
		return this.xy;
	}

	this.setXY = function(tmpxy)
	{
		this.xy = tmpxy;
		this.instance.reposMark();
	}
	
	this.setContent = function(mobj)
	{
		if(this.instance != null)
		{
			this.instance.removeItem(this);
		}
		
		if(typeof(mobj) == 'object')
		{
			tmpdiv = document.createElement('div');
			tmpdiv.appendChild(mobj);
			this.htmlstr = tmpdiv.innerHTML;
		}
		else if(typeof(mobj) == 'string')
		{
			this.htmlstr = 	mobj;
		}
		
		if(this.instance != null)
		{
			this.instance.addItem(this);
		}
	}
	
	this.openInfoWindow = function(wcontent, ww, wh)
	{
		if(this.instance != null)
		{
			this.instance.openInfoWindow(this.xy, wcontent, ww, wh);
		}
		//alert('def:' + this.xy.x + ',' + this.xy.y);
	}
	
	return this;
}

function dgGText(xary,yary,htmlary,idary)
{
	this.type = 'gtext';
	this.xys = new Array();
	this.instance = null;
	for(i=0;i<xary.length;i++)
	{
		this.xys.push(new dgXY(xary[i],yary[i]));	
	}
	this.htmlstrs = htmlary;
	this.ids = idary;
	
	this.getPoint = function(imid)
	{
		for(ic=0;ic<this.xys.length;ic++)
		{
			if(this.ids[ic] == imid)
				return this.xys[ic];
		}
		return null;
	}
	
	this.setPoint = function(imid, ixy)
	{
		if(this.instance != null)
		{
			for(ic=0;ic<this.instance.markArray.length;ic++)
			{
				if(this.instance.markArray[ic].id == imid)
				{
					this.instance.markArray[ic].id = ixy;
					return true;
				}
			}
		}
		return false;
	}
	
	return this;
}

function dgPoint(xy,fs,ptR)
{
	this.type = 'point';
	this.x = xy.x;
	this.y = xy.y;
	this.instance = null;
	this.fillStyle = fs;
	this.ptRadius = ptR;
	return this;
}

function dgSPoint(xy,fs,ptR)
{
	this.type = 'spoint';
	this.x = xy.x;
	this.y = xy.y;
	this.instance = null;
	this.fillStyle = fs;
	this.ptRadius = ptR;
	return this;
}


function dgPolyline(pts,ss,sw)
{
	this.type = 'polyline';
	this.xys = pts;
	this.instance = null;
	this.pcount = this.xys.length;
	this.strokeStyle = ss;
	this.lineWidth = sw;
	this.xs = new Array();
	this.ys = new Array();
	for(i=0;i<this.xys.length;i++)
	{
		this.xs.push(this.xys[i].x);
		this.ys.push(this.xys[i].y);
	}
	
	this.getVertexCount = function()
	{
		return (this.xys.length - 2);
	}
	
	this.getVertex = function(iidx)
	{
		return this.xys[iidx-1];
	}
	
	this.addVertex = function(ixy)
	{
		if(this.instance != null)	this.instance.removeItem(this);
		this.xys.push(ixy);
		this.xs.push(ixy.x);
		this.ys.push(ixy.y);
		this.pcount = this.xys.length;
		if(this.instance != null)	this.instance.addItem(this);
	}
	
	return this;
}

function dgSPolyline(pts,ss,sw)
{
	this.type = 'spolyline';
	this.xys = pts;
	this.instance = null;
	this.pcount = this.xys.length;
	this.strokeStyle = ss;
	this.lineWidth = sw;
	this.xs = new Array();
	this.ys = new Array();
	for(i=0;i<this.pcount;i++)
	{
		this.xs.push(this.xys[i].x);
		this.ys.push(this.xys[i].y);
	}
	return this;
}

function dgPolygon(pts,ss,fs,sw)
{
	this.type = 'polygon';
	this.xys = pts;
	this.instance = null;
	if(pts[0] != pts[(pts.length-1)])
	{
		this.xys.push(pts[0]);
	}
	this.pcount = this.xys.length;
	this.strokeStyle = ss;
	this.fillStyle = fs;
	this.lineWidth = sw;
	this.xs = new Array();
	this.ys = new Array();
	for(i=0;i<this.pcount;i++)
	{
		this.xs.push(this.xys[i].x);
		this.ys.push(this.xys[i].y);
	}
	
	this.getVertexCount = function()
	{
		return (this.xys.length - 1);
	}
	
	this.getVertex = function(iidx)
	{
		return this.xys[iidx-1];
	}
	
	this.addVertex = function(ixy)
	{
		if(this.instance != null)	this.instance.removeItem(this);
		tmpxy = this.xys.pop();
		this.xys.push(ixy);
		this.xys.push(tmpxy);
		tmpx = this.xs.pop();
		this.xs.push(ixy.x);
		this.xs.push(tmpx);
		tmpy = this.ys.pop();
		this.ys.push(ixy.y);
		this.ys.push(tmpy);
		this.pcount = this.xys.length;
		if(this.instance != null)	this.instance.addItem(this);
	}
	return this;
}

function dgSPolygon(pts,ss,fs,sw)
{
	this.type = 'spolygon';
	this.xys = pts;
	this.instance = null;
	if(pts[0] != pts[(pts.length-1)])
	{
		this.xys.push(pts[0]);
	}
	this.pcount = this.xys.length;
	this.strokeStyle = ss;
	this.fillStyle = fs;
	this.lineWidth = sw;
	this.xs = new Array();
	this.ys = new Array();
	for(i=0;i<this.pcount;i++)
	{
		this.xs.push(this.xys[i].x);
		this.ys.push(this.xys[i].y);
	}
	return this;
}

function dgCurve(xy,ss,fs,ptR,sw,ang1,ang2,clockw)
{
	this.type = 'curve';
	this.x = xy.x;
	this.y = xy.y;
	this.strokeStyle = ss;
	this.fillStyle = fs;
	this.ptRadius = ptR;
	this.lineWidth = sw;
	this.arcAngle1 = ang1;
	this.arcAngle2 = ang2;
	this.clockwise = clockw;
	this.instance = null;
	return this;
}

function dgRect(ixy1,ixy2,ss,fs,sw)
{
	this.xy1 = ixy1;
	this.xy2 = ixy2;
	
	this.getSW = function()
	{
		return new dgXY(Math.min(this.xy1.x,this.xy2.x),Math.min(this.xy1.y,this.xy2.y));
	}
	
	this.getNE = function()
	{
		return new dgXY(Math.max(this.xy1.x,this.xy2.x),Math.max(this.xy1.y,this.xy2.y));
	}
	
	this.getWidth = function()
	{
		return Math.abs(this.xy1.x - this.xy2.x);
	}

	this.getHeight = function()
	{
		return Math.abs(this.xy1.y - this.xy2.y);
	}
	
	this.getCenter = function()
	{
		return new dgXY(((this.xy1.x+this.xy2.x)/2),((this.xy1.y+this.xy2.y)/2));
	}
	
	this.contains = function(ixy)
	{
		return ( (ixy.x >= this.getSW().x) && (ixy.x <= this.getNE().x) && (ixy.y >= this.getSW().y) && (ixy.y <= this.getNE().x) ) ? true : false ;
	}
	
	this.containsRect = function(irect)
	{
		return ( (irect.getSW().x >= this.getSW().x) && (irect.getSW().x <= this.getNE().x) && (irect.getSW().y >= this.getSW().y) && (irect.getSW().y <= this.getNE().x)
					&& (irect.getNE().x >= this.getSW().x) && (irect.getNE().x <= this.getNE().x) && (irect.getNE().y >= this.getSW().y) && (irect.getNE().y <= this.getNE().x)
						) ? true : false ;
	}
	
	this.extend = function(ixy)
	{
		if(!this.contains(ixy))
		{
			this.xy1 = new dgXY(Math.min(this.getSW().x,ixy.x),Math.min(this.getSW().y,ixy.y));
			this.xy2 = new dgXY(Math.max(this.getNE().x,ixy.x),Math.max(this.getNE().y,ixy.y));
		}
	}
	
	this.isEmpty = function()
	{
		return (this.xy1 == null || this.xy2 == null) ? true : false;
	}
	
	return this;
	
}

//extend functions
function dgMenuFunc(fname, cfunc)
{
	this.mname = fname;
	this.afunc = cfunc;
	return this;
}

function printMap(dposx,dposy,e)
{
	ddposx = (dposx != null) ? dposx : e.clientX;
	ddposy = (dposy != null) ? dposy : e.clientY;
	if(document.getElementById('prtDialog') == null)
	{
		prtddiv = document.createElement('div');
		prtddiv.id = 'prtDialog';
		prtddiv.style.cssText = "background-color:#000000;position:absolute;width:260px;height:180px;border:outset 2px #A0A0A0;background-color:#F0F0F0;left:" + ddposx + "px;top:" + ddposy + "px;z-index:99;vertical-align:middle;";
		prtddiv.innerHTML = "<table style='width:100%;height:100%;vertical-align:middle;font-size:small;'><tr><td style='border:solid 1px #BBBBBB;'>格式</td><td style='border:solid 1px #BBBBBB;'><select id='mapSize'><option value='A4'>A4</option><option value='A3'>A3</option></select><select id='maplp'><option value='0'>橫式</option><option value='1'>直式</option></select></td></tr><tr><td style='border:solid 1px #BBBBBB;'>標題</td><td style='border:solid 1px #BBBBBB;'><input id='mapTitle' type='text' style='width:200px;' value='逢甲大學地理資訊系統中心' /></td></tr><tr><td style='border:solid 1px #BBBBBB;'>備註</td><td style='border:solid 1px #BBBBBB;'><textarea id='mapMemo' style='width:200px;height:60px;'>http://www.gis.tw/</textarea></td></tr><tr><td colspan='2' style='text-align:center;border:solid 1px #BBBBBB;'><input type='button' style='background-color:#CCCCCC;' value='列印' onclick='doPrint(this);' /></td></tr></table>";
		
		timg = new Image();
		timg.src = _dgmap4path + 'imgs/close.gif';
		timg.onclick = function()
			{
				//dd.elements['printPrompt'].hide(true);
				this.parentNode.style.display = 'none';
			}
		prtddiv.appendChild(timg);
		timg.style.cssText = "position:absolute;left:" + (parseInt(prtddiv.style.width)-25) + "px;top:" + (5) + "px;cursor:pointer;";


		document.body.appendChild(prtddiv);

	}
	else if(document.getElementById('prtDialog').style.visibility == 'hidden')
	{
		document.getElementById('prtDialog').style.visibility = 'visible';	
		document.getElementById('prtDialog').style.left = ddposx + 'px';
		document.getElementById('prtDialog').style.top = ddposy + 'px';
	}
	else
	{
		document.getElementById('prtDialog').style.visibility = 'hidden';	
	}
}

function doPrint(butnObj)
{
	document.getElementById('prtDialog').style.visibility = 'hidden';
	//document.getElementById('exMenu').style.visibility = 'hidden';
	window.open('printmap.htm', 'printWin');
}

var dgCMenu = [];
function dgFMenu(e)
{
	if(e.button == 2)
	{
		if(!document.getElementById('exMenu'))
		{
			exmdiv = document.createElement('div');
			exmdiv.id = 'exMenu';
			exmdiv.style.cssText = 'position:absolute;border: 2px dashed #808080;background-color:#FCFCFC;z-index:98;color:#555FAA;font-size:15px;padding: 2px';
			exmdiv.style.left = (findPos(digimap4s[0].div)[0] + e.clientX) + 'px';
			exmdiv.style.top = (findPos(digimap4s[0].div)[1] + e.clientY) + 'px';
			for(ic=0;ic<dgCMenu.length;ic++)
			{
				tmpdiv = document.createElement('div').cloneNode(true);
				tmpdiv.style.cssText = 'position:relative;margin:2px;white-space:nowrap;';
				tmpdiv.onmouseover = function()
						{
							this.style.cursor = 'pointer';
							this.style.backgroundColor = '#C0C0C0';
						};
				tmpdiv.onmouseout = function()
						{
							this.style.backgroundColor = '#E7E7E7';
						};
				tmpdiv.innerHTML = dgCMenu[ic].mname;
				tmpdiv.onclick = dgCMenu[ic].afunc;
				exmdiv.appendChild(tmpdiv);
			}
	
			document.body.appendChild(exmdiv);
			
			tmpimg = new Image();
			tmpimg.src = 'imgs/close.gif';
		}
		else
		{
			exmdiv.style.left = (findPos(digimap4s[0].div)[0] + e.clientX) + 'px';
			exmdiv.style.top = (findPos(digimap4s[0].div)[1] + e.clientY) + 'px';
			exmdiv.style.visibility = 'visible';
		}
	}
	else
	{
		if(document.getElementById('exMenu'))
		{
			if(document.getElementById('prtDialog'))
			{
				prtddiv.style.visibility = 'hidden';
			}
			exmdiv.style.visibility = 'hidden';
		}
	}
}

//Gerry Add
//計算長度
function  calLength(drawRval) 
{
    
    var XMin=9999999 , YMin =9999999,XMax =0, YMax=0 ;
    var all_len = 0;
    var x_y_len = 0 ;

	if (drawRval.length >1)
	{
		for (i=0;i<drawRval.length-1;i++)
		{
			if (XMin > drawRval[i].x)
				XMin = drawRval[i].x ;
			if (YMin > drawRval[i].y)
				YMin = drawRval[i].y ;
				
			if (XMax < drawRval[i].x)
				XMax = drawRval[i].x ;
			if (YMax < drawRval[i].y)
				YMax = drawRval[i].y ;
	
	
			x_y_len = Math.sqrt((drawRval[i].x-drawRval[i+1].x)*(drawRval[i].x-drawRval[i+1].x)+(drawRval[i].y-drawRval[i+1].y)*(drawRval[i].y-drawRval[i+1].y));
		    all_len = x_y_len + all_len;
	
		}
		
		PolyCX = (XMin +XMax) /2 ;
		PolyCY = (YMin +YMax) /2 ;
 
		return all_len;
	}
	else
	{
		PolyCX = 0 ;
		PolyCY = 0 ;
		return 0 ;
	}
}

//Gerry Add
//計算面積
function calArea(drawRval) 
{
	
	var XMin=9999999 , YMin =9999999,XMax =0, YMax=0 ;
	
	var sum=0,sub=0,carea=0;
	        var tempx,tempy;
	     
	 if (drawRval.length >3)
     {
        
	        
	
	        for(i=0;i<drawRval.length-1;i++)
	        {
	                
	                if (XMin > drawRval[i].x)
						XMin = drawRval[i].x ;
					if (YMin > drawRval[i].y)
						YMin = drawRval[i].y ;
						
					if (XMax < drawRval[i].x)
						XMax = drawRval[i].x ;
					if (YMax < drawRval[i].y)
						YMax = drawRval[i].y ;

	                
	                tempx = parseFloat(drawRval[i].x);
	                tempy = parseFloat(drawRval[i+1].y);
	                sum += tempx * tempy;
	
	                tempx = parseFloat(drawRval[i+1].x);
	                tempy = parseFloat(drawRval[i].y);
	                sub += tempx * tempy;
	        }
	        tempx = parseFloat(drawRval[parseInt(drawRval.length)-1].x) ;
	        tempy = parseFloat(drawRval[0].y);
	        sum += tempx * tempy;
	
	        tempx = parseFloat(drawRval[parseInt(drawRval.length)-1].y) ;
	        tempy = parseFloat(drawRval[0].x);
	        sub += tempx * tempy;
	        carea = Math.abs(sum-sub);
	        carea /= 2;
	        //carea = carea * dis_x * dis_y;
	        
	        PolyCX = (XMin +XMax) /2 ;
			PolyCY = (YMin +YMax) /2 ;

	        return carea;
      }
      else
      {
      		PolyCX = 0 ;
			PolyCY = 0 ;

        	return 0 ;
      }
}
