Select to view content in your preferred language

Add Polygon

1267
12
Jump to solution
01-06-2012 11:01 AM
JayKappy
Frequent Contributor
I am using this example to add a polygon: AND it works great
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave

I am referencing this example to open the data form to edit the data as soon as the feature is added...
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataForm

While this works for the Point it is not working for the line and polygon....which require mutliple mouse downs
Is there an event I can place on the Line adn Polygon Feature that when I add a new one i can open the data form
Is there an Editstarted or similar that will allow me to run soem code as soon as I finish creating the feature?

THanks

<esri:FeatureLayer ID="MG_Polygon" Visible="True" MouseLeftButtonUp="Poly_MouseLeftButtonUp"                 Url="http://156.555.555.189/ArcGIS/rest/services/TEST_FS/FeatureServer/24"          DisableClientCaching="True" Mode="OnDemand"         SelectionColor="#FFFFFF00" OutFields="*" />



    Private Sub Poly_MouseLeftButtonUp(ByVal sender As Object, ByVal args As GraphicMouseButtonEventArgs)         Dim featureLayer As FeatureLayer = TryCast(sender, FeatureLayer)          For Each g As Graphic In featureLayer.Graphics             If (g.Selected) Then                 g.UnSelect()             End If         Next          args.Graphic.Select()         MyPolygonFeatureDataForm.GraphicSource = args.Graphic          PolygonDataFormBorder.Visibility = Visibility.Visible     End Sub


Basically just trying to open the data form after the feature is added and allow the user t enter data....the way I hav it above you have to add the feature then click the new feature and then data form opens...for the line and polygon that is....adding a point it opens the data form....
?????
0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor
DataFormBorder.Visibility = Visibility.Visible 
FeatureDataForm.GraphicSource = change.Geometry
FeatureDataForm.FeatureLayer = TryCast(change.Layer, FeatureLayer) 
FeatureDataForm.GraphicSource = change.Graphic

Kindly remove the highlighted line.

View solution in original post

0 Kudos
12 Replies
JayKappy
Frequent Contributor
I tried to use the "EndSaveEdits" Event and it seems to work where it opens the dataform when done  BUT the dataform is not loaded with anything becuase there is not a selected feature.

EndSaveEdits="EndSaveEditsPoly"

HOW CAN I AUTOMATICALLY select the feature I just added?  If I can select the newly created feature then the data form should be populated correctly....anyone know how to select the newly added feature?

THanks
0 Kudos
ChristopherHill
Deactivated User
The Editor class has an event called "EditCompleted" that you can subscribe to and listen for all "Add" actions then you can get the graphic that was added to the layer and open the FeatureDataForm allow the user to add attributes to the graphic. this will allow you to automatically get the graphic when the user is done drawing and prompt them for attribute information.

private void Editor_EditCompleted(object sender, ESRI.ArcGIS.Client.Editor.EditEventArgs e)
{
 if (e.Action == ESRI.ArcGIS.Client.Editor.EditAction.Add)
 {
  // e.Edits contains graphics that was added and the layer the graphic was added to
 }
}
0 Kudos
JayKappy
Frequent Contributor
I am pretty confused...dont really know how to get the added feature and select it
I am trying this and getting to the "No Edits" messagebox


    Private Sub Editor_EditCompleted(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Client.Editor.EditEventArgs)

        ' e.Edits contains graphics that where added and the layer the graphic was added to
        If e.Action = ESRI.ArcGIS.Client.Editor.EditAction.Add Then

            Dim editor As Editor = TryCast(LayoutRoot.Resources("MyEditor"), Editor)
            For Each graphicsLayer As GraphicsLayer In editor.GraphicsLayers
                If TypeOf graphicsLayer Is FeatureLayer Then
                    Dim featureLayer As FeatureLayer = TryCast(graphicsLayer, FeatureLayer)
                    If featureLayer.HasEdits Then
                        MessageBox.Show("Has Edits")
                    Else
                        MessageBox.Show("No Edits")
                    End If
                End If
            Next graphicsLayer

        End If
    End Sub


