[OpenMap Users] OpenMap Image Servlet

From: Monte Philip V NPRI <MontePV_at_Npt.NUWC.Navy.Mil>
Date: Tue, 18 Apr 2006 08:13:24 -0400

I am trying to use openmap as a servlet to generate (map)images. I would like to send it params such as lat, lon, scale, height, width, fillColor and lineColor(for land), and background color. I am trying various methods but I am not having much luck. First, I checked the FAQ and found this in section 10.4:

"...Next, you need to wrap those components in a servlet container. Code for this has been posted on the openmap-users mailing list:


However, this link no longer works.

Next, I noticed that my distro had an IIS folder with a service for this very purpose, but I could not get it up an running properly (not being an asp or .NET guy, this probably isn't the method for me anyway). Then, I tried the SimpleHttpImageServer in package com.bbn.openmap.image. That worked fine, but it does not allow changes to fillColor and lineColor. The last method I tried was to write my own Servlet (see code at end of this message) using a MapBean. This code works, but gives the following exception. Any assistance is appreciated. Thanks.

AWT blocker activation interrupted:
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Unknown Source)
        at sun.awt.AWTAutoShutdown.activateBlockerThread(Unknown Source)
        at sun.awt.AWTAutoShutdown.notifyThreadBusy(Unknown Source)
        at java.awt.EventQueue.initDispatchThread(Unknown Source)
        at java.awt.EventQueue.postEvent(Unknown Source)
        at java.awt.EventQueue.postEventPrivate(Unknown Source)
        at java.awt.EventQueue.postEvent(Unknown Source)
        at java.awt.EventQueue.invokeLater(Unknown Source)
        at javax.swing.SwingUtilities.invokeLater(Unknown Source)
        at com.bbn.openmap.util.SwingWorker$2.run(SwingWorker.java:122)
        at java.lang.Thread.run(Unknown Source)

So, sometimes I see land and sometimes I just see the background.

import java.io.IOException;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bbn.openmap.Environment;
import com.bbn.openmap.MapBean;
import com.bbn.openmap.image.*;
import com.bbn.openmap.layer.shape.ShapeLayer;
import com.bbn.openmap.proj.Mercator;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.proj.ProjectionFactory;

public class GetMapImage extends HttpServlet {

        //private ImageServer generator;
        public static final String LAT_PARAM_NAME = "lat";
        public static final String LON_PARAM_NAME = "lon";
        public static final String SCALE_PARAM_NAME = "scale";
        public static final String WIDTH_PARAM_NAME = "width";
        public static final String HEIGHT_PARAM_NAME = "height";
        public static final String BG_COLOR_PARAM_NAME = "bg";
        public static final String PROJECTION_PARAM_NAME = "projection";
        public static final String LAND_BORDER_COLOR_PARAM = "lineColor";
        public static final String LAND_FILL_COLOR_PARAM = "fillColor";
        //ImageServer parameters with default values
        private String lat = "0.0";
        private String lon = "0.0";
        private String scale = "250000000";
        private String width = "350";
        private String height = "350";
        private String bg = "FF89C5F9"; // skyblue
        private String lineColor = "000000"; // black
        private String fillColor = "BDDE83"; // light green
        private String projection = "com.bbn.openmap.proj.Mercator";

        Projection defaultProjection;
        protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
                // LineColor and FillColor are handled separately from other variables
                // ( since they are projection independent)
                Object o = req.getParameter(LAND_BORDER_COLOR_PARAM);
                if(o != null)
                        lineColor = (String)o;
                o = req.getParameter(LAND_FILL_COLOR_PARAM);
                if(o != null)
                        fillColor = (String)o;
                setParams(req); //override default properties with custom properties (servlet request params)
                defaultProjection = initProjection();//configProperties);

          // Create a MapBean
        MapBean mapBean = new MapBean();

        Properties shapeLayerProps = new Properties();
        shapeLayerProps.put("prettyName", "Political Solid");
        shapeLayerProps.put("lineColor", lineColor); //lineColor
        shapeLayerProps.put("fillColor", fillColor); //fillColor
        shapeLayerProps.put("shapeFile", "D:\\openmap-4.6.2\\share\\data\\shape\\dcwpo-browse.shp");
        shapeLayerProps.put("spatialIndex", "D:\\openmap-4.6.2\\share\\data\\shape\\dcwpo-browse.ssx");

        // Add the political layer to the map
        AcmeGifFormatter f = new AcmeGifFormatter();
        byte[] image = f.getImageFromMapBean(mapBean);
        private Projection initProjection(){//Properties properties) {
                String projectionName = Environment.get(Environment.Projection, Mercator.MercatorName);
                Class projectionClass = ProjectionFactory.getProjClassForName(projection);
                return ProjectionFactory.makeProjection(projectionClass, Float.parseFloat(lat),
                        Float.parseFloat(lon), Float.parseFloat(scale),
                        Integer.parseInt(width), Integer.parseInt(height));

        private void setParams(HttpServletRequest req) {
                String tempVal = req.getParameter(LAT_PARAM_NAME);
                if(tempVal != null) {
                        lat = tempVal;
                tempVal = req.getParameter(LON_PARAM_NAME);
                if(tempVal != null) {
                        lon = tempVal;
                tempVal = req.getParameter(SCALE_PARAM_NAME);
                if(tempVal != null) {
                        scale = tempVal;
                tempVal = req.getParameter(WIDTH_PARAM_NAME);
                if(tempVal != null) {
                        width = tempVal;
                tempVal = req.getParameter(HEIGHT_PARAM_NAME);
                if(tempVal != null) {
                        height = tempVal;
                tempVal = req.getParameter(BG_COLOR_PARAM_NAME);
                if(tempVal != null) {
                        bg = tempVal;
                tempVal = req.getParameter(PROJECTION_PARAM_NAME);
                if(tempVal != null) {
                        projection = tempVal;
        private Properties createProperties() {
                Properties props = new Properties();
                props.put("openmap.Latitude", lat);
                props.put("openmap.Longitude", lon);
                props.put("openmap.Scale", scale);
                props.put("openmap.Projection", projection);
                props.put("openmap.Width", width);
                props.put("openmap.Height", height);
                props.put("openmap.BackgroundColor" , bg);
                props.put("openmap.Height", height);
                props.put("openmap.Height", height);
                return props;

Philip V. Monte
Software Engineer
Code 2514, Warfare Interoperability Branch
NAVSEA Warfare Centers Division Newport
(401) 832-5325

[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 Tue Apr 18 2006 - 09:22:19 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:07 EDT