//地图标点后显示在图标旁边的文字样式
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"; //图标旁标题区域背景色
var mapConfig = {currentCityCode  : '010',currentCityName  : '北京市'};
var mapPoiConfig = {poiIcon      : '/images/icon/custom/a-5.gif',lineIcon:'/images/icon/line1.gif',areaIcon:'/images/icon/area1.jpg'};
var mapLineConfig = {lineColor    : '#FF0000',lineStroke   : 3};

var oldLineNum=0;

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;  //标点类型 0-search ;1 mymaps 2 fix
	this.state=0;   //0表示从数据库中读出  ；1 新增 2 修改 3 删除
    this.lock=0;//0-关闭 1-打开
    this.id = 0; //数据对应数据库的id
    this.name = ""; //标点名称
	this.phone = ""; //电话
	this.address = ""; //地址
	this.description = ""; //简介、描述
	this.url = ""; //超链接
    this.poitype = "";//点的类型 eg 公司企业。。
    this.detailLink="";//详细信息链接
    this.isShowInfoWindow = 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 = false; //false时只显示图标，不显示后面的文字
	this.allowEdit=true;//当allowEdit为false的时候，不允许编辑
	this.citycode = "010"; //城市代码 默认为北京
    this.city="";
    this.tipInfo=new InfoWindow();
	//自动生成地图标注点的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.detailLink.length>0)sHtml+="<table><tr><td>"+this.detailLink+"</td></tr></table>";
            sHtml+="<table  style='margin-top:10px;'>";
            if(this.poitype.length>0) sHtml+="<tr><td><b>类型:</b>&nbsp;"+this.poitype+"</td></tr>";
            if(this.phone.length>0) sHtml += "<tr><td><b>电话:</b>&nbsp;" + this.phone+"</td></tr>";
			if(this.address.length>0) sHtml += "<tr><td><b>地址:</b>&nbsp;" + this.address+"</td></tr>";
			if(this.description.length>0) sHtml += "<tr><td ><b>简介:</b>&nbsp;" + this.description+"</td></tr>";
            sHtml +="</table>";
        }
//		return sHtml;
        this.tipInfo.poi.latLon=this.strlatlon;
        this.tipInfo.poi.name=this.getMarkerTitle();
        this.tipInfo.poi.cityName=this.city;
        this.tipInfo.poi.pid=this.id;
        this.tipInfo.poi.objId=this.objId;
        this.tipInfo.poi.icon=this.icon;
        this.tipInfo.poi.description=this.description;
        if((this.type==1)&&this.allowEdit){
            this.tipInfo.poi.myMapButtonDisplay='';
            this.tipInfo.poi.saveButtonDisplay='none';
        }else if(this.type==0||this.type==2){
			this.tipInfo.poi.fixMapButtonDisplay='';
		}else{
            this.tipInfo.poi.myMapButtonDisplay='none';
        }
        return sHtml+this.tipInfo.getWinText();

    }
	//自动生成地图标注点的marker信息 图标（可用html标签，可根据需要进行修改）
	this.tmpMarkerIcon = "";
	this.getMarkerIcon = function() {
		var sHtml = "";
		if(this.tmpMarkerIcon.length>0) {
			sHtml = this.tmpMarkerIcon;
		}else{
			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:void(0);\" 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 {
                if(ie6&&this.icon.indexOf(".png")!=-1){sHtml="<div style=\"top:0px;left:0px;width:"+this.iconWidth+";height:"+this.iconHeight+";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.icon+"',sizingMethod='image')\"></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:void(0);\" src="+this.icon+" "+((this.iconWidth<0)?"":("width="+this.iconWidth))+" "+((this.iconHeight<0)?"":("height="+this.iconHeight))+" ></td></tr></table></div>";
                    sHtml = this.icon;
                }
            }
		}
        return sHtml;
//        return this.icon;
    }
}

    this.bgcolor="";
    this.arrow=""; //画笔是否有表示方向的矢量箭头
