Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm working with ArcObjects in C#, and am trying to exclude all map layers but one (the only one I want to snap to) from the snapping environment. I'm using the ISnappingEnvironment and IPointSnapper interfaces. I've put the following code in the OnClick method of the tool I'm using:

 m_Snapper = m_SnappingEnvironment.PointSnapper;
 ISet anExclLyrSet = new SetClass();
 m_Snapper.ExcludedLayers(ref anExclLyrSet);

 // ...loop through all map layers, adding all but the one of interest to anExclLyrSet

 m_Snapper.ClearCache();

Basically, I'm getting poor snapping performance due to the presence of a basemap layer that contains multiple feature layers. If I turn that layer off (make invisible), the performance is good.

I've confirmed that all the layers (for composite type layers, I add each sub-layer to the exclusion as well) are being added to the exclusion set, but I can't seem to get the performance to improve without turning off that basemap layer. I'm not sure what I'm doing wrong - does the cache need to be cleared after each individual layer is excluded? I'd appreciate insights anyone might have regarding this. Thanks!

Mark C.

share|improve this question
    
What happens if you don't use a composite layer but just have each of its children as regular (orphan) layers, does performance improve? –  Kirk Kuykendall Sep 9 '11 at 15:02
    
I think exclusion only works on classic snapping. I don't nknow about the ipointsnapper. but if there is a classic method on isnappingenvironment that would probably be the way to go. –  Brad Nesom Sep 9 '11 at 15:04
    
@Kirk, I'm working with Mark on this project, and we would rather not change the map layer structure. Is there a reason you think performance would improve with that change to the map? –  Keith G Sep 9 '11 at 15:38
    
@Keith If you take he grouplayer out of the equation, but promote the child layers to standalone layers, and the performance improves, I think you could narrow it down to an issue (and perhaps a bug) with group layers. Also, maybe excluding a grouplayer implicitly excludes all the children, so maybe also try excluding just the group layer and not the children. –  Kirk Kuykendall Sep 9 '11 at 16:28

1 Answer 1

Here is the solution we settled on for this problem. It is called when the snapping environment is setup.

/// <summary>
/// Builds (adds layers) to the exclusion set for IPointSnapper. Set up to exclude all
/// layers except the one with the supplied name.
/// </summary>
/// <param name="aMap"> Reference to the map. </param>
/// <param name="anExclLyrSet"> Reference to the layer exclusion set for IPointSnapper. </param>
/// <param name="aStr"> Name of the one layer NOT to exclude. </param>
/// <param name="pSnapper"> Reference to the PointSnapper. </param>
public static void BuildSnappingExclusionSet(IMap aMap, ref ISet anExclLyrSet, string aStr, IPointSnapper pSnapper)
{
    ILayer aLyr = null;
    ICompositeLayer aCompLyr = null;
    IBasemapLayer aBmapLyr = null;
    IBasemapSubLayer aBmapSubLyr = null;
    for (int i = 0; i < aMap.LayerCount; i++)
    {
        aLyr = aMap.get_Layer(i);
        try     // Will work if this is some type of composite layer
        {
            aCompLyr = (ICompositeLayer)aLyr;
            aBmapLyr = (IBasemapLayer)aLyr;
            if (aBmapLyr != null) // basemap layer - must process differently
            {
                for (int j = 0; j < aCompLyr.Count; j++)
                {
                    aBmapSubLyr = (IBasemapSubLayer)aCompLyr.get_Layer(j);
                    aLyr = aBmapSubLyr.Layer;
                    if (aLyr.Name != aStr)
                        anExclLyrSet.Add(aBmapSubLyr.Layer);
                }
            }
            else // otherwise, process as an ordinary composite layer
            {
                for (int j = 0; j < aCompLyr.Count; j++)
                {
                    aLyr = aCompLyr.get_Layer(j);
                    if (aLyr.Name != aStr)
                        anExclLyrSet.Add(aLyr);
                }
            }
        }
        catch  // Implies not a composite layer - simply add to exclusion
        {
            if (aLyr.Name != aStr)
                anExclLyrSet.Add(aLyr);
        }

        pSnapper.ClearCache();
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.