ArcGIS runtime 100 加载多种离线数据
100.几忘记了,应该是.11。从毕设项目把离线数据的加载扒了下来,做的时候java和runtime都不会,边学边做,会有很多不规范的地方,后面做完了也懒得改了,仅供大家参考。
//加载栅格数据 public static void addReaster(Context context, MapView mMapView, String fileName) { rasterLayer = new RasterLayer(new Raster(context.getExternalFilesDir(null) + "/JQHMap/RasterImage/" + fileName)); mMapView.getMap().getOperationalLayers().add(rasterLayer); rasterLayer.loadAsync(); rasterLayer.addDoneLoadingListener(new Runnable() { @Override public void run() { try { mMapView.setViewpointGeometryAsync(rasterLayer.getFullExtent(), 10); } catch (Exception e) { Log.e(TAG, e.toString() + "addReaster"); } } }); } //加载tpk、tpkx public static void addTpk(Context context, MapView mMapView, String tpkFileName) { TileCache mainTileCache = new TileCache(context.getExternalFilesDir(null) + "/JQHMap/RasterImage/" + tpkFileName); mainTileCache.loadAsync(); mainTileCache.addDoneLoadingListener(new Runnable() { @Override public void run() { if (mainTileCache.getLoadStatus() == LoadStatus.LOADED) { ArcGISTiledLayer arcGISTiledLayer = new ArcGISTiledLayer(mainTileCache); arcGISTiledLayer.setName(tpkFileName); mMapView.getMap().getOperationalLayers().add(arcGISTiledLayer); arcGISTiledLayer.addDoneLoadingListener(new Runnable() { @Override public void run() { try { if (arcGISTiledLayer.getLoadStatus() == LoadStatus.LOADED) { mMapView.setViewpointGeometryAsync(arcGISTiledLayer.getFullExtent(), 10); } } catch (Exception e) { Log.e(TAG, e.toString() + "addTPK"); } } }); } } }); } //添加vtpk public static void addVtpk(Context context, MapView mapView, String vtpkName) { VectorTileCache vectorTileCache = new VectorTileCache(context.getExternalFilesDir(null) + "/JQHMap/VectorData/" + vtpkName); vectorTileCache.loadAsync(); vectorTileCache.addDoneLoadingListener(new Runnable() { @Override public void run() { if (vectorTileCache.getLoadStatus() == LoadStatus.LOADED) { ArcGISVectorTiledLayer arcGISVectorTiledLayer = new ArcGISVectorTiledLayer(vectorTileCache); arcGISVectorTiledLayer.setName(vtpkName); mapView.getMap().getOperationalLayers().add(arcGISVectorTiledLayer); arcGISVectorTiledLayer.addDoneLoadingListener(new Runnable() { @Override public void run() { try { if (arcGISVectorTiledLayer.getLoadStatus() == LoadStatus.LOADED) { mapView.setViewpointGeometryAsync(arcGISVectorTiledLayer.getFullExtent(), 10); } } catch (Exception e) { Log.e(TAG, e.toString() + "addVtpk"); } } }); } } }); } //添加shp数据 public static void addShp(Context context, MapView mapView, String shpName) { ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(context.getExternalFilesDir(null) + "/JQHMap/VectorData/" + shpName); ShapFileOperationUtils.loadVectorFile(context, mapView, null, shapefileFeatureTable, null, "shp"); } //添加kml public static void addKMl(Context context, MapView mapView, String kmlName) { KmlDataset mainTileCache = new KmlDataset(context.getExternalFilesDir(null) + "/JQHMap/VectorData/" + kmlName); KmlLayer kmlLayer = new KmlLayer(mainTileCache); kmlLayer.setName(kmlName); mapView.getMap().getOperationalLayers().add(kmlLayer); kmlLayer.addDoneLoadingListener(new Runnable() { @Override public void run() { try { mapView.setViewpointGeometryAsync(kmlLayer.getFullExtent(), 10);//padding左右边界 } catch (Exception e) { Log.e(TAG, e.toString() + "addRaster"); } } }); } //添加geodatabase public static void addGeodatabase(Context context, MapView mapView, String geodatabaseName) { final Geodatabase geodatabase = new Geodatabase(context.getExternalFilesDir(null) + "/JQHMap/VectorData/" + geodatabaseName); geodatabase.loadAsync(); geodatabase.addDoneLoadingListener(() -> { if (geodatabase.getLoadStatus() == LoadStatus.LOADED) { List<GeodatabaseFeatureTable> geodatabaseFeatureTables = geodatabase.getGeodatabaseFeatureTables(); for (int i = 0; i < geodatabaseFeatureTables.size(); i++) { GeodatabaseFeatureTable geodatabaseFeatureTable = geodatabaseFeatureTables.get(i); geodatabaseFeatureTable.loadAsync(); ShapFileOperationUtils.loadVectorFile(context, mapView, geodatabaseFeatureTable, null, null, "geodatabase"); } } }); } //添加mmpk public static void addMMPK(Context context, MapView mapView, String mmpkName) { final MobileMapPackage mobileMapPackage = new MobileMapPackage(context.getExternalFilesDir(null) + "/JQHMap/VectorData/" + mmpkName); mobileMapPackage.loadAsync(); mobileMapPackage.addDoneLoadingListener(() -> { if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED) { List<ArcGISMap> arcGISMaps = mobileMapPackage.getMaps(); ArcGISMap arcGISMap = arcGISMaps.get(0); mapView.setMap(arcGISMap); } }); }
本文来自博客园,作者:季夏啸华,转载请注明原文链接:https://www.cnblogs.com/jiang2020/p/15744895.html
分类:
移动GIS
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理