1.工具方法 判断文件是否存在
/*** 判断文件是否存在* @param strFile* @return*/public static boolean fileIsExists(String strFile){try{File f=new File(strFile);if(!f.exists()){return false;}}catch (Exception e){return false;}return true;}
2.加载tif格式文件
//文件路径 (根目录+文件夹)String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/333333/22.tif";Raster raster = new Raster(path);if (Uilte.fileIsExists(path)) {toast("tif文件存在");// 添加特征层到地图raster.loadAsync();raster.addDoneLoadingListener(new Runnable() {@Overridepublic void run() {// 创建一个栅格图层RasterLayer mRasterLayer = new RasterLayer(raster);// 添加光栅作为操作层0.map.getOperationalLayers().add(mRasterLayer);}});} else {toast("文件不存在");}
3.加载tpk格式文件
//根目录+文件String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/333333" + "/测试数据1.tpk";//程序的路径+文件//String path =getExternalFilesDir(null) + "/qqq.tpk";if (Uilte.fileIsExists(path)) {Log.e("tpk", "文件存在");// 从本地存储加载tile缓存TileCache tileCache = new TileCache(path);// 使用平铺缓存区来设置视图点tileCache.addDoneLoadingListener(() -> mMapView.setViewpoint(new Viewpoint(tileCache.getFullExtent())));// 创建一个平铺层,并将其添加为基础地图ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tileCache);//设置成地图的底图map.setBasemap(new Basemap(tiledLayer));//设置成图层添加上去//map.getOperationalLayers().add(tiledLayer);} else {Log.e("tpk", "文件不存在");}
4.加载shp格式文件
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/333333/2.shp";// 使用shapefile特性表创建一个特性层if (Uilte.fileIsExists(path)) {toast("shp文件存在");ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(path);featureLayer = new FeatureLayer(shapefileFeatureTable);// 添加特征层到地图shapefileFeatureTable.loadAsync();shapefileFeatureTable.addDoneLoadingListener(new Runnable() {@Overridepublic void run() {//shp格式的文件名String name = shapefileFeatureTable.getTableName();Log.e("name", name);if (featureLayer.getFullExtent() != null) {mMapView.setViewpointGeometryAsync(featureLayer.getFullExtent());} map.getOperationalLayers().add(featureLayer);}});}// 创建 点 线//SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 10.0f);//SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, lineSymbol);//创建渲染器//SimpleRenderer renderer = new SimpleRenderer();//在图层上设置渲染器//featureLayer.setRenderer(renderer);