

//地图标点后显示在图标旁边的文字样式
var jsFONT_Width = 60;
var jsFONT_Size = 12;
var jsFONT_Color = "005c9a";
var jsFONT_BorderColor = "#FFFFFF";
var jsFONT_BorderWidth = 3;
var jsFONT_Family = "宋体";
var jsNameDiv_BackgroundColor = "#FFFFCC"; //图标旁标题区域背景色
//STD_BUBBLE_WIDTH=217 点的弹出信息的宽度
//MIN_BUBBLE_HEIGHT=120 点的弹出信息的高度
var mapConfig = {
	currentCityCode  : '010',
	currentCityName  : '北京市'
};

var mapPoiConfig = {
	poiIcon      : 'images/lingxing.gif'
};

var mapLineConfig = {
	lineColor    : '#FF0000',
	lineStroke   : 3
};

function MapInfo() {

	this.poiCount = 0;
	this.lineCount = 0;
	
	this.currentCityCode = mapConfig.currentCityCode;
	this.currentCityName = mapConfig.currentCityName;
}

function MapPoi() {
	this.objId = new Date().getTime()+""+parseInt(Math.random()*10000); //对象的唯一id
	
	this.tr; //标点对象 对应 列表上的Tr对象
	this.marker; //标点对象 对应 地图显示的MMarker对象
	this.color = jsFONT_Color; //标注点在地图上icon旁边的Name颜色
	this.type = 0;  //标点类型
	
	this.id = 0; //数据对应数据库的id
	this.name = ""; //标点名称
	this.phone = ""; //电话
	this.address = ""; //地址
	this.description = ""; //简介、描述
	this.url = ""; //超链接
	this.showInfoWindow=true;//是否显示弹出框
	this.lat = 0; //纬度
	this.lon = 0; //经度
	this.strlatlon = ""; //加密后经纬度字符串
  this.preIcon = null; //图标的预读
  this.preIconReadSign = 0; //图标预读保护，避免死循环
	this.icon = mapPoiConfig.poiIcon; //使用图标
	this.iconTargetLeft = 0.5; //显示图标目标点的左侧相对位置 [0-1] 0表示图标最左边；1表示图标最右边
	this.iconTargetTop = 1;  //显示图标目标点的顶部相对位置 [0-1] 0表示图标最上边；1表示图标最下边
	
	this.iconWidth = -1; //用于输出icon时使用
	this.iconHeight = -1;
	this.showIconName = true; //false时只显示图标，不显示后面的文字
	
	this.citycode = "010"; //城市代码 默认为北京
	
	this.getlatlon = function()
	{
		if (!this.strlatlon || this.strlatlon=='')
		{
			if (this.lat!=0 && this.lon!=0)
			{
				this.strlatlon=enCode(this.lat,this.lon);
			}
		}
		return this.strlatlon;
		
	}
	
	//自动生成地图标注点的marker信息 标题（可用html标签，可根据需要进行修改）
	this.tmpMarkerTitle = ""; //临时Title，如果给Title赋值，则增加点时将不再执行getMarkerTitle方法
	this.getMarkerTitle = function() {
		var sHtml = "";
		if(this.tmpMarkerTitle.length>0) {
			sHtml = this.tmpMarkerTitle;
		}else{
			sHtml = this.name;
		}
		/*
		if (sHtml && sHtml.length>14)
		{
			sHtml=sHtml.substring(0,14)+"...";
		}
		*/
		return sHtml; 
	}
	//自动生成地图标注点的marker信息 内容（可用html标签，可根据需要进行修改）
	this.tmpMarkerContent = "";
	this.getMarkerContent = function() {
		var sHtml = "";
		if(this.tmpMarkerContent.length>0) {
			sHtml = this.tmpMarkerContent;
		}else{
			if(this.phone.length>0) sHtml += "<br><b>电话:</b>" + this.phone;
			if(this.address.length>0) sHtml += "<br><b>地址:</b>" + this.address;
			if(this.url.length>0) sHtml += "<br>" + this.url;
			if(this.description.length>0) sHtml += "<br><b>简介:</b>" + this.description;
		}
		return sHtml;
	}
	//自动生成地图标注点的marker信息 图标（可用html标签，可根据需要进行修改）
	this.tmpMarkerIcon = "";
	this.getMarkerIcon = function() {
		var sHtml = "";
		if(this.tmpMarkerIcon.length>0) {
			sHtml = this.tmpMarkerIcon;
		}else{
			//sHtml = "<div unselectable=on style=position:absolute;left:0;white-space:nowrap;FONT-SIZE:"+jsFONT_Size+"px;filter:glow(color="+jsFONT_BorderColor+",strength="+jsFONT_BorderWidth+");height:0px;color="+jsFONT_Color+";font-family:"+jsFONT_Family+";><img onclick=\"javascript:return false;\" src="+this.icon+" "+((this.iconWidth<0)?"":("width="+this.iconWidth))+" "+((this.iconHeight<0)?"":("height="+this.iconHeight))+" ><div unselectable=on style=position:relative;left:0;white-space:nowrap;BACKGROUND-COLOR:yellow;>"+this.name+"</div></div>";
			if(this.name.length>0 && this.showIconName) {
				sHtml = "<div unselectable=on style=position:absolute;left:0;white-space:nowrap;><table border=0 cellpadding=0 cellspacing=0><tr><td unselectable=on style=white-space:nowrap;><img onclick=\"javascript:return false;\" src="+this.icon+" "+((this.iconWidth<0)?"":("width="+this.iconWidth))+" "+((this.iconHeight<0)?"":("height="+this.iconHeight))+" ></td><td><table border=0 cellpadding=1 cellspacing=1 bgcolor="+this.color+"><tr><td unselectable=on height=20 valign=middle style=white-space:nowrap;BACKGROUND-COLOR:"+jsNameDiv_BackgroundColor+";FONT-SIZE:"+jsFONT_Size+"px;filter:glow(color="+jsFONT_BorderColor+",strength="+jsFONT_BorderWidth+");color:"+this.color+";font-family:"+jsFONT_Family+";>"+this.name+"</td></tr></table></td></tr></table></div>";
			} else {
				sHtml = "<div unselectable=on style=position:absolute;left:0;white-space:nowrap;><table border=0 cellpadding=0 cellspacing=0><tr><td unselectable=on style=white-space:nowrap;><img onclick=\"javascript:return false;\" src="+this.icon+" "+((this.iconWidth<0)?"":("width="+this.iconWidth))+" "+((this.iconHeight<0)?"":("height="+this.iconHeight))+" ></td></tr></table></div>";
			}
		}		
		return sHtml;
	}
}

