ThinkGeo.com    |     Documentation    |     Premium Support

Create sublayers from actual layer

Do you all have a sample where you do sublayers?

Let me give you a more detail explanation.

The data itself would be stored in sql database and lets say it will be composed of the following attributes.

By default all of them will be turned on. When the user click on the check box Houston then Houston would be turned off.


Hi Jose,

If you want to implement that by the different layer, you can create separated layers for each city, then add them to a overlay, so you can hide/show each layer.

But I think for your scenario(only shows so simple city), you should want to add the cites(feature) to one layer for example an in-memory feature layer, then remove or add the feature when you click on the check box.

Wish that’s helpful.

Regards,

Don

Thanks for the response Don,

But non of the solutions would work for me. If i create a layer per city, and i have all the cities for Texas it would take up all the screen.

I am looking to create something like this.

Where the SQL Table name is inspections and within that table I have a column named month. The month column would indicate what month it is. So then I just create a filter or sublayers of that column which results on the screen shot above.

Here is a screen capture of month/lat/lon.

Hi Jose,

Thanks for your detail requirement, our developer build a sample for your scenario.

The sample show how to use checkbox to control the visible status of features, the mainly API we used is the FeatureIdsToExclude property on layer.

8551.zip (90.5 KB)

Wish that’s helpful, and any question please let us know.

Regards,

Don

Hi Don,

I have tried the code and this is what shows up.

Notice how the “SubLayers” are treated as actual layers. The sublayers should be considered as the children of the layer itself.

Something like this:

Hi Jose,

If you are using database please let us know, we just give suggestion for the shape file now.

I understand your meaning here, your “sublayer” should a group of features, so we have another solution here.

Because your datasource is sql database, I think you can do that like this:

            MsSqlFeatureLayer layer1 = new MsSqlFeatureLayer(connectionString, tableName, featureIdColumn);
            layer1.WhereClause = "where inspected_month = 'January'";

            MsSqlFeatureLayer layer2 = new MsSqlFeatureLayer(connectionString, tableName, featureIdColumn);
            layer2.WhereClause = "where inspected_month = 'March'";

This solution need add many layers into a overlay, so you can operate the status of single layer.

Or you can implement that like this:

   PointStyle JanStyle = PointStyles.City1;
            PointStyle MarStyle = PointStyles.City2;

            ValueStyle value = new ValueStyle();
            value.ColumnName = "inspected_month";
            value.ValueItems.Add(new ValueItem("January", JanStyle));
            value.ValueItems.Add(new ValueItem("March", MarStyle));

            MsSqlFeatureLayer layer1 = new MsSqlFeatureLayer(connectionString, tableName, featureIdColumn);
            layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(value);
            layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


            // Hide January features                
            PointStyle MarStyle = PointStyles.City2;

            ValueStyle value = new ValueStyle();
            value.ColumnName = "inspected_month";                
            value.ValueItems.Add(new ValueItem("March", MarStyle));
            layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
            layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(value);
            layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Add April features
            PointStyle JanStyle = PointStyles.City1;
            PointStyle MarStyle = PointStyles.City2;
            PointStyle AprStyle = PointStyles.City3;
            
            ValueStyle value = new ValueStyle();
            value.ColumnName = "inspected_month";
            value.ValueItems.Add(new ValueItem("January", JanStyle));
            value.ValueItems.Add(new ValueItem("March", MarStyle));
            value.ValueItems.Add(new ValueItem("April", AprStyle));
            layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
            layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(value);
            layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

Wish that’s helpful, any question please let us know.

Regards,

Don

Thank You Don,

Your answer gets me closer to the end result. With adding the styles by the months it shows the different size depending on the month.

Do you have something within your API where you can say showSubLayerSwitcher?

You have something to show the overlays and be able to turn them on and off.

Map1.MapTools.OverlaySwitcher.Enabled = true;

Hi Jose,

Because we don’t have the sub layer object, so the layer switcher only shows overlay and layers.

If you want to make that work with the simplest solution, I think you can just use the solution 1, put each layer into an overlay, then you can directly control that with our default switcher.

Or you want to implement a custom layer switcher which looks like your image, please refer this topic, which talk about this more detail:

Regards,

Don

Great Don,

Could you provide me with the link of that thread from howard?

Thanks!!!

Hi Jose,

Please click here:

Regards,

Don