/* Package GeoTools/WMS Implementation
* Copyright (C) 2001 Cameron Shorter (camerons@users.sourceforge.net)
* Artur Hefczyc (kobit@users.sourceforge.net)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: WMSLayer.java,v 1.28 2001/12/21 12:00:57 ianturton Exp $
* $Author: ianturton $
* $Date: 2001/12/21 12:00:57 $
*/
package uk.ac.leeds.ccg.ogc;
import uk.ac.leeds.ccg.geotools.*;
import uk.ac.leeds.ccg.raster.*;
import java.net.*;
import java.util.*;
import java.awt.image.*;
import java.awt.*;
import java.io.InputStream;
/**
* WMSLayer provides an interface to access map layers from Web Map Services
* (as defined by the Open GIS Consortium).
*
* @author Cameron Shorter
* @author Artur Hefczyc
* @version $Revision: 1.28 $
*/
public class WMSLayer extends WebServiceLayer
{
/** Provides base URL and utils for WMS */
private RemoteWMS remoteWMS;
/** Comma seperated list of layers which will be sent to the WMS */
private String layers;
/** Comma-separated list of one rendering style per requested layer */
private String styles;
/** Extent of the layer */
private GeoRectangle bbox;
/** Image size in pixels */
private int format;
/** If TRUE, the background color of the image will be transparent,
* optional, default=FALSE. */
private boolean transparent; // optional
/** A hex red-green-blue color value for the background, optional,
* default=0xFFFFFF */
private String bgcolor; // optional
/** The format in which exceptions are to be returned, optional,
* default=INIMAGE */
private String exceptionFormat; // optional
/** Any non-standard params to send to the WMS */
//private String vendorSpecificParams; // optional
private final static boolean DEBUG=true;
/**
* Construct a WMS Layer.
* @param remoteWMS Provides base URL and utils for WMS
* @param layers Comma seperated list of layers which will be sent to the
* WMS. Eg "Bathymetry,Topography"
* @param styles Comma-separated list of one rendering style per
* requested layer. Default="". Eg ""
* @param bbox Extent of the layer as a GeoRectagle (ie BBox format not
* supported yet).
* @param format Format of the image, as defined in OGCConstants
* Eg OGCConstants.GIF
* @param transparent If TRUE, the background color of the image will be
* transparent, optional, default=FALSE.
* @param bgcolor A hex red-green-blue color value for the background,
* optional, default=0xFFFFFF. Eg "0xFF00FF"
* @param exceptionFormat The format in which exceptions are to be
* returned, optional. Values can be:
* "INIMAGE" - Error message written into the image
* "BLANK" - A blank image is returned
* "WMS_XML" - Error is returned as XML, see spec for more details
* Default="INIMAGE"
*/
public WMSLayer(
RemoteWMS remoteWMS,
String layers,
String styles,
GeoRectangle bbox, // optional
int format,
boolean transparent, // optional
String bgcolor, // optional
String exceptionFormat // optional
//String vendorSpecificParams // optional
)
{
if(DEBUG)System.out.println("WMSLayer created");
this.remoteWMS = remoteWMS;
this.layers = layers;
this.styles = styles;
this.bbox = bbox;
this.format = format;
this.transparent = transparent;
this.bgcolor = bgcolor;
this.exceptionFormat = exceptionFormat;
//this.vendorSpecificParams = vendorSpecificParams;
}
/** Build a new layer based on the extent passed in. It gets called by
* WebServices.PaintScaled().
* @param gg Graphical information required to build the layer. (In
* particular, extent).
*/
public Layer buildLayer(GeoGraphics gg)
{
// ImageLayer imageLayer;
URL url;
GeoRectangle extent = gg.getScale().getMapExtent();
String[] params = {
"REQUEST","map",
"LAYERS",this.layers,
"STYLES", this.styles,
"BBOX",extent.toBBoxString(),
"WIDTH",String.valueOf(gg.getScale().toGraphics(extent.getWidth())),
"HEIGHT",String.valueOf(gg.getScale().toGraphics(extent.getHeight())),
"FORMAT",OGCConstants.MAP_FORMAT_DESCRIPTION[this.format],
"TRANSPARENT",String.valueOf(this.transparent).toUpperCase(),
"BGCOLOR",this.bgcolor,
"EXCEPTIONS",this.exceptionFormat
};
System.out.println("buildLayer: about to request Image Str");
InputStream instr = remoteWMS.getImageStream(params);
if (instr != null) {
System.out.println("instr seems to be ok in WMSLayer.buildLayer");
return new ImageLayer(instr, extent);
} // end of if (imageData != null)
else {
System.out.println("instr seems to be null in WMSLayer.buildLayer");
url = this.remoteWMS.getURL(params);
return new ImageLayer(url,extent);
} // end of if (imageData != null)else
}
public void paintScaled(GeoGraphics gg)
{
GeoRectangle extent;
extent = gg.getScale().getMapExtent();
if (extent==null||extent.isEmpty()&&this.bbox!=null){
gg.getScale().setMapExtent(this.bbox,true);
if(DEBUG)System.out.println("WMSLayer: setExent="+extent);
}
super.paintScaled(gg);
}
}
/*
* Changes in file:
*
* $Log: WMSLayer.java,v $
* Revision 1.28 2001/12/21 12:00:57 ianturton
* improved the behaviour if the wttools connection dies completly.
*
* Revision 1.27 2001/12/20 15:27:23 ianturton
* various fixes and small mods to make WMSExample actually run. Can now
* display an image if you remember to choose gif or jpg as output. Still
* crashes if you zoom in.
*
* Revision 1.26 2001/11/21 13:48:19 kobit
* Added support for creating ImageLayer with InputStream as image data source and full support for downaloding map data from WMS with jprotocols package
*
*
* Revision 1.25 2001/11/20 17:01:45 kobit
* Added byte[] getContentData() support
*
* Revision 1.24 2001/10/24 09:40:18 kobit
* Added LOG cvs keyword to the end of file
*
*/