function MapLine() {
	this.objId = new Date().getTime()+""+parseInt(Math.random()*10000); //对象的唯一id
	this.tr; //线、面对象 对应 列表上的Tr对象
	this.marker; //线、面对象 对应 地图显示的MMarker对象
	this.color = mapLineConfig.lineColor; //线颜色
	this.stroke = mapLineConfig.lineStroke; //线粗细
	this.type = 0; //线、面类型 0:线；1:带阴影面积
	
	this.id = 0; //数据对应数据库的id
	this.name = ""; //线段名称
	this.phone = ""; //电话
	this.address = ""; //地址
	this.description = ""; //简介、描述
	this.url = ""; //超链接
	
	this.strlatlon = ""; //线段各点经纬度字符串
	this.strlatlonArray = null;
	this.centerlatlon = ""; //线段中心点经纬度字符串
	this.citycode = "010"; //城市代码 默认为北京
	

	//自动生成地图线、面的marker信息 标题（可用html标签，可根据需要进行修改）
	this.tmpMarkerTitle = ""; //临时Title，如果给Title赋值，则增加点时将不再执行getMarkerTitle方法
	this.getMarkerTitle = function() {
		var sHtml = "";
		if(this.tmpMarkerTitle.length>0) {
			sHtml = this.tmpMarkerTitle;
		}else{
			sHtml = this.name;
		}
		return sHtml; 
	}
	//自动生成地图线、面的marker信息 内容（可用html标签，可根据需要进行修改）
	this.tmpMarkerContent = "";
	this.getMarkerContent = function() {
		var sHtml = "";
		if(this.tmpMarkerContent.length>0) {
			sHtml = this.tmpMarkerContent;
		}else{
			if(this.phone.length>0) sHtml += "<b>电话</b>" + this.phone;
			if(this.address.length>0) sHtml += "<br><b>地址</b>" + this.address;
			if(this.description.length>0) sHtml += "<br><b>简介</b>" + this.description;
		}
		return sHtml;
	}
	
	//根据this.strlatlon自动生成线段各端点的Array集合
	this.getMPointArray = function() {
		var mpArray = new Array();
		if (this.strlatlon!="")
		{
			var pArray = this.strlatlon.split(",");
			for(var i=0;i<pArray.length;i++) {
				if(pArray[i].length>0) {
					mpArray.push(new MPoint(pArray[i]));
				}
			}
			return mpArray;
		}
		else if (this.strlatlonArray)
		{
			var pArray = this.strlatlonArray;
			for(var i=0;i<pArray.length;i++) {
				if(pArray[i].length>0) {
					mpArray.push(new MPoint(pArray[i]));
				}
			}
			return mpArray;
		}
	}
}


function PointGroup(){
	this.latSteps = new Array(90, 32, 16, 8, 4, 1.6000000000000001, 0.80000000000000004, 0.40000000000000002, 0.16000000000000003, 0.080000000000000016, 0.040000000000000008, 0.016, 0.0080000000000000002, 0.0040000000000000001);

	this.lonSteps = new Array(90, 40, 20, 10, 5, 2, 1.0, 0.5, 0.20000000000000001, 0.10000000000000001, 0.050000000000000003, 0.02, 0.01, 0.0050000000000000001);

	this.maxLat=0;
	this.minLat=0;
	this.maxLon=0;
	this.minLon=0;

	this.mapletWidth;
	this.mapletHeight;

	this.getCenter=function()
	{
		var center = new Array();
		center[0]=(this.maxLat+this.minLat) / 2;
		center[1]=(this.maxLon+this.minLon) / 2;
		return center;
	}

	this.getZoom=function()
	{
		if (!this.mapletWidth || !this.mapletHeight)
		{
			if (maplet)
			{
				this.mapletWidth = maplet.width;
				this.mapletHeight = maplet.height;
			}
		}

		var unitLat = (1.1000000000000001 * (this.maxLat - this.minLat) * 300) / this.mapletHeight;
        var unitLon = (1.1000000000000001 * (this.maxLon - this.minLon) * 300) / this.mapletWidth;

		var zmLat = this.getFitZoomLevel(unitLat, this.latSteps);
        var zmLon = this.getFitZoomLevel(unitLon, this.lonSteps);

		return Math.min(zmLat, zmLon);

	}
	this.addLatLon=function(lat,lon)
	{
		this.maxLat=Math.max(this.maxLat,lat);
		if (this.minLat==0)
			this.minLat=lat;
		else
			this.minLat=Math.min(this.minLat,lat);


		this.maxLon=Math.max(this.maxLon,lon);
		if (this.minLon==0)
			this.minLon=lon;
		else
			this.minLon=Math.min(this.minLon,lon);

	}

	this.getFitZoomLevel=function(value,arrays)
	{
		var i;
		for (i=1; i<arrays.length && value<=arrays[i]; i++);
		return i-1;
		
	}


}


