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: 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;
};

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: Use edit configuration
auto editConfiguration = std::make_shared<FilteringEditConfiguration>(somePropertyPath);
auto layerBuilder = FeatureLayer::newBuilder().model(model).editConfiguration(std::move(editConfiguration));
auto layer = layerBuilder.build();