Skip to content

Instantly share code, notes, and snippets.

@nommuna2
Last active April 26, 2019 22:03
Show Gist options
  • Save nommuna2/ce62d3966513932e5333bd30b1f246f8 to your computer and use it in GitHub Desktop.
Save nommuna2/ce62d3966513932e5333bd30b1f246f8 to your computer and use it in GitHub Desktop.
(ArcGIS Runtime SDK for .NET) Sample of adding layer to the map and doing a query
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
//Wait for the map view to load
MyMapView.Loaded += async (sender, e) => {
//Create a new map with the basemap
var map = new Map(Basemap.CreateDarkGrayCanvasVector());
//Set the mapview.map to the newly created map
MyMapView.Map = map;
//Call the operational layers.add to add new feature layer to the map
MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2")));
//Create a new sfs for the layer
var sfs = new SimpleFillSymbol(SimpleFillSymbolStyle.DiagonalCross, Colors.Azure, new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Brown, 5));
//Create a renderer
var renderer = new SimpleRenderer(sfs);
//Set the renderer to the feature layer and then add it to the map.
(MyMapView.Map.OperationalLayers.First() as FeatureLayer).Renderer = renderer;
//Set up a ServiceFeatureTable to do Query's on
var flQuery = new ServiceFeatureTable(new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"));
// Print out to the console the feature count. Needs to have an await since it is an Async method
var result = await flQuery.QueryFeatureCountAsync(new QueryParameters() { WhereClause = "1=1", ReturnGeometry = true}); // How would I print the result of this?
Console.WriteLine(result.ToString());
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment