Pair<Integer, Integer> getLegendSize( Style style ) { Pair<Integer, Integer> res = legendSizes.get( style ); if ( res != null ) { return res; } legendSizes.put( style, res = new Legends().getLegendSize( style ) ); return res; }
Legends legends = new Legends(); Pair<Integer, Integer> legendSize = legends.getLegendSize( parsedStyle ); BufferedImage img = new BufferedImage( legendSize.first, legendSize.second, BufferedImage.TYPE_INT_ARGB ); Graphics2D g = img.createGraphics(); g.setRenderingHint( KEY_ANTIALIASING, VALUE_ANTIALIAS_ON ); g.setRenderingHint( KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON ); legends.paintLegend( parsedStyle, legendSize.first, legendSize.second, g ); g.dispose();
BufferedImage getLegend( GetLegendGraphic req ) { Legends renderer = new Legends( req.getLegendOptions() ); Style style = findLegendStyle( req.getLayer(), req.getStyle() ); Pair<Integer, Integer> size; if ( renderer.getLegendOptions().isDefault() ) { size = getLegendSize( style ); } else { size = renderer.getLegendSize( style ); } if ( req.getWidth() == -1 ) { req.setWidth( size.first ); } if ( req.getHeight() == -1 ) { req.setHeight( size.second ); } boolean originalSize = req.getWidth() == size.first && req.getHeight() == size.second && renderer.getLegendOptions().isDefault(); HashMap<String, BufferedImage> legendMap = legends.get( style ); if ( originalSize && legendMap != null && legendMap.get( req.getFormat() ) != null ) { return legendMap.get( req.getFormat() ); } if ( legendMap == null ) { legendMap = new HashMap<String, BufferedImage>(); legends.put( style, legendMap ); } return buildLegend( req, renderer, style, originalSize, legendMap ); }
List<LegendItem> items = prepareLegend( style, g, width, height ); int rowHeight = 2 * opts.spacing + opts.baseHeight; int pos = getLegendSize( style ).second;
private BufferedImage buildLegend( GetLegendGraphic req, Legends renderer, Style style, boolean originalSize, HashMap<String, BufferedImage> legendMap ) { BufferedImage img = MapService.prepareImage( req ); Graphics2D g = img.createGraphics(); g.setRenderingHint( KEY_ANTIALIASING, VALUE_ANTIALIAS_ON ); g.setRenderingHint( KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON ); renderer.paintLegend( style, req.getWidth(), req.getHeight(), g ); g.dispose(); if ( req.getFormat().equals( "image/png; mode=8bit" ) || req.getFormat().equals( "image/png; subtype=8bit" ) || req.getFormat().equals( "image/gif" ) ) { img = postprocessPng8bit( img ); } if ( originalSize ) { legendMap.put( req.getFormat(), img ); } return img; }
paintLegendText( origin, opts, text, textRenderer );
paintLegendText( origin, opts, text, textRenderer ); origin -= opts.baseHeight + 2 * opts.spacing;
private void writeStyles( final XMLStreamWriter writer, final String name, final Map<String, Style> legends, final Map<String, Style> styles ) throws XMLStreamException { if ( styleWriter != null ) { for ( final Entry<String, Style> e : styles.entrySet() ) { if ( e.getKey() == null || e.getKey().isEmpty() ) { continue; } Style ls = e.getValue(); if ( legends.get( e.getKey() ) != null ) { ls = legends.get( e.getKey() ); } final Pair<Integer, Integer> p = new Legends().getLegendSize( ls ); styleWriter.writeStyle( writer, e.getKey(), e.getKey(), p, name, e.getValue() ); } } }
private void writeStyles( final XMLStreamWriter writer, final String name, final Map<String, Style> legends, final Map<String, Style> styles ) throws XMLStreamException { if ( styleWriter != null ) { for ( final Entry<String, Style> e : styles.entrySet() ) { if ( e.getKey() == null || e.getKey().isEmpty() ) { continue; } Style ls = e.getValue(); if ( legends.get( e.getKey() ) != null ) { ls = legends.get( e.getKey() ); } final Pair<Integer, Integer> p = new Legends().getLegendSize( ls ); styleWriter.writeStyle( writer, e.getKey(), e.getKey(), p, name, e.getValue() ); } } }