public static async Task <GraphicsLayer> CreateCustomLayer(FeatureLayer featureLayer, OD.DataSource dataSource) { if (featureLayer == null || dataSource == null) { return(null); } GraphicsLayer customLayer = new GraphicsLayer(); customLayer.DisplayName = "Edit - " + featureLayer.DisplayName; customLayer.Renderer = featureLayer.Renderer; // Execute an async query OD.Query query = new OD.Query(); query.ReturnGeometry = true; OD.QueryResult queryResult = await dataSource.ExecuteQueryAsync(query); if (queryResult.Canceled || queryResult.Features == null) { return(null); } CopyGraphics(queryResult.Features, customLayer.Graphics); return(customLayer); }
// *********************************************************************************** // * Query for the facilities is completed... populate facility type combobox // *********************************************************************************** void queryBufferLayer_ExecuteCompleted(ESRI.ArcGIS.OperationsDashboard.QueryResult result) { BufferTypes.Clear(); //set up facilities type dropdown BufferType resourceType = new BufferType(); resourceType.Name = "Select Type"; BufferTypes.Add(resourceType); if (result != null && result.Features.Count > 0) { foreach (client.Graphic graphic in result.Features) { if (graphic.Attributes[_bufferField] != null) { //string type = graphic.Attributes["MRPTYPE"].ToString(); string type = graphic.Attributes[_bufferField].ToString(); resourceType = new BufferType(); resourceType.Name = type; var resourceItem = BufferTypes.FirstOrDefault(item => item.Name == resourceType.Name); if (resourceItem == null) // none is found. { BufferTypes.Add(resourceType); } } } } else { System.Windows.MessageBox.Show("No features returned from query"); } }
async void Map_ExtentChanged(object sender, ExtentEventArgs e) { try { if (callQuery) { //Select features using polygon IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { //if (d.IsSelectable) // { System.Diagnostics.Debug.WriteLine(d.Name); ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query(); query.SpatialFilter = outdoorPoly; query.ReturnGeometry = true; query.Fields = new string[] { d.ObjectIdFieldName }; ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query); //System.Diagnostics.Debug.WriteLine("Features : " + result.Features.Count); if (result.Features.Count > 0) { // Get the array of IDs from the query results. var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]); // Find the map layer in the map widget that contains the data source. MapWidget mapW = MapWidget.FindMapWidget(d); if (mapW != null) { // Get the feature layer in the map for the data source. client.FeatureLayer featureL = mapW.FindFeatureLayer(d); // NOTE: Can check here if the feature layer is selectable, using code shown above. // For each result feature, find the corresponding graphic in the map by OID and select it. foreach (client.Graphic feature in featureL.Graphics) { int featureOid; int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid); if (resultOids.Contains(featureOid)) { feature.Select(); } } } } } } callQuery = false; } catch (Exception ex) { MessageBox.Show("Error in MapExent Changed: " + ex.Message); } }
async public void Update(OD.DataSource dataSource) { if (dataSource == null) { return; } if (SkipUpdates) { return; } if (InEditMode) { return; } // Execute an async query OD.Query query = new OD.Query() { SortField = SortByFieldName1, SortOrder = ESRI.ArcGIS.Client.Tasks.SortOrder.Ascending, ReturnGeometry = true }; OD.QueryResult queryResult = await dataSource.ExecuteQueryAsync(query); if (queryResult.Canceled || queryResult.Features == null) { Items.Clear(); return; } //hk - RESEARCH THIS APPROACH /* * List<ListItem> items = new List<ListItem>(); * int i = 0; * foreach (var result in queryResult.Features) * { * items.Add(new ListItem(this, result, dataSource)); * if (++i == ListWidget.MaxCount) * break; * } */ try { SetDataSource(dataSource); Update(queryResult.Features); } catch (Exception ex) { Log.TraceException("Updating " + dataSource.Name, ex); } }
// *********************************************************************************** // * ... Select facilities that intersect the affeced area on the map // *********************************************************************************** private async void selectFeaturesOnTheMap(ESRI.ArcGIS.Client.Geometry.Polygon geometry) { // Find the Selectable data sources provided by feature layers in the map widget. var dataSourcesFromSameWidget = OperationsDashboard.Instance.DataSources.Select((dataSource) => { client.FeatureLayer fl = _mapWidget.FindFeatureLayer(dataSource); return(((fl != null) && (dataSource.IsSelectable)) ? fl : null); }); IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); if (dataSourcesFromSameWidget.Contains(featureL)) { ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query(); query.SpatialFilter = geometry; query.ReturnGeometry = true; query.Fields = new string[] { d.ObjectIdFieldName }; ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query); if (result.Features.Count > 0) { // Get the array of IDs from the query results. var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]); // For each result feature, find the corresponding graphic in the map. foreach (client.Graphic feature in featureL.Graphics) { int featureOid; int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid); if (resultOids.Contains(featureOid)) { feature.Select(); } } } else if (d.IsSelectable == true) { featureL.ClearSelection(); } } } }
// *********************************************************************************** // * Query for the facilities is completed... populate facility type combobox // *********************************************************************************** //void queryBarrierType_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) void queryBarrierType_ExecuteCompleted(ESRI.ArcGIS.OperationsDashboard.QueryResult result) { _pointBarriersGraphicsLayer.Graphics.Clear(); if (result.Features != null && result.Features.Count > 0) { foreach (Graphic graphic in result.Features) { if (graphic.Geometry.GetType() == typeof(client.Geometry.MapPoint)) { _pointBarriersGraphicsLayer.Graphics.Add(graphic); graphic.Symbol = _incidentMarkerSymbol; //(PictureMarkerSymbol)this.FindResource("roadBlockSymbol"); ; } } } else { System.Windows.MessageBox.Show("No features returned from query"); } }
// *********************************************************************************** // * Query for the facilities is completed... populate facility type combobox // *********************************************************************************** void queryResourceType_ExecuteCompleted(ESRI.ArcGIS.OperationsDashboard.QueryResult result) { _facilitiesGraphicsLayer.Graphics.Clear(); if (result.Features != null && result.Features.Count > 0) { foreach (Graphic graphic in result.Features) { SimpleMarkerSymbol sms = new SimpleMarkerSymbol() { Size = 16, Style = SimpleMarkerSymbol.SimpleMarkerStyle.Diamond, }; graphic.Symbol = sms; _facilitiesGraphicsLayer.Graphics.Add(graphic); } } else { System.Windows.MessageBox.Show("No features returned from query"); } }
//Calculate a single statistic private async void CalculateOneStatistic(Statistic statistic) { //Construct the query opsDash.Query query = new opsDash.Query() { ReturnGeometry = false, WhereClause = "1=1", Fields = new string[] { Field } }; //If map widget is valid and UseCurrentExtent = true, we will set the current extent into the query if (MapWidget == null) { query.SpatialFilter = null; } else { if (UseCurrentExtent == false) { query.SpatialFilter = null; } else { query.SpatialFilter = MapWidget.Map.Extent; } } //Create a query task, pass in the query and the type of statistic then start the task List <Task <opsDash.QueryResult> > queryTasks = new List <Task <opsDash.QueryResult> >(); opsDash.QueryResult queryResult = await DataSource.ExecuteQueryStatisticAsync(statistic, query); //Query results are back. Check the results if (queryResult.Canceled) { return; } //There should only be one feature carrying the requested value if (queryResult.Features == null || queryResult.Features.Count != 1) { return; } //The feature should not be null and should have the field with the correct field name client.Graphic feature = queryResult.Features[0]; //When we pan outside of the map extent and do the calculation, feature.Attributes[Field] will be null //Resetting all values to 0 if (feature == null || feature.Attributes[Field] == null) { Max = Min = Avg = Sum = 0; } else { //Try to set the field into a double field double value = 0; Double.TryParse(feature.Attributes[Field].ToString(), out value); //Based on the requested, set the value to the output statsitic if (statistic == Statistic.Max) { Max = value; } else if (statistic == Statistic.Average) { Avg = value; } else if (statistic == Statistic.Min) { Min = value; } else if (statistic == Statistic.Sum) { Sum = value; } } //Update StatisticsLists, which in turn will trigger the UI to update UpdateControls(); }