void drawObject_DrawComplete(object sender, DrawEventArgs e) { if (e.Geometry.Extent.Height == 0 | e.Geometry.Extent.Width == 0) { MessageBox.Show("Please click and drag a box to define an extent", "Error", MessageBoxButton.OK); return; } myDrawObject.IsEnabled = false; ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = e.Geometry, Symbol = LayoutRoot.Resources["DrawFillSymbol"] as Symbol }; graphicsLayer.Graphics.Add(graphic); ESRI.ArcGIS.Client.Geometry.Envelope aoiEnvelope = e.Geometry as ESRI.ArcGIS.Client.Geometry.Envelope; string SOEurl = "http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationData?"; SOEurl += string.Format(System.Globalization.CultureInfo.InvariantCulture, "Extent={{\"xmin\" : {0}, \"ymin\" : {1}, \"xmax\" : {2}, \"ymax\" :{3},\"spatialReference\" : {{\"wkid\" : {4}}}}}&Rows={5}&Columns={6}&f=json", aoiEnvelope.XMin, aoiEnvelope.YMin, aoiEnvelope.XMax, aoiEnvelope.YMax, MyMap.SpatialReference.WKID, HeightTextBox.Text, WidthTextBox.Text); webClient.OpenReadAsync(new Uri(SOEurl)); }
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); e.MapPoint.SpatialReference = MyMap.SpatialReference; Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = e.MapPoint, Symbol = LayoutRoot.Resources["DefaultClickSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; graphic.SetZIndex(1); graphicsLayer.Graphics.Add(graphic); GeometryService geometryService = new GeometryService("http://serverapps101.esri.com/arcgis/rest/services/Geometry/GeometryServer"); geometryService.BufferCompleted += GeometryService_BufferCompleted; geometryService.Failed += GeometryService_Failed; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering BufferParameters bufferParams = new BufferParameters() { Unit = chkGeodesic.IsChecked.HasValue && chkGeodesic.IsChecked.Value ? LinearUnit.StatuteMile : (LinearUnit?)null, BufferSpatialReference = new SpatialReference(4326), OutSpatialReference = MyMap.SpatialReference }; bufferParams.Features.Add(graphic); bufferParams.Distances.Add(5); bufferParams.Geodesic = chkGeodesic.IsChecked == true ? true : false; geometryService.BufferAsync(bufferParams); }
void myDrawObject_DrawComplete(object sender, DrawEventArgs e) { myDrawObject.IsEnabled = false; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = e.Geometry, Symbol = LayoutRoot.Resources["DefaultClickSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; graphic.SetZIndex(1); graphicsLayer.Graphics.Add(graphic); GeometryService geometryService = new GeometryService("http://serverapps101.esri.com/arcgis/rest/services/Geometry/GeometryServer"); geometryService.BufferCompleted += GeometryService_BufferCompleted; geometryService.Failed += GeometryService_Failed; BufferParameters bufferParams = new BufferParameters() { Unit = LinearUnit.StatuteMile, OutSpatialReference = MyMap.SpatialReference, Geodesic = true }; bufferParams.Features.Add(graphic); bufferParams.Distances.Add(5); geometryService.BufferAsync(bufferParams); }
private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.Geometry, Symbol = _activeSymbol, }; graphicsLayer.Graphics.Add(graphic); }
private void StartEdit(ESRI.ArcGIS.Client.Graphic graphic, bool suppressEvent) { if (activeGraphic == graphic) { return; } StopEdit(); //Create vertex graphics layer with all the vertices of the clicked graphic vertexLayer = new GraphicsLayer(); if (graphic.Geometry is MapPoint) //Points are a little special. We start tracking immediately { DraggingVertex = AddVertexToEditLayer(graphic, vertexLayer, graphic.Geometry as MapPoint); StartTracking(); } else { if (graphic.Geometry is Polyline) { Polyline line = graphic.Geometry as Polyline; foreach (PointCollection ps in line.Paths) { BuildHoverLines(graphic, ps, true); } } else if (graphic.Geometry is Polygon) { Polygon poly = graphic.Geometry as Polygon; foreach (PointCollection ps in poly.Rings) { BuildHoverLines(graphic, ps, false); } } else if (graphic.Geometry is Envelope) { Envelope poly = graphic.Geometry as Envelope; Graphic g = AddVertexToEditLayer(graphic, vertexLayer, new MapPoint(poly.XMin, poly.YMin)); g.Attributes.Add("corner", 0); g = AddVertexToEditLayer(graphic, vertexLayer, new MapPoint(poly.XMax, poly.YMax)); g.Attributes.Add("corner", 1); } } activeGraphic = graphic; MyMap.Layers.Add(vertexLayer); //Start listening for mouse down events vertexLayer.MouseLeftButtonDown += vertexLayer_MouseLeftButtonDown; vertexLayer.MouseLeave += vertexLayer_MouseLeave; vertexLayer.MouseMove += vertexLayer_MouseMove; if (!suppressEvent) { OnGeometryEdit(activeGraphic, null, null, Action.EditStarted); } }
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; }
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); } }
private String createDescriptionString(client.Graphic f, String basedesc, String descfield, String descFlds) { String d = null; String desc = null; if (!String.IsNullOrEmpty(descfield)) { if (f.Attributes[descfield] == null) { d = null; return(d); } desc = f.Attributes[descfield].ToString(); if (!String.IsNullOrEmpty(basedesc)) { if (String.IsNullOrEmpty(descFlds)) { d = basedesc; } else { String[] flds = descFlds.Split(','); foreach (String df in flds) { if (f.Attributes[df] != null) { d = basedesc.Replace("{" + df + "}", f.Attributes[df].ToString()); } else { d = basedesc.Replace("{" + df + "}", ""); } } } } else { d = desc; } } else { d = null; } if (String.IsNullOrEmpty(d)) { return(null); } return(d); }
/// <summary> /// Called when a DataSource found in the DataSourceIds property is updated. /// </summary> /// <param name="dataSource">The DataSource being updated.</param> public async void OnRefresh(DataSource dataSource) { try { int[] oIds = new int[_rfFeatures.Count]; int count = 0; foreach (Feature f in _rfFeatures) { oIds[count] = System.Convert.ToInt32(f.Graphic.Attributes[dataSource.ObjectIdFieldName].ToString()); System.Diagnostics.Debug.WriteLine("Refresh: " + oIds[count].ToString()); count++; } Query q = new Query(); q.ReturnGeometry = true; var result = await dataSource.ExecuteQueryObjectIdsAsync(oIds, q); if (result == null || result.Features == null) { return; } client.GraphicsLayer gLayer = _map.Layers["RangeFanGraphics"] as client.GraphicsLayer; if (gLayer != null) { if (gLayer.Graphics.Count == result.Features.Count) { foreach (client.Graphic g in result.Features) { client.Graphic pFan = CreateFan(g); if (pFan != null) { foreach (client.Graphic graphic in gLayer.Graphics) { if (graphic.Attributes["Name"].ToString() == g.Attributes[_datasource.ObjectIdFieldName].ToString()) { graphic.Geometry = pFan.Geometry; } } } } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
/// <summary> /// This function creates the buffer area from user's selected feature /// </summary> public void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource BufferDS, client.Graphic BufferFeature) { //Clear any running task _geometryTask.CancelAsync(); //Get the map that contains the feature used to generate the buffer client.Map mwMap = mapWidget.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> /// Called when a feature is clicked. Makes the clicked feature "active" for editing, /// by creating a set of vertices in an edit layer /// </summary> /// <param name="sender">The sender.</param> /// <param name="graphic">The graphic.</param> /// <param name="args">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param> private void GraphicsLayer_MouseLeftButtonDown(object sender, ESRI.ArcGIS.Client.Graphic graphic, MouseButtonEventArgs args) { if (graphic.Geometry is MapPoint) { args.Handled = true; } if (activeGraphic == graphic) { StopEdit(); } else { StartEdit(graphic); } }
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); } }
//Show a point on the profile line when user clicks on a data point on the graph private void LineSeries_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Remove any existing graphic from the data point layer selecteDataPointLyr.Graphics.Clear(); //When ClearGraphics_Click occurs, all data points will be removed and no new data points will be added //In this case, skip the rest of the method if (e.RemovedItems.Count > 0 && e.AddedItems.Count == 0) { return; } PointCollection profilePointCol = Profile.Paths.FirstOrDefault(); if (profilePointCol == null || profilePointCol.Count == 0) { return; } //From the profile line, we get the map point whose m value is the same //as user's selected data point on the graph double m = ((KeyValuePair <double, double>)e.AddedItems[0]).Key; //M value of the data point selected from the graph MapPoint mapPoint = profilePointCol.FirstOrDefault(mp => mp.M == m); //Get the map point from the profile line with the same m value if (mapPoint == null) { return; } //Create a point graphic with the map point and a symbol client.Graphic dataPointGraphic = new client.Graphic() { Symbol = SimplePointSymbol.CreatePointSymbol(), Geometry = mapPoint }; //Add the graphic to the data point layer selecteDataPointLyr.Graphics.Add(dataPointGraphic); //If we can find the data point layer, we first remove it if (MapWidget.Map.Layers.Contains(selecteDataPointLyr)) { MapWidget.Map.Layers.Remove(selecteDataPointLyr); } //Add the point layer back to make sure it always stay on top MapWidget.Map.Layers.Add(selecteDataPointLyr); }
void Map_MouseClick(object sender, client.Map.MouseEventArgs e) { client.Geometry.MapPoint clickPoint = e.MapPoint; if (clickPoint != null) { e.MapPoint.SpatialReference = _mapWidget.Map.SpatialReference; client.Graphic graphic = new client.Graphic() { Geometry = e.MapPoint, Symbol = _resourceDictionary["bufferSymbol"] as client.Symbols.PictureMarkerSymbol }; graphic.SetZIndex(1); _bufferPointLayer.Graphics.Add(graphic); } }
private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { if (LayersList.SelectedItem == null) { MessageBox.Show("Please select layer(s) to extract"); (MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Graphics.Clear(); return; } Geometry filterGeometry = args.Geometry; if (args.Geometry is Polyline) { Polyline freehandLine = args.Geometry as Polyline; freehandLine.Paths[0].Add(freehandLine.Paths[0][0].Clone()); filterGeometry = new Polygon() { SpatialReference = MyMap.SpatialReference }; (filterGeometry as Polygon).Rings.Add(freehandLine.Paths[0]); } ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = filterGeometry }; _graphicsLayer.Graphics.Add(graphic); _drawObject.IsEnabled = false; ProcessingTextBlock.Visibility = Visibility.Visible; _processingTimer.Start(); List <GPParameter> parameters = new List <GPParameter>(); var strLayerList = new List <GPString>(); foreach (var itm in LayersList.SelectedItems) { strLayerList.Add(new GPString(itm.ToString(), itm.ToString())); } parameters.Add(new GPMultiValue <GPString>("Layers_to_Clip", strLayerList)); parameters.Add(new GPFeatureRecordSetLayer("Area_of_Interest", _graphicsLayer.Graphics[0].Geometry)); parameters.Add(new GPString("Feature_Format", Formats.SelectedValue.ToString())); _geoprocessorTask.SubmitJobAsync(parameters); }
/// <summary> /// Helper function which does the actual report generation work /// </summary> private async void GenerateReportAsync(client.Graphic feature, int wkid) { ReportGenerationService service = new 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)); } }
/// <summary> /// This function determines if the feature action will be enabled or disabled /// </summary> public bool CanExecute(DataSource BufferDS, client.Graphic BufferFeature) { if (BufferDistance == 0) { return(false); } MapWidget bufferDSMapWidget; //map widget containing the buffer dataSource MapWidget targetDSMapWidget; ////map widget containing the target dataSource //The feature used to generate the buffer area must not be null if (BufferFeature == null) { return(false); } //The data source to queried (TargetDataSource) and the data source that contains the BufferFeature (BufferDS) must not be null if (TargetDataSource == null || BufferDS == null) { return(false); } //Get the mapWidget consuming the target datasource if ((targetDSMapWidget = MapWidget.FindMapWidget(TargetDataSource)) == null) { return(false); } //Check if the map widget associated with the buffer dataSource is valid if ((bufferDSMapWidget = MapWidget.FindMapWidget(BufferDS)) == null) { return(false); } //Only if targetDSMapWidget and bufferDSMapWidget referes to the same object can we execute the search if (bufferDSMapWidget.Id != targetDSMapWidget.Id) { return(false); } //Assigning the selected values to the global variables for later use bufferDataSource = BufferDS; mapWidget = bufferDSMapWidget; return(true); }
void win_Closed(object sender, EventArgs e) { TextSymbolPropsWindow win = sender as TextSymbolPropsWindow; if ((bool)win.DialogResult) { GraphicsLayer graphicsLayer = BoundMap.Layers["AnnoLayer"] as GraphicsLayer; string input = win.Annotation; if (!String.IsNullOrEmpty(input)) { MapPoint pt = _currentPoint; TextSymbol sym = new TextSymbol(); sym.FontFamily = new FontFamily(win.TextFont); sym.FontSize = win.TextFontSize; sym.Text = win.Annotation; sym.Foreground = new SolidColorBrush { Color = Colors.Black }; Zekiah.Samples.Font f = new Font(); f.Family = sym.FontFamily; f.Size = sym.FontSize; f.Style = FontStyles.Normal; f.Weight = FontWeights.Normal; String s = new String(input.ToCharArray()); Size size = s.Measure(f); sym.OffsetX = size.Width / 2; sym.OffsetY = size.Height / 2; ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = pt, Symbol = sym, }; graphic.MouseEnter += new MouseEventHandler(graphic_MouseEnter); graphic.MouseLeave += new MouseEventHandler(graphic_MouseLeave); graphic.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(graphic_MouseRightButtonDown); if (win.EditMode) { graphicsLayer.Graphics.Remove(Ambient.SelectedSymbol); } graphicsLayer.Graphics.Add(graphic); } } }
/// <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); }
// *********************************************************************************** // * ...Let user enter the incident location on the map // *********************************************************************************** void Map_MouseClick(object sender, client.Map.MouseEventArgs e) { try { _spillLocationGraphicsLayer.ClearGraphics(); client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic(); graphic.Geometry = e.MapPoint; graphic.Symbol = _mydictionary["spillSymbol"] as client.Symbols.MarkerSymbol; graphic.SetZIndex(1); _spillLocationGraphicsLayer.Graphics.Add(graphic); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error in mouseclick: " + ex.Message); } _mapWidget.Map.MouseClick -= Map_MouseClick; }
// *********************************************************************************** // * 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); }
/// <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 } }
// *********************************************************************************** // * 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); } }
private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.Geometry, Symbol = _activeSymbol, }; graphicsLayer.Graphics.Add(graphic); if (args.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline) { _polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline; } ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; // clear ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = true; // show graph }
void win_Closed(object sender, EventArgs e) { TextSymbolPropsWindow win = sender as TextSymbolPropsWindow; GraphicsLayer graphicsLayer = _map.Map.Layers["defaultTextGraphicsLayer"] as GraphicsLayer; string input = win.Annotation; // System.Windows.Browser.HtmlPage.Window.Prompt("Enter text to display"); if (!String.IsNullOrEmpty(input)) { MapPoint pt = _currentPoint; TextSymbol sym = new TextSymbol(); sym.FontFamily = new FontFamily(win.TextFont); // new FontFamily("Arial"); sym.FontSize = win.TextFontSize; // 20; sym.Text = win.Annotation; // input; sym.Foreground = new SolidColorBrush { Color = Colors.Black }; Main.Helpers.Font f = new Font(); f.Family = sym.FontFamily; f.Size = sym.FontSize; f.Style = FontStyles.Normal; f.Weight = FontWeights.Normal; String s = new String(input.ToCharArray()); Size size = s.Measure(f); sym.OffsetX = size.Width / 2; sym.OffsetY = size.Height / 2; //MessageBox.Show("h:" + size.Height.ToString() + " w:" + size.Width.ToString()); //TODO: Apply offest to center label ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = pt, Symbol = sym, }; graphic.MouseLeftButtonUp += new MouseButtonEventHandler(graphic_MouseLeftButtonUp); graphic.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(graphic_MouseRightButtonDown); if (win.EditMode) { graphicsLayer.Graphics.Remove(SelectedSymbol); }//_map.PreviousExtents.Push(_map.Map.Extent); graphicsLayer.Graphics.Add(graphic); } }
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(); } } }
//When the Draw Line button is clicked: //The skecth (a polyline graphic) will be created and will be added to the sketch layer //The sketch layer will be added to the map for display //2 map events will be registered for user's interaction private void AddGraphics_Click(object sender, RoutedEventArgs e) { //Take the first map widget from the view MapWidget mapWidget = OperationsDashboard.Instance.Widgets.First(w => w.GetType() == typeof(MapWidget)) as MapWidget; if (mapWidget == null || mapWidget.Map == null) { return; } MapWidget = mapWidget; client.Map map = MapWidget.Map; //First, remove any existing graphic layer on the map RemoveAllGraphicLayers(); //Create the geometry (a polyline) for the sketch sketchGeometry = new client.Geometry.Polyline(); sketchGeometry.SpatialReference = map.SpatialReference; sketchGeometry.Paths.Add(new client.Geometry.PointCollection()); //Create the sketch with the geometry and a symbol client.Graphic sketch = new client.Graphic() { Symbol = SimplePolylineSymbol.CreateLineSymbol(), Geometry = sketchGeometry, }; //Add the sketch to the map sketch layer //mapSketchLyr.Graphics.Clear(); mapSketchLyr.Graphics.Add(sketch); //Add the sketch layer back to the map map.Layers.Add(mapSketchLyr); //Register mouse click i.e. sketch begins //Register mouse double click i.e. sketch finishes map.MouseClick += map_MouseClick; map.MouseDoubleClick += map_MouseDoubleClick; map.MouseMove += map_MouseMove; }
void drawObject_DrawComplete(object sender, DrawEventArgs e) { myDrawObject.IsEnabled = false; ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = e.Geometry, Symbol = LayoutRoot.Resources["DrawFillSymbol"] as Symbol }; graphicsLayer.Graphics.Add(graphic); ESRI.ArcGIS.Client.Geometry.Envelope aoiEnvelope = e.Geometry as ESRI.ArcGIS.Client.Geometry.Envelope; string SOEurl = "http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationData?"; SOEurl += string.Format(System.Globalization.CultureInfo.InvariantCulture, "Extent={{\"xmin\" : {0}, \"ymin\" : {1}, \"xmax\" : {2}, \"ymax\" :{3},\"spatialReference\" : {{\"wkid\" : {4}}}}}&Rows={5}&Columns={6}&f=json", aoiEnvelope.XMin, aoiEnvelope.YMin, aoiEnvelope.XMax, aoiEnvelope.YMax, MyMap.SpatialReference.WKID, HeightTextBox.Text, WidthTextBox.Text); webClient.OpenReadAsync(new Uri(SOEurl)); }
/// <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); } }
void targetAreaDraw_DrawComplete(object sender, client.DrawEventArgs e) { try { if (_graphicsLayerPoly == null) { _graphicsLayerPoly = new client.GraphicsLayer(); _graphicsLayerPoly.ID = "AircraftCommunicationGraphicsPoly"; client.AcceleratedDisplayLayers aclyrs = _mapWidget.Map.Layers.FirstOrDefault(lyr => lyr is client.AcceleratedDisplayLayers) as client.AcceleratedDisplayLayers; if (aclyrs.Count() > 0) { aclyrs.ChildLayers.Add(_graphicsLayerPoly); } } ResourceDictionary mydictionary = new ResourceDictionary(); mydictionary.Source = new Uri("/AircraftCommunicationCoverageAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); client.Graphic g = new client.Graphic(); //g.Geometry = mercator.ToGeographic(e.Geometry) as client.Geometry.Polygon; //g.Symbol = mydictionary["BasicFillSymbol_Yellow_Trans_6"] as client.Symbols.SimpleFillSymbol; g.Geometry = e.Geometry as client.Geometry.Polygon; g.Symbol = mydictionary["BasicFillSymbol_Yellow_Trans_6"] as client.Symbols.SimpleFillSymbol; _graphicsLayerPoly.Graphics.Add(g); targetAreaDraw.DrawMode = client.DrawMode.None; if (_graphicsLayer != null && _graphicsLayerPoly != null) { if (_graphicsLayer.Graphics.Count() > 0 && _graphicsLayerPoly.Graphics.Count() > 0) { RunButton.IsEnabled = true; } } targetAreaDraw.IsEnabled = false; } catch (Exception ex) { MessageBox.Show("Error in draw complete: " + ex.Message); } }
/// <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 = "GroundCommunicationGraphics"; 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("/GroundCommunicationCoverageAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); client.Graphic graphic = new client.Graphic(); //graphic.Geometry = pt; graphic.Geometry = clickPoint; graphic.Symbol = mydictionary["RedPin"] as client.Symbols.MarkerSymbol; _graphicsLayer.Graphics.Add(graphic); if (_graphicsLayer != null) { if (_graphicsLayer.Graphics.Count() > 0) { 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 void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature) { try { // Provide feature action implementation. // Check if the data source and feature can be used with this feature action. foreach (var widget in OperationsDashboard.Instance.Widgets) { if (widget is RangeFanWid) { //((RangeFanWidget)widget).Visibility = System.Windows.Visibility.Visible; RangeFanWid pWidget = (RangeFanWid)widget; pWidget.removefromList(feature); return; } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
//Open the info window (with the retrieved photo) when mouse enters the pushpin graphic void graphicsLayer_MouseEnter(object sender, client.GraphicMouseEventArgs e) { //Get the pushpin graphic we are interested in client.Graphic pushpin = e.Graphic; //Get the photoInfo object associated with the pushpin graphic //From the photoInfo object we will get the URL of the photo var photoInfo = photoInfos.FirstOrDefault(pi => pi.Location.X == (pushpin.Geometry as MapPoint).X && pi.Location.Y == (pushpin.Geometry as MapPoint).Y); if (photoInfo == null) { return; } //Set the content of the info window to the target photoInfo //Specify the location where it should open //Then open it MyInfoWindow.Content = photoInfo; MyInfoWindow.Anchor = pushpin.Geometry as MapPoint; MyInfoWindow.Placement = client.Toolkit.InfoWindow.PlacementMode.Bottom; MyInfoWindow.IsOpen = true; }
private void DrawObject_DrawComplete(object sender, DrawEventArgs e) { if (this.DrawWidget == this.GetType()) { Graphic graphic = null; if (this.drawMode == "Freepoly") { // Geometry needs to be simplified needGeneralized = true; // Create a Graphic with the newly closed Polygon graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = GeometryTool.FreehandToPolygon(e.Geometry as Polyline), Symbol = this.CurrentApp.Resources[SymbolResources.DRAW_FILL] as FillSymbol }; } else { // Create a Graphic with the drawn geometry graphic = new ESRI.ArcGIS.Client.Graphic(); graphic.Symbol = this.CurrentApp.Resources[SymbolResources.DRAW_FILL] as FillSymbol; switch (e.Geometry.GetType().Name) { case "Envelope": graphic.Geometry = GeometryTool.EnvelopeToPolygon(e.Geometry as Envelope); break; case "Polygon": graphic.Geometry = e.Geometry; break; } } if (graphic != null) { this.AddGraphic(graphic); } } }
private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint; ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters() { Geometry = clickPoint, MapExtent = MyMap.Extent, Width = (int)MyMap.ActualWidth, Height = (int)MyMap.ActualHeight, LayerOption = LayerOption.visible, SpatialReference = MyMap.SpatialReference }; IdentifyTask identifyTask = new IdentifyTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Demographics/ESRI_Census_USA/MapServer"); identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted; identifyTask.Failed += IdentifyTask_Failed; identifyTask.ExecuteAsync(identifyParams); GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = clickPoint, Symbol = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; graphicsLayer.Graphics.Add(graphic); }
void targetAreaDraw_DrawComplete(object sender, client.DrawEventArgs e) { try { if (_graphicsLayerPoly == null) { _graphicsLayerPoly = new client.GraphicsLayer(); _graphicsLayerPoly.ID = "AircraftCommunicationGraphicsPoly"; client.AcceleratedDisplayLayers aclyrs = _mapWidget.Map.Layers.FirstOrDefault(lyr => lyr is client.AcceleratedDisplayLayers) as client.AcceleratedDisplayLayers; if (aclyrs.Count() > 0) aclyrs.ChildLayers.Add(_graphicsLayerPoly); } ResourceDictionary mydictionary = new ResourceDictionary(); mydictionary.Source = new Uri("/AircraftCommunicationCoverageAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); client.Graphic g = new client.Graphic(); //g.Geometry = mercator.ToGeographic(e.Geometry) as client.Geometry.Polygon; //g.Symbol = mydictionary["BasicFillSymbol_Yellow_Trans_6"] as client.Symbols.SimpleFillSymbol; g.Geometry = e.Geometry as client.Geometry.Polygon; g.Symbol = mydictionary["BasicFillSymbol_Yellow_Trans_6"] as client.Symbols.SimpleFillSymbol; _graphicsLayerPoly.Graphics.Add(g); targetAreaDraw.DrawMode = client.DrawMode.None; if (_graphicsLayer != null && _graphicsLayerPoly != null) if (_graphicsLayer.Graphics.Count() > 0 && _graphicsLayerPoly.Graphics.Count() > 0) RunButton.IsEnabled = true; targetAreaDraw.IsEnabled = false; } catch (Exception ex) { MessageBox.Show("Error in draw complete: " + ex.Message); } }
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> /// Event handler for Draw Complete event of the draw object /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { if (!MapLayersManager.Instance.annotationsLayerAdded && !MapLayersManager.Instance.onlineAnnotationLayersAdded) return; ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.Geometry, Symbol = _activeSymbol, }; if (MapLayersManager.Instance.annotationsLayerAdded) { // GraphicsLayer graphicsLayer = MapLayersManager.Instance.annotationsLayer as GraphicsLayer; GraphicsLayer graphicsLayer = MyMap.Layers["AnnotationsLayer"] as GraphicsLayer; graphicsLayer.Graphics.Add(graphic); } if (MapLayersManager.Instance.onlineAnnotationLayersAdded) { FeatureLayer fl; if (MyDrawObject.DrawMode == DrawMode.Point) { fl = MyMap.Layers["PointAnnotationsLayer"] as FeatureLayer; } else if (MyDrawObject.DrawMode == DrawMode.Freehand || MyDrawObject.DrawMode == DrawMode.Polyline) { fl = MyMap.Layers["LineAnnotationsLayer"] as FeatureLayer; } else if (MyDrawObject.DrawMode == DrawMode.Polygon || MyDrawObject.DrawMode == DrawMode.Triangle || MyDrawObject.DrawMode == DrawMode.Circle || MyDrawObject.DrawMode == DrawMode.Ellipse || MyDrawObject.DrawMode == DrawMode.Arrow) { fl = MyMap.Layers["PolygonAnnotationsLayer"] as FeatureLayer; } else if (MyDrawObject.DrawMode == DrawMode.Rectangle) // Rectangles are returned the Draw object as Envelopes. We convert this to a polygon, to add to our feature layer. { fl = MyMap.Layers["PolygonAnnotationsLayer"] as FeatureLayer; Polygon polygon = new Polygon(); polygon.Rings.Add(GetPointCollectionFromEnvelope(graphic.Geometry as Envelope)); graphic.Geometry = polygon; } else return; graphic.Geometry.SpatialReference = MyMap.SpatialReference; // Spatial reference is not set on some of the geometry Draw returns, or on the new rectangle polygon, and is required for addition to a feature layer. fl.Graphics.Add(graphic); fl.SaveEdits(); MapLayersManager.Instance.UpdateAnnotationLayers(); } }
private void AddBufferedPoint() { GraphicsLayer graphicsLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer; point.SpatialReference = myMap.SpatialReference; Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = point, Symbol = SimplePointSymbol }; graphic.SetZIndex(1); graphicsLayer.Graphics.Add(graphic); GeometryService geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.BufferCompleted += GeometryService_BufferCompleted; geometryService.Failed += GeometryService_Failed; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering BufferParameters bufferParams = new BufferParameters() { Unit = StandardUnit, BufferSpatialReference = new SpatialReference(4326), OutSpatialReference = myMap.SpatialReference }; bufferParams.Features.Add(graphic); bufferParams.Distances.Add(radius); geometryService.BufferAsync(bufferParams); }
/// <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); } }
// Perform Identify when the map is clicked. private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs args) { // Show an icon at the Identify location. GraphicsLayer graphicsLayer = MyMap.Layers["IdentifyIconGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.MapPoint, Symbol = LayoutRoot.Resources["IdentifyLocationSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; graphicsLayer.Graphics.Add(graphic); // Identify task initialization. IdentifyTask identifyTask = new IdentifyTask("http://maverick.arcgis.com/ArcGIS/rest/services/World_WGS84/MapServer/"); identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted; identifyTask.Failed += IdentifyTask_Failed; // Initialize Identify parameters. Specify search of all layers. IdentifyParameters identifyParameters = new IdentifyParameters(); //identifyParameters.LayerOption = LayerOption.all; identifyParameters.LayerIds.AddRange(new int[] { 0, 1 }); // Pass the current Map properties to Identify parameters. identifyParameters.MapExtent = MyMap.Extent; identifyParameters.Width = (int)MyMap.ActualWidth; identifyParameters.Height = (int)MyMap.ActualHeight; // Identify features at the click point. identifyParameters.Geometry = args.MapPoint; identifyTask.ExecuteAsync(identifyParameters); }
private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { GetCheckBox(activeButton); ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.Geometry, Symbol = _activeSymbol, }; FeatureLayer fl; if (MyDrawObject.DrawMode == DrawMode.Point) { fl = PointLayer; MapPoint loc = graphic.Geometry as MapPoint; } else if (MyDrawObject.DrawMode == DrawMode.Freehand || MyDrawObject.DrawMode == DrawMode.Polyline) { fl = LineLayer; } else if (MyDrawObject.DrawMode == DrawMode.Polygon || MyDrawObject.DrawMode == DrawMode.Triangle || MyDrawObject.DrawMode == DrawMode.Circle || MyDrawObject.DrawMode == DrawMode.Ellipse || MyDrawObject.DrawMode == DrawMode.Arrow) { fl = PolygonLayer; } else if (MyDrawObject.DrawMode == DrawMode.Rectangle) // Rectangles are returned the Draw object as Envelopes. We convert this to a polygon, to add to our feature layer. { fl = PolygonLayer; Polygon polygon = new Polygon(); polygon.Rings.Add(GetPointCollectionFromEnvelope(graphic.Geometry as Envelope)); graphic.Geometry = polygon; } else return; if (graphic.Geometry == null) { System.Diagnostics.Debug.WriteLine("geom is null, that's weird!"); // This happens from time to time, looks like ESRI's api sometimes reports new map drawings incorrectly. return; } graphic.Geometry.SpatialReference = MyMap.SpatialReference; // Spatial reference is not set on some of the geometry Draw returns, or on the new rectangle polygon, and is required for addition to a feature layer. if (!fl.Visible) fl.Visible = true; fl.Graphics.Add(graphic); }
/// <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); } }
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 locatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e) { try { List<AddressCandidate> returnedCandidates = e.Results; 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; if (e.Results.Count > 0) { AddressCandidate candidate = returnedCandidates[0]; ResourceDictionary mydictionary = new ResourceDictionary(); mydictionary.Source = new Uri("/BombThreatAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); Graphic graphic = new ESRI.ArcGIS.Client.Graphic(); graphic.Geometry = candidate.Location; graphic.Symbol = mydictionary["DefaultClickSymbol"] as client.Symbols.MarkerSymbol; location = candidate.Location; graphic.SetZIndex(1); 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.Graphics.Add(graphic); GeometryService geometryTask = new GeometryService(); geometryTask.Url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"; 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 { MessageBox.Show("No address found. Example schema: 380 New York Ave., Redlands, CA or click on the map"); } } catch (Exception ex) { MessageBox.Show("Error in Address location complete: " + ex.Message); } }
private void QueryTask_ExecuteCompleted(object sender, QueryEventArgs args) { if (args.FeatureSet == null) return; FeatureSet featureSet = args.FeatureSet; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.Graphics.Clear(); if (featureSet != null && featureSet.Features.Count > 0) { foreach (Graphic feature in featureSet.Features) { ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = feature.Geometry, Symbol = LayoutRoot.Resources["ParcelFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; graphicsLayer.Graphics.Add(graphic); } } graphicsLayer.Graphics.Add(_unsimplifiedGraphic); }
private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.Geometry, Symbol = _activeSymbol, }; graphicsLayer.Graphics.Add(graphic); if (args.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline) _polyline = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline; ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; // clear ((ApplicationBarIconButton)ApplicationBar.Buttons[1]).IsEnabled = true; // show graph }
private void myMap_MouseClick(object sender, Map.MouseEventArgs args) { if (activateIdentify == true) { GraphicsLayer graphicsLayer = myMap.Layers["identifyIconGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = args.MapPoint, Symbol = LayoutRoot.Resources["identifyLocationSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; // Add the identify graphic graphicsLayer.Graphics.Add(graphic); IdentifyTask identifyTask = new IdentifyTask("http://unibeast/ArcGIS/rest/services/InternetVector/MapServer"); identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted; identifyTask.Failed += IdentifyTask_Failed; IdentifyParameters identifyParameters = new IdentifyParameters(); // Search all layers identifyParameters.LayerOption = LayerOption.all; // Initialize extent of map width and height for identify parameters identifyParameters.MapExtent = myMap.Extent; identifyParameters.Width = (int)myMap.ActualWidth; identifyParameters.Height = (int)myMap.ActualHeight; // Identify the point clicked on the map identifyParameters.Geometry = args.MapPoint; // Execute the identify task identifyTask.ExecuteAsync(identifyParameters); } }
/// <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; if (_graphicsLayer == null) { _graphicsLayer = new ESRI.ArcGIS.Client.GraphicsLayer(); _graphicsLayer.ID = "FarthestOnCircleGraphics"; 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("/FarthestOnCircleAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); client.Graphic graphic = new client.Graphic(); graphic.Geometry = clickPoint; graphic.Symbol = mydictionary["RedPin"] as client.Symbols.MarkerSymbol; _graphicsLayer.Graphics.Add(graphic); RunButton.IsEnabled = true; if (_mapWidget != null) { _mapWidget.Map.MouseClick -= Map_MouseClick; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { if (LayersList.SelectedItem == null) { MessageBox.Show("Please select layer(s) to extract"); (MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Graphics.Clear(); return; } Geometry filterGeometry = args.Geometry; if (args.Geometry is Polyline) { Polyline freehandLine = args.Geometry as Polyline; freehandLine.Paths[0].Add(freehandLine.Paths[0][0].Clone()); filterGeometry = new Polygon() { SpatialReference = MyMap.SpatialReference }; (filterGeometry as Polygon).Rings.Add(freehandLine.Paths[0]); } ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = filterGeometry }; _graphicsLayer.Graphics.Add(graphic); _drawObject.IsEnabled = false; ProcessingTextBlock.Visibility = Visibility.Visible; _processingTimer.Start(); List<GPParameter> parameters = new List<GPParameter>(); var strLayerList = new List<GPString>(); foreach (var itm in LayersList.SelectedItems) { strLayerList.Add(new GPString(itm.ToString(), itm.ToString())); } parameters.Add(new GPMultiValue<GPString>("Layers_to_Clip", strLayerList)); parameters.Add(new GPFeatureRecordSetLayer("Area_of_Interest", _graphicsLayer.Graphics[0].Geometry)); parameters.Add(new GPString("Feature_Format", Formats.SelectedValue.ToString())); _geoprocessorTask.SubmitJobAsync(parameters); }
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(); } }
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { IsBusy = true; // Cancel any outstanding Tasks _gpTask.CancelAsync(); // Get the GraphicsLayer GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); e.MapPoint.SpatialReference = MyMap.SpatialReference; // Add a graphic at the click point Graphic graphic = new ESRI.ArcGIS.Client.Graphic() { Geometry = e.MapPoint, Symbol = LayoutRoot.Resources["DefaultClickSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; graphic.SetZIndex(1); graphicsLayer.Graphics.Add(graphic); // Create the graphic to submit. Graphic g = new Graphic() { Geometry = _mercator.ToGeographic(e.MapPoint) }; // Create a new list of GP Parameters List<GPParameter> gpParams = new List<GPParameter>(); // We want to specify input attributes - create a new FeatureSet. FeatureSet featureSet = new FeatureSet(); // Create the Fields and add one called "VALUE". featureSet.Fields = new List<Field> { new Field() { FieldName = "VALUE", Type = Field.FieldType.String, Alias = "VALUE" } }; //var fs = new FeatureSet(new List<Graphic> { g }); // Add the graphic to the FeatureSet featureSet.Features.Add(g); // Set the graphic's attribute featureSet.Features[0].Attributes["VALUE"] = valueText.Text; // Add the GP Paramr gpParams.Add(new GPFeatureRecordSetLayer("InputFeatures", featureSet)); gpParams.Add(new GPLinearUnit("Distance", esriUnits.esriKilometers, 500)); // Register an inline handler for ExecuteCompleted event _gpTask.ExecuteCompleted += (s, e1) => { // Clear the graphics layer (will remove the input Pushpin) graphicsLayer.Graphics.Clear(); // Get the results GPExecuteResults results = e1.Results; GPFeatureRecordSetLayer rs = results.OutParameters[0] as GPFeatureRecordSetLayer; // Get the result feature Graphic graphicBuff = rs.FeatureSet.Features[0]; // Set the symbol graphicBuff.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; // Add to the layer graphicsLayer.Graphics.Add(graphicBuff); // Stop the progress bar IsBusy = false; }; // Register an inline handler for the failed event (just in case) _gpTask.Failed += (s2, e2) => { MessageBox.Show(e2.Error.Message); IsBusy = false; }; // Execute the Buffer asynchronously _gpTask.ExecuteAsync(gpParams); }
/// <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) { 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 = "AircraftCommunicationGraphics"; 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("/AircraftCommunicationCoverageAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute); client.Graphic graphic = new client.Graphic(); //graphic.Geometry = pt; graphic.Geometry = clickPoint; graphic.Symbol = mydictionary["RedPin"] as client.Symbols.MarkerSymbol; _graphicsLayer.Graphics.Add(graphic); if (_graphicsLayer != null && _graphicsLayerPoly != null) if (_graphicsLayer.Graphics.Count() > 0 && _graphicsLayerPoly.Graphics.Count() > 0) RunButton.IsEnabled = true; }