view src/java/de/intevation/mxd/writer/LabelStyleWriter.java @ 323:4051c39757db

Bump Version to 1.1
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 12 Oct 2012 16:26:30 +0200
parents b6c0fbae16dc
children da60e3ac2b5d
line wrap: on
line source
/*
 * Copyright (c) 2012 by Intevation GmbH, Germany <info@intevation.de>
 *
 * This file is part of MXD2map.
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LICENCE.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 *
 * MXD2map has been developed on behalf of the
 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
 * by Intevation GmbH.
 *
 * Authors:
 * Raimund Renkert <raimund.renkert@intevation.de>
 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
 * Stephan Holl <stephan.holl@intevation.de>
 */

package de.intevation.mxd.writer;

import java.awt.Color;

import org.apache.log4j.Logger;

import org.w3c.dom.Element;

import edu.umn.gis.mapscript.mapObj;
import edu.umn.gis.mapscript.classObj;
import edu.umn.gis.mapscript.styleObj;
import edu.umn.gis.mapscript.colorObj;
import edu.umn.gis.mapscript.labelObj;
import edu.umn.gis.mapscript.symbolSetObj;


/**
 * The interface to the mapfile writer.
 *
 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a>
 */
public class LabelStyleWriter {

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

    /**
     * Private member.
     */
    private mapObj map;
    private classObj cl;
    private styleObj style;

    /**
     * Contructor with map object and class object.
     *
     * @param map The map object.
     * @param cl  The class object containing the style.
     */
    public LabelStyleWriter(mapObj map, classObj cl) {
        this.map = map;
        this.cl = cl;
        this.style = new styleObj(cl);
    }

    /**
     * Write the content.
     *
     * @param symbolElement DOM element containing style attributes.
     */
    public boolean write(Element symbolElement) {
        logger.debug("write(Element)");

        cl.getLabel().insertStyle(style, -1);

        symbolSetObj symbolSet = map.getSymbolset();

        if (symbolElement.hasAttribute("angle")) {
            try {
                style.setAngle(
                    Double.parseDouble(symbolElement.getAttribute("angle")));
            }
            catch(NumberFormatException nfe) {
                logger.warn("Error setting angle.");
                style.setAngle(0.0);
            }
        }
        if(symbolElement.hasAttribute("angleBinding")) {
            style.setBinding(2,
                    symbolElement.getAttribute("angleBinding"));
        }
        if (symbolElement.hasAttribute("bg_color")) {
            // Background color takes precedence over the color as
            // background color can be archived by geomtransform
            String c = symbolElement.getAttribute("bg_color");
            Color col = Color.decode(c);
            colorObj color = new colorObj(
                col.getRed(),
                col.getGreen(),
                col.getBlue(),
                -4);
            style.setColor(color);
            style.setGeomTransform("labelpoly");
        }
        if (symbolElement.hasAttribute ("size")) {
            try {
                style.setSize(Double.parseDouble(
                    symbolElement.getAttribute("size")));
            }
            catch(NumberFormatException nfe) {
                logger.warn("Error setting size. Setting to deafult: 1.");
                style.setSize(1);
            }
        }
        if(symbolElement.hasAttribute("outline_color")) {
            Color oCol = Color.decode(
                symbolElement.getAttribute("outline_color"));
            colorObj outlineColor = new colorObj(
                oCol.getRed(),
                oCol.getGreen(),
                oCol.getBlue(),
                -4);
            style.setOutlinecolor(outlineColor);
            try {
                style.setOutlinewidth(Double.parseDouble(
                    symbolElement.getAttribute("outline_size")));
            }
            catch(NumberFormatException nfe) {
                logger.warn("Error setting outline width.");
            }
        }

        if (symbolElement.hasAttribute("x_offset")) {
            try {
                double val = 
                    Double.parseDouble(symbolElement.getAttribute("x_offset"));
                double r = Math.round(val);
                style.setOffsetx(r);
            }
            catch (NumberFormatException nfe) {
                logger.warn("Error setting the symbol x-offset");
            }
        }
        if (symbolElement.hasAttribute("y_offset")) {
            try {
                double val =
                    Double.parseDouble(symbolElement.getAttribute("y_offset"));
                double r = Math.round(val);
                //In ArcGIS positive y offset values move the symbol upwards,
                //in Mapserver positive values move downwards.
                r = -r;
                style.setOffsety(r);
            }
            catch (NumberFormatException nfe) {
                logger.warn("Error setting the symbol y-offset.");
            }
        }
        String symType = symbolElement.getAttribute("style");
        if(symType.equals("point") ||
           symType.equals("arrow") ||
           symType.equals("char") ||
           symType.equals("picture")) {
           SymbolWriter sw = new SymbolWriter(this.map, this.cl);
           sw.write(symbolElement);
        }
        else {
            return false;
        }

        String name = symbolElement.getAttribute("name");
        style.setSymbolByName(map, name);

        return true;
    }
}
// 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)