Re: [OpenMap Users] Displaying an image in open map

From: Don Dietrick <dietrick_at_bbn.com>
Date: Mon, 26 Jan 2009 18:19:15 -0500

Hi Cat,

I think the problem is how you are configuring the layer to be used in
the application. The easiest thing to way to start is to use the
default OpenMap application, configured with the openmap.properties
file. You'll want to add an entry for the EarthImagePlugIn in the
openmap.layers property with some keyword you choose. Then, using
that keyword to scope the properties for the layer, add them to the
properties file, too. For instance, if I choose earthImage as my
keyword, I'd have properties like:

earthImage.prettyName=Earth at Night
earthImage.class=com.bbn.openmap.plugin.earthImage.EarthImagePlugIn
earthImage.image=/data/geoImages/Earthlig.jpg

If you want to do this programmatically, I'd create a PlugInLayer and
then set the properties on it:


PlugInLayer pil = new PlugInLayer();
Properties earthImageProps = new Properties();
earthImageProps.put("prettyName","NasaBlueMarblePlugIn");
earthImageProps
.put("plugin","com.bbn.openmap.plugin.earthImage.EarthImagePlugIn");
earthImageProps.put("image","/data/geoImages/Earthlig.jpg");
pil.setProperties(earthImageProps);

(You don't need to set the class property for the layer because it's
already instantiated at this point)

Then, add the PlugInLayer to the MapHandler or the BasicMapPanel.
Follow the model in SimpleMap2 for configuring an OpenMap app, and
make sure you use the LayerHandler too.

Hope this helps,

Don

On Jan 23, 2009, at 6:17 AM, Cat17 wrote:

