Home > Back-end >  Unable to add a feature layer using API for .net
Unable to add a feature layer using API for .net

Time:10-26

A map contains a basemap layer and, optionally, one or more data layers. Basically, I want to access and display a feature layer in a map layers with an item ID or URL. Currently, I am using URLs to access the Trailheads, Trails, and Parks and Open Spaces feature layers and want to display them in a map.

But I am unable to add them to my map. Any suggestion.

Following are the steps I followed

In the SetupMap() function of my .cs file, I added code that defines the URIs to the hosted layers. Like below

    private void SetupMap()
    {
        Map = new Map(BasemapStyle.ArcGISTopographic);

        var parksUri = new Uri(
            "https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Parks_and_Open_Space/FeatureServer/0"
            );

        var trailsUri = new Uri(
            "https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trails/FeatureServer/0"
            );

        var trailheadsUri = new Uri(
            "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
            );

Then, in the SetupMap() function, I created new feature layers and pass the appropriate URI to the constructor for each.

        var parksLayer = new FeatureLayer(parksUri);
        var trailsLayer = new FeatureLayer(trailsUri);
        var trailheadsLayer = new FeatureLayer(trailheadsUri);

Then, I added the feature layers to the map.

   Map.Add(parksLayer);
    Map.Add(trailsLayer);
    Map.Add(trailheadsLayer);

But, my code is not adding any sort of layers?

CodePudding user response:

I am copying this piece of code from my project. Modify your script as follows, and it will work.

Map.OperationalLayers.Add(parksLayer);
            Map.OperationalLayers.Add(trailsLayer);
            Map.OperationalLayers.Add(trailheadsLayer);
  • Related