ThinkGeo.com    |     Documentation    |     Premium Support

Zig-Zag Custom Line Styles

Hi,

Is it possible to angle outer/inner lines to create a zig zag effect? Another is asterisks periodically along the centre line. Sorry if I’ve missed something obvious!

Ideally it resembles something simple like this:

Regards,
Sam

Hi Sam,

Here is a sample and how it looks like:

You can refer the sample and implement yours, wish that’s helpful.

       private void map_Loaded(object sender, RoutedEventArgs e)
    {
        map.MapUnit = GeographyUnit.Meter;

        LineShape line1 = new LineShape();

        for (int i = 0; i < 50; i++)
        {
            line1.Vertices.Add(new Vertex(i, i));
        }

        
        Collection<Vertex> newLineVertexCollection = new Collection<Vertex>();
        
        bool directionFlag = true;

        newLineVertexCollection.Add(line1.Vertices[0]);

        for (int i = 0; i < line1.Vertices.Count - 1; i++)
        {

            Vertex tmpV = Get3rdVertexOfEquilateralTriangle(line1.Vertices[i], line1.Vertices[i + 1], directionFlag);
            newLineVertexCollection.Add(tmpV);

            directionFlag = !directionFlag;
        }

        newLineVertexCollection.Add(line1.Vertices[line1.Vertices.Count - 1]);


        Feature f1 = new Feature(line1);
        Feature f = new Feature(new LineShape(newLineVertexCollection));

        map.EditOverlay.EditShapesLayer.InternalFeatures.Add(f1);
        map.EditOverlay.EditShapesLayer.InternalFeatures.Add(f);

        map.CurrentExtent = f.GetBoundingBox();
        map.Refresh();
    }

    private Vertex Get3rdVertexOfEquilateralTriangle(Vertex p1, Vertex p2, bool directionFlag)
    {
        int angle = 60;

        if (!directionFlag)
        {
            angle = -60;
        }

        double radians = (Math.PI / 180) * angle;

        double sinAngle = Math.Sin(radians);
        double cosAngle = Math.Cos(radians);

        double x1 = p1.X;
        double y1 = p1.Y;
        double x2 = p2.X;
        double y2 = p2.Y;

        Vertex p3 = new Vertex(cosAngle * (x1 - x2) - sinAngle * (y1 - y2) + x2,
            sinAngle * (x1 - x2) + cosAngle * (y1 - y2) + y2);

        return p3;
    }

    private Collection<Vertex> SplitLine(Vertex startPoint, Vertex endPoint)
    {
        // Cut a segement into many vertexes
        throw new NotImplementedException();
    }

Regards,

Ethan