ThinkGeo.com    |     Documentation    |     Premium Support

MsSql2008FeatureLayer question

Hi,


We have data on the MS SQL server and we are using MsSql2008FeatureLayer. Every object in table has property for displaying in predefined zoom (e.g. town Berlin has set property value on 5 and so it will be displaied from zoom 5).


How can I set the condition for ZoomLevelSet in MsSql2008FeatureLayer? Do you have an example?


Thanks


Ondrej



Ondrej, 


I think there is no need to create your own ZoomLevelSet, Following code is some way I can think about, if you have any better idea, just let me know.
 

 private void SetUpLayer(FeatureLayer targetLayer, int zoom, AreaStyle araStyle, LineStyle lineStyle, PointStyle pointStyle)
        {
            switch (zoom)
            {
                case 1:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = pointStyle; }
                    break;
                case 2:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel02.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel02.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel02.DefaultPointStyle = pointStyle; }
                    break;
                case 3:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel03.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel03.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel03.DefaultPointStyle = pointStyle; }
                    break;
                case 4:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel04.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel04.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel04.DefaultPointStyle = pointStyle; }
                    break;
                case 5:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel05.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel05.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel05.DefaultPointStyle = pointStyle; }
                    break;
                case 6:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel06.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel06.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel06.DefaultPointStyle = pointStyle; }
                    break;
                case 7:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel07.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel07.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel07.DefaultPointStyle = pointStyle; }
                    break;
                case 8:
                    if (araStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel08.DefaultAreaStyle = araStyle; }
                    if (lineStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel08.DefaultLineStyle = lineStyle; }
                    if (pointStyle != null) { targetLayer.ZoomLevelSet.ZoomLevel08.DefaultPointStyle = pointStyle; }
                    break;

                default:
                    break;
            }
}

 
Thanks.
 
Yale

Hi,


No. I need to set condition to MsSql2008FeatureLayer. I have table on SQL 2008, there are geometry objects with property Category. Category is from 1 to 5. I need add to LayerOverlay 5 layers of type MsSql2008FeatureLayer, but with condition (Category = 1, Category = 2, Category = 3, Category = 4, Category = 5).


After I set a ZoomLevelSet. But the getting of datas by value is the problem.


Thanks


Ondrej



Ondrej, 
  
 Do you mean you have a SqlServer table which contains geometry column and category column; what you want to do is that, for example. 
  
 If the category is 1, display all the data whose category is 1 from zoom level 1 to 20; 
 If the category is 2, display all the data whose category is 2 from zoom level 2 to 20; 
 … 
  
 Please point out if there is any misunderstanding so that I can provide you a sample correctly. 
  
 Thanks, 
 Howard

Yes Howard, your example is right. I want display 5 MsSqlLayers via column Category value.



Ondrej,



Hope the following code makes sense. Any questions please let me know.


MsSql2008FeatureLayer layer1 = new MsSql2008FeatureLayer("[ConectionString]", "[TableName]", "IdColumn");
layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(GetValueStyle("1", AreaStyles.Country1));
layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

MsSql2008FeatureLayer layer2 = new MsSql2008FeatureLayer("[ConectionString]", "[TableName]", "IdColumn");
layer2.ZoomLevelSet.ZoomLevel02.CustomStyles.Add(GetValueStyle("2", AreaStyles.Country2));
layer2.ZoomLevelSet.ZoomLevel02.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

MsSql2008FeatureLayer layer3 = new MsSql2008FeatureLayer("[ConectionString]", "[TableName]", "IdColumn");
layer3.ZoomLevelSet.ZoomLevel03.CustomStyles.Add(GetValueStyle("3", AreaStyles.County1));
layer3.ZoomLevelSet.ZoomLevel03.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

MsSql2008FeatureLayer layer4 = new MsSql2008FeatureLayer("[ConectionString]", "[TableName]", "IdColumn");
layer4.ZoomLevelSet.ZoomLevel04.CustomStyles.Add(GetValueStyle("4", AreaStyles.County2));
layer4.ZoomLevelSet.ZoomLevel04.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

MsSql2008FeatureLayer layer5 = new MsSql2008FeatureLayer("[ConectionString]", "[TableName]", "IdColumn");
layer5.ZoomLevelSet.ZoomLevel05.CustomStyles.Add(GetValueStyle("5", AreaStyles.Crop1));
layer5.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

LayerOverlay overlay = new LayerOverlay();
overlay.Layers.Add(layer1);
overlay.Layers.Add(layer2);
overlay.Layers.Add(layer3);
overlay.Layers.Add(layer4);
overlay.Layers.Add(layer5);

Map1.CustomOverlays.Add(overlay);


private ValueStyle GetValueStyle(string columnValue, Style style)
{
    ValueStyle style = new ValueStyle();
    style.ColumnName = "Category";
    style.ValueItems.Add(new ValueItem(columnValue, style));
    return style;
}




Thanks,

Howard



Yes, Howard, thank you very much.


Ondrej



Ondrej, 
  
 You are welcome. Please feel free to let me know if you have any queries. 
  
 Thanks, 
 Howard