using System; namespace GeoEdit { public partial class MainPage : UserControl { Locator _locatorTask; GraphicsLayer _candidateGraphicsLayer; private static ESRI.ArcGIS.Client.Projection.WebMercator _mercator = new ESRI.ArcGIS.Client.Projection.WebMercator(); public MainPage() { InitializeComponent(); ESRI.ArcGIS.Client.Geometry.Envelope initialExtent = new ESRI.ArcGIS.Client.Geometry.Envelope( _mercator.FromGeographic( new ESRI.ArcGIS.Client.Geometry.MapPoint(-82.23, 41.48)) as MapPoint, _mercator.FromGeographic( new ESRI.ArcGIS.Client.Geometry.MapPoint(-82.15, 41.4)) as MapPoint); initialExtent.SpatialReference = new SpatialReference(102100); MyMap.Extent = initialExtent; _candidateGraphicsLayer = MyMap.Layers["PointLayer"] as GraphicsLayer; } private void FindAddressButton_Click(object sender, RoutedEventArgs e) { _locatorTask = new Locator("http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Streets_US_10/GeocodeServer"); _locatorTask.AddressToLocationsCompleted += LocatorTask_AddressToLocationsCompleted; _locatorTask.Failed += LocatorTask_Failed; AddressToLocationsParameters addressParams = new AddressToLocationsParameters() { OutSpatialReference = MyMap.SpatialReference }; Dictionary<string, string> address = addressParams.Address; if (!string.IsNullOrEmpty(InputAddress.Text)) address.Add("Street", InputAddress.Text); if (!string.IsNullOrEmpty(City.Text)) address.Add("City", City.Text); if (!string.IsNullOrEmpty(State.Text)) address.Add("State", State.Text); if (!string.IsNullOrEmpty(Zip.Text)) address.Add("ZIP", Zip.Text); _locatorTask.AddressToLocationsAsync(addressParams); } private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { 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 _candidateListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { int index = (sender as ListBox).SelectedIndex; if (index >= 0) { MapPoint candidatePoint = _candidateGraphicsLayer.Graphics[index].Geometry as MapPoint; double displaySize = MyMap.MinimumResolution * 30; ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope( candidatePoint.X - (displaySize / 2), candidatePoint.Y - (displaySize / 2), candidatePoint.X + (displaySize / 2), candidatePoint.Y + (displaySize / 2)); MyMap.ZoomTo(displayExtent); } } private void LocatorTask_Failed(object sender, TaskFailedEventArgs e) { MessageBox.Show("Locator service failed: " + e.Error); } private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args) { FeatureLayer featureLayer = sender as FeatureLayer; for (int i = 0; i < featureLayer.SelectionCount; i++) featureLayer.SelectedGraphics.ToList().UnSelect(); args.Graphic.Select(); MyFeatureDataForm.GraphicSource = args.Graphic; FeatureDataFormBorder.Visibility = Visibility.Visible; } private void EditorWidget_Loaded(object sender, RoutedEventArgs e) { string[] myLayerIDs = { "PointLayer" }; MyEditorWidget.LayerIDs = myLayerIDs; } } }
var g = new Graphic(); g.Geometry = geocodeResult; foreach (var f in l.LayerInfo.Fields) g.Attributes[f.Name] = null; l.Graphics.Add(g); var childWindow = new ChildWindow(); var fdf = new FeatureDataForm() { FeatureLayer = l, GraphicSource = g }; childWindow.Content = fdf; childWindow.Show();
g.Attributes["Date"] = DateTime.Now; g.Attributes["Job_Location"] = InputAddress.Text;
var fdf = new FeatureDataForm() { FeatureLayer = layer, GraphicSource = graphic}; var window = new ChildWindow() { Content = fdf }; fdf.EditEnded += (a, b) => { window.Close(); }; window.Show();
//g.Attributes["Job_Type"] = "2"; //g.Attributes["Job_Type"] = "'2'"; //g.Attributes["Job_Type"] = "Broken Valve"; //g.Attributes["Job_Type"] = "'Broken Valve'";
STATUS ( type: esriFieldTypeSmallInteger , alias: Status , editable: true , nullable: true , Coded Values: [1: New] , [2: Open] , [3: Closed] )
graphic.Attributes["STATUS"] = 1;
It depends on your service. For example, this service defines its coded value domain as:This feature attribute will then be:graphic.Attributes["STATUS"] = 1;where datatype is Int16 and is one of the possible code 1, 2, 3.http://servicesbeta2.esri.com/arcgis/rest/services/SF311/FeatureServer/0/1
g.Attributes["Job_Type"] = 1;
where datatype is Int16
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.