Package org.geomajas.plugin.rasterizing.legend

Examples of org.geomajas.plugin.rasterizing.legend.LegendBuilder


  @Autowired
  private TextService textService;

  @SuppressWarnings("unchecked")
  public RenderedImage paintLegend(MapContext mapContext) {
    LegendBuilder builder = new LegendBuilder();
    MapRasterizingInfo mapRasterizingInfo = (MapRasterizingInfo) mapContext.getUserData().get(
        LayerFactory.USERDATA_RASTERIZING_INFO);
    LegendRasterizingInfo legendRasterizingInfo = mapRasterizingInfo.getLegendRasterizingInfo();
    Font font = textService.getFont(legendRasterizingInfo.getFont());
    builder.setTitle(legendRasterizingInfo.getTitle(), font);
    if (legendRasterizingInfo.getWidth() > 0) {
      builder.setSize(legendRasterizingInfo.getWidth(), legendRasterizingInfo.getHeight());
    }
    for (Layer layer : mapContext.layers()) {
      if (layer instanceof RasterDirectLayer) {
        RasterDirectLayer rasterLayer = (RasterDirectLayer) layer;
        builder.addRasterLayer(rasterLayer.getTitle(), font);
      } else if (layer instanceof FeatureLayer) {
        FeatureLayer featureLayer = (FeatureLayer) layer;
        List<Rule> rules = (List<Rule>) featureLayer.getUserData().get(LayerFactory.USERDATA_KEY_STYLE_RULES);
        for (Rule rule : rules) {
          if (!isTextOnly(rule)) {
            FeatureSource<?, ?> source = featureLayer.getFeatureSource();
            FeatureType schema = source.getSchema();
            if (schema instanceof SimpleFeatureType) {
              builder.addVectorLayer((SimpleFeatureType) schema, rule.getDescription().getTitle()
                  .toString(), rule, font);
            }
          }
        }
      } else if (layer instanceof GeometryDirectLayer) {
        GeometryDirectLayer geometryLayer = (GeometryDirectLayer) layer;
        builder.addVectorLayer(null, geometryLayer.getTitle(), geometryLayer.getStyle().featureTypeStyles()
            .get(0).rules().get(0), font);
      }
    }
    JComponent c = builder.buildComponent();
    BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D graphics = image.createGraphics();
    RenderingHints renderingHints = new Hints();
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHints(renderingHints);
View Full Code Here

TOP

Related Classes of org.geomajas.plugin.rasterizing.legend.LegendBuilder

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.