Select to view content in your preferred language

DrawGraphics Tools...can text be added?

1474
11
Jump to solution
07-30-2012 09:29 AM
ChristineZeller
New Contributor III
Is there a way to write Text (similar to Flex draw graphic tools)

http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#DrawGraphics

Thanks
Christine
0 Kudos
11 Replies
ChristineZeller
New Contributor III
Here's my xmal toolbar:

        <!-- Selectable Tools Window-->

        <userControls:DraggableWindow IsOpen="False" x:Name="DrawGraphicToolbar" IsDraggable="True" VerticalAlignment="Top" 
            HorizontalAlignment="Left" Margin="450,110,0,15" 
                                      Effect="{StaticResource dropShadow}" 
                                      Background="Black" Title="DRAW GRAPHIC TOOLS">




            <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" Height="Auto" >

                <Border Effect="{StaticResource miniDropShadow}" Style="{StaticResource RibbonElementBorder}" Padding="15" Margin="10">


                    <!--<Grid Margin="10" Background="White">-->
                    <StackPanel Orientation="Vertical" Margin="3">
                        <StackPanel x:Name="MyStackPanel" Orientation="Horizontal">
                            <Button Tag="DrawPoint" Margin="5" Click="Tool_Click" 
                                ToolTipService.ToolTip="Add a point">
                                <Image Source="images/DrawPoint.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawPolyline" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add a polyline">
                                <Image Source="images/DrawPolyline.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawPolygon" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add a polygon">
                                <Image Source="images/DrawPolygon.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawRectangle" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add a rectangle">
                                <Image Source="images/DrawRectangle.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawFreehand" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add a freehand line">
                                <Image Source="images/DrawFreehand.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawArrow" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add an arrow">
                                <Image Source="images/DrawArrow2.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawTriangle" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add a triangle">
                                <Image Source="images/DrawTriangle2.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawCircle" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add a circle">
                                <Image Source="images/DrawCircle2.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawEllipse" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add an ellipse">
                                <Image Source="images/DrawEllipse2.png" Margin="2" />
                            </Button>
                            <Button Tag="EnterText" Margin="5" Click="Tool_Click"
                                ToolTipService.ToolTip="Add text">
                                <Image Source="images/text.png" Margin="2" />
                            </Button>
                            <Button Tag="DrawNothing" Margin="5" Click="Tool_Click"
                                 Style="{x:Null}"
                                ToolTipService.ToolTip="Unselect Current Tool">
                                <Image Source="images/dismiss.png" Margin="2" />
                            </Button>
                            <Button Tag="ClearStopDraw" Margin="5" Click="Tool_Click"
                                Style="{x:Null}"
                                ToolTipService.ToolTip="Clear graphics">
                                <Image Source="images/StopDraw.png" Margin="2" />
                            </Button>
                        </StackPanel>

                        <CheckBox x:Name="EnableEditVerticesScaleRotate" Content="Click on geometry to edit" 
                          IsChecked="False" Foreground="Black" FontWeight="Bold" Margin="10,5,5,5" />

                        <TextBox x:Name="txtText" Text="test" />
                        
                    </StackPanel>
                    
                    <!--</Grid>-->


                </Border>

            </Grid>

        </userControls:DraggableWindow>



Here's my code behind:

 private void MyDrawObjectGraphic_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)
        {
           

            if (_bolText)  //if user selected text from drawing options
            {
                //MessageBox.Show(txtText.Text);
                //_activeSymbol = LayoutRoot.Resources["DefaultGraphicMarkerSymbol"] as Symbol;
                //string test = txtText.Text;
                //(_activeSymbol as TextSymbol).Text = test;
                //MessageBox.Show(test);
                (_activeSymbol as TextSymbol).Text = txtText.Text;
                txtText.Text = string.Empty;
               // spText.Visibility = Visibility.Collapsed;
            }

            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = args.Geometry,
                Symbol = _activeSymbol,
            };
            graphicsLayer.Graphics.Add(graphic);


            graphicsLayer.Refresh();
  }


  private void Tool_Click(object sender, RoutedEventArgs e)
        {
            UnSelectTools();

            VisualStateManager.GoToState(sender as Button, "Selected", false);
            _bolText = false;

            switch ((sender as Button).Tag as string)
            {
                case "DrawPoint":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Point;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicMarkerSymbol"] as Symbol;
                    break;
                case "DrawPolyline":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Polyline;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicLineSymbol"] as Symbol;
                    break;
                case "DrawPolygon":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Polygon;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol;
                    break;
                case "DrawRectangle":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Rectangle;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol;
                    break;
                case "DrawFreehand":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Freehand;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicLineSymbol"] as Symbol;
                    break;
                case "DrawArrow":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Arrow;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol;
                    break;
                case "DrawTriangle":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Triangle;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol;
                    break;
                case "DrawCircle":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Circle;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol;
                    break;
                case "DrawEllipse":
                    MyDrawObjectGraphic.DrawMode = DrawMode.Ellipse;
                    _activeSymbol = LayoutRoot.Resources["DefaultGraphicFillSymbol"] as Symbol;
                    break;
                case "EnterText":
                     MyDrawObjectGraphic.DrawMode = DrawMode.Point;
                    //_activeSymbol = LayoutRoot.Resources["DefaultGraphicMarkerSymbol"] as Symbol;
                     _activeSymbol = new TextSymbol()
                     {
                         Text = "",
                         FontSize = 12,
                     //    Foreground = new SolidColorBrush(clr),
                         FontFamily = new FontFamily("Arial"),
                     };
                    _bolText = true;
                    break;
                case "DrawNothing":
                    MyDrawObjectGraphic.DrawMode = DrawMode.None;
                    break;
                default:
                    MyDrawObjectGraphic.DrawMode = DrawMode.None;
                    graphicsLayer.ClearGraphics();
                    break;
            }
            MyDrawObjectGraphic.IsEnabled = (MyDrawObjectGraphic.DrawMode != DrawMode.None);
        }



Thanks
0 Kudos
TerryGiles
Occasional Contributor III
Christine,

I can reproduce the same behavior here.  The only difference in you DrawComplete handler and mine is I have the following 2 lines after I refresh the graphicslayer -

_Draw.IsEnabled = false;
_Draw.DrawMode = DrawMode.None;

Where _Draw is my Draw object.  If I comment these 2 lines out, I see the behavior you're describing.  My guess it's related to the re-use of the global _activesymbol variable here -
(_activesymbol as TextSymbol).Text = txtText.Text;

any graphic referencing _activesymbol will get changed.

With the 2 lines above added to disable the Draw object, I'm forcing my users to click a button again (point, line, poly, or text) which recreates _activesymbol as a new Symbol instead of just altering it's properties.

I'm sure there's a much better way to explain that, but that's what I see happening.

Hope that helps, Terry
0 Kudos