Package org.geoserver.wms.legendgraphic

Examples of org.geoserver.wms.legendgraphic.BufferedImageLegendGraphicBuilder


            Rule[] applicableRules = LegendUtils.getApplicableRules(layer.getStyle().featureTypeStyles().toArray(new FeatureTypeStyle[0]), scaleDenominator);
            if ((!layers.isEmpty() && !layers.contains(layer.getTitle())) || applicableRules.length == 0) {
                continue;
            }

            BufferedImageLegendGraphicBuilder legendGraphicBuilder = new BufferedImageLegendGraphicBuilder();
            GetLegendGraphicRequest request = new GetLegendGraphicRequest();
            request.setLayer(layer.getFeatureSource().getSchema());
            request.setTransparent(true);
            request.setScale(scaleDenominator);
            request.setStyle(layer.getStyle());

            Map legendOptions = new CaseInsensitiveMap(options);
            legendOptions.putAll(mapContext.getRequest().getFormatOptions());
            request.setLegendOptions(legendOptions);

            LayerLegend legend = new LayerLegend();
            legend.request = request;

            String title = findTitle(layer, wms.getGeoServer().getCatalog());
            if (title != null) {
                Font newFont = LegendUtils.getLabelFont(request);
                newFont = newFont.deriveFont(Font.BOLD);
                newFont = newFont.deriveFont((float) newFont.getSize() + 2);

                Font oldFont = g2d.getFont();
                g2d.setFont(newFont);
                if (LegendUtils.isFontAntiAliasing(legend.request)) {
                    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                } else {
                    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                            RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
                }

                BufferedImage titleImage = LegendUtils.renderLabel(title, g2d, request);
                g2d.setFont(oldFont);

                legend.title = titleImage;
            }

            BufferedImage legendImage = legendGraphicBuilder.buildLegendGraphic(request);
            legend.legend = legendImage;

            layerLegends.add(legend);
        }
View Full Code Here


                                request.setStrict(false);
                                Map<String, String> legendOptions = new HashMap<String, String>();
                                legendOptions.put("forceLabels", "on");
                                legendOptions.put("fontAntiAliasing", "true");
                                request.setLegendOptions(legendOptions);
                                BufferedImageLegendGraphicBuilder builder = new BufferedImageLegendGraphicBuilder();
                                BufferedImage image = builder.buildLegendGraphic(request);

                                ByteArrayOutputStream bos = new ByteArrayOutputStream();

                                ImageIO.write(image, "PNG", bos);
                                return bos.toByteArray();
View Full Code Here

TOP

Related Classes of org.geoserver.wms.legendgraphic.BufferedImageLegendGraphicBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.