This may help. Attached is my beta implementation of WMS support
as a plugin layer. It's a bit rough, so I'd love feedback/improvements.
-Raj
-- Raj Singh, Syncline rs@syncline.com MapCiti.com...it's your town on the web Christof Krug wrote: > Hi All, > > I am evaluating OpenMap for a project and I try to get an overview. I had a > look into OpenMap.java, OpenMapApplet.java and the examples. > > I want to be able to access a WMT compliant MapServer, which only returns a > map as png or jpeg file. I have to write a layer, which requests a new map > from the server, if the user changes the view. Can anybody give me a hint on > classes (layers etc.) which might be helpful to do that? > > I know OpenMap was used for the Web Mapping Test bed. Is there any > documentation on how to set up the OpenMap WMT server and client or is it > not included in the OpenMap distribution? > > Are there already classes for a client (eventually Applet) - server (not > necessary WMT) based solution in OpenMap? Which classes should I look at? > > Any hints welcome :) > > Thanks for your help in advance. > > Christof > > > > > -- > [To unsubscribe to this list send an email to "majdart@bbn.com" > with the following text in the BODY of the message "unsubscribe openmap-users"] >
/* **********************************************************************
* $Source: /cvs_code/ogcmpp1/src/com/bbn/openmap/plugin/wms/WMSPlugIn.java,v $
* $Revision: 1.1 $
* $Date: 2001/05/22 13:35:22 $
* $Author: rs $
*
* **********************************************************************
*/
package com.bbn.openmap.plugin.wms;
import java.awt.Component;
import java.util.Properties;
import javax.swing.ImageIcon;
import com.bbn.openmap.PropertyConsumer;
import com.bbn.openmap.event.MapMouseListener;
import com.bbn.openmap.image.ImageServerConstants;
import com.bbn.openmap.image.WMTConstants;
import com.bbn.openmap.omGraphics.*;
import com.bbn.openmap.plugin.*;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.util.Debug;
/**
* This class asks for an image from an OpenGIS compliant
* Web Map Server (WMS).
* It has some properties that you can set in the openmap.properties file:
*
* #For the plugin layer
* pluginlayer.class=com.bbn.openmap.plugin.PlugInLayer
* pluginlayer.prettyName=Whatever
* pluginlayer.plugin=com.bbn.openmap.plugin.wms.WMSPlugIn
* pluginlayer.plugin.host=hostname
* pluginlayer.plugin.port=port number
* pluginlayer.plugin.format=image format (JPEG, GIF from WMTConstants.java)
* pluginlayer.plugin.transparent=true or false, depends on imageformat
* pluginlayer.plugin.backgroundColor=RGB hex string (RRGGBB)
* pluginlayer.plugin.wmscgi=part of URL that makes the request (servlet/wms)
* pluginlayer.plugin.wmsversion=OpenGIS WMS version number (1.0.7)
*/
public class WMSPlugIn extends AbstractPlugIn implements ImageServerConstants {
/** URL to the server script that responds to WMS map requests */
protected String wmsName = null;
/** 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;
/** 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;
/** same as wmsServer */
protected String queryHeader = null;
protected String MAPREQUESTNAME = GETMAP;
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";
/**
* add new layers to the server request, using the default style
*/
public void addLayers(String[] ls) {
for (int j=0; j<ls.length; j++) {
layers += ","+ls[j];
styles += ",default";
}
}
/**
* The getRectangle call is the main call into the PlugIn module.
* The module is expected to fill the graphics list with objects
* that are within the screen parameters passed. The Graphics
* List is NOT automatically cleared with every call to
* getRectangle. YOU have to do that, if you want it to work that
* way. The list passed in, if not null, is the same list that
* should be passed out. If the list passed in is null, then a
* new OMGraphicList should be allocated and passed out.
*
* @param p projection of the screen, holding scale, center
* coords, height, width.
* @param list an OMGraphicList to add graphics to. Set to null
* if a new OMGraphicList should be allocated.
*/
public OMGraphicList getRectangle(Projection p, OMGraphicList list) {
if (list == null) {
list = new OMGraphicList();
}
if (Debug.debugging("plugin"))
System.out.println("graphics list:\n"+list.size());
if (queryHeader == null) {
return list;
}
String bbox = Float.toString(p.getUpperLeft().getLongitude()) +
"," +
Float.toString(p.getLowerRight().getLatitude()) +
"," +
Float.toString(p.getLowerRight().getLongitude()) +
"," +
Float.toString(p.getUpperLeft().getLatitude());
StringBuffer buf = new StringBuffer(queryHeader);
buf.append("?" + VERSION + "=" + wmsVersion +
"&" + REQUEST + "=" + MAPREQUESTNAME +
"&" + SRS + "=" + "EPSG:4326" +
"&" + BBOX + "=" + bbox +
"&" + HEIGHT + "=" + p.getHeight() +
"&" + WIDTH + "=" + p.getWidth() +
"&" + EXCEPTIONS + "=" + "INIMAGE");
if (imageFormat != null) {
buf.append("&" + FORMAT + "=" + imageFormat);
if ( imageFormat.equals(com.bbn.openmap.image.WMTConstants.IMAGEFORMAT_JPEG) )
buf.append("&quality=MEDIUM");
}
if (transparent != null) {
buf.append("&" + TRANSPARENT + "=true");
}
if (backgroundColor != null) {
buf.append("&" + BGCOLOR + "=" + backgroundColor);
}
if (layers != null)
buf.append("&" + LAYERS + "=" + layers);
if (styles != null)
buf.append("&" + STYLES + "=" + styles);
String urlString = buf.toString();
if (Debug.debugging("plugin")) {
Debug.output("WMSPlugIn.getRectangle() with \"" + urlString + "\"");
}
java.net.URL url = null;
try {
url = new java.net.URL(urlString);
java.net.HttpURLConnection urlc = (java.net.HttpURLConnection)url.openConnection();
if (Debug.debugging("plugin")) System.out.println("url content type: "+urlc.getContentType());
if ( urlc.getContentType().startsWith("text") ) {
java.io.BufferedReader bin =
new java.io.BufferedReader(
new java.io.InputStreamReader(urlc.getInputStream()) );
String st;
String message = "";
while ( (st=bin.readLine()) != null) {
message += st;
}
Debug.error(message);
} //end if text
else if ( urlc.getContentType().startsWith("image") ) {
urlc.disconnect();
ImageIcon ii = new ImageIcon(url);
OMRaster image = new OMRaster((int)0, (int)0, ii);
image.generate(p);
list.add(image);
} // end if image
} catch (java.net.MalformedURLException murle) {
Debug.error("WMSPlugIn: URL \"" + urlString + "\" is malformed.");
} catch (java.io.IOException ioe) {
Debug.error("Couldn't connect to "+queryHeader);
}
return list;
} //end getRectangle
/**
* 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) {
this.prefix = prefix;
String realPrefix = (prefix == null?"":prefix + ".");
wmsName = setList.getProperty(realPrefix + WMSNameProperty);
wmsServer = setList.getProperty(realPrefix + WMSServerProperty);
if (wmsName == null)
wmsName = "wmsName";
if (wmsServer == null)
Debug.error("WMSPlugIn needs a WMS server.");
queryHeader = wmsServer;
imageFormat = setList.getProperty(realPrefix + ImageFormatProperty);
transparent = setList.getProperty(realPrefix + TransparentProperty);
backgroundColor = setList.getProperty(realPrefix + BackgroundColorProperty);
wmsVersion = setList.getProperty(realPrefix + WMSVersionProperty);
if ( wmsVersion == null ) {
wmsVersion = "1.0.7";
Debug.output("WMSPlugin: wmsVersion is null");
}
if (Debug.debugging("plugin"))
Debug.output("WMSPlugIn: set up with header \"" + queryHeader + "\"");
int version = Integer.parseInt(wmsVersion.substring(4));
if ( version < 3 )
MAPREQUESTNAME = MAP;
layers = setList.getProperty(realPrefix + LayersProperty);
styles = setList.getProperty(realPrefix + StylesProperty);
} //end setProperties
public String getImageFormat() { return imageFormat; }
public void setImageFormat(String imgfmt) {
if ( imgfmt.equals(WMTConstants.IMAGEFORMAT_GIF) ||
imgfmt.equals(WMTConstants.IMAGEFORMAT_JPEG) ||
imgfmt.equals(WMTConstants.IMAGEFORMAT_PNG) )
imageFormat = imgfmt;
}
// make this better!! \\
public String getServerName() { return wmsServer; }
public String getPrettyName() { return wmsName; }
public String getName() { return wmsName; }
public WMSPlugIn() {}
public WMSPlugIn(Component comp) {
super(comp);
}
public java.awt.Component getGUI() {
return null;
}
public String getLayerMarkers() {
return null;
}
} //end WMSPlugin
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]Received on Fri Jun 1 12:02:02 2001
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:31 EDT