The basic concept

  • Spatial reference

Spatial reference of GIS, including coordinate system and other related spatial attributes. A spatial reference is a coordinate system used to store each element class and raster data set, as well as other coordinate properties (for example, coordinate resolution for x and Y coordinates and optional Z and measurement (M) coordinates). If desired, a vertical coordinate system can be defined for the data set using the Z-coordinate representing the surface elevation.

  • The map controls

    <com.esri.android.map.MapView
         android:id="@+id/mapView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"  />
    Copy the code

MapView is the core component of ArcGIS Runtime SDK for Android. MapView can present the data of map service, and it defines rich attributes, methods and events in MapView. Users can operate maps through MapView. The default MapView provides zoom, ping’yi operations. MapView is a subclass of ViewGroup for Android, and also a map container for ArcGIS Runtime SDK for Android.

MapView can add one or more layers. There are many types of layers, and layers are not displayed until they are added to the MapView container. Through MapView, you can set the display range of the map, whether to allow rotation, map background, the maximum/minimum resolution of the map and specify the resolution/scale of the current display. MapView also provides a variety of gesture listening interfaces. Through these listeners, you can listen for various gestures, such as click, double click, move, or long press.

  • The layer

Layer is a very important concept in GIS. As a carrier of spatial data, layer can load and display all kinds of map data through it, and is a collection of geometric figures and their corresponding attribute information. The following is an inheritance diagram of layers:

This article addresses

Map layer loading

All layers inherit from Layer, and the Map control provides the addLayer() method, so when we need to add layers we use the addLayer method to add layers to the map.

  • ArcGISLocalTiledLayer

    ArcGISLocalTiledLayer is a layer used to add offline packets. This layer currently supports offline data in two formats: a compact cache slice and a packaged TPK format.

ArcGISLocalTiledLayer tileLayer = new ArcGISLocalTiledLayer("file://" + mapPath + "/"+ fileName); // Instantiate the layer tilelayer.setvisible (false); // Control the layer display; tileLayer.setName(fileName); // Set the layer name to tilelayer.setopacity (); // Set the layer's opacity mapView.addLayer(tileLayer); // Add layers to the map windowCopy the code
  • ArcGISTiledMapServiceLayer

ArcGISTiledMapServiceLayer layer is used to display ArcGIS for Server service of slicing data, not to change the data in a layer, unless the cache update service. Because it is the PNG image data cut out by the service, arcGIS for Android cannot query this type of data, so it is often used for base map. Because it is caching data, this type of layer is one of the most quickly requested layers.

 String url ="https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer"; ArcGISTiledMapServiceLayer serviceLayer=new ArcGISTiledMapServiceLayer(url ); mapView.addLayer(serviceLayer); // Add layers to the map windowCopy the code
  • ArcGISDynamicMapServiceLayer

ArcGISDynamicMapServiceLayer dynamic map service layer is used to display data, the service side, according to the scope of the mobile device screen map scale return request data, use the same as the ArcGISTiledMapServiceLayer layer.

ArcGISDynamicMapServiceLayer layer usually contain more than one layer, the layer by the server according to the request to render and return in the form of pictures. Its feature is that it is very convenient to update and can be presented to users in time. Meanwhile, the visibility and spatial reference of layers can be changed. Separate Layer Definition can be added to layers, and ArcGIS Server dynamically projects each image. The map’s spatial reference is determined by the first layer loaded.

Performance characteristics: Its rendering time depends on the amount and complexity of the requested data, so it is generally slower than Tiled Map Server. It is suitable for situations where data changes frequently, or different data needs to be presented to different users, and element information is not required.

String  tiledLayerAddress="http://10.200.3.210:6001/arcgis/rest/services/ranqimap/gw2016_3/MapServer"; ArcGISDynamicMapServiceLayer agsDMS =new ArcGISDynamicMapServiceLayer(tiledLayerAddress); mapView.addLayer(tiledLayerAddress); // Add layers to the map windowCopy the code
  • ArcGISImageServiceLayer

The ArcGISImageServiceLayer layer is used to display image service data

String url="http://myserver/arcgis/rest/services/MyImage/ImageServer"ArcGISImageServiceLayer imgserviceLayer =new ArcGISImageServiceLayer(url,null); //option mapView.addLayer(tiledLayerAddress); // Add layers to the map windowCopy the code
  • BingMapLayer

ArcGIS Runtime for Android can also add Bing Map service, you must first register an account and obtain the Bing Map App ID, with this ID to have the Bing map permission, specific account application and operation procedures can refer to the following address: www.bingmapsportal.com/ : msdn.microsoft.com/en-us/libra…

<com.esri.android.map.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
url="http://www.arcgis.com/home/item.html?id=2b571d8c079d46b4a14a67df42b1da6f"
appId=""> </com.esri.android.map.MapView>
Copy the code

