Пример #1
0
  protected void renderCanvas() throws OutsideCoverageException, GeoWebCacheException, IOException {
    // Now we loop over all the relevant tiles and write them to the canvas,
    // Starting at the bottom, moving to the right and up

    // Bottom row of tiles, in tile coordinates
    long starty = srcRectangle[1];

    // gridy is the tile row index
    for (long gridy = starty; gridy <= srcRectangle[3]; gridy++) {

      int tiley = 0;
      int canvasy = (int) (srcRectangle[3] - gridy) * gridSubset.getTileHeight();
      int tileHeight = gridSubset.getTileHeight();

      if (canvOfs.top > 0) {
        // Add padding
        canvasy += canvOfs.top;
      } else {
        // Top tile is cut off
        if (gridy == srcRectangle[3]) {
          // This one starts at the top, so canvasy remains 0
          tileHeight = tileHeight + canvOfs.top;
          tiley = -canvOfs.top;
        } else {
          // Offset that the first tile contributed,
          // rather, we subtract what it did not contribute
          canvasy += canvOfs.top;
        }
      }

      if (gridy == srcRectangle[1] && canvOfs.bottom < 0) {
        // Check whether we only use part of the first tiles (bottom row)
        // Offset is negative, slice the bottom off the tile
        tileHeight += canvOfs.bottom;
      }

      long startx = srcRectangle[0];
      for (long gridx = startx; gridx <= srcRectangle[2]; gridx++) {

        long[] gridLoc = {gridx, gridy, srcIdx};

        ConveyorTile tile =
            new ConveyorTile(
                sb,
                layer.getName(),
                gridSubset.getName(),
                gridLoc,
                ImageMime.png,
                fullParameters,
                null,
                null);

        // Check whether this tile is to be rendered at all
        try {
          layer.applyRequestFilters(tile);
        } catch (RequestFilterException e) {
          log.debug(e.getMessage());
          continue;
        }

        layer.getTile(tile);

        BufferedImage tileImg = ImageIO.read(tile.getBlob().getInputStream());

        int tilex = 0;
        int canvasx = (int) (gridx - startx) * gridSubset.getTileWidth();
        int tileWidth = gridSubset.getTileWidth();

        if (canvOfs.left > 0) {
          // Add padding
          canvasx += canvOfs.left;
        } else {
          // Leftmost tile is cut off
          if (gridx == srcRectangle[0]) {
            // This one starts to the left top, so canvasx remains 0
            tileWidth = tileWidth + canvOfs.left;
            tilex = -canvOfs.left;
          } else {
            // Offset that the first tile contributed,
            // rather, we subtract what it did not contribute
            canvasx += canvOfs.left;
          }
        }

        if (gridx == srcRectangle[2] && canvOfs.right < 0) {
          // Check whether we only use part of the first tiles (bottom row)
          // Offset is negative, slice the bottom off the tile
          tileWidth = tileWidth + canvOfs.right;
        }

        // TODO We should really ensure we can never get here
        if (tileWidth == 0 || tileHeight == 0) {
          log.debug("tileWidth: " + tileWidth + " tileHeight: " + tileHeight);
          continue;
        }

        // Cut down the tile to the part we want
        if (tileWidth != gridSubset.getTileWidth() || tileHeight != gridSubset.getTileHeight()) {
          log.debug(
              "tileImg.getSubimage("
                  + tilex
                  + ","
                  + tiley
                  + ","
                  + tileWidth
                  + ","
                  + tileHeight
                  + ")");
          tileImg = tileImg.getSubimage(tilex, tiley, tileWidth, tileHeight);
        }

        // Render the tile on the big canvas
        log.debug(
            "drawImage(subtile," + canvasx + "," + canvasy + ",null) " + Arrays.toString(gridLoc));
        gfx.drawImage(tileImg, canvasx, canvasy, null); // imageObserver
      }
    }

    gfx.dispose();
  }