Search in sources :

Example 36 with StyledLayer

use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.

the class RenderSymbol method getRenderStyle.

/**
 * Gets the render style.
 *
 * @param selectedSymbol the selected symbol
 * @return the render style
 */
public Style getRenderStyle(SelectedSymbol selectedSymbol) {
    List<StyledLayer> styledLayerList = selectedSymbol.getSld().layers();
    for (StyledLayer styledLayer : styledLayerList) {
        List<Style> styleList = null;
        if (styledLayer instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
            styleList = namedLayer.styles();
        } else if (styledLayer instanceof UserLayerImpl) {
            UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
            styleList = userLayer.userStyles();
        }
        if (styleList != null) {
            for (Style style : styleList) {
                FeatureTypeStyle ftsToRender = selectedSymbol.getFeatureTypeStyle();
                Rule ruleToRender = selectedSymbol.getRule();
                // Check to see if style contains the rule to render
                if (shouldRenderSymbol(style, ftsToRender, ruleToRender)) {
                    return renderSymbol(style, ftsToRender, ruleToRender, renderOptions);
                }
            }
        }
    }
    return null;
}
Also used : UserLayerImpl(org.geotools.styling.UserLayerImpl) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 37 with StyledLayer

use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.

the class MapRender method renderSymbol.

/**
 * Render symbol.
 *
 * @param mapContent the map content
 * @param styledLayer the styled layer
 * @param style the style
 */
private void renderSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) {
    for (Layer layer : mapContent.layers()) {
        mapContent.removeLayer(layer);
    }
    switch(geometryType) {
        case RASTER:
            {
                GridReaderLayer gridLayer = new GridReaderLayer(gridCoverage, (org.geotools.styling.Style) style);
                mapContent.addLayer(gridLayer);
                mapContent.getViewport().setBounds(gridLayer.getBounds());
                if (gridCoverage != null) {
                    mapPane.setDisplayArea(gridCoverage.getOriginalEnvelope());
                }
            }
            break;
        case POINT:
        case LINE:
        case POLYGON:
            {
                FeatureSource<SimpleFeatureType, SimpleFeature> tmpFeatureList = null;
                if (styledLayer instanceof UserLayer) {
                    if (userLayerFeatureListMap != null) {
                        tmpFeatureList = userLayerFeatureListMap.get(styledLayer);
                    }
                } else {
                    tmpFeatureList = featureList;
                }
                if (tmpFeatureList != null) {
                    mapContent.addLayer(new FeatureLayer(tmpFeatureList, (org.geotools.styling.Style) style));
                    try {
                        mapPane.setDisplayArea(tmpFeatureList.getBounds());
                    } catch (IOException e) {
                        ConsoleManager.getInstance().exception(this, e);
                    }
                }
            }
            break;
        default:
            break;
    }
    wmsEnvVarValues.setMapBounds(mapBounds);
    EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);
}
Also used : GridReaderLayer(org.geotools.map.GridReaderLayer) FeatureSource(org.geotools.data.FeatureSource) FeatureLayer(org.geotools.map.FeatureLayer) Style(org.opengis.style.Style) IOException(java.io.IOException) UserLayer(org.geotools.styling.UserLayer) GridReaderLayer(org.geotools.map.GridReaderLayer) FeatureLayer(org.geotools.map.FeatureLayer) Layer(org.geotools.map.Layer) UserLayer(org.geotools.styling.UserLayer) StyledLayer(org.geotools.styling.StyledLayer)

Example 38 with StyledLayer

use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.

the class MapRender method internalRenderStyle.

/**
 * Internal render style.
 */
