changeset 1876:dd467951335c

Added support for labels in Mapserver layers and options to modify its style. flys-artifacts/trunk@3234 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 11 Nov 2011 09:43:36 +0000
parents 4fb81eb8b45b
children 1a6018d5f0b7
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/mapserver/db_layer.vm flys-artifacts/doc/conf/mapserver/fontset.txt flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java 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/artifacts/model/WMSDBLayerFacet.java flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java
diffstat 11 files changed, 167 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Nov 11 09:43:36 2011 +0000
@@ -1,3 +1,37 @@
+2011-11-11  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/themes.xml: Added 'textcolor' and 'textsize' attributes to the
+	  existing 'Kms' theme.
+
+	* doc/conf/mapserver/fontset.txt: Defined a 'DefaultFont' that is used as
+	  default font for Mapserver labels.
+
+	* doc/conf/mapserver/db_layer.vm: Add a Mapserver LABELITEM if a value is
+	  provided by LayerInfo object.
+
+	* src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java: Added a
+	  getLabelItem() method that returns null as default.
+
+	* src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java: Override
+	  getLabelItem() to return "km" which is the database field that contains
+	  the kilometer information.
+
+	* src/main/java/de/intevation/flys/artifacts/model/LayerInfo.java,
+	  src/main/java/de/intevation/flys/artifacts/model/WMSDBLayerFacet.java:
+	  Added an attribute labelItem with appropriate getter/setter methods.
+
+	* src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java:
+	  Splitted up the internal class Clazz. Now, there are two new inner
+	  classes Style and Label that fulfill the appropriate Mapfile sections of
+	  Mapserver.
+
+	* src/main/java/de/intevation/flys/utils/ThemeUtil.java: Also Read font
+	  attributes and add new Clazz Label for the Mapserver layer.
+
+	* src/main/java/de/intevation/flys/utils/MapfileGenerator.java: Set the
+	  "labelItem" attribute on the LayerInfo object used to fill DB layer
+	  templates.
+
 2011-11-11  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml: Re-use macros to include more data to
--- a/flys-artifacts/doc/conf/mapserver/db_layer.vm	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/doc/conf/mapserver/db_layer.vm	Fri Nov 11 09:43:36 2011 +0000
@@ -17,6 +17,10 @@
         GROUP "$LAYER.getGroup()"
     #end
 
+    #if ( $LAYER.getLabelItem() )
+        LABELITEM $LAYER.getLabelItem()
+    #end
+
     METADATA
         "wms_title" "$LAYER.getTitle()"
         "gml_include_items" "all"
@@ -34,6 +38,17 @@
                 SIZE 5
                 OUTLINECOLOR "#000000"
             END
+            #if ( $LAYER.getLabelItem() )
+                LABEL
+                    ANGLE auto
+                    SIZE 10
+                    COLOR "#000000"
+                    TYPE truetype
+                    FONT LiberationSans-Italic
+                    POSITION ur
+                    OFFSET 2 2
+                END
+            #end
         END
     #end
 END
--- a/flys-artifacts/doc/conf/mapserver/fontset.txt	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/doc/conf/mapserver/fontset.txt	Fri Nov 11 09:43:36 2011 +0000
@@ -1,1 +1,2 @@
 FreeSans /usr/share/fonts/truetype/freefont/FreeSans.ttf
+DefaultFont /usr/share/fonts/truetype/freefont/FreeSans.ttf
--- a/flys-artifacts/doc/conf/themes.xml	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Fri Nov 11 09:43:36 2011 +0000
@@ -727,6 +727,8 @@
         <fields>
             <field name="linecolor" type="Color" display="Linienfarbe" default="255, 0, 0"/>
             <field name="linesize"  type="int"   display="Liniendicke" default="5" hints="h"/>
+            <field name="textcolor" type="Color" display="Schriftfarbe"    default="0, 0, 0"/>
+            <field name="textsize"  type="int"   display="Schriftgröße" default="10"/>
             <field name="symbol"    type="Symbol" display="Symbol"     default="square"/>
         </fields>
     </theme>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Fri Nov 11 09:43:36 2011 +0000
@@ -139,6 +139,7 @@
             facet.setGeometryType(getGeometryType());
             facet.setConnection(getConnection());
             facet.setConnectionType(getConnectionType());
+            facet.setLabelItem(getLabelItem());
 
             facets.add(facet);
 
@@ -216,6 +217,10 @@
             return FLYSUtils.isUsingOracle() ? "oraclespatial" : "postgis";
         }
 
+        protected String getLabelItem() {
+            return null;
+        }
+
         protected abstract String getFacetType();
 
         protected abstract String getTitle(CallMeta meta);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSKmArtifact.java	Fri Nov 11 09:43:36 2011 +0000
@@ -161,6 +161,11 @@
         }
 
         @Override
