3636import com .esri .arcgisruntime .ArcGISRuntimeEnvironment ;
3737import com .esri .arcgisruntime .concurrent .ListenableFuture ;
3838import com .esri .arcgisruntime .data .Feature ;
39- import com .esri .arcgisruntime .data .FeatureEditResult ;
39+ import com .esri .arcgisruntime .data .FeatureTableEditResult ;
4040import com .esri .arcgisruntime .data .FeatureQueryResult ;
4141import com .esri .arcgisruntime .data .ServiceFeatureTable ;
42+ import com .esri .arcgisruntime .data .ServiceGeodatabase ;
4243import com .esri .arcgisruntime .layers .FeatureLayer ;
4344import com .esri .arcgisruntime .mapping .ArcGISMap ;
4445import com .esri .arcgisruntime .mapping .BasemapStyle ;
@@ -55,7 +56,7 @@ public class DeleteFeaturesSample extends Application {
5556 private ListenableFuture <FeatureQueryResult > selectionResult ;
5657
5758 private static final String FEATURE_LAYER_URL =
58- "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0 " ;
59+ "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer" ;
5960
6061 @ Override
6162 public void start (Stage stage ) {
@@ -106,32 +107,48 @@ public void start(Stage stage) {
106107 // set a viewpoint on the map view
107108 mapView .setViewpoint (new Viewpoint (40 , -95 , 36978595 ));
108109
109- // create service feature table from URL
110- featureTable = new ServiceFeatureTable (FEATURE_LAYER_URL );
110+ // create a service geodatabase from the service layer url and load it
111+ var serviceGeodatabase = new ServiceGeodatabase (FEATURE_LAYER_URL );
112+ serviceGeodatabase .addDoneLoadingListener (() -> {
111113
112- // create a feature layer from table
113- featureLayer = new FeatureLayer ( featureTable );
114+ // create a service feature table from the first layer on the service geodatabase's table
115+ featureTable = serviceGeodatabase . getTable ( 0 );
114116
115- // add the layer to the ArcGISMap
116- map .getOperationalLayers ().add (featureLayer );
117+ // create a feature layer from the feature table
118+ featureLayer = new FeatureLayer (featureTable );
119+
120+ // add the layer to the ArcGISMap
121+ map .getOperationalLayers ().add (featureLayer );
122+ });
123+ serviceGeodatabase .loadAsync ();
117124
118125 mapView .setOnMouseClicked (event -> {
119126 // check for primary or secondary mouse click
120127 if (event .isStillSincePress () && event .getButton () == MouseButton .PRIMARY ) {
121128 // create a point from where the user clicked
122129 Point2D point = new Point2D (event .getX (), event .getY ());
130+
131+ // clear any previous selection
132+ featureLayer .clearSelection ();
133+ deleteButton .setDisable (true );
134+
123135 // identify the clicked feature
124136 ListenableFuture <IdentifyLayerResult > results = mapView .identifyLayerAsync (featureLayer , point , 1 , false );
125137 results .addDoneListener (() -> {
126138 try {
127139 IdentifyLayerResult layer = results .get ();
128- // search the layers for identified features
129- List <Feature > features = layer .getElements ().stream ().filter (g -> g instanceof Feature ).map (
130- g -> (Feature ) g ).collect (Collectors .toList ());
131- // add the clicked feature to the selection
132- if (features .size () > 0 ) {
133- featureLayer .selectFeatures (features );
134- deleteButton .setDisable (false );
140+ if (!layer .getElements ().isEmpty ()) {
141+ // search the layers for identified features
142+ List <Feature > features = layer .getElements ()
143+ .stream ()
144+ .filter (g -> g instanceof Feature )
145+ .map (g -> (Feature ) g )
146+ .collect (Collectors .toList ());
147+ // add the clicked feature to the selection
148+ if (features .size () > 0 ) {
149+ featureLayer .selectFeatures (features );
150+ deleteButton .setDisable (false );
151+ }
135152 }
136153 } catch (InterruptedException | ExecutionException e ) {
137154 displayMessage ("Exception getting identify result" , e .getCause ().getMessage ());
@@ -169,16 +186,18 @@ private void deleteFeatures(FeatureQueryResult features, ServiceFeatureTable fea
169186 private void applyEdits (ServiceFeatureTable featureTable ) {
170187
171188 // apply the changes to the server
172- ListenableFuture <List <FeatureEditResult >> editResult = featureTable .applyEditsAsync ();
189+ ListenableFuture <List <FeatureTableEditResult >> editResult = featureTable . getServiceGeodatabase () .applyEditsAsync ();
173190 editResult .addDoneListener (() -> {
174191 try {
175- List <FeatureEditResult > edits = editResult .get ();
192+ List <FeatureTableEditResult > edits = editResult .get ();
176193 // check if the server edit was successful
177194 if (edits != null && edits .size () > 0 ) {
178- if (!edits .get (0 ).hasCompletedWithErrors ()) {
195+ var featureEditResult = edits .get (0 ).getEditResult ().get (0 );
196+ if (!featureEditResult .hasCompletedWithErrors ()) {
179197 displayMessage (null , "Feature successfully deleted" );
198+ deleteButton .setDisable (true );
180199 } else {
181- throw edits . get ( 0 ) .getError ();
200+ throw featureEditResult .getError ();
182201 }
183202 }
184203 } catch (InterruptedException | ExecutionException e ) {
0 commit comments