currentContext.setStatus(ILayer.WORKING);
setState( STARTING );
ParameterValue[] parameterValues = group.values().toArray(new ParameterValue[0]);
GridCoverage2D coverage = (GridCoverage2D) reader.read(parameterValues);
if(coverage!=null){
//setting rendering hints
//
RenderingHints hints = new RenderingHints(new HashMap<RenderingHints.Key,Object>());
hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED));
hints.add(new RenderingHints(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE));
hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED));
hints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED));
hints.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
hints.add(new RenderingHints(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE));
hints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF));
hints.add(new RenderingHints(JAI.KEY_INTERPOLATION,new InterpolationNearest()));
graphics.addRenderingHints(hints);
// JG: Store title cache on the layer blackboard so it can last between runs.
// Performance question: may do better to have a single larger tile cache on the map blackboard?
//
final TileCache tempCache=currentContext.getTileCache();
hints.add(new RenderingHints(JAI.KEY_TILE_CACHE,tempCache));
//hints.add( new Hints( Hints.RESAMPLE_TOLERANCE, 0.000000000001 ));
if( CRS.getHorizontalCRS(destinationCRS) == null ){
destinationCRS = coverage.getCoordinateReferenceSystem2D();
}
//
AffineTransform worldToScreen = null; // we are leting the GridCoverageRenderer sort that out
//draw
try {
Style style = grabStyle();
Rule rule = SLDs.getRasterSymbolizerRule(style);
final double currentScale = currentContext.getViewportModel().getScaleDenominator();
double minScale = rule.getMinScaleDenominator();
double maxScale = rule.getMaxScaleDenominator();
if (minScale <= currentScale && currentScale <= maxScale ) {
final GridCoverageRenderer paint = new GridCoverageRenderer( destinationCRS, envelope, screenSize,worldToScreen,hints );
final RasterSymbolizer rasterSymbolizer = SLD.rasterSymbolizer(style);
// check if there is a color to mask
Object maskColor = getContext().getLayer().getStyleBlackboard().getString("raster-color-mask"); //$NON-NLS-1$
if (maskColor instanceof String) {
// create a color mask
String[] colorSplit = ((String) maskColor).split(":"); //$NON-NLS-1$
Color color = new Color(Integer.parseInt(colorSplit[0]), Integer.parseInt(colorSplit[1]),
Integer.parseInt(colorSplit[2]));
RenderedImage image = coverage.getRenderedImage();
ImageWorker iw = new ImageWorker(image);
iw.makeColorTransparent(color);
image = iw.getRenderedImage();
GridCoverageFactory gcF = CoverageFactoryFinder.getGridCoverageFactory(null);
coverage = gcF.create(coverage.getName(), image, coverage.getCoordinateReferenceSystem(), coverage
.getGridGeometry().getGridToCRS(), coverage.getSampleDimensions(), null, null);
}
//setState( RENDERING );
paint.paint( graphics, coverage, rasterSymbolizer );
setState( DONE );