<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Efficiently Drawing a Zigzag Line in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595297#M13383</link>
    <description>&lt;P&gt;What is the profiler showing as your hot spots? If the lion's share of the time is spent in rendering-related code you might be out of luck if you want an immediate render using world-space data. Building a full list of graphics elements before adding them to the overlay might help here; you can even try building them in a thread or async task that you cancel on each event to avoid blasting graphics at the map when the user makes quick adjustments.&lt;/P&gt;&lt;P&gt;If the bottleneck is constructing the zigzags themselves, two things you can try are:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Hoist as many reusable heap-allocated objects out of the function as possible, the less garbage your zigzags accumulate the better.&lt;/LI&gt;&lt;LI&gt;Do all calculations in the map's current coordinate system and try to use the &lt;A href="https://developers.arcgis.com/net/api-reference/api/net/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Geometry.GeometryEngine.html" target="_self"&gt;GeometryEngine&lt;/A&gt; extension methods to do as much of the math as possible to avoid coordinate errors. This eliminates any reprojection between your graphics and the map.&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Thu, 13 Mar 2025 17:54:38 GMT</pubDate>
    <dc:creator>DavidSolari</dc:creator>
    <dc:date>2025-03-13T17:54:38Z</dc:date>
    <item>
      <title>Efficiently Drawing a Zigzag Line</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595228#M13381</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I'm working on a project where I need to draw zigzag lines of a fixed length on a map. The zigzag pattern needs to dynamically adjust based on the zoom level of the map.&lt;/P&gt;&lt;P&gt;Currently, I've implemented this functionality using a PolylineBuilder to construct the zigzag pattern and re-drawing the line every time the zoom level changes, by handling the MapView.ViewpointChanged event.&lt;BR /&gt;&lt;BR /&gt;While this approach works, I’ve encountered significant performance issues when trying to draw and manage several hundred zigzag lines simultaneously. The frequent re-drawing process slows down the application considerably.&lt;/P&gt;&lt;P&gt;I'm looking for suggestions or best practices to improve the efficiency of this process. Specifically:&lt;/P&gt;&lt;P&gt;Is there a way to optimize the re-drawing of multiple polylines based on zoom level?&lt;/P&gt;&lt;P&gt;Are there any advanced techniques or patterns in the Esri ArcGIS Runtime SDK for .NET that could help minimize performance overhead?&lt;/P&gt;&lt;P&gt;Any guidance, examples, or advice would be greatly appreciated!&lt;BR /&gt;&lt;BR /&gt;Here is the code I used to draw and update the zigzag lines:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void DrawZigZag(string id, double originLatitude, double originLongitude, double rotationAngle)
{
    // Get the current map scale for scaling
    double mapScale = this.mapMainService.mapView.MapScale;
    double scalingFactor = Math.Max(1, mapScale / 500000); // Adjust divisor for sensitivity

    // Zigzag appearance configuration
    double totalDistanceKm = 150 * 1.852; // Total length (150 nautical miles converted to kilometers)
    double zigzagLongitudeDisplacement = 0.01 * scalingFactor; // Horizontal displacement
    double segmentDistanceKm = 1.0 * scalingFactor; // Vertical increment
    double zigzagLatitudeIncrement = segmentDistanceKm / 111.0; // Convert km to degrees (approximation)

    // Convert rotation angle to radians (for CW rotation)
    double angleRadians = Math.PI * (-rotationAngle) / 180.0;
    double cosAngle = Math.Cos(angleRadians);
    double sinAngle = Math.Sin(angleRadians);

    // Create a PolylineBuilder
    PolylineBuilder pb = new PolylineBuilder(SpatialReferences.Wgs84);

    // Starting point (relative coordinates)
    double startX = 0.0;
    double startY = 0.0;

    // Calculate the number of segments
    double totalSegments = totalDistanceKm / segmentDistanceKm;

    List&amp;lt;MapPoint&amp;gt; points = new List&amp;lt;MapPoint&amp;gt;(); // To store all points for center calculation

    // Generate zigzag points
    for (int i = 0; i &amp;lt; totalSegments; i++)
    {
        double x = startX;
        double y = startY;

        if (i % 2 == 0)
        {
            x += zigzagLongitudeDisplacement;
        }
        else
        {
            x -= zigzagLongitudeDisplacement;
        }

        y += zigzagLatitudeIncrement;

        // Rotate the point
        double rotatedX = x * cosAngle - y * sinAngle;
        double rotatedY = x * sinAngle + y * cosAngle;

        // Convert to geographic coordinates
        double rotatedLongitude = originLongitude + rotatedX;
        double rotatedLatitude = originLatitude + rotatedY;

        // Add the rotated point to the polyline
        pb.AddPoint(new MapPoint(rotatedLongitude, rotatedLatitude));

        // Update starting coordinates for the next iteration
        startX = x;
        startY = y;
    }

    // Create a polyline
    Polyline polyline = pb.ToGeometry();

    // Create a symbol for the polyline
    var lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 2);

    // Create attributes for label
    List&amp;lt;KeyValuePair&amp;lt;string, object?&amp;gt;&amp;gt; attributes = new List&amp;lt;KeyValuePair&amp;lt;string, object?&amp;gt;&amp;gt;()
        {
            new KeyValuePair&amp;lt;string, object?&amp;gt;("name", id.ToString()[..10]),
            new KeyValuePair&amp;lt;string, object?&amp;gt;("name", id.ToString()[..10])
        };

    // Create a graphic and add it to the overlay
    Graphic polylineGraphic = new Graphic(polyline, attributes, lineSymbol)
    {

    };
    this.GraphicsOverlay.Graphics.Add(polylineGraphic);
}

