4242import com .esri .arcgisruntime .loadable .LoadStatus ;
4343import com .esri .arcgisruntime .mapping .ArcGISMap ;
4444import com .esri .arcgisruntime .mapping .Basemap ;
45+ import com .esri .arcgisruntime .mapping .ItemResourceCache ;
4546import com .esri .arcgisruntime .mapping .view .Graphic ;
4647import com .esri .arcgisruntime .mapping .view .GraphicsOverlay ;
4748import com .esri .arcgisruntime .mapping .view .MapView ;
4849import com .esri .arcgisruntime .portal .Portal ;
4950import com .esri .arcgisruntime .portal .PortalItem ;
5051import com .esri .arcgisruntime .security .AuthenticationManager ;
52+ import com .esri .arcgisruntime .security .Credential ;
5153import com .esri .arcgisruntime .security .OAuthConfiguration ;
5254import com .esri .arcgisruntime .symbology .SimpleLineSymbol ;
5355import com .esri .arcgisruntime .tasks .vectortilecache .ExportVectorTilesJob ;
@@ -77,22 +79,18 @@ public void start(Stage stage) throws Exception {
7779 // set the map to the map view
7880 mapView = new MapView ();
7981
82+ // authenticate with an organization account on arcgis.com
8083 AuthenticationDialog authenticationDialog = new AuthenticationDialog ();
81- authenticationDialog .show ();
8284 authenticationDialog .setOnCloseRequest (r -> {
8385
84- OAuthConfiguration configuration = authenticationDialog .getResult ();
86+ Credential credential = authenticationDialog .getResult ();
8587 // check that configuration was made
86- if (configuration != null ) {
87- AuthenticationManager .addOAuthConfiguration (configuration );
88-
89- Portal portal = new Portal ("http://" + configuration .getPortalUrl (), true );
88+ if (credential != null ) {
9089
91- // setup the handler that will prompt an authentication challenge to the user
92- OAuthChallengeHandler challengeHandler = new OAuthChallengeHandler (portal );
93- AuthenticationManager .setAuthenticationChallengeHandler (challengeHandler );
90+ Portal portal = new Portal ("http://www.arcgis.com" , true );
91+ portal .setCredential (credential );
9492
95- PortalItem portalItem = new PortalItem (portal , "8e848d9302e84dcba0de7aff8ac429dc " );
93+ PortalItem portalItem = new PortalItem (portal , "86f556a2d1fd468181855a35e344567f " );
9694
9795 // loading the vector tiled layer will invoke the authentication challenge
9896 ArcGISVectorTiledLayer vectorTiledLayer = new ArcGISVectorTiledLayer (portalItem );
@@ -101,8 +99,12 @@ public void start(Stage stage) throws Exception {
10199 // set the layer as the map's basemap
102100 ArcGISMap map = new ArcGISMap (new Basemap (vectorTiledLayer ));
103101 mapView .setMap (map );
102+ } else {
103+ Alert alert = new Alert (Alert .AlertType .ERROR , "Item requires authentication." );
104+ alert .show ();
104105 }
105106 });
107+ authenticationDialog .show ();
106108
107109 // create a graphics overlay for the map view
108110 GraphicsOverlay graphicsOverlay = new GraphicsOverlay ();
@@ -143,31 +145,34 @@ public void start(Stage stage) throws Exception {
143145 // when the button is clicked, export the tiles to a temporary file
144146 exportTilesButton .setOnAction (e -> {
145147 try {
146- File tempFile = File .createTempFile ("tiles" , ".vtpk" );
147- File styleDir = Files .createTempDirectory ("StyleItemResources" ).toFile ();
148+ File vtpkFile = File .createTempFile ("tiles" , ".vtpk" );
149+ File resDir = Files .createTempDirectory ("StyleItemResources" ).toFile ();
148150 progressBar .setVisible (true );
149151 Layer layer = mapView .getMap ().getBasemap ().getBaseLayers ().get (0 );
150152 double maxScale = layer .getMaxScale ();
151153 ExportVectorTilesTask task = new ExportVectorTilesTask ((PortalItem ) layer .getItem ());
152- ListenableFuture <ExportVectorTilesParameters > createParams = task . createDefaultExportVectorTilesParametersAsync ( downloadArea
153- .getGeometry (), maxScale );
154+ ListenableFuture <ExportVectorTilesParameters > createParams = task
155+ .createDefaultExportVectorTilesParametersAsync ( downloadArea . getGeometry (), maxScale );
154156 createParams .addDoneListener (() -> {
155157 try {
156158 ExportVectorTilesParameters params = createParams .get ();
157- ExportVectorTilesJob job = task .exportVectorTiles (params , tempFile .getAbsolutePath (), styleDir .getAbsolutePath ());
159+ ExportVectorTilesJob job = task .exportVectorTiles (params , vtpkFile .getAbsolutePath (), resDir
160+ .getAbsolutePath ());
158161 job .start ();
159162 job .addProgressChangedListener (() -> progressBar .setProgress (job .getProgress () / 100.0 ));
160163 job .addJobDoneListener (() -> {
161164 if (job .getStatus () == Job .Status .SUCCEEDED ) {
162165 // show preview of exported tiles in alert
163166 ExportVectorTilesResult tilesResult = job .getResult ();
164167 VectorTileCache tileCache = tilesResult .getVectorTileCache ();
168+ ItemResourceCache resourceCache = tilesResult .getItemResourceCache ();
165169 Alert preview = new Alert (Alert .AlertType .INFORMATION );
166170 preview .setTitle ("Preview" );
167- preview .setHeaderText ("Exported to " + tileCache .getPath ());
171+ preview .setHeaderText ("Exported tiles to " + tileCache .getPath () + "\n Exported resources to " +
172+ resourceCache .getPath ());
168173 MapView mapPreview = new MapView ();
169174 mapPreview .setMinSize (400 , 400 );
170- ArcGISVectorTiledLayer tiledLayerPreview = new ArcGISVectorTiledLayer (tileCache , tilesResult . getItemResourceCache () );
175+ ArcGISVectorTiledLayer tiledLayerPreview = new ArcGISVectorTiledLayer (tileCache , resourceCache );
171176 ArcGISMap previewMap = new ArcGISMap (new Basemap (tiledLayerPreview ));
172177 mapPreview .setMap (previewMap );
173178 preview .getDialogPane ().setContent (mapPreview );
0 commit comments