码迷,mamicode.com
首页 > 移动开发 > 详细

《ArcGIS Runtime SDK for Android开发笔记》——(15)、要素绘制Drawtools3.0工具DEMO

时间:2017-02-23 17:26:23      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:展开   otf   online   通过   封装   images   layer   工具类   file   

1、前言

移动GIS项目开发中点线面的要素绘制及编辑是最常用的操作,在ArcGIS Runtime SDK for iOS 自带AGSSketchLayer类可以帮助用户快速实现要素的绘制,图形编辑。但是在ArcGIS Runtime SDK for Android的版本中并没有提供类似的功能,实现过程相对较复杂。(10.2.8及以下版本需要用户自定义扩展实现,通过扩展MapOnTouchListener类实现,Quartz版SDK默认自带)

之前有大神gispace封装了DrawTools2.0工具类DEMO,实现了简单的要素绘制。但是并没有对要素绘制及编辑状态做很好的体现,如节点,回退操作等。所以鉴于此,我在DrawTools2.0工具类基础上扩展实现了DrawTools3.0,该版本能够实现基本点线面要素的绘制,精细化展现节点变化信息,支持加点,删点,移点操作。

DrawTools2.0地址:http://blog.csdn.net/gispace/article/details/6723459

转载请注明出处:http://www.cnblogs.com/gis-luq/p/5857661.html 

2、使用说明

DrawTools3.0基于DrawTools2.0扩展开发而来,使用思路基本一致,增加节点增加、节点删除、回退操作,要素编辑状态开启与关闭操作。

开源项目库地址:http://git.oschina.net/gis-luq/DrawTool3.0

技术分享

使用流程

  1. 初始化DrawTool工具。
  2. 使用Activity扩展DrawEventListener ,并将当前Activity设置为DrawTool的Listener。
  3. 实现DrawEventListener中的handleDrawEvent方法。
  4. 使用DrawTool工具绘制图形。

MainActivity.java 

技术分享
package com.gis_luq.drawtoolsdemo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import android.widget.Button;

import com.esri.android.map.GraphicsLayer;
import com.esri.android.map.MapOnTouchListener;
import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
import com.esri.core.map.Graphic;
import com.esri.core.table.TableException;
import com.gis_luq.lib.Draw.DrawEvent;
import com.gis_luq.lib.Draw.DrawEventListener;
import com.gis_luq.lib.Draw.DrawTool;

import java.io.FileNotFoundException;

public class MainActivity extends Activity implements DrawEventListener {

    private Context context;
    private MapView mapView = null;
    private ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = null;
    private GraphicsLayer graphicsLayer = null;

    private Graphic selectGraphic = null;
    private DrawTool drawTool;

    public MapOnTouchListener mapDefaultOnTouchListener;//默认点击事件
    public DrawEventListener drawEventListener;//要素绘制点击事件


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        context = this;

        this.mapView = (MapView)this.findViewById(R.id.map);//设置UI和代码绑定

        String strMapUrl="http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer";
        this.arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(strMapUrl);
        this.mapView.addLayer(arcGISTiledMapServiceLayer);

        graphicsLayer = new GraphicsLayer();
        this.mapView.addLayer(graphicsLayer);

        // 初始化DrawTool实例
        this.drawTool = new DrawTool(this.mapView);
        // 将本Activity设置为DrawTool实例的Listener
        this.drawTool.addEventListener(this);

        //设置地图事件
        mapDefaultOnTouchListener = new MapOnTouchListener(this.mapView.getContext(), this.mapView);
        drawEventListener = this;

        ToolsOnClickListener toolsOnClickListener = new ToolsOnClickListener(context,drawTool,selectGraphic,mapView);
        Button btnDrawPoint = (Button)this.findViewById(R.id.btnDrawPoint);
        btnDrawPoint.setOnClickListener(toolsOnClickListener);

        Button btnDrawPolyline = (Button)this.findViewById(R.id.btnDrawPolyline);
        btnDrawPolyline.setOnClickListener(toolsOnClickListener);

