45 |
import java.awt.RenderingHints; |
import java.awt.RenderingHints; |
46 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
47 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
48 |
|
import java.io.File; |
49 |
import java.util.HashMap; |
import java.util.HashMap; |
50 |
import java.util.HashSet; |
import java.util.HashSet; |
51 |
import java.util.Iterator; |
import java.util.Iterator; |
57 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
58 |
|
|
59 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
60 |
|
import org.geotools.feature.FeatureIterator; |
61 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
62 |
import org.geotools.renderer.GTRenderer; |
import org.geotools.renderer.GTRenderer; |
63 |
import org.geotools.renderer.label.LabelCacheImpl; |
import org.geotools.renderer.label.LabelCacheImpl; |
77 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
78 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
79 |
import skrueger.geotools.MapPaneToolBar; |
import skrueger.geotools.MapPaneToolBar; |
80 |
|
import skrueger.geotools.StyledFeaturesInterface; |
81 |
import skrueger.geotools.StyledLayerInterface; |
import skrueger.geotools.StyledLayerInterface; |
82 |
|
|
83 |
/** |
/** |
107 |
* model. |
* model. |
108 |
*/ |
*/ |
109 |
protected final MapLayer mapLayer; |
protected final MapLayer mapLayer; |
110 |
protected final StyledLayerInterface<?> styledLayer; |
protected final StyledFeaturesInterface<?> styledLayer; |
111 |
protected final JMapPane mapPane; |
protected final JMapPane mapPane; |
112 |
private final MapPaneToolBar toolBar; |
private final MapPaneToolBar toolBar; |
113 |
private final HashMap<Object, Object> defaultGTRenderingHints; |
private final HashMap<Object, Object> defaultGTRenderingHints; |
124 |
*/ |
*/ |
125 |
public FeatureMapLayerSelectionSynchronizer( |
public FeatureMapLayerSelectionSynchronizer( |
126 |
StyledFeatureLayerSelectionModel layerSelModel, |
StyledFeatureLayerSelectionModel layerSelModel, |
127 |
StyledLayerInterface<?> styledLayer, MapLayer mapLayer, |
StyledFeaturesInterface<?> styledLayer, MapLayer mapLayer, |
128 |
JMapPane mapPane, MapPaneToolBar toolBar, |
JMapPane mapPane, MapPaneToolBar toolBar, |
129 |
HashMap<Object, Object> defaultGTRenderingHints) { |
HashMap<Object, Object> defaultGTRenderingHints) { |
130 |
|
|
227 |
* |
* |
228 |
* Add a Filter to the selectionMapStyle, so that it is only |
* Add a Filter to the selectionMapStyle, so that it is only |
229 |
* used on objects that are selected. <br/> |
* used on objects that are selected. <br/> |
230 |
|
* To optimize rendering speed, the filter checks whether more |
231 |
|
* than half of the features are selected. If so, the filter is |
232 |
|
* inverted to be shorter. |
233 |
* |
* |
|
* Note 1:<br/> |
|
|
* It is NEVER allowed to GeoTools extend Filter () { .. } (and |
|
|
* write tests into the evaluate block). Especially for the |
|
|
* ShapeFileRenderer, we may only use a geotools Filter.<br/> |
|
|
* |
|
|
* Note 2:<br/> |
|
|
* The FilterUtil.FILTER_FAC2.id(fids) wants a set of |
|
|
* FeatureId-Objects! |
|
234 |
*/ |
*/ |
235 |
|
|
236 |
Set<FeatureId> fids = new HashSet<FeatureId>(); |
final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollectionFiltered = styledLayer |
237 |
for (String fid : newSelection) { |
.getFeatureCollectionFiltered(); |
238 |
fids.add(FilterUtil.FILTER_FAC2.featureId(fid)); |
if (newSelection.size() > featureCollectionFiltered.size() / 2) { |
239 |
} |
FeatureIterator<SimpleFeature> iterator = featureCollectionFiltered |
240 |
|
.features(); |
241 |
LOGGER.debug("The selection filter:"+fids); |
Set<FeatureId> antiFids = new HashSet<FeatureId>(); |
242 |
|
try { |
243 |
|
while (iterator.hasNext()) { |
244 |
|
SimpleFeature next = iterator.next(); |
245 |
|
if (!newSelection.contains(next.getID())) |
246 |
|
antiFids.add(FilterUtil.FILTER_FAC2 |
247 |
|
.featureId(next.getID())); |
248 |
|
} |
249 |
|
|
250 |
|
selectionFTStyle.rules().get(0).setFilter( |
251 |
|
FilterUtil.FILTER_FAC2 |
252 |
|
.not(FilterUtil.FILTER_FAC2 |
253 |
|
.id(antiFids))); |
254 |
|
|
255 |
|
} finally { |
256 |
|
featureCollectionFiltered.close(iterator); |
257 |
|
} |
258 |
|
} else { |
259 |
|
Set<FeatureId> fids = new HashSet<FeatureId>(); |
260 |
|
for (String fid : newSelection) { |
261 |
|
fids.add(FilterUtil.FILTER_FAC2.featureId(fid)); |
262 |
|
} |
263 |
|
|
264 |
selectionFTStyle.rules().get(0).setFilter( |
selectionFTStyle.rules().get(0).setFilter( |
265 |
FilterUtil.FILTER_FAC2.id(fids)); |
FilterUtil.FILTER_FAC2.id(fids)); |
266 |
|
} |
267 |
|
|
268 |
// Maybe there has already been another selection |
// Maybe there has already been another selection |
269 |
// FeatureTypeStyle... Let's replace it... |
// FeatureTypeStyle... Let's replace it... |
288 |
dsv.visit(originalStyle); |
dsv.visit(originalStyle); |
289 |
Style newStyle = (Style) dsv.getCopy(); |
Style newStyle = (Style) dsv.getCopy(); |
290 |
|
|
291 |
|
StylingUtil.saveStyleToSLD(newStyle, new File( |
292 |
|
"/home/stefan/Desktop/selection.sld")); |
293 |
|
|
294 |
|
// DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor(); |
295 |
|
// dsv.visit(originalStyle); |
296 |
|
// Style newStyle = originalStyle; |
297 |
|
|
298 |
// Style newStyle = StylingUtil.STYLE_BUILDER.createStyle(); |
// Style newStyle = StylingUtil.STYLE_BUILDER.createStyle(); |
299 |
// newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles()); |
// newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles()); |
300 |
mapLayer.setStyle(newStyle); |
mapLayer.setStyle(newStyle); |
391 |
return; |
return; |
392 |
} |
} |
393 |
|
|
394 |
// LOGGER.debug("do event " + fse); |
// LOGGER.debug("do event " + fse); |
395 |
|
|
396 |
// Avoid event circles in propertyChange(..) |
// Avoid event circles in propertyChange(..) |
397 |
selectionChangeCausedByMe = true; |
selectionChangeCausedByMe = true; |