view src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java @ 41:60ed2164035a

Introduced MapScript writer.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 14 Apr 2011 11:31:29 +0200
parents c51376f8e24c
children 9b5fb5e5914d
line wrap: on
line source
package de.intevation.mxd.reader;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.esri.arcgis.carto.IFeatureRenderer;
import com.esri.arcgis.display.ISymbol;
import com.esri.arcgis.carto.UniqueValueRenderer;

import org.w3c.dom.Element;

import de.intevation.mxd.utils.MapToXMLUtils;

/**
 * Reads unique vaule renderer information.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class UniqueValueRendererReader
implements IRendererReader {

    /**
     * The logger.
     */
    private static final Logger logger =
        Logger.getLogger(FeatureLayerReader.class);

    /**
     * Private Member.
     */
    private UniqueValueRenderer renderer;
    private Element layer;
    private MapToXMLUtils util;


    public UniqueValueRendererReader(IFeatureRenderer renderer)
    throws Exception {
        logger.debug("constructor()");
        if (renderer instanceof UniqueValueRenderer) {
            this.renderer = (UniqueValueRenderer)renderer;
        }
        else {
            throw new Exception ("Not an instance of UniqueValueRenderer.");
        }
    }

    /**
     * Setter for the parent XML element.
     *
     * @param parent The XML parent node.
     */
    public void setParent(Element parent) {
        this.layer = parent;
    }

    /**
     * Setter for XML document helper.
     *
     * @param util The helper class for storing map information.
     */
    public void setUtil(MapToXMLUtils util) {
        this.util = util;
    }

    /**
     * Reads the renderer attributes.
     *
     * @return The parent XML node.
     */
    public Element read()
    throws IOException {
        logger.debug("read()");
        for(int i = 0; i < renderer.getClassCount() - 1; i++) {
            Element rendererElement;
            try {
                rendererElement = util.addRenderer(layer);
            }
            catch(Exception e) {
                e.printStackTrace();
                return null;
            }
            String value = renderer.getValue(i);
            rendererElement.setAttribute("name", renderer.esri_getClass(i));
            rendererElement.setAttribute("description",
                renderer.getDescription(value));
            rendererElement.setAttribute("value", value);
            rendererElement.setAttribute("label", renderer.getLabel(value));

            ISymbol symbol = renderer.getSymbol(value);
            ISymbolReader symbolReader;
            try {
                 symbolReader = new SimpleMarkerSymbolReader(symbol);
            }
            catch(Exception e) {
                e.printStackTrace();
                return null;
            }
            symbolReader.setUtil(util);
            symbolReader.setParent(rendererElement);
            symbolReader.read ();

        }
        return layer;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)