+        protected String getLabelItem() {
+            return "km";
+        }
+
+        @Override
         protected String getGeometryType() {
             return "POINT";
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LayerInfo.java	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LayerInfo.java	Fri Nov 11 09:43:36 2011 +0000
@@ -15,6 +15,7 @@
     protected String title;
     protected String style;
     protected String filter;
+    protected String labelItem;
 
 
     public LayerInfo() {
@@ -139,5 +140,13 @@
     public String getFilter() {
         return filter;
     }
+
+    public void setLabelItem(String labelItem) {
+        this.labelItem = labelItem;
+    }
+
+    public String getLabelItem() {
+        return labelItem;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MapserverStyle.java	Fri Nov 11 09:43:36 2011 +0000
@@ -7,15 +7,45 @@
 public class MapserverStyle {
 
     public static class Clazz {
-        protected String name;
+        protected List<ClazzItem> items;
+        protected String    name;
+
+        public Clazz(String name) {
+            this.name  = name;
+            this.items = new ArrayList<ClazzItem>();
+        }
+
+        public void addItem(ClazzItem item) {
+            if (item != null) {
+                items.add(item);
+            }
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            sb.append("CLASS\n");
+            sb.append("NAME \"" + name + "\"\n");
+
+            for (ClazzItem item: items) {
+                item.toString(sb);
+            }
+
+            sb.append("END");
+
+            return sb.toString();
+        }
+    }
+
+    public interface ClazzItem {
+        void toString(StringBuilder sb);
+    }
+
+    public static class Style implements ClazzItem {
         protected String outlinecolor;
         protected String symbol;
         protected int    size;
 
-        public Clazz(String name) {
-            this.name = name;
-        }
-
         public void setOutlineColor(String outlinecolor) {
             this.outlinecolor = outlinecolor;
         }
@@ -30,10 +60,7 @@
             }
         }
 
-        public String toString() {
-            StringBuilder sb = new StringBuilder();
-            sb.append("CLASS\n");
-            sb.append("NAME \"" + name + "\"\n");
+        public void toString(StringBuilder sb) {
             sb.append("STYLE\n");
             sb.append("SIZE " + String.valueOf(size) + "\n");
             sb.append("OUTLINECOLOR " + outlinecolor + "\n");
@@ -43,11 +70,34 @@
             }
 
             sb.append("END\n");
-            sb.append("END\n");
+        }
+    } // end of Style
 
-            return sb.toString();
+    public static class Label implements ClazzItem {
+        protected String color;
+        protected int    size;
+
+        public void setColor(String color) {
+            this.color = color;
         }
-    } // end of Clazz
+
+        public void setSize(int size) {
+            this.size = size;
+        }
+
+        @Override
+        public void toString(StringBuilder sb) {
+            sb.append("LABEL\n");
+            sb.append("ANGLE auto\n");
+            sb.append("SIZE " + String.valueOf(size) + "\n");
+            sb.append("COLOR " + color + "\n");
+            sb.append("TYPE truetype\n");
+            sb.append("FONT DefaultFont\n");
+            sb.append("POSITION ur\n");
+            sb.append("OFFSET 2 2\n");
+            sb.append("END\n");
+        }
+    }
 
 
     protected List<Clazz> classes;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSDBLayerFacet.java	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WMSDBLayerFacet.java	Fri Nov 11 09:43:36 2011 +0000
@@ -7,6 +7,7 @@
 
     protected String data;
     protected String filter;
+    protected String labelItem;
     protected String geometryType;
     protected String connection;
     protected String connectionType;
@@ -87,5 +88,13 @@
     public String getConnectionType() {
         return connectionType;
     }
+
+    public void setLabelItem(String labelItem) {
+        this.labelItem = labelItem;
+    }
+
+    public String getLabelItem() {
+        return labelItem;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java	Fri Nov 11 09:43:36 2011 +0000
@@ -531,6 +531,7 @@
         layerinfo.setExtent(GeometryUtils.jtsBoundsToOLBounds(wms.getExtent()));
         layerinfo.setConnection(wms.getConnection());
         layerinfo.setConnectionType(wms.getConnectionType());
+        layerinfo.setLabelItem(wms.getLabelItem());
 
         String name = MS_LAYER_PREFIX + wms.getName();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Fri Nov 11 07:59:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Fri Nov 11 09:43:36 2011 +0000
@@ -11,6 +11,8 @@
 
 import de.intevation.flys.artifacts.model.MapserverStyle;
 import de.intevation.flys.artifacts.model.MapserverStyle.Clazz;
+import de.intevation.flys.artifacts.model.MapserverStyle.Style;
+import de.intevation.flys.artifacts.model.MapserverStyle.Label;
 
 
 /**
@@ -171,8 +173,7 @@
      * @param theme The theme.
      */
     public static Color parseTextColor(Document theme) {
-        String color = XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null);
-        return parseRGB(color);
+        return parseRGB(getTextColorString(theme));
     }
 
 
@@ -295,6 +296,11 @@
     }
 
 
+    public static String getTextColorString(Document theme) {
+        return XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null);
+    }
+
+
     public static String getSymbol(Document theme) {
         return XMLUtils.xpathString(theme, XPATH_SYMBOL, null);
     }
@@ -320,9 +326,22 @@
         MapserverStyle ms = new MapserverStyle();
 
         Clazz c = new Clazz(" ");
-        c.setOutlineColor(linecolor);
-        c.setSize(linewidth);
-        c.setSymbol(symbol);
+
+        Style s = new Style();
+        s.setOutlineColor(linecolor);
+        s.setSize(linewidth);
+        s.setSymbol(symbol);
+        c.addItem(s);
+
+        String textcolor = getTextColorString(theme);
+        int    textsize  = parseTextSize(theme);
+
+        if (textcolor != null && textcolor.length() > 0 && textsize > 0) {
+            Label l = new Label();
+            l.setColor(textcolor.replace(",", ""));
+            l.setSize(textsize);
+            c.addItem(l);
+        }
 
         ms.addClazz(c);
 

http://dive4elements.wald.intevation.org