var GIS_mapObj = null;
var CommonPathUrl = "/AjaxMap/Common/?get=PATH";


// °æ·Î °Ë»ö(µ¿±â)
function GIS_RouteView(mapObj, pathFindType, start, end, mid1, mid2, bPathInfo, bOilInfo, RoadName, RoadNo, RoadType)
{
	GIS_mapObj = mapObj;
	GIS_Clear(mapObj);
	
	var xmlhttp = new JXmlhttp(0, 0, false);
	var json = xmlhttp.loadhttp(getUrl(pathFindType, start, end, mid1, mid2, bPathInfo, bOilInfo, RoadName, RoadNo, RoadType));
	var pathInfo = eval('(' + json + ')');
	
	if(pathInfo.Success)
	{
		//alert(pathInfo.polyline.getPoints().length);
		pathInfo.polyline.setMinWeight(5);
		GIS_mapObj.addOverlay(pathInfo.polyline, "GIS_lanes");
		GIS_mapObj.setBound(pathInfo.polyline.getBound());
	}
	
	return pathInfo;
}

// °æ·Î °Ë»ö(ºñµ¿±â)
function GIS_AsyncRouteView(mapObj, pathFindType, start, end, mid1, mid2, bPathInfo, bOilInfo, RoadName, RoadNo, RoadType, NoAsyncFunc)
{
	GIS_NoAsyncRouteView(mapObj, pathFindType, start, end, mid1, mid2, bPathInfo, bOilInfo, RoadName, RoadNo, RoadType, NoAsyncFunc)
}
function GIS_NoAsyncRouteView(mapObj, pathFindType, start, end, mid1, mid2, bPathInfo, bOilInfo, RoadName, RoadNo, RoadType, NoAsyncFunc)
{
	GIS_mapObj = mapObj;
	GIS_Clear(mapObj);
	
	var xmlhttp = new JXmlhttp(0, 0, true);
	xmlhttp.loadhttp(getUrl(pathFindType, start, end, mid1, mid2, bPathInfo, bOilInfo, RoadName, RoadNo, RoadType), CallBackNoAsync, NoAsyncFunc);
}

// ºñµ¿±â È£Ãâ¿ë
function CallBackNoAsync(json, NoAsyncFunc)
{
	var pathInfo = eval('(' + json + ')');
	
	if(pathInfo.Success)
	{
		//alert(pathInfo.polyline.getPoints().length);
		pathInfo.polyline.setMinWeight(5);
		GIS_mapObj.addOverlay(pathInfo.polyline, "GIS_lanes");
		GIS_mapObj.setBound(pathInfo.polyline.getBound());
	}
	
	var args = new Array();
	args[0] = pathInfo;
	NoAsyncFunc.apply(this, args);
}

// Áöµµ»ó¿¡¼­ ±æÃ£±â °´Ã¼ »èÁ¦
function GIS_Clear(mapObj)
{
	GIS_mapObj = mapObj;
	GIS_mapObj.clearOverlays("GIS_lanes");
}

function getUrl(pathFindType, start, end, mid1, mid2, bPathInfo, bOilInfo, RoadName, RoadNo, RoadType)
{
    var url = CommonPathUrl;
	
	url += "&pathType=" + pathFindType;
	url += "&startX=" + start.x;
	url += "&startY=" + start.y;
	url += "&endX=" + end.x;
	url += "&endY=" + end.y;
	if(mid1)
	{
		url += "&mid1X=" + mid1.x;
		url += "&mid1Y=" + mid1.y;
	}
	if(mid2)
	{
		url += "&mid2X=" + mid2.x;
		url += "&mid2Y=" + mid2.y;
	}
	
	if(bPathInfo)
		url += "&isPath=true";
	else
		url += "&isPath=false";
		
	if(bOilInfo)
		url += "&isOil=true";
	else
		url += "&isOil=false";
	
	if(RoadName!=null && RoadNo!=null && RoadType != null)
	{
		url += "&RoadName=" + RoadName;
		url += "&RoadNo=" + RoadNo;
		url += "&RoadType=" + RoadType;
	}
	
	return url;
}

