Hi there,
I'm trying to add all fdo layer features to MgSelectionBase so I can turn on/off map layer features depending on the selection query.
here is what I have:
AcMapLayer maplayer = AcMapFeatureEntityService.GetLayer(objId); //objId is from prompt selection MgFeatureQueryOptions queryOpts = new MgFeatureQueryOptions(); queryOpts.SetFilter("PRIMARYINDEX > 0"); //select everything on the layer MgResourceIdentifier fsId = new MgResourceIdentifier(maplayer.GetFeatureSourceId()); MgFeatureService fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService) as MgFeatureService; MgFeatureReader featureReader = fs.SelectFeatures(fsId, maplayer.FeatureClassName, queryOpts); AcMapSelection selBaseAll = new AcMapSelection(AcMapMap.GetCurrentMap()); //populate selection with all features selBaseAll.AddFeatures(maplayer, featureReader, 0); //hide all features maplayer.SetFeatureVisibility(selBaseAll, false); . . //turn on features that is passed as parameter to fn.
This works if the layer source is SDF file, but if the layer source is sql spatial, i get an error "An exceotion occured in FDO component. Property "GwsId" not defined for class "Classname"". this is on line: selBase.AddFeatures(..);
That field "GwsId" doesn't exists in database, if you open it in sql studio.. what am I doing wrong?
Thank you,
-dm
When Map 3D connects to FDO data stores like Oracle/Sql Server and add layers to map, it will cache the data and use "GwsId" as identity key. Following code snippet works fine for Sql Server Spatial data store :
[CommandMethod("SetVisible")]
public void SetVisible()
{
SetFeatureVisibility(true);
}
[CommandMethod("setInvisible")]
public void SetInvisible()
{
SetFeatureVisibility(false);
}
public void SetFeatureVisibility( bool visible )
{
AcMapMap map = AcMapMap.GetCurrentMap();
MgLayerCollection layers = map.GetLayers();
MgLayerBase layer = layers.GetItem("FeatureClass1");
AcMapLayer mapLayer = layer as AcMapLayer;
MgFeatureQueryOptions opts = new MgFeatureQueryOptions();
opts.SetFilter("ID > 0");
MgResourceIdentifier featureId = new MgResourceIdentifier(mapLayer.GetFeatureSourceId());
MgFeatureReader reader = mapLayer.SelectFeatures(opts);
AcMapSelection selection = new AcMapSelection(map);
selection.AddFeatures(mapLayer, reader, 0);
reader.Close();
mapLayer.SetFeatureVisibility(selection, visible);
}
Hi
I have a question.
i would like to turn OFF/ON some set of FDO layers(Enterprises(Topobase Layers)).
The code is not working for me. Please help me
AcMapMap acMap = AcMapMap.GetCurrentMap();
MgLayerCollectionlayers = acMap.GetLayers();
if (layers != null&& layers.Count > 0)
{
foreach (MgLayerBase layer inlayers)
{
if(layer.GetVisible())
{
layer.SetVisible(
false);
//layer.Visible = false;//layer.ForceRefresh();
}
//if (layer.GetDisplayInLegend())//{// layer.DisplayInLegend = false;// layer.SetDisplayInLegend(false);// layer.ForceRefresh();//}
}
}
//AcMapMap.ForceScreenRefresh();