public class HighlightFeatures extends Activity {
private MapView mapView;
private ArcGISTiledMapServiceLayer tiledMapServiceLayer;
private GraphicsLayer graphicsLayer;
private Graphic[] highlightGraphics;
private String mapURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyBasemap/MapServer";
@SuppressWarnings("serial")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.map);
mapView.setOnLongPressListener(new OnLongPressListener() {
public void onLongPress(float x, float y) {
identifyPoint(x, y);
}
});
tiledMapServiceLayer = new ArcGISTiledMapServiceLayer(mapURL);
graphicsLayer = new GraphicsLayer();
mapView.addLayer(tiledMapServiceLayer);
mapView.addLayer(graphicsLayer);
}
// 要素识别长按点
protected void identifyPoint(float x, float y) {
try {
graphicsLayer.removeAll();
Point pointClicked = mapView.toMapPoint(x, y);
IdentifyParameters params = new IdentifyParameters();
params.setGeometry(pointClicked);
params.setLayers(new int[] { 28 });
Envelope env = new Envelope();
mapView.getExtent().queryEnvelope(env);
params.setSpatialReference(mapView.getSpatialReference());
params.setMapExtent(env);
params.setDPI(96);
params.setMapHeight(mapView.getHeight());
params.setMapWidth(mapView.getWidth());
params.setTolerance(10);
// 执行查询任务
MyIdentifyTask mIdenitfy = new MyIdentifyTask();
mIdenitfy.execute(params);
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
protected void onPause() {
super.onPause();
mapView.pause();
}
@Override
protected void onResume() {
super.onResume();
mapView.unpause();
}
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) {
if (results != null && results.length > 0) {
highlightGraphics = new Graphic[results.length];
for (int i = 0; i < results.length; i++) {
Geometry geom = results[i].getGeometry();// 得到几何对象
String typeName = geom.getType().name();// 图层类型
lightShow(i, typeName, geom);// 高亮显示
IdentifyResult result = results[i];
Log.i("andli", "图层名称---" + result.getLayerName());
Log.i("andli", "图层id ---" + result.getLayerId());
Log.i("andli", "图层类型---" + typeName);
}
} else {
Toast.makeText(HighlightFeatures.this, "查询结果为空", 3000).show();
}
}
@Override
protected void onPreExecute() {
mIdentifyTask = new IdentifyTask(mapURL);
}
}
public void lightShow(int i, String typeName, Geometry geom) {
// 高亮显示查询结果
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]);
}
}
分享到:
相关推荐
代码经我调试运行可行,目前没有出现bug,也希望大家提出修正意见。 代码主要实现了自己设置查询语句,查询结果在地图上闪烁,居中显示并且高亮
Activiti6-流程跟踪监控图-节点-流程线高亮显示-支持通过、不通过、驳回、退回 支持内容: 已完成节点高亮显示、当前执行中节点红色显示 支持一个节点多条流出线,包括通过、不通过、驳回、退回,按照已执行操作正确...
在C#+AE编程中,我们往往需要闪烁或高亮显示选定的要素,本程序通过多种方式实现了这两种功能。其中,显示的要素是由用户框选的方式指定的。
Android长按圆型有颜色变化显示进度,长按结束事件:长按按钮是一个圆,加入了OnTouchListener事件的监听。长按后该圆会慢慢的变颜色,等到整个圆的颜色变化完成后,则触发另一事件。适用于长按结束事件,增加用户...
AE开发 开发查找地图元素并高亮显示代码
23-高亮显示案例.rar
主要介绍了react中实现搜索结果中关键词高亮显示,使用react实现要比js简单很多,方法都是大同小异,具体实现代码大家跟随脚本之家小编一起看看吧
快速实现树结构加载的ztree,搜索的结果高亮显示,带有复选框。
已完成节点高亮显示、当前执行中节点红色显示 支持一个节点多条流出线,包括通过、不通过、驳回、退回,按照已执行操作正确显示高亮流程线
高亮显示关键字。 因为在网上搜到的类似插件,觉得不是太完美,或者说是不太符合自己想要的要求,于是自己写的一个高亮显示关键字插件,感觉还可以
SAP - ABAP UltraEdit 高亮显示文件
基于Highlighting System插件的鼠标选中物体时,使物体高亮显示。在这个插件的基础上,改动部分没必要的功能,使物体可以高亮显示。直接调用该脚本里的方法就可实现物体高亮显示。
12-高亮显示输入的文本框.html
Arcgis api for javascript(4.5版本) - 点击多边形(Polygon)并高亮显示
react-reactmarker高亮显示关键字并为您的文字添加颜色
一.Es的配置 实现es的全文检索功能的第一步,首先从与es进行连接开始,这里我使用的是es的5.x java api语法. public TransportClient esClient() throws UnknownHostException{ Settings settings = Settings....
上次发布SQLSever2000查询分析器免安装版时没有语法高亮显示显示功能,现在补上.另外,有大虾来问是否能包含企业管理器,为此特意做了一下研究,发现企业管理器关联的COM组件太多,做成免安装版太大(仅SQLDMO.DLL就...
名称:Cross Words Highlight 划词高亮 -------------------- 版本:1.1.3 作者:1776243356a 分类:其他 -------------------- 概述:网页划词高亮,随时随地添加批注,记录笔记,方便快捷的管理正在阅读的网页文档...
基于html2canvas、pdfjs-dist、react-pdf实现高亮img、pdf资源中的矩形区域