function MapLine() {
	this.objId = new Date().getTime()+""+parseInt(Math.random()*10000); //对象的唯一id
	this.tr; //线、面对象 对应 列表上的Tr对象
	this.marker; //线、面对象 对应 地图显示的MMarker对象
    this.lineType=0;//线、面类型 0:线；1:带阴影面积
	
	this.method=1;//默认新方法 0老方法 1 新方法
    this.color = mapLineConfig.lineColor; //线颜色
	this.stroke = mapLineConfig.lineStroke; //线粗细
    this.transparency="60";
    this.bgtransparency="30";
    this.fill=true;
	this.bgcolor='red';
    this.arrow=false;

    this.style="0";
    this.type = 0; //0 search resault 1：user add
    this.state=0;   //0表示从数据库中读出  ；1 新增 2 修改 3 删除
    this.lock=0;//0-关闭 1-打开
    this.id = 0; //数据对应数据库的id
    this.name = ""; //线段名称
	this.phone = ""; //电话
	this.address = ""; //地址
	this.description = ""; //简介、描述
	this.url = ""; //超链接

	this.strlatlon = ""; //线段各点经纬度字符串
	this.centerlatlon = ""; //线段中心点经纬度字符串
	this.citycode = "010"; //城市代码 默认为北京
    this.city="";
	this.allowEdit=true;//当allowEdit为false的时候，不允许编辑
    this.tipInfo=new InfoWindow();
	//自动生成地图线、面的marker信息 标题（可用html标签，可根据需要进行修改）
	this.tmpMarkerTitle = ""; //临时Title，如果给Title赋值，则增加点时将不再执行getMarkerTitle方法
	this.getMarkerTitle = function() {
        var sHtml = "";
		if(this.tmpMarkerTitle.length>0) {
			sHtml = this.tmpMarkerTitle;
		}else{
			/*this.tmpMarkerTitle=*/sHtml = this.name;
		}
        return sHtml;
	}
	//自动生成地图线、面的marker信息 内容（可用html标签，可根据需要进行修改）
	this.tmpMarkerContent = "";
	this.getMarkerContent = function() {
		var sHtml = "";
		if(this.tmpMarkerContent.length>0) {
			sHtml = this.tmpMarkerContent;
		}else{
            sHtml+="<table  style='margin-top:10px;'>";
            if(this.phone.length>0) sHtml += "<tr><td><b>电话:</b>&nbsp;" + this.phone+"</td></tr>";
			if(this.address.length>0) sHtml += "<tr><td><b>地址:</b>&nbsp;" + this.address+"</td></tr>";
			if(this.description.length>0) sHtml += "<tr><td ><b>简介:</b>&nbsp;" + this.description+"</td></tr>";
            sHtml +="</table>";
			/*
			if(this.phone.length>0) sHtml += "<br><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;
            this.tmpMarkerContent=sHtml;*/
        }
//        this.tipInfo.poi.latLon=this.strlatlon;
        this.tipInfo.poi.name=this.getMarkerTitle();
        this.tipInfo.poi.cityName=this.city;
        this.tipInfo.poi.pid=this.id;
        this.tipInfo.poi.objId=this.objId;
        this.tipInfo.poi.color=this.color.replace("%23","#");
        this.tipInfo.poi.bgcolor=this.bgcolor.replace("%23","#");
        this.tipInfo.poi.stroke=this.stroke;
        this.tipInfo.poi.transparency=this.transparency;
        this.tipInfo.poi.bgtransparency=this.bgtransparency;
        this.tipInfo.poi.arrow=this.arrow;

        if(this.lineType==0){
            this.tipInfo.poi.type=2;
            this.tipInfo.poi.icon=mapPoiConfig.lineIcon;
        }else{
            this.tipInfo.poi.type=3;
            this.tipInfo.poi.icon=mapPoiConfig.areaIcon;
        }
        this.tipInfo.poi.description=this.description;
        if(this.type==1&&this.allowEdit){this.tipInfo.poi.myMapButtonDisplay='';}else{
            this.tipInfo.poi.myMapButtonDisplay='none';
        }
        this.tipInfo.poi.funsDisplay="none";
        return sHtml+this.tipInfo.getWinText();
	}
	//根据this.strlatlon自动生成线段各端点的Array集合
	this.getMPointArray = function() {
		var mpArray = new Array();
		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;
	}
}
/*============================================================*/
var PoiArr = new Array();//放入所有 点 对像的数组
var LineArr = new Array();//放入所有 线，面 对像的数组
var mapLock = false; //操作地图锁， true时不能利用工具栏对地图进行新增标注点、线、面的操作
var mapLockMsg = ""; //地图加锁后，显示的提示信息


