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>
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.
What am I missing here?