//==============================================================
//Spatial Data Logic - 2005
//WMS Map Spec
/*
James Fee and others have pointed out that Cubewerks is offering an add-on to their server product that offers Google Maps data as a WMS service. This is pretty cool but what I’d expect most developers want is the ability to display WMS layers directly in a GMap instance in the browser. Fortunately, this is not too difficult if we base a WMS map spec on the existing Street Map spec and then manipulate the URL returned for each map tile. IMO, this opens up a lot more data for use in simple GMaps applications.

Download the WMSSpec code
Example:
var wms = new WMSSpec(mapTypes[0], "http://wms.jpl.nasa.gov/wms.cgi?", "WMS Test", "modis", "default", "image/jpeg" );
Either add this to your array of specs passed to the GMap constructor or use the undocumented access to the array itself. (MyGMap.mapTypes[MyGMap.mapTypes.length] = wms;)

WMSSpec(baseSpec, baseURLtoWMSServer, name, layer, style, format);
1) the Google Maps Streets spec, usually the first spec in the array but it is also pointed to by the G_MAP_TYPE and _GOOGLE_MAP_TYPE variables
2) The URL to the WMS Server, don’t forget the “?” at the end
3) Name of service, used for labeling
4) Layer – the WMS layer name to use. This parameter is passed in whole to the server so it will accept whatever the WMS server is expecting
5) Style – the WMS style to use. See 4.
6) Format – the image format to return. (e.g. image/png, image/jpeg etc.)
*/
function WMSSpec (spec, baseUrl, name, layers, styles, format, overlay, copywrite)
{
	this.BaseSpec = spec;
	this.baseUrl = baseUrl;
	this.Map = map;
    this.tileSize=spec.tileSize;
    //this.tileSize=1024;
    this.backgroundColor=spec.backgroundColor;
    this.emptyTileURL=spec.emptyTileURL;
	this.waterTileUrl=spec.waterTileUrl;
    this.numZoomLevels=spec.numZoomLevels;
    this.pixelsPerDegree=spec.pixelsPerDegree;
    this.mapBounds=spec.mapBounds;
    this.ukBounds=spec.ukBounds;
    this.earthBounds=spec.earthBounds;
	this.Name = name;
	this.Layers = layers;
	this.Styles = styles;
	this.Format = format;
	this.copywrite = copywrite;
	this.overlay = overlay;
	
}

WMSSpec.prototype.adjustBitmapX=function(a,b)
{
    return this.BaseSpec.adjustBitmapX(a,b);
}

WMSSpec.prototype.getBitmapCoordinate=function(a,b,c,d)
{
    return this.BaseSpec.getBitmapCoordinate(a,b,c,d);
}

WMSSpec.prototype.getLatLng=function(a,b,c,d)
{
    return this.BaseSpec.getLatLng(a,b,c,d);
}

WMSSpec.prototype.getTileCoordinate=function(a,b,c,d)
{
    return this.BaseSpec.getTileCoordinate(a,b,c,d);
}


WMSSpec.prototype.getOverlayURL=function(a,b,c)
{
	return this.BaseSpec.getOverlayURL(a,b,c);
}

WMSSpec.prototype.getTileURL=function(a,b,c)
{
	var ts = this.tileSize;
	var ul = this.getLatLng(a*ts,(b+1)*ts, c);
	var lr = this.getLatLng((a+1)*ts, b*ts, c);
	var bbox = ul.x + "," + ul.y + "," + lr.x + "," + lr.y;
	var url = this.baseUrl + "version=1.1.1&request=GetMap&Layers=" + this.Layers + "&Styles=" + this.Styles + "&SRS=EPSG:4326&BBOX=" + bbox + "&width=" + ts +"&height=" + ts + "&format=" + this.Format;
	//var url = this.baseUrl + "REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&LAYERS=" + this.Layers + "&STYLES=" + this.Styles + "&FORMAT=" + this.Format + "&BGCOLOR=0x000000&TRANSPARENT=TRUE&SRS=EPSG:4326&BBOX=" + bbox + "&WIDTH=" + ts + "&HEIGHT=" + ts;
	return url;
}


WMSSpec.prototype.getLowestZoomLevel=function(a,b,c)
{
    return this.BaseSpec.getLowestZoomLevel(a,b,c);
}

WMSSpec.prototype.getPixelsPerDegree=function(a)
{
   return this.BaseSpec.getPixelsPerDegree(a);
}

WMSSpec.prototype.getLinkText=function()
{
    return this.Name;
}
WMSSpec.prototype.getShortLinkText=function()
{
    return this.Name;
}
WMSSpec.prototype.hasOverlay=function()
{
    return this.BaseSpec.hasOverlay();
}
WMSSpec.prototype.getURLArg=function()
{
    return this.BaseSpec.getURLArg();
}

WMSSpec.prototype.getCopyright=function()
{
	return this.copywrite;
    //return this.BaseSpec.getCopyright();
}

WMSSpec.prototype.zoomBitmapCoord=function(a,b,c)
{
    return this.BaseSpec.zoomBitmapCoord(a,b,c);
}

