This article describes how to make a feature layer editable or not editable. For a feature layer to be editable, it has to meet these requirements:
-
Its model is editable. A model is editable when it has an
IFeatureModelUpdater
IFeatureModelUpdater
IFeatureModelUpdater
-
Its editable field is
true
. -
It has an
IFeatureEditConfiguration
IFeatureEditConfiguration
IFeatureEditConfiguration
.
Step 1 - Create an editable layer
By default, the FeatureLayer builder
FeatureLayer builder
FeatureLayer builder
creates non-editable feature layers. You can specify the editable flag, the edit configuration, or both. If you set only
the flag to true
, a default IFeatureEditConfiguration
IFeatureEditConfiguration
IFeatureEditConfiguration
is created and used.
This configuration marks all features as editable.
If you set only the configuration, the editable flag is set to true
automatically.
If you want a layer that is initially not editable, but that you can toggle to an editable layer later, you must set a valid
IFeatureEditConfiguration
IFeatureEditConfiguration
IFeatureEditConfiguration
,
and set the editable flag to false
in the builder.
// non editable layer by default
auto nonEditableLayer = FeatureLayer::newBuilder().model(model).build();
// editable layer using a default edit configuration.
auto defaultConfigLayer = FeatureLayer::newBuilder().model(model).editable(true).build();
// editable layer using a non-default edit configuration.
auto myEditConfiguration = std::make_shared<SimpleEditConfiguration>();
auto customConfigLayer = FeatureLayer::newBuilder().model(model).editConfiguration(myEditConfiguration).build();
// editable layer but initially read-only
auto readOnlyLayer = FeatureLayer::newBuilder().model(model).editConfiguration(myEditConfiguration).editable(false).build();
// non editable layer by default
var nonEditableLayer = FeatureLayer.NewBuilder().Model(model).Build();
// editable layer using a default edit configuration.
var defaultConfigLayer = FeatureLayer.NewBuilder().Model(model).Editable(true).Build();
// editable layer using a non-default edit configuration.
var myEditConfiguration = new SimpleEditConfiguration();
var customConfigLayer =
FeatureLayer.NewBuilder().Model(model).EditConfiguration(myEditConfiguration).Build();
// editable layer but initially read-only.
var readOnlyLayer = FeatureLayer.NewBuilder().Model(model).EditConfiguration(myEditConfiguration)
.Editable(false).Build();
// non editable layer by default
FeatureLayer nonEditableLayer = FeatureLayer.newBuilder()
.model(model)
.build();
// editable layer using a default edit configuration.
FeatureLayer defaultConfigLayer = FeatureLayer.newBuilder()
.model(model)
.editable(true)
.build();
// editable layer using a non-default edit configuration.
SimpleEditConfiguration myEditConfiguration = new SimpleEditConfiguration();
FeatureLayer customConfigLayer = FeatureLayer.newBuilder()
.model(model)
.editConfiguration(myEditConfiguration)
.build();
// editable layer but initially read-only.
FeatureLayer readOnlyLayer = FeatureLayer.newBuilder()
.model(model)
.editConfiguration(myEditConfiguration)
.editable(false)
.build();
Step 2 - Toggle the editing
To allow features to be edited on a layer with a IFeatureEditConfiguration
IFeatureEditConfiguration
IFeatureEditConfiguration
, change the editable flag.
readOnlyLayer->setEditable(true);
readOnlyLayer.IsEditable = true;
readOnlyLayer.setEditable(true);