A map is a canvas that draws layers of geographic data. Different layer types are used to draw different data types. For example, you may have data that is provided by a service or from local files; the data might be static in nature, or change over time. Maps can also show information relating to the map and its layers, such as GPS locations, and pop-ups.
A MapView is a component that allows you to draw a map in an Android app. This class inherits from the Android ViewGroup class, and acts as a container of one or more Layer objects. Properties of a MapView can be easily initialized by using MapOptions in layout XML or when creating a MapView programmatically.
To enable the workflows your app requires, and to maximize display performance, always consider the factors below when you create your map.
Layers can generally be thought of as basemaps, operational, or graphics layers, depending on the data they display and how they are used, with each type of layer offering different functionality and performance characteristics.
- Background data that provides context and does not change often is generally considered as the basemap, for example, topography, imagery, streets, or buildings data. Basemap data is generally prepared and cached on a server as ready-to-access image tiles that are efficient to request and display in an app. ArcGIS Online provides a free set of ready-to-use basemap layers that are pre-rendered and cached to ensure they draw quickly. Alternatively, you can use the ArcGIS platform to create your own basemaps. For details on functionality and performance, see Basemap layers in the Layer types topic. For details on using offline basemaps, see Create an offline map.
- Data edited by app users, periodically changing data, or data resulting from analyses, may best be considered as operational layers. Typically, operational data is created and maintained by your organization. Displaying or working with operational data is often the main focus of an app. For details on functionality and performance and how to take operational layers offline, see Operational layers in the Layer types topic.
- Live, rapidly changing, ephemeral data may be appropriate for a graphics layer. For example, vehicle or workforce locations, geotriggered events, or temporary query results. Graphics are generated in memory in an app, or created in an app based on an external information feed. For details on functionality and performance, see Graphics layers in the Layer types topic.
Other types of specialized layers provide the ability to add a wide range of data and services to a map, for example WMS services and KML.
A wide variety of layer classes are provided by the API. Each can be used to display a specific data type, and each has its own functionality and performance characteristics. Generally, each layer class is used for basemap, operational, or graphics layers. However, these are not absolute rules, and the choice of class should be based on an understanding of the characteristics of each type. For information on the functionality and performance of different types of layers, see Layer types.
The layer order in a map is important. Basemaps typically cover the entire surface of the map. They are added to the map first so that they draw under the layer and do not obscure other layers. Layers can be re-ordered, but this will not change the map's spatial reference.
Add operational layers to the map next. Graphics layers are typically added last and show on top of all other layers.
Maps and layers use spatial references to help define where coordinates are located on the earth's surface. Distance units and coordinates of map operations are determined by the spatial reference of the map. The first layer in a map, typically the basemap, defines the spatial reference of the map, and this cannot be changed. If creating a MapView programmatically, the spatial reference of the map can be set by using the overloaded constructor that includes a SpatialReference parameter.
If the spatial reference of layers in a map are different to the spatial reference of the map, the layers must be reprojected to the spatial reference of the map before displaying. Some layer types cannot be re-projected, for example, tiled map layer services draw and cache on a server, and cannot be changed on the client.
To maximize performance, avoid reprojection entirely by ensuring all layers have the same spatial reference as the map.
Choose how to author a map
You can author a map in ArcGIS Online, add the data layers you require, define how the layers should appear, and use this map in your app. If creating a MapView programmatically, use the WebMap class to load a web map from a Portal and pass it to the overloaded MapView constructor. Alternatively, you can load a WebMap and add the layers to a MapView that already exists.
This allows you to interactively experiment with many aspects of the appearance and behavior of the map layers, and immediately view your changes online. By loading an online map in your app, you also gain the advantage of a centrally managed map, with the ability to change the map online independent of your application code, reducing the need for application redeployment. It is also easier to offer the user a choice of pre-defined online maps to open using the Portal API. Note that online maps may only contain online data.
Alternatively, you can build a map by defining and adding layers at runtime programmatically, or even add code to allow your users to add their layers. You can also make temporary changes to a map that you created online, by adding or removing layers, and changing a layer's appearance. This approach enables you to add offline layers to your map, and offers the flexibility of programmatic control, but lacks the centralized maintainable map. Create Layer objects and add them directly to the MapView using the addLayer method.
It is not possible to directly load map package (MPK) files or map documents saved from ArcGIS for Desktop into the map.
Behavior at runtime
Also consider how the map draws and behaves at runtime, and how the user interacts with it.
Map and layer initialization
Maps are initialized asynchronously after being created. Layers are also initialized asynchronously when added to the map. Attempting to access certain properties or operations of the map or its layers before they are initialized may throw errors. For example, getting the spatial reference or center of a map, or the name or extent of a layer. You can set the OnStatusChangedListener of a MapView so that you can run code upon initialization. You can also use this listener to find out if there are problems loading any of your layers. It's also good practice to set the initial extent of the map to ensure the user starts in a location relevant to the map's usage. You can use MapOptions to initialize a number of map properties in your layout XML.
Most flat representations of the world only extend to 180 degrees east and west longitude, the approximate location of the international date line, making it more difficult to visualize routes or shapes that cross the pacific ocean. However, the map can be configured to display the eastern and western hemispheres wrapping around each other and forming a continuous surface, giving the impression that the map is endless. Panning a map becomes similar to spinning a globe. See Enable wraparound around to learn how to display a wrap around map
Navigation and interaction
Consider what actions or gestures you enable to allow users to zoom, pan, and rotate the map. By default, the MapView allows users to use a two-finger pinch gesture to zoom in and out, and a single finger drag gesture to pan. To learn how to allow users to interact with and navigate the map in different ways, see Provide map tools.
Geographic data can change over time; therefore, some layers may show stored temporal data, which is information about the changing state of a dataset over time. For example, the progression of a hurricane changes in sea temperature, destruction of wildlife habitat, or the spread of disease. These layers are called time-aware layers.
You can configure a map with time-aware layers to display different periods of time. Stepping through time in your map can help you easily identify trends and patterns in the data that may have otherwise remained unnoticed. Use the setTimeInterval method on layers that implement the TimeAwareLayer interface. Learn more about working with time aware layers.