package com.bbn.openmap.examples.simple;
import com.bbn.openmap.*;
import com.bbn.openmap.event.*;
import com.bbn.openmap.omGraphics.*;
import com.bbn.openmap.omGraphics.grid.*;
/**
* A Layer to display OMGrid of ARGB values
*
*
* - OMGrid use
*
- OMLine use
*
*/
public class GridTestLayer extends Layer {
/**
* A list of graphics to be painted on the map.
*/
private OMGraphicList omgraphics;
float lat_min = 30.620f;
float lon_min = -88.536f;
float lat_max = 37.380f;
float lon_max = -80.436f;
int num_x = 10;
int num_y = 10;
/**
* Construct a default route layer. Initializes omgraphics to
* a new OMGraphicList, and invokes createGraphics to create
* the canned list of routes.
*/
public GridTestLayer() {
omgraphics = new OMGraphicList();
createBoundingBoxGraphics(omgraphics);
createGridTestGraphics();
}
/**
* Clears and then fills the given OMGraphicList. Creates
* rectangle representing grid bounding box.
*
* @param graphics The OMGraphicList to clear and populate
* @return the graphics list, after being cleared and filled
*/
public OMGraphicList createBoundingBoxGraphics(OMGraphicList graphics) {
OMRect extentsArea = new OMRect(lat_min, lon_min, lat_max, lon_max,
OMGraphic.LINETYPE_STRAIGHT);
extentsArea.setFillPaint(null);
graphics.addOMGraphic(extentsArea);
return graphics;
}
private void createGridTestGraphics()
{
// color values to use in grid
int alpha = 0x80000000;
int amber = 0x00FFFF00 | alpha;
int red = 0x00FF0000 | alpha;
int green = 0x0000FF00 | alpha;
int blue = 0x000000FF | alpha;
// Create a 10x10 checkered array of RGB values
// nothing fancy
int colors[] = {green, amber, red, blue};
int[][] gridCols = new int[num_x][num_y];
int i = 0;
for (int x = 0; x < num_x; x++) {
for (int y = 0; y < num_y; y++) {
if (x==0 && y==0 ) // make only the origin blue
gridCols[x][y] = blue;
else // checker colors for the rest
gridCols[x][y] = colors[(i % 3)];
i++;
}
}
// compute the vertical and horizontal resolutions
float verticalRes = (float)((lat_max - lat_min )/(num_y));
float horizontalRes = (float)((lon_max - lon_min )/(num_x ));
// Create the OMGridData.Int to store the int argb values
OMGridData.Int rgbGridData = new OMGridData.Int( gridCols );
// Create the omGrid for given lat lon
OMGrid omGrid = new OMGrid(lat_min, lon_min ,
verticalRes, horizontalRes, rgbGridData);
omGrid.setRenderType(OMGraphic.RENDERTYPE_LATLON);
// Set the generator to SimpleColorGenerator
// from package com.bbn.openmap.omGraphics.grid
SimpleColorGenerator gen = new SimpleColorGenerator();
omGrid.setGenerator(gen) ;
this.omgraphics.addOMGraphic(omGrid);
this.repaint();
}
//----------------------------------------------------------------------
// Standard Layer overrides
//----------------------------------------------------------------------
/**
* Renders the graphics list. It is important to make this
* routine as fast as possible since it is called frequently
* by Swing, and the User Interface blocks while painting is
* done.
*/
public void paint(java.awt.Graphics g) {
omgraphics.render(g);
}
//----------------------------------------------------------------------
// ProjectionListener interface implementation
//----------------------------------------------------------------------
/**
* Handler for ProjectionEvents. This function is
* invoked when the MapBean projection changes. The
* graphics are reprojected and then the Layer is repainted.
*
* @param e the projection event
*/
public void projectionChanged(ProjectionEvent e) {
omgraphics.project(e.getProjection(), true);
repaint();
}
}