|
48 | 48 | import com.esri.arcgisruntime.mapping.view.MapView; |
49 | 49 | import com.esri.arcgisruntime.portal.Portal; |
50 | 50 | import com.esri.arcgisruntime.portal.PortalItem; |
51 | | -import com.esri.arcgisruntime.security.Credential; |
| 51 | +import com.esri.arcgisruntime.security.AuthenticationManager; |
| 52 | +import com.esri.arcgisruntime.security.DefaultAuthenticationChallengeHandler; |
52 | 53 | import com.esri.arcgisruntime.symbology.SimpleLineSymbol; |
53 | 54 | import com.esri.arcgisruntime.tasks.vectortilecache.ExportVectorTilesJob; |
54 | 55 | import com.esri.arcgisruntime.tasks.vectortilecache.ExportVectorTilesParameters; |
@@ -78,31 +79,23 @@ public void start(Stage stage) throws Exception { |
78 | 79 | mapView = new MapView(); |
79 | 80 |
|
80 | 81 | // authenticate with an organization account on arcgis.com |
81 | | - AuthenticationDialog authenticationDialog = new AuthenticationDialog(); |
82 | | - authenticationDialog.setOnCloseRequest(r -> { |
83 | | - |
84 | | - Credential credential = authenticationDialog.getResult(); |
85 | | - // check that configuration was made |
86 | | - if (credential != null) { |
87 | | - |
88 | | - Portal portal = new Portal("http://www.arcgis.com", true); |
89 | | - portal.setCredential(credential); |
90 | | - |
91 | | - PortalItem portalItem = new PortalItem(portal, "86f556a2d1fd468181855a35e344567f"); |
| 82 | + AuthenticationManager.setAuthenticationChallengeHandler(new DefaultAuthenticationChallengeHandler()); |
92 | 83 |
|
| 84 | + // get the portal item of the vector tile service |
| 85 | + Portal portal = new Portal("http://www.arcgis.com", true); |
| 86 | + PortalItem portalItem = new PortalItem(portal, "86f556a2d1fd468181855a35e344567f"); |
| 87 | + portalItem.addDoneLoadingListener(() -> { |
| 88 | + if (portalItem.getLoadStatus() == LoadStatus.LOADED) { |
93 | 89 | // loading the vector tiled layer will invoke the authentication challenge |
94 | 90 | ArcGISVectorTiledLayer vectorTiledLayer = new ArcGISVectorTiledLayer(portalItem); |
95 | | - vectorTiledLayer.loadAsync(); |
96 | | - |
97 | | - // set the layer as the map's basemap |
98 | 91 | ArcGISMap map = new ArcGISMap(new Basemap(vectorTiledLayer)); |
99 | 92 | mapView.setMap(map); |
100 | 93 | } else { |
101 | | - Alert alert = new Alert(Alert.AlertType.ERROR, "Item requires authentication."); |
| 94 | + Alert alert = new Alert(Alert.AlertType.ERROR, portalItem.getLoadError().getCause().getMessage()); |
102 | 95 | alert.show(); |
103 | 96 | } |
104 | 97 | }); |
105 | | - authenticationDialog.show(); |
| 98 | + portalItem.loadAsync(); |
106 | 99 |
|
107 | 100 | // create a graphics overlay for the map view |
108 | 101 | GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); |
@@ -166,7 +159,7 @@ public void start(Stage stage) throws Exception { |
166 | 159 | ItemResourceCache resourceCache = tilesResult.getItemResourceCache(); |
167 | 160 | Alert preview = new Alert(Alert.AlertType.INFORMATION); |
168 | 161 | preview.setTitle("Preview"); |
169 | | - preview.setHeaderText("Exported tiles to " + tileCache.getPath() + "\n Exported resources to " + |
| 162 | + preview.setHeaderText("Exported tiles to " + tileCache.getPath() + "\nExported resources to " + |
170 | 163 | resourceCache.getPath()); |
171 | 164 | MapView mapPreview = new MapView(); |
172 | 165 | mapPreview.setMinSize(400, 400); |
|
0 commit comments