3737public class FeatureLayerDictionaryRendererSample extends Application {
3838
3939 private MapView mapView ;
40- // keep loadables in scope to avoid garbage collection
41- private Geodatabase geodatabase ;
42- private FeatureLayer featureLayer ;
40+ private Geodatabase geodatabase ; // keep loadable in scope to avoid garbage collection
4341
4442 @ Override
4543 public void start (Stage stage ) {
@@ -63,46 +61,63 @@ public void start(Stage stage) {
6361 ArcGISMap map = new ArcGISMap (BasemapStyle .ARCGIS_TOPOGRAPHIC );
6462 mapView .setMap (map );
6563
66- // load geo-database from local location
64+ // define and load a dictionary symbol style from a local style file
65+ File stylxFile = new File (System .getProperty ("data.dir" ), "./samples-data/stylx/mil2525d.stylx" );
66+ var dictionarySymbolStyle = DictionarySymbolStyle .createFromFile (stylxFile .getAbsolutePath ());
67+ dictionarySymbolStyle .loadAsync ();
68+
69+ // create a new geodatabase instance from the geodatabase stored at the local location
6770 File geodatabaseFile = new File (System .getProperty ("data.dir" ), "./samples-data/dictionary/militaryoverlay" +
68- ".geodatabase" );
71+ ".geodatabase" );
6972 geodatabase = new Geodatabase (geodatabaseFile .getAbsolutePath ());
70- geodatabase .loadAsync ();
71-
72- // render tells layer what symbols to apply to what features
73- File stylxFile = new File (System .getProperty ("data.dir" ), "./samples-data/stylx/mil2525d.stylx" );
74- DictionarySymbolStyle symbolDictionary = DictionarySymbolStyle .createFromFile (stylxFile .getAbsolutePath ());
75- symbolDictionary .loadAsync ();
7673
7774 geodatabase .addDoneLoadingListener (() -> {
75+ // check if the geodatabase has loaded successfully
7876 if (geodatabase .getLoadStatus () == LoadStatus .LOADED ) {
79- geodatabase .getGeodatabaseFeatureTables ().forEach (table -> {
80- // add each layer to map
81- featureLayer = new FeatureLayer (table );
82- featureLayer .loadAsync ();
83- // Features no longer show after this scale
84- featureLayer .setMinScale (1000000 );
85- map .getOperationalLayers ().add (featureLayer );
86-
87- // displays features from layer using mil2525d symbols
88- DictionaryRenderer dictionaryRenderer = new DictionaryRenderer (symbolDictionary );
89- featureLayer .setRenderer (dictionaryRenderer );
90-
91- featureLayer .addDoneLoadingListener (() -> {
92- if (featureLayer .getLoadStatus () == LoadStatus .LOADED ) {
93- // initial viewpoint to encompass all graphics displayed on the map view
94- mapView .setViewpointGeometryAsync (featureLayer .getFullExtent ());
95- } else {
96- Alert alert = new Alert (Alert .AlertType .ERROR , "Feature Layer Failed to Load!" );
97- alert .show ();
98- }
99- });
77+ var mapOperationalLayersList = map .getOperationalLayers ();
78+ var geodatabaseFeatureTablesList = geodatabase .getGeodatabaseFeatureTables ();
79+
80+ geodatabaseFeatureTablesList .forEach (table -> {
81+ // create a new feature layer from each geodatabase feature table and
82+ // add it to the map's list of operational layers
83+ mapOperationalLayersList .add (new FeatureLayer (table ));
10084 });
85+
86+ // check the map operational layers size matches that of the geodatabase's feature tables size
87+ if (!mapOperationalLayersList .isEmpty () && mapOperationalLayersList .size () == geodatabaseFeatureTablesList .size ()) {
88+
89+ // check that each layer has loaded correctly and if not display an error message
90+ mapOperationalLayersList .forEach (layer ->
91+ layer .addDoneLoadingListener (() -> {
92+ if (layer .getLoadStatus () == LoadStatus .LOADED ) {
93+
94+ // set the feature layer's minimum scale so that features no longer show after this scale
95+ layer .setMinScale (1000000 );
96+
97+ // set the dictionary renderer as the feature layer's renderer
98+ if (layer instanceof FeatureLayer ) {
99+ ((FeatureLayer ) layer ).setRenderer (new DictionaryRenderer (dictionarySymbolStyle ));
100+ }
101+
102+ // set the map view viewpoint
103+ mapView .setViewpointGeometryAsync (layer .getFullExtent ());
104+
105+ } else {
106+ new Alert (Alert .AlertType .ERROR ,
107+ "Feature layer failed to load: " + layer .getLoadError ().getCause ().getMessage ()).show ();
108+ }
109+ })
110+ );
111+ } else {
112+ new Alert (Alert .AlertType .ERROR , "Error: Map operational list size does not match geodatabase feature table list size" ).show ();
113+ }
101114 } else {
102- Alert alert = new Alert (Alert .AlertType .ERROR , "Geodatabase Failed to Load!" );
103- alert .show ();
115+ new Alert (Alert .AlertType .ERROR , "Geodatabase Failed to Load!" ).show ();
104116 }
105117 });
118+
119+ // load the geodatabase
120+ geodatabase .loadAsync ();
106121 }
107122
108123 /**
0 commit comments