//从集合中根据objId获取Poi对象
function getPoiByObjId(objId) {
	var pIndex = getPoiIndexByObjId(objId);
	if(pIndex==-1){
		return null;
	} else {
		return PoiArr[pIndex];
	}
}

//从集合中根据Id获取Poi对象
function getPoiById(Id) {
	var pIndex = getPoiIndexById(Id);
	if(pIndex==-1){
		return null;
	} else {
		return PoiArr[pIndex];
	}
}
//从集合中根据Id内容 like 方法 获取其中一个Poi对象
function getPoiByLikeId(Id) {
	var pIndex = getPoiIndexByLikeId(Id);
	if(pIndex==-1){
		return null;
	} else {
		return PoiArr[pIndex];
	}
}
//从集合中根据objId查找Poi对象的Index
function getPoiIndexByObjId(objId) {
	for(var i=0; i<PoiArr.length; i++) {
		if(objId == PoiArr[i].objId) {
			return i;
		}
	}
	return -1;
}

//从集合中根据Id查找Poi对象的Index
function getPoiIndexById(Id) {
	for(var i=0; i<PoiArr.length; i++) {
		if(Id == PoiArr[i].id) {
			return i;
		}
	}
	return -1;
}
//从集合中根据Id内容 like 方法 查找其中一个Poi对象的Index
function getPoiIndexByLikeId(Id) {
	for(var i=0; i<PoiArr.length; i++) {
		if(PoiArr[i].id.indexOf(Id)>-1) {
			return i;
		}
	}
	return -1;
}
//显示指定标注点的信息
function showPoiInfoByObjId(objId) {
	var i = getPoiIndexByObjId(objId);
	if(i>-1){
		if(PoiArr[i].preIconReadSign<1000 && (PoiArr[i].preIcon==null || !PoiArr[i].preIcon.complete)){
			setTimeout("showPoiInfoById('"+Id+"')",10);
		}else if(PoiArr[i].preIcon!=null && PoiArr[i].preIcon.complete){
			setTimeout("PoiArr["+i+"].marker.openInfoWindow()",10);
		}
	}else{
		//alert("该点不存在，请刷新列表");
	}
}
function showPoiInfoById(Id) {
	var i = getPoiIndexById(Id);
	if(i>-1){
		if(PoiArr[i].preIconReadSign<1000 && (PoiArr[i].preIcon==null || !PoiArr[i].preIcon.complete)){
			setTimeout("showPoiInfoById('"+Id+"')",10);
		}else if(PoiArr[i].preIcon!=null && PoiArr[i].preIcon.complete){
			setTimeout("PoiArr["+i+"].marker.openInfoWindow()",10);
		}
	}else{
		//alert("该点不存在，请刷新列表");
	}
}

//在地图上删除指定线、面
function delLine(lineObj) {
	var lineMarker = lineObj.marker;
	maplet.removeOverlay(lineMarker);
	
	var i = getLineIndexByObjId(lineObj.objId)
	LineArr.splice(i,1);
}

