ArcGIS Runtime for Android Development tutorial V2.0 (4) Basic article---Mapview

Source: Internet
Author: User

Original address:

ArcGIS Runtime for Android Development tutorial V2.0 (4) Basic---mapview-arcgis_mobile column-blog channel-csdn.net
http://blog.csdn.net/arcgis_mobile/article/details/8147328

Mapview is the core component of the ArcGIS Runtime SDK forandroid, where data from the map service can be rendered, and rich properties, methods, and events are defined in Mapview, and users can manipulate the device's touchscreen via Mapview. The default Mapview can respond to the user's various gestures, in the development of GIS, when the map operation is indispensable. Mapview is a subclass of ViewGroup in Android and a map container in ArcGIS Runtime SDK for Android, as is the case with the map, Mapcontrol classes in many ArcGIS APIs.

1, Mapview function Introduction

Mapview is powerful not only because it is a container for rendering map data, Mapview provides us with a wealth of features, and below is an analysis of what Mapview offers us.

First, Mapview has the ability to render maps, Mapview can add one or more layers, and there are a number of layers, such as tile layers, dynamic layers, this map layer, and so on, which can only be displayed if the layer is added to the Mapview container.

Second, by Mapview we can set the display range of the map, whether it is allowed to be rotated, the map background, the maximum/minimum resolution of the map, and the resolution/scale bar that specifies the current display.

Finally, let's take a look at the rich gesture monitoring interface provided by Mapview, through which we can listen to various gestures, such as clicking, double-clicking, moving or long-pressing, and so on.

2. How to add Mapview

There are two ways we can add Mapview to our application: One is XML, the other is hard-coded, and we use XML more easily to adjust settings for layouts and their properties.

L XML mode:

< Com.esri.android.map.MapView         Android:id = "@+id/map"         android:layout_width= "Fill_parent"        android:layout_height= "Match_ Parent "></com.esri.android.map.MapView>

L Hard Coding Method:

New Mapview (this); Map.setlayoutparams (newNew Arcgistiledmapservicelayer ("Http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" ); Map.addlayer (Tilelayer); Setcontentview (map) ;

3. Map scaling, rotation, and coordinate conversion

Map scaling is the most basic feature of the map, and we can use Mapview to scale the map, Mapview provides a variety of ways to scale the map, as shown in the code:

Mmapview.zoomin ();        Mmapview.zoomout ();        Mmapview.zoomtoresolution (centerpt,res);        Mmapview.zoomtoscale (Centerpt,scale);

The first two main functions for scaling above are scaling, that is, when we call the ZoomIn () method The map zooms in one level, and once the Zoomout () method map is called down one level.

For the latter two scales, which are scaled at different resolutions or scales, when the zoomtoresolution (Centerpt, res) method is called to scale, we need to pass in two parameters, the first parameter centerpt the center point we want to scale, So we need to pass in a Point object, the second parameter is the resolution to zoom to, and for Zoomtoscale (centerpt, scale), it's similar to Zoomtoresolution (Centerpt, RES), Two methods The first parameter is the same, and the second parameter is no longer the resolution, which is the scale bar to pass in the map.

The resolution or scale values here are closely related to our published service, and if the published map service generates cache tiles, in the service I can see the scale and resolution of the different levels.

Service Address: Http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

Mapview can also set the map's display range, scale, resolution, rotation angle, and map background color, such as:

Map =(Mapview) Findviewbyid (R.ID.MAP); Envelope Env=NewEnvelope (12957628.58241, 4864247.2803126, 12958114.4225065, 4864490.20036087);//Rangemap. SetExtent (ENV)//set the map display rangemap. Setscale (295828763);//the scale bar currently displayedmap. Setresolution (9783.93962049996);//set the current display resolution//The above three methods can change the display range of the map, in the code is not used at the same timeMap.setmapbackground (0xFFFFFFFF, color.transparent, 0, 0);//set the map backgroundMap.setallowrotationbypinch (true);//is it permissible to use pinch mode to rotate map map.setrotationangle (15.0);//rotates the map 15 degrees when initialized, and rotates counterclockwise when the parameter is positive. 

In addition to the above features, Mapview also has a main function: "Coordinate transformation", here is the coordinate transformation refers to, how to convert screen coordinates into spatial coordinates or to convert the spatial coordinates into screen coordinates, such as:

// Add a Click event listener to the map Map.setonsingletaplistener (Newonsingletaplistener () {                        publicvoid onsingletap(float  float  y) {                //  TODO auto-generated method stub= Map.tomappoint (x, y);  the screen coordinates are converted into spatial coordinates  = map. Toscreenpoint (PT); // Convert to screen coordinate object              }});

4. Map Listener

For mobile gesture monitoring is a more important link, for the map gesture operation is also managed by Mapview, mainly has the following kinds of monitoring:

L Map Click Listen: Onsingletaplistener

L Panning Monitor: Onpanlistener

L Long Press listen: Onlongpresslistener

L Zoom Monitor: Onzoomlistener

L State Monitoring: Onstatuschangedlistener

L Pinch Monitor: Onpinchlistener

With these monitors we can have no action on the map, for these are not much explanation for these monitoring, if you want to learn more about the usage of these listening to see section 3.4 (Map events).

To this, all the introductions about Mapview come to an over, enter the layer world below.

ArcGIS Runtime for Android Development tutorial V2.0 (4) Basic article---Mapview

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.