1、打开地图

  • Create the map object from a layer

  /**使用图层URL来显示地图
     *
     */
    private void displayMapByLayerUrl() {
        String urlpath = "http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineCommunity_Mobile/MapServer";
        ArcGISTiledLayer layer = new ArcGISTiledLayer(urlpath);
        Basemap basemap = new Basemap(layer);
        ArcGISMap map = new ArcGISMap(basemap);
        // set the map to be displayed in this view
        mMapView.setMap(map);
    }
  • Create the map object from a web map

可以使用URL访问Web地图,也可以使用其portal item ID直接从门户访问Web地图。本文描述了这两种方法,以及访问地图(如果地图或其数据不是公共的)所需的身份验证(authentication )过程。

  • Using a web map URL
   /**使用web map URL来显示地图
     *
     */
    private void displayMapByWebMapUrl() {
        String webMapURL = "https://www.arcgis.com/home/webmap/viewer.html?webmap=69fdcd8e40734712aaec34194d4b988c";
        Basemap basemap = new Basemap(webMapURL);
        ArcGISMap map = new ArcGISMap(basemap);
        mMapView.setMap(map);
    }
  • Using a web map portal item

 /**使用PortalItem来显示地图
     *
     */
    private void displayMapByPortalItem() {
        // get the portal url and portal item from ArcGIS online
        Portal portal = new Portal("http://www.arcgis.com/", false);
        PortalItem portalItem = new PortalItem(portal, "a13c3c3540144967bc933cb5e498b8e4");
        // create scene from a portal item
        ArcGISScene scene = new ArcGISScene(portalItem);
        mSceneView.setScene(scene);
    }

Display a map

补充:身份验证(Authentication)
如果地图或其图层不是公共的,则需要提供凭据( credentials)来访问它们。在这些情况下,您可以依赖API的身份验证challenge handler 提示用户输入他们的凭据,或者您可以提供自己的登录工具,并将凭据传递给门户的setCredentials方法,如访问ArcGIS平台主题中所述。

  • Create a map object from a mobile map package

获取移动地图包的文件路径。

// The mobile map package has been placed in the apps documents folder
File mmpkFile = new File(Environment.getExternalStorageDirectory(), dataPath + "CaliforniaNevada.mmpk");
String mmpkPath = mmpkFile.getAbsolutePath();

使用文件路径构建移动地图包对象

final MobileMapPackage mobileMapPackage = new MobileMapPackage("path/to/file/.mmpk");

移动地图包必须加载到app中才能访问地图本身。一旦加载了移动地图包,它的任何地图都可以分配给要显示的地图视图。

mobileMapPackage.addDoneLoadingListener(() -> {
  if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED) {
    System.out.println("Number of maps = " + mobileMapPackage.getMaps().size());
    // In this case the first map in the array is obtained
    ArcGISMap mobileMap = mobileMapPackage.getMaps().get(0);
  } else {
    // If loading failed, deal with failure depending on the cause...
  }
});
mobileMapPackage.loadAsync();

具体参考:https://developers.arcgis.com/android/latest/sample-code/open-mobile-map-package.htm

https://github.com/gislaozhang/DisplayMap

Display a map

参考链接:

https://developers.arcgis.com/android/latest/guide/display-a-map.htm

相关文章:

  • 2021-09-01
  • 2021-06-19
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-04-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-06-28
  • 2021-10-07
相关资源
相似解决方案