EditorWidget not working

802
3
10-23-2012 07:50 AM
Labels (1)
RonVincent
Occasional Contributor
I'm sure I'm doing something wrong. I have a map package with point featureclasses stored in it. I've adding the map package programmatically but now I'm trying to edit one of these point featureclasses. I've added the EditorWidget programmatically but how do I get it to edit my featureclass? Also, how do I get a reference the particular featureclass in the map package?

            LocalMapService localMapServiceTactical = new LocalMapService()
            {
                Path = @"C:\Data\tactical.mpk",
                EnableDynamicLayers = true
            };

            // Start the local map service and once initialized
            localMapServiceTactical.StartAsync((mapService) =>
            {

                // create a new local dynamic map service layer based on the local map service
                _arcGISLocalDynamicMapServiceLayer = new ArcGISLocalDynamicMapServiceLayer(localMapServiceTactical)
                {
                    ID = "Tactical",
                    ImageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.PNG32,
                };

                // Set up an event handler for the layer initialized event
                _arcGISLocalDynamicMapServiceLayer.Initialized += (s, e) =>
                {
                    //Enable the UI once the layer has initialized
                    //DynamicLayersUiGrid.IsEnabled = true;
                    DataContext = this;
                    //IsBusy = false;
                };


                // Add the layer to the map
                _map.Layers.Add(_arcGISLocalDynamicMapServiceLayer);
            });

Thanks,

Ron
0 Kudos
3 Replies
BKuiper
Occasional Contributor III
The editor widget has a Map property that you have to set. Have you done that?

http://resources.arcgis.com/en/help/runtime-wpf/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor_...
0 Kudos
RonVincent
Occasional Contributor
The editor widget has a Map property that you have to set. Have you done that?

http://resources.arcgis.com/en/help/runtime-wpf/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor_...


Yes. I've also setup the LayerIDs. Actually I've have it now displaying a widget that has the ability to select objects, but not add, edit or delete objects using this code:

          
ESRI.ArcGIS.Client.Toolkit.EditorWidget editorWidget = null;

           string[] layerIDs = { "Target" };

            this.editorWidget = new ESRI.ArcGIS.Client.Toolkit.EditorWidget();
            this.editorWidget.Margin = new Thickness(12, 50, 0, 0);
            this.editorWidget.Map = map;
            this.editorWidget.AutoSelect = true;
            this.editorWidget.AlwaysDisplayDefaultTemplates = true;
            this.editorWidget.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.editorWidget.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            this.editorWidget.ShowAttributesOnAdd = true;
            this.editorWidget.Loaded += new RoutedEventHandler(editorWidget_Loaded);
            this.editorWidget.DataContext = arcGISLocalFeatureLayer;
            this.editorWidget.LayerIDs = layerIDs;
            this.editorWidget.ApplyTemplate();

            LayoutRoot.Children.Add(editorWidget);
0 Kudos
RonVincent
Occasional Contributor
Update: I actually had to change this so that it uses a LocalFeatureService with the EditorWidget. Here is the complete code:

            ArcGISLocalFeatureLayer arcGISLocalFeatureLayer = null;
            LocalFeatureService lfs = new LocalFeatureService();
            lfs.Path = @"C:\Data\tactical.mpk";

            arcGISLocalFeatureLayer = new ArcGISLocalFeatureLayer(lfs, "Target");

            // Set the ID.
            arcGISLocalFeatureLayer.ID = "Target";
            arcGISLocalFeatureLayer.Editable = true;
            arcGISLocalFeatureLayer.ValidateEdits = true;
            arcGISLocalFeatureLayer.AutoSave = true;
            arcGISLocalFeatureLayer.MouseLeftButtonUp += new GraphicsLayer.MouseButtonEventHandler(arcGISLocalFeatureLayer_MouseLeftButtonUp);

            // Define a SimpleRenderer with a SimpleMarkerSymbol to display each observation. Each observation
            // will be a small red triangle.
            ESRI.ArcGIS.Client.SimpleRenderer mySimpleRenderer2 = new ESRI.ArcGIS.Client.SimpleRenderer();
            ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol mySymbol2 = new ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol();
            System.Windows.Media.SolidColorBrush defaultBrush2 = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0)); //Red
            mySymbol2.Color = defaultBrush2;
            mySymbol2.Size = 8;
            mySymbol2.Style = ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Triangle;
            mySimpleRenderer2.Symbol = mySymbol2;


            arcGISLocalFeatureLayer.Renderer = mySimpleRenderer2;
            arcGISLocalFeatureLayer.InitializationFailed += new System.EventHandler<System.EventArgs>(arcGISLocalFeatureLayer_InitializationFailed);

            arcGISLocalFeatureLayer.Initialize();


            // Add the local feature layer to the map. The map will handle the initialization of the layer.
            map.Layers.Add(arcGISLocalFeatureLayer);

             ESRI.ArcGIS.Client.Toolkit.EditorWidget editorWidget = null;
            this.editorWidget = new ESRI.ArcGIS.Client.Toolkit.EditorWidget();
            this.editorWidget.Margin = new Thickness(12, 50, 0, 0);
            this.editorWidget.Map = map;
            this.editorWidget.AutoSelect = true;
            this.editorWidget.AlwaysDisplayDefaultTemplates = true;
            this.editorWidget.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.editorWidget.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            this.editorWidget.ShowAttributesOnAdd = true;
            this.editorWidget.Loaded += new RoutedEventHandler(editorWidget_Loaded);
            this.editorWidget.DataContext = arcGISLocalFeatureLayer;
            this.editorWidget.LayerIDs = layerIDs;

            this.editorWidget.ApplyTemplate();

            LayoutRoot.Children.Add(editorWidget);


When the app starts I can see the EditorWidget with a set of tools for editing but as soon as the app finishes loading the EditorWidget reverts to a tool that allows you to just select, unselect, etc.
0 Kudos