Hello,
I am new to Openmap and I am trying to create a
servlet to generate map images. The servlet code is as
follows:
package OpenMapTest;
//This works!
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.*;
import com.bbn.openmap.Environment;
import com.bbn.openmap.Layer;
import com.bbn.openmap.image.*;
import com.bbn.openmap.layer.GraticuleLayer;
import com.bbn.openmap.layer.DateLayer;
import com.bbn.openmap.layer.daynight.DayNightLayer;
import com.bbn.openmap.layer.etopo.ETOPOLayer;
import com.bbn.openmap.layer.shape.ShapeLayer;
import com.bbn.openmap.plugin.PlugIn;
import com.bbn.openmap.plugin.PlugInLayer;
import com.bbn.openmap.proj.Mercator;
import com.bbn.openmap.proj.Proj;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.proj.ProjectionFactory;
import com.bbn.openmap.util.ComponentFactory;
import com.bbn.openmap.util.PropUtils;
//
http://localhost:8080/OpenMapTest/MapServlet?REQUEST=MAP&SCALE=500000000&LAT=32.3800&LON=-117.90&HEIGHT=600&WIDTH=800&PROJTYPE=mercator&LAYERS=date,cities,test,graticule,demo,shapePolitical
//
http://localhost:8080/OpenMapTest/MapServlet?REQUEST=MAP&SCALE=500000000&LAT=32.3800&LON=-117.90&HEIGHT=600&WIDTH=800&PROJTYPE=CADRG&LAYERS=date,cities,test,graticule,demo,shapePolitical
//
http://localhost:8080/OpenMapTest/MapServlet?REQUEST=MAP&SCALE=500000000&LAT=32.3800&LON=-117.90&HEIGHT=600&WIDTH=800&PROJTYPE=CADRG&LAYERS=jdted,shapePolitical
public class MapServlet3 extends HttpServlet {
//Logger logger =
Logger.getLogger(MapServlet.class);
Layer dateLayer;
Layer[] layers;
AcmeJPEGFormatter formatter = new
AcmeJPEGFormatter();
Properties configProperties;
Projection defaultProjection;
MapRequestHandler iServer;
public void createLayers(Properties p)
{
dateLayer =
makeLayer("com.bbn.openmap.layer.DateLayer", "date",
p);
System.out.println("DateLayer isa " +
dateLayer.toString());
layers = new Layer[] { dateLayer };
}
public Layer makeLayer(String className, String
layerName, Properties p)
{
Object obj = ComponentFactory.create(className,
layerName, p);
if (obj instanceof Layer || obj instanceof
PlugIn) {
Layer l = null;
if (obj instanceof PlugIn) {
PlugIn pi = (PlugIn) obj;
PlugInLayer pil = new PlugInLayer();
pil.setPlugIn(pi);
pil.setName(p.getProperty(PropUtils.getScopedPropertyPrefix(pi)
+ Layer.PrettyNameProperty));
l = pil;
} else {
l = (Layer) obj;
}
return l;
}
return null;
}
//
public void init(ServletConfig conf) throws
ServletException {
super.init(conf);
String basePath =
getServletContext().getRealPath("/");
//String propFile = basePath +
conf.getInitParameter("openmap.properties");
String propFile = basePath +
"openmap.properties";
System.out.println("Requesting data from
properties file: " + propFile);
try {
File f = new File(propFile);
System.out.println("File f = " + f);
System.out.println("exists=" +
f.exists());
System.out.println("readable=" +
f.canRead());
System.out.println("writeable=" +
f.canWrite());
FileInputStream fis = new
FileInputStream(f);
configProperties = new Properties();
configProperties.load(fis);
createLayers(configProperties);
} catch (FileNotFoundException e) {
System.out.println("File not found " +
e.toString());
throw new
UnavailableException(e.getLocalizedMessage());
} catch (IOException e) {
System.out.println("IO Exception " + e.toString());
throw new
UnavailableException(e.getLocalizedMessage());
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.setContentType("image/jpeg");
System.out.println("in doGet " +
request.getQueryString() );
Properties requestProperties = new
Properties(configProperties);
byte[] returnImage = null;
String requestParameters =
request.getQueryString();
// Add any request-specific properties here.
byte[] image = null;
try
{
iServer = new
MapRequestHandler(requestProperties);
returnImage =
iServer.handleRequest(requestParameters);
response.setContentLength(returnImage.length);
response.getOutputStream().write(returnImage);
}
catch(Exception ex)
{
System.out.println("error in doGet " +
ex.toString());
}
}
public void destroy() {
iServer = null;
configProperties = null;
super.destroy();
}
}
I can pan, zoom and put in various layers but I can't
bring up the DTED layer. I got as far as displaying
dtedcov layer but I can't get the actual DTED layer.
Here is the http request I have been using
http://localhost:8080/OpenMapTest/MapServlet?REQUEST=MAP&SCALE=500000000&LAT=32.3800&LON=-117.90&HEIGHT=600&WIDTH=800&PROJTYPE=CADRG&LAYERS=jdted,dtedcov,shapePolitical
I am running Openmap on Windows XP with Tomcat 5.5 and
Java 1.5. Any help would be great. I am completely
out of ideas. Thanks.
--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed Dec 21 2005 - 12:21:34 EST