====== Source Code WpfEditionSample ArcGISServerLayer CS 160908.zip ======
====App.xaml.cs====
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace Wpf_ArcGISServerRestLayer
{
///
/// Interaction logic for App.xaml
///
public partial class App : Application
{
}
}
====MainWindow.xaml.cs====
using System;
using System.Windows;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WpfDesktopEdition;
namespace Wpf_ArcGISServerRestLayer
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
// Uses the WorldMapKit as the background layer.
WorldMapKitLayer worldMapKitLayer = new WorldMapKitLayer();
worldMapKitLayer.Projection = WorldMapKitProjection.DecimalDegrees;
// Creates a new ArcGISServerRestLayer. This will be used to show counties based on population.
// documentation for ArcGIS Server REST API can be found at: http://resources.arcgis.com/en/help/arcgis-rest-api/ , V 9.3 : http://resources.esri.com/help/9.3/arcgisserver/apis/rest/index-9-3.html
ArcGISServerRestLayer arcGisLayer = new ArcGISServerRestLayer();
// Specifies the uri of the web service.
arcGisLayer.ServerUri = new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export");
// Sets our parameters for image format.
arcGisLayer.Parameters.Add("format", "png");
//arcGisLayer.ImageFormat = ArcGISServerRestLayerImageFormat.Png; // we can use the property 'ImageFormat' instead of the 'format' in parameters. When they coexist, the property is perferred.
// Sets our parameters for transparency.
arcGisLayer.Parameters.Add("transparent", "true");
// Specifies the layerId(s) you wish to display. LayerId 2 is the county layer.
arcGisLayer.Parameters.Add("layers", "show:2");
// Specifies the layer and field you wish to query(layerid: field). in this example, the layerid is 2 and the data field to query is POP1999.
arcGisLayer.Parameters.Add("layerdefs", string.Format("2:POP1999{0}", txtPopulationFilter.Text));
LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.Layers.Add(worldMapKitLayer);
layerOverlay.Layers.Add("ArcGISServerRestLayer", arcGisLayer);
wpfMap1.Overlays.Add("LayerOverlay", layerOverlay);
wpfMap1.CurrentExtent = new RectangleShape(-140, 60, -58, 30);
wpfMap1.Refresh();
}
private void btnSubmitQuery_Click(object sender, RoutedEventArgs e)
{
// Gets our ArcGIS Layer and update the layerdefs parameter.
var layerOverlay = (LayerOverlay)wpfMap1.Overlays["LayerOverlay"];
var arcGISLayer = (ArcGISServerRestLayer)layerOverlay.Layers["ArcGISServerRestLayer"];
arcGISLayer.Parameters["layerdefs"] = string.Format("2:POP1999{0}", txtPopulationFilter.Text);
wpfMap1.Refresh();
}
}
}