/**
   * Sends image as an URL to IE 8 & 9, base64 data for others
   *
   * @param url
   * @param bufferedImage
   * @param bbox
   * @param isTiled
   */
  protected void sendWFSImage(
      String url,
      BufferedImage bufferedImage,
      Double[] bbox,
      boolean isTiled,
      boolean isboundaryTile) {
    if (bufferedImage == null) {
      log.warn("Failed to send image");
      return;
    }

    Map<String, Object> output = new HashMap<String, Object>();
    output.put(OUTPUT_LAYER_ID, this.layerId);

    Location location = this.session.getLocation();

    Tile tileSize = null;
    if (isTiled) {
      tileSize = this.session.getTileSize();
    } else {
      tileSize = this.session.getMapSize();
    }

    output.put(OUTPUT_IMAGE_SRS, location.getSrs());
    output.put(OUTPUT_IMAGE_BBOX, bbox);
    output.put(OUTPUT_IMAGE_ZOOM, location.getZoom());
    output.put(OUTPUT_IMAGE_TYPE, this.type.toString()); // "normal" | "highlight"
    output.put(OUTPUT_KEEP_PREVIOUS, this.session.isKeepPrevious());
    output.put(OUTPUT_BOUNDARY_TILE, isboundaryTile);
    output.put(OUTPUT_IMAGE_WIDTH, tileSize.getWidth());
    output.put(OUTPUT_IMAGE_HEIGHT, tileSize.getHeight());
    output.put(OUTPUT_IMAGE_URL, url);

    byte[] byteImage = WFSImage.imageToBytes(bufferedImage);
    String base64Image = WFSImage.bytesToBase64(byteImage);
    int base64Size = (base64Image.length() * 2) / 1024;

    // IE6 & IE7 doesn't support base64, max size in base64 for IE8 is 32KB
    if (!(this.session.getBrowser().equals(BROWSER_MSIE) && this.session.getBrowserVersion() < 8
        || this.session.getBrowser().equals(BROWSER_MSIE)
            && this.session.getBrowserVersion() == 8
            && base64Size >= 32)) {
      output.put(OUTPUT_IMAGE_DATA, base64Image);
    }

    this.service.addResults(this.session.getClient(), ResultProcessor.CHANNEL_IMAGE, output);
  }
Пример #2
0
  /**
   * Creates a image of the WFS layer's data
   *
   * @param tile
   * @param location
   * @param bounds
   * @param features
   * @return image
   */
  public BufferedImage draw(
      Tile tile,
      Location location,
      List<Double> bounds,
      FeatureCollection<SimpleFeatureType, SimpleFeature> features) {

    this.imageWidth = tile.getWidth();
    this.imageHeight = tile.getHeight();

    if (bounds == null) {
      this.location = location;
    } else {
      this.location = new Location(location.getSrs());
      this.location.setBbox(bounds);

      // enlarge if tile and buffer is defined
      this.isTile = true;
      if (bufferSize != 0.0d) {
        this.bufferedImageWidth = imageWidth + (int) (imageWidth * bufferSize);
        this.bufferedImageHeight = imageHeight + (int) (imageWidth * bufferSize);
      }
    }

    this.features = features;

    if (imageWidth == 0
        || imageHeight == 0
        || this.location == null
        || style == null
        || features == null) {
      log.warn("Not enough information to draw");
      log.warn(imageWidth);
      log.warn(imageHeight);
      log.warn(location);
      log.warn(style);
      log.warn(features.isEmpty());
      return null;
    }

    return this.draw();
  }