ArcGIS runtime for Android development tutorial V2.0 (4) Basics-mapview

Source: Internet
Author: User

Mapview is the core component of ArcGIS runtime SDK forandroid. mapview can be used to present data of the map service, and mapview defines a wide range of attributes, methods, and events, you can use mapview to operate the touch screen of the device. By default, mapview can respond to various gesture operations. During GIS development, map operations are indispensable. Mapview is a subclass of viewgroup in Android and is also ArcGIS
The map container in the runtime SDK for Android works the same as the map and mapcontrol classes in many ArcGIS APIs.

1. mapview Functions

Mapview is powerful not only because it is a container that presents map data. mapview provides us with a wide range of functions. Next we will analyze what functions mapview provides for us.

First, mapview has the ability to render a map. mapview can add one or more layers, and there are many layers, such as slice layers, dynamic layers, and local layers, layers can be displayed only when they are added to the mapview container.

Secondly, through mapview, we can set the display range of the map, whether the map can be rotated, the map background, the Maximum/minimum resolution of the map, and the resolution/scale specified for the current display.

Finally, let's take a look at the rich gesture listening interfaces provided by mapview. Through these listeners, we can monitor various gesture actions, such as clicking, double-clicking, moving, or long-pressing.

2. mapview Addition Method

We can add mapview to our application in two ways: XML and hard encoding. XML is used in most cases, it is convenient to adjust the settings of the layout and its attributes.

L
XML method:

 

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

MapView map = new MapView(this);map.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));tileLayer = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");map.addLayer(tileLayer);setContentView(map ); 

 

3. Map scaling, rotation, and coordinate transformation

Map scaling is the most basic function in a map. We can use mapview to scale a map. mapview provides multiple map scaling methods, as shown in the Code:

 

        mMapView.zoomin();        mMapView.zoomout();        mMapView.zoomToResolution(centerPt,res);        mMapView.zoomToScale(centerPt,scale); 

 

The first two main features of the preceding scaling methods are step-by-step scaling. That is to say, when we call the zoomin () method once, the map will be enlarged and zoomout () will be called once () the method map will be reduced by one level.

For the latter two types of scaling, they are scaled according to different resolutions or scales. When zoomtoresolution (centerpt, Res) method is called for scaling, We need to input two parameters, the first parameter centerpt indicates the center point for us to scale, so we need to input a point object. The second parameter is the resolution to scale to. For zoomtoscale (centerpt, scale, similar to zoomtoresolution (centerpt, Res), the first parameter of the two methods is the same, and the second parameter is no longer the resolution, but the scale of the map to be imported.

The resolution or scale value here is closely related to our published service. If the published map service generates a cache slice, I can see the corresponding scale and resolution at different levels in the service,

Service address: http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer

Mapview can also set the display range, scale, resolution, rotation angle, and background color of a map, such:

Map = (mapview) findviewbyid (R. Id. Map );...... Envelope Env = new envelope (12957628.58241, 4864247.2803126, 12958114.4225065, 4864490.20036087); // The range is map. setextent (ENV) // sets the map display range map. setscale (295828763); // The currently displayed scale map. setresolution (9783.93962049996); // set the resolution of the current display. // the preceding three methods can change the display range of the map. The map is not used in the code at the same time. setmapbackground (0 xffffffff, color. transparent, 0, 0); // sets the map background map. setallowrotationbypinch (true); // whether the map can be rotated Using Pinch. setrotationangle (15.0); // set The map is rotated for 15 degrees, and the parameter is clockwise.

 

 

In addition to the above functions, mapview also has a main function: "Coordinate Conversion". The coordinate conversion here refers to how to convert the screen coordinates into space coordinates or convert the space coordinates into screen coordinates, such:

// Add a click event listener map to the map. setonsingletaplistener (newonsingletaplistener () {publicvoid onsingletap (float X, float y) {// todo auto-generated method stubpoint Pt = map. tomappoint (x, y); // The screen coordinates are converted to the spatial coordinate point screenpoint = map. toscreenpoint (PT); // convert to screen coordinate object }});

 

4. Map listener

The monitoring of mobile gestures is an important part, and map gesture operations are also managed by mapview. There are mainly the following types of monitoring:

L
Map click listener: onsingletaplistener

L
Translation listening: onpanlistener

L
Long-pressed listener: onlongpresslistener

L
Scaling listener: onzoomlistener

L
Status listener: onstatuschangedlistener

L
Pinch listener: onpinchlistener

With these listeners, we can perform all the operations on the map. These listeners are not explained here. To learn more about the usage of these listeners, see section 3.4 (MAP event ).

At this point, all the introductions to mapview come to an end. Next we will enter the layer world.

 

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.