Google Earth WMS Image Overlay

62 views
Skip to first unread message

BobThor

unread,
Jan 23, 2014, 8:59:12 AM1/23/14
to google-earth-...@googlegroups.com
I wrote the code below to generate an image overlay using the WMS 1.1.1 protocol.  It works just fine as long as there are large number of pixels in the GIF image.  When there are very few or none (i.e. a clear image) GE EC renders it as a black square.  So my question is what should be returned when there is no data for a given tile?  A clear image isn't working out.  A null/exception displays the red x.  I would like it to just display the underlying earth.  Any help is appreciated.

            BufferedImage bi = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
            Graphics2D graphic = bi.createGraphics();

            if ((p = getRequestParameterValue(request, "layers")) == null)
                throw new Exception("Missing layer parameter");

            // add all the layers into one image left to right
            for (String s : p.split(",")) {
                generateImage(request, s, format, graphic);
            }

            // save the file in the requested format
            String fileName = String.format("map-%s.%s", request.getSession().getId(), formatToExtension(format));
            String filePath = String.format("%s/images/%s", GoogleEarthConfig.getInstance().getServletDir(), fileName);
            _logger.info(String.format("Writing image %s to file %s", fileName, filePath));
            ImageIO.write(bi, formatToExtension(format).toUpperCase(), new File(filePath));

            // set the disposition
            response.setContentType(String.format("image/%s", formatToExtension(format)));
            response.addHeader("Content-Disposition", String.format("attachment; filename=%s", fileName));

            // upload the image file to the requester
            File f = new File(filePath);
            InputStream fis = new FileInputStream(f);
            response.setContentLength((int)f.length());

            ServletOutputStream os = response.getOutputStream();
            byte[] bufferData = new byte[1024];
            int read=0;
            while((read = fis.read(bufferData))!= -1){
                os.write(bufferData, 0, read);
            }
            os.flush();
            os.close();
            fis.close();

Reply all
Reply to author
Forward
0 new messages