Mercurial > dive4elements > river
changeset 1793:1636686070f7
Initial commit to support styles in maps.
flys-artifacts/trunk@3116 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 28 Oct 2011 14:42:24 +0000 |
parents | 49ad801076e4 |
children | 2ad7ba85a2b3 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LayerInfo.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java |
diffstat | 7 files changed, 147 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Oct 28 13:48:02 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Oct 28 14:42:24 2011 +0000 @@ -1,3 +1,27 @@ +2011-10-28 Ingo Weinzierl <ingo@intevation.de> + + * doc/conf/themes.xml: Added a default theme for the riveraxis used in the + floodmap. + + * src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java: + New. This class is used by ThemeUtil to create a style which is + compatible for Mapserver- + + * src/main/java/de/intevation/flys/utils/ThemeUtil.java: Added a method to + retrieve a Mapserver compatible style (as string) based on a given + Document (that comes from CollectionItem's attribute). + + * src/main/java/de/intevation/flys/artifacts/model/LayerInfo.java: + Implemented the setStyle() and getStyle() methods. + + * src/main/java/de/intevation/flys/utils/MapfileGenerator.java: Added a + new parameter 'style' to createDatabaseLayer(). This parameter is set on + LayerInfo. + + * src/main/java/de/intevation/flys/exports/MapGenerator.java: Create + Mapserver compatible styles and call createDatabaseLayer() with this + style. + 2011-10-28 Ingo Weinzierl <ingo@intevation.de> * doc/conf/artifacts/winfo.xml: Defined "floodmap.riveraxis" and
--- a/flys-artifacts/doc/conf/themes.xml Fri Oct 28 13:48:02 2011 +0000 +++ b/flys-artifacts/doc/conf/themes.xml Fri Oct 28 14:42:24 2011 +0000 @@ -541,6 +541,15 @@ </theme> + <!-- MAP relevant themes --> + <theme name="RiverAxis"> + <fields> + <field name="linecolor" type="Color" display="Linienfarbe" default="#800080"/> + <field name="linesize" type="int" display="Liniendicke" default="5" hints="h"/> + </fields> + </theme> + + <!-- Mappings are following now. A mapping maps between a name of a facet and a theme. --> <mappings> @@ -595,5 +604,6 @@ <mapping from="computed_discharge_curve.mainvalues.w" to="ComputedDischargeCurveW"/> <mapping from="longitudinal_section.annotations" to="Annotations"/> <mapping from="w_differences" to="Differences"/> + <mapping from="floodmap.riveraxis" to="RiverAxis"/> </mappings> </themes>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LayerInfo.java Fri Oct 28 13:48:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LayerInfo.java Fri Oct 28 14:42:24 2011 +0000 @@ -10,6 +10,7 @@ protected String group; protected String groupTitle; protected String title; + protected String style; public LayerInfo( @@ -77,11 +78,13 @@ } + public void setStyle(String style) { + this.style = style; + } + + public String getStyle() { - // TODO IMPLEMENT ME - // The style of a layer depends on the theme that might be configured - // by the user (stored in the attribute of the CollectionItem). - return null; + return style; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java Fri Oct 28 14:42:24 2011 +0000 @@ -0,0 +1,64 @@ +package de.intevation.flys.artifacts.model; + +import java.util.ArrayList; +import java.util.List; + + +public class MapserverStyle { + + public static class Clazz { + protected String name; + protected String outlinecolor; + protected int size; + + public Clazz(String name) { + this.name = name; + } + + public void setOutlineColor(String outlinecolor) { + this.outlinecolor = outlinecolor; + } + + public void setSize(int size) { + this.size = size; + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("CLASS\n"); + sb.append("NAME \"" + name + "\"\n"); + sb.append("STYLE\n"); + sb.append("SIZE " + String.valueOf(size) + "\n"); + sb.append("OUTLINECOLOR \"" + outlinecolor + "\"\n"); + sb.append("END\n"); + sb.append("END\n"); + + return sb.toString(); + } + } // end of Clazz + + + protected List<Clazz> classes; + + + public MapserverStyle() { + classes = new ArrayList<Clazz>(); + } + + public void addClazz(Clazz clazz) { + if (clazz != null) { + classes.add(clazz); + } + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + + for (Clazz clazz: classes) { + sb.append(clazz.toString()); + } + + return sb.toString(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Fri Oct 28 13:48:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Fri Oct 28 14:42:24 2011 +0000 @@ -29,6 +29,7 @@ import de.intevation.flys.artifacts.model.WMSLayerFacet; import de.intevation.flys.utils.GeometryUtils; import de.intevation.flys.utils.MapfileGenerator; +import de.intevation.flys.utils.ThemeUtil; public class MapGenerator implements OutGenerator, FacetTypes { @@ -109,7 +110,7 @@ createBarriersLayer(flys, wms); } else { - createDatabaseLayer(flys, wms); + createDatabaseLayer(flys, wms, attr); } } else { @@ -144,7 +145,11 @@ } - protected void createDatabaseLayer(FLYSArtifact flys, WMSLayerFacet wms) { + protected void createDatabaseLayer( + FLYSArtifact flys, + WMSLayerFacet wms, + Document attr + ) { logger.debug("createDatabaseLayer for facet: " + wms.getName()); MapfileGenerator mfg = MapfileGenerator.getInstance(); @@ -159,7 +164,10 @@ } if (wms instanceof WMSDBLayerFacet) { - mfg.createDatabaseLayer(flys, (WMSDBLayerFacet) wms); + mfg.createDatabaseLayer( + flys, + (WMSDBLayerFacet) wms, + ThemeUtil.createMapserverStyle(attr)); } else { logger.warn("Cannot create DB layer from: " + wms.getClass());
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Fri Oct 28 13:48:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Fri Oct 28 14:42:24 2011 +0000 @@ -466,7 +466,11 @@ * @param flys The FLYSArtifact that owns <i>wms</i>. * @param wms The WMSLayerFacet that contains information for the layer. */ - public void createDatabaseLayer(FLYSArtifact flys, WMSDBLayerFacet wms) + public void createDatabaseLayer( + FLYSArtifact flys, + WMSDBLayerFacet wms, + String style + ) throws FileNotFoundException, IOException { logger.debug("createDatabaseLayer"); @@ -477,6 +481,7 @@ wms.getFilter(), wms.getData(), wms.getDescription()); + layerinfo.setStyle(style); String name = MS_LAYER_PREFIX + wms.getName();
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Fri Oct 28 13:48:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Fri Oct 28 14:42:24 2011 +0000 @@ -9,6 +9,9 @@ import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.artifacts.model.MapserverStyle; +import de.intevation.flys.artifacts.model.MapserverStyle.Clazz; + /** * Utility to deal with themes and their representations. @@ -284,13 +287,33 @@ } + public static String getLineColorString(Document theme) { + return XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); + } + + /** * Gets color from color field. * @param theme the theme document. * @return color. */ public static Color parseLineColorField(Document theme) { - String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); - return parseRGB(color); + return parseRGB(getLineColorString(theme)); + } + + + public static String createMapserverStyle(Document theme) { + String linecolor = getLineColorString(theme); + int linewidth = parseLineWidth(theme); + + MapserverStyle ms = new MapserverStyle(); + + Clazz c = new Clazz(" "); + c.setOutlineColor(linecolor); + c.setSize(linewidth); + + ms.addClazz(c); + + return ms.toString(); } }