comparison src/java/de/intevation/mxd/writer/LabelStyleWriter.java @ 317:5a2b5bc066eb

Implement Label Styles and Labels with background
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 20 Sep 2012 12:55:21 +0200
parents
children b6c0fbae16dc
comparison
equal deleted inserted replaced
316:5e3a40a84539 317:5a2b5bc066eb
1 /*
2 * Copyright (c) 2012 by Intevation GmbH, Germany <info@intevation.de>
3 *
4 * This file is part of MXD2map.
5 *
6 * This program is free software under the LGPL (>=v2.1)
7 * Read the file LICENCE.txt coming with the software for details
8 * or visit http://www.gnu.org/licenses/ if it does not exist.
9 *
10 * MXD2map has been developed on behalf of the
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
12 * by Intevation GmbH.
13 *
14 * Authors:
15 * Raimund Renkert <raimund.renkert@intevation.de>
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
17 * Stephan Holl <stephan.holl@intevation.de>
18 */
19
20 package de.intevation.mxd.writer;
21
22 import java.awt.Color;
23
24 import org.apache.log4j.Logger;
25
26 import org.w3c.dom.Element;
27
28 import edu.umn.gis.mapscript.mapObj;
29 import edu.umn.gis.mapscript.classObj;
30 import edu.umn.gis.mapscript.styleObj;
31 import edu.umn.gis.mapscript.colorObj;
32 import edu.umn.gis.mapscript.labelObj;
33 import edu.umn.gis.mapscript.symbolSetObj;
34
35
36 /**
37 * The interface to the mapfile writer.
38 *
39 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a>
40 */
41 public class LabelStyleWriter {
42
43 /**
44 * The Logger.
45 */
46 private static final Logger logger = Logger.getLogger(LabelStyleWriter.class);
47
48 /**
49 * Private member.
50 */
51 private mapObj map;
52 private classObj cl;
53 private styleObj style;
54
55 /**
56 * Contructor with map object and class object.
57 *
58 * @param map The map object.
59 * @param cl The class object containing the style.
60 */
61 public LabelStyleWriter(mapObj map, classObj cl) {
62 this.map = map;
63 this.cl = cl;
64 this.style = new styleObj(cl);
65 }
66
67 /**
68 * Write the content.
69 *
70 * @param symbolElement DOM element containing style attributes.
71 */
72 public boolean write(Element symbolElement) {
73 logger.debug("write(Element)");
74
75 style.setGeomTransform("labelpoly");
76 cl.getLabel().insertStyle(style, -1);
77
78 symbolSetObj symbolSet = map.getSymbolset();
79
80 if (symbolElement.hasAttribute("angle")) {
81 try {
82 style.setAngle(
83 Double.parseDouble(symbolElement.getAttribute("angle")));
84 }
85 catch(NumberFormatException nfe) {
86 logger.warn("Error setting angle.");
87 style.setAngle(0.0);
88 }
89 }
90 if(symbolElement.hasAttribute("angleBinding")) {
91 style.setBinding(2,
92 symbolElement.getAttribute("angleBinding"));
93 }
94 if (symbolElement.hasAttribute("bg_color")) {
95 // Background color takes precedence over the color as
96 // background color can be archived by geomtransform
97 String c = symbolElement.getAttribute("bg_color");
98 Color col = Color.decode(c);
99 colorObj color = new colorObj(
100 col.getRed(),
101 col.getGreen(),
102 col.getBlue(),
103 -4);
104 style.setColor(color);
105 } else if(symbolElement.hasAttribute("color")) {
106 String c = symbolElement.getAttribute("color");
107 Color col = Color.decode(c);
108 colorObj color = new colorObj(
109 col.getRed(),
110 col.getGreen(),
111 col.getBlue(),
112 -4);
113 style.setColor(color);
114 }
115 if (symbolElement.hasAttribute ("size")) {
116 try {
117 style.setSize(Double.parseDouble(
118 symbolElement.getAttribute("size")));
119 }
120 catch(NumberFormatException nfe) {
121 logger.warn("Error setting size. Setting to deafult: 1.");
122 style.setSize(1);
123 }
124 }
125 if(symbolElement.hasAttribute("outline_color")) {
126 Color oCol = Color.decode(
127 symbolElement.getAttribute("outline_color"));
128 colorObj outlineColor = new colorObj(
129 oCol.getRed(),
130 oCol.getGreen(),
131 oCol.getBlue(),
132 -4);
133 style.setOutlinecolor(outlineColor);
134 try {
135 style.setOutlinewidth(Double.parseDouble(
136 symbolElement.getAttribute("outline_size")));
137 }
138 catch(NumberFormatException nfe) {
139 logger.warn("Error setting outline width.");
140 }
141 }
142
143 if (symbolElement.hasAttribute("x_offset")) {
144 try {
145 double val =
146 Double.parseDouble(symbolElement.getAttribute("x_offset"));
147 double r = Math.round(val);
148 style.setOffsetx(r);
149 }
150 catch (NumberFormatException nfe) {
151 logger.warn("Error setting the symbol x-offset");
152 }
153 }
154 if (symbolElement.hasAttribute("y_offset")) {
155 try {
156 double val =
157 Double.parseDouble(symbolElement.getAttribute("y_offset"));
158 double r = Math.round(val);
159 //In ArcGIS positive y offset values move the symbol upwards,
160 //in Mapserver positive values move downwards.
161 r = -r;
162 style.setOffsety(r);
163 }
164 catch (NumberFormatException nfe) {
165 logger.warn("Error setting the symbol y-offset.");
166 }
167 }
168 String symType = symbolElement.getAttribute("style");
169 if(symType.equals("point") ||
170 symType.equals("arrow") ||
171 symType.equals("char") ||
172 symType.equals("picture")) {
173 SymbolWriter sw = new SymbolWriter(this.map, this.cl);
174 sw.write(symbolElement);
175 }
176 else {
177 return false;
178 }
179
180 String name = symbolElement.getAttribute("name");
181 style.setSymbolByName(map, name);
182
183 return true;
184 }
185 }
186 // 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)