[Schmitzm-commits] r123 - trunk/src/skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed May 20 17:54:51 CEST 2009


Author: alfonx
Date: 2009-05-20 17:54:51 +0200 (Wed, 20 May 2009)
New Revision: 123

Modified:
   trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
* Changed the logic to generate the Style which contains a FeatureTypeStyle for the selection. It now uses the MapLayer.getStyle() as a base (instead of styledObj.getStyle() ) and simply removes any old FeatureTypeStyle that contains Rules for an older selection. 
Why? 
1. Because the MapLayer's Style might have been changed by the AS and we don't want the Style to reset.
2. Because in the Atlas the DPLayer's getStyle() always returns the default style, ignoring any additionaly styles. 

Modified: trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-05-19 17:16:13 UTC (rev 122)
+++ trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-05-20 15:54:51 UTC (rev 123)
@@ -15,6 +15,7 @@
 
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Vector;
 
@@ -25,6 +26,7 @@
 import org.geotools.feature.Feature;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.map.MapLayer;
+import org.geotools.styling.FeatureTypeStyle;
 import org.geotools.styling.Style;
 import org.opengis.filter.Filter;
 import org.opengis.filter.FilterVisitor;
@@ -137,13 +139,22 @@
 			} else {
 				LOGGER.debug("SELECTION .. change style");
 
-				Style originalStyle = styledMapLayer.getStyle();
+				// We take Style from the MapLayer that is displayed at the
+				// moment. We do not use the styledMapLayer.getStyle, because in
+				// the atlas, this always return the default style, but
+				// additionaly styles might be selected.
+				// Taking the style from the mapLayer indicated, that we have to
+				// remove any selection rules first. 
+				Style originalStyle = mapLayer.getStyle();
 
-				// TODO This clone is a deep clone and it is slow..
+				// TODO The default style is not good here. We need
+				// .createSelectionStyle(normalStyle, geoObj);
 				selectionMapStyle = StylingUtil
 						.createDefaultStyle(styledMapLayer.getGeoObject());
-				selectionMapStyle.getFeatureTypeStyles()[0].setName(SELECTION_STYLING);
 
+				selectionMapStyle.getFeatureTypeStyles()[0]
+						.setName(SELECTION_STYLING);
+
 				// Symbolizer sss =
 				// selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0].getSymbolizers()[0];
 				// if (sss instanceof PolygonSymbolizer) {
@@ -165,7 +176,7 @@
 							public boolean evaluate(Object obj) {
 								if (obj instanceof Feature) {
 									Feature f = (Feature) obj;
-									// TODO BAD CODE?
+									// TODO BAD CODE! says Martin.. i am fine with it.. well.. not great... 
 									for (String ffID : newSelection) {
 										if (ffID.equals(f.getID()))
 											return true;
@@ -178,9 +189,31 @@
 
 						});
 
-				selectionMapStyle.setFeatureTypeStyles(LangUtil.extendArray(
-						originalStyle.getFeatureTypeStyles(), selectionMapStyle
-								.getFeatureTypeStyles()));
+				FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle.getFeatureTypeStyles();
+				FeatureTypeStyle[] newFeatureTypes ;
+				if (originalFeatureTypeStyles[originalFeatureTypeStyles.length-1].getName() != null && originalFeatureTypeStyles[originalFeatureTypeStyles.length-1].getName().equals(SELECTION_STYLING)){
+					newFeatureTypes = Arrays.copyOf(originalFeatureTypeStyles, originalFeatureTypeStyles.length-1);
+				} else {
+					newFeatureTypes = originalFeatureTypeStyles;
+				}
+//				
+//				// REMOVE any Selection_Styling FTS (usually the last one)
+//				
+//				for (FeatureTypeStyle fts : originalFeatureTypeStyles){
+//					if (fts.getName().equals(SELECTION_STYLING)) continue;
+//					newFeatureTypes = 
+//					
+//					LangUtil.extendArray(
+//						originalFeatureTypeStyles, selectionMapStyle
+//								.getFeatureTypeStyles());
+//				}
+				
+				// The last FTS is the selection FTS
+				newFeatureTypes =  LangUtil.extendArray(newFeatureTypes, selectionMapStyle
+						.getFeatureTypeStyles());
+				
+				
+				selectionMapStyle.setFeatureTypeStyles(newFeatureTypes);
 
 				// selectionMapStyle.setFeatureTypeStyles(originalStyle.getF)
 



More information about the Schmitzm-commits mailing list