ThinkGeo.com    |     Documentation    |     Premium Support

Styles on PostgreSqlFeatureLayer

 Hello,


I think there are problems with the way styles are applied on PostgreSqlFeatureLayers.  The following code appears to apply the red point/text styles from zoom levels 13 to 20 and blue from 01 to 12.  This seems to be reversed and different from the code?


 


 


This isn't an urgent problem but I thought I should bring it to your attention.


Regards,

Jonathan



        private void applyTextStyle(ref PostgreSqlFeatureLayer theLayer)
        {
            if (theLayer.Name == "cartographictext")
            {

                // Could do more with a value style based on one of the columns

                theLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.SimpleColors.Red, 2));
                theLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("textstring", "Calibri", 8, DrawingFontStyles.Bold, GeoColor.SimpleColors.Red, 2, 2));
                theLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level19;

                theLayer.ZoomLevelSet.ZoomLevel19.CustomStyles.Add(PointStyles.CreateSimplePointStyle(PointSymbolType.Square,GeoColor.SimpleColors.DarkBlue,2));
                theLayer.ZoomLevelSet.ZoomLevel19.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("textstring", "Calibri", 8, DrawingFontStyles.Bold, GeoColor.SimpleColors.DarkBlue, 2, 2));
                theLayer.ZoomLevelSet.ZoomLevel19.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            }

        }


Hi Jonathan, 

Thanks for your post!


I noticed that your code is not matching up with your description ie you stated "code appears to apply the red point/text styles from zoom levels 13 to 20 and blue from 01 to 12".


In your code you have ZoomLevel01 to ZoomLevel 19 and ZoomLevel19 to ZoomLevel20. I just want to make sure I understand the issue, so can you confirm that you description is correct?


Also you if you want you styles to go directly from Red to Blue you might want to setup you styles like this:



theLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.SimpleColors.Red, 2));
theLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("textstring", "Calibri", 8, DrawingFontStyles.Bold, GeoColor.SimpleColors.Red, 2, 2));
theLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level18;

theLayer.ZoomLevelSet.ZoomLevel19.CustomStyles.Add(PointStyles.CreateSimplePointStyle(PointSymbolType.Square,GeoColor.SimpleColors.DarkBlue,2));
theLayer.ZoomLevelSet.ZoomLevel19.CustomStyles.Add(TextStyles.CreateSimpleTextStyle("textstring", "Calibri", 8, DrawingFontStyles.Bold, GeoColor.SimpleColors.DarkBlue, 2, 2));
theLayer.ZoomLevelSet.ZoomLevel19.ApplyUntilZoomLevel = ApplyUntilZoomLevel


Sorry - the description is wrong 
  
 I meant that on the map the style appeared to change at the zoom level 12 to 13 transition. 
 It was a good point about applying the zoom level to 18 rather than 19 however that did not change what happened.  Actually I had tried a quite a few variations including only defining a style between 12 and 20 with the idea that the text would not be displayed at the other scales however that resulted in the same style being applied at all levels. 
  
 Regards, 
 Jonathan

I have some more information, some of which I'm sure I should have mentioned earlier.  I did change the zoom level scales like this:


 


Now whatever value I set  for intialScale the style consistently changes when moving from a scale of about 1:2500 to about 1:5000.  These look to be the default scales for zoom levels 18 and 19 therefore I think the styles are using the default zoom levels rather than the modified zoom levels.  I expect I am missing something simple so hopefully you can point me in the right direction.


Thanks,

Jonathan



            theMapControl.MapUnit = GeographyUnit.Meter;
            theMapControl.ZoomLevelSnapping = ZoomLevelSnappingMode.SnapUp;

            double intialScale = 5000;

            theMapControl.ZoomLevelSet.ZoomLevel01.Scale = intialScale;
            intialScale = intialScale / 2;

            theMapControl.ZoomLevelSet.ZoomLevel02.Scale = intialScale;
            intialScale = intialScale / 2;

            theMapControl.ZoomLevelSet.ZoomLevel03.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel04.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel05.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel06.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel07.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel08.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel09.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel10.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel11.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel12.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel13.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel14.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel15.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel16.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel17.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel18.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel19.Scale = intialScale;
            intialScale = intialScale / 2;
            
            theMapControl.ZoomLevelSet.ZoomLevel20.Scale = intialScale;
            intialScale = intialScale / 2;

            theMapControl.MinimumScale = theMapControl.ZoomLevelSet.ZoomLevel20.Scale;
            theMapControl.MaximumScale = theMapControl.ZoomLevelSet.ZoomLevel01.Scale;


 



Hi Jonathan,


You setup scales for your Map's ZoomLevelSet but if you are going to setup custom scales you also need to set these up for each Layer's ZoomLevelSet.


If you are going to maintain the same scales for the Map and Layers then I would create a new ZoomLevelSet object with your custom scales and then set the Map.ZoomLevelSet and EACH of your Layer.ZoomLevelSet to that new ZoomLevelSet object.


By setting up custom scales you now need to be sure and set the ZoomLevelSet for each new Layer you create. Otherwise the newly created layer will use the default ZoomLevelSet which will not 'line up' with your custom ZoomLevelSet settings.


Here is some sample code showing the setup of the new ZoomLevelSet's scales and the application of the new ZoomLevel to both the Map.ZoomLevelSet and a Layer.ZoomLevelSet:



 private void DisplayMap_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.Meter;

            //Setup IntialScale for use throughout the Map and Layer ZoomLevelSets
            double initialScale = 5000;
            //Create Map's ZoomLevelSet
            winformsMap1.ZoomLevelSet = CreateZoomLevelSet(initialScale);


            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
            //Setup Layer's ZoomLevelSet
            //Do this for EACH layer you add to the Map.
            worldLayer.ZoomLevelSet = CreateZoomLevelSet(initialScale);
            worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10;
            worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
}

private ZoomLevelSet CreateZoomLevelSet(double initialScale)
        {

            ZoomLevelSet myZoomLevelSet = new ZoomLevelSet();

            myZoomLevelSet.ZoomLevel01.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel02.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel03.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel04.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel05.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel06.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel07.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel08.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel09.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel10.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel11.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel12.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel13.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel14.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel15.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel16.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel17.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel18.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel19.Scale = initialScale;
            initialScale = initialScale / 2;

            myZoomLevelSet.ZoomLevel20.Scale = initialScale;
            initialScale = initialScale / 2;

            return myZoomLevelSet;
        }


Ryan,


Thank you, that makes sense and I will give it a go.


Regards,

Jonathan



Hi Jonathan, 
  
 Please let us know if you have any questions. 
  
 Regards, 
 Edgar