VectorLayer.Style.Line and VectorLayer.Style.PointColor doesn't show any effect

Topics: WinForms Controls
Aug 29, 2013 at 3:52 AM
Edited Aug 29, 2013 at 3:54 AM
Hi All,

I am playing with the ShapeMap and things are looking pretty good. Thanks for the control.

For some reason, I am not able to change the Line Color/Width and Point Color/Size. It always draws them as red point and blank lines.

I tinkered with, layerA.Style.Line = new Pen(linkColor, linkWidth);
also tried layerA.Style.Enabled = ture; but no avail :(

Any suggestions, guidance, pointing to some sample code?

Thanks,
Musa
Coordinator
Aug 29, 2013 at 7:33 AM
Edited Aug 29, 2013 at 7:36 AM
You can
  • assign any bitmap to the VectorStyle.Symbol property. There are other properties you can use to modify Symbol appearance on map.
  • assing a PointSymbolizer to the VectorStyle.PointSymbolizer property.
In the repository there are a lot of examples in the WinFormSamples- and ExampleCodeSnipplets projects.

Hth FObermaier
Coordinator
Aug 29, 2013 at 7:34 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Aug 29, 2013 at 1:10 PM
Edited Aug 29, 2013 at 1:12 PM
Thanks for the direction. I must be doing something wrong here as I don't see any change in node symbology:
private VectorLayer DrawNodes(Collection<IGeometry> geometryCollection)
{
    VectorLayer nodeLayer = new VectorLayer("nodeLayer");
    //nodeLayer.Style.PointColor = new SolidBrush(nodeColor);
    //nodeLayer.Style.Fill = new SolidBrush(nodeColor);
    //nodeLayer.Style.PointSize = nodeSize;
    //nodeLayer.Style.Enabled = true;


    var pps = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(new Pen(nodeColor), new SolidBrush(nodeColor), nodeSize);
    nodeLayer.Style.PointSymbolizer = pps;
            

    foreach (KeyValuePair<int, Node> nodeItem in Nodes)
    {
        Node node = nodeItem.Value;
        Coordinate nodeCoord = new Coordinate(node.X, node.Y);
        geometryCollection.Add(GeometryFactory.CreatePoint(nodeCoord));
    }

    nodeLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(geometryCollection);

    return nodeLayer;
}
appreciate any help.
Coordinator
Aug 29, 2013 at 2:24 PM
I assume you do sth wrong when you configure your map. Could you post that code?
Aug 29, 2013 at 3:06 PM
It's not straight copy and paste but this is what I am doing more or less:
// Add SharpMap
mapControl = new SharpMap.Forms.MapBox();
mapControl.Dock = DockStyle.Fill;
mapControl.BackColor = Color.LightYellow;
mapControl.ZoomToPointer = true;
mapControl.EnableShiftButtonDragRectangleZoom = true;


Collection<IGeometry> geometryCollection = new Collection<IGeometry>();
mapControl.Map.Layers.Clear();

mapControl.Map.Layers.Add(DrawNodes(geometryCollection));

// Drawnodes(arg)  please refer to previous post.


mapControl.Map.ZoomToExtents();
mapControl.Map.Zoom = mapControl.Map.Zoom * 1.10; // add extra white space
mapControl.Refresh();
Interestingly or oddly Styles on polygons are working:
VectorLayer polygonLayer = new VectorLayer("polygonLayer");
polygonLayer.Style.Outline = new Pen(polygonLineColor, polygonLineWidth);
polygonLayer.Style.Fill = new SolidBrush(Color.FromArgb(polygonTransparance, polygonFillColor));
polygonLayer.Style.EnableOutline = true;
Thank you for your support.
Aug 30, 2013 at 11:54 AM
Any suggestion, why the style and PointSymbolizer is not working?
Coordinator
Aug 30, 2013 at 12:52 PM
I'm sorry, I cannot reproduce your issue:
This code works fine for me:

using System;
using System.Drawing;
using System.Windows.Forms;
using SharpMap;
using SharpMap.Data.Providers;
using SharpMap.Layers;
using SharpMap.Rendering.Symbolizer;
using SharpMap.Styles;

namespace SharpMapTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            mapBox1.Map = SetupMap(0);
        }

        private Map SetupMap(int style)
        {
            var m = new Map();

            var vl = new VectorLayer("RandomPoints");
            var x = CreatingData.GetRandomOrdinates(50, 0, 100);
            var y = CreatingData.GetRandomOrdinates(50, 0, 100);
            vl.DataSource = new GeometryFeatureProvider(CreatingData.CreatePointFeatureDataTableFromArrays(x, y, null));

            switch (style)
            {
                case 0:
                    vl.Style.PointColor = new SolidBrush(Color.Blue);
                    vl.Style.PointSize = 15;
                    break;
                case 1:
                    vl.Style.Symbol = VectorStyle.DefaultSymbol;
                    break;
                case 2:
                    var ps = new CharacterPointSymbolizer();
                    ps.CharacterIndex = 65;
                    ps.Font = new Font("Arial", 32, FontStyle.Italic);
                    vl.Style.PointSymbolizer = ps;
                    break;
                case 3:
                    vl.Style.PointSymbolizer = PathPointSymbolizer.CreateTriangle(Pens.BlueViolet, Brushes.SandyBrown, 20);
                    break;
            }
            m.Layers.Add(vl);
            m.ZoomToExtents();
            return m;
        }

        private int kind;

        private void btnChange_Click(object sender, EventArgs e)
        {
            kind++;
            mapBox1.Map = SetupMap(kind % 4);
            if (kind == 4) kind = 0;
        }
    }
}
This is what I did:
  1. Download released SharpMap version (Core + UI)
  2. Extracted files to some directory
  3. Created new WinForms Project
  4. Added reference path to directory created in 2
  5. Added references to extracted assemblies.
  6. Added mapbox1 control to Form1
  7. Added the above code
