Skylineglobe Android Development Area Calculation Sample code:
If you are familiar with the two development of Skylineglobe desktop, it should be easy to understand the code.
Package Com.skyline.terraexplorer.tools;import Android.os.handler;import Android.os.looper;import Com.skyline.teapi.*;import Com.skyline.teapi.isgworld.onanalysisprogresslistener;import Com.skyline.teapi.isgworld.onlbuttonuplistener;import Com.skyline.terraexplorer.r;import Com.skyline.terraexplorer.teapp;import Com.skyline.terraexplorer.models.menuentry;import Com.skyline.terraexplorer.models.teunits;import Com.skyline.terraexplorer.models.ui;import Com.skyline.terraexplorer.views.toolcontainer.closereason;public class Areatool extends Progresstool implements Onlbuttonuplistener, Onanalysisprogresslistener {private double groundarea;private String toolcontainertext;@ Overridepublic menuentry Getmenuentry () {return menuentry.createfor (this, R.string.mm_analyze_area, R.drawable.area, Menuentry.menuentryanalyze (), 20);} private void Startdrawpolygon () {//Start draw polygonisgworld.getinstance (). GetCommand (). Execute (1012, 5); Get Object String objectId = (string) isgworld.getInstance (). GetParam (7200); Iterrainpolygon Areapolygon = Isgworld.getinstance (). Getcreator (). GetObject (objectId). Castto (Iterrainpolygon.class); if (Areapolygon! = null) {areapolygon.getposition (). Setaltitudetype (altitudetypecode.atc_terrain_relative); Areapolygon.setparam (5440, NULL); Give the polygon X-ray look Areapolygon.setparam (5441, NULL); Make sure we don't see the red "Edit vertex helper polyline" Areapolygon.getlinestyle (). SetWidth (-2.0); Make the polygon a bit wider}} @Overridepublic Boolean Onbeforeopentoolcontainer () {super.onbeforeopent Oolcontainer (); Shownormalbuttons (); Updatearea (0,0); groundarea = 0; Ui.runonrenderthread (New Runnable () {@Overridepublic void Run () {//Start draw Polygonstartdrawpolygon (); Subscribe to Lbuttonup as a event that causes the polygon to Changeisgworld.getinstance (). Addonlbuttonuplistener (areat ool.this);}); return true;} @Overridepublic Boolean Onbeforeclosetoolcontainer(Closereason Closereason) {Super.onbeforeclosetoolcontainer (Closereason); Ui.runonrenderthread (New Runnable () {@Overridepublic void run () {String objectId = (String) isgworld.getinstance (). GetParam (7200); Simulate right click to end Drawing Isgworld.getinstance (). SetParam (8044, 0); Isgworld.getinstance (). Getcreator (). DeleteObject (OBJECTID); Isgworld.getinstance (). Removeonlbuttonuplistener (Areatool.this);}); return true;} private void Updatearea (final double area, final double perimeter) {Ui.runonuithreadasync (new Runnable () {@ overridepublic void Run () {if (area = = 0 | | perimeter = = 0) {Toolcontainertext = "";} Else{string Aerialtext = String.Format (Teapp.getappcontext (). getString (R.string.measure_area_area), TEUnits.instance.formatArea (area)); String VerticalText = String.Format (Teapp.getappcontext (). getString (R.string.measure_area_perimeter), TEUnits.instance.formatDistance (perimeter)) Toolcontainertext = String.Format ("%s\r\n%s", Aerialtext, VerticalText );} ToolcontaineR.settext (Toolcontainertext);}});} @Overridepublic void OnButtonClick (int tag) {Super.onbuttonclick (tag); Switch (TAG) {Case 1://Delete all points {//bug fix 18295 groundarea = 0; Updatearea (0, 0); Ui.runonrenderthread (New Runnable () {@Overridepublic void Run () {String objectId = (string) Isgworld.getinstan CE (). GetParam (7200); Simulate right click to end Drawing Isgworld.getinstance (). SetParam (8044, 0); Delete Object Isgworld.getinstance (). Getcreator (). DeleteObject (OBJECTID); and start adding again Startdrawpolygon ();}); Get object break; } Case 3://Calculate ground area doworkasync (); Break Default:break; }} @Overrideprotected void DoWork () {if (Groundarea <= 0) {isgworld.getinstance (). Addonanalysisprogresslistener ( this); Groundarea = Calculategroundarea (); ISgworld.getinstance (). Removeonanalysisprogresslistener (This);}} @Overridepublic boolean onanalysisprogress (int currpos, int Range) {setprogress (currpos, range); return workcanceled;} @Overrideprotected void workcompleted () {if (workcanceled = = False) {String Groundtext = String.Format (TEAPP.GETAPPC Ontext (). getString (R.string.measure_area_ground), TEUnits.instance.formatArea (Groundarea)); String Text = String.Format ("%s\r\n%s", Groundtext, Toolcontainertext); Toolcontainer.settext (text);}} Private double Calculategroundarea () {String objectId = (string) isgworld.getinstance (). GetParam (7200); Iterrainpolygon Areapolygon = Isgworld.getinstance (). Getcreator (). GetObject (objectId). Castto (Iterrainpolygon.class); if (Areapolygon! = null) {Double area = isgworld.getinstance (). Getanalysis (). Measureterrainsurface (Areapolygon.getgeometry (), 0); return area; } return 0;} @Overrideprotected void Shownormalbuttons () {toolcontainer.removebuttons (); Toolcontainer.addbutton (1, r.drawable.delete); Toolcontainer.addbutton (2, R.drawable.delete_last_point); Toolcontainer.addbutton (3, R.drawable.calc_area);} @Overridepublic boolean onlbuttonup (int Flags, int X, int Y) {New Handler (Looper.getmainlooper ()). postdelayed (New Runnable () {@Overridepublic void run () {Ui.runonrenderthread (new Runnable () {@Overridepublic void run () {Strin G objectId = (String) isgworld.getinstance (). GetParam (7200); Iterrainpolygon Areapolygon = Isgworld.getinstance (). Getcreator (). GetObject (objectId). Castto (Iterrainpolygon.class); Ipolygon poly = Areapolygon.getgeometry (). Castto (Ipolygon.class); if (poly! = null) {Double area = (double) areapolygon.getparam (5430); Double perimeter = poly.getexteriorring (). GetLength (); Updatearea (area, perimeter); Groundarea = 0; }});}}, and return false;}}
Skylineglobe Android Development Area Calculation Sample code