comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 88:df2eb0e7d229

Removed obsolete code.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 31 May 2011 18:31:00 +0200
parents 7d4cf2db43f1
children 82a1f39214fd
comparison
equal deleted inserted replaced
87:7d4cf2db43f1 88:df2eb0e7d229
238 } 238 }
239 symbolSetObj symbolSet = map.getSymbolset(); 239 symbolSetObj symbolSet = map.getSymbolset();
240 saveSymbolSet(symbolSet); 240 saveSymbolSet(symbolSet);
241 } 241 }
242 } 242 }
243
244 /**
245 * Adds the symbols and styles to the mapfile.
246 * @param co Mapscript class object.
247 * @param classElement Dom element containing the style and symbol
248 * attributes.
249 */
250 private void writeSymbol(classObj co, Element classElement) {
251 //Get all symbol elements from dom.
252 NodeList list = classElement.getElementsByTagName("symbol");
253
254 //Get the symbol set from the map object.
255 symbolSetObj symbolSet = map.getSymbolset();
256
257 for(int i = 0; i < list.getLength(); i++){
258 Element symbolElement = (Element) list.item(i);
259 styleObj style = new styleObj(co);
260 if (symbolElement.hasAttribute("angle")) {
261 style.setAngle(
262 Double.parseDouble(symbolElement.getAttribute("angle")));
263 }
264 if(symbolElement.hasAttribute("color")) {
265 String c = symbolElement.getAttribute("color");
266 Color col = Color.decode(c);
267 colorObj color = new colorObj(
268 col.getRed(),
269 col.getGreen(),
270 col.getBlue(),
271 -4);
272 style.setColor(color);
273 }
274 if (symbolElement.hasAttribute ("size")) {
275 style.setSize(Double.parseDouble(
276 symbolElement.getAttribute("size")));
277 }
278 if(symbolElement.hasAttribute("outline_color")) {
279 Color oCol = Color.decode(
280 symbolElement.getAttribute("outline_color"));
281 colorObj outlineColor = new colorObj(
282 oCol.getRed(),
283 oCol.getGreen(),
284 oCol.getBlue(),
285 -4);
286 style.setOutlinecolor(outlineColor);
287 style.setOutlinewidth(Double.parseDouble(
288 symbolElement.getAttribute("outline_size")));
289 }
290 //Section for line symbols
291 //Setting the width
292 if(symbolElement.hasAttribute("width")) {
293 style.setWidth((int)Double.parseDouble(
294 symbolElement.getAttribute("width")));
295 }
296 String name = symbolElement.getAttribute("name");
297 style.setSymbolByName(map, name);
298 symbolObj sym = symbolSet.getSymbolByName(name);
299
300 //The following lines are for dashed and/or dotted lines.
301 //These lines throw an "incorrect array size" error.
302 //TODO Find out how to set the pattern correctly.
303 // style.setPatternlength(2);
304 // double[] vals = new double[] {1.0, 2.0, 3.0};
305 // vals[0] = 1.0;
306 // vals[1] = 2.0;
307 // vals[2] = 3.0;
308 // vals[3] = 4.0;
309 // style.setPattern(vals);
310 String symType = symbolElement.getAttribute("style");
311 if(symType.equals("point")) {
312 writePointSymbol(sym, symbolElement);
313 }
314 else if (symType.equals("arrow")) {
315 writeArrowSymbol(sym, symbolElement);
316 }
317 else if (symType.equals("char")) {
318 writeCharSymbol(sym, symbolElement);
319 }
320 else if(symType.equals("line")) {
321 writeSimpleLineSymbol(sym, symbolElement);
322 }
323 }
324 saveSymbolSet(symbolSet);
325 }
326
327
328 /**
329 * Write point symbols to the map.
330 * @param symbol The symbol object.
331 * @param symbolElement The DOM object containing the attributes.
332 */
333 private void writePointSymbol(symbolObj symbol, Element symbolElement) {
334 lineObj points = new lineObj();
335 points.add(new pointObj(1,1,0));
336 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue());
337 symbol.setPoints(points);
338 symbol.setFilled(1);
339 }
340
341
342 /**
343 * Write arrow symbol to the map.
344 * @param symbol The symbol object.
345 * @param symbolElement The DOM object containig the attributes.
346 */
347 private void writeArrowSymbol(symbolObj symbol, Element symbolElement) {
348 double len = Double.parseDouble(symbolElement.getAttribute("length"));
349 double width = Double.parseDouble(symbolElement.getAttribute("width"));
350 double ratio = len/width;
351 lineObj points = new lineObj();
352
353 points.add(new pointObj(0, 0, 0));
354 points.add(new pointObj((1*ratio), 0.5, 0));
355 points.add(new pointObj(0, 1, 0));
356 points.add(new pointObj(0, 0, 0));
357 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue());
358 symbol.setPoints(points);
359 symbol.setFilled(1);
360 }
361
362
363 /**
364 * Write font symbols to the map.
365 * @param symbol The symbol object.
366 * @param symbolElement The DOM object containing the attributes.
367 */
368 private void writeCharSymbol(symbolObj symbol, Element symbolElement) {
369 //TODO Write the symbol correctly. See Issue 3885 on trac.osgeo.org
370 symbol.setFont(symbolElement.getAttribute("font"));
371 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue());
372 symbol.setAntialias(1);
373 symbol.setCharacter("#&" + symbolElement.getAttribute("char") + ";");
374 }
375
376
377 private void writeSimpleLineSymbol(
378 symbolObj symbol,
379 Element symbolElement) {
380 logger.debug("writeSimpleLineSymbol()");
381 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_SIMPLE.swigValue());
382 String ls = symbolElement.getAttribute("linestyle");
383 if(ls.equals("solid")) {
384 symbol.setFilled(1);
385 }
386 }
387
388
389 /**
390 * Save the symbol set.
391 * @param symbols The symbol set.
392 */
393 private void saveSymbolSet(symbolSetObj symbols) {
394 Element fileNode = (Element)XMLUtils.xpath(
395 root,
396 "/mxd/file",
397 XPathConstants.NODE);
398 String path = "";
399 if(mapFilename.contains("/")) {
400 path = mapFilename.substring(0, mapFilename.lastIndexOf("/"));
401 }
402 else if(mapFilename.contains("\\")) {
403 path = mapFilename.substring(0, mapFilename.lastIndexOf("\\"));
404 }
405 symbols.save(path + "/symbols.sym");
406 }
407 } 243 }
408 244
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)