/**
 * 百度地图JS
 * User: hpjianhua
 * Date: 14-8-7
 * Time: 下午6:04
 * 初始化百度地图,自定义标注,搜索信息弹窗,多标注居中,添加百度显示控件.
 */
var MerpsMap = function(){
    this.map = null,
    /**
     * 创建map地图对象
     */
        this.$loadMap = function(mapId){
            this.map = new BMap.Map(mapId);
            return this.map;
        },

    /**
     * 创建标注
     * 参数说明:point指坐标,e指当前是第几个坐标,popTitle指弹窗标题,sContent指弹窗体内容,
     *        isAnimation是否跳动显示标注, isDefineIcon是否自定义标注图片,isShowTip是否默认显示弹窗, isLeft是否有左边菜单项显示;
     */
        this.$createMarker = function(point, e, popTitle, sContent, isAnimation,isDefineIcon,isShowTip,isLeft){
            var marker = null;
            if(isDefineIcon){
                marker = new BMap.Marker(point,{icon:this.$setIcon(e)});
            }else{
                marker = new BMap.Marker(point);
            }
            this.map.addOverlay(marker);
            if(isAnimation && !isLeft){
                marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
            }

            var searchInfoWindow = new BMapLib.SearchInfoWindow(this.map, sContent, {
                title  : popTitle,      //标题
                width  : 290,           //宽度
                //height : 100,           //高度
                panel  : "panel",       //检索结果面板
                enableAutoPan : true,   //自动平移
                //offset:new BMap.Size(0,30),
                searchTypes   :[
                    //BMAPLIB_TAB_TO_HERE,  //到这里去
                    //BMAPLIB_TAB_SEARCH	  //在附近查找
                ]
            });
            if(isShowTip){
                searchInfoWindow.open(marker);
            }
            if(!isLeft){
                marker.addEventListener("click", function(){
                    searchInfoWindow.open(marker);
                });
            }
        },
    /**
     * 设置地图居中
     */
        this.$setCenter = function(x,y,top){
            //设置标注中点居中
            var center = new BMap.Point(x, y);
            this.map.centerAndZoom(center, top);
        },
    /**
     * 设置多个标注层级自动适应
     */
        this.$setViewport = function(points){
            this.map.setViewport(points);
        },
        this.$setControl = function(isLeft){
            //百度控件
            this.map.enableScrollWheelZoom(true); //启用滚轮放大缩小
            if(!isLeft){
                //this.map.addControl(new BMap.MapTypeControl());  //2D图,卫星图,三维
                this.map.addControl(new BMap.NavigationControl());
                this.map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]}));     //2D图,卫星图
            }
            this.map.addControl(new BMap.CopyrightControl());
            this.map.addControl(new BMap.OverviewMapControl());
            this.map.addControl(new BMap.ScaleControl());
            this.map.setDefaultCursor("default");
            this.map.setDraggingCursor("default");
        },
    /**
     * 三维地图中需要设置当前城市
     */
        this.$setCurrentCity = function(cityName){
            this.map.setCurrentCity(cityName);
        }
}
