diff flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 4577:1c6c2ddac3d6

Work on dynamic color classes for floodmap (work in progress, not yet functional).
author Christian Lins <christian.lins@intevation.de>
date Tue, 27 Nov 2012 15:51:28 +0100
parents b87073a05f9d
children 11545c3b9111
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Tue Nov 27 14:20:46 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Tue Nov 27 15:51:28 2012 +0100
@@ -117,6 +117,15 @@
     public final static String XPATH_WSPLGEN_FIELDS =
             "/theme[@name='WSPLGEN']/field";
 
+    public final static String XPATH_WSPLGEN_STARTCOLOR =
+            "/theme/field[@name='startcolor'/@default";
+
+    public final static String XPATH_WSPLGEN_ENDCOLOR =
+            "/theme/field[@name='endcolor'/@default";
+
+    public final static String XPATH_WSPLGEN_NUMCLASSES =
+            "/theme/field[@name='numclasses'/@default";
+
     /** XPATH to bandwidth field. */
     public final static String XPATH_BANDWIDTH =
             "/theme/field[@name='bandwidth']/@default";
@@ -619,6 +628,45 @@
 
 
     public static String createWSPLGENStyle(Document theme) {
+        MapserverStyle ms = new MapserverStyle();
+
+        Color startColor = parseColor(
+                XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null));
+        Color endColor = parseColor(
+                XMLUtils.xpathString(theme, XPATH_WSPLGEN_ENDCOLOR, null));
+        int numClasses = Integer.parseInt(
+                XMLUtils.xpathString(theme, XPATH_WSPLGEN_NUMCLASSES, null));
+
+        if (numClasses < 5) {
+            numClasses = 5;
+        }
+        else if (numClasses > 20) {
+            numClasses = 20;
+        }
+
+        int rd = (startColor.getRed()   - endColor.getRed())   / numClasses;
+        int gd = (startColor.getGreen() - endColor.getGreen()) / numClasses;
+        int bd = (startColor.getBlue()  - endColor.getBlue())  / numClasses;
+
+        for (int n = 0; n < numClasses; n++) {
+            StringBuilder newColor = new StringBuilder();
+            newColor.append(startColor.getRed()   + n * rd);
+            newColor.append(' ');
+            newColor.append(startColor.getGreen() + n * gd);
+            newColor.append(' ');
+            newColor.append(startColor.getBlue()  + n * bd);
+
+            Clazz c = new Clazz("Klasse " + n + " (FIXME)");
+            Style s = new Style();
+            s.setColor(newColor.toString());
+            s.setSize(5);
+
+            c.addItem(new Expression("Klasse " + n));
+            c.addItem(s);
+
+            ms.addClazz(c);
+        }
+
         NodeList categories = (NodeList) XMLUtils.xpath(
                 theme,
                 XPATH_WSPLGEN_FIELDS,

http://dive4elements.wald.intevation.org