Adding Many Features to a FeatureSet

Presuming that you are creating a FeatureSet from scratch, you will have to add the features to the featureset. However, when this FeatureSet is part of a layer, already, then it will initiate a re-draw every time a new feature is added. This is useful for cases where you add one feature to an existing layer and you expect it to appear. It can be a problem for performance, however, if you add a large number of features at once. The example below illustrates how to suspend the events on the FeatureSet temporarily, allowing you to add the features more quickly. When you are done, a single event will be fired during the resume events section, allowing the map to update.

private void AddRange(Feature[] features)
{
    FeatureSet fs = new FeatureSet();
    fs.Features.SuspendEvents();
    for (int i = 0; i < features.Length; i++ )
    {
        fs.Features.Add(features[i]);
    }
    fs.Features.ResumeEvents();
}

Last edited Mar 6, 2010 at 4:45 PM by Shade1974, version 1

Comments

No comments yet.