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.

The following C# code works when drawing in Point mode, but not Polyline . . .

  // "Draw" is ESRI.ArcGIS.Client.Draw object
       _draw = new Draw(_map);
       _draw.DrawMode = DrawMode.Polyline;
       _draw.DrawComplete += (senderObject, drawEventArgs) =>
        {
            _barrierLine = new Graphic();
            _barrierLine.Symbol = this.Resources["LineSymbol"] as SimpleLineSymbol;
            _barrierLine.Geometry = drawEventArgs.Geometry;
            _lineGraphicsLayer.Graphics.Add(_barrierLine);
        };

This is what the XML code looks like (I tried several different methods):

   <Window.Resources>
        <esri:SimpleMarkerSymbol x:Key="PointSymbol" Color="DarkViolet" Size="15" Style="Diamond"></esri:SimpleMarkerSymbol>
        <esri:SimpleLineSymbol x:Key="LineSymbol" Color="Aqua" Width="5" Style="Solid"></esri:SimpleLineSymbol>
    </Window.Resources>
    <Grid>
        <Grid.Resources>
            <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red"/>
            <esri:SpatialReference x:Key="theSpatialReference" WKID="4326"/>
            <esri:SimpleLineSymbol x:Key="LineSymbol" Color="Aqua" Width="3" Style="Solid"/>      
        </Grid.Resources>
            <!--Graphics Layer-->
            <esri:GraphicsLayer ID="graphicsLayer" x:Name="_graphicsLayer">
                <esri:Graphic>                    
                    <esri:Graphic.Symbol>                        
                        <esri:SimpleMarkerSymbol Style="Circle" Color="Red"/>
                    </esri:Graphic.Symbol>
                    <esri:Graphic.Geometry>
                        <esri:MapPoint  X="0" Y="0" >
                            <esri:MapPoint.SpatialReference>
                                <esri:SpatialReference WKID="4326"/>
                            </esri:MapPoint.SpatialReference>
                        </esri:MapPoint>                    
                        </esri:Graphic.Geometry>                  
                </esri:Graphic> 
            </esri:GraphicsLayer>
            <esri:GraphicsLayer ID="lineGraphicsLayer" x:Name="_lineGraphicsLayer">
                <esri:Graphic>
                    <esri:Graphic.Symbol>
                        <esri:SimpleLineSymbol Style="Solid" Color="Aqua" Width="3" />
                    </esri:Graphic.Symbol>
                    <esri:Graphic.Geometry>
                        <esri:Polyline>
                            <esri:Polyline.SpatialReference>
                                <esri:SpatialReference WKID="4326"/>
                            </esri:Polyline.SpatialReference>
                        </esri:Polyline>
                    </esri:Graphic.Geometry>
                </esri:Graphic>

            </esri:GraphicsLayer>
        </esri:Map>
        <StackPanel Orientation="Vertical" HorizontalAlignment="Left">
            <Button Content="Stops" VerticalAlignment="Top" Name="StopsButton" Margin="5,5,5,0" Click="StopsButton_Click" />
            <Button Content="Point Barriers" Height="23" Name="PointBarriersButton" Width="76" Click="PointBarriersButton_Click" />
            <Button Content="Solve" Name="SolveButton" Margin="5,5,5,0" Click="SolveButton_Click" />
            <Button Content="Line Barriers" Height="23" Name="LineBarriersButton" Width="76" Click="LineBarriersButton_Click" />
        </StackPanel>
    </Grid>
share|improve this question
    
When I run the code, and then attempt to click on the map, the error message "Graphic symbol is not serializable to JSON" keeps popping up, no matter how I modify the above code. Searching online for this error message didn't turn up anything helpful for me either. –  Renee Cammarere Jan 24 '13 at 20:42
add comment

2 Answers

A simple modification of the above C# code did the trick . . .

// "Draw" is ESRI.ArcGIS.Client.Draw object
       _draw = new Draw(_map);
            {
                LineSymbol = this.Resources["LineSymbol"] as SimpleLineSymbol
            };       
       _draw.DrawComplete += (senderObject, drawEventArgs) =>
       {
            _barrierLine = new Graphic();
            _barrierLine.Symbol = this.Resources["LineSymbol"] as SimpleLineSymbol;
            _barrierLine.Geometry = drawEventArgs.Geometry;
            _lineGraphicsLayer.Graphics.Add(_barrierLine);
        };
share|improve this answer
add comment
    _draw.DrawComplete += (senderObject, drawEventArgs) =>
    {
        _barrierLine = new Graphic();
        _barrierLine.Symbol = this.Resources["LineSymbol"] as SimpleLineSymbol;
        _barrierLine.Geometry = drawEventArgs.Geometry;
        _lineGraphicsLayer.Graphics.Add(_barrierLine);
    };

I suspect this is not firing properly. When you draw a point releasing the mouse would be a DrawComplete action. I suspect with a polyline the system doesn't know when you are done and doesn't execute this code. For testing change the listener to a mouse up and see what happens. I would add further that this will only verify that your event is not firing. It will crash horribly. To avoid this you should create the polyline object outside the listener and add points after the mouse up. On your terminator event (double_click usually) you should execute the code needed to signal the end of the polyline.

share|improve this answer
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.