private void internalRenderStyle() {
    if (!underTest) {
        if (hasError()) {
            mapPane.resetRenderer();
            mapPane.getRenderer().addRenderListener(this);
            resetError();
        }
        wmsEnvVarValues.setImageWidth(mapPane.getWidth());
        wmsEnvVarValues.setImageHeight(mapPane.getHeight());
        MapContent mapContent = mapPane.getMapContent();
        if (mapContent == null) {
            mapContent = new MapContent();
            mapPane.setMapContent(mapContent);
        }
        Map<Object, Object> hints = new HashMap<Object, Object>();
        clearLabelCache();
        hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
        mapPane.getRenderer().setRendererHints(hints);
        // Add the layers back with the updated style
        StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld();
        if (sld != null) {
            List<StyledLayer> styledLayerList = sld.layers();
            for (StyledLayer styledLayer : styledLayerList) {
                List<org.geotools.styling.Style> styleList = null;
                if (styledLayer instanceof NamedLayerImpl) {
                    NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                    styleList = namedLayerImpl.styles();
                } else if (styledLayer instanceof UserLayerImpl) {
                    UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                    styleList = userLayerImpl.userStyles();
                }
                if (styleList != null) {
                    for (Style style : styleList) {
                        renderSymbol(mapContent, styledLayer, style);
                    }
                }
            }
        }
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) UserLayerImpl(org.geotools.styling.UserLayerImpl) MapContent(org.geotools.map.MapContent) HashMap(java.util.HashMap) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.opengis.style.Style)

Example 39 with StyledLayer

use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.

the class LegendManager method createLegend.

/**
 * Creates the legend.
 *
 * @param sld the sld
 * @param heading the heading
 * @param filename the filename
 * @param separateSymbolizers the separate symbolizers
 * @return the map
 */
public Map<String, BufferedImage> createLegend(StyledLayerDescriptor sld, String heading, String filename, boolean separateSymbolizers) {
    Map<String, BufferedImage> imageMap = new HashMap<String, BufferedImage>();
    // 
    // Set legend options
    // 
    Map<String, Object> legendOptions = new HashMap<String, Object>();
    if (heading != null) {
        legendOptions.put("heading", heading);
    }
    if (filename != null) {
        legendOptions.put("filename", filename);
    }
    if (legendOptionData == null) {
        legendOptionData = new LegendOptionData();
    }
    GetLegendGraphicRequest request = new GetLegendGraphicRequest();
    request.setWidth(legendOptionData.getImageWidth());
    request.setHeight(legendOptionData.getImageHeight());
    request.setTransparent(legendOptionData.isTransparent());
    request.setStrict(false);
    legendOptions.put("bgColor", ColourUtils.fromColour(legendOptionData.getBackgroundColour()));
    legendOptions.put("fontColor", ColourUtils.fromColour(legendOptionData.getLabelFontColour()));
    // 
    // Label Font
    // 
    Font font = legendOptionData.getLabelFont();
    legendOptions.put("fontName", font.getFontName());
    String styleValue = null;
    if ((font.getStyle() & java.awt.Font.BOLD) == java.awt.Font.BOLD) {
        styleValue = "bold";
    }
    if ((font.getStyle() & java.awt.Font.ITALIC) == java.awt.Font.ITALIC) {
        styleValue = "italic";
    }
    if (styleValue != null) {
        legendOptions.put("fontStyle", styleValue);
    }
    legendOptions.put("fontSize", String.valueOf(font.getSize()));
    legendOptions.put("dpi", Integer.valueOf(legendOptionData.getDpi()));
    legendOptions.put("fontAntiAliasing", getBooleanValueOnOff(legendOptionData.isFontAntiAliasing()));
    legendOptions.put("forceLabels", getBooleanValueOnOff(legendOptionData.isShowLabels()));
    legendOptions.put("forceTitles", getBooleanValueOnOff(legendOptionData.isShowTitle()));
    legendOptions.put("bandInfo", getBooleanValueTrueFalse(legendOptionData.isBandInformation()));
    legendOptions.put("border", getBooleanValueTrueFalse(legendOptionData.isBorder()));
    legendOptions.put("borderColor", ColourUtils.fromColour(legendOptionData.getBorderColour()));
    legendOptions.put("imageSizeFactor", String.valueOf(legendOptionData.getImageSize() / 100.0));
    request.setLegendOptions(legendOptions);
    if (sld != null) {
        Map<String, Style> styleMap = new LinkedHashMap<String, Style>();
        StyledLayer selectedStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        Style selectedStyle = SelectedSymbol.getInstance().getStyle();
        if (selectedStyle != null) {
            createSingleStyleLegend(styleMap, selectedStyledLayer, selectedStyle);
        } else {
            createMultipleStyleLegend(sld, styleMap, selectedStyledLayer);
        }
        // Merge symbolizers into 1 image
        if (!separateSymbolizers) {
            for (String key : styleMap.keySet()) {
                Style style = styleMap.get(key);
                if (!style.featureTypeStyles().isEmpty()) {
                    FeatureTypeStyle featureTypeStyle = style.featureTypeStyles().get(0);
                    if (featureTypeStyle != null) {
                        if (!featureTypeStyle.rules().isEmpty()) {
                            LegendRequest legendEntryRequest = request.new LegendRequest();
                            request.getLegends().add(legendEntryRequest);
                            legendEntryRequest.setTitle(key);
                            legendEntryRequest.setStyle(style);
                        }
                    }
                }
            }
            BufferedImage legendGraphic = null;
            try {
                legendGraphic = legendBuilder.buildLegendGraphic(request);
            } catch (Exception e) {
            // Ignore
            }
            imageMap.put("", legendGraphic);
        } else {
            for (String key : styleMap.keySet()) {
                request.getLegends().clear();
                LegendRequest legendEntryRequest = request.new LegendRequest();
                legendEntryRequest.setStyle(styleMap.get(key));
                legendEntryRequest.setStyleName(key);
                request.getLegends().add(legendEntryRequest);
                BufferedImage legendGraphic = null;
                try {
                    legendGraphic = legendBuilder.buildLegendGraphic(request);
                } catch (Exception e) {
                // Ignore
                }
                imageMap.put(key, legendGraphic);
            }
        }
    }
    return imageMap;
}
Also used : GetLegendGraphicRequest(org.geoserver.wms.GetLegendGraphicRequest) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StyledLayer(org.geotools.styling.StyledLayer) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) LegendRequest(org.geoserver.wms.GetLegendGraphicRequest.LegendRequest)

