ArcGIS for Android 中实现要素绘制时固定MapView
最近在项目中遇到这么一个情况,在MapView中要求实现绘制点、线、面。
在这里面就会遇到这么一个问题,绘制折线和多边形型时,每点击一个点屏幕就会跟着晃,使用起来很不方便(使用Note2 触控笔),所以有没有一种方法让我点击绘制界面开始,地图界面锁死,在绘制结束时ontouch事件才响应。
现在先说说思路,一般来说我设置MapView的OnTouch事件为Null,屏幕就不会跟着动了,但是同时OnTouch事件也没法使用了,这个方法不可用。但是流状线和流状面绘制是怎么实现的呢?经过查询,在OnTouch的中有以下两个方法:
public boolean onDragPointerMove(MotionEvent from, MotionEvent to)
public boolean onDragPointerUp(MotionEvent from, MotionEvent to)
这两个方法分别对应了按下时的滑动事件和滑动松开事件,我们让这两个方法在绘制折线和自定义面时返回false,屏幕就不会跟着跑了 。
MapOnTouchListener类如下:
public class MyTouchListener extends MapOnTouchListener
{
MultiPath polyline,polygon,line,freepolygon;
DrawType type = DrawType.None;
Point startPoint = null;
MapView map = null;
DrawWidget drawwidget =null; private View calloutView =null; int graphicFreelineId = 0;
int graphicLineId = 0;
int graphicFreePloygonId = 0;
int graphicPloygonId = 0; public MyTouchListener(Context context, MapView view,DrawWidget d,View v) {
super(context, view);
map = view;
drawwidget=d;
calloutView = v;
} public void setType(DrawType type) {
this.type = type;
}
public DrawType getType() {
return this.type;
} @Override
public boolean onSingleTap(MotionEvent e)
{
if(type == DrawType.Point)
{
Geometry geo = map.toMapPoint(new Point(e.getX(), e.getY()));
Graphic gra = addGeometryToLocalDB(geo);
if(gra!=null){
GraUID =mGraphicsLayer.addGraphic(gra);//添加要素至数据库
//弹出callout窗口
Point coordinate=(Point) geo;
drawwidget.showCallout(coordinate, calloutView);
mMyTouchListener.setType(DrawType.None);
}
return true;
}else if(type == DrawType.Line){
//获取屏幕点击坐标点
Point point = map.toMapPoint(new Point(e.getX(), e.getY()));
if (startPoint == null) {
startPoint = point;
line = new Polyline();
line.startPath(point);
//添加节点信息
Graphic graphic = new Graphic(point,new SimpleMarkerSymbol(Color.BLACK,5,STYLE.CIRCLE));
tmpLayer.addGraphic(graphic);
//添加线要素
Graphic graphic_line = new Graphic(line,FeatureSymbol.lineSymbol_new);
graphicLineId = mGraphicsLayer.addGraphic(graphic_line);
} else{
//添加线要素节点
Graphic graphic_t = new Graphic(point,new SimpleMarkerSymbol(Color.BLACK,5,STYLE.CIRCLE));
tmpLayer.addGraphic(graphic_t);
//更新线信息
line.lineTo(point);
mGraphicsLayer.updateGraphic(graphicLineId, line);
}
}else if(type == DrawType.Polygon){
//获取屏幕点击坐标点
Point point = map.toMapPoint(new Point(e.getX(), e.getY()));
if (startPoint == null) {
startPoint = point;
polygon = new Polygon();
polygon.startPath(point);
//添加节点信息
Graphic graphic = new Graphic(point,new SimpleMarkerSymbol(Color.BLACK,5,STYLE.CIRCLE));
tmpLayer.addGraphic(graphic);
//添加多边形要素
Graphic graphic_polygon = new Graphic(polygon,FeatureSymbol.polygonSymbol_new);
graphicPloygonId = mGraphicsLayer.addGraphic(graphic_polygon);
} else{
//添加要素节点
Graphic graphic_t = new Graphic(point,new SimpleMarkerSymbol(Color.BLACK,5,STYLE.CIRCLE));
tmpLayer.addGraphic(graphic_t);
//更新多边形信息
polygon.lineTo(point);
mGraphicsLayer.updateGraphic(graphicPloygonId, polygon);
}
}
return false;
} @Override
public boolean onDoubleTap(MotionEvent event) {
tmpLayer.removeAll();
if (type == DrawType.Line) {
if(line!=null){
Graphic gral = addGeometryToLocalDB(line);//添加要素至数据库
if(gral!=null){
mGraphicsLayer.updateGraphic(graphicLineId,gral);
drawwidget.showCallout(startPoint, calloutView);
}else{
mGraphicsLayer.removeGraphic(graphicLineId);
}
}else{
Toast.makeText(DrawWidget.super.context,"未添加任务要素!",Toast.LENGTH_SHORT).show();
}
GraUID =graphicLineId;
startPoint = null;
line = null;
mMyTouchListener.setType(DrawType.None);
DrawWidget.super.showMessageBox("折线绘制结束!");
return true;
}else if(type == DrawType.Polygon){
if(polygon!=null){
Graphic gra = addGeometryToLocalDB(polygon);
if(gra!=null){
mGraphicsLayer.updateGraphic(graphicPloygonId,gra ); //添加要素至数据库
//弹出callout窗口
drawwidget.showCallout(startPoint, calloutView);
}else{
mGraphicsLayer.removeGraphic(graphicPloygonId);
}
}else{
Toast.makeText(DrawWidget.super.context,"未添加任务要素!",Toast.LENGTH_SHORT).show();
}
GraUID =graphicPloygonId;
startPoint = null;
polygon = null;
mMyTouchListener.setType(DrawType.None);
DrawWidget.super.showMessageBox("多边形绘制结束!");
return true;
}
return super.onDoubleTap(event);
} //@Override
public boolean onDragPointerMove(MotionEvent from, MotionEvent to)
{
Point mapPt = map.toMapPoint(to.getX(), to.getY());
if (type == DrawType.Freeline)
{
if (startPoint == null)
{
polyline = new Polyline();
startPoint = map.toMapPoint(from.getX(), from.getY());
polyline.startPath((float) startPoint.getX(), (float) startPoint.getY());
graphicFreelineId = mGraphicsLayer.addGraphic(new Graphic(polyline,FeatureSymbol.lineSymbol_new));
}
polyline.lineTo((float) mapPt.getX(), (float) mapPt.getY());
mGraphicsLayer.updateGraphic(graphicFreelineId,new Graphic(polyline,FeatureSymbol.lineSymbol_new));
return true;
}
else if (type == DrawType.FreePolygon)
{
//polygonSymbol.setAlpha(80);
if (startPoint == null)
{
freepolygon = new Polygon();
startPoint = map.toMapPoint(from.getX(), from.getY());
freepolygon.startPath((float) startPoint.getX(), (float) startPoint.getY());
graphicFreePloygonId = mGraphicsLayer.addGraphic(new Graphic(freepolygon,FeatureSymbol.polygonSymbol_new));
}
freepolygon.lineTo((float) mapPt.getX(), (float) mapPt.getY());
mGraphicsLayer.updateGraphic(graphicFreePloygonId, new Graphic(freepolygon,FeatureSymbol.polygonSymbol_new));
return true;
}else if(type == DrawType.Polygon||type == DrawType.Line){
return false;//返回false,使屏幕不滑动固定死(两个位置)
}
return super.onDragPointerMove(from, to);
} @Override
public boolean onDragPointerUp(MotionEvent from, MotionEvent to)
{
if(type == DrawType.Line ||type == DrawType.Polygon){
return false;//返回false,使屏幕不滑动固定死(两个位置)
}else if(type ==DrawType.Freeline ){
Graphic gral = addGeometryToLocalDB(polyline);//添加要素至数据库
if(gral!=null){
mGraphicsLayer.updateGraphic(graphicFreelineId,gral);
drawwidget.showCallout(startPoint, calloutView);
}else{
mGraphicsLayer.removeGraphic(graphicFreelineId);
}
GraUID = graphicFreelineId;
startPoint = null;
polyline = null;//流状线
DrawWidget.super.mapView.setOnTouchListener(mDefaultMyTouchListener);
}else if(type == DrawType.FreePolygon){
Graphic gra = addGeometryToLocalDB(freepolygon);
if(gra!=null){
mGraphicsLayer.updateGraphic(graphicFreePloygonId,gra);//添加要素至数据库
drawwidget.showCallout(startPoint, calloutView);
}else{
mGraphicsLayer.removeGraphic(graphicFreePloygonId);
}
GraUID = graphicFreePloygonId;
startPoint = null;
freepolygon = null;//流状面
DrawWidget.super.mapView.setOnTouchListener(mDefaultMyTouchListener);
}
return super.onDragPointerUp(from, to);
}
ArcGIS for Android 中实现要素绘制时固定MapView的更多相关文章
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
Android中View的绘制过程 onMeasure方法简述 附有自定义View例子 Android中View的绘制过程 当Activity获得焦点时,它将被要求绘制自己的布局,Android fr ...
- 【转】Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
Android中View的绘制过程 当Activity获得焦点时,它将被要求绘制自己的布局,Android framework将会处理绘制过程,Activity只需提供它的布局的根节点. 绘制过程从布 ...
- Android 中View的绘制机制源代码分析 三
到眼下为止,measure过程已经解说完了,今天開始我们就来学习layout过程.只是在学习layout过程之前.大家有没有发现我换了编辑器,哈哈.最终下定决心从Html编辑器切换为markdown编 ...
- Android 中View的绘制机制源代码分析 一
尊重原创: http://blog.csdn.net/yuanzeyao/article/details/46765113 差点儿相同半年没有写博客了,一是由于工作比較忙,二是认为没有什么内容值得写, ...
- Android 中View的绘制机制源代码分析 二
尊重原创:http://blog.csdn.net/yuanzeyao/article/details/46842891 本篇文章接着上篇文章的内容来继续讨论View的绘制机制,上篇文章中我们主要解说 ...
- Android 中Activity生命周期分析:Android中横竖屏切换时的生命周期过程
最近在面试Android,今天出了一个这样的题目,即如题: 我当时以为生命周期是这样的: onCreate --> onStart -- ---> onResume ---> onP ...
- Android中使用ListView绘制自定义表格(2)
上回再写了<Android中使用ListView绘制自定义表格>后,很多人留言代码不全和没有数据样例.但因为项目原因,没法把源码全部贴上来.近两天,抽空简化了一下,做了一个例子. 效果图如 ...
- Android中View的绘制流程(专题讲解)
Android中的UI视图有两种方式实现:.xml文件(实现代码和UI的分离)和代码实现. Android的UI框架基本概念: 1. Activity:基本的页面单元,Activity包含一个Wind ...
- Android中实现照片滑动时左右进出的动画的xml代码
场景 Android中通过ImageSwitcher实现相册滑动查看照片功能(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/det ...
随机推荐
- Leetcode: 67. Add Binary
二进制加法 https://discuss.leetcode.com/topic/33693/another-simple-java public String addBinary(String a, ...
- The Little Prince
Chapter 1 That is why, at the age of six, I gave up what might have been a magnificant career as a p ...
- bzoj4873: [Shoi2017]寿司餐厅(最小割)
传送门 大佬们是怎么一眼看出这是一个最大权闭合子图的……大佬好强->这里 1.把所有区间$(i,j)$看成一个点,如果权值大于0,则从$S$向他连边,容量为权值,否则从它向$T$连边,容量为权值 ...
- MCP|LDY|Mass Spectrometry-based Absolute Quantification of 20S Proteasome Status for Controlled Ex-vivo Expansion of Human Adipose-derived Mesenchymal Stromal/Stem Cells(基于质谱技术的20S蛋白酶体绝对定量方法监控人体脂肪...
期刊名:Mol Cell Proteomics 发表时间:(2019年4月) IF:5.232 概述 20S蛋白酶体是一种多亚基蛋白质复合物,参与许多组织细胞生命活动过程.本研究基于SILAC标记 ...
- rlwrap: command not found和解决linux下sqlplus 提供浏览历史命令行的功能
rlwrap工具可以解决linux下sqlplus 提供浏览历史命令行的功能,和删除先前输入错误的字母等问题 1.安装 需要readline包 这个安装光盘就有 [root@asm RedHat]# ...
- IO模式和IO多路复用详解
网络编程里常听到阻塞IO.非阻塞IO.同步IO.异步IO等概念,总听别人装13不如自己下来钻研一下.不过,搞清楚这些概念之前,还得先回顾一些基础的概念. 1 基础知识回顾 注意:咱们下面说的都是Lin ...
- AX 2012 窗体增加分隔线
在AX中将窗体控件分区一般通过group来实现,但是类似salesTable的可以调整大小的分区其实也是用group控件再加一些方法实现的. 1, 留意splitGroup属性: Autodeclar ...
- image在div中有留白如何解决
解决办法: 1. 将img图片display:block,即可去掉div和img之间的空白: 2. 将div的line-height设置得足够小,也可以去掉空白,例如div{line-height:5 ...
- DateAdapterForDay
public class DateAdapterForDay extends XmlAdapter<String, Date> { private SimpleDateFormat dat ...
- 【手撸一个ORM】MyOrm的使用说明
[手撸一个ORM]第一步.约定和实体描述 [手撸一个ORM]第二步.封装实体描述和实体属性描述 [手撸一个ORM]第三步.SQL语句构造器和SqlParameter封装 [手撸一个ORM]第四步.Ex ...