Select to view content in your preferred language

Difficulty Adding Graphics

2913
4
Jump to solution
04-25-2012 01:03 PM
CraigPatterson
Regular Contributor
I'm attempting to create a simple Mark Up Add In.  I'm able to create the Draw object, set the correct draw mode, and enable it, but the graphic doesn't get added to the map. 

Here is my DrawComplete Method...

         private void MarkUpDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)         {             // retrieve DrawingGraphics Layer object             GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["MarkUpGraphicsLayer"] as GraphicsLayer;              if (graphicsLayer == null)             {                 graphicsLayer = new GraphicsLayer()                 {                     ID = "MarkUpGraphicsLayer",                                          Renderer = new SimpleRenderer()                     {                         Symbol =  new SimpleMarkerSymbol()                             {                                 Color = new SolidColorBrush(Color.FromArgb(0, 255,0,0)),                                 Size = 12                             }                     }                 };                  graphicsLayer.SetValue(MapApplication.LayerNameProperty, "Mark Up");                  MapApplication.Current.Map.Layers.Add(graphicsLayer);             }              //// create graphic object to hold new drawing             ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()             {                 Geometry = args.Geometry,                 Symbol = _activeMarkUpSymbol,             };              ////add it to the map             graphicsLayer.Graphics.Add(graphic);              // Turn off drawing mode otherwise new graphics may be drawn during edit             // This returns the map to normal mode, pan on click             MarkUpDrawObject.IsEnabled = false;         }


Here is where I set my Symbol and enable my draw mode
        private void DrawPointButton_Click(object sender, RoutedEventArgs e)         {             MarkUpDrawObject.DrawMode = DrawMode.Point;             MarkUpDrawObject.IsEnabled = true;              _activeMarkUpSymbol = new SimpleMarkerSymbol()             {                 Color = new SolidColorBrush(Color.FromArgb(0, 255,0,0)),                 Size = 12             };         }


The graphic layer is added to the layer list, so I know that's not the issue.  I think it may have something to do with my symbol.

Any ideas on what may be wrong?

Thanks,

Craig
0 Kudos
1 Solution

Accepted Solutions
CraigPatterson
Regular Contributor
GG,

Thanks for all of the advice.  I got this working.  The problem was that Viewer was overwriting my graphics symbology.  I configured the layer and checked, "The symbols defined here are superseded by the symbols on the individual graphics, if any"

Craig

View solution in original post

0 Kudos
4 Replies
GerardoGarza
Occasional Contributor
Hi Craig,
Try adding a Style like "Circle" to your marker symbol and making sure MarkUpDrawObject is tied to your Map object.
Look at this graphics sample from the API site for comparison.
GG
0 Kudos
CraigPatterson
Regular Contributor
Thanks for the reply. 

Is this the correct way to create the Draw Object?

public MarkUpToolSet()
        {
            InitializeComponent();

            MarkUpDrawObject = new Draw(MapApplication.Current.Map) 
            {
                FillSymbol = MarkUpToolset.Resources["DefaultFillSymbol"] as SimpleFillSymbol
            };

            // Attach MarkUpDrawObject_DrawComplete method to DrawDrawObject.DrawComplete event handler
            MarkUpDrawObject.DrawComplete += MarkUpDrawObject_DrawComplete;
        }


Note that when drawMode = rectangle and I draw the box, it shows the outline.  It just doesn't add the graphic to the map.

Thanks,

Craig
0 Kudos
GerardoGarza
Occasional Contributor
Creation of draw object looks fine. 
However, in your examples, you mention using both Marker and Fill symbols.
When drawing a point graphic, make sure your _activeMarkUpSymbol is a Marker symbol.
When drawing a rectangle/polygon graphic, make sure your _activeMarkUpSymbol is a Fill symbol.
I also noticed that when you created your graphics layer, you used a SimpleRenderer with a Markup symbol.  I believe that limits the graphics layer to creating only point graphics.  Try removing the renderer from the graphics layer creation.
0 Kudos
CraigPatterson
Regular Contributor
GG,

Thanks for all of the advice.  I got this working.  The problem was that Viewer was overwriting my graphics symbology.  I configured the layer and checked, "The symbols defined here are superseded by the symbols on the individual graphics, if any"

Craig
0 Kudos