ThinkGeo.com    |     Documentation    |     Premium Support

Suppress TextStyle based on a value?

Hello,



I have a text style:

TextStyle countryTextStyle = TextStyles.City1("SomeFeatureSourceColumn")





This works great and labels all my countries with the value from my FeatureSource.  Is there any way to suppress or hide the text if the value of "SomeFeatureSourceColumn" is "0"?  I know this must be easy, but I was unable to find a solution by searching.



Thanks,





Joseph



Joseph, 
  
 RegexStyle might be the easiest way, just set the text style for the features whose “SomeFeatureSourceColumn” is not “0”, it will only render the non-zero features. 
 
                RegexStyle regexStyle = new RegexStyle();
                regexStyle.ColumnName = “SomeFeatureSourceColumn”;
                regexStyle.RegexMatchingRule = RegexMatching.MatchAll;
                // ‘^0$’ means it doesn’t equal to ‘0’. 
                regexStyle.RegexItems.Add(new RegexItem("^0$", TextStyles.City1(“SomeFeatureSourceColumn”)));

                ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(“myPath”);
                layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(regexStyle);
                layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
 Thanks, 
  
 Ben

That's great!  Thanks for the quick reply, Ben.   The RegexStyle worked great - the only thing I had to change from you example was to modify the regex to "^(?!0)"    Before it was only showing the "0", not ignoring them.



Joseph, 
  
 That’s true. I always cannot figure that Regex out, thanks for letting me know! 
  
 Ben.

I agree - regex can be a pain unless you use it all the time.  I had to spend a lot of time googleing it before I got it right.


Thanks again for your help.


 


Joe



My pleasure! Let us know if you have more issues.