ThinkGeo.com    |     Documentation    |     Premium Support

Value Style won't display

Hi,

I am trying to apply a value style to an sqlitefeaturelayer with the following code. But, when I view the map, nothing is displayed. If I change it to use the default zooms, it looks fine.

My Flag column contains 1 and 0 for True and False. In v10, setting the value item to “False” or “True” worked just fine. I am wondering if that is an issue now?

Also, I am a bit confused about the deprecation message that appears for MapView.ZoomLevelSet. Can you tell me how that part of the code should be written?

SqliteFeatureLayer sql = new SqliteFeatureLayer(_microConn, "Shots", "Id", "geometry");
        sql.Name = "Source Points";

        ZoomLevelSet zooms = new ZoomLevelSet();
        ValueStyle vs = new ValueStyle();
        vs.ColumnName = "Flag";
        vs.ValueItems.Add(new ValueItem("False", new PointStyle(PointSymbolType.Diamond, 8, new GeoSolidBrush(GeoColors.Red))));
        vs.ValueItems.Add(new ValueItem("True", new PointStyle(PointSymbolType.Diamond, 8, new GeoSolidBrush(GeoColors.Red))));

        foreach (var zoom in _map.ZoomLevelSet.GetScales())
        {
            ZoomLevel thisZoom = new ZoomLevel(zoom);
            zooms.CustomZoomLevels.Add(thisZoom);
        }

        // The Value Style will not display on screen
        //sql.ZoomLevelSet = zooms;

Thanks,
Damian

Hi Damian,

Can you try setting valueStyle.DefaultStyle ? If you see features rendered with the default style, that means the Flag column values are not matching "False" or "True" . In the current versions, we no longer treat "1" as "True" or "0" as "False" automatically during value comparison (to distinguish with the string of “True”/“False”). So if your column stores 1 and 0, please try "0" and "1" in your ValueItem definitions instead.

Regarding the deprecation message for MapView.ZoomLevelSet :

  • ZoomLevelSet is still the right choice for a FeatureLayer , because it defines how styles are applied at different scales.
  • For the MapView , however, it was too heavy, so we replaced CustomZoomLevelSet with a simpler Collection<double> called ZoomScales .
  • MapView.ZoomScales is only used for snapping when double-clicking or wheel zooming. In practice the map can stop at any scale, and you can also programmatically zoom to an exact scale.
  • Keep in mind that MapView.ZoomScales does not need to align with the scales in your layer’s ZoomLevelSet ; the former is for zoom snapping, the latter is for styling.

So to answer your question:

  • If you’re fine with the default 20 ZoomScales , you don’t need to change anything.
  • If you want to customize them, simply clear the existing ZoomScales and add your own values in order from largest to smallest.

Thanks,
Ben

I did try setting values to 1 and 0 with no luck. I also set the valueStyle.DefaultStyle to a large blue cross and it did not show up.

You have the test project and can confirm.

Regards,
Damian

Damian,

Do you mean the test project you sent over in SqliteFeatureLayer and InMemoryFeatureLayer display problem?

  1. In that project “1” and “0” has the same style, and there’re also other styles on top of it so they will be overridden anyway. I simplified the code to the following:
     ValueStyle vs = new ValueStyle();
     vs.ColumnName = "Flag";
     vs.ValueItems.Add(new ValueItem("1", new PointStyle(PointSymbolType.Diamond, 8, new GeoSolidBrush(GeoColors.Blue))));
     vs.ValueItems.Add(new ValueItem("0", new PointStyle(PointSymbolType.Diamond, 8, new GeoSolidBrush(GeoColors.Red))));
     sql.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(vs);
     sql.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
  1. All in your demo data System.Sqlite, all the record has flag “1”, I manually changed the first record’s Flag “0” and it works as expected.
    image

Thanks,
Ben

Yes, the demo project I sent with the sqlite issue.

On my side, I see nothing at all. Yours looks right.

The data filepath is hard coded in your project, you need to either change that or copy the System.Sqlite directly under bin folder (That was what I did).
Have a try and let me know if it still doesn’t work.

It’s not the hardcoded db. If I use defaultpoint style like so, it displays.

        sql.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Diamond, 8, new GeoSolidBrush(GeoColors.Green));
        sql.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

This is my code that works fine, please take a look.
Form1.cs (3.3 KB)

Okay, I’ve found the issue. In the below, I have added a zoom level, but forgot to add the value style to the custom styles zoom level.

BTW: This was in my test project I provided. You should have been able to replicate it immediately using my code.

        foreach (var zoom in _map.ZoomScales)
        {
            ZoomLevel thisZoom = new ZoomLevel(zoom);
            zooms.CustomZoomLevels.Add(thisZoom);
        }
        sql.ZoomLevelSet = zooms;

Regards,
Damian

I see, yep, I streamlined the code a bit and that’s when I accidently fixed it.