Beispiel #1
0
  /** Get an image based on index numbers */
  public BufferedImage getIndexedImage(
      int x, int y, int zoom, int cacheZoom, GMapListener listener) {

    if (listener != null) {
      if (!getGDataSource().isCached(x, y, zoom)) {
        listener.updateGMapPainting();
        listener.updateGMapMessage(GMap.MESSAGE_DOWNLOADING);
      } else {
        listener.updateGMapMessage(GMap.MESSAGE_PAINTING);
      }
    }

    BufferedImage thumbImage = getGDataSource().getImage(x, y, zoom, true);

    if (thumbImage == null) return defaultImage;

    // if we dont have to paint cache, return here
    if (cacheZoom == (GPhysicalPoint.MIN_ZOOM - 1) || cacheZoom >= zoom) return thumbImage;

    BufferedImage paintedImage =
        new BufferedImage(
            GDataSource.sourceSize.width,
            GDataSource.sourceSize.height,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = paintedImage.createGraphics();
    graphics2D.drawImage(
        thumbImage, 0, 0, GDataSource.sourceSize.width, GDataSource.sourceSize.height, null);

    // now lets move to painting the cache
    double imageNum = Math.pow(2, zoom - cacheZoom);

    // draw cache lines
    int startX = (int) (imageNum * x);
    int startY = (int) (imageNum * y);

    // get composite to restore later, set new transparent composite
    Composite originalComposite = graphics2D.getComposite();
    graphics2D.setComposite(opacity40);

    // draw grid
    for (int i = 0; i < imageNum; i++) {
      for (int j = 0; j < imageNum; j++) {
        // points
        Point upperLeft =
            new Point(
                (int) (GDataSource.sourceSize.width / imageNum) * i,
                (int) (GDataSource.sourceSize.height / imageNum) * j);
        Dimension size =
            new Dimension(
                (int) (GDataSource.sourceSize.width / imageNum),
                (int) (GDataSource.sourceSize.height / imageNum));

        // draw lines
        graphics2D.setColor(new Color(100, 100, 100));
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x + size.width, upperLeft.y);
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x, upperLeft.y + size.height);

        // check if file exists
        if (getGDataSource().isCached(startX + i, startY + j, cacheZoom))
          graphics2D.setColor(Color.RED);
        else graphics2D.setColor(new Color(155, 155, 155));

        // shade rectangle
        graphics2D.fillRect(upperLeft.x, upperLeft.y, size.width, size.height);
      }
    }

    // restore composite
    graphics2D.setComposite(originalComposite);

    return paintedImage;
  }
Beispiel #2
0
  private BufferedImage getSpecificImage(
      int x,
      int y,
      int w,
      int h,
      int imgIndexX,
      int imgIndexY,
      BufferedImage buffImg,
      int zoom,
      int cachedZoom,
      GMapListener listener,
      boolean localFilesOnly) {

    int xIndex = x / GDataSource.sourceSize.width;
    int yIndex = y / GDataSource.sourceSize.height;

    xIndex += imgIndexX;
    yIndex += imgIndexY;

    BufferedImage image = null;
    if (!localFilesOnly || getGDataSource().isCached(xIndex, yIndex, zoom))
      image = getIndexedImage(xIndex, yIndex, zoom, cachedZoom, listener);

    int xCoord = x % GDataSource.sourceSize.width;
    int yCoord = y % GDataSource.sourceSize.height;

    // Checks for invalid xCoord and yCoord
    if (xCoord < 0) {
      xCoord = 0;
    }
    if (yCoord < 0) {
      yCoord = 0;
    }

    // get info about the image
    Dimension imageSize =
        new Dimension(getGDataSource().sourceSize.width, getGDataSource().sourceSize.height);

    // find the width of what we CAN paint
    int initPaintWidth = imageSize.width - xCoord;
    int initPaintHeight = imageSize.height - yCoord;

    int paintWidth = initPaintWidth;
    int paintHeight = initPaintHeight;

    int rowImages = numOfRows(x, y, h, zoom, cachedZoom);
    int colImages = numOfCols(x, y, w, zoom, cachedZoom);

    if (imgIndexX >= colImages || imgIndexY >= rowImages) {
      return null;
    }

    int xImage = 0;
    int yImage = 0;

    int xInitCoord = xCoord;
    int yInitCoord = yCoord;

    if (imgIndexX > 0) {
      xImage = initPaintWidth + (imgIndexX - 1) * imageSize.width;
      xCoord = 0;
      if (imgIndexX < (colImages - 1)) {
        paintWidth = imageSize.width;
      } else {
        paintWidth = w - ((colImages - 2) * imageSize.width) - (imageSize.width - xInitCoord);
      }
    }
    if (imgIndexY > 0) {
      yImage = initPaintHeight + (imgIndexY - 1) * imageSize.height;
      yCoord = 0;
      if (imgIndexY < (rowImages - 1)) {
        paintHeight = imageSize.height;
      } else {
        paintHeight = h - ((rowImages - 2) * imageSize.height) - (imageSize.height - yInitCoord);
      }
    }

    if (buffImg != null) {
      Graphics2D g = (Graphics2D) buffImg.getGraphics();
      if (image != null) {
        // System.out.println(xCoord + ":" + yCoord + ":" + paintWidth + ":" + paintHeight);
        g.drawImage(
            image.getSubimage(xCoord, yCoord, paintWidth, paintHeight),
            xImage,
            yImage,
            paintWidth,
            paintHeight,
            null);
      } else {
        Composite originalComposite = g.getComposite();
        g.setComposite(opacity40);
        g.setColor(Color.BLACK);
        g.fillRect(xImage, yImage, paintWidth, paintHeight);
        g.setComposite(originalComposite);
      }
    }

    return buffImg;
  }