Exemplo n.º 1
0
  public void apply(ConveyorTile convTile) throws RequestFilterException {
    TileLayer tl = convTile.getLayer();
    // SRS srs = convTile.getSRS();
    GridSubset gridSubset = tl.getGridSubset(convTile.getGridSetId());

    int z = (int) convTile.getTileIndex()[2];
    long[] gridCoverage = gridSubset.getCoverage(z);

    // Figure out the radius
    long width = gridCoverage[2] - gridCoverage[0];
    long height = gridCoverage[3] - gridCoverage[1];

    // Rounding must always err on the side of
    // caution if you want to use KML hierarchies
    long maxRad = 0;
    if (width > height) {
      maxRad = (width / 4) + 1;
    } else {
      maxRad = (height / 4) + 1;
    }

    // Figure out how the requested bounds relate
    long midX = gridCoverage[0] + width / 2;
    long midY = gridCoverage[1] + height / 2;

    long xDist = midX - convTile.getTileIndex()[0];
    long yDist = midY - convTile.getTileIndex()[1];

    long rad = Math.round(Math.sqrt(xDist * xDist + yDist * yDist));

    if (rad > maxRad) {
      throw new BlankTileException(this);
    }
  }
Exemplo n.º 2
0
  private void seedTiles(StorageBroker storageBroker, TileRange tr, final WMSLayer tl)
      throws Exception {
    final String layerName = tl.getName();
    // define the meta tile size to 1,1 so we hit all the tiles
    final TileRangeIterator trIter = new TileRangeIterator(tr, tl.getMetaTilingFactors());

    long[] gridLoc = trIter.nextMetaGridLocation(new long[3]);

    while (gridLoc != null) {
      Map<String, String> fullParameters = tr.getParameters();

      final ConveyorTile tile =
          new ConveyorTile(
              storageBroker,
              layerName,
              tr.getGridSetId(),
              gridLoc,
              tr.getMimeType(),
              fullParameters,
              null,
              null);
      tile.setTileLayer(tl);

      tl.seedTile(tile, false);

      gridLoc = trIter.nextMetaGridLocation(gridLoc);
    }
  }
Exemplo n.º 3
0
  public ConveyorTile getConveyor(HttpServletRequest request, HttpServletResponse response)
      throws ServiceException {
    String layerId = super.getLayersParameter(request);

    String encoding = request.getCharacterEncoding();

    Map<String, String[]> params = request.getParameterMap();
    String strFormat = ServletUtils.stringFromMap(params, encoding, "format");
    String strZoom = ServletUtils.stringFromMap(params, encoding, "zoom");
    String strX = ServletUtils.stringFromMap(params, encoding, "x");
    String strY = ServletUtils.stringFromMap(params, encoding, "y");
    String strCached = ServletUtils.stringFromMap(params, encoding, "cached");
    String strMetaTiled = ServletUtils.stringFromMap(params, encoding, "metatiled");

    long[] gridLoc =
        GMapsConverter.convert(
            Integer.parseInt(strZoom), Integer.parseInt(strX), Integer.parseInt(strY));

    MimeType mimeType = null;
    try {
      if (strFormat == null) {
        strFormat = "image/png";
      }
      mimeType = MimeType.createFromFormat(strFormat);
    } catch (MimeException me) {
      throw new ServiceException("Unable to determine requested format, " + strFormat);
    }

    ConveyorTile ret =
        new ConveyorTile(
            sb,
            layerId,
            gsb.WORLD_EPSG3857.getName(),
            gridLoc,
            mimeType,
            null,
            null,
            request,
            response);

    if (strCached != null && !Boolean.parseBoolean(strCached)) {
      ret.setRequestHandler(ConveyorTile.RequestHandler.SERVICE);

      if (strMetaTiled != null && !Boolean.parseBoolean(strMetaTiled)) {
        ret.setHint("not_cached,not_metatiled");
      } else {
        ret.setHint("not_cached");
      }
    }

    return ret;
  }
Exemplo n.º 4
0
  /** NB The following code is shared across Google Maps, Mobile Google Maps and Virtual Earth */
  public void handleRequest(ConveyorTile tile) throws GeoWebCacheException {
    if (tile.getHint() != null) {
      // boolean requestTiled = true;

      if (tile.getHint().equals("not_cached,not_metatiled")) {
        // requestTiled = false;
      } else if (!tile.getHint().equals("not_cached")) {
        throw new GeoWebCacheException("Hint " + tile.getHint() + " is not known.");
      }

      TileLayer tl = tld.getTileLayer(tile.getLayerId());

      if (tl == null) {
        throw new GeoWebCacheException("Unknown layer " + tile.getLayerId());
      }

      if (!tl.isCacheBypassAllowed().booleanValue()) {
        throw new GeoWebCacheException(
            "Layer " + tile.getLayerId() + " is not configured to allow bypassing the cache.");
      }

      tile.setTileLayer(tl);
      tl.getNoncachedTile(tile);

      Service.writeTileResponse(tile, false);
    }
  }
