
/*
 * Class MMWmsTileLayer
 */
function MMWmsTileLayer(copyrights,  minResolution,  maxResolution, opacity)
{
	GTileLayer.call(this, copyrights, minResolution, maxResolution);

	this.format = "image/gif";	
	this.styles = "";
	this.opacity = opacity;
	
	this.minResolution = minResolution;
	this.maxResolution = maxResolution;
}
MMWmsTileLayer.prototype = new GTileLayer(new GCopyrightCollection(), 0, 0);


/*
 * Returns to the map whether the tiles are in PNG image format and hence can be transparent. Otherwise GIF is assumed
 */
MMWmsTileLayer.prototype.isPng = function()
{
	return this.format == "image/png";
}

/*
 * Returns to the map the opacity with which to display this tile layer. 1.0 is opaque, 0.0 is transparent.
 */
MMWmsTileLayer.prototype.getOpacity = function()
{
	return this.opacity;
}


/**
 * Returns to the map the URL of the map tile with the tile indices given by the x and y 
 * properties of the GPoint, at the given zoom level.
 */
MMWmsTileLayer.prototype.getTileUrl = function(point, zoom)
{
	if(zoom < this.minResolution) return "";
	
	// ignoriere maxresolution (wir können immer!)
	//if(zoom > this.maxResolution) return "";
	
	var tileSize = 256;
	var projection = G_NORMAL_MAP.getProjection();
	
	var upperLeftPixel = new GPoint(point.x * tileSize, (point.y+1) * tileSize);
	var lowerRightPixel = new GPoint((point.x+1) * tileSize, point.y * tileSize);
	
	var upperLeft = projection.fromPixelToLatLng(upperLeftPixel, zoom);
	var lowerRight = projection.fromPixelToLatLng(lowerRightPixel, zoom);
		
	var boundBox = upperLeft.lng() + "," +
	               upperLeft.lat() + "," +
	               lowerRight.lng() + "," + 
	               lowerRight.lat();
	               	               
	var srs = "EPSG:4326";

	var url = this.baseURL;
	url += "&REQUEST=GetMap";
	url += "&SERVICE=WMS";
	url += "&VERSION=1.1.1";
	url += "&LAYERS=" + this.layers;
	url += "&STYLES=" + this.styles; 
	url += "&FORMAT=" + this.format;
	url += "&BGCOLOR=0xFFFFFF";
	url += "&TRANSPARENT=TRUE";
	url += "&SRS=" + srs;
	url += "&BBOX=" + boundBox;
	url += "&WIDTH=" + tileSize;
	url += "&HEIGHT=" + tileSize;
	
	return url;
};

