用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

ArcGIS二维地图标绘

2016-05-24 作者: 小木举报

[android]代码库

/**
     * 地图控件单击事件
     * @param e 屏幕单击事件
     * @return boolean
     */
    public boolean onSingleTap(MotionEvent e) {
         
        // 如果正处于编辑状态且不处于查询状态
        if(!isQuery&&isEdit){
         
            // 设置浮动按钮可见
            save.setVisibility(Button.VISIBLE);
            cancel.setVisibility(Button.VISIBLE);
             
            // 如果当前正在编辑的类型为点
            if (geometryType.length() > 1 && geometryType.equalsIgnoreCase("POINT") && isEdit) {
                 
                // 绘制点时首先清除图层要素
                Log.d(TAG,"---->lastPointID:"+lastGraphicID);
                Log.d(TAG,"---->lastType:"+lastType);
                 
                if(lastGraphicID!=-1&&lastType.equalsIgnoreCase(geometryTypes[0])){
                     
                    gLayer.updateGraphic(lastGraphicID, map.toMapPoint(new Point(e.getX(), e.getY())));
                     
                    Log.d(TAG,"---->Update Point----<");
                 
                }else{
                     
                    Graphic graphic = new Graphic(map.toMapPoint(new Point(e.getX(), e.getY())),new SimpleMarkerSymbol(Color.RED,10,STYLE.CIRCLE),graphicAttributes,null);
                     
                    Log.d(TAG,"---->Add Point----<");
                    // 将新建点要素添加到图层上
                    lastGraphicID = gLayer.addGraphic(graphic);
                     
                    map.addLayer(gLayer);
                }
                Log.d(TAG,"---->NowPointID:"+lastGraphicID);
                 
                lastType = geometryTypes[0];
                     
            }else if(geometryType.length() > 1&& (geometryType.equalsIgnoreCase("POLYLINE"))&& isEdit) {
                // 如果当前正在编辑的类型为线
                Log.d(TAG,"---->L lastType:"+lastType);
                // 得到移动后的点
                Point movePoint = new Point(map.toMapPoint(e.getX(), e.getY()).getX(),map.toMapPoint(e.getX(), e.getY()).getY());
                 
                // 判断startPoint是否为空,如果为空,给startPoint赋值
                if (startPoint == null) {
     
                    polyline = new Polyline();
     
                    startPoint = new Point(movePoint.getX(),movePoint.getY());
     
                    //将第一个点存入poly中
                    polyline.startPath(startPoint);
                     
                }else{
                    // 如果要素存在两点以上(即存在线段)
                    if(lastGraphicID!=-1&&lastType.equalsIgnoreCase(geometryTypes[1])&&polyline.getPointCount()>1){
                         
                        // 将移动的点放入poly中
                        polyline.lineTo(movePoint);
                         
                        gLayer.updateGraphic(lastGraphicID,polyline);
                         
                        map.addLayer(gLayer);
                         
                    }else{
                        // 将移动的点放入poly中
                        polyline.lineTo(movePoint);
                         
                        Graphic linegraphic = new Graphic(polyline,new SimpleLineSymbol(Color.RED, 3),graphicAttributes,null);
                         
                        lastGraphicID = gLayer.addGraphic(linegraphic);
             
                        map.addLayer(gLayer);
                    }
                     
                }
                lastType = geometryTypes[1];
     
            }else if(geometryType.length() > 1&& (geometryType.equalsIgnoreCase("POLYGON"))&& isEdit) {
                // 如果当前正在编辑的类型为面
                Log.d(TAG,"---->G lastType:"+lastType);
                // 得到移动后的点
                Point movePoint = map.toMapPoint(e.getX(), e.getY());
                 
                // 判断startPoint是否为空,如果为空,给startPoint赋值
                if (startPoint == null) {
                     
                    startPoint = new Point(movePoint.getX(),movePoint.getY());
     
                    // 将第一个点存入polygon中
                    polygon.startPath(startPoint);
                     
                    Log.d(TAG, "First Point Polygon!");
                     
                }else{
                    // 将后续点加入polygon中
                    polygon.lineTo(movePoint);
                    // 如果上一要素类型为polygon
                    if(lastGraphicID!=-1&&lastType.equalsIgnoreCase(geometryTypes[2])&&polygon.getPointCount()>3){
                        // 将起点加入要素中,闭合图形
                        polygon.lineTo(startPoint);
                        // 更新图形信息
                        gLayer.updateGraphic(lastGraphicID, polygon);
                         
                        map.addLayer(gLayer);
                        // 移除闭合点
                        polygon.removePoint(0, -1);
                         
                        Log.d(TAG,"Polygon Point >3:");
                         
                    }else if(lastType.equalsIgnoreCase(geometryTypes[2])&&polygon.getPointCount()==3){
                        // 将起点加入要素中,闭合图形
                        polygon.lineTo(startPoint);
                        // 新建闭合
                        Graphic areagraphic = new Graphic(polygon,new SimpleFillSymbol(Color.GRAY),graphicAttributes,null);
                        // 保存当前图形ID
                        lastGraphicID = gLayer.addGraphic(areagraphic);
                        // 移除闭合点
                        polygon.removePoint(0, -1);
                         
                        map.addLayer(gLayer);
                         
                        Log.d(TAG,"Polygon Point 3:");
                    }
                    Log.d(TAG,"Polygon Point Count:"+polygon.getPointCount());
                    Log.d(TAG,"Polygon LastGraohic ID:"+lastGraphicID);
                }
                lastType = geometryTypes[2];
            }
            hasFinish = false;
             
            return true;
             
        }


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...