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; }
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() ); } } }
Legends legends = new Legends(); Pair<Integer, Integer> legendSize = legends.getLegendSize( parsedStyle ); BufferedImage img = new BufferedImage( legendSize.first, legendSize.second, BufferedImage.TYPE_INT_ARGB );
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 ); }