function delLineByType(type){
	if(type==0){
		maplet.clean();//清除老方法打点画线。
		oldLineNum=0;
	}
    for(var i=0;i<LineArr.length;){
        if(LineArr[i].type==type){delLine(LineArr[i]);}
        else{i++;}
    }
	
}
/**
*通过序列号码返回类型为0.marker
*markerType 1 poi
*/
function getObjBySeq(i,markerType){
		if(markerType==1){
			 for(var j=0,k=0;j<PoiArr.length;j++){
				if(PoiArr[j].type==0&&PoiArr[j].marker){
					if(k==i){
						return PoiArr[j];
					}
					k++;
				}
			}
		}else if(markerType==2){
			for(var j=0,k=0;j<LineArr.length;j++){
				if(LineArr[j].type==0&&LineArr[j].marker){
					if(k==i){
						return LineArr[j];
					}
					k++;
				}
			}
		}
		return null;
}
function getObjByObjId(objId){
	var obj=getPoiByObjId(objId);
    if(!obj){obj=getLineByObjId(objId);}
    if(!obj)return null;
	else return obj;
}

function openBubble(poiObj){
    if(typeof ContentInfo!="undefined")poiObj.marker.info.content=poiObj.getMarkerContent();
    poiObj.marker.openInfoWindow();
}


//从集合中根据objId获取Line对象
function getLineByObjId(objId) {
	var lineIndex = getLineIndexByObjId(objId);
	if(lineIndex==-1){
		return null;
	} else {
		return LineArr[lineIndex];
	}
}
/**
 *@parm type1  1-poi 2-line 3-area
 */
function getLenByType(type1){
    var num=0;
    if(type1==1){
        for(var i=0;i<PoiArr.length;i++){
            if(PoiArr[i].type = 1){num++;}
        }
    }else if(type1==2){
        for(var i=0;i<LineArr.length;i++){
            if(LineArr[i].type = 1&&LineArr[i].lineType==0){num++;}
        }
    }else{
        for(var i=0;i<LineArr.length;i++){
            if(LineArr[i].type = 1&&LineArr[i].lineType==1){num++;}
        }
    }
    return num;

}
//从集合中根据Id获取Line对象
function getLineById(Id) {
	var lineIndex = getLineIndexById(Id);
	if(lineIndex==-1){
		return null;
	} else {
		return LineArr[lineIndex];
	}
}
//从集合中根据Id内容 like 方法 获取其中一个Line对象
function getLineByLikeId(Id) {
	var lineIndex = getLineIndexByLikeId(Id);
	if(lineIndex==-1){
		return null;
	} else {
		return LineArr[lineIndex];
	}
}

//从集合中根据objId查找Line对象的Index
function getLineIndexByObjId(objId) {
	for(var i=0; i<LineArr.length; i++) {
		if(objId == LineArr[i].objId) {
			return i;
		}
	}
	return -1;
}

//从集合中根据Id查找Line对象的Index
function getLineIndexById(Id) {
	for(var i=0; i<LineArr.length; i++) {
		if(Id == LineArr[i].id) {
			return i;
		}
	}
	return -1;
}
//从集合中根据Id内容 like 方法 查找其中一个Line对象的Index
function getLineIndexByLikeId(Id) {
	for(var i=0; i<LineArr.length; i++) {
		if(LineArr[i].id.indexOf(Id)>-1) {
			return i;
		}
	}
	return -1;
}

//在地图上删除指定点
function delPoi(poiObj) {
    maplet.hideBubble();
    var poiMarker = poiObj.marker;
	maplet.removeOverlay(poiMarker);
	
	var i = getPoiIndexByObjId(poiObj.objId);
	PoiArr.splice(i,1);
}

function delPoiByMarkerId(MMid){
    var i = getPoiIndexByObjId(MMid);
    maplet.hideBubble();
    var poiMarker = PoiArr[i].marker;
	maplet.removeOverlay(poiMarker);
    if(PoiArr[i].id == 0 && PoiArr[i].state==1){PoiArr.splice(i,1);}
    else if(PoiArr[i].id != 0){PoiArr[i].state=3;}
    var node=$(MMid);

    if(node.parentNode){
        node.parentNode.removeChild(node);
    }
}
function delPoiByType(type){
    for(var i=0;i<PoiArr.length;){
        if(PoiArr[i].type==type){delPoi(PoiArr[i]);}
        else{i++;}
    }
}


