I need to be able to add a symbol to the map and save it

1683
4
06-08-2012 01:34 PM
Labels (1)
JessicaLott1
New Contributor
I have the map adding objects or symbols, but it does not save them. I may just be missing something simple. Any help would be appreciated. Thank-You.

I attached my project to this forum. I have looked at a lot of other forums and have done the demo provided by the SDK Samples for WPF, but I am still not being able to get it to work
on mine with symbols. Even if someone could tell me how to tweak the code from the sample to use a symbol that would also work. Thanks Again.
0 Kudos
4 Replies
ShaunWeston
Occasional Contributor
So you are trying to add a picture marker symbol to the map?

You would need to have something like this in your xaml:

<esri:PictureMarkerSymbol x:Key="DefaultPictureSymbol" OffsetX="35" OffsetY="35"
                 Source="/Assets/Images/i_about.png" />


Add then something like this in the code to add it to the map:

ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{                
Geometry = _clickPoint,                
Symbol = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol            
};             
graphicsLayer.Graphics.Add(graphic);
0 Kudos
JessicaLott1
New Contributor
Could you possible explain the code a little more. I have only been using arcGIS for a couple of days so I am definitely a beginner haha. I added it to my code and it does not recognize
_clickpoint (It does not exist in the current context)

I am sure you are going to have to create a method or event for this. Could you explain how to do that?

Thank you for your help.
0 Kudos
JessicaLott1
New Contributor
Sorry. The question about _clickpoint was silly. Ok, so I have it adding objects, now I need it to save it when I add them. Do you know anything about this?
0 Kudos
AnttiKajanus1
Occasional Contributor III
Edit:
Here is one solution to store graphics locally but you should store stuff to your database if you can. In my case, we needed to store non-saved graphics temporarely so I came up with this kind of idea
Edit end.

Long time ago I wrote serialization extensions for Silverlight and I just ported that to WPF to see if the solution works also in it and with fast test it seems more or less to work. <br><br>The idea was to save deserialized information to string that you can save to file or database. In serialization I use XamlWriter internally.

The systems works like this:

You define graphics layer you want to store

  <esri:GraphicsLayer ID="glayer" x:Name="glayer">


Add execution logic (here 2 buttons with clicks to keep sample clean)

  <Button Click="SerializeClick">Serialize</Button>
   <Button Click="DeserializeClick">Deserialize</Button>


       private string serializedData;

        private void SerializeClick(object sender, RoutedEventArgs e)
        {
            var graphicsLayer = Map.Layers["glayer"] as GraphicsLayer;


            // Serialize layer and set result to private variable
            this.serializedData = graphicsLayer.SerializeGraphics();
            graphicsLayer.ClearGraphics();
        }

        private void DeserializeClick(object sender, RoutedEventArgs e)
        {
            var graphicsLayer = Map.Layers["glayer"] as GraphicsLayer;
            graphicsLayer.DeserializeGraphics(this.serializedData);


            // Reset serialized data
            this.serializedData = string.Empty;
        }



Here you have serializedData string that contains the serialized data. Now you can do what you want with it.

NOTE:
I haven't tested this solution in WPF more then this example!

The solution should be reviewed in code level to make it more WPF and newest ArcGIS API opitimized. When I wrote that we didnt have stuff like ToJson() and Silverlight does not support XamlWriter out of the box so thing might work differently in WPF than in Silverlight.

What we did in Silverlight, we created quite large graphic writing capabilities with opacity controls, border and fill customizations etc. and that worked quite well even thou in larger objects the serialized string is huge but that did the work.

Here are sample app how I tested the porting. Also if someone is brave (or grazy) enough to my solution in their code, let me know (private message) and I will test / clean this solution and give the assembly or even code to do it if you really need it.
0 Kudos