ArcGIS Runtime for Android开发教程V2.0(5)基础篇---图层
来源:互联网 发布:自学电脑编程最快多久 编辑:程序博客网 时间:2024/05/21 05:22
原址:http://blog.csdn.net/ArcGIS_Mobile/article/details/8151626
- <com.esri.android.map.MapView
- android:id="@+id/map"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- url="http://www.arcgis.com/home/item.html?id=2b571d8c079d46b4a14a67df42b1da6f"
- appId="">
- </com.esri.android.map.MapView>
图层是空间数据的载体,通过图层我们可以把地图数据读取到图层中进行显示,在GIS中图层是很重要的概念,图层只有添加到MapView对象中才可以显示加载的地图数据,在ArcGIS Runtime for Android中有许多种图层,不同的图层有不同的作用,下图是图层的关系图:
1、 ArcGISTiledMapServiceLayer
在ArcGIS Server中我们可以发布多种地图服务,移动端需要有不同的图层来对应这些服务。ArcGISTiledMapServiceLayer图层对应ArcGIS Server服务中的切片服务,由于地图服务是切片式的所以它的优势是加载速度快,用法如下:
- MapView mv = new MapView(this);
- mv.addLayer(new ArcGISTiledMapServiceLayer( "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"));
- setContentView(mv);
2、 ArcGISDynamicMapServiceLayer
ArcGISDynamicMapServiceLayer图层对应ArcGIS Server服务中的动态服务,动态地图服务的地图图像是按照移动设备范围读取的,用法如下:
- MapView mv = new MapView(this);
- mv.addLayer(new ArcGISDynamicMapServiceLayer( "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer"));
- setContentView(mv);
3、 ArcGISImageServiceLayer
ArcGISImageServiceLayer图层对应ArcGIS Server服务中的影像服务,调用影像服务非常简单,用法如下:
- MapView mv = new MapView(this);
- mv.addLayer(new ArcGISImageServiceLayer(
- "http://myserver/arcgis/rest/services/MyImage/ImageServer",null));
- setContentView(mv);
4、 ArcGISFeatureLayer
ArcGISFeatureLayer图层对应ArcGIS Server服务中的Feature Service服务,只有这样的服务才可以进行在线数据编辑,Feature Service服务在调用时可以设置调用的三种模式,不同的模式返回的数据和效率不同,三种模式分别为:MODE.SNAPSHOT按快照方式返回服务的所有数据,MODE.ONDEMAND按需返回数据,MODE.SELECTION按所选的范围返回数据,用法如下:
- String url = "https://servicesbeta.esri.com/ArcGIS/rest/services/SanJuan/TrailConditions/FeatureServer/0";
- MapView mv = new MapView(this);
- mv.addLayer(new ArcGISFeatureLayer(url,MODE.SNAPSHOT));//按照快照方式
- setContentView(mv);
5、 ArcGISLocalTiledLayer
ArcGISLocalTiledLayer是添加离线数据包的图层,该图层目前支持两种格式的离线数据:一个是紧凑型的缓存切片,另一个是打包的tpk格式的数据,对于这两种数据的制作方法可以参照附录“如何制作离线数据附录“章节,图层用法如下:
- MapView mv = new MapView(this);
- ArcGISLocalTiledLayer local = new ArcGISLocalTiledLayer("file:///mnt/sdcard/<CacheName>/Layers");//离线图层
- mv.addLayer(local);
- setContentView(mv);
6、 GraphicsLayer
GraphicsLayer在ArcGIS Runtime for Android中是比较重要的一个图层,也是我们使用最为频繁的一个,GraphicsLayer可以包含一个活多个Graphic对象,所以不管我们是查询出来还是自己标绘的Graphic数据都要通过他来呈现,并且MapView添加图层时不要第一个添加这个图层,MapView加载图层时首先要初始化一些地图参数,而该图层不具备这些参数,用法如下:
- MapView mv = new MapView(this);
- mv.addLayer(new GraphicsLayer());
- setContentView(mv);
除了可以呈现Graphic对象外,它还具备了一些其他有用的功能,如要素更新与要素获取等等。
- 要素更新
这个功能在以后的开发我们会经常用到,如我们要实时更新一个坐标的位置或者用于标绘时,我们以标绘为例来说一下它的更新用处,在我们在移动设备上想实现标绘时,我们就会用到GraphicsLayer的updateGraphic()方法进行实时更新,这时地图上绘制的几何要素将被不断绘制出来,如:
- public boolean onDragPointerMove(MotionEvent from, MotionEvent to) {
- if (startPoint == null) {//判断是否已经存在第一个点
- graphicsLayer.removeAll();
- poly = new Polyline();
- startPoint = mapView.toMapPoint(from.getX(), from.getY());
- poly.startPath((float) startPoint.getX(),
- (float) startPoint.getY());
- uid = graphicsLayer.addGraphic(new Graphic(poly,new SimpleLineSymbol(Color.BLUE,5)));
- }
- poly.lineTo((float) mapPt.getX(), (float) mapPt.getY());//增加线点
- graphicsLayer. updateGraphic(uid,poly);//更新数据显示
- return true;
- }
- 要素获取
对于在ArcGIS Runtime for Android中,与其他Web API还有所不同,其他API中Graphic对象是可以设置监听的,而在ArcGIS Runtime for Android中Graphic是不能添加任何监听的,所以当我们在地图上点击一个Graphic对象时就需要其他方式间接的获取这个对象。我们可以通过GraphicsLayer的方法getGraphicIDs(float x, float y, int tolerance)来获取要素,其中x和y是屏幕坐标,tolerance是容差,通过这个方法我们就可以间接的获取所需的Graphic对象,如:
- public boolean onSingleTap(MotionEvent e) {
- Graphic graphic = new Graphic(mapView.toMapPoint(new Point(e.getX(), e.getY())),new SimpleMarkerSymbol(Color.RED,25,STYLE.CIRCLE));
- return false;
- int[] getGraphicIDs(float x,float y, int tolerance)
- }
7、 BingMapsLayer
ArcGIS Runtime for Android中也可以添加Bing地图服务,想添加Bing地图首先我们必须注册账户并获取Bing map的App ID,有了这个ID我们就有了使用Bing地图的权限,具体的账户申请和操作步骤我们可以参照以下地址:
地址:https://www.bingmapsportal.com/
详细说明:http://msdn.microsoft.com/en-us/library/ff428642.aspx
- <com.esri.android.map.MapView
- android:id="@+id/map"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- url="http://www.arcgis.com/home/item.html?id=2b571d8c079d46b4a14a67df42b1da6f"
- appId="">
- </com.esri.android.map.MapView>
将申请的ID填入上面代码appId属性即可正常访问Bing地图服务。
8、 SpatialReference
空间参考对象,我们可以通过MapView或图层来获取这个对象,对于每一个地图服务,他都有对应的空间参考系,当我们做查询检索或坐标投影转换时会经常用到该对象,用法如下- double locy = loc.getLatitude();//纬度
- double locx = loc.getLongitude();//经度
- Point wgspoint = new Point(locx, locy);
- //将经纬度坐标转换成地图坐标系
- Point mapPoint = (Point) GeometryEngine.project(wgspoint,SpatialReference.create(4326), map.getSpatialReference());
- Unit mapUnit = map.getSpatialReference().getUnit();
- double zoomWidth = Unit.convertUnits(
- SEARCH_RADIUS,
- Unit.create(LinearUnit.Code.MILE_US),
- mapUnit);
- Envelope zoomExtent = new Envelope(mapPoint,zoomWidth, zoomWidth);
- map.setExtent(zoomExtent);
- ArcGIS Runtime for Android开发教程V2.0(5)基础篇---图层
- ArcGIS Runtime for Android开发教程V2.0(5)基础篇---图层
- ArcGIS Runtime for Android开发教程V2.0(3)基础篇---Hello World Map
- ArcGIS Runtime for Android开发教程V2.0(4)基础篇---MapView
- ArcGIS Runtime for Android开发教程V2.0(6)基础篇---空间要素可视化
- ArcGIS Runtime for Android开发教程V2.0(7)基础篇---空间要素可视化2
- ArcGIS Runtime for Android开发教程V2.0(8)基础篇-----地图事件
- ArcGIS Runtime for Android开发教程V2.0(9)基础篇-----查询检索
- ArcGIS Runtime for Android开发教程V2.0(4)基础篇
- ArcGIS Runtime for Android开发教程V2.0(3)基础篇
- ArcGIS Runtime for Android开发教程V2.0(4)基础篇
- ArcGIS Runtime for Android开发教程V2.0(3)基础篇
- ArcGIS Runtime for Android开发教程V2.0(4)基础篇---MapView
- ArcGIS Runtime for Android开发教程V2.0(6)基础篇---空间要素可视化
- ArcGIS Runtime for Android开发教程V2.0(7)基础篇---空间要素可视化2
- ArcGIS Runtime for Android开发教程V2.0(8)基础篇-----地图事件
- ArcGIS Runtime for Android开发教程V2.0(9)基础篇-----查询检索
- 【教程连载】ArcGIS Runtime for Android开发教程V2.0(3)基础篇---Hello World Map
- Eclipse导入项目:No projects are found to import
- POJ - 3264 - Balanced Lineup (线段树)
- iOS—UI-手势及控件(segment switch slider)的使用
- c++ const 成员函数 & 临时变量 & 右值引用 & move
- codeforce 559 C Gerald and Giant Chess
- ArcGIS Runtime for Android开发教程V2.0(5)基础篇---图层
- Linux下crontab+php实现Mysql数据库定时备份
- 读书笔记MoreEffectiveC++(13)
- 打包jar
- 1001 Sum Problem
- ArcGIS Runtime for Android开发教程V2.0(6)基础篇---空间要素可视化
- Android Studio 开发利器【常用插件】
- 25 - 二叉树中和为某一值的路径
- Java面试题全集(中)