安卓智能地图开发与实施十八:空间要素绘制

来源:互联网 发布:英语单词读音软件小学 编辑:程序博客网 时间:2024/06/07 01:51

空间要素绘制

这里写图片描述

日常应用中无论是草图绘制,还是外业采集都需要在移动端进行空间要素的绘制。而ArcGIS Runtime SDK for Android中提供了Geometry、Feature、Graphic,这三者到底如何使用,本文稍微做做解答。

空间要素(Geometry)

Geometries用以在特定地理位置上通过形状来表达真实世界的对象。图层范围、视图范围、GPS定位都是通过Geometries表达实现进一步的数据编辑、空间分析、地理处理、位置与面积量算都离不开空间要素。

这里写图片描述

Features 与 Graphics

Feature(com.esri.arcgisruntime.data.Feature),存储于Feature Table中,在 Feature Layer中进行显示。包含的Geometry 必须同一类型。包含的属性信息其字段信息必须相同。用以Feature Table中进行更新、删除等操作。
Graphic(com.esri.arcgisruntime.mapping.view. Graphic ),存储于运行内存中,在Graphics OverLay中进行显示。包含的Geometry类型可以不统一。通过类对象直接创建,仅用以绘制性显示。

这里写图片描述

创建 – 矩形、点

Envelope envelope = new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.getWgs84());Point pt = new Point(34.056295, -117.195800, SpatialReferences.getWgs84());PointCollection stateCapitalsPST = new PointCollection(SpatialReferences.getWgs84());stateCapitalsPST.add(-121.491014, 38.579065); // Sacramento, CAstateCapitalsPST.add(-122.891366, 47.039231); // Olympia, WAstateCapitalsPST.add(-123.043814, 44.93326); // Salem, ORstateCapitalsPST.add(-119.766999, 39.164885); // Carson City, NVMultipoint multipoint = new Multipoint(stateCapitalsPST);

创建 – 线、面

PointCollection borderCAtoNV = new PointCollection(SpatialReferences.getWgs84());borderCAtoNV.add(-119.992, 41.989);borderCAtoNV.add(-119.994, 38.994);borderCAtoNV.add(-114.620, 35.0);Polyline polyline = new Polyline(borderCAtoNV);PointCollection coloradoCorners = new PointCollection(SpatialReferences.getWgs84());    coloradoCorners.add(-109.048, 40.998);    coloradoCorners.add(-102.047, 40.998);    coloradoCorners.add(-102.037, 36.989);    coloradoCorners.add(-109.048, 36.998);    Polygon polygon = new Polygon(coloradoCorners);

空间要素绘制 – SketchEditor

绘制类型(SketchCreationMode)

  • POINT
  • MULTIPOINT
  • POLYLINE
  • POLYGON
  • FREEHAND_LINE
  • FREEHAND_POLYGON

初始化地图

mainMapView = (MapView) findViewById(R.id.mainMapView);mainBasemap = new Basemap(        TianDiTuMethodsClass.CreateTianDiTuTiledLayer(                TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_2000));mainBasemap.getBaseLayers().add(        TianDiTuMethodsClass.CreateTianDiTuTiledLayer(                TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_ANNOTATION_CHINESE_2000));mainArcGISMap = new ArcGISMap(mainBasemap);mainMapView.setMap(mainArcGISMap);mainSketchEditor = new SketchEditor();mainSketchStyle = new SketchStyle();mainSketchEditor.setSketchStyle(mainSketchStyle);mainMapView.setSketchEditor(mainSketchEditor);

启动绘制

mPointButton = (ImageButton) findViewById(R.id.pointSketchButton);mPointButton.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        try {            //mainSketchEditor.stop();            mainSketchEditor.start(SketchCreationMode.POINT);        }        catch (Exception e)        {            e.getCause();        }    }});mPolylineButton = (ImageButton) findViewById(R.id.polylineSketchButton);mPolylineButton.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        try {            //mainSketchEditor.stop();            mainSketchEditor.start(SketchCreationMode.POLYLINE);        }        catch (Exception e)        {            e.getCause();        }    }});mPolygonButton = (ImageButton) findViewById(R.id.polygonSketchButton);mPolygonButton.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        try {            //mainSketchEditor.stop();            mainSketchEditor.start(SketchCreationMode.POLYGON);        }        catch (Exception e)        {            e.getCause();        }    }});mPolylineFreeheadButton = (ImageButton) findViewById(R.id.polylineFreeheadSketchButton);mPolylineFreeheadButton.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        try {            //mainSketchEditor.stop();            mainSketchEditor.start(SketchCreationMode.FREEHAND_LINE);        }        catch (Exception e)        {            e.getCause();        }    }});mPolygonFreeheadButton = (ImageButton) findViewById(R.id.polygonFreeheadSketchButton);mPolygonFreeheadButton.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        try {            //mainSketchEditor.stop();            mainSketchEditor.start(SketchCreationMode.FREEHAND_POLYGON);        }        catch (Exception e)        {            e.getCause();        }    }});

结尾

源程序请自行下载(注:已包含hymn-release.aar):
链接:http://pan.baidu.com/s/1qYlYX68 密码:b4bk
若失效,可发邮件给韩源萌(polyline@126.com)索要。

阅读全文
1 0