        Button btnDrawFreePolyline = (Button)this.findViewById(R.id.btnDrawFreePolyline);
        btnDrawFreePolyline.setOnClickListener(toolsOnClickListener);

        Button btnDrawPolygon = (Button)this.findViewById(R.id.btnDrawPolygon);
        btnDrawPolygon.setOnClickListener(toolsOnClickListener);

        Button btnDrawFreePolygon = (Button)this.findViewById(R.id.btnDrawFreePolygon);
        btnDrawFreePolygon.setOnClickListener(toolsOnClickListener);

        Button btnDrawCircle = (Button)this.findViewById(R.id.btnDrawCircle);
        btnDrawCircle.setOnClickListener(toolsOnClickListener);

        Button btnDrawEnvlope = (Button)this.findViewById(R.id.btnDrawEnvlope);
        btnDrawEnvlope.setOnClickListener(toolsOnClickListener);

        Button btnDrawEditor = (Button)this.findViewById(R.id.btnDrawSave);
        btnDrawEditor.setOnClickListener(toolsOnClickListener);

        Button btnDrawUndo = (Button)this.findViewById(R.id.btnDrawUndo);
        btnDrawUndo.setOnClickListener(toolsOnClickListener);

        Button btnDrawDeleteNode = (Button)this.findViewById(R.id.btnDrawDeleteNode);
        btnDrawDeleteNode.setOnClickListener(toolsOnClickListener);

    }

    @Override
    public void handleDrawEvent(DrawEvent event) throws TableException, FileNotFoundException {
        // 将画好的图形(已经实例化了Graphic),添加到drawLayer中并刷新显示
        this.graphicsLayer.addGraphic(event.getDrawGraphic());
        // 修改点击事件为默认
        this.mapView.setOnTouchListener(mapDefaultOnTouchListener);
    }
}
技术分享

 ToolsOnClickListener.java

技术分享
package com.gis_luq.drawtoolsdemo;

import android.content.Context;
import android.view.View;

import com.esri.android.map.MapView;
import com.esri.core.map.Graphic;
import com.gis_luq.lib.Draw.DrawTool;

/**
 * 绘图点击事件
 * Created by gis-luq on 2016/1/2.
 */
public class ToolsOnClickListener implements View.OnClickListener {

    private Context context = null;
    private DrawTool drawTool = null;
    private Graphic selectGraphic =null;
    private MapView mapView = null;

    public ToolsOnClickListener(Context context, DrawTool drawTool, Graphic selectGraphic, MapView mapView) {
        this.context = context;
        this.drawTool = drawTool;
        this.selectGraphic = selectGraphic;
        this.mapView = mapView;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnDrawPoint://绘制点
                drawTool.activate(DrawTool.POINT);
                break;
            case R.id.btnDrawPolyline://绘制线
                drawTool.activate(DrawTool.POLYLINE);
                break;
            case R.id.btnDrawFreePolyline://绘制流状线
                drawTool.activate(DrawTool.FREEHAND_POLYLINE);
                break;
            case R.id.btnDrawPolygon://绘制面
                drawTool.activate(DrawTool.POLYGON);
                break;
            case R.id.btnDrawFreePolygon://绘制流状面
                drawTool.activate(DrawTool.FREEHAND_POLYGON);
                break;
            case R.id.btnDrawCircle://绘制圆
                drawTool.activate(DrawTool.CIRCLE);
                break;
            case R.id.btnDrawEnvlope://绘制矩形
                drawTool.activate(DrawTool.ENVELOPE);
                break;
            case R.id.btnDrawSave://保存
                drawTool.sendDrawEndEvent();
                break;
            case R.id.btnDrawUndo://回退
                drawTool.actionUndo();
                break;
            case R.id.btnDrawDeleteNode://删除节点
                drawTool.actionDelete();
                break;
        }

    }
}
技术分享

 

《ArcGIS Runtime SDK for Android开发笔记》——(15)、要素绘制Drawtools3.0工具DEMO

标签:展开   otf   online   通过   封装   images   layer   工具类   file   

原文地址:http://www.cnblogs.com/love540376/p/6434340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!