private void DrawObject_DrawComplete(object sender, DrawEventArgs e) { if (this.DrawWidget == this.GetType()) { string viewURL = ""; MapPoint point = e.Geometry as MapPoint; AddLocationGraphic(point); if (GeometryTool.IsGeographicSR(this.MapSRWKID)) { viewURL = GetViewContentURL(point.X, point.Y); OpenSteetViewWindow(viewURL); } if (GeometryTool.IsWebMercatorSR(this.MapSRWKID)) { point = point.WebMercatorToGeographic(); viewURL = GetViewContentURL(point.X, point.Y); OpenSteetViewWindow(viewURL); } else { if (geoService == null) { geoService = new GeometryService(this.AppConfig.GeometryService); geoService.ProjectCompleted += new EventHandler <GraphicsEventArgs>(GeometryService_ProjectCompleted); } geoService.ProjectAsync(this.GraphicsLayer.Graphics, new SpatialReference(2446)); } } }
/// <summary> /// Projects the input geometry to WGS 84 /// </summary> private void ProjectGeometry(Geometry geometry) { // Geometry requires reprojection. Ensure geometry service is specified. if (string.IsNullOrEmpty(GeometryServiceUrl)) { throw new Exception(Strings.GeometryServiceNotSpecified); } // Initialize geometry service object if necessary if (_geometryService == null) { _geometryService = new GeometryService(GeometryServiceUrl); _geometryService.ProjectCompleted += GeometryService_ProjectCompleted; _geometryService.Failed += GeometryService_Failed; _outSpatialRef = new SpatialReference(4326); } // Project the geometry using the geometry service Graphic g = new Graphic() { Geometry = geometry }; // if a previous projection is still executing, cancel it if (_geometryService.IsBusy) { _geometryService.CancelAsync(); } _geometryService.ProjectAsync(new Graphic[] { g }, _outSpatialRef); }
public static void ProjectEnvelope(string geometryServiceUrl, Envelope srcEnvelope, int outSRWKID, ProjectionEventHandler callback) { GeometryService geometryService = new GeometryService(geometryServiceUrl); geometryService.Failed += (obj, arg) => { if (callback != null) { callback(null, new ProjectionEventArgs(arg.Error.Message)); } }; geometryService.ProjectCompleted += (obj, arg) => { if (arg.Results.Count > 0) { Envelope resultEnvelope = arg.Results[0].Geometry as Envelope; if (callback != null) { callback(null, new ProjectionEventArgs(resultEnvelope)); } } }; List <Graphic> graphics = new List <Graphic>(); graphics.Add(new Graphic() { Geometry = srcEnvelope }); geometryService.ProjectAsync(graphics, new SpatialReference(outSRWKID)); }
void SetMapConstraint() { if (AssociatedObject == null) { return; } if (_constrainedExtent == null || _constrainedExtent.SpatialReference == null) { return; } SpatialReference mapSpatialRef = AssociatedObject.SpatialReference; // If the layer's spatial reference matches the map's, set the constraint extent if ((_constrainedExtent.SpatialReference.WKID > 0 && _constrainedExtent.SpatialReference.WKID == mapSpatialRef.WKID) || (!string.IsNullOrEmpty(_constrainedExtent.SpatialReference.WKT) && _constrainedExtent.SpatialReference.WKT == mapSpatialRef.WKT)) { if (!_constrainedExtent.Equals(ConstrainedExtent)) { ConstrainedExtent = _constrainedExtent; } } else { // Otherwise, use a geometry service to project the extent if (MapApplication.Current == null || MapApplication.Current.Urls == null || String.IsNullOrEmpty(MapApplication.Current.Urls.GeometryServiceUrl)) { return; } GeometryService geometryService = new GeometryService(MapApplication.Current.Urls.GeometryServiceUrl); geometryService.ProjectCompleted += (o, e1) => { Envelope newExtent = null; if (e1.Results != null && e1.Results.Count > 0 && e1.Results[0].Geometry != null) { newExtent = e1.Results[0].Geometry.Extent; } if (!newExtent.Equals(ConstrainedExtent)) { ConstrainedExtent = newExtent; } }; geometryService.Failed += (o, e1) => { NotificationPanel.Instance.AddNotification("Reprojecting extent of ConstrainExtentBehavior failed", "Failed to project the specified extent into the map's spatial reference.", string.Format("{0}\n\n{1}", e1.Error.Message, e1.Error.StackTrace), MessageType.Warning); }; geometryService.ProjectAsync(new Graphic[] { new Graphic() { Geometry = _constrainedExtent } }, mapSpatialRef); } }
protected override void Invoke(object parameter) { // Reset error Error = null; try { if (Target != null && OutputSpatialReference != null) { if (Target.SpatialReference == OutputSpatialReference || (Target.SpatialReference.IsWebMercator() && OutputSpatialReference.IsWebMercator())) { // Input geometry and output spatial reference define the // same projection. Assign input to output and complete. OutputGeometry = Target; OnCompleted(); } else if (Target.SpatialReference.IsWebMercator() && OutputSpatialReference.WKID == 4326) { // Web Mercator to WGS 84 can be done client-side OutputGeometry = new WebMercator().ToGeographic(Target); OnCompleted(); } else if (Target.SpatialReference.WKID == 4326 && OutputSpatialReference.IsWebMercator()) { // WGS 84 to Web Mercator can be done client-side OutputGeometry = new WebMercator().FromGeographic(Target); OnCompleted(); } else if (!string.IsNullOrEmpty(GeometryServiceUrl)) // Need to use geometry service { Graphic g = new Graphic() { Geometry = Target }; // if a previous project operation is still running, cancel it if (_geometryService.IsBusy) { _geometryService.CancelAsync(); } _geometryService.ProjectAsync(new Graphic[] { g }, OutputSpatialReference); } else // input not valid { OnFailed(new Exception(Strings.ProjectInputsNotValid)); } } } catch (Exception ex) { OnFailed(ex); } }
protected virtual void OnResultReady(List <LocationCandidate> candidates, int srWKID, bool reverse) { if (srWKID == this.outSRWKID) { if (ResultReady != null) { ResultReady(this, new GeocodeResultEventArgs(candidates, reverse)); } } else if (GeometryTool.IsGeographicSR(srWKID) && GeometryTool.IsWebMercatorSR(this.outSRWKID)) { foreach (LocationCandidate candidate in candidates) { candidate.Location.SpatialReference = new SpatialReference(srWKID); candidate.Location = candidate.Location.GeographicToWebMercator(); } if (ResultReady != null) { ResultReady(this, new GeocodeResultEventArgs(candidates, reverse)); } } else if (GeometryTool.IsWebMercatorSR(srWKID) && GeometryTool.IsGeographicSR(this.outSRWKID)) { foreach (LocationCandidate candidate in candidates) { candidate.Location.SpatialReference = new SpatialReference(srWKID); candidate.Location = candidate.Location.WebMercatorToGeographic(); } if (ResultReady != null) { ResultReady(this, new GeocodeResultEventArgs(candidates, reverse)); } } else { List <Graphic> locGraphics = new List <Graphic>(); foreach (LocationCandidate candidate in candidates) { Graphic graphic = new Graphic(); candidate.Location.SpatialReference = new SpatialReference(srWKID); graphic.Geometry = candidate.Location; locGraphics.Add(graphic); } isReverse = reverse; lastResults = candidates; // Save to pass GeometryService geometryService = new GeometryService(geoServiceUrl); geometryService.ProjectCompleted += new EventHandler <GraphicsEventArgs>(GeometryService_ProjectCompleted); geometryService.Failed += new EventHandler <TaskFailedEventArgs>(GeometryService_Failed); // Use a UserToken to avoid it execute other projection complete handlers geometryService.ProjectAsync(locGraphics, new SpatialReference(this.outSRWKID)); } }
public MainWindow() { // License setting and ArcGIS Runtime initialization is done in Application.xaml.cs. //Converting from WGS1984(WKID4326) to Web Mercator(WKID 102100) //Expected output: //outstring "contains 9 points\n //-16760359.2704728 17285613.0087787\n //-47750.2729367931 -382002.488729203\n //18479370.4320312 -18240618.8875065\n //18192868.5717715 16999110.8145016\n //-15900853.6896935 -17476613.9857872\n //-10552818.7793126 10696069.8481236\n //12653832.4583238 10791570.3324641\n //-9979815.0587931 -11937577.7150823\n //13417837.4932295 -11651075.9091873\n InitializeComponent(); geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += geometryService_ProjectCompleted; geometryService.Failed += geometryService_Failed; graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; List<Graphic> listgraphic = new List<Graphic>(); MapPoint inp1 = new MapPoint(-150.560869, 82.387691, new SpatialReference(4326)); MapPoint inp2 = new MapPoint(-0.428948, -3.429537, new SpatialReference(4326)); MapPoint inp3 = new MapPoint(166.003009, -83.443769, new SpatialReference(4326)); MapPoint inp4 = new MapPoint(163.429319, 82.039054, new SpatialReference(4326)); MapPoint inp5 = new MapPoint(-142.839799, -82.61164, new SpatialReference(4326)); MapPoint inp6 = new MapPoint(-94.797584, 68.823145, new SpatialReference(4326)); MapPoint inp7 = new MapPoint(113.671311, 69.130903, new SpatialReference(4326)); MapPoint inp8 = new MapPoint(-89.650204, -72.504886, new SpatialReference(4326)); MapPoint inp9 = new MapPoint(120.534485, -71.714384, new SpatialReference(4326)); listgraphic.Add(new Graphic() { Geometry = inp1 }); listgraphic.Add(new Graphic() { Geometry = inp2 }); listgraphic.Add(new Graphic() { Geometry = inp3 }); listgraphic.Add(new Graphic() { Geometry = inp4 }); listgraphic.Add(new Graphic() { Geometry = inp5 }); listgraphic.Add(new Graphic() { Geometry = inp6 }); listgraphic.Add(new Graphic() { Geometry = inp7 }); listgraphic.Add(new Graphic() { Geometry = inp8 }); listgraphic.Add(new Graphic() { Geometry = inp9 }); geometryService.ProjectAsync(listgraphic, new SpatialReference(102100)); }
private void ProjectButton_Click(object sender, System.Windows.RoutedEventArgs e) { double x; double y; if (!double.TryParse(XTextBox.Text, out x) || !double.TryParse(YTextBox.Text, out y)) { MessageBox.Show("Enter valid coordinate values."); return; } MapPoint inputMapPoint = new MapPoint(x, y, new SpatialReference(4326)); geometryService.ProjectAsync(new List <Graphic>() { new Graphic() { Geometry = inputMapPoint } }, MyMap.SpatialReference, inputMapPoint); }
private void DoMesurement(Graphic graphic) { List <Graphic> graphicList = new List <Graphic>(); graphicList.Add(graphic); if (widgetConfig.AlwaysProject || this.CurrentPage.MapUnits == ScaleLine.ScaleLineUnit.DecimalDegrees) { geometryService.ProjectAsync(graphicList, new SpatialReference(widgetConfig.ProjectToWKID)); } else { switch (this.measurementMode) { case MODE_LENGTH: geometryService.LengthsAsync(graphicList, this.CurrentPage.MapUnits); break; case MODE_AREA: geometryService.AreasAndLengthsAsync(graphicList, this.CurrentPage.MapUnits); break; } } }
void geoprocessorTask_GetResultDataCompleted(object sender, GPParameterEventArgs gpParameterEventArgs) { // Get the result features from the parameter GPFeatureRecordSetLayer gpLayer; gpLayer = gpParameterEventArgs.Parameter as GPFeatureRecordSetLayer; // Check the parameter name, reproject and add to the appropriate graphics layer. // again - two separate tasks are created allowing them to run conncurrently. switch (gpParameterEventArgs.Parameter.Name) { case "Sysvalves_Layer": GeometryService valvesProjectTask = new GeometryService(localGeometryService.UrlGeometryService); valvesProjectTask.ProjectCompleted += (sender2, graphicsEventArgs) => { valvesGraphicsLayer.Graphics.AddRange(graphicsEventArgs.Results); }; valvesProjectTask.ProjectAsync(gpLayer.FeatureSet.Features, new SpatialReference(3857)); break; case "DistribMains_Layer": GeometryService mainsProjectTask = new GeometryService(localGeometryService.UrlGeometryService); mainsProjectTask.ProjectCompleted += (sender2, graphicsEventArgs) => { mainsGraphicsLayer.Graphics.AddRange(graphicsEventArgs.Results); }; mainsProjectTask.ProjectAsync(gpLayer.FeatureSet.Features, new SpatialReference(3857)); break; } }
// Raised when a property of the map changes. Used to check whether map units have changed. private void Map_PropertyChanged(object sender, PropertyChangedEventArgs e) { Map map = ((Map)sender); if (map.SpatialReference.WKID != _spatialRefWKID) { _gotMapUnits = false; _spatialRefWKID = map.SpatialReference.WKID; // Spatial reference has changed, so determine map units if (map.Layers.Count > 0) { map.GetMapUnitsAsync(OnGetMapUnitsCompleted, OnGetMapUnitsFailed); } else { NotifyCollectionChangedEventHandler collectionChanged = null; collectionChanged = (o, args) => { if (map.Layers.Count > 0) { map.Layers.CollectionChanged -= collectionChanged; map.GetMapUnitsAsync(OnGetMapUnitsCompleted, OnGetMapUnitsFailed); } }; map.Layers.CollectionChanged += collectionChanged; } // handle case where map's spatial reference has changed while there are results. Projection // of results will need to be changed to match that of the map. if (_results.Count > 0) { SpatialReference oldSRef = new SpatialReference(_spatialRefWKID); if (oldSRef.IsWebMercator() && map.SpatialReference.IsGeographic()) { // Transform result extents from Web Mercator to Geographic WGS 84 WebMercator mercator = new WebMercator(); foreach (LocatorResultViewModel result in _results) { result.Extent = (Envelope)mercator.ToGeographic(result.Extent); AddressCandidate oldCandidate = result.Candidate; MapPoint newLocation = (MapPoint)mercator.ToGeographic(result.Candidate.Location); result.Candidate = new AddressCandidate(oldCandidate.Address, newLocation, oldCandidate.Score, oldCandidate.Attributes); } } else if (oldSRef.IsGeographic() && map.SpatialReference.IsWebMercator()) { // Transform result exstents from Geographic WGS 84 to Web Mercator WebMercator mercator = new WebMercator(); foreach (LocatorResultViewModel result in _results) { result.Extent = (Envelope)mercator.FromGeographic(result.Extent); AddressCandidate oldCandidate = result.Candidate; MapPoint newLocation = (MapPoint)mercator.FromGeographic(result.Candidate.Location); result.Candidate = new AddressCandidate(oldCandidate.Address, newLocation, oldCandidate.Score, oldCandidate.Attributes); } } else if (!string.IsNullOrEmpty(GeometryServiceUrl)) { // Use a geometry service to project the result extents List<LocatorResultViewModel> resultsToProject = new List<LocatorResultViewModel>(); List<Graphic> extentsToProject = new List<Graphic>(); List<Graphic> locationsToProject = new List<Graphic>(); foreach (LocatorResultViewModel result in _results) { // Copy the results to a new collection (list) - necessary because the results // could change during the project operation, so maintaining these in a separate // collection ensures that the updated extents are applied to the proper results resultsToProject.Add(result); // Get the geometries to project. Both extent and candidate location must be re-projected. extentsToProject.Add(new Graphic() { Geometry = result.Extent }); locationsToProject.Add(new Graphic() { Geometry = result.Candidate.Location }); } GeometryService geomService = new GeometryService(GeometryServiceUrl); GeometryService geomService2 = new GeometryService(GeometryServiceUrl); EventHandler<GraphicsEventArgs> projectExtentsCompleted = null; EventHandler<GraphicsEventArgs> projectLocationsCompleted = null; EventHandler<TaskFailedEventArgs> projectFailed = null; // Update the result extents when the projection completes projectExtentsCompleted = (o, args) => { geomService.ProjectCompleted -= projectExtentsCompleted; geomService.Failed -= projectFailed; int count = args.Results.Count; for (int i = 0; i < count; i++) resultsToProject[i].Extent = (Envelope)args.Results[i].Geometry; }; // Update the result locations when the projection completes projectLocationsCompleted = (o, args) => { geomService2.ProjectCompleted -= projectLocationsCompleted; geomService2.Failed -= projectFailed; int count = args.Results.Count; LocatorResultViewModel result = null; for (int i = 0; i < count; i++) { result = resultsToProject[i]; AddressCandidate oldCandidate = result.Candidate; MapPoint newLocation = (MapPoint)args.Results[i].Geometry; result.Candidate = new AddressCandidate(oldCandidate.Address, newLocation, oldCandidate.Score, oldCandidate.Attributes); } }; // Just clear the results and remove handlers if the projection fails projectFailed = (o, args) => { geomService.ProjectCompleted -= projectExtentsCompleted; geomService.Failed -= projectFailed; geomService2.ProjectCompleted -= projectLocationsCompleted; geomService2.Failed -= projectFailed; _results.Clear(); }; geomService.ProjectCompleted += projectExtentsCompleted; geomService.Failed += projectFailed; geomService2.ProjectCompleted += projectLocationsCompleted; geomService2.Failed += projectFailed; geomService.ProjectAsync(extentsToProject, map.SpatialReference); geomService2.ProjectAsync(locationsToProject, map.SpatialReference); } } } }
private void ShowProjectedExtent(Map thisMap) { if (thisMap != null) System.Console.WriteLine("Current extent {0}", thisMap.Extent); if (_xmlConfiguation.OutputSpatialReference == null || thisMap == null) return; // if we are in Web Mercator, project the extent back into the output spatial reference. // // This is for debugging only. GeometryService geometryServiceProject = new GeometryService(_xmlConfiguation.GeometryServerUrl); if (geometryServiceProject == null) return; geometryServiceProject.ProjectCompleted += GeometryService_CalculateOutputCoords; geometryServiceProject.Failed += GeometryService_FailedWebMercatorScale; geometryServiceProject.CancelAsync(); var graphicList = new List<Graphic>(); double x = thisMap.Extent.XMin; double y = thisMap.Extent.YMin; MapPoint minPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic minGraphic = new Graphic(); minGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; minGraphic.Geometry = minPoint; graphicList.Add(minGraphic); x = thisMap.Extent.XMax; y = thisMap.Extent.YMax; MapPoint maxPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic maxGraphic = new Graphic(); maxGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; maxGraphic.Geometry = maxPoint; graphicList.Add(maxGraphic); if (_xmlConfiguation.HasDatumTransformation) { DatumTransform transformation = new DatumTransform(); if (_xmlConfiguation.DatumTransformationWKID > 0) transformation.WKID = _xmlConfiguation.DatumTransformationWKID; else transformation.WKT = _xmlConfiguation.DatumTransformationWKT; geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference, transformation, _xmlConfiguation.DatumTransformationForward); } else geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference); }
private void handleGeographicResults(List<LocatorResultViewModel> results) { WebMercator mercator = new WebMercator(); MapPoint extentCenter = null; double extentHeight = _extentWidthInMapUnits / 3; if (results[0].Candidate.Location.SpatialReference.IsGeographic()) { foreach (LocatorResultViewModel result in results) { extentCenter = (MapPoint)mercator.FromGeographic(result.Candidate.Location); Envelope extentInMeters = extentCenter.ToEnvelope(_extentWidthInMapUnits, extentHeight); result.Extent = (Envelope)mercator.ToGeographic(extentInMeters); _results.Add(result); } // Refresh paged collection to update pagination PagedResults.Refresh(); IsSearching = false; // Reset busy state OnSearchCompleted(); // Raise completed event } else if (!string.IsNullOrEmpty(GeometryServiceUrl)) { GeometryService geomService = new GeometryService(GeometryServiceUrl); List<Graphic> graphicsToProject = new List<Graphic>(); foreach (LocatorResultViewModel result in results) graphicsToProject.Add(new Graphic() { Geometry = result.Candidate.Location }); EventHandler<GraphicsEventArgs> projectCompleted = null; EventHandler<TaskFailedEventArgs> projectFailed = null; projectCompleted = (o, e) => { geomService.ProjectCompleted -= projectCompleted; graphicsToProject.Clear(); foreach (Graphic g in e.Results) { extentCenter = (MapPoint)g.Geometry; Envelope extentInMeters = extentCenter.ToEnvelope(_extentWidthInMapUnits, extentHeight); graphicsToProject.Add(new Graphic() { Geometry = extentInMeters }); } projectCompleted = (s, a) => { geomService.ProjectCompleted -= projectCompleted; geomService.Failed -= projectFailed; for (int i = 0; i < a.Results.Count; i++) { LocatorResultViewModel result = results[i]; result.Extent = (Envelope)a.Results[i].Geometry; _results.Add(result); } // Refresh paged collection to update pagination PagedResults.Refresh(); IsSearching = false; // Reset busy state OnSearchCompleted(); // Raise completed event }; geomService.ProjectCompleted += projectCompleted; // Project extents into map spatial reference geomService.ProjectAsync(graphicsToProject, _map.SpatialReference); }; projectFailed = (o, e) => { geomService.ProjectCompleted -= projectCompleted; geomService.Failed -= projectFailed; // Refresh paged collection to update pagination PagedResults.Refresh(); IsSearching = false; // Reset busy state OnSearchCompleted(); // Raise completed event }; geomService.ProjectCompleted += projectCompleted; geomService.Failed += projectFailed; // Project result locations to web mercator geomService.ProjectAsync(graphicsToProject, new SpatialReference(3857)); } }
private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { _candidateGraphicsLayer.Graphics.Clear(); CandidateListBox.Items.Clear(); List<AddressCandidate> returnedCandidates = args.Results; foreach (AddressCandidate candidate in returnedCandidates) { if (candidate.Score >= 80) { CandidateListBox.Items.Add(candidate.Address); Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = candidate.Location }; graphic.Attributes.Add("Address", candidate.Address); string latlon = String.Format("{0}, {1}", candidate.Location.X, candidate.Location.Y); graphic.Attributes.Add("LatLon", latlon); if (candidate.Location.SpatialReference == null) { candidate.Location.SpatialReference = new SpatialReference(4326); } if (!candidate.Location.SpatialReference.Equals(MyMap.SpatialReference)) { if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) && candidate.Location.SpatialReference.Equals(new SpatialReference(4326))) graphic.Geometry = _mercator.FromGeographic(graphic.Geometry); else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) && candidate.Location.SpatialReference.Equals(new SpatialReference(102100))) graphic.Geometry = _mercator.ToGeographic(graphic.Geometry); else if (MyMap.SpatialReference != new SpatialReference(4326)) { GeometryService geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += (s, a) => { graphic.Geometry = a.Results[0].Geometry; }; geometryService.Failed += (s, a) => { MessageBox.Show("Projection error: " + a.Error.Message); }; geometryService.ProjectAsync(new List<Graphic> { graphic }, MyMap.SpatialReference); } } _candidateGraphicsLayer.Graphics.Add(graphic); } } if (_candidateGraphicsLayer.Graphics.Count > 0) { CandidatePanelGrid.Visibility = Visibility.Visible; CandidateListBox.SelectedIndex = 0; } }
void projectGraphicsAsync(string geometryServiceUrl, IList <Graphic> graphics, SpatialReference outputSpatialReference, ProjectCompleteDelegate onProjectGeometryComplete, object userState) { if (graphics == null) { throw new ArgumentNullException("graphics"); } if (graphics.Count < 1) { OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = graphics }); return; } if (outputSpatialReference.WKID == 4326 && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && isWebMercator(g.Geometry.SpatialReference))) { // Project from web mercator to GCS client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List <Graphic> outGraphics = new List <Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.ToGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else if (isWebMercator(outputSpatialReference) && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && g.Geometry.SpatialReference.WKID == 4326)) { // Project from GCS to web mercator client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List <Graphic> outGraphics = new List <Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.FromGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else { GeometryService geomService = new GeometryService(geometryServiceUrl) { ProxyURL = this.ProxyUrl }; geomService.ProjectCompleted += (o, e) => { int len1 = graphics.Count; int len2 = e.Results.Count; System.Diagnostics.Debug.Assert(len1 == len2, Resources.Strings.ExceptionNumberofGraphicsBeforeAndAfterProjectionAreNotEqual); for (int i = 0; i < len1 && i < len2; i++) { var targetGraphic = cloneGraphic(graphics[i]); targetGraphic.Geometry = e.Results[i].Geometry; e.Results[i] = targetGraphic; } onProjectGeometryComplete(o, e); }; geomService.Failed += (o, e) => { if ((e.Error is ESRI.ArcGIS.Client.Tasks.ServiceException || e.Error is System.Net.WebException) && geometryServiceUrl != FallbackGeometryServer) { projectGraphicsAsync(FallbackGeometryServer, graphics, outputSpatialReference, onProjectGeometryComplete, e.UserState); } else { OnGeometryServiceOperationFailed(new ExceptionEventArgs(new Exception(e.Error == null ? e.Error.Message : ""), e.UserState)); } }; geomService.ProjectAsync(graphics, outputSpatialReference, userState); } }
void geoprocessorTask_GetResultDataCompleted(object sender, GPParameterEventArgs gpParameterEventArgs) { // Get the result features from the parameter GPFeatureRecordSetLayer gpLayer; gpLayer = gpParameterEventArgs.Parameter as GPFeatureRecordSetLayer; // Check the parameter name, reproject and add to the appropriate graphics layer. // again - two separate tasks are created allowing them to run conncurrently. switch (gpParameterEventArgs.Parameter.Name) { case "Sysvalves_Layer": GeometryService valvesProjectTask = new GeometryService(localGeometryService.UrlGeometryService); valvesProjectTask.ProjectCompleted += (sender2, graphicsEventArgs) => { valvesGraphicsLayer.Graphics.AddRange(graphicsEventArgs.Results); }; valvesProjectTask.ProjectAsync(gpLayer.FeatureSet.Features, new SpatialReference(3857)); break; case "DistribMains_Layer": GeometryService mainsProjectTask = new GeometryService(localGeometryService.UrlGeometryService); mainsProjectTask.ProjectCompleted += (sender2, graphicsEventArgs) => { mainsGraphicsLayer.Graphics.AddRange(graphicsEventArgs.Results); }; mainsProjectTask.ProjectAsync(gpLayer.FeatureSet.Features, new SpatialReference(3857)); break; } }
public MainWindow() { // License setting and ArcGIS Runtime initialization is done in Application.xaml.cs. //Converting from WGS1984(WKID4326) to Web Mercator(WKID 102100) //Expected output: //outstring "contains 9 points\n //-16760359.2704728 17285613.0087787\n //-47750.2729367931 -382002.488729203\n //18479370.4320312 -18240618.8875065\n //18192868.5717715 16999110.8145016\n //-15900853.6896935 -17476613.9857872\n //-10552818.7793126 10696069.8481236\n //12653832.4583238 10791570.3324641\n //-9979815.0587931 -11937577.7150823\n //13417837.4932295 -11651075.9091873\n InitializeComponent(); geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += geometryService_ProjectCompleted; geometryService.Failed += geometryService_Failed; graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; List <Graphic> listgraphic = new List <Graphic>(); MapPoint inp1 = new MapPoint(-150.560869, 82.387691, new SpatialReference(4326)); MapPoint inp2 = new MapPoint(-0.428948, -3.429537, new SpatialReference(4326)); MapPoint inp3 = new MapPoint(166.003009, -83.443769, new SpatialReference(4326)); MapPoint inp4 = new MapPoint(163.429319, 82.039054, new SpatialReference(4326)); MapPoint inp5 = new MapPoint(-142.839799, -82.61164, new SpatialReference(4326)); MapPoint inp6 = new MapPoint(-94.797584, 68.823145, new SpatialReference(4326)); MapPoint inp7 = new MapPoint(113.671311, 69.130903, new SpatialReference(4326)); MapPoint inp8 = new MapPoint(-89.650204, -72.504886, new SpatialReference(4326)); MapPoint inp9 = new MapPoint(120.534485, -71.714384, new SpatialReference(4326)); listgraphic.Add(new Graphic() { Geometry = inp1 }); listgraphic.Add(new Graphic() { Geometry = inp2 }); listgraphic.Add(new Graphic() { Geometry = inp3 }); listgraphic.Add(new Graphic() { Geometry = inp4 }); listgraphic.Add(new Graphic() { Geometry = inp5 }); listgraphic.Add(new Graphic() { Geometry = inp6 }); listgraphic.Add(new Graphic() { Geometry = inp7 }); listgraphic.Add(new Graphic() { Geometry = inp8 }); listgraphic.Add(new Graphic() { Geometry = inp9 }); geometryService.ProjectAsync(listgraphic, new SpatialReference(102100)); }
private void ShowProjectedExtent(Map thisMap) { if (thisMap != null) { System.Console.WriteLine("Current extent {0}", thisMap.Extent); } if (_xmlConfiguation.OutputSpatialReference == null || thisMap == null) { return; } // if we are in Web Mercator, project the extent back into the output spatial reference. // // This is for debugging only. GeometryService geometryServiceProject = new GeometryService(_xmlConfiguation.GeometryServerUrl); if (geometryServiceProject == null) { return; } geometryServiceProject.ProjectCompleted += GeometryService_CalculateOutputCoords; geometryServiceProject.Failed += GeometryService_FailedWebMercatorScale; geometryServiceProject.CancelAsync(); var graphicList = new List <Graphic>(); double x = thisMap.Extent.XMin; double y = thisMap.Extent.YMin; MapPoint minPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic minGraphic = new Graphic(); minGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; minGraphic.Geometry = minPoint; graphicList.Add(minGraphic); x = thisMap.Extent.XMax; y = thisMap.Extent.YMax; MapPoint maxPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic maxGraphic = new Graphic(); maxGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; maxGraphic.Geometry = maxPoint; graphicList.Add(maxGraphic); if (_xmlConfiguation.HasDatumTransformation) { DatumTransform transformation = new DatumTransform(); if (_xmlConfiguation.DatumTransformationWKID > 0) { transformation.WKID = _xmlConfiguation.DatumTransformationWKID; } else { transformation.WKT = _xmlConfiguation.DatumTransformationWKT; } geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference, transformation, _xmlConfiguation.DatumTransformationForward); } else { geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference); } }
void projectGraphicsAsync(string geometryServiceUrl, IList<Graphic> graphics, SpatialReference outputSpatialReference, ProjectCompleteDelegate onProjectGeometryComplete, object userState) { if (graphics == null) throw new ArgumentNullException("graphics"); if (graphics.Count < 1) { OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = graphics }); return; } if (outputSpatialReference.WKID == 4326 && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && isWebMercator(g.Geometry.SpatialReference))) { // Project from web mercator to GCS client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List<Graphic> outGraphics = new List<Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.ToGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else if (isWebMercator(outputSpatialReference) && graphics.All(g => g.Geometry != null && g.Geometry.SpatialReference != null && g.Geometry.SpatialReference.WKID == 4326)) { // Project from GCS to web mercator client-side var wm = new ESRI.ArcGIS.Client.Projection.WebMercator(); List<Graphic> outGraphics = new List<Graphic>(); foreach (var g in graphics) { var outGraphic = cloneGraphic(g); outGraphic.Geometry = wm.FromGeographic(g.Geometry); outGraphics.Add(outGraphic); } OnProjectExtentComplete(new ProjectGraphicsCompletedEventArgs() { Graphics = outGraphics }); } else { GeometryService geomService = new GeometryService(geometryServiceUrl) { ProxyURL = this.ProxyUrl }; geomService.ProjectCompleted += (o, e) => { int len1 = graphics.Count; int len2 = e.Results.Count; System.Diagnostics.Debug.Assert(len1 == len2, Resources.Strings.ExceptionNumberofGraphicsBeforeAndAfterProjectionAreNotEqual); for (int i = 0; i < len1 && i < len2; i++) { var targetGraphic = cloneGraphic(graphics[i]); targetGraphic.Geometry = e.Results[i].Geometry; e.Results[i] = targetGraphic; } onProjectGeometryComplete(o, e); }; geomService.Failed += (o, e) => { if ((e.Error is ESRI.ArcGIS.Client.Tasks.ServiceException || e.Error is System.Net.WebException) && geometryServiceUrl != FallbackGeometryServer) { projectGraphicsAsync(FallbackGeometryServer, graphics, outputSpatialReference, onProjectGeometryComplete, e.UserState); } else { OnGeometryServiceOperationFailed(new ExceptionEventArgs(new Exception(e.Error == null ? e.Error.Message : ""), e.UserState)); } }; geomService.ProjectAsync(graphics, outputSpatialReference, userState); } }
} // public void userGiveCSVLayerParams(string url, string lyrname, string proxy) /// <summary> /// Call from form, add to map graphicslayer from json /// </summary> /// <param name="url"></param> /// <param name="lyrname"></param> /// <param name="proxy"></param> public void userGiveJSONLayerParams(string url, string lyrname, string proxy) { log(string.Format("userGiveJSONLayerParams, name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname)); MapApplication.Current.HideWindow(jsonParamsForm); var requrl = string.IsNullOrEmpty(proxy) ? url : string.Format("{0}?{1}", proxy, url); // get json text WebClient wc = new WebClient(); Uri uri = new Uri(requrl, UriKind.RelativeOrAbsolute); wc.OpenReadCompleted += (sender, args) => { if (args.Error != null) { log(String.Format("userGiveJSONLayerParams wc_OpenReadCompleted, error in reading answer, msg [{0}], trace [{1}]", args.Error.Message, args.Error.StackTrace)); } else { try { StreamReader reader = new StreamReader(args.Result); string text = reader.ReadToEnd(); log(string.Format("userGiveJSONLayerParams wc_OpenReadCompleted, resp '{0}'", text)); // got layer content, make layer var featureSet = FeatureSet.FromJson(text); var graphicsLayer = new GraphicsLayer() { Graphics = new GraphicCollection(featureSet) }; // set layer params graphicsLayer.Opacity = 1; graphicsLayer.ID = VExtClass.computeSHA1Hash(string.Format("{0}", text)); graphicsLayer.Initialized += (osender, eargs) => { log(string.Format("userGiveJSONLayerParams.Initialized, {0}-{1}", lyrname, graphicsLayer.ID)); }; // projection var MyMap = MapApplication.Current.Map; var mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); if (!featureSet.SpatialReference.Equals(MyMap.SpatialReference)) { if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) && featureSet.SpatialReference.Equals(new SpatialReference(4326))) { foreach (Graphic g in graphicsLayer.Graphics) { g.Geometry = mercator.FromGeographic(g.Geometry); } } else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) && featureSet.SpatialReference.Equals(new SpatialReference(102100))) { foreach (Graphic g in graphicsLayer.Graphics) { g.Geometry = mercator.ToGeographic(g.Geometry); } } else { var geometryService = new GeometryService( "http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += (s, a) => { for (int i = 0; i < a.Results.Count; i++) { graphicsLayer.Graphics[i].Geometry = a.Results[i].Geometry; } }; geometryService.Failed += (s, a) => { MessageBox.Show("Ошибка проецирования: " + a.Error.Message); }; geometryService.ProjectAsync(graphicsLayer.Graphics, MyMap.SpatialReference); } } // if map.SR != featureset.SR // add layer to map graphicsLayer.Initialize(); MapApplication.SetLayerName(graphicsLayer, lyrname); ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(graphicsLayer, true); MapApplication.Current.Map.Layers.Add(graphicsLayer); } // got json text catch (Exception ex) { log(String.Format("userGiveJSONLayerParams wc_OpenReadCompleted, make layer failed {0}, {1}", ex.Message, ex.StackTrace)); } } }; // wc.OpenReadCompleted wc.OpenReadAsync(uri); log(string.Format("userGiveJSONLayerParams, done for name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname)); } // public void userGiveJSONLayerParams(string url, string lyrname, string proxy)
private void Button_Load(object sender, System.Windows.RoutedEventArgs e) { try { FeatureSet featureSet = FeatureSet.FromJson(JsonTextBox.Text); GraphicsLayer graphicsLayerFromFeatureSet = new GraphicsLayer() { Graphics = new GraphicCollection(featureSet) }; if (!featureSet.SpatialReference.Equals(MyMap.SpatialReference)) { if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) && featureSet.SpatialReference.Equals(new SpatialReference(4326))) { foreach (Graphic g in graphicsLayerFromFeatureSet.Graphics) { g.Geometry = _mercator.FromGeographic(g.Geometry); } } else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) && featureSet.SpatialReference.Equals(new SpatialReference(102100))) { foreach (Graphic g in graphicsLayerFromFeatureSet.Graphics) { g.Geometry = _mercator.ToGeographic(g.Geometry); } } else { GeometryService geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += (s, a) => { for (int i = 0; i < a.Results.Count; i++) { graphicsLayerFromFeatureSet.Graphics[i].Geometry = a.Results[i].Geometry; } }; geometryService.Failed += (s, a) => { MessageBox.Show("Projection error: " + a.Error.Message); }; geometryService.ProjectAsync(graphicsLayerFromFeatureSet.Graphics, MyMap.SpatialReference); } } SimpleRenderer simpleRenderer = new SimpleRenderer(); SolidColorBrush symbolColor = new SolidColorBrush(Colors.Blue); graphicsLayerFromFeatureSet.Renderer = simpleRenderer; if (featureSet.GeometryType == GeometryType.Polygon || featureSet.GeometryType == GeometryType.Polygon) { simpleRenderer.Symbol = new SimpleFillSymbol() { Fill = symbolColor }; } else if (featureSet.GeometryType == GeometryType.Polyline) { simpleRenderer.Symbol = new SimpleLineSymbol() { Color = symbolColor }; } else // Point { simpleRenderer.Symbol = new SimpleMarkerSymbol() { Color = symbolColor, Size = 12 }; } myInfoWindow = new InfoWindow() { Background = new SolidColorBrush(Colors.Black), BorderBrush = new SolidColorBrush(Colors.White), BorderThickness = new Thickness(1), CornerRadius = 10, Map = MyMap, }; myInfoWindow.MouseLeftButtonDown += myInfoWindow_MouseLeftButtonDown; StackPanel stackPanelParent = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical, Margin = new Thickness(12) }; foreach (KeyValuePair <string, string> keyvalue in featureSet.FieldAliases) { StackPanel stackPanelChild = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal, Margin = new Thickness(0, 0, 0, 6) }; TextBlock textValue = new TextBlock() { Text = keyvalue.Value + ": " }; TextBlock textKey = new TextBlock(); Binding keyBinding = new Binding(string.Format("[{0}]", keyvalue.Key)); textKey.SetBinding(TextBlock.TextProperty, keyBinding); stackPanelChild.Children.Add(textValue); stackPanelChild.Children.Add(textKey); if (keyvalue.Key == featureSet.DisplayFieldName) { textKey.FontWeight = textValue.FontWeight = FontWeights.Bold; stackPanelParent.Children.Insert(0, stackPanelChild); } else { stackPanelParent.Children.Add(stackPanelChild); } } myInfoWindow.Content = stackPanelParent; ContentPanel.Children.Add(myInfoWindow); MyMap.Layers.Add(graphicsLayerFromFeatureSet); graphicsLayerFromFeatureSet.MouseLeftButtonDown += graphicsLayerFromFeatureSet_MouseLeftButtonDown; JsonPivot.Visibility = Visibility.Collapsed; } catch (Exception ex) { MessageBox.Show(ex.Message, "GraphicsLayer creation failed", MessageBoxButton.OK); } }
private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { _candidateGraphicsLayer.ClearGraphics(); CandidateListBox.Items.Clear(); List <AddressCandidate> returnedCandidates = args.Results; foreach (AddressCandidate candidate in returnedCandidates) { if (candidate.Score >= 80) { CandidateListBox.Items.Add(candidate.Address); Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = candidate.Location }; graphic.Attributes.Add("Address", candidate.Address); string latlon = String.Format("{0}, {1}", candidate.Location.X, candidate.Location.Y); graphic.Attributes.Add("LatLon", latlon); if (candidate.Location.SpatialReference == null) { candidate.Location.SpatialReference = new SpatialReference(4326); } if (!candidate.Location.SpatialReference.Equals(MyMap.SpatialReference)) { if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) && candidate.Location.SpatialReference.Equals(new SpatialReference(4326))) { graphic.Geometry = _mercator.FromGeographic(graphic.Geometry); } else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) && candidate.Location.SpatialReference.Equals(new SpatialReference(102100))) { graphic.Geometry = _mercator.ToGeographic(graphic.Geometry); } else if (MyMap.SpatialReference != new SpatialReference(4326)) { GeometryService geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += (s, a) => { graphic.Geometry = a.Results[0].Geometry; }; geometryService.Failed += (s, a) => { MessageBox.Show("Projection error: " + a.Error.Message); }; geometryService.ProjectAsync(new List <Graphic> { graphic }, MyMap.SpatialReference); } } _candidateGraphicsLayer.Graphics.Add(graphic); } } if (_candidateGraphicsLayer.Graphics.Count > 0) { CandidatePanelGrid.Visibility = Visibility.Visible; CandidateListBox.SelectedIndex = 0; } }
private void Button_Load(object sender, System.Windows.RoutedEventArgs e) { try { FeatureSet featureSet = FeatureSet.FromJson(JsonTextBox.Text); GraphicsLayer graphicsLayerFromFeatureSet = new GraphicsLayer() { Graphics = new GraphicCollection(featureSet) }; if (!featureSet.SpatialReference.Equals(MyMap.SpatialReference)) { if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) && featureSet.SpatialReference.Equals(new SpatialReference(4326))) foreach (Graphic g in graphicsLayerFromFeatureSet.Graphics) g.Geometry = _mercator.FromGeographic(g.Geometry); else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) && featureSet.SpatialReference.Equals(new SpatialReference(102100))) foreach (Graphic g in graphicsLayerFromFeatureSet.Graphics) g.Geometry = _mercator.ToGeographic(g.Geometry); else { GeometryService geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += (s, a) => { for (int i = 0; i < a.Results.Count; i++) graphicsLayerFromFeatureSet.Graphics[i].Geometry = a.Results[i].Geometry; }; geometryService.Failed += (s, a) => { MessageBox.Show("Projection error: " + a.Error.Message); }; geometryService.ProjectAsync(graphicsLayerFromFeatureSet.Graphics, MyMap.SpatialReference); } } SimpleRenderer simpleRenderer = new SimpleRenderer(); SolidColorBrush symbolColor = new SolidColorBrush(Colors.Blue); graphicsLayerFromFeatureSet.Renderer = simpleRenderer; if (featureSet.GeometryType == GeometryType.Polygon || featureSet.GeometryType == GeometryType.Polygon) { simpleRenderer.Symbol = new SimpleFillSymbol() { Fill = symbolColor }; } else if (featureSet.GeometryType == GeometryType.Polyline) { simpleRenderer.Symbol = new SimpleLineSymbol() { Color = symbolColor }; } else // Point { simpleRenderer.Symbol = new SimpleMarkerSymbol() { Color = symbolColor, Size = 12 }; } Border border = new Border() { Background = new SolidColorBrush(Colors.White), BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(10), Effect = new DropShadowEffect() }; StackPanel stackPanelParent = new StackPanel() { Orientation = Orientation.Vertical, Margin = new Thickness(12) }; foreach (KeyValuePair<string, string> keyvalue in featureSet.FieldAliases) { StackPanel stackPanelChild = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 0, 0, 6) }; TextBlock textValue = new TextBlock() { Text = keyvalue.Value + ": " }; TextBlock textKey = new TextBlock(); Binding keyBinding = new Binding(string.Format("[{0}]", keyvalue.Key)); textKey.SetBinding(TextBlock.TextProperty, keyBinding); stackPanelChild.Children.Add(textValue); stackPanelChild.Children.Add(textKey); if (keyvalue.Key == featureSet.DisplayFieldName) { textKey.FontWeight = textValue.FontWeight = FontWeights.Bold; stackPanelParent.Children.Insert(0, stackPanelChild); } else stackPanelParent.Children.Add(stackPanelChild); } border.Child = stackPanelParent; graphicsLayerFromFeatureSet.MapTip = border; MyMap.Layers.Add(graphicsLayerFromFeatureSet); } catch (Exception ex) { MessageBox.Show(ex.Message, "GraphicsLayer creation failed", MessageBoxButton.OK); } }
void MyMap_MouseClick(object sender, Map.MouseEventArgs e) { /* * Add a graphic at the user input location */ MyMap.MouseClick -= MyMap_MouseClick; if (inputGraphicsLayer == null) { inputGraphicsLayer = new GraphicsLayer(); MyMap.Layers.Add(inputGraphicsLayer); } // Add a Graphic at the click point Graphic graphic = new Graphic() { Symbol = MainGrid.Resources["IncidentMarkerSymbol"] as Symbol, Geometry = e.MapPoint }; inputGraphicsLayer.Graphics.Add(graphic); /* * Reproject the mouseclick into the GP coordinate system */ // Declare the ProjectCompleted Handler EventHandler <GraphicsEventArgs> ProjectCompletedHandler = null; // Handle the event ProjectCompletedHandler = (sender2, graphicsEventArgs) => { // Unregister the handler geometryTask.ProjectCompleted -= ProjectCompletedHandler; // Cancel any existing Jobs geoprocessorTask.CancelAsync(); // Handle the JobCompleted geoprocessorTask.JobCompleted += (sender3, jobInfoEventArgs) => { // Check whether it succeeded if (jobInfoEventArgs.JobInfo.JobStatus != esriJobStatus.esriJobSucceeded) { //Do Something } ; /* * Create two new Geoprocessor Tasks to fetch the result data (thereby allowing them to run concurrently) * Each will use the same event handler and we'll choose based on the Parameter Name. * Alternatively could use the overload which takes an object (userToken). */ Geoprocessor gpTaskSysvalves_Layer = new Geoprocessor(traceNetworkLocalGpService.Tasks[0].Url); gpTaskSysvalves_Layer.GetResultDataCompleted += geoprocessorTask_GetResultDataCompleted; gpTaskSysvalves_Layer.GetResultDataAsync( jobInfoEventArgs.JobInfo.JobId, "Sysvalves_Layer"); Geoprocessor gpTaskDistribMains_Layer = new Geoprocessor(traceNetworkLocalGpService.Tasks[0].Url); gpTaskDistribMains_Layer.GetResultDataCompleted += geoprocessorTask_GetResultDataCompleted; gpTaskDistribMains_Layer.GetResultDataAsync( jobInfoEventArgs.JobInfo.JobId, "DistribMains_Layer"); }; // Create the GP Parameter List List <GPParameter> parameters = new List <GPParameter>(); parameters.Add(new GPFeatureRecordSetLayer("Flags", graphicsEventArgs.Results[0].Geometry)); geoprocessorTask.SubmitJobAsync(parameters); }; // Register the handler for the ProjectCompleted event. geometryTask.ProjectCompleted += ProjectCompletedHandler; // Project the input point into the coordinate system of the data geometryTask.ProjectAsync(new List <Graphic>() { new Graphic() { Geometry = e.MapPoint } }, waterNetworkLocalMapService.SpatialReference); }