>
> Does anyone have some example code for displaying a background image
> of the
> world as an OMRaster layer?
> I have tried various different methods but all unsucessful. Enclosed
> is code
> of my attempts.
> Any help at all would be very much appreciated.
>
> Thanks in advance,
> Cat
>
> * Try adding the plugin directly . . .
> * _at_return
> */
> private OMGraphicHandlerLayer getEarthLayerDirect()
> {
> /*
> * Generate image from URL
> */
> BufferedImage bi = null;
> Image img = null;
> URL url= null;
>
> try {
> url = new URL( "file://C/~/share/data/images/GRID.bmp" );
>
> ImageProducer ip = BMPReader.getBMPImage(url.openStream());
> img = Toolkit.getDefaultToolkit().createImage(ip);
>
> bi = BufferedImageCreator.toBufferedImage(img);
>
> } catch (MalformedURLException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> /*
> * Earth plugin
> */
> EarthImagePlugIn epi = new EarthImagePlugIn();
> Properties earthImageProps = new Properties();
> earthImageProps.put("class",
> "com.bbn.openmap.plugin.PlugInLayer");
> earthImageProps.put("prettyName","NasaBlueMarblePlugIn");
> earthImageProps.put("plugin",
> "com.bbn.openmap.plugin.earthImage.EarthImagePlugIn");
>
>
>
> //earthImageProps.put("plugin.image","./share/data/images/GRID.bmp");
> earthImageProps.put("image",url);
>
> epi.setProperties(earthImageProps);
>
> //epi.setProperties("pluginlayer", properties);
> // epi.setProperties("eipi", properties);
> // //For testing
> // System.out.println(properties.getProperty("eipi.image"));
>
> OMGraphicList graphics =
> epi.getRectangle(mapBean.getProjection());
> graphics.generate(mapBean.getProjection());
>
> OMGraphicHandlerLayer omgHandler = new OMGraphicHandlerLayer();
> omgHandler.setList(graphics);
> mapHandler.add(omgHandler);
>
> return omgHandler;
> }
>
> /**
> * Try adding the plugin directly . . . Using my edited version of
> the
> plugin (NomsEarthLayerDirect)
> * _at_return
> */
> private OMGraphicHandlerLayer getNomsEarthLayerDirect()
> {
> /*
> * Generate image from URL
> */
> BufferedImage bi = null;
> Image img = null;
> URL url= null;
>
>
> try {
> url = new URL( "file://C:/~/share/data/images/GRID.bmp" );
>
> } catch (MalformedURLException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> /*
> * Earth plugin
> */
> NomsEarthImagePlugIn epi = new NomsEarthImagePlugIn();
> Properties earthImageProps = new Properties();
> // earthImageProps.put("class",
> "com.bbn.openmap.plugin.PlugInLayer");
> // earthImageProps.put("prettyName","NasaBlueMarblePlugIn");
> // earthImageProps.put("plugin",
> "com.bbn.openmap.plugin.earthImage.EarthImagePlugIn");
>
>
> //
> //earthImageProps.put("plugin.image","./share/data/images/GRID.bmp");
> // earthImageProps.put("image",url);
>
> // epi.setProperties(earthImageProps);
>
> //epi.setProperties("pluginlayer", properties);
> // epi.setProperties("eipi", properties);
> // //For testing
> // System.out.println(properties.getProperty("eipi.image"));
>
> OMGraphicList graphics =
> epi.getRectangle(mapBean.getProjection(),
> url);
> graphics.generate(mapBean.getProjection());
>
> OMGraphicHandlerLayer omgHandler = new OMGraphicHandlerLayer();
> omgHandler.setList(graphics);
> mapHandler.add(omgHandler);
>
> return omgHandler;
> }
>
> /*
> * Try getting blue marble as an image . . .
> * Perhaps can add it this way instead . . . .
> */
> private Image getBlueMarbleAsImage()
> {
> Image img = null;
>
> try {
> URL url = new URL( "share/data/images/GRID.bmp" );
> ImageProducer ip = BMPReader.getBMPImage(url.openStream());
> img = Toolkit.getDefaultToolkit().createImage(ip);
> } catch (MalformedURLException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> return img;
> //now do something with this image. . . . !!!!
> }
>
> public void placeImageOnMap(String img, float latitude, float
> longitude)
> {
>
> String imagefile = new String(img);
> File file = new File(imagefile);
> OMRaster omRaster = new OMRaster();
> OMGraphicHandlerLayer omgHandler = new OMGraphicHandlerLayer();
> OMGraphicList omgl = new OMGraphicList();
> try{
> BufferedImage image = ImageIO.read(file);
>
> //add image to map
> omRaster.setImage(image);
> omRaster.scaleTo(25,25,25);
> omRaster.setLat(latitude);
> omRaster.setLon(longitude);
>
> omgl.addOMGraphic(omRaster);
> omgl.generate(mapBean.getProjection()); //not sure if this
> required
> or not?
> repaint();
> omgHandler.setList(omgl);
> mapHandler.add(omgHandler);
>
> }catch(IOException ioe){
> System.out.println(ioe.getMessage());
> }
> }
>
> public JButton testDisplayImage()
> {
> Image image = null;
> try {
> // Read from a file
> File file = new File("share/data/images/GRID.bmp");
> image = ImageIO.read(file);
> //
> // // Read from an input stream
> // InputStream is = new BufferedInputStream(
> // new FileInputStream("image.gif"));
> // image = ImageIO.read(is);
>
> // Read from a URL
> //URL url = new URL( "file://C~share/data/images/GRID.bmp" );
> // URL url = new URL ("client/gui/images/bluemarble.jpg");
> // image = ImageIO.read(url);
>
> // ImageProducer ip = BMPReader.getBMPImage(url.openStream());
> // image = Toolkit.getDefaultToolkit().createImage(ip);
>
> } catch (IOException e) {
> }
>
> // Use a label to display the image
> // JFrame frame = new JFrame();
> // JLabel label = new JLabel(new ImageIcon(image));
> // frame.getContentPane().add(label, BorderLayout.CENTER);
> // frame.pack();
> // frame.setVisible(true);
>
>
>
> JButton imageBtn = new JButton();
> if (image != null)
> {
> ImageIcon bgImg = new ImageIcon(image);
> imageBtn.setIcon(bgImg);
> }
> else
> System.out.println("IMAGE IS NULL...FAILED TO DISPLAY");
>
>
> // OMRaster omRaster = new OMRaster();
> // OMGraphicHandlerLayer omgHandler = new OMGraphicHandlerLayer();
> // OMGraphicList omgl = new OMGraphicList();
> // //add image to map
> // omRaster.setImage(image);
> //// omRaster.scaleTo(25,25,25);
> //// omRaster.setLat(latitude);
> //// omRaster.setLon(longitude);
> //
> // omgl.addOMGraphic(omRaster);
> // omgl.generate(mapBean.getProjection()); //not sure if this
> required or not?
> // repaint();
> // omgHandler.setList(omgl);
> // mapHandler.add(omgHandler);
> //
> return imageBtn;
>
> }
>
> --
> View this message in context: http://www.nabble.com/Displaying-an-image-in-open-map-tp21609173p21609173.html
> Sent from the OpenMap mailing list archive at Nabble.com.
>
> --
> [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"]



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, openmap_at_bbn.com
BBN Technologies, Cambridge MA, USA
http://openmap.bbn.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


--
[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 Mon Jan 26 2009 - 18:24:08 EST

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