ThinkGeo.com    |     Documentation    |     Premium Support

Not all streets labeled?

In the lowest level (zoom level=20), all the street names were displayed. But as i was turning the mouse wheel to zoom out, for each zoom out, i noticed more and more street names were disappearing, some were displayed, some were not. Is there any remedy to this situation?


My declarations is simple:




ShapeFileFeatureLayer expresswayLayer = new ShapeFileFeatureLayer(@"C:\Maps\expressway.shp");
expresswayLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(LineStyles.LocalRoad1);
expresswayLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

ShapeFileFeatureLayer expresswayLabelLayer = new ShapeFileFeatureLayer(@"C:\Maps\expressway.shp");
expresswayLabelLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.LocalRoad1("ST_NAME"));
expresswayLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
expresswayLabelLayer.DrawingMarginPercentage = 100;

wpfMap1.StaticOverlay.Layers.Add("ExpresswayLayer", expresswayLayer);
wpfMap1.StaticOverlay.Layers.Add("ExpresswayLabelLayer", expresswayLabelLayer);




Ric






 


Ric,


Labeling is a big part,  there are whole bunch of properties just for it. Here I want to show you some of those by a simple sample.


Here I want to show the Austin Street in a small extent,  the codes are very simple.



ShapeFileFeatureLayer labelLayer = new ShapeFileFeatureLayer(@"C:\Program Files\ThinkGeo\Map Suite Web Evaluation Edition 3.0\Samples\CSharp Samples\SampleData\USA\Austin\Austinstreets.shp");
labelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Country1("FENAME"); // FENAME taken from the "Austinstreets.dbf" file
labelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


Why only one label is displayed. One reason is that as all the roads are shown in the map, the length of each road is very small. To avoid the case that you have a long label for a short line, we just ignore drawing the labels for that case. We have a property TextStyle.TextLineSegmentRatio(0.9 by default), if a road’s label is longer than road.Length * TextStyle.TextLineSegmentRatio, it will not be displayed.


 


I added the following code and have another try. (I set it to double.MaxValue so there is no limit)


layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.TextLineSegmentRatio = double.MaxValue;


 



Still seems not have enough labels? That’s because to avoid having too many labels in one small area, we divided the map into many grids and each grid we allow to draw at most one label.  We has a property TextStyle.GridSize to set the size (in integer) of the grid, by default is 100.


 


Adding the following line to the code, here is the result.


layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.GridSize = 5;


 



(Please see the next thread for the second part)








 


(continue with the last message)


By default, overlapping is not allowed for labeling. Sure you can enable it by setting TextStyle.OverlappingRule to AllowOverlapping. With the following codes added, the result will be like this.


layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping;


 


 



 


Also please have a look at the following post for the DrawingMarginPercentage property.


gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/12/aft/4890/afv/topic/Default.aspx


 


I hope that helps.




Ben