I see the EDITs Property gives a list of edits but cant see any examples on how to get them....or select the newly added feature
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor+Edi...
0 Kudos
ChristopherHill
Deactivated User
if (e.Action == ESRI.ArcGIS.Client.Editor.EditAction.Add)
{
 foreach (ESRI.ArcGIS.Client.Editor.Change change in e.Edits)
 {
  MyFeatureDataForm.GraphicSource = change.Graphic; // this is the newly added graphic
 }
}
0 Kudos
JayKappy
Frequent Contributor
Thanks for your imput....one more question....I mean where can I go to determine and figure out that code?
How am I supposed to know that the DataForm has a Graphic Source and that I set the ForEach up in that manner?
It all seems so ellusive...

Where can I go to find out more stuff I can do based on the Edit.Action...such as Add, Select etc....

In my app I have radio buttons that the user selects to set the Editable LayerID.  I used this to help open the correct Dataform based on the addition of a new feature....think I am all good to go for now...thanks for yoru help

   Private Sub Editor_EditCompleted(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Client.Editor.EditEventArgs)

        Dim Test As String = Me.EditLayer2.Text

        ' e.Edits contains graphics that where added and the layer the graphic was added to
        If e.Action = ESRI.ArcGIS.Client.Editor.EditAction.Add Then

            For Each change As ESRI.ArcGIS.Client.Editor.Change In e.Edits

                If Test = "MG_Point" Then
                    ' this is the newly added graphic
                    MyPointFeatureDataForm.GraphicSource = change.Graphic

                    PointDataFormBorder.Visibility = Visibility.Visible
                    LineDataFormBorder.Visibility = Visibility.Collapsed
                    PolygonDataFormBorder.Visibility = Visibility.Collapsed
                ElseIf Test = "MG_Line" Then
                    ' this is the newly added graphic
                    MyLineFeatureDataForm.GraphicSource = change.Graphic

                    PointDataFormBorder.Visibility = Visibility.Collapsed
                    LineDataFormBorder.Visibility = Visibility.Visible
                    PolygonDataFormBorder.Visibility = Visibility.Collapsed
                ElseIf Test = "MG_Polygon" Then
                    ' this is the newly added graphic
                    MyPolygonFeatureDataForm.GraphicSource = change.Graphic

                    PointDataFormBorder.Visibility = Visibility.Collapsed
                    LineDataFormBorder.Visibility = Visibility.Collapsed
                    PolygonDataFormBorder.Visibility = Visibility.Visible
                Else

                End If
            Next
        End If

    End Sub
0 Kudos
ChristopherHill
Deactivated User
The for loop I used only makes sense when you are dealing with adding 1 geometry at a time. i.e. (FeatureLayer.AutoSave = true). I wouldn't use FeatureDataForm like that in cases where multiple geometry is being added.

I noticed you are using a different FeatureDataForm per geometry type. you can get by with only 1 FeatureDataForm.

myFeatureDataForm.GraphicSource = change.Geometry
myFeatureDataForm.FeatureLayer = change.Layer as FeatureLayer;


You should also check out the EditorWidget control becasue it allows for creating geometry and opening a feature data form for attribute entry as well, along with lots of other features such as creating geometry, deleting, moving , rotating, adding vertices(polygons, polylines), removing vertices, moving vertices, scaling, attribute editing, etc...


These are the two main sources for our API our interactive samples which you know about and our library reference for out API.

Silverlight SDK Samples
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm

Silverlight API Reference
http://help.arcgis.com/en/webapi/silverlight/apiref/api_start.htm
0 Kudos
JayKappy
Frequent Contributor
Thanks Christopher for your input....yea I have been using a mixture of those examples....cant decide on one...

Question...in teh example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitEditorWidget

Where is the call to open the attribute input dialog box....I see it pops up but cant see where, why, or how?

THanks again for your help...very appreciated.
0 Kudos
ChristopherHill
Deactivated User
You can set the EditorWidget.ShowAttributesOnAdd = true and it will automatically create and open a FeatureDataForm when a user adds a geometry to a layer. The EditorWidget also has a attribute editor toolbar option that will allow the user to edit geometry at anytime, by selection the toolbar option on the widget then clicking the geometry, so even after the user is done editing the attributes they can reopen and change values whenever they want.

API Reference link to the EditorWidget.ShowAttributesOnAdd property:
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.To...
0 Kudos
JayKappy
Frequent Contributor
Thanks Christopher....very apprected....
0 Kudos