SkylineGlobe Android 开发 面积计算示例代码:

如果之前熟悉SkylineGlobe桌面端的二次开发,看这些代码应该不难理解。

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; @Override
public MenuEntry getMenuEntry() {
return MenuEntry.createFor(this, R.string.mm_analyze_area, R.drawable.area,MenuEntry.MenuEntryAnalyze(), 20);
} private void startDrawPolygon()
{
// start draw polygon
ISGWorld.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 do not see the red "edit vertex helper polyline"
areaPolygon.getLineStyle().setWidth(-2.0); // Make the polygon a bit wider
}
} @Override
public boolean onBeforeOpenToolContainer() {
super.onBeforeOpenToolContainer();
showNormalButtons();
updateArea(0,0);
groundArea = 0;
UI.runOnRenderThread(new Runnable() {
@Override
public void run() {
// start draw polygon
startDrawPolygon();
// subscribe to lButtonUp as an event that causes the polygon to change
ISGWorld.getInstance().addOnLButtonUpListener(AreaTool.this);
}
});
return true;
} @Override
public boolean onBeforeCloseToolContainer(CloseReason closeReason) {
super.onBeforeCloseToolContainer(closeReason);
UI.runOnRenderThread(new Runnable() {
@Override
public 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() {
@Override
public 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);
}
});
} @Override
public 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() {
@Override
public void run() {
String objectId = (String) ISGWorld.getInstance().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;
} } @Override
protected void doWork() {
if(groundArea <= 0)
{
ISGWorld.getInstance().addOnAnalysisProgressListener(this);
groundArea = calculateGroundArea();
ISGWorld.getInstance().removeOnAnalysisProgressListener(this);
}
} @Override
public boolean OnAnalysisProgress(int CurrPos, int Range) {
setProgress(CurrPos, Range);
return workCanceled;
} @Override
protected void workCompleted() {
if(workCanceled == false)
{
String groundText = String.format(TEApp.getAppContext().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;
} @Override
protected 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);
} @Override
public boolean OnLButtonUp(int Flags, int X, int Y)
{
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
UI.runOnRenderThread(new Runnable() {
@Override
public void run() {
String 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;
}
}
});
}
}, 10);
return false;
} }

SkylineGlobe Android 开发 面积计算示例代码的更多相关文章

  1. Android开发中使用代码删除数据库

    更多信息参考:Android开发中使用代码删除数据库 在Android开发中,如果用到数据库,就会有一个很麻烦的问题,就是有时候需要删除数据库很麻烦,要打开Android Device Monitor ...

  2. Android 开发怎样做代码加密或混淆?

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 在大公司怎么做android代码混淆的?发现他们的软件用apktool反编译居然没看到classes.dex文件和当前安卓APP加固到底该如何做到防 ...

  3. Linux命令行下编译Android NDK的示例代码

    这几天琢磨写一个Android的Runtime用来加速HTML5 Canvas,让GameBuilder+CanTK 不但开发速度快,运行速度也能接近原生应用.所以花了点时间研究 Android ND ...

  4. android开发系列之代码整洁之道

    说起代码整洁之道,想必大家想到更多的是那本经典重构书籍.没错,记得当时自己读那本书的时候,一边结合项目实战,一边结合书中的讲解,确实学到了很多东西,对我自己的编码风格影响极深.随着时间的流逝,书中很多 ...

  5. 【项目实例】android开发游戏音效代码实例

    //音效的音量 int streamVolume; //定义SoundPool 对象 private SoundPool soundPool; //定义HASH表 private HashMap< ...

  6. Android开发工程师文集-相关控件的讲解,五大布局

    前言 大家好,给大家带来Android开发工程师文集-相关控件的讲解,五大布局的概述,希望你们喜欢 TextView控件 TextView控件有哪些属性: android:id->控件的id a ...

  7. Android开发网上的一些重要知识点[经验分享]

    1. android单实例运行方法 我们都知道Android平台没有任务管理器,而内部App维护者一个Activity history stack来实现窗口显示和销毁,对于常规从快捷方式运行来看都是s ...

  8. 【转载】Eclipse:Android开发中如何查看System.out.println的输出内容

    Android开发中在代码中通过System.out.println的输出内容不知道去哪了,在console视图中看不到.而通过Log.i之类的要在Logcat视图中看到,夹杂了太多的其它App及底层 ...

  9. IDEA插件(Android Studio插件)开发示例代码及bug解决

    IDEA插件(Android Studio插件)开发示例代码及bug解决 代码在actionPerformed方法中,有个AnActionEvent e 插件开发就是要求我们复写上述的这个方法即可,在 ...

随机推荐

  1. 前端周报:前端面试题及答案总结;JavaScript参数传递的深入理解

    1.2017前端面试题及答案总结 |掘金技术征文 "金三银四,金九银十",用来形容求职最好的几个月.但是随着行业的饱和,初中级前端er就业形势不容乐观. 行业状态不可控,我们能做的 ...

  2. Redis 入门 安装 命令

    win7 64位安装redis 及Redis Desktop Manager使用 引自:http://blog.csdn.net/joyhen/article/details/47358999 写基于 ...

  3. VUE基于ElementUI搭建的简易单页后台

    一.项目链接 GitHub 地址: https://github.com/imxiaoer/ElementUIAdmin 项目演示地址:https://imxiaoer.github.io/Eleme ...

  4. 喜闻乐见-Activity生命周期

    Activity的生命周期,对于Android开发者来说,再熟悉不过了.但是我们接触到的资料,绝大部分都只是谈了一些表面上的东西,例如各个回调的顺序等等.本文试图换个角度来讲解,也希望对各位读者有所帮 ...

  5. [20171124]bbed的使用问题2.txt

    [20171124]bbed的使用问题2.txt --//bbed 是探究oracle数据块的好工具,有时候不用转储,直接可以它看oracle内部块的内部结构.--//在使用中要注意一些问题,昨天又犯 ...

  6. Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    在主工程(ASP.NET WEB/WCF等)的NuGet里引用 System.Data.SQLite.Core 不仅仅是Service需要引用,主工程即使不直接使用SQLite的库,也需要引用. 若使 ...

  7. element-ui的回调函数Events的用法

    做轮播的时候想用这个change回调函数,但是官方文档上竟然就只列了这么一行东西,完全没有示例代码(也可能我没找到哈) 鼓捣了半天,东拼西凑终于找到了靠谱的使用方法,其实很简单 在轮播组件上加上@ch ...

  8. Asp.Net WebApi Get请求整理(一)

    Asp.Net WebApi+JQuery Ajax的Get请求整理 一.总结 1.Asp.Net WebApi默认不支持Get请求,需要在Action方法上指定[HttpGet], 除非Action ...

  9. python中json序列化的东东

    之所以写这个因为自己总是弄混了,容易弄错,记下来有事没事看看   序列化是指把变量从内存中变成可存储或传输的过程称之为序列化用(使用dump或者dumps),把变量内容从序列化的对象重新读到 内存里称 ...

  10. 阿里八八β阶段Scrum(1/5)

    今日进度 叶文滔: 修改了α阶段遗留的部分界面BUG,比如状态栏白底等 张岳: 修复用户模块信息修改返回失败的BUG 林炜鸿: 重构了添加事件的代码,增加可修改的特性 黄梅玲: 绘制了新的日程显示格界 ...