AnsweredAssumed Answered

Unable to show FeatureLayer using code behind

Question asked by HuyHo on May 5, 2016
Latest reply on May 13, 2016 by MBranscomb-esristaff

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?

Outcomes