4

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 22, 2012 at 15:52
3
  • 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. Commented Jun 22, 2012 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. Commented Jun 22, 2012 at 16:14
  • 1
    JLott your rep is now 16 - you can add images... Commented Jun 22, 2012 at 17:25

2 Answers 2

2

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

answered Mar 27, 2014 at 11:43
6
  • Thank you :) I solved this a while ago using this. Completely forgot about the question. Commented Mar 27, 2014 at 14:50
  • Can you do this with a feature layer? Commented Mar 27, 2014 at 20:23
  • I do that with an ArcGISLocalFeatureLayer that inherits from FeatureLayer Commented Mar 28, 2014 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. Commented Mar 28, 2014 at 13:13
  • var localServiceMPK = new LocalFeatureService { Path = @"ArcGISPackages\MyPackage.mpk", MaxRecords = 100000 }; Commented Mar 28, 2014 at 19:17
0

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

answered Jun 22, 2012 at 16:44
1
  • 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. Commented Jun 22, 2012 at 18:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.