Hello,
I'm attempting to use OMGraphicHandlerLayer, and I used the simple example of wallpapering the map with 5 degree by 5 degree OMRects. I modeled the class after the GraticuleLayer, but I can't seem to get my class to display. GraticuleLayer displays, and my class does not. I've attached the code below. Any ideas?
Thanks,
Brian
//BEGIN CODE
import com.bbn.openmap.event.ProjectionEvent;
import com.bbn.openmap.layer.OMGraphicHandlerLayer;
import com.bbn.openmap.layer.policy.BufferedImageRenderPolicy;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.OMRect;
import com.bbn.openmap.proj.Projection;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import static com.bbn.openmap.omGraphics.OMGraphicConstants.*;
public class OverlayLayer extends OMGraphicHandlerLayer
{
private OMGraphicList omgraphics;
public OverlayLayer()
{
int scale = 5;
omgraphics = new OMGraphicList();
//Create 5 degree by 5 degree rectangles
for(int i=-90; i<90; i+=scale)
for(int j=-180; j<180; j+=scale)
{
OMRect r = new OMRect((float)i+scale,(float)j,(float)i,(float)j+scale, LINETYPE_RHUMB);
r.setFillPaint(new Color(1.0f, 0.5f, 0.0f, 0.5f));
omgraphics.add(r);
}
//Generate all rectangles
omgraphics.generate(super.getProjection());
setRenderPolicy(new BufferedImageRenderPolicy());
repaint();
}
public synchronized void renderDataForProjection(Projection proj, Graphics g)
{
if (proj == null) return;
if (!proj.equals(getProjection()))
{
setProjection(proj.makeClone());
setList(getVisibleRectList());
}
paint(g);
}
private OMGraphicList getVisibleRectList()
//This function returns only OMRects that have at least one corner visible
//on the screen.
{
OMGraphicList toRender = new OMGraphicList();
Projection p = super.getProjection();
if(p==null) return null;
for(int a=0; a<omgraphics.size(); a++)
{
OMRect omr = (OMRect)omgraphics.getOMGraphicAt(a);
float s = omr.getSouthLat();
float w = omr.getWestLon();
float n = omr.getNorthLat();
float e = omr.getEastLon();
if( isVisible(p,n,e) ||
isVisible(p,n,w) ||
isVisible(p,s,e) ||
isVisible(p,s,w))
{
toRender.add(omr);
}
}
return toRender;
}
public synchronized OMGraphicList prepare()
{
OMGraphicList ogl = getVisibleRectList();
setList(ogl);
return ogl;
}
private boolean isVisible(Projection proj, float lat, float lon)
{
//returns true if the point is visible
//From the openmap-users archive
Point p = proj.forward(lat, lon);
return
p.getX() >=0 &&
p.getX() < proj.getWidth() &&
p.getY() >= 0 &&
p.getY() < proj.getHeight();
}
public void projectionChanged(ProjectionEvent p1)
{
Projection proj = setProjection(p1);
if (proj == null)
{
repaint();
return;
}
setList(null);
doPrepare();
}
}
-- [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 Mar 24 08:48:41 2004
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:38 EDT