7/22/10

Create a selection theme and "reverse selection theme."

Product: MapXtreme Java
Version: 4.5
Platform: Not Platform Related
Category: Code Samples

Summary:
Create a selection theme and "reverse selection theme."

Question:
This code sample creates a selection theme on the selected feature, and a second selection theme on all other features in the layer.

Answer:

// Assumptions
// selectedLayer is type Layer & represents the layer the selections are being created on
// mapj is type MapJ
// columnName is type String & represents a column name of the layer data

selectedLayer.setSelectable(true);
selectedLayer.getThemeList().removeAll();

// define a selection obj & selection theme rendition for the NON-SELECTED features
Selection sel1 = new Selection();
SelectionTheme nonselectedTheme = new SelectionTheme("non-selected features");
Rendition nonselThemeRend = new RenditionImpl();
nonselThemeRend.setValue(Rendition.FILL, Color.blue);
nonselectedTheme.setRendition(nonselThemeRend);
nonselectedTheme.setSelection(sel1);

// define a selection obj and selection theme rendition for the SELECTED features
Selection sel2 = new Selection();
SelectionTheme selectedTheme = new SelectionTheme("selected feature");
Rendition selThemeRend = new RenditionImpl();
selThemeRend.setValue(Rendition.FILL, Color.yellow);
selectedTheme.setRendition(selThemeRend);
selectedTheme.setSelection(sel2);

// get all the features from this layer and add them to the selection object
// add the theme to the theme list
// dispose of the feature set then get the feature the user clicked on...
// ... and remove it from the selection
FeatureSet fsAll = null;
FeatureSet fsAtPoint = null;
RewindableFeatureSet rwFs = null;
ArrayList colNames = new ArrayList();
colNames.add(columnName);
try
{
fsAll = selectedLayer.searchAll(colNames, null);
sel1.add(fsAll);
selectedLayer.getThemeList().add(nonselectedTheme);
selectedLayer.getThemeList().add(selectedTheme);
fsAll.dispose();

fsAtPoint = selectedLayer.searchAtPoint(colNames, dp,null);
rwFs = new RewindableFeatureSet(fsAtPoint);
Feature ft = rwFs.getNextFeature();
rwFs.rewind();
sel1.remove(ft);
sel2.add(rwFs);
}
catch(Exception e)
{
e.printStackTrace();
}

SOURCE

0 comments:

Post a Comment