public void UpdateZigZags()
{
    // Clear all graphics to redraw
    this.GraphicsOverlay.Graphics.Clear();

    // Redraw each zigzag with the updated scale
    foreach (var kvp in this.zigZagLines)
    {
        var id = kvp.Key;
        var (latitude, longitude, rotation) = kvp.Value;

        DrawZigZag(id, latitude, longitude, rotation);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 15:43:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595228#M13381</guid>
      <dc:creator>AaronBarkan</dc:creator>
      <dc:date>2025-03-13T15:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Efficiently Drawing a Zigzag Line</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595296#M13382</link>
      <description>&lt;P&gt;I think you should look into CIM symbols. I don't work with runtime, but I think it's supported. You can use CIM to build multi-layered symbols that fit your custom needs. There are many examples for CIM symbols for js here:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/visualization/symbols-color-ramps/esri-web-style-symbols-2d/" target="_blank"&gt;Esri Web Style Symbols (2D) | Overview | ArcGIS Maps SDK for JavaScript 4.32 | Esri Developer&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Search for "Zigzag". You can customize the amplitude and density of the waves. Your geometries will be straight, but they will be displayed as zig-zags. It will also resize based on zoom level and should render a lot faster.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 17:51:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595296#M13382</guid>
      <dc:creator>Edvinas_S</dc:creator>
      <dc:date>2025-03-13T17:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Efficiently Drawing a Zigzag Line</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595297#M13383</link>
      <description>&lt;P&gt;What is the profiler showing as your hot spots? If the lion's share of the time is spent in rendering-related code you might be out of luck if you want an immediate render using world-space data. Building a full list of graphics elements before adding them to the overlay might help here; you can even try building them in a thread or async task that you cancel on each event to avoid blasting graphics at the map when the user makes quick adjustments.&lt;/P&gt;&lt;P&gt;If the bottleneck is constructing the zigzags themselves, two things you can try are:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Hoist as many reusable heap-allocated objects out of the function as possible, the less garbage your zigzags accumulate the better.&lt;/LI&gt;&lt;LI&gt;Do all calculations in the map's current coordinate system and try to use the &lt;A href="https://developers.arcgis.com/net/api-reference/api/net/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Geometry.GeometryEngine.html" target="_self"&gt;GeometryEngine&lt;/A&gt; extension methods to do as much of the math as possible to avoid coordinate errors. This eliminates any reprojection between your graphics and the map.&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 13 Mar 2025 17:54:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595297#M13383</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2025-03-13T17:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Efficiently Drawing a Zigzag Line</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595842#M13389</link>
      <description>&lt;P&gt;You can use CIM symbols to do this instead. They have this feature "built in".&lt;/P&gt;&lt;P&gt;Here's an example of a JSON version of a zigzag line symbol:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{"type":"CIMLineSymbol","symbolLayers":[
   {"type":"CIMSolidStroke","effects": [
    {"type":"CIMGeometricEffectWave","amplitude":10,"period":3,"seed":1,"waveform":"Triangle"}]
,"enable":true,"capStyle":"Butt","joinStyle":"Round","lineStyle3D":"Strip",
"miterLimit":10,"width":1,"height3D":1,"anchor3D":"Center","color":[104,104,104,255]}]}&lt;/LI-CODE&gt;&lt;P&gt;You can play with the parameters to get what you want.&lt;/P&gt;&lt;P&gt;Example of creating a symbol from this JSON:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Symbol s = Symbol.FromJson("{\"type\":\"CIMLineSymbol\",\"symbolLayers\":[{\"type\":\"CIMSolidStroke\",\"effects\":[{\"type\":\"CIMGeometricEffectWave\",\"amplitude\":10,\"period\":3,\"seed\":1,\"waveform\":\"Triangle\"}],\"enable\":true,\"capStyle\":\"Butt\",\"joinStyle\":\"Round\",\"lineStyle3D\":\"Strip\",\"miterLimit\":10,\"width\":1,\"height3D\":1,\"anchor3D\":\"Center\",\"color\":[104,104,104,255]}]}")!;
SimpleRenderer r = new SimpleRenderer(s);
layer.Renderer = r;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also use the CIM APIs to build it up, but JSON is just a quick way to show the concept.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Mar 2025 18:22:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595842#M13389</guid>
      <dc:creator>dotMorten_esri</dc:creator>
      <dc:date>2025-03-15T18:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Efficiently Drawing a Zigzag Line</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595874#M13390</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi everyone,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks so much for your suggestions, especially about CIM symbols. I implemented them, and the performance has improved significantly—it works great now!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I used the zigzag CIM symbol from this resource:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/visualization/symbols-color-ramps/esri-web-style-symbols-2d/" target="_blank"&gt;Esri Web Style Symbols (2D) | Overview | ArcGIS Maps SDK for JavaScript 4.32 | Esri Developer&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, I’ve noticed an issue with the appearance of the zigzag line—it seems to be cut off in the middle. I'll attach a photo (see below). Has anyone experienced this or know how to fix it?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cut off Zigzag" style="width: 235px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/127990i711E2B160B426DE1/image-size/large?v=v2&amp;amp;px=999" role="button" title="{81623881-B0CA-4FAB-9B54-36A1C9CB7CB6&amp;amp;#125;.png" alt="Cut off Zigzag" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Cut off Zigzag&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is how the normal line should look like for reference:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Normal Zigzag" style="width: 147px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/127991i97EC2ECC4E2C1382/image-size/large?v=v2&amp;amp;px=999" role="button" title="{00CD4975-5EE4-4B9B-AF46-F87441E74736&amp;amp;#125;.png" alt="Normal Zigzag" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Normal Zigzag&lt;/span&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again for your help!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Mar 2025 08:24:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595874#M13390</guid>
      <dc:creator>AaronBarkan</dc:creator>
      <dc:date>2025-03-16T08:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Efficiently Drawing a Zigzag Line</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595961#M13391</link>
      <description>&lt;P&gt;Try checking the geometry. Is it one long line, or maybe a lot of small ones? Does the broken zigzag stay all the time, or just on specific zoom levels?&lt;/P&gt;&lt;P&gt;If geometry is fine, try changing the CIMGeometricEffectWave parameters:&amp;nbsp;&lt;SPAN&gt; amplitude,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;period and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;seed&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Try changing cap style (Butt, Round, Square), or join style (Bevel, Round, Miter)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If none of that works, this is probably a bug.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 07:51:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/efficiently-drawing-a-zigzag-line/m-p/1595961#M13391</guid>
      <dc:creator>Edvinas_S</dc:creator>
      <dc:date>2025-03-17T07:51:46Z</dc:date>
    </item>
  </channel>
</rss>

