comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 62:e468cf8701ea

Prepared the converter to handle and write line symbols.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 24 May 2011 14:16:25 +0200
parents ef1ee8e752b2
children 7d4cf2db43f1
comparison
equal deleted inserted replaced
61:e00deee347a5 62:e468cf8701ea
171 171
172 //The layer type. 172 //The layer type.
173 String type = layerElement.getAttribute("type"); 173 String type = layerElement.getAttribute("type");
174 if(type.equals("point")) { 174 if(type.equals("point")) {
175 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT); 175 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
176 }
177 else if (type.equals("line")) {
178 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
176 } 179 }
177 180
178 //The layer datasource. 181 //The layer datasource.
179 layer.setData(layerElement.getAttribute("data_source")); 182 layer.setData(layerElement.getAttribute("data_source"));
180 183
228 NodeList list = classElement.getElementsByTagName("symbol"); 231 NodeList list = classElement.getElementsByTagName("symbol");
229 232
230 //Get the symbol set from the map object. 233 //Get the symbol set from the map object.
231 symbolSetObj symbolSet = map.getSymbolset(); 234 symbolSetObj symbolSet = map.getSymbolset();
232 235
233 //
234 for(int i = 0; i < list.getLength(); i++){ 236 for(int i = 0; i < list.getLength(); i++){
235 Element symbolElement = (Element) list.item(i); 237 Element symbolElement = (Element) list.item(i);
236 styleObj style = new styleObj(co); 238 styleObj style = new styleObj(co);
237 style.setAngle( 239 if (symbolElement.hasAttribute("angle")) {
238 Double.parseDouble(symbolElement.getAttribute("angle"))); 240 style.setAngle(
241 Double.parseDouble(symbolElement.getAttribute("angle")));
242 }
239 if(symbolElement.hasAttribute("color")) { 243 if(symbolElement.hasAttribute("color")) {
240 String c = symbolElement.getAttribute("color"); 244 String c = symbolElement.getAttribute("color");
241 Color col = Color.decode(c); 245 Color col = Color.decode(c);
242 colorObj color = new colorObj( 246 colorObj color = new colorObj(
243 col.getRed(), 247 col.getRed(),
244 col.getGreen(), 248 col.getGreen(),
245 col.getBlue(), 249 col.getBlue(),
246 -4); 250 -4);
247 style.setColor(color); 251 style.setColor(color);
248 } 252 }
249 style.setSize(Double.parseDouble( 253 if (symbolElement.hasAttribute ("size")) {
250 symbolElement.getAttribute("size"))); 254 style.setSize(Double.parseDouble(
255 symbolElement.getAttribute("size")));
256 }
251 if(symbolElement.hasAttribute("outline_color")) { 257 if(symbolElement.hasAttribute("outline_color")) {
252 Color oCol = Color.decode( 258 Color oCol = Color.decode(
253 symbolElement.getAttribute("outline_color")); 259 symbolElement.getAttribute("outline_color"));
254 colorObj outlineColor = new colorObj( 260 colorObj outlineColor = new colorObj(
255 oCol.getRed(), 261 oCol.getRed(),
258 -4); 264 -4);
259 style.setOutlinecolor(outlineColor); 265 style.setOutlinecolor(outlineColor);
260 style.setOutlinewidth(Double.parseDouble( 266 style.setOutlinewidth(Double.parseDouble(
261 symbolElement.getAttribute("outline_size"))); 267 symbolElement.getAttribute("outline_size")));
262 } 268 }
269 //Section for line symbols
270 //Setting the width
271 if(symbolElement.hasAttribute("width")) {
272 style.setWidth((int)Double.parseDouble(
273 symbolElement.getAttribute("width")));
274 }
263 String name = symbolElement.getAttribute("name"); 275 String name = symbolElement.getAttribute("name");
264 style.setSymbolByName(map, name); 276 style.setSymbolByName(map, name);
265 symbolObj sym = symbolSet.getSymbolByName(name); 277 symbolObj sym = symbolSet.getSymbolByName(name);
266 278
279 //The following lines are for dashed and/or dotted lines.
280 //These lines throw an "incorrect array size" error.
281 //TODO Find out how to set the pattern correctly.
282 // style.setPatternlength(2);
283 // double[] vals = new double[] {1.0, 2.0, 3.0};
284 // vals[0] = 1.0;
285 // vals[1] = 2.0;
286 // vals[2] = 3.0;
287 // vals[3] = 4.0;
288 // style.setPattern(vals);
267 String symType = symbolElement.getAttribute("style"); 289 String symType = symbolElement.getAttribute("style");
268 if(symType.equals("point")) { 290 if(symType.equals("point")) {
269 writePointSymbol(sym, symbolElement); 291 writePointSymbol(sym, symbolElement);
270 } 292 }
271 else if (symType.equals("arrow")) { 293 else if (symType.equals("arrow")) {
272 writeArrowSymbol(sym, symbolElement); 294 writeArrowSymbol(sym, symbolElement);
273 } 295 }
274 else if (symType.equals("char")) { 296 else if (symType.equals("char")) {
275 writeCharSymbol(sym, symbolElement); 297 writeCharSymbol(sym, symbolElement);
298 }
299 else if(symType.equals("line")) {
300 writeSimpleLineSymbol(sym, symbolElement);
276 } 301 }
277 } 302 }
278 saveSymbolSet(symbolSet); 303 saveSymbolSet(symbolSet);
279 } 304 }
280 305
326 symbol.setAntialias(1); 351 symbol.setAntialias(1);
327 symbol.setCharacter("#&" + symbolElement.getAttribute("char") + ";"); 352 symbol.setCharacter("#&" + symbolElement.getAttribute("char") + ";");
328 } 353 }
329 354
330 355
356 private void writeSimpleLineSymbol(
357 symbolObj symbol,
358 Element symbolElement) {
359 logger.debug("writeSimpleLineSymbol()");
360 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_SIMPLE.swigValue());
361 String ls = symbolElement.getAttribute("linestyle");
362 if(ls.equals("solid")) {
363 symbol.setFilled(1);
364 }
365 }
366
367
331 /** 368 /**
332 * Save the symbol set. 369 * Save the symbol set.
333 * @param symbols The symbol set. 370 * @param symbols The symbol set.
334 */ 371 */
335 private void saveSymbolSet(symbolSetObj symbols) { 372 private void saveSymbolSet(symbolSetObj symbols) {
336 Element fileNode = (Element)XMLUtils.xpath( 373 Element fileNode = (Element)XMLUtils.xpath(
337 root, 374 root,
338 "/mxd/file", 375 "/mxd/file",
339 XPathConstants.NODE); 376 XPathConstants.NODE);
340 String mapFilename = fileNode.getAttribute("name");
341 String path = ""; 377 String path = "";
342 if(mapFilename.contains("/")) { 378 if(mapFilename.contains("/")) {
343 path = mapFilename.substring(0, mapFilename.lastIndexOf("/")); 379 path = mapFilename.substring(0, mapFilename.lastIndexOf("/"));
344 } 380 }
345 else if(mapFilename.contains("\\")) { 381 else if(mapFilename.contains("\\")) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)