diff src/java/de/intevation/mxd/writer/MarkerStyleWriter.java @ 87:7d4cf2db43f1

Added new writer classes to be flexible in creating mapfiles.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 31 May 2011 17:54:43 +0200
parents
children 11d63bf00326
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/writer/MarkerStyleWriter.java	Tue May 31 17:54:43 2011 +0200
@@ -0,0 +1,93 @@
+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.symbolSetObj;
+
+
+/**
+ * The interface to the mapfile writer.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class MarkerStyleWriter {
+
+    /**
+     * The Logger.
+     */
+    private static final Logger logger = Logger.getLogger(MarkerStyleWriter.class);
+
+    private mapObj map;
+    private classObj cl;
+    private styleObj style;
+
+    public MarkerStyleWriter (mapObj map, classObj cl) {
+        this.map = map;
+        this.cl = cl;
+        this.style = new styleObj(cl);
+    }
+
+    /**
+     * Write the content.
+     */
+    public boolean write(Element symbolElement)
+    throws Exception {
+        logger.debug("write(Element)");
+        symbolSetObj symbolSet = map.getSymbolset();
+
+        if (symbolElement.hasAttribute("angle")) {
+            style.setAngle(
+                Double.parseDouble(symbolElement.getAttribute("angle")));
+        }
+        if(symbolElement.hasAttribute("color")) {
+            String c = symbolElement.getAttribute("color");
+            Color col = Color.decode(c);
+            colorObj color = new colorObj(
+                col.getRed(),
+                col.getGreen(),
+                col.getBlue(),
+                -4);
+            style.setColor(color);
+        }
+        if (symbolElement.hasAttribute ("size")) {
+            style.setSize(Double.parseDouble(
+                symbolElement.getAttribute("size")));
+        }
+        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);
+            style.setOutlinewidth(Double.parseDouble(
+                symbolElement.getAttribute("outline_size")));
+        }
+
+        String name = symbolElement.getAttribute("name");
+        style.setSymbolByName(map, name);
+
+        String symType = symbolElement.getAttribute("style");
+        if(symType.equals("point") ||
+           symType.equals("arrow") ||
+           symType.equals("char")) {
+           SymbolWriter sw = new SymbolWriter(this.map, this.cl);
+           sw.write(symbolElement);
+        }
+        else {
+            return false;
+        }
+        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)