@Test public void testTruncateByBounds() throws Exception { String layerName = tileLayer.getName(); ReferencedEnvelope bounds; // bounds outside layer bounds (which are -180,0,0,90) bounds = new ReferencedEnvelope(10, 20, 10, 20, DefaultGeographicCRS.WGS84); BoundingBox layerBounds = tileLayer.getGridSubset("EPSG:4326").getGridSet().getOriginalExtent(); assertFalse(bounds.intersects(layerBounds.getMinX(), layerBounds.getMinY())); assertFalse(bounds.intersects(layerBounds.getMaxX(), layerBounds.getMaxY())); mediator.truncate(layerName, bounds); verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class)); // bounds intersecting layer bounds bounds = new ReferencedEnvelope(-10, -10, 10, 10, DefaultGeographicCRS.WGS84); mediator.truncate(layerName, bounds); int numGridsets = tileLayer.getGridSubsets().size(); int numFormats = tileLayer.getMimeTypes().size(); int numStyles = 1 /* default */ + tileLayer.getInfo().cachedStyles().size(); final int expected = numGridsets * numFormats * numStyles; verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); reset(tileBreeder); bounds = bounds.transform(CRS.decode("EPSG:900913"), true); mediator.truncate(layerName, bounds); verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); reset(tileBreeder); bounds = mediator.getAreaOfValidity(CRS.decode("EPSG:2083")); // Terra del Fuego mediator.truncate(layerName, bounds); verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class)); reset(tileBreeder); bounds = mediator.getAreaOfValidity(CRS.decode("EPSG:26986")); // Massachussets mediator.truncate(layerName, bounds); verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); }
private void renderNotRenderedTiles( Graphics2D destination, IProgressMonitor monitor, WMTRenderJob renderJob, TileRange range, RasterSymbolizer style, int tileWorth, int thisid, Set<String> notRenderedTiles, Set<String> renderedTiles) throws Exception { checkCancelState(monitor, thisid, false); // set the listener on the tile range range.addListener(listener); // load the missing tiles by sending requests for them range.loadTiles(monitor); // block until all the missing tiles have come through (and draw them // as they are added to the blocking queue while (!notRenderedTiles.isEmpty()) { // check that the rendering is not canceled checkCancelState(monitor, thisid, true); if (testing) { System.out.println("BLOCKED: " + thisid); // $NON-NLS-1$ System.out.println( "waiting on: " + notRenderedTiles.size() + " tiles"); // $NON-NLS-1$ //$NON-NLS-2$ } Tile tile = null; try { Object element = null; /* get the next tile that is ready to render, * check after 1 sec if the rendering was canceled */ while ((element = tilesToDraw_queue.poll(1000, TimeUnit.MILLISECONDS)) == null) { checkCancelState(monitor, thisid, true); } tile = (Tile) element; if (testing) { System.out.println("removed from queue: " + tile.getId()); // $NON-NLS-1$ } } catch (InterruptedException ex) { if (testing) { System.out.println("InterruptedException trying to take: " + ex); // $NON-NLS-1$ } } if (testing) { System.out.println("UNBLOCKED!!!: " + thisid); // $NON-NLS-1$ } // check that the rendering is not canceled again after block checkCancelState(monitor, thisid, true); // check that the tile's bounds are within the current // context's bounds (if it's not, don't bother drawing it) and also // only draw tiles that haven't already been drawn (panning fast // can result in listeners being notified the same tile is ready multiple // times but we don't want to draw it more than once per render cycle) // ReferencedEnvelope viewbounds = getContext().getViewportModel().getBounds(); ReferencedEnvelope viewbounds = renderJob.projectMapToTileCrs(context.getViewportModel().getBounds()); if (tile != null && tile.getBufferedImage() != null && viewbounds != null && viewbounds.intersects(tile.getBounds()) && !renderedTiles.contains(tile.getId()) && notRenderedTiles.contains(tile.getId())) { try { renderedTiles.add(tile.getId()); renderTile(destination, (WMTTile) tile, style, renderJob); } catch (Exception exc) { WMTPlugin.log( "[BasicWMTRender.render] renderTile failed (2): " + tile.getId(), exc); // $NON-NLS-1$ } monitor.worked(tileWorth); // inc the monitor work by 1 tile setState(RENDERING); // tell renderer new data is ready } // remove the tile from the not rendered list regardless // of whether it was actually drawn (this is to prevent // this render cycle from blocking endlessly waiting for tiles // that either didn't return or had some error) notRenderedTiles.remove(tile.getId()); } }