[GIS] Saving Graphics to map using WPF, C# and ArcGIS for Server

arcgis-10.0arcgis-serverccartographywpf

I have everything working just like I need it to, but when I add a new graphic to the map it does not save it. So I will add it, close the application, and when I reopen it the graphic is gone. I have AutoSave set to true on both of my feature maps. If anyone knows what my problem is or possible solutions I would really appreciate the help. I am using WPF and C#. I also have my map published to a map server. I don't quite understand the arcGIS for Server though. I have only been using arcGIS for a couple of weeks so bare with me on this one haha.

Below is some of my code. If you need me to clear up anything just leave me a comment.

XAML:

<Grid x:Name="AddressLayout" Background="White">
        <Grid.Resources>

            <esri:Editor x:Key="MyEditor" LayerIDs="WaterMeterLayer" GeometryServiceUrl="http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
            <esri:SimpleRenderer x:Key="WaterMeterRenderer">
                                 <esri:SimpleRenderer.Symbol>
                <esri:PictureMarkerSymbol 
                                      OffsetX="0" OffsetY="31" Source="C:\Program Files\ESRI\Data Interoperability\icons\V2.png"/>
                                 </esri:SimpleRenderer.Symbol>
            </esri:SimpleRenderer>

            <esri:SimpleRenderer x:Key="LotRenderer">
                <esri:SimpleRenderer.Symbol>
                    <esri:PictureMarkerSymbol  
                                      OffsetX="0" OffsetY="31" Source="C:\Program Files\ESRI\Data Interoperability\icons\J3.png" />
                </esri:SimpleRenderer.Symbol>
            </esri:SimpleRenderer>


            <esri:PictureMarkerSymbol x:Key="DefaultMarkerSymbol"
                                      OffsetX="0" OffsetY="31" Source="C:\Program Files\ESRI\Data Interoperability\icons\K2.png"/>
            <LinearGradientBrush x:Key="PanelGradient" EndPoint="0.5, 1" StartPoint="0.5, 0">
                <LinearGradientBrush.RelativeTransform>
                    <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5"/>
                        <SkewTransform  CenterX="0.5" CenterY="0.5"/>
                        <RotateTransform Angle="175" CenterX="0.5" CenterY="0.5"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </LinearGradientBrush.RelativeTransform>

                <GradientStop Color="#FF145787" Offset="0.15"/>
                <GradientStop Color="#FF3D7FAC" Offset="0.5"/>
                <GradientStop Color="#FF88C5EF" Offset="1.0"/>
            </LinearGradientBrush>

        </Grid.Resources>



        <esri:Map x:Name="MyMap" Background="#FFE3E3E3" WrapAround="True" MouseClick="MyMap_MouseClick" MouseMove="MyMap_MouseMove" MouseRightButtonDown="MyMap_MouseRightButtonDown">
            <esri:Map.Layers>
            <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" 
                      Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
            <esri:GraphicsLayer ID="CandidateGraphicsLayer" >
                <esri:GraphicsLayer.MapTip>
                    <Grid>
                        <Rectangle Stroke="Gray"  RadiusX="10" RadiusY="10" Fill="#77FF0000" Margin="0,0,0,5" >
                            <Rectangle.Effect>
                                <DropShadowEffect/>
                            </Rectangle.Effect>
                        </Rectangle>
                        <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
                        <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="30,20,30,30">
                            <TextBlock Text="{Binding [Address]}" HorizontalAlignment="Left" Foreground="Black" />
                            <TextBlock Text="{Binding [LatLon]}" HorizontalAlignment="Left" Foreground="Black" />

                        </StackPanel>
                    </Grid>
                </esri:GraphicsLayer.MapTip>
            </esri:GraphicsLayer>


                <esri:FeatureLayer ID="WaterMeterLayer"
                               Url="http://localhost:6080/arcgis/rest/services///World_Street_Map/MapServer"
                               AutoSave="True"
                               Mode="OnDemand"
                               Renderer="{StaticResource WaterMeterRenderer}"
                               ValidateEdits="True"
                               DisableClientCaching="True">

                    <esri:FeatureLayer.MapTip>
                        <Grid>
                            <Rectangle Stroke="Gray"  RadiusX="10" RadiusY="10" Fill="#77FF0000" Margin="0,0,0,5" >
                                <Rectangle.Effect>
                                    <DropShadowEffect/>
                                </Rectangle.Effect>
                            </Rectangle>
                            <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
                            <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="30,20,30,30">
                                <TextBlock Text="{Binding [MeterNum]}" HorizontalAlignment="Left" Foreground="Black" />
                                <TextBlock Text="{Binding [Comment]}" HorizontalAlignment="Left" Foreground="Black" />
                                <TextBlock Text="{Binding [Address1]}" HorizontalAlignment="Left" Foreground="Black" />
                                <TextBlock Text="{Binding [Address2]}" HorizontalAlignment="Left" Foreground="Black" />


                            </StackPanel>
                        </Grid>
                    </esri:FeatureLayer.MapTip>
                </esri:FeatureLayer>

                <esri:FeatureLayer ID="LotLayer"
                               Url="http://localhost:6080/arcgis/rest/services///World_Street_Map/MapServer"
                               AutoSave="True"
                               Mode="OnDemand"
                               Renderer="{StaticResource LotRenderer}"
                               ValidateEdits="True"
                               DisableClientCaching="True" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown">
                    <esri:FeatureLayer.MapTip>
                        <Grid>
                            <Rectangle Stroke="Gray"  RadiusX="10" RadiusY="10" Fill="#77FF0000" Margin="0,0,0,5" >
                                <Rectangle.Effect>
                                    <DropShadowEffect/>
                                </Rectangle.Effect>
                            </Rectangle>
                            <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
                            <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="30,20,30,30">
                                <TextBlock Text="{Binding [MeterNum]}" HorizontalAlignment="Left" Foreground="Black" />
                                <TextBlock Text="{Binding [Comment]}" HorizontalAlignment="Left" Foreground="Black" />
                                <TextBlock Text="{Binding [Address1]}" HorizontalAlignment="Left" Foreground="Black" />
                                <TextBlock Text="{Binding [Address2]}" HorizontalAlignment="Left" Foreground="Black" />

                            </StackPanel>
                        </Grid>
                    </esri:FeatureLayer.MapTip>
                </esri:FeatureLayer>

            </esri:Map.Layers>
        </esri:Map>

