From: http://blog.csdn.net/arcgis_mobile/article/details/7801467
In the development of GIS, map operation is indispensable. In ArcGIS for Android, the map component is Mapview,mapview is a class (reference) based on ViewGroup in Android, and is also a map container in ArcGIS Runtime SDK for Android. The same is true of the map and Mapcontrol classes in many ArcGIS APIs.
The common operations of maps are zoom, rotate, pan, get range, scale, resolution and other information, as well as common gesture operations, where frequently used features and frequently asked questions have the following:
1) Zoom the map to the specified scale/resolution/level;
2) Set the maximum minimum zoom level of the map;
3) Get the latitude and longitude coordinates of a point on the map;
4) Gesture manipulation of the map;
5) The map cannot be displayed.
The following will give you a detailed answer to the above questions.
1, Access/set scale, resolution, center point, range;
In ArcGIS forandroid, Mapview has a number of methods related to map operations, including the map's scale, resolution, center point, and extent, as follows:
Gets/sets the center point, extent, resolution, scale bar of the map |
return type |
Method |
Description |
Void |
Centerat (Point Centerpt, Boolean animated) |
Center the map to a specified point |
Point |
Getcenter () |
Get Map Center Point |
Polygon |
GetExtent () |
Get map Minimum Outsourced rectangle |
Envelope
|
Getmapboundaryextent() |
Get the boundaries of a map |
Void |
SetExtent (Geometry Geometry) |
Enlarges the map to the specified range and geometry the bound as the map's current extent |
Void |
SetExtent (Geometry Geometry, int padding) |
Enlarges the map to the specified geometry so that geometry adapts to the bound of the map |
Double |
Getmaxresolution () |
Get Map Maximum resolution |
Void |
Setmaxresolution (double maxresolution) |
Set map Maximum resolution |
Double |
Getminresolution () |
Get Map Minimum resolution |
Void |
Setminresolution (double minresolution) |
Set Map Minimum resolution |
Double |
Getresolution () |
Get the current map resolution |
Void |
Setresolution ( Double res) |
Set the current map resolution |
Double |
Getscale () |
Get the current map scale |
Void |
Setscale (double scale) |
Set the current map scale |
To get/Set the map scale, initial resolution, range, center point and other information, directly using the above method can be, very simple, do not repeat here, the sample code is as follows:
Map.setscale (18489297.737236);//Set the scale at which the map is initialized;
Map.setallowrotationbypinch (true);//sets whether the map is allowed to rotate by pinch mode;
Map.setrotationangle (15.0);//Set the rotation angle of the map;
......
2, Map zoom, pan and rotate;
Map events related to scaling and rotation are as follows:
Map Zoom, rotate |
return type |
Method |
Description |
Void |
ZoomIn () |
|
Void |
Zoomout () |
|
Void |
Zoomto (point centerpt, float factor) |
Debauchery a map to a specified point |
Void |
Zoomtoresolution (Point centerpt, double res) |
Zoom the map to the specified resolution |
Void |
Zoomtoscale (point centerpt, double scale) |
Enlarge the map to a specified scale |
Double |
Getrotationangle () |
Returns the current map rotation angle (unit degree) |
Void |
Setrotationangle (double degree) |
Rotates the map at the specified angle (unit degree), with a positive number in degrees counterclockwise |
Void |
Setrotationangle (double degree, float pivotx, float pivoty) |
Rotates the map at a specified point and angle, and the angle is positive by counterclockwise |
Void |
Setallowrotationbypinch (Boolean Allowrotationbypinch) |
Allow/Cancel pinch rotation |
Boolean |
Isallowrotationbypinch () |
Whether to allow rotation when pinch |
2.1 Panning
The Mapview method, which is not specifically for panning operations, is mainly due to the fact that panning is already supported by default in Mapview, which translates the map when dragging a map with a mouse or gesture, so no setting is required;
2.2 Zoom to the specified resolution/scale and continuously enlarge n times
The typical tiled map service, in its Rest service directory, can be found in the level of slices, the corresponding resolution and scale scales, the resolution between each level and the scale is twice times the relationship.
There is no pointer control in ArcGIS like the web, there is no direct map-level control, and the level control is usually achieved by resolution or scale. You can use the Getresolution () and Getscale () methods to get the scale and resolution of the current map, and then use a multiple relationship of 2, using Zoomto ()/zoomtoscale ()/zoomtoresolution () to achieve " To control the zoom level of the map:
Zoom In/out 1 time times:
Map.zoomin (), map.zoomout ();
Continuous amplification/Reduction n times:
Map.zoomto (point centerpt, float factor), such as Map.zoomto (CENTERPT,2N), where n is a multiple of magnification or reduction;
Map.zoomtoscale (point centerpt, double scale), such as: Map.zoomtoscale (Centerpt, Map.getscale ()/2n)/map.zoomtoscale (PT, Map.getscale () *2n), where n is a multiple of magnification 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 magnification or reduction;
In Zoomto (point centerpt, float factor), the centerpt refers to which points to enlarge, the factor parameter is used to calculate the new resolution, the formula is: the new resolution = Current resolution/factor. This means that, in order to zoom in at the current resolution of 3 times times, the new resolution = Current resolution/(23), because the resolution between each level is a multiple of 2, zoom three, the resolution is 23 times times, factor = 23. As you can see, the map level is increased by 1 levels, resolution/2, scale/2, so if you want to enlarge the map continuously n-level, factor =2n. Factor =2-n If you want to shrink the map continuously by an n-level.
In Zootoscale (point centerpt, double scale) and zoomtoresolution (Points centerpt, double res), scale and res refer to the actual resolution and Therefore, according to the multiple relationship of 2 directly multiplication can.
2.3 Setting the maximum minimum zoom level for a map
Sometimes we need to set the map to zoom in or zoom out to a certain level, do not allow users to zoom in or zoom out, the following two methods are easy to do:
Map.setmaxresolution (maxresolution);
Map.setminresolution (minresolution);
These two methods set the maximum and minimum resolution of the map, and limit the zoom level of the map, the map will no longer be scaled down or enlarged when the local map reaches its maximum and minimum resolution, so that the user can not scale the map or see more content without restrictions.
At initialization, set the map to a certain level (find the corresponding resolution, scale bar):
Map.setresolution (resolution of this level);
As for how to get the current map level, there is no way to get resolution first, then go to the rest Service directory to control its level.
2.4 Rotate the map
You can use Setrotationangle (double degree) and Setrotationangle (Doubledegree, float pivotx, float pivoty) to rotate the map to a certain angle, To achieve rotation through gestures, you need to do this through Setonpinchlistener (Onpinchlistener onpinchlistener) monitoring. Such as:
Public void onCreate (Bundle savedinstancestate, Onpinchlistener onpinchlistener) { Super. OnCreate (savedinstancestate); Setcontentview (r.layout. Main); Map = (Mapview) Findviewbyid (r.id. Map); ...... Map.setallowrotationbypinch (true); Allow rotation of the map using pinch mode Map.setrotationangle (15.0); Rotates the map 15 degrees when initialized, and rotates counterclockwise when the parameter is positive. } |
3. Get the coordinates of a point on the map
To get the coordinates of a point on the map mainly uses the following methods, in which the main use of the Tomappoint () method to obtain point coordinate information on the map:
return type |
method |
Description |
spatialreference |
Getspatialreference () |
Returns the coordinate system of the map |
Point |
to MapPoint (float Screenx, float screeny) |
Convert screen coordinates to ArcGIS geometry point coordinates in the map coordinate system | /tr>
Point |
Tomappoint (POINT SRC) |
Convert screen coordinates to ArcGIS geometry point coordinates in the map coordinate system |
Point |
Toscreenpoint (POINT SRC) |
Converts ArcGIS geometry point coordinates in the map coordinate system to screen coordinates |
For example, the coordinate code for getting the mouse point while long pressing the map is as follows:
Long press show Mouse point coordinates and scale this. Map.setonlongpresslistener (new Onlongpresslistener () { private static final long Serialversionuid = 1L; @Override Public void onlongpress (float x,float y) { Com.esri.core.geometry.Point pt = map.tomappoint (x, y); Mapcenter.settext ("X:" + pt.getx () + "Y:" + pt.gety ()); Labelxy.settext ("The current map resolution is:" +map.getresolution ()); Mapscale.settext ("The current map scale is:" +map.getscale ()); } }); |
The results of the operation are as follows:
4. Gesture operation
By default, Mapview responds to the following gestures:
1) Single finger double click and pinch-out enlarge map;
2) Two or more fingers pinch-in reduce the map;
3) Drag and drop a single finger to pan the map.
Other gesture monitors are:
Gesture Events |
return type |
Method/Event Monitoring |
Description |
Onlongpresslistener |
Getonlongpresslistener () |
Get map long press event listener |
Onpanlistener |
Getonpanlistener () |
Get map Panning Event listener |
Onpinchlistener |
Getonpinchlistener () |
Get map pinch clip Event Monitor |
Onsingletaplistener |
Getonsingletaplistener () |
Get Map Click event Listener |
Onzoomlistener |
Getonzoomlistener () |
Get Zoom Listener |
void |
Setonlongpresslistener (Onlongpresslistener Onlongpresslistener) |
Set map long press event listener |
Void |
Setonpanlistener (Onpanlistener Onpanlistener) |
Set map Panning Event listener |
Void |
Setonpinchlistener (Onpinchlistener Onpinchlistener) |
Set up a map pinch clip event Listener |
Void |
Setonsingletaplistener (Onsingletaplistener Onsingletaplistener) |
Set up a map click event Listener |
Void |
Setonzoomlistener (Onzoomlistener Onzoomlistener) |
Setting the Zoom Listener |
5, about the map display does not come out of the problem
Many beginners when using ArcGIS Runtimesdk for Android development, the simplest HelloWorld program will encounter problems, follow the steps of the tutorial, add Mapview, add tile layer, everything is ready, the map is always out, This problem can be found in the following ways:
1) If more than one layer is added, make sure that the geographic reference of multiple layers is the same;
2) is the service type;
3) layer is declared in the XML layout file;
4) If you just add a basemap layer still out of the basemap, then nine to ten is the extent problem. First, the Mapview control must contain at least one layer, and secondly, it is best to specify initextent for the layer, and the code in the XML is as follows:
<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"> </com.esri.android.map.MapView> |
Where does the initextent come from? or in the Map service directory:
Take any of the two, or customize a extent that is included in both of these ranges, it is recommended to use full extent.
6. Other common methods
In addition to the various methods and monitoring mentioned above, there are some map-related, but also more commonly used methods and monitoring are as follows:
Other properties and Events |
return type |
Method/Event Monitoring |
Description |
Onstatuschangedlistener |
Getonstatuschangedlistener () |
Get Map status Change event listener |
Void |
Setonstatuschangedlistener (Onstatuschangedlisteneronstatuschangedlistener) |
Set map state Change event Listener |
Boolean |
IsLoaded () |
Mapview returns True after initialization |
Void |
Setesrilogovisible (Boolean visible) |
Turn on or off ESRI's logo tag on the map |
Void |
Setmapbackground (int bkcolor, int gridcolor, float gridSize, float gridlinesize) |
Set the map background color |
Top 5 common actions for the ArcGIS for Android map control