ArcGIS runtime for Android development tutorial V2.0 (8) Basics-MAP events

Source: Internet
Author: User

ArcGIS runtime SDK for Android provides us with a wide range of event listeners. This section mainly introduces our frequently used listeners and introduces the functions that can be implemented through these listeners, in the following listener, only mapontouchlistener is a class, and all others are interfaces ,:

1.1 mapontouchlistener


Mapontouchlistener is one of the most important mapview listeners. It implements ontouchlistener and mapgesturedetector. the ongesturelistener interface can be used for all MAP operations. mapontouchlistener can be used conveniently. before using this interface, we only need to extend this class and override the methods in this class. Usage:

myListener = new MyTouchListener(this, mapView);mapView.setOnTouchListener(myListener);        /* * MapView's touch listener */class MyTouchListener extends MapOnTouchListener {public MyTouchListener(Context context, MapView view) {super(context, view);}public void setType(String geometryType) {this.type = geometryType;}public String getType() {return this.type;}public boolean onSingleTap(MotionEvent e) {    return true;}public boolean onDragPointerMove(MotionEvent from, MotionEvent to) {return super.onDragPointerMove(from, to);}@Overridepublic boolean onDragPointerUp(MotionEvent from, MotionEvent to) {return super.onDragPointerUp(from, to);}}

Through the code above, we can monitor different gesture operations. Different gesture operations will not pass through the method. Through these methods, we can add the required operation functions. For example, when you click on a map, a form is displayed. You only need to obtain the point, create the form, and pop up the form in the onsingletap () method.

1.2 onlongpresslistener

The onlongpresslistener interface is used to listen to long-pressed events on a map. Its usage is as follows:

// Add a long-pressed listener mapview to the map. setonlongclicklistener (new view. onlongclicklistener () {// method automatically executed after long-pressed public Boolean onlongclick (view v) {// todo auto-generated method stubreturn false ;}});

 

1.3 onpanlistener


The onpanlistener interface is used for event listening when map translation is performed on mapview. Its usage is as follows:

// Add a translation listener mapview to the map. setonpanlistener (New onpanlistener () {public void prepointerup (float fromx, float fromy, float tox, float toy) {} public void prepointermove (float fromx, float fromy, float tox, float toy) {} public void postpointerup (float fromx, float fromy, float tox, float toy) {} public void postpointermove (float fromx, float fromy, float tox, float toy) {}});

 

1.4 onpinchlistener

The onpinchlistener interface is also frequently used as an event listener for two or more map operations, for example, we can use this interface to zoom in or out a map. The usage is as follows:

// Add a clip/pinch listener mapview for the map. setonpinchlistener (New onpinchlistener () {public void prepointersup (float X1, float Y1, float X2, float Y2, double factor) {} public void prepointersmove (float X1, float Y1, float X2, float Y2, double factor) {} public void prepointersdown (float X1, float Y1, float X2, float Y2, double factor) {} public void postpointersup (float X1, float Y1, float X2, float Y2, double factor) {} public void postpointersmove (float X1, float Y1, float X2, float Y2, double factor) {} public void postpointersdown (float X1, float Y1, float X2, float Y2, double factor ){}});

 

1.5 onsingletaplistener


Onsingletaplistener is the event listener when we click a map. Its usage is as follows:

// Add a click event listener mapview for the map. setonsingletaplistener (New onsingletaplistener () {// method automatically executed after clicking the map public void onsingletap (float X, float y) {// todo auto-generated method stub }});

 

1.6 onstatuschangedlistener


The onstatuschangedlistener interface is used to listen to mapview or layer state change listeners. The usage is as follows:

// Add the status listener mapview. setonstatuschangedlistener (New onstatuschangedlistener () {public void onstatuschanged (Object source, status) {If (status = status. initialized) {} else if (status = status. layer_loaded) {} else if (status = status. initialization_failed) {} else if (status = status. layer_loading_failed )){}}});

 

From the code above, we can clearly see that there are four main changes to mapview status:

1)
Status.Initialized initialization successful

2)
Status.Layer_loaded layer loaded successfully

3)
Status.Initialization_failed initialization failed

4)
Status.Layer_loading_failed layer loading failed

 

1.7 onzoomlistener

The onzoomlistener interface monitors map scaling events. The usage is as follows:

Mapview. setonzoomlistener (New onzoomlistener () {// method automatically called before scaling public void preaction (float ready Tx, float variable ty, double factor) {}// the method automatically called after scaling public void postaction (float character Tx, float character ty, double factor ){}});

 

 

At this point, all listeners on the map have been introduced. If you have any questions, you can join the ArcGIS 4 Android group: 167467748 or 250106494 for consultation.

 

 

 

 

 

 

 

 

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.