changeset 141:8f30f7e802d6

Manage symbol names and symbol comparison.
author vc11884admin@VC11884.win.bsh.de
date Mon, 27 Jun 2011 16:07:13 +0200 (2011-06-27)
parents cd55975ba0c4
children f98d2759e494 6d294beb0e59
files ChangeLog src/java/de/intevation/mxd/writer/LineStyleWriter.java src/java/de/intevation/mxd/writer/MapScriptWriter.java src/java/de/intevation/mxd/writer/MarkerStyleWriter.java src/java/de/intevation/mxd/writer/SymbolWriter.java
diffstat 5 files changed, 75 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 23 16:59:29 2011 +0200
+++ b/ChangeLog	Mon Jun 27 16:07:13 2011 +0200
@@ -1,3 +1,16 @@
+2011-06-27  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Write symbol styles in reverse order to the mapfile.
+
+	* src/java/de/intevation/mxd/writer/LineStyleWriter.java,
+	  src/java/de/intevation/mxd/writer/MarkerStyleWriter.java:
+	  Create the symbol first, then set symbolname for style.
+
+	* src/java/de/intevation/mxd/writer/SymbolWriter.java:
+	  Test if symbol exists. If not exists, write new symbol with new
+	  name.
+
 2011-06-23  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/utils/MapToXMLUtils.java,
--- a/src/java/de/intevation/mxd/writer/LineStyleWriter.java	Thu Jun 23 16:59:29 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/LineStyleWriter.java	Mon Jun 27 16:07:13 2011 +0200
@@ -69,7 +69,13 @@
             style.setSize((int)Double.parseDouble(
                 symbolElement.getAttribute("size")));
         }
+        String type = symbolElement.getAttribute("type");
+        if(type.equals("marker")) {
+            SymbolWriter sw = new SymbolWriter(this.map, this.cl);
+            sw.write(symbolElement);
+        }
         String name = symbolElement.getAttribute("name");
+        style.setSymbolByName(map, name);
         symbolObj sym = symbolSet.getSymbolByName(name);
 
         //The following lines are for dashed and/or dotted lines.
@@ -136,13 +142,9 @@
             }
         }
 
-        String type = symbolElement.getAttribute("type");
 
-        if(type.equals("marker")) {
-            style.setSymbolByName(map, name);
-            SymbolWriter sw = new SymbolWriter(this.map, this.cl);
-            sw.write(symbolElement);
-        }
+
+
         return false;
     }
 }
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Thu Jun 23 16:59:29 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Jun 27 16:07:13 2011 +0200
@@ -265,7 +265,7 @@
             }
             //Write symbols and styles.
             NodeList l = classElement.getChildNodes();
-            for (int j = 0; j < l.getLength(); j++) {
+            for (int j = l.getLength() - 1; j >= 0; j--) {
                 Element elem = (Element)l.item(j);
 
                 String type = layerElement.getAttribute("type");
--- a/src/java/de/intevation/mxd/writer/MarkerStyleWriter.java	Thu Jun 23 16:59:29 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MarkerStyleWriter.java	Mon Jun 27 16:07:13 2011 +0200
@@ -72,10 +72,6 @@
             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") ||
@@ -86,6 +82,10 @@
         else {
             return false;
         }
+        String name = symbolElement.getAttribute("name");
+        style.setSymbolByName(map, name);
+
+
         return true;
     }
 }
--- a/src/java/de/intevation/mxd/writer/SymbolWriter.java	Thu Jun 23 16:59:29 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/SymbolWriter.java	Mon Jun 27 16:07:13 2011 +0200
@@ -54,8 +54,19 @@
             writeArrow(sym, symbolElement);
         }
         else if (symType.equals("char")) {
-            //TODO Does not work at all...  waiting for fix.
-            writeCharacter(sym, symbolElement);
+            int exists = symbolExists(symbolElement);
+            if(exists == -1) {
+                String old = symbolElement.getAttribute("name");
+                symbolElement.setAttribute(
+                    "name",
+                    old + symbolSet.getNumsymbols() + 1);
+                writeCharacter(sym, symbolElement);
+            }
+            else {
+                symbolElement.setAttribute(
+                    "name",
+                    symbolSet.getSymbol(exists).getName());
+            }
         }
         else if (type.equals("line")) {
             writeHatch(sym);
@@ -106,6 +117,7 @@
         String font = symbolElement.getAttribute("font");
         //Remove all blank character to match the mapserver fonts.txt.
         font = font.replaceAll(" ", "");
+        symbol.setName(symbolElement.getAttribute("name"));
         symbol.setFont(font);
         symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue());
         symbol.setAntialias(1);
@@ -140,5 +152,40 @@
         }
         symbols.save(path);
     }
+
+    private int symbolExists (Element elem) {
+        symbolSetObj symbolSet = map.getSymbolset();
+        for (int i = 0; i < symbolSet.getNumsymbols(); i++) {
+            symbolObj sym = symbolSet.getSymbol(i);
+            int stype = sym.getType();
+            String etype = elem.getAttribute("style");
+            if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue () &&
+                etype.equals("point")) {
+                return i;   
+            }
+            else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue () &&
+                    etype.equals("arrow")) {
+                return i;        
+            }
+            else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue () &&
+                    etype.equals("char")) {
+                String font = elem.getAttribute("font");
+                font = font.replaceAll(" ", "");
+                String c = elem.getAttribute("char");
+                c = "&#" + c + ";";
+                if (font.equals(sym.getFont()) &&
+                    c.equals(sym.getCharacter())) {
+                    return i;
+                }
+
+            }
+            else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue () &&
+                    etype.equals("hatch")) {
+                return i;        
+            }
+
+        }
+        return -1;
+    }
 }
 // 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)