/********************************以下是LTMarkerCollection类的定义************************************/

//定义用来管理标记的LTMarkerCollection类，参数map是地图，注意必须是已经初始化完毕的地图
//也就是说map必须先经过centerAndZoom定位
//By K_Reverter
	function LTMarkerCollection(map)
	{
		this.markers=[];
		this._markers=[];
		LTEvent.bind(map,"moveend",this,this.onMapMove);
		LTEvent.bind(map,"zoom",this,this.onMapMove);
		this.map=map;
		this.onMapMove();
	}
	LTMarkerCollection.prototype.showMarker=function(m)
	{
		this.map.addOverLay(m[0]);
	}
	LTMarkerCollection.prototype.hideMarker=function(m)
	{
		this.map.removeOverLay(m[0]);
	}
//添加一个标记，参数分别是标记,显示的最小缩放等级,显示的最大缩放等级
	LTMarkerCollection.prototype.addMarker=function(marker,startZoom,endZoom)
	{
		var m=[marker,startZoom,endZoom];
		if(this.inMapView(m))
		{
			this.markers.push(m);
			this.showMarker(m);
		}
		else
		{
			this._markers.push(m);
		}
	}
//在地图移动的时候执行本方法
	LTMarkerCollection.prototype.onMapMove=function()
	{
		var flag=true;
		var zoom=this.map.getCurrentZoom();
		var bounds=this.map.getBoundsLatLng();
		if(zoom!=this.zoom)
		{
			flag=false;
		}
		else
		{
			if(!this.bounds || !this.bounds.containsBounds(bounds)){flag=false;}
		}
		if(flag){return;}
		this.zoom=zoom;
		this.bounds=new LTBounds(2*bounds.Xmin-bounds.Xmax,2*bounds.Ymin-bounds.Ymax,2*bounds.Xmax-bounds.Xmin,2*bounds.Ymax-bounds.Ymin);
		for(var i=this.markers.length-1;i>=0;i--)
		{
			if(!this.inMapView(this.markers[i]))
			{
				var m=this.markers[i];
				this._markers.push(m);
				this.hideMarker(m);
				this.markers.splice(i,1);
			}
		}
		for(var i=this._markers.length-1;i>=0;i--)
		{
			if(this.inMapView(this._markers[i]))
			{
				var m=this._markers[i];
				this.markers.push(m);
				this.showMarker(m);
				this._markers.splice(i,1);
			}
		}
	}
//判断一个标记是否要添加到地图
	LTMarkerCollection.prototype.inMapView=function(m)
	{
		return this.bounds.containsPoint(m[0].getPoint()) && m[1]<=this.zoom && m[2]>=this.zoom;

	}
/********************************LTMarkerCollection类的定义结束************************************/


