Edit feature attributes which are linked to annotation through an expression.
Use case
Annotation is useful for displaying text that you don't want to move or resize when the map is panned or zoomed (unlike labels which will move and resize). Feature-linked annotation will update when a feature attribute referenced by the annotation expression is also updated. Additionally, the position of the annotation will transform to match any transformation to the linked feature's geometry.
How to use the sample
Pan and zoom the map to see that the text on the map is annotation, not labels. Click one of the address points to update the house number (AD_ADDRESS) and street name (ST_STR_NAM). Once you have edited the feature attributes, click "Update" and then click again on the map to move the address point to a new location. You can also click one of the dashed parcel polylines and click another location to change its geometry and update its annotation (distance in feet). NOTE: Selection is only enabled for points and straight (single segment) polylines.
The feature-linked annotation will update accordingly.
How it works
Load the geodatabase. NOTE: Read/write geodatabases should normally come from a GeodatabaseSyncTask, but this has been omitted here. That functionality is covered in the sample Generate geodatabase.
Create FeatureLayers from GeodatabaseFeatureTables found in the geodatabase with Geodatabase.getGeodatabaseFeatureTable().
Create AnnotationLayers from GeodatabaseFeatureTables found in the geodatabase with Geodatabase.getGeodatabaseAnnotationTables().
Add the FeatureLayers and AnnotationLayers to the map's operational layers.
Use MapView.setOnMouseClicked() to handle clicks on the map to either select address points or parcel polyline features. NOTE: Selection is only enabled for points and straight (single segment) polylines.
For the address points, a dialog opens to allow editing of the address number (AD_ADDRESS) and street name (ST_STR_NAM) attributes, which use the expression $feature.AD_ADDRESS + " " + $feature.ST_STR_NAM for annotation.
For the parcel lines, a second mouse click will change one of the polyline's vertices. Note that the dimension annotation updates according to the expression Round(Length(Geometry($feature), 'feet'), 2).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright 2020 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/package com.esri.samples.edit_features_with_feature_linked_annotation;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextField;
import com.esri.arcgisruntime.data.Feature;
/**
* Custom dialog for editing feature attributes.
*/publicclassEditAttributesDialogextendsDialog<Boolean>{
@FXMLprivate TextField addressTextField;
@FXMLprivate TextField streetNameTextField;
@FXMLprivate ButtonType updateButton;
EditAttributesDialog(Feature selectedFeature){
FXMLLoader loader = new FXMLLoader(getClass().getResource("/edit_features_with_feature_linked_annotation/edit_attributes_dialog.fxml"));
loader.setRoot(this);
loader.setController(this);
setTitle("Edit Feature Attributes");
try {
loader.load();
} catch (Exception e) {
e.printStackTrace();
}
// populate text fields with current attribute values addressTextField.setText(selectedFeature.getAttributes().get("AD_ADDRESS").toString());
streetNameTextField.setText(selectedFeature.getAttributes().get("ST_STR_NAM").toString());
// convert the result to an address and street name when the update button is clicked setResultConverter(dialogButton -> {
if (dialogButton == updateButton) {
try {
// ensure input is equal to or less than 5 characters (max length for addresses in area)if (addressTextField.getLength() <= 5){
// set AD_ADDRESS value to the int from the text field selectedFeature.getAttributes().put("AD_ADDRESS", Integer.parseInt(addressTextField.getText()));
} else {
new Alert(Alert.AlertType.WARNING, "Field not updated. Integer must be less than 6 characters").showAndWait();
}
// set ST_STR_NAM value to the string from the text field selectedFeature.getAttributes().put("ST_STR_NAM", streetNameTextField.getText());
} catch (Exception e) {
e.printStackTrace();
}
returntrue;
}
returnnull;
});
}
}