Hi Lynellen,
Comments enclosed in the code...
On Friday, October 11, 2002, at 10:25 AM, Perry, Lynellen wrote:
> Hello All,
>
> I suspect this is something VERY simple that I'm overlooking, but I've
> looked at the code for all the examples, all the layers that come with
> openmap, and read the FAQ etc.
>
> What am I missing here so that I get the error message
> "OMScalingRaster:
> null projection in position" ??
>
> Best,
> Lynellen Perry
> Computer Scientist, SAIC
> V: 703-676-5497
>
> package com.saic.jnuance.GAS;
>
> import java.awt.*;
> import javax.swing.*;
>
> import com.bbn.openmap.*;
> import com.bbn.openmap.omGraphics.*;
> import com.bbn.openmap.Layer;
> import com.bbn.openmap.proj.Projection;
> import com.bbn.openmap.event.ProjectionEvent;
> import com.bbn.openmap.MapBean;
>
> /**
> * A Layer to display Andrews Air Force Base composite image.
> */
> public class AndrewsAFBLayer extends Layer {
>
> private OMGraphicList omgraphics;
> private com.bbn.openmap.omGraphics.OMScalingRaster basePhoto;
>
> public AndrewsAFBLayer() {
>
> ImageIcon baseIcon = new
> ImageIcon("C:\\NuanceGas\\com\\saic\\jnuance\\GAS\\composite.jpg");
> System.out.println("In Andrews constructor... loading image");
> basePhoto = new OMScalingRaster(38.8295f, 76.9050f, 38.7815f,
> 76.8463f, baseIcon);
> omgraphics = new OMGraphicList();
// actually, the omgraphics is empty at this point. :)
> omgraphics.clear();
> omgraphics.addOMGraphic(basePhoto);
> System.out.println("About to generate image.");
>
> }
>
>
>
>
> /
> /----------------------------------------------------------------------
> // Layer overrides
>
> /
> /----------------------------------------------------------------------
>
> public void paint(java.awt.Graphics g) {
// here's the problem. Don't call this here. Well, you can, but you
want to avoid generating omgraphics in the Swing painting thread, it
slows down the application since paint() gets called a lot more than
just when you call repaint(). It gets called whenever Swing decides
that the layer needs to help reconstruct a map. Anyway, this is where
you are getting a problems, since getProjection() will return null.
The reason why is further down...
> omgraphics.generate(getProjection());
> omgraphics.render(g);
> }
>
>
> /
> /----------------------------------------------------------------------
> // ProjectionListener interface implementation
>
> /
> /----------------------------------------------------------------------
>
>
> /**
> * Handler for <code>ProjectionEvent</code>s. This function is
> * invoked when the <code>MapBean</code> projection changes. The
> * graphics are reprojected and then the Layer is repainted.
> * <p>
> * @param e the projection event
> */
> public void
> projectionChanged(com.bbn.openmap.event.ProjectionEvent e) {
// You need to call:
setProjection(e);
// to set the layer's projection so that getProjection() will return
something other than null. But after you generate the omgraphics list
here, you don't have to do it in the paint() method too.
> omgraphics.generate(e.getProjection());
> repaint();
> }
That should fix it.
Hope this helps,
Don
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, BBN Technologies, dietrick@bbn.com
10 Moulton Street, Cambridge, MA 02138
617-873-3031 [fax]-2794
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- [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 Fri Oct 11 12:49:30 2002
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:33 EDT