24 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
25 |
|
|
26 |
import org.geotools.feature.Feature; |
import org.geotools.feature.Feature; |
|
import org.geotools.feature.FeatureCollection; |
|
27 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
28 |
import org.geotools.styling.FeatureTypeStyle; |
import org.geotools.styling.FeatureTypeStyle; |
29 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
133 |
if (newSelection.isEmpty()) { |
if (newSelection.isEmpty()) { |
134 |
|
|
135 |
selectionMapStyle = styledMapLayer.getStyle(); |
selectionMapStyle = styledMapLayer.getStyle(); |
136 |
LOGGER.debug("NO SELECTION .. set to original style directly"); |
// LOGGER.debug("NO SELECTION .. set to original style directly"); |
137 |
|
|
138 |
} else { |
} else { |
139 |
LOGGER.debug("SELECTION .. change style"); |
LOGGER.debug("SELECTION .. change style"); |
143 |
// the atlas, this always return the default style, but |
// the atlas, this always return the default style, but |
144 |
// additionaly styles might be selected. |
// additionaly styles might be selected. |
145 |
// Taking the style from the mapLayer indicated, that we have to |
// Taking the style from the mapLayer indicated, that we have to |
146 |
// remove any selection rules first. |
// remove any selection rules first. |
147 |
Style originalStyle = mapLayer.getStyle(); |
Style originalStyle = mapLayer.getStyle(); |
148 |
|
|
149 |
// TODO The default style is not good here. We need |
// TODO The default style is not good here. We need |
150 |
// .createSelectionStyle(normalStyle, geoObj); |
// .createSelectionStyle(normalStyle, geoObj); |
151 |
selectionMapStyle = StylingUtil |
selectionMapStyle = StylingUtil |
152 |
.createDefaultStyle(styledMapLayer.getGeoObject()); |
.createSelectionStyle(styledMapLayer.getGeoObject()); |
153 |
|
// selectionMapStyle = StylingUtil |
154 |
|
// .createDefaultStyle(styledMapLayer.getGeoObject()); |
155 |
|
|
156 |
selectionMapStyle.getFeatureTypeStyles()[0] |
selectionMapStyle.getFeatureTypeStyles()[0] |
157 |
.setName(SELECTION_STYLING); |
.setName(SELECTION_STYLING); |
158 |
|
|
|
// Symbolizer sss = |
|
|
// selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0].getSymbolizers()[0]; |
|
|
// if (sss instanceof PolygonSymbolizer) { |
|
|
// PolygonSymbolizer ps = (PolygonSymbolizer) sss; |
|
|
// ps.getFill().setOpacity( FilterUtil.FILTER_FAC.literal(0.5)); |
|
|
// } |
|
|
|
|
159 |
// Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule(); |
// Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule(); |
160 |
selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0] |
selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0] |
161 |
.setFilter(new Filter() { |
.setFilter(new Filter() { |
170 |
public boolean evaluate(Object obj) { |
public boolean evaluate(Object obj) { |
171 |
if (obj instanceof Feature) { |
if (obj instanceof Feature) { |
172 |
Feature f = (Feature) obj; |
Feature f = (Feature) obj; |
173 |
// TODO BAD CODE! says Martin.. i am fine with it.. well.. not great... |
// TODO BAD CODE! says Martin.. i am fine |
174 |
|
// with it.. well.. not great... |
175 |
for (String ffID : newSelection) { |
for (String ffID : newSelection) { |
176 |
if (ffID.equals(f.getID())) |
if (ffID.equals(f.getID())) |
177 |
return true; |
return true; |
184 |
|
|
185 |
}); |
}); |
186 |
|
|
187 |
FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle.getFeatureTypeStyles(); |
FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle |
188 |
FeatureTypeStyle[] newFeatureTypes ; |
.getFeatureTypeStyles(); |
189 |
if (originalFeatureTypeStyles[originalFeatureTypeStyles.length-1].getName() != null && originalFeatureTypeStyles[originalFeatureTypeStyles.length-1].getName().equals(SELECTION_STYLING)){ |
FeatureTypeStyle[] newFeatureTypes; |
190 |
newFeatureTypes = Arrays.copyOf(originalFeatureTypeStyles, originalFeatureTypeStyles.length-1); |
if (originalFeatureTypeStyles[originalFeatureTypeStyles.length - 1] |
191 |
|
.getName() != null |
192 |
|
&& originalFeatureTypeStyles[originalFeatureTypeStyles.length - 1] |
193 |
|
.getName().equals(SELECTION_STYLING)) { |
194 |
|
newFeatureTypes = Arrays.copyOf(originalFeatureTypeStyles, |
195 |
|
originalFeatureTypeStyles.length - 1); |
196 |
} else { |
} else { |
197 |
newFeatureTypes = originalFeatureTypeStyles; |
newFeatureTypes = originalFeatureTypeStyles; |
198 |
} |
} |
|
// |
|
|
// // 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()); |
|
|
// } |
|
199 |
|
|
200 |
// The last FTS is the selection FTS |
// The last FTS is the selection FTS |
201 |
newFeatureTypes = LangUtil.extendArray(newFeatureTypes, selectionMapStyle |
newFeatureTypes = LangUtil.extendArray(newFeatureTypes, |
202 |
.getFeatureTypeStyles()); |
selectionMapStyle.getFeatureTypeStyles()); |
|
|
|
|
|
|
|
selectionMapStyle.setFeatureTypeStyles(newFeatureTypes); |
|
203 |
|
|
204 |
// selectionMapStyle.setFeatureTypeStyles(originalStyle.getF) |
selectionMapStyle.setFeatureTypeStyles(newFeatureTypes); |
|
|
|
|
// Flat copy the style |
|
|
|
|
|
// selectionMapStyle = |
|
|
// StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject()); |
|
205 |
|
|
206 |
} |
} |
207 |
|
|