Select to view content in your preferred language

Load and display local shapefile on a disconnected system

1645
2
03-08-2021 04:50 AM
Labels (1)
GiridharPragada
New Contributor

Hi,

I am building an offline (permanently disconnected system) application. I need to load a combination of raster and shapefiles as different layers. Is there a sample program available to demonstrate this in 100.9 or above. 

Is it also possible to load and display it without the base map?

thanks in advance

Giridhar

 

TileCache tileCache = new TileCache("\local_server\mpk_blank.mpk");
ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tileCache);
Basemap basemap = new Basemap(tiledLayer);
// ArcGISMap map = new ArcGISMap(Basemap.createStreetsVector());
ArcGISMap map = new ArcGISMap(basemap);

mapView = new MapView();
mapView.setMap(map);

// create a shapefile feature table from the local file
File shapefile = new File(System.getProperty("data.dir"), "\san_diego_boundary_datasd.shp");
ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(shapefile.getAbsolutePath());
// use the shapefile feature table to create a feature layer
featureLayer = new FeatureLayer(shapefileFeatureTable);
featureLayer.addDoneLoadingListener(() -> {
if (featureLayer.getLoadStatus() == LoadStatus.LOADED) {
Alert alert = new Alert(Alert.AlertType.INFORMATION, "loaded success...");
alert.show();
} else {
Alert alert = new Alert(Alert.AlertType.ERROR, featureLayer.getLoadError().getMessage());
alert.show();
}
});

// add the feature layer to the map
map.getOperationalLayers().add(featureLayer);
//add the map view to the stack pane
stackPane.getChildren().add(mapView);

0 Kudos
2 Replies
TroyFoster
Frequent Contributor

Yes it is possible, in Qt/c++ at least.  You can call "featureLayer.load();" right before you add the feature layer to the operationalLayers.

0 Kudos
GiridharPragada
New Contributor

Thanks for the reply. 

I still don't see anything on the map in disconnected mode. Any suggestion on what could be wrong here?

//////////////////////////////////////////////////////////////////////////

public class LocalServerMapImageLayerSample extends Application {

private static final int APPLICATION_WIDTH = 800;

private ArcGISMapImageLayer imageLayer; // keep loadable in scope to avoid garbage collection
private MapView mapView;
private LocalMapService mapImageService;
private ProgressIndicator imageLayerProgress;

@Override
public void start(Stage stage) {

try {
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);

// set title, size, and add scene to stage
stage.setTitle("Local Server Map Image Layer Sample");
stage.setWidth(APPLICATION_WIDTH);
stage.setHeight(700);
stage.setScene(scene);
stage.show();

// create a view with a map and basemap
ArcGISMap map = new ArcGISMap(Basemap.createStreets());
mapView = new MapView();
mapView.setMap(map);

// track progress of loading map image layer to map
imageLayerProgress = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS);
imageLayerProgress.setMaxWidth(30);

// check that local server install path can be accessed
if (LocalServer.INSTANCE.checkInstallValid()) {
LocalServer server = LocalServer.INSTANCE;
// start local server
server.addStatusChangedListener(status -> {
if (status.getNewStatus() == LocalServerStatus.STARTED) {
// start map image service
String mapServiceURL = new File(System.getProperty("data.dir"), "C:\\GISData\\data\\mpks\\PointsofInterest.mpk").getAbsolutePath();
mapImageService = new LocalMapService(mapServiceURL);
mapImageService.addStatusChangedListener(this::addLocalMapImageLayer);
mapImageService.startAsync();
}
});
server.startAsync();
} else {
Platform.runLater(() -> {
Alert dialog = new Alert(AlertType.INFORMATION);
dialog.initOwner(mapView.getScene().getWindow());
dialog.setHeaderText("Local Server Load Error");
dialog.setContentText("Local Geoprocessing Failed to load.");
dialog.show();
});
}

// add view to application window with progress bar
stackPane.getChildren().addAll(mapView, imageLayerProgress);
StackPane.setAlignment(imageLayerProgress, Pos.CENTER);
} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
}
}

/**
* Once the map service starts, a map image layer is created from that service and added to the map.
* <p>
* When the map image layer is done loading, the view will zoom to the location of were the image has been added.
*
* @param status status of feature service
*/
private void addLocalMapImageLayer(StatusChangedEvent status) {

// check that the map service has started
if (status.getNewStatus() == LocalServerStatus.STARTED && mapView.getMap() != null) {
// get the url of where map service is located
String url = mapImageService.getUrl();
// create a map image layer using url
imageLayer = new ArcGISMapImageLayer(url);
// set viewpoint once layer has loaded
imageLayer.addDoneLoadingListener(() -> {
Envelope extent = imageLayer.getFullExtent();
if (imageLayer.getLoadStatus() == LoadStatus.LOADED && extent != null) {
mapView.setViewpoint(new Viewpoint(extent));
Platform.runLater(() -> imageLayerProgress.setVisible(false));
} else {
Alert alert = new Alert(Alert.AlertType.ERROR, "Image Layer Failed to Load!");
alert.show();
}
});
imageLayer.loadAsync();
// add image layer to map
mapView.getMap().getOperationalLayers().add(imageLayer);
}
}

0 Kudos