Re: [OpenMap Users] ImageServer and OMGraphics

From: Greg Bulla <gbulla_at_yahoo.com>
Date: Wed, 22 Feb 2006 15:10:42 -0800 (PST)

Hi Dan - Are you saying that you want to write on top of the image on
the client side, or back on the server (servlet) that is generating
the original image?

If you want to do it on the client, we use JPanel and its public
synchronized void paintComponent(Graphics graphics) method. This is
called when the panel is repainted. But you can get the graphics
using JPanel's (actually JComponent's) getGraphics(). You have to
add the image to the JPanel first, then can do your line drawing. Our
code looks something like this.

   private boolean downloadImage(String urlString)
   {
      try
      {
         if (isVisible())
         {
            java.net.URL url = new java.net.URL(urlString);

            java.awt.Image mapImage = null;

            mapImage = Toolkit.getDefaultToolkit().createImage(url);

            MediaTracker mediaTracker = new
MediaTracker(MapLayer.this);
            mediaTracker.addImage(mapImage, 0);
            mediaTracker.waitForAll();
            mediaTracker.removeImage(mapImage);

            // previously set graphics using getGraphics()
            if (graphics != null)
            {
               if (!blackAndWhite)
               {
                  graphics.setColor(parent.getMapBackgroundColor());
                  graphics.fillRect(0, 0, 640, 480);

                  graphics.drawImage(mapImage, 0, 0, this);
               else
               {
                  Image bw = makeBlackAndWhite(mapImage);
                  graphics.drawImage(bw, 0, 0, this);
                  bw = null;
               }
            }

            repaint();
            mediaTracker = null;
         }

         // free up memory

         url = null;
         System.gc();
         return true;
      }
      catch (Exception e)
      {
         return false;
      }
   }


-Greg


> Hi,
> I have a servlet that returns an image generated with
> ImageServer. ¿How can I use OMGraphics over that
> image?
> I want draw some lines over it but dont know how to
> get the graphic context.
>
> Thank you very much!
>
> This is the code that have:
> float lat = 40;
> float lon = -3;
> int escale = 45000000;
>
> LatLonPoint ll = new LatLonPoint(lat,lon);
> Projection pp = new Mercator(ll,escale,400,200);
> ImageServer iServer = new ImageServer(Props);
> SunJPEGFormatter JpegFF = new SunJPEGFormatter();
> JpegFF.setImageQuality(1);
> iServer.setFormatter(JpegFF);
> response.setContentType("image/jpeg");
> ServletOutputStream fo = response.getOutputStream();
> fo.write( iServer.createImage(pp));
>
> end
>
>
>
> ______________________________________________
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por minuto.
> http://es.voice.yahoo.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"]
>

--
[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 Wed Feb 22 2006 - 18:11:54 EST

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