Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 5655:53a2ceeae9a3
Create floodmap colorrange dynamically from artifact parameters. Theme setting for colorrange classes is currently not functioning (wasn't before either).
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Thu, 11 Apr 2013 11:25:41 +0200 |
parents | dc0d37715e16 |
children |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Thu Apr 11 10:55:41 2013 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Thu Apr 11 11:25:41 2013 +0200 @@ -660,22 +660,35 @@ * @param theme * @return String representation of the MapserverStyle */ - public static String createDynamicMapserverStyle(Document theme) { + public static String createDynamicMapserverStyle(Document theme, + float from, float to, float step) + { MapserverStyle ms = new MapserverStyle(); String strStartColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null); Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215); String strEndColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_ENDCOLOR, null); Color endColor = strEndColor != null? parseColor(strEndColor) : new Color(2, 27, 42); +/* String strNumClasses = XMLUtils.xpathString(theme, XPATH_WSPLGEN_NUMCLASSES, null); - int numClasses = strNumClasses != null ? Integer.parseInt(strNumClasses) : 5; + int numClasses; + if (strNumClasses != null) { + numClasses = Integer.parseInt(strNumClasses); + } + else { + numClasses = 5; + logger.warn("createDynamicMapserverStyle(): strNumClasses is null"); + } if (numClasses < 5) { numClasses = 5; } else if (numClasses > 20) { numClasses = 20; - } + }*/ + + + int numClasses = (int)((to - from) / step); float rd = (endColor.getRed() - startColor.getRed()) / (float)numClasses; float gd = (endColor.getGreen() - startColor.getGreen()) / (float)numClasses; @@ -689,7 +702,7 @@ newColor.append(' '); newColor.append(startColor.getBlue() + Math.round(n * bd)); - String expr = createWSPLGENExpression(n + 1, numClasses); + String expr = createWSPLGENExpression(from + n * step, step, n + 1, numClasses); Clazz c = new Clazz(expr); Style s = new Style(); @@ -706,13 +719,12 @@ } - protected static String createWSPLGENExpression(int idx, int maxIdx) { + protected static String createWSPLGENExpression(float val, float step, int idx, int maxIdx) { if (idx < maxIdx) { - int lower = idx - 1; - return "[DIFF] >= " + lower + " AND [DIFF] < " + idx; + return "[DIFF] >= " + val + " AND [DIFF] < " + (val + step); } else { - return "[DIFF] >= " + (maxIdx - 1); + return "[DIFF] >= " + val; } }