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 }
public TeamAssignmentPage(string searchAreaName, client.FeatureLayer teamFeatureLayer, List <client.Graphic> teamsNearby, bool smsEnabled) { InitializeComponent(); DataContext = this; #region Initialize the default values for team assignment page this.teamFeatureLayer = teamFeatureLayer; this.recommendedTeams = teamsNearby; this.searchAreaName = searchAreaName; SMSEnabled = smsEnabled; SendSMS = true; nameAttribute = teamFeatureLayer.LayerInfo.DisplayField; #endregion #region Populate the team checkboxes CheckListItems = new ObservableCollection <MyCheckedListItem>(); PopulateTeamsComboboxes(); #endregion #region Construct the default message body if (!SMSEnabled) { MessageBody = "<Teams do not contain phone information>"; } else { foreach (client.Graphic team in teamsNearby) { MessageBody += team.Attributes[nameAttribute].ToString() + ", "; } MessageBody += " please search in: " + searchAreaName; } #endregion }
/// <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 { if (_mapWidget != null) { _mapWidget.Map.MouseClick -= Map_MouseClick; } // Find the map layer in the map widget that contains the data source. IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { if (_mapWidget != null && d.IsSelectable == true) { // Get the feature layer in the map for the data source. client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); //Clear Selection on Feature Layers in map featureL.ClearSelection(); } } location = e.MapPoint; if (_graphicsLayer == null) { _graphicsLayer = new ESRI.ArcGIS.Client.GraphicsLayer(); _graphicsLayer.ID = "BombThreatGraphics"; client.AcceleratedDisplayLayers aclyrs = _mapWidget.Map.Layers.FirstOrDefault(lyr => lyr is client.AcceleratedDisplayLayers) as client.AcceleratedDisplayLayers; if (aclyrs.Count() > 0) { aclyrs.ChildLayers.Add(_graphicsLayer); } } _graphicsLayer.ClearGraphics(); Graphic graphic = new ESRI.ArcGIS.Client.Graphic(); graphic.Geometry = location; graphic.Attributes.Add("Evac", bombType.Text); ResourceDictionary mydictionary = new ResourceDictionary(); mydictionary.Source = new Uri("/BombThreatAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); graphic.Symbol = mydictionary["DefaultClickSymbol"] as client.Symbols.MarkerSymbol; _graphicsLayer.MapTip = new ContentControl() { ContentTemplate = (DataTemplate)Resources["kymaptip"] }; _graphicsLayer.MapTip.SetBinding(ContentControl.ContentProperty, new Binding()); graphic.SetZIndex(1); _graphicsLayer.Graphics.Add(graphic); if (location != null) { RunButton.IsEnabled = true; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error in mouseclick: " + ex.Message); } }
} // public string getFieldAlias(string fieldname) /// <summary> /// create Layer according to its Type /// </summary> /// <param name="id"></param> /// <param name="vis"></param> /// <returns></returns> private Layer createLayer(string id, bool vis) { string typ = lyrType; ESRI.ArcGIS.Client.Layer res = null; if (typ == "ArcGISTiledMapServiceLayer") { var lr = new ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer(); lr.Url = lyrUrl; lr.ProxyURL = proxy; res = lr; } else if (typ == "OpenStreetMapLayer") { var lr = new ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer(); res = lr; } else if (typ == "ArcGISDynamicMapServiceLayer") { var lr = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer(); lr.Url = lyrUrl; lr.ProxyURL = proxy; res = lr; } else if (typ == "FeatureLayer") { var lr = new ESRI.ArcGIS.Client.FeatureLayer(); lr.Url = lyrUrl; lr.ProxyUrl = proxy; res = lr; } else if (typ == "GraphicsLayer") { var gl = setContent(id, lyrUrl); res = gl; } if (res != null) { ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsPopupEnabled(res, popupOn); // sublayers popups on/off if (identifyLayerIds.Length <= 3) { ; } else { var xmlszn = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.ObjectModel.Collection <int>)); var sr = new StringReader(identifyLayerIds); var ids = xmlszn.Deserialize(sr) as System.Collections.ObjectModel.Collection <int>; ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIdentifyLayerIds(res, ids); } } return(res); } // private Layer createLayer(string id, bool vis)
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); } }
private void btnOK_Click_1(object sender, RoutedEventArgs e) { PolygonLayer = cmbLayers.SelectedItem as client.FeatureLayer; if (PolygonLayer != null) DialogResult = true; else DialogResult = false; this.Close(); }
/// <summary> /// OnActivated is called when the map tool is added to the toolbar of the map widget in which it is configured to appear. /// Called when the operational view is opened, and also after a custom toolbar is reverted to the configured toolbar, /// and during toolbar configuration. /// </summary> public void OnActivated() { //Retrieve the previously selected search area layer (i.e. when SearchAreaLayerID is not null or empty) //If the search area layer has never been set then pick the first polygon layer if (!string.IsNullOrEmpty(SearchAreaLayerID)) { searchAreaLayer = MapFeatureLayersFinder.GetMapFeatureLayers(MapWidget.Map).FirstOrDefault(layer => layer.ID == SearchAreaLayerID); } else { searchAreaLayer = MapFeatureLayersFinder.GetMapFeatureLayers(MapWidget.Map).FirstOrDefault(layer => layer.LayerInfo.GeometryType == client.Tasks.GeometryType.Polygon); } }
/// <summary> /// Allow users to specify the search area layer, or use the first polygon layer as default /// </summary> public bool Configure(System.Windows.Window owner) { DrawPolygonMapToolDialog configDialog = new DrawPolygonMapToolDialog(MapWidget); if (configDialog.ShowDialog() == false) { MessageBox.Show("Error selecting search area layer"); return(false); } searchAreaLayer = configDialog.PolygonLayer; SearchAreaLayerID = searchAreaLayer.ID; return(true); }
private void btnOK_Click_1(object sender, RoutedEventArgs e) { PolygonLayer = cmbLayers.SelectedItem as client.FeatureLayer; if (PolygonLayer != null) { DialogResult = true; } else { DialogResult = false; } this.Close(); }
// *********************************************************************************** // * ... 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(); } } } }
// *********************************************************************************** // * ...Clear the graphicslayers and charts // *********************************************************************************** private void clearMapToolParameters() { //clear the graphicsLayer _spillLocationGraphicsLayer.Graphics.Clear(); _ergZoneGraphicsLayer.Graphics.Clear(); _facilitiesGraphicsLayer.Graphics.Clear(); //Select features using polygon IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); featureL.ClearSelection(); } }
// *********************************************************************************** // * ...Set the map mouseclick event so that user can enter the incident // *********************************************************************************** private void btnSolve_Click(object sender, RoutedEventArgs e) { // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering _bufferParams = new BufferParameters(); _bufferParams.Unit = currentLinearUnit(); _bufferParams.BufferSpatialReference = new SpatialReference(4326); _bufferParams.OutSpatialReference = _mapWidget.Map.SpatialReference; _bufferParams.Features.Clear(); if (_selectedRadioButtonName == "rbDrawPoints" || _selectedRadioButtonName == "rbSelectedFeaturesFromLayer") { _bufferParams.Features.AddRange(_bufferPointLayer.Graphics); } else if (_selectedRadioButtonName == "rbSelectedFeaturesOnMap") { _bufferPointLayer.ClearGraphics(); IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); if (featureL.SelectionCount > 0) { _bufferParams.Features.AddRange(featureL.SelectedGraphics); } } } if (_bufferParams.Features.Count == 0) { MessageBox.Show("Please select features on the map first", "Error"); return; } var bufferDistance = Convert.ToDouble(ringInterval.Text); var ringDistance = bufferDistance; var numRings = Convert.ToInt32(numberOfRings.Text); for (var i = 0; i < numRings; i++) { _bufferParams.Distances.Add(ringDistance); ringDistance = ringDistance + bufferDistance; } _geometryService.BufferAsync(_bufferParams); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.MyDataGrid = ((ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid)(target)); return; case 2: this.MyMap = ((ESRI.ArcGIS.Client.Map)(target)); #line 26 "..\..\MainWindow.xaml" this.MyMap.Loaded += new System.Windows.RoutedEventHandler(this.MyMap_Loaded); #line default #line hidden return; case 3: this.TrajectoriesLayer = ((ESRI.ArcGIS.Client.FeatureLayer)(target)); #line 36 "..\..\MainWindow.xaml" this.TrajectoriesLayer.MouseLeftButtonUp += new ESRI.ArcGIS.Client.GraphicsLayer.MouseButtonEventHandler(this.FeatureLayer_MouseLeftButtonUp); #line default #line hidden return; case 4: this.ResponseTextBlock = ((System.Windows.Controls.TextBox)(target)); return; case 5: this.DeleteScenarioButton = ((System.Windows.Controls.Button)(target)); #line 43 "..\..\MainWindow.xaml" this.DeleteScenarioButton.Click += new System.Windows.RoutedEventHandler(this.DeleteScenarioButton_Click); #line default #line hidden return; } this._contentLoaded = true; }
public async Task QueryForFeatures(client.Geometry.Geometry bufferPolygon) { //Set up the query and query result Query query = new Query("", bufferPolygon, true); //Run the query and check the result QueryResult result = await TargetDataSource.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 Convert.ToInt32(resultFeature.Attributes[TargetDataSource.ObjectIdFieldName]); // Get the feature layer in the map for the data source. client.FeatureLayer featureLayer = mapWidget.FindFeatureLayer(TargetDataSource); if (featureLayer == null) { return; } // 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[TargetDataSource.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(); } } }
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(); } } } }
private void HighlightFeature_Click(object sender, RoutedEventArgs e) { SiteDetails sd = ((Button)sender).DataContext as SiteDetails; Geometry g = Geometry.FromJson(sd.ZoomExtent); ESRI.ArcGIS.Client.FeatureLayer fl = mapWidget.FindFeatureLayer(dataSource); for (int i = 0; i < fl.Graphics.Count; i++) { client.Graphic feature = fl.Graphics[i]; int featureOid; int.TryParse(feature.Attributes[dataSource.ObjectIdFieldName].ToString(), out featureOid); if (sd.f == featureOid.ToString()) { fl.ClearSelection(); feature.Select(); } } }
public static DomainSubtypeLookup GetDomainSubTypeLookup(Layer layer, FieldInfo field) { if (field.DomainSubtypeLookup != DomainSubtypeLookup.NotDefined) { return(field.DomainSubtypeLookup); } ESRI.ArcGIS.Client.FeatureLayer featureLayer = layer as ESRI.ArcGIS.Client.FeatureLayer; if (featureLayer == null) { field.DomainSubtypeLookup = DomainSubtypeLookup.None; return(field.DomainSubtypeLookup); } ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo featureLayerInfo = featureLayer.LayerInfo; if (featureLayerInfo != null) { Client.Field f = GetField(field.Name, featureLayerInfo.Fields); field.DomainSubtypeLookup = GetDomainSubTypeLookup(featureLayerInfo, f); } return(field.DomainSubtypeLookup); }
private void clearMapToolParameters() { ////clear the graphicsLayer _bufferPointLayer.Graphics.Clear(); _bufferPolygonLayer.Graphics.Clear(); if (_bufferParams != null) { _bufferParams.Features.Clear(); } ////Clear selected features IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); featureL.ClearSelection(); } _mapWidget.Map.MouseClick -= Map_MouseClick; }
public static Core.FieldInfo FieldInfoFromField(Layer layer, Client.Field field) { ESRI.ArcGIS.Mapping.Core.FieldInfo fieldInfo = new ESRI.ArcGIS.Mapping.Core.FieldInfo() { DisplayName = field.Alias, AliasOnServer = field.Alias, FieldType = mapFieldType(field.Type), Name = field.Name, VisibleInAttributeDisplay = true, VisibleOnMapTip = true, }; ESRI.ArcGIS.Client.FeatureLayer featureLayer = layer as ESRI.ArcGIS.Client.FeatureLayer; if (featureLayer != null) { ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo featureLayerInfo = featureLayer.LayerInfo; if (featureLayerInfo != null) { fieldInfo.DomainSubtypeLookup = GetDomainSubTypeLookup(featureLayerInfo, field); } } return(fieldInfo); }
//Validate if the input data source can be used as a team data source private bool IsValidTeamDataSource(DataSource dataSrc) { //If the dataSource has the field "SearchAreaName", //and its associated feature layer is a polygon layer //return true if (dataSrc.Fields.Any(f => f.Name == "SearchAreaName") == false) { return(false); } MapWidget mw = MapWidget.FindMapWidget(dataSrc); client.FeatureLayer layer = mw.FindFeatureLayer(dataSrc); if (layer != null && layer.LayerInfo.GeometryType == client.Tasks.GeometryType.Point) { return(true); } else { return(false); } }
private void DoneButton_Click(object sender, RoutedEventArgs e) { try { if (_graphicsLayer != null) { _graphicsLayer.Graphics.Clear(); } // Find the map layer in the map widget that contains the data source. IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { if (_mapWidget != null && d.IsSelectable == true) { // Get the feature layer in the map for the data source. client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); //Clear Selection on Feature Layers in map featureL.ClearSelection(); } } location = null; RunButton.IsEnabled = false; txtAddress.Text = "Enter Address"; if (_mapWidget != null) { _mapWidget.Map.MouseClick -= Map_MouseClick; _mapWidget.SetToolbar(null); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
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 }
public ERGChemicalMapToolbar(MapWidget mapWidget, string ERGChemicalURL, string ERGPlacardURL, string FindNearestWSURL, string WindDirectionLayerDataSource, string windDirectionFieldName, string windWeatherStationFieldName, string windRecordedDateFieldName, string defaultChemicalName, string defaultPlacardName) { try { InitializeComponent(); this.DataContext = this; // Store a reference to the MapWidget that the toolbar has been installed to. _mapWidget = mapWidget; if (string.IsNullOrEmpty(ERGChemicalURL)) { MessageBox.Show("Please configure the tool!", "Error"); return; } //set up erg Chemical GP URL ERGChemicalURL = (ERGChemicalURL ?? ""); _chemicalURL = ERGChemicalURL; chemicalGPParameters = new List <GPParameterInfo>(); var chemicalJSONUrl = _chemicalURL + "?f=pjson"; ChemicalList = getListOfChemicalsOrPlacards("chemical", chemicalJSONUrl); cmbChemicalOrPlacardType.ItemsSource = ChemicalList; if (!String.IsNullOrEmpty(defaultChemicalName)) { _defaultChemicalName = defaultChemicalName; } else { _defaultChemicalName = _defaultERGName; } cmbChemicalOrPlacardType.SelectedValue = _defaultChemicalName; //set up erg Placard GP URL ERGPlacardURL = (ERGPlacardURL ?? ""); _placardURL = ERGPlacardURL; placardGPParameters = new List <GPParameterInfo>(); var placardJsonUrl = _placardURL + "?f=pjson"; PlacardList = getListOfChemicalsOrPlacards("placard", placardJsonUrl); if (!String.IsNullOrEmpty(defaultPlacardName)) { _defaultPlacardName = defaultPlacardName; } else { _defaultPlacardName = _defaultERGName; } //wind direction _findNearestWSURL = FindNearestWSURL; if (!string.IsNullOrEmpty(WindDirectionLayerDataSource) && !string.IsNullOrEmpty(_findNearestWSURL)) { ESRI.ArcGIS.OperationsDashboard.DataSource dataSource = OperationsDashboard.Instance.DataSources.FirstOrDefault(ds => ds.Name == WindDirectionLayerDataSource); if (dataSource != null) { _windDirectionLayer = _mapWidget.FindFeatureLayer(dataSource); } //wind direction fields if (!string.IsNullOrEmpty(windDirectionFieldName)) { _windDirectionFieldName = windDirectionFieldName; } if (!string.IsNullOrEmpty(windWeatherStationFieldName)) { _windWeatherStationFieldName = windWeatherStationFieldName; } if (!string.IsNullOrEmpty(windRecordedDateFieldName)) { _windRecordedDateFieldName = windRecordedDateFieldName; } btnLookupWindDirection.IsEnabled = true; } _mydictionary = new ResourceDictionary(); _mydictionary.Source = new Uri("/ERGChemicalAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); MessageBox.Show("There is an error! Check your parameters!", "Error"); return; } }
/// <summary> /// Allow users to specify the search area layer, or use the first polygon layer as default /// </summary> public bool Configure(System.Windows.Window owner) { DrawPolygonMapToolDialog configDialog = new DrawPolygonMapToolDialog(MapWidget); if (configDialog.ShowDialog() == false) { MessageBox.Show("Error selecting search area layer"); return false; } searchAreaLayer = configDialog.PolygonLayer; SearchAreaLayerID = searchAreaLayer.ID; return true; }
/// <summary> /// OnDeactivated is called before the map tool is removed from the toolbar. Called when the operational view is closed, /// and also before a custom toolbar is installed, and during toolbar configuration. /// </summary> public void OnDeactivated() { searchAreaLayer = null; }
/// <summary> /// OnActivated is called when the map tool is added to the toolbar of the map widget in which it is configured to appear. /// Called when the operational view is opened, and also after a custom toolbar is reverted to the configured toolbar, /// and during toolbar configuration. /// </summary> public void OnActivated() { //Retrieve the previously selected search area layer (i.e. when SearchAreaLayerID is not null or empty) //If the search area layer has never been set then pick the first polygon layer if (!string.IsNullOrEmpty(SearchAreaLayerID)) searchAreaLayer = MapFeatureLayersFinder.GetMapFeatureLayers(MapWidget.Map).FirstOrDefault(layer => layer.ID == SearchAreaLayerID); else searchAreaLayer = MapFeatureLayersFinder.GetMapFeatureLayers(MapWidget.Map).FirstOrDefault(layer => layer.LayerInfo.GeometryType == client.Tasks.GeometryType.Polygon); }
/// <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; } }
private void btnAddSighting_Click(object sender, RoutedEventArgs e) { btnAddSighting.IsEnabled = false; btnSaveSighting.IsEnabled = true; ESRI.ArcGIS.OperationsDashboard.MapWidget mapWidget; DataSource answer=null; foreach (DataSource dS in OperationsDashboard.Instance.DataSources) { if (dS.Name.ToString() == "animal_sightings - animal_sightings") { answer = dS; } } if (answer != null) { mapWidget = (ESRI.ArcGIS.OperationsDashboard.MapWidget)OperationsDashboard.Instance.FindWidget(answer); globalMapWidget = mapWidget; globalFeatureLayer = mapWidget.FindFeatureLayer(answer); if (this.eventMouse == 0) { mapWidget.Map.MouseClick += Map_MouseClick; this.eventMouse = 1; } } }
private void RunButton_Click_1(object sender, RoutedEventArgs e) { try { if (_graphicsLayer != null) { _graphicsLayer.Graphics.Clear(); } // Find the map layer in the map widget that contains the data source. IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { if (_mapWidget != null && d.IsSelectable == true) { // Get the feature layer in the map for the data source. client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); //Clear Selection on Feature Layers in map featureL.ClearSelection(); } } if (txtAddress.Text == "Enter Address") { int BuildingEvacDistance = 0; int OutdoorEvacDistance = 0; if (bombType.Text == "Pipe bomb") { BuildingEvacDistance = 70; OutdoorEvacDistance = 1200; } else if (bombType.Text == "Suicide vest") { BuildingEvacDistance = 110; OutdoorEvacDistance = 1750; } else if (bombType.Text == "Briefcase/suitcase bomb") { BuildingEvacDistance = 150; OutdoorEvacDistance = 1850; } else if (bombType.Text == "Sedan") { BuildingEvacDistance = 320; OutdoorEvacDistance = 1900; } else if (bombType.Text == "SUV/van") { BuildingEvacDistance = 400; OutdoorEvacDistance = 2400; } else if (bombType.Text == "Small delivery truck") { BuildingEvacDistance = 640; OutdoorEvacDistance = 3800; } else if (bombType.Text == "Container/water truck") { BuildingEvacDistance = 860; OutdoorEvacDistance = 5100; } else if (bombType.Text == "Semi-trailer") { BuildingEvacDistance = 1570; OutdoorEvacDistance = 9300; } if (BuildingEvacDistance == 0 || OutdoorEvacDistance == 0) { return; } //e.MapPoint.SpatialReference = _mapWidget.Map.SpatialReference; //location = e.MapPoint; if (location == null) { return; } Graphic graphic = new ESRI.ArcGIS.Client.Graphic(); graphic.Geometry = location; GeometryService geometryTask = new GeometryService(); geometryTask.Url = _serviceURL; geometryTask.BufferCompleted += GeometryService_BufferCompleted; geometryTask.Failed += GeometryService_Failed; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering BufferParameters bufferParams = new BufferParameters() { Unit = LinearUnit.SurveyFoot, BufferSpatialReference = new SpatialReference(102004), OutSpatialReference = _mapWidget.Map.SpatialReference }; bufferParams.Features.Add(graphic); double[] theDistances = new double[] { BuildingEvacDistance, OutdoorEvacDistance }; bufferParams.Distances.AddRange(theDistances); geometryTask.BufferAsync(bufferParams); } else { findAddress(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error in run: " + ex.Message); } }
void Map_MouseClick(object sender, client.Map.MouseEventArgs e) { if (sizeComboBox.Text=="Select Size") MessageBox.Show("Please select a size of animal before adding to the map."); if (btnAddSighting.IsEnabled == false && sizeComboBox.Text!="Select Size") { ESRI.ArcGIS.Client.Graphic graphicFeature = new client.Graphic(); ESRI.ArcGIS.Client.FeatureLayer featureLayer = new client.FeatureLayer(); featureLayer = this.globalFeatureLayer; ESRI.ArcGIS.Client.Geometry.MapPoint point = new client.Geometry.MapPoint(); point = e.MapPoint; graphicFeature.Geometry=point; graphicFeature.Attributes.Add("size", sizeComboBox.Text.ToString()); featureLayer.Graphics.Add(graphicFeature); featureLayer.SaveEdits(); MessageBox.Show("Successfully added sighting!"); ///Thread.Sleep(10000); //MessageBox.Show("finished"); //featureLayer.Update(); //featureLayer.Refresh(); //globalMapWidget.Map.UpdateLayout(); } }
public ERGChemicalMapToolbar(MapWidget mapWidget, string ERGChemicalURL, string ERGPlacardURL, string FindNearestWSURL, string WindDirectionLayerDataSource, string windDirectionFieldName, string windWeatherStationFieldName, string windRecordedDateFieldName, string defaultChemicalName, string defaultPlacardName) { try { InitializeComponent(); this.DataContext = this; // Store a reference to the MapWidget that the toolbar has been installed to. _mapWidget = mapWidget; if (string.IsNullOrEmpty(ERGChemicalURL)) { MessageBox.Show("Please configure the tool!", "Error"); return; } //set up erg Chemical GP URL ERGChemicalURL = (ERGChemicalURL ?? ""); _chemicalURL = ERGChemicalURL; chemicalGPParameters = new List<GPParameterInfo>(); var chemicalJSONUrl = _chemicalURL + "?f=pjson"; ChemicalList = getListOfChemicalsOrPlacards("chemical", chemicalJSONUrl); cmbChemicalOrPlacardType.ItemsSource = ChemicalList; if (!String.IsNullOrEmpty(defaultChemicalName)) _defaultChemicalName = defaultChemicalName; else _defaultChemicalName = _defaultERGName; cmbChemicalOrPlacardType.SelectedValue = _defaultChemicalName; //set up erg Placard GP URL ERGPlacardURL = (ERGPlacardURL ?? ""); _placardURL = ERGPlacardURL; placardGPParameters = new List<GPParameterInfo>(); var placardJsonUrl = _placardURL + "?f=pjson"; PlacardList = getListOfChemicalsOrPlacards("placard", placardJsonUrl); if (!String.IsNullOrEmpty(defaultPlacardName)) _defaultPlacardName = defaultPlacardName; else _defaultPlacardName = _defaultERGName; //wind direction _findNearestWSURL = FindNearestWSURL; if (!string.IsNullOrEmpty(WindDirectionLayerDataSource) && !string.IsNullOrEmpty(_findNearestWSURL)) { ESRI.ArcGIS.OperationsDashboard.DataSource dataSource = OperationsDashboard.Instance.DataSources.FirstOrDefault(ds => ds.Name == WindDirectionLayerDataSource); if (dataSource != null) _windDirectionLayer = _mapWidget.FindFeatureLayer(dataSource); //wind direction fields if (!string.IsNullOrEmpty(windDirectionFieldName)) _windDirectionFieldName = windDirectionFieldName; if (!string.IsNullOrEmpty(windWeatherStationFieldName)) _windWeatherStationFieldName = windWeatherStationFieldName; if (!string.IsNullOrEmpty(windRecordedDateFieldName)) _windRecordedDateFieldName = windRecordedDateFieldName; btnLookupWindDirection.IsEnabled = true; } _mydictionary = new ResourceDictionary(); _mydictionary.Source = new Uri("/ERGChemicalAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); MessageBox.Show("There is an error! Check your parameters!", "Error"); return; } }
/// <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); } }
/*private void set_equipment(object sender, RoutedEventArgs e) * { * if ((Boolean)((CheckBox)sender).IsChecked) * { * DataSourceSelectorEquipment.IsEnabled = true; * //EquipmentUIDComboBox.IsEnabled = true; * //EquipmentHFComboBox.IsEnabled = true; * //EquipmentLabelComboBox.IsEnabled = true; * } * else * { * if (DataSources.Count > 1) * { * DataSources.Remove(DataSources[1]); * } * DataSourceSelectorEquipment.IsEnabled = false; * //EquipmentUIDComboBox.IsEnabled = false; * //EquipmentHFComboBox.IsEnabled = false; * //EquipmentLabelComboBox.IsEnabled = false; * } * }*/ private async void AddDatasourceToCache(OOBDataSource ods) { try { String Uid = ods.UIDField; String HF = ods.HFField; String DF = ods.DescField; String Labels = ""; String DescFlds = ""; String CacheName = ods.Key; Dictionary <String, String> fields = new Dictionary <String, String>(); fields["UID"] = Uid; fields["HF"] = HF; Int32 numBaseFlds = 2; if (DF != null) { fields["DESCFIELD"] = DF; numBaseFlds = 3; } Int32 arraySize = ods.LabelFields.Count + ods.DescriptionFields.Count + numBaseFlds; string[] qfields = new string[arraySize]; qfields[0] = Uid; qfields[1] = HF; if (DF != null) { qfields[2] = DF; } Int32 c = numBaseFlds; Boolean first = true; foreach (String f in ods.LabelFields) { if (!first) { Labels += ","; } else { first = false; } Labels += f; qfields[c] = f; ++c; } first = true; foreach (String f in ods.DescriptionFields) { if (!first) { DescFlds += ","; } else { first = false; } DescFlds += f; qfields[c] = f; ++c; } fields["LABELS"] = Labels; fields["DESCFLDS"] = DescFlds; Query q = new Query(); q.Fields = qfields; cache.AddFeatuereContainer(CacheName); DataSource ds = ods.DataSource; q.ReturnGeometry = true; QueryResult res = await ds.ExecuteQueryAsync(q); var resultOids = from feature in res.Features select System.Convert.ToInt32(feature.Attributes[ds.ObjectIdFieldName]); MapWidget mw = MapWidget.FindMapWidget(ds); client.FeatureLayer fl = mw.FindFeatureLayer(ds); //fl.Update(); client.UniqueValueRenderer r = fl.Renderer as client.UniqueValueRenderer; foreach (client.Graphic g in fl.Graphics) { cache.AddFeature(CacheName, g, ods.BaseDescription, ods.BaseLabel, fields, r); } ods.IsCacheCreated = true; //cache.AddFeature } catch (Exception e) { System.Windows.MessageBox.Show(e.Message + "/n" + e.Source + "/n" + e.StackTrace); } }
} // public void initRelations() private Layer createLayer(string id, bool vis) { // create Layer according to its Type string typ = lyrType; ESRI.ArcGIS.Client.Layer res = new ESRI.ArcGIS.Client.GraphicsLayer(); if (typ == "ArcGISTiledMapServiceLayer") { var lr = new ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer(); lr.Url = lyrUrl; lr.ProxyURL = proxy; res = lr; } else if (typ == "OpenStreetMapLayer") { var lr = new ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer(); res = lr; } else if (typ == "ArcGISDynamicMapServiceLayer") { var lr = new ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer(); lr.Url = lyrUrl; lr.ProxyURL = proxy; lr.ImageFormat = imageFormat; res = lr; } else if (typ == "FeatureLayer") { var lr = new ESRI.ArcGIS.Client.FeatureLayer() { Url = lyrUrl, ProxyUrl = proxy }; lr.OutFields.Add("*"); lr.Mode = FeatureLayer.QueryMode.OnDemand; lr.Initialize(); // retrieve attribs from server var rr = rendererFromJson(renderer); if (rr != null) { lr.Renderer = rr; } res = lr; } else if (typ == "GraphicsLayer") { var gl = setContent(id, lyrUrl); var rr = rendererFromJson(renderer); if (rr != null) { gl.Renderer = rr; } res = gl; } if (res != null) { ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsPopupEnabled(res, popupOn); // sublayers popups on/off if (identifyLayerIds.Length <= 3) { ; } else { var xmlszn = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.ObjectModel.Collection <int>)); var sr = new StringReader(identifyLayerIds); var ids = xmlszn.Deserialize(sr) as System.Collections.ObjectModel.Collection <int>; ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIdentifyLayerIds(res, ids); } } return(res); } // private Layer createLayer(string id, bool vis)