/*
 * Create GoogleMap WMS (transparent) layers on any GoogleMap.
 *
 * CREDITS
 * Questo codice e' basato ed ispirato da:
 * Brian Flood 
 * Kyle Mulka
 * Just van den Broecke
 */

function creaWMS(URL, gName1, gName2, Layers) {
	var tile = new GTileLayer(new GCopyrightCollection(""), 1, 17);
	tile.getTileUrl = function(a, b) {

	var lULP = new GPoint(a.x * 256, (a.y + 1) * 256);
	var lLRP = new GPoint((a.x + 1) * 256, a.y * 256);
	var lUL = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lULP, b);
	var lLR = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lLRP, b);
	
	var lBbox = lUL.x + "," + lUL.y + "," + lLR.x + "," + lLR.y;
	var lURL = URL;
	lURL += "&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&LAYERS=" + Layers;
	lURL += "&FORMAT=image/png&TRANSPARENT=TRUE&SRS=EPSG:4326"
	lURL += "&BBOX=" + lBbox + "&WIDTH=256&HEIGHT=256&reaspect=false";
	return lURL;
};

	var layer = [tile];
	var mapType = new GMapType(layer, G_SATELLITE_MAP.getProjection(), gName1, G_SATELLITE_MAP);
	return mapType;
}

function creaWMSOvr(gSpec, wmsSpec, gName1, gName2) {
	wmsSpec.getTileLayers()[0].getOpacity = function() {
		return 0.5;
	}
	var layers = [gSpec.getTileLayers()[0], wmsSpec.getTileLayers()[0]];
	return new GMapType(layers, gSpec.getProjection(), gName2);
}
