Hi,Here's a QueryTask sample: http://resources.arcgis.com/en/help/runtime-wpf/samples/index.html#/Spatial_Query_Online/02q2000000m.... It sounds like you're using the DynamicLayers capability to add Shapefiles - if this is the case you'll need to set the Source property on the Query object (http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli...).Also - you mentioned that the Shapefiles are added in different colours each time? - you can set the renderer on the layer so the colour is up to you... at the current release unfortunately you'll need to make a manual request to get the geometry type, but for the next release we've extended the GetAllDetails method to support DynnamicLayers.e.g.
/*
* Apply a renderer for vector layers.
* Note: It is always necessary to provide a renderer when the layer being added (represented by a DynamicLayerInfo) is part of a new
* DynamicLayerInfoCollection as opposed to using the CreateDynamicLayerInfosFromLayerInfos() method which creates a DynamicLayerInfoCollection
* containing the existing layers in the map service.
*/
// Create a new LayerDrawingOptions object to hold the renderer information.
var layerDrawOpt = new LayerDrawingOptions()
{
// Match up the LayerID to the ID of the layer within the service.
LayerID = counter,
};
// We need to determine the geometry type of the new feature class.
// To do this, we will submit a request to the ..\MapServer\dynamicLayer?.. endpoint which will return the service level metadata,
// Allowing us to identify the geometry type and create an appropriate renderer.
// Create a new WebClient instance to make the request and download the response.
WebClient webClient = new WebClient();
// Register an asynchronous handler in which to create the renderers and apply the to the dynamic map service layer.
webClient.DownloadDataCompleted += (client, downloadDataEventArgs) =>
{
// Read the JSON response as XML
XmlReader reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader(downloadDataEventArgs.Result, new XmlDictionaryReaderQuotas());
// Get the root XML element
XElement root = XElement.Load(reader);
// Query for the "geometryType" element
XElement geometryType = root.XPathSelectElement("//geometryType");
// Create the render based on the geometry type
switch (geometryType.Value)
{
case "esriGeometryPoint":
layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { Color = new SolidColorBrush(GetRandomColor()), Size=8 } };
break;
case "esriGeometryPolyline":
layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleLineSymbol() { Color = new SolidColorBrush(GetRandomColor()) } };
break;
case "esriGeometryPolygon":
layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(GetRandomColor()), BorderBrush = new SolidColorBrush(GetRandomColor()) } };
break;
}
// Set the LayerDrawingOptions property on the local dynamic map service layer (the LayerID property ties this to the DynamicLayerInfo object).
layerDrawingOptionsCollection.Add(layerDrawOpt);
// Update the layer drawing options property on the dynamic map service layer.
arcGisLocalDynamicMapServiceLayer.LayerDrawingOptions = layerDrawingOptionsCollection;
// Need to refresh the layer after the renderer(s) have been applied.
arcGisLocalDynamicMapServiceLayer.Refresh();
};
// Make the request for the service metadata
// e.g. http://127.0.0.1:<PORT>/arcgis/rest/services/<MPK_NAME>/MapServer/dynamicLayer?layer={"id":0,"source":{"type":"dataLayer","dataSource":{"type":"table","workspaceId":"MyWorkspace","dataSourceName":"MyFeatureClassName"}}}
webClient.DownloadDataAsync(new Uri(arcGisLocalDynamicMapServiceLayer.Url
+ "/dynamicLayer?layer={'id':" + counter.ToString() + ","
+ "'source':{'type':'dataLayer','dataSource':{"
+ "'type':'table',"
+ "'workspaceId':'"+ workspaceInfo.Id + "',"
+ "'dataSourceName':'" + fileName + "'"
+ "}}}"));
CheersMike