ArcGIS for Android 100.3.0(8):绘制点,线,面,圆,添加文本和图片「建议收藏」

ArcGIS for Android 100.3.0(8):绘制点,线,面,圆,添加文本和图片「建议收藏」空间要素(Geometry)Geometries用以在特定地理位置上通过形状来表达真实世界的对象。图层范围、视图范围、GPS定位都是通过Geometries表达实现进一步的数据编辑、空间分析、地理处理、位置与面积量算都离不开空间要素。案例效果图:布局:<?xmlversion="1.0"encoding="utf-8"?><RelativeL…

大家好,又见面了,我是你们的朋友全栈君。

空间要素(Geometry)

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

案例

效果图:
这里写图片描述

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".GraphicsOverlayActivity">

    <com.esri.arcgisruntime.mapping.view.MapView  android:id="@+id/mapview" android:layout_width="match_parent" android:layout_height="match_parent"></com.esri.arcgisruntime.mapping.view.MapView>


    <RadioGroup  android:id="@+id/radiogroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">

        <RadioButton  android:id="@+id/rb_draw_point" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="绘制点" />

        <RadioButton  android:id="@+id/rb_draw_polyline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="绘制线" />

        <RadioButton  android:id="@+id/rb_draw_scroll_line" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="绘制曲线" />

        <RadioButton  android:id="@+id/rb_draw_polygon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="绘制面" />

        <RadioButton  android:id="@+id/rb_add_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="添加图片" />

        <RadioButton  android:id="@+id/rb_draw_circle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="绘制圆" />

        <RadioButton  android:id="@+id/rb_draw_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="绘制文字" />
    </RadioGroup>

    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/radiogroup" android:onClick="clear" android:text="清除" />
</RelativeLayout>

代码:

