the same file set the different maxvisable value

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Jul 21, 2010 at 5:17 AM
Hello, 

I'd like to draw different road color by roadType and show it by different zoom value.

(for example, I'd like to show RoadType="HW" by zoomvalue=1 and show RoadType="HU" by zoomvalue=0.06)

I don't know where I set wrong. the Road all show as defalut setting zoomvalue.

If I explain unclearly, please tell me. Thanks. :) 

 private delegate IStyle GetStyleHandler(FeatureDataRow row);

 

 VectorStyle transparentStyle = new VectorStyle();
            transparentStyle.Fill = Brushes.Transparent;
            transparentStyle.EnableOutline = true;
            transparentStyle.Line.Brush = Brushes.Transparent;
            transparentStyle.Outline.Brush = Brushes.Transparent;
            transparentStyle.Symbol = null;
            transparentStyle.MaxVisible = 0.008;
VectorLayer layRoads = new VectorLayer("Roads");
            layRoads.DataSource = new SharpMap.Data.Providers.ShapeFile("road.shp", true);
            ((SharpMap.Data.Providers.ShapeFile)layRoads.DataSource).Encoding = System.Text.Encoding.GetEncoding("Big5");
layRoads.Style = transparentStyle;
            ThemeViaDelegate themeRoads = new ThemeViaDelegate(transparentStyle, "RoadType");
            themeRoads.GetStyleFunction = delegate(FeatureDataRow row)
 {
                                                  VectorStyle returnStyle = new VectorStyle();

                                                  switch ((String)row["RoadType"])
                                                  {
                                                      case "HW":
                                                          returnStyle.Line.Width = 4;
                                                          returnStyle.Line.Color = Color.Tomato;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.DarkGray;
                                                          returnStyle.Outline.Width = 5;
                                                          returnStyle.MaxVisible = 1;
                                                          break;
                                                       case "HU":
                                                          returnStyle.Line.Width = 4;
                                                          returnStyle.Line.Color = Color.Yellow;
                                                          returnStyle.Outline.Brush = Brushes.DarkGray;
                                                          returnStyle.Outline.Width = 5;
                                                          returnStyle.MaxVisible = 0.06;
                                                          break;
                                                       case "GE":                                                     
                                                           returnStyle.Line.Color = Color.Pink;
                                                           returnStyle.Line.Width = 4;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.DarkGray;
                                                          returnStyle.Outline.Width = 5;
                                                          returnStyle.MaxVisible = 0.008; 
                                                          break;
                                                     default:
                                                          returnStyle.MaxVisible = 0.008; 
                                                          break;
                                                  }
                                                  return returnStyle; 
                                              };
     layRoads.Theme = themeRoads;
      layRoads.SRID = 4326;
            
     class ThemeViaDelegate : ITheme
        {
            public GetStyleHandler GetStyleFunction;
            private readonly IStyle _default;
            private readonly String _columnName;
            private readonly IDictionary<String, IStyle> _stylePreserver;

            public ThemeViaDelegate(IStyle defaultStyle, String columnName)
            {
                _default = defaultStyle;
                _stylePreserver = new Dictionary<string, IStyle>();
                _columnName = columnName;
            }


            #region Implementation of ITheme

            public IStyle GetStyle(FeatureDataRow attribute)
            {
                IStyle returnStyle;
                String value = Convert.ToString(attribute[_columnName]);
                if (!_stylePreserver.TryGetValue(value, out returnStyle))
                {
                    if (GetStyleFunction != null)
                    {
                        returnStyle = GetStyleFunction(attribute);
                        if (returnStyle == null) returnStyle = _default;
                        _stylePreserver.Add(value, returnStyle);
                    }
                    else
                        returnStyle = _default;
                }
               return returnStyle;
            }

            #endregion
        }
Coordinator
Jul 21, 2010 at 10:20 AM

Hello carolting,

Min- and MaxZoom properties expect values in the unit of your geometry data.

Are you sure that the values you use in your switch case block are present in your data, maybe a ToUpper() call would help.

Hth FObermaier

Jul 22, 2010 at 2:15 AM

Hi, FObermaier

Thanks for your reply.

Sorry for my English. I still don't understand what you mean... :(

It'd not work, if I set Maxvisible value in VectorStyle.

Just make sure if I'd like to draw different roadtype by different color and show them in different scale.

How to do it?...could you give me a sample?

Caolting

Coordinator
Jul 22, 2010 at 9:25 AM
Edited Jul 22, 2010 at 9:27 AM

I would do the following modifications:

Ensure that ther is no casing problem:

switch (((String)row["RoadType"]).ToUpper())

Set MaxValue to some portion of your layer extent

//somewhere at class level
SharpMap.Geometries.BoundingBox _extent;
...
//Create Provider and get extent
SharpMap.Data.Provider.ShapeFile shapeFile = new SharpMap.Data.Provider.ShapeFile(<path>);
shapeFile.Open();
_extent = shapeFile.GetExtents();
...
//Set Max Value to some portion of the extent determinated above
returnStyle.MaxValue = 0.06d * _extent.Width;

Hth FObermaier

 

Jul 22, 2010 at 10:21 AM

Sorry, FObermaier

I think you mistake my problem. (Sorry, my explain my problem unclearly.)

I use a sample like my problem.

Sometimes, we set MaxVisible of VectorLayer. It works OK.

I find it has the smae property "MaxVisible" in VectorLayer.Style .

I still don't unstardand what the different between VectorLayer.MaxVisible and VectorLayer.Style.MaxVisible.

I use a simple sample as follows:

            SharpMap.Layers.VectorLayer layTown= new SharpMap.Layers.VectorLayer("Town");
            layTown.DataSource = new SharpMap.Data.Providers.ShapeFile(<path>);
            layTown.Style.Fill = new SolidBrush(Color.PaleGreen);
            layTown.Style.Outline = System.Drawing.Pens.Yellow; 
            layTown.Style.EnableOutline = true;
            layTown.SRID = 4326;

if I add code layTown.MaxVisible = 0.5;

it will show this layer when zoom value=0.5;

but if I remove code  layer when zoom value=0.5; and  add code layTown.Style.MaxVisible = 0.5;

it doesn't show this layer like before.

zoomvalue is default value.

In your code, I'd like to make sure the MaxVisible value have to setted by one VectorLayer. and it can't set the different value in the same VectorLayer. Right??

 

Thanks a lot,

Carolting

Coordinator
Jul 22, 2010 at 7:34 PM
Hello Carolting, now i get what you are saying, and you are right there is an inconsistency in the rendering logic: Min- and MaxVisible properties of Layer do not at all refer to the values set in Style property. The Min- and MaxVisible properties of Style, as far as I can tell, only apply when a theme is attached to a layer. Please feel free to raise an issue if you want that fixed. Cheers FObermaier