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 ...
随机推荐
- Umbraco 的template使用的默认Model问题
Umbraco中的Template默认都继承自 Umbraco.Web.Mvc.UmbracoTemplatePage @inherits Umbraco.Web.Mvc.UmbracoTemplat ...
- Spring 属性配置
此文已由作者尧飘海授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 随着Spring的不断发展与完善,早期它的功能可能只看做是IOC(反转控制)的容器,或者其最大的亮点为DI( ...
- [CentOS7] 设置开机启动方式(图形界面或命令行)
由于CenOS之前一直都是通过修改inittab文件来修改开机启动模式,于是 通过 vim /etc/inittab 打开inittab来查看 如上所示,CentOS 7由于使用systemd而不是i ...
- Linux中关机和磁盘管理命令
常用的关机命令 shutdown -h 关机 -r 重启 halt poweroff reboot 重启 logout 退出登录命令 磁盘管理命令 df -h 以1024进制计算最合适的单位显示磁盘容 ...
- Codeforces - 77B - Falling Anvils - 几何概型
https://codeforc.es/contest/77/problem/B 用求根公式得到: \(p-4q\geq0\) 换成熟悉的元: \(y-4x\geq0\) 其中: \(x:[-b,b] ...
- IIS中使用子目录文件作为默认文档(Default Document)替代重定向
以前一直以为IIS应用程序的默认文档只能设置根目录下的文件,像index.html,default.aspx等,后来经同事指点,原来子目录或者子应用程序下的文件也可以添加到根应用程序的默认文档列表中. ...
- (PHP)redis Zset(有序集合 sorted set)操作
/** * * Zset操作 * sorted set操作 * 有序集合 * sorted set 它在set的基础上增加了一个顺序属性,这一属性在修改添加元素的时候可以指定,每次指定后,zset会自 ...
- 小R的棋子
小R的棋子(dp) 数轴上有 n 个位置可以摆放棋子,标号为1,2,3...n.小 R 现在要在一些位置摆放棋子,每个位置最多摆放一个棋子,摆放棋子的总数没有限制.小 R 不希望他摆放的棋子过于拥挤, ...
- CF622F The Sum of the k-th Powers(拉格朗日插值)
题意 给出 \(n,k\) , \(n\le10^9,k\le10^6\) ,求 \(\sum_{i=1}^n i^k(mod\;10^9+7)\) 题解 自然数幂次和,是一个\(k+1\)次多项式, ...
- 前后分离调用API跨域
前后分离调用API接口跨域问题 什么是跨域? 跨域是指一个域下的文档或脚本试图去请求另一个域下的资源,这里跨域是广义的. 广义的跨域: 资源跳转:A链接.重定向.表单提交. 资源嵌入: <li ...