Exemplo n.º 5
0
  private void testMultipleCrsMatchingGridSubsets(
      final String srs, final String expectedGridset, long[] tileIndex) throws Exception {
    GetMapRequest request = new GetMapRequest();

    @SuppressWarnings("unchecked")
    Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>());
    request.setRawKvp(rawKvp);
    request.setFormat("image/png");

    request.setSRS(srs);

    request.setWidth(256);
    request.setHeight(256);
    rawKvp.put("layers", "mockLayer");
    List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326");
    tileLayer = mockTileLayer("mockLayer", gridSetNames);

    // make the request match a tile in the expected gridset
    BoundingBox bounds;
    bounds = tileLayer.getGridSubset(expectedGridset).boundsFromIndex(tileIndex);

    Envelope reqBbox =
        new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY());
    request.setBbox(reqBbox);

    ArgumentCaptor<ConveyorTile> captor = ArgumentCaptor.forClass(ConveyorTile.class);
    StringBuilder errors = new StringBuilder();

    mediator.dispatch(request, errors);

    assertTrue(errors.toString(), errors.length() == 0);

    verify(tileLayer, times(1)).getTile(captor.capture());

    ConveyorTile tileRequest = captor.getValue();

    assertEquals(expectedGridset, tileRequest.getGridSetId());
    assertEquals("image/png", tileRequest.getMimeType().getMimeType());
    assertTrue(
        "Expected "
            + Arrays.toString(tileIndex)
            + " got "
            + Arrays.toString(tileRequest.getTileIndex()),
        Arrays.equals(tileIndex, tileRequest.getTileIndex()));
  }
Exemplo n.º 6
0
  private void testParameterFilter(
      GetMapRequest request,
      Map<String, String> rawKvp,
      String rawKvpParamName,
      String rawKvpParamValue) {

    // set up raw kvp
    rawKvp.put(rawKvpParamName, rawKvpParamValue);

    StringBuilder errors = new StringBuilder();
    ConveyorTile tileRequest = mediator.prepareRequest(tileLayer, request, errors);
    assertTrue(errors.toString(), errors.length() == 0);

    Map<String, String> fullParameters = tileRequest.getFullParameters();
    assertEquals(
        fullParameters.toString(),
        rawKvpParamValue,
        fullParameters.get(rawKvpParamName.toUpperCase()));
  }
Exemplo n.º 7
0
  // ignore to fix the build until the failing assertion is worked out
  @Test
  @Ignore
  public void testMinMaxCacheGetTile() throws Exception {
    WMSLayer tl = createWMSLayer("image/png", 5, 6);

    MockTileSupport mock = new MockTileSupport(tl);

    // we're not really seeding, just using the range
    SeedRequest req = createRequest(tl, GWCTask.TYPE.SEED, 4, 7);
    TileRange tr = TileBreeder.createTileRange(req, tl);

    List<ConveyorTile> tiles = getTiles(mock.storageBroker, tr, tl);

    // this number is determined by our tileRange minus those out of bounds
    assertEquals(880, tiles.size());
    // tiles at zoom 4 and 7 will have non png data
    for (int i = 0; i < tiles.size(); i++) {
      ConveyorTile tile = tiles.get(i);
      assertNotNull(tile.getBlob());
      // System.out.println(tile.getTileIndex()[2] + " " + tile.getBlob().getSize());
    }

    // empirical numbers
    // this number is determined by the number of metarequests at level 5+6
    assertEquals(218, mock.storagePutCounter.get());
    // and the number of successful hits at level 5+6
    assertEquals(176, mock.storageGetCounter.get());
    // these last will vary - on a dual core machine, they appeared predictable
    // but on a 8 core machine, the threads compete for cache and we can only
    // assertain by range
    // @todo
    // assertTrue(Math.abs(532 - mock.cacheHits.get()) < 10);
    // assertTrue(Math.abs(494 - mock.cacheMisses.get()) < 10);
    // assertTrue(Math.abs(172 - mock.wmsMetaRequestCounter.get()) < 10);
    // stats
    System.out.println("transientCacheSize " + mock.transientCache.size());
    System.out.println("transientCacheStorage " + mock.transientCache.storageSize());
  }
Exemplo n.º 8
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();
  }