arcgis for android 100.2加载离线地图随笔

Global.INSTANCE.getMapView().setAttributionTextVisible(false); //去掉下方“power by esri”

地图去水印的两种方式(去掉License for developer use only):

    需要esri授权的标准版权限许可,然后在初始化地图代码之前添加:    

        1、在licensing界面中可查看你的Arcgis runtime lite license key

      如果你已经获得授权,可以直接访问这个链接查看你的key:    https://developers.arcgis.com/arcgis-runtime/licensing/  

ArcGISRuntimeEnvironment.("runtimelite,1000,rudxxxxxx6614,none,5H80TK8Exxxxxxxx203");

 

  2、通过credential授权

 UserCredential credential = new UserCredential("username", "userpasd");

        portal = new Portal("https://xxxxx.maps.arcgis.com/");        //你的域名

        portal.setCredential(credential);

        portal.loadAsync();
        portal.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                // get license info from the portal
                licenseInfo = portal.getPortalInfo().getLicenseInfo();
                // Apply the license at Standard level
                ArcGISRuntimeEnvironment.setLicense(licenseInfo);
            }
        });   

    去网格:

    BackgroundGrid backgroundGrid = new BackgroundGrid();
        backgroundGrid.setColor(0xf6f6f6f6);
        backgroundGrid.setGridLineWidth(0);
        mMapview.setBackgroundGrid(backgroundGrid);

 

加载底图:

        ArcGISMap arcGISMap = new ArcGISMap();
        TileCache mainTileCache = new TileCache(url);    //url = 底图的链接url
        ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(mainTileCache);
        Basemap basemap = new Basemap(tiledLayer);
        arcGISMap.setBasemap(basemap);
        mapView.setMap(arcGISMap);

 

加载shp:

    shapefile是一种用于存储地理要素的几何位置和属性信息的非拓扑简单格式。地理要素通过点、线、面(区域)来表示。包含shapefile的工作空间可以包含dBASE表,用于存储可连接到shapefile的要素的附加属性。

加载shapefile:

ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(shapefile_path));
    shapefileFeatureTable.loadAsync();
    shapefileFeatureTable.addDoneLoadingListener(new Runnable() {
        @Override
        public void run() {
            GeometryType geotype= shapefileFeatureTable.getGeometryType();
            String tableName= shapefileFeatureTable.getTableName();
            FeatureLayer mainShapefileLayer = new FeatureLayer(shapefileFeatureTable);
            if (mainShapefileLayer.getFullExtent() != null) {
                mainMapView.setViewpointGeometryAsync(mainShapefileLayer.getFullExtent());
            } else {
                mainShapefileLayer.addDoneLoadingListener(new Runnable() {
                    @Override
                    public void run() {
                        mainMapView.setViewpointGeometryAsync(mainShapefileLayer.getFullExtent());
                    }
                });
            }
            arcGISMap.getOperationalLayers().add(mainShapefileLayer);
            startDrawing();
        }
    });

点击位置查询shapefile

    mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener((MapActivity) getView(), mMapView) {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {

                if (isClick) {
                    LayerList layersList = Global.INSTANCE.getMapView().getMap().getOperationalLayers();
                    Log.e("xyh", "onSingleTapConfirmed: " + layersList.size());
                    final GraphicsOverlay graphicsOverlay = ((MapActivity) getView()).getGraphicsOverlay();
                    if (graphicsOverlay != null) {
                        ListenableList graphics = graphicsOverlay.getGraphics();
                        if (graphics.size() > 0) {
                            graphics.removeAll(graphics);
                        }
                    }
                    final Point clickPoint = mMapView.screenToLocation(new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())));
                    int tolerance = 1;
                    double mapTolerance = tolerance * mMapView.getUnitsPerDensityIndependentPixel();
                    SpatialReference spatialReference = mMapView.getSpatialReference();
                    int wkid = spatialReference.getWkid();
                    Envelope envelope = new Envelope(clickPoint.getX() - mapTolerance, clickPoint.getY() - mapTolerance, clickPoint.getX() + mapTolerance, clickPoint.getY() + mapTolerance, spatialReference);
                    QueryParameters query = new QueryParameters();
                    query.setGeometry(envelope);
                    query.setSpatialRelationship(QueryParameters.SpatialRelationship.WITHIN);
                    final ListenableFuture future = mainShapefileLayer.selectFeaturesAsync(query, FeatureLayer.SelectionMode.NEW);
                    future.addDoneListener(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                FeatureQueryResult result = future.get();
                                Iterator iterator = result.iterator();
                                Feature feature;

                                int counter = 0;
                                while (iterator.hasNext()) {
                                    feature = iterator.next();
                                    Map attributes = feature.getAttributes();
                                    getView().onShpAttrData(attributes, clickPoint);
                                    Geometry geometry = feature.getGeometry();
                                    SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 3);
                                    SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.RED, lineSymbol);
                                    Graphic graphic = new Graphic(geometry, fillSymbol);
                                    graphicsOverlay.getGraphics().add(graphic);
                                    if (!mMapView.getGraphicsOverlays().contains(graphicsOverlay)) {
                                        mMapView.getGraphicsOverlays().add(graphicsOverlay);
                                    }
                                    counter++;
                                }
                            } catch (Exception e) {
                                e.getCause();
                                // Log.e("xyh", "run: " + e.getMessage());
                            }
                        }
                    });
                    return super.onSingleTapConfirmed(e);
                } else {
                    return true;
                }
            }
        });

 

