You will learn: how to build an app to load and display a web map from ArcGIS Online.
A web map is a JSON structure that contains the settings required to display a 2D map. ArcGIS and custom applications can load web maps and automatically configure the map extent, basemap, layers and styles, pop-ups, labels and more. Web maps can be created interactively with the Map Viewer and ArcGIS Pro. Web maps are stored in ArcGIS Online or ArcGIS Enterprise as an item with a unique ID.
In this tutorial, you will build an app that loads and displays a web map.
Make sure you have installed the latest version of Android Studio.
If you have completed the Create a starter app tutorial, then copy the project into a new empty folder. Otherwise, download and unzip the project solution. Open, run, and verify the map displays in the device simulator.
Go to the LA Trails and Parks Map to view the map in the Map Viewer. Make note of the ID at the end of the URL.
In the file app > java > {your.package.name} > MainActivity.java, locate the setupMap()
member function. Change the way the ArcGISMap
is initialized to reference the web map that was created in the Configure pop-ups design tutorial. Create the web map given its item ID and the portal where it is located.
private void setupMap() {
if (mMapView != null) {
String itemId = "41281c51f9de45edaf1c8ed44bb10e30";
Portal portal = new Portal("https://www.arcgis.com", false);
PortalItem portalItem = new PortalItem(portal, itemId);
ArcGISMap map = new ArcGISMap(portalItem);
mMapView.setMap(map);
}
}
Press Control-R to run your project in the simulator.
Your map should show trails, trail heads and parks in the Santa Monica Mountains. Compare your solution with our completed solution project.
Instead of using the web map we prepared, use the web map you made in the design tutorial Create a Web Map (2D).
Replace the itemId
variable with the ID of your own web map.
Open your web map in the map viewer, make changes to your map design, then save your map. Next time you load that map in your app your changes will be reflected.