var markList = new Array();
var landInfo = new Array();
var markTs=new Array();
var minCircle = 120;
var myRed = "已销售",myBlue = "未动工",myGreen="已动工";
var map;
function markObj(id,name,radii,lot,lat,state,par)
{
    this.id = id;
    this.name = name;
    this.lot = lot;
    this.lat = lat;
    this.state = state;
    this.radii = radii;
    this.par = par;
}

function SetLandArea(id,name,radii,lot,lat,state,par)
{
    markList[markList.length] = new markObj(id,name,radii,lot,lat,state,par);
}

function LandObj(lid,lname,laddress,lbtime,letime,larea,lparea,lcause,state,pro)
{
    this.lid = lid;
    this.lname = lname;
    this.laddress = laddress;
    this.lbtime = lbtime;
    this.letime = letime;
    this.larea = larea;
    this.lparea = lparea;
    this.lcause = lcause;
    this.state = state;
    this.project = pro;
}

function SetLandInfo(lid,lname,laddress,lbtime,letime,larea,lparea,lcause,state,pro)
{
    landInfo[landInfo.length] = new LandObj(lid,lname,laddress,lbtime,letime,larea,lparea,lcause,state,pro)
}

function FindLandByID(id)
{
    for(var i=0;i<landInfo.length;i++)
    {
        var obj = landInfo[i];
        if(obj.lid == id)
        {
            return obj;
        }
    }
    return null;
}

$(document).ready(function(){

    map = new LTMaps( "maps" );
    map.cityNameAndZoom( "nanchang" , 2 );
//    map.addControl(new LTStandMapControl());
    $("#pLine").bind("click",function(){
        polyLine.btnClick();
    });
    
    $("#pGon").bind("click",function(){
        polyGon.btnClick();
        
    });
    
    $("#zoomIn").bind("click",function(){
        map.zoomIn();
    });
    
    $("#zoomOut").bind("click",function(){
	    if( map.getCurrentZoom() <= 5 ){
	        map.zoomOut();
	    }
    });
    
    $("#recMap").bind("click",function(){
        var recPoi = map.getCenterPoint();
        map.centerAndZoom( new LTPoint( recPoi.getLongitude() ,recPoi.getLatitude() ) , 2);
    });
    var polyLine = new LTPolyLineControl();
    polyLine.setVisible(false);
    map.addControl(polyLine);
    
    var polyGon = new LTPolygonControl();
    polyGon.setVisible(false);
    map.addControl(polyGon);
    var scale = new LTScaleControl();
    scale.setColor("blue");
    scale.setBottom(10);
    scale.setOpacity(0.8);
    map.addControl(scale);
   
    for(var i=0;i<markList.length;i++)
    {
        var obj = markList[i];
        var val = obj.radii;
        
        if(val < minCircle)
        {
            val = minCircle;
        }
        
        var lot = obj.lot;
        var lat = obj.lat;
        var name = obj.name;
        var num = i+1;
        
        var lands = FindLandByID(obj.id);
        
        var point=new LTPoint(lot,lat);
        var text=new LTMapText(point,[-21,0]);
        var color;
        switch(obj.state)
       {
            case 10:
                color = "itemBlue"
                break;
            case 11:
                color = "itemGreen";
                break;
            case 12:
                color = "itemRed";
                break;
       } 
        
        var str;
        
        if(lands.project == "" || lands.project == null)
        {
            str = '<ul id="'+obj.id+'" class="' + color + '"><li>' + name + '</li></ul>'
        }
        else
        {
            str = '<ul id="'+obj.id+'" class="' + color + '"><li>' + name + '</li><li style="background-color:blue">'+ lands.project +'</li></ul>';
        }
        
        text.setLabel(str);
		text.setBorderLine(0);//将文字设置为没有边框
		text.setBackgroundColor("");//将文字标签背景色设置为透明,用空字符串就可以设置成无背景色了
        map.addOverLay(text);
        
        LTEvent.addListener( text , "mouseover" ,getOverCallBack(obj.id)); 
        LTEvent.addListener( text , "mouseout" ,getOutCallBack(obj.id)); 


        var bounds=new LTBounds(lot-val,lat-val,lot+val,lat+val);

       
        var cir=new LTCircle(bounds);
        map.addOverLay(cir);
    }
    
})

