/// <summary> /// Determines if the feature action can be executed based on the specified data source and feature, before the option to execute /// the feature action is displayed to the user. /// </summary> /// <param name="dataSource">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <param name="feature">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <returns>True if the feature action should be enabled, otherwise false.</returns> public bool CanExecute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { // Check if the data source and feature can be used with this feature action. // For example, identify if a MapWidget is ultimately providing the data source, and enable the feature action if that // MapWidget also has its Show Popups setting enabled. return true; }
public SearchNearbyFeatureAction(string targetDataSourceId, int bufferDistance, client.Tasks.LinearUnit bufferUnit) { _geometryTask = new client.Tasks.GeometryService( "http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); _geometryTask.BufferCompleted += GeometryTask_BufferCompleted; _geometryTask.Failed += GeometryServiceFailed; TargetDataSourceId = targetDataSourceId; BufferDistance = bufferDistance; BufferUnit = bufferUnit; }
//This method returns all the feature layers displayed on a map public static List<client.FeatureLayer> GetMapFeatureLayers(client.Map Map) { List<client.FeatureLayer> FeatureLayers = new List<client.FeatureLayer>(); //To know more about acceleratedDisplayLayers, read //http://resources.arcgis.com/en/help/runtime-wpf/concepts/index.html#//0170000000n4000000 client.AcceleratedDisplayLayers adLayers = Map.Layers.FirstOrDefault(l => l is client.AcceleratedDisplayLayers) as client.AcceleratedDisplayLayers; foreach (client.FeatureLayer layer in adLayers.ChildLayers.OfType<client.FeatureLayer>()) FeatureLayers.Add(layer); return FeatureLayers; }
/// <summary> /// Determines if the feature action can be executed based on the specified data source and feature, before the option to execute /// the feature action is displayed to the user. /// </summary> /// <param name="dataSource">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <param name="feature">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <returns>True if the feature action should be enabled, otherwise false.</returns> public bool CanExecute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { // Check if the data source and feature can be used with this feature action. bool available = false; foreach (var widget in OperationsDashboard.Instance.Widgets) { if (widget is RangeFanWid) available = true; else available = false; } return available; }
/// <summary> /// Determines if the feature action can be executed based on the specified data source and feature, before the option to execute /// the feature action is displayed to the user. /// </summary> /// <param name="dataSource">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <param name="feature">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <returns>True if the feature action should be enabled, otherwise false.</returns> public bool CanExecute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { //CanExecute = false if the feature's data source is a stand alone data source (i.e. map widget is null) MapWidget mw = MapWidget.FindMapWidget(dataSource); if (mw == null) return false; //CanExecute = false if the input feature's geometry is null if (feature.Geometry == null) return false; //CanExecute = false if the input feature is not a polyline if (feature.Geometry.GetType() != typeof(client.Geometry.Polyline)) return false; return true; }
public DrawPolygonToolbar(MapWidget mapWidget, client.FeatureLayer searchAreaFL) { InitializeComponent(); DataContext = this; #region Initialize the map widget and the search area feature layer MapWidget = mapWidget; if (!mapWidget.Map.IsInitialized) return; SearchAreaLayer = searchAreaFL; SearchAreaLayer.DisableClientCaching = true; #endregion #region MapWidget is not null, initialize the editor tool Editor = new client.Editor() { LayerIDs = new string[] { SearchAreaLayer.ID }, Map = mapWidget.Map, GeometryServiceUrl = @"http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer" }; Editor.EditCompleted += Editor_EditCompleted; Editor.EditorActivated += Editor_EditorActivated; #endregion }
void GeometryServiceFailed(object sender, client.Tasks.TaskFailedEventArgs e) { MessageBox.Show("fail to calculate buffer, error: " + e.Error); }
/// <summary> /// Execute is called when user chooses the feature action from the feature actions context menu. Only called if /// CanExecute returned true. /// </summary> public void Execute(DataSource searchAreaDS, client.Graphic searchArea) { try { //Clear any running task _geometryTask.CancelAsync(); //Get the map widget and the map that contains the polygon used to generate the buffer client.Map mwMap = MapWidget.Map; //Define the params to pass to the buffer operation client.Tasks.BufferParameters bufferParameters = CreateBufferParameters(searchArea, mwMap); //Copy the display field of the search area for later use. //Polygon.Attributes[polygonDataSrc.DisplayFieldName] might be null if for example, //user creates a new polygon without specifying its attributes if (searchArea.Attributes[searchAreaDS.DisplayFieldName] == null) SearchAreaName = ""; else SearchAreaName = searchArea.Attributes[searchAreaDS.DisplayFieldName].ToString(); //Execute the GP tool _geometryTask.BufferAsync(bufferParameters); } catch (Exception) { MessageBox.Show("Error searching for team. Please retry"); } }
private client.Tasks.BufferParameters CreateBufferParameters(client.Graphic feature, client.Map mwMap) { client.Tasks.BufferParameters bufferParameters = new client.Tasks.BufferParameters() { Unit = BufferUnit, BufferSpatialReference = mwMap.SpatialReference, OutSpatialReference = mwMap.SpatialReference, UnionResults = true, }; bufferParameters.Distances.AddRange(new List<double> { BufferDistance }); bufferParameters.Features.AddRange(new List<client.Graphic>() { feature }); return bufferParameters; }
void DrawComplete(object sender, client.DrawEventArgs e) { // Deactivate the draw object for now. if (_drawObject != null) { _drawObject.IsEnabled = false; _drawObject.DrawComplete -= DrawComplete; _mapWidget.Map.KeyDown -= Map_KeyDown; } // Remove the cancelation toolbar _mapWidget.SetToolbar(null); // Get the tracked shape passed in as an argument. client.Geometry.Envelope env = e.Geometry as client.Geometry.Envelope; if (env != null) { _mapWidget.Map.Extent = env; if (isZoomout == false) { // If zoom in, set the Map Extent to be the extent of the drawn geometry. _mapWidget.Map.Extent = env; } else { //Zoom out based on the shorter dimension of the drawm rectangle double shorterRectangleDimension = env.Height > env.Width ? env.Width : env.Height; double selectedMapExtentDimension = shorterRectangleDimension == env.Width ? _mapWidget.Map.Extent.Width : _mapWidget.Map.Extent.Height; _mapWidget.Map.Zoom(shorterRectangleDimension / selectedMapExtentDimension); } } }
/// <summary> /// Helper function which does the actual report generation work /// </summary> private async void GenerateReportAsync(client.Graphic feature, int wkid) { CensusReport.ReportGenerationService.ReportGenerationService service = new CensusReport.ReportGenerationService.ReportGenerationService(); //Generate a census report and retrive the location of the report string reportLocation = await service.GetReportGenerationAsync(feature, BufferRadius, wkid); //Try to open the report in a pdf viewer if (string.IsNullOrEmpty(reportLocation)) MessageBox.Show("Error generating report", "Report Generation", MessageBoxButton.OK, MessageBoxImage.None); else Process.Start(new ProcessStartInfo(reportLocation)); }
public bool addToList(client.Graphic pGraphic) { try { if (_map == null) GetMapFromWidget(); if (_graphics == null) { _graphics = new ESRI.ArcGIS.Client.GraphicsLayer(); _graphics.ID = "RangeFanGraphics"; _map.Layers.Add(_graphics); } string oID = _datasource.ObjectIdFieldName; bool contains = false; foreach (Feature p in _rfFeatures) { if (p.Graphic.Attributes[oID].ToString() == pGraphic.Attributes[oID].ToString()) contains = true; } if (contains == false) { Feature pFeature = new Feature(pGraphic, Field); client.Graphic cFan = CreateFan(pGraphic); if (cFan != null) _graphics.Graphics.Add(cFan); _rfFeatures.Add(pFeature); FeatureListBox.ItemsSource = null; FeatureListBox.ItemsSource = _rfFeatures; } return true; } catch { return false; } }
private client.Graphic CreateFan(client.Graphic g) { try { SimpleFillSymbol _sym = new SimpleFillSymbol() { Fill = new SolidColorBrush(Color.FromArgb(100, (byte)255, (byte)190, (byte)232)), BorderBrush = new SolidColorBrush(Color.FromArgb(100, (byte)197, (byte)0, (byte)255)), BorderThickness = 1 }; client.Graphic pPolyGraphic = new client.Graphic(); if (Traversal < 360) { double initBearing = Bearing; initBearing = Geo2Arithmetic(Bearing); //Need to convert from geographic angles (zero north clockwise) to arithmetic (zero east counterclockwise) if (Traversal == 0) Traversal = 1; double leftAngle = initBearing - (Traversal / 2.0); double rightAngle = initBearing + (Traversal / 2.0); double centerpointX = g.Geometry.Extent.GetCenter().X; double centerpointY = g.Geometry.Extent.GetCenter().Y; ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> pcol = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>(); ESRI.ArcGIS.Client.Geometry.PointCollection ptCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); ptCollection.Add(g.Geometry as MapPoint); for (int i = System.Convert.ToInt16(leftAngle); i < rightAngle; i++) { double x = centerpointX + (Range * Math.Cos(DegreeToRadian(i))); double y = centerpointY + (Range * Math.Sin(DegreeToRadian(i))); ESRI.ArcGIS.Client.Geometry.MapPoint mPt = new MapPoint(x, y); ptCollection.Add(mPt); } ptCollection.Add(g.Geometry as MapPoint); ESRI.ArcGIS.Client.Geometry.Polygon pPoly = new ESRI.ArcGIS.Client.Geometry.Polygon(); pcol.Add(ptCollection); pPoly.Rings = pcol; pPolyGraphic.Geometry = pPoly; pPolyGraphic.Symbol = _sym; pPolyGraphic.Attributes.Add("Name", g.Attributes[_datasource.ObjectIdFieldName].ToString()); System.Diagnostics.Debug.WriteLine(g.Attributes[_datasource.ObjectIdFieldName].ToString()); } else { Circle pCircle = new Circle(); ESRI.ArcGIS.Client.Geometry.MapPoint mPt = new MapPoint(g.Geometry.Extent.GetCenter().X, g.Geometry.Extent.GetCenter().Y); pCircle.Center = mPt; pCircle.Radius = Range; pPolyGraphic.Symbol = _sym; pPolyGraphic.Geometry = pCircle; pPolyGraphic.Attributes.Add("Name", g.Attributes[_datasource.ObjectIdFieldName].ToString()); } return pPolyGraphic; } catch { return null; } }
/// <summary> /// Get the spatial query result (the buffer polygon) then use the polygon to search for the /// team features that intersect with it. /// Finally, show the team assignment page and select the teams nearby /// </summary> async void GeometryTask_BufferCompleted(object sender, client.Tasks.GraphicsEventArgs e) { if (e.Results != null) { //There will be only one result client.Graphic buffer = e.Results[0]; //Then query for the team features that intersect with the buffer polygon await QueryForFeatures(buffer.Geometry); #region Confirm team assignment and send SMS to the teams. //If the team data source doesn't have the phone number or the carrier field, we won't allowing sending SMS bool smsEnabled = (TeamDataSrc.Fields.Count(f => f.FieldName == "PhoneNumber" || f.FieldName == "Carrier") == 2) ? true : false; TeamAssignmentPage smsPage = new TeamAssignmentPage(SearchAreaName, TeamFeatureLayer, TeamsNearby, smsEnabled); smsPage.Show(); #endregion } }
public async Task QueryForFeatures(client.Geometry.Geometry buffer) { //Reset the list of TeamsNearby before re-populating them later in the method TeamsNearby.Clear(); //Set up the query and query result Query query = new Query("", buffer, true); if (TeamDataSrc != null) { //Run the query and check the result QueryResult result = await TeamDataSrc.ExecuteQueryAsync(query); if ((result == null) || (result.Canceled) || (result.Features == null)) return; // Get the array of Oids from the query results. var resultOids = from resultFeature in result.Features select System.Convert.ToInt32(resultFeature.Attributes[TeamDataSrc.ObjectIdFieldName]); // For each graphic feature in featureLayer, use its OID to find the graphic feature from the result set. // Note that though the featureLayer's graphic feature and the result set's feature graphic feature share the same properties, // they are indeed different objects foreach (client.Graphic team in TeamFeatureLayer.Graphics) { int featureOid; int.TryParse(team.Attributes[TeamDataSrc.ObjectIdFieldName].ToString(), out featureOid); //If feature has been selected in previous session, unselect it if (team.Selected) team.UnSelect(); //If the feature is in the query result set, select it //Also add them to the TeamsNearby list so we can send SMS later if ((resultOids.Contains(featureOid))) { team.Select(); TeamsNearby.Add(team); } } } }
/// <summary> /// Define the radius where teams will be searched. We hardcoded it to 1 mile for this sample /// </summary> private client.Tasks.BufferParameters CreateBufferParameters(client.Graphic polygon, client.Map mwMap) { client.Tasks.BufferParameters bufferParameters = new client.Tasks.BufferParameters() { Unit = client.Tasks.LinearUnit.SurveyMile, BufferSpatialReference = mwMap.SpatialReference, OutSpatialReference = mwMap.SpatialReference, UnionResults = true, }; bufferParameters.Distances.AddRange(new List<double> { 0.5 }); bufferParameters.Features.AddRange(new List<client.Graphic>() { polygon }); return bufferParameters; }
/// <summary> /// Execute is called when the user chooses the feature action from the feature actions context menu. Only called if /// CanExecute returned true. /// </summary> public void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { try { // For example, in the MapWidget that ultimately provides the data source, show the popup window for the feature. MapWidget mw = MapWidget.FindMapWidget(dataSource); foreach (var widget in OperationsDashboard.Instance.Widgets) if (widget is RangeFanWid) { RangeFanWid pWidget = (RangeFanWid)widget; pWidget.addToList(feature); return; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
/// <summary> /// Determines if the feature action can be executed based on the specified data source and feature, before the option to execute /// the feature action is displayed to the user. /// </summary> /// <param name="searchAreaDS">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <param name="searchArea">The data which will be subsequently passed to the Execute method if CanExecute returns true.</param> /// <returns>True if the feature action should be enabled, otherwise false.</returns> public bool CanExecute(DataSource searchAreaDS, client.Graphic searchArea) { //Map widget that contains the searchArea data Source MapWidget areaMW; //Map widget that contains the rescueTeam data Source MapWidget teamMW; try { #region Check if the polygon data source is valid //Check if the searchAreaDS has a display name field if (searchAreaDS.DisplayFieldName == null) return false; //Check if the map widget associated with the search area dataSource is valid if ((areaMW = MapWidget.FindMapWidget(searchAreaDS)) == null) return false; //Check if the search area layer is polygon if (areaMW.FindFeatureLayer(searchAreaDS).LayerInfo.GeometryType != client.Tasks.GeometryType.Polygon) return false; #endregion #region Find the rescue team data source and check if it is consumed by the same mapWidget as the polygon data source //Find all the data sources that can possibly be a taem data sources //(i.e. are associated with point layers and hase the field "SearchAreaName") var teamDataSrcs = OperationsDashboard.Instance.DataSources.Where(ds => IsValidTeamDataSource(ds)); if (teamDataSrcs == null || teamDataSrcs.Count() == 0) return false; //For each of the data source retrieved, get its associated mapWidget //Check if the polygon feature source is also consumed by the same map widget (i.e. teamMW) foreach (DataSource teamDataSrc in teamDataSrcs) { if ((teamMW = MapWidget.FindMapWidget(teamDataSrc)) == null) return false; if (teamMW.Id == areaMW.Id) { MapWidget = areaMW; TeamDataSrc = teamDataSrc; TeamFeatureLayer = MapWidget.FindFeatureLayer(TeamDataSrc); return true; } } #endregion return false; } catch (Exception) { return false; } }
/// <summary> /// This function determines if the feature action will be enabled or disabled /// In order for the FeatureAction to execute: /// - The map widget that contains the dataSource from which the buffer area is generated must not be null /// - The Target DataSource that will be queried must not be null /// - The radius (Distance) of the buffer area must be >0 /// </summary> /// <param name="BufferDS">BufferDS is the data source containing the BufferFeature</param> /// <param name="BufferFeature">BufferFeature is the feature used to generate the buffer area</param> public bool CanExecute(ESRI.ArcGIS.OperationsDashboard.DataSource BufferDS, client.Graphic BufferFeature) { return (MapWidget.FindMapWidget(BufferDS) != null && TargetDataSourceId != null && BufferDistance > 0); }
/// <summary> /// Mouse handler that sets the coordinates of the clicked point into text in the toolbar. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Map_MouseClick(object sender, client.Map.MouseEventArgs e) { try { client.Geometry.MapPoint clickPoint = e.MapPoint; WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); client.Geometry.MapPoint pt = null; pt = mercator.ToGeographic(clickPoint) as client.Geometry.MapPoint; if (_graphicsLayer == null) { _graphicsLayer = new client.GraphicsLayer(); _graphicsLayer.ID = "ComputedPoints"; client.AcceleratedDisplayLayers aclyrs = _mapWidget.Map.Layers.FirstOrDefault(lyr => lyr is client.AcceleratedDisplayLayers) as client.AcceleratedDisplayLayers; if (aclyrs.Count() > 0) aclyrs.ChildLayers.Add(_graphicsLayer); } ResourceDictionary mydictionary = new ResourceDictionary(); mydictionary.Source = new Uri("/AirCraftRouteGenerationLineAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); client.Graphic graphic = new client.Graphic(); graphic.Geometry = pt; graphic.Symbol = mydictionary["RedPin"] as client.Symbols.MarkerSymbol; _graphicsLayer.Graphics.Add(graphic); RunButton.IsEnabled = true; } catch (Exception ex) { MessageBox.Show("Error in map mouseclick: " + ex.Message); } }
/// <summary> /// Execute is called when the user chooses the feature action from the feature actions context menu. Only called if /// CanExecute returned true. /// </summary> public async void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { //This feature action relies on a profile graph widget to create a graph based on the profile line //Check if the view has a ProfileGraphWidget widget to display the output graph ProfileGraphFromMap profileWidget = OperationsDashboard.Instance.Widgets.FirstOrDefault(w => w.GetType() == typeof(ProfileGraphFromMap)) as ProfileGraphFromMap; if (profileWidget == null) { MessageBox.Show("Add the Profile Graph Widget to the view to execute this feature action", "Profile Graph Widget Required"); return; } //Send the feature to the Elevation Analysis service to get the profile line ProfileService service = new ProfileService(); Profile = await service.GetProfileLine(feature.Geometry); if (Profile == null) { MessageBox.Show("Failed to get elevation profile"); return; } //Send the result (Profile) to the profile graph widget and ask it to generate the graph profileWidget.MapWidget = MapWidget.FindMapWidget(dataSource); profileWidget.Profile = Profile; profileWidget.UpdateControls(); }
// *********************************************************************************** // * Add an incident location on the map... closest facility will be found for this location // *********************************************************************************** void Map_MouseClick(object sender, client.Map.MouseEventArgs e) { client.Geometry.MapPoint clickPoint = e.MapPoint; if (clickPoint != null) { client.Graphic tempGraphic = new client.Graphic() { Geometry = clickPoint, Symbol = new client.Symbols.SimpleMarkerSymbol() { Color = System.Windows.Media.Brushes.Red, Size = 12, Style = client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle } }; _incidentsGraphicsLayer.Graphics.Add(tempGraphic); } }
public void removefromList(client.Graphic pGraphic) { try { string oid = pGraphic.Attributes[_datasource.ObjectIdFieldName].ToString(); System.Diagnostics.Debug.WriteLine("Removing OID: " + oid); foreach (Feature f in _rfFeatures) { if (f.Graphic.Attributes[_datasource.ObjectIdFieldName].ToString() == oid) { _rfFeatures.Remove(f); break; } } int idx = 0; for (int g = 0; g < _graphics.Graphics.Count; g++) { if (_graphics.Graphics[g].Attributes["Name"].ToString() == oid) { idx = g; } } _graphics.Graphics.RemoveAt(idx); FeatureListBox.ItemsSource = _rfFeatures; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
// *********************************************************************************** // * User finished drawing a polyline on the map. Add the polyline // * barriers GraphicsLayer. // *********************************************************************************** void DrawComplete(object sender, client.DrawEventArgs e) { // Deactivate the draw object for now. if (_drawObject != null) { _drawObject.IsEnabled = false; _drawObject.DrawComplete -= DrawComplete; } client.Geometry.Polyline barrierGeometry = e.Geometry as client.Geometry.Polyline; client.Graphic barrierGraphic = new client.Graphic() { Symbol = _polylineBarrierSymbol, //(LineSymbol)this.FindResource("routeSymbol") Geometry = barrierGeometry }; _polylineBarriersGraphicLayer.Graphics.Add(barrierGraphic); }
public Feature(client.Graphic feature, string field) { Graphic = feature; _field = field; }
/// <summary> /// This function creates the buffer area from user's selected feature /// </summary> /// <param name="BufferDS">BufferDS is the data source containing the BufferFeature</param> /// <param name="BufferFeature">BufferFeature is the feature used to generate the buffer area</param> public void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource BufferDS, client.Graphic BufferFeature) { //Clear any running task _geometryTask.CancelAsync(); //Get the map widget and the map that contains the feature used to generate the buffer MapWidget mw = MapWidget.FindMapWidget(BufferDS); client.Map mwMap = mw.Map; //Define the params to pass to the buffer operation client.Tasks.BufferParameters bufferParameters = CreateBufferParameters(BufferFeature, mwMap); //Execute the GP tool _geometryTask.BufferAsync(bufferParameters); }
/// <summary> /// Execute is called when the user chooses the feature action from the feature actions context menu. Only called if /// CanExecute returned true. /// </summary> public void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { int wkid = MapWidget.FindMapWidget(dataSource).Map.SpatialReference.WKID; GenerateReportAsync(feature, wkid); }
async void GeometryTask_BufferCompleted(object sender, client.Tasks.GraphicsEventArgs e) { //check the result (the buffer polygon) //then pass to the query operation if (e.Results != null) { //There will be only one result client.Graphic buffer = e.Results[0]; //Then query for the features that intersect with the polygon await QueryForFeatures(buffer.Geometry); } }
/// <summary> /// Determines if the feature action can be executed based on: /// whether the data source is the one specified in the config window. If not, check if the data source is the selection data source of the one specified; /// whether the data source is broken; /// whether the feature's geometry is not null; /// whether the feature is a point feature /// </summary> public bool CanExecute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { #region If there's a previously set DataSourceId, we try to use it if (!string.IsNullOrEmpty(DataSourceId)) SelectedDataSource = OperationsDashboard.Instance.DataSources.FirstOrDefault(ds => ds.Id == DataSourceId); if (SelectedDataSource == null) return false; #endregion //Check if the data source picked by user is the one specified in the config window if (dataSource.Id != SelectedDataSource.Id) { //If not, check if the data source picked by user is the selection data source of the one specified in the config window if (SelectedDataSource.Name == string.Format("{0} Selection", dataSource.Name) && SelectedDataSource.IsSelectable) return true; else return false; } //Check if the data source is broken if (dataSource.IsBroken) return false; //Check if the feature's geometry is null if (feature == null || feature.Geometry == null || string.IsNullOrEmpty(feature.Geometry.ToJson())) return false; //Check if the feature is a point feature if (feature.Geometry.GetType() != typeof(client.Geometry.MapPoint)) return false; return true; }
public async Task QueryForFeatures(client.Geometry.Geometry bufferPolygon) { //Set up the query and query result Query query = new Query("", bufferPolygon, true); DataSource ds = OperationsDashboard.Instance.DataSources.Where(d => d.Id == TargetDataSourceId).FirstOrDefault(); if (ds != null) { //Run the query and check the result QueryResult result = await ds.ExecuteQueryAsync(query); if ((result == null) || (result.Canceled) || (result.Features == null) || (result.Features.Count < 1)) return; // Get the array of OIDs from the query results. var resultOids = from resultFeature in result.Features select System.Convert.ToInt32(resultFeature.Attributes[ds.ObjectIdFieldName]); // Find the map layer in the map widget that contains the target data source. MapWidget mapW = MapWidget.FindMapWidget(ds); if (mapW != null) { // Get the feature layer in the map for the data source. client.FeatureLayer featureLayer = mapW.FindFeatureLayer(ds); // For each graphic feature in featureLayer, use its OID to find the graphic feature from the result set. // Note that though the featureLayer's graphic feature and the result set's feature graphic feature share the same properties, // they are indeed different objects foreach (client.Graphic feature in featureLayer.Graphics) { int featureOid; int.TryParse(feature.Attributes[ds.ObjectIdFieldName].ToString(), out featureOid); //If feature has been selected in previous session, unselect it if (feature.Selected) feature.UnSelect(); //If the feature is in the query result set, select it if ((resultOids.Contains(featureOid))) feature.Select(); } } } }