View on GitHub Sample viewer app

Edit feature attributes which are linked to annotation through an expression.

Image of edit features with feature-linked annotation

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

  1. 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.
  2. Create FeatureLayers from GeodatabaseFeatureTables found in the geodatabase with Geodatabase.getGeodatabaseFeatureTable().
  3. Create AnnotationLayers from GeodatabaseFeatureTables found in the geodatabase with Geodatabase.getGeodatabaseAnnotationTables().
  4. Add the FeatureLayers and AnnotationLayers to the map’s operational layers.
  5. 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.
  6. 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.
  7. 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).

Both expressions were defined by the data author in ArcGIS Pro using the Arcade expression language.

Relevant API

  • AnnotationLayer
  • Feature
  • FeatureLayer
  • Geodatabase

About the data

This sample uses data derived from the Loudoun GeoHub.

Tags

annotation, attributes, features, feature-linked annotation, fields

Sample Code

module-info.java module-info.java EditAttributesDialog.java EditFeaturesWithFeatureLinkedAnnotationSample.java
/*
* Copyright 2022 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.
*/
module com.esri.samples.edit_features_with_feature_linked_annotation {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
requires javafx.fxml;
// make all @FXML annotated objects reflectively accessible to the javafx.fxml module
opens com.esri.samples.edit_features_with_feature_linked_annotation to javafx.fxml;
exports com.esri.samples.edit_features_with_feature_linked_annotation;
}