arcgis for android 離線切片載入與geodatabase查詢
阿新 • • 發佈:2019-02-15
載入geodatabase資料
private FeatureLayer valueFL; //離線資料圖 @Override public void getLocalMapServerDiFangData(){ try { List<File> list=null; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){ File file=Environment.getExternalStorageDirectory().getAbsoluteFile(); File file1=new File(file,Constant.LOCAL_DATA); if (file1.exists()){ list=Arrays.asList(file1.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith("geodatabase"); } })); } } if (list==null||list.size()==0){ messageDialog("請在手機SD卡根目錄下localdata檔案架下放入geodatabase檔案!"); }else { String mainGeodatabaseFilePath =list.get(0).getPath(); final Geodatabase mainGeodatabase = new Geodatabase(mainGeodatabaseFilePath); mainGeodatabase.loadAsync(); mainGeodatabase.addDoneLoadingListener(new Runnable() { @Override public void run() { List<GeodatabaseFeatureTable> resultsGFT = mainGeodatabase.getGeodatabaseFeatureTables(); valueFL = new FeatureLayer(resultsGFT.get(2)); QueryParameters query = new QueryParameters(); query.setWhereClause("1=1");// 設定空間幾何物件 FeatureTable mTable = valueFL.getFeatureTable();//得到查詢屬性表 final ListenableFuture<FeatureQueryResult> featureQueryResult = mTable.queryFeaturesAsync(query); featureQueryResult.addDoneListener(new Runnable() { @Override public void run() { try { FeatureQueryResult featureResul = featureQueryResult.get(); mGeometryMap = new HashMap<String, Geometry>(); for (Object element : featureResul) { if (element instanceof Feature) { Feature mFeatureGrafic = (Feature) element; Map<String, Object> mQuerryString = mFeatureGrafic.getAttributes(); mList.add(mQuerryString); mGeometryMap.put(mQuerryString.get("TBYBH") + "", mFeatureGrafic.getGeometry()); mLayerMap.put(mQuerryString.get("TBYBH") + "_"+mQuerryString.get("YH")+"_"+mQuerryString.get("DCLY"),mFeatureGrafic); } } getSortData(mList); Message message = new Message(); message.what = 666; mHandler.sendMessage(message); }catch (Exception e){ e.printStackTrace(); } } }); valueFL.setVisible(true); LayerList mainLayerList = mArcGISMap.getOperationalLayers(); mainLayerList.add(valueFL); } }); } } catch (Exception e) { } }
離線切片tpk:
/** * 函式:建立離線底圖 * 引數: * @param path tpk資料路徑 * @param mBaseMap arcgis 基礎圖層 * @param mArcgisMap arcgis 圖層 * 返回值: */ //離線底圖 @Override public void createLocalMapView(){ if (mMapView == null) return; List<File> list=null; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){ File file=Environment.getExternalStorageDirectory().getAbsoluteFile(); File file1=new File(file,Constant.LOCAL_TPK); if (file1.exists()){ list=Arrays.asList(file1.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith("tpk"); } })); } } if (list==null||list.size()==0){ messageDialog("請在手機SD卡根目錄下localtpk檔案架下放入tpk檔案!"); }else { TileCache vTileCache = new TileCache(list.get(0).getPath()); ArcGISTiledLayer mainArcGISTiledLayer = new ArcGISTiledLayer(vTileCache); mBasemap = new Basemap(mainArcGISTiledLayer); mArcGISMap = new ArcGISMap(mBasemap); mMapView.setMap(mArcGISMap); } }