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"]
Received on Fri Jan 23 2009 - 06:18:57 EST