继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

ArcGIS Runtime For Android 开发(3)

慕姐6208834
关注TA
已关注
手记 7
粉丝 19
获赞 19

第三课 地图图层加载

在上一节中,我们了解了ArcGIS Runtime for Android 中支持的图层,这节课我们来学习如何加载图层。

所有的图层都继承自Layer,地图控件为我们提供了addLayer()方法,所以需要添加图层的时候我们使用addLayer方法将图层添加到map中。下面直接上 代码吧。

1.ArcGISLocalTiledLayer

ArcGISLocalTiledLayer tileLayer = new ArcGISLocalTiledLayer("file://" + mapPath + "/" + fileName);//实例化图层
tileLayer.setVisible(false);//控制图层显示与否;
tileLayer.setName(fileName);//设置图层的名称
tileLayer.setOpacity();//设置图层的不透明度
mapView.addLayer(tileLayer);//添加图层到地图窗口中

注意,路径前边的file://不能省略,这是个固定格式
2.ArcGISTiledMapServiceLayer

 String url ="https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer";
ArcGISTiledMapServiceLayer serviceLayer=new  ArcGISTiledMapServiceLayer(url );
mapView.addLayer(serviceLayer);//添加图层到地图窗口中

3.ArcGISDynamicMapServiceLayer

String  tiledLayerAddress="http://10.200.3.210:6001/arcgis/rest/services/ranqimap/gw2016_3/MapServer";
ArcGISDynamicMapServiceLayer agsDMS =new ArcGISDynamicMapServiceLayer(tiledLayerAddress);
mapView.addLayer(tiledLayerAddress);//添加图层到地图窗口中

4.ArcGISImageServiceLayer

String url="http://myserver/arcgis/rest/services/MyImage/ImageServer" 
ArcGISImageServiceLayer imgserviceLayer =new ArcGISImageServiceLayer(url,null);//option
mapView.addLayer(tiledLayerAddress);//添加图层到地图窗口中

5.BingMapLayer

 BingMapsLayer blyr=new BingMapsLayer("你的Bingmap ID",地图风格); 
mapView.addLayer(blyr);//添加图层到地图窗口中

地图风格有如下几种:
AERIAL("Aerial"),
AERIAL_WITH_LABELS("AerialWithLabels"),
ROAD("Road");
6.GraphicsLayer

GraphicsLayer graphicsLayer=new GraphicsLayer();
mapView.addLayers(graphicsLayer);

7.ArcGISFeatureLayer

String url = "https://servicesbeta.esri.com/ArcGIS/rest/services/SanJuan/TrailConditions/FeatureS erver/0"; MapView mv = new MapView(this); mv.addLayer(new ArcGISFeatureLayer(url,MODE.SNAPSHOT));//按照快照方式 setContentView(mv);  

8.本地矢量数据
FeatureLayer支持两种格式的矢量图层数据(Shp,geodatabase),通用的SHP文件直接可以在里边加载,另外使用ArcMap发布的geodabase数据库文件数据也可以直接打开。我们推荐使用geodatabase数据库文件的数据进行地图的浏览,因为geodatabase数据库数据中包含了简单的符号化。

  • 加载SHP文件数据
ShapefileFeatureTable fTab = new ShapefileFeatureTable(dataFile.getAbsolutePath()); 
FeatureLayer fLayer = new FeatureLayer(fTab); // 
SimpleFillSymbol fillSymbolRender = new SimpleFillSymbol(Color.parseColor("#"));
Renderer renderer = new SimpleRenderer(fillSymbolRender);
fLayer.setRenderer(renderer);//图层符号化;
mapView.addLayer(fLayer);
  • 加载geodataabase数据文件
Geodatabase dataBase = new Geodatabase(dataFile.getAbsolutePath());
 List<GeodatabaseFeatureTable> gfts = dataBase.getGeodatabaseTables();
 if (gfts.size() > 0) {
    int lyrCnt = gfts.size();
    for (int j = lyrCnt - 1; j > -1; j--) {
        GeodatabaseFeatureTable gft = gfts.get(j);
        // String layerName = gft.getFeatureServiceLayerName();
        FeatureTable tab = (FeatureTable) gft;
        //featurecount += tab.getNumberOfFeatures();
        FeatureLayer featureLayer = new FeatureLayer(tab);
        featureLayer.setName(tab.getTableName());
        featureLayer.setVisible(false);
        featureLayer.setEnableLabels(true);
        //Log.i("TabeName",tab.getTableName());
       Geometry.Type geoType = featureLayer.getGeometryType();
       //Log.i("GeoType", geoType.toString());
       //mMapView.addLayer(featureLayer);
       mapView.addLayer(featureLayer);
   }
}
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP

热门评论

这笔记做了有什么意义?

查看全部评论