//设置地图中心点
function setMapCenter(strlatlon){
	var point = new MPoint(strlatlon);
	maplet.setCenter(point);
}
//获取当前地图中心点
function getMapCenter(){
	return maplet.getCurrentMap();
}
//地图设置缩放比例
function setMapZoom(zoom){
	maplet.setZoomLevel(zoom);
}
//地图设置中心点与缩放比例
function setMapCenterAndZoom(strlatlon,zoom){
	var point = new MPoint(strlatlon);
	maplet.centerAndZoom(point, zoom);
}

function setTimeoutMapCenterAndZoom(strlatlon,zoom){
	var i = 0;
	if(!maplet && i < 100){
		i++;
		setTimeout("setMapCenterAndZoom('" + strlatlon + "','" + zoom +"');",500);
	}else{
		setMapCenterAndZoom(strlatlon,zoom);
	}
	
}
//***************************************************************

//移动模式
function setMoveMode(){
    drawPanel.changeButton(0,1);
    maplet.setMode("pan");//设定地图移动方式
}

//地图纠错模式
/**
*/
function setFixMapMode(icon,mode){
	maplet.hideBubble();
    if(!mapLock) {
		var pIcon = icon || mapPoiConfig.poiIcon;
		maplet.setCursorIcon(pIcon);
		MEvent.clearListeners(maplet, mode);
        maplet.setMode(mode, function(strURL){fixMapBack(strURL,mode);});
	}
}
//地图标点方式
function setPoiMode(icon,callBack){
    maplet.hideBubble();
    //if(!user.checkLogin()){user.createLoginPanel();return false;}
    drawPanel.changeButton(1,1);
    if(!mapLock) {
        //todo have some problems in close package fun .
//        maplet.setMode("bookmark", function(strURL){alert(xxx + "," + (++yyy));poiCallback(strURL,callBack);});
        
		MEvent.clearListeners(maplet, "bookmark");
		//MEvent.addListener(maplet, 'bookmark', poiCallback);
		maplet.setMode("bookmark", poiCallback);
        var pIcon = icon || mapPoiConfig.poiIcon;
		maplet.setCursorIcon(pIcon);
	}
}

//地图画线方式
function setLineMode(callBack){
    maplet.hideBubble();
    //if(!user.checkLogin()){user.createLoginPanel();return false;}
    drawPanel.changeButton(2,1);
    if(!mapLock) {
		maplet.setCursorIcon("/images/nw/pen.cur");
		MEvent.clearListeners(maplet, "drawline");
		maplet.setMode("drawline",lineCallback);
	}
}
//地图画面方式
function setAreaMode(callBack){
    maplet.hideBubble();
    //if(!user.checkLogin()){user.createLoginPanel();return false;}
    drawPanel.changeButton(3,1);
    if(!mapLock) {
		maplet.setCursorIcon(null);
		MEvent.clearListeners(maplet, "drawarea");
		maplet.setMode("drawarea",areaCallback);
	}
}
//编辑模式
function setEditMode(){
	maplet.setMode("edit",editCallback);
}


//--------------------callback操作------------------
function fixMapBack(strURL,mode){
	var callBack=function(obj){
		obj.type=2;//设定模式
		obj.marker.setEditable(true);
		if(typeof fixMapSave!="undefined"){
			fixMapSave.addMarker(obj.objId);
		}
		if(mode=="bookmark"){
			obj.getMarkerContent();//for infowindow
			feebackPoi(obj.objId);
		}
		//obj.marker.openInfoWindow();
	}
	//console.debug(strURL);
	if(mode=="bookmark")poiCallback(strURL,callBack,0);
	else if(mode=="drawline")lineCallback(strURL,callBack,0);
	else if(mode=="drawarea")areaCallback(strURL,callBack,0);
}


//标点后处理
function poiCallback(strURL,callBack,poitype) {
	setMoveMode();
    //关闭地图显示的气泡信息
	maplet.hideBubble();
	var Request = request.init("#"+strURL);
    addPoiByLatLon(Request.latlon,callBack,poitype);
}

