/*----百度地图-----*/
var Forbaidumap = function(opat){
    this.opat = opat;
    this.base();
    }
Forbaidumap.prototype = {
    base:function(){
        this.star();
        },
    star:function(){
        var _this     = this;
        _this.map     = new BMap.Map(_this.opat.id);
        _this.myGeo = new BMap.Geocoder();
        _this.searchLocation(_this.opat.add,_this.opat.city,_this.opat.x,_this.opat.y);
        /*-插件star-*/
        _this.map.enableScrollWheelZoom();
        _this.map.enableInertialDragging();
        _this.map.addControl(new BMap.NavigationControl()); 
        /*-插件end-*/
        },
    searchLocation:function(where,city,x,y){
        var _this         = this,
             _findinfo     = _this.opat.findinfo,
             _myGeo         = _this.myGeo,
             _map         = _this.map,
             _title         = _this.opat.title,
             _content     = _this.opat.content;
             _myGeo.getPoint(where, function(p){
                var point = p || new BMap.Point(x,y);
                if(_findinfo) point = new BMap.Point(x,y);
                var marker = new BMap.Marker(point);
                _map.centerAndZoom(point, 17);
                _map.addOverlay(marker);
                marker.setAnimation(BMAP_ANIMATION_BOUNCE);    
                var opts = {
                    width : 250,
                    height: 100,
                    title : _title
                    }
                var infoWindow = new BMap.InfoWindow(_content, opts);
                marker.addEventListener("click", function(){          
                    this.openInfoWindow(infoWindow);  
                    })
            }, city);
        }
    }
new Forbaidumap({
        id:"container",
        add:"宁波市火星",
        city:"宁波",
        title:"Hello",
        content:"嘟嘟嘟1",
        findinfo:false,            //默认为false,如果是true 匹配下面的经纬度
        x:120.845502,
        y:30.340754
        });
posted on 2012-07-15 22:04  somesayss  阅读(985)  评论(0编辑  收藏  举报