Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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... Thank You for your help! :)

share|improve this question
    
Thanks for adding the code detail. It might help if you detail the process you follow that adds these graphics to the map. Also a screenshot showing the graphics may help. –  Get Spatial Jun 22 '12 at 15:59
    
I don't think I can add an image until I have a reputation of 15... But I did add a little more detail to the question. –  JLott Jun 22 '12 at 16:14
1  
JLott your rep is now 16 - you can add images... –  Mapperz Jun 22 '12 at 17:25
add comment

2 Answers

up vote 2 down vote accepted

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();

share|improve this answer
    
Thank you :) I solved this a while ago using this. Completely forgot about the question. –  JLott Mar 27 at 14:50
    
Can you do this with a feature layer? –  JLott Mar 27 at 20:23
    
I do that with an ArcGISLocalFeatureLayer that inherits from FeatureLayer –  XtianGIS Mar 28 at 12:46
    
I am about to ask another question. I have done this before not using a local feature layer and it worked... There has to be some little mistake that I am missing. –  JLott Mar 28 at 13:13
    
var localServiceMPK = new LocalFeatureService { Path = @"ArcGISPackages\MyPackage.mpk", MaxRecords = 100000 }; –  XtianGIS Mar 28 at 19:17
show 1 more comment

You can try serializing the graphic and then save it into isolated storage There are some good examples here and here.

share|improve this answer
    
I really thought that there was a way to just save it to the map with the map server... I have a list set up that contains the attributes of each image... So I could probably have it loop through that like a database every time the app starts up. –  JLott Jun 22 '12 at 18:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.