/*
 * Call generic wms service for GoogleMaps v2.36 and above
 *
 * Code altered and tested for Cadcorp SIS GeognoSIS v6.3.901
 *
 * Dennis Bauszus, Cadcorp http://www.cadcorp.com , dennis.bauszus@cadcorp.com
 *
 * This script is based on the work from:
 *
 * John Deck, UC Berkeley  http://johndeck.blogspot.com
 * Mike Williams http://www.econym.demon.co.uk/googlemaps2
 * Brian Flood http://www.spatialdatalogic.com/cs/blogs/brian_flood/archive/2005/07/11/39.aspx
 * Kyle Mulka http://blog.kylemulka.com/?p=287
 *
 * This script provides an implementation of GTileLayer that works with WMS services that provide EPSG4326.
 * It also performs the calculation from a GPoint to the appropriate BBOX to pass the WMS.
 *
 * There is more information at:
 * http://cfis.savagexi.com/articles/2006/05/03/google-maps-deconstructed
 *
 * This script is used by creating a new GTileLayer, setting the required and any desired optional variables,
 * and setting the functions here to override the appropriate GTileLayer ones.
 *
 * At the very least you will need:
 * var myTileLayer= new GTileLayer(new GCopyrightCollection(""),1,17);
 *     myTileLayer.myBaseURL='http://yourserver.org/wms?'
 *     myTileLayer.myLayers='myLayerName';
 *     myTileLayer=CustomGetTileUrl
 *
 * Then you can overlay on google maps with something like:
 * var layer=[G_SATELLITE_MAP.getTileLayers()[0],tileCountry];
 * var custommap = new GMapType(layer, G_SATELLITE_MAP.getProjection(), "WMS");
 * var map = new GMap(document.getElementById("map"));
 * map.addMapType(custommap);
 *
 */

CustomGetTileUrl=function(a,b,c) {

	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,c);
	var lLR = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lLRP,b,c);

	var lBbox=lUL.x+","+lUL.y+","+lLR.x+","+lLR.y;
	var lSRS="EPSG:4326";

	var lURL=this.myBaseURL;
	lURL+="&REQUEST=GetMap";
	lURL+="&SERVICE=WMS";
	lURL+="&VERSION=1.1.1";
	lURL+="&LAYERS="+this.myLayers;
	lURL+="&STYLES=default";
	lURL+="&FORMAT="+this.myFormat;
	lURL+="&BGCOLOR=0xFFFFFF";
	lURL+="&TRANSPARENT=true";
	lURL+="&SRS="+lSRS;
	lURL+="&BBOX="+lBbox;
	lURL+="&WIDTH=256";
	lURL+="&HEIGHT=256";
	lURL+="&reaspect=false";
	return lURL;
}