function addPoiByLatLon(strlatlon,callBack,poitype){
    //if(!user.checkLogin()){user.createLoginPanel();return false;}
    callBack=callBack||function(obj){mymaps.addNewPoiCbk(obj);}
    var obj=new MapPoi();
    obj.type=(typeof poitype=="undefined")?1:poitype;//打点默认为mymaps操作
    obj.tmpMarkerIcon=obj.icon;
    obj.strlatlon=strlatlon;
    if(typeof mapbardis!="undefined")obj.city=mapbardis.city;//todo no good
    obj.name="标点";
    window.addPoi(obj,function(o){if(typeof callBack=="function"){callBack(o);}});
}

//画线、面后处理
function lineCallback(strURL,callBack,poitype) {
	setMoveMode();
	//maplet.removeLineAt(0); //这种方式要注意保证地图上没有其他地方使用旧方法画线
	maplet.removeLineAt(oldLineNum);
	maplet.refresh();

	callBack=callBack||function(obj){mymaps.addNewLineCbk(obj);}
    var Request = request.init(strURL);
    var obj=new MapLine();
	obj.type=(typeof poitype=="undefined")?1:poitype;//打点默认为mymaps操作
	//console.debug("obj.type"+obj.type);
    obj.strlatlon=Request.pline.split(":")[1];
    obj.name="画线";
    window.addLine(obj,function(o){if(typeof callBack=="function"){callBack(o);}});
}

function areaCallback(strURL,callBack,poitype) {
	setMoveMode();
	maplet.removeLineAt(0); //这种方式要注意保证地图上没有其他地方使用旧方法画线
	maplet.refresh();
	
	callBack=callBack||function(obj){mymaps.addNewAreaCbk(obj);}
    var Request = request.init(strURL);
    var obj=new MapLine();
    obj.type=(typeof poitype=="undefined")?1:poitype;//打点默认为mymaps操作
    obj.lineType=1;
    obj.strlatlon=Request.pline.split(":")[1];
    obj.name="画面";
    window.addArea(obj,function(o){if(typeof callBack=="function"){callBack(o);}});
}


//obj --marker
function editCallback(obj){
        var i=getPoiIndexByObjId(obj.id);
        if(i!=-1){
            if(PoiArr[i].strlatlon==obj.pt.pid)return;
            PoiArr[i].strlatlon=obj.pt.pid;
            if(PoiArr[i].lock==1||PoiArr[i].id !=0){//如果新加点只改变其经纬度，如果列表中点要改变其修改状态
                PoiArr[i].state=2;
            }else{
                PoiArr[i].state=1;
            }
            if(PoiArr[i].type==1)mymaps.updatePoi(PoiArr[i]);
			if(PoiArr[i].type==0||PoiArr[i].type==2){
				if(typeof feebackPoi=="function"){
					if(PoiArr[i].type==0)feedbackPanel.hide();
					else if(PoiArr[i].type==2)feedbackPanel.show();
					setTimeout(function(){feebackPoi(PoiArr[i].objId);},500);
				}
			}
        }else{
            i=getLineIndexByObjId(obj.id);
            if(i==-1)return;
            var arr=[];
            for(var j =0;j<obj.pts.length;j++){arr.push(obj.pts[j].pid);}
            if(LineArr[i].strlatlon==arr.join(","))return;
            LineArr[i].strlatlon=arr.join(",");
            if(LineArr[i].lock==1||LineArr[i].id !=0){//如果新加点只改变其经纬度，如果列表中点要改变其修改状态
                LineArr[i].state=2;
            }else{
                LineArr[i].state=1;
            }
            if(LineArr[i].type==1)mymaps.updatePoi(LineArr[i]);
			if(LineArr[i].type==0){
				if($('fixMap_content'))$(feedbackPanel.id).show();
				else{feedbackPanel.show();}
				fixMapSave.addMarker(LineArr[i].objId);				
			}
        }

    }
