/**
* @author mcollini
* @version 1.0
* @class This class provides to create one Sinfo_MapLayer object that can be placed from the Sinfo_Map object on the Map.
* @param{Sinfo_Map} oSinfo_Map Instance of Sinfo_map class
* @param{<a href="http://code.google.com/apis/maps/documentation/reference.html#GMap2">GMap2</a>} oGMap2 Instance of GMap2 class (by Google Maps API)
*/ 
Sinfo_MapLayer = function(oSinfo_Map, oGMap2)
{
	var shapes = new Array();
	var layerId;
	
	var ooSinfoMap = oSinfo_Map;
	
	
	this.getSinfoMap = function()
	{
		return ooSinfoMap;
	}
    
    this.getGoogleMapObject = function()
    {
    	return ooSinfoMap.getGoogleMapObject();
    }

	 /**
    * This method provides to create one Sinfo_MapPin object.
    * @param {Sinfo_Point} par_oSinfo_Point Sinfo_Point object that contains the coordinates point.
    * @return {Sinfo_MapPin}
    */
    this.createPin = function(par_oSinfo_MapPoint)
                {
                    var oPin = new Sinfo_MapPin(this, oGMap2, par_oSinfo_MapPoint);
                    shapes[shapes.length]= oPin;
                    return oPin;
                }

    /**
    * This method provides to create one Sinfo_MapPolygon object.
    * @param {Sinfo_MapPoint} par_oSinfo_MapPoint Sinfo_MapPoint object that contains the coordinates point.
    * @return {Sinfo_MapPolygon}
    */
    this.createPolygon = function(par_oSinfo_MapPoint)
    {
        var oPolygon = new Sinfo_MapPolygon(this, oGMap2, par_oSinfo_MapPoint,"");
        shapes[shapes.length]= oPolygon;
        return oPolygon;
    }
	
    /*
     * Prova per generare un poligono
     */
    this.createPolygonFromXml = function(str_urlGeoRssXml)
    {
    	var oPolygon = new Sinfo_MapPolygon(this, oGMap2, null, str_urlGeoRssXml);
        shapes[shapes.length]= oPolygon;
        return oPolygon;
    }
    
    /**
     * This method provides to assign one id to this Sinfo_MapLayer object.
     * @param {layerId} layerId string that identifies this layer.
     */
     this.setId = function(str_layerId)
     {
    	 layerId = str_layerId;
     }
     
     /**
      * This method provides to retrieve the id for this Sinfo_MapLayer object.
      * @return {layerId} layerId string that identifies this layer.
      */
      this.getId = function()
      {
    	  return layerId;
      }
    
    /**
    * This method provites to create and show one <a href="http://code.google.com/apis/maps/documentation/reference.html#GPolygon">GPolygon</a> object on the Map or only to show this when he is just created.
    */
  	this.show = function()
      	{
  			//todo ciclo sui shapes e chiama il metodo show su quelli...
  			for(shapeCounter=0;shapeCounter<shapes.length;shapeCounter++){
  				shapes[shapeCounter].setVisible(true);
  			}
        }
  	
    /**
     * This method provites to centrate and zoom the map on the rectangular area formed by the points of this layer.
     */
   	this.centrateAndZoom = function()
       	{
   			 
   			
   		  var bounds = new GLatLngBounds;
   		  //todo ciclo sui shapes e chiama il metodo show su quelli...
   		  for(shapeCounter=0;shapeCounter<shapes.length;shapeCounter++){
   			var pointSet = new GLatLng(shapes[shapeCounter].getLat(), shapes[shapeCounter].getLng());
 			bounds.extend(pointSet);
   		  }
   		  oGMap2.setZoom(oGMap2.getBoundsZoomLevel(bounds));
   		  oGMap2.setCenter(bounds.getCenter());
   		  return true;
         }
    /**
    * This method provites to hide the <a href="http://code.google.com/apis/maps/documentation/reference.html#GPolygon">#GPolygon</a> object on the Map;
    */
    this.hide = function(){
    	//todo ciclo sui shapes e chiama il metodo hide su quelli...
			for(shapeCounter=0;shapeCounter<shapes.length;shapeCounter++){
  				shapes[shapeCounter].setVisible(false);
  			}
    	}
    
    /**
     * This method return one Array of Sinfo_MapPin and Sinfo_MapPolygon objects
     * @return {Array}
     */
    this.getShapes = function (){return shapes;}
}
