Unable to show FeatureLayer using code behind

3375
4
Jump to solution
05-05-2016 07:43 AM
HuyHo
by
Occasional Contributor

We are having trouble loading FeatureLayers from the code behind.  We based our example on the FeatureLayerHitTesting sample using the following feature layer as a guide:

If we added the feature layer using XAML, the features would show up as expected:

        <esri:FeatureLayer ID="FeatureLayer">

          <esri:FeatureLayer.Renderer>

            <esri:SimpleRenderer>

              <esri:SimpleMarkerSymbol Color="LightBlue" Style="Circle" Size="12">

                <esri:SimpleMarkerSymbol.Outline>

                  <esri:SimpleLineSymbol Color="Blue" Width="2" Style="Solid" />

                </esri:SimpleMarkerSymbol.Outline>

              </esri:SimpleMarkerSymbol>

            </esri:SimpleRenderer>

          </esri:FeatureLayer.Renderer>

          <esri:FeatureLayer.FeatureTable>

            <esri:ServiceFeatureTable ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"

                            Where="pop2000 > 200000" OutFields="*" />

          </esri:FeatureLayer.FeatureTable>

        </esri:FeatureLayer>

Capture1.PNG

However, if we add the layer using code-behind, the layer would not display.

async void MyMapView_Loaded(object sender, RoutedEventArgs e)

    {

      Esri.ArcGISRuntime.Layers.FeatureLayer layer = new Esri.ArcGISRuntime.Layers.FeatureLayer();

      ServiceFeatureTable serviceTable = await ServiceFeatureTable.OpenAsync(

        new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"));

      serviceTable.Where = "pop2000 > 200000";

      SimpleMarkerSymbol symbol = new SimpleMarkerSymbol

      {

        Color = Colors.Orange,

        Style = SimpleMarkerStyle.Circle,

        Size = 12,

        Outline = new SimpleLineSymbol

        {

          Color = Colors.Red,

          Width = 2,

          Style = SimpleLineStyle.Solid

        }

      };

      SimpleRenderer renderer = new SimpleRenderer();

      renderer.Symbol = symbol;

      layer.Renderer = renderer;

      layer.FeatureTable = serviceTable;

      MyMapView.Map.Layers.Add(layer);

    }

But interestingly enough, we we try to added the same feature layer in both XAML and code behind, the code-behind layer would show up, but with a wrong projection.

Capture2.PNG

What am I missing here?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
HuyHo
by
Occasional Contributor

Update.  It seems the problem might had to do with the way the ServiceFeatureTable was created.  If I changed the code to use the constructor to obtain the service table instead of using OpenAsync(), it works.  Based on the description, OpenAsync() creates AND initializes the service (most likely in the spatial reference from the service), causing conflict in projection.

      ServiceFeatureTable serviceTable = new ServiceFeatureTable(

        new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"));

      serviceTable.Where = "pop2000 > 200000";

View solution in original post

0 Kudos
4 Replies
HuyHo
by
Occasional Contributor

Update.  It seems the problem might had to do with the way the ServiceFeatureTable was created.  If I changed the code to use the constructor to obtain the service table instead of using OpenAsync(), it works.  Based on the description, OpenAsync() creates AND initializes the service (most likely in the spatial reference from the service), causing conflict in projection.

      ServiceFeatureTable serviceTable = new ServiceFeatureTable(

        new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"));

      serviceTable.Where = "pop2000 > 200000";

View solution in original post

0 Kudos
AnttiKajanus1
Regular Contributor II

It seems that you are targeting dynamic service instead of feature service here.

0 Kudos
HuyHo
by
Occasional Contributor

Hi Antti,

Glad you brought this up.  What is the difference when the ServiceFeatureTable is created from a dynamic map service (as in the example shown) verses ones from a feature service.  I've seen examples of ServiceFeatureTables created from both types of services, but never quite sure what the differences are.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi Huy,

They're similar operations - both effectively executing a query and returning a featureset from which we create a ServiceFeatureTable. ServiceFeatureTables created from the MapServer/<Layer-ID> endpoint are not editable whereas ServiceFeatureTables created from the FeatureServer/<Layer-ID> endpoint may be editable, depending on the service configuration.

For more info see:

MapServer/Layer Query: ArcGIS REST API

FeatureServer/Layer Query: ArcGIS REST API

Cheers

Mike