Creating a line graphic with symbol style "Solid" throws

930
5
03-17-2017 03:49 AM
JannisKotsis
New Contributor

I modified one of the standard WPF samples (RenderSimpleMarkers) to create a line graphic instead of a point graphic e.g:

replaced:  

Graphic graphicWithSymbol = new Graphic(centralLocation, simpleSymbol);

with:

Graphic graphicWithSymbol = CreateSimpleLine(), where CreateSimpleLine is  the following procedure:

public static Graphic CreateSimpleLine()
{
MapPoint point1 = new MapPoint(-79.497238, 8.849289, SpatialReferences.Wgs84);

var newPoint1 = (MapPoint)GeometryEngine.Project(point1, SpatialReferences.WebMercator);

var cartoLineSym = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Black, 1);

MapPoint point2 = new MapPoint(-80.035568, 9.432302, SpatialReferences.Wgs84);
var newPoint2 = (MapPoint)GeometryEngine.Project(point2, SpatialReferences.WebMercator);
var aBuilder = new PolylineBuilder(new MapPoint[] { newPoint1, newPoint2 });

var aGraphic = new Graphic(aBuilder.ToGeometry(), cartoLineSym);
return aGraphic;
}

If I change the SimpleLineSymbolStyle to other than solid everything works OK but with the solid pattern the program throws!

Tags (1)
0 Kudos
5 Replies
ChadYoder1
Occasional Contributor II

We are using this to draw a solid line with throwing any errors.

The polyline passed in is created using a List<MapPoint>, such as var polyline = new Polyline(mapPtList);

Maybe there is an issue with the Geometry created by the polyline builder.

/// <summary>
/// Creates the line symbol.
/// </summary>
/// <param name="polyline">Polyline.</param>
public static Graphic CreatePolylineSymbol (Polyline polyline)
{
  //Create the symbol and add the graphic to the map
  var lineSymbol = new SimpleLineSymbol () {
  Width = 5,
  Style = SimpleLineSymbolStyle.Solid
#if !__IOS__
#if WINDOWS_UWP
           ,Color = Windows.UI.Colors.Cyan
#else
           ,Color = System.Drawing.Color.Cyan
#endif
#endif
  } ;

  //Create the graphic and add to the map
  Graphic lineGraphic = new Graphic (polyline, lineSymbol);
  return lineGraphic;
}

 

0 Kudos
JannisKotsis
New Contributor

Can't be an issue with the geometry because it works as expected for other line styles... 

0 Kudos
ChadYoder1
Occasional Contributor II

Good point!

0 Kudos
JenniferNery
Esri Regular Contributor

I tried your code as-is for creating geometry and symbol, added this line to see the graphic. SimpleLineSolid.Style worked. Also tried in on Forms.Android.

MyMapView.SetViewpoint(new Viewpoint(aGraphic.Geometry.Extent));

Since I couldn't repro, I tried the following to iterate through SimpleLineSymbol styles and use SketchEditor to draw freehand (gesture: touch down, drag and up).

foreach (SimpleLineSymbolStyle lineStyle in Enum.GetValues(typeof(SimpleLineSymbolStyle)))
{
    var symbol = new SimpleLineSymbol(lineStyle, Colors.Cyan, 5d);
    try
    {
        var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.FreehandLine, false);
        overlay.Graphics.Add(new Graphic(geometry, symbol));
    }
    catch (TaskCanceledException)
    {

    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
    }
}

Every style worked and Null style is the only thing that did not render as expected.

GraphicsRenderingMode.Dynamic(default) or Static did not seem to make a difference in this case. Am I missing something in your repro code? 

0 Kudos
JannisKotsis
New Contributor

You can take the following code and paste it in the RenderSimpleMarkers.xaml.cs, sample provided in from ArcgisRuntime.WPF.Samples. This draws a red line across the Panama Canal, if it's style isn't SOLID of cource!

public partial class RenderSimpleMarkers
{
public RenderSimpleMarkers()
{
InitializeComponent();

// Create the UI, setup the control references and execute initialization
Initialize();
}

private void Initialize()
{
// Create new Map with basemap
Map myMap = new Map(Basemap.CreateImagery());

// Create initial map location and reuse the location for graphic
MapPoint point1 = new MapPoint(-79.497238, 8.849289, SpatialReferences.Wgs84);

var centralLocation = (MapPoint)GeometryEngine.Project(point1, SpatialReferences.WebMercator);

Viewpoint initialViewpoint = new Viewpoint(centralLocation, 1000000);

// Set initial viewpoint
myMap.InitialViewpoint = initialViewpoint;

// Provide used Map to the MapView
MyMapView.Map = myMap;

// Create overlay to where graphics are shown
GraphicsOverlay overlay = new GraphicsOverlay();

// Add created overlay to the MapView
MyMapView.GraphicsOverlays.Add(overlay);

// Create a simple marker symbol
SimpleMarkerSymbol simpleSymbol = new SimpleMarkerSymbol()
{
Color = Colors.Red,
Size = 10,
Style = SimpleMarkerSymbolStyle.Circle
};

// Add a new graphic with a central point that was created earlier
Graphic graphicWithSymbol = CreateSimpleLine(); //new Graphic(centralLocation, simpleSymbol);
overlay.Graphics.Add(graphicWithSymbol);
}



public static Graphic CreateSimpleLine()
{
MapPoint point1 = new MapPoint(-79.497238, 8.849289, SpatialReferences.Wgs84);
var newPoint1 = (MapPoint)GeometryEngine.Project(point1, SpatialReferences.WebMercator);
var cartoLineSym = new SimpleLineSymbol(SimpleLineSymbolStyle.DashDot, Colors.Red, 5);
MapPoint point2 = new MapPoint(-80.035568, 9.432302, SpatialReferences.Wgs84);
var newPoint2 = (MapPoint)GeometryEngine.Project(point2, SpatialReferences.WebMercator);
var aBuilder = new PolylineBuilder(new MapPoint[] { newPoint1, newPoint2 });

var aGraphic = new Graphic(aBuilder.ToGeometry(), cartoLineSym);
return aGraphic;

}
}

0 Kudos