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
IFeatureEditConfiguration
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.
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;
};
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();
}
}
public static class FilteringEditConfiguration implements IFeatureEditConfiguration {
private final DataPropertyPath somePropertyPath;
public FilteringEditConfiguration(DataPropertyPath somePropertyPath) {
this.somePropertyPath = somePropertyPath;
}
@Override
public void edit(Feature feature, long layerId, Map map, FeatureEditConfigurationBuilder builder) {
if (feature.<Long>getValue(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.
auto editConfiguration = std::make_shared<FilteringEditConfiguration>(somePropertyPath);
auto layerBuilder = FeatureLayer::newBuilder().model(model).editConfiguration(std::move(editConfiguration));
auto layer = layerBuilder.build();
var editConfiguration = new FilteringEditConfiguration(somePropertyPath);
var layerBuilder = FeatureLayer.NewBuilder()
.Model(model)
.EditConfiguration(editConfiguration);
var layer = layerBuilder.Build();
IFeatureEditConfiguration editConfiguration = new FilteringEditConfiguration(somePropertyPath);
FeatureLayer.Builder layerBuilder = FeatureLayer.newBuilder()
.model(model)
.editConfiguration(editConfiguration);
FeatureLayer layer = layerBuilder.build();