# Custom line dash style (power line, rail road)

**URL:** <https://community.thinkgeo.com/t/custom-line-dash-style-power-line-rail-road/10067>\
**Category:** WPF\
**Created:** [May 6, 2021, 7:12am UTC](https://community.thinkgeo.com/t/custom-line-dash-style-power-line-rail-road/10067 "2021-05-06T07:12:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikko\_Viitala](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@Mikko\_Viitala](https://community.thinkgeo.com/u/Mikko_Viitala)\
**Post date:** [May 6, 2021, 7:12am UTC](https://community.thinkgeo.com/t/custom-line-dash-style-power-line-rail-road/10067/1 "2021-05-06T07:12:01Z")

</div>

Hey,

I’m trying to create custom dash style for lines but can’t find too much information on how to go about it. I tried to use LineDashStyle.Custom and then add a few LineStyles to CustomLineStyles collection. Seems that all styles are applied “at once” and I just can’t come up with satisfactory results… ☹

I’d need to implement the following:

![style2](https://community.thinkgeo.com/uploads/default/original/3X/0/d/0d0c92424da9a030d74ccbf6abeaa91a982059e5.png)  
 ![style1](https://community.thinkgeo.com/uploads/default/original/3X/5/4/54fec0ff641d37013aa0a1735a33eae67564dacd.png)

Any help? Thanks.

---

<div class="post-metadata">

**Author:** ![Mikko\_Viitala](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@Mikko\_Viitala](https://community.thinkgeo.com/u/Mikko_Viitala)\
**Post date:** [May 6, 2021, 11:35am UTC](https://community.thinkgeo.com/t/custom-line-dash-style-power-line-rail-road/10067/2 "2021-05-06T11:35:55Z")

</div>

Seems like I managed to solve this by myself. I’ll post the code here in case someone else needs something similar.

```
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(
    GeoColors.Black, 3, LineDashStyle.Solid,
    GeoColors.Black, 3, LineDashStyle.Solid,
    GeoColors.Black, 12, LineDashStyle.Custom,
    true);
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.DashPattern.Clear();
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.DashPattern.Add(0.05f);
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.DashPattern.Add(1.6f);
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.StartCap = DrawingLineCap.Flat;
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.EndCap = DrawingLineCap.Flat;

```

 ![style4](https://community.thinkgeo.com/uploads/default/original/3X/e/8/e8fff0e749cafa4d857841a86232ca5cb110f653.png)

```
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(
    GeoColors.Transparent, 0, LineDashStyle.Solid,
    GeoColors.White, 3, LineDashStyle.Dash,
    GeoColors.Black, 6, LineDashStyle.Solid,
    true);
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.InnerPen.DashPattern.Clear();
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.InnerPen.DashPattern.Add(1f);
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.InnerPen.DashPattern.Add(1f);
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.InnerPen.StartCap = DrawingLineCap.Flat;
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.InnerPen.EndCap = DrawingLineCap.Flat;

```

![style3](https://community.thinkgeo.com/uploads/default/original/3X/9/7/97ec68c9378d8b05b806e8000814a3e431c89fbd.png)

---

<div class="post-metadata">

**Author:** ![Kyle\_Day](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/kyle_day/32/25613_2.png) [@Kyle\_Day](https://community.thinkgeo.com/u/Kyle_Day)\
**Post date:** [May 6, 2021, 5:13pm UTC](https://community.thinkgeo.com/t/custom-line-dash-style-power-line-rail-road/10067/3 "2021-05-06T17:13:50Z")

</div>

Hey @Mikko_Viitala,

Glad you were able to figure out the dash styles on your own and thank you for posting your solution! I think it would be fitting for us to update our samples to include more detail on how to do more complex `LineStyles` for future reference.

To expand on this a bit more, you really only need the inner and outer pen to achieve your results, no need for the center pen as you’ve already figured out. Additionally, I would recommend using the normal `LineStyle` constructor when it comes to more complex line styles, like dash lines, since it gives you better control over how each pen is drawn. Below is some example code that achieves similar results:

```cs
var lineStyle = new LineStyle(
    outerPen: new GeoPen(GeoColors.Black, 16)
    {
        DashStyle = LineDashStyle.Custom,
        DashPattern = { 0.2f, 5f },
        StartCap = DrawingLineCap.Flat,
        EndCap = DrawingLineCap.Flat
    },
    innerPen: new GeoPen(GeoColors.Black, 4)
);

```

 ![image](https://community.thinkgeo.com/uploads/default/original/3X/4/4/44822d74c2c11d592353a7477b2e8f574385590b.png)

```cs
var lineStyle = new LineStyle(
    outerPen: new GeoPen(GeoColors.Black, 12),
    innerPen: new GeoPen(GeoColors.White, 6)
    {
        DashStyle = LineDashStyle.Custom,
        DashPattern = { 3f, 3f },
        StartCap = DrawingLineCap.Flat,
        EndCap = DrawingLineCap.Flat
    }
);

```

 ![image](https://community.thinkgeo.com/uploads/default/original/3X/8/3/83fca4988a953f5af3a3a731283b1af39646ddd7.png)

Thanks,  
Kyle

---

<div class="post-metadata">

**Author:** ![Mikko\_Viitala](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@Mikko\_Viitala](https://community.thinkgeo.com/u/Mikko_Viitala)\
**Post date:** [May 7, 2021, 5:25am UTC](https://community.thinkgeo.com/t/custom-line-dash-style-power-line-rail-road/10067/4 "2021-05-07T05:25:01Z")

</div>

Thanks. Seems like I took the harder way around 😃

Another issue I faced is clustering so maybe I ask it here even it’s not related to original topic.

I have an overlay which has multiple layers on it containing multilines. Now to get clustering working I’m extracting center point of each feature, put those on separate layer, and do cluster styling based on those points. Is there any way to cluster the original multilines without the extra effort?

---

<div class="post-metadata">

**Author:** ![Kyle\_Day](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/kyle_day/32/25613_2.png) [@Kyle\_Day](https://community.thinkgeo.com/u/Kyle_Day)\
**Post date:** [May 7, 2021, 4:27pm UTC](https://community.thinkgeo.com/t/custom-line-dash-style-power-line-rail-road/10067/5 "2021-05-07T16:27:18Z")

</div>

Hey @Mikko_Viitala,

No worries, considering where you started out, you still achieved the same result. And sometimes, that’s all you need.

For your follow-up question, I think you are going in the right direction since only points are supported for clustering and you are dealing with multiple layers at a time with a potential of overlapping areas.

Alternatively, you could extend the `ClusterPointStyle` class and override the `DrawCore` method that converts any features that would be drawn to the center point of that feature instead. Something like:

```cs
public class CenterPointClusterStyle : ClusterPointStyle
{
    public CenterPointClusterStyle(PointStyle pointStyle, TextStyle textStyle)
        : base(pointStyle, textStyle) { }

    protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
    {
        var centerPointFeatures = new Collection<Feature>();
        foreach (var feature in features)
        {
            var centerFeature = new Feature(feature.GetShape().GetCenterPoint(), feature.ColumnValues);
            centerPointFeatures.Add(centerFeature);
        }
        base.DrawCore(centerPointFeatures, canvas, labelsInThisLayer, labelsInAllLayers);
    }
}

```

The only limitation to this is that it only applies to a single layer at a time. Since you have multiple layers in your overlay, this might not be what you are looking for. But this might give you an idea of how to solve this more efficiently without having to create brand new point layers.

Thanks,  
Kyle