加载.tpk文件

 

    ArcGISTiledLayer mArcGISTiledLayer = new ArcGISTiledLayer(tpkPath);
    arcGISMap.getOperationalLayers().add(tiledLayer);
    mapView.setMap(arcGISMap);

移除.tpk图层

   arcGISMap.getOperationalLayers().remove(arcGISTiledLayer);

加载三维地图:

    ArcGISScene arcGISScene = new ArcGISScene(Basemap.createImagery());
    ArcGISSceneLayer layer = new ArcGISSceneLayer("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");
    arcGISScene.getOperationalLayers().add(layer);
    sceneView.setScene(arcGISScene);

加载.vtpk

  String URL_BASEMAP = Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + "测试底图/qfeddacdd.vtpk";
  ArcGISVectorTiledLayer tiledLayer = new ArcGISVectorTiledLayer(URL_BASEMAP7);
  basemap = new Basemap(tiledLayer);
  ArcGISMap map = new ArcGISMap(basemap);
  mapView.setMap(map);

加载.mmpk离线地图包

MobileMapPackage mobileMapPackage = new MobileMapPackage(MMPKURL);
       mobileMapPackage.loadAsync();
        mobileMapPackage.addDoneLoadingListener(new Runnable() {
           @Override
           public void run() {
               LoadStatus loadStatus = mobileMapPackage.getLoadStatus();
               if(loadStatus == LoadStatus.LOADED){
                   List maps = mobileMapPackage.getMaps();

                   Log.e("enbir",maps.size()+"");
                   initBaseImage();
                   arcGISMap = maps.get(0);
                   arcGISMap.setBasemap(basemap);
                   mMapView.setMap(arcGISMap);
//                   mMapView.setMap(arcGISMap1);
               }
           }
       });
//        ArcGISMap arcGISMap = new ArcGISMap(basemap);

加载.geodatabase离线地图

 File file = new File(MyApplication.getLOCALGDBPATH());
        if (file.exists()) {
            mGeodatabase = new Geodatabase(MyApplication.getLOCALGDBPATH());
            mGeodatabase.loadAsync();
            mGeodatabase.addDoneLoadingListener(new Runnable() {
                @Override
                public void run() {
                    geodatabaseFeatureTables = mGeodatabase.getGeodatabaseFeatureTables();
                    int size = geodatabaseFeatureTables.size();
                    for (int i = 0; i < size; i++) {
                        FeatureLayer featureLayerTemp = new FeatureLayer(geodatabaseFeatureTables.get(i));
                        String tableName = geodatabaseFeatureTables.get(i).getTableName();
                        if(geodatabaseFeatureTables.get(i).getTableName().equals("QXXZQ")){
                            xzqFeatureLayer = featureLayerTemp;
                        }
                        featureLayerList.add(featureLayerTemp);
                        Map layerMap = new HashMap<>();
                        layerMap.put(geodatabaseFeatureTables.get(i).getTableName().toString(), featureLayerTemp);
                        layerData.add(layerMap);
                        layerNames.add(geodatabaseFeatureTables.get(i).getTableName().toString());

                    }
                }
            });
        }

Callout展示

Callout callout = mMapview.getCallout();
            callout.setLocation(point);
            callout.setContent(calloutView);
            Callout.Style style = new Callout.Style(this);
            style.setMaxWidth(600);
            style.setMaxHeight(600);
            style.setLeaderLength(100);
            style.setLeaderPosition(Callout.Style.LeaderPosition.LOWER_LEFT_CORNER);
            style.setBackgroundColor(Color.parseColor("#aa000000"));
            style.setBorderColor(Color.parseColor("#ffffff"));
            callout.setStyle(style);
            callout.show();
            ivClose.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    callout.dismiss();
                }
            });

mapview居中到点

 mMapview.setViewpointCenterAsync(point);

 

觉得好就记得关注哦~~Thanks♪(・ω・)ノ

 

 

你可能感兴趣的:(arcigs,for,android)