Conversion from 5 common operations of ArcGIS for Android map controls to arcgisandroid

Source: Internet
Author: User

Conversion from 5 common operations of ArcGIS for Android map controls to arcgisandroid

Http://blog.csdn.net/arcgis_mobile/article/details/7801467

 

During GIS development, map operations are indispensable. In ArcGIS for Android, the map component is MapView, and MapView is a class (reference) based on ViewGroup in Android. It is also a map container in ArcGIS Runtime SDK for Android, the functions of Map and MapControl are the same as those of many ArcGIS APIs.

Common map operations include scaling, rotation, translation, range acquisition, scale, resolution, and other information, as well as common gesture operations. The frequently used features and frequently asked questions include:

1) scale the map to a specified scale, resolution, or level;

2) set the maximum and minimum zoom level of the map;

3) obtain the longitude and latitude coordinates of a point on the map;

4) map gesture operations;

5) The map cannot be displayed.

The following content will answer the above questions in detail.

 

1. Obtain/set the scale, resolution, center, and range;

In ArcGIS forAndroid, MapView has many methods related to map operations. The methods related to the map's scale, resolution, center, and range are as follows:

 

 
 

Obtain/set the center, range, resolution, and scale of the map.

Return type

Method

Description

Void

CenterAt (Point centerPt, Boolean animated)

Center a map to a specified point

Point

GetCenter ()

Obtain the map center point

Polygon

GetExtent ()

Obtain the minimum outsourcing rectangle of a map

Envelope

GetMapBoundaryExtent()

Obtain the map Boundary

Void

SetExtent (Geometry geometry)

Enlarge the map to a specified range and use the bound of the geometry as the current extent of the map.

Void

SetExtent (Geometry geometry, int padding)

Enlarge the map to the specified geometry so that geometry can adapt to the bound of the map.

Double

GetMaxResolution ()

Get the maximum resolution of a map

Void

SetMaxResolution (double maxResolution)

Sets the maximum resolution of a map.

Double

GetMinResolution ()

Obtain the minimum resolution of a map

Void

SetMinResolution (double minResolution)

Sets the minimum resolution of a map.

Double

GetResolution ()

Get current map resolution

Void

SetResolution(Double res)

Set the current map resolution

Double

GetScale ()

Returns the current map scale.

Void

SetScale (double scale)

Set the current map scale

To obtain/set the map's scale, initial resolution, range, center point, and other information, simply use the preceding method. The sample code is as follows:

Map. setScale (18489297.737236); // you can specify the scale when the map is initialized;

Map. setAllowRotationByPinch (True); // Sets whether to allow the map to be rotated by pinch;

Map. setRotationAngle (15.0); // you can specify the Rotation Angle of a map;

……

 

2. Map scaling, translation, and Rotation;

MAP events related to scaling and rotation are as follows:

Map scaling and Rotation

Return type

Method

Description

Void

Zoomin ()

 

Void

Zoomout ()

 

Void

ZoomTo (Point centerPt, float factor)

Disallowing a map to a specified point

Void

ZoomToResolution (Point centerPt, double res)

Enlarge the map to a specified resolution

Void

ZoomToScale (Point centerPt, double scale)

Enlarge a map to a specified scale

Double

GetRotationAngle ()

Returns the current map rotation angle (unit: degree)

Void

SetRotationAngle (double degree)

Rotate the map according to the specified angle (in degree). If the degree is positive, the map is rotated in the clockwise direction.

Void

SetRotationAngle (double degree, float interval Tx, float interval ty)

Rotate the map according to the specified point and angle, and the angle is positive counter-clockwise.

Void

SetAllowRotationByPinch (boolean allowRotationByPinch)

Allow/cancel pinch Rotation

Boolean

IsAllowRotationByPinch ()

Whether to allow rotation during pinch

 

2.1 Translation

The MapView method does not have a specific translation operation. The main reason is that MapView supports the translation operation by default, that is, the map is moved when you drag the map with the mouse or gesture, so you do not need to set it;

 

