/**
*
* @param id
* @param x
* @param y
* @param opts
* @return
*/
function GMap(id,x,y,opts){
opts = opts ? opts : {scale:'y',zoom:12,over:'n',mouse:'y'};
var obj = {
'config' : {scale:'y',zoom:12,over:'n',mouse:'y'},
'blueIcon' : '', //蓝标记
'redIcon' : '',  //红标记
'yellowIcon' : '',
'loading' : '<div ><img src="/js/loading.gif"><br/>数据正在加载中,请稍候...</div>',
'map' : '',
'circleOverLay' : '', //在地图上画的圆叠加层对象
'listenEvent' : '',
'bounds' : new GLatLngBounds(),
'initialize' : function(){ //地图初始化
if(GBrowserIsCompatible()){//判断当前浏览器是否支持谷歌地图
this.map = new ElementById(id));
this.setCenter(x,y,));//设置初始中心位置
use!='n')ableScrollWheelZoom();  //鼠标滚动轮缩放地图
ableDoubleClickZoom() ; //启用双击缩放地图     
ableDragging();  //地图拖动
this.map.addControl(new GLargeMapControl());
fig.scale!='n')this.map.addControl(new GScaleControl());  //显示地图比例尺
fig.over=='y'){//添加鹰眼图,并设置鹰眼图的大小
var Overmap = new GOverviewMapControl(new GSize(162,150));     
this.map.addControl(Overmap);
}
this.map.addControl(new GHierarchicalMapTypeControl());      //卫星
this.blueIcon = ateIcon('/js/market/blue.png');
}
},
'createIcon' : function(image){//自定义创建一个标记点图标
var icon = new GIcon(G_DEFAULT_ICON);
icon.iconSize = new GSize(20,34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(9, 34);
icon.image = image;
return icon;
},
/**
* 指定点显示对话框
* point:可为一个标记点对象,也可以一个包含经度和纬度的数组,如{x:22,y:47}
*/
'dialog' : function(point,html){
html = html ? html : this.loading;
if(point.x || point.y){
point = new GLatLng(point.x,point.y);
this.map.openInfoWindow(point,html);
}else{
point.openInfoWindow(html);
}
},
/**
* 在地图上指定点为圆心画圆
* point:可为一个标记点对象,也可以一个包含经度和纬度的数组,如{x:22,y:47}
* radius:半径(单位:公里),nodes:画的点数(默认为48个点),color:填充颜,默认为红
*/
'drawCircle' : function(point,radius,nodes,color){//在地图上指定点为圆心画圆
if(this.circleOverLay){//移除前一次画的圆
veOverlay(this.circleOverLay);
this.circleOverLay = '';
}
if(this.listenEvent){//移除前次监听事件
this.listenEvent = '';
}
if(point.x || point.y)
point = new GLatLng(point.x,point.y);
else{
point = Point();
}
var lat = point.distanceFrom(new GLatLng(point.lat()+0.1, point.lng()))/100; 
var lng = point.distanceFrom(new GLatLng(point.lat(), point.lng()+0.1))/100;
nodes = nodes ? nodes : 48;
var points = [];
var step = parseInt(360/nodes)||10;
for(i=0;i<=360;i+=step){
var _point = new GLatLng(point.lat() + (radius/lat * s(i * Math.PI/180)), point.lng() + (radius/lng * Math.sin(i * Math.PI/180)));
points.push(_point); 
d(_point);
}
color = color ? color : '#ff0000'
var overlay = this.circleOverLay = new GPolygon(points,color,1,1,color,0.4);  //开始画图
this.map.addOverlay(this.circleOverLay);
this.listenEvent = GEvent.addListener(this.map,'infowindowclose',function(){
if(obj.circleOverLay){
obj.circleOverLay = '';
}
});
},
'newGMarker' : function(x,y,options,event,callback){//在地图上创建新标记
x = x<=-90?-90:(x>=90?90:x);
y = y<=-180?-180:(y>=180?180:y);
var point = new GLatLng(x,y);
var marker = new GMarker(point,options);
if(event){
GEvent.addListener(marker,event,callback);
}
return marker;
},
/
**
* x:经度,y:纬度,options:标记选项,event:要绑定的事件,callbak:触发事件回调函数
*/
'point' : function(x,y,options,event,callbak){//向地图加入点标记
this.map.wGMarker(x,y,options,event,callbak));
},
'setCenter' : function(x,y,zoom){//按指定的中心设置地图视图
zoom = zoom<=0?0:(zoom>=19?19:zoom);
x = x<=-90?-90:(x>=90?90:x);
y = y<=-180?-180:(y>=180?180:y);
this.map.setCenter(new GLatLng(x,y),zoom);
},
'zoomIn' : function(){//缩小地图比例
In();
},
'zoomOut' : function(){//放大地图比例
Out();
},
'addCR' : function(title){//向地图右下角加上版权信息
var copyright = new GCopyrightCollection();
copyright.addCopyright(new GCopyright('Demo',new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)),0,title));
var tilelayer = new GTileLayer(copyright);
函数prototype// TileUrl = function() { return "/js/blue.png"; };  //水印图片
//tilelayer.isPng = function() { return true;};
//  Opacity = function() { return 0.1; }
var tileLayer = new GTileLayerOverlay(tilelayer);
this.map.addOverlay(tileLayer);
},
/**
* x:经度
* y:纬度
* title:文字内容
* opts:一个数字对象,包括选项有:size字体大小,weight字体是否加粗,color:字体
*/
'addWordMarker' : function(x,y,title,opts){//添加文字标记
if(!title) return;
function Rectangle(bounds,opt_size,opt_color,opt_weight) {
this.bounds_ = bounds;
this.size_ =  opt_size || (opts.size?opts.size:12);  //字体大小
this.weight_ = opt_weight || (opts.weight?opts.weight:false); //字体是否加粗
}
Rectangle.prototype = new GOverlay();
Rectangle.prototype.initialize = function(map) {//自定义曾初始化
var div = ateElement("div");
lor = lor_;
div.style.fontSize = this.size_+'px';
if(this.weight_)div.style.fontWeight = "bold";
Align = 'center';
div.style.position = "absolute";
div.innerHTML = title;
this.map_ = map;
this.div_ = div;
}
ve = function() {
this.div_.veChild(this.div_);
}
//  py = function() {
//    return new Rectangle(this.bounds_,this.size_, lor_, this.weight_);
//  }
draw = function(force) {
if (!force) return;
var c = this.map_.fromLatLngToDivPixel(new GLatLng(x,y));
this.div_.style.width = (title.length*14)+"px";
this.div_.style.left = (c.x-title.length*7) + "px";
this.div_.p = c.y + "px";
}
var bounds = Bounds();
var southWest = SouthWest();
var northEast = NorthEast();
var lngDelta = (northEast.lng() - southWest.lng()) / 4;
var latDelta = (northEast.lat() - southWest.lat()) / 4;
var rectBounds = new GLatLngBounds(new GLatLng(southWest.lat() + latDelta,southWest.lng() + lngDelta),new GLatLng(northEast.lat() - latDelta,northEast.lng() - lngDelta));
this.map.addOverlay(new Rectangle(rectBounds));
},
'clear' : function(){//清除所有叠加层
this.map.clearOverlays();
}
}
obj.initialize();
return obj;
}