📄 wmsplugin.java
字号:
/* ********************************************************************** * $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/plugin/wms/WMSPlugIn.java,v $ * $Revision: 1.3.2.2 $ * $Date: 2006/01/13 21:04:22 $ * $Author: dietrick $ * * Code provided by Raj Singh, raj@rajsingh.org * Updates provided by Holger Kohler, Holger.Kohler@dsto.defence.gov.au * Raj Singh updates in July 2002 to: * - support WMS versions 1.0.8, 1.1.0 and 1.1.1 * - make JPEG image quality setting adjustable * ********************************************************************* */package com.bbn.openmap.plugin.wms;import java.util.NoSuchElementException;import java.util.Properties;import java.util.StringTokenizer;import com.bbn.openmap.image.ImageServerConstants;import com.bbn.openmap.image.WMTConstants;import com.bbn.openmap.plugin.WebImagePlugIn;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * This class asks for an image from an OpenGIS compliant Web Map Server (WMS). * Make sure that OpenMap is using the LLXY projection, because this plugin is * only asking for images that are in the Spatial Reference System EPS 4326 * projection, and anything else won't match up. This class will be growing to * be more interactive with the WMS. * * It has some properties that you can set in the openmap.properties file: * * <pre> * * #For the plugin layer, add wms_plugin to openmap.layers list * wms_plugin=com.bbn.openmap.plugin.wms.WMSPlugIn * wms_plugin.wmsserver=A URL for the WMS server (eg. http://host.domain.name/servlet/com.esri.wms.Esrimap) * wms_plugin.wmsversion=OpenGIS WMS version number (eg. 1.1.0) * wms_plugin.format=image format (eg. JPEG, GIF, PNG from WMTConstants.java) * wms_plugin.transparent=true or false, depends on imageformat * wms_plugin.backgroundcolor=RGB hex string (RRGGBB) * wms_plugin.layers=comma separated list of map layer names (eg. SDE.SASAUS_BND_COASTL,SDE.SASAUS_BND_POLBNDL) * wms_plugin.styles=comma separated list of layer rendering styles corresponding to the layers listed * wms_plugin.vendorspecificnames=comma separated list of vendor specific parameter names in order (eg. SERVICENAME) * wms_plugin.vendorspecificvalues=comma separated list of vendor specific parameter values in order (eg. default) * * </pre> * * <p> * One of the best demo WMS servers can be found at: * http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi */public class WMSPlugIn extends WebImagePlugIn implements ImageServerConstants { /** URL to the server script that responds to WMS map requests */ protected String wmsServer = null; /** GIF, PNG, JPEG, etc. (anything the server supports) */ protected String imageFormat = null; /** * If using a lossy image format, such as jpeg, set this to high, medium or * low */ protected String imageQuality = "MEDIUM"; /** Specify the color for non-data areas of the image in r,g,b */ protected String backgroundColor = null; /** true=make the backgroundColor transparent */ protected String transparent = null; /** version of the Web map server spec the server supports */ protected String wmsVersion = null; /** Comma-separated list of layer names */ protected String layers = null; /** Comma-separated list of style names */ protected String styles = null; /** Comma-separated list of vendor specific parameter names */ protected String vendorSpecificNames = null; /** Comma-separated list of vendor specific parameter values */ protected String vendorSpecificValues = null; /** Same as wmsServer */ protected String queryHeader = null; /** Keyword for map request. Changes to MAP for WMS version 1.0.0 */ protected String mapRequestName = WMTConstants.GETMAP; /** * Keyword for error handling. Changes to INIMAGE for WMS version under * 1.1.0. Changes to application/vnd.ogc.se+inimage for versions greater * than 1.1.1 */ protected String errorHandling = "application/vnd.ogc.se_inimage"; public final static String WMSNameProperty = "wmsname"; public final static String WMSServerProperty = "wmsserver"; public final static String ImageFormatProperty = "format"; public final static String BackgroundColorProperty = "backgroundcolor"; public final static String TransparentProperty = "transparent"; public static final String WMSVersionProperty = "wmsversion"; public static final String LayersProperty = "layers"; public static final String StylesProperty = "styles"; public static final String VendorSpecificNamesProperty = "vendorspecificnames"; public static final String VendorSpecificValuesProperty = "vendorspecificvalues"; /** integer identifier for high image quality */ public static final int LOSSY_IMAGE_QUALITY_HIGH = 2; /** integer identifier for medium image quality */ public static final int LOSSY_IMAGE_QUALITY_MEDIUM = 1; /** integer identifier for low image quality */ public static final int LOSSY_IMAGE_QUALITY_LOW = 0; public WMSPlugIn() {} /** * Add new layers to the server request, using the default style. */ public void addLayers(String[] ls) { addLayers(ls, null); } /** * Add new layers to the server request, using specified styles. */ public void addLayers(String[] ls, String[] st) { // DFD - do they have to be the same length? How about we just // use the styles we have for that number of layers, and let // the defaults take over for the rest. // if (ls.length != st.length) { // return null; // } for (int j = 0; j < ls.length; j++) { layers += "," + ls[j]; // Put some other checks in here instead of the length // check above. if (st == null || j >= st.length || st[j] == null) { styles += ","; } else { styles += "," + st[j]; } } } /** * Create the query to be sent to the server, based on current settings. */ public String createQueryString(Projection p) { if (queryHeader == null) { return null; } String bbox = "undefined"; String height = "undefined"; String width = "undefined"; if (p != null) { bbox = Double.toString(p.getUpperLeft().getLongitude()) + "," + Double.toString(p.getLowerRight().getLatitude()) + "," + Double.toString(p.getLowerRight().getLongitude()) + "," + Double.toString(p.getUpperLeft().getLatitude()); height = Integer.toString(p.getHeight()); width = Integer.toString(p.getWidth()); } StringBuffer buf = new StringBuffer(queryHeader); buf.append("?" + "VERSION" + "=" + wmsVersion + "&" + WMTConstants.REQUEST + "=" + mapRequestName + "&" + WMTConstants.SRS + "=" + "EPSG:4326" + "&" + WMTConstants.BBOX + "=" + bbox + "&" + WMTConstants.HEIGHT + "=" + height + "&" + WMTConstants.WIDTH + "=" + width + "&" + WMTConstants.EXCEPTIONS + "=" + errorHandling); if (imageFormat != null) { buf.append("&" + FORMAT + "=" + imageFormat); String baseImageFormat = imageFormat; if (baseImageFormat.indexOf('/') > 0) baseImageFormat = baseImageFormat.substring(baseImageFormat.indexOf('/')); if (baseImageFormat.equals(WMTConstants.IMAGEFORMAT_JPEG)) { buf.append("&quality=" + imageQuality); } } if (transparent != null) { buf.append("&" + TRANSPARENT + "=" + transparent); } if (backgroundColor != null) { buf.append("&" + BGCOLOR + "=" + backgroundColor); } if (layers != null) { buf.append("&" + LAYERS + "=" + layers); } if (styles != null) { buf.append("&" + STYLES + "=" + styles); } if (Debug.debugging("wms")) { Debug.output("query string: " + buf); } /* * Included to allow for one or more vendor specific parameters to be * specified such as ESRI's ArcIMS's "ServiceName" parameter. */ if (vendorSpecificNames != null) { if (vendorSpecificValues != null) { StringTokenizer nameTokenizer = new StringTokenizer(vendorSpecificNames, ","); StringTokenizer valueTokenizer = new StringTokenizer(vendorSpecificValues, ","); String paramName = null; String paramValue = null; while (nameTokenizer.hasMoreTokens()) { try { paramName = nameTokenizer.nextToken(); paramValue = valueTokenizer.nextToken(); buf.append("&" + paramName + "=" + paramValue); } catch (NoSuchElementException e) { if (Debug.debugging("wms")) { Debug.output("WMSPlugIn.getRectangle(): " + "parameter \"" + paramName + "\" has no value"); } } } } } return buf.toString(); } /** * Method to set the properties in the PropertyConsumer. The prefix is a * string that should be prepended to each property key (in addition to a * separating '.') in order for the PropertyConsumer to uniquely identify * properies meant for it, in the midst of Properties meant for several * objects. * * @param prefix a String used by the PropertyConsumer to prepend to each * property value it wants to look up - * setList.getProperty(prefix.propertyKey). If the prefix had already * been set, then the prefix passed in should replace that previous * value. * * @param setList a Properties object that the PropertyConsumer can use to * retrieve expected properties it can use for configuration. */ public void setProperties(String prefix, Properties setList) { super.setProperties(prefix, setList); prefix = PropUtils.getScopedPropertyPrefix(prefix);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -