最近在项目中遇到这么一个情况,在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;}@Overridepublic 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;}@Overridepublic 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);}//@Overridepublic 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);}@Overridepublic 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);}

转载于:https://www.cnblogs.com/gis-luq/p/3497785.html

ArcGIS for Android 中实现要素绘制时固定MapView相关推荐

  1. Android 中View的绘制机制源代码分析 三

    到眼下为止,measure过程已经解说完了,今天開始我们就来学习layout过程.只是在学习layout过程之前.大家有没有发现我换了编辑器,哈哈.最终下定决心从Html编辑器切换为markdown编 ...

  2. 从源码解析-Android中View的绘制流程及performTraversals方法

    谈谈Activity的setContentView是怎么加载XML视图的 谈谈Activity的View怎么与View绘制工具ViewRootImpl关联的 在前面两篇文章中分析了View是如何跟绘制 ...

  3. android listview 数据同步,android中ListView数据刷新时的同步方法

    本文实例讲述了android中ListView数据刷新时的同步方法.分享给大家供大家参考.具体实现方法如下: public class Main extends BaseActivity { priv ...

  4. android中的横竖屏切换,Android中横竖屏切换时Activity的生命周期

    Android中横竖屏切换时Activity的生命周期执行情况 1.默认情况下生命周期 (1)第一次进入界面 11-17 13:55:18.452: E/ImageListActivity(10586 ...

  5. Android中View(视图)绘制不同状态背景图片原理深入分析以及StateListDrawable使用详解...

    2019独角兽企业重金招聘Python工程师标准>>> 今天继续给大家分享下View的相关知识,重点有一下两点:   1.View的几种不同状态属性            2.如何根 ...

  6. Android中在使用Room时提示:Cannot figure out how to save this field into database. You can consider adding a

    场景 在Android中使用Room进行存储数据库时提示: Cannot figure out how to save this field into database. You can consid ...

  7. Android 中基本图像绘制

    看<Google Android 手机设计达人讲座>,觉得里面对绘图相关的几个类的描述很经典,怕忘记了就copy出来吧: 在Android中的绘图和现实中的绘图大同小异,View以及其子类 ...

  8. Android中实现照片滑动时左右进出的动画的xml代码

    场景 Android中通过ImageSwitcher实现相册滑动查看照片功能(附代码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/det ...

  9. android canvas drawrect画图,为什么在android中调用canvas.drawRect时只绘制一个矩形?

    我正在尝试使用foreach循环为ArrayList中的每个字符串绘制一个矩形,但它似乎只绘制了最后一个矩形. 我看过类似的问题,但他们遇到的问题包括矩形底部高于顶部并调用drawPaint - 但我 ...

最新文章

  1. HTML学习感想(4)【密码输入框、单选、复选框】
  2. 软件工程师到30岁就要转行?
  3. BZOJ 3694DTOJ 1972: 最短路
  4. react实现汉堡_利用 React 高阶组件实现一个面包屑导航
  5. 【C++grammar】访问控制与抽象类与纯虚函数
  6. Mysql在sql中截取时间类型字段的年月日和时间-DATE_FORMAT() 函数
  7. Windows10中安装VMware Workstation Pro 15.x与使用Ubuntu 20.04 LTS
  8. 软考高级系统架构设计师总结
  9. win10 外接键盘 win失效
  10. 网站APP信息以及用户数据泄露排查方案
  11. Project组合项目案例分享
  12. 怎样下载ImageNet数据集并使用?
  13. html内容被背景图片遮住怎么办_div被iframe遮住的几种情况及解决方法
  14. JavaScript将扁平化数据转为树形结构
  15. 通过蓝奏云与云端检测来实现软件自动更新
  16. Cesium入门(五):加载WMTS瓦片地图服务
  17. nodejs实现新闻爬虫
  18. 电气工程与计算机最好的大学,加州大学伯克利分校电气工程与计算机科学研究生怎么样?好不好...
  19. npm 查看指定 package 的依赖关系
  20. 教你用300万共享单车出行数据,预测骑行目的地 !(附源码)

热门文章

  1. 多用户用linux会很卡顿吗,新手学Linux系统,解决Linux系统卡顿的方法
  2. 开发测试矛盾java吧_不愿看到Java开发者再做的10件事
  3. win7 32 php+mysql+apache环境_win7 搭建PHP环境(php+mysql+apache)
  4. android8卡顿,Android 8.0系统曝光,解决了安卓系统卡顿的问题
  5. ncl 多个单一时间文件合并成一个nc文件_iOS逆向--MachoO文件
  6. [原创]windows下unix2dos dos2unix 文本文件批量转换工具
  7. SCPPO(二十):系统统一身份认证的改造之路
  8. 训练AI太辛苦?OpenAI新方法:不如让AI之间互教吧
  9. 网络协议 反扒机制 fidder 抓包工具
  10. CentOS7.5安装Tigervnc-server