﻿////////////////////////////////////////////////////////////
//
//ファイル名:   mode.js
//機能		:	モード管理
//依存		:	main.js
//バージョン:　 2.0.0.1
//更新日時	:　 2006.08.02
//更新者	:	kawame
//
//////////////////////////////////////////////////////////////


function ModeManager(gis)
{
	var gisMain			= gis;
	var currentMode		= "none";
	
	// モード定義
	this.modeDefinition	= new Mode();

	// モードの取得


	this.getCurrentMode = function()
	{
		return currentMode;
	}
	
	// モードの設定


	this.setCurrentMode = function(mode)
	{
		currentMode = mode;
	}
}

//
//	モード
//
function Mode()
{
	// 何もしない
	this.NONE	 			= "none";
	
	// 中心移動
	this.MOVE_CENTER		= "move_center";

	// つかみ移動
	this.MOVE_DRAG			= "move_drag";
	
	// スムーズ移動
	this.MOVE_SMOOTH		= "move_smooth";
	
	// 矩形ズーム
	this.ZOOM_RECT			= "zoom_rect";
	
	// 矩形拡大
	this.ZOOM_IN_RECT		= "zoom_in_rect";
	
	// 矩形縮小
	this.ZOOM_OUT_RECT		= "zoom_out_rect";
	
	// スムーズズーム
	this.ZOOM_SMOOTH		= "zoom_smooth";
	
	// 距離計測
	this.MEASURE_LENGTH		= "measure_length";
	
	// 面積計測
	this.MEASURE_AREA		= "measure_area";
	
	// 同心円計測
	this.MEASURE_CIRCLE		= "measure_circle";
	
	// 点検索
	this.SEARCH_POINT		= "search_point";
	
	// 矩形検索
	this.SEARCH_RECT		= "search_rect";
	
	// 多角形検索
	this.SEARCH_POLYGON		= "search_polygon";
	
	// 円検索
	this.SEARCH_CIRCLE		= "search_circle";
	
	// 点選択
	this.SELECT_POINT		= "select_point";
	
	// 線選択
	this.SELECT_CURVE		= "select_curve";
	
	// 面選択
	this.SELECT_SURFACE		= "select_surface";
	
	// テキスト選択
	this.SELECT_TEXT		= "select_text";
	
	// 円選択
	this.SELECT_CIRCLE		= "select_circle";
	
	// 地物の追加
	this.ADD_FEATURE		= "add_feature";
	
	// 地物の編集
	this.EDIT_FEATURE		= "edit_feature";
	
	// 地物の削除
	this.DELETE_FEATURE		= "delete_feature";
	
	// スムーズ回転
	this.ROTATE_SMOOTH		= "rotate_smooth";	
	
	//一時作図
	this.DRAW_TEMP			= "draw_temp";
	
	//投稿機能
	this.POST				= "post";
	
	//ルート検索
	this.SEARCH_ROUTE		= "search_route";
}

		//以下kwm追加
		//モードの切り替え****************************************************************
		//以下kwm追加
		//モードの切り替え****************************************************************
		function modeChange(mode)
		{
			mode = (mode) ? mode : gis.modeManager.modeDefinition.NONE;
			
			var nowMode = gis.modeManager.getCurrentMode();
			var mode_disp_node=document.getElementById("modedisp_contents");
			var msg="<nobr>■クリック：登録されている情報を表示します        </nobr>";
			//msg+="<nobr>■ダブルクリック：中心移動をします      </nobr><br/>";
			
			var snode = document.getElementById("attr_search_container");
			if(snode)
			{
				if(mode == "move_drag" || mode  == "zoom_rect")
				{
					snode.style.display = "block";
				}
				else
				{
					snode.style.display = "none";
				}
			}
			
			if(dblClickInterval)
			{
				window.clearInterval(dblClickInterval);
			}	
					
			if (mode != nowMode)
			{ 
				var f=true;
				if(flg_viewLock)
				{
					f=check_flg_viewLock();
				}
				
				if(f)
				{
					//logger.debug(nowMode+'→'+mode);
					//モードの変更
					gis.modeManager.setCurrentMode(mode);	
					nowMode = mode;
					cur_mode = mode; 
					
					if(!disableFlg)
					{
						setCurModeButton(mode);	
					}
					
					setInputButtonView(1,-1,-1);
				
					//ビューロックがかかっていない場合モードを切り替える
				
					if (nowMode == 'none')
					{
						noMode();	
					}
					else if (nowMode == 'move_center') 
					{
						msg="<nobr>■中心座標をクリック  </nobr>";	
						initMC();	
					}	
					else if (nowMode == 'move_drag') 
					{
						msg+="<nobr>■ドラッグ：移動します  </nobr>";	
						initMD();
					}
					else if (nowMode == 'zoom_rect') 
					{
						msg+="<nobr>■ドラッグ：指定した範囲を拡大表示します  </nobr>";
						initZR();	
					}
					else if (nowMode == 'search_point') 
					{
						msg="<nobr>■クリック:検索箇所を指定します  </nobr>";	
						initAttrSearchPoint();	
					}
					else if (nowMode == 'search_circle') 
					{
						msg="<nobr>■クリック：検索範囲の中心を指定します  </nobr>";
						initAttrSearchCircle();
					}
					else if (nowMode == 'measure_length') 
					{
						mode_input = 'input_polyline';
						INPUT_COLOR = measureLength_Color;
						INPUT_WIDTH = 2;
						msg = "<nobr>"+changeModeDisp(mode_input)+"  </nobr>";	
						startInput();	
					}
					else if (nowMode == 'measure_area') 
					{
						mode_input = 'input_polygon';
						INPUT_COLOR = measureArea_Color;
						INPUT_WIDTH = 2;
						msg = "<nobr>"+changeModeDisp(mode_input)+"  </nobr>";	
						startInput();
					}
					else if (nowMode == 'add_feature') 
					{
						msg = "<nobr>"+changeModeDisp(mode_input)+"  </nobr>";	
						startInput();
					}
					else if (nowMode == 'draw_temp') 
					{
						msg = "<nobr>"+changeModeDisp(mode_input)+"  </nobr>";	
						startInput();
					}
					else if (nowMode == 'post') 
					{
						msg = "<nobr>"+changeModeDisp(mode_input)+"  </nobr>";	
						startInput();
					}
					else if (nowMode == 'start_route')
					{						
						msg = "<nobr>■クリック：始点を指定します  </nobr><nobr>■ドラッグ：移動します  </nobr>";	
						setInputButtonView(-1,-1,1);
						initRS();
					}
					else if(nowMode == 'search_route')
					{
						msg = "<nobr>■クリック：終点を指定します  </nobr><nobr>■ドラッグ：移動します  </nobr>";	
						setInputButtonView(-1,-1,1);
						initRS();
					}
				}
				if(mode_disp_node)
				{
					mode_disp_node.innerHTML=msg;
				}
				//20060529追加
				if(nowMode == DEF_MODE && PopWin_o)
				{
					//PopWin_o.close();
					//PopWin_o = null;
				}
			}
		}
		
		/*ボタンの入れ替え*/
		function setCurModeButton(mode)
		{
			var array = document.getElementsByName("tools");
			if(array)
			{
				for(var i=0;i<array.length;i++)
				{
					var src = array[i].src;
					
					var id = array[i].id;
					//if(id == "tool_"+mode)
					if(id == mode)
					{
						var j = src.lastIndexOf(".",src.length)-1;
						var txt = "_"+src.substr(j,1)+".";
						array[i].src = src.replace(txt,"_c.");
						//array[i].src = src.replace(src.substr(src.length-6,6),"_c.gif");
						array[i].onmouseout = setImgC;
						array[i].onmouseover = "return false;";
					}
					else
					{
						var j = src.lastIndexOf(".",src.length)-1;
						var txt = "_"+src.substr(j,1)+".";
						array[i].src = src.replace(txt,"_n.");
						//array[i].src = src.replace(src.substr(src.length-6,6),"_n.gif");;
						array[i].onmouseout = setImgN;
						array[i].onmouseover = setImgO;
					}
				}			
			}
		}
		
		function noMode()
		{
			eventLayer.onclick		= null;
			eventLayer.ondblclick	= null;
			eventLayer.onmousedown	= null;
			eventLayer.onmouseup	= null;
			eventLayer.onmousemove	= null;
			eventLayer.onmouseover	= null;
			eventLayer.onmouseout	= null;
			
			eventLayer.style.cursor = "default";
		}