Example 40 with StyledLayer

use of org.geotools.styling.StyledLayer in project sldeditor by robward-scisys.

the class LegendManager method createMultipleStyleLegend.

/**
 * Creates the legend for multiple SLD styles.
 *
 * @param sld the sld
 * @param styleMap the style map
 * @param selectedStyledLayer the selected styled layer
 */
private void createMultipleStyleLegend(StyledLayerDescriptor sld, Map<String, Style> styleMap, StyledLayer selectedStyledLayer) {
    List<StyledLayer> styledLayerList = null;
    if (selectedStyledLayer == null) {
        styledLayerList = sld.layers();
    } else {
        styledLayerList = new ArrayList<StyledLayer>();
        styledLayerList.add(selectedStyledLayer);
    }
    for (StyledLayer styledLayer : styledLayerList) {
        List<Style> styleList = null;
        if (styledLayer instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
            styleList = namedLayer.styles();
        } else if (styledLayer instanceof UserLayerImpl) {
            UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
            styleList = userLayer.userStyles();
        }
        if (styleList != null) {
            int count = 1;
            for (Style style : styleList) {
                String styleName;
                if (style.getName() != null) {
                    styleName = style.getName();
                } else {
                    styleName = String.format("Style %d", count);
                }
                styleMap.put(styleName, style);
                count++;
            }
        }
    }
}
Also used : UserLayerImpl(org.geotools.styling.UserLayerImpl) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Aggregations

StyledLayer (org.geotools.styling.StyledLayer)43 Style (org.geotools.styling.Style)28 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)25 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)22 Rule (org.geotools.styling.Rule)19 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)19 UserLayerImpl (org.geotools.styling.UserLayerImpl)16 Symbolizer (org.geotools.styling.Symbolizer)12 NamedLayer (org.geotools.styling.NamedLayer)10 Test (org.junit.Test)10 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)7 LineSymbolizer (org.geotools.styling.LineSymbolizer)6 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)5 IOException (java.io.IOException)4 FeatureTypeConstraint (org.geotools.styling.FeatureTypeConstraint)4 SLDData (com.sldeditor.common.data.SLDData)3 ArrayList (java.util.ArrayList)3 UserLayer (org.geotools.styling.UserLayer)3 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)2