Folks,
I am observing that a text style is not being applied to all the lines in a MultiLineShaped feature. It is being applied only to one of the line segments. What is the strategy you use to label a MultiLineShape?
TIA/
Folks,
I am observing that a text style is not being applied to all the lines in a MultiLineShaped feature. It is being applied only to one of the line segments. What is the strategy you use to label a MultiLineShape?
TIA/
Klaus,
As far as I know, the default way cannot satisfy your requirement.
Here is a custom text style with a sample code. Please have a try and let me know if you have more queries.public partial class DisplayASimpleMap : UserControl
{
public DisplayASimpleMap()
{
InitializeComponent();
}
private void WpfMap_Loaded(object sender, RoutedEventArgs e)
{
Map1.MapUnit = GeographyUnit.DecimalDegree;
Map1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9);
InMemoryFeatureLayer layer = new InMemoryFeatureLayer();
layer.Open();
layer.Columns.Add(new FeatureSourceColumn("ID"));
layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Canal1;
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new CustomTextStyle("ID", new GeoFont(), new GeoSolidBrush(GeoColor.StandardColors.Black));
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
layer.Close();
MultilineShape mlines = new MultilineShape();
double latitude = 90;
while (latitude > -90)
{
mlines.Lines.Add(new LineShape(new Collection<Vertex>() { new Vertex(-180, latitude), new Vertex(180, latitude) }));
latitude -= 10;
}
Feature feature = new Feature(mlines);
feature.ColumnValues.Add("ID", Guid.NewGuid().ToString());
layer.InternalFeatures.Add(feature);
LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.TileType = TileType.SingleTile;
layerOverlay.Layers.Add(layer);
Map1.Overlays.Add(layerOverlay);
}
}
public class CustomTextStyle : TextStyle
{
public CustomTextStyle(string textColumnName, GeoFont textFont, GeoSolidBrush textSolidBrush)
: base(textColumnName, textFont, textSolidBrush)
{ }
protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
{
Collection<Feature> featuresForDrawing = new Collection<Feature>();
foreach (Feature feature in features)
{
if (feature.GetWellKnownType() == WellKnownType.Multiline)
{
MultilineShape multiline = (MultilineShape)(feature.GetShape());
foreach (LineShape line in multiline.Lines)
{
Feature newFeature = new Feature(line);
CopyColumnValues(newFeature, feature);
featuresForDrawing.Add(newFeature);
}
}
else
{
featuresForDrawing.Add(feature);
}
}
base.DrawCore(featuresForDrawing, canvas, labelsInThisLayer, labelsInAllLayers);
}
private static void CopyColumnValues(Feature targetFeature, Feature sourceFeature)
{
targetFeature.ColumnValues.Clear();
foreach (KeyValuePair<string, string> item in sourceFeature.ColumnValues)
{
targetFeature.ColumnValues.Add(item.Key, item.Value);
}
}
}
Thanks,
Howard
Magical! Thanks.
Hi Klaus,
I’m surprised that we have “LabelAllPolygonParts” property on text style for doing st. like you want to do on the polygon; but we don’t have LabelAllLineParts. We’ll consider this feature and add it to our product. It’s on our list now and just let you know.
Thanks,
Howard
Klaus,
We have added LabelAllLineParts on TextStyle, please try it by using MapSuite dlls version 4.5.136.0 or later.
Thanks,
James
Thanks James. Will wait for you guys to publish v 4.5.136.0 and give it a try.
You’re welcome, Klaus.
Klaus,
I want to also let you know that there is a Code Community sample that shows how to create your own custom LineStyle for that effect if you do not want to wait for the next version. I think it will also be interesting to see the internals of how that class was created. You can check it out.
Multiline Labeling wiki.thinkgeo.com/wiki/Map_Suite_De...e_Labeling
Thank you.
Guys, a quick question on labelling of the MultiLineShape. If TextStyle.LabelAllLineParts = false, how do you determine which line segment to label? Also, is is possible for one to override this, if I know which line (or line index) I want labelled?
Hi Klaus,
When the LabelAlllineParts property is false, we will label the longest segment of the line shape. I’m afraid we don’t have a very easy way to override the default functionality, you know the text style responsible all line, point and area shapes; we also need handle the offset, rotation and different font styles. At this point, we only exposed the GetLabelingCandidateCore in TextStyle for inheritance, but this method is very complex to override and write a guild line. I’m very glad to hear your idea so that we have a scenario to make our style more extensible.
Thanks,
Howard
Klaus,
To add to what Howard was saying you can override the GetLabelingCanidateCore and that will allow you to see each feature as it comes in to be labeled. You have access to the feature and place the resulting label into the LabelCanidate collection. The label candidate is pretty straight forward and you can override the method and start to see what kind of candidates it builds up for certain scenarios. I think you can do it if you have some inclination.
David