第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

ArcGIS Runtime For Android 開發(fā)(4)

標(biāo)簽:
Android
第四课 图形绘制

加载完地图以后,我们可能需要做一些数据采集的操作,那么绘制图形就非常的有用处了。在ArcGIS Runtime For Android 中,我们使用GraphicsLayer来承载绘制的图形。

我们先看一下绘制的逻辑:图片描述
地图中应该包含绘制层---------->GraphicsLayer
在界面上,点击按钮向系统发送命令-------->需要一个枚举类,存放命令
地图需要监听点击事件 ---------->OnSingleTapListener
每个图形需要一个默认的符号------>Symbol
图形是根据点来绘制的,所以需要保存图形的点数据------->List<Point>
那么接下来就简单了,根据ArcGIS Runtime For Android 提供的API,我们就可以完成图形的绘制。
首先,新建一个ActionCommand枚举类

public enum ActionCommand {
     NULL,                 //置空
    DRAW_POINT,           //绘制点
    DRAW_LINE,            //绘制线
    DRAW_POLYGON        //绘制面
}

在地图界面,实例化一个GraphicsLayer,并将这个GraphicsLayer加入到Map中;

GraphicsLayer drawLayer;
MapView mapView;
List<Point> tempDrawPoints;
PloyLine pPloyLine;
Ploygon pPloygon;
……
public void InitControl()
{
     mapView =(MapView) findViewById(R.id.mapView);
     mapView.setOnSingleTapListener(onSingleTap);
}
public InitData()
{
    String url ="https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer"; 
    ArcGISTiledMapServiceLayer serviceLayer=new ArcGISTiledMapServiceLayer(url ); 
    mapView.addLayer(serviceLayer);//添加图层到地图窗口中
    drawLayer=new GraphicsLayer ();
    mapView.addLayer(drawLayer);
   tempDrawPoints=new ArrayList();
}

添加监听事件:

 OnSingleTapListener onSingleTapListener = new OnSingleTapListener() {

        @Override
        public void onSingleTap(float v, float v1) {
            Point pnt = mapView.toMapPoint(v, v1);
            switch (SystemManager.curAction) {
                case NULL: 
                    break;  
                case DRAW_POINT:
                    DrawPoint(pnt );
                    break;
                case DRAW_LINE: 
                    DrawLine(pnt );
                    break;
                case DRAW_POLYGON:  
                    DrawPolygon(pnt );
                    break; 
            }
        }
    };

然后是绘制图形:

public void DrawPoint(Point pnt)
{
       Graphic graphic = new Graphic(curPoint, simpleSymbol);
       drawLayer.addGraphic(graphic);
}
public void DrawLine(Point pnt)
{
    if (tempPoints.size() == 1) {
    Point point = tempDrawPoints.get(0);
    DrawPoint(point )
} 
esle{
    drawLayer.removeAll();
    pPloyLine= new PloyLine();
    for (int i = 1; i < tempDrawPoints.size(); i++) {
        Point sPoint = tempDrawPoints.get(i - 1);
        Point ePoint = tempDrawPoints.get(i);
        Line line = new Line();
        line.setStart(sPoint);
        line.setEnd(ePoint);
        pPloyLine.addSegment(line, false);
    }
    Graphic polylineGraphic= new Graphic(pPloyLine,
                    MapManager.simpleLineSymbol);
    int UID=drawLayer.addGraphic(polylineGraphic);}
}
public void DrawPolygon()
{
    if (tempPoints.size() == 1) {
    Point point = tempDrawPoints.get(0);
     DrawPoint(point )
    } 
   else {
            drawLayer.removeAll();
            pPolygon = new Polygon();
            for (int i = 1; i < tempDrawPoints.size(); i++) {
                Point sPoint = tempDrawPoints.get(i - 1);
                Point ePoint = tempDrawPoints.get(i);
                Line line = new Line();
                line.setStart(sPoint);
                line.setEnd(ePoint);
                pPolygon.addSegment(line, false);
            }
            Graphic polygonGraphic = new Graphic(pPolygon,
                    MapManager.simpleFillSymbolInspection);
            int UID=drawLayer.addGraphic(polygonGraphic);
        }
} 
點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開發(fā)工程師
手記
粉絲
19
獲贊與收藏
19

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消