示例#1
0
        private async void LoadFeatures()
        {
            try
            {
                var damageAssessmentTable = await ServiceFeatureTable.OpenAsync(
                    new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0"));

                damageAssessmentTable.OutFields = OutFields.All;

                // Get incidents that has incidentid
                var damageAssessments = await damageAssessmentTable.QueryAsync(new QueryFilter()
                {
                    WhereClause = "incidentid <> ''", MaximumRows = 100
                });

                var assessments = new List <Assessment>();
                // Create assessment items from search results
                foreach (var assessment in damageAssessments)
                {
                    var feature = assessment as GeodatabaseFeature;

                    assessments.Add(new Assessment
                    {
                        Feature = feature,
                        Symbol  = damageAssessmentTable.ServiceInfo.DrawingInfo.Renderer.GetSymbol(feature)
                    });
                }

                FeatureList.ItemsSource = assessments;
            }
            catch (Exception exception)
            {
                MessageBox.Show(string.Format("Error occured : {0}", exception.ToString()), "Sample error");
            }
        }
示例#2
0
        /// <summary>
        /// Enables attribute editing, submits attribute edit back to the server and refreshes dynamic layer.
        /// </summary>
        private async void ChoiceList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ChoiceList.SelectionChanged -= ChoiceList_SelectionChanged;
            var    featureID = (Int64)AttributeEditor.Tag;
            var    selected  = (KeyValuePair <object, string>)ChoiceList.SelectedItem;
            var    layer     = MyMapView.Map.Layers["PoolPermit"] as ArcGISDynamicMapServiceLayer;
            var    overlay   = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;
            string message   = null;

            try
            {
                if (table == null)
                {
                    // Creates table based on visible layer of dynamic layer
                    // using FeatureServer specifying has_pool field to enable editing.
                    var id  = layer.VisibleLayers[0];
                    var url = layer.ServiceUri.Replace("MapServer", "FeatureServer");
                    url   = string.Format("{0}/{1}", url, id);
                    table = await ServiceFeatureTable.OpenAsync(new Uri(url), null, MyMapView.SpatialReference);

                    table.OutFields = new OutFields(new string[] { "has_pool" });
                }
                // Retrieves feature identified by ID and updates its attributes.
                var feature = await table.QueryAsync(featureID);

                feature.Attributes["has_pool"] = selected.Key;
                await table.UpdateAsync(feature);

                if (table.HasEdits)
                {
                    // Pushes attribute edits back to the server.
                    var result = await table.ApplyEditsAsync();

                    if (result.UpdateResults == null || result.UpdateResults.Count < 1)
                    {
                        return;
                    }
                    var updateResult = result.UpdateResults[0];
                    if (updateResult.Error != null)
                    {
                        message = updateResult.Error.Message;
                    }
                    // Refreshes layer to reflect attribute edits.
                    layer.Invalidate();
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            finally
            {
                overlay.Graphics.Clear();
                SetAttributeEditor();
            }
            if (!string.IsNullOrWhiteSpace(message))
            {
                MessageBox.Show(message);
            }
        }
        /// <summary>
        /// Gets related table for editing.
        /// </summary>
        private async Task <ServiceFeatureTable> GetRelatedTableAsync()
        {
            var layer = MyMapView.Map.Layers["ServiceRequests"] as ArcGISDynamicMapServiceLayer;
            // Creates table based on related table ID of the visible layer in dynamic layer
            // using FeatureServer specifying rank and comments fields to enable editing.
            var id  = relationship.RelatedTableID.Value;
            var url = layer.ServiceUri.Replace("MapServer", "FeatureServer");

            url = string.Format("{0}/{1}", url, id);
            var table = await ServiceFeatureTable.OpenAsync(new Uri(url), null, MyMapView.SpatialReference);

            table.OutFields = new OutFields(new string[] { relationship.KeyField, "rank", "comments", "submitdt" });
            return(table);
        }
        private async void CreateFeatureLayer()
        {
            try
            {
                var gdbFeatureServiceTable = await ServiceFeatureTable.OpenAsync(
                    new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/FeatureServer/0"));

                MyMapView.Map.Layers.Add(new FeatureLayer(gdbFeatureServiceTable)
                {
                    ID = "featureLayer"
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Cannot initialize FeatureLayer: {0}", ex.ToString());
            }
        }
示例#5
0
        private async void CreateFeatureLayer()
        {
            try
            {
                var gdbFeatureServiceTable = await ServiceFeatureTable.OpenAsync(
                    new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/2"));

                MyMapView.Map.Layers.Add(new FeatureLayer(gdbFeatureServiceTable)
                {
                    ID = "featureLayer"
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Cannot create FeatureLayer: {0}", ex.ToString());
            }
        }
        /// <summary>
        /// Enables geometry editing, submits geometry edit back to the server and refreshes dynamic layer.
        /// </summary>
        private async void EditButton_Click(object sender, RoutedEventArgs e)
        {
            var    layer     = MyMapView.Map.Layers["RecreationalArea"] as ArcGISDynamicMapServiceLayer;
            var    overlay   = MyMapView.GraphicsOverlays["Highlighter"] as GraphicsOverlay;
            var    featureID = (long)EditButton.Tag;
            string message   = null;

            try
            {
                // Hides graphic from overlay and dynamic layer while its geometry is being modified.
                overlay.Graphics.Clear();
                // Negative IDs indicate they do not exist on server yet.
                if (featureID > 0)
                {
                    if (layer.LayerDefinitions == null)
                    {
                        layer.LayerDefinitions = new ObservableCollection <LayerDefinition>();
                    }
                    else
                    {
                        layer.LayerDefinitions.Clear();
                    }
                    layer.LayerDefinitions.Add(new LayerDefinition()
                    {
                        LayerID    = layer.VisibleLayers[0],
                        Definition = string.Format("Objectid <> {0}", featureID)
                    });
                }
                if (table == null)
                {
                    // Creates table based on visible layer of dynamic layer
                    // using FeatureServer specifying shape field to enable editing.
                    var id  = layer.VisibleLayers[0];
                    var url = layer.ServiceUri.Replace("MapServer", "FeatureServer");
                    url   = string.Format("{0}/{1}", url, id);
                    table = await ServiceFeatureTable.OpenAsync(new Uri(url), null, MyMapView.SpatialReference);
                }
                // Retrieves feature identified by ID and updates its geometry
                // using GeometryEngine to correct ring orientation.
                var feature = await table.QueryAsync(featureID);

                var geometry = await MyMapView.Editor.EditGeometryAsync(feature.Geometry);

                feature.Geometry = GeometryEngine.Simplify(geometry);
                await table.UpdateAsync(feature);

                if (table.HasEdits)
                {
                    // Pushes geometry edits back to the server.
                    var result = await table.ApplyEditsAsync();

                    if (result.UpdateResults == null || result.UpdateResults.Count < 1)
                    {
                        return;
                    }
                    var updateResult = result.UpdateResults[0];
                    if (updateResult.Error != null)
                    {
                        message = updateResult.Error.Message;
                    }
                }
            }
            catch (TaskCanceledException te)
            {
                // Handles canceling out of Editor.
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            finally
            {
                SetGeometryEditor();
                if (layer.LayerDefinitions != null)
                {
                    layer.LayerDefinitions.Clear();
                    // Refreshes layer to reflect geometry edits.
                    layer.Invalidate();
                }
            }
            if (!string.IsNullOrWhiteSpace(message))
            {
                MessageBox.Show(message);
            }
        }