|
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
}
}
|