转自:http://blog.csdn.net/wozaifeiyang0/article/details/7323606

HighlightFeatures

要素高亮化功能,相信有其他gis开发经营的开发人员都有过相应的实现经验,对于高亮要素,简单说起来就是我们查询的或识别出来的要素进行渲染,让其突出显示而已,这个例子中涉及后面要介绍的识别的内容,我们只简单介绍相关的知识,主要介绍要素对象的渲染(也就是所谓的高亮),来看代码:

mapView.setOnLongPressListener(new OnLongPressListener() {

public void onLongPress(float x,float y) {

try {

if (tiledMapServiceLayer.isInitialized() && selectedLayerIndex >= 0) {

graphicsLayer.removeAll();

/*

*点击地图的点

*/

Point pointClicked = mapView.toMapPoint(x, y);

/*

* 识别任务所需的参数,初始化相应的值

*/

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);

/*

* 这是我们自己扩展的类,在其中主要实现了IdentifyTask的请求

*/

MyIdentifyTask mIdenitfy = new MyIdentifyTask();

//执行异步操作并将参数传入异步操作中

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();

}

}

});

上面的代码中,主要给地图添加了一个长按地图事件监听,在事件处理函数中主要做了初始化识别任务的参数及其执行我们扩展的MyIdentifyTask操作,MyIdentifyTask其实就是一个异步请求类,下面我们来看看,这异步请求类做了什么,代码如下:

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];//获取参数

try {

mResult = mIdentifyTask.execute(mParams);//执行识别操作

catch (Exception e) {

e.printStackTrace();

}

}

return mResult;

}

@Override

protected void onPostExecute(IdentifyResult[] results) {

// TODO Auto-generated method stub

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

//生成要素对象数组

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();

//在这里我们进行要素的高亮显示,也就是要素渲染工作

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, 20, 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);//初始化识别任务实例

}

}

在这里我们可以看到,这个异步类主要做了实例化识别任务对象,并且执行识别任务,返回的结果再进行渲染显示,对于Android中的异步类AsyncTask应该有所了解吧,简单介绍一下他的执行过程,当我们生成AsyncTask实例并执行execute()方法后,他的内部还是执行顺序为onPreExecute()à doInBackground()àonPostExecute()

这样我们的高亮功能示例就介绍完成了,要想实现不同的、五彩缤纷的效果那就需要我们深入了解要素的渲染类及其相关的特性。

ArcGIS for Android示例解析之高亮要素-----HighlightFeatures的更多相关文章

  1. ArcGIS for Android示例解析之空间查询-----QueryTask

    转自:http://blog.csdn.net/wozaifeiyang0/article/details/7331450 QueryTask 查询功能在GIS中是一个不可或缺的重要功能,示例中提供了 ...

  2. ArcGIS for Android示例解析之离线地图-----LocalTiledLayer

    转自:http://blog.csdn.net/wozaifeiyang0/article/details/7327423 LocalTiledLayer 看到这个标题是否是很激动,如题,该示例就是添 ...

  3. Arcgis for android 离线查询

    参考.. 官方API demo ... 各种资料 以及.. ArcGIS for Android示例解析之高亮要素-----HighlightFeatures ttp://blog.csdn.net/ ...

  4. ArcGIS for Android离线数据编辑实现原理

    来自:http://blog.csdn.net/arcgis_mobile/article/details/7565877 ArcGIS for Android中现已经提供了离线缓存图片的加载功能,极 ...

  5. ArcGIS for Android地图控件的5大常见操作

    GIS的开发中,什么时候都少不了地图操作.ArcGIS for Android中,地图组件就是MapView,MapView是基于Android中ViewGroup的一个类(参考),也是ArcGIS ...

  6. ArcGIS for Android学习(一)

    GIS的开发中,什么时候都少不了地图操作.ArcGIS for Android中,地图组件就是MapView,MapView是基于Android中ViewGroup的一个类(参考),也是ArcGIS ...

  7. 外业数据采集平台(GPS+Android Studio+Arcgis for android 100.2.1)

    外业数据采集平台 1. 综述 在室外,通过平板或者手机接收GPS坐标,实时绘制点.线.面数据,以便为后续进行海域监测.土地确权.地图绘图提供有效数据和依据. 2. 技术路线 Android studi ...

  8. arcgis for android常见问题回答

    Q:arcgis for android最新版本是多少?(2014-7-18) Arcgis for android 10.2.3 sdk 百度盘下载地址:http://pan.baidu.com/s ...

  9. 【Arcgis for android】相关教程收集自网络

    请加入qq群:143501213 一起交流和学习 推荐博客: 张云飞VIR http://www.cnblogs.com/vir56k/tag/arcgis%20for%20android/ arcg ...

随机推荐

  1. echarts雷达图

    用echarts展现雷达图的定制 <!doctype html> <html> <head> <meta charset="utf-8"& ...

  2. 分页 page

    1.根据条件计算出数据的总数 2.import(page类); 3.实例化分页类 4.设置相关的参数 5.调用show()方法 // 导入分页类  import('ORG.Util.Page');$p ...

  3. php 用户验证的简单示例

    发布:thebaby   来源:net     [大 中 小] 本文介绍下,在php中,进行用户登录验证的例子,这个是基于WWW-Authenticate登录验证的实例,有需要的朋友参考下吧. 大家是 ...

  4. MVC之重定向

    MVC的重定向主要通过RedirectResult和RedirectToRouteResult实现.很显然,这两个对象都是MVC返回对象ActionResult的两个继承,具体原理不赘述. 这两个方法 ...

  5. 【5】了解Bootstrap预置的栅格系统

    在开篇之前我们来说2个class,因为以后要用到的 <div class="container"> ... </div> 用.container包裹页面上的 ...

  6. Android分类前言

    柚子园项目搁置后,半年多时间里都在开发微信公众平台和在公司实习,用的都是python,django,bottle,已经很久没有开发android了.技术的东西,不用就容易生疏甚至忘掉.刚好现在需要写毕 ...

  7. 六,WPF的Application类

    Application.ShutdownMode属性:通过,只要有一个窗口还没有关闭,Application类就保持应用程序处于有效状态,如果这不是所期望的行为,就可以调整该属性. 应用程序事件 Ap ...

  8. Django路由

    一.路由流程 1. 用户浏览器发出请求后,通过根url设置,去找urlpattern变量.在setting.py中对 ROOT_URLCONF进行配置,以确定根URLconf(URL configur ...

  9. Razor语法小记

    1.代码块中,<text>标签用来输出,如: @{ <text>sdfsdf</text> } 输出Html: sdfsdf

  10. nodejs 第一次使用

    在win7下安装与使用 1 nodejs官网下载,安装  https://nodejs.org/ 2 下载最新的 npm,在E:\nodejs\中解压  http://nodejs.org/dist/ ...