26 |
|
|
27 |
import org.geotools.feature.Feature; |
import org.geotools.feature.Feature; |
28 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
29 |
|
import org.geotools.styling.PolygonSymbolizer; |
30 |
import org.geotools.styling.Rule; |
import org.geotools.styling.Rule; |
31 |
import org.geotools.styling.RuleImpl; |
import org.geotools.styling.RuleImpl; |
32 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
36 |
import org.opengis.filter.FilterVisitor; |
import org.opengis.filter.FilterVisitor; |
37 |
import org.opengis.layer.StyleURL; |
import org.opengis.layer.StyleURL; |
38 |
|
|
39 |
|
import schmitzm.geotools.FilterUtil; |
40 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
41 |
import schmitzm.geotools.gui.JMapPane; |
import schmitzm.geotools.gui.JMapPane; |
42 |
import schmitzm.geotools.map.event.FeatureSelectedEvent; |
import schmitzm.geotools.map.event.FeatureSelectedEvent; |
69 |
* (University of Bonn/Germany) |
* (University of Bonn/Germany) |
70 |
*/ |
*/ |
71 |
public class FeatureMapLayerSelectionSynchronizer extends |
public class FeatureMapLayerSelectionSynchronizer extends |
72 |
StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> implements |
StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
73 |
JMapPaneListener { |
implements JMapPaneListener { |
74 |
/** |
/** |
75 |
* Holds the {@link MapLayer} to keep synchronized with the layer selection |
* Holds the {@link MapLayer} to keep synchronized with the layer selection |
76 |
* model. |
* model. |
142 |
|
|
143 |
selectionMapStyle = styledMapLayer.getStyle(); |
selectionMapStyle = styledMapLayer.getStyle(); |
144 |
LOGGER.debug("NO SELECTION .. reset original style"); |
LOGGER.debug("NO SELECTION .. reset original style"); |
145 |
|
|
146 |
} else { |
} else { |
147 |
LOGGER.debug("SELECTION .. change style"); |
LOGGER.debug("SELECTION .. change style"); |
148 |
|
|
149 |
Style originalStyle = styledMapLayer.getStyle(); |
Style originalStyle = styledMapLayer.getStyle(); |
|
|
|
|
// TODO This clone is a deep clone and it is slow.. |
|
|
selectionMapStyle = StylingUtil.clone(originalStyle); |
|
|
|
|
|
Rule[] rules = selectionMapStyle.getFeatureTypeStyles()[0].getRules(); |
|
|
|
|
|
Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule(); |
|
|
selectedRule.setFilter(new Filter() { |
|
150 |
|
|
151 |
@Override |
// TODO This clone is a deep clone and it is slow.. |
152 |
public Object accept(FilterVisitor visitor, Object extraData) { |
selectionMapStyle = StylingUtil |
153 |
return null; |
.createDefaultStyle(styledMapLayer.getGeoObject()); |
154 |
} |
|
155 |
|
// Symbolizer sss = selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0].getSymbolizers()[0]; |
156 |
@Override |
// if (sss instanceof PolygonSymbolizer) { |
157 |
public boolean evaluate(Object obj) { |
// PolygonSymbolizer ps = (PolygonSymbolizer) sss; |
158 |
if (obj instanceof Feature) { |
// ps.getFill().setOpacity( FilterUtil.FILTER_FAC.literal(0.5)); |
159 |
Feature f = (Feature)obj; |
// } |
160 |
LOGGER.info("treffer"); |
|
161 |
return newSelection.contains(f); |
// Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule(); |
162 |
|
selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0] |
163 |
} |
.setFilter(new Filter() { |
164 |
LOGGER.info("kein treffer"); |
|
165 |
return false; |
@Override |
166 |
} |
public Object accept(FilterVisitor visitor, |
167 |
|
Object extraData) { |
168 |
}); |
return null; |
169 |
|
} |
170 |
Symbolizer[] symbolizers = selectedRule.getSymbolizers(); |
|
171 |
Style selectedStyle = StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject()); |
@Override |
172 |
LangUtil.extendArray(symbolizers, selectedStyle); |
public boolean evaluate(Object obj) { |
173 |
selectedRule.setSymbolizers(symbolizers); |
if (obj instanceof Feature) { |
174 |
|
Feature f = (Feature) obj; |
175 |
LangUtil.extendArray(rules, selectedRule); |
// TODO BAD CODE |
176 |
|
for (Feature ff : newSelection) { |
177 |
// selectionMapStyle.setFeatureTypeStyles(originalStyle.getF) |
if (ff.getID().equals(f.getID())) |
178 |
|
return true; |
179 |
|
} |
180 |
|
return false; |
181 |
|
|
182 |
|
} |
183 |
|
return false; |
184 |
|
} |
185 |
|
|
186 |
|
}); |
187 |
|
|
188 |
|
selectionMapStyle.setFeatureTypeStyles(LangUtil.extendArray( |
189 |
|
originalStyle |
190 |
|
.getFeatureTypeStyles(), selectionMapStyle.getFeatureTypeStyles())); |
191 |
|
|
192 |
|
// selectionMapStyle.setFeatureTypeStyles(originalStyle.getF) |
193 |
|
|
194 |
// Flat copy the style |
// Flat copy the style |
195 |
|
|
196 |
|
// selectionMapStyle = |
197 |
|
// StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject()); |
198 |
|
|
199 |
} |
} |
200 |
|
|
201 |
mapLayer.setStyle(selectionMapStyle); |
mapLayer.setStyle(selectionMapStyle); |
221 |
|
|
222 |
@Override |
@Override |
223 |
public void performMapPaneEvent(JMapPaneEvent e) { |
public void performMapPaneEvent(JMapPaneEvent e) { |
|
if (!(e instanceof FeatureSelectedEvent)) |
|
|
return; |
|
224 |
|
|
225 |
|
if (!(e instanceof FeatureSelectedEvent)) { |
226 |
|
// LOGGER.debug("Ignoring event " + e); |
227 |
|
return; |
228 |
|
} |
229 |
|
// only listen to events directly coming from JMapPane |
230 |
|
// selection (ignore selections from FilterDialog) |
231 |
|
if ( e.getSourceObject() != this.mapPane ) |
232 |
|
return; |
233 |
|
|
234 |
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
235 |
|
// LOGGER.debug("Do event " + fse); |
236 |
|
// LOGGER.debug("Do event " + fse.getSelectionResult()); |
237 |
|
|
238 |
// ignore event if it is caused by the DpLayerVectorSelectionModel |
// ignore event if it is caused by the DpLayerVectorSelectionModel |
239 |
if (selectionChangeCausedByMe) |
if (selectionChangeCausedByMe) |
261 |
// Show selected feature in the map, which is not automatically done by |
// Show selected feature in the map, which is not automatically done by |
262 |
// the FeatureSelectedEvent |
// the FeatureSelectedEvent |
263 |
changeLayerStyle(layerSelModel.getSelection()); |
changeLayerStyle(layerSelModel.getSelection()); |
264 |
|
|
265 |
// Danger of event circles in propertyChange(..) banned |
// Danger of event circles in propertyChange(..) banned |
266 |
selectionChangeCausedByMe = false; |
selectionChangeCausedByMe = false; |
267 |
} |
} |