This article describes how to configure a custom edit configuration on a layer. With such a custom configuration, we can make only specific features editable.

Step 1 - Create the edit configuration and implement its methods

We must create our own implementation of IFeatureEditConfiguration. In this class, we can check which features should be editable, and call either submit() or notEditable() on the builder. For this use case, we filter on the "someProperty" property of the feature and accept the feature only if the property value is even.

Program (C++): Create an edit configuration
class FilteringEditConfiguration : public IFeatureEditConfiguration {
public:
  explicit FilteringEditConfiguration(const DataPropertyPath& dataPropertyPath) : _somePropertyPath(dataPropertyPath) {
  }

  void edit(const Feature& feature, LayerId /*layerId*/, const std::shared_ptr<Map>& /*map*/, FeatureEditConfigurationBuilder& builder) const override {
    if (std::fmod(feature.getValue<int64_t>(*_somePropertyPath).value(), 2) == 1) {
      builder.notEditable();
      return;
    }
    builder.submit();
  }

private:
  std::optional<DataPropertyPath> _somePropertyPath;
};

C#

private sealed class FilteringEditConfiguration : IFeatureEditConfiguration
{
    private DataPropertyPath _somePropertyPath;

    public FilteringEditConfiguration(DataPropertyPath somePropertyPath)
    {
        _somePropertyPath = somePropertyPath;
    }

    public void Edit(Feature feature, ulong layerId, Map map, FeatureEditConfigurationBuilder builder)
    {
        if (feature.GetValue<long?>(_somePropertyPath) % 2 == 1)
        {
            builder.NotEditable();
            return;
        }

        builder.Submit();
    }
}

Step 2 - Use the edit configuration

The next step is to use an instance of our custom edit configuration in the feature layer creation.

Program (C++): Use edit configuration
auto editConfiguration = std::make_shared<FilteringEditConfiguration>(somePropertyPath);
auto layerBuilder = FeatureLayer::newBuilder().model(model).editConfiguration(std::move(editConfiguration));
auto layer = layerBuilder.build();

C#

var editConfiguration = new FilteringEditConfiguration(somePropertyPath);
var layerBuilder = FeatureLayer.NewBuilder()
    .Model(model)
    .EditConfiguration(editConfiguration);
var layer = layerBuilder.Build();