C# Code Example of when I add something:

private void MyMap_MouseClick(object sender, Map.MouseEventArgs e)
        {
            if (blnAddInformationClicked)
            { 

            locatorTask.LocationToAddressCompleted += LocatorTask_LocationToAddressCompleted;
            locatorTask.Failed += LocatorTask_Failed;


            double tolerance = 30;
            locatorTask.LocationToAddressAsync(e.MapPoint, tolerance, e.MapPoint);


            InstructionGrid.Visibility = Visibility.Collapsed;
            PortalGrid.IsEnabled = true;

            }
        }

        private void LocatorTask_LocationToAddressCompleted(object sender, AddressEventArgs args)
        {
            locatorTask.LocationToAddressCompleted -= LocatorTask_LocationToAddressCompleted;
            if (Information.ContainsKey(txtNumber.Text))
            {
                MessageBox.Show("This Object has already been added");
                PortalGrid.Visibility = Visibility.Visible;
                InformationGrid.Visibility = Visibility.Visible;
                return;
            }

            Address address = args.Address;
            Dictionary<string, object> attributes = address.Attributes;


            if (radWaterMeter.IsChecked == true)
            { 
            Graphic graphic = new Graphic()
            {
                Symbol = AddressLayout.Resources["WaterMeterRenderer"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                Geometry = args.UserState as MapPoint
            };

            string address1 = attributes["Street"].ToString();
            string address2 = String.Format("{0}, {1} {2}", attributes["City"], attributes["State"], attributes["ZIP"]);
            string addressCombined =  String.Format("{0},{1},{2},{3}", attributes["Street"].ToString(), attributes["City"], attributes["State"], attributes["ZIP"]); ;
            //Information.Add(txtObjectNumber.Text, addressCombined);

            ObjectProperties record = new ObjectProperties
            {
                ObjectNumber = txtObjectNumber.Text,
                ObjectComments = txtComments.Text,
                ObjectAddress = addressCombined,
            };

            Properties.Add(record);



            //var recordsAsString = string.Join(" ", Properties.Select(p => p.ToString()));

            //MessageBox.Show(recordsAsString);

            if (blnAddInformationClicked == true)
            {
                graphic.Attributes.Add("MeterNum", record.ObjectNumber);
                graphic.Attributes.Add("Comment", record.ObjectComments);
                graphic.Attributes.Add("Address1", address1);
                graphic.Attributes.Add("Address2", address2);

                FeatureLayer graphicsLayer = MyMap.Layers["WaterMeterLayer"] as FeatureLayer;
                graphicsLayer.Graphics.Add(graphic);
                blnAddInformationClicked = false;
            }
            }

            if (radLot.IsChecked == true)
            {
                Graphic graphic = new Graphic()
                {
                    Symbol = AddressLayout.Resources["LotRenderer"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                    Geometry = args.UserState as MapPoint
                };

                string address1 = attributes["Street"].ToString();
                string address2 = String.Format("{0}, {1} {2}", attributes["City"], attributes["State"], attributes["ZIP"]);
                string addressCombined = String.Format("{0},{1},{2},{3}", attributes["Street"].ToString(), attributes["City"], attributes["State"], attributes["ZIP"]);

                ObjectProperties record = new ObjectProperties
                {
                    ObjectNumber = txtObjectNumber.Text,
                    ObjectComments = txtComments.Text,
                    ObjectAddress = addressCombined,
                };

                Properties.Add(record);


                    graphic.Attributes.Add("MeterNum", record.ObjectNumber);
                    graphic.Attributes.Add("Comment", record.ObjectComments);
                    graphic.Attributes.Add("Address1", address1);
                    graphic.Attributes.Add("Address2", address2);

                    FeatureLayer graphicsLayer = MyMap.Layers["LotLayer"] as FeatureLayer;
                    graphicsLayer.Graphics.Add(graphic);
                    blnAddInformationClicked = false;


            }

        }
        private void LocatorTask_Failed(object sender, TaskFailedEventArgs e)
        {
            MessageBox.Show("Unable to determine an address. Try selecting a location closer to a street.");
        }

I have two different feature layers. There is a radio button there that determines which feature layer and graphic to use. The graphics/renderers are just .png files that are on my C: drive. I add the attributes to the graphics using a list and the information giving by the user. These attributes are then added to the maptip. The graphics are being added, but it does not save it to the map, so when I reopen the application the graphics that I added are not there anymore.

I have looked through all of the resources for arcGIS that I could find and there is nothing there that is helping me much. I feel as though the resources are lacking when it comes to beginners.

Best Answer

when you create the feature layer be aware that you set the properties

DisableClientCaching = true, AutoSave = false, Mode = FeatureLayer.QueryMode.Snapshot

then it will be save the edits with:

graphicsLayer.SaveEdits();

Related Question