2.2 zoom to the specified resolution/scale and continuous zoom n times

Generally, the slice map service can check the level and resolution and scale of the slice under its REST service directory. The resolution and scale of each level are two times the same.
In ArcGIS Android, there is no pointer control like in the Web, and there is no direct map-level control. Generally, level control is implemented by resolution or scale. You can use the getResolution () and getscale () methods to obtain the scale and resolution of the current map. Then, use zoomTo ()/zoomToScale ()/zoomToResolution () by using the multiples of 2 () to control the zoom level of a map:

Zoom in/out 1 times:

Map. zoomin (), map. zoomout ();

Continuous amplification/reduction n times:

Map. zoomTo (point centerPt, float factor); for example, map. zoomTo (centerPt, 2n), where n is a multiple of amplification or reduction;

Map. zoomToScale (Point centerPt, double scale); for example: map. zoomToScale (centerPt, map. getScale ()/2n)/map. zoomToScale (pt, map. getScale () * 2n), where n is a multiple of amplification or reduction;

Map. zoomToResolution (point centerPt, double res): map. zoomToResolution (centerPt, map. getResolution ()/2n)/map. zoomToResolution (centerPt, map. getResolution () * 2n), where n is a multiple of amplification or reduction;

In zoomTo (point centerPt, float factor), centerPt refers to the point at which the centerPt is enlarged. The factor parameter is used to calculate the new resolution. The formula is as follows: new resolution = current resolution/factor. This means that if you want to increase the resolution by 3 times, the new resolution is equal to the current resolution/(23). Because the resolution between each level is a multiple of 2, the resolution is amplified by three levels, resolution is 23 times, factor = 23. We can see that each time the map level is increased by 1, the resolution is/2, and the scale is/2, If You Want To continuously enlarge the map to n, factor = 2n. If you want to scale down a map by n consecutive levels, factor = 2-n.

In zooToScale (Point centerPt, double scale) and zoomToResolution (point centerPt, double res), scale and res both indicate the actual resolution and scale, therefore, we can simply multiply and divide them according to the multiples of 2.

 

2.3 set the maximum and minimum scaling levels of a map

Sometimes we need to set the map to zoom in or out to a certain level, and the user is not allowed to zoom in or out again, it is easy to do with the following two methods:

Map. setMaxResolution (MaxResolution );

Map. setMinResolution (MinResolution );

These two methods set the maximum and minimum resolution of the map, which limits the zoom level of the map. When the map reaches the maximum and minimum resolution, the map cannot be reduced or enlarged, this prevents users from scaling the map or seeing more content without restrictions.

Set the map to a certain level during initialization (locate the resolution and scale corresponding to the level ):

Map. setResolution (resolution corresponding to this level );

As for how to obtain the current map level, there is no way to obtain the resolution first, and then compare it to the rest service directory.

 

2.4 rotating Map

You can use setRotationAngle (double degree) and setRotationAngle (doubledegree, float rotate Tx, float rotate ty) to rotate a map at a certain angle, you must use setOnPinchListener (OnPinchListener onPinchListener) to listen. For example:

 

 
 

Public voidOnCreate (Bundle savedInstanceState, OnPinchListener onPinchListener ){

Super. OnCreate (savedInstanceState );

SetContentView (R. layout.Main);

 

Map = (MapView) findViewById (R. id.Map);

......

Map. setAllowRotationByPinch (True); // Whether the map can be rotated Using Pinch

Map. setRotationAngle (15.0); // At initialization, the map is rotated for 15 degrees. When the parameter is set, it is rotated in the clockwise direction.

}


 

 

3. Get the coordinates of a certain point on the map

The following methods are used to obtain the coordinates of a point on a map. The toMapPoint () method is used to obtain the coordinate information of a point on the map:

 
 

Return type

Method

Description

SpatialReference

GetSpatialReference ()

Returns the coordinate system of the map.

Point

ToMapPoint (float screenx, float screeny)

