Also, if you set the location.href property of the IMG tag (using
javascript) as the source of your map image instead of refreshing the
entire html page you can DRASTICALLY improve the performance of the map
request. Would look something like this:
var vHref = "mapimageservlet";
vHref += "?projtype=MERCATOR";
vHref += "&action=center";
vHref += "&scale=" + m_vScale;
vHref += "&lat=" + m_vLatitude;
vHref += "&lon=" + m_vLongitude;
vHref += "&width=" + m_vWidth;
vHref += "&height=" + m_vHeight;
vHref += "&bgcolor=FFFFFF";
vHref += "&x=" + nMapX;
vHref += "&y=" + nMapY;
window.frames["map_image"].location.href = vHref;
Here is some sample code that will return an image as a byte stream.
Just set the .href property of the IMG tag and whalaa your image will
refresh without posting the page back to the server. Also, this code
creates a rectangle on the screen as an AOI.
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.bbn.openmap.*;
import com.bbn.openmap.image.*;
import com.bbn.openmap.omGraphics.*;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.proj.ProjectionFactory;
import com.bbn.openmap.dataAccess.shape.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ImageServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html";
//Initialize global variables
public void init() throws ServletException
{
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
getMapImage( request, response );
}
//Clean up resources
public void destroy()
{
}
private void getMapImage( HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException
{
try
{
int nProjType = ProjectionFactory.getProjType( "MERCATOR" );
SunJPEGFormatter oFormatter = new SunJPEGFormatter();
oFormatter.setImageQuality( 100.0f );
Frame oFrame = new Frame();
OMGraphicList oGraphicList = new OMGraphicList();
Projection oProjection = ProjectionFactory.makeProjection(
nProjType,
32.0f,
-100.0f,
60000000.0f,
400,
430 );
oGraphicList.setTraverseMode( OMGraphicList.LAST_ADDED_ON_TOP
);
OMGraphicList list = new OMGraphicList();
float[] nPoints = new float[8];
nPoints[0] = 34;
nPoints[1] = -100;
nPoints[2] = 30;
nPoints[3] = -100;
nPoints[4] = 30;
nPoints[5] = -90;
nPoints[6] = 34;
nPoints[7] = -90;
EsriPolygon oEsriPolygon = new EsriPolygon( nPoints,
OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_STRAIGHT );
oEsriPolygon.setLinePaint(new Color(0, 0, 255));
oEsriPolygon.setFillPaint(new Color(0, 0, 255, 15));
oEsriPolygon.setStroke(new BasicStroke(2.0f));
oGraphicList.add( oEsriPolygon );
StringBuffer sUrlBuffer = new StringBuffer();
sUrlBuffer.append( "http://" );
sUrlBuffer.append( "172.17.38.83" );
sUrlBuffer.append( ":" );
sUrlBuffer.append( "3000" );
sUrlBuffer.append( "/openmap?REQUEST=MAP" );
sUrlBuffer.append( "&LAT=" );
sUrlBuffer.append( "32.0" );
sUrlBuffer.append( "&LON=" );
sUrlBuffer.append( "-100.0" );
sUrlBuffer.append( "&SCALE=" );
sUrlBuffer.append( "60000000" );
sUrlBuffer.append( "&PROJTYPE=" );
sUrlBuffer.append( "MERCATOR" );
sUrlBuffer.append( "&HEIGHT=" );
sUrlBuffer.append( "400" );
sUrlBuffer.append( "&WIDTH=" );
sUrlBuffer.append( "430" );
sUrlBuffer.append( "&BGCOLOR=" );
sUrlBuffer.append( "FFFFFF" );
sUrlBuffer.append( "&LAYERS=" );
sUrlBuffer.append( "graticule,politicalCombo" );
String s = sUrlBuffer.toString();
URL oUrl = new URL( sUrlBuffer.toString() );
Image oImage = Toolkit.getDefaultToolkit().getImage( oUrl );
MediaTracker oTracker = new MediaTracker( oFrame );
oTracker.addImage( oImage, 0 );
oTracker.waitForAll();
BufferedImage oBuffedImage = new BufferedImage(
oImage.getWidth( oFrame ),
oImage.getHeight( oFrame ),
BufferedImage.TYPE_INT_RGB );
Graphics2D oBiContext = oBuffedImage.createGraphics();
LatLonPoint oOrigin = oProjection.inverse( 0, 0 );
OMRaster oRaster = new OMRaster( oOrigin.getLatitude(),
oOrigin.getLongitude(),
oImage );
oGraphicList.insertOMGraphicAt( oRaster, 0 );
oGraphicList.project( oProjection, true );
oGraphicList.render( oBiContext );
byte[] byData = oFormatter.formatImage( oBuffedImage );
ServletOutputStream oOstream = response.getOutputStream();
response.setContentType( "image/jpeg" );
oOstream.write( byData );
}
catch ( Exception e )
{
throw new ServletException( e.getMessage() );
}
}
}
-----Original Message-----
From: owner-openmap-users@bbn.com [mailto:owner-openmap-users@bbn.com]
On Behalf Of David Garnier
Sent: Wednesday, May 14, 2003 1:52 PM
To: openmap-users@bbn.com
Subject: RE: [OpenMap Users] servlet example
Le mar 13/05/2003 à 19:46, Keith Alphonso a écrit :
> Generating the map via servlet is relatively simple, making it
> clickable is a little bit more difficult. The approach we took was to
> create a servlet for generating the map, then we created a servlet
> that would convert X/Y coordinates into Lat/Lon based on that map's
> settings. We used the Projection.inverse method to convert the X/Y to
> Lat/Lon. Then you can use the servlet map image as an input field in
> your HTML to send the X/Y via click.
I've been using the ismap attribute of the IMG tag. It adds the
coordinates of the cursor on the map to the url of the image, if there
is one. It works quite well and is supported since HTML 2.0. Still, it
is a little tricky to use, so I think that I will try your idea. Thanks.
Best Regards
-- David Garnier <david.garnier@etudier-online.com> -- [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"] -- [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 Wed May 14 17:17:50 2003
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:35 EDT