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); } }
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())); }