在arcgis地图上简单添加一个图层

Add a feature layer,这次来个简单的arcgis学习例子。在arcgis地图上简单添加一个图层展示。

一、创建一个基图

 // create a map with the BasemapStyle topographic
    val map = ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC)
     // set the map to be displayed in the layout's MapView
    mapView.map = map
    这里也可以是下面方式来创建基图
val url = "http://map.geoq.cn/arcgis/rest/services/ChinaOnlineCommunity/MapServer"
   //val url = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
    val arcGISTiledLayer = ArcGISTiledLayer(url)
    val map = ArcGISMap(Basemap(arcGISTiledLayer))

二、设置一个展示目标位置

// set the viewpoint, Viewpoint(latitude, longitude, scale)
        mapView.setViewpoint(Viewpoint(34.0270, -118.8050, 200000.0))

三、创建一个新的图层

// create the service feature table
        val serviceFeatureTable =
            ServiceFeatureTable("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0")

四、把这个图层加入到地图的操作图层组中

// create the feature layer using the service feature table
    val featureLayer = FeatureLayer(serviceFeatureTable)
    map.operationalLayers.add(featureLayer)

五、完整代码如下

// set up your map here. You will call this method from onCreate()
private fun setupMap() {
    // create a map with the BasemapStyle topographic
    val map = ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC)

    // create the service feature table
    val serviceFeatureTable =
        ServiceFeatureTable("https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0")

    // create the feature layer using the service feature table
    val featureLayer = FeatureLayer(serviceFeatureTable)
    map.operationalLayers.add(featureLayer)

    // set the map to be displayed in the layout's MapView
    mapView.map = map

    // set the viewpoint, Viewpoint(latitude, longitude, scale)
    mapView.setViewpoint(Viewpoint(34.0270, -118.8050, 200000.0))

}

arcgis英文官方参考文档
https://developers.arcgis.com/android/layers/tutorials/add-a-feature-layer/
有一起学习ARCGIS的朋友,可以一起多交流。
在这里插入图片描述