I didn't even have to add a binding redirect.

Hth FObermaier
Aug 30, 2013 at 4:00 PM
Thank you FOBermaier. Confirmed. The code provided works. So, there must be something going on the way I am doing it. Since it's not that complex, I should be able to figure out. If there is anything worth sharing out, will do that.

Thanks for building the confidence.
Aug 30, 2013 at 5:03 PM
I think I found what's going on and might be a bug or wrong steps in my end

1) Add another layer (let's say ly2) for creating points
2) Set style to ly2 (obviously different than ly)
3) Run the code.

you will notice the style of first layer ly is overwritten (or something) by the second layer. (may be this is not the way I should do it)

I have to modify the code you provided as I don't have "CreatingData".

But to save your time, following lines may help to copy/paste on your end.
var vl2 = new VectorLayer("secondLayer");
vl2.DataSource = //?

switch (style)
{
    case 0:
        vl.Style.PointColor = new SolidBrush(Color.Green);
        vl.Style.PointSize = 15;

        vl2.Style.PointColor = new SolidBrush(Color.Red);
        vl2.Style.PointSize = 5;

        break;
    case 1:
        vl.Style.Symbol = VectorStyle.DefaultSymbol;
        vl2.Style.Symbol = VectorStyle.DefaultSymbol;
        break;
    case 2:
        var ps = new CharacterPointSymbolizer();
        ps.CharacterIndex = 65;
        ps.Font = new Font("Arial", 32, FontStyle.Italic);
        vl.Style.PointSymbolizer = ps;

        ps = new CharacterPointSymbolizer();
        ps.CharacterIndex = 66;
        ps.Font = new Font("Arial", 32, FontStyle.Italic);
        vl2.Style.PointSymbolizer = ps;

        break;
    case 3:
        vl.Style.PointSymbolizer = PathPointSymbolizer.CreateTriangle(Pens.BlueViolet, Brushes.SandyBrown, 20);
        vl2.Style.PointSymbolizer = PathPointSymbolizer.CreateTriangle(Pens.Cyan, Brushes.SandyBrown, 10);
        break;
}
Now, if you see features drawn with one color in the Map then you were able to reproduce and if you see two different colors then again my computer is messing with me.
Aug 30, 2013 at 5:18 PM
Take that back. Seem working again. Sorry.