//**********************
//地图上的marker操作
function addPoi(poiObj,callback) {
    if(typeof maplet!="object")throw("maplet has not init");
    if(!poiObj||!poiObj.objId){return;}
    if(getPoiIndexByObjId(poiObj.objId)==-1){
		PoiArr.push(poiObj);
	}
	if(poiObj.preIconReadSign<1000 && (poiObj.preIcon==null || !poiObj.preIcon.complete)){
		if(poiObj.preIcon==null){
				poiObj.preIcon=new Image();
				poiObj.preIcon.src=poiObj.icon;
		}
		poiObj.preIconReadSign++;
        setTimeout(function(){window.addPoi(getPoiByObjId(poiObj.objId),callback);},200);
        return;
    } else {
        if(document.getElementById("OverlayBg_BubbleBg3")){maplet.hideBubble();}
        if(poiObj.preIcon.width<2 || poiObj.preIcon.height<2) {
			poiObj.iconWidth = 32;
			poiObj.iconHeight = 32;
		}else{
			poiObj.iconWidth = poiObj.preIcon.width;
			poiObj.iconHeight = poiObj.preIcon.height;
		}
        var point = new MPoint(poiObj.strlatlon);
        var icon = new MIcon(poiObj.getMarkerIcon(), poiObj.iconWidth, poiObj.iconHeight,(poiObj.iconWidth*poiObj.iconTargetLeft),(poiObj.iconHeight*poiObj.iconTargetTop));
        var infoWindow = null;
        if(poiObj.isShowInfoWindow) infoWindow = new MInfoWindow(poiObj.getMarkerTitle(), "");
        var poiMarker = new MMarker(point,icon,infoWindow);
        
        //放大缩小事件完成监听器
        MEvent.addListener(poiMarker , 'bubble_zoomend' , function(zoomtype){bubbleZoomEndCbk(zoomtype);});
        
        //放大缩小事件监听器
        MEvent.addListener(poiMarker , 'bubble_zoomout' , function(){bubbleZoomOutInCbk();});
        MEvent.addListener(poiMarker , 'bubble_zoomin' , function(){bubbleZoomOutInCbk();});
        
		maplet.addOverlay(poiMarker);//打点
        poiObj.objId=   poiMarker.id;
        if(typeof ContentInfo=="undefined"){poiMarker.info.content=poiObj.getMarkerContent();}
        poiObj.marker = poiMarker;
        if(poiObj.type == 1){
			poiMarker.info.content=poiObj.getMarkerContent();
            if(typeof ContentInfo!="undefined")MEvent.addListener(poiMarker, 'click', function(){
				//if(typeof getBubbleSize!="undefined")getBubbleSize();//for bubble
				setViewContentC(poiObj.objId)
			});
			poiMarker.setEditable(poiObj.allowEdit);
            if(poiObj.allowEdit)setMarkerContextMenu(poiMarker);
        }else{
           	MEvent.addListener(poiMarker, 'click', function(){
				MarkerClickExecBeforeBubble(poiObj);
				});
        }
        if(typeof callback=="function"){callback(poiObj);}

    }
}

function MarkerClickExecBeforeBubble(poiObj){
	poiMarker=poiObj.marker;
	//if(typeof getBubbleSize!="undefined")getBubbleSize();//for bubble
	if(poiMarker.info){
		poiMarker.info.title = poiObj.getMarkerTitle();
		poiMarker.info.content=poiObj.getMarkerContent();
	}
	/**for bubble */
	Request = request.init();
	if((Request.ac=='lc'||Request.ac=='nb')){
		if(poiMarker.info)poiMarker.info.setZMBtnVisible(true);
	}else{
		if(poiMarker.info)poiMarker.info.setZMBtnVisible(false);
	}

	Request.markerId=poiObj.id;
	setHash(request.toHashString(Request),false);
}