Convert screen coordinates to ArcGIS geometry Point coordinates in the map coordinate system

Point

ToMapPoint (Point src)

Convert screen coordinates to ArcGIS geometry Point coordinates in the map coordinate system

Point

ToScreenPoint (Point src)

Convert ArcGIS geometry Point in the map coordinate system to screen Coordinate


 

For example, the Code for obtaining the coordinates of a mouse point when a long-pressed map is as follows:

 
 

// Long-pressed display of the coordinates and scale of the mouse point

This. Map. setOnLongPressListener (NewOnLongPressListener (){

Private static final long SerialVersionUID= 1L;

@ Override

Public voidOnLongPress (FloatX,FloatY ){

Com. esri. core. geometry. Point pt = map. toMapPoint (x, y );

Mapcenter. setText ("X:" + pt. getX () + "Y:" + pt. getY ());

Labelxy. setText ("current map resolution:" + map. getResolution ());

Mapscale. setText ("current map scale:" + map. getScale ());

}

});

 

The running result is as follows:

 

 

4. gesture operations

By default, MapView responds to the following gestures:

1) double-click a single finger and zoom in the map with pinch-out;

2) zoom out the map with two or more fingers pinch-in;

3) drag and drop a single finger to pan the map.

Other gesture listening methods include:

 
 

Gesture events

Return type

Method/event listening

Description

OnLongPressListener

GetOnLongPressListener ()

Obtain long-pressed event listening for a map

OnPanListener

GetOnPanListener ()

Get Map translation event listening

OnPinchListener

GetOnPinchListener ()

Obtain a map pinch event listener

OnSingleTapListener

GetOnSingleTapListener ()

Get Map click event listening

OnZoomListener

GetOnZoomListener ()

Get scaling listening

Void

SetOnLongPressListener (OnLongPressListeneronLongPressListener)

Set monitoring of long-pressed map events

Void

SetOnPanListener (OnPanListener onPanListener)

Set map translation event listening

Void

SetOnPinchListener (OnPinchListener onPinchListener)

Set map pinch event monitoring

Void

SetOnSingleTapListener (OnSingleTapListener onSingleTapListener)

Set map click event listening

Void

SetOnZoomListener (OnZoomListener onZoomListener)

Set scaling listening

 

5. Questions about Map Display failures

Many new users encounter problems in the simplest HelloWorld program when using ArcGIS RuntimeSDk for Android development. Follow the steps in the tutorial to add MapView and slicing layers. Everything is ready, the map is always unavailable. You can find the cause from the following aspects:

1) if multiple layers are added, ensure that the geographical references of the layers are consistent;

2) whether the service type corresponds;

3) layer declaration is in the xml layout file;

4) if only a basemap layer is added and the basemap is still hidden, the problem is extent. First, the MapView control must contain at least one layer. Secondly, it is best to specify initExtent for this layer. The code in xml is as follows:

 
 

    <</SPAN>com.esri.android.map.MapView

        android:id="@+id/map"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        initExtent="-20037507.0672, -30240971.9584, 20037507.0672, 30240971.9584">

    </</SPAN>com.esri.android.map.MapView>

 

Where does the initExtent come from? Or in the map service directory:

Take either of the two or customize an extent that is included in the preceding two ranges. We recommend that you use full extent.

 

6. Other common methods

In addition to the methods and listeners mentioned above, there are also some map-related and commonly used methods and listeners as follows:

 
 

Other attributes and events

Return type

Method/event listening

Description

OnStatusChangedListener

GetOnStatusChangedListener ()

Obtain the MAP status change event listener

Void

SetOnStatusChangedListener (OnStatusChangedListeneronStatusChangedListener)

Set MAP status change event monitoring

Boolean

IsLoaded ()

Returns true after MapView initialization.

Void

SetEsriLogoVisible (Boolean visible)

Enable or disable ESRI logo labels on the map

Void

SetMapBackground (int bkColor, int gridColor, float gridSize, float gridLineSize)

Set map background color

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.