172 |
* A {@link Vector} of SimpleFeature-IDs that are selected. |
* A {@link Vector} of SimpleFeature-IDs that are selected. |
173 |
*/ |
*/ |
174 |
private void changeLayerStyle(final Vector<String> newSelection) { |
private void changeLayerStyle(final Vector<String> newSelection) { |
|
Style selectionMapStyle = null; |
|
175 |
try { |
try { |
176 |
|
Style originalStyle = mapLayer.getStyle(); |
177 |
if (newSelection.isEmpty()) { |
if (newSelection.isEmpty()) { |
178 |
|
|
179 |
selectionMapStyle = styledLayer.getStyle(); |
// Check if the Style contains a SELECTION FTS |
180 |
// LOGGER.debug("NO SELECTION .. set to original style directly"); |
|
181 |
|
FeatureTypeStyle[] clone = originalStyle.featureTypeStyles().toArray( new FeatureTypeStyle[] {} ).clone(); |
182 |
|
|
183 |
|
for (FeatureTypeStyle fts : clone) { |
184 |
|
if (fts.getName() != null |
185 |
|
&& fts.getName().equals(SELECTION_STYLING)) { |
186 |
|
originalStyle.featureTypeStyles().remove(fts); |
187 |
|
|
188 |
|
mapPane.refresh(); |
189 |
|
|
190 |
|
return; |
191 |
|
} |
192 |
|
} |
193 |
|
|
194 |
} else { |
} else { |
195 |
LOGGER.debug("SELECTION .. change style"); |
LOGGER.debug("SELECTION .. change style"); |
200 |
// additional styles might be selected. |
// additional styles might be selected. |
201 |
// Taking the style from the mapLayer indicated, that we have to |
// Taking the style from the mapLayer indicated, that we have to |
202 |
// remove any selection rules first. |
// remove any selection rules first. |
|
Style originalStyle = mapLayer.getStyle(); |
|
203 |
|
|
204 |
// TODO The default style is not good here. We need |
FeatureTypeStyle selectionFTStyle = StylingUtil |
|
// .createSelectionStyle(normalStyle, geoObj); |
|
|
selectionMapStyle = StylingUtil |
|
205 |
.createSelectionStyle(styledLayer.getGeoObject()); |
.createSelectionStyle(styledLayer.getGeoObject()); |
|
// selectionMapStyle = StylingUtil |
|
|
// .createDefaultStyle(styledLayer.getGeoObject()); |
|
206 |
|
|
207 |
selectionMapStyle.getFeatureTypeStyles()[0] |
selectionFTStyle.setName(SELECTION_STYLING); |
|
.setName(SELECTION_STYLING); |
|
208 |
|
|
209 |
/** |
/** |
210 |
* |
* |
226 |
fids.add(FilterUtil.FILTER_FAC2.featureId(fid)); |
fids.add(FilterUtil.FILTER_FAC2.featureId(fid)); |
227 |
} |
} |
228 |
|
|
229 |
selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0] |
selectionFTStyle.rules().get(0).setFilter( |
230 |
.setFilter(FilterUtil.FILTER_FAC2.id(fids)); |
FilterUtil.FILTER_FAC2.id(fids)); |
231 |
|
|
232 |
FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle |
// Maybe there has already been another selection |
233 |
.getFeatureTypeStyles(); |
// FeatureTypeStyle... Let's replace it... |
234 |
FeatureTypeStyle[] newFeatureTypes; |
boolean foundAndReplaced = false; |
235 |
if (originalFeatureTypeStyles[originalFeatureTypeStyles.length - 1] |
for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) { |
236 |
.getName() != null |
if (fts.getName() != null |
237 |
&& originalFeatureTypeStyles[originalFeatureTypeStyles.length - 1] |
&& fts.getName().equals(SELECTION_STYLING)) { |
238 |
.getName().equals(SELECTION_STYLING)) { |
foundAndReplaced = true; |
239 |
newFeatureTypes = Arrays.copyOf(originalFeatureTypeStyles, |
fts.rules().clear(); |
240 |
originalFeatureTypeStyles.length - 1); |
fts.rules().addAll(selectionFTStyle.rules()); |
241 |
} else { |
break; |
242 |
newFeatureTypes = originalFeatureTypeStyles; |
} |
243 |
|
} |
244 |
|
if (!foundAndReplaced) { |
245 |
|
originalStyle.featureTypeStyles().add(selectionFTStyle); |
246 |
} |
} |
247 |
|
|
248 |
// The last FTS is the selection FTS |
// Refresh the map |
249 |
newFeatureTypes = LangUtil.extendArray(newFeatureTypes, |
mapPane.refresh(); |
|
selectionMapStyle.getFeatureTypeStyles()); |
|
|
|
|
|
selectionMapStyle.setFeatureTypeStyles(newFeatureTypes); |
|
|
|
|
250 |
} |
} |
251 |
|
|
|
mapLayer.setStyle(selectionMapStyle); |
|
|
mapPane.refresh(); |
|
252 |
} catch (Exception e) { |
} catch (Exception e) { |
253 |
LOGGER.error("Error while trying to create a selection style", e); |
LOGGER.error("Error while trying to create a selection style", e); |
254 |
} |
} |