public class GraphicsOverlayActivity extends AppCompatActivity { 

private MapView mMapView;
private RadioGroup mRadioGroup;
private GraphicsOverlay mGraphicsOverlay;
//点集合
private PointCollection mPointCollection = new PointCollection(SpatialReferences.getWebMercator());
private List<Point> mPointList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graphics_overlay);
findViews();
addBasemap();
initListener();
}
private void addBasemap() {
ArcGISMap arcGISMap = new ArcGISMap(Basemap.Type.OCEANS, 56.075844, -2.681572, 11);
mMapView.setMap(arcGISMap);
mGraphicsOverlay = new GraphicsOverlay();
mMapView.getGraphicsOverlays().add(mGraphicsOverlay);
}
private void initListener() {
mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.rb_draw_point: //绘制点
drawPoint();
break;
case R.id.rb_draw_polyline: //绘制线
drawPolyline();
break;
case R.id.rb_draw_scroll_line: //绘制曲线
drawScrollline();
break;
case R.id.rb_draw_polygon: //绘制面
drawPolygon();
break;
case R.id.rb_add_image: //添加图片
addImage();
break;
case R.id.rb_draw_circle: //绘制圆
drawCircle();
break;
case R.id.rb_draw_text: //绘制文字
drawText();
break;
}
}
});
}
/** * 绘制点 */
private void drawPoint() {
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Point clickPoint = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 20);
Graphic graphic = new Graphic(clickPoint, simpleMarkerSymbol);
//清除上一个点
mGraphicsOverlay.getGraphics().clear();
mGraphicsOverlay.getGraphics().add(graphic);
//使用渲染器
// Graphic graphic1 = new Graphic(clickPoint);
// SimpleRenderer simpleRenderer = new SimpleRenderer(simpleMarkerSymbol);
// mGraphicsOverlay.setRenderer(simpleRenderer);
// mGraphicsOverlay.getGraphics().clear();
// mGraphicsOverlay.getGraphics().add(graphic1);
return super.onSingleTapConfirmed(e);
}
});
}
/** * 绘制线 */
private void drawPolyline() {
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
mPointCollection.add(point);
Polyline polyline = new Polyline(mPointCollection);
//点
SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
Graphic pointGraphic = new Graphic(point, simpleMarkerSymbol);
mGraphicsOverlay.getGraphics().add(pointGraphic);
//线
SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.parseColor("#FC8145"), 3);
Graphic graphic = new Graphic(polyline, simpleLineSymbol);
mGraphicsOverlay.getGraphics().add(graphic);
return super.onSingleTapConfirmed(e);
}
});
}
/** * 绘制曲线 */
private void drawScrollline() {
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Point point1 = mMapView.screenToLocation(new android.graphics.Point(Math.round(e1.getX()), Math.round(e1.getY())));
Point point2 = mMapView.screenToLocation(new android.graphics.Point(Math.round(e2.getX()), Math.round(e2.getY())));
mPointCollection.add(point1);
mPointCollection.add(point2);
Polyline polyline = new Polyline(mPointCollection);
Graphic graphic = new Graphic(polyline, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.parseColor("#FC8145"), 3));
mGraphicsOverlay.getGraphics().add(graphic);
return true;
}
});
}
/** * 绘制面 */
private void drawPolygon() {
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
mGraphicsOverlay.getGraphics().clear();
Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
mPointCollection.add(point);
Polygon polygon = new Polygon(mPointCollection);
if (mPointCollection.size() == 1) {
SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
Graphic pointGraphic = new Graphic(point, simpleMarkerSymbol);
mGraphicsOverlay.getGraphics().add(pointGraphic);
}
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GREEN, 3.0f);
SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.parseColor("#33e97676"), lineSymbol);
Graphic graphic = new Graphic(polygon, simpleFillSymbol);
mGraphicsOverlay.getGraphics().add(graphic);
return super.onSingleTapConfirmed(e);
}
});
}
/** * 添加图片 */
private void addImage() {
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Point clickPoint = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol(bitmapDrawable);
final Graphic graphic = new Graphic(clickPoint, pictureMarkerSymbol);
//涉及到加载图片到符号里,所以需要一个异步监听操作
pictureMarkerSymbol.loadAsync();
pictureMarkerSymbol.addDoneLoadingListener(new Runnable() {
@Override
public void run() {
mGraphicsOverlay.getGraphics().clear();
mGraphicsOverlay.getGraphics().add(graphic);
}
});
return super.onSingleTapConfirmed(e);
}
});
}
/** * 绘制文字 */
private void drawText() {
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Point clickPoint = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
TextSymbol textSymbol = new TextSymbol(20, "绘制文字", Color.RED,
TextSymbol.HorizontalAlignment.CENTER, TextSymbol.VerticalAlignment.MIDDLE);
Graphic graphic = new Graphic(clickPoint, textSymbol);
mGraphicsOverlay.getGraphics().clear();
mGraphicsOverlay.getGraphics().add(graphic);
return super.onSingleTapConfirmed(e);
}
});
}
/** * 绘制圆 */
private void drawCircle() {
mPointList = new ArrayList<>();
mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
double radius = 0;
Point point = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
mPointList.add(point);
if (mPointList.size() == 2) {
double x = (mPointList.get(1).getX() - mPointList.get(0).getX());
double y = (mPointList.get(1).getY() - mPointList.get(0).getY());
radius = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
}
getCircle(mPointList.get(0), radius);
return super.onSingleTapConfirmed(e);
}
});
}
private void getCircle(Point point, double radius) {
// polygon.setEmpty();
Point[] points = getPoints(point, radius);
mPointCollection.clear();
for (Point p : points) {
mPointCollection.add(p);
}
Polygon polygon = new Polygon(mPointCollection);
SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
Graphic pointGraphic = new Graphic(point, simpleMarkerSymbol);
mGraphicsOverlay.getGraphics().add(pointGraphic);
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.parseColor("#FC8145"), 3.0f);
SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.parseColor("#33e97676"), lineSymbol);
Graphic graphic = new Graphic(polygon, simpleFillSymbol);
mGraphicsOverlay.getGraphics().add(graphic);
}
/** * 通过中心点和半径计算得出圆形的边线点集合 * * @param center * @param radius * @return */
private static Point[] getPoints(Point center, double radius) {
Point[] points = new Point[50];
double sin;
double cos;
double x;
double y;
for (double i = 0; i < 50; i++) {
sin = Math.sin(Math.PI * 2 * i / 50);
cos = Math.cos(Math.PI * 2 * i / 50);
x = center.getX() + radius * sin;
y = center.getY() + radius * cos;
points[(int) i] = new Point(x, y);
}
return points;
}
/** * 清除 * * @param view */
public void clear(View view) {
mGraphicsOverlay.getGraphics().clear();
mPointCollection.clear();
if (mPointList != null) {
mPointList.clear();
}
}
private void findViews() {
mMapView = (MapView) findViewById(R.id.mapview);
mRadioGroup = (RadioGroup) findViewById(R.id.radiogroup);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/160604.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 【22】进大厂必须掌握的面试题-30个Informatica面试

    点击上方“全栈程序员社区”,星标公众号 重磅干货,第一时间送达 在大数据时代,任何公司的成功都取决于数据驱动的决策和业务流程。在这种情况下,数据集成对于任何业务的成功秘诀都是至关重…

  • [转载]Matlab fmincon函数用法

    [转载]Matlab fmincon函数用法原文地址:fmincon函数用法”style=”text-decoration:none;color:rgb(151,38,38)”>Matlab fmincon函数用法作者:长笛人倚楼Gloria这个函数在之前优化工具箱一文中已经介绍过,由于其应用广泛,所以这里通过实例单独整理一下其用法。一、基本介绍求解问题的标准型为minF(X)s.tAXAeqX=

  • es数据库索引_sql 创建索引

    es数据库索引_sql 创建索引PUTindex{“mappings”:{“type”:{“properties”:{“text”:{“id”:”string”,”name”:”string”,”nickName”:”string”,”skuCode”:”string”,”dimensionValues”:”string”,”stock”:”string”,”salesNum”:”string”.

  • ipad 运行linux_linux 终端快捷键

    ipad 运行linux_linux 终端快捷键实现的具体步骤如下:1.、cydia安装openssh2、installous安装issh3、进入issh,选addconfigurationdescription:随便填host:localhostport:22login:rootpassword:默认为alpine(这个进入以后可以改)保存,连接4、连接时会出现一个警告,点确认即可于是出现:***-mato-ipad:-root#现在就可…

  • dumpbin的使用

    dumpbin的使用1.输入Dumpbin-importscalldll.exe查看它的输入信息,可以看到它加载了***.dll2.输入dumpbin–exportsdlltest.dll,列出导出函数

  • 【通俗易懂】关系模式范式分解教程 3NF与BCNF口诀!小白也能看懂「建议收藏」

    本来是为了复习数据库期末考试,结果找了一圈都没有发现比较好的解释,通过查阅资料和总结,为大家提供通俗易懂的解法,一听就会!并且配有速记口诀!介是你没有玩过的船新版本包含最小依赖集求法候选码求法在模式分解之前,首先对于1NF,2NF,3NF,BCNF做一个简明扼要的介绍。1NF是指数据库表的每一列都是不可分割的基本数据项,即实体中的某个属性不能有多个值或者不能有重复的属性。2NF要求属性…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号