I was trying to create a custom Linestyle class that would color lines based on color values in my .dbf file. Using code a former programmer was working on, so I don't know what his plan was or if this would work. But the result I get is using the following code on 4 of my layers seems to kill all my layers. It doesn't even seem like the DrawCore is being called as I don't hit my breakpoint when Debugging. Am I completely off the path or just missing something?
private void ApplyHTMLLineStyle(ShapeFileFeatureLayer layer){
ShapeFileFeatureLayer.BuildIndexFile(layer.ShapePathFileName, BuildIndexMode.DoNotRebuild);
HTMLLineStyle lineStyle = new HTMLLineStyle();
lineStyle.RequiredColumnNames.Add("Html");
layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(lineStyle);
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
}
class HTMLLineStyle : LineStyle
{
protected override void DrawCore(IEnumerable<
Feature
> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<
SimpleCandidate
> labelsInThisLayer, System.Collections.ObjectModel.Collection<
SimpleCandidate
> labelsInAllLayers)
{
double customWidth = 0;
int customOpacity = 0;
GeoColor customColor;
foreach (Feature feature in features)
{
customWidth = Convert.ToDouble(feature.ColumnValues["#StrokeWei"]);
customOpacity = (int)(Convert.ToInt32(feature.ColumnValues["#Opacity"]) * 2.55);
customColor = GeoColor.FromHtml(feature.ColumnValues["Html"]);
canvas.DrawLine(feature, new GeoPen(GeoColor.FromArgb(customOpacity, customColor), (float)customWidth), DrawingLevel.LabelLevel);
}
}
}
Custom Linestyle
Hi Jonci,
There’s one thing you need to do. In HTMLLineStyle, you used "#StrokeWei" "#Opacity" "Html", but you only added “Html” to the lineStyle.RequiredColumnNames.
Add the following code after the line lineStyle.RequiredColumnNames.Add("Html")
lineStyle.RequiredColumnNames.Add("#StrokeWei");
lineStyle.RequiredColumnNames.Add("#Opacity");
Hope it works.
Thanks,
Johnny
Okay, that gets my lines drawing correctly. So I just need to set a requirement for any column I will access.
New issue. I get random sections where the tile doesn’t draw since using the corrected code. Tiles that would have layers using the HTMLLineStyle and generic ThinkGeo styles. Any idea what could create these artifacts?
Actually, I think I know the reason. Looks like some of my dbf files have errors in the column naming. Some are "Html" and some are "HTML", along with some entries being similar.
Jonci,
Good to hear you figure it out.
If any other queries, please feel free to let us know.
Regards,
Johnny
You wouldn’t happen to know what program can edit a dbf file, would you? I’ve found that Excel will open it, but it can’t save back out
Hi Jonci,
There are several ways can edit the dbf file:
- using software: The simplest way is using Map Suite GisEditor to visualize and edit your data. Besides, there are many fantastic features integrating in it and I guess you might be interesting in it. More detail about GisEditor please refer to thinkgeo.com/gis-editor/
- by programming: If the dbf file is standing with the corresponding shape file, then we can use the ShapeFileFeatureLayer or ShaeFileFeatureSource class to do it. Here is a sample: wiki.thinkgeo.com/wiki/Map_S…_Shapefile
Hope it helps.
Regards,
Troy