日常应用中无论是草图绘制,还是外业采集都需要在移动端进行空间要素的绘制。而ArcGIS Runtime SDK for Android中提供了Geometry、Feature、Graphic,这三者到底如何使用,本文稍微做做解答。
Geometries用以在特定地理位置上通过形状来表达真实世界的对象。图层范围、视图范围、GPS定位都是通过Geometries表达实现进一步的数据编辑、空间分析、地理处理、位置与面积量算都离不开空间要素。
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);
绘制类型(SketchCreationMode)
初始化地图
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(); } }});
联系客服