• ArcGIS Runtime for Android开发教程V2.0(5)基础篇图层


    目录(?)[-]

    1. ArcGISTiledMapServiceLayer
    2. ArcGISDynamicMapServiceLayer
    3. ArcGISFeatureLayer
    4. ArcGISLocalTiledLayer
    5. GraphicsLayer
    6. BingMapsLayer
    7. SpatialReference      
    <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);

    原文链接:http://blog.csdn.net/arcgis_mobile/article/details/8151626

  • 相关阅读:
    IOS8 设置TableView Separatorinset 分割线从边框顶端开始
    文件目录的访问
    The file “XXX” couldn’t be opened because you don’t have permission to view it.解决方法:
    NSString 的常见方法
    如何在一个工作站里创建多个工程(同一个xcode下面创建多个工程)
    自定义NSLog
    内存恶鬼drawRect
    URL编码解码
    怎样在UICollectionView中添加Header和footer
    本人开始玩微信公众号了!名称:BHS编程技术交流分享,只发干货,不发水文,欢迎阅读
  • 原文地址:https://www.cnblogs.com/dwf07223/p/3085869.html
Copyright © 2020-2023  润新知