ArcGIS for Android Sample parsing highlighting features-----highlightfeatures

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/wozaifeiyang0/article/details/7323606

Highlightfeatures

Feature highlighting function, I believe that there are other GIS development and management developers have the corresponding experience, for highlighting features, simply speaking, we query or identify the elements to render, so that it is highlighted, this example involves the following to introduce the recognition of the content, we simply introduce the relevant knowledge, Mainly introduces the rendering of the feature object (that is, the so-called highlighting), to see the code:

Mapview.setonlongpresslistener (new Onlongpresslistener () {

Public void onlongpress (float x,float y) {

Try {

if (tiledmapservicelayer.isinitialized () && selectedlayerindex >= 0) {

Graphicslayer.removeall ();

/*

* Click on the map point

*/

Point pointclicked = Mapview.tomappoint (x, y);

/*

* Identify the required parameters for the task, initialize the corresponding values

*/

Identifyparameters InputParameters = new identifyparameters ();

Inputparameters.setgeometry (pointclicked);

Inputparameters.setlayers (new int[] {Layerindexes[selectedlayerindex]});

Envelope env = new Envelope ();

Mapview.getextent (). Queryenvelope (env);

Inputparameters.setspatialreference (Mapview.getspatialreference ());

Inputparameters.setmapextent (env);

INPUTPARAMETERS.SETDPI (96);

Inputparameters.setmapheight (Mapview.getheight ());

Inputparameters.setmapwidth (Mapview.getwidth ());

Inputparameters.settolerance (10);

/*

* This is our own extension of the class, in which the main implementation of the IDENTIFYTASK request

*/

Myidentifytask midenitfy = new myidentifytask ();

Performs an asynchronous operation and passes parameters into an asynchronous operation

Midenitfy.execute (InputParameters);

} Else {

Toast toast = toast. Maketext (Getapplicationcontext (), "Please select a layer to identify features from.",

Toast. length_short);

Toast.show ();

}

} catch (Exception ex) {

Ex.printstacktrace ();

}

}

});

The above code, mainly to the map added a long-press map event monitoring, in the event handler function is mainly to do the initialization of the parameters of the recognition task and its implementation of our extended Myidentifytask operation, Myidentifytask is actually an asynchronous request class, let's see, What this asynchronous request class does, the code is as follows:

Private Class Myidentifytask extends asynctask<identifyparameters, Void, identifyresult[]> {

Identifytask Midentifytask;

@Override

protected Identifyresult[] Doinbackground (identifyparameters ... params) {

identifyresult[] Mresult = null;

if (params = null && params.length > 0) {

Identifyparameters mparams = params[0];//Get Parameters

Try {

Mresult = Midentifytask.execute (mparams);//Perform recognition operations

} catch (Exception e) {

E.printstacktrace ();

}

}

return Mresult;

}

@Override

protected void OnPostExecute (identifyresult[] results) {

TODO auto-generated Method stub

if (Results! = null && results.length > 0) {

Generating an array of feature objects

Highlightgraphics = new graphic[results.length];

Toast toast = toast. Maketext (Getapplicationcontext (), Results.length + "features identified\n",

Toast. Length_long);

Toast.setgravity (Gravity. BOTTOM, 0, 0);

Toast.show ();

for (int i = 0; i < results.length; i++) {

Geometry Geom = Results[i].getgeometry ();

String typeName = Geom.gettype (). Name ();

Here we are highlighting the features, that is, the feature rendering work

Random r = new random ();

int color = color. RGB (R.nextint (255), R.nextint (255), R.nextint (255));

if (Typename.equalsignorecase ("point")) {

Simplemarkersymbol SMS = new simplemarkersymbol (color, STYLE. SQUARE);

Highlightgraphics[i] = new Graphic (Geom, SMS);

} else if (Typename.equalsignorecase ("polyline")) {

Simplelinesymbol SLS = new simplelinesymbol (color, 5);

Highlightgraphics[i] = new Graphic (Geom, SLS);

} else if (typename.equalsignorecase ("polygon")) {

Simplefillsymbol SFS = new simplefillsymbol (color);

Sfs.setalpha (75);

Highlightgraphics[i] = new Graphic (Geom, SFS);

}

Graphicslayer.addgraphic (Highlightgraphics[i]);

Clearbutton.setenabled (true);

}

} Else {

Toast toast = toast. Maketext (Getapplicationcontext (), "No features identified.", Toast. length_short);

Toast.show ();

}

}

@Override

protected void OnPreExecute () {

Midentifytask = new identifytask (MapURL);//Initialize Recognition task instance

}

}

Here we can see that this asynchronous class is mainly to do the instantiation of the recognition Task object, and perform the recognition task, return the results of the rendering display, for the asynchronous class Asynctask Android should have some understanding of it, a brief introduction of his implementation process, When we generate an Asynctask instance and execute the Execute () method, his internal or execution order is OnPreExecute () Àdoinbackground () Àonpostexecute ()

So our highlight feature example is done, and to achieve a different, colorful effect, we need to delve into the rendering class of the feature and its associated features.

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.