Street direction

Topics: SharpMap Project, SharpMap v0.9 / v1.x, WinForms Controls
Mar 22, 2012 at 8:10 AM
Edited Mar 22, 2012 at 8:10 AM

How i can to draw arrows on polylines to show street direction, if my polylines must to have different styles (small street, big street). SharpMap.Layers.Symbolizer.LinealVectorLayer does not support themes(i want to set own style for each polyline), can i do this using themes in VectorLayer?

Thanks in advance.

Coordinator
Mar 22, 2012 at 12:25 PM

You can apply a line symbolizer to the GeometryStyle as well. It is not as efficient as using LinealVectorLayer, but it works.

Thus you can use it in themes as well. Another idea would be to split the datasource into categories. You will then have more layers but less theming. It probably will perform better!

Hth FObermaier

Mar 22, 2012 at 8:25 PM

CachedLineSymbolizer does not work(polyline does not draw), my code is

 CachedLineSymbolizer cls = new CachedLineSymbolizer();
                        cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Brown, 5) });
                        cls.LineSymbolizeHandlers.Add(new WarpedLineSymbolizeHander
                                    {
                                        Pattern = WarpedLineSymbolizer.GetTriangleSeries(12, 20),
                                        Line = new Pen(Color.Red, 2),
                                        Fill = new SolidBrush(Color.Firebrick)
                                    });
                        style.LineSymbolizer = cls;
and when i use only WarpedLineSymbolizer with pattern WarpedLineSymbolizer.GetTriangleSeries(12, 20), all triangles are drawn parallel polyline (it does not look like arrows). Please help me with CachedLineSymbolizer and how can i rotate WarpedLineSymbolizer triangles?

Developer
Mar 23, 2012 at 4:40 AM

Try add:

Line.StartCap = LineCap.Round;
Line.EndCap = LineCap.ArrowAnchor;
Line.CustomEndCap = new AdjustableArrowCap(2, 2);

Mar 23, 2012 at 5:46 AM

In this case arrows will be only at the end of polyline and if i wand to check direction, i must see fully polyline(

Coordinator
Mar 23, 2012 at 7:27 AM

You have to modify the WarpedLineSymbolizer.GetTriangleSeries like this

/// <summary>
/// Creates a forward oriented triangle pattern
/// </summary>
/// <param name="x">The base length of the triangle</param>
/// <param name="y">The location of the next triangle</param>
/// <returns></returns>
public static GraphicsPath GetTriangleSeriesForward(float x, float y)
{
    var gp = new GraphicsPath();
    gp.AddPolygon(new[] { new PointF(0f, -0.5f*x), new PointF(0f, 0.5f*x), new PointF(2f * x / 3f, 0), new PointF(0f, -0.5f*x) });
    gp.CloseFigure();

    //Just to move to a new position
    gp.AddEllipse(y, 0f, 0f, 0f);
    gp.CloseFigure();
    return gp;
}

Why do you think the CachedLineSymbolizer does not work? I have checked the example in the example code snipplets project and everything looks fine to me.

Hth FObermaier

Coordinator
Mar 23, 2012 at 7:36 AM

Addendum:

If you would want to use trieuvy's alternative, you'd have to split the polyline into segments. There are forum posts that deal with this topic

Mar 23, 2012 at 7:47 AM

In the example code snipplets, VectorLayer does not use themes, in my case VectorStyle  is retrieved from my CustomTheme (RenderInternal function in VectorLayer has some differences), maybe reason in this(

Thanks in advance.

Coordinator
Mar 23, 2012 at 7:58 AM

Good point, I'll take a look

Developer
Mar 23, 2012 at 8:57 AM

I checked RenderInternal function with theme. The present it was not supported LineSymbolizer

lack the segment code:

 

 if (vStyle.LineSymbolizer != null)
  {
        vStyle.LineSymbolizer.Symbolize(g, map);
        vStyle.LineSymbolizer.End(g, map);
  }

I notice that Symbolizer access a data source again and slow shaprmap down

Maybe next time, i will add direction style in to sharpmap core like outline style.

Coordinator
Mar 23, 2012 at 9:30 AM

@vxd_dev:

Just added ImmediateMode property to CachedLineSymbolizer, that works with theming, if set to true.

@trieuvy:

The symbolizer, if applied to a style is unaware of any provider, so it presumably can't be the cause of having to requery the datasource.
The deal with CachedLineSymbolizer is that it transforms the queried geometries once to graphics paths and applies the assigned line symbolizers subsequently. This is different than with using EnableOutline where the graphics paths are created twice. My test case shows that CachedLineSymbolizer performs better than EnableOutline (if you do not use the warped symbolizer).

FObermaier

Developer
Mar 23, 2012 at 9:51 AM

Thanks FObermaier!

Mar 23, 2012 at 10:56 AM

Thanks a lot.

Dec 5, 2012 at 2:40 AM
FObermaier wrote:

@vxd_dev:

Just added ImmediateMode property to CachedLineSymbolizer, that works with theming, if set to true.

@trieuvy:

The symbolizer, if applied to a style is unaware of any provider, so it presumably can't be the cause of having to requery the datasource.
The deal with CachedLineSymbolizer is that it transforms the queried geometries once to graphics paths and applies the assigned line symbolizers subsequently. This is different than with using EnableOutline where the graphics paths are created twice. My test case shows that CachedLineSymbolizer performs better than EnableOutline (if you do not use the warped symbolizer).

FObermaier

Hi FObermaier,

Can you help me for how to add ImmediateMode property to CachedLineSymbolizer.

I can't find ImmediateMode property in CachedLineSymbolizer Class.

Thank you & Best regards!

Coordinator
Dec 5, 2012 at 9:39 AM

It is there:

http://sharpmap.codeplex.com/SourceControl/changeset/view/100705#1811515

Find: ImmediateMode

Maybe you use some old source?

Hth FObermaier

Dec 6, 2012 at 3:08 AM

Thank FObermaier a lot!