//在地图上修改点
function updatePoi(poiObj) {
	
	if(poiObj.preIconReadSign<1000 && (poiObj.preIcon==null || !poiObj.preIcon.complete)){
		setTimeout("updatePoi(getPoiByObjId('"+poiObj.objId+"'))",10);
	} else {
        if(document.getElementById("OverlayBg_BubbleBg3")){maplet.hideBubble();}
        var poiMarker = poiObj.marker;
		try{poiMarker.icon.img.innerHTML = poiObj.getMarkerIcon();}catch(e){alert(e);}
//        poiMarker.icon.img.getElementsByTagName("img")[0].src=poiObj.icon;
        poiMarker.info.title = poiObj.getMarkerTitle();
		poiMarker.info.content = poiObj.getMarkerContent();
		poiMarker.pt = new MPoint(poiObj.strlatlon);
        poiMarker.paint();
		poiObj.marker = poiMarker;
	}
}

//在地图上增加线、面
function addLine(lineObj,callBack) {
	if(lineObj.method==0){//用老方法划线
		addPolyline(lineObj);
		return;
	}
	//用新方法画线
    var infoWindow = null;
    if(lineObj.getMarkerTitle()!="")infoWindow = new MInfoWindow(lineObj.getMarkerTitle(), "");
    var lineBrush = new MBrush();
	lineBrush.color=lineObj.color; //线颜色
	lineBrush.stroke=lineObj.stroke; //线粗细
	lineBrush.style=lineObj.style; //未知功能
	lineBrush.fill=false; //false画线；true画面
	lineBrush.bgcolor=lineObj.bgcolor; //面颜色
	lineBrush.transparency=lineObj.transparency;; //线透明度
	lineBrush.bgtransparency=lineObj.bgtransparency; //面透明度
    lineBrush.arrow=/*lineObj.arrow||*/false; //箭头
	var lineMarker = new MPolyline( lineObj.getMPointArray(), lineBrush, infoWindow);
    maplet.addOverlay(lineMarker);//打点
	lineObj.marker = lineMarker;
	lineObj.objId=   lineMarker.id;

    if(infoWindow != null)lineMarker.info.content=lineObj.getMarkerContent();
	
    LineArr.push(lineObj);
    if(lineObj.type == 1){
        lineMarker.setEditable(lineObj.allowEdit);
        if(lineObj.allowEdit)setMarkerContextMenu(lineMarker);
        maplet.refresh();
    }
    if(typeof callBack=="function"){callBack(lineObj);}   
}
function addPolyline(lineObj,callBack){
	maplet.addPolylineString(lineObj.stroke+",1,"+lineObj.color, lineObj.strlatlon);
	maplet.refresh();
	oldLineNum++;
}
//在地图上修改线、面
function updateLine(lineObj) {

	var lineMarker = lineObj.marker;
    try{
        lineMarker.info.title = lineObj.getMarkerTitle();
        lineMarker.info.content = lineObj.getMarkerContent();
    }catch(e){}
    lineMarker.pts = lineObj.getMPointArray();
	lineMarker.paint();
	lineObj.marker = lineMarker;
    maplet.refresh();
}

//在地图上增加面
function addArea(areaObj,callBack) {
	
	var infoWindow = new MInfoWindow(areaObj.getMarkerTitle(), "");
	var lineBrush = new MBrush();
    lineBrush.style=areaObj.style; //未知功能

    lineBrush.color=areaObj.color.replace("%23","#"); //线颜色
	lineBrush.stroke=areaObj.stroke; //线粗细
	lineBrush.fill=areaObj; //false画线；true画面
	lineBrush.bgcolor=areaObj.bgcolor; //面颜色
	lineBrush.transparency=areaObj.transparency;; //线透明度
	lineBrush.bgtransparency=areaObj.bgtransparency; //面透明度
	lineBrush.arrow=areaObj.arrow;

    var lineMarker = new MPolyline( areaObj.getMPointArray(), lineBrush, infoWindow);
	maplet.addOverlay(lineMarker);//打点
	areaObj.marker = lineMarker;
    areaObj.objId=   lineMarker.id;
    lineMarker.info.content=areaObj.getMarkerContent();
    LineArr.push(areaObj);
    if(areaObj.type == 1){
        lineMarker.setEditable(areaObj.allowEdit);
        if(areaObj.allowEdit)setMarkerContextMenu(lineMarker);
    }
    if(typeof callBack=="function"){callBack(areaObj);}
}
