1 package com.example.arcgis;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import com.esri.android.map.GraphicsLayer;
7 import com.esri.android.map.MapOnTouchListener;
8 import com.esri.android.map.MapView;
9 import com.esri.android.map.ags.ArcGISDynamicMapServiceLayer;
10 import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
11 import com.esri.android.runtime.ArcGISRuntime;
12 import com.esri.core.geometry.Envelope;
13 import com.esri.core.geometry.Geometry;
14 import com.esri.core.geometry.GeometryEngine;
15 import com.esri.core.geometry.Line;
16 import com.esri.core.geometry.LinearUnit;
17 import com.esri.core.geometry.Point;
18 import com.esri.core.geometry.Polygon;
19 import com.esri.core.geometry.Polyline;
20 import com.esri.core.geometry.SpatialReference;
21 import com.esri.core.geometry.Unit;
22 import com.esri.core.map.FeatureSet;
23 import com.esri.core.map.Graphic;
24 import com.esri.core.symbol.PictureMarkerSymbol;
25 import com.esri.core.symbol.SimpleFillSymbol;
26 import com.esri.core.symbol.SimpleLineSymbol;
27 import com.esri.core.symbol.SimpleMarkerSymbol;
28 import com.esri.core.symbol.SimpleMarkerSymbol.STYLE;
29 import com.esri.core.tasks.SpatialRelationship;
30 import com.esri.core.tasks.ags.find.FindParameters;
31 import com.esri.core.tasks.ags.find.FindResult;
32 import com.esri.core.tasks.ags.find.FindTask;
33 import com.esri.core.tasks.ags.query.Query;
34 import com.esri.core.tasks.ags.query.QueryTask;
35 import com.esri.core.tasks.identify.IdentifyParameters;
36 import com.esri.core.tasks.identify.IdentifyResult;
37 import com.esri.core.tasks.identify.IdentifyTask;
38 import android.os.AsyncTask;
39 import android.os.Bundle;
40 import android.app.Activity;
41 import android.content.Context;
42 import android.graphics.Color;
43 import android.util.DisplayMetrics;
44 import android.view.MotionEvent;
45 import android.view.View;
46 import android.view.View.OnClickListener;
47 import android.widget.Button;
48 import android.widget.Toast;
49
50 public class ArcGisHandleActivity extends Activity {
51 private MapView mapview;
52 private Button zoomin;
53 private Button zoomout;
54 private Button addlayer1;
55 private Button addlayer2;
56 private Button drawpoint;
57 private Button drawline;
58 private Button drawpolygon;
59 private Button clean;
60 private Button cleanlayer;
61 private Button calc;
62 private Button search;
63 private Button search2;
64 private Button search3;
65 private Button search4;
66 private Button btn_line;
67 private Button btn_rectangle;
68 private Button btn_polygonal;
69
70 private GraphicsLayer drawLayer;
71 private MapTouchListener mapTouchListener;
72
73 private SimpleLineSymbol lineSymbol;
74 private PictureMarkerSymbol picSymbol;
75 private SimpleMarkerSymbol markerSymbol;
76 private SimpleFillSymbol fillSymbol;
77 private SimpleFillSymbol fillSymbol2;
78 private SimpleFillSymbol fillSymbol3;
79 private SimpleFillSymbol fillSymbol4;
80 private Geometry geometry = null;
81
82 @Override
83 protected void onCreate(Bundle savedInstanceState) {
84 super.onCreate(savedInstanceState);
85 setContentView(R.layout.activity_main);
86 findById();
87 getMap();
88
89 }
90
91 public void findById() {
92 mapview = (MapView) findViewById(R.id.map);
93 zoomin = (Button) findViewById(R.id.zoomin);
94 zoomout = (Button) findViewById(R.id.zoomout);
95 addlayer1 = (Button) findViewById(R.id.addlayer1);
96 addlayer2 = (Button) findViewById(R.id.addlayer2);
97 drawpoint = (Button) findViewById(R.id.drawpoint);
98 drawline = (Button) findViewById(R.id.drawline);
99 drawpolygon = (Button) findViewById(R.id.drawpolygon);
100 clean = (Button) findViewById(R.id.clean);
101 cleanlayer = (Button) findViewById(R.id.cleanlayer);
102 calc = (Button) findViewById(R.id.calc);
103 search = (Button) findViewById(R.id.search);
104 search2 = (Button) findViewById(R.id.search2);
105 search3 = (Button) findViewById(R.id.search3);
106 search4 = (Button) findViewById(R.id.search4);
107 btn_line = (Button) findViewById(R.id.btn_line);
108 btn_rectangle = (Button) findViewById(R.id.btn_rectangle);
109 btn_polygonal = (Button) findViewById(R.id.btn_polygonal);
110 // 本地图片symbol
111 picSymbol = new PictureMarkerSymbol(getResources().getDrawable(
112 R.drawable.point));
113 // 标记symbol
114 markerSymbol = new SimpleMarkerSymbol(Color.RED, 10, STYLE.CIRCLE);
115 ;
116 // 线条symbol
117 lineSymbol = new SimpleLineSymbol(
118 getResources().getColor(R.color.blue), 2);
119 // 填充物symbol
120 fillSymbol = new SimpleFillSymbol(getResources().getColor(
121 R.color.orange));
122 fillSymbol2 = new SimpleFillSymbol(getResources().getColor(
123 R.color.half_blue));
124 fillSymbol3 = new SimpleFillSymbol(getResources().getColor(
125 R.color.yellow));
126 fillSymbol4 = new SimpleFillSymbol(getResources().getColor(R.color.red));
127
128 zoomin.setOnClickListener(new Onclick());
129 zoomout.setOnClickListener(new Onclick());
130 addlayer1.setOnClickListener(new Onclick());
131 addlayer2.setOnClickListener(new Onclick());
132 drawpoint.setOnClickListener(new Onclick());
133 drawline.setOnClickListener(new Onclick());
134 drawpolygon.setOnClickListener(new Onclick());
135 clean.setOnClickListener(new Onclick());
136 cleanlayer.setOnClickListener(new Onclick());
137 calc.setOnClickListener(new Onclick());
138 search.setOnClickListener(new Onclick());
139 search2.setOnClickListener(new Onclick());
140 search3.setOnClickListener(new Onclick());
141 search4.setOnClickListener(new Onclick());
142 btn_line.setOnClickListener(new Onclick());
143 btn_rectangle.setOnClickListener(new Onclick());
144 btn_polygonal.setOnClickListener(new Onclick());
145 }
146
147 public void getMap() {
148 // 设置clientId 去除水印
149 ArcGISRuntime.setClientId("UoFIN8IWetDb7YWr");
150 // Tile静态地图
151 ArcGISTiledMapServiceLayer tileLayer = new ArcGISTiledMapServiceLayer(
152 "http://10.50.50.6/ArcGIS/rest/services/GTJ_JCDT/MapServer");
153 // 基础地图index设置为最底层 index=0
154 mapview.addLayer(tileLayer, 0);
155 // 加载花图层
156 drawLayer = new GraphicsLayer();
157 mapview.addLayer(drawLayer, 1);
158 mapTouchListener = new MapTouchListener(ArcGisHandleActivity.this,
159 mapview);
160 mapview.setOnTouchListener(mapTouchListener);
161
162 }
163
164 class MapTouchListener extends MapOnTouchListener {
165 private Geometry.Type geoType = null;// 用于判定当前选择的几何图形类型
166 private Point ptStart = null;// 起点
167 private Point ptPrevious = null;// 上一个点
168 private ArrayList<Point> points = null;// 记录全部点
169 private Polygon tempPolygon = null;// 记录绘制过程中的多边形
170
171 public MapTouchListener(Context context, MapView view) {
172 super(context, view);
173 points = new ArrayList<Point>();
174 }
175
176 // 三种画图的类型
177 public void setType(String geometryType) {
178 if (geometryType.equalsIgnoreCase("Point")) {
179 this.geoType = Geometry.Type.POINT;
180 } else if (geometryType.equalsIgnoreCase("Polyline")) {
181 this.geoType = Geometry.Type.POLYLINE;
182 } else if (geometryType.equalsIgnoreCase("Polygon")) {
183 this.geoType = Geometry.Type.POLYGON;
184 } else {
185 this.geoType = null;
186 }
187 }
188
189 public Geometry.Type getType() {
190 return this.geoType;
191 }
192
193 @Override
194 public boolean onSingleTap(MotionEvent point) {
195 Point ptCurrent = mapview.toMapPoint(new Point(point.getX(), point
196 .getY()));
197 // 画点
198 if (geoType == Geometry.Type.POINT) {
199 ptStart = ptCurrent;
200 Graphic graphic = new Graphic(ptCurrent, picSymbol);
201 drawLayer.addGraphic(graphic);
202 geometry = ptCurrent;
203 return true;
204 }
205 // 画线
206 else if (geoType == Geometry.Type.POLYLINE) {
207 points.add(ptCurrent);// 将当前点加入点集合中
208 if (ptStart == null) {// 画线第一个点
209 ptStart = ptCurrent;
210 Graphic graphic = new Graphic(ptStart, markerSymbol);
211 drawLayer.addGraphic(graphic);
212 } else {
213 // 根据当前点和前一个点画线
214 Graphic graphic = new Graphic(ptCurrent, markerSymbol);
215 drawLayer.addGraphic(graphic);
216 Line line = new Line();
217 line.setStart(ptPrevious);
218 line.setEnd(ptCurrent);
219 Polyline polyline = new Polyline();
220 polyline.addSegment(line, true);
221 Graphic g = new Graphic(polyline, lineSymbol);
222 geometry = polyline;
223 drawLayer.addGraphic(g);
224 }
225 ptPrevious = ptCurrent;
226 return true;
227 }
228 // 画面
229 else if (geoType == Geometry.Type.POLYGON) {
230 points.add(ptCurrent);// 将当前点加入点集合中
231 if (ptStart == null) {// 多边形的第一个点
232 ptStart = ptCurrent;
233 Graphic graphic = new Graphic(ptStart, markerSymbol);
234 drawLayer.addGraphic(graphic);
235 } else {
236 // 根据前一个点和当前点画出线,并将线条集中放入tempPolygon并画成图形
237 drawLayer.removeAll();
238 Graphic graphic = new Graphic(ptCurrent, markerSymbol);
239 drawLayer.addGraphic(graphic);
240 Line line = new Line();
241 line.setStart(ptPrevious);
242 line.setEnd(ptCurrent);
243 Polyline polyline = new Polyline();
244 polyline.addSegment(line, true);
245 Graphic g = new Graphic(polyline, lineSymbol);
246 if (tempPolygon == null) {
247 tempPolygon = new Polygon();
248 }
249 tempPolygon.addSegment(line, false);
250 geometry = tempPolygon;
251 Graphic g2 = new Graphic(tempPolygon, fillSymbol);
252 drawLayer.addGraphic(g2);
253 }
254 ptPrevious = ptCurrent;
255 return true;
256 } else {
257 return true;
258 }
259
260 }
261
262 // 双击事件
263 @Override
264 public boolean onDoubleTap(MotionEvent point) {
265 return false;
266 }
267
268 }
269
270 // 空间查询异步线程
271 class MyTask extends AsyncTask<IdentifyParameters, Void, IdentifyResult[]> {
272 IdentifyTask mIdentifyTask;
273 Geometry geometry;
274
275 public MyTask(Geometry geometry) {
276 super();
277 this.geometry = geometry;
278 }
279
280 @Override
281 protected IdentifyResult[] doInBackground(IdentifyParameters... params) {
282 if (geometry != null) {
283 // 设置参数
284 IdentifyResult[] mResult = null;
285 IdentifyParameters param = new IdentifyParameters();
286 param.setGeometry(geometry);
287 param.setSpatialReference(mapview.getSpatialReference());// 设置坐标系
288 param.setMapHeight(mapview.getHeight());// 设置地图像素高
289 param.setMapWidth(mapview.getWidth());// 设置地图像素宽
290 DisplayMetrics metric = new DisplayMetrics();
291 getWindowManager().getDefaultDisplay().getMetrics(metric);
292 int densityDpi = metric.densityDpi;
293 param.setDPI(densityDpi);
294 Envelope env = new Envelope();
295 mapview.getExtent().queryEnvelope(env);
296 param.setMapExtent(env);// 设置当前地图范围
297
298 // 设置地图信息的Url
299 mIdentifyTask = new IdentifyTask(
300 "http://10.50.50.6/ArcGIS/rest/services/GTJ_CZDJSH/MapServer");
301 try {
302 mResult = mIdentifyTask.execute(param);
303 } catch (Exception e) {
304 System.out.println(e.getMessage());
305 e.printStackTrace();
306 }
307 return mResult;
308 } else {
309 return null;
310 }
311 }
312
313 @Override
314 protected void onPostExecute(IdentifyResult[] results) {
315 List<IdentifyResult> list = new ArrayList<IdentifyResult>();
316 if (results != null) {
317 // 过滤信息
318 for (int index = 0; index < results.length; index++) {
319 if (!results[index].getLayerName().contains("嘉峪关市行政区")) {
320 list.add(results[index]);
321 }
322
323 }
324
325 // 获取第0个数据 并且是该区域高亮
326 if (list != null && list.size() > 0) {
327 IdentifyResult identifyResult = list.get(0);
328 Geometry geometry = identifyResult.getGeometry();
329 Graphic graphic = null;
330 if (geometry.getType() == Geometry.Type.POINT) {
331 graphic = new Graphic(geometry, markerSymbol);
332 } else if (geometry.getType() == Geometry.Type.POLYLINE) {
333 graphic = new Graphic(geometry, lineSymbol);
334 } else if (geometry.getType() == Geometry.Type.POLYGON) {
335 graphic = new Graphic(geometry, fillSymbol2);
336 }
337 drawLayer.addGraphic(graphic);
338 // 地图位移到该位置
339 mapview.setExtent(geometry);
340 System.out.println(identifyResult.toString());
341 }
342 }
343 }
344 }
345
346 // 缓冲区查询 异步线程
347 class MyTask2 extends AsyncTask<IdentifyParameters, Void, IdentifyResult[]> {
348 IdentifyTask mIdentifyTask;
349 Geometry geometry;
350 int buffer;
351
352 public MyTask2(Geometry geometry, int buffer) {
353 super();
354 this.geometry = geometry;
355 this.buffer = buffer;
356 }
357
358 @Override
359 protected IdentifyResult[] doInBackground(IdentifyParameters... params) {
360 if (geometry != null) {
361 // 缓冲区图层绘制
362 SpatialReference spatialRef = SpatialReference.create(102100);
363 Polygon p = GeometryEngine.buffer(geometry, spatialRef,
364 this.buffer, Unit.create(LinearUnit.Code.METER));
365 Graphic g = new Graphic(p, fillSymbol);
366 drawLayer.addGraphic(g);
367
368 // 设置参数
369 IdentifyResult[] mResult = null;
370 IdentifyParameters param = new IdentifyParameters();
371 param.setGeometry(p);
372 param.setSpatialReference(mapview.getSpatialReference());// 设置坐标系
373 param.setMapHeight(mapview.getHeight());// 设置地图像素高
374 param.setMapWidth(mapview.getWidth());// 设置地图像素宽
375 DisplayMetrics metric = new DisplayMetrics();
376 getWindowManager().getDefaultDisplay().getMetrics(metric);
377 int densityDpi = metric.densityDpi;
378 param.setDPI(densityDpi);
379 Envelope env = new Envelope();
380 mapview.getExtent().queryEnvelope(env);
381 param.setMapExtent(env);// 设置当前地图范围
382
383 // 设置地图信息的Url
384 mIdentifyTask = new IdentifyTask(
385 "http://10.50.50.6/ArcGIS/rest/services/GTJ_CZDJSH/MapServer");
386 try {
387 mResult = mIdentifyTask.execute(param);
388 } catch (Exception e) {
389 System.out.println(e.getMessage());
390 e.printStackTrace();
391 }
392 return mResult;
393 } else {
394 return null;
395 }
396 }
397
398 @Override
399 protected void onPostExecute(IdentifyResult[] results) {
400 List<IdentifyResult> list = new ArrayList<IdentifyResult>();
401 if (results != null) {
402 // 过滤信息
403 for (int index = 0; index < results.length; index++) {
404 if (!results[index].getLayerName().contains("嘉峪关市行政区")) {
405 list.add(results[index]);
406 }
407
408 }
409
410 // 获取第0个数据 并且是该区域高亮
411 if (list != null && list.size() > 0) {
412 IdentifyResult identifyResult = list.get(0);
413 Geometry geometry = identifyResult.getGeometry();
414 Graphic graphic = null;
415 if (geometry.getType() == Geometry.Type.POINT) {
416 graphic = new Graphic(geometry, markerSymbol);
417 } else if (geometry.getType() == Geometry.Type.POLYLINE) {
418 graphic = new Graphic(geometry, lineSymbol);
419 } else if (geometry.getType() == Geometry.Type.POLYGON) {
420 graphic = new Graphic(geometry, fillSymbol2);
421 }
422 drawLayer.addGraphic(graphic);
423 // 地图位移到该位置
424 mapview.setExtent(geometry);
425 System.out.println(identifyResult.toString());
426 }
427 }
428 }
429 }
430
431 // 模糊查询异步线程
432 class MyTask3 extends AsyncTask<FindParameters, Void, List<FindResult>> {
433 FindTask mFindTask;
434 String text;
435
436 public MyTask3(String text) {
437 super();
438 this.text = text;
439 }
440
441 @Override
442 protected List<FindResult> doInBackground(FindParameters... params) {
443 List<FindResult> mResult = null;
444 FindParameters param = new FindParameters();
445 param.setReturnGeometry(true);// 需要返回Geometry
446 param.setSearchText(this.text);// 搜索关键字
447 param.setLayerIds(new int[] { 6 });// 查找图层(默认为查找所有图层)
448 param.setSearchFields(new String[] { "土地使用者" });
449 mFindTask = new FindTask(
450 "http://10.50.50.6/ArcGIS/rest/services/GTJ_CZDJSH/MapServer");
451 try {
452 mResult = mFindTask.execute(param);
453 } catch (Exception e) {
454 // TODO Auto-generated catch block
455 e.printStackTrace();
456 }
457 return mResult;
458
459 }
460
461 @Override
462 protected void onPostExecute(List<FindResult> results) {
463 System.out.println(results.size());
464 // 获取第0个数据 并且是该区域高亮
465 if (results != null && results.size() > 0) {
466 FindResult FindResult = results.get(0);
467 Geometry geometry = FindResult.getGeometry();
468 Graphic graphic = null;
469 if (geometry.getType() == Geometry.Type.POINT) {
470 graphic = new Graphic(geometry, markerSymbol);
471 } else if (geometry.getType() == Geometry.Type.POLYLINE) {
472 graphic = new Graphic(geometry, lineSymbol);
473 } else if (geometry.getType() == Geometry.Type.POLYGON) {
474 graphic = new Graphic(geometry, fillSymbol2);
475 }
476 drawLayer.addGraphic(graphic);
477 // 地图位移到该位置
478 mapview.setExtent(geometry);
479 System.out.println(FindResult.toString());
480 }
481 }
482 }
483
484 // 专题分析线程
485 class MyTask4 extends AsyncTask<Query, Void, FeatureSet> {
486 QueryTask mQueryTask;
487 Geometry geometry;
488
489 public MyTask4(Geometry geometry) {
490 super();
491 this.geometry = geometry;
492 }
493
494 @Override
495 protected FeatureSet doInBackground(Query... params) {
496 FeatureSet result = null;
497 // 规定好相交模型 获取图层结果
498 mQueryTask = new QueryTask(
499 "http://10.50.50.6/ArcGIS/rest/services/GTJ_CZDJSH/MapServer/6");
500 Query query = new Query();
501 query.setOutFields(new String[] { "*" });
502 query.setGeometry(geometry);
503 query.setReturnGeometry(true);
504 query.setOutSpatialReference(mapview.getSpatialReference());
505 query.setSpatialRelationship(SpatialRelationship.INTERSECTS);
506 try {
507 result = mQueryTask.execute(query);
508 } catch (Exception e) {
509 System.out.println(e.getMessage());
510 e.printStackTrace();
511 }
512 return result;
513 }
514
515 @Override
516 protected void onPostExecute(FeatureSet result) {
517 // 获取每一个图层
518 Graphic[] graphics = result.getGraphics();
519 for (int i = 0; i < graphics.length; i++) {
520 Geometry geometry = graphics[i].getGeometry();
521 // 获取相交图形
522 Geometry geometry2 = GeometryEngine.intersect(geometry,
523 this.geometry, mapview.getSpatialReference());
524 Graphic graphic1 = new Graphic(geometry, fillSymbol4);
525 Graphic graphic2 = new Graphic(geometry2, fillSymbol3);
526 // 计算面积
527 System.out.println(geometry2.calculateArea2D());
528 drawLayer.addGraphic(graphic1);
529 drawLayer.addGraphic(graphic2);
530 }
531
532 }
533 }
534
535 // 计算
536 public void calc() {
537 // 计算点的坐标
538 if (mapTouchListener.getType() == Geometry.Type.POINT) {
539 String latlng = mapTouchListener.ptStart.getX() + ","
540 + mapTouchListener.ptStart.getY();
541 Toast.makeText(ArcGisHandleActivity.this, latlng,
542 Toast.LENGTH_SHORT).show();
543 }
544 // 计算线的长度
545 else if (mapTouchListener.getType() == Geometry.Type.POLYLINE) {
546 Polyline polyline = new Polyline();
547 Point startPoint = null;
548 Point endPoint = null;
549 // 通过点的集合把所有的线描绘出来,并且计算
550 for (int i = 1; i < mapTouchListener.points.size(); i++) {
551 startPoint = mapTouchListener.points.get(i - 1);
552 endPoint = mapTouchListener.points.get(i);
553 Line line = new Line();
554 line.setStart(startPoint);
555 line.setEnd(endPoint);
556 polyline.addSegment(line, false);
557 }
558 String length = Double.toString(Math.round(polyline
559 .calculateLength2D())) + " 米";
560 Toast.makeText(ArcGisHandleActivity.this, length,
561 Toast.LENGTH_SHORT).show();
562 }
563 // 计算图形的面积
564 else if (mapTouchListener.getType() == Geometry.Type.POLYGON) {
565 Polygon polygon = new Polygon();
566 Point startPoint = null;
567 Point endPoint = null;
568 // 通过点的集合把所有的线描绘出来,并且传入polygon,然后计算面积
569 for (int i = 1; i < mapTouchListener.points.size(); i++) {
570 startPoint = mapTouchListener.points.get(i - 1);
571 endPoint = mapTouchListener.points.get(i);
572
573 Line line = new Line();
574 line.setStart(startPoint);
575 line.setEnd(endPoint);
576 polygon.addSegment(line, false);
577 }
578 String sArea = getAreaString(polygon.calculateArea2D());
579 Toast.makeText(ArcGisHandleActivity.this, sArea, Toast.LENGTH_SHORT)
580 .show();
581 } else {
582
583 }
584
585 }
586
587 // 计算面积
588 private String getAreaString(double dValue) {
589 long area = Math.abs(Math.round(dValue));
590 String sArea = "";
591 // 顺时针绘制多边形,面积为正,逆时针绘制,则面积为负
592 if (area >= 1000000) {
593 double dArea = area / 1000000.0;
594 sArea = Double.toString(dArea) + " 平方公里";
595 } else
596 sArea = Double.toString(area) + " 平方米";
597
598 return sArea;
599 }
600
601 class Onclick implements OnClickListener {
602
603 @Override
604 public void onClick(View v) {
605 switch (v.getId()) {
606 // 放大
607 case R.id.zoomin:
608 mapview.zoomin();
609 break;
610 // 缩小
611 case R.id.zoomout:
612 mapview.zoomout();
613 break;
614 // 添加第一个图层 index=1
615 case R.id.addlayer1:
616 ArcGISDynamicMapServiceLayer dynamicMapServiceLayer1 = new ArcGISDynamicMapServiceLayer(
617 "http://10.50.50.6/ArcGIS/rest/services/GTJ_TDLYXZT/MapServer");
618 dynamicMapServiceLayer1.setOpacity(0.5f);
619 mapview.addLayer(dynamicMapServiceLayer1, 1);
620 break;
621 // 添加第二个图层 index=2
622 case R.id.addlayer2:
623 ArcGISDynamicMapServiceLayer dynamicMapServiceLayer2 = new ArcGISDynamicMapServiceLayer(
624 "http://10.50.50.6/ArcGIS/rest/services/GTJ_CZDJSH/MapServer");
625 dynamicMapServiceLayer2.setOpacity(0.5f);
626 mapview.addLayer(dynamicMapServiceLayer2, 2);
627 break;
628 // 画点
629 case R.id.drawpoint:
630 mapTouchListener.ptStart = null;
631 mapTouchListener.ptPrevious = null;
632 mapTouchListener.points.clear();
633 mapTouchListener.tempPolygon = null;
634 mapTouchListener.setType("Point");
635 break;
636 // 画线
637 case R.id.drawline:
638 mapTouchListener.ptStart = null;
639 mapTouchListener.ptPrevious = null;
640 mapTouchListener.points.clear();
641 mapTouchListener.tempPolygon = null;
642 mapTouchListener.setType("Polyline");
643 break;
644 // 画面
645 case R.id.drawpolygon:
646 mapTouchListener.ptStart = null;
647 mapTouchListener.ptPrevious = null;
648 mapTouchListener.points.clear();
649 mapTouchListener.tempPolygon = null;
650 mapTouchListener.setType("Polygon");
651 break;
652 // 清除画板
653 case R.id.clean:
654 geometry = null;
655 drawLayer.removeAll();
656 mapTouchListener.ptStart = null;
657 mapTouchListener.ptPrevious = null;
658 mapTouchListener.points.clear();
659 mapTouchListener.tempPolygon = null;
660 mapTouchListener.setType("");
661 break;
662 // 清楚第一个图层
663 case R.id.cleanlayer:
664 mapview.removeLayer(1);
665 break;
666 // 计算
667 case R.id.calc:
668 calc();
669 break;
670 // 查询
671 case R.id.search:
672 // 异步获取地理信息
673 new MyTask(geometry).execute();
674 break;
675 case R.id.search2:
676 // 异步获取地理信息
677 new MyTask2(geometry, 10).execute();
678 break;
679 case R.id.search3:
680 // 异步获取地理信息
681 new MyTask3("张海").execute();
682 break;
683 case R.id.search4:
684 // 异步获取地理信息
685 new MyTask4(geometry).execute();
686 break;
687 case R.id.btn_line:
688 List<Point> list = getPointList();
689 for (int i = 0; i < list.size(); i++) {
690 Line line = new Line();
691 line.setStart(new Point(list.get(0).getX(), list.get(0)
692 .getY()));
693 line.setEnd(new Point(list.get(1).getX(), list.get(1)
694 .getY()));
695 Polyline polyline = new Polyline();
696 polyline.addSegment(line, true);
697 Graphic g = new Graphic(polyline, lineSymbol);
698 drawLayer.addGraphic(g);
699 }
700 break;
701 case R.id.btn_rectangle:
702 Envelope elope = new Envelope(3.3437058041800953E7,
703 4411930.256464715, 3.3433762387338314E7,
704 4415067.189463225);
705 SimpleFillSymbol sfs = new SimpleFillSymbol(Color.GREEN);
706 sfs.setAlpha(60);
707 drawLayer.addGraphic(new Graphic(elope, sfs));
708 break;
709 case R.id.btn_polygonal:
710 Polygon py = new Polygon();
711 py.startPath(new Point(3.3430444761173524E7, 4418097.292269631));
712 py.lineTo(new Point(3.342695869070306E7, 4412426.6831117235));
713 py.lineTo(new Point(3.3431528664667748E7, 4407419.65485851));
714 py.lineTo(new Point(3.343876445803166E7, 4409500.890103303));
715 py.lineTo(new Point(3.343738760831217E7, 4415593.776775944));
716 py.lineTo(new Point(3.3430444761173524E7, 4418097.292269631));
717 Graphic g = new Graphic(py, fillSymbol);
718 drawLayer.addGraphic(g);
719 break;
720 default:
721 break;
722 }
723 }
724 }
725
726 private List<Point> getPointList() {
727 List<Point> list = new ArrayList<Point>();
728 list.add(new Point(3.3429800278327744E7, 4418791.035334834));
729 list.add(new Point(3.342733952188005E7, 4413331.565192465));
730 return list;
731 }
732 }
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 tools:context=".MainActivity" >
6
7 <com.esri.android.map.MapView
8 android:id="@+id/map"
9 android:layout_width="match_parent"
10 android:layout_height="match_parent" >
11 </com.esri.android.map.MapView>
12
13 <LinearLayout
14 android:id="@+id/ly1"
15 android:layout_width="fill_parent"
16 android:layout_height="wrap_content"
17 android:orientation="horizontal" >
18
19 <Button
20 android:id="@+id/zoomin"
21 android:layout_width="50dip"
22 android:layout_height="50dip"
23 android:text="放大"
24 android:textSize="12sp" />
25
26 <Button
27 android:id="@+id/zoomout"
28 android:layout_width="50dip"
29 android:layout_height="50dip"
30 android:text="缩小"
31 android:textSize="12sp" />
32
33 <Button
34 android:id="@+id/btn_line"
35 android:layout_width="50dip"
36 android:layout_height="50dip"
37 android:text="直线"
38 android:textSize="12sp" />
39
40 <Button
41 android:id="@+id/btn_rectangle"
42 android:layout_width="50dip"
43 android:layout_height="50dip"
44 android:text="矩形"
45 android:textSize="12sp" />
46
47 <Button
48 android:id="@+id/btn_polygonal"
49 android:layout_width="50dip"
50 android:layout_height="50dip"
51 android:text="多边形"
52 android:textSize="12sp" />
53 </LinearLayout>
54
55 <LinearLayout
56 android:id="@+id/ly2"
57 android:layout_width="fill_parent"
58 android:layout_height="wrap_content"
59 android:layout_below="@+id/ly1"
60 android:orientation="horizontal" >
61
62 <Button
63 android:id="@+id/drawpoint"
64 android:layout_width="50dip"
65 android:layout_height="50dip"
66 android:text="画点"
67 android:textSize="12sp" />
68
69 <Button
70 android:id="@+id/drawline"
71 android:layout_width="50dip"
72 android:layout_height="50dip"
73 android:text="画线"
74 android:textSize="12sp" />
75
76 <Button
77 android:id="@+id/drawpolygon"
78 android:layout_width="50dip"
79 android:layout_height="50dip"
80 android:text="画面"
81 android:textSize="12sp" />
82
83 <Button
84 android:id="@+id/calc"
85 android:layout_width="50dip"
86 android:layout_height="50dip"
87 android:text="计算"
88 android:textSize="12sp" />
89
90 <Button
91 android:id="@+id/clean"
92 android:layout_width="50dip"
93 android:layout_height="50dip"
94 android:text="清空"
95 android:textSize="12sp" />
96 </LinearLayout>
97
98 <LinearLayout
99 android:id="@+id/ly3"
100 android:layout_width="fill_parent"
101 android:layout_height="wrap_content"
102 android:layout_below="@+id/ly2"
103 android:orientation="horizontal" >
104
105 <Button
106 android:id="@+id/search"
107 android:layout_width="wrap_content"
108 android:layout_height="50dip"
109 android:text="空间查询"
110 android:textSize="12sp" />
111
112 <Button
113 android:id="@+id/search2"
114 android:layout_width="wrap_content"
115 android:layout_height="50dip"
116 android:text="缓冲区查询"
117 android:textSize="12sp" />
118
119 <Button
120 android:id="@+id/search3"
121 android:layout_width="wrap_content"
122 android:layout_height="50dip"
123 android:text="模糊查询"
124 android:textSize="12sp" />
125
126 <Button
127 android:id="@+id/search4"
128 android:layout_width="wrap_content"
129 android:layout_height="50dip"
130 android:text="专题分析"
131 android:textSize="12sp" />
132 </LinearLayout>
133
134 <LinearLayout
135 android:layout_width="fill_parent"
136 android:layout_height="wrap_content"
137 android:layout_below="@+id/ly3"
138 android:orientation="horizontal" >
139
140 <Button
141 android:id="@+id/addlayer1"
142 android:layout_width="wrap_content"
143 android:layout_height="50dip"
144 android:text="添加图层一"
145 android:textSize="12sp" />
146
147 <Button
148 android:id="@+id/addlayer2"
149 android:layout_width="wrap_content"
150 android:layout_height="50dip"
151 android:text="添加图层二"
152 android:textSize="12sp" />
153
154 <Button
155 android:id="@+id/cleanlayer"
156 android:layout_width="wrap_content"
157 android:layout_height="50dip"
158 android:text="清空图层一"
159 android:textSize="12sp" />
160 </LinearLayout>
161
162 </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="orange">#7ff67516</color>
<color name="blue">#ff23acde</color>
<color name="half_blue">#6f23acde</color>
<color name="yellow">#fff29900</color>
<color name="red">#7ff29900</color>
</resources>