You can also add layers dynamically using code:

BingMapsLayer blyr=new BingMapsLayer("Your Bingmap ID", map style); mapView.addLayer(blyr); // Add layers to the map windowCopy the code

Map styles are as follows:

AERIAL("Aerial"),
AERIAL_WITH_LABELS("AerialWithLabels"),
ROAD("Road");
Copy the code
  • GraphicsLayer

Graphic is an important layer type in ArcGIS Runtime for Android, and it is also the most frequently used one. A GraphicsLayer can contain one or more Graphic objects through which the results of a query and dynamically plotted Graphic data are rendered. It is recommended not to add this type of layer first when adding a layer to MapView, because MapView loads a layer first by initializing some map parameters that this layer does not have.

GraphicsLayer is an application-defined layer used to draw elements with spatial reference. GraphicsLayer is an application-defined layer used to draw elements with spatial reference. It is not suitable for drawing non-geographical elements, such as the compass or copyright text. You can query elements in layers using screen coordinates and have the getGraphics () method return elements, as well as support for setting layer scales.

It is not recommended to store too many elements in the Graphics Layer, however, it has good performance and is the base class of the Feature Layer class. If a large number of elements must be processed, Feature collection is recommended to be stored in the Feature layer.

 GraphicsLayer graphicsLayer=new GraphicsLayer();
mapView.addLayers(graphicsLayer);
Copy the code
  • ArcGISFeatureLayer

ArcGISFeatureLayer displays the data provided by the Feature Service. Compared to other layer types, ArcGISFeatureLayer has the most rich features. Each element can be queried and filtered by SQL statements, inherited from GraphicsLayer.

This layer can be a spatial layer or a non-spatial table. It contains the information of many elements, and each element is rendered separately. Elements are requested from ArcGIS Server Feature Service or Map Service (such Feature layer cannot be edited). Return data in JSON format and draw. The loading speed is relatively slow.

Only Feature Service can have online data editing function. If you want to edit or synchronize some data online, you need to publish it as Feature Service and create an ArcGISFeatureLayer layer on the mobile terminal to load the Service. This layer has a number of Settings that affect the layer’s performance, including request time, return size, processing and response time (Settings need to be done after layer Initialized). ArcGISFeatureLayer can be set in three modes (mode), different modes have different data return methods and execution efficiency

String url = "https://servicesbeta.esri.com/ArcGIS/rest/services/SanJuan/TrailConditions/FeatureServer/0"; MapView mv = new MapView(this); mv.addLayer(new ArcGISFeatureLayer(url,MODE.SNAPSHOT)); // Use snapshot modeCopy the code
  • Local vector data

FeatureLayer supports two formats of vector layer data (Shp, GeoDatabase). Generic Shp files can be loaded directly into FeatureLayer, and geodabase database files distributed using ArcMap can also be opened directly. We recommend using data from the GeoDatabase database file for map browsing because the GeoDatabase data contains simple symbolization.

  • Load SHP file data
ShapefileFeatureTable fTab = new ShapefileFeatureTable(dataFile.getAbsolutePath()); 
FeatureLayer fLayer = new FeatureLayer(fTab); // 
SimpleFillSymbol fillSymbolRender = new SimpleFillSymbol(Color.parseColor("#")); Renderer renderer = new SimpleRenderer(fillSymbolRender); fLayer.setRenderer(renderer); // Layer symbolization; mapView.addLayer(fLayer);Copy the code
  • Load the Geodataabase data file
Geodatabase dataBase = new Geodatabase(dataFile.getAbsolutePath());
List<GeodatabaseFeatureTable> gfts = dataBase.getGeodatabaseTables();
if (gfts.size() > 0) {
 int lyrCnt = gfts.size();
 for (int j = lyrCnt - 1; j > -1; j--) {
     GeodatabaseFeatureTable gft = gfts.get(j);
     // String layerName = gft.getFeatureServiceLayerName();
     FeatureTable tab = (FeatureTable) gft;
     //featurecount += tab.getNumberOfFeatures();
     FeatureLayer featureLayer = new FeatureLayer(tab);
     featureLayer.setName(tab.getTableName());
     featureLayer.setVisible(false);
     featureLayer.setEnableLabels(true);
     //Log.i("TabeName",tab.getTableName());
    Geometry.Type geoType = featureLayer.getGeometryType();
    //Log.i("GeoType", geoType.toString()); //mMapView.addLayer(featureLayer); mapView.addLayer(featureLayer); }}Copy the code

This article addresses

Graphics rendering

Logic for drawing:

The map should contain the drawing layer ———->GraphicsLayer on the interface, click the button to send the command to the system ——–> requires an enumeration class, ———->OnSingleTapListener Each graph needs a default Symbol ——>Symbol The graph is drawn according to points, so save the graph’s point data ——->List