Search in sources :

Example 1 with EsriLabelRendererInterface

use of com.sldeditor.exportdata.esri.label.EsriLabelRendererInterface in project sldeditor by robward-scisys.

the class MXDParser method processLabelRenderer.

/**
 * Gets the label renderer.
 *
 * @param sld the sld
 * @param labelRenderArrayElement the label render array element
 * @param transparency the transparency
 */
private void processLabelRenderer(StyledLayerDescriptor sld, JsonArray labelRenderArrayElement, int transparency) {
    if (sld != null) {
        if (labelRenderArrayElement != null) {
            List<StyledLayer> styledLayers = sld.layers();
            if (!styledLayers.isEmpty()) {
                if (styledLayers.get(0) instanceof NamedLayer) {
                    NamedLayer namedLayer = (NamedLayer) styledLayers.get(0);
                    List<Style> styleList = namedLayer.styles();
                    if (!styleList.isEmpty()) {
                        List<FeatureTypeStyle> ftsList = styleList.get(0).featureTypeStyles();
                        if (!ftsList.isEmpty()) {
                            List<Rule> ruleList = ftsList.get(0).rules();
                            List<Rule> newLabelRuleList = new ArrayList<Rule>();
                            for (int index = 0; index < labelRenderArrayElement.size(); index++) {
                                JsonElement labelRenderElement = labelRenderArrayElement.get(index);
                                JsonObject renderer = labelRenderElement.getAsJsonObject();
                                boolean found = false;
                                for (String labelRendererType : labelRendererMap.keySet()) {
                                    JsonElement obj = renderer.get(labelRendererType);
                                    if (obj != null) {
                                        EsriLabelRendererInterface esriLabelRenderer = labelRendererMap.get(labelRendererType);
                                        if (esriLabelRenderer != null) {
                                            for (Rule rule : ruleList) {
                                                esriLabelRenderer.convert(newLabelRuleList, rule, obj, transparency);
                                            }
                                        }
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found) {
                                    ConsoleManager.getInstance().error(this, "Unsupported label renderer : " + SymbolUtils.extractName(labelRenderElement));
                                }
                            }
                            ruleList.addAll(newLabelRuleList);
                        }
                    }
                }
            }
        }
    }
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) EsriLabelRendererInterface(com.sldeditor.exportdata.esri.label.EsriLabelRendererInterface) JsonElement(com.google.gson.JsonElement) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Aggregations

JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 EsriLabelRendererInterface (com.sldeditor.exportdata.esri.label.EsriLabelRendererInterface)1 ArrayList (java.util.ArrayList)1 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)1 NamedLayer (org.geotools.styling.NamedLayer)1 Rule (org.geotools.styling.Rule)1 Style (org.geotools.styling.Style)1 StyledLayer (org.geotools.styling.StyledLayer)1