How to add a FeatureLayer published by ArcGIS Server

352
5
01-13-2021 11:19 PM
wanglong
New Contributor II

HELLO,

I published the service using ArcGIS Server,and load it success with JS API.

var layerss = new FeatureLayer({
url: "https://hbsyb.booway.com.cn/arcgis/rest/services/zjsxyd/sichuanxianjixingzhengqu/MapServer/0",
outFields : ["*"],
opacity : 0.5
});
map.add(layerss);

bud when i want to load it with Android Runtime Sdk 100.5.0(FeatureLayer), it doesn't work.

What shall I do?

0 Kudos
5 Replies
MarkBaird
Esri Regular Contributor

I've tried adding your feature later to a map using our latest release (100.9.0) and it displayed without any issues.

I was basically swapping your service into this app on github:

https://github.com/Esri/arcgis-runtime-samples-android/tree/master/kotlin/feature-layer-feature-serv...

I had to zoom to a different area, but I could see your data:

MarkBaird_0-1610624622260.png

Does using this code help?

0 Kudos
wanglong
New Contributor II

Thank you. It helped me a lot.

I found out the problem is that for the sake of security, Google has explicitly prohibited the amount of HTTP protocol on Android P, so I set it the "android: networkSecurityConfig" in my code.  Therefore,  I successfully loaded the layer(https://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/MapServer/9) when I removed it. 

However, what puzzles me is that i still couldn't load my service, even if i imported the app on GitHub and  replaced my sdk version to 100.9.0.😔

Did to just replaced the service url in the sample's code?

Looking forward to hearing from you.

0 Kudos
wanglong
New Contributor II

Hey, MarkBaird. Please tell me if your screenshot is a mobile phone screenshot?

0 Kudos
MarkBaird
Esri Regular Contributor

The screenshot in my previous post was grabbed from running it in a desktop Java Runtime app which was for convenience.  

I does however work on in my Kotlin Android app too.  This is the modified onCreate method from my app:

 

 

 

 

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // create the service feature table
    val serviceFeatureTable = ServiceFeatureTable("https://hbsyb.booway.com.cn/arcgis/rest/services/zjsxyd/sichuanxianjixingzhengqu/MapServer/0");

    // create the feature layer using the service feature table
    val featureLayer = FeatureLayer(serviceFeatureTable)

    // create a map with the terrain with labels basemap
    ArcGISMap(Basemap.createTerrainWithLabels()).let { map ->
      // set an initial viewpoint
      //map.initialViewpoint = Viewpoint(
      //  Point(
      //    -13176752.0,
      //    4090404.0,
      //    SpatialReferences.getWebMercator()
      //  ), 500000.0
      //)

      // add the feature layer to the map
      map.operationalLayers.add(featureLayer)

      featureLayer.loadAsync()
      featureLayer.addDoneLoadingListener {
        val extent: Envelope = featureLayer.getFullExtent()

        mapView.setViewpointGeometryAsync(extent)
      }

      // set the map to be displayed in the mapview
      mapView.map = map
    }
  }

 

 

 

 

This zooms to the extent of the layer once it is loaded and on my Samsung phone looks like this:

 

MarkBaird_4-1610970430116.png

 

If you use my code, does this work for you?

0 Kudos
MarkBaird
Esri Regular Contributor

I have had some instances when the service hasn't loaded.  I basically wasn't getting a response from the server and it timed out.

The code sample above could be made more robust by checking the load status of the feature layer.

 

      featureLayer.loadAsync()
      featureLayer.addDoneLoadingListener {
        //Toast.makeText(this, "loaded", 3)
        if (featureLayer.loadStatus == LoadStatus.FAILED_TO_LOAD) {
          Toast.makeText(this, "failed to load " + featureLayer.loadError.message, Toast.LENGTH_SHORT).show()

        } else {


          Toast.makeText(this, "loaded okay", Toast.LENGTH_SHORT).show()
          val extent: Envelope = featureLayer.getFullExtent()

          mapView.setViewpointGeometryAsync(extent)
        }
      }

 

0 Kudos