ArcGIS runtime for Android development tutorial V2.0 (5) Basics-Layers

Source: Internet
Author: User
Tags gety

<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>

Layers are the carrier of Spatial Data. Through layers, we can read map data into layers for display. in GIS, layers are an important concept, only when a layer is added to a mapview object can the loaded map data be displayed. There are many layers in ArcGIS runtime for Android. Different layers have different effects and are the relationship diagrams of layers:

 

1,
Arcgistiledmapservicelayer

In ArcGIS Server, we can publish a variety of map services. Mobile Terminals need different layers to correspond to these services. The arcgistiledmapservicelayer layer corresponds to the slice service in the ArcGIS Server Service. Because the map service is sliced, its advantage is that the loading speed is fast. Its usage is as follows:

MapView mv = new MapView(this);mv.addLayer(new ArcGISTiledMapServiceLayer( "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer")); setContentView(mv);

2,
Arcgisdynamicmapservicelayer

The arcgisdynamicmapservicelayer layer corresponds to the dynamic service in the ArcGIS Server Service. The map images of the dynamic map service are read by mobile devices and used as follows:

MapView mv = new MapView(this);mv.addLayer(new ArcGISDynamicMapServiceLayer( "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer")); setContentView(mv);

 

3,
Arcgisimageservicelayer

 

The arcgisimageservicelayer layer corresponds to the image service in the ArcGIS Server service. It is very easy to call the image service. Its usage is as follows:

 

MapView mv = new MapView(this); mv.addLayer(new ArcGISImageServiceLayer( "http://myserver/arcgis/rest/services/MyImage/ImageServer",null)); setContentView(mv);

 

4,
Arcgisfeaturelayer

The arcgisfeaturelayer layer corresponds to the feature service in the ArcGIS Server Service. Only such a service can be used for online data editing. The feature service can be used to set three modes for calling, data and efficiency returned by different modes are different. The three modes are mode. snapshot returns all data of the Service in snapshot mode. onDemand returns data as needed, mode. selection returns data according to the selected range. The usage is as follows:

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); // setcontentview (MV) based on the snapshot method );

 

5,
Arcgislocaltiledlayer

 

Arcgislocaltiledlayer is the layer for adding offline data packets. Currently, this layer supports two formats of offline data: one is compact cache slicing, and the other is packaged data in TPK format, for how to create these two types of data, refer to the appendix "How to Create offline data Appendix". The layers are used as follows:

Mapview mv = new mapview (this); arcgislocaltiledlayer local = new arcgislocaltiledlayer ("file: // MNT/sdcard/<cachename>/layers"); // offline layer mV. addlayer (local); setcontentview (MV );

 

6,
Graphicslayer

Graphicslayer is an important layer in ArcGIS runtime for Android. It is also the most frequently used layer. graphicslayer can contain multiple living graphic objects, therefore, no matter whether we query the graphic data or the graphic data we plot, we need to present it through it. When mapview adds a layer, do not add this layer first, when mapview loads a layer, it first needs to initialize some map parameters, which are not available in this layer. The usage is as follows:

MapView mv = new MapView(this);mv.addLayer(new GraphicsLayer());setContentView(mv);

In addition to rendering graphic objects, it also provides some other useful functions, such as element update and element acquisition.

  • Element update

This feature will be frequently used in future development. For example, when we want to update the coordinates in real time or use it for plotting, we will take the plotting as an example to illustrate its update usage, when we want to implement plotting on mobile devices, we will use the updategraphic () method of graphicslayer for real-time update. Then, the geometric elements drawn on the map will be constantly drawn, such:

Public Boolean ondragpointermove (motionevent from, motionevent to) {If (startpoint = NULL) {// determine whether the first vertex graphicslayer exists. removeall (); Poly = new polyline (); startpoint = mapview. tomappoint (from. getx (), from. gety (); Poly. startpath (float) startpoint. getx (), (float) startpoint. gety (); uid = graphicslayer. addgraphic (new graphic (poly, new simplelinesymbol (color. blue, 5);} Poly. lineto (float) mappt. getx (), (float) mappt. gety (); // Add a line point graphicslayer. updategraphic (UID, poly); // return true when updating data ;}

 

  • Element Acquisition

In ArcGIS runtime for Android, graphic objects can be set to listen to different Web APIs, in ArcGIS runtime for Android, graphic cannot be added with any listeners. Therefore, when we click a graphic object on the map, we need other methods to indirectly obtain this object. We can use the graphicslayer method getgraphicids (float X,
Float y, int tolerance) to obtain elements. X and Y are the screen coordinates, and tolerance is the tolerance. Through this method, we can indirectly obtain the required graphic objects, such:

             public boolean onSingleTap(MotionEvent e) {Graphic graphic = new Graphic(mapView.toMapPoint(new Point(e.getX(), e.getY())),new SimpleMarkerSymbol(Color.RED,25,STYLE.CIRCLE));return false;                  int[] getGraphicIDs(float x,float y,            int tolerance)}

 

7,
Bingmapslayer

You can also add Bing map to ArcGIS runtime for Android. To add Bing map, you must first register an account and obtain the Bing map app ID, with this ID, we have the permission to use Bing map. For specific account application and operation steps, refer to the following address:

Address: https://www.bingmapsportal.com/

Http://msdn.microsoft.com/en-us/library/ff428642.aspx

 

        <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>

Enter the applied ID in the appid attribute of the above code to access the Bing map service normally.

8,
Spatialreference

The space reference object can be obtained through mapview or layer. For each map service, it has a corresponding space reference system, this object is often used for query and retrieval or coordinate projection conversion. The usage is as follows:

Double locy = loc. getlatitude (); // latitude double locx = loc. getlongpolling (); // longitude point wgspoint = new point (locx, locy); // converts longitude and latitude coordinates into map coordinate system point mappoint = (point) geometryengine. project (wgspoint, spatialreference. create (4326), map. getspatialreference (); Unit mapunit = map. getspatialreference (). getunit (); double zoomwidth = unit. convertunits (search_radius, unit. create (linearunit. code. mile_us), mapunit); envelope zoomextent = new envelope (mappoint, zoomwidth, zoomwidth); map. setextent (zoomextent );

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.