function getOverCallBack(id)
{ 
    return function(){
    $("ul").each(function(){
    if($(this).attr("class")=="itemBlue2"||$(this).attr("class")=="itemGreen2"||$(this).attr("class")=="itemRed2"){
    $(this).attr("class",$("#"+id).attr("class").replace("2",""));
    }
    });
    $("#"+id).attr("class",$("#"+id).attr("class")+"2");
    };
}
function getOutCallBack(id)
{ 
//    return function(){
//    $("#"+id).attr("class",$("#"+id).attr("class").replace("2",""));
//    };
}

function LTCircle(bounds,color,bgcolor,weight,opacity)
{

	if(!document.all){return;}

	this.bounds=bounds;
	this.color=color?color:"#003366";
	this.bgcolor=bgcolor?bgcolor:"#CCCCFF";
	this.weight=weight?weight:1;
	this.opacity=opacity?opacity:0.5;

	this.circle=document.createElement("v:oval");
	this.circle.style.position="absolute";
	this.circle.unselectable="on";
	this.stroke=document.createElement("v:stroke");
	this.stroke.weight=this.weight;
	this.stroke.color=this.color;
	this.stroke.opacity=this.opacity;
	this.circle.appendChild(this.stroke);

	if(this.bgcolor!="transparent")
	{
		this.circle.filled=true;
		this.fill=document.createElement("v:fill");
		this.fill.color=this.bgcolor;
		this.fill.opacity=this.opacity;
		this.circle.appendChild(this.fill);
	}
	else
	{
		this.circle.filled=false;
	}
	this.circle.style.position="absolute";
	this.circle.style.zIndex=420;
}

LTCircle.prototype.initialize=function(map)
{
	if(!this.circle || this.map){return false;}
	this.map=map;
}

LTCircle.prototype.reDraw=function(flag)
{
	if(!flag || this.bounds==null){return;}

	var lb=this.map.getOverLayPosition(new LTPoint(this.bounds.Xmin,this.bounds.Ymax));
	this.circle.style.left=lb[0]+"px";
	this.circle.style.top=lb[1]+"px";

	var rt=this.map.getOverLayPosition(new LTPoint(this.bounds.Xmax,this.bounds.Ymin));
	this.circle.style.width=(rt[0]-lb[0])+"px";
	this.circle.style.height=(rt[1]-lb[1])+"px";
	
}

LTCircle.prototype.getObject=function()
{
    return this.circle;
}

LTCircle.prototype.remove=function()
{
	this.map=null;
}

LTCircle.prototype.depose=function()
{
	LTEvent.deposeNode(this.circle);
	this.circle=null;
	this.stroke=null;
	this.bounds=null;
}

LTCircle.prototype.setBounds=function(bounds)
{
	this.bounds=bounds;
	if(this.map)
	{
		this.reDraw(true);
	}
}


function moveMap(getLong,getLat,id){
	if(map==null){
	map = new LTMaps( "maps" );
    map.cityNameAndZoom( "nanchang" , 2 );
    map.addControl(new LTStandMapControl());
    }
    map.moveToCenter( new LTPoint( getLong , getLat ))
    
    $("ul").each(function(i){
    if($(this).attr("class")=="itemBlue2"||$(this).attr("class")=="itemGreen2"||$(this).attr("class")=="itemRed2"){

       $(this).attr("class",$("#"+id).attr("class").replace("2",""));

        $(this).parent().attr("style",$(this).parent().attr("style").replace("Z-INDEX: 999;","Z-INDEX: 480;").replace("Z-INDEX:999;","Z-INDEX: 480;"));

    }
    });
    $("#"+id).attr("class",$("#"+id).attr("class")+"2");
    try{
        $("#"+id).parent().attr("style",$("#"+id).parent().attr("style").replace("Z-INDEX: 480;","Z-INDEX: 999;").replace("Z-INDEX:480;","Z-INDEX: 999;"));
    }catch(ex){}
    clearBackGround();
}
function moveoutMap(id){
//    try{
//    $("#"+id).attr("class",$("#"+id).attr("class").replace("2",""));
//    $("#"+id).parent().attr("style",$("#"+id).parent().attr("style").replace("Z-INDEX: 999;","Z-INDEX: 480;"));
//    }
//    catch(ex){}
}
